2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
9 #include <aros/debug.h>
11 #include <devices/rawkeycodes.h>
12 #include <mui/HotkeyString_mcc.h>
13 #include <zune/prefseditor.h>
14 #include <zune/customclasses.h>
16 #include <proto/alib.h>
17 #include <proto/commodities.h>
18 #include <proto/intuition.h>
19 #include <proto/muimaster.h>
20 #include <proto/alib.h>
25 #include "icontroleditor.h"
29 #include "menupopup3d_image.c"
30 #include "menupopupclassic_image.c"
31 #include "menupulldown3d_image.c"
32 #include "menupulldownclassic_image.c"
34 #if MENUPOPUP3D_PACKED
35 static UBYTE menupopup3d_imagedata
[MENUPOPUP3D_WIDTH
* MENUPOPUP3D_HEIGHT
];
37 #define menupopup3d_imagedata menupopup3d_data
40 #if MENUPOPUPCLASSIC_PACKED
41 static UBYTE menupopupclassic_imagedata
[MENUPOPUPCLASSIC_WIDTH
* MENUPOPUPCLASSIC_HEIGHT
];
43 #define menupopupclassic_imagedata menupopupclassic_data
46 #if MENUPULLDOWN3D_PACKED
47 static UBYTE menupulldown3d_imagedata
[MENUPULLDOWN3D_WIDTH
* MENUPULLDOWN3D_HEIGHT
];
49 #define menupulldown3d_imagedata menupulldown3d_data
52 #if MENUPULLDOWNCLASSIC_PACKED
53 static UBYTE menupulldownclassic_imagedata
[MENUPULLDOWNCLASSIC_WIDTH
* MENUPULLDOWNCLASSIC_HEIGHT
];
55 #define menupulldownclassic_imagedata menupulldownclassic_data
58 /*********************************************************************************************/
60 struct IControlEditor_DATA
65 Object
*menutitlepullobj
;
68 Object
*scrleftdragobj
;
69 Object
*scrrightdragobj
;
70 Object
*scrtopdragobj
;
71 Object
*scrbotdragobj
;
76 /*********************************************************************************************/
78 #define SETUP_INST_DATA struct IControlEditor_DATA *data = INST_DATA(CLASS, self)
80 /*********************************************************************************************/
82 static struct Hook previewhook
;
83 static CONST_STRPTR menutype_labels
[3], menulook_labels
[3];
84 static WORD imagetransparray
[4];
86 /*********************************************************************************************/
88 static void InitImagePal(const ULONG
*pal
, WORD numcols
, WORD index
)
92 imagetransparray
[index
] = -1;
93 for(i
= 0; i
< numcols
; i
++)
95 if ((pal
[i
] & 0xFCFCFC) == 0xFC00FC)
97 imagetransparray
[index
] = i
;
100 ((UBYTE
*)pal
)[i
* 3 + 0] = pal
[i
] >> 16;
101 ((UBYTE
*)pal
)[i
* 3 + 1] = pal
[i
] >> 8;
102 ((UBYTE
*)pal
)[i
* 3 + 2] = pal
[i
];
106 /*********************************************************************************************/
108 #if MENUPOPUP3D_PACKED || MENUPOPUPCLASSIC_PACKED ||MENUPULLDOWN3D_PACKED || MENUPULLDOWNCLASSIC_PACKED
110 static const UBYTE
*unpack_byterun1(const UBYTE
*source
, UBYTE
*dest
, LONG unpackedsize
)
117 c
= (BYTE
)(*source
++);
123 if (--unpackedsize
<= 0) return source
;
134 if (--unpackedsize
<= 0) return source
;
142 /*********************************************************************************************/
144 static void InitImages(void)
146 #if MENUPOPUP3D_PACKED
147 unpack_byterun1(menupopup3d_data
, menupopup3d_imagedata
, sizeof(menupopup3d_imagedata
));
150 #if MENUPOPUPCLASSIC_PACKED
151 unpack_byterun1(menupopupclassic_data
, menupopupclassic_imagedata
, sizeof(menupopupclassic_imagedata
));
154 #if MENUPULLDOWN3D_PACKED
155 unpack_byterun1(menupulldown3d_data
, menupulldown3d_imagedata
, sizeof(menupulldown3d_imagedata
));
158 #if MENUPULLDOWNCLASSIC_PACKED
159 unpack_byterun1(menupulldownclassic_data
, menupulldownclassic_imagedata
, sizeof(menupulldownclassic_imagedata
));
162 InitImagePal(menupulldownclassic_pal
, MENUPULLDOWNCLASSIC_COLORS
, 0);
163 InitImagePal(menupulldown3d_pal
, MENUPULLDOWN3D_COLORS
, 1);
164 InitImagePal(menupopupclassic_pal
, MENUPOPUPCLASSIC_COLORS
, 2);
165 InitImagePal(menupopup3d_pal
, MENUPOPUP3D_COLORS
, 3);
169 /*********************************************************************************************/
171 static void SetPreviewImage(Object
*previewpage
, struct IControlEditor_DATA
**data
)
176 GET((*data
)->menutypeobj
, MUIA_Cycle_Active
, &type
);
177 SET((*data
)->menutitlepullobj
, MUIA_Disabled
, (type
== 0) ? TRUE
: FALSE
);
178 GET((*data
)->menulookobj
, MUIA_Cycle_Active
, &look
);
180 NNSET(previewpage
, MUIA_Group_ActivePage
, type
* 2 + look
);
183 /*********************************************************************************************/
185 static void PreviewFunc(struct Hook
*hook
, Object
*previewpage
, struct IControlEditor_DATA
**data
)
187 SetPreviewImage(previewpage
, data
);
190 /*********************************************************************************************/
192 BOOL
Gadgets2IControlPrefs(struct IControlEditor_DATA
*data
)
194 struct IControlPrefs
*prefs
= &icontrolprefs
;
198 struct InputXpression ix
= {IX_VERSION
, 0};
200 // Clear options we are about to set..
201 prefs
->ic_Flags
&= ~(ICF_POPUPMENUS
| ICF_3DMENUS
| ICF_PULLDOWNTITLEMENUS
| ICF_STICKYMENUS
| ICF_OFFSCREENLAYERS
| ICF_DEFPUBSCREEN
);
203 GET(data
->menutypeobj
, MUIA_Cycle_Active
, &active
);
206 prefs
->ic_Flags
|= ICF_POPUPMENUS
;
207 GET(data
->menutitlepullobj
, MUIA_Selected
, &active
);
209 prefs
->ic_Flags
|= ICF_PULLDOWNTITLEMENUS
;
212 GET(data
->menulookobj
, MUIA_Cycle_Active
, &active
);
214 prefs
->ic_Flags
|= ICF_3DMENUS
;
216 GET(data
->menustickobj
, MUIA_Selected
, &active
);
218 prefs
->ic_Flags
|= ICF_STICKYMENUS
;
220 GET(data
->offscreenobj
, MUIA_Selected
, &active
);
222 prefs
->ic_Flags
|= ICF_OFFSCREENLAYERS
;
224 GET(data
->defpubscrobj
, MUIA_Selected
, &active
);
226 prefs
->ic_Flags
|= ICF_DEFPUBSCREEN
;
228 prefs
->ic_VDragModes
[0] = 0;
229 GET(data
->scrleftdragobj
, MUIA_Selected
, &active
);
231 prefs
->ic_VDragModes
[0] |= ICVDM_LBOUND
;
232 GET(data
->scrrightdragobj
, MUIA_Selected
, &active
);
234 prefs
->ic_VDragModes
[0] |= ICVDM_RBOUND
;
235 GET(data
->scrtopdragobj
, MUIA_Selected
, &active
);
237 prefs
->ic_VDragModes
[0] |= ICVDM_TBOUND
;
238 GET(data
->scrbotdragobj
, MUIA_Selected
, &active
);
240 prefs
->ic_VDragModes
[0] |= ICVDM_BBOUND
;
242 GET(data
->metadragobj
, MUIA_String_Contents
, &key
);
243 if (!ParseIX(key
, &ix
))
244 prefs
->ic_MetaDrag
= ix
.ix_Qualifier
;
246 prefs
->ic_Flags
|= ICF_AVOIDWINBORDERERASE
;
251 /*********************************************************************************************/
253 BOOL
IControlPrefs2Gadgets(struct IControlEditor_DATA
*data
)
255 struct IControlPrefs
*prefs
= &icontrolprefs
;
257 struct InputXpression ix
=
268 NNSET(data
->menutypeobj
, MUIA_Cycle_Active
, (prefs
->ic_Flags
& ICF_POPUPMENUS
) ? 1 : 0);
269 NNSET(data
->menutitlepullobj
, MUIA_Selected
, (prefs
->ic_Flags
& ICF_PULLDOWNTITLEMENUS
) ? 1 : 0);
270 SET(data
->menutitlepullobj
, MUIA_Disabled
, (prefs
->ic_Flags
& ICF_POPUPMENUS
) ? FALSE
: TRUE
);
271 NNSET(data
->menulookobj
, MUIA_Cycle_Active
, (prefs
->ic_Flags
& ICF_3DMENUS
) ? 1 : 0);
272 NNSET(data
->menustickobj
, MUIA_Selected
, (prefs
->ic_Flags
& ICF_STICKYMENUS
) ? 1 : 0);
273 NNSET(data
->offscreenobj
, MUIA_Selected
, (prefs
->ic_Flags
& ICF_OFFSCREENLAYERS
) ? 1 : 0);
274 NNSET(data
->defpubscrobj
, MUIA_Selected
, (prefs
->ic_Flags
& ICF_DEFPUBSCREEN
) ? 1 : 0);
275 NNSET(data
->scrleftdragobj
, MUIA_Selected
, prefs
->ic_VDragModes
[0] & ICVDM_LBOUND
);
276 NNSET(data
->scrrightdragobj
, MUIA_Selected
, prefs
->ic_VDragModes
[0] & ICVDM_RBOUND
);
277 NNSET(data
->scrtopdragobj
, MUIA_Selected
, prefs
->ic_VDragModes
[0] & ICVDM_TBOUND
);
278 NNSET(data
->scrbotdragobj
, MUIA_Selected
, prefs
->ic_VDragModes
[0] & ICVDM_BBOUND
);
280 ix
.ix_Qualifier
= prefs
->ic_MetaDrag
;
281 NNSET(data
->metadragobj
, MUIA_HotkeyString_IX
, &ix
);
283 SetPreviewImage(data
->previewpage
, &data
);
288 /*********************************************************************************************/
290 IPTR IControlEditor__OM_NEW
292 Class
*CLASS
, Object
*self
, struct opSet
*message
295 struct IControlEditor_DATA
*data
= NULL
;
296 Object
*previewpage
, *menutypeobj
, *menulookobj
;
297 Object
*menustickobj
, *menutitlepullobj
;
298 Object
*offscreenobj
;
299 Object
*defpubscrobj
;
300 Object
*scrleftdragobj
, *scrrightdragobj
, *scrtopdragobj
, *scrbotdragobj
;
305 previewhook
.h_Entry
= HookEntry
;
306 previewhook
.h_SubEntry
= (HOOKFUNC
)PreviewFunc
;
309 WARNING: All Prefs structs must be initialized at this point!
312 menutype_labels
[0] = _(MSG_MENUS_TYPE_PULLDOWN
);
313 menutype_labels
[1] = _(MSG_MENUS_TYPE_POPUP
);
315 menulook_labels
[0] = _(MSG_MENUS_LOOK_CLASSIC
);
316 menulook_labels
[1] = _(MSG_MENUS_LOOK_3D
);
318 D(bug("Creating window object...\n"));
320 self
= (Object
*) DoSuperNewTags
324 MUIA_PrefsEditor_Name
, __(MSG_WINTITLE
),
325 MUIA_PrefsEditor_Path
, (IPTR
) "SYS/icontrol.prefs",
326 MUIA_PrefsEditor_IconTool
, (IPTR
) "SYS:Prefs/IControl",
331 GroupFrameT(_(MSG_MENUS_GROUP
)),
333 Child
, Label1(_(MSG_MENUS_TYPE
)),
334 Child
, menutypeobj
= MUI_MakeObject(MUIO_Cycle
, NULL
, menutype_labels
),
335 Child
, Label1(_(MSG_MENUS_LOOK
)),
336 Child
, menulookobj
= MUI_MakeObject(MUIO_Cycle
, NULL
, menulook_labels
),
340 Child
, Label1(_(MSG_MENUS_STICKY
)),
341 Child
, menustickobj
= MUI_MakeObject(MUIO_Checkmark
, NULL
),
342 Child
, Label1(_(MSG_MENUS_TITLEPOPUP
)),
343 Child
, menutitlepullobj
= MUI_MakeObject(MUIO_Checkmark
, NULL
),
346 Child
, previewpage
= PageGroup
,
348 MUIA_Background
, (IPTR
)"2:6c6c6c6c,6a6a6a6a,b5b5b5b5",
349 Child
, ChunkyImageObject
,
350 MUIA_ChunkyImage_Pixels
, (IPTR
)menupulldownclassic_imagedata
,
351 MUIA_ChunkyImage_Palette
, (IPTR
)menupulldownclassic_pal
,
352 MUIA_ChunkyImage_NumColors
, MENUPULLDOWNCLASSIC_COLORS
,
353 MUIA_Bitmap_Width
, MENUPULLDOWNCLASSIC_WIDTH
,
354 MUIA_Bitmap_Height
, MENUPULLDOWNCLASSIC_HEIGHT
,
355 MUIA_FixWidth
, MENUPULLDOWNCLASSIC_WIDTH
,
356 MUIA_FixHeight
, MENUPULLDOWNCLASSIC_HEIGHT
,
357 MUIA_Bitmap_UseFriend
, TRUE
,
358 MUIA_Bitmap_Transparent
, imagetransparray
[0],
360 Child
, ChunkyImageObject
,
361 MUIA_ChunkyImage_Pixels
, (IPTR
)menupulldown3d_imagedata
,
362 MUIA_ChunkyImage_Palette
, (IPTR
)menupulldown3d_pal
,
363 MUIA_ChunkyImage_NumColors
, MENUPULLDOWN3D_COLORS
,
364 MUIA_Bitmap_Width
, MENUPULLDOWN3D_WIDTH
,
365 MUIA_Bitmap_Height
, MENUPULLDOWN3D_HEIGHT
,
366 MUIA_FixWidth
, MENUPULLDOWN3D_WIDTH
,
367 MUIA_FixHeight
, MENUPULLDOWN3D_HEIGHT
,
368 MUIA_Bitmap_UseFriend
, TRUE
,
369 MUIA_Bitmap_Transparent
, imagetransparray
[1],
371 Child
, ChunkyImageObject
,
372 MUIA_ChunkyImage_Pixels
, (IPTR
)menupopupclassic_imagedata
,
373 MUIA_ChunkyImage_Palette
, (IPTR
)menupopupclassic_pal
,
374 MUIA_ChunkyImage_NumColors
, MENUPOPUPCLASSIC_COLORS
,
375 MUIA_Bitmap_Width
, MENUPOPUPCLASSIC_WIDTH
,
376 MUIA_Bitmap_Height
, MENUPOPUPCLASSIC_HEIGHT
,
377 MUIA_FixWidth
, MENUPOPUPCLASSIC_WIDTH
,
378 MUIA_FixHeight
, MENUPOPUPCLASSIC_HEIGHT
,
379 MUIA_Bitmap_UseFriend
, TRUE
,
380 MUIA_Bitmap_Transparent
, imagetransparray
[2],
382 Child
, ChunkyImageObject
,
383 MUIA_ChunkyImage_Pixels
, (IPTR
)menupopup3d_imagedata
,
384 MUIA_ChunkyImage_Palette
, (IPTR
)menupopup3d_pal
,
385 MUIA_ChunkyImage_NumColors
, MENUPOPUP3D_COLORS
,
386 MUIA_Bitmap_Width
, MENUPOPUP3D_WIDTH
,
387 MUIA_Bitmap_Height
, MENUPOPUP3D_HEIGHT
,
388 MUIA_FixWidth
, MENUPOPUP3D_WIDTH
,
389 MUIA_FixHeight
, MENUPOPUP3D_HEIGHT
,
390 MUIA_Bitmap_UseFriend
, TRUE
,
391 MUIA_Bitmap_Transparent
, imagetransparray
[3],
397 GroupFrameT(_(MSG_WINDOWS
)),
401 Child
, Label1(_(MSG_OFFSCREEN_MOVE
)),
402 Child
, offscreenobj
= MUI_MakeObject(MUIO_Checkmark
, NULL
),
408 GroupFrameT(_(MSG_SCREENS
)),
411 Child
, Label1(_(MSG_FRONTMOST_DEFAULT
)),
413 Child
, defpubscrobj
= MUI_MakeObject(MUIO_Checkmark
, NULL
),
416 Child
, Label1(_(MSG_BOUND_LEFT_DRAG
)),
418 Child
, scrleftdragobj
= MUI_MakeObject(MUIO_Checkmark
, NULL
),
421 Child
, Label1(_(MSG_BOUND_RIGHT_DRAG
)),
423 Child
, scrrightdragobj
= MUI_MakeObject(MUIO_Checkmark
, NULL
),
426 Child
, Label1(_(MSG_BOUND_TOP_DRAG
)),
428 Child
, scrtopdragobj
= MUI_MakeObject(MUIO_Checkmark
, NULL
),
431 Child
, Label1(_(MSG_BOUND_BOTTOM_DRAG
)),
433 Child
, scrbotdragobj
= MUI_MakeObject(MUIO_Checkmark
, NULL
),
436 Child
, Label1(_(MSG_META_DRAG
)),
437 Child
, metadragobj
= MUI_NewObject("HotkeyString.mcc",
438 MUIA_Frame
, MUIV_Frame_String
,
448 D(bug("Created prefs window object 0x%p\n", self
));
450 if (self
== NULL
) goto error
;
452 data
= INST_DATA(CLASS
, self
);
453 data
->menutypeobj
= menutypeobj
;
454 data
->menulookobj
= menulookobj
;
455 data
->menustickobj
= menustickobj
;
456 data
->menutitlepullobj
= menutitlepullobj
;
457 data
->offscreenobj
= offscreenobj
;
458 SET(data
->offscreenobj
, MUIA_ShortHelp
, __(MSG_OFFSCREEN_DESC
));
459 data
->defpubscrobj
= defpubscrobj
;
460 data
->scrleftdragobj
= scrleftdragobj
;
461 data
->scrrightdragobj
= scrrightdragobj
;
462 data
->scrtopdragobj
= scrtopdragobj
;
463 data
->scrbotdragobj
= scrbotdragobj
;
464 data
->metadragobj
= metadragobj
;
465 data
->previewpage
= previewpage
;
466 SET(data
->defpubscrobj
, MUIA_ShortHelp
, __(MSG_FRONTMOST_DEFAULT_DESC
));
470 menutypeobj
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
471 (IPTR
)previewpage
, 3, MUIM_CallHook
, (IPTR
)&previewhook
, (IPTR
)data
476 menulookobj
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
477 (IPTR
)previewpage
, 3, MUIM_CallHook
, (IPTR
)&previewhook
, (IPTR
)data
482 menutypeobj
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
483 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
488 menulookobj
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
489 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
494 menustickobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
495 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
500 menutitlepullobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
501 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
506 offscreenobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
507 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
512 defpubscrobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
513 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
518 scrleftdragobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
519 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
524 scrrightdragobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
525 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
530 scrtopdragobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
531 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
536 scrbotdragobj
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
537 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
540 // FIXME: MUIA_String_Acknowledge doesn't work and
541 // MUIA_String_Contents sets MUIA_PrefsEditor_Changed immediately
544 metadragobj
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
545 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
548 IControlPrefs2Gadgets(data
);
557 /*********************************************************************************************/
559 IPTR
IControlEditor__MUIM_PrefsEditor_ImportFH (
560 Class
*CLASS
, Object
*self
,
561 struct MUIP_PrefsEditor_ImportFH
*message
567 D(bug("[icontroleditor class] IControlEditor Class Import\n"));
569 success
= Prefs_ImportFH(message
->fh
);
570 if (success
) IControlPrefs2Gadgets(data
);
575 /*********************************************************************************************/
577 IPTR IControlEditor__MUIM_PrefsEditor_ExportFH
579 Class
*CLASS
, Object
*self
,
580 struct MUIP_PrefsEditor_ExportFH
*message
586 D(bug("[icontroleditor class] IControlEditor Class Export\n"));
588 Gadgets2IControlPrefs(data
);
589 success
= Prefs_ExportFH(message
->fh
);
594 /*********************************************************************************************/
596 IPTR IControlEditor__MUIM_PrefsEditor_SetDefaults
598 Class
*CLASS
, Object
*self
, Msg message
604 D(bug("[icontroleditor class] IControlEditor Class SetDefaults\n"));
606 success
= Prefs_Default();
607 if (success
) IControlPrefs2Gadgets(data
);
612 /*** Setup ******************************************************************/
615 IControlEditor
, NULL
, MUIC_PrefsEditor
, NULL
,
616 OM_NEW
, struct opSet
*,
617 MUIM_PrefsEditor_ImportFH
, struct MUIP_PrefsEditor_ImportFH
*,
618 MUIM_PrefsEditor_ExportFH
, struct MUIP_PrefsEditor_ExportFH
*,
619 MUIM_PrefsEditor_SetDefaults
, Msg