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
&& panel
->defBtn
) {
31 WMPerformButtonClick(panel
->defBtn
);
33 if (event
->xkey
.keycode
== panel
->escKey
) {
34 if (panel
->altBtn
|| panel
->othBtn
) {
35 WMPerformButtonClick(panel
->othBtn
? panel
->othBtn
: panel
->altBtn
);
37 panel
->result
= WAPRDefault
;
45 WMRunAlertPanel(WMScreen
*scrPtr
, WMWindow
*owner
,
46 char *title
, char *msg
, char *defaultButton
,
47 char *alternateButton
, char *otherButton
)
52 panel
= WMCreateAlertPanel(scrPtr
, owner
, title
, msg
, defaultButton
,
53 alternateButton
, otherButton
);
55 scrPtr
->modalView
= W_VIEW(panel
->win
);
56 WMMapWidget(panel
->win
);
59 while (!panel
->done
|| WMScreenPending(scrPtr
)) {
62 WMNextEvent(scrPtr
->display
, &event
);
63 WMHandleEvent(&event
);
69 WMDestroyAlertPanel(panel
);
76 WMDestroyAlertPanel(WMAlertPanel
*panel
)
78 WMUnmapWidget(panel
->win
);
79 WMDestroyWidget(panel
->win
);
85 WMCreateAlertPanel(WMScreen
*scrPtr
, WMWindow
*owner
,
86 char *title
, char *msg
, char *defaultButton
,
87 char *alternateButton
, char *otherButton
)
90 int x
, dw
=0, aw
=0, ow
=0, w
;
93 panel
= wmalloc(sizeof(WMAlertPanel
));
94 memset(panel
, 0, sizeof(WMAlertPanel
));
97 panel
->retKey
= XKeysymToKeycode(scrPtr
->display
, XK_Return
);
98 panel
->escKey
= XKeysymToKeycode(scrPtr
->display
, XK_Escape
);
101 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "alertPanel",
104 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "alertPanel",
107 WMSetWindowInitialPosition(panel
->win
,
108 (scrPtr
->rootView
->size
.width
- WMWidgetWidth(panel
->win
))/2,
109 (scrPtr
->rootView
->size
.height
- WMWidgetHeight(panel
->win
))/2);
111 WMSetWindowTitle(panel
->win
, "");
113 if (scrPtr
->applicationIcon
) {
114 panel
->iLbl
= WMCreateLabel(panel
->win
);
115 WMResizeWidget(panel
->iLbl
, scrPtr
->applicationIcon
->width
,
116 scrPtr
->applicationIcon
->height
);
117 WMMoveWidget(panel
->iLbl
, 8 + (64 - scrPtr
->applicationIcon
->width
)/2,
118 (75 - scrPtr
->applicationIcon
->height
)/2);
119 WMSetLabelImage(panel
->iLbl
, scrPtr
->applicationIcon
);
120 WMSetLabelImagePosition(panel
->iLbl
, WIPImageOnly
);
126 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
128 panel
->tLbl
= WMCreateLabel(panel
->win
);
129 WMMoveWidget(panel
->tLbl
, 80, (80 - WMFontHeight(largeFont
))/2);
130 WMResizeWidget(panel
->tLbl
, 400 - 70, WMFontHeight(largeFont
)+4);
131 WMSetLabelText(panel
->tLbl
, title
);
132 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
133 WMSetLabelFont(panel
->tLbl
, largeFont
);
135 WMReleaseFont(largeFont
);
140 panel
->mLbl
= WMCreateLabel(panel
->win
);
141 WMMoveWidget(panel
->mLbl
, 10, 83);
142 WMResizeWidget(panel
->mLbl
, 380, WMFontHeight(scrPtr
->normalFont
)*4);
143 WMSetLabelText(panel
->mLbl
, msg
);
144 WMSetLabelTextAlignment(panel
->mLbl
, WACenter
);
148 /* create divider line */
150 panel
->line
= WMCreateFrame(panel
->win
);
151 WMMoveWidget(panel
->line
, 0, 80);
152 WMResizeWidget(panel
->line
, 400, 2);
153 WMSetFrameRelief(panel
->line
, WRGroove
);
157 ow
= WMWidthOfString(scrPtr
->normalFont
, otherButton
,
158 strlen(otherButton
));
161 aw
= WMWidthOfString(scrPtr
->normalFont
, alternateButton
,
162 strlen(alternateButton
));
165 dw
= WMWidthOfString(scrPtr
->normalFont
, defaultButton
,
166 strlen(defaultButton
));
168 w
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
180 panel
->defBtn
= WMCreateCommandButton(panel
->win
);
181 WMSetButtonAction(panel
->defBtn
, alertPanelOnClick
, panel
);
182 WMMoveWidget(panel
->defBtn
, x
, 144);
183 WMResizeWidget(panel
->defBtn
, w
, 24);
184 WMSetButtonText(panel
->defBtn
, defaultButton
);
185 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
186 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
187 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
189 if (alternateButton
) {
192 panel
->altBtn
= WMCreateCommandButton(panel
->win
);
193 WMMoveWidget(panel
->altBtn
, x
, 144);
194 WMResizeWidget(panel
->altBtn
, w
, 24);
195 WMSetButtonAction(panel
->altBtn
, alertPanelOnClick
, panel
);
196 WMSetButtonText(panel
->altBtn
, alternateButton
);
201 panel
->othBtn
= WMCreateCommandButton(panel
->win
);
202 WMSetButtonAction(panel
->othBtn
, alertPanelOnClick
, panel
);
203 WMMoveWidget(panel
->othBtn
, x
, 144);
204 WMResizeWidget(panel
->othBtn
, w
, 24);
205 WMSetButtonText(panel
->othBtn
, otherButton
);
210 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
,
211 handleKeyPress
, panel
);
213 WMRealizeWidget(panel
->win
);
214 WMMapSubwidgets(panel
->win
);
224 inputBoxOnClick(WMWidget
*self
, void *clientData
)
226 WMInputPanel
*panel
= clientData
;
229 if (self
== panel
->defBtn
) {
230 panel
->result
= WAPRDefault
;
231 } else if (self
== panel
->altBtn
) {
232 panel
->result
= WAPRAlternate
;
239 handleKeyPress2(XEvent
*event
, void *clientData
)
241 WMInputPanel
*panel
= (WMInputPanel
*)clientData
;
243 if (event
->xkey
.keycode
== panel
->retKey
&& panel
->defBtn
) {
244 WMPerformButtonClick(panel
->defBtn
);
246 if (event
->xkey
.keycode
== panel
->escKey
) {
248 WMPerformButtonClick(panel
->altBtn
);
250 /* printf("got esc\n");*/
252 panel
->result
= WAPRDefault
;
259 WMRunInputPanel(WMScreen
*scrPtr
, WMWindow
*owner
, char *title
,
260 char *msg
, char *defaultText
,
261 char *okButton
, char *cancelButton
)
266 panel
= WMCreateInputPanel(scrPtr
, owner
, title
, msg
, defaultText
,
267 okButton
, cancelButton
);
269 WMMapWidget(panel
->win
);
271 while (!panel
->done
|| WMScreenPending(scrPtr
)) {
274 WMNextEvent(scrPtr
->display
, &event
);
275 WMHandleEvent(&event
);
279 if (panel
->result
== WAPRDefault
)
280 tmp
= WMGetTextFieldText(panel
->text
);
284 WMDestroyInputPanel(panel
);
291 WMDestroyInputPanel(WMInputPanel
*panel
)
293 WMRemoveNotificationObserver(panel
);
294 WMUnmapWidget(panel
->win
);
295 WMDestroyWidget(panel
->win
);
302 endedEditingObserver(void *observerData
, WMNotification
*notification
)
304 WMInputPanel
*panel
= (WMInputPanel
*)observerData
;
306 switch ((int)WMGetNotificationClientData(notification
)) {
307 case WMReturnTextMovement
:
309 WMPerformButtonClick(panel
->defBtn
);
311 case WMEscapeTextMovement
:
313 WMPerformButtonClick(panel
->altBtn
);
316 panel
->result
= WAPRDefault
;
326 WMCreateInputPanel(WMScreen
*scrPtr
, WMWindow
*owner
, char *title
, char *msg
,
327 char *defaultText
, char *okButton
, char *cancelButton
)
330 int x
, dw
=0, aw
=0, w
;
333 panel
= wmalloc(sizeof(WMInputPanel
));
334 memset(panel
, 0, sizeof(WMInputPanel
));
336 panel
->retKey
= XKeysymToKeycode(scrPtr
->display
, XK_Return
);
337 panel
->escKey
= XKeysymToKeycode(scrPtr
->display
, XK_Escape
);
340 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "inputPanel",
343 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "inputPanel",
345 WMSetWindowTitle(panel
->win
, "");
347 WMResizeWidget(panel
->win
, 320, 160);
352 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
354 panel
->tLbl
= WMCreateLabel(panel
->win
);
355 WMMoveWidget(panel
->tLbl
, 20, 16);
356 WMResizeWidget(panel
->tLbl
, 320 - 40, WMFontHeight(largeFont
)+4);
357 WMSetLabelText(panel
->tLbl
, title
);
358 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
359 WMSetLabelFont(panel
->tLbl
, largeFont
);
361 WMReleaseFont(largeFont
);
366 panel
->mLbl
= WMCreateLabel(panel
->win
);
367 WMMoveWidget(panel
->mLbl
, 20, 50);
368 WMResizeWidget(panel
->mLbl
, 320 - 40,
369 WMFontHeight(scrPtr
->normalFont
)*2);
370 WMSetLabelText(panel
->mLbl
, msg
);
371 WMSetLabelTextAlignment(panel
->mLbl
, WALeft
);
374 panel
->text
= WMCreateTextField(panel
->win
);
375 WMMoveWidget(panel
->text
, 20, 85);
376 WMResizeWidget(panel
->text
, 320 - 40, WMWidgetHeight(panel
->text
));
377 WMSetTextFieldText(panel
->text
, defaultText
);
379 WMAddNotificationObserver(endedEditingObserver
, panel
,
380 WMTextDidEndEditingNotification
, panel
->text
);
384 aw
= WMWidthOfString(scrPtr
->normalFont
, cancelButton
,
385 strlen(cancelButton
));
388 dw
= WMWidthOfString(scrPtr
->normalFont
, okButton
,
391 w
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
401 panel
->defBtn
= WMCreateCustomButton(panel
->win
, WBBPushInMask
404 WMSetButtonAction(panel
->defBtn
, inputBoxOnClick
, panel
);
405 WMMoveWidget(panel
->defBtn
, x
, 124);
406 WMResizeWidget(panel
->defBtn
, w
, 24);
407 WMSetButtonText(panel
->defBtn
, okButton
);
408 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
409 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
410 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
415 panel
->altBtn
= WMCreateCommandButton(panel
->win
);
416 WMSetButtonAction(panel
->altBtn
, inputBoxOnClick
, panel
);
417 WMMoveWidget(panel
->altBtn
, x
, 124);
418 WMResizeWidget(panel
->altBtn
, w
, 24);
419 WMSetButtonText(panel
->altBtn
, cancelButton
);
424 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
,
425 handleKeyPress2
, panel
);
427 WMRealizeWidget(panel
->win
);
428 WMMapSubwidgets(panel
->win
);
430 WMSetFocusToWidget(panel
->text
);