2 Copyright © 2013-2017, The AROS Development Team. All rights reserved.
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>
23 #include "reqtoolseditor.h"
24 #include "reqtoolsstringify.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
;
43 Object
*defaultsforobj
;
44 Object
*sizepercentobj
;
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
;
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
;
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
)
93 tmpval
= prefs
->ReqDefaults
[active
].Size
;
94 if ((prefs
->ReqDefaults
[active
].Size
= XGET((*data
)->sizepercentobj
, MUIA_Numeric_Value
)) != tmpval
)
96 tmpval
= prefs
->ReqDefaults
[active
].LeftOffset
;
97 if ((prefs
->ReqDefaults
[active
].LeftOffset
= XGET((*data
)->offsetxobj
, MUIA_String_Integer
)) != tmpval
)
99 tmpval
= prefs
->ReqDefaults
[active
].TopOffset
;
100 if ((prefs
->ReqDefaults
[active
].TopOffset
= XGET((*data
)->offsetyobj
, MUIA_String_Integer
)) != tmpval
)
102 tmpval
= prefs
->ReqDefaults
[active
].MinEntries
;
103 if ((prefs
->ReqDefaults
[active
].MinEntries
= XGET((*data
)->minvisobj
, MUIA_String_Integer
)) != tmpval
)
105 tmpval
= prefs
->ReqDefaults
[active
].MaxEntries
;
106 if ((prefs
->ReqDefaults
[active
].MaxEntries
= XGET((*data
)->maxvisobj
, MUIA_String_Integer
)) != tmpval
)
111 SET( _parent(self
), MUIA_PrefsEditor_Changed
, TRUE
);
115 /*********************************************************************************************/
117 BOOL
Gadgets2ReqToolsPrefs(struct ReqToolsEditor_DATA
*data
)
119 struct ReqToolsPrefs
*prefs
= &reqtoolsprefs
;
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
);
129 prefs
->Flags
|= RTPRF_NOSCRTOFRONT
;
130 GET(data
->usesysfontobj
, MUIA_Selected
, &active
);
132 prefs
->Flags
|= RTPRF_DEFAULTFONT
;
133 GET(data
->usefunckeysobj
, MUIA_Selected
, &active
);
135 prefs
->Flags
|= RTPRF_FKEYS
;
136 GET(data
->colorwheelstyleobj
, MUIA_Cycle_Active
, &active
);
138 prefs
->Flags
|= RTPRB_DOWHEEL
;
140 prefs
->Flags
|= RTPRB_FANCYWHEEL
;
141 GET(data
->immediatesortobj
, MUIA_Selected
, &active
);
143 prefs
->Flags
|= RTPRF_IMMSORT
;
144 GET(data
->drawersfirstobj
, MUIA_Selected
, &active
);
146 prefs
->Flags
|= RTPRF_DIRSFIRST
;
147 GET(data
->drawersmixedobj
, MUIA_Selected
, &active
);
149 prefs
->Flags
|= RTPRF_DIRSMIXED
;
150 GET(data
->diskactivityobj
, MUIA_Selected
, &active
);
152 prefs
->Flags
|= RTPRF_NOLED
;
153 GET(data
->mmbobj
, MUIA_Selected
, &active
);
155 prefs
->Flags
|= RTPRF_MMBPARENT
;
160 /*********************************************************************************************/
162 BOOL
ReqToolsPrefs2Gadgets(struct ReqToolsEditor_DATA
*data
)
164 struct ReqToolsPrefs
*prefs
= &reqtoolsprefs
;
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)
174 else if ((prefs
->Flags
& (RTPRB_DOWHEEL
| RTPRB_FANCYWHEEL
)) == RTPRB_DOWHEEL
)
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
);
190 /*********************************************************************************************/
192 Object
*ReqToolsEditor__Checkmark()
194 Object
*obj
= MUI_MakeObject(MUIO_Checkmark
, (IPTR
)NULL
);
198 SET(obj
, MUIA_CycleChain
, 1);
203 Object
*ReqToolsEditor__Cycle(const UBYTE
**labels
)
205 Object
*obj
= MUI_MakeObject(MUIO_Cycle
, (IPTR
)NULL
, labels
);
209 SET(obj
, MUIA_CycleChain
, 1);
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
;
242 Object
*defaultsforobj
;
244 Object
*sizepercentobj
;
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
280 MUIA_PrefsEditor_Name
, __(MSG_WINDOW_TITLE
),
281 MUIA_PrefsEditor_Path
, (IPTR
) "ReqTools.prefs",
282 MUIA_PrefsEditor_IconTool
, (IPTR
) "SYS:Prefs/ReqTools",
288 GroupFrameT(__(MSG_GENERAL
)),
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
)),
301 Child
, Label1(__(MSG_DOWHEEL
)),
302 Child
, (colorwheelstyleobj
= ReqToolsEditor__Cycle(colorwheelstyle_labels
)),
307 GroupFrameT(__(MSG_FILEREQUESTER
)),
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
)),
324 GroupFrameT(__(MSG_DEFAULTS
)),
326 Child
, Label1(__(MSG_REQUESTER
)),
327 Child
, (defaultsforobj
= ReqToolsEditor__Cycle(defaultsfor_labels
)),
329 Child
, RectangleObject
,
331 MUIA_Rectangle_HBar
, TRUE
,
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
)),
342 Child
, (IPTR
)(offsetxobj
= StringObject
,
345 MUIA_CycleChain
, TRUE
,
346 MUIA_String_Accept
, (IPTR
)"0123456789",
347 MUIA_FixWidthTxt
, (IPTR
)"55555",
353 Child
, (IPTR
)(offsetyobj
= StringObject
,
356 MUIA_CycleChain
, TRUE
,
357 MUIA_String_Accept
, (IPTR
)"0123456789",
358 MUIA_FixWidthTxt
, (IPTR
)"55555",
362 Child
, Label1(__(MSG_NR_OF_ENTRIES
)),
364 Child
, Label1(__(MSG_MIN
)),
366 Child
, (IPTR
)(minvisobj
= StringObject
,
369 MUIA_CycleChain
, TRUE
,
370 MUIA_String_Accept
, (IPTR
)"0123456789",
371 MUIA_FixWidthTxt
, (IPTR
)"55555",
375 Child
, Label1(__(MSG_MAX
)),
377 Child
, (IPTR
)(maxvisobj
= StringObject
,
380 MUIA_CycleChain
, TRUE
,
381 MUIA_String_Accept
, (IPTR
)"0123456789",
382 MUIA_FixWidthTxt
, (IPTR
)"55555",
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
;
420 poptofrontobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
421 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
426 usesysfontobj
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
427 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
432 usefunckeysobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
433 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
438 colorwheelstyleobj
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
439 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
444 immediatesortobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
445 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
450 drawersfirstobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
451 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
456 drawersmixedobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
457 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
462 diskactivityobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
463 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
468 mmbobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
469 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
474 defaultsforobj
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
475 (IPTR
)defaultsforobj
, 3, MUIM_CallHook
, (IPTR
)&selectdefaultshook
, (IPTR
)data
480 positionobj
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
481 (IPTR
) self
, 3, MUIM_CallHook
, (IPTR
)&updatedefaultshook
, (IPTR
)data
486 sizepercentobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
487 (IPTR
) self
, 3, MUIM_CallHook
, (IPTR
)&updatedefaultshook
, (IPTR
)data
492 offsetxobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
493 (IPTR
) self
, 3, MUIM_CallHook
, (IPTR
)&updatedefaultshook
, (IPTR
)data
498 offsetyobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
499 (IPTR
) self
, 3, MUIM_CallHook
, (IPTR
)&updatedefaultshook
, (IPTR
)data
504 minvisobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
505 (IPTR
) self
, 3, MUIM_CallHook
, (IPTR
)&updatedefaultshook
, (IPTR
)data
510 maxvisobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
511 (IPTR
) self
, 3, MUIM_CallHook
, (IPTR
)&updatedefaultshook
, (IPTR
)data
514 ReqToolsPrefs2Gadgets(data
);
520 /*********************************************************************************************/
522 IPTR
ReqToolsEditor__MUIM_PrefsEditor_ImportFH (
523 Class
*CLASS
, Object
*self
,
524 struct MUIP_PrefsEditor_ImportFH
*message
530 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__
));
532 success
= Prefs_ImportFH(message
->fh
);
533 if (success
) ReqToolsPrefs2Gadgets(data
);
538 /*********************************************************************************************/
540 IPTR ReqToolsEditor__MUIM_PrefsEditor_ExportFH
542 Class
*CLASS
, Object
*self
,
543 struct MUIP_PrefsEditor_ExportFH
*message
549 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__
));
551 Gadgets2ReqToolsPrefs(data
);
552 success
= Prefs_ExportFH(message
->fh
);
557 /*********************************************************************************************/
559 IPTR ReqToolsEditor__MUIM_PrefsEditor_SetDefaults
561 Class
*CLASS
, Object
*self
, Msg message
567 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__
));
569 success
= Prefs_Default();
570 if (success
) ReqToolsPrefs2Gadgets(data
);
575 /*** Setup ******************************************************************/
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