Laxkit  0.0.7.1
boxarrange.h
1 //
2 //
3 // The Laxkit, a windowing toolkit
4 // Please consult http://laxkit.sourceforge.net about where to send any
5 // correspondence about this software.
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //
21 // Copyright (C) 2004-2010 by Tom Lechner
22 //
23 #ifndef _LAX_BOXARRANGE_H
24 #define _LAX_BOXARRANGE_H
25 
26 
27 #ifndef NULL
28 #define NULL 0
29 #endif
30 
31 //#define LAX_LISTS_H_ONLY
32 #include <lax/lists.h>
33 //#undef LAX_LISTS_H_ONLY
34 
35 
36 #define BOX_SHOULD_WRAP 100000
37 #define BOX_NO_BREAK 1000000
38 #define BOX_MUST_BREAK -1000000
39 
40  // For laying out, for instance LRTB == Left to Right, Top to Bottom
41  // Note that only LRTB and TBLR are implemented in ArrangeRowCol().
42  // These correspond to LAX_LRTB, etc. note that they take up
43  // only the leftmost 3 bits of flags.
44 #define BOX_LRTB (0)
45 #define BOX_LRBT (1)
46 #define BOX_RLTB (2)
47 #define BOX_RLBT (3)
48 #define BOX_TBLR (4)
49 #define BOX_TBRL (5)
50 #define BOX_BTLR (6)
51 #define BOX_BTRL (7)
52 #define BOX_FLOW_MASK (0x7)
53 
54 #define BOX_HORIZONTAL (1<<3)
55 #define BOX_VERTICAL (1<<4)
56 #define BOX_WRAP_TO_X_EXTENT (1<<5)
57 #define BOX_WRAP_TO_Y_EXTENT (1<<6)
58 #define BOX_WRAP_TO_EXTENT (3<<5)
59 
60  // if laying out x, make y,h value sync with target->h
61 #define BOX_SET_Y_TOO (1<<7)
62  // if laying out y, make x,w value sync with target->w
63 #define BOX_SET_X_TOO (1<<8)
64 #define BOX_SET_METRICS (1<<7|1<<8)
65 
66  // |11223344| <-- with any of the left/center/right/justify, always acts as justify
67 #define BOX_STRETCH_TO_FILL_X (1<<9)
68 #define BOX_STRETCH_TO_FILL_Y (1<<10)
69 #define BOX_STRETCH_MASK (1<<9|1<<10)
70 
71  // Space with left/right/center/justify
72  // |1 2 3 4 |
73  // | 1 2 3 4 |
74  // | 1 2 3 4|
75  // |1 2 3 4|
76 #define BOX_SPACE_TO_FILL_X (1<<11)
77 #define BOX_SPACE_TO_FILL_Y (1<<12)
78 #define BOX_SPACE_JUSTIFY (1<<13)
79 #define BOX_SPACE_MASK (1<<11|1<<12|1<<13)
80 
81  // overall alignment of the laid out boxes
82  // |1 2 3 4 |
83  // | 1 2 3 4 |
84  // | 1 2 3 4|
85 #define BOX_ALIGN_MASK (63<<14)
86 #define BOX_HALIGN_SHIFT 14
87 #define BOX_HALIGN_MASK (7<<14)
88 #define BOX_LEFT (1<<14)
89 #define BOX_HCENTER (1<<15)
90 #define BOX_RIGHT (1<<16)
91 
92 #define BOX_VALIGN_SHIFT 17
93 #define BOX_VALIGN_MASK (7<<17)
94 #define BOX_TOP (1<<17)
95 #define BOX_VCENTER (1<<18)
96 #define BOX_BOTTOM (1<<19)
97 #define BOX_CENTER (1<<15|1<<18)
98 
99 #define BOX_STRETCH_IN_ROW (1<<20)
100 #define BOX_STRETCH_IN_COL (1<<21)
101 
102  // Windows (rather than boxes) set positions according to their own origin,
103  // so don't add on the x and y positions.
104 #define BOX_DONT_PROPAGATE_POS (1<<22)
105 
106  //whether to use this box in calculations or not
107 #define BOX_HIDDEN (1<<23)
108 
109 
110 namespace Laxkit {
111 
112 
113 
114 //----------------------------- SquishyBox -------------------------------
115 
117 {
118  public:
119  int m[14]; // metrics: x,w,pw,ws,wg,halign,hgap, y,h,ph,hs,hg,valign,vgap
120  int pad; // the bevel would go around this box, and should be added to the width in width calculations.
121  int padinset; // additional pad inside a box. "pad" is outside the box
122  int fpen,lpen; //flow penalty, line penalty
123  unsigned long flags; // LAX_LRTB, BOX_CENTER, for instance <-- these refer to arrangement of children
124  SquishyBox();
125  SquishyBox(unsigned int nflags,
126  int nx,int nw,int npw,int nws,int nwg,int nhalign,int nhgap,
127  int ny,int nh,int nph,int nhs,int nhg,int nvalign,int nvgap);
128  virtual ~SquishyBox() {}
129 
130  virtual int hideBox(int yeshide);
131  virtual int hidden();
132 
133  virtual int WrapToExtent();
134  virtual void sync(int xx,int yy,int ww,int hh);
135  virtual void sync();
136 
137  //sizing functions
138  virtual int x() { return m[0]; }
139  virtual int w() { return m[1]; }
140  virtual int pw() { return m[2]; }
141  virtual int ws() { return m[3]; }
142  virtual int wg() { return m[4]; }
143  virtual int halign() { return m[5]; }
144  virtual int hgap() { return m[6]; }
145 
146  virtual int y() { return m[7]; }
147  virtual int h() { return m[8]; }
148  virtual int ph() { return m[9]; }
149  virtual int hs() { return m[10]; }
150  virtual int hg() { return m[11]; }
151  virtual int valign() { return m[12]; }
152  virtual int vgap() { return m[13]; }
153 
154  virtual int x(int val) { return m[0]=val; }
155  virtual int w(int val) { return m[1]=val; }
156  virtual int pw(int val) { return m[2]=val; }
157  virtual int ws(int val) { return m[3]=val; }
158  virtual int wg(int val) { return m[4]=val; }
159  virtual int halign(int val) { return m[5]=val; }
160  virtual int hgap(int val) { return m[6]=val; }
161 
162  virtual int y(int val) { return m[7]=val; }
163  virtual int h(int val) { return m[8]=val; }
164  virtual int ph(int val) { return m[9]=val; }
165  virtual int hs(int val) { return m[10]=val; }
166  virtual int hg(int val) { return m[11]=val; }
167  virtual int valign(int val) { return m[12]=val; }
168  virtual int vgap(int val) { return m[13]=val; }
169 
170  virtual int fpenalty() { return fpen; } //0=nothing, <0 force break, >0 never break
171  virtual int fpenalty(int val) { return fpen=val; }
172  virtual int lpenalty() { return lpen; }
173  virtual int lpenalty(int val) { return lpen=val; }
174 };
175 
176 //----------------------------- ListBox ------------------------------
177 class ListBox : public SquishyBox
178 {
179  public:
181 
182  ListBox(unsigned int flag=0);//BOX_VERTICAL or BOX_HORIZONTAL
183  ListBox(unsigned int nflags,
184  int nx,int nw,int npw,int nws,int nwg,int nhalign,int nhgap,
185  int ny,int nh,int nph,int nhs,int nhg,int nvalign,int nvgap);
186 
187  //list management functions
188  virtual void Push(SquishyBox *box,char islocal=0,int where=-1);
189  virtual int Pop(int which=-1);
190  virtual void Flush();
191 
192  //syncing and distributing
193  virtual int WrapToExtent();
194  virtual void sync();
195  virtual int arrangeBoxes(int distributetoo=0);
196  virtual int distributeBoxes(int setmetrics=0);
197  virtual int figureDimensions(ListBox *target,int *nextrow=NULL,SquishyBox **boxes=NULL, int n=0,
198  double *squishx=NULL,double *squishy=NULL);
199 };
200 
201 //----------------------------- RowColBox ------------------------------
202 
203 class RowColBox : public ListBox
204 {
205  protected:
206  PtrStack<SquishyBox> wholelist; // the master list of boxes
207  int arrangedstate;
208  virtual ListBox *newSubBox();
209  virtual void filterflags();
210  public:
211  unsigned int elementflags;
212  RowColBox();
213  RowColBox(unsigned int nflags,
214  int nx,int nw,int npw,int nws,int nwg,int nhalign,int nhgap,
215  int ny,int nh,int nph,int nhs,int nhg,int nvalign,int nvgap);
216  virtual void Push(SquishyBox *box,char islocal=0,int where=-1);
217  virtual int Pop(int which=-1);
218  virtual void Flush();
219 
220 // virtual int figureDimensions(); // finds and sets the pw,s,g, ph,s,g based on the children
221  virtual int arrangeBoxes(int distributetoo=0);
222  virtual int distributeBoxes(int setmetrics=0);
223 };
224 
225 
226 
227 //-------------------------------------- tables ------------------------
228 
229 class TableData
230 {
231  public:
232  int i,j,rowspan,colspan;
233  SquishyBox *box;
234 };
235 
236 class TableBox : public SquishyBox
237 {
238  public:
239  int i,j; // row i, column j == coordinates of upper left corner
240  int rowspan,colspan;
241  //int cellpadding; <-- use SquishyBox::pad
242 };
243 
244 } // namespace Laxkit
245 
246 #endif
247 

Mon Feb 17 2014 11:52:56, Laxkit