Update for 0.51.2-pre2
[wmaker-crm.git] / WPrefs.app / Appearance.c
blobf6086fa528acadc82eadad34d2802a0eccf688e6
1 /* Apperance.c- color/texture for titlebar etc.
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1999 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
24 #include "WPrefs.h"
26 #include "TexturePanel.h"
28 typedef struct _Panel {
29 WMFrame *frame;
30 char *sectionName;
32 CallbackRec callbacks;
34 WMWindow *win;
36 WMButton *prevB;
38 WMPopUpButton *secP;
40 /* texture list */
41 WMLabel *texL;
42 WMList *texLs;
44 WMButton *newB;
45 WMButton *editB;
46 WMButton *ripB;
47 WMButton *delB;
50 proplist_t ftitleTex;
51 proplist_t utitleTex;
52 proplist_t ptitleTex;
53 proplist_t iconTex;
54 proplist_t menuTex;
55 proplist_t mtitleTex;
56 proplist_t backTex;
58 int ftitleIndex;
59 int utitleIndex;
60 int ptitleIndex;
61 int iconIndex;
62 int menuIndex;
63 int mtitleIndex;
64 int backIndex;
66 WMFont *normalFont;
67 WMFont *selectedFont;
69 /* for preview shit */
70 Pixmap preview;
71 Pixmap ftitle;
72 Pixmap utitle;
73 Pixmap otitle;
74 Pixmap icon;
75 Pixmap back;
76 Pixmap mtitle;
77 Pixmap mitem;
78 } _Panel;
82 #define ICON_FILE "appearance"
84 #define TNEW_FILE "tnew"
85 #define TDEL_FILE "tdel"
86 #define TEDIT_FILE "tedit"
87 #define TEXTR_FILE "textr"
90 #define FTITLE (1<<0)
91 #define UTITLE (1<<1)
92 #define OTITLE (1<<2)
93 #define ICON (1<<3)
94 #define BACK (1<<4)
95 #define MTITLE (1<<5)
96 #define MITEM (1<<6)
97 #define EVERYTHING 0xff
100 static Pixmap
101 renderTexture(_Panel *panel, char *texture, int width, int height,
102 Bool bordered)
104 return None;
107 #if 0
108 static void
109 updatePreviewBox(_Panel *panel, int elements)
111 WMScreen *scr = WMWidgetScreen(panel->win);
112 Display *dpy = WMScreenDisplay(scr);
113 /* RContext *rc = WMScreenRContext(scr);*/
114 int refresh = 0;
115 char *tmp;
117 if (!panel->preview) {
118 panel->preview = XCreatePixmap(dpy, WMWidgetXID(panel->win),
119 220-4, 185-4, WMScreenDepth(scr));
121 refresh = -1;
124 if (elements & FTITLE) {
125 if (panel->ftitle)
126 XFreePixmap(dpy, panel->ftitle);
128 panel->ftitle = renderTexture(panel, tmp, 180, 20, True);
129 free(tmp);
132 /* have to repaint everything to make things simple, eliminating
133 * clipping stuff */
134 if (refresh) {
138 if (refresh<0) {
139 WMPixmap *pix;
140 pix = WMCreatePixmapFromXPixmaps(scr, panel->preview, None,
141 220-4, 185-4, WMScreenDepth(scr));
143 WMSetLabelImage(panel->prevL, pix);
144 WMReleasePixmap(pix);
150 static char*
151 getStrArrayForKey(char *key)
153 proplist_t v;
155 v = GetObjectForKey(key);
156 if (!v)
157 return NULL;
159 return PLGetDescription(v);
161 #endif
165 static void
166 newTexture(WMButton *bPtr, void *data)
168 _Panel *panel = (_Panel*)data;
174 static void
175 changePage(WMWidget *w, void *data)
177 _Panel *panel = (_Panel*)data;
178 int section;
180 section = WMGetPopUpButtonSelectedItem(panel->secP);
182 WMSelectListItem(panel->texLs, section);
187 static void
188 selectTexture(WMWidget *w, void *data)
190 _Panel *panel = (_Panel*)data;
191 int section;
193 section = WMGetListSelectedItemRow(panel->secP);
198 static void
199 fillTextureList(WMList *lPtr)
201 proplist_t textures;
202 WMUserDefaults *udb = WMGetStandardUserDefaults();
204 textures = WMGetUDObjectForKey(udb, "Textures");
206 if (!textures)
207 return;
213 static void
214 createPanel(Panel *p)
216 _Panel *panel = (_Panel*)p;
217 WMColor *color;
218 WMFont *font;
219 WMScreen *scr = WMWidgetScreen(panel->win);
221 panel->frame = WMCreateFrame(panel->win);
222 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
223 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
225 /* preview box */
226 panel->prevB = WMCreateCommandButton(panel->frame);
227 WMResizeWidget(panel->prevB, 260, 165);
228 WMMoveWidget(panel->prevB, 15, 10);
229 WMSetButtonImagePosition(panel->prevB, WIPImageOnly);
231 panel->secP = WMCreatePopUpButton(panel->frame);
232 WMResizeWidget(panel->secP, 260, 20);
233 WMMoveWidget(panel->secP, 15, 180);
234 WMSetPopUpButtonSelectedItem(panel->secP, 0);
235 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window"));
236 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Unfocused Windows"));
237 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window's Owner"));
238 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Menus"));
239 WMAddPopUpButtonItem(panel->secP, _("Menu Items"));
240 WMAddPopUpButtonItem(panel->secP, _("Icon Background"));
241 WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
242 WMSetPopUpButtonAction(panel->secP, changePage, panel);
244 /* texture list */
245 font = WMBoldSystemFontOfSize(scr, 12);
247 panel->texL = WMCreateLabel(panel->frame);
248 WMResizeWidget(panel->texL, 225, 18);
249 WMMoveWidget(panel->texL, 285, 10);
250 WMSetLabelFont(panel->texL, font);
251 WMSetLabelText(panel->texL, _("Textures"));
252 WMSetLabelRelief(panel->texL, WRSunken);
253 WMSetLabelTextAlignment(panel->texL, WACenter);
254 color = WMDarkGrayColor(scr);
255 WMSetWidgetBackgroundColor(panel->texL, color);
256 WMReleaseColor(color);
257 color = WMWhiteColor(scr);
258 WMSetLabelTextColor(panel->texL, color);
259 WMReleaseColor(color);
261 WMReleaseFont(font);
263 panel->texLs = WMCreateList(panel->frame);
264 WMResizeWidget(panel->texLs, 225, 144);
265 WMMoveWidget(panel->texLs, 285, 30);
267 /* command buttons */
269 font = WMSystemFontOfSize(scr, 10);
272 panel->newB = WMCreateCommandButton(panel->frame);
273 WMResizeWidget(panel->newB, 56, 48);
274 WMMoveWidget(panel->newB, 285, 180);
275 WMSetButtonFont(panel->newB, font);
276 WMSetButtonImagePosition(panel->newB, WIPAbove);
277 WMSetButtonText(panel->newB, _("New"));
278 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE);
280 panel->ripB = WMCreateCommandButton(panel->frame);
281 WMResizeWidget(panel->ripB, 56, 48);
282 WMMoveWidget(panel->ripB, 341, 180);
283 WMSetButtonFont(panel->ripB, font);
284 WMSetButtonImagePosition(panel->ripB, WIPAbove);
285 WMSetButtonText(panel->ripB, _("Extract..."));
286 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE);
288 panel->editB = WMCreateCommandButton(panel->frame);
289 WMResizeWidget(panel->editB, 56, 48);
290 WMMoveWidget(panel->editB, 397, 180);
291 WMSetButtonFont(panel->editB, font);
292 WMSetButtonImagePosition(panel->editB, WIPAbove);
293 WMSetButtonText(panel->editB, _("Edit"));
294 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE);
295 WMSetButtonEnabled(panel->editB, False);
297 panel->delB = WMCreateCommandButton(panel->frame);
298 WMResizeWidget(panel->delB, 56, 48);
299 WMMoveWidget(panel->delB, 453, 180);
300 WMSetButtonFont(panel->delB, font);
301 WMSetButtonImagePosition(panel->delB, WIPAbove);
302 WMSetButtonText(panel->delB, _("Delete"));
303 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE);
304 WMSetButtonEnabled(panel->delB, False);
306 WMReleaseFont(font);
308 /**/
310 WMRealizeWidget(panel->frame);
311 WMMapSubwidgets(panel->frame);
313 WMSetPopUpButtonSelectedItem(panel->secP, 0);
315 showData(panel);
317 fillTextureList(panel->texLs);
321 static proplist_t
322 setupTextureFor(WMList *list, char *key, char *defValue, char *title)
324 WMListItem *item;
325 char *tex, *str;
326 proplist_t prop;
328 prop = GetObjectForKey(key);
329 if (!prop) {
330 prop = PLMakeString(defValue);
332 tex = PLGetDescription(prop);
333 str = wstrappend(title, tex);
334 free(tex);
335 item = WMAddListItem(list, str);
336 free(str);
337 item->clientData = prop;
339 return prop;
343 static void
344 showData(_Panel *panel)
346 panel->ftitleTex = setupTextureFor(panel->texLs, "FTitleBack",
347 "(solid, black)", "[Focused]:");
348 panel->ftitleIndex = 0;
350 panel->utitleTex = setupTextureFor(panel->texLs, "UTitleBack",
351 "(solid, gray)", "[Unfocused]:");
352 panel->utitleIndex = 1;
354 panel->ptitleTex = setupTextureFor(panel->texLs, "PTitleBack",
355 "(solid, \"#616161\")",
356 "[Owner of Focused]:");
357 panel->ptitleIndex = 2;
359 panel->mtitleTex = setupTextureFor(panel->texLs, "MenuTitleBack",
360 "(solid, black)", "[Menu Title]:");
361 panel->mtitleIndex = 3;
363 panel->menuTex = setupTextureFor(panel->texLs, "MenuTextBack",
364 "(solid, gray)", "[Menu Item]:");
365 panel->menuIndex = 4;
367 panel->iconTex = setupTextureFor(panel->texLs, "IconBack",
368 "(solid, gray)", "[Icon]:");
369 panel->iconIndex = 5;
371 panel->backTex = setupTextureFor(panel->texLs, "WorkspaceBack",
372 "(solid, black)", "[Workspace]:");
373 panel->backIndex = 6;
378 Panel*
379 InitAppearance(WMScreen *scr, WMWindow *win)
381 _Panel *panel;
383 panel = wmalloc(sizeof(_Panel));
384 memset(panel, 0, sizeof(_Panel));
386 panel->sectionName = _("Appearance Preferences");
388 panel->win = win;
390 panel->callbacks.createWidgets = createPanel;
392 AddSection(panel, ICON_FILE);
394 return panel;