Tabs to spaces, more consistent formatting.
[AROS.git] / workbench / libs / muimaster / classes / configdata.c
blob659450bbaf98d4f177b03ee875e10f5535bbe2bb
1 /*
2 Copyright 2002, The AROS Development Team.
3 All rights reserved.
5 $Id$
6 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <stdio.h>
11 #include <exec/types.h>
12 #include <prefs/prefhdr.h>
13 #include <clib/alib_protos.h>
14 #include <proto/exec.h>
15 #include <proto/intuition.h>
16 #include <proto/utility.h>
17 #include <proto/iffparse.h>
18 #include <proto/dos.h>
19 #include <proto/commodities.h>
20 #include <proto/muimaster.h>
22 /* #define MYDEBUG 1 */
23 #include "debug.h"
25 #include "muimaster_intern.h"
26 #include "mui.h"
27 #include "support.h"
28 #include "prefs.h"
29 #include "imspec.h"
31 extern struct Library *MUIMasterBase;
33 struct MUI_ConfigdataData
35 Object *app;
36 CONST_STRPTR appbase;
37 struct ZunePrefsNew prefs;
41 static CONST_STRPTR GetConfigString(Object *obj, ULONG id)
43 return (CONST_STRPTR) DoMethod(obj, MUIM_Configdata_GetString, id);
46 static ULONG GetConfigULong(Object *obj, ULONG id)
48 return (ULONG) DoMethod(obj, MUIM_Configdata_GetULong, id);
52 /**************************************************************************
53 Default ImageSpec values
54 **************************************************************************/
56 struct spec_cfg
58 ULONG muiv;
59 ULONG cfgid;
60 CONST_STRPTR defspec;
63 const static struct spec_cfg DefImspecValues[] =
65 { MUII_WindowBack, MUICFG_Background_Window, "0:128" },
66 { MUII_RequesterBack, MUICFG_Background_Requester, "0:137" },
67 { MUII_ButtonBack, MUICFG_Background_Button, "0:128" },
68 { MUII_ListBack, MUICFG_Background_List, "0:128" },
69 { MUII_TextBack, MUICFG_Background_Text, "0:128" },
70 { MUII_PropBack, MUICFG_Background_Prop, "0:128" },
71 { MUII_PopupBack, MUICFG_Background_PopUp, "0:128" },
72 { MUII_SelectedBack, MUICFG_Background_Selected, "0:131" },
73 { MUII_ListCursor, MUICFG_Background_ListCursor, "0:131" },
74 { MUII_ListSelect, MUICFG_Background_ListSelect, "0:135" },
75 { MUII_ListSelCur, MUICFG_Background_ListSelCur, "0:138" },
76 { MUII_ArrowUp, MUICFG_Image_ArrowUp, "1:0" },
77 { MUII_ArrowDown, MUICFG_Image_ArrowDown, "1:1" },
78 { MUII_ArrowLeft, MUICFG_Image_ArrowLeft, "1:2" },
79 { MUII_ArrowRight, MUICFG_Image_ArrowRight, "1:3" },
80 { MUII_CheckMark, MUICFG_Image_CheckMark, "1:4" },
81 { MUII_RadioButton, MUICFG_Image_RadioButton, "1:5" },
82 { MUII_Cycle, MUICFG_Image_Cycle, "1:6" },
83 { MUII_PopUp, MUICFG_Image_PopUp, "1:7" },
84 { MUII_PopFile, MUICFG_Image_PopFile, "1:8" },
85 { MUII_PopDrawer, MUICFG_Image_PopDrawer, "1:9" },
86 { MUII_PropKnob, MUICFG_Image_PropKnob, "0:129" },
87 { MUII_Drawer, MUICFG_Image_Drawer, "1:10" },
88 { MUII_HardDisk, MUICFG_Image_HardDisk, "1:11" },
89 { MUII_Disk, MUICFG_Image_Disk, "1:12" },
90 { MUII_Chip, MUICFG_Image_Chip, "1:13" },
91 { MUII_Volume, MUICFG_Image_Volume, "1:14" },
92 { MUII_RegisterBack, MUICFG_Background_Register, "0:128" },
93 { MUII_Network, MUICFG_Image_Network, "1:15" },
94 { MUII_Assign, MUICFG_Image_Assign, "1:16" },
95 { MUII_TapePlay, MUICFG_Image_TapePlay, "1:17" },
96 { MUII_TapePlayBack, MUICFG_Image_TapePlayBack, "1:18" },
97 { MUII_TapePause, MUICFG_Image_TapePause, "1:19" },
98 { MUII_TapeStop, MUICFG_Image_TapeStop, "1:20" },
99 { MUII_TapeRecord, MUICFG_Image_TapeRecord, "1:21" },
100 { MUII_GroupBack, MUICFG_Background_Framed, "0:128" },
101 { MUII_SliderBack, MUICFG_Background_Slider, "0:128" },
102 { MUII_SliderKnob, MUICFG_Background_SliderKnob, "0:128" },
103 { MUII_TapeUp, MUICFG_Image_TapeUp, "1:22" },
104 { MUII_TapeDown, MUICFG_Image_TapeDown, "1:23" },
105 { MUII_PageBack, MUICFG_Background_Page, "0:128" },
106 { MUII_ReadListBack, MUICFG_Background_ReadList, "0:128" },
107 { 0, 0, NULL },
110 /* called by Configdata_New */
111 static void init_imspecs(Object *obj, struct MUI_ConfigdataData *data)
113 int i;
115 for (i = 0; DefImspecValues[i].defspec; i++)
117 CONST_STRPTR imspec;
118 const struct spec_cfg *img = DefImspecValues + i;
120 imspec = GetConfigString(obj, img->cfgid);
121 /* D(bug("init_imspecs: %ld %lx %s ...\n", img->muiv, img->cfgid, imspec)); */
122 data->prefs.imagespecs[img->muiv] = imspec;
123 if (!data->prefs.imagespecs[img->muiv])
125 /* D(bug("*** init_imspecs: null imagespec %ld\n", img->muiv)); */
130 /**************************************************************************
131 Default FrameSpec values
132 **************************************************************************/
134 /* spec format : type, recessed, left, right, up, down spacing */
135 const static struct spec_cfg DefFramespecValues[] =
137 { MUIV_Frame_None, MUICFG_Invalid, "000000" }, /* invisible frame */
138 { MUIV_Frame_Button, MUICFG_Frame_Button, "202211" }, /* text button */
139 { MUIV_Frame_ImageButton, MUICFG_Frame_ImageButton, "202211" }, /* image button */
140 { MUIV_Frame_Text, MUICFG_Frame_Text, "212211" }, /* textfield without input */
141 { MUIV_Frame_String, MUICFG_Frame_String, "302211" }, /* string gadget */
142 { MUIV_Frame_ReadList, MUICFG_Frame_ReadList, "212211" }, /* list without input */
143 { MUIV_Frame_InputList, MUICFG_Frame_InputList, "202211" }, /* list with input */
144 { MUIV_Frame_Prop, MUICFG_Frame_Prop, "202211" }, /* scrollbar container */
145 { MUIV_Frame_Gauge, MUICFG_Frame_Gauge, "210000" }, /* gauge */
146 { MUIV_Frame_Group, MUICFG_Frame_Group, "314444" }, /* normal group */
147 { MUIV_Frame_PopUp, MUICFG_Frame_PopUp, "112211" }, /* cycle menu, popup window */
148 { MUIV_Frame_Virtual, MUICFG_Frame_Virtual, "212211" }, /* virt group */
149 { MUIV_Frame_Slider, MUICFG_Frame_Slider, "400000" }, /* slider container */
150 { MUIV_Frame_Knob, MUICFG_Frame_Knob, "202211" }, /* slider knob */
151 { MUIV_Frame_Drag, MUICFG_Frame_Drag, "300000" }, /* dnd frame */
152 { -1, -1, NULL },
155 /* called by Configdata_New */
156 static void init_framespecs(Object *obj, struct MUI_ConfigdataData *data)
158 int i;
160 for (i = 0; DefFramespecValues[i].defspec; i++)
162 CONST_STRPTR framespec;
163 const struct spec_cfg *fcfg = DefFramespecValues + i;
165 framespec = GetConfigString(obj, fcfg->cfgid);
166 zune_frame_spec_to_intern(framespec,
167 &data->prefs.frames[fcfg->muiv]);
171 /**************************************************************************
172 Default ULONG values
173 **************************************************************************/
175 struct def_ulval
177 ULONG id;
178 ULONG val;
181 const static struct def_ulval DefULValues[] = {
182 {MUICFG_Window_Spacing_Left, 4},
183 {MUICFG_Window_Spacing_Right, 4},
184 {MUICFG_Window_Spacing_Top, 3},
185 {MUICFG_Window_Buttons, 0},
186 {MUICFG_Window_Spacing_Bottom, 3},
187 {MUICFG_Window_Positions, WINDOW_POSITION_FORGET_ON_EXIT},
188 {MUICFG_Window_Redraw, WINDOW_REDRAW_WITHOUT_CLEAR},
189 {MUICFG_Window_Refresh, WINDOW_REFRESH_SIMPLE},
190 {MUICFG_Radio_HSpacing, 4},
191 {MUICFG_Radio_VSpacing, 1},
192 {MUICFG_Group_HSpacing, 6},
193 {MUICFG_Group_VSpacing, 3},
194 {MUICFG_Cycle_MenuCtrl_Position, CYCLE_MENU_POSITION_BELOW},
195 {MUICFG_Cycle_MenuCtrl_Level, 2},
196 {MUICFG_Cycle_MenuCtrl_Speed, 0},
197 {MUICFG_Cycle_Menu_Recessed, FALSE},
198 {MUICFG_Listview_Font_Leading, 1},
199 {MUICFG_Listview_Smoothed, FALSE},
200 {MUICFG_Listview_SmoothVal, 0},
201 {MUICFG_Listview_Refresh, LISTVIEW_REFRESH_MIXED},
202 {MUICFG_Listview_Multi, LISTVIEW_MULTI_SHIFTED},
203 {MUICFG_GroupTitle_Position, GROUP_TITLE_POSITION_CENTERED},
204 {MUICFG_GroupTitle_Color, GROUP_TITLE_COLOR_HILITE},
205 {MUICFG_Scrollbar_Type, SCROLLBAR_TYPE_STANDARD},
206 {MUICFG_Scrollbar_Arrangement, SCROLLBAR_ARRANGEMENT_TOP},
207 {MUICFG_Balance_Look, BALANCING_SHOW_FRAMES},
208 {MUICFG_Dragndrop_Look, DND_LOOK_GHOSTED_ON_BOX},
209 {MUICFG_Drag_Autostart, TRUE},
210 {MUICFG_Drag_Autostart_Length, 3},
211 {MUICFG_Drag_LeftButton, TRUE},
212 {MUICFG_Drag_MiddleButton, FALSE},
213 {MUICFG_Register_TruncateTitles, FALSE},
214 {MUICFG_Screen_Mode, 0},
215 {MUICFG_Screen_Mode_ID, -1},
216 {MUICFG_Screen_Width, 0},
217 {MUICFG_Screen_Height, 0},
218 {MUICFG_PublicScreen_PopToFront, TRUE},
219 {MUICFG_Iconification_ShowIcon, TRUE},
220 {MUICFG_Iconification_ShowMenu, FALSE},
221 {MUICFG_Iconification_OnStartup, FALSE},
222 {MUICFG_Interfaces_EnableARexx, TRUE},
223 {MUICFG_BubbleHelp_FirstDelay, 30},
224 {MUICFG_BubbleHelp_NextDelay, 10},
225 {0, 0},
228 /**************************************************************************
229 Default string values
230 **************************************************************************/
232 struct def_strval
234 ULONG id;
235 CONST_STRPTR val;
238 /* NULL values not allowed */
239 const static struct def_strval DefStrValues[] = {
240 {MUICFG_Font_Normal, ""},
241 {MUICFG_Font_List, ""},
242 {MUICFG_Font_Tiny, ""},
243 {MUICFG_Font_Fixed, ""},
244 {MUICFG_Font_Title, ""},
245 {MUICFG_Font_Big, ""},
246 {MUICFG_Font_Button, ""},
247 {MUICFG_Font_Knob, ""},
248 {MUICFG_String_Background, "2:m2"},
249 {MUICFG_String_Text, "m5"},
250 {MUICFG_String_ActiveBackground, "2:m1"},
251 {MUICFG_String_ActiveText, "m5"},
252 {MUICFG_String_Cursor, "m7"},
253 {MUICFG_String_MarkedBackground, "m6"},
254 {MUICFG_String_MarkedText, "m0"},
255 {MUICFG_ActiveObject_Color, "m0"},
256 {MUICFG_Keyboard_Press, "-upstroke return"},
257 {MUICFG_Keyboard_Toggle, "-repeat space"},
258 {MUICFG_Keyboard_Up, "-repeat up"},
259 {MUICFG_Keyboard_Down, "-repeat down"},
260 {MUICFG_Keyboard_PageUp, "-repeat shift up"},
261 {MUICFG_Keyboard_PageDown, "-repeat shift down"},
262 {MUICFG_Keyboard_Top, "control up"},
263 {MUICFG_Keyboard_Bottom, "control down"},
264 {MUICFG_Keyboard_Left, "-repeat left"},
265 {MUICFG_Keyboard_Right, "-repeat right"},
266 {MUICFG_Keyboard_WordLeft, "-repeat control left"},
267 {MUICFG_Keyboard_WordRight, "-repeat control right"},
268 {MUICFG_Keyboard_LineStart, "shift left"},
269 {MUICFG_Keyboard_LineEnd, "shift right"},
270 {MUICFG_Keyboard_NextGadget, "-repeat tab"},
271 {MUICFG_Keyboard_PrevGadget, "-repeat shift tab"},
272 {MUICFG_Keyboard_GadgetOff, "control tab"},
273 {MUICFG_Keyboard_CloseWindow, "esc"},
274 {MUICFG_Keyboard_NextWindow, "-repeat alt tab"},
275 {MUICFG_Keyboard_PrevWindow, "-repeat alt shift tab"},
276 {MUICFG_Keyboard_Help, "help"},
277 {MUICFG_Keyboard_Popup, "control p"},
278 {MUICFG_Drag_LMBModifier, "control"},
279 {MUICFG_Drag_MMBModifier, ""},
280 {MUICFG_PublicScreen, ""},
281 {MUICFG_Iconification_Hotkey, ""},
282 {0, 0},
286 /**************************************************************************
287 OM_NEW
288 Load global (and maybe application-specific) prefs files into the dataspace,
289 then fill the prefs struct with dataspace or default values
290 **************************************************************************/
291 IPTR Configdata__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
293 struct MUI_ConfigdataData *data;
294 struct TagItem *tags;
295 struct TagItem *tag;
296 //APTR cdata;
297 int i, res = 0;
299 obj = (Object *) DoSuperMethodA(cl, obj, (Msg) msg);
300 if (!obj)
301 return (IPTR) NULL;
303 /* D(bug("Configdata_New(%p)\n", obj)); */
305 data = INST_DATA(cl, obj);
307 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags));)
309 switch (tag->ti_Tag)
311 case MUIA_Configdata_Application:
312 data->app = (Object *) tag->ti_Data;
313 break;
314 case MUIA_Configdata_ApplicationBase:
315 data->appbase = (CONST_STRPTR) tag->ti_Data;
316 break;
320 if (data->app && !data->appbase)
322 get(data->app, MUIA_Application_Base, &data->appbase);
325 if (data->appbase)
327 char filename[255];
328 snprintf(filename, 255, "ENV:zune/%s.prefs", data->appbase);
329 res = DoMethod(obj, MUIM_Configdata_Load, (IPTR) filename);
330 if (!res)
332 snprintf(filename, 255, "ENVARC:zune/%s.prefs", data->appbase);
333 res = DoMethod(obj, MUIM_Configdata_Load, (IPTR) filename);
337 // load only global prefs if no local app pref is found
338 if (!res)
340 if (!DoMethod(obj, MUIM_Configdata_Load,
341 (IPTR) "ENV:zune/global.prefs"))
343 DoMethod(obj, MUIM_Configdata_Load,
344 (IPTR) "ENVARC:zune/global.prefs");
347 /*---------- fonts stuff ----------*/
349 data->prefs.fonts[-MUIV_Font_Normal] =
350 GetConfigString(obj, MUICFG_Font_Normal);
351 data->prefs.fonts[-MUIV_Font_List] =
352 GetConfigString(obj, MUICFG_Font_List);
353 data->prefs.fonts[-MUIV_Font_Tiny] =
354 GetConfigString(obj, MUICFG_Font_Tiny);
355 data->prefs.fonts[-MUIV_Font_Fixed] =
356 GetConfigString(obj, MUICFG_Font_Fixed);
357 data->prefs.fonts[-MUIV_Font_Title] =
358 GetConfigString(obj, MUICFG_Font_Title);
359 data->prefs.fonts[-MUIV_Font_Big] =
360 GetConfigString(obj, MUICFG_Font_Big);
361 data->prefs.fonts[-MUIV_Font_Button] =
362 GetConfigString(obj, MUICFG_Font_Button);
363 data->prefs.fonts[-MUIV_Font_Knob] =
364 GetConfigString(obj, MUICFG_Font_Knob);
366 /*---------- images stuff ----------*/
368 init_imspecs(obj, data);
370 /*---------- frame stuff ----------*/
372 init_framespecs(obj, data);
374 /*---------- system stuff ----------*/
376 data->prefs.publicscreen_name =
377 GetConfigString(obj, MUICFG_PublicScreen);
378 data->prefs.publicscreen_pop_to_front =
379 GetConfigULong(obj, MUICFG_PublicScreen_PopToFront);
380 data->prefs.iconification_hotkey =
381 GetConfigString(obj, MUICFG_Iconification_Hotkey);
382 data->prefs.iconification_show_icon =
383 GetConfigULong(obj, MUICFG_Iconification_ShowIcon);
384 data->prefs.iconification_show_menu =
385 GetConfigULong(obj, MUICFG_Iconification_ShowMenu);
386 data->prefs.iconification_on_startup =
387 GetConfigULong(obj, MUICFG_Iconification_OnStartup);
388 data->prefs.interfaces_enable_arexx =
389 GetConfigULong(obj, MUICFG_Interfaces_EnableARexx);
390 data->prefs.bubblehelp_first_delay =
391 GetConfigULong(obj, MUICFG_BubbleHelp_FirstDelay);
392 data->prefs.bubblehelp_next_delay =
393 GetConfigULong(obj, MUICFG_BubbleHelp_NextDelay);
395 /*---------- window stuff ----------*/
397 data->prefs.window_inner_left =
398 GetConfigULong(obj, MUICFG_Window_Spacing_Left);
399 data->prefs.window_inner_right =
400 GetConfigULong(obj, MUICFG_Window_Spacing_Right);
401 data->prefs.window_inner_top =
402 GetConfigULong(obj, MUICFG_Window_Spacing_Top);
403 data->prefs.window_inner_bottom =
404 GetConfigULong(obj, MUICFG_Window_Spacing_Bottom);
405 data->prefs.window_position =
406 GetConfigULong(obj, MUICFG_Window_Positions);
407 data->prefs.window_redraw = GetConfigULong(obj, MUICFG_Window_Redraw);
408 data->prefs.window_refresh = GetConfigULong(obj, MUICFG_Window_Refresh);
409 data->prefs.screenmode = GetConfigULong(obj, MUICFG_Screen_Mode);
410 data->prefs.screenmodeid = GetConfigULong(obj, MUICFG_Screen_Mode_ID);
411 data->prefs.screen_width = GetConfigULong(obj, MUICFG_Screen_Width);
412 data->prefs.screen_height = GetConfigULong(obj, MUICFG_Screen_Height);
413 data->prefs.window_buttons = GetConfigULong(obj, MUICFG_Window_Buttons);
415 /*---------- group stuff ----------*/
417 data->prefs.group_title_position =
418 GetConfigULong(obj, MUICFG_GroupTitle_Position);
419 data->prefs.group_title_color =
420 GetConfigULong(obj, MUICFG_GroupTitle_Color);
421 data->prefs.group_hspacing = GetConfigULong(obj, MUICFG_Group_HSpacing);
422 data->prefs.group_vspacing = GetConfigULong(obj, MUICFG_Group_VSpacing);
424 /*---------- registers ----------*/
426 data->prefs.register_look = REGISTER_LOOK_TRADITIONAL;
427 data->prefs.register_truncate_titles =
428 GetConfigULong(obj, MUICFG_Register_TruncateTitles);
430 /*---------- Buttons ----------*/
432 data->prefs.radiobutton_hspacing =
433 GetConfigULong(obj, MUICFG_Radio_HSpacing);
434 data->prefs.radiobutton_vspacing =
435 GetConfigULong(obj, MUICFG_Radio_VSpacing);
437 /*---------- Cycles ----------*/
439 data->prefs.cycle_menu_position =
440 GetConfigULong(obj, MUICFG_Cycle_MenuCtrl_Position);
441 data->prefs.cycle_menu_min_entries =
442 GetConfigULong(obj, MUICFG_Cycle_MenuCtrl_Level);
443 data->prefs.cycle_menu_speed =
444 GetConfigULong(obj, MUICFG_Cycle_MenuCtrl_Speed);
445 data->prefs.cycle_menu_recessed_entries =
446 GetConfigULong(obj, MUICFG_Cycle_Menu_Recessed);
448 /*---------- Sliders ----------*/
449 /* all taken care of in frames and images */
451 /*---------- Scrollbars ----------*/
453 data->prefs.scrollbar_type = GetConfigULong(obj, MUICFG_Scrollbar_Type);
454 data->prefs.scrollbar_arrangement =
455 GetConfigULong(obj, MUICFG_Scrollbar_Arrangement);
457 /*---------- Lists ----------*/
459 data->prefs.list_linespacing =
460 GetConfigULong(obj, MUICFG_Listview_Font_Leading);
461 data->prefs.list_smoothed =
462 GetConfigULong(obj, MUICFG_Listview_Smoothed);
463 data->prefs.list_smoothval =
464 GetConfigULong(obj, MUICFG_Listview_SmoothVal);
465 data->prefs.list_multi = GetConfigULong(obj, MUICFG_Listview_Multi);
466 data->prefs.list_refresh = GetConfigULong(obj, MUICFG_Listview_Refresh);
468 /*---------- Strings ----------*/
469 data->prefs.string_bg_inactive =
470 GetConfigString(obj, MUICFG_String_Background);
471 data->prefs.string_text_inactive =
472 GetConfigString(obj, MUICFG_String_Text);
473 data->prefs.string_bg_active =
474 GetConfigString(obj, MUICFG_String_ActiveBackground);
475 data->prefs.string_text_active =
476 GetConfigString(obj, MUICFG_String_ActiveText);
477 data->prefs.string_cursor = GetConfigString(obj, MUICFG_String_Cursor);
478 data->prefs.string_bg_marked =
479 GetConfigString(obj, MUICFG_String_MarkedBackground);
480 data->prefs.string_text_marked =
481 GetConfigString(obj, MUICFG_String_MarkedText);
483 /*---------- Navigation ----------*/
485 data->prefs.drag_left_button =
486 GetConfigULong(obj, MUICFG_Drag_LeftButton);
487 data->prefs.drag_left_modifier.readable_hotkey =
488 GetConfigString(obj, MUICFG_Drag_LMBModifier);
489 data->prefs.drag_middle_button =
490 GetConfigULong(obj, MUICFG_Drag_MiddleButton);
491 data->prefs.drag_middle_modifier.readable_hotkey =
492 GetConfigString(obj, MUICFG_Drag_MMBModifier);
493 data->prefs.drag_autostart = GetConfigULong(obj, MUICFG_Drag_Autostart);
494 data->prefs.drag_autostart_length =
495 GetConfigULong(obj, MUICFG_Drag_Autostart_Length);
496 data->prefs.drag_look = GetConfigULong(obj, MUICFG_Dragndrop_Look);
497 data->prefs.balancing_look = GetConfigULong(obj, MUICFG_Balance_Look);
499 if (data->prefs.drag_left_modifier.readable_hotkey != NULL)
500 data->prefs.drag_left_modifier.ix_well =
501 !ParseIX(data->prefs.drag_left_modifier.readable_hotkey,
502 &data->prefs.drag_left_modifier.ix);
503 else
504 data->prefs.drag_left_modifier.ix_well = 0;
506 if (data->prefs.drag_middle_modifier.readable_hotkey != NULL)
507 data->prefs.drag_middle_modifier.ix_well =
508 !ParseIX(data->prefs.drag_middle_modifier.readable_hotkey,
509 &data->prefs.drag_middle_modifier.ix);
510 else
511 data->prefs.drag_middle_modifier.ix_well = 0;
513 data->prefs.active_object_color =
514 GetConfigString(obj, MUICFG_ActiveObject_Color);
515 /*---------- mui keys ----------*/
517 data->prefs.muikeys[MUIKEY_PRESS].readable_hotkey =
518 GetConfigString(obj, MUICFG_Keyboard_Press);
519 data->prefs.muikeys[MUIKEY_TOGGLE].readable_hotkey =
520 GetConfigString(obj, MUICFG_Keyboard_Toggle);
521 data->prefs.muikeys[MUIKEY_UP].readable_hotkey =
522 GetConfigString(obj, MUICFG_Keyboard_Up);
523 data->prefs.muikeys[MUIKEY_DOWN].readable_hotkey =
524 GetConfigString(obj, MUICFG_Keyboard_Down);
525 data->prefs.muikeys[MUIKEY_PAGEUP].readable_hotkey =
526 GetConfigString(obj, MUICFG_Keyboard_PageUp);
527 data->prefs.muikeys[MUIKEY_PAGEDOWN].readable_hotkey =
528 GetConfigString(obj, MUICFG_Keyboard_PageDown);
529 data->prefs.muikeys[MUIKEY_TOP].readable_hotkey =
530 GetConfigString(obj, MUICFG_Keyboard_Top);
531 data->prefs.muikeys[MUIKEY_BOTTOM].readable_hotkey =
532 GetConfigString(obj, MUICFG_Keyboard_Bottom);
533 data->prefs.muikeys[MUIKEY_LEFT].readable_hotkey =
534 GetConfigString(obj, MUICFG_Keyboard_Left);
535 data->prefs.muikeys[MUIKEY_RIGHT].readable_hotkey =
536 GetConfigString(obj, MUICFG_Keyboard_Right);
537 data->prefs.muikeys[MUIKEY_WORDLEFT].readable_hotkey =
538 GetConfigString(obj, MUICFG_Keyboard_WordLeft);
539 data->prefs.muikeys[MUIKEY_WORDRIGHT].readable_hotkey =
540 GetConfigString(obj, MUICFG_Keyboard_WordRight);
541 data->prefs.muikeys[MUIKEY_LINESTART].readable_hotkey =
542 GetConfigString(obj, MUICFG_Keyboard_LineStart);
543 data->prefs.muikeys[MUIKEY_LINEEND].readable_hotkey =
544 GetConfigString(obj, MUICFG_Keyboard_LineEnd);
545 data->prefs.muikeys[MUIKEY_GADGET_NEXT].readable_hotkey =
546 GetConfigString(obj, MUICFG_Keyboard_NextGadget);
547 data->prefs.muikeys[MUIKEY_GADGET_PREV].readable_hotkey =
548 GetConfigString(obj, MUICFG_Keyboard_PrevGadget);
549 data->prefs.muikeys[MUIKEY_GADGET_OFF].readable_hotkey =
550 GetConfigString(obj, MUICFG_Keyboard_GadgetOff);
551 data->prefs.muikeys[MUIKEY_WINDOW_CLOSE].readable_hotkey =
552 GetConfigString(obj, MUICFG_Keyboard_CloseWindow);
553 data->prefs.muikeys[MUIKEY_WINDOW_NEXT].readable_hotkey =
554 GetConfigString(obj, MUICFG_Keyboard_NextWindow);
555 data->prefs.muikeys[MUIKEY_WINDOW_PREV].readable_hotkey =
556 GetConfigString(obj, MUICFG_Keyboard_PrevWindow);
557 data->prefs.muikeys[MUIKEY_HELP].readable_hotkey =
558 GetConfigString(obj, MUICFG_Keyboard_Help);
559 data->prefs.muikeys[MUIKEY_POPUP].readable_hotkey =
560 GetConfigString(obj, MUICFG_Keyboard_Popup);
562 for (i = 0; i < MUIKEY_COUNT; i++)
564 if (data->prefs.muikeys[i].readable_hotkey)
565 data->prefs.muikeys[i].ix_well =
566 !ParseIX(data->prefs.muikeys[i].readable_hotkey,
567 &data->prefs.muikeys[i].ix);
568 else
569 data->prefs.muikeys[i].ix_well = 0;
572 /*---------- CustomFrames ----------*/
573 data->prefs.customframe_config_1 =
574 GetConfigString(obj, MUICFG_CustomFrame_1);
575 data->prefs.customframe_config_2 =
576 GetConfigString(obj, MUICFG_CustomFrame_2);
577 data->prefs.customframe_config_3 =
578 GetConfigString(obj, MUICFG_CustomFrame_3);
579 data->prefs.customframe_config_4 =
580 GetConfigString(obj, MUICFG_CustomFrame_4);
581 data->prefs.customframe_config_5 =
582 GetConfigString(obj, MUICFG_CustomFrame_5);
583 data->prefs.customframe_config_6 =
584 GetConfigString(obj, MUICFG_CustomFrame_6);
585 data->prefs.customframe_config_7 =
586 GetConfigString(obj, MUICFG_CustomFrame_7);
587 data->prefs.customframe_config_8 =
588 GetConfigString(obj, MUICFG_CustomFrame_8);
589 data->prefs.customframe_config_9 =
590 GetConfigString(obj, MUICFG_CustomFrame_9);
591 data->prefs.customframe_config_10 =
592 GetConfigString(obj, MUICFG_CustomFrame_10);
593 data->prefs.customframe_config_11 =
594 GetConfigString(obj, MUICFG_CustomFrame_11);
595 data->prefs.customframe_config_12 =
596 GetConfigString(obj, MUICFG_CustomFrame_12);
597 data->prefs.customframe_config_13 =
598 GetConfigString(obj, MUICFG_CustomFrame_13);
599 data->prefs.customframe_config_14 =
600 GetConfigString(obj, MUICFG_CustomFrame_14);
601 data->prefs.customframe_config_15 =
602 GetConfigString(obj, MUICFG_CustomFrame_15);
603 data->prefs.customframe_config_16 =
604 GetConfigString(obj, MUICFG_CustomFrame_16);
606 /*---------- Special ----------*/
607 /* all taken care of in frames and images */
609 return (IPTR) obj;
612 /**************************************************************************
613 OM_DISPOSE
614 **************************************************************************/
615 IPTR Configdata__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
617 /* struct MUI_ConfigdataData *data = INST_DATA(cl, obj); */
618 /* int i; */
620 return DoSuperMethodA(cl, obj, msg);
623 /**************************************************************************
624 OM_GET
625 **************************************************************************/
626 IPTR Configdata__OM_GET(struct IClass *cl, Object *obj,
627 struct opGet *msg)
629 struct MUI_ConfigdataData *data = INST_DATA(cl, obj);
630 IPTR *store = msg->opg_Storage;
631 ULONG tag = msg->opg_AttrID;
633 switch (tag)
635 case MUIA_Configdata_ZunePrefs:
636 *store = (IPTR) & data->prefs;
637 DoMethod(obj, MUIM_Configdata_GetWindowPos, 0);
638 return 1;
641 return DoSuperMethodA(cl, obj, (Msg) msg);
644 #ifndef AROS_BIG_ENDIAN
645 #define AROS_BIG_ENDIAN 0
646 #endif
648 static LONG windowpos_endian(IPTR data, BOOL isNative)
650 LONG size, items;
651 WORD cnt, i, j;
652 void *p = (void *)data;
654 if (AROS_BIG_ENDIAN)
656 size = *(LONG *) p;
658 else
660 if (isNative)
662 size = *(LONG *) p;
664 else
666 size = AROS_BE2LONG(*((LONG *) p));
668 *((LONG *) p) = AROS_SWAP_BYTES_LONG(*((LONG *) p));
671 cnt = sizeof(LONG);
672 items = (size - sizeof(LONG)) / sizeof(struct windowpos);
673 D(bug("size=%d items=%d\n", size, items));
674 if (size > 100 || items > 100)
676 bug("%s crashed...\n", FindTask(NULL)->tc_Node.ln_Name);
678 volatile int dead = 1;
679 while (dead);
683 for (i = 0; i < items; i++)
685 if (AROS_BIG_ENDIAN)
687 D(bug("ID=%08x\n", *((LONG *) (p + cnt))));
689 else
691 if (isNative)
692 D(bug("ID=%08x\n", *((LONG *) (p + cnt))));
693 *((LONG *) (p + cnt)) =
694 AROS_SWAP_BYTES_LONG(*((LONG *) (p + cnt)));
695 if (!isNative)
696 D(bug("ID=%08x\n", *((LONG *) (p + cnt))));
698 cnt += sizeof(LONG);
699 for (j = 0; j < 8; j++)
701 if (AROS_BIG_ENDIAN)
703 D(bug("V%d: %d\n", j, *((WORD *) (p + cnt))));
705 else
707 if (isNative)
708 D(bug("V%d: %d\n", j, *((WORD *) (p + cnt))));
709 *((WORD *) (p + cnt)) =
710 AROS_SWAP_BYTES_LONG(*((WORD *) (p + cnt)));
711 if (!isNative)
712 D(bug("V%d: %d\n", j, *((WORD *) (p + cnt))));
714 cnt += sizeof(WORD);
717 D(bug("size=%d\n", cnt));
718 return cnt;
721 static IPTR Configdata_GetWindowPos(struct IClass *cl, Object *obj,
722 struct MUIP_Configdata_GetString *msg)
724 struct MUI_ConfigdataData *data;
725 IPTR s;
726 data = INST_DATA(cl, obj);
727 //kprintf ("getwindowpos\n");
728 s = (IPTR) DoMethod(obj, MUIM_Dataspace_Find, MUICFG_WindowPos);
729 if (s && data->app)
731 windowpos_endian(s, FALSE);
732 set(data->app, MUIA_Application_CopyWinPosToApp, s);
733 windowpos_endian(s, TRUE);
735 return s;
738 static IPTR Configdata_SetWindowPos(struct IClass *cl, Object *obj,
739 struct MUIP_Configdata_GetString *msg)
741 struct MUI_ConfigdataData *data;
742 //kprintf ("setwindowpos\n");
743 data = INST_DATA(cl, obj);
744 IPTR addr = 0;
745 LONG size = 0;
747 if (data->app)
749 get(data->app, MUIA_Application_GetWinPosAddr, &addr);
750 get(data->app, MUIA_Application_GetWinPosSize, &size);
752 /* We can ignore size-variable because
753 * MUIA_Application_GetWinPosSize updates *((LONG*)addr) */
754 size = windowpos_endian(addr, TRUE);
755 DoMethod(obj, MUIM_Dataspace_Add, addr, size, MUICFG_WindowPos);
756 windowpos_endian(addr, FALSE);
758 return 0;
763 /**************************************************************************
764 MUIM_Configdata_GetString
765 Check if string is found in dataspace, then if not found, search each
766 builtin array
767 **************************************************************************/
768 IPTR Configdata__MUIM_GetString(struct IClass *cl, Object *obj,
769 struct MUIP_Configdata_GetString *msg)
771 CONST_STRPTR s;
773 s = (CONST_STRPTR) DoMethod(obj, MUIM_Dataspace_Find, msg->id);
774 if (!s)
776 int i;
778 for (i = 0; DefStrValues[i].id; i++)
780 if (DefStrValues[i].id == msg->id)
781 return (IPTR) DefStrValues[i].val;
783 for (i = 0; DefImspecValues[i].defspec; i++)
785 if (DefImspecValues[i].cfgid == msg->id)
786 return (IPTR) DefImspecValues[i].defspec;
788 for (i = 0; DefFramespecValues[i].defspec; i++)
790 if (DefFramespecValues[i].cfgid == msg->id)
791 return (IPTR) DefFramespecValues[i].defspec;
793 return (IPTR) 0;
795 else
797 return (IPTR) s;
801 /**************************************************************************
802 MUIM_Configdata_SetImspec
803 search in builtin array first, to not not have in dataspace the default
804 value (would be redundant)
805 **************************************************************************/
806 IPTR Configdata__MUIM_SetImspec(struct IClass *cl, Object *obj,
807 struct MUIP_Configdata_SetImspec *msg)
809 int i;
811 if (!msg->imspec || !*msg->imspec || *msg->imspec == '6')
813 /* D(bug("Configdata_SetImspec(%p) : id %08lx, val invalid\n", */
814 /* obj, msg->id)); */
815 return 0;
818 for (i = 0; DefImspecValues[i].defspec; i++)
820 if (DefImspecValues[i].cfgid == msg->id)
821 if (!strcmp(DefImspecValues[i].defspec, msg->imspec))
823 /* D(bug("Configdata_SetImspec(%p) : set to def, id %08lx, val %s\n", */
824 /* obj, msg->id, msg->imspec)); */
825 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
826 return 0;
830 for (i = 0; DefStrValues[i].id; i++)
832 if (DefStrValues[i].id == msg->id)
833 if (!strcmp(DefStrValues[i].val, msg->imspec))
835 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
836 return 0;
840 DoMethod(obj, MUIM_Dataspace_Add, (IPTR) msg->imspec,
841 strlen(msg->imspec) + 1, msg->id);
842 return 0;
845 /**************************************************************************
846 MUIM_Configdata_SetFramespec
847 **************************************************************************/
848 IPTR Configdata__MUIM_SetFramespec(struct IClass *cl, Object *obj,
849 struct MUIP_Configdata_SetFramespec *msg)
851 int i;
853 if (!msg->framespec || !*msg->framespec)
855 /* D(bug("Configdata_SetFramespec(%p) : id %08lx, val invalid\n", */
856 /* obj, msg->id)); */
857 return 0;
860 for (i = 0; DefFramespecValues[i].defspec; i++)
862 if (DefFramespecValues[i].cfgid == msg->id)
863 if (!strcmp(DefFramespecValues[i].defspec, msg->framespec))
865 /* D(bug("Configdata_SetFramespec(%p): " */
866 /* "set to def, id %08lx, val %s\n", */
867 /* obj, msg->id, msg->framespec)); */
868 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
869 return 0;
873 DoMethod(obj, MUIM_Dataspace_Add, (IPTR) msg->framespec,
874 strlen(msg->framespec) + 1, msg->id);
875 return 0;
878 /**************************************************************************
879 MUIM_Configdata_SetPenspec
880 **************************************************************************/
881 IPTR Configdata__MUIM_SetPenspec(struct IClass *cl, Object *obj,
882 struct MUIP_Configdata_SetPenspec *msg)
884 int i;
886 if (!msg->penspec || !*msg->penspec)
887 return 0;
889 for (i = 0; DefStrValues[i].id; i++)
891 if (DefStrValues[i].id == msg->id)
892 if (!strcmp(DefStrValues[i].val, msg->penspec))
894 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
895 return 0;
899 DoMethod(obj, MUIM_Dataspace_Add, (IPTR) msg->penspec,
900 strlen(msg->penspec) + 1, msg->id);
901 return 0;
904 /**************************************************************************
905 MUIM_Configdata_SetFont
906 **************************************************************************/
907 IPTR Configdata__MUIM_SetFont(struct IClass *cl, Object *obj,
908 struct MUIP_Configdata_SetFont *msg)
910 if (!msg->font || !*msg->font)
912 /* D(bug("Configdata_SetFont(%p) : id %08lx, val invalid\n", */
913 /* obj, msg->id)); */
914 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
915 return 0;
918 DoMethod(obj, MUIM_Dataspace_Add, (IPTR) msg->font,
919 strlen(msg->font) + 1, msg->id);
920 return 0;
923 /**************************************************************************
924 MUIM_Configdata_SetString
925 **************************************************************************/
926 IPTR Configdata__MUIM_SetString(struct IClass *cl, Object *obj,
927 struct MUIP_Configdata_SetString *msg)
929 int i;
931 for (i = 0; DefStrValues[i].id; i++)
933 if (DefStrValues[i].id == msg->id)
934 if (!strcmp(DefStrValues[i].val, msg->string))
936 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
937 return 0;
941 DoMethod(obj, MUIM_Dataspace_Add, (IPTR) msg->string,
942 strlen(msg->string) + 1, msg->id);
943 return 0;
946 /**************************************************************************
947 MUIM_Configdata_GetULong
948 **************************************************************************/
949 IPTR Configdata__MUIM_GetULong(struct IClass *cl, Object *obj,
950 struct MUIP_Configdata_GetULong *msg)
952 ULONG *vp;
954 vp = (ULONG *) DoMethod(obj, MUIM_Dataspace_Find, msg->id);
955 if (!vp)
957 int i;
959 for (i = 0; DefULValues[i].id != 0; i++)
961 if (DefULValues[i].id == msg->id)
962 return DefULValues[i].val;
964 return 0;
966 else
968 return AROS_BE2LONG(*vp);
972 /**************************************************************************
973 MUIM_Configdata_SetULong
974 **************************************************************************/
975 IPTR Configdata__MUIM_SetULong(struct IClass *cl, Object *obj,
976 struct MUIP_Configdata_SetULong *msg)
978 ULONG v = msg->val;
979 ULONG *vp = &v;
980 int i;
982 for (i = 0; DefULValues[i].id != 0; i++)
984 if (DefULValues[i].id == msg->id)
985 if (DefULValues[i].val == v)
987 /* D(bug("Configdata_SetULong(%p):" */
988 /* " set to def, id %08lx, val %ld\n", */
989 /* obj, msg->id, v)); */
990 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
991 return 0;
995 v = AROS_LONG2BE(v);
996 /* D(bug("Configdata_SetULong(%p): adding %08lx to %08lx chunk\n", */
997 /* obj, v, msg->id)); */
998 DoMethod(obj, MUIM_Dataspace_Add, (IPTR) vp, 4, msg->id);
999 return 0;
1003 /**************************************************************************
1004 SavePrefsHeader: Write a PRHD chunk
1005 **************************************************************************/
1006 static int SavePrefsHeader(struct IFFHandle *iff)
1008 if (!PushChunk(iff, 0, MAKE_ID('P', 'R', 'H', 'D'), IFFSIZE_UNKNOWN))
1010 struct PrefHeader ph;
1011 ph.ph_Version = 0;
1012 ph.ph_Type = 0;
1013 ph.ph_Flags = 0;
1015 if (WriteChunkBytes(iff, &ph, sizeof(struct PrefHeader)))
1016 if (!PopChunk(iff))
1017 return 1;
1018 PopChunk(iff);
1020 return 0;
1023 /**************************************************************************
1024 MUIM_Configdata_Save
1025 **************************************************************************/
1026 IPTR Configdata__MUIM_Save(struct IClass *cl, Object *obj,
1027 struct MUIP_Configdata_Save *msg)
1029 struct IFFHandle *iff;
1030 if ((iff = AllocIFF()))
1032 if (!(iff->iff_Stream = (IPTR) Open(msg->filename, MODE_NEWFILE)))
1034 /* Try to Create the directory where the file is located */
1035 char *path = StrDup(msg->filename);
1036 if (path)
1038 char *path_end = PathPart(path);
1039 if (path_end != path)
1041 BPTR lock;
1042 *path_end = 0;
1043 if ((lock = CreateDir(path)))
1045 UnLock(lock);
1046 iff->iff_Stream =
1047 (IPTR) Open(msg->filename, MODE_NEWFILE);
1050 FreeVec(path);
1054 if (iff->iff_Stream)
1056 InitIFFasDOS(iff);
1058 if (!OpenIFF(iff, IFFF_WRITE))
1060 if (!PushChunk(iff, MAKE_ID('P', 'R', 'E', 'F'), ID_FORM,
1061 IFFSIZE_UNKNOWN))
1063 Configdata_SetWindowPos(cl, obj, (APTR) msg);
1064 if (SavePrefsHeader(iff))
1066 DoMethod(obj, MUIM_Dataspace_WriteIFF, (IPTR) iff,
1067 0, MAKE_ID('M', 'U', 'I', 'C'));
1069 PopChunk(iff);
1072 CloseIFF(iff);
1074 Close((BPTR) iff->iff_Stream);
1076 FreeIFF(iff);
1078 return 0;
1082 /**************************************************************************
1083 MUIM_Configdata_Load
1084 Get the content of the file into the object.
1085 **************************************************************************/
1086 IPTR Configdata__MUIM_Load(struct IClass *cl, Object *obj,
1087 struct MUIP_Configdata_Load *msg)
1089 struct IFFHandle *iff;
1090 IPTR res = TRUE;
1092 if ((iff = AllocIFF()))
1094 D(bug("loading prefs from %s\n", msg->filename));
1095 if ((iff->iff_Stream = (IPTR) Open(msg->filename, MODE_OLDFILE)))
1097 InitIFFasDOS(iff);
1099 if (!OpenIFF(iff, IFFF_READ))
1101 StopChunk(iff, MAKE_ID('P', 'R', 'E', 'F'), MAKE_ID('M',
1102 'U', 'I', 'C'));
1104 while (!ParseIFF(iff, IFFPARSE_SCAN))
1106 struct ContextNode *cn;
1107 if (!(cn = CurrentChunk(iff)))
1108 continue;
1109 if (cn->cn_ID == MAKE_ID('M', 'U', 'I', 'C'))
1110 DoMethod(obj, MUIM_Dataspace_ReadIFF, (IPTR) iff);
1113 CloseIFF(iff);
1115 else
1117 res = FALSE;
1119 Close((BPTR) iff->iff_Stream);
1121 else
1123 res = FALSE;
1125 FreeIFF(iff);
1127 else
1129 res = FALSE;
1131 return res;
1136 * The class dispatcher
1138 BOOPSI_DISPATCHER(IPTR, Configdata_Dispatcher, cl, obj, msg)
1140 switch (msg->MethodID)
1142 case OM_NEW:
1143 return Configdata__OM_NEW(cl, obj, (struct opSet *)msg);
1144 case OM_DISPOSE:
1145 return Configdata__OM_DISPOSE(cl, obj, (APTR) msg);
1146 case OM_GET:
1147 return Configdata__OM_GET(cl, obj, (APTR) msg);
1148 case MUIM_Configdata_GetString:
1149 return Configdata__MUIM_GetString(cl, obj, (APTR) msg);
1150 case MUIM_Configdata_GetULong:
1151 return Configdata__MUIM_GetULong(cl, obj, (APTR) msg);
1152 case MUIM_Configdata_SetULong:
1153 return Configdata__MUIM_SetULong(cl, obj, (APTR) msg);
1154 case MUIM_Configdata_SetImspec:
1155 return Configdata__MUIM_SetImspec(cl, obj, (APTR) msg);
1156 case MUIM_Configdata_SetFramespec:
1157 return Configdata__MUIM_SetFramespec(cl, obj, (APTR) msg);
1158 case MUIM_Configdata_SetPenspec:
1159 return Configdata__MUIM_SetPenspec(cl, obj, (APTR) msg);
1160 case MUIM_Configdata_SetFont:
1161 return Configdata__MUIM_SetFont(cl, obj, (APTR) msg);
1162 case MUIM_Configdata_SetString:
1163 return Configdata__MUIM_SetString(cl, obj, (APTR) msg);
1164 case MUIM_Configdata_Save:
1165 return Configdata__MUIM_Save(cl, obj, (APTR) msg);
1166 case MUIM_Configdata_Load:
1167 return Configdata__MUIM_Load(cl, obj, (APTR) msg);
1168 case MUIM_Configdata_SetWindowPos:
1169 return Configdata_SetWindowPos(cl, obj, (APTR) msg);
1170 case MUIM_Configdata_GetWindowPos:
1171 return Configdata_GetWindowPos(cl, obj, (APTR) msg);
1175 return DoSuperMethodA(cl, obj, msg);
1177 BOOPSI_DISPATCHER_END
1180 * Class descriptor.
1182 const struct __MUIBuiltinClass _MUI_Configdata_desc =
1184 MUIC_Configdata, /* Class name */
1185 MUIC_Dataspace, /* super class name */
1186 sizeof(struct MUI_ConfigdataData), /* size of class own datas */
1187 (void *) Configdata_Dispatcher /* class dispatcher */