Fixed the size of a byte-swap operation. Saving window positions works
[AROS.git] / workbench / libs / muimaster / classes / configdata.c
blobcb5220ace8818a9e8d9253d012a10a456d666482
1 /*
2 Copyright © 2002-2014, The AROS Development Team. All rights reserved.
4 $Id$
5 */
6 #include <stdlib.h>
7 #include <string.h>
8 #include <stdio.h>
10 #include <exec/types.h>
11 #include <prefs/prefhdr.h>
12 #include <clib/alib_protos.h>
13 #include <proto/exec.h>
14 #include <proto/intuition.h>
15 #include <proto/utility.h>
16 #include <proto/iffparse.h>
17 #include <proto/dos.h>
18 #include <proto/commodities.h>
19 #include <proto/muimaster.h>
21 /* #define MYDEBUG 1 */
22 #include "debug.h"
24 #include "muimaster_intern.h"
25 #include "mui.h"
26 #include "support.h"
27 #include "prefs.h"
28 #include "imspec.h"
30 extern struct Library *MUIMasterBase;
32 struct MUI_ConfigdataData
34 Object *app;
35 CONST_STRPTR appbase;
36 struct ZunePrefsNew prefs;
40 static CONST_STRPTR GetConfigString(Object *obj, ULONG id)
42 return (CONST_STRPTR) DoMethod(obj, MUIM_Configdata_GetString, id);
45 static ULONG GetConfigULong(Object *obj, ULONG id)
47 return (ULONG) DoMethod(obj, MUIM_Configdata_GetULong, id);
51 /**************************************************************************
52 Default ImageSpec values
53 **************************************************************************/
55 struct spec_cfg
57 ULONG muiv;
58 ULONG cfgid;
59 CONST_STRPTR defspec;
62 const static struct spec_cfg DefImspecValues[] =
64 { MUII_WindowBack, MUICFG_Background_Window, "0:128" },
65 { MUII_RequesterBack, MUICFG_Background_Requester, "0:137" },
66 { MUII_ButtonBack, MUICFG_Background_Button, "0:128" },
67 { MUII_ListBack, MUICFG_Background_List, "0:128" },
68 { MUII_TextBack, MUICFG_Background_Text, "0:128" },
69 { MUII_PropBack, MUICFG_Background_Prop, "0:128" },
70 { MUII_PopupBack, MUICFG_Background_PopUp, "0:128" },
71 { MUII_SelectedBack, MUICFG_Background_Selected, "0:131" },
72 { MUII_ListCursor, MUICFG_Background_ListCursor, "0:131" },
73 { MUII_ListSelect, MUICFG_Background_ListSelect, "0:135" },
74 { MUII_ListSelCur, MUICFG_Background_ListSelCur, "0:138" },
75 { MUII_ArrowUp, MUICFG_Image_ArrowUp, "1:0" },
76 { MUII_ArrowDown, MUICFG_Image_ArrowDown, "1:1" },
77 { MUII_ArrowLeft, MUICFG_Image_ArrowLeft, "1:2" },
78 { MUII_ArrowRight, MUICFG_Image_ArrowRight, "1:3" },
79 { MUII_CheckMark, MUICFG_Image_CheckMark, "1:4" },
80 { MUII_RadioButton, MUICFG_Image_RadioButton, "1:5" },
81 { MUII_Cycle, MUICFG_Image_Cycle, "1:6" },
82 { MUII_PopUp, MUICFG_Image_PopUp, "1:7" },
83 { MUII_PopFile, MUICFG_Image_PopFile, "1:8" },
84 { MUII_PopDrawer, MUICFG_Image_PopDrawer, "1:9" },
85 { MUII_PropKnob, MUICFG_Image_PropKnob, "0:129" },
86 { MUII_Drawer, MUICFG_Image_Drawer, "1:10" },
87 { MUII_HardDisk, MUICFG_Image_HardDisk, "1:11" },
88 { MUII_Disk, MUICFG_Image_Disk, "1:12" },
89 { MUII_Chip, MUICFG_Image_Chip, "1:13" },
90 { MUII_Volume, MUICFG_Image_Volume, "1:14" },
91 { MUII_RegisterBack, MUICFG_Background_Register, "0:128" },
92 { MUII_Network, MUICFG_Image_Network, "1:15" },
93 { MUII_Assign, MUICFG_Image_Assign, "1:16" },
94 { MUII_TapePlay, MUICFG_Image_TapePlay, "1:17" },
95 { MUII_TapePlayBack, MUICFG_Image_TapePlayBack, "1:18" },
96 { MUII_TapePause, MUICFG_Image_TapePause, "1:19" },
97 { MUII_TapeStop, MUICFG_Image_TapeStop, "1:20" },
98 { MUII_TapeRecord, MUICFG_Image_TapeRecord, "1:21" },
99 { MUII_GroupBack, MUICFG_Background_Framed, "0:128" },
100 { MUII_SliderBack, MUICFG_Background_Slider, "0:128" },
101 { MUII_SliderKnob, MUICFG_Background_SliderKnob, "0:128" },
102 { MUII_TapeUp, MUICFG_Image_TapeUp, "1:22" },
103 { MUII_TapeDown, MUICFG_Image_TapeDown, "1:23" },
104 { MUII_PageBack, MUICFG_Background_Page, "0:128" },
105 { MUII_ReadListBack, MUICFG_Background_ReadList, "0:128" },
106 { 0, 0, NULL },
109 /* called by Configdata_New */
110 static void init_imspecs(Object *obj, struct MUI_ConfigdataData *data)
112 int i;
114 for (i = 0; DefImspecValues[i].defspec; i++)
116 CONST_STRPTR imspec;
117 const struct spec_cfg *img = DefImspecValues + i;
119 imspec = GetConfigString(obj, img->cfgid);
120 /* D(bug("init_imspecs: %ld %lx %s ...\n", img->muiv, img->cfgid, imspec)); */
121 data->prefs.imagespecs[img->muiv] = imspec;
122 if (!data->prefs.imagespecs[img->muiv])
124 /* D(bug("*** init_imspecs: null imagespec %ld\n", img->muiv)); */
129 /**************************************************************************
130 Default FrameSpec values
131 **************************************************************************/
133 /* spec format : type, recessed, left, right, up, down spacing */
134 const static struct spec_cfg DefFramespecValues[] =
136 { MUIV_Frame_None, MUICFG_Invalid, "000000" }, /* invisible frame */
137 { MUIV_Frame_Button, MUICFG_Frame_Button, "202211" }, /* text button */
138 { MUIV_Frame_ImageButton, MUICFG_Frame_ImageButton, "202211" }, /* image button */
139 { MUIV_Frame_Text, MUICFG_Frame_Text, "212211" }, /* textfield without input */
140 { MUIV_Frame_String, MUICFG_Frame_String, "302211" }, /* string gadget */
141 { MUIV_Frame_ReadList, MUICFG_Frame_ReadList, "212211" }, /* list without input */
142 { MUIV_Frame_InputList, MUICFG_Frame_InputList, "202211" }, /* list with input */
143 { MUIV_Frame_Prop, MUICFG_Frame_Prop, "202211" }, /* scrollbar container */
144 { MUIV_Frame_Gauge, MUICFG_Frame_Gauge, "210000" }, /* gauge */
145 { MUIV_Frame_Group, MUICFG_Frame_Group, "314444" }, /* normal group */
146 { MUIV_Frame_PopUp, MUICFG_Frame_PopUp, "112211" }, /* cycle menu, popup window */
147 { MUIV_Frame_Virtual, MUICFG_Frame_Virtual, "212211" }, /* virt group */
148 { MUIV_Frame_Slider, MUICFG_Frame_Slider, "400000" }, /* slider container */
149 { MUIV_Frame_Knob, MUICFG_Frame_Knob, "202211" }, /* slider knob */
150 { MUIV_Frame_Drag, MUICFG_Frame_Drag, "300000" }, /* dnd frame */
151 { -1, -1, NULL },
154 /* called by Configdata_New */
155 static void init_framespecs(Object *obj, struct MUI_ConfigdataData *data)
157 int i;
159 for (i = 0; DefFramespecValues[i].defspec; i++)
161 CONST_STRPTR framespec;
162 const struct spec_cfg *fcfg = DefFramespecValues + i;
164 framespec = GetConfigString(obj, fcfg->cfgid);
165 zune_frame_spec_to_intern(framespec,
166 &data->prefs.frames[fcfg->muiv]);
170 /**************************************************************************
171 Default ULONG values
172 **************************************************************************/
174 struct def_ulval
176 ULONG id;
177 ULONG val;
180 const static struct def_ulval DefULValues[] = {
181 {MUICFG_Window_Spacing_Left, 4},
182 {MUICFG_Window_Spacing_Right, 4},
183 {MUICFG_Window_Spacing_Top, 3},
184 {MUICFG_Window_Buttons, 0},
185 {MUICFG_Window_Spacing_Bottom, 3},
186 {MUICFG_Window_Positions, WINDOW_POSITION_FORGET_ON_EXIT},
187 {MUICFG_Window_Redraw, WINDOW_REDRAW_WITHOUT_CLEAR},
188 {MUICFG_Window_Refresh, WINDOW_REFRESH_SIMPLE},
189 {MUICFG_Radio_HSpacing, 4},
190 {MUICFG_Radio_VSpacing, 1},
191 {MUICFG_Group_HSpacing, 6},
192 {MUICFG_Group_VSpacing, 3},
193 {MUICFG_Cycle_MenuCtrl_Position, CYCLE_MENU_POSITION_BELOW},
194 {MUICFG_Cycle_MenuCtrl_Level, 2},
195 {MUICFG_Cycle_MenuCtrl_Speed, 0},
196 {MUICFG_Cycle_Menu_Recessed, FALSE},
197 {MUICFG_Listview_Font_Leading, 1},
198 {MUICFG_Listview_Smoothed, FALSE},
199 {MUICFG_Listview_SmoothVal, 0},
200 {MUICFG_Listview_Refresh, LISTVIEW_REFRESH_MIXED},
201 {MUICFG_Listview_Multi, LISTVIEW_MULTI_SHIFTED},
202 {MUICFG_GroupTitle_Position, GROUP_TITLE_POSITION_CENTERED},
203 {MUICFG_GroupTitle_Color, GROUP_TITLE_COLOR_HILITE},
204 {MUICFG_Scrollbar_Type, SCROLLBAR_TYPE_STANDARD},
205 {MUICFG_Scrollbar_Arrangement, SCROLLBAR_ARRANGEMENT_TOP},
206 {MUICFG_Balance_Look, BALANCING_SHOW_FRAMES},
207 {MUICFG_Dragndrop_Look, DND_LOOK_GHOSTED_ON_BOX},
208 {MUICFG_Drag_Autostart, TRUE},
209 {MUICFG_Drag_Autostart_Length, 3},
210 {MUICFG_Drag_LeftButton, TRUE},
211 {MUICFG_Drag_MiddleButton, FALSE},
212 {MUICFG_Register_TruncateTitles, FALSE},
213 {MUICFG_Screen_Mode, 0},
214 {MUICFG_Screen_Mode_ID, -1},
215 {MUICFG_Screen_Width, 0},
216 {MUICFG_Screen_Height, 0},
217 {MUICFG_PublicScreen_PopToFront, TRUE},
218 {MUICFG_Iconification_ShowIcon, TRUE},
219 {MUICFG_Iconification_ShowMenu, FALSE},
220 {MUICFG_Iconification_OnStartup, FALSE},
221 {MUICFG_Interfaces_EnableARexx, TRUE},
222 {MUICFG_BubbleHelp_FirstDelay, 30},
223 {MUICFG_BubbleHelp_NextDelay, 10},
224 {0, 0},
227 /**************************************************************************
228 Default string values
229 **************************************************************************/
231 struct def_strval
233 ULONG id;
234 CONST_STRPTR val;
237 /* NULL values not allowed */
238 const static struct def_strval DefStrValues[] = {
239 {MUICFG_Font_Normal, ""},
240 {MUICFG_Font_List, ""},
241 {MUICFG_Font_Tiny, ""},
242 {MUICFG_Font_Fixed, ""},
243 {MUICFG_Font_Title, ""},
244 {MUICFG_Font_Big, ""},
245 {MUICFG_Font_Button, ""},
246 {MUICFG_Font_Knob, ""},
247 {MUICFG_String_Background, "2:m2"},
248 {MUICFG_String_Text, "m5"},
249 {MUICFG_String_ActiveBackground, "2:m1"},
250 {MUICFG_String_ActiveText, "m5"},
251 {MUICFG_String_Cursor, "m7"},
252 {MUICFG_String_MarkedBackground, "m6"},
253 {MUICFG_String_MarkedText, "m0"},
254 {MUICFG_ActiveObject_Color, "m0"},
255 {MUICFG_Keyboard_Press, "-upstroke return"},
256 {MUICFG_Keyboard_Toggle, "-repeat space"},
257 {MUICFG_Keyboard_Up, "-repeat up"},
258 {MUICFG_Keyboard_Down, "-repeat down"},
259 {MUICFG_Keyboard_PageUp, "-repeat shift up"},
260 {MUICFG_Keyboard_PageDown, "-repeat shift down"},
261 {MUICFG_Keyboard_Top, "control up"},
262 {MUICFG_Keyboard_Bottom, "control down"},
263 {MUICFG_Keyboard_Left, "-repeat left"},
264 {MUICFG_Keyboard_Right, "-repeat right"},
265 {MUICFG_Keyboard_WordLeft, "-repeat control left"},
266 {MUICFG_Keyboard_WordRight, "-repeat control right"},
267 {MUICFG_Keyboard_LineStart, "shift left"},
268 {MUICFG_Keyboard_LineEnd, "shift right"},
269 {MUICFG_Keyboard_NextGadget, "-repeat tab"},
270 {MUICFG_Keyboard_PrevGadget, "-repeat shift tab"},
271 {MUICFG_Keyboard_GadgetOff, "control tab"},
272 {MUICFG_Keyboard_CloseWindow, "esc"},
273 {MUICFG_Keyboard_NextWindow, "-repeat alt tab"},
274 {MUICFG_Keyboard_PrevWindow, "-repeat alt shift tab"},
275 {MUICFG_Keyboard_Help, "help"},
276 {MUICFG_Keyboard_Popup, "control p"},
277 {MUICFG_Drag_LMBModifier, "control"},
278 {MUICFG_Drag_MMBModifier, ""},
279 {MUICFG_PublicScreen, ""},
280 {MUICFG_Iconification_Hotkey, ""},
281 {0, 0},
285 /**************************************************************************
286 OM_NEW
287 Load global (and maybe application-specific) prefs files into the dataspace,
288 then fill the prefs struct with dataspace or default values
289 **************************************************************************/
290 IPTR Configdata__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
292 struct MUI_ConfigdataData *data;
293 struct TagItem *tags;
294 struct TagItem *tag;
295 //APTR cdata;
296 int i, res = 0;
298 obj = (Object *) DoSuperMethodA(cl, obj, (Msg) msg);
299 if (!obj)
300 return (IPTR) NULL;
302 /* D(bug("Configdata_New(%p)\n", obj)); */
304 data = INST_DATA(cl, obj);
306 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags));)
308 switch (tag->ti_Tag)
310 case MUIA_Configdata_Application:
311 data->app = (Object *) tag->ti_Data;
312 break;
313 case MUIA_Configdata_ApplicationBase:
314 data->appbase = (CONST_STRPTR) tag->ti_Data;
315 break;
319 if (data->app && !data->appbase)
321 get(data->app, MUIA_Application_Base, &data->appbase);
324 if (data->appbase)
326 char filename[255];
327 snprintf(filename, 255, "ENV:zune/%s.prefs", data->appbase);
328 res = DoMethod(obj, MUIM_Configdata_Load, (IPTR) filename);
329 if (!res)
331 snprintf(filename, 255, "ENVARC:zune/%s.prefs", data->appbase);
332 res = DoMethod(obj, MUIM_Configdata_Load, (IPTR) filename);
336 // load only global prefs if no local app pref is found
337 if (!res)
339 if (!DoMethod(obj, MUIM_Configdata_Load,
340 (IPTR) "ENV:zune/global.prefs"))
342 DoMethod(obj, MUIM_Configdata_Load,
343 (IPTR) "ENVARC:zune/global.prefs");
346 /*---------- fonts stuff ----------*/
348 data->prefs.fonts[-MUIV_Font_Normal] =
349 GetConfigString(obj, MUICFG_Font_Normal);
350 data->prefs.fonts[-MUIV_Font_List] =
351 GetConfigString(obj, MUICFG_Font_List);
352 data->prefs.fonts[-MUIV_Font_Tiny] =
353 GetConfigString(obj, MUICFG_Font_Tiny);
354 data->prefs.fonts[-MUIV_Font_Fixed] =
355 GetConfigString(obj, MUICFG_Font_Fixed);
356 data->prefs.fonts[-MUIV_Font_Title] =
357 GetConfigString(obj, MUICFG_Font_Title);
358 data->prefs.fonts[-MUIV_Font_Big] =
359 GetConfigString(obj, MUICFG_Font_Big);
360 data->prefs.fonts[-MUIV_Font_Button] =
361 GetConfigString(obj, MUICFG_Font_Button);
362 data->prefs.fonts[-MUIV_Font_Knob] =
363 GetConfigString(obj, MUICFG_Font_Knob);
365 /*---------- images stuff ----------*/
367 init_imspecs(obj, data);
369 /*---------- frame stuff ----------*/
371 init_framespecs(obj, data);
373 /*---------- system stuff ----------*/
375 data->prefs.publicscreen_name =
376 GetConfigString(obj, MUICFG_PublicScreen);
377 data->prefs.publicscreen_pop_to_front =
378 GetConfigULong(obj, MUICFG_PublicScreen_PopToFront);
379 data->prefs.iconification_hotkey =
380 GetConfigString(obj, MUICFG_Iconification_Hotkey);
381 data->prefs.iconification_show_icon =
382 GetConfigULong(obj, MUICFG_Iconification_ShowIcon);
383 data->prefs.iconification_show_menu =
384 GetConfigULong(obj, MUICFG_Iconification_ShowMenu);
385 data->prefs.iconification_on_startup =
386 GetConfigULong(obj, MUICFG_Iconification_OnStartup);
387 data->prefs.interfaces_enable_arexx =
388 GetConfigULong(obj, MUICFG_Interfaces_EnableARexx);
389 data->prefs.bubblehelp_first_delay =
390 GetConfigULong(obj, MUICFG_BubbleHelp_FirstDelay);
391 data->prefs.bubblehelp_next_delay =
392 GetConfigULong(obj, MUICFG_BubbleHelp_NextDelay);
394 /*---------- window stuff ----------*/
396 data->prefs.window_inner_left =
397 GetConfigULong(obj, MUICFG_Window_Spacing_Left);
398 data->prefs.window_inner_right =
399 GetConfigULong(obj, MUICFG_Window_Spacing_Right);
400 data->prefs.window_inner_top =
401 GetConfigULong(obj, MUICFG_Window_Spacing_Top);
402 data->prefs.window_inner_bottom =
403 GetConfigULong(obj, MUICFG_Window_Spacing_Bottom);
404 data->prefs.window_position =
405 GetConfigULong(obj, MUICFG_Window_Positions);
406 data->prefs.window_redraw = GetConfigULong(obj, MUICFG_Window_Redraw);
407 data->prefs.window_refresh = GetConfigULong(obj, MUICFG_Window_Refresh);
408 data->prefs.screenmode = GetConfigULong(obj, MUICFG_Screen_Mode);
409 data->prefs.screenmodeid = GetConfigULong(obj, MUICFG_Screen_Mode_ID);
410 data->prefs.screen_width = GetConfigULong(obj, MUICFG_Screen_Width);
411 data->prefs.screen_height = GetConfigULong(obj, MUICFG_Screen_Height);
412 data->prefs.window_buttons = GetConfigULong(obj, MUICFG_Window_Buttons);
414 /*---------- group stuff ----------*/
416 data->prefs.group_title_position =
417 GetConfigULong(obj, MUICFG_GroupTitle_Position);
418 data->prefs.group_title_color =
419 GetConfigULong(obj, MUICFG_GroupTitle_Color);
420 data->prefs.group_hspacing = GetConfigULong(obj, MUICFG_Group_HSpacing);
421 data->prefs.group_vspacing = GetConfigULong(obj, MUICFG_Group_VSpacing);
423 /*---------- registers ----------*/
425 data->prefs.register_look = REGISTER_LOOK_TRADITIONAL;
426 data->prefs.register_truncate_titles =
427 GetConfigULong(obj, MUICFG_Register_TruncateTitles);
429 /*---------- Buttons ----------*/
431 data->prefs.radiobutton_hspacing =
432 GetConfigULong(obj, MUICFG_Radio_HSpacing);
433 data->prefs.radiobutton_vspacing =
434 GetConfigULong(obj, MUICFG_Radio_VSpacing);
436 /*---------- Cycles ----------*/
438 data->prefs.cycle_menu_position =
439 GetConfigULong(obj, MUICFG_Cycle_MenuCtrl_Position);
440 data->prefs.cycle_menu_min_entries =
441 GetConfigULong(obj, MUICFG_Cycle_MenuCtrl_Level);
442 data->prefs.cycle_menu_speed =
443 GetConfigULong(obj, MUICFG_Cycle_MenuCtrl_Speed);
444 data->prefs.cycle_menu_recessed_entries =
445 GetConfigULong(obj, MUICFG_Cycle_Menu_Recessed);
447 /*---------- Sliders ----------*/
448 /* all taken care of in frames and images */
450 /*---------- Scrollbars ----------*/
452 data->prefs.scrollbar_type = GetConfigULong(obj, MUICFG_Scrollbar_Type);
453 data->prefs.scrollbar_arrangement =
454 GetConfigULong(obj, MUICFG_Scrollbar_Arrangement);
456 /*---------- Lists ----------*/
458 data->prefs.list_linespacing =
459 GetConfigULong(obj, MUICFG_Listview_Font_Leading);
460 data->prefs.list_smoothed =
461 GetConfigULong(obj, MUICFG_Listview_Smoothed);
462 data->prefs.list_smoothval =
463 GetConfigULong(obj, MUICFG_Listview_SmoothVal);
464 data->prefs.list_multi = GetConfigULong(obj, MUICFG_Listview_Multi);
465 data->prefs.list_refresh = GetConfigULong(obj, MUICFG_Listview_Refresh);
467 /*---------- Strings ----------*/
468 data->prefs.string_bg_inactive =
469 GetConfigString(obj, MUICFG_String_Background);
470 data->prefs.string_text_inactive =
471 GetConfigString(obj, MUICFG_String_Text);
472 data->prefs.string_bg_active =
473 GetConfigString(obj, MUICFG_String_ActiveBackground);
474 data->prefs.string_text_active =
475 GetConfigString(obj, MUICFG_String_ActiveText);
476 data->prefs.string_cursor = GetConfigString(obj, MUICFG_String_Cursor);
477 data->prefs.string_bg_marked =
478 GetConfigString(obj, MUICFG_String_MarkedBackground);
479 data->prefs.string_text_marked =
480 GetConfigString(obj, MUICFG_String_MarkedText);
482 /*---------- Navigation ----------*/
484 data->prefs.drag_left_button =
485 GetConfigULong(obj, MUICFG_Drag_LeftButton);
486 data->prefs.drag_left_modifier.readable_hotkey =
487 GetConfigString(obj, MUICFG_Drag_LMBModifier);
488 data->prefs.drag_middle_button =
489 GetConfigULong(obj, MUICFG_Drag_MiddleButton);
490 data->prefs.drag_middle_modifier.readable_hotkey =
491 GetConfigString(obj, MUICFG_Drag_MMBModifier);
492 data->prefs.drag_autostart = GetConfigULong(obj, MUICFG_Drag_Autostart);
493 data->prefs.drag_autostart_length =
494 GetConfigULong(obj, MUICFG_Drag_Autostart_Length);
495 data->prefs.drag_look = GetConfigULong(obj, MUICFG_Dragndrop_Look);
496 data->prefs.balancing_look = GetConfigULong(obj, MUICFG_Balance_Look);
498 if (data->prefs.drag_left_modifier.readable_hotkey != NULL)
499 data->prefs.drag_left_modifier.ix_well =
500 !ParseIX(data->prefs.drag_left_modifier.readable_hotkey,
501 &data->prefs.drag_left_modifier.ix);
502 else
503 data->prefs.drag_left_modifier.ix_well = 0;
505 if (data->prefs.drag_middle_modifier.readable_hotkey != NULL)
506 data->prefs.drag_middle_modifier.ix_well =
507 !ParseIX(data->prefs.drag_middle_modifier.readable_hotkey,
508 &data->prefs.drag_middle_modifier.ix);
509 else
510 data->prefs.drag_middle_modifier.ix_well = 0;
512 data->prefs.active_object_color =
513 GetConfigString(obj, MUICFG_ActiveObject_Color);
514 /*---------- mui keys ----------*/
516 data->prefs.muikeys[MUIKEY_PRESS].readable_hotkey =
517 GetConfigString(obj, MUICFG_Keyboard_Press);
518 data->prefs.muikeys[MUIKEY_TOGGLE].readable_hotkey =
519 GetConfigString(obj, MUICFG_Keyboard_Toggle);
520 data->prefs.muikeys[MUIKEY_UP].readable_hotkey =
521 GetConfigString(obj, MUICFG_Keyboard_Up);
522 data->prefs.muikeys[MUIKEY_DOWN].readable_hotkey =
523 GetConfigString(obj, MUICFG_Keyboard_Down);
524 data->prefs.muikeys[MUIKEY_PAGEUP].readable_hotkey =
525 GetConfigString(obj, MUICFG_Keyboard_PageUp);
526 data->prefs.muikeys[MUIKEY_PAGEDOWN].readable_hotkey =
527 GetConfigString(obj, MUICFG_Keyboard_PageDown);
528 data->prefs.muikeys[MUIKEY_TOP].readable_hotkey =
529 GetConfigString(obj, MUICFG_Keyboard_Top);
530 data->prefs.muikeys[MUIKEY_BOTTOM].readable_hotkey =
531 GetConfigString(obj, MUICFG_Keyboard_Bottom);
532 data->prefs.muikeys[MUIKEY_LEFT].readable_hotkey =
533 GetConfigString(obj, MUICFG_Keyboard_Left);
534 data->prefs.muikeys[MUIKEY_RIGHT].readable_hotkey =
535 GetConfigString(obj, MUICFG_Keyboard_Right);
536 data->prefs.muikeys[MUIKEY_WORDLEFT].readable_hotkey =
537 GetConfigString(obj, MUICFG_Keyboard_WordLeft);
538 data->prefs.muikeys[MUIKEY_WORDRIGHT].readable_hotkey =
539 GetConfigString(obj, MUICFG_Keyboard_WordRight);
540 data->prefs.muikeys[MUIKEY_LINESTART].readable_hotkey =
541 GetConfigString(obj, MUICFG_Keyboard_LineStart);
542 data->prefs.muikeys[MUIKEY_LINEEND].readable_hotkey =
543 GetConfigString(obj, MUICFG_Keyboard_LineEnd);
544 data->prefs.muikeys[MUIKEY_GADGET_NEXT].readable_hotkey =
545 GetConfigString(obj, MUICFG_Keyboard_NextGadget);
546 data->prefs.muikeys[MUIKEY_GADGET_PREV].readable_hotkey =
547 GetConfigString(obj, MUICFG_Keyboard_PrevGadget);
548 data->prefs.muikeys[MUIKEY_GADGET_OFF].readable_hotkey =
549 GetConfigString(obj, MUICFG_Keyboard_GadgetOff);
550 data->prefs.muikeys[MUIKEY_WINDOW_CLOSE].readable_hotkey =
551 GetConfigString(obj, MUICFG_Keyboard_CloseWindow);
552 data->prefs.muikeys[MUIKEY_WINDOW_NEXT].readable_hotkey =
553 GetConfigString(obj, MUICFG_Keyboard_NextWindow);
554 data->prefs.muikeys[MUIKEY_WINDOW_PREV].readable_hotkey =
555 GetConfigString(obj, MUICFG_Keyboard_PrevWindow);
556 data->prefs.muikeys[MUIKEY_HELP].readable_hotkey =
557 GetConfigString(obj, MUICFG_Keyboard_Help);
558 data->prefs.muikeys[MUIKEY_POPUP].readable_hotkey =
559 GetConfigString(obj, MUICFG_Keyboard_Popup);
561 for (i = 0; i < MUIKEY_COUNT; i++)
563 if (data->prefs.muikeys[i].readable_hotkey)
564 data->prefs.muikeys[i].ix_well =
565 !ParseIX(data->prefs.muikeys[i].readable_hotkey,
566 &data->prefs.muikeys[i].ix);
567 else
568 data->prefs.muikeys[i].ix_well = 0;
571 /*---------- CustomFrames ----------*/
572 data->prefs.customframe_config_1 =
573 GetConfigString(obj, MUICFG_CustomFrame_1);
574 data->prefs.customframe_config_2 =
575 GetConfigString(obj, MUICFG_CustomFrame_2);
576 data->prefs.customframe_config_3 =
577 GetConfigString(obj, MUICFG_CustomFrame_3);
578 data->prefs.customframe_config_4 =
579 GetConfigString(obj, MUICFG_CustomFrame_4);
580 data->prefs.customframe_config_5 =
581 GetConfigString(obj, MUICFG_CustomFrame_5);
582 data->prefs.customframe_config_6 =
583 GetConfigString(obj, MUICFG_CustomFrame_6);
584 data->prefs.customframe_config_7 =
585 GetConfigString(obj, MUICFG_CustomFrame_7);
586 data->prefs.customframe_config_8 =
587 GetConfigString(obj, MUICFG_CustomFrame_8);
588 data->prefs.customframe_config_9 =
589 GetConfigString(obj, MUICFG_CustomFrame_9);
590 data->prefs.customframe_config_10 =
591 GetConfigString(obj, MUICFG_CustomFrame_10);
592 data->prefs.customframe_config_11 =
593 GetConfigString(obj, MUICFG_CustomFrame_11);
594 data->prefs.customframe_config_12 =
595 GetConfigString(obj, MUICFG_CustomFrame_12);
596 data->prefs.customframe_config_13 =
597 GetConfigString(obj, MUICFG_CustomFrame_13);
598 data->prefs.customframe_config_14 =
599 GetConfigString(obj, MUICFG_CustomFrame_14);
600 data->prefs.customframe_config_15 =
601 GetConfigString(obj, MUICFG_CustomFrame_15);
602 data->prefs.customframe_config_16 =
603 GetConfigString(obj, MUICFG_CustomFrame_16);
605 /*---------- Special ----------*/
606 /* all taken care of in frames and images */
608 return (IPTR) obj;
611 /**************************************************************************
612 OM_DISPOSE
613 **************************************************************************/
614 IPTR Configdata__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
616 /* struct MUI_ConfigdataData *data = INST_DATA(cl, obj); */
617 /* int i; */
619 return DoSuperMethodA(cl, obj, msg);
622 /**************************************************************************
623 OM_GET
624 **************************************************************************/
625 IPTR Configdata__OM_GET(struct IClass *cl, Object *obj,
626 struct opGet *msg)
628 struct MUI_ConfigdataData *data = INST_DATA(cl, obj);
629 IPTR *store = msg->opg_Storage;
630 ULONG tag = msg->opg_AttrID;
632 switch (tag)
634 case MUIA_Configdata_ZunePrefs:
635 *store = (IPTR) & data->prefs;
636 DoMethod(obj, MUIM_Configdata_GetWindowPos, 0);
637 return 1;
640 return DoSuperMethodA(cl, obj, (Msg) msg);
643 #ifndef AROS_BIG_ENDIAN
644 #define AROS_BIG_ENDIAN 0
645 #endif
647 static LONG windowpos_endian(IPTR data, BOOL isNative)
649 LONG size, items;
650 WORD cnt, i, j;
651 void *p = (void *)data;
653 if (AROS_BIG_ENDIAN)
655 size = *(LONG *) p;
657 else
659 if (isNative)
661 size = *(LONG *) p;
663 else
665 size = AROS_BE2LONG(*((LONG *) p));
667 *((LONG *) p) = AROS_SWAP_BYTES_LONG(*((LONG *) p));
670 cnt = sizeof(LONG);
671 items = (size - sizeof(LONG)) / sizeof(struct windowpos);
672 D(bug("size=%d items=%d\n", size, items));
673 if (size > 100 || items > 100)
675 bug("%s crashed...\n", FindTask(NULL)->tc_Node.ln_Name);
677 volatile int dead = 1;
678 while (dead);
682 for (i = 0; i < items; i++)
684 if (AROS_BIG_ENDIAN)
686 D(bug("ID=%08x\n", *((LONG *) (p + cnt))));
688 else
690 if (isNative)
691 D(bug("ID=%08x\n", *((LONG *) (p + cnt))));
692 *((LONG *) (p + cnt)) =
693 AROS_SWAP_BYTES_LONG(*((LONG *) (p + cnt)));
694 if (!isNative)
695 D(bug("ID=%08x\n", *((LONG *) (p + cnt))));
697 cnt += sizeof(LONG);
698 for (j = 0; j < 8; j++)
700 if (AROS_BIG_ENDIAN)
702 D(bug("V%d: %d\n", j, *((WORD *) (p + cnt))));
704 else
706 if (isNative)
707 D(bug("V%d: %d\n", j, *((WORD *) (p + cnt))));
708 *((WORD *) (p + cnt)) =
709 AROS_SWAP_BYTES_WORD(*((WORD *) (p + cnt)));
710 if (!isNative)
711 D(bug("V%d: %d\n", j, *((WORD *) (p + cnt))));
713 cnt += sizeof(WORD);
716 D(bug("size=%d\n", cnt));
717 return cnt;
720 static IPTR Configdata_GetWindowPos(struct IClass *cl, Object *obj,
721 struct MUIP_Configdata_GetString *msg)
723 struct MUI_ConfigdataData *data;
724 IPTR s;
725 data = INST_DATA(cl, obj);
726 //kprintf ("getwindowpos\n");
727 s = (IPTR) DoMethod(obj, MUIM_Dataspace_Find, MUICFG_WindowPos);
728 if (s && data->app)
730 windowpos_endian(s, FALSE);
731 set(data->app, MUIA_Application_CopyWinPosToApp, s);
732 windowpos_endian(s, TRUE);
734 return s;
737 static IPTR Configdata_SetWindowPos(struct IClass *cl, Object *obj,
738 struct MUIP_Configdata_GetString *msg)
740 struct MUI_ConfigdataData *data;
741 //kprintf ("setwindowpos\n");
742 data = INST_DATA(cl, obj);
743 IPTR addr = 0;
744 LONG size = 0;
746 if (data->app)
748 get(data->app, MUIA_Application_GetWinPosAddr, &addr);
749 get(data->app, MUIA_Application_GetWinPosSize, &size);
751 /* We can ignore size-variable because
752 * MUIA_Application_GetWinPosSize updates *((LONG*)addr) */
753 size = windowpos_endian(addr, TRUE);
754 DoMethod(obj, MUIM_Dataspace_Add, addr, size, MUICFG_WindowPos);
755 windowpos_endian(addr, FALSE);
757 return 0;
762 /**************************************************************************
763 MUIM_Configdata_GetString
764 Check if string is found in dataspace, then if not found, search each
765 builtin array
766 **************************************************************************/
767 IPTR Configdata__MUIM_GetString(struct IClass *cl, Object *obj,
768 struct MUIP_Configdata_GetString *msg)
770 CONST_STRPTR s;
772 s = (CONST_STRPTR) DoMethod(obj, MUIM_Dataspace_Find, msg->id);
773 if (!s)
775 int i;
777 for (i = 0; DefStrValues[i].id; i++)
779 if (DefStrValues[i].id == msg->id)
780 return (IPTR) DefStrValues[i].val;
782 for (i = 0; DefImspecValues[i].defspec; i++)
784 if (DefImspecValues[i].cfgid == msg->id)
785 return (IPTR) DefImspecValues[i].defspec;
787 for (i = 0; DefFramespecValues[i].defspec; i++)
789 if (DefFramespecValues[i].cfgid == msg->id)
790 return (IPTR) DefFramespecValues[i].defspec;
792 return (IPTR) 0;
794 else
796 return (IPTR) s;
800 /**************************************************************************
801 MUIM_Configdata_SetImspec
802 search in builtin array first, to not not have in dataspace the default
803 value (would be redundant)
804 **************************************************************************/
805 IPTR Configdata__MUIM_SetImspec(struct IClass *cl, Object *obj,
806 struct MUIP_Configdata_SetImspec *msg)
808 int i;
810 if (!msg->imspec || !*msg->imspec || *msg->imspec == '6')
812 /* D(bug("Configdata_SetImspec(%p) : id %08lx, val invalid\n", */
813 /* obj, msg->id)); */
814 return 0;
817 for (i = 0; DefImspecValues[i].defspec; i++)
819 if (DefImspecValues[i].cfgid == msg->id)
820 if (!strcmp(DefImspecValues[i].defspec, msg->imspec))
822 /* D(bug("Configdata_SetImspec(%p) : set to def, id %08lx, val %s\n", */
823 /* obj, msg->id, msg->imspec)); */
824 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
825 return 0;
829 for (i = 0; DefStrValues[i].id; i++)
831 if (DefStrValues[i].id == msg->id)
832 if (!strcmp(DefStrValues[i].val, msg->imspec))
834 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
835 return 0;
839 DoMethod(obj, MUIM_Dataspace_Add, (IPTR) msg->imspec,
840 strlen(msg->imspec) + 1, msg->id);
841 return 0;
844 /**************************************************************************
845 MUIM_Configdata_SetFramespec
846 **************************************************************************/
847 IPTR Configdata__MUIM_SetFramespec(struct IClass *cl, Object *obj,
848 struct MUIP_Configdata_SetFramespec *msg)
850 int i;
852 if (!msg->framespec || !*msg->framespec)
854 /* D(bug("Configdata_SetFramespec(%p) : id %08lx, val invalid\n", */
855 /* obj, msg->id)); */
856 return 0;
859 for (i = 0; DefFramespecValues[i].defspec; i++)
861 if (DefFramespecValues[i].cfgid == msg->id)
862 if (!strcmp(DefFramespecValues[i].defspec, msg->framespec))
864 /* D(bug("Configdata_SetFramespec(%p): " */
865 /* "set to def, id %08lx, val %s\n", */
866 /* obj, msg->id, msg->framespec)); */
867 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
868 return 0;
872 DoMethod(obj, MUIM_Dataspace_Add, (IPTR) msg->framespec,
873 strlen(msg->framespec) + 1, msg->id);
874 return 0;
877 /**************************************************************************
878 MUIM_Configdata_SetPenspec
879 **************************************************************************/
880 IPTR Configdata__MUIM_SetPenspec(struct IClass *cl, Object *obj,
881 struct MUIP_Configdata_SetPenspec *msg)
883 int i;
885 if (!msg->penspec || !*msg->penspec)
886 return 0;
888 for (i = 0; DefStrValues[i].id; i++)
890 if (DefStrValues[i].id == msg->id)
891 if (!strcmp(DefStrValues[i].val, msg->penspec))
893 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
894 return 0;
898 DoMethod(obj, MUIM_Dataspace_Add, (IPTR) msg->penspec,
899 strlen(msg->penspec) + 1, msg->id);
900 return 0;
903 /**************************************************************************
904 MUIM_Configdata_SetFont
905 **************************************************************************/
906 IPTR Configdata__MUIM_SetFont(struct IClass *cl, Object *obj,
907 struct MUIP_Configdata_SetFont *msg)
909 if (!msg->font || !*msg->font)
911 /* D(bug("Configdata_SetFont(%p) : id %08lx, val invalid\n", */
912 /* obj, msg->id)); */
913 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
914 return 0;
917 DoMethod(obj, MUIM_Dataspace_Add, (IPTR) msg->font,
918 strlen(msg->font) + 1, msg->id);
919 return 0;
922 /**************************************************************************
923 MUIM_Configdata_SetString
924 **************************************************************************/
925 IPTR Configdata__MUIM_SetString(struct IClass *cl, Object *obj,
926 struct MUIP_Configdata_SetString *msg)
928 int i;
930 for (i = 0; DefStrValues[i].id; i++)
932 if (DefStrValues[i].id == msg->id)
933 if (!strcmp(DefStrValues[i].val, msg->string))
935 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
936 return 0;
940 DoMethod(obj, MUIM_Dataspace_Add, (IPTR) msg->string,
941 strlen(msg->string) + 1, msg->id);
942 return 0;
945 /**************************************************************************
946 MUIM_Configdata_GetULong
947 **************************************************************************/
948 IPTR Configdata__MUIM_GetULong(struct IClass *cl, Object *obj,
949 struct MUIP_Configdata_GetULong *msg)
951 ULONG *vp;
953 vp = (ULONG *) DoMethod(obj, MUIM_Dataspace_Find, msg->id);
954 if (!vp)
956 int i;
958 for (i = 0; DefULValues[i].id != 0; i++)
960 if (DefULValues[i].id == msg->id)
961 return DefULValues[i].val;
963 return 0;
965 else
967 return AROS_BE2LONG(*vp);
971 /**************************************************************************
972 MUIM_Configdata_SetULong
973 **************************************************************************/
974 IPTR Configdata__MUIM_SetULong(struct IClass *cl, Object *obj,
975 struct MUIP_Configdata_SetULong *msg)
977 ULONG v = msg->val;
978 ULONG *vp = &v;
979 int i;
981 for (i = 0; DefULValues[i].id != 0; i++)
983 if (DefULValues[i].id == msg->id)
984 if (DefULValues[i].val == v)
986 /* D(bug("Configdata_SetULong(%p):" */
987 /* " set to def, id %08lx, val %ld\n", */
988 /* obj, msg->id, v)); */
989 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
990 return 0;
994 v = AROS_LONG2BE(v);
995 /* D(bug("Configdata_SetULong(%p): adding %08lx to %08lx chunk\n", */
996 /* obj, v, msg->id)); */
997 DoMethod(obj, MUIM_Dataspace_Add, (IPTR) vp, 4, msg->id);
998 return 0;
1002 /**************************************************************************
1003 SavePrefsHeader: Write a PRHD chunk
1004 **************************************************************************/
1005 static int SavePrefsHeader(struct IFFHandle *iff)
1007 if (!PushChunk(iff, 0, MAKE_ID('P', 'R', 'H', 'D'), IFFSIZE_UNKNOWN))
1009 struct PrefHeader ph;
1010 ph.ph_Version = 0;
1011 ph.ph_Type = 0;
1012 ph.ph_Flags = 0;
1014 if (WriteChunkBytes(iff, &ph, sizeof(struct PrefHeader)))
1015 if (!PopChunk(iff))
1016 return 1;
1017 PopChunk(iff);
1019 return 0;
1022 /**************************************************************************
1023 MUIM_Configdata_Save
1024 **************************************************************************/
1025 IPTR Configdata__MUIM_Save(struct IClass *cl, Object *obj,
1026 struct MUIP_Configdata_Save *msg)
1028 struct IFFHandle *iff;
1029 if ((iff = AllocIFF()))
1031 if (!(iff->iff_Stream = (IPTR) Open(msg->filename, MODE_NEWFILE)))
1033 /* Try to Create the directory where the file is located */
1034 char *path = StrDup(msg->filename);
1035 if (path)
1037 char *path_end = PathPart(path);
1038 if (path_end != path)
1040 BPTR lock;
1041 *path_end = 0;
1042 if ((lock = CreateDir(path)))
1044 UnLock(lock);
1045 iff->iff_Stream =
1046 (IPTR) Open(msg->filename, MODE_NEWFILE);
1049 FreeVec(path);
1053 if (iff->iff_Stream)
1055 InitIFFasDOS(iff);
1057 if (!OpenIFF(iff, IFFF_WRITE))
1059 if (!PushChunk(iff, MAKE_ID('P', 'R', 'E', 'F'), ID_FORM,
1060 IFFSIZE_UNKNOWN))
1062 Configdata_SetWindowPos(cl, obj, (APTR) msg);
1063 if (SavePrefsHeader(iff))
1065 DoMethod(obj, MUIM_Dataspace_WriteIFF, (IPTR) iff,
1066 0, MAKE_ID('M', 'U', 'I', 'C'));
1068 PopChunk(iff);
1071 CloseIFF(iff);
1073 Close((BPTR) iff->iff_Stream);
1075 FreeIFF(iff);
1077 return 0;
1081 /**************************************************************************
1082 MUIM_Configdata_Load
1083 Get the content of the file into the object.
1084 **************************************************************************/
1085 IPTR Configdata__MUIM_Load(struct IClass *cl, Object *obj,
1086 struct MUIP_Configdata_Load *msg)
1088 struct IFFHandle *iff;
1089 IPTR res = TRUE;
1091 if ((iff = AllocIFF()))
1093 D(bug("loading prefs from %s\n", msg->filename));
1094 if ((iff->iff_Stream = (IPTR) Open(msg->filename, MODE_OLDFILE)))
1096 InitIFFasDOS(iff);
1098 if (!OpenIFF(iff, IFFF_READ))
1100 StopChunk(iff, MAKE_ID('P', 'R', 'E', 'F'), MAKE_ID('M',
1101 'U', 'I', 'C'));
1103 while (!ParseIFF(iff, IFFPARSE_SCAN))
1105 struct ContextNode *cn;
1106 if (!(cn = CurrentChunk(iff)))
1107 continue;
1108 if (cn->cn_ID == MAKE_ID('M', 'U', 'I', 'C'))
1109 DoMethod(obj, MUIM_Dataspace_ReadIFF, (IPTR) iff);
1112 CloseIFF(iff);
1114 else
1116 res = FALSE;
1118 Close((BPTR) iff->iff_Stream);
1120 else
1122 res = FALSE;
1124 FreeIFF(iff);
1126 else
1128 res = FALSE;
1130 return res;
1135 * The class dispatcher
1137 BOOPSI_DISPATCHER(IPTR, Configdata_Dispatcher, cl, obj, msg)
1139 switch (msg->MethodID)
1141 case OM_NEW:
1142 return Configdata__OM_NEW(cl, obj, (struct opSet *)msg);
1143 case OM_DISPOSE:
1144 return Configdata__OM_DISPOSE(cl, obj, (APTR) msg);
1145 case OM_GET:
1146 return Configdata__OM_GET(cl, obj, (APTR) msg);
1147 case MUIM_Configdata_GetString:
1148 return Configdata__MUIM_GetString(cl, obj, (APTR) msg);
1149 case MUIM_Configdata_GetULong:
1150 return Configdata__MUIM_GetULong(cl, obj, (APTR) msg);
1151 case MUIM_Configdata_SetULong:
1152 return Configdata__MUIM_SetULong(cl, obj, (APTR) msg);
1153 case MUIM_Configdata_SetImspec:
1154 return Configdata__MUIM_SetImspec(cl, obj, (APTR) msg);
1155 case MUIM_Configdata_SetFramespec:
1156 return Configdata__MUIM_SetFramespec(cl, obj, (APTR) msg);
1157 case MUIM_Configdata_SetPenspec:
1158 return Configdata__MUIM_SetPenspec(cl, obj, (APTR) msg);
1159 case MUIM_Configdata_SetFont:
1160 return Configdata__MUIM_SetFont(cl, obj, (APTR) msg);
1161 case MUIM_Configdata_SetString:
1162 return Configdata__MUIM_SetString(cl, obj, (APTR) msg);
1163 case MUIM_Configdata_Save:
1164 return Configdata__MUIM_Save(cl, obj, (APTR) msg);
1165 case MUIM_Configdata_Load:
1166 return Configdata__MUIM_Load(cl, obj, (APTR) msg);
1167 case MUIM_Configdata_SetWindowPos:
1168 return Configdata_SetWindowPos(cl, obj, (APTR) msg);
1169 case MUIM_Configdata_GetWindowPos:
1170 return Configdata_GetWindowPos(cl, obj, (APTR) msg);
1174 return DoSuperMethodA(cl, obj, msg);
1176 BOOPSI_DISPATCHER_END
1179 * Class descriptor.
1181 const struct __MUIBuiltinClass _MUI_Configdata_desc =
1183 MUIC_Configdata, /* Class name */
1184 MUIC_Dataspace, /* super class name */
1185 sizeof(struct MUI_ConfigdataData), /* size of class own datas */
1186 (void *) Configdata_Dispatcher /* class dispatcher */