2 Copyright © 2013, The AROS Development Team. All rights reserved.
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>
26 #include "reqtoolseditor.h"
27 #include "reqtoolsstringify.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
;
46 Object
*defaultsforobj
;
47 Object
*sizepercentobj
;
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
;
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
;
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
)
96 tmpval
= prefs
->ReqDefaults
[active
].Size
;
97 if ((prefs
->ReqDefaults
[active
].Size
= XGET((*data
)->sizepercentobj
, MUIA_Numeric_Value
)) != tmpval
)
99 tmpval
= prefs
->ReqDefaults
[active
].LeftOffset
;
100 if ((prefs
->ReqDefaults
[active
].LeftOffset
= XGET((*data
)->offsetxobj
, MUIA_String_Integer
)) != tmpval
)
102 tmpval
= prefs
->ReqDefaults
[active
].TopOffset
;
103 if ((prefs
->ReqDefaults
[active
].TopOffset
= XGET((*data
)->offsetyobj
, MUIA_String_Integer
)) != tmpval
)
105 tmpval
= prefs
->ReqDefaults
[active
].MinEntries
;
106 if ((prefs
->ReqDefaults
[active
].MinEntries
= XGET((*data
)->minvisobj
, MUIA_String_Integer
)) != tmpval
)
108 tmpval
= prefs
->ReqDefaults
[active
].MaxEntries
;
109 if ((prefs
->ReqDefaults
[active
].MaxEntries
= XGET((*data
)->maxvisobj
, MUIA_String_Integer
)) != tmpval
)
114 SET( _parent(self
), MUIA_PrefsEditor_Changed
, TRUE
);
118 /*********************************************************************************************/
120 BOOL
Gadgets2ReqToolsPrefs(struct ReqToolsEditor_DATA
*data
)
122 struct ReqToolsPrefs
*prefs
= &reqtoolsprefs
;
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
);
132 prefs
->Flags
|= RTPRF_NOSCRTOFRONT
;
133 GET(data
->usesysfontobj
, MUIA_Selected
, &active
);
135 prefs
->Flags
|= RTPRF_DEFAULTFONT
;
136 GET(data
->usefunckeysobj
, MUIA_Selected
, &active
);
138 prefs
->Flags
|= RTPRF_FKEYS
;
139 GET(data
->colorwheelstyleobj
, MUIA_Cycle_Active
, &active
);
141 prefs
->Flags
|= RTPRB_DOWHEEL
;
143 prefs
->Flags
|= RTPRB_FANCYWHEEL
;
144 GET(data
->immediatesortobj
, MUIA_Selected
, &active
);
146 prefs
->Flags
|= RTPRF_IMMSORT
;
147 GET(data
->drawersfirstobj
, MUIA_Selected
, &active
);
149 prefs
->Flags
|= RTPRF_DIRSFIRST
;
150 GET(data
->drawersmixedobj
, MUIA_Selected
, &active
);
152 prefs
->Flags
|= RTPRF_DIRSMIXED
;
153 GET(data
->diskactivityobj
, MUIA_Selected
, &active
);
155 prefs
->Flags
|= RTPRF_NOLED
;
156 GET(data
->mmbobj
, MUIA_Selected
, &active
);
158 prefs
->Flags
|= RTPRF_MMBPARENT
;
163 /*********************************************************************************************/
165 BOOL
ReqToolsPrefs2Gadgets(struct ReqToolsEditor_DATA
*data
)
167 struct ReqToolsPrefs
*prefs
= &reqtoolsprefs
;
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)
177 else if ((prefs
->Flags
& (RTPRB_DOWHEEL
| RTPRB_FANCYWHEEL
)) == RTPRB_DOWHEEL
)
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
);
193 /*********************************************************************************************/
195 Object
*ReqToolsEditor__Checkmark()
197 Object
*obj
= MUI_MakeObject(MUIO_Checkmark
, (IPTR
)NULL
);
201 SET(obj
, MUIA_CycleChain
, 1);
206 Object
*ReqToolsEditor__Cycle(const UBYTE
**labels
)
208 Object
*obj
= MUI_MakeObject(MUIO_Cycle
, (IPTR
)NULL
, labels
);
212 SET(obj
, MUIA_CycleChain
, 1);
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
;
245 Object
*defaultsforobj
;
247 Object
*sizepercentobj
;
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
283 MUIA_PrefsEditor_Name
, __(MSG_WINDOW_TITLE
),
284 MUIA_PrefsEditor_Path
, (IPTR
) "ReqTools.prefs",
285 MUIA_PrefsEditor_IconTool
, (IPTR
) "SYS:Prefs/ReqTools",
291 GroupFrameT(__(MSG_GENERAL
)),
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()),
303 Child
, (colorwheelstyleobj
= ReqToolsEditor__Cycle(colorwheelstyle_labels
)),
307 GroupFrameT(__(MSG_FILEREQUESTER
)),
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()),
327 MUIA_Frame
, MUIV_Frame_Group
,
329 Child
, Label1(__(MSG_REQUESTER
)),
330 Child
, (defaultsforobj
= ReqToolsEditor__Cycle(defaultsfor_labels
)),
332 Child
, RectangleObject
,
333 MUIA_Background
, MUII_FILL
,
336 Child
, Label1(__(MSG_POSITION
)),
337 Child
, (positionobj
= ReqToolsEditor__Cycle(position_labels
)),
338 Child
, Label1(__(MSG_SIZE
)),
339 Child
, sizepercentobj
,
343 MUIA_FramePhantomHoriz
, TRUE
,
344 MUIA_Text_PreParse
, "\33r",
345 MUIA_Text_Contents
, __(MSG_OFFSET
),
349 MUIA_FramePhantomHoriz
, TRUE
,
350 MUIA_Text_Contents
, " ",
354 MUIA_FramePhantomHoriz
, TRUE
,
355 MUIA_Text_PreParse
, "\33r",
356 MUIA_Text_Contents
, __(MSG_NR_OF_ENTRIES
),
360 MUIA_FramePhantomHoriz
, TRUE
,
361 MUIA_Text_Contents
, " ",
367 Child
, (IPTR
)(offsetxobj
= StringObject
,
370 MUIA_CycleChain
, TRUE
,
371 MUIA_String_Accept
, (IPTR
)"0123456789",
372 MUIA_FixWidthTxt
, (IPTR
)"55555",
376 Child
, (IPTR
)(offsetyobj
= StringObject
,
379 MUIA_CycleChain
, TRUE
,
380 MUIA_String_Accept
, (IPTR
)"0123456789",
381 MUIA_FixWidthTxt
, (IPTR
)"55555",
384 Child
, Label1(__(MSG_MIN
)),
385 Child
, (IPTR
)(minvisobj
= StringObject
,
388 MUIA_CycleChain
, TRUE
,
389 MUIA_String_Accept
, (IPTR
)"0123456789",
390 MUIA_FixWidthTxt
, (IPTR
)"55555",
393 Child
, Label1(__(MSG_MAX
)),
394 Child
, (IPTR
)(maxvisobj
= StringObject
,
397 MUIA_CycleChain
, TRUE
,
398 MUIA_String_Accept
, (IPTR
)"0123456789",
399 MUIA_FixWidthTxt
, (IPTR
)"55555",
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
;
438 poptofrontobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
439 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
444 usesysfontobj
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
445 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
450 usefunckeysobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
451 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
456 colorwheelstyleobj
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
457 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
462 immediatesortobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
463 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
468 drawersfirstobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
469 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
474 drawersmixedobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
475 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
480 diskactivityobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
481 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
486 mmbobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
487 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
492 defaultsforobj
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
493 (IPTR
)defaultsforobj
, 3, MUIM_CallHook
, (IPTR
)&selectdefaultshook
, (IPTR
)data
498 positionobj
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
499 (IPTR
) self
, 3, MUIM_CallHook
, (IPTR
)&updatedefaultshook
, (IPTR
)data
504 sizepercentobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
505 (IPTR
) self
, 3, MUIM_CallHook
, (IPTR
)&updatedefaultshook
, (IPTR
)data
510 offsetxobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
511 (IPTR
) self
, 3, MUIM_CallHook
, (IPTR
)&updatedefaultshook
, (IPTR
)data
516 offsetyobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
517 (IPTR
) self
, 3, MUIM_CallHook
, (IPTR
)&updatedefaultshook
, (IPTR
)data
522 minvisobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
523 (IPTR
) self
, 3, MUIM_CallHook
, (IPTR
)&updatedefaultshook
, (IPTR
)data
528 maxvisobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
529 (IPTR
) self
, 3, MUIM_CallHook
, (IPTR
)&updatedefaultshook
, (IPTR
)data
532 ReqToolsPrefs2Gadgets(data
);
538 /*********************************************************************************************/
540 IPTR
ReqToolsEditor__MUIM_PrefsEditor_ImportFH (
541 Class
*CLASS
, Object
*self
,
542 struct MUIP_PrefsEditor_ImportFH
*message
548 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__
));
550 success
= Prefs_ImportFH(message
->fh
);
551 if (success
) ReqToolsPrefs2Gadgets(data
);
556 /*********************************************************************************************/
558 IPTR ReqToolsEditor__MUIM_PrefsEditor_ExportFH
560 Class
*CLASS
, Object
*self
,
561 struct MUIP_PrefsEditor_ExportFH
*message
567 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__
));
569 Gadgets2ReqToolsPrefs(data
);
570 success
= Prefs_ExportFH(message
->fh
);
575 /*********************************************************************************************/
577 IPTR ReqToolsEditor__MUIM_PrefsEditor_SetDefaults
579 Class
*CLASS
, Object
*self
, Msg message
585 D(bug("[ReqToolsEditor.class] %s()\n", __PRETTY_FUNCTION__
));
587 success
= Prefs_Default();
588 if (success
) ReqToolsPrefs2Gadgets(data
);
593 /*** Setup ******************************************************************/
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