4 #include <X11/keysym.h>
7 static void alertPanelOnClick(WMWidget
* self
, void *clientData
)
9 WMAlertPanel
*panel
= clientData
;
11 WMBreakModalLoop(WMWidgetScreen(self
));
12 if (self
== panel
->defBtn
) {
13 panel
->result
= WAPRDefault
;
14 } else if (self
== panel
->othBtn
) {
15 panel
->result
= WAPROther
;
16 } else if (self
== panel
->altBtn
) {
17 panel
->result
= WAPRAlternate
;
21 static void handleKeyPress(XEvent
* event
, void *clientData
)
23 WMAlertPanel
*panel
= (WMAlertPanel
*) clientData
;
26 XLookupString(&event
->xkey
, NULL
, 0, &ksym
, NULL
);
28 if ((ksym
== XK_Return
|| ksym
== XK_KP_Enter
) && panel
->defBtn
) {
29 WMPerformButtonClick(panel
->defBtn
);
30 } else if (ksym
== XK_Escape
) {
31 if (panel
->altBtn
|| panel
->othBtn
) {
32 WMPerformButtonClick(panel
->othBtn
? panel
->othBtn
: panel
->altBtn
);
34 panel
->result
= WAPRDefault
;
35 WMBreakModalLoop(WMWidgetScreen(panel
->win
));
41 WMRunAlertPanel(WMScreen
* scrPtr
, WMWindow
* owner
,
42 const char *title
, const char *msg
, const char *defaultButton
, const char *alternateButton
, const char *otherButton
)
47 panel
= WMCreateAlertPanel(scrPtr
, owner
, title
, msg
, defaultButton
, alternateButton
, otherButton
);
51 WMView
*view
= WMWidgetView(panel
->win
);
54 WMView
*oview
= WMWidgetView(owner
);
55 WMPoint pt
= WMGetViewScreenPosition(oview
);
57 px
= (W_VIEW_WIDTH(oview
) - W_VIEW_WIDTH(view
)) / 2;
58 py
= (W_VIEW_HEIGHT(oview
) - W_VIEW_HEIGHT(view
)) / 2;
63 px
= (W_VIEW_WIDTH(scrPtr
->rootView
) - W_VIEW_WIDTH(view
)) / 2;
64 py
= (W_VIEW_HEIGHT(scrPtr
->rootView
) - W_VIEW_HEIGHT(view
)) / 2;
66 WMSetWindowInitialPosition(panel
->win
, px
, py
);
69 WMMapWidget(panel
->win
);
71 WMRunModalLoop(scrPtr
, W_VIEW(panel
->win
));
75 WMDestroyAlertPanel(panel
);
80 void WMDestroyAlertPanel(WMAlertPanel
* panel
)
82 WMUnmapWidget(panel
->win
);
83 WMDestroyWidget(panel
->win
);
87 WMAlertPanel
*WMCreateAlertPanel(WMScreen
* scrPtr
, WMWindow
* owner
,
88 const char *title
, const char *msg
, const char *defaultButton
,
89 const char *alternateButton
, const char *otherButton
)
93 int dw
= 0, aw
= 0, ow
= 0, w
;
97 defaultFont
= WMSystemFontOfSize(scrPtr
, 12);
98 panel
= wmalloc(sizeof(WMAlertPanel
));
101 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "alertPanel", WMTitledWindowMask
);
103 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "alertPanel", WMTitledWindowMask
);
106 WMSetWindowInitialPosition(panel
->win
,
107 (scrPtr
->rootView
->size
.width
- WMWidgetWidth(panel
->win
)) / 2,
108 (scrPtr
->rootView
->size
.height
- WMWidgetHeight(panel
->win
)) / 2);
110 WMSetWindowTitle(panel
->win
, "");
112 panel
->vbox
= WMCreateBox(panel
->win
);
113 WMSetViewExpandsToParent(WMWidgetView(panel
->vbox
), 0, 0, 0, 0);
114 WMSetBoxHorizontal(panel
->vbox
, False
);
115 WMMapWidget(panel
->vbox
);
117 hbox
= WMCreateBox(panel
->vbox
);
118 WMSetBoxBorderWidth(hbox
, 5);
119 WMSetBoxHorizontal(hbox
, True
);
121 WMAddBoxSubview(panel
->vbox
, WMWidgetView(hbox
), False
, True
, 74, 0, 5);
123 panel
->iLbl
= WMCreateLabel(hbox
);
124 WMSetLabelImagePosition(panel
->iLbl
, WIPImageOnly
);
125 WMMapWidget(panel
->iLbl
);
126 WMAddBoxSubview(hbox
, WMWidgetView(panel
->iLbl
), False
, True
, 64, 0, 10);
127 icon
= WMCreateApplicationIconBlendedPixmap(scrPtr
, (RColor
*) NULL
);
129 WMSetLabelImage(panel
->iLbl
, icon
);
130 WMReleasePixmap(icon
);
132 WMSetLabelImage(panel
->iLbl
, scrPtr
->applicationIconPixmap
);
138 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
140 panel
->tLbl
= WMCreateLabel(hbox
);
141 WMMapWidget(panel
->tLbl
);
142 WMAddBoxSubview(hbox
, WMWidgetView(panel
->tLbl
), True
, True
, 64, 0, 0);
143 WMSetLabelText(panel
->tLbl
, title
);
144 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
145 WMSetLabelFont(panel
->tLbl
, largeFont
);
147 WMReleaseFont(largeFont
);
150 /* create divider line */
152 panel
->line
= WMCreateFrame(panel
->win
);
153 WMMapWidget(panel
->line
);
154 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->line
), False
, True
, 2, 2, 5);
155 WMSetFrameRelief(panel
->line
, WRGroove
);
158 panel
->mLbl
= WMCreateLabel(panel
->vbox
);
159 WMSetLabelWraps(panel
->mLbl
, True
);
160 WMMapWidget(panel
->mLbl
);
161 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->mLbl
), True
, True
,
162 WMFontHeight(scrPtr
->normalFont
) * 4, 0, 5);
163 WMSetLabelText(panel
->mLbl
, msg
);
164 WMSetLabelTextAlignment(panel
->mLbl
, WACenter
);
165 WMSetLabelFont(panel
->mLbl
, defaultFont
);
168 panel
->hbox
= WMCreateBox(panel
->vbox
);
169 WMSetBoxBorderWidth(panel
->hbox
, 10);
170 WMSetBoxHorizontal(panel
->hbox
, True
);
171 WMMapWidget(panel
->hbox
);
172 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->hbox
), False
, True
, 44, 0, 0);
176 ow
= WMWidthOfString(defaultFont
, otherButton
, strlen(otherButton
));
179 aw
= WMWidthOfString(defaultFont
, alternateButton
, strlen(alternateButton
));
182 dw
= WMWidthOfString(defaultFont
, defaultButton
, strlen(defaultButton
));
184 dw
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
190 w
= WMAX(dw
, WMAX(aw
, ow
));
191 if ((w
+ 10) * 3 < 400) {
198 t
= 400 - 40 - aw
- ow
- dw
;
205 panel
->defBtn
= WMCreateCommandButton(panel
->hbox
);
206 WMSetButtonAction(panel
->defBtn
, alertPanelOnClick
, panel
);
207 WMAddBoxSubviewAtEnd(panel
->hbox
, WMWidgetView(panel
->defBtn
), False
, True
, dw
, 0, 0);
208 WMSetButtonText(panel
->defBtn
, defaultButton
);
209 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
210 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
211 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
212 WMSetButtonFont(panel
->defBtn
, defaultFont
);
214 if (alternateButton
) {
215 panel
->altBtn
= WMCreateCommandButton(panel
->hbox
);
216 WMAddBoxSubviewAtEnd(panel
->hbox
, WMWidgetView(panel
->altBtn
), False
, True
, aw
, 0, 5);
217 WMSetButtonAction(panel
->altBtn
, alertPanelOnClick
, panel
);
218 WMSetButtonText(panel
->altBtn
, alternateButton
);
219 WMSetButtonFont(panel
->altBtn
, defaultFont
);
222 panel
->othBtn
= WMCreateCommandButton(panel
->hbox
);
223 WMSetButtonAction(panel
->othBtn
, alertPanelOnClick
, panel
);
224 WMAddBoxSubviewAtEnd(panel
->hbox
, WMWidgetView(panel
->othBtn
), False
, True
, ow
, 0, 5);
225 WMSetButtonText(panel
->othBtn
, otherButton
);
226 WMSetButtonFont(panel
->othBtn
, defaultFont
);
229 WMMapSubwidgets(panel
->hbox
);
231 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
, handleKeyPress
, panel
);
233 WMRealizeWidget(panel
->win
);
234 WMMapSubwidgets(panel
->win
);
236 WMReleaseFont(defaultFont
);
241 WMAlertPanel
*WMCreateScaledAlertPanel(WMScreen
* scrPtr
, WMWindow
* owner
,
242 const char *title
, const char *msg
, const char *defaultButton
,
243 const char *alternateButton
, const char *otherButton
)
246 int dw
= 0, aw
= 0, ow
= 0, w
;
249 int wmScaleWidth
, wmScaleHeight
;
252 panel
= wmalloc(sizeof(WMAlertPanel
));
255 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "alertPanel", WMTitledWindowMask
);
257 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "alertPanel", WMTitledWindowMask
);
260 /* calculate and set the panel's size */
261 WMGetScaleBaseFromSystemFont(scrPtr
, &wmScaleWidth
, &wmScaleHeight
);
262 pwidth
= WMScaleX(400);
263 pheight
= WMScaleY(5) /* upper margin */
265 + WMScaleY(5) /* space between icon and divider line */
266 + 2 /* divider line */
267 + WMScaleY(5); /* space between divider line and message */
269 pheight
+= WMFontHeight(scrPtr
->normalFont
) * 4 + WMScaleY(5);
270 pheight
+= WMScaleY(44);
271 WMResizeWidget(panel
->win
, pwidth
, pheight
);
273 WMSetWindowInitialPosition(panel
->win
,
274 (scrPtr
->rootView
->size
.width
- pwidth
) / 2,
275 (scrPtr
->rootView
->size
.height
- pheight
) / 2);
277 WMSetWindowTitle(panel
->win
, "");
279 panel
->vbox
= WMCreateBox(panel
->win
);
280 WMSetViewExpandsToParent(WMWidgetView(panel
->vbox
), 0, 0, 0, 0);
281 WMSetBoxHorizontal(panel
->vbox
, False
);
282 WMMapWidget(panel
->vbox
);
284 hbox
= WMCreateBox(panel
->vbox
);
285 WMSetBoxBorderWidth(hbox
, WMScaleX(5));
286 WMSetBoxHorizontal(hbox
, True
);
288 WMAddBoxSubview(panel
->vbox
, WMWidgetView(hbox
), False
, True
, 64 + 2 * WMScaleY(5), 0, WMScaleY(5));
290 panel
->iLbl
= WMCreateLabel(hbox
);
291 WMSetLabelImagePosition(panel
->iLbl
, WIPImageOnly
);
292 WMMapWidget(panel
->iLbl
);
293 WMAddBoxSubview(hbox
, WMWidgetView(panel
->iLbl
), False
, True
, 64, 0, 10);
294 icon
= WMCreateApplicationIconBlendedPixmap(scrPtr
, (RColor
*) NULL
);
296 WMSetLabelImage(panel
->iLbl
, icon
);
297 WMReleasePixmap(icon
);
299 WMSetLabelImage(panel
->iLbl
, scrPtr
->applicationIconPixmap
);
305 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
307 panel
->tLbl
= WMCreateLabel(hbox
);
308 WMMapWidget(panel
->tLbl
);
309 WMAddBoxSubview(hbox
, WMWidgetView(panel
->tLbl
), True
, True
, 64, 0, 0);
310 WMSetLabelText(panel
->tLbl
, title
);
311 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
312 WMSetLabelFont(panel
->tLbl
, largeFont
);
314 WMReleaseFont(largeFont
);
317 /* create divider line */
319 panel
->line
= WMCreateFrame(panel
->win
);
320 WMMapWidget(panel
->line
);
321 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->line
), False
, True
, 2, 2, WMScaleY(5));
322 WMSetFrameRelief(panel
->line
, WRGroove
);
325 panel
->mLbl
= WMCreateLabel(panel
->vbox
);
326 WMSetLabelWraps(panel
->mLbl
, True
);
327 WMMapWidget(panel
->mLbl
);
328 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->mLbl
), True
, True
,
329 WMFontHeight(scrPtr
->normalFont
) * 4, 0, WMScaleY(5));
330 WMSetLabelText(panel
->mLbl
, msg
);
331 WMSetLabelTextAlignment(panel
->mLbl
, WACenter
);
334 panel
->hbox
= WMCreateBox(panel
->vbox
);
335 WMSetBoxBorderWidth(panel
->hbox
, WMScaleX(10));
336 WMSetBoxHorizontal(panel
->hbox
, True
);
337 WMMapWidget(panel
->hbox
);
338 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->hbox
), False
, True
, WMScaleY(44), 0, 0);
342 ow
= WMWidthOfString(scrPtr
->normalFont
, otherButton
, strlen(otherButton
));
345 aw
= WMWidthOfString(scrPtr
->normalFont
, alternateButton
, strlen(alternateButton
));
348 dw
= WMWidthOfString(scrPtr
->normalFont
, defaultButton
, strlen(defaultButton
));
350 dw
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
356 w
= WMAX(dw
, WMAX(aw
, ow
));
357 if ((w
+ WMScaleX(10)) * 3 < pwidth
) {
364 t
= pwidth
- 4 * WMScaleX(10) - aw
- ow
- dw
;
371 panel
->defBtn
= WMCreateCommandButton(panel
->hbox
);
372 WMResizeWidget(panel
->defBtn
, dw
, WMScaleY(24));
373 WMSetButtonAction(panel
->defBtn
, alertPanelOnClick
, panel
);
374 WMAddBoxSubviewAtEnd(panel
->hbox
, WMWidgetView(panel
->defBtn
), False
, True
, dw
, 0, 0);
375 WMSetButtonText(panel
->defBtn
, defaultButton
);
376 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
377 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
378 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
380 if (alternateButton
) {
381 panel
->altBtn
= WMCreateCommandButton(panel
->hbox
);
382 WMResizeWidget(panel
->altBtn
, aw
, WMScaleY(24));
383 WMAddBoxSubviewAtEnd(panel
->hbox
, WMWidgetView(panel
->altBtn
), False
, True
, aw
, 0, WMScaleX(5));
384 WMSetButtonAction(panel
->altBtn
, alertPanelOnClick
, panel
);
385 WMSetButtonText(panel
->altBtn
, alternateButton
);
388 panel
->othBtn
= WMCreateCommandButton(panel
->hbox
);
389 WMResizeWidget(panel
->othBtn
, ow
, WMScaleY(24));
390 WMSetButtonAction(panel
->othBtn
, alertPanelOnClick
, panel
);
391 WMAddBoxSubviewAtEnd(panel
->hbox
, WMWidgetView(panel
->othBtn
), False
, True
, ow
, 0, WMScaleX(5));
392 WMSetButtonText(panel
->othBtn
, otherButton
);
395 WMMapSubwidgets(panel
->hbox
);
397 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
, handleKeyPress
, panel
);
399 WMRealizeWidget(panel
->win
);
400 WMMapSubwidgets(panel
->win
);
405 static void inputBoxOnClick(WMWidget
* self
, void *clientData
)
407 WMInputPanel
*panel
= clientData
;
409 WMBreakModalLoop(WMWidgetScreen(self
));
410 if (self
== panel
->defBtn
) {
411 panel
->result
= WAPRDefault
;
412 } else if (self
== panel
->altBtn
) {
413 panel
->result
= WAPRAlternate
;
417 static void handleKeyPress2(XEvent
* event
, void *clientData
)
419 WMInputPanel
*panel
= (WMInputPanel
*) clientData
;
422 XLookupString(&event
->xkey
, NULL
, 0, &ksym
, NULL
);
424 if ((ksym
== XK_Return
|| ksym
== XK_KP_Enter
) && panel
->defBtn
) {
425 WMPerformButtonClick(panel
->defBtn
);
426 } else if (ksym
== XK_Escape
) {
428 WMPerformButtonClick(panel
->altBtn
);
430 /* printf("got esc\n"); */
431 WMBreakModalLoop(WMWidgetScreen(panel
->win
));
432 panel
->result
= WAPRDefault
;
437 char *WMRunInputPanel(WMScreen
* scrPtr
, WMWindow
* owner
, const char *title
,
438 const char *msg
, const char *defaultText
, const char *okButton
, const char *cancelButton
)
443 panel
= WMCreateInputPanel(scrPtr
, owner
, title
, msg
, defaultText
, okButton
, cancelButton
);
447 WMView
*view
= WMWidgetView(panel
->win
);
450 WMView
*oview
= WMWidgetView(owner
);
451 WMPoint pt
= WMGetViewScreenPosition(oview
);
453 px
= (W_VIEW_WIDTH(oview
) - W_VIEW_WIDTH(view
)) / 2;
454 py
= (W_VIEW_HEIGHT(oview
) - W_VIEW_HEIGHT(view
)) / 2;
459 px
= (W_VIEW_WIDTH(scrPtr
->rootView
) - W_VIEW_WIDTH(view
)) / 2;
460 py
= (W_VIEW_HEIGHT(scrPtr
->rootView
) - W_VIEW_HEIGHT(view
)) / 2;
462 WMSetWindowInitialPosition(panel
->win
, px
, py
);
465 WMMapWidget(panel
->win
);
467 WMRunModalLoop(scrPtr
, W_VIEW(panel
->win
));
469 if (panel
->result
== WAPRDefault
)
470 tmp
= WMGetTextFieldText(panel
->text
);
474 WMDestroyInputPanel(panel
);
479 void WMDestroyInputPanel(WMInputPanel
* panel
)
481 WMRemoveNotificationObserver(panel
);
482 WMUnmapWidget(panel
->win
);
483 WMDestroyWidget(panel
->win
);
487 static void endedEditingObserver(void *observerData
, WMNotification
* notification
)
489 WMInputPanel
*panel
= (WMInputPanel
*) observerData
;
491 switch ((uintptr_t)WMGetNotificationClientData(notification
)) {
492 case WMReturnTextMovement
:
494 WMPerformButtonClick(panel
->defBtn
);
496 case WMEscapeTextMovement
:
498 WMPerformButtonClick(panel
->altBtn
);
500 WMBreakModalLoop(WMWidgetScreen(panel
->win
));
501 panel
->result
= WAPRDefault
;
509 WMInputPanel
*WMCreateInputPanel(WMScreen
* scrPtr
, WMWindow
* owner
, const char *title
, const char *msg
,
510 const char *defaultText
, const char *okButton
, const char *cancelButton
)
514 int x
, dw
= 0, aw
= 0, w
;
516 defaultFont
= WMSystemFontOfSize(scrPtr
, 12);
517 panel
= wmalloc(sizeof(WMInputPanel
));
520 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "inputPanel", WMTitledWindowMask
);
522 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "inputPanel", WMTitledWindowMask
);
523 WMSetWindowTitle(panel
->win
, "");
525 WMResizeWidget(panel
->win
, 320, 160);
530 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
532 panel
->tLbl
= WMCreateLabel(panel
->win
);
533 WMMoveWidget(panel
->tLbl
, 20, 16);
534 WMResizeWidget(panel
->tLbl
, 320 - 40, WMFontHeight(largeFont
) + 4);
535 WMSetLabelText(panel
->tLbl
, title
);
536 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
537 WMSetLabelFont(panel
->tLbl
, largeFont
);
539 WMReleaseFont(largeFont
);
543 panel
->mLbl
= WMCreateLabel(panel
->win
);
544 WMMoveWidget(panel
->mLbl
, 20, 50);
545 WMResizeWidget(panel
->mLbl
, 320 - 40, WMFontHeight(scrPtr
->normalFont
) * 2);
546 WMSetLabelText(panel
->mLbl
, msg
);
547 WMSetLabelTextAlignment(panel
->mLbl
, WALeft
);
548 WMSetLabelFont(panel
->mLbl
, defaultFont
);
551 panel
->text
= WMCreateTextField(panel
->win
);
552 WMMoveWidget(panel
->text
, 20, 85);
553 WMResizeWidget(panel
->text
, 320 - 40, WMWidgetHeight(panel
->text
));
554 WMSetTextFieldText(panel
->text
, defaultText
);
555 WMSetTextFieldFont(panel
->text
, defaultFont
);
557 WMAddNotificationObserver(endedEditingObserver
, panel
, WMTextDidEndEditingNotification
, panel
->text
);
561 aw
= WMWidthOfString(defaultFont
, cancelButton
, strlen(cancelButton
));
564 dw
= WMWidthOfString(defaultFont
, okButton
, strlen(okButton
));
566 w
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
576 panel
->defBtn
= WMCreateCustomButton(panel
->win
, WBBPushInMask
577 | WBBPushChangeMask
| WBBPushLightMask
);
578 WMSetButtonAction(panel
->defBtn
, inputBoxOnClick
, panel
);
579 WMMoveWidget(panel
->defBtn
, x
, 124);
580 WMResizeWidget(panel
->defBtn
, w
, 24);
581 WMSetButtonText(panel
->defBtn
, okButton
);
582 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
583 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
584 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
585 WMSetButtonFont(panel
->defBtn
, defaultFont
);
590 panel
->altBtn
= WMCreateCommandButton(panel
->win
);
591 WMSetButtonAction(panel
->altBtn
, inputBoxOnClick
, panel
);
592 WMMoveWidget(panel
->altBtn
, x
, 124);
593 WMResizeWidget(panel
->altBtn
, w
, 24);
594 WMSetButtonText(panel
->altBtn
, cancelButton
);
595 WMSetButtonFont(panel
->altBtn
, defaultFont
);
598 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
, handleKeyPress2
, panel
);
600 WMRealizeWidget(panel
->win
);
601 WMMapSubwidgets(panel
->win
);
603 WMSetFocusToWidget(panel
->text
);
605 WMReleaseFont(defaultFont
);
610 WMInputPanel
*WMCreateScaledInputPanel(WMScreen
* scrPtr
, WMWindow
* owner
, const char *title
, const char *msg
,
611 const char *defaultText
, const char *okButton
, const char *cancelButton
)
614 int x
, dw
= 0, aw
= 0, w
;
615 int wmScaleWidth
, wmScaleHeight
;
617 panel
= wmalloc(sizeof(WMInputPanel
));
620 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "inputPanel", WMTitledWindowMask
);
622 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "inputPanel", WMTitledWindowMask
);
623 WMSetWindowTitle(panel
->win
, "");
625 WMGetScaleBaseFromSystemFont(scrPtr
, &wmScaleWidth
, &wmScaleHeight
);
626 WMResizeWidget(panel
->win
, WMScaleX(320), WMScaleY(160));
631 largeFont
= WMBoldSystemFontOfSize(scrPtr
, WMScaleY(24));
633 panel
->tLbl
= WMCreateLabel(panel
->win
);
634 WMMoveWidget(panel
->tLbl
, WMScaleX(20), WMScaleY(16));
635 WMResizeWidget(panel
->tLbl
, WMScaleX(320) - 2 * WMScaleX(20), WMFontHeight(largeFont
) + WMScaleY(4));
636 WMSetLabelText(panel
->tLbl
, title
);
637 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
638 WMSetLabelFont(panel
->tLbl
, largeFont
);
640 WMReleaseFont(largeFont
);
644 panel
->mLbl
= WMCreateLabel(panel
->win
);
645 WMMoveWidget(panel
->mLbl
, WMScaleX(20), WMScaleY(50));
646 WMResizeWidget(panel
->mLbl
, WMScaleX(320) - 2 * WMScaleX(20), WMFontHeight(scrPtr
->normalFont
) * 2);
647 WMSetLabelText(panel
->mLbl
, msg
);
648 WMSetLabelTextAlignment(panel
->mLbl
, WALeft
);
651 panel
->text
= WMCreateTextField(panel
->win
);
652 WMMoveWidget(panel
->text
, WMScaleX(20), WMScaleY(85));
653 WMResizeWidget(panel
->text
, WMScaleX(320) - 2 * WMScaleX(20), WMScaleY(20));
654 WMSetTextFieldText(panel
->text
, defaultText
);
656 WMAddNotificationObserver(endedEditingObserver
, panel
, WMTextDidEndEditingNotification
, panel
->text
);
660 aw
= WMWidthOfString(scrPtr
->normalFont
, cancelButton
, strlen(cancelButton
));
663 dw
= WMWidthOfString(scrPtr
->normalFont
, okButton
, strlen(okButton
));
665 w
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
673 x
-= w
+ WMScaleX(10);
675 panel
->defBtn
= WMCreateCustomButton(panel
->win
, WBBPushInMask
676 | WBBPushChangeMask
| WBBPushLightMask
);
677 WMSetButtonAction(panel
->defBtn
, inputBoxOnClick
, panel
);
678 WMMoveWidget(panel
->defBtn
, x
, WMScaleY(124));
679 WMResizeWidget(panel
->defBtn
, w
, WMScaleY(24));
680 WMSetButtonText(panel
->defBtn
, okButton
);
681 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
682 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
683 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
686 x
-= w
+ WMScaleX(10);
688 panel
->altBtn
= WMCreateCommandButton(panel
->win
);
689 WMSetButtonAction(panel
->altBtn
, inputBoxOnClick
, panel
);
690 WMMoveWidget(panel
->altBtn
, x
, WMScaleY(124));
691 WMResizeWidget(panel
->altBtn
, w
, WMScaleY(24));
692 WMSetButtonText(panel
->altBtn
, cancelButton
);
695 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
, handleKeyPress2
, panel
);
697 WMRealizeWidget(panel
->win
);
698 WMMapSubwidgets(panel
->win
);
700 WMSetFocusToWidget(panel
->text
);
705 static void handleKeyPress3(XEvent
* event
, void *clientData
)
707 WMGenericPanel
*panel
= (WMGenericPanel
*) clientData
;
710 XLookupString(&event
->xkey
, NULL
, 0, &ksym
, NULL
);
712 if ((ksym
== XK_Return
|| ksym
== XK_KP_Enter
) && panel
->defBtn
) {
713 WMPerformButtonClick(panel
->defBtn
);
714 } else if (ksym
== XK_Escape
) {
716 WMPerformButtonClick(panel
->altBtn
);
718 panel
->result
= WAPRDefault
;
719 WMBreakModalLoop(WMWidgetScreen(panel
->win
));
724 void WMDestroyGenericPanel(WMGenericPanel
* panel
)
726 WMUnmapWidget(panel
->win
);
727 WMDestroyWidget(panel
->win
);
731 WMGenericPanel
*WMCreateGenericPanel(WMScreen
* scrPtr
, WMWindow
* owner
,
732 const char *title
, const char *defaultButton
, const char *alternateButton
)
734 WMGenericPanel
*panel
;
736 int dw
= 0, aw
= 0, w
;
740 defaultFont
= WMSystemFontOfSize(scrPtr
, 12);
741 panel
= wmalloc(sizeof(WMGenericPanel
));
744 panel
->win
= WMCreatePanelWithStyleForWindow(owner
, "genericPanel", WMTitledWindowMask
);
746 panel
->win
= WMCreateWindowWithStyle(scrPtr
, "genericPanel", WMTitledWindowMask
);
749 WMSetWindowInitialPosition(panel
->win
,
750 (scrPtr
->rootView
->size
.width
- WMWidgetWidth(panel
->win
)) / 2,
751 (scrPtr
->rootView
->size
.height
- WMWidgetHeight(panel
->win
)) / 2);
753 WMSetWindowTitle(panel
->win
, "");
755 panel
->vbox
= WMCreateBox(panel
->win
);
756 WMSetViewExpandsToParent(WMWidgetView(panel
->vbox
), 0, 0, 0, 0);
757 WMSetBoxHorizontal(panel
->vbox
, False
);
758 WMMapWidget(panel
->vbox
);
760 hbox
= WMCreateBox(panel
->vbox
);
761 WMSetBoxBorderWidth(hbox
, 5);
762 WMSetBoxHorizontal(hbox
, True
);
764 WMAddBoxSubview(panel
->vbox
, WMWidgetView(hbox
), False
, True
, 74, 0, 5);
766 panel
->iLbl
= WMCreateLabel(hbox
);
767 WMSetLabelImagePosition(panel
->iLbl
, WIPImageOnly
);
768 WMMapWidget(panel
->iLbl
);
769 WMAddBoxSubview(hbox
, WMWidgetView(panel
->iLbl
), False
, True
, 64, 0, 10);
770 icon
= WMCreateApplicationIconBlendedPixmap(scrPtr
, (RColor
*) NULL
);
772 WMSetLabelImage(panel
->iLbl
, icon
);
773 WMReleasePixmap(icon
);
775 WMSetLabelImage(panel
->iLbl
, scrPtr
->applicationIconPixmap
);
781 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
783 panel
->tLbl
= WMCreateLabel(hbox
);
784 WMMapWidget(panel
->tLbl
);
785 WMAddBoxSubview(hbox
, WMWidgetView(panel
->tLbl
), True
, True
, 64, 0, 0);
786 WMSetLabelText(panel
->tLbl
, title
);
787 WMSetLabelTextAlignment(panel
->tLbl
, WALeft
);
788 WMSetLabelFont(panel
->tLbl
, largeFont
);
790 WMReleaseFont(largeFont
);
793 /* create divider line */
795 panel
->line
= WMCreateFrame(panel
->vbox
);
796 WMMapWidget(panel
->line
);
797 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->line
), False
, True
, 2, 2, 5);
798 WMSetFrameRelief(panel
->line
, WRGroove
);
800 panel
->content
= WMCreateFrame(panel
->vbox
);
801 WMMapWidget(panel
->content
);
802 WMAddBoxSubview(panel
->vbox
, WMWidgetView(panel
->content
), True
, True
, 50, 0, 5);
803 WMSetFrameRelief(panel
->content
, WRFlat
);
805 hbox
= WMCreateBox(panel
->vbox
);
806 WMSetBoxBorderWidth(hbox
, 10);
807 WMSetBoxHorizontal(hbox
, True
);
809 WMAddBoxSubview(panel
->vbox
, WMWidgetView(hbox
), False
, True
, 44, 0, 0);
813 dw
= WMWidthOfString(defaultFont
, defaultButton
, strlen(defaultButton
));
816 aw
= WMWidthOfString(defaultFont
, alternateButton
, strlen(alternateButton
));
818 dw
= dw
+ (scrPtr
->buttonArrow
? scrPtr
->buttonArrow
->width
: 0);
824 if ((w
+ 10) * 2 < 400) {
829 t
= 400 - 40 - aw
- dw
;
834 panel
->defBtn
= WMCreateCommandButton(hbox
);
835 WMSetButtonAction(panel
->defBtn
, alertPanelOnClick
, panel
);
836 WMAddBoxSubviewAtEnd(hbox
, WMWidgetView(panel
->defBtn
), False
, True
, dw
, 0, 0);
837 WMSetButtonText(panel
->defBtn
, defaultButton
);
838 WMSetButtonImage(panel
->defBtn
, scrPtr
->buttonArrow
);
839 WMSetButtonAltImage(panel
->defBtn
, scrPtr
->pushedButtonArrow
);
840 WMSetButtonImagePosition(panel
->defBtn
, WIPRight
);
841 WMSetButtonFont(panel
->defBtn
, defaultFont
);
844 WMMapSubwidgets(hbox
);
846 WMCreateEventHandler(W_VIEW(panel
->win
), KeyPressMask
, handleKeyPress3
, panel
);
848 WMRealizeWidget(panel
->win
);
849 WMMapSubwidgets(panel
->win
);
851 WMReleaseFont(defaultFont
);