diff options
-rw-r--r-- | dw/core.hh | 1 | ||||
-rw-r--r-- | dw/textblock.hh | 1 | ||||
-rw-r--r-- | dw/tools.cc | 54 | ||||
-rw-r--r-- | dw/tools.hh | 10 | ||||
-rw-r--r-- | dw/widget.cc | 21 | ||||
-rw-r--r-- | dw/widget.hh | 1 |
6 files changed, 83 insertions, 5 deletions
@@ -45,6 +45,7 @@ class ResourceFactory; #include "../lout/container.hh" #include "../lout/signal.hh" +#include "tools.hh" #include "types.hh" #include "events.hh" #include "imgbuf.hh" diff --git a/dw/textblock.hh b/dw/textblock.hh index 69e3ef89..439942de 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -4,7 +4,6 @@ #include <limits.h> #include "regardingborder.hh" -#include "tools.hh" #include "../lout/misc.hh" // These were used when improved line breaking and hyphenation were implemented. diff --git a/dw/tools.cc b/dw/tools.cc index a2d05367..60e5e029 100644 --- a/dw/tools.cc +++ b/dw/tools.cc @@ -1,14 +1,32 @@ -#include "tools.hh" +#include "core.hh" namespace dw { namespace core { +using namespace lout::misc; + SizeParams::SizeParams () { DBG_OBJ_CREATE ("dw::core::SizeParams"); init (); debugPrint (); } + +SizeParams::SizeParams (int numPos, Widget **references, int *x, int *y) +{ + DBG_OBJ_CREATE ("dw::core::SizeParams"); + init (); + fill (numPos, references, x, y); + debugPrint (); +} + +SizeParams::SizeParams (SizeParams &other) +{ + DBG_OBJ_CREATE ("dw::core::SizeParams"); + init (); + fill (other.numPos, other.references, other.x, other.y); + debugPrint (); +} SizeParams::~SizeParams () { @@ -127,7 +145,39 @@ bool SizeParams::findReference (Widget *reference, int *x, int *y) return found; } - +/** + * Compares two instances, but considers a change in the order of the reference + * widgets as equivalent. + */ +bool SizeParams::isEquivalent (SizeParams *other) +{ + DBG_OBJ_ENTER ("resize", 0, "isEquivalent", "%p", other); + bool result; + + if (numPos != other->numPos) + result = false; + else { + result = true; + + for (int i = 0; result && i < numPos; i++) { + bool otherFound = false; + for (int j = 0; !otherFound && j < numPos; j++) { + if (references[i] == other->references[j]) { + otherFound = true; + if (!(x[i] == other->x[j] && y[i] == other->y[j])) + result = false; + } + } + + if (!otherFound) + result = false; + } + } + + DBG_OBJ_LEAVE_VAL ("%s", boolToStr (result)); + return result; +} + } // namespace core } // namespace dw diff --git a/dw/tools.hh b/dw/tools.hh index 973881af..60435c5a 100644 --- a/dw/tools.hh +++ b/dw/tools.hh @@ -1,6 +1,10 @@ #ifndef __DW_TOOLS_HH__ #define __DW_TOOLS_HH__ +#ifndef __INCLUDED_FROM_DW_CORE_HH__ +# error Do not include this file directly, use "core.hh" instead. +#endif + #include "core.hh" #include "../lout/debug.hh" @@ -34,13 +38,17 @@ private: public: SizeParams (); + SizeParams (int numPos, Widget **references, int *x, int *y); + SizeParams (SizeParams &other); ~SizeParams (); void fill (int numPos, Widget **references, int *x, int *y); void forChild (Widget *parent, Widget *child, int xRel, int yRel, SizeParams *childParams); bool findReference (Widget *reference, int *x, int *y); - + + bool isEquivalent (SizeParams *other); + inline int getNumPos () { return numPos; } inline Widget **getReferences () { return references; } inline int *getX () { return x; } diff --git a/dw/widget.cc b/dw/widget.cc index d63d1edc..a87072f0 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -68,6 +68,8 @@ Widget::Widget () DBG_OBJ_CREATE ("dw::core::Widget"); registerName ("dw::core::Widget", &CLASS_ID); + DBG_OBJ_ASSOC_CHILD (&requisitionParams); + flags = (Flags)(NEEDS_RESIZE | EXTREMES_CHANGED); parent = quasiParent = generator = container = NULL; DBG_OBJ_SET_PTR ("container", container); @@ -585,7 +587,24 @@ void Widget::sizeRequest (Requisition *requisition, int numPos, // Layout::resizeIdle. } - if (needsResize ()) { + bool callImpl; + if (needsResize ()) + callImpl = true; + else { + // Even if RESIZE_QUEUED / NEEDS_RESIZE is not set, calling + // sizeRequestImpl is necessary when the relavive positions passed here + // have changed. + SizeParams newParams (numPos, references, x, y); + DBG_OBJ_ASSOC_CHILD (&newParams); + if (newParams.isEquivalent (&requisitionParams)) + callImpl = false; + else { + callImpl = true; + requisitionParams = newParams; + } + } + + if (callImpl) { calcExtraSpace (true); /** \todo Check requisition == &(this->requisition) and do what? */ sizeRequestImpl (requisition, numPos, references, x, y); diff --git a/dw/widget.hh b/dw/widget.hh index d21b2697..06c19e28 100644 --- a/dw/widget.hh +++ b/dw/widget.hh @@ -136,6 +136,7 @@ private: * Do not read this directly, but call size_request(). */ Requisition requisition; + SizeParams requisitionParams; /** * \brief Analogue to dw::core::Widget::requisition. |