fix remapping behavior. Remapping is only necessary if we are rendering on the workbe...
[AROS-Contrib.git] / scalos / Prefs / Menu / Menu.c
bloba2c996f05c6a923fcb5dcfd61c4f6c3a5316abcd
1 // Menu.c
2 // $Date$
3 // $Revision$
5 #include <stdlib.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include <ctype.h>
9 #include <exec/types.h>
10 #include <exec/memory.h>
11 #include <exec/ports.h>
12 #include <exec/io.h>
13 #include <exec/execbase.h>
14 #ifndef __amigaos4__
15 #endif
16 #include <dos/dos.h>
17 #include <libraries/dos.h>
18 #include <libraries/dosextens.h>
19 #include <libraries/gadtools.h>
20 #include <libraries/asl.h>
21 #include <libraries/mui.h>
22 #include <devices/clipboard.h>
23 #include <workbench/workbench.h>
24 #include <workbench/icon.h>
25 #include <intuition/intuition.h>
26 #include <intuition/classusr.h>
27 #include <prefs/prefhdr.h>
29 #include <clib/alib_protos.h>
31 #define __USE_SYSBASE
33 #include <proto/exec.h>
34 #include <proto/dos.h>
35 #include <proto/icon.h>
36 #include <proto/intuition.h>
37 #include <proto/gadtools.h>
38 #include <proto/utility.h>
39 #include <proto/asl.h>
40 #include <proto/muimaster.h>
41 #include <proto/locale.h>
42 #include <proto/scalosprefsplugin.h>
44 #include <defs.h>
45 #include <Year.h> // +jmc+
46 #include <scalosdebug.h>
48 #include <scalos/scalosprefsplugin.h>
49 #include <scalos/scalosmenuprefsplugin.h>
51 struct ScalosMenu_LocaleInfo
53 APTR li_LocaleBase;
54 APTR li_Catalog;
55 struct LocaleIFace *li_ILocale;
58 #define ScalosMenu_NUMBERS
59 #define ScalosMenu_ARRAY
60 #define ScalosMenu_CODE
61 #include STR(SCALOSLOCALE)
63 //----------------------------------------------------------------------------
65 // limits for various menu entries
66 #define MAX_MENU (NOMENU + 1)
67 #define MAX_MENUITEM (NOITEM + 1)
68 #define MAX_SUBITEM (NOSUB + 1)
70 #define Sizeof(array) (sizeof(array) / sizeof((array)[0]))
72 //----------------------------------------------------------------------------
74 #if !defined(__amigaos4__) && !defined(__AROS__)
75 #include <dos.h>
77 long _stack = 16384; // minimum stack size, used by SAS/C startup code
78 #endif
80 //----------------------------------------------------------------------------
82 // local data structures
84 #define KeyButtonHelp(name,key,HelpText)\
85 TextObject,\
86 ButtonFrame,\
87 MUIA_Font, MUIV_Font_Button,\
88 MUIA_Text_Contents, name,\
89 MUIA_Text_PreParse, "\33c",\
90 MUIA_Text_HiChar , key,\
91 MUIA_ControlChar , key,\
92 MUIA_CycleChain , TRUE, \
93 MUIA_InputMode , MUIV_InputMode_RelVerify,\
94 MUIA_Background , MUII_ButtonBack,\
95 MUIA_ShortHelp, HelpText,\
96 End
99 #define Application_Return_EDIT 0
100 #define Application_Return_USE 1001
101 #define Application_Return_SAVE 1002
103 //----------------------------------------------------------------------------
105 // local functions
107 static void init(void);
108 static void fail(APTR APP_Main, CONST_STRPTR str);
109 static BOOL OpenLibraries(void);
110 static void CloseLibraries(void);
111 static SAVEDS(APTR) INTERRUPT OpenAboutMUIFunc(struct Hook *hook, Object *o, Msg msg);
112 static STRPTR GetLocString(ULONG MsgId);
113 //static void TranslateStringArray(STRPTR *stringArray);
114 static struct MUI_CustomClass *OpenPrefsModule(CONST_STRPTR FileName);
115 static struct TagItem *CreatePluginSubWindowArray(void);
116 static void DisposePrefsPlugin(void);
117 static BOOL CheckMCCforPlugin(STRPTR *UsedClasses, size_t MaxUsedClasses);
118 static BOOL CheckMCCVersion(CONST_STRPTR name, ULONG minver, ULONG minrev);
119 #if !defined(__SASC) &&!defined(__MORPHOS__) && !defined(__amigaos4__)
120 size_t stccpy(char *dest, const char *src, size_t MaxLen);
121 #endif /* !defined(__SASC) &&!defined(__MORPHOS__) */
123 //----------------------------------------------------------------------------
125 // local data items
127 struct Library *MUIMasterBase;
128 T_LOCALEBASE LocaleBase;
129 struct Library *IconBase;
130 struct IntuitionBase *IntuitionBase;
131 struct Library *ScalosPrefsPluginBase;
133 #ifdef __amigaos4__
134 extern struct Library *SysBase;
135 struct MUIMasterIFace *IMUIMaster;
136 struct LocaleIFace *ILocale;
137 struct IconIFace *IIcon;
138 struct IntuitionIFace *IIntuition;
139 struct ScalosPrefsPluginIFace *IScalosPrefsPlugin;
140 #endif
142 static struct Catalog *MenuCatalog;
144 static struct Hook AboutMUIHook = { { NULL, NULL }, HOOKFUNC_DEF(OpenAboutMUIFunc), NULL };
146 static struct MUI_CustomClass *MenuPluginClass;
148 static struct TagItem *SubWindowTagList;
150 static APTR Group_Plugin;
151 static Object **PluginSubWindows;
152 static APTR APP_Main;
153 static APTR WIN_Main;
154 static APTR WIN_AboutMUI;
155 static APTR SaveButton, UseButton, CancelButton;
156 static APTR MenuOpen, MenuSaveAs, MenuAbout, MenuAboutMUI, MenuQuit;
157 static APTR MenuResetToDefaults, MenuLastSaved, MenuRestore;
158 static APTR MenuMerge, MenuImport, MenuImportTD, MenuImportP;
159 static APTR MenuCreateIcons;
160 static APTR MenuCollapseAll, MenuExpandAll;
162 //----------------------------------------------------------------------------
164 int main(int argc, char *argv[])
166 LONG Action = Application_Return_EDIT;
167 LONG win_opened = 0;
168 struct RDArgs *rdArgs = NULL;
169 CONST_STRPTR GivenFileName = NULL;
170 BPTR oldDir = (BPTR)NULL;
171 ULONG fCreateIcons = TRUE;
172 struct DiskObject *MenuDiskObject = NULL;
173 struct DiskObject *icon = NULL;
174 STRPTR ProgramName;
175 STRPTR UsedClasses[32];
176 struct WBStartup *WBenchMsg =
177 (argc == 0) ? (struct WBStartup *)argv : NULL;
179 init();
181 d1(kprintf(__FUNC__ "/%ld: \n", __LINE__));
183 if (WBenchMsg && WBenchMsg->sm_ArgList)
185 static char PrgNamePath[512];
186 struct WBArg *arg;
188 if (WBenchMsg->sm_NumArgs > 1)
190 arg = &WBenchMsg->sm_ArgList[1];
191 GivenFileName = arg->wa_Name;
193 else
195 arg = &WBenchMsg->sm_ArgList[0];
198 ProgramName = PrgNamePath;
200 NameFromLock(WBenchMsg->sm_ArgList[0].wa_Lock, PrgNamePath, sizeof(PrgNamePath));
201 AddPart(PrgNamePath, WBenchMsg->sm_ArgList[0].wa_Name, sizeof(PrgNamePath));
203 oldDir = CurrentDir(arg->wa_Lock);
205 icon = GetDiskObject(arg->wa_Name);
206 if (icon)
208 STRPTR tt;
210 tt = FindToolType(icon->do_ToolTypes, "CREATEICONS");
211 if (tt)
213 if (MatchToolValue(tt, "NO"))
214 fCreateIcons = FALSE;
217 tt = FindToolType(icon->do_ToolTypes, "ACTION");
218 if (tt)
220 if (MatchToolValue(tt, "EDIT"))
221 Action = Application_Return_EDIT;
222 if (MatchToolValue(tt, "USE"))
223 Action = Application_Return_USE;
224 if (MatchToolValue(tt, "SAVE"))
225 Action = Application_Return_SAVE;
230 else
232 SIPTR ArgArray[4];
234 ProgramName = argv[0];
236 memset(ArgArray, 0, sizeof(ArgArray));
238 rdArgs = ReadArgs("FROM,EDIT/S,USE/S,SAVE/S", ArgArray, NULL);
240 if (ArgArray[0])
241 GivenFileName = (CONST_STRPTR) ArgArray[0];
242 if (ArgArray[1])
243 Action = Application_Return_EDIT;
244 if (ArgArray[2])
245 Action = Application_Return_USE;
246 if (ArgArray[3])
247 Action = Application_Return_SAVE;
250 d1(kprintf(__FUNC__ "/%ld: MenuPluginClass=%08lx\n", __LINE__, MenuPluginClass));
252 if (NULL == MenuPluginClass)
253 fail(APP_Main, "Failed to open Menu Plugin.");
255 MenuDiskObject = GetDiskObject(ProgramName);
257 Group_Plugin = NewObject(MenuPluginClass->mcc_Class, 0,
258 MUIA_ScalosPrefs_CreateIcons, fCreateIcons,
259 MUIA_ScalosPrefs_ProgramName, (IPTR) ProgramName,
260 TAG_END);
262 d1(kprintf(__FUNC__ "/%ld: Group_Plugin=%08lx\n", __LINE__, Group_Plugin));
263 if (NULL == Group_Plugin)
264 fail(APP_Main, "Failed to create Group_Plugin.");
266 if (!CheckMCCforPlugin(UsedClasses, Sizeof(UsedClasses)))
267 fail(APP_Main, "Required MCC missing.");
269 SubWindowTagList = CreatePluginSubWindowArray();
271 d1(kprintf(__FUNC__ "/%ld: \n", __LINE__));
273 APP_Main = ApplicationObject,
274 MUIA_Application_Title, GetLocString(MSGID_TITLENAME),
275 MUIA_Application_Version, "$VER: Scalos Menu V40.20 (" __DATE__ ")" COMPILER_STRING,
276 MUIA_Application_Copyright, "The Scalos Team, 2000" CURRENTYEAR,
277 MUIA_Application_Author, "The Scalos Team",
278 MUIA_Application_Description, "Scalos Menu preferences editor",
279 MUIA_Application_Base, "SCALOS_MENU",
280 MenuDiskObject ? MUIA_Application_DiskObject : TAG_IGNORE, MenuDiskObject,
281 #if defined(MUIA_Application_UsedClasses)
282 MUIA_Application_UsedClasses, UsedClasses,
283 #endif /* MUIA_Application_UsedClasses */
285 SubWindow, WIN_Main = WindowObject,
286 MUIA_Window_Title, GetLocString(MSGID_TITLENAME),
287 MUIA_Window_ID, MAKE_ID('M','A','I','N'),
288 MUIA_Window_AppWindow, TRUE,
289 WindowContents, VGroup,
290 Child, Group_Plugin,
292 Child, ColGroup(3),
293 Child, SaveButton = KeyButtonHelp(GetLocString(MSGID_SAVENAME),
294 's', GetLocString(MSGID_SHORTHELP_SAVEBUTTON)),
295 Child, UseButton = KeyButtonHelp(GetLocString(MSGID_USENAME),
296 'u', GetLocString(MSGID_SHORTHELP_USEBUTTON)),
297 Child, CancelButton = KeyButtonHelp(GetLocString(MSGID_CANCELNAME),
298 'c', GetLocString(MSGID_SHORTHELP_CANCELBUTTON)),
299 End, //ColGroup(3)
300 End, //VGroup
301 End, //WindowObject
303 MUIA_Application_Menustrip, MenustripObject,
304 Child, MenuObjectT(GetLocString(MSGID_MENU_PROJECT)),
305 Child, MenuOpen = MenuitemObject,
306 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_PROJECT_OPEN),
307 MUIA_Menuitem_Shortcut, GetLocString(MSGID_MENU_PROJECT_OPEN_SHORT),
308 End,
309 Child, MenuMerge = MenuitemObject,
310 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_PROJECT_MERGE),
311 MUIA_Menuitem_Shortcut, GetLocString(MSGID_MENU_PROJECT_MERGE_SHORT),
312 End,
313 Child, MenuSaveAs = MenuitemObject,
314 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_PROJECT_SAVEAS),
315 MUIA_Menuitem_Shortcut, GetLocString(MSGID_MENU_PROJECT_SAVEAS_SHORT),
316 End,
317 Child, MenuitemObject,
318 MUIA_Menuitem_Title, -1,
319 End,
320 Child, MenuImport = MenuitemObject,
321 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_PROJECT_IMPORT),
322 Child, MenuImportTD = MenuitemObject,
323 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_PROJECT_IMPORT_TD),
324 MUIA_Menuitem_Shortcut, GetLocString(MSGID_MENU_PROJECT_IMPORT_TD_SHORT),
325 End,
326 Child, MenuImportP = MenuitemObject,
327 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_PROJECT_IMPORT_P),
328 MUIA_Menuitem_Shortcut, GetLocString(MSGID_MENU_PROJECT_IMPORT_P_SHORT),
329 End,
330 End,
331 Child, MenuitemObject,
332 MUIA_Menuitem_Title, -1,
333 End,
334 Child, MenuAbout = MenuitemObject,
335 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_PROJECT_ABOUT),
336 End,
337 Child, MenuAboutMUI = MenuitemObject,
338 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_PROJECT_ABOUTMUI),
339 End,
340 Child, MenuitemObject,
341 MUIA_Menuitem_Title, -1,
342 End,
343 Child, MenuQuit = MenuitemObject,
344 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_PROJECT_QUIT),
345 MUIA_Menuitem_Shortcut, GetLocString(MSGID_MENU_PROJECT_QUIT_SHORT),
346 End,
348 End, //MenuObjectT
349 Child, MenuObjectT(GetLocString(MSGID_MENU_EDIT)),
350 Child, MenuResetToDefaults = MenuitemObject,
351 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_EDIT_RESETTODEFAULTS),
352 MUIA_Menuitem_Shortcut, GetLocString(MSGID_MENU_EDIT_RESETTODEFAULTS_SHORT),
353 End,
354 Child, MenuLastSaved = MenuitemObject,
355 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_EDIT_LASTSAVED),
356 MUIA_Menuitem_Shortcut, GetLocString(MSGID_MENU_EDIT_LASTSAVED_SHORT),
357 End,
358 Child, MenuRestore = MenuitemObject,
359 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_EDIT_RESTORE),
360 MUIA_Menuitem_Shortcut, GetLocString(MSGID_MENU_EDIT_RESTORE_SHORT),
361 End,
362 Child, MenuitemObject,
363 MUIA_Menuitem_Title, -1,
364 End,
365 Child, MenuCollapseAll = MenuitemObject,
366 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_EDIT_COLLAPSEALL),
367 End,
368 Child, MenuExpandAll = MenuitemObject,
369 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_EDIT_EXPANDALL),
370 End,
371 End, //MenuObjectT
372 Child, MenuObjectT(GetLocString(MSGID_MENU_SETTINGS)),
373 Child, MenuCreateIcons = MenuitemObject,
374 MUIA_Menuitem_Title, GetLocString(MSGID_MENU_SETTINGS_CREATEICONS),
375 MUIA_Menuitem_Shortcut, GetLocString(MSGID_MENU_SETTINGS_CREATEICONS_SHORT),
376 MUIA_Menuitem_Checkit, TRUE,
377 MUIA_Menuitem_Checked, fCreateIcons,
378 End,
379 End, //MenuObjectT
380 End, //MenuStripObject
382 SubWindowTagList ? TAG_MORE : TAG_IGNORE, SubWindowTagList,
383 End; //ApplicationObject
385 d1(kprintf(__FUNC__ "/%ld: APP_Main=%08lx\n", __LINE__, APP_Main));
387 if (NULL == APP_Main)
389 MUI_DisposeObject(Group_Plugin);
390 Group_Plugin = NULL;
391 fail(APP_Main, "Failed to create Application.");
394 set(Group_Plugin, MUIA_ScalosPrefs_MainWindow, (IPTR) WIN_Main);
395 set(Group_Plugin, MUIA_ScalosPrefs_Application, (IPTR) APP_Main);
397 DoMethod(Group_Plugin, MUIM_ScalosPrefs_PageActive, TRUE);
399 DoMethod(WIN_Main, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
400 WIN_Main, 3, MUIM_Set, MUIA_Window_Open, FALSE);
401 DoMethod(WIN_Main, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
402 APP_Main, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
403 DoMethod(CancelButton, MUIM_Notify, MUIA_Pressed, FALSE,
404 APP_Main, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
406 DoMethod(MenuQuit, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
407 APP_Main, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
409 DoMethod(SaveButton, MUIM_Notify, MUIA_Pressed, FALSE,
410 APP_Main, 2, MUIM_Application_ReturnID, Application_Return_SAVE);
412 DoMethod(UseButton, MUIM_Notify,MUIA_Pressed, FALSE,
413 APP_Main, 2, MUIM_Application_ReturnID, Application_Return_USE);
415 DoMethod(MenuQuit, MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
416 APP_Main, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
418 DoMethod(MenuOpen, MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,
419 Group_Plugin, 1, MUIM_ScalosPrefs_OpenConfig);
421 DoMethod(MenuSaveAs, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
422 Group_Plugin, 1, MUIM_ScalosPrefs_SaveConfigAs);
424 DoMethod(MenuResetToDefaults, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
425 Group_Plugin, 1, MUIM_ScalosPrefs_ResetToDefaults);
427 DoMethod(MenuLastSaved, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
428 Group_Plugin, 1, MUIM_ScalosPrefs_LastSavedConfig);
430 DoMethod(MenuRestore, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
431 Group_Plugin, 1, MUIM_ScalosPrefs_RestoreConfig);
433 DoMethod(MenuAbout, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
434 Group_Plugin, 1, MUIM_ScalosPrefs_About);
436 DoMethod(MenuAboutMUI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
437 APP_Main, 2, MUIM_CallHook, &AboutMUIHook);
439 DoMethod(MenuImportTD, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
440 Group_Plugin, 1, MUIM_ScalosPrefs_MenuPrefs_ImportTD);
442 DoMethod(MenuImportP, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
443 Group_Plugin, 1, MUIM_ScalosPrefs_MenuPrefs_ImportP);
445 DoMethod(MenuMerge, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
446 Group_Plugin, 1, MUIM_ScalosPrefs_MenuPrefs_Merge);
448 DoMethod(MenuCollapseAll, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
449 Group_Plugin, 1, MUIM_ScalosPrefs_MenuPrefs_CollapseAll);
451 DoMethod(MenuExpandAll, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
452 Group_Plugin, 1, MUIM_ScalosPrefs_MenuPrefs_ExpandAll);
454 DoMethod(MenuCreateIcons, MUIM_Notify, MUIA_Menuitem_Checked, MUIV_EveryTime,
455 Group_Plugin, 3, MUIM_Set, MUIA_ScalosPrefs_CreateIcons, MUIV_TriggerValue);
457 if (icon)
459 DoMethod(Group_Plugin, MUIM_ScalosPrefs_ParseToolTypes, icon->do_ToolTypes);
462 if (GivenFileName)
464 DoMethod(Group_Plugin, MUIM_ScalosPrefs_LoadNamedConfig, GivenFileName);
466 else
468 DoMethod(Group_Plugin, MUIM_ScalosPrefs_LoadConfig);
471 if (Application_Return_EDIT == Action)
473 set(WIN_Main, MUIA_Window_Open, TRUE);
475 get(WIN_Main, MUIA_Window_Open, &win_opened);
477 if (win_opened)
479 ULONG sigs = 0;
480 BOOL Run = TRUE;
482 while (Run)
484 Action = DoMethod(APP_Main, MUIM_Application_NewInput, &sigs);
486 switch (Action)
488 case MUIV_Application_ReturnID_Quit:
489 case Application_Return_SAVE:
490 case Application_Return_USE:
491 Run = FALSE;
492 break;
495 if (Run && sigs)
497 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
499 if (sigs & SIGBREAKF_CTRL_C)
501 Run = FALSE;
502 break;
507 else
509 printf("failed to open main window !\n");
513 switch (Action)
515 case Application_Return_SAVE:
516 DoMethod(Group_Plugin, MUIM_ScalosPrefs_SaveConfig);
517 break;
518 case Application_Return_USE:
519 DoMethod(Group_Plugin, MUIM_ScalosPrefs_UseConfig);
520 break;
523 set(WIN_Main, MUIA_Window_Open, FALSE);
525 if (MenuDiskObject)
526 FreeDiskObject(MenuDiskObject);
527 if (oldDir)
528 CurrentDir(oldDir);
529 if (rdArgs)
530 FreeArgs(rdArgs);
531 if (icon)
532 FreeDiskObject(icon);
535 fail(APP_Main, NULL);
537 return 0;
541 static VOID fail(APTR APP_Main, CONST_STRPTR str)
543 if (APP_Main)
544 MUI_DisposeObject(APP_Main);
546 DisposePrefsPlugin();
548 if (MenuCatalog)
550 CloseCatalog(MenuCatalog);
551 MenuCatalog = NULL;
554 CloseLibraries();
556 if (str)
558 puts(str);
559 exit(20);
562 exit(0);
566 static void init(void)
568 if (!OpenLibraries())
569 fail(NULL, "Failed to open "MUIMASTER_NAME".");
571 if (LocaleBase)
572 MenuCatalog = OpenCatalogA(NULL, "Scalos/ScalosMenu.catalog", NULL);
574 MenuPluginClass = OpenPrefsModule("Menu.prefsplugin");
578 static BOOL OpenLibraries(void)
580 IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 39);
581 if (NULL == IntuitionBase)
582 return FALSE;
583 #ifdef __amigaos4__
584 IIntuition = (struct IntuitionIFace *)GetInterface((struct Library *)IntuitionBase, "main", 1, NULL);
585 if (NULL == IIntuition)
586 return FALSE;
587 #endif
589 MUIMasterBase = OpenLibrary("zune.library", 0);
590 if (NULL == MUIMasterBase)
591 MUIMasterBase = OpenLibrary(MUIMASTER_NAME, MUIMASTER_VMIN-1);
592 if (NULL == MUIMasterBase)
593 return FALSE;
594 #ifdef __amigaos4__
595 IMUIMaster = (struct MUIMasterIFace *)GetInterface((struct Library *)MUIMasterBase, "main", 1, NULL);
596 if (NULL == IMUIMaster)
597 return FALSE;
598 #endif
600 IconBase = OpenLibrary("icon.library", 0);
601 if (NULL == IconBase)
602 return FALSE;
603 #ifdef __amigaos4__
604 IIcon = (struct IconIFace *)GetInterface((struct Library *)IconBase, "main", 1, NULL);
605 if (NULL == IIcon)
606 return FALSE;
607 #endif
609 LocaleBase = (T_LOCALEBASE) OpenLibrary("locale.library", 39);
610 #ifdef __amigaos4__
611 if (LocaleBase)
612 ILocale = (struct LocaleIFace *)GetInterface((struct Library *)LocaleBase, "main", 1, NULL);
613 #endif
615 return TRUE;
619 static void CloseLibraries(void)
621 #ifdef __amigaos4__
622 if (ILocale)
624 DropInterface((struct Interface *)ILocale);
625 ILocale = NULL;
627 #endif
628 if (LocaleBase)
630 CloseLibrary((struct Library *) LocaleBase);
631 LocaleBase = NULL;
633 #ifdef __amigaos4__
634 if (IIcon)
636 DropInterface((struct Interface *)IIcon);
637 IIcon = NULL;
639 #endif
640 if (IconBase)
642 CloseLibrary(IconBase);
643 IconBase = NULL;
645 #ifdef __amigaos4__
646 if (IMUIMaster)
648 DropInterface((struct Interface *)IMUIMaster);
649 IMUIMaster = NULL;
651 #endif
652 if (MUIMasterBase)
654 CloseLibrary(MUIMasterBase);
655 MUIMasterBase = NULL;
657 #ifdef __amigaos4__
658 if (IIntuition)
660 DropInterface((struct Interface *)IIntuition);
661 IIntuition = NULL;
663 #endif
664 if (IntuitionBase)
666 CloseLibrary((struct Library *) IntuitionBase);
667 IntuitionBase = NULL;
671 //----------------------------------------------------------------------------
673 static STRPTR GetLocString(ULONG MsgId)
675 struct ScalosMenu_LocaleInfo li;
677 li.li_Catalog = MenuCatalog;
678 #ifndef __amigaos4__
679 li.li_LocaleBase = LocaleBase;
680 #else
681 li.li_ILocale = ILocale;
682 #endif
684 return (STRPTR) GetScalosMenuString(&li, MsgId);
687 static void TranslateStringArray(STRPTR *stringArray)
689 while (*stringArray)
691 *stringArray = GetLocString((IPTR) *stringArray);
692 stringArray++;
696 //----------------------------------------------------------------------------
698 static SAVEDS(APTR) INTERRUPT OpenAboutMUIFunc(struct Hook *hook, Object *o, Msg msg)
700 if (NULL == WIN_AboutMUI)
702 WIN_AboutMUI = MUI_NewObject(MUIC_Aboutmui,
703 MUIA_Window_RefWindow, WIN_Main,
704 MUIA_Aboutmui_Application, APP_Main,
705 End;
708 if (WIN_AboutMUI)
709 set(WIN_AboutMUI, MUIA_Window_Open, TRUE);
711 return 0;
714 //----------------------------------------------------------------------------
716 static struct MUI_CustomClass *OpenPrefsModule(CONST_STRPTR FileName)
718 struct MUI_CustomClass *pclass = NULL;
720 d1(kprintf(__FUNC__ "/%ld: FileName=<%s>\n", __LINE__, FileName));
722 do {
723 ScalosPrefsPluginBase = OpenLibrary(FileName, 0);
724 d1(kprintf(__FUNC__ "/%ld: ScalosPrefsPluginBase=%08lx\n", __LINE__, ScalosPrefsPluginBase));
725 if (NULL == ScalosPrefsPluginBase)
726 break;
727 #ifdef __amigaos4__
728 IScalosPrefsPlugin = (struct ScalosPrefsPluginIFace *)GetInterface(
729 ScalosPrefsPluginBase, "main", 1, NULL
731 #endif
733 pclass = (struct MUI_CustomClass *) SCAGetPrefsInfo(SCAPREFSINFO_GetClass);
734 d1(kprintf(__FUNC__ "/%ld: PluginClass=%08lx\n", __LINE__, pclass));
735 if (NULL == pclass)
736 break;
737 } while (0);
739 if (NULL == pclass)
740 DisposePrefsPlugin();
742 return pclass;
746 static struct TagItem *CreatePluginSubWindowArray(void)
748 struct TagItem *SubWindowTagList;
749 struct TagItem *ti;
750 ULONG SubWindowCount = 0;
751 ULONG n;
753 d1(kprintf(__FUNC__ "/%ld: \n", __LINE__));
755 PluginSubWindows = (Object **) DoMethod(Group_Plugin, MUIM_ScalosPrefs_CreateSubWindows);
757 d1(kprintf(__FUNC__ "/%ld: PluginSubWindows=%08lx\n", __LINE__, PluginSubWindows));
759 for (n=0; PluginSubWindows && PluginSubWindows[n]; n++)
760 SubWindowCount++;
762 d1(kprintf(__FUNC__ "/%ld: SubWindowCount=%lu\n", __LINE__, SubWindowCount));
764 SubWindowTagList = ti = calloc(1 + SubWindowCount, sizeof(struct TagItem));
766 d1(kprintf(__FUNC__ "/%ld: SubWindowTagList=%08lx\n", __LINE__, SubWindowTagList));
767 if (NULL == SubWindowTagList)
768 return NULL;
770 for (n=0; PluginSubWindows && PluginSubWindows[n]; n++)
772 ti->ti_Tag = MUIA_Application_Window;
773 ti->ti_Data = (IPTR) PluginSubWindows[n];
774 ti++;
777 ti->ti_Tag = TAG_END;
779 d1(kprintf(__FUNC__ "/%ld: SubWindowTagList=%08lx\n", __LINE__, SubWindowTagList));
781 return SubWindowTagList;
785 static void DisposePrefsPlugin(void)
787 #ifdef __amiagos4__
788 if (IScalosPrefsPlugin)
790 DropInterface((struct Interface *)IScalosPrefsPlugin);
791 IScalosPrefsPlugin = NULL;
793 #endif
794 if (ScalosPrefsPluginBase)
796 d1(kprintf(__FUNC__ "/%ld: Plugin=<%s> OpenCount=%ld\n", \
797 __LINE__, ScalosPrefsPluginBase->lib_Node.ln_Name, ScalosPrefsPluginBase->lib_OpenCnt));
799 if (NULL == Group_Plugin)
800 CloseLibrary(ScalosPrefsPluginBase);
801 ScalosPrefsPluginBase = NULL;
805 static BOOL CheckMCCforPlugin(STRPTR *UsedClasses, size_t MaxUsedClasses)
807 const struct MUIP_ScalosPrefs_MCCList *RequiredMccList = NULL;
809 RequiredMccList = (const struct MUIP_ScalosPrefs_MCCList *) DoMethod(Group_Plugin, MUIM_ScalosPrefs_GetListOfMCCs);
811 while (RequiredMccList && RequiredMccList->MccName)
813 if (!CheckMCCVersion(RequiredMccList->MccName,
814 RequiredMccList->MccMinVersion,
815 RequiredMccList->MccMinRevision))
816 return FALSE;
818 if (MaxUsedClasses > 1)
820 *UsedClasses++ = (STRPTR) RequiredMccList->MccName;
821 MaxUsedClasses--;
824 RequiredMccList++;
827 *UsedClasses = NULL;
829 return TRUE;
832 //----------------------------------------------------------------------------
834 // Checks if a certain version of a MCC is available
835 static BOOL CheckMCCVersion(CONST_STRPTR name, ULONG minver, ULONG minrev)
837 BOOL flush = TRUE;
839 d1(kprintf(__FILE__ "/" __FUNC__ "/%ld: %s ", name, __LINE__);)
841 while (1)
843 ULONG ver = 0;
844 ULONG rev = 0;
845 struct Library *base;
846 char libname[256];
848 // First we attempt to acquire the version and revision through MUI
849 Object *obj = MUI_NewObject((STRPTR) name, TAG_DONE);
850 if (obj)
852 get(obj, MUIA_Version, &ver);
853 get(obj, MUIA_Revision, &rev);
855 MUI_DisposeObject(obj);
857 if(ver > minver || (ver == minver && rev >= minrev))
859 d1(kprintf(__FILE__ "/" __FUNC__ "/%ld: v%ld.%ld found through MUIA_Version/Revision\n", __LINE__, ver, rev);)
860 return TRUE;
864 // If we did't get the version we wanted, let's try to open the
865 // libraries ourselves and see what happens...
866 stccpy(libname, "PROGDIR:mui", sizeof(libname));
867 AddPart(libname, name, sizeof(libname));
869 if ((base = OpenLibrary(&libname[8], 0)) || (base = OpenLibrary(&libname[0], 0)))
871 UWORD OpenCnt = base->lib_OpenCnt;
873 ver = base->lib_Version;
874 rev = base->lib_Revision;
876 CloseLibrary(base);
878 // we add some additional check here so that eventual broken .mcc also have
879 // a chance to pass this test (i.e. Toolbar.mcc is broken)
880 if (ver > minver || (ver == minver && rev >= minrev))
882 d1(kprintf(__FILE__ "/" __FUNC__ "/%ld: v%ld.%ld found through OpenLibrary()\n", __LINE__, ver, rev);)
883 return TRUE;
886 if (OpenCnt > 1)
888 if (MUI_Request(NULL, NULL, 0L, GetLocString(MSGID_STARTUP_FAILURE),
889 GetLocString(MSGID_STARTUP_RETRY_QUIT_GAD), GetLocString(MSGID_STARTUP_MCC_IN_USE),
890 (IPTR) name, minver, minrev, ver, rev))
892 flush = TRUE;
894 else
895 break;
898 // Attempt to flush the library if open count is 0 or because the
899 // user wants to retry (meaning there's a chance that it's 0 now)
901 if (flush)
903 struct Library *result;
905 Forbid();
906 if ((result = (struct Library *) FindName(&((struct ExecBase *)SysBase)->LibList, name)))
907 RemLibrary(result);
908 Permit();
909 flush = FALSE;
911 else
913 d1(kprintf(__FILE__ "/" __FUNC__ "/%ld: couldn`t find minimum required version.\n", __LINE__);)
915 // We're out of luck - open count is 0, we've tried to flush
916 // and still haven't got the version we want
917 // MUI_RequestA
918 if (MUI_Request(NULL, NULL, 0L, GetLocString(MSGID_STARTUP_FAILURE),
919 GetLocString(MSGID_STARTUP_RETRY_QUIT_GAD), GetLocString(MSGID_STARTUP_OLD_MCC),
920 (IPTR) name, minver, minrev, ver, rev))
922 flush = TRUE;
924 else
925 break;
928 else
930 // No MCC at all - no need to attempt flush
931 flush = FALSE;
932 if (!MUI_Request(NULL, NULL, 0L, GetLocString(MSGID_STARTUP_FAILURE),
933 GetLocString(MSGID_STARTUP_RETRY_QUIT_GAD), GetLocString(MSGID_STARTUP_MCC_NOT_FOUND),
934 (IPTR) name, minver, minrev))
936 break;
941 return FALSE;
944 //----------------------------------------------------------------------------
946 #if !defined(__SASC) && !defined(__amigaos4__)
947 // Replacement for SAS/C library functions
949 #if !defined(__MORPHOS__)
950 // Replacement for SAS/C library functions
952 size_t stccpy(char *dest, const char *src, size_t MaxLen)
954 size_t Count = 0;
956 while (*src && MaxLen > 1)
958 *dest++ = *src++;
959 MaxLen--;
960 Count++;
962 *dest = '\0';
963 Count++;
965 return Count;
967 #endif /*__MORPHOS__*/
969 #endif /* !defined(__SASC) && !defined(__amigaos4__) */
970 //-----------------------------------------------------------------------------