grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / prefs / reqtools / reqtoolseditor.c
blobb748e09eb2a470b6f7978fcb5b80cd35bbbc5354
1 /*
2 Copyright © 2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #define DEBUG 0
10 #include <aros/debug.h>
12 #include <devices/rawkeycodes.h>
13 #include <mui/HotkeyString_mcc.h>
14 #include <zune/prefseditor.h>
15 #include <zune/customclasses.h>
17 #include <proto/alib.h>
18 #include <proto/commodities.h>
19 #include <proto/intuition.h>
20 #include <proto/muimaster.h>
21 #include <proto/alib.h>
23 #include <string.h>
24 #include <stdio.h>
26 #include "reqtoolseditor.h"
27 #include "reqtoolsstringify.h"
28 #include "prefs.h"
29 #include "locale.h"
31 /*********************************************************************************************/
33 struct ReqToolsEditor_DATA
35 Object *poptofrontobj;
36 Object *usesysfontobj;
37 Object *usefunckeysobj;
38 Object *colorwheelstyleobj;
40 Object *immediatesortobj;
41 Object *drawersfirstobj;
42 Object *drawersmixedobj;
43 Object *diskactivityobj;
44 Object *mmbobj;
46 Object *defaultsforobj;
47 Object *sizepercentobj;
48 Object *minvisobj;
49 Object *maxvisobj;
50 Object *positionobj;
51 Object *offsetxobj;
52 Object *offsetyobj;
55 /*********************************************************************************************/
57 #define SETUP_INST_DATA struct ReqToolsEditor_DATA *data = INST_DATA(CLASS, self)
59 /*********************************************************************************************/
61 static struct Hook selectdefaultshook, updatedefaultshook;
62 static CONST_STRPTR colorwheelstyle_labels[4], defaultsfor_labels[7], position_labels[6];
64 /*********************************************************************************************/
66 static void SelectDefaultsHook(struct Hook *hook, Object *self, struct ReqToolsEditor_DATA **data)
68 struct ReqToolsPrefs *prefs = &reqtoolsprefs;
69 IPTR active = 0;
71 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
73 GET(self, MUIA_Cycle_Active, &active);
75 NNSET((*data)->positionobj, MUIA_Cycle_Active, prefs->ReqDefaults[active].ReqPos);
76 NNSET((*data)->sizepercentobj, MUIA_Numeric_Value, prefs->ReqDefaults[active].Size);
77 NNSET((*data)->offsetxobj, MUIA_String_Integer, prefs->ReqDefaults[active].LeftOffset);
78 NNSET((*data)->offsetyobj, MUIA_String_Integer, prefs->ReqDefaults[active].TopOffset);
79 NNSET((*data)->minvisobj, MUIA_String_Integer, prefs->ReqDefaults[active].MinEntries);
80 NNSET((*data)->maxvisobj, MUIA_String_Integer, prefs->ReqDefaults[active].MaxEntries);
83 static void UpdateDefaultsHook(struct Hook *hook, Object *self, struct ReqToolsEditor_DATA **data)
85 struct ReqToolsPrefs *prefs = &reqtoolsprefs;
86 IPTR active = 0, tmpval;
87 BOOL changed = FALSE;
89 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
91 GET((*data)->defaultsforobj, MUIA_Cycle_Active, &active);
93 tmpval = prefs->ReqDefaults[active].ReqPos;
94 if ((prefs->ReqDefaults[active].ReqPos = XGET((*data)->positionobj, MUIA_Cycle_Active)) != tmpval)
95 changed = TRUE;
96 tmpval = prefs->ReqDefaults[active].Size;
97 if ((prefs->ReqDefaults[active].Size = XGET((*data)->sizepercentobj, MUIA_Numeric_Value)) != tmpval)
98 changed = TRUE;
99 tmpval = prefs->ReqDefaults[active].LeftOffset;
100 if ((prefs->ReqDefaults[active].LeftOffset = XGET((*data)->offsetxobj, MUIA_String_Integer)) != tmpval)
101 changed = TRUE;
102 tmpval = prefs->ReqDefaults[active].TopOffset;
103 if ((prefs->ReqDefaults[active].TopOffset = XGET((*data)->offsetyobj, MUIA_String_Integer)) != tmpval)
104 changed = TRUE;
105 tmpval = prefs->ReqDefaults[active].MinEntries;
106 if ((prefs->ReqDefaults[active].MinEntries = XGET((*data)->minvisobj, MUIA_String_Integer)) != tmpval)
107 changed = TRUE;
108 tmpval = prefs->ReqDefaults[active].MaxEntries;
109 if ((prefs->ReqDefaults[active].MaxEntries = XGET((*data)->maxvisobj, MUIA_String_Integer)) != tmpval)
110 changed = TRUE;
112 if (changed)
114 SET( _parent(self), MUIA_PrefsEditor_Changed, TRUE);
118 /*********************************************************************************************/
120 BOOL Gadgets2ReqToolsPrefs(struct ReqToolsEditor_DATA *data)
122 struct ReqToolsPrefs *prefs = &reqtoolsprefs;
123 IPTR active = 0;
125 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
127 // Clear options we are about to set..
128 prefs->Flags &= ~(RTPRF_NOSCRTOFRONT | RTPRF_DEFAULTFONT | RTPRF_FKEYS | RTPRB_DOWHEEL | RTPRB_FANCYWHEEL | RTPRF_IMMSORT | RTPRF_DIRSFIRST | RTPRF_DIRSMIXED | RTPRF_NOLED | RTPRF_MMBPARENT);
130 GET(data->poptofrontobj, MUIA_Selected, &active);
131 if (active == 0)
132 prefs->Flags |= RTPRF_NOSCRTOFRONT;
133 GET(data->usesysfontobj, MUIA_Selected, &active);
134 if (active != 0)
135 prefs->Flags |= RTPRF_DEFAULTFONT;
136 GET(data->usefunckeysobj, MUIA_Selected, &active);
137 if (active != 0)
138 prefs->Flags |= RTPRF_FKEYS;
139 GET(data->colorwheelstyleobj, MUIA_Cycle_Active, &active);
140 if (active > 0)
141 prefs->Flags |= RTPRB_DOWHEEL;
142 if (active > 1)
143 prefs->Flags |= RTPRB_FANCYWHEEL;
144 GET(data->immediatesortobj, MUIA_Selected, &active);
145 if (active != 0)
146 prefs->Flags |= RTPRF_IMMSORT;
147 GET(data->drawersfirstobj, MUIA_Selected, &active);
148 if (active != 0)
149 prefs->Flags |= RTPRF_DIRSFIRST;
150 GET(data->drawersmixedobj, MUIA_Selected, &active);
151 if (active != 0)
152 prefs->Flags |= RTPRF_DIRSMIXED;
153 GET(data->diskactivityobj, MUIA_Selected, &active);
154 if (active == 0)
155 prefs->Flags |= RTPRF_NOLED;
156 GET(data->mmbobj, MUIA_Selected, &active);
157 if (active != 0)
158 prefs->Flags |= RTPRF_MMBPARENT;
160 return TRUE;
163 /*********************************************************************************************/
165 BOOL ReqToolsPrefs2Gadgets(struct ReqToolsEditor_DATA *data)
167 struct ReqToolsPrefs *prefs = &reqtoolsprefs;
168 IPTR active = 0;
170 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
172 NNSET(data->poptofrontobj, MUIA_Selected, (prefs->Flags & RTPRF_NOSCRTOFRONT) ? 0 : 1);
173 NNSET(data->usesysfontobj, MUIA_Selected, (prefs->Flags & RTPRF_DEFAULTFONT) ? 1 : 0);
174 NNSET(data->usefunckeysobj, MUIA_Selected, (prefs->Flags & RTPRF_FKEYS) ? 1 : 0);
175 if ((prefs->Flags & (RTPRB_DOWHEEL | RTPRB_FANCYWHEEL)) == 0)
176 active = 0;
177 else if ((prefs->Flags & (RTPRB_DOWHEEL | RTPRB_FANCYWHEEL)) == RTPRB_DOWHEEL)
178 active = 1;
179 else
180 active = 2;
181 NNSET(data->colorwheelstyleobj, MUIA_Cycle_Active, active);
182 NNSET(data->immediatesortobj, MUIA_Selected, (prefs->Flags & RTPRF_IMMSORT) ? 1 : 0);
183 NNSET(data->drawersfirstobj, MUIA_Selected, (prefs->Flags & RTPRF_DIRSFIRST) ? 1 : 0);
184 NNSET(data->drawersmixedobj, MUIA_Selected, (prefs->Flags & RTPRF_DIRSMIXED) ? 1 : 0);
185 NNSET(data->diskactivityobj, MUIA_Selected, (prefs->Flags & RTPRF_NOLED) ? 0 : 1);
186 NNSET(data->mmbobj, MUIA_Selected, (prefs->Flags & RTPRF_MMBPARENT) ? 1 : 0);
188 SelectDefaultsHook(NULL, data->defaultsforobj, &data);
190 return TRUE;
193 /*********************************************************************************************/
195 Object *ReqToolsEditor__Checkmark()
197 Object *obj = MUI_MakeObject(MUIO_Checkmark, (IPTR)NULL);
199 if (obj)
201 SET(obj, MUIA_CycleChain, 1);
203 return obj;
206 Object *ReqToolsEditor__Cycle(const UBYTE **labels)
208 Object *obj = MUI_MakeObject(MUIO_Cycle, (IPTR)NULL, labels);
210 if (obj)
212 SET(obj, MUIA_CycleChain, 1);
214 return obj;
217 /*********************************************************************************************/
219 IPTR ReqToolsEditor__OM_NEW
221 Class *CLASS, Object *self, struct opSet *message
224 struct ReqToolsEditor_DATA *data = NULL;
226 struct TagItem ReqToolsStringifyTags[] = {
227 { MUIA_Numeric_Value, 0 },
228 { MUIA_Numeric_Min, 0 },
229 { MUIA_Numeric_Max, 100 },
230 { TAG_DONE, (IPTR)NULL }
234 Object *poptofrontobj;
235 Object *usesysfontobj;
236 Object *usefunckeysobj;
237 Object *colorwheelstyleobj;
239 Object *immediatesortobj;
240 Object *drawersfirstobj;
241 Object *drawersmixedobj;
242 Object *diskactivityobj;
243 Object *mmbobj;
245 Object *defaultsforobj;
246 Object *positionobj;
247 Object *sizepercentobj;
248 Object *offsetxobj;
249 Object *offsetyobj;
250 Object *minvisobj;
251 Object *maxvisobj;
253 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
255 selectdefaultshook.h_Entry = HookEntry;
256 selectdefaultshook.h_SubEntry = (HOOKFUNC)SelectDefaultsHook;
257 updatedefaultshook.h_Entry = HookEntry;
258 updatedefaultshook.h_SubEntry = (HOOKFUNC)UpdateDefaultsHook;
260 colorwheelstyle_labels[0] = _(MSG_WHEEL_NONE);
261 colorwheelstyle_labels[1] = _(MSG_WHEEL_SIMPLE);
262 colorwheelstyle_labels[2] = _(MSG_WHEEL_FANCY);
264 defaultsfor_labels[0] = _(MSG_FILEREQ);
265 defaultsfor_labels[1] = _(MSG_FONTREQ);
266 defaultsfor_labels[2] = _(MSG_PALETTEREQ);
267 defaultsfor_labels[3] = _(MSG_SCRMODEREQ);
268 defaultsfor_labels[4] = _(MSG_VOLUMEREQ);
269 defaultsfor_labels[5] = _(MSG_OTHERREQ);
271 position_labels[0] = _(MSG_POINTER);
272 position_labels[1] = _(MSG_CENTERWIN);
273 position_labels[2] = _(MSG_CENTERSCR);
274 position_labels[3] = _(MSG_TOPLEFTWIN);
275 position_labels[4] = _(MSG_TOPLEFTSCR);
277 sizepercentobj = (Object *)NewObjectA(ReqToolsStringify_CLASS->mcc_Class, NULL, ReqToolsStringifyTags);
279 self = (Object *) DoSuperNewTags
281 CLASS, self, NULL,
283 MUIA_PrefsEditor_Name, __(MSG_WINDOW_TITLE),
284 MUIA_PrefsEditor_Path, (IPTR) "ReqTools.prefs",
285 MUIA_PrefsEditor_IconTool, (IPTR) "SYS:Prefs/ReqTools",
287 Child, HGroup,
288 Child, (IPTR)VGroup,
289 MUIA_Weight, 0,
290 Child, VGroup,
291 GroupFrameT(__(MSG_GENERAL)),
292 Child, HGroup,
293 Child, HVSpace,
294 Child, ColGroup(2),
295 Child, Label1(__(MSG_POPSCREEN)),
296 Child, (poptofrontobj = ReqToolsEditor__Checkmark()),
297 Child, Label1(__(MSG_DEFAULTFONT)),
298 Child, (usesysfontobj = ReqToolsEditor__Checkmark()),
299 Child, Label1(__(MSG_FKEYS)),
300 Child, (usefunckeysobj = ReqToolsEditor__Checkmark()),
301 End,
302 End,
303 Child, (colorwheelstyleobj = ReqToolsEditor__Cycle(colorwheelstyle_labels)),
304 Child, HVSpace,
305 End,
306 Child, VGroup,
307 GroupFrameT(__(MSG_FILEREQUESTER)),
308 Child, HGroup,
309 Child, HVSpace,
310 Child, ColGroup(2),
311 Child, Label1(__(MSG_IMMEDIATESORT)),
312 Child, (immediatesortobj = ReqToolsEditor__Checkmark()),
313 Child, Label1(__(MSG_DRAWERSFIRST)),
314 Child, (drawersfirstobj = ReqToolsEditor__Checkmark()),
315 Child, Label1(__(MSG_DRAWERSMIXED)),
316 Child, (drawersmixedobj = ReqToolsEditor__Checkmark()),
317 Child, Label1(__(MSG_LED)),
318 Child, (diskactivityobj = ReqToolsEditor__Checkmark()),
319 Child, Label1(__(MSG_MMB_PARENT)),
320 Child, (mmbobj = ReqToolsEditor__Checkmark()),
321 End,
322 End,
323 Child, HVSpace,
324 End,
325 End,
326 Child, VGroup,
327 MUIA_Frame, MUIV_Frame_Group,
328 Child, ColGroup(2),
329 Child, Label1(__(MSG_REQUESTER)),
330 Child, (defaultsforobj = ReqToolsEditor__Cycle(defaultsfor_labels)),
331 Child, HVSpace,
332 Child, RectangleObject,
333 MUIA_Background, MUII_FILL,
334 MUIA_FixHeight, 2,
335 End,
336 Child, Label1(__(MSG_POSITION)),
337 Child, (positionobj = ReqToolsEditor__Cycle(position_labels)),
338 Child, Label1(__(MSG_SIZE)),
339 Child, sizepercentobj,
340 Child, VGroup,
341 Child, TextObject,
342 StringFrame,
343 MUIA_FramePhantomHoriz, TRUE,
344 MUIA_Text_PreParse, "\33r",
345 MUIA_Text_Contents, __(MSG_OFFSET),
346 End,
347 Child, TextObject,
348 StringFrame,
349 MUIA_FramePhantomHoriz, TRUE,
350 MUIA_Text_Contents, " ",
351 End,
352 Child, TextObject,
353 StringFrame,
354 MUIA_FramePhantomHoriz, TRUE,
355 MUIA_Text_PreParse, "\33r",
356 MUIA_Text_Contents, __(MSG_NR_OF_ENTRIES),
357 End,
358 Child, TextObject,
359 StringFrame,
360 MUIA_FramePhantomHoriz, TRUE,
361 MUIA_Text_Contents, " ",
362 End,
363 End,
364 Child, VGroup,
365 Child, ColGroup(3),
366 Child, Label1("X"),
367 Child, (IPTR)(offsetxobj = StringObject,
368 StringFrame,
369 MUIA_Weight, 0,
370 MUIA_CycleChain, TRUE,
371 MUIA_String_Accept, (IPTR)"0123456789",
372 MUIA_FixWidthTxt, (IPTR)"55555",
373 End),
374 Child, HSpace(100),
375 Child, Label1("Y"),
376 Child, (IPTR)(offsetyobj = StringObject,
377 StringFrame,
378 MUIA_Weight, 0,
379 MUIA_CycleChain, TRUE,
380 MUIA_String_Accept, (IPTR)"0123456789",
381 MUIA_FixWidthTxt, (IPTR)"55555",
382 End),
383 Child, HSpace(100),
384 Child, Label1(__(MSG_MIN)),
385 Child, (IPTR)(minvisobj = StringObject,
386 StringFrame,
387 MUIA_Weight, 0,
388 MUIA_CycleChain, TRUE,
389 MUIA_String_Accept, (IPTR)"0123456789",
390 MUIA_FixWidthTxt, (IPTR)"55555",
391 End),
392 Child, HSpace(100),
393 Child, Label1(__(MSG_MAX)),
394 Child, (IPTR)(maxvisobj = StringObject,
395 StringFrame,
396 MUIA_Weight, 0,
397 MUIA_CycleChain, TRUE,
398 MUIA_String_Accept, (IPTR)"0123456789",
399 MUIA_FixWidthTxt, (IPTR)"55555",
400 End),
401 Child, HSpace(100),
402 End,
403 End,
404 End,
405 Child, HVSpace,
406 End,
407 End,
408 TAG_DONE
411 if (self != NULL)
413 data = INST_DATA(CLASS, self);
415 D(bug("[ReqToolsEditor.class] %s: Self @ 0x%p, Data @ 0x%p\n", __PRETTY_FUNCTION__, self, data));
417 data->colorwheelstyleobj = colorwheelstyleobj;
418 data->poptofrontobj = poptofrontobj;
419 data->usesysfontobj = usesysfontobj;
420 data->usefunckeysobj = usefunckeysobj;
422 data->immediatesortobj = immediatesortobj;
423 data->drawersfirstobj = drawersfirstobj;
424 data->drawersmixedobj = drawersmixedobj;
425 data->diskactivityobj = diskactivityobj;
426 data->mmbobj = mmbobj;
428 data->defaultsforobj = defaultsforobj;
429 data->positionobj = positionobj;
430 data->sizepercentobj = sizepercentobj;
431 data->offsetxobj = offsetxobj;
432 data->offsetyobj = offsetyobj;
433 data->minvisobj = minvisobj;
434 data->maxvisobj = maxvisobj;
436 DoMethod
438 poptofrontobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
439 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
442 DoMethod
444 usesysfontobj, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
445 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
448 DoMethod
450 usefunckeysobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
451 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
454 DoMethod
456 colorwheelstyleobj, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
457 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
460 DoMethod
462 immediatesortobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
463 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
466 DoMethod
468 drawersfirstobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
469 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
472 DoMethod
474 drawersmixedobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
475 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
478 DoMethod
480 diskactivityobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
481 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
484 DoMethod
486 mmbobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
487 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
490 DoMethod
492 defaultsforobj, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
493 (IPTR)defaultsforobj, 3, MUIM_CallHook, (IPTR)&selectdefaultshook, (IPTR)data
496 DoMethod
498 positionobj, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
499 (IPTR) self, 3, MUIM_CallHook, (IPTR)&updatedefaultshook, (IPTR)data
502 DoMethod
504 sizepercentobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
505 (IPTR) self, 3, MUIM_CallHook, (IPTR)&updatedefaultshook, (IPTR)data
508 DoMethod
510 offsetxobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
511 (IPTR) self, 3, MUIM_CallHook, (IPTR)&updatedefaultshook, (IPTR)data
514 DoMethod
516 offsetyobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
517 (IPTR) self, 3, MUIM_CallHook, (IPTR)&updatedefaultshook, (IPTR)data
520 DoMethod
522 minvisobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
523 (IPTR) self, 3, MUIM_CallHook, (IPTR)&updatedefaultshook, (IPTR)data
526 DoMethod
528 maxvisobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
529 (IPTR) self, 3, MUIM_CallHook, (IPTR)&updatedefaultshook, (IPTR)data
532 ReqToolsPrefs2Gadgets(data);
534 return (IPTR) self;
538 /*********************************************************************************************/
540 IPTR ReqToolsEditor__MUIM_PrefsEditor_ImportFH (
541 Class *CLASS, Object *self,
542 struct MUIP_PrefsEditor_ImportFH *message
545 SETUP_INST_DATA;
546 BOOL success = TRUE;
548 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
550 success = Prefs_ImportFH(message->fh);
551 if (success) ReqToolsPrefs2Gadgets(data);
553 return success;
556 /*********************************************************************************************/
558 IPTR ReqToolsEditor__MUIM_PrefsEditor_ExportFH
560 Class *CLASS, Object *self,
561 struct MUIP_PrefsEditor_ExportFH *message
564 SETUP_INST_DATA;
565 BOOL success = TRUE;
567 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
569 Gadgets2ReqToolsPrefs(data);
570 success = Prefs_ExportFH(message->fh);
572 return success;
575 /*********************************************************************************************/
577 IPTR ReqToolsEditor__MUIM_PrefsEditor_SetDefaults
579 Class *CLASS, Object *self, Msg message
582 SETUP_INST_DATA;
583 BOOL success = TRUE;
585 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
587 success = Prefs_Default();
588 if (success) ReqToolsPrefs2Gadgets(data);
590 return success;
593 /*** Setup ******************************************************************/
594 ZUNE_CUSTOMCLASS_4
596 ReqToolsEditor, NULL, MUIC_PrefsEditor, NULL,
597 OM_NEW, struct opSet *,
598 MUIM_PrefsEditor_ImportFH, struct MUIP_PrefsEditor_ImportFH *,
599 MUIM_PrefsEditor_ExportFH, struct MUIP_PrefsEditor_ExportFH *,
600 MUIM_PrefsEditor_SetDefaults, Msg