Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / Appearance.c
Commit [+]AuthorDateLineData
088c0ac2 dan1999-03-09 14:58:01 +00001/* Apperance.c- color/texture for titlebar etc.
6830b057 dan2004-10-12 21:28:27 +00002 *
0261c326 dan1999-01-06 15:22:33 +00003 * WPrefs - Window Maker Preferences Program
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1999-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
0261c326 dan1999-01-06 15:22:33 +00007 * 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.
11 *
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.
16 *
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
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
0261c326 dan1999-01-06 15:22:33 +000020 * USA.
21 */
22
0261c326 dan1999-01-06 15:22:33 +000023#include "WPrefs.h"
24
c56756dc dan1999-03-14 22:35:50 +000025#include <unistd.h>
26#include <errno.h>
ea55bc5e kojima1999-03-18 01:11:18 +000027#include <ctype.h>
28#include <time.h>
29#include <sys/stat.h>
30#include <sys/types.h>
31#include <fcntl.h>
32#include <unistd.h>
33
0261c326 dan1999-01-06 15:22:33 +000034#include "TexturePanel.h"
35
36typedef struct _Panel {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020037 WMBox *box;
38 char *sectionName;
d3f29988 kojima1999-04-25 01:49:46 +000039
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020040 char *description;
0261c326 dan1999-01-06 15:22:33 +000041
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020042 CallbackRec callbacks;
0261c326 dan1999-01-06 15:22:33 +000043
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020044 WMWidget *parent;
0261c326 dan1999-01-06 15:22:33 +000045
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020046 WMLabel *prevL;
0261c326 dan1999-01-06 15:22:33 +000047
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020048 WMTabView *tabv;
dd2d71fc kojima1999-05-15 17:38:05 +000049
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020050 /* texture list */
51 WMFrame *texF;
52 WMList *texLs;
0261c326 dan1999-01-06 15:22:33 +000053
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020054 WMPopUpButton *secP;
86f9c4dd kojima1999-05-16 02:49:05 +000055
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020056 WMButton *newB;
57 WMButton *editB;
58 WMButton *ripB;
59 WMButton *delB;
088c0ac2 dan1999-03-09 14:58:01 +000060
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020061 /* text color */
62 WMFrame *colF;
dd2d71fc kojima1999-05-15 17:38:05 +000063
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020064 WMPopUpButton *colP;
65 WMColor *colors[14];
59e1504f kojima1999-05-16 06:59:48 +000066
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020067 WMColorWell *colW;
59e1504f kojima1999-05-16 06:59:48 +000068
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020069 WMColorWell *sampW[24];
59e1504f kojima1999-05-16 06:59:48 +000070
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020071 /* options */
72 WMFrame *optF;
905010ce kojima1999-05-16 04:54:13 +000073
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020074 WMFrame *mstyF;
75 WMButton *mstyB[3];
905010ce kojima1999-05-16 04:54:13 +000076
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020077 WMFrame *taliF;
78 WMButton *taliB[3];
07e83b45 kojima1999-05-17 03:54:38 +000079
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020080 /* root bg */
81 WMFrame *bgF;
6830b057 dan2004-10-12 21:28:27 +000082
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020083 WMLabel *bgprevL;
84 WMButton *selbgB;
e44130b5 kojima2000-05-22 03:24:40 +000085
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020086 WMPopUpButton *modeB[3];
6830b057 dan2004-10-12 21:28:27 +000087
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020088 /* */
dd2d71fc kojima1999-05-15 17:38:05 +000089
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020090 int textureIndex[8];
c56756dc dan1999-03-14 22:35:50 +000091
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020092 WMFont *smallFont;
93 WMFont *normalFont;
94 WMFont *boldFont;
c56756dc dan1999-03-14 22:35:50 +000095
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020096 TexturePanel *texturePanel;
c56756dc dan1999-03-14 22:35:50 +000097
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020098 WMPixmap *onLed;
99 WMPixmap *offLed;
100 WMPixmap *hand;
0261c326 dan1999-01-06 15:22:33 +0000101
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200102 int oldsection;
103 int oldcsection;
07e83b45 kojima1999-05-17 03:54:38 +0000104
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200105 char oldTabItem;
905010ce kojima1999-05-16 04:54:13 +0000106
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200107 int menuStyle;
905010ce kojima1999-05-16 04:54:13 +0000108
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200109 int titleAlignment;
07e83b45 kojima1999-05-17 03:54:38 +0000110
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200111 Pixmap preview;
112 Pixmap previewNoText;
c56756dc dan1999-03-14 22:35:50 +0000113
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200114 char *fprefix;
0261c326 dan1999-01-06 15:22:33 +0000115} _Panel;
116
c56756dc dan1999-03-14 22:35:50 +0000117typedef struct {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200118 char *title;
119 char *texture;
120 WMPropList *prop;
121 Pixmap preview;
c56756dc dan1999-03-14 22:35:50 +0000122
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200123 char *path;
c56756dc dan1999-03-14 22:35:50 +0000124
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200125 char selectedFor;
126 unsigned current:1;
127 unsigned ispixmap:1;
c56756dc dan1999-03-14 22:35:50 +0000128} TextureListItem;
129
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200130static void updateColorPreviewBox(_Panel * panel, int elements);
07e83b45 kojima1999-05-17 03:54:38 +0000131
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200132static void showData(_Panel * panel);
52988491 kojima1999-03-16 11:27:01 +0000133
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200134static void changePage(WMWidget * w, void *data);
07e83b45 kojima1999-05-17 03:54:38 +0000135
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200136static void changeColorPage(WMWidget * w, void *data);
07e83b45 kojima1999-05-17 03:54:38 +0000137
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200138static void OpenExtractPanelFor(_Panel * panel, char *path);
07e83b45 kojima1999-05-17 03:54:38 +0000139
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200140static void changedTabItem(struct WMTabViewDelegate *self, WMTabView * tabView, WMTabViewItem * item);
07e83b45 kojima1999-05-17 03:54:38 +0000141
142static WMTabViewDelegate tabviewDelegate = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200143 NULL,
144 NULL, /* didChangeNumberOfItems */
145 changedTabItem, /* didSelectItem */
146 NULL, /* shouldSelectItem */
147 NULL /* willSelectItem */
07e83b45 kojima1999-05-17 03:54:38 +0000148};
149
0261c326 dan1999-01-06 15:22:33 +0000150#define ICON_FILE "appearance"
151
088c0ac2 dan1999-03-09 14:58:01 +0000152#define TNEW_FILE "tnew"
153#define TDEL_FILE "tdel"
154#define TEDIT_FILE "tedit"
155#define TEXTR_FILE "textr"
156
905010ce kojima1999-05-16 04:54:13 +0000157#define MSTYLE1_FILE "msty1"
158#define MSTYLE2_FILE "msty2"
159#define MSTYLE3_FILE "msty3"
0261c326 dan1999-01-06 15:22:33 +0000160
c56756dc dan1999-03-14 22:35:50 +0000161/* XPM */
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200162static char *blueled_xpm[] = {
163 "8 8 17 1",
164 " c None",
165 ". c #020204",
166 "+ c #16B6FC",
167 "@ c #176AFC",
168 "# c #163AFC",
169 "$ c #72D2FC",
170 "% c #224CF4",
171 "& c #76D6FC",
172 "* c #16AAFC",
173 "= c #CEE9FC",
174 "- c #229EFC",
175 "; c #164CFC",
176 "> c #FAFEFC",
177 ", c #2482FC",
178 "' c #1652FC",
179 ") c #1E76FC",
180 "! c #1A60FC",
181 " .... ",
182 " .=>-@. ",
183 ".=>$@@'.",
184 ".=$@!;;.",
185 ".!@*+!#.",
186 ".#'*+*,.",
187 " .@)@,. ",
188 " .... "
189};
c56756dc dan1999-03-14 22:35:50 +0000190
191/* XPM */
192static char *blueled2_xpm[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200193 /* width height num_colors chars_per_pixel */
194 " 8 8 17 1",
195 /* colors */
196 ". c None",
197 "# c #090909",
198 "a c #4b63a4",
199 "b c #011578",
200 "c c #264194",
201 "d c #04338c",
202 "e c #989dac",
203 "f c #011a7c",
204 "g c #465c9c",
205 "h c #03278a",
206 "i c #6175ac",
207 "j c #011e74",
208 "k c #043a90",
209 "l c #042f94",
210 "m c #0933a4",
211 "n c #022184",
212 "o c #012998",
213 /* pixels */
214 "..####..",
215 ".#aimn#.",
216 "#aechnf#",
217 "#gchnjf#",
218 "#jndknb#",
219 "#bjdddl#",
220 ".#nono#.",
221 "..####.."
c56756dc dan1999-03-14 22:35:50 +0000222};
223
e75050c3 kojima1999-03-18 20:03:27 +0000224/* XPM */
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200225static char *hand_xpm[] = {
226 "22 21 19 1",
227 " c None",
228 ". c #030305",
229 "+ c #7F7F7E",
230 "@ c #B5B5B6",
231 "# c #C5C5C6",
232 "$ c #969697",
233 "% c #FDFDFB",
234 "& c #F2F2F4",
235 "* c #E5E5E4",
236 "= c #ECECEC",
237 "- c #DCDCDC",
238 "; c #D2D2D0",
239 "> c #101010",
240 ", c #767674",
241 "' c #676767",
242 ") c #535355",
243 "! c #323234",
244 "~ c #3E3C56",
245 "{ c #333147",
246 " ",
247 " ..... ",
248 " ..+@##$. ",
249 " .%%%&@.......... ",
250 " .%*%%&#%%%%%%%%%$. ",
251 " .*#%%%%%%%%%&&&&==. ",
252 " .-%%%%%%%%%=*-;;;#$. ",
253 " .-%%%%%%%%&..>..... ",
254 " >-%%%%%%%%%*#+. ",
255 " >-%%%%%%%%%*@,. ",
256 " >#%%%%%%%%%*@'. ",
257 " >$&&%%%%%%=... ",
258 " .+@@;=&%%&;$,> ",
259 " .',$@####$+). ",
260 " .!',+$++,'. ",
261 " ..>>>>>. ",
262 " ",
263 " ~~{{{~~ ",
264 " {{{{{{{{{{{ ",
265 " ~~{{{~~ ",
266 " "
267};
c56756dc dan1999-03-14 22:35:50 +0000268
8fb8355a kojima1999-05-19 00:20:45 +0000269static char *sampleColors[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200270 "black",
271 "#292929",
272 "#525252",
273 "#848484",
274 "#adadad",
275 "#d6d6d6",
276 "white",
277 "#d6d68c",
278 "#d6a57b",
279 "#8cd68c",
280 "#8cd6ce",
281 "#d68c8c",
282 "#8c9cd6",
283 "#bd86d6",
284 "#d68cbd",
285 "#d64a4a",
286 "#4a5ad6",
287 "#4ad6ce",
288 "#4ad65a",
289 "#ced64a",
290 "#d6844a",
291 "#8ad631",
292 "#ce29c6",
293 "#ce2973",
294 "black"
8fb8355a kojima1999-05-19 00:20:45 +0000295};
296
07e83b45 kojima1999-05-17 03:54:38 +0000297static char *textureOptions[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200298 "FTitleBack", "(solid, black)", "[Focused]",
299 "UTitleBack", "(solid, gray)", "[Unfocused]",
300 "PTitleBack", "(solid, \"#616161\")", "[Owner of Focused]",
301 "ResizebarBack", "(solid, gray)", "[Resizebar]",
302 "MenuTitleBack", "(solid, black)", "[Menu Title]",
303 "MenuTextBack", "(solid, gray)", "[Menu Item]",
304 "IconBack", "(solid, gray)", "[Icon]"
07e83b45 kojima1999-05-17 03:54:38 +0000305};
0261c326 dan1999-01-06 15:22:33 +0000306
ad6c5e0b kojima1999-04-12 04:54:50 +0000307#define RESIZEBAR_BEVEL -1
308#define MENU_BEVEL -2
c56756dc dan1999-03-14 22:35:50 +0000309
310#define TEXPREV_WIDTH 40
311#define TEXPREV_HEIGHT 24
312
905010ce kojima1999-05-16 04:54:13 +0000313#define MSTYLE_NORMAL 0
314#define MSTYLE_SINGLE 1
315#define MSTYLE_FLAT 2
316
07e83b45 kojima1999-05-17 03:54:38 +0000317#define FTITLE_COL (1<<0)
318#define UTITLE_COL (1<<1)
319#define OTITLE_COL (1<<2)
320#define MTITLE_COL (1<<3)
321#define MITEM_COL (1<<4)
322#define MDISAB_COL (1<<5)
323#define MHIGH_COL (1<<6)
324#define MHIGHT_COL (1<<7)
325#define ICONT_COL (1<<8)
326#define ICONB_COL (1<<9)
327#define CLIP_COL (1<<10)
328#define CCLIP_COL (1<<11)
329
07e83b45 kojima1999-05-17 03:54:38 +0000330static char *colorOptions[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200331 "FTitleColor", "white",
332 "UTitleColor", "black",
333 "PTitleColor", "white",
334 "MenuTitleColor", "white",
335 "MenuTextColor", "black",
336 "MenuDisabledColor", "#616161",
337 "HighlightColor", "white",
338 "HighlightTextColor", "black",
339 "IconTitleColor", "white",
340 "IconTitleBack", "black",
341 "ClipTitleColor", "black",
342 "CClipTitleColor", "#454045"
07e83b45 kojima1999-05-17 03:54:38 +0000343};
344
07e83b45 kojima1999-05-17 03:54:38 +0000345static WMRect previewPositions[] = {
346#define PFOCUSED 0
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200347 {{30, 10}, {190, 20}},
07e83b45 kojima1999-05-17 03:54:38 +0000348#define PUNFOCUSED 1
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200349 {{30, 40}, {190, 20}},
07e83b45 kojima1999-05-17 03:54:38 +0000350#define POWNER 2
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200351 {{30, 70}, {190, 20}},
07e83b45 kojima1999-05-17 03:54:38 +0000352#define PRESIZEBAR 3
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200353 {{30, 100}, {190, 9}},
07e83b45 kojima1999-05-17 03:54:38 +0000354#define PMTITLE 4
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200355 {{30, 120}, {90, 20}},
07e83b45 kojima1999-05-17 03:54:38 +0000356#define PMITEM 5
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200357 {{30, 140}, {90, 20 * 4}},
07e83b45 kojima1999-05-17 03:54:38 +0000358#define PICON 6
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200359 {{155, 130}, {64, 64}}
07e83b45 kojima1999-05-17 03:54:38 +0000360};
07e83b45 kojima1999-05-17 03:54:38 +0000361
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200362#define EVERYTHING 0xff
07e83b45 kojima1999-05-17 03:54:38 +0000363
364static WMRect previewColorPositions[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200365 {{30, 10}, {190, 20}},
366 {{30, 40}, {190, 20}},
367 {{30, 70}, {190, 20}},
368 {{30, 120}, {90, 20}},
369 {{30, 140}, {90, 20}},
370 {{30, 160}, {90, 20}},
371 {{30, 180}, {90, 20}},
372 {{30, 200}, {90, 20}},
373 {{155, 130}, {64, 64}},
374 {{155, 130}, {64, 64}},
375 {{155, 130}, {64, 64}},
376 {{155, 130}, {64, 64}}
07e83b45 kojima1999-05-17 03:54:38 +0000377};
378
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200379static void str2rcolor(RContext * rc, char *name, RColor * color)
c56756dc dan1999-03-14 22:35:50 +0000380{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200381 XColor xcolor;
6830b057 dan2004-10-12 21:28:27 +0000382
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200383 XParseColor(rc->dpy, rc->cmap, name, &xcolor);
c56756dc dan1999-03-14 22:35:50 +0000384
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200385 color->alpha = 255;
386 color->red = xcolor.red >> 8;
387 color->green = xcolor.green >> 8;
388 color->blue = xcolor.blue >> 8;
c56756dc dan1999-03-14 22:35:50 +0000389}
390
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200391static void dumpRImage(char *path, RImage * image)
c56756dc dan1999-03-14 22:35:50 +0000392{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200393 FILE *f;
394 int channels = (image->format == RRGBAFormat ? 4 : 3);
ea55bc5e kojima1999-03-18 01:11:18 +0000395
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200396 f = fopen(path, "wb");
397 if (!f) {
398 wsyserror(path);
399 return;
400 }
401 fprintf(f, "%02x%02x%1x", image->width, image->height, channels);
c56756dc dan1999-03-14 22:35:50 +0000402
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200403 fwrite(image->data, 1, image->width * image->height * channels, f);
c56756dc dan1999-03-14 22:35:50 +0000404
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200405 if (fclose(f) < 0) {
406 wsyserror(path);
407 }
c56756dc dan1999-03-14 22:35:50 +0000408}
409
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200410static int isPixmap(WMPropList * prop)
ea55bc5e kojima1999-03-18 01:11:18 +0000411{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200412 WMPropList *p;
413 char *s;
414
415 p = WMGetFromPLArray(prop, 0);
416 s = WMGetFromPLString(p);
417 if (strcasecmp(&s[1], "pixmap") == 0)
418 return 1;
419 else
420 return 0;
ea55bc5e kojima1999-03-18 01:11:18 +0000421}
422
07e83b45 kojima1999-05-17 03:54:38 +0000423/**********************************************************************/
424
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200425static void drawResizebarBevel(RImage * img)
ad6c5e0b kojima1999-04-12 04:54:50 +0000426{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200427 RColor light;
428 RColor dark;
429 RColor black;
430 int width = img->width;
431 int height = img->height;
432 int cwidth = 28;
ad6c5e0b kojima1999-04-12 04:54:50 +0000433
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200434 black.alpha = 255;
435 black.red = black.green = black.blue = 0;
6830b057 dan2004-10-12 21:28:27 +0000436
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200437 light.alpha = 0;
438 light.red = light.green = light.blue = 80;
ad6c5e0b kojima1999-04-12 04:54:50 +0000439
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200440 dark.alpha = 0;
441 dark.red = dark.green = dark.blue = 40;
ad6c5e0b kojima1999-04-12 04:54:50 +0000442
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200443 ROperateLine(img, RSubtractOperation, 0, 0, width - 1, 0, &dark);
444 ROperateLine(img, RAddOperation, 0, 1, width - 1, 1, &light);
ad6c5e0b kojima1999-04-12 04:54:50 +0000445
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200446 ROperateLine(img, RSubtractOperation, cwidth, 2, cwidth, height - 1, &dark);
447 ROperateLine(img, RAddOperation, cwidth + 1, 2, cwidth + 1, height - 1, &light);
ad6c5e0b kojima1999-04-12 04:54:50 +0000448
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200449 ROperateLine(img, RSubtractOperation, width - cwidth - 2, 2, width - cwidth - 2, height - 1, &dark);
450 ROperateLine(img, RAddOperation, width - cwidth - 1, 2, width - cwidth - 1, height - 1, &light);
6830b057 dan2004-10-12 21:28:27 +0000451
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200452 RDrawLine(img, 0, height - 1, width - 1, height - 1, &black);
453 RDrawLine(img, 0, 0, 0, height - 1, &black);
454 RDrawLine(img, width - 1, 0, width - 1, height - 1, &black);
ad6c5e0b kojima1999-04-12 04:54:50 +0000455}
456
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200457static void drawMenuBevel(RImage * img)
ad6c5e0b kojima1999-04-12 04:54:50 +0000458{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200459 RColor light, dark, mid;
460 int i;
461 int iheight = img->height / 4;
6830b057 dan2004-10-12 21:28:27 +0000462
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200463 light.alpha = 0;
464 light.red = light.green = light.blue = 80;
6830b057 dan2004-10-12 21:28:27 +0000465
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200466 dark.alpha = 255;
467 dark.red = dark.green = dark.blue = 0;
6830b057 dan2004-10-12 21:28:27 +0000468
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200469 mid.alpha = 0;
470 mid.red = mid.green = mid.blue = 40;
6830b057 dan2004-10-12 21:28:27 +0000471
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200472 for (i = 1; i < 4; i++) {
473 ROperateLine(img, RSubtractOperation, 0, i * iheight - 2, img->width - 1, i * iheight - 2, &mid);
6830b057 dan2004-10-12 21:28:27 +0000474
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200475 RDrawLine(img, 0, i * iheight - 1, img->width - 1, i * iheight - 1, &dark);
6830b057 dan2004-10-12 21:28:27 +0000476
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200477 ROperateLine(img, RAddOperation, 1, i * iheight, img->width - 2, i * iheight, &light);
478 }
ad6c5e0b kojima1999-04-12 04:54:50 +0000479}
480
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200481static Pixmap renderTexture(WMScreen * scr, WMPropList * texture, int width, int height, char *path, int border)
0261c326 dan1999-01-06 15:22:33 +0000482{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200483 char *type;
484 RImage *image = NULL;
485 Pixmap pixmap;
486 RContext *rc = WMScreenRContext(scr);
487 char *str;
488 RColor rcolor;
489
490 type = WMGetFromPLString(WMGetFromPLArray(texture, 0));
491
492 if (strcasecmp(type, "solid") == 0) {
493
494 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
495
496 str2rcolor(rc, str, &rcolor);
497
498 image = RCreateImage(width, height, False);
499 RClearImage(image, &rcolor);
500 } else if (strcasecmp(type, "igradient") == 0) {
501 int t1, t2;
502 RColor c1[2], c2[2];
503
504 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
505 str2rcolor(rc, str, &c1[0]);
506 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
507 str2rcolor(rc, str, &c1[1]);
508 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
509 t1 = atoi(str);
510
511 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
512 str2rcolor(rc, str, &c2[0]);
513 str = WMGetFromPLString(WMGetFromPLArray(texture, 5));
514 str2rcolor(rc, str, &c2[1]);
515 str = WMGetFromPLString(WMGetFromPLArray(texture, 6));
516 t2 = atoi(str);
517
518 image = RRenderInterwovenGradient(width, height, c1, t1, c2, t2);
519 } else if (strcasecmp(&type[1], "gradient") == 0) {
520 int style;
521 RColor rcolor2;
522
523 switch (toupper(type[0])) {
524 case 'V':
525 style = RVerticalGradient;
526 break;
527 case 'H':
528 style = RHorizontalGradient;
529 break;
530 default:
531 case 'D':
532 style = RDiagonalGradient;
533 break;
534 }
535
536 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
537 str2rcolor(rc, str, &rcolor);
538 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
539 str2rcolor(rc, str, &rcolor2);
540
541 image = RRenderGradient(width, height, &rcolor, &rcolor2, style);
542 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'T') {
543 int style;
544 RColor rcolor2;
545 int i;
546 RImage *grad, *timage;
547 char *path;
548
549 switch (toupper(type[1])) {
550 case 'V':
551 style = RVerticalGradient;
552 break;
553 case 'H':
554 style = RHorizontalGradient;
555 break;
556 default:
557 case 'D':
558 style = RDiagonalGradient;
559 break;
560 }
561
562 str = WMGetFromPLString(WMGetFromPLArray(texture, 3));
563 str2rcolor(rc, str, &rcolor);
564 str = WMGetFromPLString(WMGetFromPLArray(texture, 4));
565 str2rcolor(rc, str, &rcolor2);
566
567 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
568
569 if ((path = wfindfileinarray(GetObjectForKey("PixmapPath"), str)) != NULL)
570 timage = RLoadImage(rc, path, 0);
571
572 if (!path || !timage) {
573 wwarning("could not load file '%s': %s", path, RMessageForError(RErrorCode));
574 } else {
575 grad = RRenderGradient(width, height, &rcolor, &rcolor2, style);
576
577 image = RMakeTiledImage(timage, width, height);
578 RReleaseImage(timage);
579
580 i = atoi(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
581
582 RCombineImagesWithOpaqueness(image, grad, i);
583 RReleaseImage(grad);
584 }
585 } else if (strcasecmp(&type[2], "gradient") == 0 && toupper(type[0]) == 'M') {
586 int style;
587 RColor **colors;
588 int i, j;
589
590 switch (toupper(type[1])) {
591 case 'V':
592 style = RVerticalGradient;
593 break;
594 case 'H':
595 style = RHorizontalGradient;
596 break;
597 default:
598 case 'D':
599 style = RDiagonalGradient;
600 break;
601 }
602
603 j = WMGetPropListItemCount(texture);
604
605 if (j > 0) {
606 colors = wmalloc(j * sizeof(RColor *));
607
608 for (i = 2; i < j; i++) {
609 str = WMGetFromPLString(WMGetFromPLArray(texture, i));
610 colors[i - 2] = wmalloc(sizeof(RColor));
611 str2rcolor(rc, str, colors[i - 2]);
612 }
613 colors[i - 2] = NULL;
614
615 image = RRenderMultiGradient(width, height, colors, style);
616
617 for (i = 0; colors[i] != NULL; i++)
618 wfree(colors[i]);
619 wfree(colors);
620 }
621 } else if (strcasecmp(&type[1], "pixmap") == 0) {
622 RImage *timage = NULL;
623 char *path;
624 RColor color;
625
626 str = WMGetFromPLString(WMGetFromPLArray(texture, 1));
627
628 if ((path = wfindfileinarray(GetObjectForKey("PixmapPath"), str)) != NULL)
629 timage = RLoadImage(rc, path, 0);
630
631 if (!path || !timage) {
632 wwarning("could not load file '%s': %s", path ? path : str, RMessageForError(RErrorCode));
633 } else {
634 str = WMGetFromPLString(WMGetFromPLArray(texture, 2));
635 str2rcolor(rc, str, &color);
636
637 switch (toupper(type[0])) {
638 case 'T':
639 image = RMakeTiledImage(timage, width, height);
640 RReleaseImage(timage);
641 timage = image;
642 break;
643 case 'C':
644 image = RMakeCenteredImage(timage, width, height, &color);
645 RReleaseImage(timage);
646 timage = image;
647 break;
648 case 'S':
649 case 'M':
650 image = RScaleImage(timage, width, height);
651 RReleaseImage(timage);
652 timage = image;
653 break;
654 }
655
656 }
657 wfree(path);
658 }
659
660 if (!image)
661 return None;
662
663 if (path) {
664 dumpRImage(path, image);
665 }
666
667 if (border < 0) {
668 if (border == RESIZEBAR_BEVEL) {
669 drawResizebarBevel(image);
670 } else if (border == MENU_BEVEL) {
671 drawMenuBevel(image);
672 RBevelImage(image, RBEV_RAISED2);
673 }
674 } else if (border) {
675 RBevelImage(image, border);
676 }
677
678 RConvertImage(rc, image, &pixmap);
679 RReleaseImage(image);
680
681 return pixmap;
0261c326 dan1999-01-06 15:22:33 +0000682}
683
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200684static Pixmap renderMenu(_Panel * panel, WMPropList * texture, int width, int iheight)
ad6c5e0b kojima1999-04-12 04:54:50 +0000685{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200686 WMScreen *scr = WMWidgetScreen(panel->parent);
687 Display *dpy = WMScreenDisplay(scr);
688 Pixmap pix, tmp;
689 GC gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
690 int i;
691
692 switch (panel->menuStyle) {
693 case MSTYLE_NORMAL:
694 tmp = renderTexture(scr, texture, width, iheight, NULL, RBEV_RAISED2);
695
696 pix = XCreatePixmap(dpy, tmp, width, iheight * 4, WMScreenDepth(scr));
697 for (i = 0; i < 4; i++) {
698 XCopyArea(dpy, tmp, pix, gc, 0, 0, width, iheight, 0, iheight * i);
699 }
700 XFreePixmap(dpy, tmp);
701 break;
702 case MSTYLE_SINGLE:
703 pix = renderTexture(scr, texture, width, iheight * 4, NULL, MENU_BEVEL);
704 break;
705 case MSTYLE_FLAT:
706 pix = renderTexture(scr, texture, width, iheight * 4, NULL, RBEV_RAISED2);
707 break;
708 }
709 XFreeGC(dpy, gc);
710
711 return pix;
ad6c5e0b kojima1999-04-12 04:54:50 +0000712}
52988491 kojima1999-03-16 11:27:01 +0000713
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200714static void renderPreview(_Panel * panel, GC gc, int part, int relief)
07e83b45 kojima1999-05-17 03:54:38 +0000715{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200716 WMListItem *item;
717 TextureListItem *titem;
718 Pixmap pix;
719 WMScreen *scr = WMWidgetScreen(panel->box);
07e83b45 kojima1999-05-17 03:54:38 +0000720
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200721 item = WMGetListItem(panel->texLs, panel->textureIndex[part]);
722 titem = (TextureListItem *) item->clientData;
07e83b45 kojima1999-05-17 03:54:38 +0000723
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200724 pix = renderTexture(scr, titem->prop,
725 previewPositions[part].size.width, previewPositions[part].size.height, NULL, relief);
52988491 kojima1999-03-16 11:27:01 +0000726
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200727 XCopyArea(WMScreenDisplay(scr), pix, panel->preview, gc, 0, 0,
728 previewPositions[part].size.width,
729 previewPositions[part].size.height, previewPositions[part].pos.x, previewPositions[part].pos.y);
0261c326 dan1999-01-06 15:22:33 +0000730
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200731 XCopyArea(WMScreenDisplay(scr), pix, panel->previewNoText, gc, 0, 0,
732 previewPositions[part].size.width,
733 previewPositions[part].size.height, previewPositions[part].pos.x, previewPositions[part].pos.y);
088c0ac2 dan1999-03-09 14:58:01 +0000734
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200735 XFreePixmap(WMScreenDisplay(scr), pix);
736}
088c0ac2 dan1999-03-09 14:58:01 +0000737
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200738static void updatePreviewBox(_Panel * panel, int elements)
088c0ac2 dan1999-03-09 14:58:01 +0000739{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200740 WMScreen *scr = WMWidgetScreen(panel->parent);
741 Display *dpy = WMScreenDisplay(scr);
742 Pixmap pix;
743 GC gc;
744 int colorUpdate = 0;
745 WMColor *black = WMBlackColor(scr);
746
747 gc = XCreateGC(dpy, WMWidgetXID(panel->parent), 0, NULL);
748
749 if (panel->preview == None) {
750 WMColor *color;
751 WMPixmap *p;
752
753 panel->previewNoText = XCreatePixmap(dpy, WMWidgetXID(panel->parent),
754 240 - 4, 215 - 4, WMScreenDepth(scr));
755
756 p = WMCreatePixmap(scr, 240 - 4, 215 - 4, WMScreenDepth(scr), False);
757 panel->preview = WMGetPixmapXID(p);
758 WMSetLabelImage(panel->prevL, p);
759 WMReleasePixmap(p);
760
761 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
762 XFillRectangle(dpy, panel->preview, WMColorGC(color), 0, 0, 240 - 4, 215 - 4);
763 XFillRectangle(dpy, panel->previewNoText, WMColorGC(color), 0, 0, 240 - 4, 215 - 4);
764 WMReleaseColor(color);
765 }
766
767 if (elements & (1 << PFOCUSED)) {
768 renderPreview(panel, gc, PFOCUSED, RBEV_RAISED2);
769 XDrawRectangle(dpy, panel->preview, WMColorGC(black),
770 previewPositions[PFOCUSED].pos.x - 1,
771 previewPositions[PFOCUSED].pos.y - 1,
772 previewPositions[PFOCUSED].size.width, previewPositions[PFOCUSED].size.height);
773 XDrawRectangle(dpy, panel->previewNoText, WMColorGC(black),
774 previewPositions[PFOCUSED].pos.x - 1,
775 previewPositions[PFOCUSED].pos.y - 1,
776 previewPositions[PFOCUSED].size.width, previewPositions[PFOCUSED].size.height);
777 colorUpdate |= FTITLE_COL;
778 }
779 if (elements & (1 << PUNFOCUSED)) {
780 renderPreview(panel, gc, PUNFOCUSED, RBEV_RAISED2);
781 XDrawRectangle(dpy, panel->preview, WMColorGC(black),
782 previewPositions[PUNFOCUSED].pos.x - 1,
783 previewPositions[PUNFOCUSED].pos.y - 1,
784 previewPositions[PUNFOCUSED].size.width, previewPositions[PUNFOCUSED].size.height);
785 XDrawRectangle(dpy, panel->previewNoText, WMColorGC(black),
786 previewPositions[PUNFOCUSED].pos.x - 1,
787 previewPositions[PUNFOCUSED].pos.y - 1,
788 previewPositions[PUNFOCUSED].size.width, previewPositions[PUNFOCUSED].size.height);
789 colorUpdate |= UTITLE_COL;
790 }
791 if (elements & (1 << POWNER)) {
792 renderPreview(panel, gc, POWNER, RBEV_RAISED2);
793 XDrawRectangle(dpy, panel->preview, WMColorGC(black),
794 previewPositions[POWNER].pos.x - 1,
795 previewPositions[POWNER].pos.y - 1,
796 previewPositions[POWNER].size.width, previewPositions[POWNER].size.height);
797 XDrawRectangle(dpy, panel->previewNoText, WMColorGC(black),
798 previewPositions[POWNER].pos.x - 1,
799 previewPositions[POWNER].pos.y - 1,
800 previewPositions[POWNER].size.width, previewPositions[POWNER].size.height);
801 colorUpdate |= OTITLE_COL;
802 }
803 if (elements & (1 << PRESIZEBAR)) {
804 renderPreview(panel, gc, PRESIZEBAR, RESIZEBAR_BEVEL);
805 }
806 if (elements & (1 << PMTITLE)) {
807 renderPreview(panel, gc, PMTITLE, RBEV_RAISED2);
808 colorUpdate |= MTITLE_COL;
809 }
810 if (elements & (1 << PMITEM)) {
811 WMListItem *item;
812 TextureListItem *titem;
813
814 item = WMGetListItem(panel->texLs, panel->textureIndex[5]);
815 titem = (TextureListItem *) item->clientData;
816
817 pix = renderMenu(panel, titem->prop,
818 previewPositions[PMITEM].size.width, previewPositions[PMITEM].size.height / 4);
819
820 XCopyArea(dpy, pix, panel->preview, gc, 0, 0,
821 previewPositions[PMITEM].size.width,
822 previewPositions[PMITEM].size.height,
823 previewPositions[PMITEM].pos.x, previewPositions[PMITEM].pos.y);
824
825 XCopyArea(dpy, pix, panel->previewNoText, gc, 0, 0,
826 previewPositions[PMITEM].size.width,
827 previewPositions[PMITEM].size.height,
828 previewPositions[PMITEM].pos.x, previewPositions[PMITEM].pos.y);
829
830 XFreePixmap(dpy, pix);
831
832 colorUpdate |= MITEM_COL | MDISAB_COL | MHIGH_COL | MHIGHT_COL;
833 }
834 if (elements & (1 << PMITEM | 1 << PMTITLE)) {
835 XDrawLine(dpy, panel->preview, gc, 29, 120, 29, 120 + 20 * 4 + 20);
836 XDrawLine(dpy, panel->preview, gc, 29, 119, 119, 119);
837
838 XDrawLine(dpy, panel->previewNoText, gc, 29, 120, 29, 120 + 20 * 4 + 20);
839 XDrawLine(dpy, panel->previewNoText, gc, 29, 119, 119, 119);
840 }
841 if (elements & (1 << PICON)) {
842 WMListItem *item;
843 TextureListItem *titem;
844
845 item = WMGetListItem(panel->texLs, panel->textureIndex[6]);
846 titem = (TextureListItem *) item->clientData;
847
848 renderPreview(panel, gc, PICON, titem->ispixmap ? 0 : RBEV_RAISED3);
849
850 colorUpdate |= ICONT_COL | ICONB_COL | CLIP_COL | CCLIP_COL;
851 }
852
853 if (colorUpdate)
854 updateColorPreviewBox(panel, colorUpdate);
855 else
856 WMRedisplayWidget(panel->prevL);
857
858 XFreeGC(dpy, gc);
859 WMReleaseColor(black);
c56756dc dan1999-03-14 22:35:50 +0000860}
861
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200862static void cancelNewTexture(void *data)
863{
864 _Panel *panel = (_Panel *) data;
c56756dc dan1999-03-14 22:35:50 +0000865
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200866 HideTexturePanel(panel->texturePanel);
867}
4eda6949 kojima1999-03-16 12:17:14 +0000868
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200869static char *makeFileName(char *prefix)
c56756dc dan1999-03-14 22:35:50 +0000870{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200871 char *fname;
c56756dc dan1999-03-14 22:35:50 +0000872
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200873 fname = wstrdup(prefix);
c56756dc dan1999-03-14 22:35:50 +0000874
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200875 while (access(fname, F_OK) == 0) {
876 char buf[30];
c56756dc dan1999-03-14 22:35:50 +0000877
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200878 wfree(fname);
879 sprintf(buf, "%08lx.cache", time(NULL));
880 fname = wstrconcat(prefix, buf);
881 }
c56756dc dan1999-03-14 22:35:50 +0000882
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200883 return fname;
088c0ac2 dan1999-03-09 14:58:01 +0000884}
885
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200886static void okNewTexture(void *data)
088c0ac2 dan1999-03-09 14:58:01 +0000887{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200888 _Panel *panel = (_Panel *) data;
889 WMListItem *item;
890 char *name;
891 char *str;
892 WMPropList *prop;
893 TextureListItem *titem;
894 WMScreen *scr = WMWidgetScreen(panel->parent);
c56756dc dan1999-03-14 22:35:50 +0000895
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200896 titem = wmalloc(sizeof(TextureListItem));
897 memset(titem, 0, sizeof(TextureListItem));
c56756dc dan1999-03-14 22:35:50 +0000898
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200899 HideTexturePanel(panel->texturePanel);
c56756dc dan1999-03-14 22:35:50 +0000900
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200901 name = GetTexturePanelTextureName(panel->texturePanel);
c56756dc dan1999-03-14 22:35:50 +0000902
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200903 prop = GetTexturePanelTexture(panel->texturePanel);
c56756dc dan1999-03-14 22:35:50 +0000904
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200905 str = WMGetPropListDescription(prop, False);
c56756dc dan1999-03-14 22:35:50 +0000906
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200907 titem->title = name;
908 titem->prop = prop;
909 titem->texture = str;
910 titem->selectedFor = 0;
c56756dc dan1999-03-14 22:35:50 +0000911
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200912 titem->ispixmap = isPixmap(prop);
ea55bc5e kojima1999-03-18 01:11:18 +0000913
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200914 titem->path = makeFileName(panel->fprefix);
915 titem->preview = renderTexture(scr, prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
c56756dc dan1999-03-14 22:35:50 +0000916
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200917 item = WMAddListItem(panel->texLs, "");
918 item->clientData = titem;
c56756dc dan1999-03-14 22:35:50 +0000919
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200920 WMSetListPosition(panel->texLs, WMGetListNumberOfRows(panel->texLs));
c56756dc dan1999-03-14 22:35:50 +0000921}
922
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200923static void okEditTexture(void *data)
c56756dc dan1999-03-14 22:35:50 +0000924{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200925 _Panel *panel = (_Panel *) data;
926 WMListItem *item;
927 char *name;
928 char *str;
929 WMPropList *prop;
930 TextureListItem *titem;
c56756dc dan1999-03-14 22:35:50 +0000931
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200932 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
933 titem = (TextureListItem *) item->clientData;
c56756dc dan1999-03-14 22:35:50 +0000934
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200935 HideTexturePanel(panel->texturePanel);
c56756dc dan1999-03-14 22:35:50 +0000936
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200937 if (titem->current) {
938 name = GetTexturePanelTextureName(panel->texturePanel);
6d7e5a33 kojima1999-03-16 03:25:10 +0000939
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200940 wfree(titem->title);
941 titem->title = name;
942 }
c56756dc dan1999-03-14 22:35:50 +0000943
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200944 prop = GetTexturePanelTexture(panel->texturePanel);
c56756dc dan1999-03-14 22:35:50 +0000945
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200946 str = WMGetPropListDescription(prop, False);
c56756dc dan1999-03-14 22:35:50 +0000947
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200948 WMReleasePropList(titem->prop);
949 titem->prop = prop;
c56756dc dan1999-03-14 22:35:50 +0000950
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200951 titem->ispixmap = isPixmap(prop);
ea55bc5e kojima1999-03-18 01:11:18 +0000952
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200953 wfree(titem->texture);
954 titem->texture = str;
c56756dc dan1999-03-14 22:35:50 +0000955
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200956 XFreePixmap(WMScreenDisplay(WMWidgetScreen(panel->texLs)), titem->preview);
957 titem->preview = renderTexture(WMWidgetScreen(panel->texLs), titem->prop,
958 TEXPREV_WIDTH, TEXPREV_HEIGHT, titem->path, 0);
c56756dc dan1999-03-14 22:35:50 +0000959
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200960 WMRedisplayWidget(panel->texLs);
4eda6949 kojima1999-03-16 12:17:14 +0000961
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200962 if (titem->selectedFor)
963 updatePreviewBox(panel, titem->selectedFor);
2b1dfb43 kojima1999-04-18 22:10:50 +0000964
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200965 changePage(panel->secP, panel);
c56756dc dan1999-03-14 22:35:50 +0000966}
967
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200968static void editTexture(WMWidget * w, void *data)
c56756dc dan1999-03-14 22:35:50 +0000969{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200970 _Panel *panel = (_Panel *) data;
971 WMListItem *item;
972 TextureListItem *titem;
c56756dc dan1999-03-14 22:35:50 +0000973
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200974 item = WMGetListItem(panel->texLs, WMGetListSelectedItemRow(panel->texLs));
975 titem = (TextureListItem *) item->clientData;
c56756dc dan1999-03-14 22:35:50 +0000976
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200977 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
ea55bc5e kojima1999-03-18 01:11:18 +0000978
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200979 SetTexturePanelTexture(panel->texturePanel, titem->title, titem->prop);
c56756dc dan1999-03-14 22:35:50 +0000980
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200981 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
982 SetTexturePanelOkAction(panel->texturePanel, okEditTexture, panel);
c56756dc dan1999-03-14 22:35:50 +0000983
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200984 ShowTexturePanel(panel->texturePanel);
c56756dc dan1999-03-14 22:35:50 +0000985}
986
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200987static void newTexture(WMWidget * w, void *data)
c56756dc dan1999-03-14 22:35:50 +0000988{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200989 _Panel *panel = (_Panel *) data;
c56756dc dan1999-03-14 22:35:50 +0000990
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200991 SetTexturePanelPixmapPath(panel->texturePanel, GetObjectForKey("PixmapPath"));
ea55bc5e kojima1999-03-18 01:11:18 +0000992
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200993 SetTexturePanelTexture(panel->texturePanel, "New Texture", NULL);
c56756dc dan1999-03-14 22:35:50 +0000994
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200995 SetTexturePanelCancelAction(panel->texturePanel, cancelNewTexture, panel);
c56756dc dan1999-03-14 22:35:50 +0000996
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200997 SetTexturePanelOkAction(panel->texturePanel, okNewTexture, panel);
c56756dc dan1999-03-14 22:35:50 +0000998
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200999 ShowTexturePanel(panel->texturePanel);
c56756dc dan1999-03-14 22:35:50 +00001000}
1001
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001002static void deleteTexture(WMWidget * w, void *data)
c56756dc dan1999-03-14 22:35:50 +00001003{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001004 _Panel *panel = (_Panel *) data;
1005 WMListItem *item;
1006 TextureListItem *titem;
1007 int row;
1008 int section;
1009
1010 section = WMGetPopUpButtonSelectedItem(panel->secP);
1011 row = WMGetListSelectedItemRow(panel->texLs);
1012 item = WMGetListItem(panel->texLs, row);
1013 titem = (TextureListItem *) item->clientData;
1014
1015 if (titem->selectedFor & (1 << section)) {
1016 TextureListItem *titem2;
1017
1018 panel->textureIndex[section] = section;
1019 item = WMGetListItem(panel->texLs, section);
1020 titem2 = (TextureListItem *) item->clientData;
1021 titem2->selectedFor |= 1 << section;
1022 }
1023
1024 wfree(titem->title);
1025 wfree(titem->texture);
1026 WMReleasePropList(titem->prop);
1027 if (titem->path) {
1028 if (remove(titem->path) < 0 && errno != ENOENT) {
1029 wsyserror("could not remove file %s", titem->path);
1030 }
1031 wfree(titem->path);
1032 }
1033
1034 wfree(titem);
1035
1036 WMRemoveListItem(panel->texLs, row);
1037 WMSetButtonEnabled(panel->delB, False);
088c0ac2 dan1999-03-09 14:58:01 +00001038}
1039
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001040static void extractTexture(WMWidget * w, void *data)
52988491 kojima1999-03-16 11:27:01 +00001041{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001042 _Panel *panel = (_Panel *) data;
1043 char *path;
1044 WMOpenPanel *opanel;
1045 WMScreen *scr = WMWidgetScreen(w);
52988491 kojima1999-03-16 11:27:01 +00001046
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001047 opanel = WMGetOpenPanel(scr);
1048 WMSetFilePanelCanChooseDirectories(opanel, False);
1049 WMSetFilePanelCanChooseFiles(opanel, True);
52988491 kojima1999-03-16 11:27:01 +00001050
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001051 if (WMRunModalFilePanelForDirectory(opanel, panel->parent, wgethomedir(), _("Select File"), NULL)) {
1052 path = WMGetFilePanelFileName(opanel);
52988491 kojima1999-03-16 11:27:01 +00001053
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001054 OpenExtractPanelFor(panel, path);
52988491 kojima1999-03-16 11:27:01 +00001055
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001056 wfree(path);
1057 }
52988491 kojima1999-03-16 11:27:01 +00001058}
1059
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001060static void changePage(WMWidget * w, void *data)
088c0ac2 dan1999-03-09 14:58:01 +00001061{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001062 _Panel *panel = (_Panel *) data;
1063 int section;
1064 WMListItem *item;
1065 TextureListItem *titem;
1066 WMScreen *scr = WMWidgetScreen(panel->box);
1067 RContext *rc = WMScreenRContext(scr);
1068 static WMPoint positions[] = {
1069 {5, 10},
1070 {5, 40},
1071 {5, 70},
1072 {5, 100},
1073 {5, 120},
1074 {5, 160},
1075 {130, 150}
1076 };
1077
1078 if (w) {
1079 section = WMGetPopUpButtonSelectedItem(panel->secP);
1080
1081 WMSelectListItem(panel->texLs, panel->textureIndex[section]);
1082
1083 WMSetListPosition(panel->texLs, panel->textureIndex[section] - 2);
1084
1085 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1086
1087 titem = (TextureListItem *) item->clientData;
1088 }
1089 {
1090 WMColor *color;
1091
1092 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
1093 XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1094 positions[panel->oldsection].x, positions[panel->oldsection].y, 22, 22);
1095 WMReleaseColor(color);
1096 }
1097 if (w) {
1098 panel->oldsection = section;
1099 WMDrawPixmap(panel->hand, panel->preview, positions[section].x, positions[section].y);
1100 }
1101 WMRedisplayWidget(panel->prevL);
088c0ac2 dan1999-03-09 14:58:01 +00001102}
1103
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001104static void previewClick(XEvent * event, void *clientData)
dfac16f9 kojima1999-03-19 00:48:03 +00001105{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001106 _Panel *panel = (_Panel *) clientData;
1107 int i;
1108
1109 switch (panel->oldTabItem) {
1110 case 0:
1111 for (i = 0; i < sizeof(previewPositions) / sizeof(WMRect); i++) {
1112 if (event->xbutton.x >= previewPositions[i].pos.x
1113 && event->xbutton.y >= previewPositions[i].pos.y
1114 && event->xbutton.x < previewPositions[i].pos.x
1115 + previewPositions[i].size.width
1116 && event->xbutton.y < previewPositions[i].pos.y + previewPositions[i].size.height) {
1117
1118 WMSetPopUpButtonSelectedItem(panel->secP, i);
1119 changePage(panel->secP, panel);
1120 return;
1121 }
1122 }
1123 break;
1124 case 1:
1125 for (i = 0; i < WMGetPopUpButtonNumberOfItems(panel->colP); i++) {
1126 if (event->xbutton.x >= previewColorPositions[i].pos.x
1127 && event->xbutton.y >= previewColorPositions[i].pos.y
1128 && event->xbutton.x < previewColorPositions[i].pos.x
1129 + previewColorPositions[i].size.width
1130 && event->xbutton.y < previewColorPositions[i].pos.y
1131 + previewColorPositions[i].size.height) {
1132
1133 /* yuck kluge */
1134 if (i == 7)
1135 i = 4;
1136
1137 WMSetPopUpButtonSelectedItem(panel->colP, i);
1138 changeColorPage(panel->colP, panel);
1139 return;
1140 }
1141 }
1142 break;
1143 }
dfac16f9 kojima1999-03-19 00:48:03 +00001144}
1145
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001146static void textureClick(WMWidget * w, void *data)
c56756dc dan1999-03-14 22:35:50 +00001147{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001148 _Panel *panel = (_Panel *) data;
1149 int i;
1150 WMListItem *item;
1151 TextureListItem *titem;
c56756dc dan1999-03-14 22:35:50 +00001152
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001153 i = WMGetListSelectedItemRow(panel->texLs);
c56756dc dan1999-03-14 22:35:50 +00001154
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001155 item = WMGetListItem(panel->texLs, i);
c56756dc dan1999-03-14 22:35:50 +00001156
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001157 titem = (TextureListItem *) item->clientData;
c56756dc dan1999-03-14 22:35:50 +00001158
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001159 if (titem->current) {
1160 WMSetButtonEnabled(panel->delB, False);
1161 } else {
1162 WMSetButtonEnabled(panel->delB, True);
1163 }
c56756dc dan1999-03-14 22:35:50 +00001164}
1165
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001166static void textureDoubleClick(WMWidget * w, void *data)
c56756dc dan1999-03-14 22:35:50 +00001167{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001168 _Panel *panel = (_Panel *) data;
1169 int i, section;
1170 WMListItem *item;
1171 TextureListItem *titem;
c56756dc dan1999-03-14 22:35:50 +00001172
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001173 /* unselect old texture */
1174 section = WMGetPopUpButtonSelectedItem(panel->secP);
c56756dc dan1999-03-14 22:35:50 +00001175
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001176 item = WMGetListItem(panel->texLs, panel->textureIndex[section]);
1177 titem = (TextureListItem *) item->clientData;
1178 titem->selectedFor &= ~(1 << section);
c56756dc dan1999-03-14 22:35:50 +00001179
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001180 /* select new texture */
1181 i = WMGetListSelectedItemRow(panel->texLs);
c56756dc dan1999-03-14 22:35:50 +00001182
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001183 item = WMGetListItem(panel->texLs, i);
c56756dc dan1999-03-14 22:35:50 +00001184
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001185 titem = (TextureListItem *) item->clientData;
c56756dc dan1999-03-14 22:35:50 +00001186
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001187 titem->selectedFor |= 1 << section;
c56756dc dan1999-03-14 22:35:50 +00001188
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001189 panel->textureIndex[section] = i;
c56756dc dan1999-03-14 22:35:50 +00001190
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001191 WMRedisplayWidget(panel->texLs);
67a00893 kojima1999-03-17 02:00:13 +00001192
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001193 updatePreviewBox(panel, 1 << section);
c56756dc dan1999-03-14 22:35:50 +00001194}
1195
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001196static void paintListItem(WMList * lPtr, int index, Drawable d, char *text, int state, WMRect * rect)
c56756dc dan1999-03-14 22:35:50 +00001197{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001198 _Panel *panel = (_Panel *) WMGetHangedData(lPtr);
1199 WMScreen *scr = WMWidgetScreen(lPtr);
1200 int width, height, x, y;
1201 Display *dpy = WMScreenDisplay(scr);
1202 WMColor *back = (state & WLDSSelected) ? WMWhiteColor(scr) : WMGrayColor(scr);
1203 WMListItem *item;
1204 WMColor *black = WMBlackColor(scr);
1205 TextureListItem *titem;
1206
1207 item = WMGetListItem(lPtr, index);
1208 titem = (TextureListItem *) item->clientData;
1209 if (!titem) {
1210 WMReleaseColor(back);
1211 WMReleaseColor(black);
1212 return;
1213 }
1214
1215 width = rect->size.width;
1216 height = rect->size.height;
1217 x = rect->pos.x;
1218 y = rect->pos.y;
1219
1220 XFillRectangle(dpy, d, WMColorGC(back), x, y, width, height);
1221
1222 if (titem->preview)
1223 XCopyArea(dpy, titem->preview, d, WMColorGC(black), 0, 0,
1224 TEXPREV_WIDTH, TEXPREV_HEIGHT, x + 5, y + 5);
1225
1226 if ((1 << WMGetPopUpButtonSelectedItem(panel->secP)) & titem->selectedFor)
1227 WMDrawPixmap(panel->onLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1228 else if (titem->selectedFor)
1229 WMDrawPixmap(panel->offLed, d, x + TEXPREV_WIDTH + 10, y + 6);
1230
1231 WMDrawString(scr, d, black, panel->boldFont,
1232 x + TEXPREV_WIDTH + 22, y + 2, titem->title, strlen(titem->title));
1233
1234 WMDrawString(scr, d, black, panel->smallFont,
1235 x + TEXPREV_WIDTH + 14, y + 18, titem->texture, strlen(titem->texture));
1236
1237 WMReleaseColor(back);
1238 WMReleaseColor(black);
c56756dc dan1999-03-14 22:35:50 +00001239}
1240
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001241static Pixmap loadRImage(WMScreen * scr, char *path)
c56756dc dan1999-03-14 22:35:50 +00001242{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001243 FILE *f;
1244 RImage *image;
1245 int w, h, d;
1246 Pixmap pixmap;
c56756dc dan1999-03-14 22:35:50 +00001247
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001248 f = fopen(path, "rb");
1249 if (!f)
1250 return None;
c56756dc dan1999-03-14 22:35:50 +00001251
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001252 fscanf(f, "%02x%02x%1x", &w, &h, &d);
c56756dc dan1999-03-14 22:35:50 +00001253
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001254 image = RCreateImage(w, h, d == 4);
1255 fread(image->data, 1, w * h * d, f);
1256 fclose(f);
c56756dc dan1999-03-14 22:35:50 +00001257
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001258 RConvertImage(WMScreenRContext(scr), image, &pixmap);
1259 RReleaseImage(image);
c56756dc dan1999-03-14 22:35:50 +00001260
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001261 return pixmap;
c56756dc dan1999-03-14 22:35:50 +00001262}
1263
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001264static void fillTextureList(WMList * lPtr)
088c0ac2 dan1999-03-09 14:58:01 +00001265{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001266 WMPropList *textureList;
1267 WMPropList *texture;
1268 WMUserDefaults *udb = WMGetStandardUserDefaults();
1269 TextureListItem *titem;
1270 WMScreen *scr = WMWidgetScreen(lPtr);
1271 int i;
1272
1273 textureList = WMGetUDObjectForKey(udb, "TextureList");
1274 if (!textureList)
1275 return;
1276
1277 for (i = 0; i < WMGetPropListItemCount(textureList); i++) {
1278 WMListItem *item;
1279
1280 texture = WMGetFromPLArray(textureList, i);
1281
1282 titem = wmalloc(sizeof(TextureListItem));
1283 memset(titem, 0, sizeof(TextureListItem));
1284
1285 titem->title = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 0)));
1286 titem->prop = WMRetainPropList(WMGetFromPLArray(texture, 1));
1287 titem->texture = WMGetPropListDescription(titem->prop, False);
1288 titem->selectedFor = 0;
1289 titem->path = wstrdup(WMGetFromPLString(WMGetFromPLArray(texture, 2)));
1290
1291 titem->preview = loadRImage(scr, titem->path);
1292 if (!titem->preview) {
1293 titem->preview = renderTexture(scr, titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1294 }
1295 item = WMAddListItem(lPtr, "");
1296 item->clientData = titem;
1297 }
088c0ac2 dan1999-03-09 14:58:01 +00001298}
1299
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001300static void fillColorList(_Panel * panel)
8fb8355a kojima1999-05-19 00:20:45 +00001301{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001302 WMColor *color;
1303 WMPropList *list;
1304 WMUserDefaults *udb = WMGetStandardUserDefaults();
1305 WMScreen *scr = WMWidgetScreen(panel->box);
1306 int i;
1307
1308 list = WMGetUDObjectForKey(udb, "ColorList");
1309 if (!list) {
1310 for (i = 0; i < 24; i++) {
1311 color = WMCreateNamedColor(scr, sampleColors[i], False);
1312 if (!color)
1313 continue;
1314 WMSetColorWellColor(panel->sampW[i], color);
1315 WMReleaseColor(color);
1316 }
1317 } else {
1318 WMPropList *c;
1319
1320 for (i = 0; i < WMIN(24, WMGetPropListItemCount(list)); i++) {
1321 c = WMGetFromPLArray(list, i);
1322 if (!c || !WMIsPLString(c))
1323 continue;
1324 color = WMCreateNamedColor(scr, WMGetFromPLString(c), False);
1325 if (!color)
1326 continue;
1327 WMSetColorWellColor(panel->sampW[i], color);
1328 WMReleaseColor(color);
1329 }
1330 }
8fb8355a kojima1999-05-19 00:20:45 +00001331}
1332
07e83b45 kojima1999-05-17 03:54:38 +00001333/*************************************************************************/
1334
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001335static void changeColorPage(WMWidget * w, void *data)
07e83b45 kojima1999-05-17 03:54:38 +00001336{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001337 _Panel *panel = (_Panel *) data;
1338 int section;
1339 WMScreen *scr = WMWidgetScreen(panel->box);
1340 RContext *rc = WMScreenRContext(scr);
1341 static WMPoint positions[] = {
1342 {5, 10},
1343 {5, 40},
1344 {5, 70},
1345 {5, 120},
1346 {5, 140},
1347 {5, 160},
1348 {5, 180},
1349 {5, 180},
1350 {130, 140},
1351 {130, 140},
1352 {130, 140},
1353 {130, 140}
1354 };
1355
1356 if (panel->preview) {
1357 WMColor *color;
1358
1359 color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
1360 XFillRectangle(rc->dpy, panel->preview, WMColorGC(color),
1361 positions[panel->oldcsection].x, positions[panel->oldcsection].y, 22, 22);
1362 WMReleaseColor(color);
1363 }
1364 if (w) {
1365 section = WMGetPopUpButtonSelectedItem(panel->colP);
1366
1367 panel->oldcsection = section;
1368 if (panel->preview)
1369 WMDrawPixmap(panel->hand, panel->preview, positions[section].x, positions[section].y);
1370
1371 section = WMGetPopUpButtonSelectedItem(panel->colP);
1372
1373 WMSetColorWellColor(panel->colW, panel->colors[section]);
1374 }
1375 WMRedisplayWidget(panel->prevL);
07e83b45 kojima1999-05-17 03:54:38 +00001376}
1377
07e83b45 kojima1999-05-17 03:54:38 +00001378static void
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001379paintText(WMScreen * scr, Drawable d, WMColor * color, WMFont * font,
1380 int x, int y, int w, int h, WMAlignment align, char *text)
07e83b45 kojima1999-05-17 03:54:38 +00001381{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001382 int l = strlen(text);
1383
1384 switch (align) {
1385 case WALeft:
1386 x += 5;
1387 break;
1388 case WARight:
1389 x += w - 5 - WMWidthOfString(font, text, l);
1390 break;
1391 default:
1392 case WACenter:
1393 x += (w - WMWidthOfString(font, text, l)) / 2;
1394 break;
1395 }
1396 WMDrawString(scr, d, color, font, x, y + (h - WMFontHeight(font)) / 2, text, l);
07e83b45 kojima1999-05-17 03:54:38 +00001397}
1398
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001399static void updateColorPreviewBox(_Panel * panel, int elements)
07e83b45 kojima1999-05-17 03:54:38 +00001400{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001401 WMScreen *scr = WMWidgetScreen(panel->box);
1402 Display *dpy = WMScreenDisplay(scr);
1403 Pixmap d, pnot;
1404 GC gc;
1405
1406 d = panel->preview;
1407 pnot = panel->previewNoText;
1408 gc = WMColorGC(panel->colors[0]);
1409
1410 if (elements & FTITLE_COL) {
1411 XCopyArea(dpy, pnot, d, gc, 30, 10, 190, 20, 30, 10);
1412 paintText(scr, d, panel->colors[0], panel->boldFont, 30, 10, 190, 20,
1413 panel->titleAlignment, _("Focused Window"));
1414 }
1415 if (elements & UTITLE_COL) {
1416 XCopyArea(dpy, pnot, d, gc, 30, 40, 190, 20, 30, 40);
1417 paintText(scr, d, panel->colors[1], panel->boldFont, 30, 40, 190, 20,
1418 panel->titleAlignment, _("Unfocused Window"));
1419 }
1420 if (elements & OTITLE_COL) {
1421 XCopyArea(dpy, pnot, d, gc, 30, 70, 190, 20, 30, 70);
1422 paintText(scr, d, panel->colors[2], panel->boldFont, 30, 70, 190, 20,
1423 panel->titleAlignment, _("Owner of Focused Window"));
1424 }
1425 if (elements & MTITLE_COL) {
1426 XCopyArea(dpy, pnot, d, gc, 30, 120, 90, 20, 30, 120);
1427 paintText(scr, d, panel->colors[3], panel->boldFont, 30, 120, 90, 20, WALeft, _("Menu Title"));
1428 }
1429 if (elements & MITEM_COL) {
1430 XCopyArea(dpy, pnot, d, gc, 30, 140, 90, 20, 30, 140);
1431 paintText(scr, d, panel->colors[4], panel->normalFont, 30, 140, 90, 20, WALeft, _("Normal Item"));
1432 XCopyArea(dpy, pnot, d, gc, 30, 200, 90, 20, 30, 200);
1433 paintText(scr, d, panel->colors[4], panel->normalFont, 30, 200, 90, 20, WALeft, _("Normal Item"));
1434 }
1435 if (elements & MDISAB_COL) {
1436 XCopyArea(dpy, pnot, d, gc, 30, 160, 90, 20, 30, 160);
1437 paintText(scr, d, panel->colors[5], panel->normalFont, 30, 160, 90, 20,
1438 WALeft, _("Disabled Item"));
1439 }
1440 if (elements & MHIGH_COL) {
1441 XFillRectangle(WMScreenDisplay(scr), d, WMColorGC(panel->colors[6]), 31, 181, 87, 17);
1442 XFillRectangle(WMScreenDisplay(scr), pnot, WMColorGC(panel->colors[6]), 31, 181, 87, 17);
1443 elements |= MHIGHT_COL;
1444 }
1445 if (elements & MHIGHT_COL) {
1446 XCopyArea(dpy, pnot, d, gc, 30, 180, 90, 20, 30, 180);
1447 paintText(scr, d, panel->colors[7], panel->normalFont, 30, 180, 90, 20, WALeft, _("Highlighted"));
1448 }
1449 /*
1450 if (elements & ICONT_COL) {
1451 WRITE(_("Focused Window"), panel->colors[8], panel->boldFont,
1452 155, 130, 64);
1453 }
1454 if (elements & ICONB_COL) {
1455 WRITE(_("Focused Window"), panel->colors[9], panel->boldFont,
1456 0, 0, 30);
1457 }
1458 if (elements & CLIP_COL) {
1459 WRITE(_("Focused Window"), panel->colors[10], panel->boldFont,
1460 0, 0, 30);
1461 }
1462 if (elements & CCLIP_COL) {
1463 WRITE(_("Focused Window"), panel->colors[11], panel->boldFont,
1464 0, 0, 30);
1465 }
1466 */
1467 WMRedisplayWidget(panel->prevL);
07e83b45 kojima1999-05-17 03:54:38 +00001468}
1469
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001470static void colorWellObserver(void *self, WMNotification * n)
07e83b45 kojima1999-05-17 03:54:38 +00001471{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001472 _Panel *panel = (_Panel *) self;
1473 int p;
07e83b45 kojima1999-05-17 03:54:38 +00001474
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001475 p = WMGetPopUpButtonSelectedItem(panel->colP);
07e83b45 kojima1999-05-17 03:54:38 +00001476
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001477 WMReleaseColor(panel->colors[p]);
8fb8355a kojima1999-05-19 00:20:45 +00001478
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001479 panel->colors[p] = WMRetainColor(WMGetColorWellColor(panel->colW));
07e83b45 kojima1999-05-17 03:54:38 +00001480
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001481 updateColorPreviewBox(panel, 1 << p);
07e83b45 kojima1999-05-17 03:54:38 +00001482}
1483
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001484static void changedTabItem(struct WMTabViewDelegate *self, WMTabView * tabView, WMTabViewItem * item)
07e83b45 kojima1999-05-17 03:54:38 +00001485{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001486 _Panel *panel = self->data;
1487 int i;
1488
1489 i = WMGetTabViewItemIdentifier(item);
1490 switch (i) {
1491 case 0:
1492 switch (panel->oldTabItem) {
1493 case 1:
1494 changeColorPage(NULL, panel);
1495 break;
1496 }
1497 changePage(panel->secP, panel);
1498 break;
1499 case 1:
1500 switch (panel->oldTabItem) {
1501 case 0:
1502 changePage(NULL, panel);
1503 break;
1504 }
1505 changeColorPage(panel->colP, panel);
1506 break;
1507 case 3:
1508 switch (panel->oldTabItem) {
1509 case 0:
1510 changePage(NULL, panel);
1511 break;
1512 case 1:
1513 changeColorPage(NULL, panel);
1514 break;
1515 }
1516 break;
1517 }
1518
1519 panel->oldTabItem = i;
07e83b45 kojima1999-05-17 03:54:38 +00001520}
1521
07e83b45 kojima1999-05-17 03:54:38 +00001522/*************************************************************************/
1523
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001524static void menuStyleCallback(WMWidget * self, void *data)
905010ce kojima1999-05-16 04:54:13 +00001525{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001526 _Panel *panel = (_Panel *) data;
905010ce kojima1999-05-16 04:54:13 +00001527
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001528 if (self == panel->mstyB[0]) {
1529 panel->menuStyle = MSTYLE_NORMAL;
1530 updatePreviewBox(panel, 1 << PMITEM);
905010ce kojima1999-05-16 04:54:13 +00001531
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001532 } else if (self == panel->mstyB[1]) {
1533 panel->menuStyle = MSTYLE_SINGLE;
1534 updatePreviewBox(panel, 1 << PMITEM);
905010ce kojima1999-05-16 04:54:13 +00001535
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001536 } else if (self == panel->mstyB[2]) {
1537 panel->menuStyle = MSTYLE_FLAT;
1538 updatePreviewBox(panel, 1 << PMITEM);
1539 }
07e83b45 kojima1999-05-17 03:54:38 +00001540}
1541
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001542static void titleAlignCallback(WMWidget * self, void *data)
07e83b45 kojima1999-05-17 03:54:38 +00001543{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001544 _Panel *panel = (_Panel *) data;
07e83b45 kojima1999-05-17 03:54:38 +00001545
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001546 if (self == panel->taliB[0]) {
1547 panel->titleAlignment = WALeft;
1548 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
07e83b45 kojima1999-05-17 03:54:38 +00001549
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001550 } else if (self == panel->taliB[1]) {
1551 panel->titleAlignment = WACenter;
1552 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
07e83b45 kojima1999-05-17 03:54:38 +00001553
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001554 } else if (self == panel->taliB[2]) {
1555 panel->titleAlignment = WARight;
1556 updatePreviewBox(panel, 1 << PFOCUSED | 1 << PUNFOCUSED | 1 << POWNER);
1557 }
905010ce kojima1999-05-16 04:54:13 +00001558}
1559
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001560static void createPanel(Panel * p)
0261c326 dan1999-01-06 15:22:33 +00001561{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001562 _Panel *panel = (_Panel *) p;
1563 WMFont *font;
1564 WMScreen *scr = WMWidgetScreen(panel->parent);
1565 WMTabViewItem *item;
1566 int i;
1567 char *tmp;
1568 Bool ok = True;
1569
1570 panel->fprefix = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
1571
1572 if (access(panel->fprefix, F_OK) != 0) {
1573 if (mkdir(panel->fprefix, 0755) < 0) {
1574 wsyserror(panel->fprefix);
1575 ok = False;
1576 }
1577 }
1578 if (ok) {
1579 tmp = wstrconcat(panel->fprefix, "/WPrefs/");
1580 wfree(panel->fprefix);
1581 panel->fprefix = tmp;
1582 if (access(panel->fprefix, F_OK) != 0) {
1583 if (mkdir(panel->fprefix, 0755) < 0) {
1584 wsyserror(panel->fprefix);
1585 }
1586 }
1587 }
1588
1589 panel->smallFont = WMSystemFontOfSize(scr, 10);
1590 panel->normalFont = WMSystemFontOfSize(scr, 12);
1591 panel->boldFont = WMBoldSystemFontOfSize(scr, 12);
1592
1593 panel->onLed = WMCreatePixmapFromXPMData(scr, blueled_xpm);
1594 panel->offLed = WMCreatePixmapFromXPMData(scr, blueled2_xpm);
1595 panel->hand = WMCreatePixmapFromXPMData(scr, hand_xpm);
1596
1597 panel->box = WMCreateBox(panel->parent);
1598 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
1599
1600 /* preview box */
1601 panel->prevL = WMCreateLabel(panel->box);
1602 WMResizeWidget(panel->prevL, 240, FRAME_HEIGHT - 20);
1603 WMMoveWidget(panel->prevL, 15, 10);
1604 WMSetLabelRelief(panel->prevL, WRSunken);
1605 WMSetLabelImagePosition(panel->prevL, WIPImageOnly);
1606
1607 WMCreateEventHandler(WMWidgetView(panel->prevL), ButtonPressMask, previewClick, panel);
1608
1609 /* tabview */
1610
1611 tabviewDelegate.data = panel;
1612
1613 panel->tabv = WMCreateTabView(panel->box);
1614 WMResizeWidget(panel->tabv, 245, FRAME_HEIGHT - 20);
1615 WMMoveWidget(panel->tabv, 265, 10);
1616 WMSetTabViewDelegate(panel->tabv, &tabviewDelegate);
0261c326 dan1999-01-06 15:22:33 +00001617
dd2d71fc kojima1999-05-15 17:38:05 +00001618 /*** texture list ***/
1619
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001620 panel->texF = WMCreateFrame(panel->box);
1621 WMSetFrameRelief(panel->texF, WRFlat);
1622
1623 item = WMCreateTabViewItemWithIdentifier(0);
1624 WMSetTabViewItemView(item, WMWidgetView(panel->texF));
1625 WMSetTabViewItemLabel(item, _("Texture"));
1626
1627 WMAddItemInTabView(panel->tabv, item);
1628
1629 panel->secP = WMCreatePopUpButton(panel->texF);
1630 WMResizeWidget(panel->secP, 228, 20);
1631 WMMoveWidget(panel->secP, 7, 7);
1632 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window"));
1633 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Unfocused Windows"));
1634 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Focused Window's Owner"));
1635 WMAddPopUpButtonItem(panel->secP, _("Window Resizebar"));
1636 WMAddPopUpButtonItem(panel->secP, _("Titlebar of Menus"));
1637 WMAddPopUpButtonItem(panel->secP, _("Menu Items"));
1638 WMAddPopUpButtonItem(panel->secP, _("Icon Background"));
1639 /* WMAddPopUpButtonItem(panel->secP, _("Workspace Backgrounds"));
1640 */
1641 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1642 WMSetPopUpButtonAction(panel->secP, changePage, panel);
1643
1644 panel->texLs = WMCreateList(panel->texF);
1645 WMResizeWidget(panel->texLs, 165, 155);
1646 WMMoveWidget(panel->texLs, 70, 33);
1647 WMSetListUserDrawItemHeight(panel->texLs, 35);
1648 WMSetListUserDrawProc(panel->texLs, paintListItem);
1649 WMHangData(panel->texLs, panel);
1650 WMSetListAction(panel->texLs, textureClick, panel);
1651 WMSetListDoubleAction(panel->texLs, textureDoubleClick, panel);
1652
1653 WMSetBalloonTextForView(_("Double click in the texture you want to use\n"
1654 "for the selected item."), WMWidgetView(panel->texLs));
1655
1656 /* command buttons */
1657
1658 font = WMSystemFontOfSize(scr, 10);
1659
1660 panel->newB = WMCreateCommandButton(panel->texF);
1661 WMResizeWidget(panel->newB, 57, 39);
1662 WMMoveWidget(panel->newB, 7, 33);
1663 WMSetButtonFont(panel->newB, font);
1664 WMSetButtonImagePosition(panel->newB, WIPAbove);
1665 WMSetButtonText(panel->newB, _("New"));
1666 WMSetButtonAction(panel->newB, newTexture, panel);
1667 SetButtonAlphaImage(scr, panel->newB, TNEW_FILE, NULL, NULL);
1668
1669 WMSetBalloonTextForView(_("Create a new texture."), WMWidgetView(panel->newB));
1670
1671 panel->ripB = WMCreateCommandButton(panel->texF);
1672 WMResizeWidget(panel->ripB, 57, 39);
1673 WMMoveWidget(panel->ripB, 7, 72);
1674 WMSetButtonFont(panel->ripB, font);
1675 WMSetButtonImagePosition(panel->ripB, WIPAbove);
1676 WMSetButtonText(panel->ripB, _("Extract..."));
1677 WMSetButtonAction(panel->ripB, extractTexture, panel);
1678 SetButtonAlphaImage(scr, panel->ripB, TEXTR_FILE, NULL, NULL);
1679
1680 WMSetBalloonTextForView(_("Extract texture(s) from a theme or a style file."), WMWidgetView(panel->ripB));
1681
1682 WMSetButtonEnabled(panel->ripB, False);
1683
1684 panel->editB = WMCreateCommandButton(panel->texF);
1685 WMResizeWidget(panel->editB, 57, 39);
1686 WMMoveWidget(panel->editB, 7, 111);
1687 WMSetButtonFont(panel->editB, font);
1688 WMSetButtonImagePosition(panel->editB, WIPAbove);
1689 WMSetButtonText(panel->editB, _("Edit"));
1690 SetButtonAlphaImage(scr, panel->editB, TEDIT_FILE, NULL, NULL);
1691 WMSetButtonAction(panel->editB, editTexture, panel);
1692 WMSetBalloonTextForView(_("Edit the highlighted texture."), WMWidgetView(panel->editB));
1693
1694 panel->delB = WMCreateCommandButton(panel->texF);
1695 WMResizeWidget(panel->delB, 57, 38);
1696 WMMoveWidget(panel->delB, 7, 150);
1697 WMSetButtonFont(panel->delB, font);
1698 WMSetButtonImagePosition(panel->delB, WIPAbove);
1699 WMSetButtonText(panel->delB, _("Delete"));
1700 SetButtonAlphaImage(scr, panel->delB, TDEL_FILE, NULL, NULL);
1701 WMSetButtonEnabled(panel->delB, False);
1702 WMSetButtonAction(panel->delB, deleteTexture, panel);
1703 WMSetBalloonTextForView(_("Delete the highlighted texture."), WMWidgetView(panel->delB));
1704
1705 WMReleaseFont(font);
1706
1707 WMMapSubwidgets(panel->texF);
dd2d71fc kojima1999-05-15 17:38:05 +00001708
1709 /*** colors ***/
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001710 panel->colF = WMCreateFrame(panel->box);
1711 WMSetFrameRelief(panel->colF, WRFlat);
1712
1713 item = WMCreateTabViewItemWithIdentifier(1);
1714 WMSetTabViewItemView(item, WMWidgetView(panel->colF));
1715 WMSetTabViewItemLabel(item, _("Color"));
1716
1717 WMAddItemInTabView(panel->tabv, item);
1718
1719 panel->colP = WMCreatePopUpButton(panel->colF);
1720 WMResizeWidget(panel->colP, 228, 20);
1721 WMMoveWidget(panel->colP, 7, 7);
1722 WMAddPopUpButtonItem(panel->colP, _("Focused Window Title"));
1723 WMAddPopUpButtonItem(panel->colP, _("Unfocused Window Title"));
1724 WMAddPopUpButtonItem(panel->colP, _("Owner of Focused Window Title"));
1725 WMAddPopUpButtonItem(panel->colP, _("Menu Title"));
1726 WMAddPopUpButtonItem(panel->colP, _("Menu Item Text"));
1727 WMAddPopUpButtonItem(panel->colP, _("Disabled Menu Item Text"));
1728 WMAddPopUpButtonItem(panel->colP, _("Menu Highlight Color"));
1729 WMAddPopUpButtonItem(panel->colP, _("Highlighted Menu Text Color"));
1730 /*
1731 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title"));
1732 WMAddPopUpButtonItem(panel->colP, _("Miniwindow Title Back"));
1733 WMAddPopUpButtonItem(panel->colP, _("Clip Title"));
1734 WMAddPopUpButtonItem(panel->colP, _("Collapsed Clip Title"));
1735 */
1736
1737 WMSetPopUpButtonSelectedItem(panel->colP, 0);
1738
1739 WMSetPopUpButtonAction(panel->colP, changeColorPage, panel);
1740
1741 panel->colW = WMCreateColorWell(panel->colF);
1742 WMResizeWidget(panel->colW, 65, 50);
1743 WMMoveWidget(panel->colW, 30, 75);
1744 WMAddNotificationObserver(colorWellObserver, panel, WMColorWellDidChangeNotification, panel->colW);
1745
1746 for (i = 0; i < 4; i++) {
1747 int j;
1748 for (j = 0; j < 6; j++) {
1749 panel->sampW[i + j * 4] = WMCreateColorWell(panel->colF);
1750 WMResizeWidget(panel->sampW[i + j * 4], 22, 22);
1751 WMMoveWidget(panel->sampW[i + j * 4], 130 + i * 22, 40 + j * 22);
1752 WSetColorWellBordered(panel->sampW[i + j * 4], False);
1753 }
1754 }
1755
1756 WMMapSubwidgets(panel->colF);
6830b057 dan2004-10-12 21:28:27 +00001757
7ab70f69 kojima2001-01-06 23:52:00 +00001758#ifdef unfinished
e44130b5 kojima2000-05-22 03:24:40 +00001759 /*** root bg ***/
6830b057 dan2004-10-12 21:28:27 +00001760
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001761 panel->bgF = WMCreateFrame(panel->box);
1762 WMSetFrameRelief(panel->bgF, WRFlat);
e44130b5 kojima2000-05-22 03:24:40 +00001763
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001764 item = WMCreateTabViewItemWithIdentifier(2);
1765 WMSetTabViewItemView(item, WMWidgetView(panel->bgF));
1766 WMSetTabViewItemLabel(item, _("Background"));
e44130b5 kojima2000-05-22 03:24:40 +00001767
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001768 WMAddItemInTabView(panel->tabv, item);
e44130b5 kojima2000-05-22 03:24:40 +00001769
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001770 panel->bgprevL = WMCreateLabel(panel->bgF);
1771 WMResizeWidget(panel->bgprevL, 230, 155);
1772 WMMoveWidget(panel->bgprevL, 5, 5);
1773 WMSetLabelRelief(panel->bgprevL, WRSunken);
6830b057 dan2004-10-12 21:28:27 +00001774
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001775 panel->selbgB = WMCreateCommandButton(panel->bgF);
1776 WMMoveWidget(panel->selbgB, 5, 165);
1777 WMResizeWidget(panel->selbgB, 100, 24);
1778 WMSetButtonText(panel->selbgB, _("Browse..."));
6830b057 dan2004-10-12 21:28:27 +00001779
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001780 WMMapSubwidgets(panel->bgF);
1781#endif /* unfinished */
905010ce kojima1999-05-16 04:54:13 +00001782 /*** options ***/
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001783 panel->optF = WMCreateFrame(panel->box);
1784 WMSetFrameRelief(panel->optF, WRFlat);
1785
1786 item = WMCreateTabViewItemWithIdentifier(3);
1787 WMSetTabViewItemView(item, WMWidgetView(panel->optF));
1788 WMSetTabViewItemLabel(item, _("Options"));
1789
1790 WMAddItemInTabView(panel->tabv, item);
1791
1792 panel->mstyF = WMCreateFrame(panel->optF);
1793 WMResizeWidget(panel->mstyF, 215, 85);
1794 WMMoveWidget(panel->mstyF, 15, 10);
1795 WMSetFrameTitle(panel->mstyF, _("Menu Style"));
1796
1797 for (i = 0; i < 3; i++) {
1798 WMPixmap *icon;
1799 char *path;
1800
1801 panel->mstyB[i] = WMCreateButton(panel->mstyF, WBTOnOff);
1802 WMResizeWidget(panel->mstyB[i], 54, 54);
1803 WMMoveWidget(panel->mstyB[i], 15 + i * 65, 20);
1804 WMSetButtonImagePosition(panel->mstyB[i], WIPImageOnly);
1805 WMSetButtonAction(panel->mstyB[i], menuStyleCallback, panel);
1806 switch (i) {
1807 case 0:
1808 path = LocateImage(MSTYLE1_FILE);
1809 break;
1810 case 1:
1811 path = LocateImage(MSTYLE2_FILE);
1812 break;
1813 case 2:
1814 path = LocateImage(MSTYLE3_FILE);
1815 break;
1816 }
1817 if (path) {
1818 icon = WMCreatePixmapFromFile(scr, path);
1819 if (icon) {
1820 WMSetButtonImage(panel->mstyB[i], icon);
1821 WMReleasePixmap(icon);
1822 } else {
1823 wwarning(_("could not load icon file %s"), path);
1824 }
1825 wfree(path);
1826 }
1827 }
1828 WMGroupButtons(panel->mstyB[0], panel->mstyB[1]);
1829 WMGroupButtons(panel->mstyB[0], panel->mstyB[2]);
1830
1831 WMMapSubwidgets(panel->mstyF);
1832
1833 panel->taliF = WMCreateFrame(panel->optF);
1834 WMResizeWidget(panel->taliF, 110, 80);
1835 WMMoveWidget(panel->taliF, 15, 100);
1836 WMSetFrameTitle(panel->taliF, _("Title Alignment"));
1837
1838 for (i = 0; i < 3; i++) {
1839 panel->taliB[i] = WMCreateRadioButton(panel->taliF);
1840 WMSetButtonAction(panel->taliB[i], titleAlignCallback, panel);
1841 switch (i) {
1842 case 0:
1843 WMSetButtonText(panel->taliB[i], _("Left"));
1844 break;
1845 case 1:
1846 WMSetButtonText(panel->taliB[i], _("Center"));
1847 break;
1848 case 2:
1849 WMSetButtonText(panel->taliB[i], _("Right"));
1850 break;
1851 }
1852 WMResizeWidget(panel->taliB[i], 90, 18);
1853 WMMoveWidget(panel->taliB[i], 10, 15 + 20 * i);
1854 }
1855 WMGroupButtons(panel->taliB[0], panel->taliB[1]);
1856 WMGroupButtons(panel->taliB[0], panel->taliB[2]);
1857
1858 WMMapSubwidgets(panel->taliF);
1859
1860 WMMapSubwidgets(panel->optF);
1861
1862 /**/ WMRealizeWidget(panel->box);
1863 WMMapSubwidgets(panel->box);
1864
1865 WMSetPopUpButtonSelectedItem(panel->secP, 0);
1866
1867 showData(panel);
1868
1869 changePage(panel->secP, panel);
1870
1871 fillTextureList(panel->texLs);
1872
1873 fillColorList(panel);
1874
1875 panel->texturePanel = CreateTexturePanel(panel->parent);
088c0ac2 dan1999-03-09 14:58:01 +00001876}
1877
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001878static void setupTextureFor(WMList * list, char *key, char *defValue, char *title, int index)
088c0ac2 dan1999-03-09 14:58:01 +00001879{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001880 WMListItem *item;
1881 TextureListItem *titem;
1882
1883 titem = wmalloc(sizeof(TextureListItem));
1884 memset(titem, 0, sizeof(TextureListItem));
1885
1886 titem->title = wstrdup(title);
1887 titem->prop = GetObjectForKey(key);
1888 if (!titem->prop || !WMIsPLArray(titem->prop)) {
1889 /* Maybe also give a error message to stderr that the entry is bad? */
1890 titem->prop = WMCreatePropListFromDescription(defValue);
1891 } else {
1892 WMRetainPropList(titem->prop);
1893 }
1894 titem->texture = WMGetPropListDescription((WMPropList *) titem->prop, False);
1895 titem->current = 1;
1896 titem->selectedFor = 1 << index;
1897
1898 titem->ispixmap = isPixmap(titem->prop);
1899
1900 titem->preview = renderTexture(WMWidgetScreen(list), titem->prop, TEXPREV_WIDTH, TEXPREV_HEIGHT, NULL, 0);
1901
1902 item = WMAddListItem(list, "");
1903 item->clientData = titem;
088c0ac2 dan1999-03-09 14:58:01 +00001904}
0261c326 dan1999-01-06 15:22:33 +00001905
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001906static void showData(_Panel * panel)
088c0ac2 dan1999-03-09 14:58:01 +00001907{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001908 int i;
1909 char *str;
1910
1911 str = GetStringForKey("MenuStyle");
1912 if (str && strcasecmp(str, "flat") == 0) {
1913 panel->menuStyle = MSTYLE_FLAT;
1914 } else if (str && strcasecmp(str, "singletexture") == 0) {
1915 panel->menuStyle = MSTYLE_SINGLE;
1916 } else {
1917 panel->menuStyle = MSTYLE_NORMAL;
1918 }
1919
1920 str = GetStringForKey("TitleJustify");
1921 if (str && strcasecmp(str, "left") == 0) {
1922 panel->titleAlignment = WALeft;
1923 } else if (str && strcasecmp(str, "right") == 0) {
1924 panel->titleAlignment = WARight;
1925 } else {
1926 panel->titleAlignment = WACenter;
1927 }
1928
1929 for (i = 0; i < sizeof(colorOptions) / (2 * sizeof(char *)); i++) {
1930 WMColor *color;
1931
1932 str = GetStringForKey(colorOptions[i * 2]);
1933 if (!str)
1934 str = colorOptions[i * 2 + 1];
1935
1936 if (!(color = WMCreateNamedColor(WMWidgetScreen(panel->box), str, False))) {
1937 color = WMCreateNamedColor(WMWidgetScreen(panel->box), "#000000", False);
1938 }
1939
1940 panel->colors[i] = color;
1941 }
1942 changeColorPage(panel->colP, panel);
1943
1944 for (i = 0; i < sizeof(textureOptions) / (3 * sizeof(char *)); i++) {
1945 setupTextureFor(panel->texLs, textureOptions[i * 3],
1946 textureOptions[i * 3 + 1], textureOptions[i * 3 + 2], i);
1947 panel->textureIndex[i] = i;
1948 }
1949 updatePreviewBox(panel, EVERYTHING);
1950
1951 WMSetButtonSelected(panel->mstyB[panel->menuStyle], True);
1952 WMSetButtonSelected(panel->taliB[panel->titleAlignment], True);
c56756dc dan1999-03-14 22:35:50 +00001953}
1954
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02001955static void storeData(_Panel * panel)
c56756dc dan1999-03-14 22:35:50 +00001956{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02001957 TextureListItem *titem;
1958 WMListItem *item;
1959 int i;
1960
1961 for (i = 0; i < sizeof(textureOptions) / (sizeof(char *) * 3); i++) {
1962 item = WMGetListItem(panel->texLs, panel->textureIndex[i]);
1963 titem = (TextureListItem *) item->clientData;
1964 SetObjectForKey(titem->prop, textureOptions[i * 3]);
1965 }
1966
1967 for (i = 0; i < 8; i++) {
1968 char *str;
1969
1970 str = WMGetColorRGBDescription(panel->colors[i]);
1971
1972 if (str) {
1973 SetStringForKey(str, colorOptions[i * 2]);
1974 wfree(str);
1975 }
1976 }
1977
1978 switch (panel->menuStyle) {
1979 case MSTYLE_SINGLE:
1980 SetStringForKey("singletexture", "MenuStyle");
1981 break;
1982 case MSTYLE_FLAT:
1983 SetStringForKey("flat", "MenuStyle");
1984 break;
1985 default:
1986 case MSTYLE_NORMAL:
1987 SetStringForKey("normal", "MenuStyle");
1988 break;
1989 }
1990 switch (panel->titleAlignment) {
1991 case WALeft:
1992 SetStringForKey("left", "TitleJustify");
1993 break;
1994 case WARight:
1995 SetStringForKey("right", "TitleJustify");
1996 break;
1997 default:
1998 case WACenter:
1999 SetStringForKey("center", "TitleJustify");
2000 break;
2001 }
ea55bc5e kojima1999-03-18 01:11:18 +00002002}
2003
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002004static void prepareForClose(_Panel * panel)
ea55bc5e kojima1999-03-18 01:11:18 +00002005{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002006 WMPropList *textureList;
2007 WMPropList *texture;
2008 TextureListItem *titem;
2009 WMListItem *item;
2010 WMUserDefaults *udb = WMGetStandardUserDefaults();
2011 int i;
0261c326 dan1999-01-06 15:22:33 +00002012
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002013 textureList = WMCreatePLArray(NULL, NULL);
0261c326 dan1999-01-06 15:22:33 +00002014
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002015 /* store list of textures */
2016 for (i = 7; i < WMGetListNumberOfRows(panel->texLs); i++) {
2017 item = WMGetListItem(panel->texLs, i);
2018 titem = (TextureListItem *) item->clientData;
0261c326 dan1999-01-06 15:22:33 +00002019
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002020 texture = WMCreatePLArray(WMCreatePLString(titem->title),
2021 WMRetainPropList(titem->prop), WMCreatePLString(titem->path), NULL);
6830b057 dan2004-10-12 21:28:27 +00002022
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002023 WMAddToPLArray(textureList, texture);
2024 }
0261c326 dan1999-01-06 15:22:33 +00002025
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002026 WMSetUDObjectForKey(udb, textureList, "TextureList");
2027 WMReleasePropList(textureList);
d3f29988 kojima1999-04-25 01:49:46 +00002028
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002029 /* store list of colors */
2030 textureList = WMCreatePLArray(NULL, NULL);
2031 for (i = 0; i < 24; i++) {
2032 WMColor *color;
2033 char *str;
0261c326 dan1999-01-06 15:22:33 +00002034
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002035 color = WMGetColorWellColor(panel->sampW[i]);
0261c326 dan1999-01-06 15:22:33 +00002036
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002037 str = WMGetColorRGBDescription(color);
2038 WMAddToPLArray(textureList, WMCreatePLString(str));
2039 wfree(str);
2040 }
2041 WMSetUDObjectForKey(udb, textureList, "ColorList");
2042 WMReleasePropList(textureList);
0261c326 dan1999-01-06 15:22:33 +00002043
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002044 WMSynchronizeUserDefaults(udb);
0261c326 dan1999-01-06 15:22:33 +00002045}
52988491 kojima1999-03-16 11:27:01 +00002046
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002047Panel *InitAppearance(WMScreen * scr, WMWindow * win)
2048{
2049 _Panel *panel;
52988491 kojima1999-03-16 11:27:01 +00002050
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002051 panel = wmalloc(sizeof(_Panel));
2052 memset(panel, 0, sizeof(_Panel));
52988491 kojima1999-03-16 11:27:01 +00002053
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002054 panel->sectionName = _("Appearance Preferences");
52988491 kojima1999-03-16 11:27:01 +00002055
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002056 panel->description = _("Background texture configuration for windows,\n" "menus and icons.");
52988491 kojima1999-03-16 11:27:01 +00002057
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002058 panel->parent = win;
52988491 kojima1999-03-16 11:27:01 +00002059
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002060 panel->callbacks.createWidgets = createPanel;
2061 panel->callbacks.updateDomain = storeData;
2062 panel->callbacks.prepareForClose = prepareForClose;
52988491 kojima1999-03-16 11:27:01 +00002063
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002064 AddSection(panel, ICON_FILE);
52988491 kojima1999-03-16 11:27:01 +00002065
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002066 return panel;
2067}
52988491 kojima1999-03-16 11:27:01 +00002068
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002069/****************************************************************************/
52988491 kojima1999-03-16 11:27:01 +00002070
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002071typedef struct ExtractPanel {
2072 WMWindow *win;
52988491 kojima1999-03-16 11:27:01 +00002073
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002074 WMLabel *label;
2075 WMList *list;
52988491 kojima1999-03-16 11:27:01 +00002076
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002077 WMButton *closeB;
2078 WMButton *extrB;
2079} ExtractPanel;
52988491 kojima1999-03-16 11:27:01 +00002080
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002081static void OpenExtractPanelFor(_Panel * panel, char *path)
2082{
2083 ExtractPanel *epanel;
2084 WMColor *color;
2085 WMFont *font;
2086 WMScreen *scr = WMWidgetScreen(panel->parent);
52988491 kojima1999-03-16 11:27:01 +00002087
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002088 epanel = wmalloc(sizeof(ExtractPanel));
2089 epanel->win = WMCreatePanelWithStyleForWindow(panel->parent, "extract",
2090 WMTitledWindowMask | WMClosableWindowMask);
2091 WMResizeWidget(epanel->win, 245, 250);
2092 WMSetWindowTitle(epanel->win, _("Extract Texture"));
52988491 kojima1999-03-16 11:27:01 +00002093
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002094 epanel->label = WMCreateLabel(epanel->win);
2095 WMResizeWidget(epanel->label, 225, 18);
2096 WMMoveWidget(epanel->label, 10, 10);
2097 WMSetLabelTextAlignment(epanel->label, WACenter);
2098 WMSetLabelRelief(epanel->label, WRSunken);
52988491 kojima1999-03-16 11:27:01 +00002099
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002100 color = WMDarkGrayColor(scr);
2101 WMSetWidgetBackgroundColor(epanel->label, color);
2102 WMReleaseColor(color);
6830b057 dan2004-10-12 21:28:27 +00002103
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002104 color = WMWhiteColor(scr);
2105 WMSetLabelTextColor(epanel->label, color);
2106 WMReleaseColor(color);
52988491 kojima1999-03-16 11:27:01 +00002107
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002108 font = WMBoldSystemFontOfSize(scr, 12);
2109 WMSetLabelFont(epanel->label, font);
2110 WMReleaseFont(font);
52988491 kojima1999-03-16 11:27:01 +00002111
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002112 WMSetLabelText(epanel->label, _("Textures"));
52988491 kojima1999-03-16 11:27:01 +00002113
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002114 epanel->list = WMCreateList(epanel->win);
2115 WMResizeWidget(epanel->list, 225, 165);
2116 WMMoveWidget(epanel->list, 10, 30);
52988491 kojima1999-03-16 11:27:01 +00002117
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002118 epanel->closeB = WMCreateCommandButton(epanel->win);
2119 WMResizeWidget(epanel->closeB, 74, 24);
2120 WMMoveWidget(epanel->closeB, 165, 215);
2121 WMSetButtonText(epanel->closeB, _("Close"));
6830b057 dan2004-10-12 21:28:27 +00002122
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +02002123 epanel->extrB = WMCreateCommandButton(epanel->win);
2124 WMResizeWidget(epanel->extrB, 74, 24);
2125 WMMoveWidget(epanel->extrB, 80, 215);
2126 WMSetButtonText(epanel->extrB, _("Extract"));
6830b057 dan2004-10-12 21:28:27 +00002127
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002128 WMMapSubwidgets(epanel->win);
6830b057 dan2004-10-12 21:28:27 +00002129
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002130 /* take textures from file */
52988491 kojima1999-03-16 11:27:01 +00002131
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002132 WMRealizeWidget(epanel->win);
6830b057 dan2004-10-12 21:28:27 +00002133
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +02002134 WMMapWidget(epanel->win);
52988491 kojima1999-03-16 11:27:01 +00002135}