18 void closeAll(WMWidget
*self
,void *data
){
19 WMDestroyWidget(self
);
20 fprintf(stderr
,"I've been used!\n");
24 static void selectFiles(void *self
, void *data
){
26 oPanel
= WMGetOpenPanel(screen
);
27 if (WMRunModalFilePanelForDirectory(oPanel
, NULL
, "/tmp",
28 "Search..", NULL
) == True
){
29 snprintf(textbuf
,39,"%s\n-", WMGetFilePanelFileName(oPanel
));
31 WMAppendTextStream(text
,textbuf
);
37 static void handleEvents(XEvent
*event
, void *data
){
38 WMWidget
*widget
= (WMWidget
*)data
;
39 switch (event
->type
) {
41 snprintf(textbuf
,39,"Button down at (%i,%i) \n-",event
->xbutton
.x
,event
->xbutton
.y
);
43 WMAppendTextStream(text
,textbuf
);
49 static void resizeHandler(void *self
, WMNotification
*notif
){
50 WMSize size
= WMGetViewSize(WMWidgetView(win
));
51 WMMoveWidget(box
, size
.width
-ButtonsetSize
.width
, size
.height
-ButtonsetSize
.height
);
52 WMResizeWidget(text
, size
.width
-MARGIN
-10, size
.height
-80);
56 int main (int argc
, char **argv
){
58 WMInitializeApplication("FourthWindow", &argc
, argv
);
59 if (!(display
= XOpenDisplay(""))){
60 fprintf(stderr
,"err: cannot open display");
63 screen
= WMCreateScreen(display
, DefaultScreen(display
));
66 win
= WMCreateWindow(screen
, "");
67 WMResizeWidget(win
, WINWIDTH
, WINHEIGHT
);
68 WMSetWindowCloseAction(win
, closeAll
, NULL
);
70 color
= WMCreateRGBColor(screen
, 124<<9,206<<8,162<<8, False
);
71 WMSetWidgetBackgroundColor((WMWidget
*)win
, color
);
73 WMCreateEventHandler(WMWidgetView(win
), ButtonPressMask
,handleEvents
, win
);
74 WMSetViewNotifySizeChanges(WMWidgetView(win
), True
);
75 WMAddNotificationObserver(resizeHandler
, NULL
, WMViewSizeDidChangeNotification
, WMWidgetView(win
));
79 text
= WMCreateText(win
);
80 WMResizeWidget(text
, WINWIDTH
-MARGIN
, WINHEIGHT
-80);
81 WMMoveWidget(text
, 10, 10);
82 WMSetTextHasVerticalScroller(text
, True
);
83 WMSetTextEditable(text
, False
);
84 WMSetTextIgnoresNewline(text
, False
);
86 /* box with buttons */
88 WMSetBoxBorderWidth(box
, MARGIN
);
89 WMSetWidgetBackgroundColor((WMWidget
*)box
, color
);
90 WMSetBoxHorizontal(box
, True
);
93 Button
=WMCreateButton(box
,WBTMomentaryPush
);
94 WMSetWidgetBackgroundColor((WMWidget
*)Button
, color
);
95 WMSetButtonText (Button
, "Files");
96 WMSetButtonAction (Button
, selectFiles
, NULL
);
98 ButtonsetSize
= WMGetViewSize(WMWidgetView(Button
));
100 WMAddBoxSubview(box
, WMWidgetView(Button
), True
, False
, 60, 1000, MARGIN
);
102 Button
=WMCreateButton(box
,WBTMomentaryPush
);
103 WMSetWidgetBackgroundColor((WMWidget
*)Button
, color
);
104 WMSetButtonText (Button
, "Quit");
105 WMSetButtonAction (Button
, closeAll
, NULL
);
108 WMAddBoxSubview(box
, WMWidgetView(Button
), True
,False
, 60, 1000, 0);
109 WMResizeWidget(box
, 4*MARGIN
+2*ButtonsetSize
.width
,2*MARGIN
+ButtonsetSize
.height
);
110 ButtonsetSize
=WMGetViewSize(WMWidgetView(box
));
111 resizeHandler(NULL
,NULL
);
112 /* end of box and buttons setup */
116 WMMapSubwidgets(win
);
117 WMRealizeWidget(win
);
119 WMScreenMainLoop(screen
);