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 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); void WMSetButtonSelected(WMButton *bPtr, int isSelected);
int WMGetButtonSelected(WMButton *bPtr); int WMGetButtonSelected(WMButton *bPtr);

View File

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

View File

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

View File

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