16 void closeAll(WMWidget
*self
,void *data
)
18 WMDestroyWidget(self
);
19 fprintf(stderr
, "I've been used!\n");
23 static void selectFiles(void *self
, void *data
)
26 oPanel
= WMGetOpenPanel(screen
);
27 if (WMRunModalFilePanelForDirectory(oPanel
, NULL
, "/tmp",
28 "Search..", NULL
) == True
) {
31 snprintf(textbuf
, sizeof(textbuf
), "%s\n-", WMGetFilePanelFileName(oPanel
));
33 WMAppendTextStream(text
, textbuf
);
39 static void handleEvents(XEvent
*event
, void *data
)
41 WMWidget
*widget
= (WMWidget
*) data
;
44 switch (event
->type
) {
46 snprintf(textbuf
, sizeof(textbuf
), "Button down at (%i,%i) \n-",
47 event
->xbutton
.x
, event
->xbutton
.y
);
49 WMAppendTextStream(text
, textbuf
);
55 static void resizeHandler(void *self
, WMNotification
*notif
)
57 WMSize size
= WMGetViewSize(WMWidgetView(win
));
58 WMMoveWidget(box
, size
.width
- ButtonsetSize
.width
, size
.height
- ButtonsetSize
.height
);
59 WMResizeWidget(text
, size
.width
- MARGIN
- 10, size
.height
- 80);
63 int main(int argc
, char **argv
)
65 WMInitializeApplication("FourthWindow", &argc
, argv
);
66 if (!(display
= XOpenDisplay(""))) {
67 fprintf(stderr
, "err: cannot open display");
70 screen
= WMCreateScreen(display
, DefaultScreen(display
));
73 win
= WMCreateWindow(screen
, "");
74 WMResizeWidget(win
, WINWIDTH
, WINHEIGHT
);
75 WMSetWindowCloseAction(win
, closeAll
, NULL
);
77 color
= WMCreateRGBColor(screen
, 124<<9, 206<<8, 162<<8, False
);
78 WMSetWidgetBackgroundColor((WMWidget
*)win
, color
);
80 WMCreateEventHandler(WMWidgetView(win
), ButtonPressMask
, handleEvents
, win
);
81 WMSetViewNotifySizeChanges(WMWidgetView(win
), True
);
82 WMAddNotificationObserver(resizeHandler
, NULL
, WMViewSizeDidChangeNotification
, WMWidgetView(win
));
85 text
= WMCreateText(win
);
86 WMResizeWidget(text
, WINWIDTH
- MARGIN
, WINHEIGHT
- 80);
87 WMMoveWidget(text
, 10, 10);
88 WMSetTextHasVerticalScroller(text
, True
);
89 WMSetTextEditable(text
, False
);
90 WMSetTextIgnoresNewline(text
, False
);
92 /* box with buttons */
93 box
= WMCreateBox(win
);
94 WMSetBoxBorderWidth(box
, MARGIN
);
95 WMSetWidgetBackgroundColor((WMWidget
*)box
, color
);
96 WMSetBoxHorizontal(box
, True
);
98 Button
= WMCreateButton(box
, WBTMomentaryPush
);
99 WMSetWidgetBackgroundColor((WMWidget
*)Button
, color
);
100 WMSetButtonText(Button
, "Files");
101 WMSetButtonAction(Button
, selectFiles
, NULL
);
103 ButtonsetSize
= WMGetViewSize(WMWidgetView(Button
));
105 WMAddBoxSubview(box
, WMWidgetView(Button
), True
, False
, 60, 1000, MARGIN
);
107 Button
= WMCreateButton(box
, WBTMomentaryPush
);
108 WMSetWidgetBackgroundColor((WMWidget
*)Button
, color
);
109 WMSetButtonText(Button
, "Quit");
110 WMSetButtonAction(Button
, closeAll
, NULL
);
113 WMAddBoxSubview(box
, WMWidgetView(Button
), True
, False
, 60, 1000, 0);
114 WMResizeWidget(box
, 4 * MARGIN
+ 2 * ButtonsetSize
.width
,
115 2 * MARGIN
+ ButtonsetSize
.height
);
116 ButtonsetSize
= WMGetViewSize(WMWidgetView(box
));
117 resizeHandler(NULL
, NULL
);
118 /* end of box and buttons setup */
122 WMMapSubwidgets(win
);
123 WMRealizeWidget(win
);
125 WMScreenMainLoop(screen
);