WINGs widgets use a palette of six colors.  (Essentially, just four.  There are
two colors used only for unselected tabs in tabviews.)  This patch allows a user
to declare these six colors in ~/GNUstep/Defaults/WMGLOBAL, e.g.,
{
  Background = color1;
  Foreground = color2;
  Shadow = color3;
  Highlight = color4;
  UnselectedTabBackground = color5;
  UnselectedTabHighlight = color6;
}
---
 WINGs/WINGs/WINGs.h  |  4 ++++
 WINGs/WINGs/WINGsP.h | 13 +++++++++++
 WINGs/wcolor.c       | 61 ++++++++++++++++++++++++++++++++++++++++++++++++----
 WINGs/widgets.c      |  2 ++
 WINGs/wtabview.c     |  4 ++--
 5 files changed, 78 insertions(+), 6 deletions(-)

diff --git a/WINGs/WINGs/WINGs.h b/WINGs/WINGs/WINGs.h
index 0104e03..ff9eaef 100644
--- a/WINGs/WINGs/WINGs.h
+++ b/WINGs/WINGs/WINGs.h
@@ -349,6 +349,8 @@ typedef struct W_Pixmap WMPixmap;
 typedef struct W_Font  WMFont;
 typedef struct W_Color WMColor;
 
+typedef struct WMTheme WMTheme;
+
 typedef struct W_Screen WMScreen;
 
 typedef struct W_View WMView;
@@ -881,6 +883,8 @@ unsigned short WMGetColorAlpha(WMColor *color);
 
 char* WMGetColorRGBDescription(WMColor *color);
 
+WMTheme* W_GetTheme(WMScreen *scr);
+
 /* ---[ WINGs/widgets.c ]------------------------------------------------- */
 
 WMScreen* WMWidgetScreen(WMWidget *w);
diff --git a/WINGs/WINGs/WINGsP.h b/WINGs/WINGs/WINGsP.h
index de01412..df5cfc4 100644
--- a/WINGs/WINGs/WINGsP.h
+++ b/WINGs/WINGs/WINGsP.h
@@ -64,6 +64,17 @@ typedef struct W_DraggingInfo {
     struct W_DragDestinationInfo* destInfo; /* infos needed by destination */
 } W_DraggingInfo;
 
+/* ---[ wcolor.c ]----------------------------------------------------- */
+
+typedef struct WMTheme {
+       WMColor *background;
+       WMColor *foreground;
+       WMColor *shadow;
+       WMColor *highlight;
+       WMColor *unselectedTabBackground;
+       WMColor *unselectedTabHighlight;
+} WMTheme;
+
 /* ---[ Structures from WINGs.h ]----------------------------------------- */
 
 /* Pre-definition of internal structs */
@@ -265,6 +276,8 @@ typedef struct W_Screen {
     struct W_View *modalView;
     unsigned modalLoop:1;
     unsigned ignoreNextDoubleClick:1;
+
+    WMTheme *theme;
 } W_Screen;
 
 #define W_DRAWABLE(scr)                (scr)->rcontext->drawable
diff --git a/WINGs/wcolor.c b/WINGs/wcolor.c
index a02c182..154d5e1 100644
--- a/WINGs/wcolor.c
+++ b/WINGs/wcolor.c
@@ -199,7 +199,7 @@ void WMSetColorInGC(WMColor * color, GC gc)
 WMColor *WMWhiteColor(WMScreen * scr)
 {
        if (!scr->white) {
-               scr->white = WMCreateRGBColor(scr, 0xffff, 0xffff, 0xffff, 
True);
+               scr->white = scr->theme->highlight;
                if (!scr->white->flags.exact)
                        wwarning(_("could not allocate %s color"), _("white"));
        }
@@ -209,7 +209,7 @@ WMColor *WMWhiteColor(WMScreen * scr)
 WMColor *WMBlackColor(WMScreen * scr)
 {
        if (!scr->black) {
-               scr->black = WMCreateRGBColor(scr, 0, 0, 0, True);
+               scr->black = scr->theme->foreground;
                if (!scr->black->flags.exact)
                        wwarning(_("could not allocate %s color"), _("black"));
        }
@@ -245,7 +245,7 @@ WMColor *WMGrayColor(WMScreen * scr)
                        WMReleaseColor(white);
                        WMReleaseColor(black);
                } else {
-                       color = WMCreateRGBColor(scr, 0xaeba, 0xaaaa, 0xaeba, 
True);
+                       color = scr->theme->background;
                        if (!color->flags.exact)
                                wwarning(_("could not allocate %s color"), 
_("gray"));
                }
@@ -283,7 +283,7 @@ WMColor *WMDarkGrayColor(WMScreen * scr)
                        WMReleaseColor(white);
                        WMReleaseColor(black);
                } else {
-                       color = WMCreateRGBColor(scr, 0x5144, 0x5555, 0x5144, 
True);
+                       color = scr->theme->shadow;
                        if (!color->flags.exact)
                                wwarning(_("could not allocate %s color"), 
_("dark gray"));
                }
@@ -324,3 +324,56 @@ char *WMGetColorRGBDescription(WMColor * color)
 
        return str;
 }
+
+WMTheme *W_GetTheme(WMScreen *scr)
+{
+       WMTheme *theme;
+       WMUserDefaults *defaults;
+
+       char *background;
+       char *foreground;
+       char *shadow;
+       char *highlight;
+       char *unselectedTabBackground;
+       char *unselectedTabHighlight;
+       
+       defaults = WMGetStandardUserDefaults();
+
+       if (defaults) {
+               background = WMGetUDStringForKey(defaults, "Background");
+               foreground = WMGetUDStringForKey(defaults, "Foreground");
+               shadow = WMGetUDStringForKey(defaults, "Shadow");
+               highlight = WMGetUDStringForKey(defaults, "Highlight");
+               unselectedTabBackground = WMGetUDStringForKey(defaults, 
"UnselectedTabBackground");
+               unselectedTabHighlight = WMGetUDStringForKey(defaults, 
"UnselectedTabHighlight");
+       }
+
+
+       theme = wmalloc(sizeof(WMTheme));
+       
+       theme->background = WMCreateNamedColor(scr,background,True);
+       if (!theme->background)
+               theme->background = WMCreateRGBColor(scr, 0xaeba, 0xaaaa, 
0xaeba, True);
+       
+       theme->foreground = WMCreateNamedColor(scr,foreground,True);
+       if (!theme->foreground)
+               theme->foreground = WMCreateRGBColor(scr, 0, 0, 0, True);
+
+       theme->shadow = WMCreateNamedColor(scr,shadow,True);
+       if (!theme->shadow)
+               theme->shadow = WMCreateRGBColor(scr, 0x5144, 0x5555, 0x5144, 
True);
+
+       theme->highlight = WMCreateNamedColor(scr,highlight,True);
+       if (!theme->highlight)
+               theme->highlight = WMCreateRGBColor(scr, 0xffff, 0xffff, 
0xffff, True);
+
+       theme->unselectedTabBackground = 
WMCreateNamedColor(scr,unselectedTabBackground,True);
+       if (!theme->unselectedTabBackground)
+               theme->unselectedTabBackground = WMCreateRGBColor(scr, 0x8420, 
0x8420, 0x8420, False);
+
+       theme->unselectedTabHighlight = 
WMCreateNamedColor(scr,unselectedTabHighlight,True);
+       if (!theme->unselectedTabHighlight)
+               theme->unselectedTabHighlight = WMCreateRGBColor(scr, 0xd9d9, 
0xd9d9, 0xd9d9, False);
+
+       return theme;
+}
diff --git a/WINGs/widgets.c b/WINGs/widgets.c
index 7b9ffe8..f470e0a 100644
--- a/WINGs/widgets.c
+++ b/WINGs/widgets.c
@@ -668,6 +668,8 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int 
screen, RContext * c
                scrPtr->ignoredModifierMask = numLockMask | scrollLockMask | 
LockMask;
        }
 
+       scrPtr->theme = W_GetTheme(scrPtr);
+
        /* initially allocate some colors */
        WMWhiteColor(scrPtr);
        WMBlackColor(scrPtr);
diff --git a/WINGs/wtabview.c b/WINGs/wtabview.c
index 57a458c..43bf746 100644
--- a/WINGs/wtabview.c
+++ b/WINGs/wtabview.c
@@ -200,8 +200,8 @@ WMTabView *WMCreateTabView(WMWidget * parent)
        tPtr->view->self = tPtr;
        tPtr->view->delegate = &delegate;
 
-       tPtr->lightGray = WMCreateRGBColor(scr, 0xd9d9, 0xd9d9, 0xd9d9, False);
-       tPtr->tabColor = WMCreateRGBColor(scr, 0x8420, 0x8420, 0x8420, False);
+       tPtr->lightGray = scr->theme->unselectedTabHighlight;
+       tPtr->tabColor = scr->theme->unselectedTabBackground;
 
        tPtr->font = WMRetainFont(scr->normalFont);
 
-- 
1.8.3.2


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to