added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / prefs / icontrol / gui.c
blob14d77ec7b833692c79b036945faa84c0c537df13
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*********************************************************************************************/
11 #include "global.h"
12 #include "version.h"
14 #include <string.h>
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];
29 #else
30 #define menupopup3d_imagedata menupopup3d_data
31 #endif
33 #if MENUPOPUPCLASSIC_PACKED
34 static UBYTE menupopupclassic_imagedata[MENUPOPUPCLASSIC_WIDTH * MENUPOPUPCLASSIC_HEIGHT];
35 #else
36 #define menupopupclassic_imagedata menupopupclassic_data
37 #endif
39 #if MENUPULLDOWN3D_PACKED
40 static UBYTE menupulldown3d_imagedata[MENUPULLDOWN3D_WIDTH * MENUPULLDOWN3D_HEIGHT];
41 #else
42 #define menupulldown3d_imagedata menupulldown3d_data
43 #endif
45 #if MENUPULLDOWNCLASSIC_PACKED
46 static UBYTE menupulldownclassic_imagedata[MENUPULLDOWNCLASSIC_WIDTH * MENUPULLDOWNCLASSIC_HEIGHT];
47 #else
48 #define menupulldownclassic_imagedata menupulldownclassic_data
49 #endif
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 /*********************************************************************************************/
62 struct IPWindow_DATA
64 Object *menutypeobj;
65 Object *menulookobj;
66 Object *offscreenobj;
67 Object *defpubscrobj;
68 BOOL tested;
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)
84 UBYTE r;
85 BYTE c;
87 for(;;)
89 c = (BYTE)(*source++);
90 if (c >= 0)
92 while(c-- >= 0)
94 *dest++ = *source++;
95 if (--unpackedsize <= 0) return source;
98 else if (c != -128)
100 c = -c;
101 r = *source++;
103 while(c-- >= 0)
105 *dest++ = r;
106 if (--unpackedsize <= 0) return source;
113 #endif
115 /*********************************************************************************************/
117 BOOL Gadgets2Prefs
119 struct IControlPrefs *prefs, struct IPWindow_DATA *data
122 IPTR active;
124 get(data->menutypeobj, MUIA_Cycle_Active, &active);
125 if (active == 0)
127 prefs->ic_Flags &= ~ICF_POPUPMENUS;
129 else
131 prefs->ic_Flags |= ICF_POPUPMENUS;
134 get(data->menulookobj, MUIA_Cycle_Active, &active);
135 if (active == 0)
137 prefs->ic_Flags &= ~ICF_3DMENUS;
139 else
141 prefs->ic_Flags |= ICF_3DMENUS;
144 get(data->offscreenobj, MUIA_Selected, &active);
145 if (active == 0)
147 prefs->ic_Flags &= ~ICF_OFFSCREENLAYERS;
149 else
151 prefs->ic_Flags |= ICF_OFFSCREENLAYERS;
154 get(data->defpubscrobj, MUIA_Selected, &active);
155 if (active == 0)
157 prefs->ic_Flags &= ~ICF_DEFPUBSCREEN;
159 else
161 prefs->ic_Flags |= ICF_DEFPUBSCREEN;
164 prefs->ic_Flags |= ICF_AVOIDWINBORDERERASE;
166 return TRUE;
169 /*********************************************************************************************/
171 BOOL Prefs2Gadgets
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);
180 return TRUE;
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
211 CLASS, self, NULL,
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,
220 Child, (IPTR)VGroup,
221 MUIA_Weight, 0,
222 GroupFrameT(MSG(MSG_MENUS_GROUP)),
223 Child, ColGroup(2),
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),
228 End,
229 Child, VSpace(1),
230 Child, previewpage = PageGroup,
231 //ImageButtonFrame,
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],
243 End,
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],
254 End,
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],
265 End,
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],
276 End,
277 End,
278 End,
279 Child, VGroup,
280 Child, VGroup,
281 GroupFrameT(MSG(MSG_WINDOWS)),
282 Child, VSpace(0),
283 Child, ColGroup(4),
284 Child, HSpace(0),
285 Child, Label1(MSG(MSG_OFFSCREEN_MOVE)),
286 Child, offscreenobj = MUI_MakeObject(MUIO_Checkmark,
287 NULL),
288 Child, HSpace(0),
289 End,
290 Child, VSpace(0),
291 End,
292 Child, VGroup,
293 GroupFrameT(MSG(MSG_SCREENS)),
294 Child, VSpace(0),
295 Child, ColGroup(4),
296 Child, HSpace(0),
297 Child, Label1(MSG(MSG_FRONTMOST_DEFAULT)),
298 Child, defpubscrobj = MUI_MakeObject(MUIO_Checkmark,
299 NULL),
300 Child, HSpace(0),
301 End,
302 Child, VSpace(0),
303 End,
304 End,
305 End,
306 TAG_DONE
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);
328 return (IPTR) self;
330 error:
332 return 0;
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);
347 data->tested = TRUE;
349 return 0;
352 /*********************************************************************************************/
354 IPTR IPWindow__MUIM_PrefsWindow_Revert
356 Class *CLASS, Object *self, Msg message
359 struct IPWindow_DATA *data = INST_DATA(CLASS, self);
361 RestorePrefs();
362 Prefs2Gadgets(data, &icontrolprefs);
363 SavePrefs(CONFIGNAME_ENV);
365 return 0;
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);
384 return 0;
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);
402 return 0;
405 /*********************************************************************************************/
407 IPTR IPWindow__MUIM_PrefsWindow_Cancel
409 Class *CLASS, Object *self, Msg message
412 struct IPWindow_DATA *data = INST_DATA(CLASS, self);
414 if (data->tested)
416 RestorePrefs();
417 SavePrefs(CONFIGNAME_ENV);
420 SetAttrs(self, MUIA_Window_Open, FALSE, TAG_DONE);
421 DoMethod(_app(self), MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
423 return 0;
426 /*********************************************************************************************/
428 IPTR IPWindow__MUIM_IPWindow_Open
430 Class *CLASS, Object *self, Msg message
433 struct IPWindow_DATA *data = INST_DATA(CLASS, self);
434 STRPTR filename;
436 if ((filename = GetFile(MSG(MSG_ASL_OPEN_TITLE), "SYS:Prefs/Presets", FALSE)))
438 if (LoadPrefs(filename))
440 Prefs2Gadgets(data, &icontrolprefs);
444 return 0;
447 /*********************************************************************************************/
449 IPTR IPWindow__MUIM_IPWindow_SaveAs
451 Class *CLASS, Object *self, Msg message
454 STRPTR filename;
456 if ((filename = GetFile(MSG(MSG_ASL_SAVE_TITLE), "SYS:Prefs/Presets", TRUE)))
458 SavePrefs(filename);
461 return 0;
464 /*********************************************************************************************/
466 IPTR IPWindow__MUIM_IPWindow_Default
468 Class *CLASS, Object *self, Msg message
471 struct IPWindow_DATA *data = INST_DATA(CLASS, self);
473 DefaultPrefs();
474 Prefs2Gadgets(data, &icontrolprefs);
476 return 0;
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);
493 return 0;
496 /*********************************************************************************************/
498 BOOPSI_DISPATCHER(IPTR, IPWindow_Dispatcher, CLASS, self, message)
500 switch (message->MethodID)
502 case OM_NEW:
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);
532 default:
533 return DoSuperMethodA(CLASS, self, message);
536 return 0;
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)
551 return TRUE;
552 else
553 return FALSE;
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)
566 WORD i;
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));
589 #endif
591 #if MENUPOPUPCLASSIC_PACKED
592 unpack_byterun1(menupopupclassic_data, menupopupclassic_imagedata, sizeof(menupopupclassic_imagedata));
593 #endif
595 #if MENUPULLDOWN3D_PACKED
596 unpack_byterun1(menupulldown3d_data, menupulldown3d_imagedata, sizeof(menupulldown3d_imagedata));
597 #endif
599 #if MENUPULLDOWNCLASSIC_PACKED
600 unpack_byterun1(menupulldownclassic_data, menupulldownclassic_imagedata, sizeof(menupulldownclassic_imagedata));
601 #endif
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)
614 IPTR type, look;
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 /*********************************************************************************************/
624 void MakeGUI(void)
626 if (!IPWindow_Initialize()) Cleanup(MSG(MSG_CANT_CREATE_CUSTOM_CLASS));
628 InitImages();
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)),
642 End;
644 if (!app)
646 #if 1
647 D(bug("icontrol: Can't create application"));
648 Cleanup(NULL);
649 #else
650 Cleanup(MSG(MSG_CANT_CREATE_APP));
651 #endif
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 /*********************************************************************************************/
667 void KillGUI(void)
669 DisposeObject(app);
670 IPWindow_Deinitialize();