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 WMSetWindowUPosition(panel
->win
,
99 (scrPtr
->rootView
->size
.width
- WMWidgetWidth(panel
->win
))/2,
100 (scrPtr
->rootView
->size
.height
- WMWidgetHeight(panel
->win
))/2);
101 WMSetWindowTitle(panel
->win
, "");
103 if (scrPtr
->applicationIcon
) {
104 panel
->iLbl
= WMCreateLabel(panel
->win
);
105 WMResizeWidget(panel
->iLbl
, scrPtr
->applicationIcon
->width
,
106 scrPtr
->applicationIcon
->height
);
107 WMMoveWidget(panel
->iLbl
, 8 + (64 - scrPtr
->applicationIcon
->width
)/2,
108 (75 - scrPtr
->applicationIcon
->height
)/2);
109 WMSetLabelImage(panel
->iLbl
, scrPtr
->applicationIcon
);
110 WMSetLabelImagePosition(panel
->iLbl
, WIPImageOnly
);
116 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
118 panel
->tLbl
= WMCreateLabel(panel
->win
);
119 WMMoveWidget(panel
->tLbl
, 80, (80 - WMFontHeight(largeFont
))/2);
120 WMResizeWidget(panel
->tLbl
, 400 - 70, WMFontHeight(largeFont
)+4);
121 WMSetLabelText(panel
->tLbl
, title
);
122 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
123 WMSetLabelFont(panel
->tLbl
, largeFont
);
125 WMReleaseFont(largeFont
);
130 panel
->mLbl
= WMCreateLabel(panel
->win
);
131 WMMoveWidget(panel
->mLbl
, 10, 83);
132 WMResizeWidget(panel
->mLbl
, 380, WMFontHeight(scrPtr
->normalFont
)*4);
133 WMSetLabelText(panel
->mLbl
, msg
);
134 WMSetLabelTextAlignment(panel
->mLbl
, WACenter
);
138 /* create divider line */
140 panel
->line
= WMCreateFrame(panel
->win
);
141 WMMoveWidget(panel
->line
, 0, 80);
142 WMResizeWidget(panel
->line
, 400, 2);
143 WMSetFrameRelief(panel
->line
, WRGroove
);
147 ow
= WMWidthOfString(scrPtr
->normalFont
, otherButton
,
148 strlen(otherButton
));
151 aw
= WMWidthOfString(scrPtr
->normalFont
, alternateButton
,
152 strlen(alternateButton
));
155 dw
= WMWidthOfString(scrPtr
->normalFont
, defaultButton
,
156 strlen(defaultButton
));
158 w
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
170 panel
->defBtn
= WMCreateCommandButton(panel
->win
);
171 WMSetButtonAction(panel
->defBtn
, alertPanelOnClick
, panel
);
172 WMMoveWidget(panel
->defBtn
, x
, 144);
173 WMResizeWidget(panel
->defBtn
, w
, 24);
174 WMSetButtonText(panel
->defBtn
, defaultButton
);
175 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
176 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
177 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
179 if (alternateButton
) {
182 panel
->altBtn
= WMCreateCommandButton(panel
->win
);
183 WMMoveWidget(panel
->altBtn
, x
, 144);
184 WMResizeWidget(panel
->altBtn
, w
, 24);
185 WMSetButtonAction(panel
->altBtn
, alertPanelOnClick
, panel
);
186 WMSetButtonText(panel
->altBtn
, alternateButton
);
191 panel
->othBtn
= WMCreateCommandButton(panel
->win
);
192 WMSetButtonAction(panel
->othBtn
, alertPanelOnClick
, panel
);
193 WMMoveWidget(panel
->othBtn
, x
, 144);
194 WMResizeWidget(panel
->othBtn
, w
, 24);
195 WMSetButtonText(panel
->othBtn
, otherButton
);
200 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
,
201 handleKeyPress
, panel
);
203 WMRealizeWidget(panel
->win
);
204 WMMapSubwidgets(panel
->win
);
214 inputBoxOnClick(WMWidget
*self
, void *clientData
)
216 WMInputPanel
*panel
= clientData
;
219 if (self
== panel
->defBtn
) {
220 panel
->result
= WAPRDefault
;
221 } else if (self
== panel
->altBtn
) {
222 panel
->result
= WAPRAlternate
;
229 handleKeyPress2(XEvent
*event
, void *clientData
)
231 WMInputPanel
*panel
= (WMInputPanel
*)clientData
;
233 if (event
->xkey
.keycode
== panel
->retKey
) {
234 WMPerformButtonClick(panel
->defBtn
);
240 WMRunInputPanel(WMScreen
*scrPtr
, WMWindow
*owner
, char *title
,
241 char *msg
, char *defaultText
,
242 char *okButton
, char *cancelButton
)
247 panel
= WMCreateInputPanel(scrPtr
, owner
, title
, msg
, defaultText
,
248 okButton
, cancelButton
);
250 WMMapWidget(panel
->win
);
252 while (!panel
->done
|| WMScreenPending(scrPtr
)) {
255 WMNextEvent(scrPtr
->display
, &event
);
256 WMHandleEvent(&event
);
260 if (panel
->result
== WAPRDefault
)
261 tmp
= WMGetTextFieldText(panel
->text
);
265 WMDestroyInputPanel(panel
);
272 WMDestroyInputPanel(WMInputPanel
*panel
)
274 WMRemoveNotificationObserver(panel
);
275 WMUnmapWidget(panel
->win
);
276 WMDestroyWidget(panel
->win
);
283 endedEditingObserver(void *observerData
, WMNotification
*notification
)
285 WMInputPanel
*panel
= (WMInputPanel
*)observerData
;
287 if ((int)WMGetNotificationClientData(notification
) == WMReturnTextMovement
) {
288 WMPerformButtonClick(panel
->defBtn
);
294 WMCreateInputPanel(WMScreen
*scrPtr
, WMWindow
*owner
, char *title
, char *msg
,
295 char *defaultText
, char *okButton
, char *cancelButton
)
298 int x
, dw
=0, aw
=0, w
;
301 panel
= wmalloc(sizeof(WMInputPanel
));
302 memset(panel
, 0, sizeof(WMInputPanel
));
304 panel
->retKey
= XKeysymToKeycode(scrPtr
->display
, XK_Return
);
307 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "inputPanel",
310 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "inputPanel",
312 WMSetWindowTitle(panel
->win
, "");
314 WMResizeWidget(panel
->win
, 320, 160);
319 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
321 panel
->tLbl
= WMCreateLabel(panel
->win
);
322 WMMoveWidget(panel
->tLbl
, 20, 16);
323 WMResizeWidget(panel
->tLbl
, 320 - 40, WMFontHeight(largeFont
)+4);
324 WMSetLabelText(panel
->tLbl
, title
);
325 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
326 WMSetLabelFont(panel
->tLbl
, largeFont
);
328 WMReleaseFont(largeFont
);
333 panel
->mLbl
= WMCreateLabel(panel
->win
);
334 WMMoveWidget(panel
->mLbl
, 20, 50);
335 WMResizeWidget(panel
->mLbl
, 320 - 40,
336 WMFontHeight(scrPtr
->normalFont
)*2);
337 WMSetLabelText(panel
->mLbl
, msg
);
338 WMSetLabelTextAlignment(panel
->mLbl
, WALeft
);
341 panel
->text
= WMCreateTextField(panel
->win
);
342 WMMoveWidget(panel
->text
, 20, 85);
343 WMResizeWidget(panel
->text
, 320 - 40, WMWidgetHeight(panel
->text
));
344 WMSetTextFieldText(panel
->text
, defaultText
);
346 WMAddNotificationObserver(endedEditingObserver
, panel
,
347 WMTextDidEndEditingNotification
, panel
->text
);
351 aw
= WMWidthOfString(scrPtr
->normalFont
, cancelButton
,
352 strlen(cancelButton
));
355 dw
= WMWidthOfString(scrPtr
->normalFont
, okButton
,
358 w
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
368 panel
->defBtn
= WMCreateCustomButton(panel
->win
, WBBPushInMask
371 WMSetButtonAction(panel
->defBtn
, inputBoxOnClick
, panel
);
372 WMMoveWidget(panel
->defBtn
, x
, 124);
373 WMResizeWidget(panel
->defBtn
, w
, 24);
374 WMSetButtonText(panel
->defBtn
, okButton
);
375 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
376 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
377 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
382 panel
->altBtn
= WMCreateCommandButton(panel
->win
);
383 WMSetButtonAction(panel
->altBtn
, inputBoxOnClick
, panel
);
384 WMMoveWidget(panel
->altBtn
, x
, 124);
385 WMResizeWidget(panel
->altBtn
, w
, 24);
386 WMSetButtonText(panel
->altBtn
, cancelButton
);
391 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
,
392 handleKeyPress2
, panel
);
394 WMRealizeWidget(panel
->win
);
395 WMMapSubwidgets(panel
->win
);
397 WMSetFocusToWidget(panel
->text
);