summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2016-01-01 14:54:31 +0100
committerSebastian Geerken <devnull@localhost>2016-01-01 14:54:31 +0100
commitbf6aeb8e54aac0b5aec39de544ec41f3a59daddf (patch)
treec07ab632acc86a71bed08fe3d29b088a33277e2b
parent21b11e2ef463d13f5ce1002a5ba2575c2cac3606 (diff)
SRDOP: Consider references and positions in Widget::sizeRequest.
-rw-r--r--dw/core.hh1
-rw-r--r--dw/textblock.hh1
-rw-r--r--dw/tools.cc54
-rw-r--r--dw/tools.hh10
-rw-r--r--dw/widget.cc21
-rw-r--r--dw/widget.hh1
6 files changed, 83 insertions, 5 deletions
diff --git a/dw/core.hh b/dw/core.hh
index fcf8ef4b..286243fa 100644
--- a/dw/core.hh
+++ b/dw/core.hh
@@ -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.