2 * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3 * Copyright (C) 2004-2008 Kim Woelders
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies of the Software, its documentation and marketing & publicity
14 * materials, and acknowledgment shall be given in the documentation, materials
15 * and software packages that this Software was used.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include "e16-ecore_list.h"
32 #define ENABLE_DESTROY 0 /* Broken */
34 static Ecore_List *tclass_list = NULL;
36 static TextClass *TextclassGetFallback(void);
39 TextstateFontLookup(const char *name)
45 font = FontLookup(name + 1);
53 TextstateCreate(const char *font)
57 ts = ECALLOC(TextState, 1);
61 ts->style.mode = MODE_WRAP_CHAR;
62 ts->style.orientation = FONT_TO_RIGHT;
66 ts->fontname = TextstateFontLookup(font);
67 ts->style.mode = MODE_VERBATIM;
75 TextStateDestroy(TextState * ts)
89 TextclassCreate(const char *name)
93 tc = ECALLOC(TextClass, 1);
98 tclass_list = ecore_list_new();
99 ecore_list_prepend(tclass_list, tc);
101 tc->name = Estrdup(name);
102 tc->justification = 512;
109 TextclassDestroy(TextClass * tc)
111 if (tc->ref_count > 0)
113 DialogOK("TextClass Error!", _("%u references remain\n"),
118 TextStateDestroy(tc->norm.normal);
119 TextStateDestroy(tc->norm.hilited);
120 TextStateDestroy(tc->norm.clicked);
121 TextStateDestroy(tc->norm.disabled);
122 TextStateDestroy(tc->active.normal);
123 TextStateDestroy(tc->active.hilited);
124 TextStateDestroy(tc->active.clicked);
125 TextStateDestroy(tc->active.disabled);
126 TextStateDestroy(tc->sticky.normal);
127 TextStateDestroy(tc->sticky.hilited);
128 TextStateDestroy(tc->sticky.clicked);
129 TextStateDestroy(tc->sticky.disabled);
130 TextStateDestroy(tc->sticky_active.normal);
131 TextStateDestroy(tc->sticky_active.hilited);
132 TextStateDestroy(tc->sticky_active.clicked);
133 TextStateDestroy(tc->sticky_active.disabled);
137 #endif /* ENABLE_DESTROY */
140 TextclassAlloc(const char *name, int fallback)
144 if (!name || !name[0])
147 tc = TextclassFind(name, fallback);
155 TextclassFree(TextClass * tc)
162 TextclassGetJustification(TextClass * tc)
164 return tc->justification;
168 TextclassSetJustification(TextClass * tc, int just)
170 tc->justification = just;
174 TextclassPopulate(TextClass * tclass)
179 if (!tclass->norm.normal)
182 if (!tclass->norm.hilited)
183 tclass->norm.hilited = tclass->norm.normal;
184 if (!tclass->norm.clicked)
185 tclass->norm.clicked = tclass->norm.normal;
186 if (!tclass->norm.disabled)
187 tclass->norm.disabled = tclass->norm.normal;
189 if (!tclass->active.normal)
190 tclass->active.normal = tclass->norm.normal;
191 if (!tclass->active.hilited)
192 tclass->active.hilited = tclass->active.normal;
193 if (!tclass->active.clicked)
194 tclass->active.clicked = tclass->active.normal;
195 if (!tclass->active.disabled)
196 tclass->active.disabled = tclass->active.normal;
198 if (!tclass->sticky.normal)
199 tclass->sticky.normal = tclass->norm.normal;
200 if (!tclass->sticky.hilited)
201 tclass->sticky.hilited = tclass->sticky.normal;
202 if (!tclass->sticky.clicked)
203 tclass->sticky.clicked = tclass->sticky.normal;
204 if (!tclass->sticky.disabled)
205 tclass->sticky.disabled = tclass->sticky.normal;
207 if (!tclass->sticky_active.normal)
208 tclass->sticky_active.normal = tclass->norm.normal;
209 if (!tclass->sticky_active.hilited)
210 tclass->sticky_active.hilited = tclass->sticky_active.normal;
211 if (!tclass->sticky_active.clicked)
212 tclass->sticky_active.clicked = tclass->sticky_active.normal;
213 if (!tclass->sticky_active.disabled)
214 tclass->sticky_active.disabled = tclass->sticky_active.normal;
218 _TextclassMatchName(const void *data, const void *match)
220 return strcmp(((const TextClass *)data)->name, (const char *)match);
224 TextclassFind(const char *name, int fallback)
226 TextClass *tc = NULL;
229 tc = (TextClass *) ecore_list_find(tclass_list, _TextclassMatchName,
235 Eprintf("%s: Get fallback (%s)\n", __func__, name);
237 return TextclassGetFallback();
241 TextclassConfigLoad(FILE * fs)
244 char s[FILEPATH_LEN_MAX];
245 char s2[FILEPATH_LEN_MAX];
247 TextClass *tc = NULL;
248 TextState *ts = NULL;
250 while (GetLine(s, sizeof(s), fs))
252 i1 = ConfigParseline1(s, s2, NULL, NULL);
256 TextclassPopulate(tc);
258 case CONFIG_CLASSNAME:
259 if (TextclassFind(s2, 0))
264 tc = TextclassCreate(s2);
266 case TEXT_ORIENTATION:
268 ts->style.orientation = atoi(s2);
270 case TEXT_JUSTIFICATION:
272 tc->justification = atoi(s2);
277 tc->norm.normal = ts = TextstateCreate(s2);
281 tc->norm.clicked = ts = TextstateCreate(s2);
285 tc->norm.hilited = ts = TextstateCreate(s2);
287 case ICLASS_DISABLED:
289 tc->norm.disabled = ts = TextstateCreate(s2);
291 case ICLASS_STICKY_NORMAL:
293 tc->sticky.normal = ts = TextstateCreate(s2);
295 case ICLASS_STICKY_CLICKED:
297 tc->sticky.clicked = ts = TextstateCreate(s2);
299 case ICLASS_STICKY_HILITED:
301 tc->sticky.hilited = ts = TextstateCreate(s2);
303 case ICLASS_STICKY_DISABLED:
305 tc->sticky.disabled = ts = TextstateCreate(s2);
307 case ICLASS_ACTIVE_NORMAL:
309 tc->active.normal = ts = TextstateCreate(s2);
311 case ICLASS_ACTIVE_CLICKED:
313 tc->active.clicked = ts = TextstateCreate(s2);
315 case ICLASS_ACTIVE_HILITED:
317 tc->active.hilited = ts = TextstateCreate(s2);
319 case ICLASS_ACTIVE_DISABLED:
321 tc->active.disabled = ts = TextstateCreate(s2);
323 case ICLASS_STICKY_ACTIVE_NORMAL:
325 tc->sticky_active.normal = ts = TextstateCreate(s2);
327 case ICLASS_STICKY_ACTIVE_CLICKED:
329 tc->sticky_active.clicked = ts = TextstateCreate(s2);
331 case ICLASS_STICKY_ACTIVE_HILITED:
333 tc->sticky_active.hilited = ts = TextstateCreate(s2);
335 case ICLASS_STICKY_ACTIVE_DISABLED:
337 tc->sticky_active.disabled = ts = TextstateCreate(s2);
341 ts->style.mode = atoi(s2);
345 ts->style.effect = atoi(s2);
351 sscanf(s, "%*s %i %i %i", &r, &g, &b);
352 SET_COLOR(&ts->fg_col, r, g, b);
359 sscanf(s, "%*s %i %i %i", &r, &g, &b);
360 SET_COLOR(&ts->bg_col, r, g, b);
364 ConfigParseError("TextClass", s);
375 TextclassGetFallback(void)
379 tc = TextclassFind("__fb_tc", 0);
383 /* Create fallback textclass */
384 tc = TextclassCreate("__fb_tc");
389 TextstateCreate("-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*");
390 SET_COLOR(&(tc->norm.normal->fg_col), 0, 0, 0);
391 TextclassPopulate(tc);
401 TextclassIpc(const char *params)
411 IpcPrintf("Please specify...\n");
417 param1[0] = param2[0] = '\0';
418 sscanf(p, "%1000s %1000s %n", param1, param2, &l);
421 if (!strncmp(param1, "list", 2))
423 ECORE_LIST_FOR_EACH(tclass_list, tc) IpcPrintf("%s\n", tc->name);
429 IpcPrintf("TextClass not specified\n");
433 if (!strcmp(param2, "create"))
435 /* Not implemented */
439 tc = TextclassFind(param1, 0);
442 IpcPrintf("TextClass not found: %s\n", param1);
446 if (!strcmp(param2, "delete"))
449 TextclassDestroy(tc);
452 else if (!strcmp(param2, "modify"))
454 /* Not implemented */
456 else if (!strcmp(param2, "apply"))
463 /* 3:xwin 4:x 5:y 6:state 7-:txt */
468 sscanf(p, "%lx %d %d %16s %n", &xwin, &x, &y, state, &l);
471 if (!strcmp(state, "normal"))
473 else if (!strcmp(state, "hilited"))
475 else if (!strcmp(state, "clicked"))
477 else if (!strcmp(state, "disabled"))
485 win = ECreateWinFromXwin(xwin);
489 TextDraw(tc, win, None, 0, 0, st, p, x, y, 99999, 99999, 17, 0);
492 else if (!strcmp(param2, "query_size"))
502 TextSize(tc, 0, 0, STATE_NORMAL, p, &w, &h, 17);
503 IpcPrintf("%i %i\n", w, h);
505 else if (!strcmp(param2, "query"))
507 IpcPrintf("TextClass %s found\n", tc->name);
509 else if (!strcmp(param2, "ref_count"))
511 IpcPrintf("%u references remain\n", tc->ref_count);
515 IpcPrintf("Error: unknown operation specified\n");
519 static const IpcItem TextclassIpcArray[] = {
523 "List textclasses, apply a textclass",
527 #define N_IPC_FUNCS (sizeof(TextclassIpcArray)/sizeof(IpcItem))
532 extern const EModule ModTextclass;
533 const EModule ModTextclass = {
536 {N_IPC_FUNCS, TextclassIpcArray}