/rusxmms/librcc

To get this branch, use:
bzr branch http://suren.me/webbzr/rusxmms/librcc

« back to all changes in this revision

Viewing changes to ui/librccui.c

  • Committer: Suren A. Chilingaryan
  • Date: 2005-07-02 05:08:36 UTC
  • Revision ID: Arch-1:ds@dside.dyndns.org--darksoft-2004%librcc--main--0.1--patch-3
02.07.2005

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include "../src/rccconfig.h"
 
3
#include "internal.h"
 
4
#include "rccnames.h"
 
5
 
 
6
#define RCC_UI_LOCK_CODE 0x1111
 
7
 
 
8
static rcc_ui_menu_context rccUiMenuCreateContext(rcc_ui_menu_type type, rcc_ui_id id, rcc_ui_context uictx) {
 
9
    rcc_ui_menu_context ctx;
 
10
    if ((!uictx)||(type>RCC_UI_MENU_MAX)) return NULL;
 
11
    
 
12
    ctx = (rcc_ui_menu_context)malloc(sizeof(rcc_ui_menu_context_s));
 
13
    if (!ctx) return ctx;
 
14
    
 
15
    ctx->uictx = uictx;
 
16
    ctx->type = type;
 
17
    ctx->id = id;
 
18
    
 
19
    ctx->widget = rccUiMenuCreateWidget(ctx);
 
20
    ctx->box = NULL;
 
21
    
 
22
    return ctx;
 
23
}
 
24
 
 
25
static void rccUiMenuFreeContext(rcc_ui_menu_context ctx) {
 
26
    if (!ctx) return;
 
27
    rccUiMenuFreeWidget(ctx);
 
28
    free(ctx);
 
29
}
 
30
 
 
31
rcc_ui_context rccUiCreateContext(rcc_context rccctx) {
 
32
    int err = 0;
 
33
    unsigned int i;
 
34
    
 
35
    rcc_class_ptr *classes;
 
36
    rcc_ui_context ctx;
 
37
    rcc_ui_menu_context *charsets;
 
38
    rcc_ui_menu_context *options;
 
39
    
 
40
    if (!rccctx) return NULL;
 
41
 
 
42
    err = rccLockConfiguration(rccctx, RCC_UI_LOCK_CODE);
 
43
    if (err) return NULL;
 
44
    
 
45
    classes = rccGetClassList(rccctx);
 
46
    for (i=0; classes[i]; i++);
 
47
 
 
48
    ctx = (rcc_ui_context)malloc(sizeof(struct rcc_ui_context_t));
 
49
    charsets = (rcc_ui_menu_context*)malloc((i+1)*sizeof(rcc_ui_menu_context));
 
50
    options = (rcc_ui_menu_context*)malloc((RCC_MAX_OPTIONS)*sizeof(rcc_ui_menu_context));
 
51
    if ((!ctx)||(!charsets)) {
 
52
        if (ctx) free(ctx);
 
53
        if (charsets) free(charsets);
 
54
        rccUnlockConfiguration(rccctx, RCC_UI_LOCK_CODE);
 
55
        return NULL;
 
56
    }
 
57
 
 
58
    ctx->language_frame = NULL;
 
59
    ctx->charset_frame = NULL;
 
60
    ctx->engine_frame = NULL;
 
61
    ctx->page = NULL;
 
62
    
 
63
    ctx->charsets = charsets;
 
64
    ctx->rccctx = rccctx;
 
65
    
 
66
    ctx->language_names = rcc_default_language_names;
 
67
    ctx->option_names = rcc_default_option_names;
 
68
 
 
69
    ctx->internal = rccUiCreateInternal(ctx);
 
70
 
 
71
    ctx->language = rccUiMenuCreateContext(RCC_UI_MENU_LANGUAGE, 0, ctx);
 
72
    ctx->engine = rccUiMenuCreateContext(RCC_UI_MENU_ENGINE, 0, ctx);
 
73
    for (i=0; classes[i]; i++) {
 
74
        charsets[i] = rccUiMenuCreateContext(RCC_UI_MENU_CHARSET, i, ctx);
 
75
        if (!charsets[i]) err = 1;
 
76
    }
 
77
    charsets[i] = NULL;
 
78
    for (i=0; i<RCC_MAX_OPTIONS; i++) {
 
79
        options[i] = rccUiMenuCreateContext(RCC_UI_MENU_OPTION, i, ctx);
 
80
        if (!options[i]) err = 1;
 
81
    }
 
82
 
 
83
    if ((err)||(!ctx->language)||(!ctx->engine)) {
 
84
        rccUiFreeContext(ctx);
 
85
        return NULL;
 
86
    }
 
87
 
 
88
    return ctx;
 
89
}
 
90
 
 
91
void rccUiFreeContext(rcc_ui_context ctx) {
 
92
    unsigned int i;
 
93
    rcc_class_ptr *classes;
 
94
 
 
95
    if (!ctx) return;
 
96
    
 
97
    rccUiFreeInternal(ctx);
 
98
    
 
99
    if (ctx->charsets) {
 
100
        classes = rccGetClassList(ctx->rccctx);
 
101
        for (i=0; classes[i]; i++)
 
102
            if (ctx->charsets[i]) rccUiMenuFreeContext(ctx->charsets[i]);
 
103
        free(ctx->charsets);
 
104
    }
 
105
    if (ctx->options) {
 
106
        for (i=0;i<RCC_MAX_OPTIONS;i++) {
 
107
            if (ctx->options[i]) rccUiMenuFreeContext(ctx->options[i]);
 
108
        }
 
109
        free(ctx->options);
 
110
    }
 
111
    if (ctx->engine) rccUiMenuFreeContext(ctx->engine);
 
112
    if (ctx->language) rccUiMenuFreeContext(ctx->language);
 
113
 
 
114
    rccUnlockConfiguration(ctx->rccctx, RCC_UI_LOCK_CODE);
 
115
 
 
116
    free(ctx);
 
117
}
 
118
 
 
119
int rccUiSetLanguageNames(rcc_ui_context ctx, rcc_language_name *names) {
 
120
    if (!ctx) return -1;
 
121
    
 
122
    if (names) ctx->language_names = names;
 
123
    else ctx->language_names = rcc_default_language_names;
 
124
    return 0;
 
125
}
 
126
 
 
127
int rccUiSetOptionNames(rcc_ui_context ctx, rcc_option_name *names) {
 
128
    if (!ctx) return -1;
 
129
 
 
130
    if (names) ctx->option_names = names;
 
131
    else ctx->option_names = rcc_default_option_names;
 
132
    return 0;
 
133
}
 
134
 
 
135
 
 
136
int rccUiRestoreLanguage(rcc_ui_context ctx) {
 
137
    unsigned int i;
 
138
    rcc_class_ptr *classes;
 
139
    rcc_context rccctx;
 
140
    
 
141
    if (!ctx) return -1;
 
142
    
 
143
    rccctx = ctx->rccctx;
 
144
    
 
145
    rccUiMenuSet(ctx->engine, (rcc_ui_id)rccGetSelectedEngine(rccctx));
 
146
    
 
147
    for (i=0;i<RCC_MAX_OPTIONS;i++)
 
148
        rccUiMenuSet(ctx->options[i], rccGetOption(rccctx, (rcc_option)i));
 
149
    
 
150
    classes = rccGetClassList(rccctx);
 
151
    for (i=0;classes[i];i++) 
 
152
        rccUiMenuSet(ctx->charsets[i], rccGetSelectedCharset(rccctx, (rcc_class_id)i));
 
153
 
 
154
    return 0;
 
155
}
 
156
 
 
157
int rccUiRestore(rcc_ui_context ctx) {
 
158
    rcc_language_id language_id;
 
159
    
 
160
    if (!ctx) return -1;
 
161
    
 
162
    language_id = rccGetSelectedLanguage(ctx->rccctx);
 
163
    rccUiMenuSet(ctx->language, (rcc_ui_id)language_id);
 
164
    return 0;
 
165
}
 
166
 
 
167
int rccUiUpdate(rcc_ui_context ctx) {
 
168
    unsigned int i;
 
169
    rcc_class_ptr *classes;
 
170
    rcc_context rccctx;
 
171
    
 
172
    if (!ctx) return -1;
 
173
    
 
174
    rccctx = ctx->rccctx;
 
175
 
 
176
    rccSetLanguage(rccctx, (rcc_language_id)rccUiMenuGet(ctx->language));
 
177
 
 
178
    for (i=0;i<RCC_MAX_OPTIONS;i++)
 
179
        rccSetOption(rccctx, (rcc_option)i, (rcc_option_value)rccUiMenuGet(ctx->options[i]));
 
180
 
 
181
    rccSetEngine(rccctx, (rcc_language_id)rccUiMenuGet(ctx->engine));
 
182
 
 
183
    classes = rccGetClassList(rccctx);
 
184
    for (i=0;classes[i];i++)
 
185
        rccSetCharset(rccctx, (rcc_class_id)i, rccUiMenuGet(ctx->charsets[i])); 
 
186
    
 
187
    return 0;
 
188
}
 
189
 
 
190
 
 
191
 
 
192
rcc_ui_widget rccUiGetLanguageMenu(rcc_ui_context ctx) {
 
193
    if (!ctx) return NULL;
 
194
    
 
195
    if (rccUiMenuConfigureWidget(ctx->language)) return NULL;
 
196
    return ctx->language->widget;
 
197
}
 
198
 
 
199
rcc_ui_widget rccUiGetCharsetMenu(rcc_ui_context ctx, rcc_class_id id) {
 
200
    rcc_charset *charsets;
 
201
    unsigned int i;
 
202
    
 
203
    if ((!ctx)||(id<0)) return NULL;
 
204
 
 
205
    charsets = rccGetCurrentCharsetList(ctx->rccctx);
 
206
    for (i=0;charsets[i];i++);
 
207
    if (id>=i) return NULL;
 
208
    
 
209
    if (rccUiMenuConfigureWidget(ctx->charsets[i])) return NULL;
 
210
    return ctx->charsets[i]->widget;
 
211
}
 
212
 
 
213
 
 
214
rcc_ui_widget rccUiGetEngineMenu(rcc_ui_context ctx) {
 
215
    if (!ctx) return NULL;
 
216
 
 
217
    if (rccUiMenuConfigureWidget(ctx->engine)) return NULL;
 
218
    return ctx->engine->widget;
 
219
}
 
220
 
 
221
 
 
222
rcc_ui_widget rccUiGetOptionMenu(rcc_ui_context ctx, rcc_option option) {
 
223
    if ((!ctx)||(option<0)||(option>RCC_MAX_OPTIONS)) return NULL;
 
224
 
 
225
    if (rccUiMenuConfigureWidget(ctx->options[option])) return NULL;
 
226
    return ctx->options[option]->widget;
 
227
}
 
228
 
 
229
 
 
230
rcc_ui_box rccUiGetLanguageBox(rcc_ui_context ctx, const char *title) {
 
231
    rcc_ui_widget language;
 
232
 
 
233
    if (!ctx) return NULL;
 
234
    if (ctx->language->box) return ctx->language->box;
 
235
    
 
236
    language = rccUiGetLanguageMenu(ctx);
 
237
    if (!language) return NULL;
 
238
    
 
239
    ctx->language->box = rccUiBoxCreate(ctx->language, title);
 
240
    return ctx->language->box;
 
241
}
 
242
 
 
243
rcc_ui_box rccUiGetCharsetBox(rcc_ui_context ctx, rcc_class_id id, const char *title) {
 
244
    unsigned int i;
 
245
    rcc_class_ptr *classes;
 
246
    rcc_ui_widget charset;
 
247
    
 
248
    if (!ctx) return NULL;
 
249
 
 
250
    classes = rccGetClassList(ctx->rccctx);
 
251
    for (i=0; classes[i]; i++);
 
252
    if (id>=i) return NULL;
 
253
 
 
254
    if (ctx->charsets[id]->box) return ctx->charsets[id]->box;
 
255
 
 
256
 
 
257
    charset = rccUiGetCharsetMenu(ctx, id);
 
258
    if (!charset) return NULL;
 
259
    
 
260
    ctx->charsets[id]->box = rccUiBoxCreate(ctx->charsets[id], title);
 
261
    return ctx->charsets[id]->box;
 
262
}
 
263
 
 
264
rcc_ui_box rccUiGetEngineBox(rcc_ui_context ctx, const char *title) {
 
265
    rcc_ui_widget engine;
 
266
 
 
267
    if (!ctx) return NULL;
 
268
    if (ctx->engine->box) return ctx->engine->box;
 
269
 
 
270
    engine = rccUiGetEngineMenu(ctx);
 
271
    if (!engine) return NULL;
 
272
 
 
273
    ctx->engine->box = rccUiBoxCreate(ctx->engine, title);
 
274
    return ctx->engine->box;
 
275
}
 
276
 
 
277
rcc_ui_box rccUiGetOptionBox(rcc_ui_context ctx, rcc_option option, const char *title) {
 
278
    rcc_ui_widget opt;
 
279
 
 
280
    if ((!ctx)||(option<0)||(option>=RCC_MAX_OPTIONS)) return NULL;
 
281
    if (ctx->options[option]->box) return ctx->options[option]->box;
 
282
 
 
283
    opt = rccUiGetOptionMenu(ctx, option);
 
284
    if (!opt) return NULL;
 
285
    
 
286
    ctx->options[option]->box = rccUiBoxCreate(ctx->options[option], title);
 
287
    return ctx->options[option]->box;
 
288
 
 
289
}
 
290
 
 
291
rcc_ui_frame rccUiGetLanguageFrame(rcc_ui_context ctx, const char *title) {
 
292
    rcc_ui_frame frame;
 
293
    rcc_ui_box language;
 
294
 
 
295
    if (!ctx) return NULL;
 
296
 
 
297
    if (ctx->language_frame) return ctx->language_frame;
 
298
    
 
299
    frame = rccUiFrameCreate(ctx, title);
 
300
    if (!frame) return NULL;
 
301
    
 
302
    language = rccUiGetLanguageBox(ctx, title);
 
303
    if (!language) return NULL;
 
304
 
 
305
    rccUiFrameAdd(frame, language);
 
306
    
 
307
    ctx->language_frame = frame;
 
308
    
 
309
    return frame;
 
310
}
 
311
 
 
312
rcc_ui_frame rccUiGetCharsetsFrame(rcc_ui_context ctx, const char *title) {
 
313
    unsigned int i;
 
314
    rcc_class_ptr *classes;
 
315
    rcc_ui_frame frame;
 
316
    rcc_ui_box charset;
 
317
    
 
318
    if (!ctx) return NULL;
 
319
 
 
320
    if (ctx->charset_frame) return ctx->charset_frame;
 
321
 
 
322
    frame = rccUiFrameCreate(ctx, title);
 
323
    if (!frame) return NULL;
 
324
 
 
325
    classes = rccGetClassList(ctx->rccctx);
 
326
    for (i=0; classes[i]; i++) {
 
327
        charset = rccUiGetCharsetBox(ctx, (rcc_class_id)i,  classes[i]->fullname);
 
328
        rccUiFrameAdd(frame, charset);
 
329
    }
 
330
    
 
331
    ctx->charset_frame = frame;
 
332
    
 
333
    return frame;
 
334
}
 
335
 
 
336
 
 
337
rcc_ui_frame rccUiGetEngineFrame(rcc_ui_context ctx, const char *title) {
 
338
    unsigned int i;
 
339
    rcc_ui_frame frame;
 
340
    rcc_ui_box engine;
 
341
    rcc_ui_box opt;
 
342
 
 
343
    if (!ctx) return NULL;
 
344
 
 
345
    if (ctx->engine_frame) return ctx->engine_frame;
 
346
    
 
347
    frame = rccUiFrameCreate(ctx, title);
 
348
    if (!frame) return NULL;
 
349
    
 
350
    engine = rccUiGetEngineBox(ctx, title);
 
351
    rccUiFrameAdd(frame, engine);
 
352
 
 
353
    for (i=0; i<RCC_MAX_OPTIONS; i++) {
 
354
        opt = rccUiGetOptionBox(ctx, (rcc_option)i,  rccUiGetOptionName(ctx, i));
 
355
        rccUiFrameAdd(frame, opt);
 
356
    }
 
357
    
 
358
    ctx->engine_frame = frame;
 
359
    
 
360
    return frame;
 
361
}
 
362
 
 
363
 
 
364
rcc_ui_page rccUiGetPage(rcc_ui_context ctx, const char *title, const char *language_title, const char *charset_title, const char *engine_title) {
 
365
    rcc_ui_page page;
 
366
    rcc_ui_frame frame;
 
367
    
 
368
    if (!ctx) return NULL;
 
369
 
 
370
    if (ctx->page) return ctx->page;
 
371
        
 
372
    page = rccUiPageCreate(ctx, title);
 
373
    if (!page) return NULL;
 
374
    
 
375
    frame = rccUiGetLanguageFrame(ctx, language_title);
 
376
    rccUiPageAdd(page, frame);
 
377
 
 
378
    frame = rccUiGetCharsetsFrame(ctx, charset_title);
 
379
    rccUiPageAdd(page, frame);
 
380
 
 
381
    frame = rccUiGetEngineFrame(ctx, engine_title);
 
382
    rccUiPageAdd(page, frame);
 
383
    
 
384
    ctx->page = page;
 
385
    
 
386
    return page;
 
387
}