16 typedef struct W_Box
{
20 SubviewItem
*subviews
;
25 unsigned horizontal
:1;
29 #define DEFAULT_WIDTH 40
30 #define DEFAULT_HEIGHT 40
33 static void destroyBox(Box
*bPtr
);
35 static void handleEvents(XEvent
*event
, void *data
);
37 static void didResize(struct W_ViewDelegate
*, WMView
*);
39 static W_ViewDelegate delegate
= {
50 WMCreateBox(WMWidget
*parent
)
54 bPtr
= wmalloc(sizeof(Box
));
55 memset(bPtr
, 0, sizeof(Box
));
57 bPtr
->widgetClass
= WC_Box
;
59 bPtr
->view
= W_CreateView(W_VIEW(parent
));
64 bPtr
->view
->self
= bPtr
;
66 bPtr
->view
->delegate
= &delegate
;
68 WMCreateEventHandler(bPtr
->view
, StructureNotifyMask
,
71 WMResizeWidget(bPtr
, DEFAULT_WIDTH
, DEFAULT_HEIGHT
);
73 bPtr
->subviews
= NULL
;
74 bPtr
->subviewCount
= 0;
91 if (box
->horizontal
) {
92 h
= WMWidgetHeight(box
) - 2 * box
->borderWidth
;
93 total
= WMWidgetWidth(box
) - 2 * box
->borderWidth
;
95 w
= WMWidgetWidth(box
) - 2 * box
->borderWidth
;
96 total
= WMWidgetHeight(box
) - 2 * box
->borderWidth
;
99 if (w
<= 0 || h
<= 0 || total
<= 0) {
103 for (i
= 0; i
< box
->subviewCount
; i
++) {
104 total
-= box
->subviews
[i
].minSize
;
105 total
-= box
->subviews
[i
].space
;
106 if (box
->subviews
[i
].expand
) {
111 for (i
= 0; i
< box
->subviewCount
; i
++) {
112 if (box
->horizontal
) {
113 w
= box
->subviews
[i
].minSize
;
114 if (box
->subviews
[i
].expand
)
117 h
= box
->subviews
[i
].minSize
;
118 if (box
->subviews
[i
].expand
)
121 W_MoveView(box
->subviews
[i
].view
, x
, y
);
122 W_ResizeView(box
->subviews
[i
].view
, w
, h
);
123 if (box
->horizontal
) {
124 x
+= w
+ box
->subviews
[i
].space
;
126 y
+= h
+ box
->subviews
[i
].space
;
133 WMSetBoxBorderWidth(WMBox
*box
, unsigned width
)
135 box
->borderWidth
= width
;
142 WMAddBoxSubview(WMBox
*bPtr
, WMView
*view
, Bool expand
, Bool fill
,
143 int minSize
, int maxSize
, int space
)
145 int i
= bPtr
->subviewCount
;
147 bPtr
->subviewCount
++;
149 bPtr
->subviews
= wmalloc(sizeof(SubviewItem
));
151 bPtr
->subviews
= wrealloc(bPtr
->subviews
,
152 bPtr
->subviewCount
*sizeof(SubviewItem
));
153 bPtr
->subviews
[i
].view
= view
;
154 bPtr
->subviews
[i
].minSize
= minSize
;
155 bPtr
->subviews
[i
].maxSize
= maxSize
;
156 bPtr
->subviews
[i
].expand
= expand
;
157 bPtr
->subviews
[i
].fill
= fill
;
158 bPtr
->subviews
[i
].space
= space
;
165 WMSetBoxHorizontal(WMBox
*box
, Bool flag
)
167 box
->horizontal
= flag
;
173 destroyBox(Box
*bPtr
)
180 didResize(struct W_ViewDelegate
*delegate
, WMView
*view
)
182 rearrange(view
->self
);
186 handleEvents(XEvent
*event
, void *data
)
188 Box
*bPtr
= (Box
*)data
;
190 CHECK_CLASS(data
, WC_Box
);
192 switch (event
->type
) {
197 case ConfigureNotify
: