diff options
author | Sebastian Geerken <devnull@localhost> | 2014-07-24 23:40:21 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2014-07-24 23:40:21 +0200 |
commit | 6c77ae97e8d500a35caf3b9acdc5c0a377337d9d (patch) | |
tree | fd96fa08b1ef23266865edefed5587da3bdb6a39 | |
parent | b6aeac03a3e6c5f4ea7edaad9a42b79cf5a8fe10 (diff) |
More work on tables; some reorganization.
-rw-r--r-- | dw/Makefile.am | 2 | ||||
-rw-r--r-- | dw/alignedtablecell.cc | 44 | ||||
-rw-r--r-- | dw/alignedtablecell.hh | 3 | ||||
-rw-r--r-- | dw/simpletablecell.cc | 39 | ||||
-rw-r--r-- | dw/simpletablecell.hh | 3 | ||||
-rw-r--r-- | dw/table.cc | 12 | ||||
-rw-r--r-- | dw/tablecell.cc | 91 | ||||
-rw-r--r-- | dw/tablecell.hh | 27 | ||||
-rw-r--r-- | dw/widget.cc | 14 | ||||
-rw-r--r-- | dw/widget.hh | 1 |
10 files changed, 212 insertions, 24 deletions
diff --git a/dw/Makefile.am b/dw/Makefile.am index 25d8bbce..0b4b7bb4 100644 --- a/dw/Makefile.am +++ b/dw/Makefile.am @@ -78,6 +78,8 @@ libDw_widgets_a_SOURCES = \ table.cc \ table_iterator.cc \ table.hh \ + tablecell.cc \ + tablecell.hh \ textblock.cc \ textblock_iterator.cc \ textblock_linebreaking.cc \ diff --git a/dw/alignedtablecell.cc b/dw/alignedtablecell.cc index f1e1203a..5e4b9e24 100644 --- a/dw/alignedtablecell.cc +++ b/dw/alignedtablecell.cc @@ -21,6 +21,7 @@ #include "alignedtablecell.hh" #include "table.hh" +#include "tablecell.hh" #include "../lout/debug.hh" #include <stdio.h> @@ -46,26 +47,53 @@ AlignedTableCell::~AlignedTableCell() DBG_OBJ_DELETE (); } + +bool AlignedTableCell::getAdjustMinWidth () +{ + return tablecell::getAdjustMinWidth (); +} + bool AlignedTableCell::isBlockLevel () { - return false; + return tablecell::isBlockLevel (); +} + +int AlignedTableCell::getAvailWidthOfChild (Widget *child, bool forceValue) +{ + DBG_OBJ_ENTER ("resize", 0, "AlignedTableCell/getAvailWidthOfChild", + "%p, %s", child, forceValue ? "true" : "false"); + + int width = tablecell::correctAvailWidthOfChild + (this, child, Textblock::getAvailWidthOfChild (child, forceValue), + forceValue); + + DBG_OBJ_LEAVE (); + return width; +} + +int AlignedTableCell::getAvailHeightOfChild (Widget *child, bool forceValue) +{ + DBG_OBJ_ENTER ("resize", 0, "AlignedTableCell/getAvailHeightOfChild", + "%p, %s", child, forceValue ? "true" : "false"); + + int height = tablecell::correctAvailHeightOfChild + (this, child, Textblock::getAvailHeightOfChild (child, forceValue), + forceValue); + + DBG_OBJ_LEAVE (); + return height; } int AlignedTableCell::applyPerWidth (int containerWidth, core::style::Length perWidth) { - return core::style::multiplyWithPerLength (containerWidth, perWidth); + return tablecell::applyPerWidth (this, containerWidth, perWidth); } int AlignedTableCell::applyPerHeight (int containerHeight, core::style::Length perHeight) { - return core::style::multiplyWithPerLength (containerHeight, perHeight); -} - -bool AlignedTableCell::getAdjustMinWidth () -{ - return Table::getAdjustTableMinWidth (); + return tablecell::applyPerHeight (this, containerHeight, perHeight); } int AlignedTableCell::wordWrap(int wordIndex, bool wrapAll) diff --git a/dw/alignedtablecell.hh b/dw/alignedtablecell.hh index 20733bce..b49660ba 100644 --- a/dw/alignedtablecell.hh +++ b/dw/alignedtablecell.hh @@ -12,6 +12,9 @@ private: int charWordIndex, charWordPos; protected: + int getAvailWidthOfChild (Widget *child, bool forceValue); + int getAvailHeightOfChild (Widget *child, bool forceValue); + bool getAdjustMinWidth (); int wordWrap (int wordIndex, bool wrapAll); diff --git a/dw/simpletablecell.cc b/dw/simpletablecell.cc index 43dec92a..2621c348 100644 --- a/dw/simpletablecell.cc +++ b/dw/simpletablecell.cc @@ -20,7 +20,8 @@ #include "simpletablecell.hh" -#include "table.hh" +#include "tablecell.hh" +#include "../lout/misc.hh" #include "../lout/debug.hh" namespace dw { @@ -41,24 +42,50 @@ SimpleTableCell::~SimpleTableCell() bool SimpleTableCell::getAdjustMinWidth () { - return Table::getAdjustTableMinWidth (); + return tablecell::getAdjustMinWidth (); } bool SimpleTableCell::isBlockLevel () { - return false; + return tablecell::isBlockLevel (); +} + +int SimpleTableCell::getAvailWidthOfChild (Widget *child, bool forceValue) +{ + DBG_OBJ_ENTER ("resize", 0, "SimpleTableCell/getAvailWidthOfChild", + "%p, %s", child, forceValue ? "true" : "false"); + + int width = tablecell::correctAvailWidthOfChild + (this, child, Textblock::getAvailWidthOfChild (child, forceValue), + forceValue); + + DBG_OBJ_LEAVE (); + return width; +} + +int SimpleTableCell::getAvailHeightOfChild (Widget *child, bool forceValue) +{ + DBG_OBJ_ENTER ("resize", 0, "SimpleTableCell/getAvailHeightOfChild", + "%p, %s", child, forceValue ? "true" : "false"); + + int height = tablecell::correctAvailHeightOfChild + (this, child, Textblock::getAvailHeightOfChild (child, forceValue), + forceValue); + + DBG_OBJ_LEAVE (); + return height; } int SimpleTableCell::applyPerWidth (int containerWidth, - core::style::Length perWidth) + core::style::Length perWidth) { - return core::style::multiplyWithPerLength (containerWidth, perWidth); + return tablecell::applyPerWidth (this, containerWidth, perWidth); } int SimpleTableCell::applyPerHeight (int containerHeight, core::style::Length perHeight) { - return core::style::multiplyWithPerLength (containerHeight, perHeight); + return tablecell::applyPerHeight (this, containerHeight, perHeight); } } // namespace dw diff --git a/dw/simpletablecell.hh b/dw/simpletablecell.hh index 45a6d31f..f731ec9b 100644 --- a/dw/simpletablecell.hh +++ b/dw/simpletablecell.hh @@ -8,6 +8,9 @@ namespace dw { class SimpleTableCell: public Textblock { protected: + int getAvailWidthOfChild (Widget *child, bool forceValue); + int getAvailHeightOfChild (Widget *child, bool forceValue); + bool getAdjustMinWidth (); public: diff --git a/dw/table.cc b/dw/table.cc index 3959f01a..b1c04018 100644 --- a/dw/table.cc +++ b/dw/table.cc @@ -768,8 +768,16 @@ void Table::forceCalcCellSizes (bool calcHeights) maxWidth += colExtremes->getRef(col)->maxWidth; } - // CSS 'width' defined? - bool totalWidthSpecified = getStyle()->width != core::style::LENGTH_AUTO; + // CSS 'width' defined and effective? + bool totalWidthSpecified = false; + if (getStyle()->width != core::style::LENGTH_AUTO) { + // Even if 'width' is defined, it may not have a defined value. We try + // this trick (should perhaps be replaced by a cleaner solution): + core::Requisition testReq = { -1, -1, -1 }; + correctRequisition (&testReq, core::splitHeightPreserveDescent); + if (testReq.width != -1) + totalWidthSpecified = true; + } DBG_OBJ_MSGF ("resize", 1, "minWidth = %d, minWidthIntrinsic = %d, maxWidth %d, " diff --git a/dw/tablecell.cc b/dw/tablecell.cc new file mode 100644 index 00000000..1c8e0d0d --- /dev/null +++ b/dw/tablecell.cc @@ -0,0 +1,91 @@ +/* + * 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; +} + +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 diff --git a/dw/tablecell.hh b/dw/tablecell.hh new file mode 100644 index 00000000..0b3b324f --- /dev/null +++ b/dw/tablecell.hh @@ -0,0 +1,27 @@ +#ifndef __DW_TABLECELL_HH__ +#define __DW_TABLECELL_HH__ + +#include "core.hh" + +namespace dw { + +namespace tablecell { + +bool getAdjustMinWidth (); +bool isBlockLevel (); + +int correctAvailWidthOfChild (core::Widget *widget, core::Widget *child, + int width, bool forceValue); +int correctAvailHeightOfChild (core::Widget *widget, core::Widget *child, + int height, bool forceValue); + +int applyPerWidth (core::Widget *widget, int containerWidth, + core::style::Length perWidth); +int applyPerHeight (core::Widget *widget, int containerHeight, + core::style::Length perHeight); + +} // namespace dw + +} // namespace dw + +#endif // __DW_TABLECELL_HH__ diff --git a/dw/widget.cc b/dw/widget.cc index 7192008a..5543ed38 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -1284,11 +1284,10 @@ int Widget::getAvailWidthOfChild (Widget *child, bool forceValue) if (child->getStyle()->width == style::LENGTH_AUTO) { DBG_OBJ_MSG ("resize", 1, "no specification"); - int availWidth = getAvailWidth (forceValue); - if (availWidth == -1) - width = -1; + if (forceValue) + width = misc::max (getAvailWidth (true) - boxDiffWidth (), 0); else - width = misc::max (availWidth - boxDiffWidth (), 0); + width = -1; } else { // In most cases, the toplevel widget should be a container, so // the container is non-NULL when the parent is non-NULL. Just @@ -1347,11 +1346,10 @@ int Widget::getAvailHeightOfChild (Widget *child, bool forceValue) if (child->getStyle()->height == style::LENGTH_AUTO) { DBG_OBJ_MSG ("resize", 1, "no specification"); - int availHeight = getAvailHeight (forceValue); - if (availHeight == -1) - height = -1; + if (forceValue) + height = misc::max (getAvailHeight (true) - boxDiffHeight (), 0); else - height = misc::max (availHeight - boxDiffHeight (), 0); + height = -1; } else { // In most cases, the toplevel widget should be a container, so // the container is non-NULL when the parent is non-NULL. Just diff --git a/dw/widget.hh b/dw/widget.hh index d6251f4f..2599d14c 100644 --- a/dw/widget.hh +++ b/dw/widget.hh @@ -464,6 +464,7 @@ public: inline bool isButtonSensitive () { return buttonSensitive; } inline Widget *getParent () { return parent; } + inline Widget *getContainer () { return container; } Widget *getTopLevel (); int getLevel (); int getGeneratorLevel (); |