1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-29 01:42:32 +01:00

added box widget

This commit is contained in:
kojima
2000-11-09 05:01:58 +00:00
parent 366bf50d3c
commit 19160e8dfd
3 changed files with 251 additions and 4 deletions

View File

@@ -115,6 +115,40 @@ testFrame(WMScreen *scr)
}
void
testBox(WMScreen *scr)
{
WMWindow *win;
WMBox *box;
WMButton *btn;
int i;
windowCount++;
win = WMCreateWindow(scr, "testBox");
WMSetWindowTitle(win, "Box");
WMSetWindowCloseAction(win, closeAction, NULL);
WMResizeWidget(win, 400, 300);
box = WMCreateBox(win);
WMMoveWidget(box, 50, 50);
WMResizeWidget(box, 300, 200);
// WMSetBoxHorizontal(box, True);
for (i = 0; i < 4; i++) {
btn = WMCreateCommandButton(box);
WMSetButtonText(btn, "bla");
WMMapWidget(btn);
WMAddBoxSubview(box, WMWidgetView(btn), i&1, True, 20, 0, 5);
}
WMRealizeWidget(win);
WMMapSubwidgets(win);
WMMapWidget(win);
}
static void
singleClick(WMWidget *self, void *data)
{
@@ -1204,9 +1238,12 @@ main(int argc, char **argv)
* Put the testSomething() function you want to test here.
*/
testBox(scr);
#if 0
testList(scr);
#if 0
testProgressIndicator(scr);
testColorWell(scr);
testTextField(scr);
@@ -1217,7 +1254,6 @@ main(int argc, char **argv)
testFontPanel(scr);
testScrollView(scr);
testButton(scr);
testFrame(scr);
@@ -1230,7 +1266,6 @@ main(int argc, char **argv)
testSplitView(scr);
testGradientButtons(scr);
testProgressIndicator(scr);
testOpenFilePanel(scr);

View File

@@ -284,7 +284,8 @@ enum {
WC_ProgressIndicator = 15,
WC_MenuView = 16,
WC_Ruler = 17,
WC_Text = 18
WC_Text = 18,
WC_Box = 19
};
/* All widgets must start with the following structure
@@ -330,6 +331,7 @@ typedef struct W_SplitView WMSplitView;
typedef struct W_TabView WMTabView;
typedef struct W_Ruler WMRuler;
typedef struct W_Text WMText;
typedef struct W_Box WMBox;
/* not widgets */
@@ -1634,6 +1636,18 @@ WMView *WMGetTabViewItemView(WMTabViewItem *item);
void WMDestroyTabViewItem(WMTabViewItem *item);
/* ....................................................................... */
WMBox *WMCreateBox(WMWidget *parent);
void WMSetBoxBorderWidth(WMBox *box, unsigned width);
void WMAddBoxSubview(WMBox *bPtr, WMView *view, Bool expand, Bool fill,
int minSize, int maxSize, int space);
void WMSetBoxHorizontal(WMBox *box, Bool flag);
/* ....................................................................... */
int WMRunAlertPanel(WMScreen *app, WMWindow *owner, char *title, char *msg,

198
WINGs/wbox.c Normal file
View File

@@ -0,0 +1,198 @@
#include "WINGsP.h"
typedef struct {
WMView *view;
int minSize;
int maxSize;
int space;
unsigned expand:1;
unsigned fill:1;
} SubviewItem;
typedef struct W_Box {
W_Class widgetClass;
W_View *view;
SubviewItem *subviews;
int subviewCount;
short borderWidth;
unsigned horizontal:1;
} Box;
#define DEFAULT_WIDTH 40
#define DEFAULT_HEIGHT 40
static void destroyBox(Box *bPtr);
static void handleEvents(XEvent *event, void *data);
static void didResize(struct W_ViewDelegate*, WMView*);
static W_ViewDelegate delegate = {
NULL,
NULL,
didResize,
NULL,
NULL
};
WMBox*
WMCreateBox(WMWidget *parent)
{
Box *bPtr;
bPtr = wmalloc(sizeof(Box));
memset(bPtr, 0, sizeof(Box));
bPtr->widgetClass = WC_Box;
bPtr->view = W_CreateView(W_VIEW(parent));
if (!bPtr->view) {
wfree(bPtr);
return NULL;
}
bPtr->view->self = bPtr;
bPtr->view->delegate = &delegate;
WMCreateEventHandler(bPtr->view, StructureNotifyMask,
handleEvents, bPtr);
WMResizeWidget(bPtr, DEFAULT_WIDTH, DEFAULT_HEIGHT);
bPtr->subviews = NULL;
bPtr->subviewCount = 0;
return bPtr;
}
static void
rearrange(WMBox *box)
{
int i;
int x, y;
int w, h;
int total;
int expands = 0;
x = box->borderWidth;
y = box->borderWidth;
if (box->horizontal) {
h = WMWidgetHeight(box) - 2 * box->borderWidth;
total = WMWidgetWidth(box) - 2 * box->borderWidth;
} else {
w = WMWidgetWidth(box) - 2 * box->borderWidth;
total = WMWidgetHeight(box) - 2 * box->borderWidth;
}
for (i = 0; i < box->subviewCount; i++) {
total -= box->subviews[i].minSize;
total -= box->subviews[i].space;
if (box->subviews[i].expand) {
expands++;
}
}
for (i = 0; i < box->subviewCount; i++) {
if (box->horizontal) {
w = box->subviews[i].minSize;
if (box->subviews[i].expand)
w += total/expands;
} else {
h = box->subviews[i].minSize;
if (box->subviews[i].expand)
h += total/expands;
}
W_ResizeView(box->subviews[i].view, w, h);
W_MoveView(box->subviews[i].view, x, y);
if (box->horizontal) {
x += w + box->subviews[i].space;
} else {
y += h + box->subviews[i].space;
}
}
}
void
WMSetBoxBorderWidth(WMBox *box, unsigned width)
{
box->borderWidth = width;
rearrange(box);
}
void
WMAddBoxSubview(WMBox *bPtr, WMView *view, Bool expand, Bool fill,
int minSize, int maxSize, int space)
{
int i = bPtr->subviewCount;
bPtr->subviewCount++;
if (!bPtr->subviews)
bPtr->subviews = wmalloc(sizeof(SubviewItem));
else
bPtr->subviews = wrealloc(bPtr->subviews,
bPtr->subviewCount*sizeof(SubviewItem));
bPtr->subviews[i].view = view;
bPtr->subviews[i].minSize = minSize;
bPtr->subviews[i].maxSize = maxSize;
bPtr->subviews[i].expand = expand;
bPtr->subviews[i].fill = fill;
bPtr->subviews[i].space = space;
rearrange(bPtr);
}
void
WMSetBoxHorizontal(WMBox *box, Bool flag)
{
box->horizontal = flag;
rearrange(box);
}
static void
destroyBox(Box *bPtr)
{
wfree(bPtr);
}
static void
didResize(struct W_ViewDelegate *delegate, WMView *view)
{
rearrange(view->self);
}
static void
handleEvents(XEvent *event, void *data)
{
Box *bPtr = (Box*)data;
CHECK_CLASS(data, WC_Box);
switch (event->type) {
case DestroyNotify:
destroyBox(bPtr);
break;
case ConfigureNotify:
rearrange(bPtr);
break;
}
}