2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
9 /*********************************************************************************************/
16 #include <aros/debug.h>
18 /*********************************************************************************************/
20 #include <zune/prefswindow.h>
22 #include "menupopup3d_image.c"
23 #include "menupopupclassic_image.c"
24 #include "menupulldown3d_image.c"
25 #include "menupulldownclassic_image.c"
27 #if MENUPOPUP3D_PACKED
28 static UBYTE menupopup3d_imagedata
[MENUPOPUP3D_WIDTH
* MENUPOPUP3D_HEIGHT
];
30 #define menupopup3d_imagedata menupopup3d_data
33 #if MENUPOPUPCLASSIC_PACKED
34 static UBYTE menupopupclassic_imagedata
[MENUPOPUPCLASSIC_WIDTH
* MENUPOPUPCLASSIC_HEIGHT
];
36 #define menupopupclassic_imagedata menupopupclassic_data
39 #if MENUPULLDOWN3D_PACKED
40 static UBYTE menupulldown3d_imagedata
[MENUPULLDOWN3D_WIDTH
* MENUPULLDOWN3D_HEIGHT
];
42 #define menupulldown3d_imagedata menupulldown3d_data
45 #if MENUPULLDOWNCLASSIC_PACKED
46 static UBYTE menupulldownclassic_imagedata
[MENUPULLDOWNCLASSIC_WIDTH
* MENUPULLDOWNCLASSIC_HEIGHT
];
48 #define menupulldownclassic_imagedata menupulldownclassic_data
51 /*********************************************************************************************/
53 #define IPWindowObject BOOPSIOBJMACRO_START(IPWindow_CLASS->mcc_Class)
55 #define MUIM_IPWindow_Open (TAG_USER | 0x20000000)
56 #define MUIM_IPWindow_SaveAs (TAG_USER | 0x20000001)
57 #define MUIM_IPWindow_Default (TAG_USER | 0x20000002)
58 #define MUIM_IPWindow_LastSaved (TAG_USER | 0x20000003)
60 /*********************************************************************************************/
71 /*********************************************************************************************/
73 static struct MUI_CustomClass
*IPWindow_CLASS
;
74 static struct Hook previewhook
;
75 static STRPTR menutype_labels
[3], menulook_labels
[3];
76 static WORD imagetransparray
[4];
78 /*********************************************************************************************/
80 #if MENUPOPUP3D_PACKED || MENUPOPUPCLASSIC_PACKED ||MENUPULLDOWN3D_PACKED || MENUPULLDOWNCLASSIC_PACKED
82 static UBYTE
*unpack_byterun1(UBYTE
*source
, UBYTE
*dest
, LONG unpackedsize
)
89 c
= (BYTE
)(*source
++);
95 if (--unpackedsize
<= 0) return source
;
106 if (--unpackedsize
<= 0) return source
;
115 /*********************************************************************************************/
119 struct IControlPrefs
*prefs
, struct IPWindow_DATA
*data
124 get(data
->menutypeobj
, MUIA_Cycle_Active
, &active
);
127 prefs
->ic_Flags
&= ~ICF_POPUPMENUS
;
131 prefs
->ic_Flags
|= ICF_POPUPMENUS
;
134 get(data
->menulookobj
, MUIA_Cycle_Active
, &active
);
137 prefs
->ic_Flags
&= ~ICF_3DMENUS
;
141 prefs
->ic_Flags
|= ICF_3DMENUS
;
144 get(data
->offscreenobj
, MUIA_Selected
, &active
);
147 prefs
->ic_Flags
&= ~ICF_OFFSCREENLAYERS
;
151 prefs
->ic_Flags
|= ICF_OFFSCREENLAYERS
;
154 get(data
->defpubscrobj
, MUIA_Selected
, &active
);
157 prefs
->ic_Flags
&= ~ICF_DEFPUBSCREEN
;
161 prefs
->ic_Flags
|= ICF_DEFPUBSCREEN
;
164 prefs
->ic_Flags
|= ICF_AVOIDWINBORDERERASE
;
169 /*********************************************************************************************/
173 struct IPWindow_DATA
*data
, struct IControlPrefs
*prefs
176 set(data
->menutypeobj
, MUIA_Cycle_Active
, (prefs
->ic_Flags
& ICF_POPUPMENUS
) ? 1 : 0);
177 set(data
->menulookobj
, MUIA_Cycle_Active
, (prefs
->ic_Flags
& ICF_3DMENUS
) ? 1 : 0);
178 set(data
->offscreenobj
, MUIA_Selected
, (prefs
->ic_Flags
& ICF_OFFSCREENLAYERS
) ? 1 : 0);
179 set(data
->defpubscrobj
, MUIA_Selected
, (prefs
->ic_Flags
& ICF_DEFPUBSCREEN
) ? 1 : 0);
183 /*********************************************************************************************/
185 IPTR IPWindow__OM_NEW
187 Class
*CLASS
, Object
*self
, struct opSet
*message
190 struct IPWindow_DATA
*data
= NULL
;
191 Object
*menu
, *previewpage
, *menutypeobj
, *menulookobj
;
192 Object
*offscreenobj
;
193 Object
*defpubscrobj
;
195 extern struct NewMenu nm
[];
197 menu
= MUI_MakeObject(MUIO_MenustripNM
, nm
, 0);
200 WARNING: All Prefs structs must be initialized at this point!
203 menutype_labels
[0] = MSG(MSG_MENUS_TYPE_PULLDOWN
);
204 menutype_labels
[1] = MSG(MSG_MENUS_TYPE_POPUP
);
206 menulook_labels
[0] = MSG(MSG_MENUS_LOOK_CLASSIC
);
207 menulook_labels
[1] = MSG(MSG_MENUS_LOOK_3D
);
209 self
= (Object
*) DoSuperNewTags
213 MUIA_Window_Title
, (IPTR
)MSG(MSG_WINTITLE
),
214 MUIA_Window_Activate
, TRUE
,
215 MUIA_Window_ID
, MAKE_ID('I','C','T','L'),
217 menu
? MUIA_Window_Menustrip
: TAG_IGNORE
, (IPTR
)menu
,
219 WindowContents
, (IPTR
)HGroup
,
222 GroupFrameT(MSG(MSG_MENUS_GROUP
)),
224 Child
, Label1(MSG(MSG_MENUS_TYPE
)),
225 Child
, menutypeobj
= MUI_MakeObject(MUIO_Cycle
, NULL
, menutype_labels
),
226 Child
, Label1(MSG(MSG_MENUS_LOOK
)),
227 Child
, menulookobj
= MUI_MakeObject(MUIO_Cycle
, NULL
, menulook_labels
),
230 Child
, previewpage
= PageGroup
,
232 MUIA_Background
, (IPTR
)"2:6c6c6c6c,6a6a6a6a,b5b5b5b5",
233 Child
, ChunkyImageObject
,
234 MUIA_ChunkyImage_Pixels
, (IPTR
)menupulldownclassic_imagedata
,
235 MUIA_ChunkyImage_Palette
, (IPTR
)menupulldownclassic_pal
,
236 MUIA_ChunkyImage_NumColors
, MENUPULLDOWNCLASSIC_COLORS
,
237 MUIA_Bitmap_Width
, MENUPULLDOWNCLASSIC_WIDTH
,
238 MUIA_Bitmap_Height
, MENUPULLDOWNCLASSIC_HEIGHT
,
239 MUIA_FixWidth
, MENUPULLDOWNCLASSIC_WIDTH
,
240 MUIA_FixHeight
, MENUPULLDOWNCLASSIC_HEIGHT
,
241 MUIA_Bitmap_UseFriend
, TRUE
,
242 MUIA_Bitmap_Transparent
, imagetransparray
[0],
244 Child
, ChunkyImageObject
,
245 MUIA_ChunkyImage_Pixels
, (IPTR
)menupulldown3d_imagedata
,
246 MUIA_ChunkyImage_Palette
, (IPTR
)menupulldown3d_pal
,
247 MUIA_ChunkyImage_NumColors
, MENUPULLDOWN3D_COLORS
,
248 MUIA_Bitmap_Width
, MENUPULLDOWN3D_WIDTH
,
249 MUIA_Bitmap_Height
, MENUPULLDOWN3D_HEIGHT
,
250 MUIA_FixWidth
, MENUPULLDOWN3D_WIDTH
,
251 MUIA_FixHeight
, MENUPULLDOWN3D_HEIGHT
,
252 MUIA_Bitmap_UseFriend
, TRUE
,
253 MUIA_Bitmap_Transparent
, imagetransparray
[1],
255 Child
, ChunkyImageObject
,
256 MUIA_ChunkyImage_Pixels
, (IPTR
)menupopupclassic_imagedata
,
257 MUIA_ChunkyImage_Palette
, (IPTR
)menupopupclassic_pal
,
258 MUIA_ChunkyImage_NumColors
, MENUPOPUPCLASSIC_COLORS
,
259 MUIA_Bitmap_Width
, MENUPOPUPCLASSIC_WIDTH
,
260 MUIA_Bitmap_Height
, MENUPOPUPCLASSIC_HEIGHT
,
261 MUIA_FixWidth
, MENUPOPUPCLASSIC_WIDTH
,
262 MUIA_FixHeight
, MENUPOPUPCLASSIC_HEIGHT
,
263 MUIA_Bitmap_UseFriend
, TRUE
,
264 MUIA_Bitmap_Transparent
, imagetransparray
[2],
266 Child
, ChunkyImageObject
,
267 MUIA_ChunkyImage_Pixels
, (IPTR
)menupopup3d_imagedata
,
268 MUIA_ChunkyImage_Palette
, (IPTR
)menupopup3d_pal
,
269 MUIA_ChunkyImage_NumColors
, MENUPOPUP3D_COLORS
,
270 MUIA_Bitmap_Width
, MENUPOPUP3D_WIDTH
,
271 MUIA_Bitmap_Height
, MENUPOPUP3D_HEIGHT
,
272 MUIA_FixWidth
, MENUPOPUP3D_WIDTH
,
273 MUIA_FixHeight
, MENUPOPUP3D_HEIGHT
,
274 MUIA_Bitmap_UseFriend
, TRUE
,
275 MUIA_Bitmap_Transparent
, imagetransparray
[3],
281 GroupFrameT(MSG(MSG_WINDOWS
)),
285 Child
, Label1(MSG(MSG_OFFSCREEN_MOVE
)),
286 Child
, offscreenobj
= MUI_MakeObject(MUIO_Checkmark
,
293 GroupFrameT(MSG(MSG_SCREENS
)),
297 Child
, Label1(MSG(MSG_FRONTMOST_DEFAULT
)),
298 Child
, defpubscrobj
= MUI_MakeObject(MUIO_Checkmark
,
309 if (self
== NULL
) goto error
;
311 data
= INST_DATA(CLASS
, self
);
312 data
->menutypeobj
= menutypeobj
;
313 data
->menulookobj
= menulookobj
;
314 data
->offscreenobj
= offscreenobj
;
315 set(data
->offscreenobj
, MUIA_ShortHelp
,
316 (IPTR
)MSG(MSG_OFFSCREEN_DESC
));
317 data
->defpubscrobj
= defpubscrobj
;
318 set(data
->defpubscrobj
, MUIA_ShortHelp
,
319 (IPTR
)MSG(MSG_FRONTMOST_DEFAULT_DESC
));
321 DoMethod(menutypeobj
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
322 (IPTR
)previewpage
, 3, MUIM_CallHook
, (IPTR
)&previewhook
, (IPTR
)data
);
323 DoMethod(menulookobj
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
324 (IPTR
)previewpage
, 3, MUIM_CallHook
, (IPTR
)&previewhook
, (IPTR
)data
);
326 Prefs2Gadgets(data
, &icontrolprefs
);
335 /*********************************************************************************************/
337 IPTR IPWindow__MUIM_PrefsWindow_Test
339 Class
*CLASS
, Object
*self
, Msg message
342 struct IPWindow_DATA
*data
= INST_DATA(CLASS
, self
);
344 Gadgets2Prefs(&icontrolprefs
, data
);
345 SavePrefs(CONFIGNAME_ENV
);
352 /*********************************************************************************************/
354 IPTR IPWindow__MUIM_PrefsWindow_Revert
356 Class
*CLASS
, Object
*self
, Msg message
359 struct IPWindow_DATA
*data
= INST_DATA(CLASS
, self
);
362 Prefs2Gadgets(data
, &icontrolprefs
);
363 SavePrefs(CONFIGNAME_ENV
);
368 /*********************************************************************************************/
370 IPTR IPWindow__MUIM_PrefsWindow_Save
372 Class
*CLASS
, Object
*self
, Msg message
375 struct IPWindow_DATA
*data
= INST_DATA(CLASS
, self
);
377 Gadgets2Prefs(&icontrolprefs
, data
);
378 SavePrefs(CONFIGNAME_ENVARC
);
379 SavePrefs(CONFIGNAME_ENV
);
381 SetAttrs(self
, MUIA_Window_Open
, FALSE
, TAG_DONE
);
382 DoMethod(_app(self
), MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
387 /*********************************************************************************************/
389 IPTR IPWindow__MUIM_PrefsWindow_Use
391 Class
*CLASS
, Object
*self
, Msg message
394 struct IPWindow_DATA
*data
= INST_DATA(CLASS
, self
);
396 Gadgets2Prefs(&icontrolprefs
, data
);
397 SavePrefs(CONFIGNAME_ENV
);
399 SetAttrs(self
, MUIA_Window_Open
, FALSE
, TAG_DONE
);
400 DoMethod(_app(self
), MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
405 /*********************************************************************************************/
407 IPTR IPWindow__MUIM_PrefsWindow_Cancel
409 Class
*CLASS
, Object
*self
, Msg message
412 struct IPWindow_DATA
*data
= INST_DATA(CLASS
, self
);
417 SavePrefs(CONFIGNAME_ENV
);
420 SetAttrs(self
, MUIA_Window_Open
, FALSE
, TAG_DONE
);
421 DoMethod(_app(self
), MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
426 /*********************************************************************************************/
428 IPTR IPWindow__MUIM_IPWindow_Open
430 Class
*CLASS
, Object
*self
, Msg message
433 struct IPWindow_DATA
*data
= INST_DATA(CLASS
, self
);
436 if ((filename
= GetFile(MSG(MSG_ASL_OPEN_TITLE
), "SYS:Prefs/Presets", FALSE
)))
438 if (LoadPrefs(filename
))
440 Prefs2Gadgets(data
, &icontrolprefs
);
447 /*********************************************************************************************/
449 IPTR IPWindow__MUIM_IPWindow_SaveAs
451 Class
*CLASS
, Object
*self
, Msg message
456 if ((filename
= GetFile(MSG(MSG_ASL_SAVE_TITLE
), "SYS:Prefs/Presets", TRUE
)))
464 /*********************************************************************************************/
466 IPTR IPWindow__MUIM_IPWindow_Default
468 Class
*CLASS
, Object
*self
, Msg message
471 struct IPWindow_DATA
*data
= INST_DATA(CLASS
, self
);
474 Prefs2Gadgets(data
, &icontrolprefs
);
479 /*********************************************************************************************/
481 IPTR IPWindow__MUIM_IPWindow_LastSaved
483 Class
*CLASS
, Object
*self
, Msg message
486 struct IPWindow_DATA
*data
= INST_DATA(CLASS
, self
);
488 if (LoadPrefs(CONFIGNAME_ENVARC
))
490 Prefs2Gadgets(data
, &icontrolprefs
);
496 /*********************************************************************************************/
498 BOOPSI_DISPATCHER(IPTR
, IPWindow_Dispatcher
, CLASS
, self
, message
)
500 switch (message
->MethodID
)
503 return IPWindow__OM_NEW(CLASS
, self
, (struct opSet
*) message
);
505 case MUIM_PrefsWindow_Test
:
506 return IPWindow__MUIM_PrefsWindow_Test(CLASS
, self
, message
);
508 case MUIM_PrefsWindow_Revert
:
509 return IPWindow__MUIM_PrefsWindow_Revert(CLASS
, self
, message
);
511 case MUIM_PrefsWindow_Save
:
512 return IPWindow__MUIM_PrefsWindow_Save(CLASS
, self
, message
);
514 case MUIM_PrefsWindow_Use
:
515 return IPWindow__MUIM_PrefsWindow_Use(CLASS
, self
, message
);
517 case MUIM_PrefsWindow_Cancel
:
518 return IPWindow__MUIM_PrefsWindow_Cancel(CLASS
, self
, message
);
520 case MUIM_IPWindow_Open
:
521 return IPWindow__MUIM_IPWindow_Open(CLASS
, self
, message
);
523 case MUIM_IPWindow_SaveAs
:
524 return IPWindow__MUIM_IPWindow_SaveAs(CLASS
, self
, message
);
526 case MUIM_IPWindow_Default
:
527 return IPWindow__MUIM_IPWindow_Default(CLASS
, self
, message
);
529 case MUIM_IPWindow_LastSaved
:
530 return IPWindow__MUIM_IPWindow_LastSaved(CLASS
, self
, message
);
533 return DoSuperMethodA(CLASS
, self
, message
);
538 BOOPSI_DISPATCHER_END
540 /*********************************************************************************************/
542 static BOOL
IPWindow_Initialize()
544 IPWindow_CLASS
= MUI_CreateCustomClass
546 NULL
, MUIC_PrefsWindow
, NULL
,
547 sizeof(struct IPWindow_DATA
), IPWindow_Dispatcher
550 if (IPWindow_CLASS
!= NULL
)
555 /*********************************************************************************************/
557 static void IPWindow_Deinitialize()
559 if (IPWindow_CLASS
) MUI_DeleteCustomClass(IPWindow_CLASS
);
562 /*********************************************************************************************/
564 static void InitImagePal(ULONG
*pal
, WORD numcols
, WORD index
)
568 imagetransparray
[index
] = -1;
569 for(i
= 0; i
< numcols
; i
++)
571 if ((pal
[i
] & 0xFCFCFC) == 0xFC00FC)
573 imagetransparray
[index
] = i
;
576 ((UBYTE
*)pal
)[i
* 3 + 0] = pal
[i
] >> 16;
577 ((UBYTE
*)pal
)[i
* 3 + 1] = pal
[i
] >> 8;
578 ((UBYTE
*)pal
)[i
* 3 + 2] = pal
[i
];
583 /*********************************************************************************************/
585 static void InitImages(void)
587 #if MENUPOPUP3D_PACKED
588 unpack_byterun1(menupopup3d_data
, menupopup3d_imagedata
, sizeof(menupopup3d_imagedata
));
591 #if MENUPOPUPCLASSIC_PACKED
592 unpack_byterun1(menupopupclassic_data
, menupopupclassic_imagedata
, sizeof(menupopupclassic_imagedata
));
595 #if MENUPULLDOWN3D_PACKED
596 unpack_byterun1(menupulldown3d_data
, menupulldown3d_imagedata
, sizeof(menupulldown3d_imagedata
));
599 #if MENUPULLDOWNCLASSIC_PACKED
600 unpack_byterun1(menupulldownclassic_data
, menupulldownclassic_imagedata
, sizeof(menupulldownclassic_imagedata
));
603 InitImagePal(menupulldownclassic_pal
, MENUPULLDOWNCLASSIC_COLORS
, 0);
604 InitImagePal(menupulldown3d_pal
, MENUPULLDOWN3D_COLORS
, 1);
605 InitImagePal(menupopupclassic_pal
, MENUPOPUPCLASSIC_COLORS
, 2);
606 InitImagePal(menupopup3d_pal
, MENUPOPUP3D_COLORS
, 3);
610 /*********************************************************************************************/
612 static void PreviewFunc(struct Hook
*hook
, Object
*previewpage
, struct IPWindow_DATA
**data
)
616 get((*data
)->menutypeobj
, MUIA_Cycle_Active
, &type
);
617 get((*data
)->menulookobj
, MUIA_Cycle_Active
, &look
);
619 nnset(previewpage
, MUIA_Group_ActivePage
, type
* 2 + look
);
622 /*********************************************************************************************/
626 if (!IPWindow_Initialize()) Cleanup(MSG(MSG_CANT_CREATE_CUSTOM_CLASS
));
630 previewhook
.h_Entry
= HookEntry
;
631 previewhook
.h_SubEntry
= (HOOKFUNC
)PreviewFunc
;
633 app
= ApplicationObject
,
634 MUIA_Application_Title
, (IPTR
)"IControl",
635 MUIA_Application_Version
, (IPTR
)VERSIONSTR
,
636 MUIA_Application_Copyright
, (IPTR
)"Copyright © 1995-2006, The AROS Development Team",
637 MUIA_Application_Author
, (IPTR
)"The AROS Development Team",
638 MUIA_Application_Description
, (IPTR
)MSG(MSG_WINTITLE
),
639 MUIA_Application_Base
, (IPTR
)"ICONTROL",
640 MUIA_Application_SingleTask
, TRUE
,
641 SubWindow
, (IPTR
) (wnd
= NewObject(IPWindow_CLASS
->mcc_Class
, NULL
, TAG_DONE
)),
647 D(bug("icontrol: Can't create application"));
650 Cleanup(MSG(MSG_CANT_CREATE_APP
));
654 DoMethod(wnd
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
, (IPTR
) app
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
656 DoMethod(wnd
, MUIM_Notify
, MUIA_Window_MenuAction
, MSG_MEN_PROJECT_OPEN
, (IPTR
) wnd
, 1, MUIM_IPWindow_Open
);
657 DoMethod(wnd
, MUIM_Notify
, MUIA_Window_MenuAction
, MSG_MEN_PROJECT_SAVEAS
, (IPTR
) wnd
, 1, MUIM_IPWindow_SaveAs
);
658 DoMethod(wnd
, MUIM_Notify
, MUIA_Window_MenuAction
, MSG_MEN_PROJECT_QUIT
, (IPTR
) app
, 2, MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
659 DoMethod(wnd
, MUIM_Notify
, MUIA_Window_MenuAction
, MSG_MEN_EDIT_DEFAULT
, (IPTR
) wnd
, 1, MUIM_IPWindow_Default
);
660 DoMethod(wnd
, MUIM_Notify
, MUIA_Window_MenuAction
, MSG_MEN_EDIT_LASTSAVED
, (IPTR
) wnd
, 1, MUIM_IPWindow_LastSaved
);
661 DoMethod(wnd
, MUIM_Notify
, MUIA_Window_MenuAction
, MSG_MEN_EDIT_RESTORE
, (IPTR
) wnd
, 1, MUIM_PrefsWindow_Revert
);
665 /*********************************************************************************************/
670 IPWindow_Deinitialize();