5 #include <X11/keysym.h>
11 alertPanelOnClick(WMWidget
*self
, void *clientData
)
13 WMAlertPanel
*panel
= clientData
;
15 WMBreakModalLoop(WMWidgetScreen(self
));
16 if (self
== panel
->defBtn
) {
17 panel
->result
= WAPRDefault
;
18 } else if (self
== panel
->othBtn
) {
19 panel
->result
= WAPROther
;
20 } else if (self
== panel
->altBtn
) {
21 panel
->result
= WAPRAlternate
;
27 handleKeyPress(XEvent
*event
, void *clientData
)
29 WMAlertPanel
*panel
= (WMAlertPanel
*)clientData
;
32 XLookupString(&event
->xkey
, NULL
, 0, &ksym
, NULL
);
34 if (ksym
== XK_Return
&& panel
->defBtn
) {
35 WMPerformButtonClick(panel
->defBtn
);
36 } else if (ksym
== XK_Escape
) {
37 if (panel
->altBtn
|| panel
->othBtn
) {
38 WMPerformButtonClick(panel
->othBtn
? panel
->othBtn
: panel
->altBtn
);
40 panel
->result
= WAPRDefault
;
41 WMBreakModalLoop(WMWidgetScreen(panel
->win
));
48 WMRunAlertPanel(WMScreen
*scrPtr
, WMWindow
*owner
,
49 char *title
, char *msg
, char *defaultButton
,
50 char *alternateButton
, char *otherButton
)
55 panel
= WMCreateAlertPanel(scrPtr
, owner
, title
, msg
, defaultButton
,
56 alternateButton
, otherButton
);
60 WMView
*view
= WMWidgetView(panel
->win
);
63 WMView
*oview
= WMWidgetView(owner
);
64 WMPoint pt
= WMGetViewScreenPosition(oview
);
66 px
= (W_VIEW_WIDTH(oview
)-W_VIEW_WIDTH(view
))/2;
67 py
= (W_VIEW_HEIGHT(oview
)-W_VIEW_HEIGHT(view
))/2;
72 px
= (W_VIEW_WIDTH(scrPtr
->rootView
)-W_VIEW_WIDTH(view
))/2;
73 py
= (W_VIEW_HEIGHT(scrPtr
->rootView
)-W_VIEW_HEIGHT(view
))/2;
75 WMSetWindowInitialPosition(panel
->win
, px
, py
);
78 WMMapWidget(panel
->win
);
80 WMRunModalLoop(scrPtr
, W_VIEW(panel
->win
));
84 WMDestroyAlertPanel(panel
);
91 WMDestroyAlertPanel(WMAlertPanel
*panel
)
93 WMUnmapWidget(panel
->win
);
94 WMDestroyWidget(panel
->win
);
100 WMCreateAlertPanel(WMScreen
*scrPtr
, WMWindow
*owner
,
101 char *title
, char *msg
, char *defaultButton
,
102 char *alternateButton
, char *otherButton
)
105 int dw
=0, aw
=0, ow
=0, w
;
110 panel
= wmalloc(sizeof(WMAlertPanel
));
111 memset(panel
, 0, sizeof(WMAlertPanel
));
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 WMSetViewExpandsToParent(WMWidgetView(panel
->vbox
), 0, 0, 0, 0);
129 WMSetBoxHorizontal(panel
->vbox
, False
);
130 WMMapWidget(panel
->vbox
);
132 hbox
= WMCreateBox(panel
->vbox
);
133 WMSetBoxBorderWidth(hbox
, 5);
134 WMSetBoxHorizontal(hbox
, True
);
136 WMAddBoxSubview(panel
->vbox
, WMWidgetView(hbox
), False
, True
, 74, 0, 5);
138 panel
->iLbl
= WMCreateLabel(hbox
);
139 WMSetLabelImagePosition(panel
->iLbl
, WIPImageOnly
);
140 WMMapWidget(panel
->iLbl
);
141 WMAddBoxSubview(hbox
, WMWidgetView(panel
->iLbl
), False
, True
, 64, 0, 10);
142 icon
= WMCreateApplicationIconBlendedPixmap(scrPtr
, (RColor
*)NULL
);
144 WMSetLabelImage(panel
->iLbl
, icon
);
145 WMReleasePixmap(icon
);
147 WMSetLabelImage(panel
->iLbl
, scrPtr
->applicationIconPixmap
);
153 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
155 panel
->tLbl
= WMCreateLabel(hbox
);
156 WMMapWidget(panel
->tLbl
);
157 WMAddBoxSubview(hbox
, WMWidgetView(panel
->tLbl
), True
, True
,
159 WMSetLabelText(panel
->tLbl
, title
);
160 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
161 WMSetLabelFont(panel
->tLbl
, largeFont
);
163 WMReleaseFont(largeFont
);
166 /* create divider line */
168 panel
->line
= WMCreateFrame(panel
->win
);
169 WMMapWidget(panel
->line
);
170 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->line
), False
, True
,
172 WMSetFrameRelief(panel
->line
, WRGroove
);
176 panel
->mLbl
= WMCreateLabel(panel
->vbox
);
177 WMSetLabelWraps(panel
->mLbl
, True
);
178 WMMapWidget(panel
->mLbl
);
179 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->mLbl
), True
, True
,
180 WMFontHeight(scrPtr
->normalFont
)*4, 0, 5);
181 WMSetLabelText(panel
->mLbl
, msg
);
182 WMSetLabelTextAlignment(panel
->mLbl
, WACenter
);
185 panel
->hbox
= WMCreateBox(panel
->vbox
);
186 WMSetBoxBorderWidth(panel
->hbox
, 10);
187 WMSetBoxHorizontal(panel
->hbox
, True
);
188 WMMapWidget(panel
->hbox
);
189 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->hbox
), False
, True
, 44, 0, 0);
193 ow
= WMWidthOfString(scrPtr
->normalFont
, otherButton
,
194 strlen(otherButton
));
197 aw
= WMWidthOfString(scrPtr
->normalFont
, alternateButton
,
198 strlen(alternateButton
));
201 dw
= WMWidthOfString(scrPtr
->normalFont
, defaultButton
,
202 strlen(defaultButton
));
204 dw
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
210 w
= WMAX(dw
, WMAX(aw
, ow
));
211 if ((w
+10)*3 < 400) {
218 t
= 400 - 40 - aw
- ow
- dw
;
225 panel
->defBtn
= WMCreateCommandButton(panel
->hbox
);
226 WMSetButtonAction(panel
->defBtn
, alertPanelOnClick
, panel
);
227 WMAddBoxSubviewAtEnd(panel
->hbox
, WMWidgetView(panel
->defBtn
),
228 False
, True
, dw
, 0, 0);
229 WMSetButtonText(panel
->defBtn
, defaultButton
);
230 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
231 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
232 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
234 if (alternateButton
) {
235 panel
->altBtn
= WMCreateCommandButton(panel
->hbox
);
236 WMAddBoxSubviewAtEnd(panel
->hbox
, WMWidgetView(panel
->altBtn
),
237 False
, True
, aw
, 0, 5);
238 WMSetButtonAction(panel
->altBtn
, alertPanelOnClick
, panel
);
239 WMSetButtonText(panel
->altBtn
, alternateButton
);
242 panel
->othBtn
= WMCreateCommandButton(panel
->hbox
);
243 WMSetButtonAction(panel
->othBtn
, alertPanelOnClick
, panel
);
244 WMAddBoxSubviewAtEnd(panel
->hbox
, WMWidgetView(panel
->othBtn
),
245 False
, True
, ow
, 0, 5);
246 WMSetButtonText(panel
->othBtn
, otherButton
);
249 WMMapSubwidgets(panel
->hbox
);
251 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
,
252 handleKeyPress
, panel
);
254 WMRealizeWidget(panel
->win
);
255 WMMapSubwidgets(panel
->win
);
265 inputBoxOnClick(WMWidget
*self
, void *clientData
)
267 WMInputPanel
*panel
= clientData
;
269 WMBreakModalLoop(WMWidgetScreen(self
));
270 if (self
== panel
->defBtn
) {
271 panel
->result
= WAPRDefault
;
272 } else if (self
== panel
->altBtn
) {
273 panel
->result
= WAPRAlternate
;
280 handleKeyPress2(XEvent
*event
, void *clientData
)
282 WMInputPanel
*panel
= (WMInputPanel
*)clientData
;
285 XLookupString(&event
->xkey
, NULL
, 0, &ksym
, NULL
);
287 if (ksym
== XK_Return
&& panel
->defBtn
) {
288 WMPerformButtonClick(panel
->defBtn
);
289 } else if (ksym
== XK_Escape
) {
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)(uintptr_t)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
));
395 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "inputPanel",
398 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "inputPanel",
400 WMSetWindowTitle(panel
->win
, "");
402 WMResizeWidget(panel
->win
, 320, 160);
407 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
409 panel
->tLbl
= WMCreateLabel(panel
->win
);
410 WMMoveWidget(panel
->tLbl
, 20, 16);
411 WMResizeWidget(panel
->tLbl
, 320 - 40, WMFontHeight(largeFont
)+4);
412 WMSetLabelText(panel
->tLbl
, title
);
413 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
414 WMSetLabelFont(panel
->tLbl
, largeFont
);
416 WMReleaseFont(largeFont
);
421 panel
->mLbl
= WMCreateLabel(panel
->win
);
422 WMMoveWidget(panel
->mLbl
, 20, 50);
423 WMResizeWidget(panel
->mLbl
, 320 - 40,
424 WMFontHeight(scrPtr
->normalFont
)*2);
425 WMSetLabelText(panel
->mLbl
, msg
);
426 WMSetLabelTextAlignment(panel
->mLbl
, WALeft
);
429 panel
->text
= WMCreateTextField(panel
->win
);
430 WMMoveWidget(panel
->text
, 20, 85);
431 WMResizeWidget(panel
->text
, 320 - 40, WMWidgetHeight(panel
->text
));
432 WMSetTextFieldText(panel
->text
, defaultText
);
434 WMAddNotificationObserver(endedEditingObserver
, panel
,
435 WMTextDidEndEditingNotification
, panel
->text
);
439 aw
= WMWidthOfString(scrPtr
->normalFont
, cancelButton
,
440 strlen(cancelButton
));
443 dw
= WMWidthOfString(scrPtr
->normalFont
, okButton
,
446 w
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
456 panel
->defBtn
= WMCreateCustomButton(panel
->win
, WBBPushInMask
459 WMSetButtonAction(panel
->defBtn
, inputBoxOnClick
, panel
);
460 WMMoveWidget(panel
->defBtn
, x
, 124);
461 WMResizeWidget(panel
->defBtn
, w
, 24);
462 WMSetButtonText(panel
->defBtn
, okButton
);
463 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
464 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
465 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
470 panel
->altBtn
= WMCreateCommandButton(panel
->win
);
471 WMSetButtonAction(panel
->altBtn
, inputBoxOnClick
, panel
);
472 WMMoveWidget(panel
->altBtn
, x
, 124);
473 WMResizeWidget(panel
->altBtn
, w
, 24);
474 WMSetButtonText(panel
->altBtn
, cancelButton
);
477 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
,
478 handleKeyPress2
, panel
);
480 WMRealizeWidget(panel
->win
);
481 WMMapSubwidgets(panel
->win
);
483 WMSetFocusToWidget(panel
->text
);
492 handleKeyPress3(XEvent
*event
, void *clientData
)
494 WMGenericPanel
*panel
= (WMGenericPanel
*)clientData
;
497 XLookupString(&event
->xkey
, NULL
, 0, &ksym
, NULL
);
499 if (ksym
== XK_Return
&& panel
->defBtn
) {
500 WMPerformButtonClick(panel
->defBtn
);
501 } else if (ksym
== XK_Escape
) {
503 WMPerformButtonClick(panel
->altBtn
);
505 panel
->result
= WAPRDefault
;
506 WMBreakModalLoop(WMWidgetScreen(panel
->win
));
513 WMDestroyGenericPanel(WMGenericPanel
*panel
)
515 WMUnmapWidget(panel
->win
);
516 WMDestroyWidget(panel
->win
);
522 WMCreateGenericPanel(WMScreen
*scrPtr
, WMWindow
*owner
,
523 char *title
, char *defaultButton
,
524 char *alternateButton
)
526 WMGenericPanel
*panel
;
532 panel
= wmalloc(sizeof(WMGenericPanel
));
533 memset(panel
, 0, sizeof(WMGenericPanel
));
536 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "genericPanel",
539 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "genericPanel",
543 WMSetWindowInitialPosition(panel
->win
,
544 (scrPtr
->rootView
->size
.width
- WMWidgetWidth(panel
->win
))/2,
545 (scrPtr
->rootView
->size
.height
- WMWidgetHeight(panel
->win
))/2);
547 WMSetWindowTitle(panel
->win
, "");
549 panel
->vbox
= WMCreateBox(panel
->win
);
550 WMSetViewExpandsToParent(WMWidgetView(panel
->vbox
), 0, 0, 0, 0);
551 WMSetBoxHorizontal(panel
->vbox
, False
);
552 WMMapWidget(panel
->vbox
);
554 hbox
= WMCreateBox(panel
->vbox
);
555 WMSetBoxBorderWidth(hbox
, 5);
556 WMSetBoxHorizontal(hbox
, True
);
558 WMAddBoxSubview(panel
->vbox
, WMWidgetView(hbox
), False
, True
, 74, 0, 5);
560 panel
->iLbl
= WMCreateLabel(hbox
);
561 WMSetLabelImagePosition(panel
->iLbl
, WIPImageOnly
);
562 WMMapWidget(panel
->iLbl
);
563 WMAddBoxSubview(hbox
, WMWidgetView(panel
->iLbl
), False
, True
, 64, 0, 10);
564 icon
= WMCreateApplicationIconBlendedPixmap(scrPtr
, (RColor
*)NULL
);
566 WMSetLabelImage(panel
->iLbl
, icon
);
567 WMReleasePixmap(icon
);
569 WMSetLabelImage(panel
->iLbl
, scrPtr
->applicationIconPixmap
);
575 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
577 panel
->tLbl
= WMCreateLabel(hbox
);
578 WMMapWidget(panel
->tLbl
);
579 WMAddBoxSubview(hbox
, WMWidgetView(panel
->tLbl
), True
, True
,
581 WMSetLabelText(panel
->tLbl
, title
);
582 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
583 WMSetLabelFont(panel
->tLbl
, largeFont
);
585 WMReleaseFont(largeFont
);
588 /* create divider line */
590 panel
->line
= WMCreateFrame(panel
->vbox
);
591 WMMapWidget(panel
->line
);
592 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->line
), False
, True
,
594 WMSetFrameRelief(panel
->line
, WRGroove
);
597 panel
->content
= WMCreateFrame(panel
->vbox
);
598 WMMapWidget(panel
->content
);
599 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->content
), True
, True
,
601 WMSetFrameRelief(panel
->content
, WRFlat
);
603 hbox
= WMCreateBox(panel
->vbox
);
604 WMSetBoxBorderWidth(hbox
, 10);
605 WMSetBoxHorizontal(hbox
, True
);
607 WMAddBoxSubview(panel
->vbox
, WMWidgetView(hbox
), False
, True
, 44, 0, 0);
611 dw
= WMWidthOfString(scrPtr
->normalFont
, defaultButton
,
612 strlen(defaultButton
));
615 aw
= WMWidthOfString(scrPtr
->normalFont
, alternateButton
,
616 strlen(alternateButton
));
619 dw
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
625 if ((w
+10)*2 < 400) {
631 t
= 400 - 40 - aw
- dw
;
637 panel
->defBtn
= WMCreateCommandButton(hbox
);
638 WMSetButtonAction(panel
->defBtn
, alertPanelOnClick
, panel
);
639 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->defBtn
),
640 False
, True
, dw
, 0, 0);
641 WMSetButtonText(panel
->defBtn
, defaultButton
);
642 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
643 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
644 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
647 WMMapSubwidgets(hbox
);
649 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
,
650 handleKeyPress3
, panel
);
652 WMRealizeWidget(panel
->win
);
653 WMMapSubwidgets(panel
->win
);