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",
108 WMSetWindowInitialPosition(panel
->win
,
109 (scrPtr
->rootView
->size
.width
- WMWidgetWidth(panel
->win
))/2,
110 (scrPtr
->rootView
->size
.height
- WMWidgetHeight(panel
->win
))/2);
112 WMSetWindowTitle(panel
->win
, "");
114 if (scrPtr
->applicationIcon
) {
115 panel
->iLbl
= WMCreateLabel(panel
->win
);
116 WMResizeWidget(panel
->iLbl
, scrPtr
->applicationIcon
->width
,
117 scrPtr
->applicationIcon
->height
);
118 WMMoveWidget(panel
->iLbl
, 8 + (64 - scrPtr
->applicationIcon
->width
)/2,
119 (75 - scrPtr
->applicationIcon
->height
)/2);
120 WMSetLabelImage(panel
->iLbl
, scrPtr
->applicationIcon
);
121 WMSetLabelImagePosition(panel
->iLbl
, WIPImageOnly
);
127 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
129 panel
->tLbl
= WMCreateLabel(panel
->win
);
130 WMMoveWidget(panel
->tLbl
, 80, (80 - WMFontHeight(largeFont
))/2);
131 WMResizeWidget(panel
->tLbl
, 400 - 70, WMFontHeight(largeFont
)+4);
132 WMSetLabelText(panel
->tLbl
, title
);
133 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
134 WMSetLabelFont(panel
->tLbl
, largeFont
);
136 WMReleaseFont(largeFont
);
141 panel
->mLbl
= WMCreateLabel(panel
->win
);
142 WMMoveWidget(panel
->mLbl
, 10, 83);
143 WMResizeWidget(panel
->mLbl
, 380, WMFontHeight(scrPtr
->normalFont
)*4);
144 WMSetLabelText(panel
->mLbl
, msg
);
145 WMSetLabelTextAlignment(panel
->mLbl
, WACenter
);
149 /* create divider line */
151 panel
->line
= WMCreateFrame(panel
->win
);
152 WMMoveWidget(panel
->line
, 0, 80);
153 WMResizeWidget(panel
->line
, 400, 2);
154 WMSetFrameRelief(panel
->line
, WRGroove
);
158 ow
= WMWidthOfString(scrPtr
->normalFont
, otherButton
,
159 strlen(otherButton
));
162 aw
= WMWidthOfString(scrPtr
->normalFont
, alternateButton
,
163 strlen(alternateButton
));
166 dw
= WMWidthOfString(scrPtr
->normalFont
, defaultButton
,
167 strlen(defaultButton
));
169 w
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
181 panel
->defBtn
= WMCreateCommandButton(panel
->win
);
182 WMSetButtonAction(panel
->defBtn
, alertPanelOnClick
, panel
);
183 WMMoveWidget(panel
->defBtn
, x
, 144);
184 WMResizeWidget(panel
->defBtn
, w
, 24);
185 WMSetButtonText(panel
->defBtn
, defaultButton
);
186 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
187 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
188 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
190 if (alternateButton
) {
193 panel
->altBtn
= WMCreateCommandButton(panel
->win
);
194 WMMoveWidget(panel
->altBtn
, x
, 144);
195 WMResizeWidget(panel
->altBtn
, w
, 24);
196 WMSetButtonAction(panel
->altBtn
, alertPanelOnClick
, panel
);
197 WMSetButtonText(panel
->altBtn
, alternateButton
);
202 panel
->othBtn
= WMCreateCommandButton(panel
->win
);
203 WMSetButtonAction(panel
->othBtn
, alertPanelOnClick
, panel
);
204 WMMoveWidget(panel
->othBtn
, x
, 144);
205 WMResizeWidget(panel
->othBtn
, w
, 24);
206 WMSetButtonText(panel
->othBtn
, otherButton
);
211 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
,
212 handleKeyPress
, panel
);
214 WMRealizeWidget(panel
->win
);
215 WMMapSubwidgets(panel
->win
);
225 inputBoxOnClick(WMWidget
*self
, void *clientData
)
227 WMInputPanel
*panel
= clientData
;
230 if (self
== panel
->defBtn
) {
231 panel
->result
= WAPRDefault
;
232 } else if (self
== panel
->altBtn
) {
233 panel
->result
= WAPRAlternate
;
240 handleKeyPress2(XEvent
*event
, void *clientData
)
242 WMInputPanel
*panel
= (WMInputPanel
*)clientData
;
244 if (event
->xkey
.keycode
== panel
->retKey
&& panel
->defBtn
) {
245 WMPerformButtonClick(panel
->defBtn
);
247 if (event
->xkey
.keycode
== panel
->escKey
) {
249 WMPerformButtonClick(panel
->altBtn
);
251 /* printf("got esc\n");*/
253 panel
->result
= WAPRDefault
;
260 WMRunInputPanel(WMScreen
*scrPtr
, WMWindow
*owner
, char *title
,
261 char *msg
, char *defaultText
,
262 char *okButton
, char *cancelButton
)
267 panel
= WMCreateInputPanel(scrPtr
, owner
, title
, msg
, defaultText
,
268 okButton
, cancelButton
);
270 WMMapWidget(panel
->win
);
272 while (!panel
->done
|| WMScreenPending(scrPtr
)) {
275 WMNextEvent(scrPtr
->display
, &event
);
276 WMHandleEvent(&event
);
280 if (panel
->result
== WAPRDefault
)
281 tmp
= WMGetTextFieldText(panel
->text
);
285 WMDestroyInputPanel(panel
);
292 WMDestroyInputPanel(WMInputPanel
*panel
)
294 WMRemoveNotificationObserver(panel
);
295 WMUnmapWidget(panel
->win
);
296 WMDestroyWidget(panel
->win
);
303 endedEditingObserver(void *observerData
, WMNotification
*notification
)
305 WMInputPanel
*panel
= (WMInputPanel
*)observerData
;
307 switch ((int)WMGetNotificationClientData(notification
)) {
308 case WMReturnTextMovement
:
310 WMPerformButtonClick(panel
->defBtn
);
312 case WMEscapeTextMovement
:
314 WMPerformButtonClick(panel
->altBtn
);
317 panel
->result
= WAPRDefault
;
327 WMCreateInputPanel(WMScreen
*scrPtr
, WMWindow
*owner
, char *title
, char *msg
,
328 char *defaultText
, char *okButton
, char *cancelButton
)
331 int x
, dw
=0, aw
=0, w
;
334 panel
= wmalloc(sizeof(WMInputPanel
));
335 memset(panel
, 0, sizeof(WMInputPanel
));
337 panel
->retKey
= XKeysymToKeycode(scrPtr
->display
, XK_Return
);
338 panel
->escKey
= XKeysymToKeycode(scrPtr
->display
, XK_Escape
);
341 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "inputPanel",
344 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "inputPanel",
346 WMSetWindowTitle(panel
->win
, "");
348 WMResizeWidget(panel
->win
, 320, 160);
353 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
355 panel
->tLbl
= WMCreateLabel(panel
->win
);
356 WMMoveWidget(panel
->tLbl
, 20, 16);
357 WMResizeWidget(panel
->tLbl
, 320 - 40, WMFontHeight(largeFont
)+4);
358 WMSetLabelText(panel
->tLbl
, title
);
359 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
360 WMSetLabelFont(panel
->tLbl
, largeFont
);
362 WMReleaseFont(largeFont
);
367 panel
->mLbl
= WMCreateLabel(panel
->win
);
368 WMMoveWidget(panel
->mLbl
, 20, 50);
369 WMResizeWidget(panel
->mLbl
, 320 - 40,
370 WMFontHeight(scrPtr
->normalFont
)*2);
371 WMSetLabelText(panel
->mLbl
, msg
);
372 WMSetLabelTextAlignment(panel
->mLbl
, WALeft
);
375 panel
->text
= WMCreateTextField(panel
->win
);
376 WMMoveWidget(panel
->text
, 20, 85);
377 WMResizeWidget(panel
->text
, 320 - 40, WMWidgetHeight(panel
->text
));
378 WMSetTextFieldText(panel
->text
, defaultText
);
380 WMAddNotificationObserver(endedEditingObserver
, panel
,
381 WMTextDidEndEditingNotification
, panel
->text
);
385 aw
= WMWidthOfString(scrPtr
->normalFont
, cancelButton
,
386 strlen(cancelButton
));
389 dw
= WMWidthOfString(scrPtr
->normalFont
, okButton
,
392 w
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
402 panel
->defBtn
= WMCreateCustomButton(panel
->win
, WBBPushInMask
405 WMSetButtonAction(panel
->defBtn
, inputBoxOnClick
, panel
);
406 WMMoveWidget(panel
->defBtn
, x
, 124);
407 WMResizeWidget(panel
->defBtn
, w
, 24);
408 WMSetButtonText(panel
->defBtn
, okButton
);
409 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
410 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
411 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
416 panel
->altBtn
= WMCreateCommandButton(panel
->win
);
417 WMSetButtonAction(panel
->altBtn
, inputBoxOnClick
, panel
);
418 WMMoveWidget(panel
->altBtn
, x
, 124);
419 WMResizeWidget(panel
->altBtn
, w
, 24);
420 WMSetButtonText(panel
->altBtn
, cancelButton
);
425 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
,
426 handleKeyPress2
, panel
);
428 WMRealizeWidget(panel
->win
);
429 WMMapSubwidgets(panel
->win
);
431 WMSetFocusToWidget(panel
->text
);