From c803218ed1970d09541a125f47a4e24076f3ada0 Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Tue, 18 Jun 2019 21:17:27 +0200 Subject: [PATCH] New functions for the creation of scaled panels (WMCreateScaled*Panel) To prevent breaking applications depending on the static layout behavior of the WMCreateAlertPanel and WMCreateInputPanel functions in WINGs, the scaling functionality has been moved to the new functions WMCreateScaledAlertPanel and WMCreateScaledInputPanel. The system dialogs (wMessageDialog, wExitDialog, etc.) now use the new functions, thus keeping the improved layout introduced in the previous patches. --- WINGs/WINGs/WINGs.h | 7 ++ WINGs/wpanel.c | 239 ++++++++++++++++++++++++++++++++++++++++++++ src/dialog.c | 8 +- 3 files changed, 250 insertions(+), 4 deletions(-) diff --git a/WINGs/WINGs/WINGs.h b/WINGs/WINGs/WINGs.h index 5ccf24b6..9b99c92a 100644 --- a/WINGs/WINGs/WINGs.h +++ b/WINGs/WINGs/WINGs.h @@ -1841,10 +1841,17 @@ WMAlertPanel* WMCreateAlertPanel(WMScreen *app, WMWindow *owner, const char *tit const char *msg, const char *defaultButton, const char *alternateButton, const char *otherButton); +WMAlertPanel* WMCreateScaledAlertPanel(WMScreen *app, WMWindow *owner, const char *title, + const char *msg, const char *defaultButton, + const char *alternateButton, const char *otherButton); + WMInputPanel* WMCreateInputPanel(WMScreen *app, WMWindow *owner, const char *title, const char *msg, const char *defaultText, const char *okButton, const char *cancelButton); +WMInputPanel* WMCreateScaledInputPanel(WMScreen *app, WMWindow *owner, const char *title, + const char *msg, const char *defaultText, const char *okButton, + const char *cancelButton); WMGenericPanel* WMCreateGenericPanel(WMScreen *scrPtr, WMWindow *owner, const char *title, const char *defaultButton, diff --git a/WINGs/wpanel.c b/WINGs/wpanel.c index f8b730eb..58d9bd6f 100644 --- a/WINGs/wpanel.c +++ b/WINGs/wpanel.c @@ -92,6 +92,152 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner, int dw = 0, aw = 0, ow = 0, w; WMBox *hbox; WMPixmap *icon; + + panel = wmalloc(sizeof(WMAlertPanel)); + + if (owner) { + panel->win = WMCreatePanelWithStyleForWindow(owner, "alertPanel", WMTitledWindowMask); + } else { + panel->win = WMCreateWindowWithStyle(scrPtr, "alertPanel", WMTitledWindowMask); + } + + WMSetWindowInitialPosition(panel->win, + (scrPtr->rootView->size.width - WMWidgetWidth(panel->win)) / 2, + (scrPtr->rootView->size.height - WMWidgetHeight(panel->win)) / 2); + + WMSetWindowTitle(panel->win, ""); + + panel->vbox = WMCreateBox(panel->win); + WMSetViewExpandsToParent(WMWidgetView(panel->vbox), 0, 0, 0, 0); + WMSetBoxHorizontal(panel->vbox, False); + WMMapWidget(panel->vbox); + + hbox = WMCreateBox(panel->vbox); + WMSetBoxBorderWidth(hbox, 5); + WMSetBoxHorizontal(hbox, True); + WMMapWidget(hbox); + WMAddBoxSubview(panel->vbox, WMWidgetView(hbox), False, True, 74, 0, 5); + + panel->iLbl = WMCreateLabel(hbox); + WMSetLabelImagePosition(panel->iLbl, WIPImageOnly); + WMMapWidget(panel->iLbl); + WMAddBoxSubview(hbox, WMWidgetView(panel->iLbl), False, True, 64, 0, 10); + icon = WMCreateApplicationIconBlendedPixmap(scrPtr, (RColor *) NULL); + if (icon) { + WMSetLabelImage(panel->iLbl, icon); + WMReleasePixmap(icon); + } else { + WMSetLabelImage(panel->iLbl, scrPtr->applicationIconPixmap); + } + + if (title) { + WMFont *largeFont; + + largeFont = WMBoldSystemFontOfSize(scrPtr, 24); + + panel->tLbl = WMCreateLabel(hbox); + WMMapWidget(panel->tLbl); + WMAddBoxSubview(hbox, WMWidgetView(panel->tLbl), True, True, 64, 0, 0); + WMSetLabelText(panel->tLbl, title); + WMSetLabelTextAlignment(panel->tLbl, WALeft); + WMSetLabelFont(panel->tLbl, largeFont); + + WMReleaseFont(largeFont); + } + + /* create divider line */ + + panel->line = WMCreateFrame(panel->win); + WMMapWidget(panel->line); + WMAddBoxSubview(panel->vbox, WMWidgetView(panel->line), False, True, 2, 2, 5); + WMSetFrameRelief(panel->line, WRGroove); + + if (msg) { + panel->mLbl = WMCreateLabel(panel->vbox); + WMSetLabelWraps(panel->mLbl, True); + WMMapWidget(panel->mLbl); + WMAddBoxSubview(panel->vbox, WMWidgetView(panel->mLbl), True, True, + WMFontHeight(scrPtr->normalFont) * 4, 0, 5); + WMSetLabelText(panel->mLbl, msg); + WMSetLabelTextAlignment(panel->mLbl, WACenter); + } + + panel->hbox = WMCreateBox(panel->vbox); + WMSetBoxBorderWidth(panel->hbox, 10); + WMSetBoxHorizontal(panel->hbox, True); + WMMapWidget(panel->hbox); + WMAddBoxSubview(panel->vbox, WMWidgetView(panel->hbox), False, True, 44, 0, 0); + + /* create buttons */ + if (otherButton) + ow = WMWidthOfString(scrPtr->normalFont, otherButton, strlen(otherButton)); + + if (alternateButton) + aw = WMWidthOfString(scrPtr->normalFont, alternateButton, strlen(alternateButton)); + + if (defaultButton) + dw = WMWidthOfString(scrPtr->normalFont, defaultButton, strlen(defaultButton)); + + dw = dw + (scrPtr->buttonArrow ? scrPtr->buttonArrow->width : 0); + + aw += 30; + ow += 30; + dw += 30; + + w = WMAX(dw, WMAX(aw, ow)); + if ((w + 10) * 3 < 400) { + aw = w; + ow = w; + dw = w; + } else { + int t; + + t = 400 - 40 - aw - ow - dw; + aw += t / 3; + ow += t / 3; + dw += t / 3; + } + + if (defaultButton) { + panel->defBtn = WMCreateCommandButton(panel->hbox); + WMSetButtonAction(panel->defBtn, alertPanelOnClick, panel); + WMAddBoxSubviewAtEnd(panel->hbox, WMWidgetView(panel->defBtn), False, True, dw, 0, 0); + WMSetButtonText(panel->defBtn, defaultButton); + WMSetButtonImage(panel->defBtn, scrPtr->buttonArrow); + WMSetButtonAltImage(panel->defBtn, scrPtr->pushedButtonArrow); + WMSetButtonImagePosition(panel->defBtn, WIPRight); + } + if (alternateButton) { + panel->altBtn = WMCreateCommandButton(panel->hbox); + WMAddBoxSubviewAtEnd(panel->hbox, WMWidgetView(panel->altBtn), False, True, aw, 0, 5); + WMSetButtonAction(panel->altBtn, alertPanelOnClick, panel); + WMSetButtonText(panel->altBtn, alternateButton); + } + if (otherButton) { + panel->othBtn = WMCreateCommandButton(panel->hbox); + WMSetButtonAction(panel->othBtn, alertPanelOnClick, panel); + WMAddBoxSubviewAtEnd(panel->hbox, WMWidgetView(panel->othBtn), False, True, ow, 0, 5); + WMSetButtonText(panel->othBtn, otherButton); + } + + WMMapSubwidgets(panel->hbox); + + WMCreateEventHandler(W_VIEW(panel->win), KeyPressMask, handleKeyPress, panel); + + WMRealizeWidget(panel->win); + WMMapSubwidgets(panel->win); + + return panel; +} + +WMAlertPanel *WMCreateScaledAlertPanel(WMScreen * scrPtr, WMWindow * owner, + const char *title, const char *msg, const char *defaultButton, + const char *alternateButton, const char *otherButton) +{ + WMAlertPanel *panel; + int dw = 0, aw = 0, ow = 0, w; + WMBox *hbox; + WMPixmap *icon; int fw, fh; int pwidth, pheight; @@ -357,6 +503,99 @@ WMInputPanel *WMCreateInputPanel(WMScreen * scrPtr, WMWindow * owner, const char { WMInputPanel *panel; int x, dw = 0, aw = 0, w; + + panel = wmalloc(sizeof(WMInputPanel)); + + if (owner) + panel->win = WMCreatePanelWithStyleForWindow(owner, "inputPanel", WMTitledWindowMask); + else + panel->win = WMCreateWindowWithStyle(scrPtr, "inputPanel", WMTitledWindowMask); + WMSetWindowTitle(panel->win, ""); + + WMResizeWidget(panel->win, 320, 160); + + if (title) { + WMFont *largeFont; + + largeFont = WMBoldSystemFontOfSize(scrPtr, 24); + + panel->tLbl = WMCreateLabel(panel->win); + WMMoveWidget(panel->tLbl, 20, 16); + WMResizeWidget(panel->tLbl, 320 - 40, WMFontHeight(largeFont) + 4); + WMSetLabelText(panel->tLbl, title); + WMSetLabelTextAlignment(panel->tLbl, WALeft); + WMSetLabelFont(panel->tLbl, largeFont); + + WMReleaseFont(largeFont); + } + + if (msg) { + panel->mLbl = WMCreateLabel(panel->win); + WMMoveWidget(panel->mLbl, 20, 50); + WMResizeWidget(panel->mLbl, 320 - 40, WMFontHeight(scrPtr->normalFont) * 2); + WMSetLabelText(panel->mLbl, msg); + WMSetLabelTextAlignment(panel->mLbl, WALeft); + } + + panel->text = WMCreateTextField(panel->win); + WMMoveWidget(panel->text, 20, 85); + WMResizeWidget(panel->text, 320 - 40, WMWidgetHeight(panel->text)); + WMSetTextFieldText(panel->text, defaultText); + + WMAddNotificationObserver(endedEditingObserver, panel, WMTextDidEndEditingNotification, panel->text); + + /* create buttons */ + if (cancelButton) + aw = WMWidthOfString(scrPtr->normalFont, cancelButton, strlen(cancelButton)); + + if (okButton) + dw = WMWidthOfString(scrPtr->normalFont, okButton, strlen(okButton)); + + w = dw + (scrPtr->buttonArrow ? scrPtr->buttonArrow->width : 0); + if (aw > w) + w = aw; + + w += 30; + x = 310; + + if (okButton) { + x -= w + 10; + + panel->defBtn = WMCreateCustomButton(panel->win, WBBPushInMask + | WBBPushChangeMask | WBBPushLightMask); + WMSetButtonAction(panel->defBtn, inputBoxOnClick, panel); + WMMoveWidget(panel->defBtn, x, 124); + WMResizeWidget(panel->defBtn, w, 24); + WMSetButtonText(panel->defBtn, okButton); + WMSetButtonImage(panel->defBtn, scrPtr->buttonArrow); + WMSetButtonAltImage(panel->defBtn, scrPtr->pushedButtonArrow); + WMSetButtonImagePosition(panel->defBtn, WIPRight); + } + if (cancelButton) { + x -= w + 10; + + panel->altBtn = WMCreateCommandButton(panel->win); + WMSetButtonAction(panel->altBtn, inputBoxOnClick, panel); + WMMoveWidget(panel->altBtn, x, 124); + WMResizeWidget(panel->altBtn, w, 24); + WMSetButtonText(panel->altBtn, cancelButton); + } + + WMCreateEventHandler(W_VIEW(panel->win), KeyPressMask, handleKeyPress2, panel); + + WMRealizeWidget(panel->win); + WMMapSubwidgets(panel->win); + + WMSetFocusToWidget(panel->text); + + return panel; +} + +WMInputPanel *WMCreateScaledInputPanel(WMScreen * scrPtr, WMWindow * owner, const char *title, const char *msg, + const char *defaultText, const char *okButton, const char *cancelButton) +{ + WMInputPanel *panel; + int x, dw = 0, aw = 0, w; int fw, fh; panel = wmalloc(sizeof(WMInputPanel)); diff --git a/src/dialog.c b/src/dialog.c index 1d0398d3..3b8362c7 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -77,7 +77,7 @@ int wMessageDialog(WScreen *scr, const char *title, const char *message, const c WMPoint center; int pwidth, pheight; - panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message, defBtn, altBtn, othBtn); + panel = WMCreateScaledAlertPanel(scr->wmscreen, NULL, title, message, defBtn, altBtn, othBtn); pwidth = WMWidgetWidth(panel->win); pheight = WMWidgetHeight(panel->win); @@ -126,7 +126,7 @@ int wExitDialog(WScreen *scr, const char *title, const char *message, const char int result; int pwidth, pheight; - panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message, defBtn, altBtn, othBtn); + panel = WMCreateScaledAlertPanel(scr->wmscreen, NULL, title, message, defBtn, altBtn, othBtn); pwidth = WMWidgetWidth(panel->win); pheight = WMWidgetHeight(panel->win); @@ -432,7 +432,7 @@ int wAdvancedInputDialog(WScreen *scr, const char *title, const char *message, c filename = HistoryFileName(name); p = wmalloc(sizeof(WMInputPanelWithHistory)); - p->panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text, _("OK"), _("Cancel")); + p->panel = WMCreateScaledInputPanel(scr->wmscreen, NULL, title, message, *text, _("OK"), _("Cancel")); p->history = LoadHistory(filename, wPreferences.history_lines); p->histpos = 0; p->prefix = NULL; @@ -496,7 +496,7 @@ int wInputDialog(WScreen *scr, const char *title, const char *message, char **te WMPoint center; int pwidth, pheight; - panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text, _("OK"), _("Cancel")); + panel = WMCreateScaledInputPanel(scr->wmscreen, NULL, title, message, *text, _("OK"), _("Cancel")); pwidth = WMWidgetWidth(panel->win); pheight = WMWidgetHeight(panel->win);