mirror of
https://github.com/gryf/wmaker.git
synced 2026-02-10 02:25:46 +01:00
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.
This commit is contained in:
committed by
Carlos R. Mafra
parent
6c6853ea30
commit
c803218ed1
@@ -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,
|
||||
|
||||
239
WINGs/wpanel.c
239
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));
|
||||
|
||||
Reference in New Issue
Block a user