5 #include <X11/keysym.h>
10 alertPanelOnClick(WMWidget
*self
, void *clientData
)
12 WMAlertPanel
*panel
= clientData
;
15 if (self
== panel
->defBtn
) {
16 panel
->result
= WAPRDefault
;
17 } else if (self
== panel
->othBtn
) {
18 panel
->result
= WAPROther
;
19 } else if (self
== panel
->altBtn
) {
20 panel
->result
= WAPRAlternate
;
26 handleKeyPress(XEvent
*event
, void *clientData
)
28 WMAlertPanel
*panel
= (WMAlertPanel
*)clientData
;
30 if (event
->xkey
.keycode
== panel
->retKey
) {
31 WMPerformButtonClick(panel
->defBtn
);
37 WMRunAlertPanel(WMScreen
*scrPtr
, WMWindow
*owner
,
38 char *title
, char *msg
, char *defaultButton
,
39 char *alternateButton
, char *otherButton
)
44 panel
= WMCreateAlertPanel(scrPtr
, owner
, title
, msg
, defaultButton
,
45 alternateButton
, otherButton
);
47 scrPtr
->modalView
= W_VIEW(panel
->win
);
48 WMMapWidget(panel
->win
);
51 while (!panel
->done
|| WMScreenPending(scrPtr
)) {
54 WMNextEvent(scrPtr
->display
, &event
);
55 WMHandleEvent(&event
);
61 WMDestroyAlertPanel(panel
);
68 WMDestroyAlertPanel(WMAlertPanel
*panel
)
70 WMUnmapWidget(panel
->win
);
71 WMDestroyWidget(panel
->win
);
77 WMCreateAlertPanel(WMScreen
*scrPtr
, WMWindow
*owner
,
78 char *title
, char *msg
, char *defaultButton
,
79 char *alternateButton
, char *otherButton
)
82 int x
, dw
=0, aw
=0, ow
=0, w
;
85 panel
= wmalloc(sizeof(WMAlertPanel
));
86 memset(panel
, 0, sizeof(WMAlertPanel
));
89 panel
->retKey
= XKeysymToKeycode(scrPtr
->display
, XK_Return
);
92 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "alertPanel",
95 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "alertPanel",
98 WMSetWindowTitle(panel
->win
, "");
100 if (scrPtr
->applicationIcon
) {
101 panel
->iLbl
= WMCreateLabel(panel
->win
);
102 WMResizeWidget(panel
->iLbl
, scrPtr
->applicationIcon
->width
,
103 scrPtr
->applicationIcon
->height
);
104 WMMoveWidget(panel
->iLbl
, 8 + (64 - scrPtr
->applicationIcon
->width
)/2,
105 (75 - scrPtr
->applicationIcon
->height
)/2);
106 WMSetLabelImage(panel
->iLbl
, scrPtr
->applicationIcon
);
107 WMSetLabelImagePosition(panel
->iLbl
, WIPImageOnly
);
113 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
115 panel
->tLbl
= WMCreateLabel(panel
->win
);
116 WMMoveWidget(panel
->tLbl
, 80, (80 - WMFontHeight(largeFont
))/2);
117 WMResizeWidget(panel
->tLbl
, 400 - 70, WMFontHeight(largeFont
)+4);
118 WMSetLabelText(panel
->tLbl
, title
);
119 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
120 WMSetLabelFont(panel
->tLbl
, largeFont
);
122 WMReleaseFont(largeFont
);
127 panel
->mLbl
= WMCreateLabel(panel
->win
);
128 WMMoveWidget(panel
->mLbl
, 10, 83);
129 WMResizeWidget(panel
->mLbl
, 380, WMFontHeight(scrPtr
->normalFont
)*4);
130 WMSetLabelText(panel
->mLbl
, msg
);
131 WMSetLabelTextAlignment(panel
->mLbl
, WACenter
);
135 /* create divider line */
137 panel
->line
= WMCreateFrame(panel
->win
);
138 WMMoveWidget(panel
->line
, 0, 80);
139 WMResizeWidget(panel
->line
, 400, 2);
140 WMSetFrameRelief(panel
->line
, WRGroove
);
144 ow
= WMWidthOfString(scrPtr
->normalFont
, otherButton
,
145 strlen(otherButton
));
148 aw
= WMWidthOfString(scrPtr
->normalFont
, alternateButton
,
149 strlen(alternateButton
));
152 dw
= WMWidthOfString(scrPtr
->normalFont
, defaultButton
,
153 strlen(defaultButton
));
155 w
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
167 panel
->defBtn
= WMCreateCommandButton(panel
->win
);
168 WMSetButtonAction(panel
->defBtn
, alertPanelOnClick
, panel
);
169 WMMoveWidget(panel
->defBtn
, x
, 144);
170 WMResizeWidget(panel
->defBtn
, w
, 24);
171 WMSetButtonText(panel
->defBtn
, defaultButton
);
172 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
173 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
174 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
176 if (alternateButton
) {
179 panel
->altBtn
= WMCreateCommandButton(panel
->win
);
180 WMMoveWidget(panel
->altBtn
, x
, 144);
181 WMResizeWidget(panel
->altBtn
, w
, 24);
182 WMSetButtonAction(panel
->altBtn
, alertPanelOnClick
, panel
);
183 WMSetButtonText(panel
->altBtn
, alternateButton
);
188 panel
->othBtn
= WMCreateCommandButton(panel
->win
);
189 WMSetButtonAction(panel
->othBtn
, alertPanelOnClick
, panel
);
190 WMMoveWidget(panel
->othBtn
, x
, 144);
191 WMResizeWidget(panel
->othBtn
, w
, 24);
192 WMSetButtonText(panel
->othBtn
, otherButton
);
197 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
,
198 handleKeyPress
, panel
);
200 WMRealizeWidget(panel
->win
);
201 WMMapSubwidgets(panel
->win
);
211 inputBoxOnClick(WMWidget
*self
, void *clientData
)
213 WMInputPanel
*panel
= clientData
;
216 if (self
== panel
->defBtn
) {
217 panel
->result
= WAPRDefault
;
218 } else if (self
== panel
->altBtn
) {
219 panel
->result
= WAPRAlternate
;
226 handleKeyPress2(XEvent
*event
, void *clientData
)
228 WMInputPanel
*panel
= (WMInputPanel
*)clientData
;
230 if (event
->xkey
.keycode
== panel
->retKey
) {
231 WMPerformButtonClick(panel
->defBtn
);
237 WMRunInputPanel(WMScreen
*scrPtr
, WMWindow
*owner
, char *title
,
238 char *msg
, char *defaultText
,
239 char *okButton
, char *cancelButton
)
244 panel
= WMCreateInputPanel(scrPtr
, owner
, title
, msg
, defaultText
,
245 okButton
, cancelButton
);
247 WMMapWidget(panel
->win
);
249 while (!panel
->done
|| WMScreenPending(scrPtr
)) {
252 WMNextEvent(scrPtr
->display
, &event
);
253 WMHandleEvent(&event
);
257 if (panel
->result
== WAPRDefault
)
258 tmp
= WMGetTextFieldText(panel
->text
);
262 WMDestroyInputPanel(panel
);
269 WMDestroyInputPanel(WMInputPanel
*panel
)
271 WMRemoveNotificationObserver(panel
);
272 WMUnmapWidget(panel
->win
);
273 WMDestroyWidget(panel
->win
);
280 endedEditingObserver(void *observerData
, WMNotification
*notification
)
282 WMInputPanel
*panel
= (WMInputPanel
*)observerData
;
284 if ((int)WMGetNotificationClientData(notification
) == WMReturnTextMovement
) {
285 WMPerformButtonClick(panel
->defBtn
);
291 WMCreateInputPanel(WMScreen
*scrPtr
, WMWindow
*owner
, char *title
, char *msg
,
292 char *defaultText
, char *okButton
, char *cancelButton
)
295 int x
, dw
=0, aw
=0, w
;
298 panel
= wmalloc(sizeof(WMInputPanel
));
299 memset(panel
, 0, sizeof(WMInputPanel
));
301 panel
->retKey
= XKeysymToKeycode(scrPtr
->display
, XK_Return
);
304 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "inputPanel",
307 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "inputPanel",
309 WMSetWindowTitle(panel
->win
, "");
311 WMResizeWidget(panel
->win
, 320, 160);
316 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
318 panel
->tLbl
= WMCreateLabel(panel
->win
);
319 WMMoveWidget(panel
->tLbl
, 20, 16);
320 WMResizeWidget(panel
->tLbl
, 320 - 40, WMFontHeight(largeFont
)+4);
321 WMSetLabelText(panel
->tLbl
, title
);
322 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
323 WMSetLabelFont(panel
->tLbl
, largeFont
);
325 WMReleaseFont(largeFont
);
330 panel
->mLbl
= WMCreateLabel(panel
->win
);
331 WMMoveWidget(panel
->mLbl
, 20, 50);
332 WMResizeWidget(panel
->mLbl
, 320 - 40,
333 WMFontHeight(scrPtr
->normalFont
)*2);
334 WMSetLabelText(panel
->mLbl
, msg
);
335 WMSetLabelTextAlignment(panel
->mLbl
, WALeft
);
338 panel
->text
= WMCreateTextField(panel
->win
);
339 WMMoveWidget(panel
->text
, 20, 85);
340 WMResizeWidget(panel
->text
, 320 - 40, WMWidgetHeight(panel
->text
));
341 WMSetTextFieldText(panel
->text
, defaultText
);
343 WMAddNotificationObserver(endedEditingObserver
, panel
,
344 WMTextDidEndEditingNotification
, panel
->text
);
348 aw
= WMWidthOfString(scrPtr
->normalFont
, cancelButton
,
349 strlen(cancelButton
));
352 dw
= WMWidthOfString(scrPtr
->normalFont
, okButton
,
355 w
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
365 panel
->defBtn
= WMCreateCustomButton(panel
->win
, WBBPushInMask
368 WMSetButtonAction(panel
->defBtn
, inputBoxOnClick
, panel
);
369 WMMoveWidget(panel
->defBtn
, x
, 124);
370 WMResizeWidget(panel
->defBtn
, w
, 24);
371 WMSetButtonText(panel
->defBtn
, okButton
);
372 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
373 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
374 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
379 panel
->altBtn
= WMCreateCommandButton(panel
->win
);
380 WMSetButtonAction(panel
->altBtn
, inputBoxOnClick
, panel
);
381 WMMoveWidget(panel
->altBtn
, x
, 124);
382 WMResizeWidget(panel
->altBtn
, w
, 24);
383 WMSetButtonText(panel
->altBtn
, cancelButton
);
388 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
,
389 handleKeyPress2
, panel
);
391 WMRealizeWidget(panel
->win
);
392 WMMapSubwidgets(panel
->win
);
394 WMSetFocusToWidget(panel
->text
);