Updating to version 0.20.2
[wmaker-crm.git] / WPrefs.app / TextureAndColor.c
blob1b7920119205f5081a025acd4e2e35ab52a1da0c
1 /* TextureAndColor.c- color/texture for titlebar etc.
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1998 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 WMPopUpButton *secP;
38 WMLabel *prevL;
40 /* window titlebar */
41 WMFrame *focF;
42 WMColorWell *focC;
43 WMLabel *focL;
44 WMTextField *focT;
45 WMLabel *foc2L;
46 WMButton *focB;
48 WMFrame *unfF;
49 WMColorWell *unfC;
50 WMLabel *unfL;
51 WMTextField *unfT;
52 WMLabel *unf2L;
53 WMButton *unfB;
55 WMFrame *ownF;
56 WMColorWell *ownC;
57 WMLabel *ownL;
58 WMTextField *ownT;
59 WMLabel *own2L;
60 WMButton *ownB;
62 /* menu title */
63 WMFrame *backF;
64 WMTextField *backT;
65 WMButton *backB;
67 WMFrame *textF;
68 WMColorWell *textC;
70 /* menu items */
71 WMFrame *unsF;
72 WMTextField *unsT;
73 WMButton *unsB;
74 WMLabel *unsL;
75 WMColorWell *unsnC;
76 WMLabel *unsnL;
77 WMColorWell *unsdC;
78 WMLabel *unsdL;
80 WMFrame *selF;
81 WMColorWell *seltC;
82 WMLabel *seltL;
83 WMColorWell *selbC;
84 WMLabel *selbL;
86 /* workspace/clip */
87 WMFrame *workF;
88 WMTextField *workT;
89 WMButton *workB;
91 WMFrame *clipF;
92 WMColorWell *clipnC;
93 WMColorWell *clipcC;
94 WMLabel *clipnL;
95 WMLabel *clipcL;
97 /* icon */
98 WMFrame *iconF;
99 WMTextField *iconT;
100 WMButton *iconB;
102 Pixmap preview;
103 Pixmap ftitle;
104 Pixmap utitle;
105 Pixmap otitle;
106 Pixmap icon;
107 Pixmap back;
108 Pixmap mtitle;
109 Pixmap mitem;
110 } _Panel;
115 #define ICON_FILE "appearance"
118 #define FTITLE (1<<0)
119 #define UTITLE (1<<1)
120 #define OTITLE (1<<2)
121 #define ICON (1<<3)
122 #define BACK (1<<4)
123 #define MTITLE (1<<5)
124 #define MITEM (1<<6)
125 #define EVERYTHING 0xff
128 static Pixmap
129 renderTexture(_Panel *panel, char *texture, int width, int height,
130 Bool bordered)
132 return None;
136 static void
137 updatePreviewBox(_Panel *panel, int elements)
139 WMScreen *scr = WMWidgetScreen(panel->win);
140 Display *dpy = WMScreenDisplay(scr);
141 /* RContext *rc = WMScreenRContext(scr);*/
142 int refresh = 0;
143 char *tmp;
145 if (!panel->preview) {
146 panel->preview = XCreatePixmap(dpy, WMWidgetXID(panel->win),
147 220-4, 185-4, WMScreenDepth(scr));
149 refresh = -1;
152 if (elements & FTITLE) {
153 if (panel->ftitle)
154 XFreePixmap(dpy, panel->ftitle);
156 tmp = WMGetTextFieldText(panel->focT);
157 panel->ftitle = renderTexture(panel, tmp, 180, 20, True);
158 free(tmp);
161 /* have to repaint everything to make things simple, eliminating
162 * clipping stuff */
163 if (refresh) {
167 if (refresh<0) {
168 WMPixmap *pix;
169 pix = WMCreatePixmapFromXPixmaps(scr, panel->preview, None,
170 220-4, 185-4, WMScreenDepth(scr));
172 WMSetLabelImage(panel->prevL, pix);
173 WMReleasePixmap(pix);
179 static void
180 changePage(WMWidget *self, void *data)
182 int i;
183 _Panel *panel = (_Panel*)data;
185 i = WMGetPopUpButtonSelectedItem(self);
187 if (i==0) {
188 WMMapWidget(panel->focF);
189 WMMapWidget(panel->unfF);
190 WMMapWidget(panel->ownF);
191 } else if (i==1) {
192 WMMapWidget(panel->backF);
193 WMMapWidget(panel->textF);
194 } else if (i==2) {
195 WMMapWidget(panel->unsF);
196 WMMapWidget(panel->selF);
197 } else if (i==3) {
198 WMMapWidget(panel->workF);
199 WMMapWidget(panel->clipF);
200 } else if (i==4) {
201 WMMapWidget(panel->iconF);
204 if (i!=0) {
205 WMUnmapWidget(panel->focF);
206 WMUnmapWidget(panel->unfF);
207 WMUnmapWidget(panel->ownF);
209 if (i!=1) {
210 WMUnmapWidget(panel->backF);
211 WMUnmapWidget(panel->textF);
213 if (i!=2) {
214 WMUnmapWidget(panel->unsF);
215 WMUnmapWidget(panel->selF);
217 if (i!=3) {
218 WMUnmapWidget(panel->workF);
219 WMUnmapWidget(panel->clipF);
221 if (i!=4) {
222 WMUnmapWidget(panel->iconF);
227 static char*
228 getStrArrayForKey(char *key)
230 proplist_t v;
232 v = GetObjectForKey(key);
233 if (!v)
234 return NULL;
236 return PLGetDescription(v);
240 static void
241 showData(_Panel *panel)
243 char *str;
244 WMScreen *scr = WMWidgetScreen(panel->win);
245 WMColor *color;
247 str = GetStringForKey("FTitleColor");
248 if (!str)
249 str = "white";
250 color = WMCreateNamedColor(scr, str, True);
251 WMSetColorWellColor(panel->focC, color);
252 WMReleaseColor(color);
254 str = GetStringForKey("PTitleColor");
255 if (!str)
256 str = "white";
257 color = WMCreateNamedColor(scr, str, True);
258 WMSetColorWellColor(panel->ownC, color);
259 WMReleaseColor(color);
261 str = GetStringForKey("UTitleColor");
262 if (!str)
263 str = "black";
264 color = WMCreateNamedColor(scr, str, True);
265 WMSetColorWellColor(panel->unfC, color);
266 WMReleaseColor(color);
269 str = getStrArrayForKey("FTitleBack");
270 if (!str)
271 str = wstrdup("(solid, black)");
272 WMSetTextFieldText(panel->focT, str);
273 free(str);
275 str = getStrArrayForKey("PTitleBack");
276 if (!str)
277 str = wstrdup("(solid, gray40)");
278 WMSetTextFieldText(panel->ownT, str);
279 free(str);
281 str = getStrArrayForKey("UTitleBack");
282 if (!str)
283 str = wstrdup("(solid, grey66)");
284 WMSetTextFieldText(panel->unfT, str);
285 free(str);
287 /**/
289 str = GetStringForKey("MenuTitleColor");
290 if (!str)
291 str = "white";
292 color = WMCreateNamedColor(scr, str, True);
293 WMSetColorWellColor(panel->textC, color);
294 WMReleaseColor(color);
296 str = getStrArrayForKey("MenuTitleBack");
297 if (!str)
298 str = wstrdup("(solid, black)");
299 WMSetTextFieldText(panel->backT, str);
300 free(str);
302 /**/
304 str = getStrArrayForKey("MenuTextBack");
305 if (!str)
306 str = wstrdup("gray66");
307 WMSetTextFieldText(panel->unsT, str);
308 free(str);
310 str = GetStringForKey("MenuTextColor");
311 if (!str)
312 str = "black";
313 color = WMCreateNamedColor(scr, str, True);
314 WMSetColorWellColor(panel->unsnC, color);
315 WMReleaseColor(color);
317 str = GetStringForKey("MenuDisabledColor");
318 if (!str)
319 str = "gray40";
320 color = WMCreateNamedColor(scr, str, True);
321 WMSetColorWellColor(panel->unsdC, color);
322 WMReleaseColor(color);
324 str = GetStringForKey("HighlightTextColor");
325 if (!str)
326 str = "white";
327 color = WMCreateNamedColor(scr, str, True);
328 WMSetColorWellColor(panel->seltC, color);
329 WMReleaseColor(color);
331 str = GetStringForKey("HighlightColor");
332 if (!str)
333 str = "black";
334 color = WMCreateNamedColor(scr, str, True);
335 WMSetColorWellColor(panel->selbC, color);
336 WMReleaseColor(color);
338 /**/
340 str = getStrArrayForKey("WorkspaceBack");
341 WMSetTextFieldText(panel->workT, str);
342 if (str)
343 free(str);
346 str = GetStringForKey("ClipTitleColor");
347 if (!str)
348 str = "black";
349 color = WMCreateNamedColor(scr, str, True);
350 WMSetColorWellColor(panel->clipnC, color);
351 WMReleaseColor(color);
353 str = GetStringForKey("CClipTitleColor");
354 if (!str)
355 str = "grey40";
356 color = WMCreateNamedColor(scr, str, True);
357 WMSetColorWellColor(panel->clipcC, color);
358 WMReleaseColor(color);
360 /**/
362 str = getStrArrayForKey("IconBack");
363 if (!str)
364 str = wstrdup("(solid, gray66)");
365 WMSetTextFieldText(panel->iconT, str);
366 free(str);
370 static void
371 createPanel(Panel *p)
373 _Panel *panel = (_Panel*)p;
375 panel->frame = WMCreateFrame(panel->win);
376 WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
377 WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
379 panel->secP = WMCreatePopUpButton(panel->frame);
380 WMResizeWidget(panel->secP, 220, 20);
381 WMMoveWidget(panel->secP, 15, 10);
382 WMSetPopUpButtonAction(panel->secP, changePage, panel);
384 WMAddPopUpButtonItem(panel->secP, _("Window Title Bar"));
385 WMAddPopUpButtonItem(panel->secP, _("Menu Title Bar"));
386 WMAddPopUpButtonItem(panel->secP, _("Menu Items"));
387 WMAddPopUpButtonItem(panel->secP, _("Workspace/Clip"));
388 WMAddPopUpButtonItem(panel->secP, _("Icons"));
390 panel->prevL = WMCreateLabel(panel->frame);
391 WMResizeWidget(panel->prevL, 220, 185);
392 WMMoveWidget(panel->prevL, 15, 40);
393 WMSetLabelRelief(panel->prevL, WRSunken);
395 /* window titlebar */
396 panel->focF = WMCreateFrame(panel->frame);
397 WMResizeWidget(panel->focF, 265, 70);
398 WMMoveWidget(panel->focF, 245, 5);
399 WMSetFrameTitle(panel->focF, _("Focused Window"));
401 panel->focC = WMCreateColorWell(panel->focF);
402 WMResizeWidget(panel->focC, 60, 35);
403 WMMoveWidget(panel->focC, 15, 15);
405 panel->focT = WMCreateTextField(panel->focF);
406 WMResizeWidget(panel->focT, 116, 20);
407 WMMoveWidget(panel->focT, 85, 25);
409 panel->foc2L = WMCreateLabel(panel->focF);
410 WMResizeWidget(panel->foc2L, 165, 16);
411 WMMoveWidget(panel->foc2L, 90, 50);
412 WMSetLabelText(panel->foc2L, _("Texture"));
413 WMSetLabelTextAlignment(panel->foc2L, WACenter);
415 panel->focL = WMCreateLabel(panel->focF);
416 WMResizeWidget(panel->focL, 100, 16);
417 WMMoveWidget(panel->focL, 15, 50);
418 WMSetLabelText(panel->focL, _("Text Color"));
420 panel->focB = WMCreateCommandButton(panel->focF);
421 WMResizeWidget(panel->focB, 48, 22);
422 WMMoveWidget(panel->focB, 205, 24);
423 WMSetButtonText(panel->focB, _("Set..."));
425 WMMapSubwidgets(panel->focF);
426 /**/
427 panel->unfF = WMCreateFrame(panel->frame);
428 WMResizeWidget(panel->unfF, 265, 70);
429 WMMoveWidget(panel->unfF, 245, 80);
430 WMSetFrameTitle(panel->unfF, _("Unfocused Window"));
432 panel->unfC = WMCreateColorWell(panel->unfF);
433 WMResizeWidget(panel->unfC, 60, 35);
434 WMMoveWidget(panel->unfC, 15, 15);
436 panel->unfT = WMCreateTextField(panel->unfF);
437 WMResizeWidget(panel->unfT, 116, 20);
438 WMMoveWidget(panel->unfT, 85, 25);
440 panel->unf2L = WMCreateLabel(panel->unfF);
441 WMResizeWidget(panel->unf2L, 165, 16);
442 WMMoveWidget(panel->unf2L, 90, 50);
443 WMSetLabelText(panel->unf2L, _("Texture"));
444 WMSetLabelTextAlignment(panel->unf2L, WACenter);
446 panel->unfL = WMCreateLabel(panel->unfF);
447 WMResizeWidget(panel->unfL, 100, 16);
448 WMMoveWidget(panel->unfL, 15, 50);
449 WMSetLabelText(panel->unfL, _("Text Color"));
451 panel->unfB = WMCreateCommandButton(panel->unfF);
452 WMResizeWidget(panel->unfB, 48, 22);
453 WMMoveWidget(panel->unfB, 205, 24);
454 WMSetButtonText(panel->unfB, _("Set..."));
456 WMMapSubwidgets(panel->unfF);
457 /**/
458 panel->ownF = WMCreateFrame(panel->frame);
459 WMResizeWidget(panel->ownF, 265, 70);
460 WMMoveWidget(panel->ownF, 245, 155);
461 WMSetFrameTitle(panel->ownF, _("Owner of Focused Window"));
463 panel->ownC = WMCreateColorWell(panel->ownF);
464 WMResizeWidget(panel->ownC, 60, 35);
465 WMMoveWidget(panel->ownC, 15, 15);
467 panel->ownT = WMCreateTextField(panel->ownF);
468 WMResizeWidget(panel->ownT, 116, 20);
469 WMMoveWidget(panel->ownT, 85, 25);
471 panel->own2L = WMCreateLabel(panel->ownF);
472 WMResizeWidget(panel->own2L, 165, 16);
473 WMMoveWidget(panel->own2L, 90, 50);
474 WMSetLabelText(panel->own2L, _("Texture"));
475 WMSetLabelTextAlignment(panel->own2L, WACenter);
477 panel->ownL = WMCreateLabel(panel->ownF);
478 WMResizeWidget(panel->ownL, 100, 16);
479 WMMoveWidget(panel->ownL, 15, 50);
480 WMSetLabelText(panel->ownL, _("Text Color"));
482 panel->ownB = WMCreateCommandButton(panel->ownF);
483 WMResizeWidget(panel->ownB, 48, 22);
484 WMMoveWidget(panel->ownB, 205, 24);
485 WMSetButtonText(panel->ownB, _("Set..."));
487 WMMapSubwidgets(panel->ownF);
489 /***************** Menu Item *****************/
491 panel->unsF = WMCreateFrame(panel->frame);
492 WMResizeWidget(panel->unsF, 260, 140);
493 WMMoveWidget(panel->unsF, 250, 5);
494 WMSetFrameTitle(panel->unsF, _("Unselected Items"));
496 panel->unsT = WMCreateTextField(panel->unsF);
497 WMResizeWidget(panel->unsT, 175, 20);
498 WMMoveWidget(panel->unsT, 15, 25);
500 panel->unsL = WMCreateLabel(panel->unsF);
501 WMResizeWidget(panel->unsL, 175, 16);
502 WMMoveWidget(panel->unsL, 15, 50);
503 WMSetLabelTextAlignment(panel->unsL, WACenter);
504 WMSetLabelText(panel->unsL, _("Background"));
506 panel->unsB = WMCreateCommandButton(panel->unsF);
507 WMResizeWidget(panel->unsB, 48, 22);
508 WMMoveWidget(panel->unsB, 200, 24);
509 WMSetButtonText(panel->unsB, _("Set..."));
511 panel->unsnC = WMCreateColorWell(panel->unsF);
512 WMResizeWidget(panel->unsnC, 60, 40);
513 WMMoveWidget(panel->unsnC, 40, 75);
515 panel->unsnL = WMCreateLabel(panel->unsF);
516 WMResizeWidget(panel->unsnL, 120, 16);
517 WMMoveWidget(panel->unsnL, 10, 117);
518 WMSetLabelTextAlignment(panel->unsnL, WACenter);
519 WMSetLabelText(panel->unsnL, _("Normal Text"));
521 panel->unsdC = WMCreateColorWell(panel->unsF);
522 WMResizeWidget(panel->unsdC, 60, 40);
523 WMMoveWidget(panel->unsdC, 160, 75);
525 panel->unsdL = WMCreateLabel(panel->unsF);
526 WMResizeWidget(panel->unsdL, 120, 16);
527 WMMoveWidget(panel->unsdL, 130, 117);
528 WMSetLabelTextAlignment(panel->unsdL, WACenter);
529 WMSetLabelText(panel->unsdL, _("Disabled Text"));
531 WMMapSubwidgets(panel->unsF);
533 /**/
535 panel->selF = WMCreateFrame(panel->frame);
536 WMResizeWidget(panel->selF, 260, 75);
537 WMMoveWidget(panel->selF, 250, 150);
538 WMSetFrameTitle(panel->selF, _("Selected Items"));
540 panel->seltC = WMCreateColorWell(panel->selF);
541 WMResizeWidget(panel->seltC, 60, 36);
542 WMMoveWidget(panel->seltC, 40, 20);
544 panel->seltL = WMCreateLabel(panel->selF);
545 WMResizeWidget(panel->seltL, 120, 16);
546 WMMoveWidget(panel->seltL, 10, 56);
547 WMSetLabelTextAlignment(panel->seltL, WACenter);
548 WMSetLabelText(panel->seltL, _("Text"));
550 panel->selbC = WMCreateColorWell(panel->selF);
551 WMResizeWidget(panel->selbC, 60, 36);
552 WMMoveWidget(panel->selbC, 160, 20);
554 panel->selbL = WMCreateLabel(panel->selF);
555 WMResizeWidget(panel->selbL, 120, 16);
556 WMMoveWidget(panel->selbL, 130, 56);
557 WMSetLabelTextAlignment(panel->selbL, WACenter);
558 WMSetLabelText(panel->selbL, _("Background"));
560 WMMapSubwidgets(panel->selF);
562 /***************** Menu Title *****************/
563 panel->backF = WMCreateFrame(panel->frame);
564 WMResizeWidget(panel->backF, 260, 110);
565 WMMoveWidget(panel->backF, 250, 35);
566 WMSetFrameTitle(panel->backF, _("Menu Title Background"));
568 panel->backT = WMCreateTextField(panel->backF);
569 WMResizeWidget(panel->backT, 210, 20);
570 WMMoveWidget(panel->backT, 25, 35);
572 panel->backB = WMCreateCommandButton(panel->backF);
573 WMResizeWidget(panel->backB, 50, 24);
574 WMMoveWidget(panel->backB, 185, 60);
575 WMSetButtonText(panel->backB, _("Set..."));
577 WMMapSubwidgets(panel->backF);
579 /**/
581 panel->textF = WMCreateFrame(panel->frame);
582 WMResizeWidget(panel->textF, 260, 75);
583 WMMoveWidget(panel->textF, 250, 150);
584 WMSetFrameTitle(panel->textF, _("Menu Title Text"));
586 panel->textC = WMCreateColorWell(panel->textF);
587 WMResizeWidget(panel->textC, 60, 40);
588 WMMoveWidget(panel->textC, 100, 20);
590 WMMapSubwidgets(panel->textF);
592 /***************** Workspace ****************/
593 panel->workF = WMCreateFrame(panel->frame);
594 WMResizeWidget(panel->workF, 260, 90);
595 WMMoveWidget(panel->workF, 250, 35);
596 WMSetFrameTitle(panel->workF, _("Workspace Background"));
598 panel->workT = WMCreateTextField(panel->workF);
599 WMResizeWidget(panel->workT, 220, 20);
600 WMMoveWidget(panel->workT, 20, 25);
602 panel->workB = WMCreateCommandButton(panel->workF);
603 WMResizeWidget(panel->workB, 70, 24);
604 WMMoveWidget(panel->workB, 170, 55);
605 WMSetButtonText(panel->workB, _("Change"));
607 /**/
608 panel->clipF = WMCreateFrame(panel->frame);
609 WMResizeWidget(panel->clipF, 260, 90);
610 WMMoveWidget(panel->clipF, 250, 135);
611 WMSetFrameTitle(panel->clipF, _("Clip Title Text"));
613 panel->clipnC = WMCreateColorWell(panel->clipF);
614 WMResizeWidget(panel->clipnC, 60, 40);
615 WMMoveWidget(panel->clipnC, 40, 25);
617 panel->clipnL = WMCreateLabel(panel->clipF);
618 WMResizeWidget(panel->clipnL, 120, 16);
619 WMMoveWidget(panel->clipnL, 10, 70);
620 WMSetLabelTextAlignment(panel->clipnL, WACenter);
621 WMSetLabelText(panel->clipnL, _("Normal"));
623 panel->clipcC = WMCreateColorWell(panel->clipF);
624 WMResizeWidget(panel->clipcC, 60, 40);
625 WMMoveWidget(panel->clipcC, 160, 25);
627 panel->clipcL = WMCreateLabel(panel->clipF);
628 WMResizeWidget(panel->clipcL, 120, 16);
629 WMMoveWidget(panel->clipcL, 130, 70);
630 WMSetLabelTextAlignment(panel->clipcL, WACenter);
631 WMSetLabelText(panel->clipcL, _("Collapsed"));
633 WMMapSubwidgets(panel->clipF);
637 WMMapSubwidgets(panel->workF);
639 /***************** Icon *****************/
640 panel->iconF = WMCreateFrame(panel->frame);
641 WMResizeWidget(panel->iconF, 260, 190);
642 WMMoveWidget(panel->iconF, 250, 35);
643 WMSetFrameTitle(panel->iconF, _("Icon Background"));
645 panel->iconT = WMCreateTextField(panel->iconF);
646 WMResizeWidget(panel->iconT, 220, 20);
647 WMMoveWidget(panel->iconT, 20, 80);
649 panel->iconB = WMCreateCommandButton(panel->iconF);
650 WMResizeWidget(panel->iconB, 50, 24);
651 WMMoveWidget(panel->iconB, 190, 105);
652 WMSetButtonText(panel->iconB, _("Set..."));
654 WMMapSubwidgets(panel->iconF);
655 /**/
657 WMRealizeWidget(panel->frame);
658 WMMapSubwidgets(panel->frame);
660 WMSetPopUpButtonSelectedItem(panel->secP, 0);
661 changePage(panel->secP, panel);
664 showData(panel);
669 Panel*
670 InitTextureAndColor(WMScreen *scr, WMWindow *win)
672 _Panel *panel;
674 panel = wmalloc(sizeof(_Panel));
675 memset(panel, 0, sizeof(_Panel));
677 panel->sectionName = _("Texture and Color Preferences");
679 panel->win = win;
681 panel->callbacks.createWidgets = createPanel;
683 AddSection(panel, ICON_FILE);
685 return panel;