5 #include <X11/keysym.h>
10 alertPanelOnClick(WMWidget
*self
, void *clientData
)
12 WMAlertPanel
*panel
= clientData
;
14 WMBreakModalLoop(WMWidgetScreen(self
));
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
;
38 WMBreakModalLoop(WMWidgetScreen(panel
->win
));
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
);
57 WMView
*view
= WMWidgetView(panel
->win
);
60 WMView
*oview
= WMWidgetView(owner
);
61 WMPoint pt
= WMGetViewScreenPosition(oview
);
63 px
= (W_VIEW_WIDTH(oview
)-W_VIEW_WIDTH(view
))/2;
64 py
= (W_VIEW_HEIGHT(oview
)-W_VIEW_HEIGHT(view
))/2;
69 px
= (W_VIEW_WIDTH(scrPtr
->rootView
)-W_VIEW_WIDTH(view
))/2;
70 py
= (W_VIEW_HEIGHT(scrPtr
->rootView
)-W_VIEW_HEIGHT(view
))/2;
72 WMSetWindowInitialPosition(panel
->win
, px
, py
);
75 WMMapWidget(panel
->win
);
77 WMRunModalLoop(scrPtr
, W_VIEW(panel
->win
));
81 WMDestroyAlertPanel(panel
);
88 WMDestroyAlertPanel(WMAlertPanel
*panel
)
90 WMUnmapWidget(panel
->win
);
91 WMDestroyWidget(panel
->win
);
97 WMCreateAlertPanel(WMScreen
*scrPtr
, WMWindow
*owner
,
98 char *title
, char *msg
, char *defaultButton
,
99 char *alternateButton
, char *otherButton
)
102 int x
, dw
=0, aw
=0, ow
=0, w
;
106 panel
= wmalloc(sizeof(WMAlertPanel
));
107 memset(panel
, 0, sizeof(WMAlertPanel
));
110 panel
->retKey
= XKeysymToKeycode(scrPtr
->display
, XK_Return
);
111 panel
->escKey
= XKeysymToKeycode(scrPtr
->display
, XK_Escape
);
114 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "alertPanel",
117 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "alertPanel",
121 WMSetWindowInitialPosition(panel
->win
,
122 (scrPtr
->rootView
->size
.width
- WMWidgetWidth(panel
->win
))/2,
123 (scrPtr
->rootView
->size
.height
- WMWidgetHeight(panel
->win
))/2);
125 WMSetWindowTitle(panel
->win
, "");
127 panel
->vbox
= WMCreateBox(panel
->win
);
128 WMSetBoxExpandsToParent(panel
->vbox
);
129 WMSetBoxHorizontal(panel
->vbox
, False
);
130 WMMapWidget(panel
->vbox
);
132 hbox
= WMCreateBox(panel
->vbox
);
133 WMSetBoxHorizontal(hbox
, True
);
135 WMAddBoxSubview(panel
->vbox
, WMWidgetView(hbox
), False
, True
, 80, 0, 5);
137 panel
->iLbl
= WMCreateLabel(hbox
);
138 WMSetLabelImagePosition(panel
->iLbl
, WIPImageOnly
);
139 WMMapWidget(panel
->iLbl
);
140 WMAddBoxSubview(hbox
, WMWidgetView(panel
->iLbl
), False
, True
, 64, 0, 10);
142 if (scrPtr
->applicationIcon
) {
143 WMSetLabelImage(panel
->iLbl
, scrPtr
->applicationIcon
);
149 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
151 panel
->tLbl
= WMCreateLabel(hbox
);
152 WMMapWidget(panel
->tLbl
);
153 WMAddBoxSubview(hbox
, WMWidgetView(panel
->tLbl
), True
, True
,
155 WMSetLabelText(panel
->tLbl
, title
);
156 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
157 WMSetLabelFont(panel
->tLbl
, largeFont
);
159 WMReleaseFont(largeFont
);
162 /* create divider line */
164 panel
->line
= WMCreateFrame(panel
->win
);
165 WMMapWidget(panel
->line
);
166 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->line
), False
, True
,
168 WMSetFrameRelief(panel
->line
, WRGroove
);
172 panel
->mLbl
= WMCreateLabel(panel
->win
);
173 WMMapWidget(panel
->mLbl
);
174 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->mLbl
), True
, True
,
175 WMFontHeight(scrPtr
->normalFont
)*4, 0, 5);
176 WMSetLabelText(panel
->mLbl
, msg
);
177 WMSetLabelTextAlignment(panel
->mLbl
, WACenter
);
180 hbox
= WMCreateBox(panel
->vbox
);
181 WMSetBoxHorizontal(hbox
, True
);
183 WMAddBoxSubview(panel
->vbox
, WMWidgetView(hbox
), False
, True
, 24, 0, 0);
187 ow
= WMWidthOfString(scrPtr
->normalFont
, otherButton
,
188 strlen(otherButton
));
191 aw
= WMWidthOfString(scrPtr
->normalFont
, alternateButton
,
192 strlen(alternateButton
));
195 dw
= WMWidthOfString(scrPtr
->normalFont
, defaultButton
,
196 strlen(defaultButton
));
198 dw
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
204 w
= WMAX(dw
, WMAX(aw
, ow
));
205 if ((w
+10)*3 < 400) {
212 t
= 400 - 40 - aw
- ow
- dw
;
223 panel
->defBtn
= WMCreateCommandButton(panel
->win
);
224 WMSetButtonAction(panel
->defBtn
, alertPanelOnClick
, panel
);
225 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->defBtn
),
226 False
, True
, dw
, 0, 5);
227 WMSetButtonText(panel
->defBtn
, defaultButton
);
228 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
229 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
230 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
232 if (alternateButton
) {
235 panel
->altBtn
= WMCreateCommandButton(panel
->win
);
236 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->altBtn
),
237 False
, True
, aw
, 0, 5);
238 WMSetButtonAction(panel
->altBtn
, alertPanelOnClick
, panel
);
239 WMSetButtonText(panel
->altBtn
, alternateButton
);
244 panel
->othBtn
= WMCreateCommandButton(panel
->win
);
245 WMSetButtonAction(panel
->othBtn
, alertPanelOnClick
, panel
);
246 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->othBtn
),
247 False
, True
, ow
, 0, 5);
248 WMSetButtonText(panel
->othBtn
, otherButton
);
251 WMMapSubwidgets(hbox
);
253 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
,
254 handleKeyPress
, panel
);
256 WMRealizeWidget(panel
->win
);
257 WMMapSubwidgets(panel
->win
);
267 inputBoxOnClick(WMWidget
*self
, void *clientData
)
269 WMInputPanel
*panel
= clientData
;
271 WMBreakModalLoop(WMWidgetScreen(self
));
272 if (self
== panel
->defBtn
) {
273 panel
->result
= WAPRDefault
;
274 } else if (self
== panel
->altBtn
) {
275 panel
->result
= WAPRAlternate
;
282 handleKeyPress2(XEvent
*event
, void *clientData
)
284 WMInputPanel
*panel
= (WMInputPanel
*)clientData
;
286 if (event
->xkey
.keycode
== panel
->retKey
&& panel
->defBtn
) {
287 WMPerformButtonClick(panel
->defBtn
);
289 if (event
->xkey
.keycode
== panel
->escKey
) {
291 WMPerformButtonClick(panel
->altBtn
);
293 /* printf("got esc\n");*/
294 WMBreakModalLoop(WMWidgetScreen(panel
->win
));
295 panel
->result
= WAPRDefault
;
302 WMRunInputPanel(WMScreen
*scrPtr
, WMWindow
*owner
, char *title
,
303 char *msg
, char *defaultText
,
304 char *okButton
, char *cancelButton
)
309 panel
= WMCreateInputPanel(scrPtr
, owner
, title
, msg
, defaultText
,
310 okButton
, cancelButton
);
315 WMView
*view
= WMWidgetView(panel
->win
);
318 WMView
*oview
= WMWidgetView(owner
);
319 WMPoint pt
= WMGetViewScreenPosition(oview
);
321 px
= (W_VIEW_WIDTH(oview
)-W_VIEW_WIDTH(view
))/2;
322 py
= (W_VIEW_HEIGHT(oview
)-W_VIEW_HEIGHT(view
))/2;
327 px
= (W_VIEW_WIDTH(scrPtr
->rootView
)-W_VIEW_WIDTH(view
))/2;
328 py
= (W_VIEW_HEIGHT(scrPtr
->rootView
)-W_VIEW_HEIGHT(view
))/2;
330 WMSetWindowInitialPosition(panel
->win
, px
, py
);
333 WMMapWidget(panel
->win
);
335 WMRunModalLoop(scrPtr
, W_VIEW(panel
->win
));
337 if (panel
->result
== WAPRDefault
)
338 tmp
= WMGetTextFieldText(panel
->text
);
342 WMDestroyInputPanel(panel
);
349 WMDestroyInputPanel(WMInputPanel
*panel
)
351 WMRemoveNotificationObserver(panel
);
352 WMUnmapWidget(panel
->win
);
353 WMDestroyWidget(panel
->win
);
360 endedEditingObserver(void *observerData
, WMNotification
*notification
)
362 WMInputPanel
*panel
= (WMInputPanel
*)observerData
;
364 switch ((int)WMGetNotificationClientData(notification
)) {
365 case WMReturnTextMovement
:
367 WMPerformButtonClick(panel
->defBtn
);
369 case WMEscapeTextMovement
:
371 WMPerformButtonClick(panel
->altBtn
);
373 WMBreakModalLoop(WMWidgetScreen(panel
->win
));
374 panel
->result
= WAPRDefault
;
384 WMCreateInputPanel(WMScreen
*scrPtr
, WMWindow
*owner
, char *title
, char *msg
,
385 char *defaultText
, char *okButton
, char *cancelButton
)
388 int x
, dw
=0, aw
=0, w
;
391 panel
= wmalloc(sizeof(WMInputPanel
));
392 memset(panel
, 0, sizeof(WMInputPanel
));
394 panel
->retKey
= XKeysymToKeycode(scrPtr
->display
, XK_Return
);
395 panel
->escKey
= XKeysymToKeycode(scrPtr
->display
, XK_Escape
);
398 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "inputPanel",
401 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "inputPanel",
403 WMSetWindowTitle(panel
->win
, "");
405 WMResizeWidget(panel
->win
, 320, 160);
410 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
412 panel
->tLbl
= WMCreateLabel(panel
->win
);
413 WMMoveWidget(panel
->tLbl
, 20, 16);
414 WMResizeWidget(panel
->tLbl
, 320 - 40, WMFontHeight(largeFont
)+4);
415 WMSetLabelText(panel
->tLbl
, title
);
416 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
417 WMSetLabelFont(panel
->tLbl
, largeFont
);
419 WMReleaseFont(largeFont
);
424 panel
->mLbl
= WMCreateLabel(panel
->win
);
425 WMMoveWidget(panel
->mLbl
, 20, 50);
426 WMResizeWidget(panel
->mLbl
, 320 - 40,
427 WMFontHeight(scrPtr
->normalFont
)*2);
428 WMSetLabelText(panel
->mLbl
, msg
);
429 WMSetLabelTextAlignment(panel
->mLbl
, WALeft
);
432 panel
->text
= WMCreateTextField(panel
->win
);
433 WMMoveWidget(panel
->text
, 20, 85);
434 WMResizeWidget(panel
->text
, 320 - 40, WMWidgetHeight(panel
->text
));
435 WMSetTextFieldText(panel
->text
, defaultText
);
437 WMAddNotificationObserver(endedEditingObserver
, panel
,
438 WMTextDidEndEditingNotification
, panel
->text
);
442 aw
= WMWidthOfString(scrPtr
->normalFont
, cancelButton
,
443 strlen(cancelButton
));
446 dw
= WMWidthOfString(scrPtr
->normalFont
, okButton
,
449 w
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
459 panel
->defBtn
= WMCreateCustomButton(panel
->win
, WBBPushInMask
462 WMSetButtonAction(panel
->defBtn
, inputBoxOnClick
, panel
);
463 WMMoveWidget(panel
->defBtn
, x
, 124);
464 WMResizeWidget(panel
->defBtn
, w
, 24);
465 WMSetButtonText(panel
->defBtn
, okButton
);
466 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
467 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
468 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
473 panel
->altBtn
= WMCreateCommandButton(panel
->win
);
474 WMSetButtonAction(panel
->altBtn
, inputBoxOnClick
, panel
);
475 WMMoveWidget(panel
->altBtn
, x
, 124);
476 WMResizeWidget(panel
->altBtn
, w
, 24);
477 WMSetButtonText(panel
->altBtn
, cancelButton
);
480 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
,
481 handleKeyPress2
, panel
);
483 WMRealizeWidget(panel
->win
);
484 WMMapSubwidgets(panel
->win
);
486 WMSetFocusToWidget(panel
->text
);