Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / muimaster / classes / configdata.c
blobb6f01d2c3bc2428a3ee8deb49972a4ae94316f0c
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 {
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 {
175 ULONG id;
176 ULONG val;
179 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 {
232 ULONG id;
233 CONST_STRPTR val;
236 /* NULL values not allowed */
237 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 const 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) return (IPTR)NULL;
301 /* D(bug("Configdata_New(%p)\n", obj)); */
303 data = INST_DATA(cl, obj);
305 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
307 switch (tag->ti_Tag)
309 case MUIA_Configdata_Application:
310 data->app = (Object *)tag->ti_Data;
311 break;
312 case MUIA_Configdata_ApplicationBase:
313 data->appbase = (CONST_STRPTR)tag->ti_Data;
314 break;
318 if (data->app && !data->appbase)
320 get(data->app, MUIA_Application_Base, &data->appbase);
323 if (data->appbase)
325 char filename[255];
326 snprintf(filename, 255, "ENV:zune/%s.prefs", data->appbase);
327 res = DoMethod(obj, MUIM_Configdata_Load, (IPTR)filename);
328 if (!res)
330 snprintf(filename, 255, "ENVARC:zune/%s.prefs", data->appbase);
331 res=DoMethod(obj, MUIM_Configdata_Load, (IPTR)filename);
334 if (!res) //load only global prefs if no local app pref is found
336 if (!DoMethod(obj, MUIM_Configdata_Load, (IPTR)"ENV:zune/global.prefs"))
338 DoMethod(obj, MUIM_Configdata_Load, (IPTR)"ENVARC:zune/global.prefs");
341 /*---------- fonts stuff ----------*/
343 data->prefs.fonts[-MUIV_Font_Normal] = GetConfigString(obj, MUICFG_Font_Normal);
344 data->prefs.fonts[-MUIV_Font_List] = GetConfigString(obj, MUICFG_Font_List);
345 data->prefs.fonts[-MUIV_Font_Tiny] = GetConfigString(obj, MUICFG_Font_Tiny);
346 data->prefs.fonts[-MUIV_Font_Fixed] = GetConfigString(obj, MUICFG_Font_Fixed);
347 data->prefs.fonts[-MUIV_Font_Title] = GetConfigString(obj, MUICFG_Font_Title);
348 data->prefs.fonts[-MUIV_Font_Big] = GetConfigString(obj, MUICFG_Font_Big);
349 data->prefs.fonts[-MUIV_Font_Button] = GetConfigString(obj, MUICFG_Font_Button);
350 data->prefs.fonts[-MUIV_Font_Knob] = GetConfigString(obj, MUICFG_Font_Knob);
352 /*---------- images stuff ----------*/
354 init_imspecs(obj, data);
356 /*---------- frame stuff ----------*/
358 init_framespecs(obj, data);
360 /*---------- system stuff ----------*/
362 data->prefs.publicscreen_name = GetConfigString(obj, MUICFG_PublicScreen);
363 data->prefs.publicscreen_pop_to_front = GetConfigULong(obj, MUICFG_PublicScreen_PopToFront);
364 data->prefs.iconification_hotkey = GetConfigString(obj, MUICFG_Iconification_Hotkey);
365 data->prefs.iconification_show_icon = GetConfigULong(obj, MUICFG_Iconification_ShowIcon);
366 data->prefs.iconification_show_menu = GetConfigULong(obj, MUICFG_Iconification_ShowMenu);
367 data->prefs.iconification_on_startup = GetConfigULong(obj, MUICFG_Iconification_OnStartup);
368 data->prefs.interfaces_enable_arexx = GetConfigULong(obj, MUICFG_Interfaces_EnableARexx);
369 data->prefs.bubblehelp_first_delay = GetConfigULong(obj, MUICFG_BubbleHelp_FirstDelay);
370 data->prefs.bubblehelp_next_delay = GetConfigULong(obj, MUICFG_BubbleHelp_NextDelay);
372 /*---------- window stuff ----------*/
374 data->prefs.window_inner_left = GetConfigULong(obj, MUICFG_Window_Spacing_Left);
375 data->prefs.window_inner_right = GetConfigULong(obj, MUICFG_Window_Spacing_Right);
376 data->prefs.window_inner_top = GetConfigULong(obj, MUICFG_Window_Spacing_Top);
377 data->prefs.window_inner_bottom = GetConfigULong(obj, MUICFG_Window_Spacing_Bottom);
378 data->prefs.window_position = GetConfigULong(obj, MUICFG_Window_Positions);
379 data->prefs.window_redraw = GetConfigULong(obj, MUICFG_Window_Redraw);
380 data->prefs.window_refresh = GetConfigULong(obj, MUICFG_Window_Refresh);
381 data->prefs.screenmode = GetConfigULong(obj, MUICFG_Screen_Mode);
382 data->prefs.screenmodeid = GetConfigULong(obj, MUICFG_Screen_Mode_ID);
383 data->prefs.screen_width = GetConfigULong(obj, MUICFG_Screen_Width);
384 data->prefs.screen_height = GetConfigULong(obj, MUICFG_Screen_Height);
385 data->prefs.window_buttons = GetConfigULong(obj, MUICFG_Window_Buttons);
387 /*---------- group stuff ----------*/
389 data->prefs.group_title_position = GetConfigULong(obj, MUICFG_GroupTitle_Position);
390 data->prefs.group_title_color = GetConfigULong(obj, MUICFG_GroupTitle_Color);
391 data->prefs.group_hspacing = GetConfigULong(obj, MUICFG_Group_HSpacing);
392 data->prefs.group_vspacing = GetConfigULong(obj, MUICFG_Group_VSpacing);
394 /*---------- registers ----------*/
396 data->prefs.register_look = REGISTER_LOOK_TRADITIONAL;
397 data->prefs.register_truncate_titles = GetConfigULong(obj, MUICFG_Register_TruncateTitles);
399 /*---------- Buttons ----------*/
401 data->prefs.radiobutton_hspacing = GetConfigULong(obj, MUICFG_Radio_HSpacing);
402 data->prefs.radiobutton_vspacing = GetConfigULong(obj, MUICFG_Radio_VSpacing);
404 /*---------- Cycles ----------*/
406 data->prefs.cycle_menu_position = GetConfigULong(obj, MUICFG_Cycle_MenuCtrl_Position);
407 data->prefs.cycle_menu_min_entries = GetConfigULong(obj, MUICFG_Cycle_MenuCtrl_Level);
408 data->prefs.cycle_menu_speed = GetConfigULong(obj, MUICFG_Cycle_MenuCtrl_Speed);
409 data->prefs.cycle_menu_recessed_entries = GetConfigULong(obj, MUICFG_Cycle_Menu_Recessed);
411 /*---------- Sliders ----------*/
412 /* all taken care of in frames and images */
414 /*---------- Scrollbars ----------*/
416 data->prefs.scrollbar_type = GetConfigULong(obj, MUICFG_Scrollbar_Type);
417 data->prefs.scrollbar_arrangement = GetConfigULong(obj, MUICFG_Scrollbar_Arrangement);
419 /*---------- Lists ----------*/
421 data->prefs.list_linespacing = GetConfigULong(obj, MUICFG_Listview_Font_Leading);
422 data->prefs.list_smoothed = GetConfigULong(obj, MUICFG_Listview_Smoothed);
423 data->prefs.list_smoothval = GetConfigULong(obj, MUICFG_Listview_SmoothVal);
424 data->prefs.list_multi = GetConfigULong(obj, MUICFG_Listview_Multi);
425 data->prefs.list_refresh = GetConfigULong(obj, MUICFG_Listview_Refresh);
427 /*---------- Strings ----------*/
428 data->prefs.string_bg_inactive = GetConfigString(obj, MUICFG_String_Background);
429 data->prefs.string_text_inactive = GetConfigString(obj, MUICFG_String_Text);
430 data->prefs.string_bg_active = GetConfigString(obj, MUICFG_String_ActiveBackground);
431 data->prefs.string_text_active = GetConfigString(obj, MUICFG_String_ActiveText);
432 data->prefs.string_cursor = GetConfigString(obj, MUICFG_String_Cursor);
433 data->prefs.string_bg_marked = GetConfigString(obj, MUICFG_String_MarkedBackground);
434 data->prefs.string_text_marked = GetConfigString(obj, MUICFG_String_MarkedText);
436 /*---------- Navigation ----------*/
438 data->prefs.drag_left_button = GetConfigULong(obj, MUICFG_Drag_LeftButton);
439 data->prefs.drag_left_modifier.readable_hotkey = GetConfigString(obj, MUICFG_Drag_LMBModifier);
440 data->prefs.drag_middle_button = GetConfigULong(obj, MUICFG_Drag_MiddleButton);
441 data->prefs.drag_middle_modifier.readable_hotkey = GetConfigString(obj, MUICFG_Drag_MMBModifier);
442 data->prefs.drag_autostart = GetConfigULong(obj, MUICFG_Drag_Autostart);
443 data->prefs.drag_autostart_length = GetConfigULong(obj, MUICFG_Drag_Autostart_Length);
444 data->prefs.drag_look = GetConfigULong(obj, MUICFG_Dragndrop_Look);
445 data->prefs.balancing_look = GetConfigULong(obj, MUICFG_Balance_Look);
447 if (data->prefs.drag_left_modifier.readable_hotkey != NULL)
448 data->prefs.drag_left_modifier.ix_well =
449 !ParseIX(data->prefs.drag_left_modifier.readable_hotkey,
450 &data->prefs.drag_left_modifier.ix);
451 else
452 data->prefs.drag_left_modifier.ix_well = 0;
454 if (data->prefs.drag_middle_modifier.readable_hotkey != NULL)
455 data->prefs.drag_middle_modifier.ix_well =
456 !ParseIX(data->prefs.drag_middle_modifier.readable_hotkey,
457 &data->prefs.drag_middle_modifier.ix);
458 else
459 data->prefs.drag_middle_modifier.ix_well = 0;
461 data->prefs.active_object_color = GetConfigString(obj, MUICFG_ActiveObject_Color);
462 /*---------- mui keys ----------*/
464 data->prefs.muikeys[MUIKEY_PRESS].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_Press);
465 data->prefs.muikeys[MUIKEY_TOGGLE].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_Toggle);
466 data->prefs.muikeys[MUIKEY_UP].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_Up);
467 data->prefs.muikeys[MUIKEY_DOWN].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_Down);
468 data->prefs.muikeys[MUIKEY_PAGEUP].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_PageUp);
469 data->prefs.muikeys[MUIKEY_PAGEDOWN].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_PageDown);
470 data->prefs.muikeys[MUIKEY_TOP].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_Top);
471 data->prefs.muikeys[MUIKEY_BOTTOM].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_Bottom);
472 data->prefs.muikeys[MUIKEY_LEFT].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_Left);
473 data->prefs.muikeys[MUIKEY_RIGHT].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_Right);
474 data->prefs.muikeys[MUIKEY_WORDLEFT].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_WordLeft);
475 data->prefs.muikeys[MUIKEY_WORDRIGHT].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_WordRight);
476 data->prefs.muikeys[MUIKEY_LINESTART].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_LineStart);
477 data->prefs.muikeys[MUIKEY_LINEEND].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_LineEnd);
478 data->prefs.muikeys[MUIKEY_GADGET_NEXT].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_NextGadget);
479 data->prefs.muikeys[MUIKEY_GADGET_PREV].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_PrevGadget);
480 data->prefs.muikeys[MUIKEY_GADGET_OFF].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_GadgetOff);
481 data->prefs.muikeys[MUIKEY_WINDOW_CLOSE].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_CloseWindow);
482 data->prefs.muikeys[MUIKEY_WINDOW_NEXT].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_NextWindow);
483 data->prefs.muikeys[MUIKEY_WINDOW_PREV].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_PrevWindow);
484 data->prefs.muikeys[MUIKEY_HELP].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_Help);
485 data->prefs.muikeys[MUIKEY_POPUP].readable_hotkey = GetConfigString(obj, MUICFG_Keyboard_Popup);
487 for (i = 0; i < MUIKEY_COUNT; i++)
489 if (data->prefs.muikeys[i].readable_hotkey)
490 data->prefs.muikeys[i].ix_well = !ParseIX(data->prefs.muikeys[i].readable_hotkey, &data->prefs.muikeys[i].ix);
491 else data->prefs.muikeys[i].ix_well = 0;
494 /*---------- CustomFrames ----------*/
495 data->prefs.customframe_config_1 = GetConfigString(obj, MUICFG_CustomFrame_1);
496 data->prefs.customframe_config_2 = GetConfigString(obj, MUICFG_CustomFrame_2);
497 data->prefs.customframe_config_3 = GetConfigString(obj, MUICFG_CustomFrame_3);
498 data->prefs.customframe_config_4 = GetConfigString(obj, MUICFG_CustomFrame_4);
499 data->prefs.customframe_config_5 = GetConfigString(obj, MUICFG_CustomFrame_5);
500 data->prefs.customframe_config_6 = GetConfigString(obj, MUICFG_CustomFrame_6);
501 data->prefs.customframe_config_7 = GetConfigString(obj, MUICFG_CustomFrame_7);
502 data->prefs.customframe_config_8 = GetConfigString(obj, MUICFG_CustomFrame_8);
503 data->prefs.customframe_config_9 = GetConfigString(obj, MUICFG_CustomFrame_9);
504 data->prefs.customframe_config_10 = GetConfigString(obj, MUICFG_CustomFrame_10);
505 data->prefs.customframe_config_11 = GetConfigString(obj, MUICFG_CustomFrame_11);
506 data->prefs.customframe_config_12 = GetConfigString(obj, MUICFG_CustomFrame_12);
507 data->prefs.customframe_config_13 = GetConfigString(obj, MUICFG_CustomFrame_13);
508 data->prefs.customframe_config_14 = GetConfigString(obj, MUICFG_CustomFrame_14);
509 data->prefs.customframe_config_15 = GetConfigString(obj, MUICFG_CustomFrame_15);
510 data->prefs.customframe_config_16 = GetConfigString(obj, MUICFG_CustomFrame_16);
512 /*---------- Special ----------*/
513 /* all taken care of in frames and images */
515 return (IPTR)obj;
518 /**************************************************************************
519 OM_DISPOSE
520 **************************************************************************/
521 IPTR Configdata__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
523 /* struct MUI_ConfigdataData *data = INST_DATA(cl, obj); */
524 /* int i; */
526 return DoSuperMethodA(cl,obj,msg);
529 /**************************************************************************
530 OM_GET
531 **************************************************************************/
532 IPTR Configdata__OM_GET(struct IClass *cl, Object * obj, struct opGet *msg)
534 struct MUI_ConfigdataData *data = INST_DATA(cl, obj);
535 IPTR *store = msg->opg_Storage;
536 ULONG tag = msg->opg_AttrID;
538 switch (tag)
540 case MUIA_Configdata_ZunePrefs:
541 *store = (IPTR)&data->prefs;
542 DoMethod(obj, MUIM_Configdata_GetWindowPos,0);
543 return 1;
546 return DoSuperMethodA(cl, obj, (Msg)msg);
549 static IPTR Configdata_GetWindowPos(struct IClass *cl, Object * obj,
550 struct MUIP_Configdata_GetString *msg)
552 struct MUI_ConfigdataData *data;
553 IPTR s;
554 data = INST_DATA(cl, obj);
555 //kprintf ("getwindowpos\n");
556 s = (IPTR)DoMethod(obj, MUIM_Dataspace_Find,MUICFG_WindowPos);
557 if (s && data->app) set(data->app,MUIA_Application_CopyWinPosToApp,s);
558 return s;
561 static IPTR Configdata_SetWindowPos(struct IClass *cl, Object * obj,
562 struct MUIP_Configdata_GetString *msg)
564 struct MUI_ConfigdataData *data;
565 //kprintf ("setwindowpos\n");
566 data = INST_DATA(cl, obj);
567 IPTR addr = 0;
568 LONG size = 0;
570 if (data->app)
572 get(data->app,MUIA_Application_GetWinPosAddr, &addr);
573 get(data->app,MUIA_Application_GetWinPosSize, &size);
574 DoMethod(obj, MUIM_Dataspace_Add,addr,size,MUICFG_WindowPos);
576 return 0;
581 /**************************************************************************
582 MUIM_Configdata_GetString
583 Check if string is found in dataspace, then if not found, search each
584 builtin array
585 **************************************************************************/
586 IPTR Configdata__MUIM_GetString(struct IClass *cl, Object * obj,
587 struct MUIP_Configdata_GetString *msg)
589 CONST_STRPTR s;
591 s = (CONST_STRPTR)DoMethod(obj, MUIM_Dataspace_Find, msg->id);
592 if (!s)
594 int i;
596 for (i = 0; DefStrValues[i].id; i++)
598 if (DefStrValues[i].id == msg->id)
599 return (IPTR)DefStrValues[i].val;
601 for (i = 0; DefImspecValues[i].defspec; i++)
603 if (DefImspecValues[i].cfgid == msg->id)
604 return (IPTR)DefImspecValues[i].defspec;
606 for (i = 0; DefFramespecValues[i].defspec; i++)
608 if (DefFramespecValues[i].cfgid == msg->id)
609 return (IPTR)DefFramespecValues[i].defspec;
611 return (IPTR)0;
613 else
615 return (IPTR)s;
619 /**************************************************************************
620 MUIM_Configdata_SetImspec
621 search in builtin array first, to not not have in dataspace the default
622 value (would be redundant)
623 **************************************************************************/
624 IPTR Configdata__MUIM_SetImspec(struct IClass *cl, Object * obj,
625 struct MUIP_Configdata_SetImspec *msg)
627 int i;
629 if (!msg->imspec || !*msg->imspec || *msg->imspec == '6')
631 /* D(bug("Configdata_SetImspec(%p) : id %08lx, val invalid\n", */
632 /* obj, msg->id)); */
633 return 0;
636 for (i = 0; DefImspecValues[i].defspec; i++)
638 if (DefImspecValues[i].cfgid == msg->id)
639 if (!strcmp(DefImspecValues[i].defspec, msg->imspec))
641 /* D(bug("Configdata_SetImspec(%p) : set to def, id %08lx, val %s\n", */
642 /* obj, msg->id, msg->imspec)); */
643 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
644 return 0;
648 for (i = 0; DefStrValues[i].id; i++)
650 if (DefStrValues[i].id == msg->id)
651 if (!strcmp(DefStrValues[i].val, msg->imspec))
653 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
654 return 0;
658 DoMethod(obj, MUIM_Dataspace_Add, (IPTR)msg->imspec, strlen(msg->imspec) + 1, msg->id);
659 return 0;
662 /**************************************************************************
663 MUIM_Configdata_SetFramespec
664 **************************************************************************/
665 IPTR Configdata__MUIM_SetFramespec(struct IClass *cl, Object * obj,
666 struct MUIP_Configdata_SetFramespec *msg)
668 int i;
670 if (!msg->framespec || !*msg->framespec)
672 /* D(bug("Configdata_SetFramespec(%p) : id %08lx, val invalid\n", */
673 /* obj, msg->id)); */
674 return 0;
677 for (i = 0; DefFramespecValues[i].defspec; i++)
679 if (DefFramespecValues[i].cfgid == msg->id)
680 if (!strcmp(DefFramespecValues[i].defspec, msg->framespec))
682 /* D(bug("Configdata_SetFramespec(%p) : set to def, id %08lx, val %s\n", */
683 /* obj, msg->id, msg->framespec)); */
684 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
685 return 0;
689 DoMethod(obj, MUIM_Dataspace_Add, (IPTR)msg->framespec,
690 strlen(msg->framespec) + 1, msg->id);
691 return 0;
694 /**************************************************************************
695 MUIM_Configdata_SetPenspec
696 **************************************************************************/
697 IPTR Configdata__MUIM_SetPenspec(struct IClass *cl, Object * obj,
698 struct MUIP_Configdata_SetPenspec *msg)
700 int i;
702 if (!msg->penspec || !*msg->penspec)
703 return 0;
705 for (i = 0; DefStrValues[i].id; i++)
707 if (DefStrValues[i].id == msg->id)
708 if (!strcmp(DefStrValues[i].val, msg->penspec))
710 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
711 return 0;
715 DoMethod(obj, MUIM_Dataspace_Add, (IPTR)msg->penspec,
716 strlen(msg->penspec) + 1, msg->id);
717 return 0;
720 /**************************************************************************
721 MUIM_Configdata_SetFont
722 **************************************************************************/
723 IPTR Configdata__MUIM_SetFont(struct IClass *cl, Object * obj,
724 struct MUIP_Configdata_SetFont *msg)
726 if (!msg->font || !*msg->font)
728 /* D(bug("Configdata_SetFont(%p) : id %08lx, val invalid\n", */
729 /* obj, msg->id)); */
730 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
731 return 0;
734 DoMethod(obj, MUIM_Dataspace_Add, (IPTR)msg->font, strlen(msg->font) + 1, msg->id);
735 return 0;
738 /**************************************************************************
739 MUIM_Configdata_SetString
740 **************************************************************************/
741 IPTR Configdata__MUIM_SetString(struct IClass *cl, Object * obj,
742 struct MUIP_Configdata_SetString *msg)
744 int i;
746 for (i = 0; DefStrValues[i].id; i++)
748 if (DefStrValues[i].id == msg->id)
749 if (!strcmp(DefStrValues[i].val, msg->string))
751 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
752 return 0;
756 DoMethod(obj, MUIM_Dataspace_Add, (IPTR)msg->string, strlen(msg->string) + 1, msg->id);
757 return 0;
760 /**************************************************************************
761 MUIM_Configdata_GetULong
762 **************************************************************************/
763 IPTR Configdata__MUIM_GetULong(struct IClass *cl, Object * obj,
764 struct MUIP_Configdata_GetULong *msg)
766 ULONG *vp;
768 vp = (ULONG *)DoMethod(obj, MUIM_Dataspace_Find, msg->id);
769 if (!vp)
771 int i;
773 for (i = 0; DefULValues[i].id != 0; i++)
775 if (DefULValues[i].id == msg->id)
776 return DefULValues[i].val;
778 return 0;
780 else
782 return AROS_BE2LONG(*vp);
786 /**************************************************************************
787 MUIM_Configdata_SetULong
788 **************************************************************************/
789 IPTR Configdata__MUIM_SetULong(struct IClass *cl, Object * obj,
790 struct MUIP_Configdata_SetULong *msg)
792 ULONG v = msg->val;
793 ULONG *vp = &v;
794 int i;
796 for (i = 0; DefULValues[i].id != 0; i++)
798 if (DefULValues[i].id == msg->id)
799 if (DefULValues[i].val == v)
801 /* D(bug("Configdata_SetULong(%p) : set to def, id %08lx, val %ld\n", */
802 /* obj, msg->id, v)); */
803 DoMethod(obj, MUIM_Dataspace_Remove, msg->id);
804 return 0;
808 v = AROS_LONG2BE(v);
809 /* D(bug("Configdata_SetULong(%p): adding %08lx to %08lx chunk\n", obj, v, msg->id)); */
810 DoMethod(obj, MUIM_Dataspace_Add, (IPTR)vp, 4, msg->id);
811 return 0;
815 /**************************************************************************
816 SavePrefsHeader: Write a PRHD chunk
817 **************************************************************************/
818 static int SavePrefsHeader(struct IFFHandle *iff)
820 if (!PushChunk( iff, 0, MAKE_ID('P','R','H','D'), IFFSIZE_UNKNOWN))
822 struct PrefHeader ph;
823 ph.ph_Version = 0;
824 ph.ph_Type = 0;
825 ph.ph_Flags = 0;
827 if (WriteChunkBytes(iff, &ph, sizeof(struct PrefHeader)))
828 if (!PopChunk(iff)) return 1;
829 PopChunk(iff);
831 return 0;
834 /**************************************************************************
835 MUIM_Configdata_Save
836 **************************************************************************/
837 IPTR Configdata__MUIM_Save(struct IClass *cl, Object * obj,
838 struct MUIP_Configdata_Save *msg)
840 struct IFFHandle *iff;
841 if ((iff = AllocIFF()))
843 if (!(iff->iff_Stream = (IPTR)Open(msg->filename,MODE_NEWFILE)))
845 /* Try to Create the directory where the file is located */
846 char *path = StrDup(msg->filename);
847 if (path)
849 char *path_end = PathPart(path);
850 if (path_end != path)
852 BPTR lock;
853 *path_end = 0;
854 if ((lock = CreateDir(path)))
856 UnLock(lock);
857 iff->iff_Stream = (IPTR)Open(msg->filename,MODE_NEWFILE);
860 FreeVec(path);
864 if (iff->iff_Stream)
866 InitIFFasDOS(iff);
868 if (!OpenIFF(iff, IFFF_WRITE))
870 if (!PushChunk(iff, MAKE_ID('P','R','E','F'), ID_FORM, IFFSIZE_UNKNOWN))
872 Configdata_SetWindowPos(cl, obj, (APTR)msg);
873 if (SavePrefsHeader(iff))
875 DoMethod(obj,MUIM_Dataspace_WriteIFF, (IPTR)iff, 0, MAKE_ID('M','U','I','C'));
877 PopChunk(iff);
880 CloseIFF(iff);
882 Close((BPTR)iff->iff_Stream);
884 FreeIFF(iff);
886 return 0;
890 /**************************************************************************
891 MUIM_Configdata_Load
892 Get the content of the file into the object.
893 **************************************************************************/
894 IPTR Configdata__MUIM_Load(struct IClass *cl, Object * obj,
895 struct MUIP_Configdata_Load *msg)
897 struct IFFHandle *iff;
898 IPTR res = TRUE;
900 if ((iff = AllocIFF()))
902 D(bug("loading prefs from %s\n", msg->filename));
903 if ((iff->iff_Stream = (IPTR)Open(msg->filename,MODE_OLDFILE)))
905 InitIFFasDOS(iff);
907 if (!OpenIFF(iff, IFFF_READ))
909 StopChunk( iff, MAKE_ID('P','R','E','F'), MAKE_ID('M','U','I','C'));
911 while (!ParseIFF(iff, IFFPARSE_SCAN))
913 struct ContextNode *cn;
914 if (!(cn = CurrentChunk(iff))) continue;
915 if (cn->cn_ID == MAKE_ID('M','U','I','C'))
916 DoMethod(obj, MUIM_Dataspace_ReadIFF, (IPTR)iff);
919 CloseIFF(iff);
921 else
923 res = FALSE;
925 Close((BPTR)iff->iff_Stream);
927 else
929 res = FALSE;
931 FreeIFF(iff);
933 else
935 res = FALSE;
937 return res;
942 * The class dispatcher
944 BOOPSI_DISPATCHER(IPTR, Configdata_Dispatcher, cl, obj, msg)
946 switch (msg->MethodID)
948 case OM_NEW: return Configdata__OM_NEW(cl, obj, (struct opSet *)msg);
949 case OM_DISPOSE: return Configdata__OM_DISPOSE(cl, obj, (APTR)msg);
950 case OM_GET: return Configdata__OM_GET(cl, obj, (APTR)msg);
951 case MUIM_Configdata_GetString: return Configdata__MUIM_GetString(cl, obj, (APTR)msg);
952 case MUIM_Configdata_GetULong: return Configdata__MUIM_GetULong(cl, obj, (APTR)msg);
953 case MUIM_Configdata_SetULong: return Configdata__MUIM_SetULong(cl, obj, (APTR)msg);
954 case MUIM_Configdata_SetImspec: return Configdata__MUIM_SetImspec(cl, obj, (APTR)msg);
955 case MUIM_Configdata_SetFramespec: return Configdata__MUIM_SetFramespec(cl, obj, (APTR)msg);
956 case MUIM_Configdata_SetPenspec: return Configdata__MUIM_SetPenspec(cl, obj, (APTR)msg);
957 case MUIM_Configdata_SetFont: return Configdata__MUIM_SetFont(cl, obj, (APTR)msg);
958 case MUIM_Configdata_SetString: return Configdata__MUIM_SetString(cl, obj, (APTR)msg);
959 case MUIM_Configdata_Save: return Configdata__MUIM_Save(cl, obj, (APTR)msg);
960 case MUIM_Configdata_Load: return Configdata__MUIM_Load(cl, obj, (APTR)msg);
961 case MUIM_Configdata_SetWindowPos: return Configdata_SetWindowPos(cl, obj, (APTR)msg);
962 case MUIM_Configdata_GetWindowPos: return Configdata_GetWindowPos(cl, obj, (APTR)msg);
966 return DoSuperMethodA(cl, obj, msg);
968 BOOPSI_DISPATCHER_END
971 * Class descriptor.
973 const struct __MUIBuiltinClass _MUI_Configdata_desc = {
974 MUIC_Configdata, /* Class name */
975 MUIC_Dataspace, /* super class name */
976 sizeof(struct MUI_ConfigdataData), /* size of class own datas */
977 (void*)Configdata_Dispatcher /* class dispatcher */