13 WMFrame
*controlframe
;
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
)
28 oPanel
= WMGetOpenPanel(screen
);
29 if (WMRunModalFilePanelForDirectory(oPanel
, NULL
, "/tmp",
30 "Search..", NULL
) == True
) {
33 snprintf(textbuf
, sizeof(textbuf
), "%s\n-", WMGetFilePanelFileName(oPanel
));
35 WMAppendTextStream(text
, textbuf
);
41 static void handleEvents(XEvent
*event
, void *data
)
44 WMWidget
*widget
= (WMWidget
*) data
;
46 switch (event
->type
) {
48 snprintf(textbuf
, sizeof(textbuf
), "Button down at (%i,%i) \n-",
49 event
->xbutton
.x
, event
->xbutton
.y
);
51 WMAppendTextStream(text
, textbuf
);
57 static void resizeHandler(void *self
, WMNotification
*notif
)
59 WMSize size
= WMGetViewSize(WMWidgetView(win
));
60 WMMoveWidget(controlframe
, size
.width
-ButtonsetSize
.width
, size
.height
-ButtonsetSize
.height
);
61 WMResizeWidget(text
, size
.width
- MARGIN
- 10, size
.height
- 80);
65 int main(int argc
, char **argv
)
69 WMInitializeApplication("FifthWindow", &argc
, argv
);
70 display
= XOpenDisplay("");
72 fprintf(stderr
, "err: cannot open display");
75 screen
= WMCreateScreen(display
, DefaultScreen(display
));
78 win
= WMCreateWindow(screen
, "");
79 WMResizeWidget(win
, WINWIDTH
, WINHEIGHT
);
80 WMSetWindowCloseAction(win
, closeAll
, NULL
);
81 WMCreateEventHandler(WMWidgetView(win
), ButtonPressMask
, handleEvents
, win
);
82 color
= WMCreateRGBColor(screen
, 124<<9, 206<<8, 162<<8, False
);
83 WMSetWidgetBackgroundColor((WMWidget
*)win
, color
);
84 WMSetViewNotifySizeChanges(WMWidgetView(win
), True
);
85 WMAddNotificationObserver(resizeHandler
, NULL
, WMViewSizeDidChangeNotification
, WMWidgetView(win
));
89 text
= WMCreateText(win
);
90 WMResizeWidget(text
, WINWIDTH
- MARGIN
, WINHEIGHT
- 80);
91 WMMoveWidget(text
, 10, 10);
92 WMSetTextHasVerticalScroller(text
, True
);
93 WMSetTextEditable(text
, False
);
95 /* frame and two buttons */
97 controlframe
= WMCreateFrame(win
);
98 WMSetWidgetBackgroundColor((WMWidget
*)controlframe
, color
);
99 WMSetFrameRelief(controlframe
, WRFlat
);
101 Button
= WMCreateButton(controlframe
, WBTMomentaryPush
);
102 WMSetWidgetBackgroundColor((WMWidget
*)Button
, color
);
103 WMSetButtonText(Button
, "Files");
104 WMSetButtonAction(Button
, selectFiles
, NULL
);
105 ButtonsetSize
= WMGetViewSize(WMWidgetView(Button
));
106 WMMoveWidget(Button
, MARGIN
, MARGIN
);
108 Button
= WMCreateButton(controlframe
, WBTMomentaryPush
);
109 WMSetWidgetBackgroundColor((WMWidget
*)Button
, color
);
110 WMSetButtonText(Button
, "Quit");
111 WMSetButtonAction(Button
, closeAll
, NULL
);
112 WMMoveWidget(Button
, 2*MARGIN
+ ButtonsetSize
.width
, MARGIN
);
113 ButtonsetSize
.width
= 3*MARGIN
+ 2*ButtonsetSize
.width
;
114 ButtonsetSize
.height
= 2*MARGIN
+ ButtonsetSize
.height
;
115 WMResizeWidget(controlframe
, ButtonsetSize
.width
, ButtonsetSize
.height
);
117 WMMapSubwidgets(controlframe
);
118 resizeHandler(NULL
,NULL
);
120 /* end of frame and buttons setup */
122 WMMapSubwidgets(win
);
124 WMRealizeWidget(win
);
126 WMScreenMainLoop(screen
);