revert between 56095 -> 55830 in arch
[AROS.git] / workbench / prefs / reqtools / reqtoolseditor.c
blobd1804a3dbcaa9f5d93fda36b6a007107c8fd165c
1 /*
2 Copyright © 2013-2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
7 #include <aros/debug.h>
9 #include <devices/rawkeycodes.h>
10 #include <mui/HotkeyString_mcc.h>
11 #include <zune/prefseditor.h>
12 #include <zune/customclasses.h>
14 #include <proto/alib.h>
15 #include <proto/commodities.h>
16 #include <proto/intuition.h>
17 #include <proto/muimaster.h>
18 #include <proto/alib.h>
20 #include <string.h>
21 #include <stdio.h>
23 #include "reqtoolseditor.h"
24 #include "reqtoolsstringify.h"
25 #include "prefs.h"
26 #include "locale.h"
28 /*********************************************************************************************/
30 struct ReqToolsEditor_DATA
32 Object *poptofrontobj;
33 Object *usesysfontobj;
34 Object *usefunckeysobj;
35 Object *colorwheelstyleobj;
37 Object *immediatesortobj;
38 Object *drawersfirstobj;
39 Object *drawersmixedobj;
40 Object *diskactivityobj;
41 Object *mmbobj;
43 Object *defaultsforobj;
44 Object *sizepercentobj;
45 Object *minvisobj;
46 Object *maxvisobj;
47 Object *positionobj;
48 Object *offsetxobj;
49 Object *offsetyobj;
52 /*********************************************************************************************/
54 #define SETUP_INST_DATA struct ReqToolsEditor_DATA *data = INST_DATA(CLASS, self)
56 /*********************************************************************************************/
58 static struct Hook selectdefaultshook, updatedefaultshook;
59 static CONST_STRPTR colorwheelstyle_labels[4], defaultsfor_labels[7], position_labels[6];
61 /*********************************************************************************************/
63 static void SelectDefaultsHook(struct Hook *hook, Object *self, struct ReqToolsEditor_DATA **data)
65 struct ReqToolsPrefs *prefs = &reqtoolsprefs;
66 IPTR active = 0;
68 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
70 GET(self, MUIA_Cycle_Active, &active);
72 NNSET((*data)->positionobj, MUIA_Cycle_Active, prefs->ReqDefaults[active].ReqPos);
73 NNSET((*data)->sizepercentobj, MUIA_Numeric_Value, prefs->ReqDefaults[active].Size);
74 NNSET((*data)->offsetxobj, MUIA_String_Integer, prefs->ReqDefaults[active].LeftOffset);
75 NNSET((*data)->offsetyobj, MUIA_String_Integer, prefs->ReqDefaults[active].TopOffset);
76 NNSET((*data)->minvisobj, MUIA_String_Integer, prefs->ReqDefaults[active].MinEntries);
77 NNSET((*data)->maxvisobj, MUIA_String_Integer, prefs->ReqDefaults[active].MaxEntries);
80 static void UpdateDefaultsHook(struct Hook *hook, Object *self, struct ReqToolsEditor_DATA **data)
82 struct ReqToolsPrefs *prefs = &reqtoolsprefs;
83 IPTR active = 0, tmpval;
84 BOOL changed = FALSE;
86 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
88 GET((*data)->defaultsforobj, MUIA_Cycle_Active, &active);
90 tmpval = prefs->ReqDefaults[active].ReqPos;
91 if ((prefs->ReqDefaults[active].ReqPos = XGET((*data)->positionobj, MUIA_Cycle_Active)) != tmpval)
92 changed = TRUE;
93 tmpval = prefs->ReqDefaults[active].Size;
94 if ((prefs->ReqDefaults[active].Size = XGET((*data)->sizepercentobj, MUIA_Numeric_Value)) != tmpval)
95 changed = TRUE;
96 tmpval = prefs->ReqDefaults[active].LeftOffset;
97 if ((prefs->ReqDefaults[active].LeftOffset = XGET((*data)->offsetxobj, MUIA_String_Integer)) != tmpval)
98 changed = TRUE;
99 tmpval = prefs->ReqDefaults[active].TopOffset;
100 if ((prefs->ReqDefaults[active].TopOffset = XGET((*data)->offsetyobj, MUIA_String_Integer)) != tmpval)
101 changed = TRUE;
102 tmpval = prefs->ReqDefaults[active].MinEntries;
103 if ((prefs->ReqDefaults[active].MinEntries = XGET((*data)->minvisobj, MUIA_String_Integer)) != tmpval)
104 changed = TRUE;
105 tmpval = prefs->ReqDefaults[active].MaxEntries;
106 if ((prefs->ReqDefaults[active].MaxEntries = XGET((*data)->maxvisobj, MUIA_String_Integer)) != tmpval)
107 changed = TRUE;
109 if (changed)
111 SET( _parent(self), MUIA_PrefsEditor_Changed, TRUE);
115 /*********************************************************************************************/
117 BOOL Gadgets2ReqToolsPrefs(struct ReqToolsEditor_DATA *data)
119 struct ReqToolsPrefs *prefs = &reqtoolsprefs;
120 IPTR active = 0;
122 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
124 // Clear options we are about to set..
125 prefs->Flags &= ~(RTPRF_NOSCRTOFRONT | RTPRF_DEFAULTFONT | RTPRF_FKEYS | RTPRB_DOWHEEL | RTPRB_FANCYWHEEL | RTPRF_IMMSORT | RTPRF_DIRSFIRST | RTPRF_DIRSMIXED | RTPRF_NOLED | RTPRF_MMBPARENT);
127 GET(data->poptofrontobj, MUIA_Selected, &active);
128 if (active == 0)
129 prefs->Flags |= RTPRF_NOSCRTOFRONT;
130 GET(data->usesysfontobj, MUIA_Selected, &active);
131 if (active != 0)
132 prefs->Flags |= RTPRF_DEFAULTFONT;
133 GET(data->usefunckeysobj, MUIA_Selected, &active);
134 if (active != 0)
135 prefs->Flags |= RTPRF_FKEYS;
136 GET(data->colorwheelstyleobj, MUIA_Cycle_Active, &active);
137 if (active > 0)
138 prefs->Flags |= RTPRB_DOWHEEL;
139 if (active > 1)
140 prefs->Flags |= RTPRB_FANCYWHEEL;
141 GET(data->immediatesortobj, MUIA_Selected, &active);
142 if (active != 0)
143 prefs->Flags |= RTPRF_IMMSORT;
144 GET(data->drawersfirstobj, MUIA_Selected, &active);
145 if (active != 0)
146 prefs->Flags |= RTPRF_DIRSFIRST;
147 GET(data->drawersmixedobj, MUIA_Selected, &active);
148 if (active != 0)
149 prefs->Flags |= RTPRF_DIRSMIXED;
150 GET(data->diskactivityobj, MUIA_Selected, &active);
151 if (active == 0)
152 prefs->Flags |= RTPRF_NOLED;
153 GET(data->mmbobj, MUIA_Selected, &active);
154 if (active != 0)
155 prefs->Flags |= RTPRF_MMBPARENT;
157 return TRUE;
160 /*********************************************************************************************/
162 BOOL ReqToolsPrefs2Gadgets(struct ReqToolsEditor_DATA *data)
164 struct ReqToolsPrefs *prefs = &reqtoolsprefs;
165 IPTR active = 0;
167 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
169 NNSET(data->poptofrontobj, MUIA_Selected, (prefs->Flags & RTPRF_NOSCRTOFRONT) ? 0 : 1);
170 NNSET(data->usesysfontobj, MUIA_Selected, (prefs->Flags & RTPRF_DEFAULTFONT) ? 1 : 0);
171 NNSET(data->usefunckeysobj, MUIA_Selected, (prefs->Flags & RTPRF_FKEYS) ? 1 : 0);
172 if ((prefs->Flags & (RTPRB_DOWHEEL | RTPRB_FANCYWHEEL)) == 0)
173 active = 0;
174 else if ((prefs->Flags & (RTPRB_DOWHEEL | RTPRB_FANCYWHEEL)) == RTPRB_DOWHEEL)
175 active = 1;
176 else
177 active = 2;
178 NNSET(data->colorwheelstyleobj, MUIA_Cycle_Active, active);
179 NNSET(data->immediatesortobj, MUIA_Selected, (prefs->Flags & RTPRF_IMMSORT) ? 1 : 0);
180 NNSET(data->drawersfirstobj, MUIA_Selected, (prefs->Flags & RTPRF_DIRSFIRST) ? 1 : 0);
181 NNSET(data->drawersmixedobj, MUIA_Selected, (prefs->Flags & RTPRF_DIRSMIXED) ? 1 : 0);
182 NNSET(data->diskactivityobj, MUIA_Selected, (prefs->Flags & RTPRF_NOLED) ? 0 : 1);
183 NNSET(data->mmbobj, MUIA_Selected, (prefs->Flags & RTPRF_MMBPARENT) ? 1 : 0);
185 SelectDefaultsHook(NULL, data->defaultsforobj, &data);
187 return TRUE;
190 /*********************************************************************************************/
192 Object *ReqToolsEditor__Checkmark()
194 Object *obj = MUI_MakeObject(MUIO_Checkmark, (IPTR)NULL);
196 if (obj)
198 SET(obj, MUIA_CycleChain, 1);
200 return obj;
203 Object *ReqToolsEditor__Cycle(const UBYTE **labels)
205 Object *obj = MUI_MakeObject(MUIO_Cycle, (IPTR)NULL, labels);
207 if (obj)
209 SET(obj, MUIA_CycleChain, 1);
211 return obj;
214 /*********************************************************************************************/
216 IPTR ReqToolsEditor__OM_NEW
218 Class *CLASS, Object *self, struct opSet *message
221 struct ReqToolsEditor_DATA *data = NULL;
223 struct TagItem ReqToolsStringifyTags[] = {
224 { MUIA_Numeric_Value, 0 },
225 { MUIA_Numeric_Min, 0 },
226 { MUIA_Numeric_Max, 100 },
227 { TAG_DONE, (IPTR)NULL }
231 Object *poptofrontobj;
232 Object *usesysfontobj;
233 Object *usefunckeysobj;
234 Object *colorwheelstyleobj;
236 Object *immediatesortobj;
237 Object *drawersfirstobj;
238 Object *drawersmixedobj;
239 Object *diskactivityobj;
240 Object *mmbobj;
242 Object *defaultsforobj;
243 Object *positionobj;
244 Object *sizepercentobj;
245 Object *offsetxobj;
246 Object *offsetyobj;
247 Object *minvisobj;
248 Object *maxvisobj;
250 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
252 selectdefaultshook.h_Entry = HookEntry;
253 selectdefaultshook.h_SubEntry = (HOOKFUNC)SelectDefaultsHook;
254 updatedefaultshook.h_Entry = HookEntry;
255 updatedefaultshook.h_SubEntry = (HOOKFUNC)UpdateDefaultsHook;
257 colorwheelstyle_labels[0] = _(MSG_WHEEL_NONE);
258 colorwheelstyle_labels[1] = _(MSG_WHEEL_SIMPLE);
259 colorwheelstyle_labels[2] = _(MSG_WHEEL_FANCY);
261 defaultsfor_labels[0] = _(MSG_FILEREQ);
262 defaultsfor_labels[1] = _(MSG_FONTREQ);
263 defaultsfor_labels[2] = _(MSG_PALETTEREQ);
264 defaultsfor_labels[3] = _(MSG_SCRMODEREQ);
265 defaultsfor_labels[4] = _(MSG_VOLUMEREQ);
266 defaultsfor_labels[5] = _(MSG_OTHERREQ);
268 position_labels[0] = _(MSG_POINTER);
269 position_labels[1] = _(MSG_CENTERWIN);
270 position_labels[2] = _(MSG_CENTERSCR);
271 position_labels[3] = _(MSG_TOPLEFTWIN);
272 position_labels[4] = _(MSG_TOPLEFTSCR);
274 sizepercentobj = (Object *)NewObjectA(ReqToolsStringify_CLASS->mcc_Class, NULL, ReqToolsStringifyTags);
276 self = (Object *) DoSuperNewTags
278 CLASS, self, NULL,
280 MUIA_PrefsEditor_Name, __(MSG_WINDOW_TITLE),
281 MUIA_PrefsEditor_Path, (IPTR) "ReqTools.prefs",
282 MUIA_PrefsEditor_IconTool, (IPTR) "SYS:Prefs/ReqTools",
284 Child, HGroup,
285 Child, (IPTR)VGroup,
286 MUIA_Weight, 0,
287 Child, VGroup,
288 GroupFrameT(__(MSG_GENERAL)),
289 Child, HGroup,
290 Child, ColGroup(2),
291 Child, (poptofrontobj = ReqToolsEditor__Checkmark()),
292 Child, LLabel1(__(MSG_POPSCREEN)),
293 Child, (usesysfontobj = ReqToolsEditor__Checkmark()),
294 Child, LLabel1(__(MSG_DEFAULTFONT)),
295 Child, (usefunckeysobj = ReqToolsEditor__Checkmark()),
296 Child, LLabel1(__(MSG_FKEYS)),
297 End,
298 Child, HVSpace,
299 End,
300 Child, HGroup,
301 Child, Label1(__(MSG_DOWHEEL)),
302 Child, (colorwheelstyleobj = ReqToolsEditor__Cycle(colorwheelstyle_labels)),
303 Child, HVSpace,
304 End,
305 End,
306 Child, HGroup,
307 GroupFrameT(__(MSG_FILEREQUESTER)),
308 Child, ColGroup(2),
309 Child, (immediatesortobj = ReqToolsEditor__Checkmark()),
310 Child, LLabel1(__(MSG_IMMEDIATESORT)),
311 Child, (drawersfirstobj = ReqToolsEditor__Checkmark()),
312 Child, LLabel1(__(MSG_DRAWERSFIRST)),
313 Child, (drawersmixedobj = ReqToolsEditor__Checkmark()),
314 Child, LLabel1(__(MSG_DRAWERSMIXED)),
315 Child, (diskactivityobj = ReqToolsEditor__Checkmark()),
316 Child, LLabel1(__(MSG_LED)),
317 Child, (mmbobj = ReqToolsEditor__Checkmark()),
318 Child, LLabel1(__(MSG_MMB_PARENT)),
319 End,
320 Child, HVSpace,
321 End,
322 End,
323 Child, VGroup,
324 GroupFrameT(__(MSG_DEFAULTS)),
325 Child, HGroup,
326 Child, Label1(__(MSG_REQUESTER)),
327 Child, (defaultsforobj = ReqToolsEditor__Cycle(defaultsfor_labels)),
328 End,
329 Child, RectangleObject,
330 MUIA_VertWeight, 0,
331 MUIA_Rectangle_HBar, TRUE,
332 End,
333 Child, ColGroup(2),
334 Child, Label1(__(MSG_POSITION)),
335 Child, (positionobj = ReqToolsEditor__Cycle(position_labels)),
336 Child, Label1(__(MSG_SIZE)),
337 Child, sizepercentobj,
338 Child, Label1(__(MSG_OFFSET)),
339 Child, HVSpace,
340 Child, Label1("X:"),
341 Child, HGroup,
342 Child, (IPTR)(offsetxobj = StringObject,
343 StringFrame,
344 MUIA_Weight, 0,
345 MUIA_CycleChain, TRUE,
346 MUIA_String_Accept, (IPTR)"0123456789",
347 MUIA_FixWidthTxt, (IPTR)"55555",
348 End),
349 Child, HVSpace,
350 End,
351 Child, Label1("Y:"),
352 Child, HGroup,
353 Child, (IPTR)(offsetyobj = StringObject,
354 StringFrame,
355 MUIA_Weight, 0,
356 MUIA_CycleChain, TRUE,
357 MUIA_String_Accept, (IPTR)"0123456789",
358 MUIA_FixWidthTxt, (IPTR)"55555",
359 End),
360 Child, HVSpace,
361 End,
362 Child, Label1(__(MSG_NR_OF_ENTRIES)),
363 Child, HVSpace,
364 Child, Label1(__(MSG_MIN)),
365 Child, HGroup,
366 Child, (IPTR)(minvisobj = StringObject,
367 StringFrame,
368 MUIA_Weight, 0,
369 MUIA_CycleChain, TRUE,
370 MUIA_String_Accept, (IPTR)"0123456789",
371 MUIA_FixWidthTxt, (IPTR)"55555",
372 End),
373 Child, HVSpace,
374 End,
375 Child, Label1(__(MSG_MAX)),
376 Child, HGroup,
377 Child, (IPTR)(maxvisobj = StringObject,
378 StringFrame,
379 MUIA_Weight, 0,
380 MUIA_CycleChain, TRUE,
381 MUIA_String_Accept, (IPTR)"0123456789",
382 MUIA_FixWidthTxt, (IPTR)"55555",
383 End),
384 Child, HVSpace,
385 End,
386 End,
387 Child, HVSpace,
388 End,
389 End,
390 TAG_DONE
393 if (self != NULL)
395 data = INST_DATA(CLASS, self);
397 D(bug("[ReqToolsEditor.class] %s: Self @ 0x%p, Data @ 0x%p\n", __PRETTY_FUNCTION__, self, data));
399 data->colorwheelstyleobj = colorwheelstyleobj;
400 data->poptofrontobj = poptofrontobj;
401 data->usesysfontobj = usesysfontobj;
402 data->usefunckeysobj = usefunckeysobj;
404 data->immediatesortobj = immediatesortobj;
405 data->drawersfirstobj = drawersfirstobj;
406 data->drawersmixedobj = drawersmixedobj;
407 data->diskactivityobj = diskactivityobj;
408 data->mmbobj = mmbobj;
410 data->defaultsforobj = defaultsforobj;
411 data->positionobj = positionobj;
412 data->sizepercentobj = sizepercentobj;
413 data->offsetxobj = offsetxobj;
414 data->offsetyobj = offsetyobj;
415 data->minvisobj = minvisobj;
416 data->maxvisobj = maxvisobj;
418 DoMethod
420 poptofrontobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
421 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
424 DoMethod
426 usesysfontobj, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
427 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
430 DoMethod
432 usefunckeysobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
433 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
436 DoMethod
438 colorwheelstyleobj, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
439 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
442 DoMethod
444 immediatesortobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
445 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
448 DoMethod
450 drawersfirstobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
451 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
454 DoMethod
456 drawersmixedobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
457 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
460 DoMethod
462 diskactivityobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
463 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
466 DoMethod
468 mmbobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
469 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
472 DoMethod
474 defaultsforobj, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
475 (IPTR)defaultsforobj, 3, MUIM_CallHook, (IPTR)&selectdefaultshook, (IPTR)data
478 DoMethod
480 positionobj, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
481 (IPTR) self, 3, MUIM_CallHook, (IPTR)&updatedefaultshook, (IPTR)data
484 DoMethod
486 sizepercentobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
487 (IPTR) self, 3, MUIM_CallHook, (IPTR)&updatedefaultshook, (IPTR)data
490 DoMethod
492 offsetxobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
493 (IPTR) self, 3, MUIM_CallHook, (IPTR)&updatedefaultshook, (IPTR)data
496 DoMethod
498 offsetyobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
499 (IPTR) self, 3, MUIM_CallHook, (IPTR)&updatedefaultshook, (IPTR)data
502 DoMethod
504 minvisobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
505 (IPTR) self, 3, MUIM_CallHook, (IPTR)&updatedefaultshook, (IPTR)data
508 DoMethod
510 maxvisobj, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
511 (IPTR) self, 3, MUIM_CallHook, (IPTR)&updatedefaultshook, (IPTR)data
514 ReqToolsPrefs2Gadgets(data);
516 return (IPTR) self;
520 /*********************************************************************************************/
522 IPTR ReqToolsEditor__MUIM_PrefsEditor_ImportFH (
523 Class *CLASS, Object *self,
524 struct MUIP_PrefsEditor_ImportFH *message
527 SETUP_INST_DATA;
528 BOOL success = TRUE;
530 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
532 success = Prefs_ImportFH(message->fh);
533 if (success) ReqToolsPrefs2Gadgets(data);
535 return success;
538 /*********************************************************************************************/
540 IPTR ReqToolsEditor__MUIM_PrefsEditor_ExportFH
542 Class *CLASS, Object *self,
543 struct MUIP_PrefsEditor_ExportFH *message
546 SETUP_INST_DATA;
547 BOOL success = TRUE;
549 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
551 Gadgets2ReqToolsPrefs(data);
552 success = Prefs_ExportFH(message->fh);
554 return success;
557 /*********************************************************************************************/
559 IPTR ReqToolsEditor__MUIM_PrefsEditor_SetDefaults
561 Class *CLASS, Object *self, Msg message
564 SETUP_INST_DATA;
565 BOOL success = TRUE;
567 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__));
569 success = Prefs_Default();
570 if (success) ReqToolsPrefs2Gadgets(data);
572 return success;
575 /*** Setup ******************************************************************/
576 ZUNE_CUSTOMCLASS_4
578 ReqToolsEditor, NULL, MUIC_PrefsEditor, NULL,
579 OM_NEW, struct opSet *,
580 MUIM_PrefsEditor_ImportFH, struct MUIP_PrefsEditor_ImportFH *,
581 MUIM_PrefsEditor_ExportFH, struct MUIP_PrefsEditor_ExportFH *,
582 MUIM_PrefsEditor_SetDefaults, Msg