aboutsummaryrefslogtreecommitdiff
path: root/dw/tablecell.cc
blob: 3e143c96885827d6e2c257d5d232a4b2346551c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * Dillo Widget
 *
 * Copyright 2014 Sebastian Geerken <sgeerken@dillo.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "tablecell.hh"
#include "table.hh"

namespace dw {

/**
 * \brief Provided some common implementations of virtual widget
 *    methods.
 *
 * Once I understand how diamond inheritance works, a class TableCell
 * will be provided, from which SimpleTableCell and AlignedTableCell
 * will inherit, additionaly (in a multiple way).
 */
namespace tablecell {

bool getAdjustMinWidth ()
{
   return Table::getAdjustTableMinWidth ();
}

bool isBlockLevel ()
{
   return false;
}

int correctAvailWidthOfChild (core::Widget *widget, core::Widget *child,
                              int width, bool forceValue)
{
   DBG_OBJ_ENTER_O ("resize", 0, widget, "tablecell/correctAvailWidthOfChild",
                    "%p, %d, %s", child, width, forceValue ? "true" : "false");

   // Make sure that this width does not exceed the width of the table
   // cell (minus margin/border/padding).

   if (width != -1) {
      int thisWidth = widget->getAvailWidth (forceValue);
      DBG_OBJ_MSGF_O ("resize", 1, widget, "thisWidth = %d", thisWidth);
      if (thisWidth != -1)
         width =
            lout::misc::max (lout::misc::min (width,
                                              thisWidth
                                              - widget->boxDiffWidth ()),
                             0);
   }

   DBG_OBJ_MSGF_O ("resize", 1, widget, "=> %d", width);
   DBG_OBJ_LEAVE_O (widget);
   return width;
}

int correctAvailHeightOfChild (core::Widget *widget, core::Widget *child,
                               int height, bool forceValue)
{
   // Something to do?
   return height;
}

void correctCorrectedRequisitionOfChild (core::Widget *widget,
                                         core::Widget *child,
                                         core::Requisition *requisition,
                                         void (*splitHeightFun) (int, int*,
                                                                 int*))
{
   DBG_OBJ_ENTER_O ("resize", 0, widget, "tablecell/correctRequisitionOfChild",
                    "%p, %d * (%d + %d), ...", child, requisition->width,
                    requisition->ascent, requisition->descent);

   // Make sure that this width does not exceed the width of the table
   // cell (minus margin/border/padding).

   int thisWidth = widget->getAvailWidth (true);
   DBG_OBJ_MSGF_O ("resize", 1, widget, "thisWidth = %d", thisWidth);
   requisition->width =
      lout::misc::max (lout::misc::min (requisition->width,
                                        thisWidth - widget->boxDiffWidth ()),
                       0);

   DBG_OBJ_LEAVE_O (widget);
}

void correctCorrectedExtremesOfChild (core::Widget *widget, core::Widget *child,
                                      core::Extremes *extremes,
                                      bool useAdjustmentWidth)
{
   // Something to do?
}

int applyPerWidth (core::Widget *widget, int containerWidth,
                   core::style::Length perWidth)
{
   return core::style::multiplyWithPerLength (containerWidth, perWidth);
}

int applyPerHeight (core::Widget *widget, int containerHeight,
                    core::style::Length perHeight)
{
   return core::style::multiplyWithPerLength (containerHeight, perHeight);
}

} // namespace dw

} // namespace dw