1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 12:28:22 +01:00

- Fixed a bug in popup button code.

- Added functions to allow the color of the text in buttons to be specified.
This commit is contained in:
dan
2000-01-05 22:02:22 +00:00
parent d5f177fe66
commit dba6e4d2d0
4 changed files with 95 additions and 22 deletions

View File

@@ -825,6 +825,12 @@ void WMSetButtonText(WMButton *bPtr, char *text);
void WMSetButtonAltText(WMButton *bPtr, char *text);
void WMSetButtonTextColor(WMButton *bPtr, WMColor *color);
void WMSetButtonAltTextColor(WMButton *bPtr, WMColor *color);
void WMSetButtonDisabledTextColor(WMButton *bPtr, WMColor *color);
void WMSetButtonSelected(WMButton *bPtr, int isSelected);
int WMGetButtonSelected(WMButton *bPtr);

View File

@@ -14,6 +14,10 @@ typedef struct W_Button {
WMFont *font;
WMColor *textColor;
WMColor *altTextColor;
WMColor *disTextColor;
W_Pixmap *image;
W_Pixmap *altImage;
@@ -373,6 +377,36 @@ WMSetButtonAltText(WMButton *bPtr, char *text)
}
void
WMSetButtonTextColor(WMButton *bPtr, WMColor *color)
{
if (bPtr->textColor)
WMReleaseColor(bPtr->textColor);
bPtr->textColor = WMRetainColor(color);
}
void
WMSetButtonAltTextColor(WMButton *bPtr, WMColor *color)
{
if (bPtr->altTextColor)
WMReleaseColor(bPtr->altTextColor);
bPtr->altTextColor = WMRetainColor(color);
}
void
WMSetButtonDisabledTextColor(WMButton *bPtr, WMColor *color)
{
if (bPtr->disTextColor)
WMReleaseColor(bPtr->disTextColor);
bPtr->disTextColor = WMRetainColor(color);
}
void
WMSetButtonSelected(WMButton *bPtr, int isSelected)
{
@@ -545,15 +579,24 @@ static void
paintButton(Button *bPtr)
{
W_Screen *scrPtr = bPtr->view->screen;
GC gc;
WMReliefType relief;
int offset;
char *caption;
WMPixmap *image;
GC textGC;
WMColor *textColor;
GC gc;
gc = NULL;
caption = bPtr->caption;
if (bPtr->flags.enabled) {
textColor = (bPtr->textColor!=NULL
? bPtr->textColor : scrPtr->black);
} else {
textColor = (bPtr->disTextColor!=NULL
? bPtr->disTextColor : scrPtr->darkGray);
}
if (bPtr->flags.enabled || !bPtr->dimage)
image = bPtr->image;
else
@@ -565,16 +608,19 @@ paintButton(Button *bPtr)
relief = WRFlat;
if (bPtr->flags.selected) {
if (bPtr->flags.stateLight)
gc = WMColorGC(scrPtr->white);
if (bPtr->flags.stateLight) {
gc = WMColorGC(scrPtr->white);
textColor = scrPtr->black;
}
if (bPtr->flags.stateChange) {
if (bPtr->altCaption) {
if (bPtr->altCaption)
caption = bPtr->altCaption;
}
if (bPtr->altImage)
image = bPtr->altImage;
}
if (bPtr->altTextColor)
textColor = bPtr->altTextColor;
}
if (bPtr->flags.statePush && bPtr->flags.bordered) {
relief = WRSunken;
@@ -587,25 +633,22 @@ paintButton(Button *bPtr)
relief = WRPushed;
offset = 1;
}
if (bPtr->flags.pushLight)
gc = WMColorGC(scrPtr->white);
if (bPtr->flags.pushLight) {
gc = WMColorGC(scrPtr->white);
textColor = scrPtr->black;
}
if (bPtr->flags.pushChange) {
if (bPtr->altCaption) {
if (bPtr->altCaption)
caption = bPtr->altCaption;
}
if (bPtr->altImage)
image = bPtr->altImage;
if (bPtr->altTextColor)
textColor = bPtr->altTextColor;
}
}
if (bPtr->flags.enabled)
textGC = WMColorGC(scrPtr->black);
else
textGC = WMColorGC(scrPtr->darkGray);
W_PaintTextAndImage(bPtr->view, True, textGC,
W_PaintTextAndImage(bPtr->view, True, WMColorGC(textColor),
(bPtr->font!=NULL ? bPtr->font : scrPtr->normalFont),
relief, caption, bPtr->flags.alignment, image,
bPtr->flags.imagePosition, gc, offset);
@@ -756,7 +799,16 @@ destroyButton(Button *bPtr)
if (bPtr->altCaption)
wfree(bPtr->altCaption);
if (bPtr->textColor)
WMReleaseColor(bPtr->textColor);
if (bPtr->altTextColor)
WMReleaseColor(bPtr->altTextColor);
if (bPtr->disTextColor)
WMReleaseColor(bPtr->disTextColor);
if (bPtr->image)
WMReleasePixmap(bPtr->image);

View File

@@ -93,6 +93,8 @@ WMCreatePopUpButton(WMWidget *parent)
bPtr->items = WMCreateBag(4);
bPtr->selectedItemIndex = -1;
bPtr->menuView = W_CreateTopView(scr);
bPtr->menuView->attribs.override_redirect = True;
bPtr->menuView->attribFlags |= CWOverrideRedirect;

View File

@@ -104,7 +104,7 @@ testGradientButtons(WMScreen *scr)
WMPixmap *pix1, *pix2;
RImage *back;
RColor light, dark;
WMColor *color;
WMColor *color, *altColor;
windowCount++;
@@ -134,6 +134,9 @@ testGradientButtons(WMScreen *scr)
pix2 = WMCreatePixmapFromRImage(scr, back, 0);
RDestroyImage(back);
color = WMWhiteColor(scr);
altColor = WMCreateNamedColor(scr, "red", True);
btn = WMCreateButton(win, WBTMomentaryChange);
WMResizeWidget(btn, 60, 24);
WMMoveWidget(btn, 20, 100);
@@ -142,8 +145,10 @@ testGradientButtons(WMScreen *scr)
WMSetButtonImage(btn, pix1);
WMSetButtonAltImage(btn, pix2);
WMSetButtonText(btn, "Cool");
WMSetButtonTextColor(btn, color);
WMSetButtonAltTextColor(btn, altColor);
WMSetBalloonTextForView("This is a button", WMWidgetView(btn));
WMSetBalloonTextForView("This is a cool button", WMWidgetView(btn));
btn = WMCreateButton(win, WBTMomentaryChange);
WMResizeWidget(btn, 60, 24);
@@ -153,9 +158,13 @@ testGradientButtons(WMScreen *scr)
WMSetButtonImage(btn, pix1);
WMSetButtonAltImage(btn, pix2);
WMSetButtonText(btn, "Button");
WMSetButtonTextColor(btn, color);
WMSetBalloonTextForView("Este é outro balão.", WMWidgetView(btn));
WMReleaseColor(color);
color = WMCreateNamedColor(scr, "orange", True);
btn = WMCreateButton(win, WBTMomentaryChange);
WMResizeWidget(btn, 60, 24);
WMMoveWidget(btn, 160, 100);
@@ -164,10 +173,14 @@ testGradientButtons(WMScreen *scr)
WMSetButtonImage(btn, pix1);
WMSetButtonAltImage(btn, pix2);
WMSetButtonText(btn, "Test");
WMSetButtonTextColor(btn, color);
WMSetBalloonTextForView("This is yet another button.\nBut the balloon has 3 lines.\nYay!",
WMWidgetView(btn));
WMReleaseColor(color);
WMReleaseColor(altColor);
WMRealizeWidget(win);
WMMapSubwidgets(win);
WMMapWidget(win);
@@ -680,10 +693,10 @@ int main(int argc, char **argv)
testSplitView(scr);
testFontPanel(scr);
testGradientButtons(scr);
#if 0
testProgressIndicator(scr);
testGradientButtons(scr);
testColorWell(scr);
testTabView(scr);