aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2014-06-17 14:55:33 +0200
committerSebastian Geerken <devnull@localhost>2014-06-17 14:55:33 +0200
commit3d0f00b5c50b1d1bc55ccf051a957e753ac51ed6 (patch)
tree528730a4ddfcebb707baf7b0d30a1bc18a84cd04
parent3f0b24b7ea91a60e52c9f426f146dd0dcbed6e75 (diff)
Mostly finished work on Widget::containerSizeChanged().
-rw-r--r--dw/ruler.cc5
-rw-r--r--dw/ruler.hh1
-rw-r--r--dw/table.cc5
-rw-r--r--dw/table.hh1
-rw-r--r--dw/textblock.cc5
-rw-r--r--dw/textblock.hh1
-rw-r--r--dw/widget.cc92
-rw-r--r--dw/widget.hh6
8 files changed, 110 insertions, 6 deletions
diff --git a/dw/ruler.cc b/dw/ruler.cc
index 5525f21b..3d3bc0b8 100644
--- a/dw/ruler.cc
+++ b/dw/ruler.cc
@@ -51,6 +51,11 @@ bool Ruler::isBlockLevel ()
return true;
}
+bool Ruler::usesAvailWidth ()
+{
+ return true;
+}
+
void Ruler::draw (core::View *view, core::Rectangle *area)
{
drawWidgetBox (view, area, false);
diff --git a/dw/ruler.hh b/dw/ruler.hh
index eea1f952..1f2e80b0 100644
--- a/dw/ruler.hh
+++ b/dw/ruler.hh
@@ -18,6 +18,7 @@ class Ruler: public core::Widget
protected:
void sizeRequestImpl (core::Requisition *requisition);
void getExtremesImpl (core::Extremes *extremes);
+ bool usesAvailWidth ();
void draw (core::View *view, core::Rectangle *area);
public:
diff --git a/dw/table.cc b/dw/table.cc
index 6c9fa19e..c968627d 100644
--- a/dw/table.cc
+++ b/dw/table.cc
@@ -255,6 +255,11 @@ int Table::getAvailWidthOfChild (Widget *child, bool forceValue)
return width;
}
+bool Table::usesAvailWidth ()
+{
+ return true;
+}
+
bool Table::isBlockLevel ()
{
return true;
diff --git a/dw/table.hh b/dw/table.hh
index 847327c9..03eb410d 100644
--- a/dw/table.hh
+++ b/dw/table.hh
@@ -427,6 +427,7 @@ protected:
void resizeDrawImpl ();
int getAvailWidthOfChild (Widget *child, bool forceValue);
+ bool usesAvailWidth ();
bool isBlockLevel ();
diff --git a/dw/textblock.cc b/dw/textblock.cc
index ea8af331..4601a5c4 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -607,6 +607,11 @@ void Textblock::sizeAllocateImpl (core::Allocation *allocation)
}
}
+bool Textblock::usesAvailWidth ()
+{
+ return true;
+}
+
void Textblock::resizeDrawImpl ()
{
DBG_OBJ_MSG ("draw", 0, "<b>resizeDrawImpl</b> ()");
diff --git a/dw/textblock.hh b/dw/textblock.hh
index bb2e6ddd..8f38ccc2 100644
--- a/dw/textblock.hh
+++ b/dw/textblock.hh
@@ -747,6 +747,7 @@ protected:
void sizeRequestImpl (core::Requisition *requisition);
void getExtremesImpl (core::Extremes *extremes);
void sizeAllocateImpl (core::Allocation *allocation);
+ bool usesAvailWidth ();
void resizeDrawImpl ();
void markSizeChange (int ref);
diff --git a/dw/widget.cc b/dw/widget.cc
index c649be55..40f690d1 100644
--- a/dw/widget.cc
+++ b/dw/widget.cc
@@ -286,11 +286,6 @@ void Widget::actualQueueResize (int ref, bool extremesChanged, bool fast)
DBG_OBJ_MSG_END ();
}
-bool Widget::affectedByContainerSizeChange ()
-{
- return true;
-}
-
void Widget::containerSizeChanged ()
{
DBG_OBJ_MSG ("resize", 0, "<b>containerSizeChanged</b> ()");
@@ -317,6 +312,75 @@ void Widget::containerSizeChanged ()
DBG_OBJ_MSG_END ();
}
+bool Widget::affectedByContainerSizeChange ()
+{
+ DBG_OBJ_MSG ("resize", 0, "<b>affectedByContainerSizeChange</b> ()");
+ DBG_OBJ_MSG_START ();
+
+ bool ret;
+
+ // This standard implementation is suitable for all widgets which
+ // call correctRequisition() and correctExtremes(), even in the way
+ // how Textblock and Image do (see comments there). Has to be kept
+ // in sync.
+
+ if (container == NULL) {
+ if (style::isAbsLength (getStyle()->width) &&
+ style::isAbsLength (getStyle()->height))
+ // Both absolute, i. e. fixed: no dependency.
+ ret = false;
+ else if (style::isPerLength (getStyle()->width) ||
+ style::isPerLength (getStyle()->height)) {
+ // Any percentage: certainly dependenant.
+ ret = true;
+ } else
+ // One or both is "auto": depends ...
+ ret =
+ (getStyle()->width == style::LENGTH_AUTO ?
+ usesAvailWidth () : false) ||
+ (getStyle()->height == style::LENGTH_AUTO ?
+ usesAvailHeight () : false);
+ } else
+ ret = this->affectsSizeChangeContainerChild (this);
+
+ DBG_OBJ_MSGF ("resize", 1, "=> %s", ret ? "true" : "false");
+ DBG_OBJ_MSG_END ();
+ return ret;
+}
+
+bool Widget::affectsSizeChangeContainerChild (Widget *child)
+{
+ DBG_OBJ_MSGF ("resize", 0, "<b>affectsSizeChangeContainerChild</b> (%p)",
+ child);
+ DBG_OBJ_MSG_START ();
+
+ bool ret;
+
+ // From the point of view of the container. This standard
+ // implementation should be suitable for most (if not all)
+ // containers.
+
+ if (style::isAbsLength (child->getStyle()->width) &&
+ style::isAbsLength (child->getStyle()->height))
+ // Both absolute, i. e. fixed: no dependency.
+ ret = false;
+ else if (style::isPerLength (child->getStyle()->width) ||
+ style::isPerLength (child->getStyle()->height)) {
+ // Any percentage: certainly dependenant.
+ ret = true;
+ } else
+ // One or both is "auto": depends ...
+ ret =
+ (child->getStyle()->width == style::LENGTH_AUTO ?
+ child->usesAvailWidth () : false) ||
+ (child->getStyle()->height == style::LENGTH_AUTO ?
+ child->usesAvailHeight () : false);
+
+ DBG_OBJ_MSGF ("resize", 1, "=> %s", ret ? "true" : "false");
+ DBG_OBJ_MSG_END ();
+ return ret;
+}
+
void Widget::containerSizeChangedForChildren ()
{
DBG_OBJ_MSG ("resize", 0, "<b>containerSizeChangedForChildren</b> ()");
@@ -334,6 +398,24 @@ void Widget::containerSizeChangedForChildren ()
}
/**
+ * \brief Must be implemengted by a method returning true, when
+ * getAvailWidth() is called.
+ */
+bool Widget::usesAvailWidth ()
+{
+ return false;
+}
+
+/**
+ * \brief Must be implemengted by a method returning true, when
+ * getAvailHeight() is called.
+ */
+bool Widget::usesAvailHeight ()
+{
+ return false;
+}
+
+/**
* \brief This method is a wrapper for Widget::sizeRequestImpl(); it calls
* the latter only when needed.
*/
diff --git a/dw/widget.hh b/dw/widget.hh
index 25a951d4..2e51e32c 100644
--- a/dw/widget.hh
+++ b/dw/widget.hh
@@ -171,7 +171,6 @@ private:
{ queueResize (ref, extremesChanged, true); }
void actualQueueResize (int ref, bool extremesChanged, bool fast);
- bool affectedByContainerSizeChange ();
void containerSizeChanged ();
public:
@@ -329,6 +328,11 @@ protected:
virtual void containerSizeChangedForChildren ();
+ virtual bool affectedByContainerSizeChange ();
+ virtual bool affectsSizeChangeContainerChild (Widget *child);
+ virtual bool usesAvailWidth ();
+ virtual bool usesAvailHeight ();
+
virtual void notifySetAsTopLevel();
virtual void notifySetParent();