aboutsummaryrefslogtreecommitdiff
path: root/dw/tools.cc
blob: a2d0536756c94b644cf8b829e694906c3779431e (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
122
123
124
125
126
127
128
129
130
131
132
133
#include "tools.hh"

namespace dw {
namespace core {

SizeParams::SizeParams ()
{
   DBG_OBJ_CREATE ("dw::core::SizeParams");
   init ();
   debugPrint ();
}
   
SizeParams::~SizeParams ()
{
   cleanup ();
   DBG_OBJ_DELETE ();
}

void SizeParams::init ()
{
   numPos = 0;
   references = NULL;
   x = y = NULL;
}

void SizeParams::cleanup ()
{
   if (references)
      delete[] references;
   if (x)
      delete[] x;
   if (y)
      delete[] y;

   init ();
}

void SizeParams::fill (int numPos, Widget **references, int *x, int *y)
{
   DBG_OBJ_ENTER ("resize", 0, "fill", "%d, ...", numPos);

   cleanup ();
   
   this->numPos = numPos;

   this->references = new Widget*[numPos];
   this->x = new int[numPos];
   this->y = new int[numPos];
   
   for (int i = 0; i < numPos; i++) {
      this->references[i] = references[i];
      this->x[i] = x[i];
      this->y[i] = y[i];
   }

   debugPrint ();

   DBG_OBJ_LEAVE ();
}

void SizeParams::forChild (Widget *parent, Widget *child, int xRel, int yRel,
                           SizeParams *childParams)
{
   DBG_OBJ_ENTER ("resize", 0, "forChild", "%p, %p, %d, %d, %p",
                  parent, child, xRel, yRel, childParams);
   
   int numChildReferences = child->numSizeRequestReferences ();

   childParams->numPos = 0;
   childParams->references = new Widget*[numChildReferences];
   childParams->x = new int[numChildReferences];
   childParams->y = new int[numChildReferences];

   for (int i = 0; i < numChildReferences; i++) {
      Widget *childReference = child->sizeRequestReference (i);
      
      if (childReference == parent) {
         childParams->references[childParams->numPos] = childReference;
         childParams->x[childParams->numPos] = xRel;
         childParams->y[childParams->numPos] = yRel;
         childParams->numPos++;
      } else {
         bool found = false;
         for (int j = 0; !found && j < numPos; j++) {
            if (childReference == references[j]) {
               found = true;
               childParams->references[childParams->numPos] = childReference;
               childParams->x[childParams->numPos] = x[j] + xRel;
               childParams->y[childParams->numPos] = y[j] + yRel;
               childParams->numPos++;
            } 
         }
      }
   }

   childParams->debugPrint ();

   DBG_OBJ_LEAVE ();
}

bool SizeParams::findReference (Widget *reference, int *x, int *y)
{
   DBG_OBJ_ENTER ("resize", 0, "findReference", "%p", reference);

   bool found = false;
   for (int i = 0; i < numPos && !found; i++) {
      if (reference == references[i]) {
         if (x)
            *x = this->x[i];
         if (y)
            *y = this->y[i];
         found = true;
      }
   }

   if (found) {
      if (x && y)
         DBG_OBJ_LEAVE_VAL ("true, x = %d, y = %d", *x, *y);
      else if (x)
         DBG_OBJ_LEAVE_VAL ("true, x = %d", *x);
      else if (y)
         DBG_OBJ_LEAVE_VAL ("true, y = %d", *y);
      else
         DBG_OBJ_LEAVE_VAL ("%s", "true");
   } else
      DBG_OBJ_LEAVE_VAL ("%s", "false");

   return found;
}
  

} // namespace core
} // namespace dw