13 WMFrame
*controlframe
;
17 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
){
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(controlframe
, 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
){
60 WMInitializeApplication("FifthWindow", &argc
, argv
);
61 if (!(display
= XOpenDisplay(""))){
62 fprintf(stderr
,"err: cannot open display");
65 screen
= WMCreateScreen(display
, DefaultScreen(display
));
68 win
= WMCreateWindow(screen
, "");
69 WMResizeWidget(win
, WINWIDTH
, WINHEIGHT
);
70 WMSetWindowCloseAction(win
, closeAll
, NULL
);
71 WMCreateEventHandler(WMWidgetView(win
), ButtonPressMask
,handleEvents
, win
);
72 color
= WMCreateRGBColor(screen
, 124<<9,206<<8,162<<8, False
);
73 WMSetWidgetBackgroundColor((WMWidget
*)win
, color
);
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
);
85 /* frame and two buttons */
87 controlframe
=WMCreateFrame(win
);
88 WMSetWidgetBackgroundColor((WMWidget
*)controlframe
, color
);
89 WMSetFrameRelief(controlframe
,WRFlat
);
91 Button
=WMCreateButton(controlframe
,WBTMomentaryPush
);
92 WMSetWidgetBackgroundColor((WMWidget
*)Button
, color
);
93 WMSetButtonText (Button
, "Files");
94 WMSetButtonAction (Button
, selectFiles
, NULL
);
95 ButtonsetSize
= WMGetViewSize(WMWidgetView(Button
));
96 WMMoveWidget(Button
, MARGIN
, MARGIN
);
98 Button
=WMCreateButton(controlframe
,WBTMomentaryPush
);
99 WMSetWidgetBackgroundColor((WMWidget
*)Button
, color
);
100 WMSetButtonText (Button
, "Quit");
101 WMSetButtonAction (Button
, closeAll
, NULL
);
102 WMMoveWidget(Button
,2*MARGIN
+ButtonsetSize
.width
, MARGIN
);
103 ButtonsetSize
.width
= 3*MARGIN
+2*ButtonsetSize
.width
;
104 ButtonsetSize
.height
=2*MARGIN
+ButtonsetSize
.height
;
105 WMResizeWidget(controlframe
,ButtonsetSize
.width
,ButtonsetSize
.height
);
107 WMMapSubwidgets(controlframe
);
108 resizeHandler(NULL
,NULL
);
109 /* end of frame and buttons setup */
112 WMMapSubwidgets(win
);
114 WMRealizeWidget(win
);
116 WMScreenMainLoop(screen
);