Initial import of Scalos. To decrease size I have
[AROS-Contrib.git] / scalos / Plugins / Prefs / Menu / MenuPrefs.c
blob2f9acc3f2128eed1883365cb5214fd49b7a00e42
1 // MenuPrefs.c
2 // $Date$
3 // $Revision$
5 #ifdef __AROS__
6 #define MUIMASTER_YES_INLINE_STDARG
7 #endif
9 #include <stdlib.h>
10 #include <string.h>
11 #include <stdio.h>
12 #include <stddef.h>
13 #include <ctype.h>
14 #include <dos/dos.h>
15 #include <exec/types.h>
16 #include <exec/memory.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 <libraries/iffparse.h>
23 #include <devices/clipboard.h>
24 #include <utility/utility.h>
25 #include <workbench/workbench.h>
26 #include <workbench/icon.h>
27 #include <intuition/intuition.h>
28 #include <intuition/classusr.h>
29 #include <graphics/gfxmacros.h>
30 #include <prefs/prefhdr.h>
32 #include <clib/alib_protos.h>
34 #define __USE_SYSBASE
36 #include <proto/exec.h>
37 #include <proto/dos.h>
38 #include <proto/icon.h>
39 #include <proto/graphics.h>
40 #include <proto/intuition.h>
41 #include <proto/gadtools.h>
42 #include <proto/utility.h>
43 #include <proto/asl.h>
44 #include <proto/locale.h>
45 #include <proto/iffparse.h>
47 #ifndef __AROS__
48 #define NO_INLINE_STDARG
49 #endif
51 #include <proto/muimaster.h>
53 #include <mui/NListview_mcc.h>
54 #include <mui/NListtree_mcc.h>
55 #include <mui/Lamp_mcc.h>
56 #include <scalos/scalosprefsplugin.h>
57 #include <scalos/scalosmenuprefsplugin.h>
58 #include <defs.h>
59 #include <Year.h>
61 #include "MenuPrefs.h"
62 #include "DataTypesMCC.h"
64 #define ScalosMenu_NUMBERS
65 #define ScalosMenu_ARRAY
66 #define ScalosMenu_CODE
67 #include STR(SCALOSLOCALE)
69 #include "plugin.h"
71 //----------------------------------------------------------------------------
73 #ifdef __AROS__
74 #define myNListTreeObject BOOPSIOBJMACRO_START(myNListTreeClass->mcc_Class)
75 //#define myNListObject BOOPSIOBJMACRO_START(myNListClass->mcc_Class)
76 //#define myFileTypesNListTreeObject BOOPSIOBJMACRO_START(myFileTypesNListTreeClass->mcc_Class)
77 #else
78 #define myNListTreeObject NewObject(myNListTreeClass->mcc_Class, 0
79 #define myNListObject NewObject(myNListClass->mcc_Class, 0
80 #define myFileTypesNListTreeObject NewObject(myFileTypesNListTreeClass->mcc_Class, 0
81 #define myFileTypesActionsNListObject NewObject(myFileTypesActionsNListClass->mcc_Class, 0
82 #endif
84 //----------------------------------------------------------------------------
86 // Intuition limits for various menu entries
87 #define MAX_MENU (NOMENU + 1)
88 #define MAX_MENUITEM (NOITEM + 1)
89 #define MAX_SUBITEM (NOSUB + 1)
92 //----------------------------------------------------------------------------
94 #define IMG(prefix1,PREFIX2) \
95 BodychunkObject,\
96 MUIA_FixWidth , PREFIX2##_WIDTH ,\
97 MUIA_FixHeight , PREFIX2##_HEIGHT,\
98 MUIA_Bitmap_Width , PREFIX2##_WIDTH ,\
99 MUIA_Bitmap_Height , PREFIX2##_HEIGHT,\
100 MUIA_Bodychunk_Depth , PREFIX2##_DEPTH ,\
101 MUIA_Bodychunk_Body , (UBYTE *) prefix1##_body,\
102 MUIA_Bodychunk_Compression, PREFIX2##_COMPRESSION,\
103 MUIA_Bodychunk_Masking , PREFIX2##_MASKING,\
104 MUIA_Bitmap_SourceColors , (ULONG *) prefix1##_colors,\
105 MUIA_Bitmap_Transparent , 0,\
108 //----------------------------------------------------------------------------
110 // defined in DefaultMenu.c
112 extern const struct DefaultMenuEntry DefaultMenu[];
113 extern const ULONG DefaultMenuEntries;
115 //----------------------------------------------------------------------------
117 // local data structures
119 #define KeyButtonHelp(name,key,HelpText)\
120 TextObject,\
121 ButtonFrame,\
122 MUIA_CycleChain, TRUE, \
123 MUIA_Font, MUIV_Font_Button,\
124 MUIA_Text_Contents, (name),\
125 MUIA_Text_PreParse, "\33c",\
126 MUIA_Text_HiChar , (key),\
127 MUIA_ControlChar , (key),\
128 MUIA_InputMode , MUIV_InputMode_RelVerify,\
129 MUIA_Background , MUII_ButtonBack,\
130 MUIA_ShortHelp, HelpText,\
134 #define Application_Return_EDIT 0
135 #define Application_Return_USE 1001
136 #define Application_Return_SAVE 1002
138 #define ID_MENU MAKE_ID('M','E','N','U')
140 #define MAX_LINESIZE 500 // maximum length for command strings
141 #define MAX_NAMESIZE 100 // maximum length for menu names
142 #define MAX_COMMANDNAME 300 // maximum length for command names
144 struct MenuListEntry
146 char llist_HotKey[2];
147 UBYTE llist_EntryType;
148 UBYTE llist_Flags;
149 UBYTE llist_CommandType;
150 UBYTE llist_CommandFlags;
151 BYTE llist_Priority;
152 ULONG llist_Stack;
153 Object *llist_UnSelImageObj; // Popup menu image
154 ULONG llist_UnSelImageIndex;
155 char llist_name[MAX_LINESIZE];
156 char llist_UnselectedIconName[MAX_COMMANDNAME];
157 char llist_SelectedIconName[MAX_COMMANDNAME];
158 char llist_MenuItemName[MAX_NAMESIZE + 10];
161 struct MenuInsertEntry
163 struct ScalosMenuTree *mie_TreeEntry;
164 ULONG mie_MenuFlags;
167 // values in llist_Flags
168 #define LLISTFLGB_NotRemovable 0
169 #define LLISTFLGB_NameNotSetable 1
170 #define LLISTFLGB_MayNotHaveChildren 2
171 #define LLISTFLGB_PopupMenu 3
172 #define LLISTFLGF_NotRemovable (1 << LLISTFLGB_NotRemovable)
173 #define LLISTFLGF_NameNotSetable (1 << LLISTFLGB_NameNotSetable)
174 #define LLISTFLGF_MayNotHaveChildren (1 << LLISTFLGB_MayNotHaveChildren)
175 #define LLISTFLGF_PopupMenu (1 << LLISTFLGB_PopupMenu)
178 enum ScalosMenuChunkId
180 SCMID_MainMenu = 0,
181 SCMID_Popup_Disk,
182 SCMID_Popup_Drawer,
183 SCMID_Popup_Tool,
184 SCMID_Popup_Trashcan,
185 SCMID_Popup_Window,
186 SCMID_Popup_AppIcon,
187 SCMID_Popup_Desktop,
190 struct ScalosMenuChunk
192 UWORD smch_MenuID; // enum ScalosMenuChunkId
193 UWORD smch_Entries; // number of entries
194 struct ScalosMenuTree smch_Menu[1]; // (variable) the menu entries
197 struct CommandTableEntry
199 CONST_STRPTR cte_Command;
200 ULONG cte_NameMsgId;
203 enum MenuEntryType
205 MENUENTRY_Menu,
206 MENUENTRY_MenuItem,
207 MENUENTRY_SubItem,
208 MENUENTRY_Invalid,
211 //----------------------------------------------------------------------------
213 // aus mempools.lib
214 #ifndef __amigaos4__
215 extern int _STI_240_InitMemFunctions(void);
216 extern void _STD_240_TerminateMemFunctions(void);
217 #endif
219 //----------------------------------------------------------------------------
221 // local functions
223 static BOOL OpenLibraries(void);
224 static void CloseLibraries(void);
226 DISPATCHER_PROTO(MenuPrefs);
227 static Object *CreatePrefsGroup(struct MenuPrefsInst *inst);
229 static SAVEDS(APTR) INTERRUPT CmdListConstructHookFunc(struct Hook *hook, APTR obj, struct NList_ConstructMessage *msg);
230 static SAVEDS(void) INTERRUPT CmdListDestructHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *msg);
231 static SAVEDS(ULONG) INTERRUPT CmdListDisplayHookFunc(struct Hook *hook, APTR obj, struct NList_DisplayMessage *ltdm);
232 static SAVEDS(LONG) INTERRUPT CmdListCompareHookFunc(struct Hook *hook, Object *obj, struct NList_CompareMessage *msg);
233 static SAVEDS(LONG) INTERRUPT CmdListPopupOpenHookFunc(struct Hook *hook, Object *list, Object *str);
235 static SAVEDS(APTR) INTERRUPT TreeConstructFunc(struct Hook *hook, APTR obj, struct MUIP_NListtree_ConstructMessage *ltcm);
236 static SAVEDS(void) INTERRUPT TreeDestructFunc(struct Hook *hook, APTR obj, struct MUIP_NListtree_DestructMessage *ltdm);
237 static SAVEDS(ULONG) INTERRUPT TreeDisplayFunc(struct Hook *hook, APTR obj, struct MUIP_NListtree_DisplayMessage *ltdm);
239 static SAVEDS(ULONG) INTERRUPT ImagePopAslFileStartHookFunc(struct Hook *hook, Object *o, Msg msg);
241 static STRPTR GetLocString(ULONG MsgId);
242 static void TranslateStringArray(STRPTR *stringArray);
243 static void TranslateNewMenu(struct NewMenu *nm);
245 static SAVEDS(APTR) INTERRUPT ResetToDefaultsHookFunc(struct Hook *hook, Object *o, Msg msg);
246 static SAVEDS(APTR) INTERRUPT OpenHookFunc(struct Hook *hook, Object *o, Msg msg);
247 static SAVEDS(APTR) INTERRUPT SaveAsHookFunc(struct Hook *hook, Object *o, Msg msg);
248 static SAVEDS(APTR) INTERRUPT AboutHookFunc(struct Hook *hook, Object *o, Msg msg);
249 static SAVEDS(APTR) INTERRUPT LastSavedHookFunc(struct Hook *hook, Object *o, Msg msg);
250 static SAVEDS(APTR) INTERRUPT RestoreHookFunc(struct Hook *hook, Object *o, Msg msg);
251 static SAVEDS(APTR) INTERRUPT MergeHookFunc(struct Hook *hook, Object *o, Msg msg);
252 static SAVEDS(APTR) INTERRUPT ImportTDHookFunc(struct Hook *hook, Object *o, Msg msg);
253 static SAVEDS(APTR) INTERRUPT ImportPHookFunc(struct Hook *hook, Object *o, Msg msg);
255 static SAVEDS(APTR) INTERRUPT RenameEntryHookFunc(struct Hook *hook, Object *o, Msg msg);
256 static SAVEDS(APTR) INTERRUPT ChangeEntry3HookFunc(struct Hook *hook, Object *o, Msg msg);
257 static SAVEDS(APTR) INTERRUPT ChangeUnselectedImageHookFunc(struct Hook *hook, Object *o, Msg msg);
258 static SAVEDS(APTR) INTERRUPT ChangeSelectedImageHookFunc(struct Hook *hook, Object *o, Msg msg);
260 static SAVEDS(APTR) INTERRUPT ChangeHotkeyHookFunc(struct Hook *hook, Object *o, Msg msg);
261 static SAVEDS(APTR) INTERRUPT SelectEntryHookFunc(struct Hook *hook, Object *o, Msg msg);
262 static SAVEDS(APTR) INTERRUPT PopButtonHookFunc(struct Hook *hook, Object *o, Msg msg);
263 static SAVEDS(APTR) INTERRUPT AddMenuHookFunc(struct Hook *hook, Object *o, Msg msg);
264 static SAVEDS(APTR) INTERRUPT AddCommandHookFunc(struct Hook *hook, Object *o, Msg msg);
265 static SAVEDS(APTR) INTERRUPT AddMenuItemHookFunc(struct Hook *hook, Object *o, Msg msg);
266 static SAVEDS(APTR) INTERRUPT RemoveEntryHookFunc(struct Hook *hook, Object *o, Msg msg);
267 static SAVEDS(APTR) INTERRUPT CollapseSelectedHookFunc(struct Hook *hook, Object *o, Msg msg);
268 static SAVEDS(APTR) INTERRUPT ExpandSelectedHookFunc(struct Hook *hook, Object *o, Msg msg);
269 static SAVEDS(APTR) INTERRUPT CollapseAllHookFunc(struct Hook *hook, Object *o, Msg msg);
270 static SAVEDS(APTR) INTERRUPT ExpandAllHookFunc(struct Hook *hook, Object *o, Msg msg);
271 static SAVEDS(APTR) INTERRUPT CmdSelectedHookFunc(struct Hook *hook, Object *o, Msg msg);
272 static SAVEDS(APTR) INTERRUPT ContextMenuTriggerHookFunc(struct Hook *hook, Object *o, Msg msg);
273 static SAVEDS(APTR) INTERRUPT AppMessageHookFunc(struct Hook *hook, Object *o, Msg msg);
274 static SAVEDS(APTR) INTERRUPT SettingsChangedHookFunc(struct Hook *hook, Object *o, Msg msg);
275 static SAVEDS(void) INTERRUPT AslIntuiMsgHookFunc(struct Hook *hook, Object *o, Msg msg);
276 static SAVEDS(void) INTERRUPT HideObsoleteHookFunc(struct Hook *hook, Object *o, Msg msg);
278 static SAVEDS(void) INTERRUPT MenuCopyHookFunc(struct Hook *hook, Object *o, Msg msg);
279 static SAVEDS(void) INTERRUPT MenuCutHookFunc(struct Hook *hook, Object *o, Msg msg);
280 static SAVEDS(void) INTERRUPT MenuPasteHookFunc(struct Hook *hook, Object *o, Msg msg);
282 static struct MUI_NListtree_TreeNode *MoveMenuTree(struct MenuPrefsInst *inst,
283 ULONG DestListtreeIndex, ULONG SrcListtreeIndex, ULONG EntryIndex);
284 static struct MUI_NListtree_TreeNode *CopyFileTypesEntry(struct MenuPrefsInst *inst,
285 struct MUI_NListtree_TreeNode *tnToListNode, struct MUI_NListtree_TreeNode *tnToPrevNode,
286 struct MUI_NListtree_TreeNode *tnFrom, ULONG destList, ULONG srcList);
287 static LONG CopyMenuTree(struct MenuPrefsInst *inst,
288 Object *ListTreeDest, Object *ListTreeSrc,
289 struct MUI_NListtree_TreeNode *Src, struct MUI_NListtree_TreeNode *DestParent);
290 static struct MUI_NListtree_TreeNode *CopyMenuEntry(struct MenuPrefsInst *inst,
291 Object *ListTreeDest, Object *ListTreeSrc,
292 struct MUI_NListtree_TreeNode *Src, struct MUI_NListtree_TreeNode *DestParent);
293 static LONG ReadPrefsFile(struct MenuPrefsInst *inst, CONST_STRPTR Filename, BOOL Quiet);
294 static LONG WritePrefsFile(struct MenuPrefsInst *inst, CONST_STRPTR Filename);
295 static LONG SaveMenuNode(struct MenuPrefsInst *inst, struct IFFHandle *iff,
296 const struct MenuPrefsPopMenuNode *TreeNode, enum ScalosMenuChunkId ChunkID);
297 static UWORD CountMenuEntries(struct MenuPrefsInst *inst, Object *ListTree,
298 const struct MUI_NListtree_TreeNode *TreeNode, size_t *StringSpace);
299 static LONG BuildMenuTree(struct MenuPrefsInst *inst, Object *ListTree,
300 const struct MUI_NListtree_TreeNode *TreeNode,
301 struct ScalosMenuTree **MenuSpace, STRPTR *StringSpace,
302 struct ScalosMenuTree **Parent);
303 static void RemoveAddresses(struct ScalosMenuTree *MenuTree, const UBYTE *baseAddr);
304 static LONG SaveIcon(struct MenuPrefsInst *inst, CONST_STRPTR IconName);
305 static void ClearMenuList(struct MenuPrefsInst *inst);
306 static STRPTR AddMenuString(CONST_STRPTR MenuString, STRPTR *StringSpace);
307 static void AddAddresses(struct ScalosMenuTree *MenuTree, const UBYTE *BaseAddr);
308 static void GenerateMenuList(struct MenuPrefsInst *inst, struct ScalosMenuTree *mTree,
309 Object *ListTree, struct MUI_NListtree_TreeNode *MenuNode);
310 static BOOL RequestTdFile(struct MenuPrefsInst *inst, char *FileName, size_t MaxLen);
311 static BOOL RequestParmFile(struct MenuPrefsInst *inst, char *FileName, size_t MaxLen);
312 static BOOL CmpWord(CONST_STRPTR Cmd, CONST_STRPTR Line);
313 static void StripLF(STRPTR Line);
314 static STRPTR NextWord(STRPTR lp);
315 static void CopyWord(STRPTR dest, CONST_STRPTR src, size_t MaxLen);
316 static struct MUI_NListtree_TreeNode *AppMessage_Menu(struct MenuPrefsInst *inst,
317 struct MUI_NListtree_TreeNode **TreeNode,
318 struct MUI_NListtree_TreeNode **ParentNode, const struct WBArg *wbArg,
319 CONST_STRPTR Path, CONST_STRPTR FileName);
320 static void EnableCommandArgumentGadgets(struct MenuPrefsInst *inst, const struct MenuListEntry *mle);
321 static BOOL IsPopupMenu(struct MenuPrefsInst *inst, struct MUI_NListtree_TreeNode *TreeNode);
322 static enum MenuEntryType GetMenuEntryType(struct MenuPrefsInst *inst,
323 struct MUI_NListtree_TreeNode *TreeNode);
324 static ULONG GetMaxCountForEntry(enum MenuEntryType type);
325 static void SwitchPopButton(struct MenuPrefsInst *inst, UBYTE CommandType);
326 DISPATCHER_PROTO(myNListTree);
327 static Object *CreatePrefsImage(void);
328 static void InitHooks(struct MenuPrefsInst *inst);
329 static void SetChangedFlag(struct MenuPrefsInst *inst, BOOL changed);
330 static void AddDefaultMenuContents(struct MenuPrefsInst *inst);
331 static void ParseToolTypes(struct MenuPrefsInst *inst, struct MUIP_ScalosPrefs_ParseToolTypes *ptt);
332 static void InsertMenuRootEntries(struct MenuPrefsInst *inst);
333 static Object *GetMenuEntryListtree(struct MenuPrefsInst *inst);
334 static struct MUI_NListtree_TreeNode *GetParentNodeForMenu(struct MenuPrefsInst *inst, struct MUI_NListtree_TreeNode **PrevNode);
335 static struct MUI_NListtree_TreeNode *GetParentNodeForMenuItem(struct MenuPrefsInst *inst, struct MUI_NListtree_TreeNode **PrevNode);
336 static BOOL MayPasteOnto(struct MenuPrefsInst *inst,
337 struct MUI_NListtree_TreeNode *tnTo, struct MUI_NListtree_TreeNode *tnFrom);
338 static struct MUI_NListtree_TreeNode *MayPasteBelow(struct MenuPrefsInst *inst,
339 struct MUI_NListtree_TreeNode *tnTo, struct MUI_NListtree_TreeNode *tnFrom);
340 #if !defined(__SASC) && !defined(__MORPHOS__) && !defined(__AROS__)
341 static char *stpblk(const char *q);
342 #if !defined(__amigaos4__)
343 static size_t stccpy(char *dest, const char *src, size_t MaxLen);
344 #endif /* !defined(__amigaos4__) */
345 #endif /* !defined(__SASC) && !defined(__MORPHOS__) */
347 //----------------------------------------------------------------------------
349 // local data items
351 struct Library *MUIMasterBase;
352 T_LOCALEBASE LocaleBase;
353 struct GfxBase *GfxBase;
354 struct Library *IconBase;
355 struct Library *IFFParseBase;
356 T_UTILITYBASE UtilityBase;
357 struct IntuitionBase *IntuitionBase;
358 struct Library *DataTypesBase;
360 #ifdef __amigaos4__
361 struct Library *DOSBase;
362 struct DOSIFace *IDOS;
363 struct LocaleIFace *ILocale;
364 struct MUIMasterIFace *IMUIMaster;
365 struct GraphicsIFace *IGraphics;
366 struct IconIFace *IIcon;
367 struct IFFParseIFace *IIFFParse;
368 struct DataTypesIFace *IDataTypes;
369 struct UtilityIFace *IUtility;
370 struct IntuitionIFace *IIntuition;
371 struct Library *NewlibBase;
372 struct Interface *INewlib;
373 #endif
375 #ifdef __AROS__
376 struct DosLibrary *DOSBase;
377 #endif
379 static BOOL StaticsTranslated;
381 static ULONG MajorVersion, MinorVersion;
383 static const struct MUIP_ScalosPrefs_MCCList RequiredMccList[] =
385 { MUIC_Lamp, 11, 1 },
386 { MUIC_NListtree, 18, 18 },
387 { MUIC_NListview, 18, 0 },
388 { NULL, 0, 0 }
391 static const struct Hook MenuPrefsHooks[] =
393 { { NULL, NULL }, HOOKFUNC_DEF(TreeConstructFunc), NULL },
394 { { NULL, NULL }, HOOKFUNC_DEF(TreeDestructFunc), NULL },
395 { { NULL, NULL }, HOOKFUNC_DEF(TreeDisplayFunc), NULL },
397 { { NULL, NULL }, HOOKFUNC_DEF(CmdListConstructHookFunc), NULL },
398 { { NULL, NULL }, HOOKFUNC_DEF(CmdListDestructHookFunc), NULL },
399 { { NULL, NULL }, HOOKFUNC_DEF(CmdListDisplayHookFunc), },
400 { { NULL, NULL }, HOOKFUNC_DEF(CmdListCompareHookFunc), NULL },
401 { { NULL, NULL }, HOOKFUNC_DEF(CmdListPopupOpenHookFunc), NULL },
403 { { NULL, NULL }, HOOKFUNC_DEF(ImagePopAslFileStartHookFunc), NULL },
405 { { NULL, NULL }, HOOKFUNC_DEF(ResetToDefaultsHookFunc), NULL },
406 { { NULL, NULL }, HOOKFUNC_DEF(OpenHookFunc), NULL },
407 { { NULL, NULL }, HOOKFUNC_DEF(LastSavedHookFunc), NULL },
408 { { NULL, NULL }, HOOKFUNC_DEF(RestoreHookFunc), NULL },
409 { { NULL, NULL }, HOOKFUNC_DEF(SaveAsHookFunc), NULL },
410 { { NULL, NULL }, HOOKFUNC_DEF(MergeHookFunc), NULL },
411 { { NULL, NULL }, HOOKFUNC_DEF(ImportTDHookFunc), NULL },
412 { { NULL, NULL }, HOOKFUNC_DEF(ImportPHookFunc), NULL },
413 { { NULL, NULL }, HOOKFUNC_DEF(RenameEntryHookFunc), NULL },
414 { { NULL, NULL }, HOOKFUNC_DEF(ChangeHotkeyHookFunc), NULL },
415 { { NULL, NULL }, HOOKFUNC_DEF(ChangeEntry3HookFunc), NULL },
416 { { NULL, NULL }, HOOKFUNC_DEF(ChangeUnselectedImageHookFunc), NULL },
417 { { NULL, NULL }, HOOKFUNC_DEF(ChangeSelectedImageHookFunc), NULL },
418 { { NULL, NULL }, HOOKFUNC_DEF(SelectEntryHookFunc), NULL },
419 { { NULL, NULL }, HOOKFUNC_DEF(PopButtonHookFunc), NULL },
420 { { NULL, NULL }, HOOKFUNC_DEF(AddMenuHookFunc), NULL },
421 { { NULL, NULL }, HOOKFUNC_DEF(AddCommandHookFunc), NULL },
422 { { NULL, NULL }, HOOKFUNC_DEF(AddMenuItemHookFunc), NULL },
423 { { NULL, NULL }, HOOKFUNC_DEF(RemoveEntryHookFunc), NULL },
424 { { NULL, NULL }, HOOKFUNC_DEF(AboutHookFunc), NULL },
425 { { NULL, NULL }, HOOKFUNC_DEF(CollapseSelectedHookFunc), NULL },
426 { { NULL, NULL }, HOOKFUNC_DEF(ExpandSelectedHookFunc), NULL },
427 { { NULL, NULL }, HOOKFUNC_DEF(CollapseAllHookFunc), NULL },
428 { { NULL, NULL }, HOOKFUNC_DEF(ExpandAllHookFunc), NULL },
429 { { NULL, NULL }, HOOKFUNC_DEF(CmdSelectedHookFunc), NULL },
430 { { NULL, NULL }, HOOKFUNC_DEF(ContextMenuTriggerHookFunc), NULL },
431 { { NULL, NULL }, HOOKFUNC_DEF(AppMessageHookFunc), NULL },
432 { { NULL, NULL }, HOOKFUNC_DEF(SettingsChangedHookFunc), NULL },
433 { { NULL, NULL }, HOOKFUNC_DEF(AslIntuiMsgHookFunc), NULL },
434 { { NULL, NULL }, HOOKFUNC_DEF(HideObsoleteHookFunc), NULL },
436 { { NULL, NULL }, HOOKFUNC_DEF(MenuCopyHookFunc), NULL },
437 { { NULL, NULL }, HOOKFUNC_DEF(MenuCutHookFunc), NULL },
438 { { NULL, NULL }, HOOKFUNC_DEF(MenuPasteHookFunc), NULL },
441 static struct Locale *MenuPrefsLocale;
442 static struct Catalog *MenuPrefsCatalog;
444 struct MUI_CustomClass *MenuPrefsClass;
445 struct MUI_CustomClass *myNListTreeClass;
446 struct MUI_CustomClass *DataTypesImageClass;
448 static STRPTR CmdModeStrings[] =
450 (STRPTR) MSGID_COMMANDNAME,
451 (STRPTR) MSGID_WBNAME,
452 (STRPTR) MSGID_ADOSNAME,
453 (STRPTR) MSGID_ICONWINNAME,
454 (STRPTR) MSGID_AREXXNAME,
455 (STRPTR) MSGID_PLUGINNAME,
456 NULL
459 struct CommandTableEntry CommandsTable[] =
461 { "about", MSGID_COM5NAME },
462 { "backdrop", MSGID_COM1NAME },
463 { "cleanup", MSGID_COM12NAME },
464 { "cleanupbydate", MSGID_COM44NAME },
465 { "cleanupbyname", MSGID_COM43NAME },
466 { "cleanupbysize", MSGID_COM45NAME },
467 { "cleanupbytype", MSGID_COM46NAME },
468 { "clearselection", MSGID_COM36NAME },
469 { "clone", MSGID_COM28NAME },
470 { "close", MSGID_COM9NAME },
471 { "copy", MSGID_COM39NAME },
472 { "copyto", MSGID_COM49NAME },
473 { "createthumbnail", MSGID_COM51NAME },
474 { "cut", MSGID_COM40NAME },
475 { "delete", MSGID_COM27NAME },
476 { "emptytrashcan", MSGID_COM29NAME },
477 { "executecommand", MSGID_COM2NAME },
478 { "find", MSGID_COM_FIND },
479 { "formatdisk", MSGID_COM33NAME },
480 { "iconify", MSGID_COM32NAME },
481 { "iconinfo", MSGID_COM22NAME },
482 { "iconproperties", MSGID_COM_ICONPROPERTIES },
483 { "lastmsg", MSGID_COM30NAME },
484 { "leaveout", MSGID_COM25NAME },
485 { "makedir", MSGID_COM7NAME },
486 { "moveto", MSGID_COM50NAME },
487 { "open", MSGID_COM19NAME },
488 { "openinbrowserwindow", MSGID_COM_OPENBROWSERWINDOW },
489 { "openinnewwindow", MSGID_COM_OPENNEWWINDOW },
490 { "parent", MSGID_COM8NAME },
491 { "paste", MSGID_COM41NAME },
492 { "putaway", MSGID_COM26NAME },
493 { "quit", MSGID_COM6NAME },
494 { "redo", MSGID_COM_REDO },
495 { "redraw", MSGID_COM31NAME },
496 { "redrawall", MSGID_COM3NAME },
497 { "rename", MSGID_COM21NAME },
498 { "reset", MSGID_COM20NAME },
499 { "selectall", MSGID_COM11NAME },
500 { "showallfiles", MSGID_COM16NAME },
501 { "showdefault", MSGID_COM48NAME },
502 { "showonlyicons", MSGID_COM15NAME },
503 { "shutdown", MSGID_COM34NAME },
504 { "sizetofit", MSGID_COM35NAME },
505 { "snapshot", MSGID_COM23NAME },
506 { "snapshotall", MSGID_COM14NAME },
507 { "snapshotwindow", MSGID_COM13NAME },
508 { "thumbnailcachecleanup", MSGID_COM_THUMBNAILCACHECLEANUP },
509 { "undo", MSGID_COM_UNDO },
510 { "unsnapshot", MSGID_COM24NAME },
511 { "update", MSGID_COM10NAME },
512 { "updateall", MSGID_COM4NAME },
513 { "viewbydate", MSGID_COM38NAME },
514 { "viewbydefault", MSGID_COM47NAME },
515 { "viewbyicon", MSGID_COM17NAME },
516 { "viewbysize", MSGID_COM37NAME },
517 { "viewbytext", MSGID_COM18NAME },
518 { "viewbytype", MSGID_COM42NAME },
519 { "windowproperties", MSGID_COM_WINDOWPROPERTIES },
522 struct CommandTableEntry *CommandsArray[1 + Sizeof(CommandsTable)];
524 static struct NewMenu ContextMenus[] =
526 { NM_TITLE, (STRPTR) MSGID_TITLENAME, NULL, 0, 0, NULL },
527 { NM_ITEM, (STRPTR) MSGID_MENU_PROJECT_OPEN, (STRPTR) MSGID_MENU_PROJECT_OPEN_SHORT, 0, 0, (APTR) HOOKNDX_Open },
528 { NM_ITEM, (STRPTR) MSGID_MENU_PROJECT_MERGE, (STRPTR) MSGID_MENU_PROJECT_MERGE_SHORT, 0, 0, (APTR) HOOKNDX_Merge },
529 { NM_ITEM, (STRPTR) MSGID_MENU_PROJECT_SAVEAS, (STRPTR) MSGID_MENU_PROJECT_SAVEAS_SHORT, 0, 0, (APTR) HOOKNDX_SaveAs },
530 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, NULL },
531 { NM_ITEM, (STRPTR) MSGID_MENU_PROJECT_IMPORT, NULL, 0, 0, NULL },
532 { NM_SUB, (STRPTR) MSGID_MENU_PROJECT_IMPORT_TD, (STRPTR) MSGID_MENU_PROJECT_IMPORT_TD_SHORT, 0, 0, (APTR) HOOKNDX_ImportTD },
533 { NM_SUB, (STRPTR) MSGID_MENU_PROJECT_IMPORT_P, (STRPTR) MSGID_MENU_PROJECT_IMPORT_P_SHORT, 0, 0, (APTR) HOOKNDX_ImportP },
534 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, NULL },
535 { NM_ITEM, (STRPTR) MSGID_MENU_EDIT_COLLAPSE, NULL, NM_ITEMDISABLED, 0, (APTR) HOOKNDX_CollapseSelected },
536 { NM_ITEM, (STRPTR) MSGID_MENU_EDIT_EXPAND, NULL, NM_ITEMDISABLED, 0, (APTR) HOOKNDX_ExpandSelected },
537 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, NULL },
538 { NM_ITEM, (STRPTR) MSGID_MENU_EDIT_COLLAPSEALL, NULL, 0, 0, (APTR) HOOKNDX_CollapseAll },
539 { NM_ITEM, (STRPTR) MSGID_MENU_EDIT_EXPANDALL, NULL, 0, 0, (APTR) HOOKNDX_ExpandAll },
540 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, NULL },
541 { NM_ITEM, (STRPTR) MSGID_MENU_EDIT_COPY, NULL, 0, 0, (APTR) HOOKNDX_MenuCopy },
542 { NM_ITEM, (STRPTR) MSGID_MENU_EDIT_CUT, NULL, 0, 0, (APTR) HOOKNDX_MenuCut },
543 { NM_ITEM, (STRPTR) MSGID_MENU_EDIT_PASTE, NULL, NM_ITEMDISABLED, 0, (APTR) HOOKNDX_MenuPaste },
544 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, NULL },
545 { NM_ITEM, (STRPTR) MSGID_MENU_SETTINGS_HIDEOBSOLETE, NULL, CHECKIT|MENUTOGGLE, 0, (APTR) HOOKNDX_HideObsolete },
546 { NM_ITEM, NM_BARLABEL, NULL, 0, 0, NULL },
547 { NM_ITEM, (STRPTR) MSGID_MENU_PROJECT_ABOUT, NULL, 0, 0, (APTR) HOOKNDX_About },
549 { NM_END, NULL, NULL, 0, 0, 0,},
552 static const LONG StopChunkList[] =
554 ID_PREF, ID_MENU,
557 #define ENTRYTYPE_MAX (1 + SCAMENUTYPE_ToolsMenu)
559 // dest source
560 static const BOOL MayPasteAfterMatrix[ENTRYTYPE_MAX][ENTRYTYPE_MAX] =
562 // 0 1 2 3 4
563 /* 0 SCAMENUTYPE_MainMenu */
564 { FALSE, FALSE, FALSE, FALSE, FALSE, },
565 /* 1 SCAMENUTYPE_Menu */
566 { FALSE, TRUE, TRUE, FALSE, TRUE, },
567 /* 2 SCAMENUTYPE_MenuItem */
568 { FALSE, TRUE, TRUE, TRUE, FALSE, },
569 /* 3 SCAMENUTYPE_Command */
570 { FALSE, FALSE, FALSE, TRUE, FALSE, },
571 /* 4 SCAMENUTYPE_ToolsMenu */
572 { FALSE, TRUE, FALSE, FALSE, FALSE, },
573 // 0 1 2 3 4
575 // dest source
576 static const BOOL MayPasteIntoMatrix[ENTRYTYPE_MAX][ENTRYTYPE_MAX] =
578 // 0 1 2 3 4
579 /* 0 SCAMENUTYPE_MainMenu */
580 { FALSE, TRUE, FALSE, FALSE, FALSE, },
581 /* 1 SCAMENUTYPE_Menu */
582 { FALSE, TRUE, TRUE, FALSE, FALSE, },
583 /* 2 SCAMENUTYPE_MenuItem */
584 { FALSE, FALSE, FALSE, TRUE, FALSE, },
585 /* 3 SCAMENUTYPE_Command */
586 { FALSE, FALSE, FALSE, TRUE, FALSE, },
587 /* 4 SCAMENUTYPE_ToolsMenu */
588 { FALSE, TRUE, TRUE, FALSE, FALSE, },
589 // 0 1 2 3 4
591 //----------------------------------------------------------------------------
593 void closePlugin(struct PluginBase *PluginBase)
595 d1(kprintf("%s/%s/%ld: start\n", __FILE__, __FUNC__, __LINE__));
597 if (DataTypesImageClass)
599 CleanupDtpicClass(DataTypesImageClass);
600 DataTypesImageClass = NULL;
602 if (myNListTreeClass)
604 MUI_DeleteCustomClass(myNListTreeClass);
605 myNListTreeClass = NULL;
607 if (MenuPrefsCatalog)
609 CloseCatalog(MenuPrefsCatalog);
610 MenuPrefsCatalog = NULL;
612 if (MenuPrefsLocale)
614 CloseLocale(MenuPrefsLocale);
615 MenuPrefsLocale = NULL;
618 if (MenuPrefsClass)
620 MUI_DeleteCustomClass(MenuPrefsClass);
621 MenuPrefsClass = NULL;
624 CloseLibraries();
626 d1(kprintf("%s/%s//%ld:\n", __FILE__, __FUNC__, __LINE__));
628 #if !defined(__amigaos4__) && !defined(__AROS__)
629 _STD_240_TerminateMemFunctions();
630 #endif
632 d1(kprintf("%s/%s//%ld: endt\n", __FILE__, __FUNC__, __LINE__));
636 LIBFUNC_P2(ULONG, LIBSCAGetPrefsInfo,
637 D0, ULONG, which,
638 A6, struct PluginBase *, PluginBase);
640 ULONG result;
642 d1(kprintf("%s/%s/%ld: which=%ld\n", __FILE__, __FUNC__, __LINE__, which));
644 (void) PluginBase;
646 switch(which)
648 case SCAPREFSINFO_GetClass:
649 result = (ULONG) MenuPrefsClass;
650 break;
652 case SCAPREFSINFO_GetTitle:
653 result = (ULONG) GetLocString(MSGID_PLUGIN_LIST_TITLE);
654 break;
656 case SCAPREFSINFO_GetTitleImage:
657 result = (ULONG) CreatePrefsImage();
658 break;
660 default:
661 result = (ULONG) NULL;
662 break;
665 d1(kprintf("%s/%s/%ld: result=%lu\n", __FILE__, __FUNC__, __LINE__, result));
667 return result;
669 LIBFUNC_END
671 //----------------------------------------------------------------------------
673 DISPATCHER(MenuPrefs)
675 struct MenuPrefsInst *inst;
676 ULONG result = 0;
678 switch(msg->MethodID)
680 case OM_NEW:
681 obj = (Object *) DoSuperMethodA(cl, obj, msg);
682 d1(kprintf("%s/%s/%ld: OM_NEW obj=%08lx\n", __FILE__, __FUNC__, __LINE__, obj));
683 if (obj)
685 Object *prefsobject;
686 struct opSet *ops = (struct opSet *) msg;
688 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
690 memset(inst, 0, sizeof(struct MenuPrefsInst));
692 inst->mpb_TreeImageIndex = 0;
693 inst->mpb_Changed = FALSE;
694 inst->mpb_WBScreen = LockPubScreen("Workbench");
696 InitHooks(inst);
698 inst->mpb_fCreateIcons = GetTagData(MUIA_ScalosPrefs_CreateIcons, TRUE, ops->ops_AttrList);
699 inst->mpb_ProgramName = (CONST_STRPTR) GetTagData(MUIA_ScalosPrefs_ProgramName, (ULONG) "", ops->ops_AttrList);
700 inst->mpb_HideObsoletePopupMenus = GetTagData(MUIM_ScalosPrefs_MenuPrefs_HideObsolete, TRUE, ops->ops_AttrList);
701 inst->mpb_Objects[OBJNDX_WIN_Main] = (APTR) GetTagData(MUIA_ScalosPrefs_MainWindow, (ULONG) NULL, ops->ops_AttrList);
702 inst->mpb_Objects[OBJNDX_APP_Main] = (APTR) GetTagData(MUIA_ScalosPrefs_Application, (ULONG) NULL, ops->ops_AttrList);
704 prefsobject = CreatePrefsGroup(inst);
705 d1(kprintf("%s/%s/%ld: prefsobject=%08lx\n", __FILE__, __FUNC__, __LINE__, prefsobject));
706 if (prefsobject)
708 DoMethod(obj, OM_ADDMEMBER, prefsobject);
710 result = (ULONG) obj;
712 else
714 CoerceMethod(cl, obj, OM_DISPOSE);
717 break;
719 case OM_DISPOSE:
720 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
721 d1(kprintf("%s/%s/%ld: OM_DISPOSE obj=%08lx\n", __FILE__, __FUNC__, __LINE__, obj));
722 if (inst->mpb_WBScreen)
724 UnlockPubScreen(NULL, inst->mpb_WBScreen);
725 inst->mpb_WBScreen = NULL;
727 if (inst->mpb_Objects[OBJNDX_ContextMenu])
729 MUI_DisposeObject(inst->mpb_Objects[OBJNDX_ContextMenu]);
730 inst->mpb_Objects[OBJNDX_ContextMenu] = NULL;
732 if (inst->mpb_SaveReq)
734 MUI_FreeAslRequest(inst->mpb_SaveReq);
735 inst->mpb_SaveReq = NULL;
737 if (inst->mpb_LoadReq)
739 MUI_FreeAslRequest(inst->mpb_LoadReq);
740 inst->mpb_LoadReq = NULL;
742 return DoSuperMethodA(cl, obj, msg);
743 break;
745 case OM_SET:
747 struct opSet *ops = (struct opSet *) msg;
749 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
751 if (FindTagItem(MUIM_ScalosPrefs_MenuPrefs_HideObsolete, ops->ops_AttrList))
753 inst->mpb_HideObsoletePopupMenus = GetTagData(MUIM_ScalosPrefs_MenuPrefs_HideObsolete, inst->mpb_HideObsoletePopupMenus, ops->ops_AttrList);
754 set(inst->mpb_Objects[OBJNDX_Menu_HideObsolete], MUIA_Menuitem_Checked, inst->mpb_HideObsoletePopupMenus);
755 CallHookPkt(&inst->mpb_Hooks[HOOKNDX_HideObsolete],
756 inst->mpb_Objects[OBJNDX_APP_Main], 0);
758 inst->mpb_fCreateIcons = GetTagData(MUIA_ScalosPrefs_CreateIcons, inst->mpb_fCreateIcons, ops->ops_AttrList);
759 inst->mpb_ProgramName = (CONST_STRPTR) GetTagData(MUIA_ScalosPrefs_ProgramName, (ULONG) inst->mpb_ProgramName, ops->ops_AttrList);
760 inst->mpb_Objects[OBJNDX_WIN_Main] = (APTR) GetTagData(MUIA_ScalosPrefs_MainWindow,
761 (ULONG) inst->mpb_Objects[OBJNDX_WIN_Main], ops->ops_AttrList);
762 inst->mpb_Objects[OBJNDX_APP_Main] = (APTR) GetTagData(MUIA_ScalosPrefs_Application,
763 (ULONG) inst->mpb_Objects[OBJNDX_APP_Main], ops->ops_AttrList);
765 return DoSuperMethodA(cl, obj, msg);
767 break;
769 case OM_GET:
771 struct opGet *opg = (struct opGet *) msg;
773 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
774 switch (opg->opg_AttrID)
776 case MUIA_ScalosPrefs_CreateIcons:
777 *opg->opg_Storage = inst->mpb_fCreateIcons;
778 result = 0;
779 break;
780 default:
781 result = DoSuperMethodA(cl, obj, msg);
784 break;
786 case MUIM_ScalosPrefs_ParseToolTypes:
787 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
788 d1(kprintf(__FILE__ "/%s/%ld: before ParseToolTypes\n", __FUNC__, __LINE__));
789 ParseToolTypes(inst, (struct MUIP_ScalosPrefs_ParseToolTypes *) msg);
790 d1(kprintf(__FILE__ "/%s/%ld: after ParseToolTypes\n", __FUNC__, __LINE__));
791 break;
793 case MUIM_ScalosPrefs_LoadConfig:
794 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
795 if (RETURN_OK != ReadPrefsFile(inst, "ENV:Scalos/Menu13.prefs", TRUE))
797 ClearMenuList(inst);
798 ReadPrefsFile(inst, "ENV:Scalos/Menu.prefs", FALSE);
800 SetChangedFlag(inst, FALSE);
801 break;
803 case MUIM_ScalosPrefs_UseConfig:
804 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
805 WritePrefsFile(inst, "ENV:Scalos/Menu13.prefs");
806 SetChangedFlag(inst, FALSE);
807 break;
809 case MUIM_ScalosPrefs_UseConfigIfChanged:
810 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
811 if (inst->mpb_Changed)
813 WritePrefsFile(inst, "ENV:Scalos/Menu13.prefs");
814 SetChangedFlag(inst, FALSE);
816 break;
818 case MUIM_ScalosPrefs_SaveConfig:
819 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
820 WritePrefsFile(inst, "ENVARC:Scalos/Menu13.prefs");
821 WritePrefsFile(inst, "ENV:Scalos/Menu13.prefs");
822 SetChangedFlag(inst, FALSE);
823 break;
825 case MUIM_ScalosPrefs_SaveConfigIfChanged:
826 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
827 if (inst->mpb_Changed)
829 WritePrefsFile(inst, "ENVARC:Scalos/Menu13.prefs");
830 WritePrefsFile(inst, "ENV:Scalos/Menu13.prefs");
831 SetChangedFlag(inst, FALSE);
833 break;
835 case MUIM_ScalosPrefs_RestoreConfig:
836 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
837 DoMethod(obj, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_Restore], 0);
838 break;
840 case MUIM_ScalosPrefs_ResetToDefaults:
841 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
842 DoMethod(obj, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_ResetToDefaults], 0);
843 break;
845 case MUIM_ScalosPrefs_LastSavedConfig:
846 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
847 DoMethod(obj, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_LastSaved], 0);
848 break;
850 case MUIM_ScalosPrefs_PageActive:
852 struct MUIP_ScalosPrefs_PageActive *spa = (struct MUIP_ScalosPrefs_PageActive *) msg;
854 d1(kprintf("%s/%s/%ld: MUIM_ScalosPrefs_PageActive isActive=%08lx\n", __FILE__, __FUNC__, __LINE__, spa->isActive));
855 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
856 inst->mpb_PageIsActive = spa->isActive;
858 break;
860 case MUIM_ScalosPrefs_OpenConfig:
861 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
862 DoMethod(obj, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_Open], 0);
863 break;
865 case MUIM_ScalosPrefs_SaveConfigAs:
866 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
867 DoMethod(obj, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_SaveAs], 0);
868 break;
870 case MUIM_ScalosPrefs_About:
871 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
872 DoMethod(obj, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_About], 0);
873 break;
875 case MUIM_ScalosPrefs_LoadNamedConfig:
877 struct MUIP_ScalosPrefs_LoadNamedConfig *lnc = (struct MUIP_ScalosPrefs_LoadNamedConfig *) msg;
879 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
880 ClearMenuList(inst);
881 ReadPrefsFile(inst, lnc->ConfigFileName, FALSE);
883 break;
885 case MUIM_ScalosPrefs_MenuPrefs_ImportTD:
886 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
887 DoMethod(obj, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_ImportTD], 0);
888 break;
890 case MUIM_ScalosPrefs_MenuPrefs_ImportP:
891 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
892 DoMethod(obj, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_ImportP], 0);
893 break;
895 case MUIM_ScalosPrefs_MenuPrefs_Merge:
896 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
897 DoMethod(obj, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_Merge], 0);
898 break;
900 case MUIM_ScalosPrefs_MenuPrefs_CollapseAll:
901 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
902 DoMethod(obj, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_CollapseAll], 0);
903 break;
905 case MUIM_ScalosPrefs_MenuPrefs_ExpandAll:
906 inst = (struct MenuPrefsInst *) INST_DATA(cl, obj);
907 DoMethod(obj, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_ExpandAll], 0);
908 break;
910 case MUIM_ScalosPrefs_CreateSubWindows:
911 result = (ULONG) NULL;
912 break;
914 case MUIM_ScalosPrefs_GetListOfMCCs:
915 result = (ULONG) RequiredMccList;
916 break;
918 default:
919 d1(kprintf("%s/%s/%ld: MethodID=%08lx\n", __FILE__, __FUNC__, __LINE__, msg->MethodID));
920 result = DoSuperMethodA(cl, obj, msg);
921 break;
924 return result;
926 DISPATCHER_END
928 //----------------------------------------------------------------------------
930 static Object *CreatePrefsGroup(struct MenuPrefsInst *inst)
932 d1(kprintf("%s/%s//%ld: inst=%08lx\n", __FILE__, __FUNC__, __LINE__, inst));
934 inst->mpb_Objects[OBJNDX_ContextMenu] = MUI_MakeObject(MUIO_MenustripNM, ContextMenus, 0);
936 inst->mpb_Objects[OBJNDX_Menu_Copy] = (Object *) DoMethod(inst->mpb_Objects[OBJNDX_ContextMenu],
937 MUIM_FindUData, HOOKNDX_MenuCopy);
938 inst->mpb_Objects[OBJNDX_Menu_Cut] = (Object *) DoMethod(inst->mpb_Objects[OBJNDX_ContextMenu],
939 MUIM_FindUData, HOOKNDX_MenuCut);
940 inst->mpb_Objects[OBJNDX_Menu_Paste] = (Object *) DoMethod(inst->mpb_Objects[OBJNDX_ContextMenu],
941 MUIM_FindUData, HOOKNDX_MenuPaste);
942 inst->mpb_Objects[OBJNDX_Menu_HideObsolete] = (Object *) DoMethod(inst->mpb_Objects[OBJNDX_ContextMenu],
943 MUIM_FindUData, HOOKNDX_HideObsolete);
944 inst->mpb_Objects[OBJNDX_Menu_CollapseSelected] = (Object *) DoMethod(inst->mpb_Objects[OBJNDX_ContextMenu],
945 MUIM_FindUData, HOOKNDX_CollapseSelected);
946 inst->mpb_Objects[OBJNDX_Menu_ExpandSelected] = (Object *) DoMethod(inst->mpb_Objects[OBJNDX_ContextMenu],
947 MUIM_FindUData, HOOKNDX_ExpandSelected);
949 inst->mpb_Objects[OBJNDX_Group_Main] = VGroup,
950 MUIA_Background, MUII_PageBack,
952 Child, inst->mpb_Objects[OBJNDX_Group_List] = VGroup,
953 MUIA_Frame, MUIV_Frame_Group,
954 MUIA_FrameTitle, GetLocString(MSGID_FRAMETITLE),
956 Child, HGroup,
957 Child, VGroup,
958 Child, inst->mpb_Objects[OBJNDX_MainListView] = NListviewObject,
959 MUIA_NListview_NList, inst->mpb_Objects[OBJNDX_MainListTree] = myNListTreeObject,
960 MUIA_CycleChain, TRUE,
961 MUIA_ContextMenu, inst->mpb_Objects[OBJNDX_ContextMenu],
962 MUIA_NList_PrivateData, inst,
963 MUIA_NList_Format, ",",
964 InputListFrame,
965 MUIA_Background, MUII_ListBack,
966 MUIA_NListtree_DisplayHook, &inst->mpb_Hooks[HOOKNDX_TreeDisplay],
967 MUIA_NListtree_ConstructHook, &inst->mpb_Hooks[HOOKNDX_TreeConstruct],
968 MUIA_NListtree_DestructHook, &inst->mpb_Hooks[HOOKNDX_TreeDestruct],
969 MUIA_NListtree_DragDropSort, TRUE,
970 MUIA_NList_ShowDropMarks, TRUE,
971 MUIA_NListtree_AutoVisible, MUIV_NListtree_AutoVisible_Expand,
972 End,
973 MUIA_ObjectID, MAKE_ID('M','T','R','E'),
974 MUIA_Listview_DragType, MUIV_Listview_DragType_Immediate,
975 End,
977 Child, NListviewObject,
978 MUIA_ShowMe, FALSE,
979 MUIA_NListview_NList, inst->mpb_Objects[OBJNDX_HiddenListTree] = myNListTreeObject,
980 MUIA_CycleChain, TRUE,
981 MUIA_NList_PrivateData, inst,
982 MUIA_NList_Format, ",",
983 InputListFrame,
984 MUIA_Background, MUII_ListBack,
985 MUIA_NListtree_DisplayHook, &inst->mpb_Hooks[HOOKNDX_TreeDisplay],
986 MUIA_NListtree_ConstructHook, &inst->mpb_Hooks[HOOKNDX_TreeConstruct],
987 MUIA_NListtree_DestructHook, &inst->mpb_Hooks[HOOKNDX_TreeDestruct],
988 End,
989 MUIA_Listview_DragType, MUIV_Listview_DragType_None,
990 End,
992 Child, NListviewObject,
993 MUIA_ShowMe, FALSE,
994 MUIA_NListview_NList, inst->mpb_Objects[OBJNDX_ListTreeClipboard] = myNListTreeObject,
995 MUIA_CycleChain, TRUE,
996 MUIA_NList_PrivateData, inst,
997 MUIA_NList_Format, ",",
998 InputListFrame,
999 MUIA_Background, MUII_ListBack,
1000 MUIA_NListtree_DisplayHook, &inst->mpb_Hooks[HOOKNDX_TreeDisplay],
1001 MUIA_NListtree_ConstructHook, &inst->mpb_Hooks[HOOKNDX_TreeConstruct],
1002 MUIA_NListtree_DestructHook, &inst->mpb_Hooks[HOOKNDX_TreeDestruct],
1003 End,
1004 MUIA_Listview_DragType, MUIV_Listview_DragType_None,
1005 End,
1007 End, //VGroup
1009 Child, BalanceObject,
1010 End, //Balance
1012 Child, VGroup,
1014 Child, inst->mpb_Objects[OBJNDX_Group_Name] = VGroup,
1015 Child, VGroup,
1016 Child, LLabel(GetLocString(MSGID_ENTRY_STRING_NAME)),
1017 Child, inst->mpb_Objects[OBJNDX_NameString] = StringObject,
1018 MUIA_CycleChain, TRUE,
1019 MUIA_Frame, MUIV_Frame_String,
1020 MUIA_String_MaxLen, MAX_NAMESIZE,
1021 End,
1022 End, //VGroup
1023 Child, HGroup,
1024 MUIA_Weight, 0,
1025 Child, Label(GetLocString(MSGID_HOTKEYNAME)),
1026 Child, inst->mpb_Objects[OBJNDX_StringHotkey] = StringObject,
1027 MUIA_CycleChain, TRUE,
1028 MUIA_String_MaxLen, 2,
1029 MUIA_Weight, 10,
1030 MUIA_Frame, MUIV_Frame_String,
1031 End,
1032 End,
1033 Child, HVSpace,
1034 End, //VGroup
1036 Child, HVSpace,
1038 Child, ColGroup(2),
1039 MUIA_FrameTitle, GetLocString(MSGID_ENTRY_GROUP_UNSELECTEDIMAGE),
1040 MUIA_Background, MUII_GroupBack,
1041 GroupFrame,
1043 Child, inst->mpb_Objects[OBJNDX_PopAsl_UnselectedImage] = PopaslObject,
1044 MUIA_CycleChain, TRUE,
1045 MUIA_ShortHelp, GetLocString(MSGID_POPASL_UNSELECTEDIMAGE_SHORTHELP),
1046 MUIA_Popasl_Type, ASL_FileRequest,
1047 MUIA_Popasl_StartHook, &inst->mpb_Hooks[HOOKNDX_ImagePopAslFileStart],
1048 MUIA_Popstring_String, MUI_MakeObject(MUIO_String, NULL, MAX_COMMANDNAME),
1049 MUIA_Popstring_Button, PopButton(MUII_PopFile),
1050 End, //PopaslObject
1052 Child, inst->mpb_Objects[OBJNDX_DtImage_UnselectedImage] = DataTypesImageObject,
1053 MUIA_ShortHelp, GetLocString(MSGID_SAMPLE_UNSELECTEDIMAGE_SHORTHELP),
1054 MUIA_ScaDtpic_Name, (ULONG) "",
1055 End, //DataTypesMCCObject
1056 End, //ColGroup
1058 Child, ColGroup(2),
1059 MUIA_FrameTitle, GetLocString(MSGID_ENTRY_GROUP_SELECTEDIMAGE),
1060 MUIA_Background, MUII_GroupBack,
1061 GroupFrame,
1063 Child, inst->mpb_Objects[OBJNDX_PopAsl_SelectedImage] = PopaslObject,
1064 MUIA_CycleChain, TRUE,
1065 MUIA_ShortHelp, GetLocString(MSGID_POPASL_SELECTEDIMAGE_SHORTHELP),
1066 MUIA_Popasl_Type, ASL_FileRequest,
1067 MUIA_Popasl_StartHook, &inst->mpb_Hooks[HOOKNDX_ImagePopAslFileStart],
1068 MUIA_Popstring_String, MUI_MakeObject(MUIO_String, NULL, MAX_COMMANDNAME),
1069 MUIA_Popstring_Button, PopButton(MUII_PopFile),
1070 End, //PopaslObject
1072 Child, inst->mpb_Objects[OBJNDX_DtImage_SelectedImage] = DataTypesImageObject,
1073 MUIA_ShortHelp, GetLocString(MSGID_SAMPLE_SELECTEDIMAGE_SHORTHELP),
1074 MUIA_ScaDtpic_Name, (ULONG) "",
1075 End, //DataTypesMCCObject
1077 End, //ColGroup
1079 Child, HVSpace,
1081 Child, inst->mpb_Objects[OBJNDX_Group_CmdProperties] = VGroup,
1082 MUIA_FrameTitle, GetLocString(MSGID_MENU_GROUP_COMMAND_PROPERTIES),
1083 MUIA_Background, MUII_GroupBack,
1084 GroupFrame,
1086 Child, inst->mpb_Objects[OBJNDX_Group_String] = VGroup,
1087 Child, inst->mpb_Objects[OBJNDX_CycleGad] = CycleObject,
1088 MUIA_Cycle_Entries, CmdModeStrings,
1089 MUIA_Weight, 5,
1090 MUIA_CycleChain, TRUE,
1091 End,
1093 Child, HGroup,
1094 Child, inst->mpb_Objects[OBJNDX_PopObject] = PopobjectObject,
1095 MUIA_ShowMe, FALSE,
1096 MUIA_CycleChain, TRUE,
1097 MUIA_Popstring_Button, PopButton(MUII_PopUp),
1098 MUIA_Popobject_StrObjHook, &inst->mpb_Hooks[HOOKNDX_CmdListPopupOpen],
1099 MUIA_Popobject_Object, inst->mpb_Objects[OBJNDX_CmdListView] = NListviewObject,
1100 MUIA_NListview_NList, NListObject,
1101 InputListFrame,
1102 MUIA_Background, MUII_ListBack,
1103 MUIA_NList_Format, ",",
1104 MUIA_NList_ConstructHook2, &inst->mpb_Hooks[HOOKNDX_CmdListConstruct],
1105 MUIA_NList_DestructHook2, &inst->mpb_Hooks[HOOKNDX_CmdListDestruct],
1106 MUIA_NList_DisplayHook2, &inst->mpb_Hooks[HOOKNDX_CmdListDisplay],
1107 MUIA_NList_CompareHook2, &inst->mpb_Hooks[HOOKNDX_CmdListCompare],
1108 MUIA_NList_AdjustWidth, TRUE,
1109 MUIA_NList_SortType, 1,
1110 MUIA_NList_TitleMark, MUIV_NList_TitleMark_Down | 1,
1111 MUIA_NList_SourceArray, CommandsArray,
1112 End, //NListObject
1113 End, //NListviewObject
1114 End, //PopobjectObject
1116 Child, inst->mpb_Objects[OBJNDX_Popbutton] = PopButton(MUII_PopUp),
1118 Child, inst->mpb_Objects[OBJNDX_StringCmd] = StringObject,
1119 MUIA_CycleChain, TRUE,
1120 MUIA_String_MaxLen, MAX_LINESIZE,
1121 MUIA_Frame, MUIV_Frame_String,
1122 End,
1123 End, //HGroup
1124 End, //VGroup
1126 Child, HVSpace,
1128 Child, ColGroup(4),
1129 Child, HVSpace,
1131 Child, Label(GetLocString(MSGID_ARGSNAME)),
1132 Child, inst->mpb_Objects[OBJNDX_CheckArgs] = CheckMark(FALSE),
1134 Child, HVSpace,
1135 End, //ColGroup
1137 Child, ColGroup(2),
1138 Child, Label(GetLocString(MSGID_STACKNAME)),
1139 Child, inst->mpb_Objects[OBJNDX_StringStack] = StringObject,
1140 MUIA_CycleChain, TRUE,
1141 MUIA_Frame, MUIV_Frame_String,
1142 MUIA_Weight, 30,
1143 MUIA_String_Accept, "0123456789",
1144 MUIA_String_MaxLen, 10,
1145 MUIA_String_Integer, DEFAULT_STACKSIZE,
1146 End,
1148 Child, Label(GetLocString(MSGID_PRIORITY_SLIDER_NAME)),
1149 Child, inst->mpb_Objects[OBJNDX_SliderPriority] = SliderObject,
1150 MUIA_CycleChain, TRUE,
1151 MUIA_Group_Horiz, TRUE,
1152 MUIA_Numeric_Min, -128,
1153 MUIA_Numeric_Max, 127,
1154 MUIA_Numeric_Value, 0,
1155 MUIA_ShortHelp, GetLocString(MSGID_PRIORITY_SLIDER_BUBBLE),
1156 End,
1157 End, //ColGroup
1158 End, //VGroup
1159 Child, HVSpace,
1160 End, //VGroup
1161 End, //HGroup
1163 Child, HGroup,
1164 Child, inst->mpb_Objects[OBJNDX_Lamp_Changed] = LampObject,
1165 MUIA_Lamp_Type, MUIV_Lamp_Type_Huge,
1166 MUIA_Lamp_Color, MUIV_Lamp_Color_Off,
1167 MUIA_ShortHelp, GetLocString(MSGID_SHORTHELP_LAMP_CHANGED),
1168 End, //LampObject
1170 Child, inst->mpb_Objects[OBJNDX_Group_Buttons1] = HGroup,
1171 MUIA_Group_SameWidth, TRUE,
1172 Child, inst->mpb_Objects[OBJNDX_NewMenuButton] = KeyButtonHelp(GetLocString(MSGID_NEWNAME),
1173 'm', GetLocString(MSGID_SHORTHELP_NEWMENUBUTTON)),
1174 Child, inst->mpb_Objects[OBJNDX_NewItemButton] = KeyButtonHelp(GetLocString(MSGID_NEWINAME),
1175 'i', GetLocString(MSGID_SHORTHELP_NEWITEMBUTTON)),
1176 Child, inst->mpb_Objects[OBJNDX_NewCommandButton] = KeyButtonHelp(GetLocString(MSGID_NEW2NAME),
1177 'c', GetLocString(MSGID_SHORTHELP_NEWCOMMANDBUTTON)),
1178 Child, inst->mpb_Objects[OBJNDX_DelButton] = KeyButtonHelp(GetLocString(MSGID_DELNAME),
1179 'd', GetLocString(MSGID_SHORTHELP_DELBUTTON)),
1180 End, //HGroup
1181 End, //HGroup
1182 End, //VGroup
1184 MUIA_ContextMenu, inst->mpb_Objects[OBJNDX_ContextMenu],
1185 End;
1187 if (NULL == inst->mpb_Objects[OBJNDX_Group_Main])
1188 return NULL;
1190 d1(kprintf("%s/%s//%ld: ContextMenu=%08lx\n", __FILE__, __FUNC__, __LINE__, inst->mpb_Objects[OBJNDX_ContextMenu]));
1192 set(inst->mpb_Objects[OBJNDX_Menu_HideObsolete], MUIA_Menuitem_Checked, inst->mpb_HideObsoletePopupMenus);
1194 DoMethod(inst->mpb_Objects[OBJNDX_CmdListView], MUIM_NList_Sort);
1196 DoMethod(inst->mpb_Objects[OBJNDX_CmdListView], MUIM_Notify, MUIA_Listview_DoubleClick, TRUE,
1197 inst->mpb_Objects[OBJNDX_CmdListView], 2, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_CmdSelected]);
1198 DoMethod(inst->mpb_Objects[OBJNDX_StringHotkey], MUIM_Notify, MUIA_String_Contents, MUIV_EveryTime,
1199 inst->mpb_Objects[OBJNDX_MainListTree], 3, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_ChangeHotkey], MUIV_TriggerValue);
1201 DoMethod(inst->mpb_Objects[OBJNDX_PopAsl_UnselectedImage], MUIM_Notify, MUIA_String_Contents, MUIV_EveryTime,
1202 inst->mpb_Objects[OBJNDX_MainListTree], 3, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_ChangeUnselectedImage], MUIV_TriggerValue);
1204 DoMethod(inst->mpb_Objects[OBJNDX_PopAsl_SelectedImage], MUIM_Notify, MUIA_String_Contents, MUIV_EveryTime,
1205 inst->mpb_Objects[OBJNDX_MainListTree], 3, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_ChangeSelectedImage], MUIV_TriggerValue);
1207 DoMethod(inst->mpb_Objects[OBJNDX_NameString], MUIM_Notify, MUIA_String_Contents, MUIV_EveryTime,
1208 inst->mpb_Objects[OBJNDX_MainListTree], 3, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_RenameEntry], MUIV_TriggerValue);
1210 DoMethod(inst->mpb_Objects[OBJNDX_SliderPriority], MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime,
1211 inst->mpb_Objects[OBJNDX_MainListTree], 2, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_ChangeEntry3]);
1213 DoMethod(inst->mpb_Objects[OBJNDX_StringStack], MUIM_Notify, MUIA_String_Contents, MUIV_EveryTime,
1214 inst->mpb_Objects[OBJNDX_MainListTree], 2, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_ChangeEntry3]);
1216 DoMethod(inst->mpb_Objects[OBJNDX_StringCmd], MUIM_Notify, MUIA_String_Contents, MUIV_EveryTime,
1217 inst->mpb_Objects[OBJNDX_MainListTree], 2, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_ChangeEntry3]);
1219 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree], MUIM_Notify, MUIA_NListtree_Active, MUIV_EveryTime,
1220 inst->mpb_Objects[OBJNDX_MainListTree], 3, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_SelectEntry], MUIV_TriggerValue);
1222 DoMethod(inst->mpb_Objects[OBJNDX_CycleGad], MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
1223 inst->mpb_Objects[OBJNDX_MainListTree], 2, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_ChangeEntry3]);
1225 DoMethod(inst->mpb_Objects[OBJNDX_Popbutton], MUIM_Notify, MUIA_Pressed, FALSE,
1226 inst->mpb_Objects[OBJNDX_MainListTree], 2, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_PopButton]);
1228 DoMethod(inst->mpb_Objects[OBJNDX_NewMenuButton], MUIM_Notify, MUIA_Pressed, FALSE,
1229 inst->mpb_Objects[OBJNDX_MainListTree], 2, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_AddMenu]);
1231 DoMethod(inst->mpb_Objects[OBJNDX_NewItemButton], MUIM_Notify, MUIA_Pressed, FALSE,
1232 inst->mpb_Objects[OBJNDX_MainListTree], 2, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_AddMenuItem]);
1234 DoMethod(inst->mpb_Objects[OBJNDX_NewCommandButton], MUIM_Notify, MUIA_Pressed, FALSE,
1235 inst->mpb_Objects[OBJNDX_MainListTree], 2, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_AddCommand]);
1237 DoMethod(inst->mpb_Objects[OBJNDX_DelButton], MUIM_Notify, MUIA_Pressed, FALSE,
1238 inst->mpb_Objects[OBJNDX_MainListTree], 2, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_RemoveEntry]);
1241 DoMethod(inst->mpb_Objects[OBJNDX_CheckArgs], MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
1242 inst->mpb_Objects[OBJNDX_MainListTree], 2, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_ChangeEntry3]);
1244 DoMethod(inst->mpb_Objects[OBJNDX_Group_Main], MUIM_Notify, MUIA_ContextMenuTrigger, MUIV_EveryTime,
1245 inst->mpb_Objects[OBJNDX_Group_Main], 3, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_ContextMenuTrigger], MUIV_TriggerValue );
1247 DoMethod(inst->mpb_Objects[OBJNDX_Group_Main], MUIM_Notify, MUIA_AppMessage, MUIV_EveryTime,
1248 inst->mpb_Objects[OBJNDX_Group_Main], 3, MUIM_CallHook, &inst->mpb_Hooks[HOOKNDX_AppMessage], MUIV_TriggerValue);
1250 d1(KPrintF("%s/%s//%ld: mpb_HideObsoletePopupMenus=%ld\n", __FILE__, __FUNC__, __LINE__, inst->mpb_HideObsoletePopupMenus));
1252 InsertMenuRootEntries(inst);
1254 d1(kprintf("%s/%s//%ld:\n", __FILE__, __FUNC__, __LINE__));
1255 d1(kprintf("%s/%s//%ld: LocaleBase=%08lx IFFParseBase=%08lx\n", __FILE__, __FUNC__, __LINE__, LocaleBase, IFFParseBase));
1257 return inst->mpb_Objects[OBJNDX_Group_Main];
1261 static BOOL OpenLibraries(void)
1263 d1(kprintf("%s/%s//%ld:\n", __FILE__, __FUNC__, __LINE__));
1265 DOSBase = (APTR) OpenLibrary( "dos.library", 39 );
1266 if (NULL == DOSBase)
1267 return FALSE;
1268 #ifdef __amigaos4__
1269 IDOS = (struct DOSIFace *)GetInterface((struct Library *)DOSBase, "main", 1, NULL);
1270 if (NULL == IDOS)
1271 return FALSE;
1272 #endif
1274 IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 39);
1275 if (NULL == IntuitionBase)
1276 return FALSE;
1277 #ifdef __amigaos4__
1278 IIntuition = (struct IntuitionIFace *)GetInterface((struct Library *)IntuitionBase, "main", 1, NULL);
1279 if (NULL == IIntuition)
1280 return FALSE;
1281 #endif
1283 MUIMasterBase = OpenLibrary("zune.library", 0);
1284 if (NULL == MUIMasterBase)
1285 MUIMasterBase = OpenLibrary(MUIMASTER_NAME, MUIMASTER_VMIN-1);
1286 if (NULL == MUIMasterBase)
1287 return FALSE;
1288 #ifdef __amigaos4__
1289 IMUIMaster = (struct MUIMasterIFace *)GetInterface((struct Library *)MUIMasterBase, "main", 1, NULL);
1290 if (NULL == IMUIMaster)
1291 return FALSE;
1292 #endif
1294 IFFParseBase = OpenLibrary("iffparse.library", 36);
1295 if (NULL == IFFParseBase)
1296 return FALSE;
1297 #ifdef __amigaos4__
1298 IIFFParse = (struct IFFParseIFace *)GetInterface((struct Library *)IFFParseBase, "main", 1, NULL);
1299 if (NULL == IIFFParse)
1300 return FALSE;
1301 #endif
1303 IconBase = OpenLibrary("icon.library", 0);
1304 if (NULL == IconBase)
1305 return FALSE;
1306 #ifdef __amigaos4__
1307 IIcon = (struct IconIFace *)GetInterface((struct Library *)IconBase, "main", 1, NULL);
1308 if (NULL == IIcon)
1309 return FALSE;
1310 #endif
1312 GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 39);
1313 if (NULL == GfxBase)
1314 return FALSE;
1315 #ifdef __amigaos4__
1316 IGraphics = (struct GraphicsIFace *)GetInterface((struct Library *)GfxBase, "main", 1, NULL);
1317 if (NULL == IGraphics)
1318 return FALSE;
1319 #endif
1321 UtilityBase = (T_UTILITYBASE) OpenLibrary(UTILITYNAME, 39);
1322 if (NULL == UtilityBase)
1323 return FALSE;
1324 #ifdef __amigaos4__
1325 IUtility = (struct UtilityIFace *)GetInterface((struct Library *)UtilityBase, "main", 1, NULL);
1326 if (NULL == IUtility)
1327 return FALSE;
1328 #endif
1330 DataTypesBase = OpenLibrary("datatypes.library", 39);
1331 if (NULL == DataTypesBase)
1332 return FALSE;
1333 #ifdef __amigaos4__
1334 IDataTypes = (struct DataTypesIFace *)GetInterface((struct Library *)DataTypesBase, "main", 1, NULL);
1335 if (NULL == IDataTypes)
1336 return FALSE;
1337 #endif
1339 #ifdef __amigaos4__
1340 NewlibBase = OpenLibrary("newlib.library", 0);
1341 if (NULL == NewlibBase)
1342 return FALSE;
1343 INewlib = GetInterface(NewlibBase, "main", 1, NULL);
1344 if (NULL == INewlib)
1345 return FALSE;
1346 #endif
1348 LocaleBase = (T_LOCALEBASE) OpenLibrary("locale.library", 39);
1349 #ifdef __amigaos4__
1350 if (LocaleBase)
1351 ILocale = (struct LocaleIFace *)GetInterface((struct Library *)LocaleBase, "main", 1, NULL);
1352 #endif
1354 d1(kprintf("%s/%s//%ld: LocaleBase=%08lx IFFParseBase=%08lx\n", __FILE__, __FUNC__, __LINE__, LocaleBase, IFFParseBase));
1356 return TRUE;
1360 static void CloseLibraries(void)
1362 d1(kprintf("%s/%s//%ld:\n", __FILE__, __FUNC__, __LINE__));
1364 #ifdef __amigaos4__
1365 if (ILocale)
1367 DropInterface((struct Interface *)ILocale);
1368 ILocale = NULL;
1370 #endif
1371 if (LocaleBase)
1373 CloseLibrary((struct Library *) LocaleBase);
1374 LocaleBase = NULL;
1376 #ifdef __amigaos4__
1377 if (INewlib)
1379 DropInterface(INewlib);
1380 INewlib = NULL;
1382 if (NewlibBase)
1384 CloseLibrary(NewlibBase);
1385 NewlibBase = NULL;
1387 if (IDataTypes)
1389 DropInterface((struct Interface *)IDataTypes);
1390 IDataTypes = NULL;
1392 #endif
1393 if (DataTypesBase)
1395 CloseLibrary(DataTypesBase);
1396 DataTypesBase = NULL;
1398 #ifdef __amigaos4__
1399 if (IUtility)
1401 DropInterface((struct Interface *)IUtility);
1402 IUtility = NULL;
1404 #endif
1405 if (UtilityBase)
1407 CloseLibrary((struct Library *) UtilityBase);
1408 UtilityBase = NULL;
1410 #ifdef __amigaos4__
1411 if (IGraphics)
1413 DropInterface((struct Interface *)IGraphics);
1414 IGraphics = NULL;
1416 #endif
1417 if (GfxBase)
1419 CloseLibrary((struct Library *) GfxBase);
1420 GfxBase = NULL;
1422 #ifdef __amigaos4__
1423 if (IIcon)
1425 DropInterface((struct Interface *)IIcon);
1426 IIcon = NULL;
1428 #endif
1429 if (IconBase)
1431 CloseLibrary(IconBase);
1432 IconBase = NULL;
1434 #ifdef __amigaos4__
1435 if (IIFFParse)
1437 DropInterface((struct Interface *)IIFFParse);
1438 IIFFParse = NULL;
1440 #endif
1441 if (IFFParseBase)
1443 CloseLibrary(IFFParseBase);
1444 IFFParseBase = NULL;
1446 #ifdef __amigaos4__
1447 if (IMUIMaster)
1449 DropInterface((struct Interface *)IMUIMaster);
1450 IMUIMaster = NULL;
1452 #endif
1453 if (MUIMasterBase)
1455 CloseLibrary(MUIMasterBase);
1456 MUIMasterBase = NULL;
1458 #ifdef __amigaos4__
1459 if (IIntuition)
1461 DropInterface((struct Interface *)IIntuition);
1462 IIntuition = NULL;
1464 #endif
1465 if (IntuitionBase)
1467 CloseLibrary((struct Library *) IntuitionBase);
1468 IntuitionBase = NULL;
1470 #ifdef __amigaos4__
1471 if (IDOS)
1473 DropInterface((struct Interface *)IDOS);
1474 IDOS = NULL;
1476 #endif
1477 if (DOSBase)
1479 CloseLibrary((struct Library *) DOSBase);
1480 DOSBase = NULL;
1485 //----------------------------------------------------------------------------
1487 static SAVEDS(APTR) INTERRUPT CmdListConstructHookFunc(struct Hook *hook, APTR obj, struct NList_ConstructMessage *msg)
1489 (void) hook;
1490 (void) obj;
1492 return msg->entry;
1495 static SAVEDS(void) INTERRUPT CmdListDestructHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *msg)
1497 (void) hook;
1498 (void) obj;
1499 (void) msg;
1503 static SAVEDS(ULONG) INTERRUPT CmdListDisplayHookFunc(struct Hook *hook, APTR obj, struct NList_DisplayMessage *ltdm)
1505 struct CommandTableEntry *cte = (struct CommandTableEntry *) ltdm->entry;
1507 d1(KPrintF(__FILE__ "/%s/%ld: cte=%08lx\n", __FUNC__, __LINE__, cte));
1509 if (cte)
1511 ltdm->preparses[0] = "";
1513 ltdm->strings[0] = GetLocString(cte->cte_NameMsgId);
1514 ltdm->strings[1] = (STRPTR) cte->cte_Command;
1516 else
1518 // display titles
1519 ltdm->preparses[0] = "";
1520 ltdm->preparses[1] = "";
1522 ltdm->strings[0] = "";
1523 ltdm->strings[1] = "";
1526 return 0;
1530 static SAVEDS(LONG) INTERRUPT CmdListCompareHookFunc(struct Hook *hook, Object *obj, struct NList_CompareMessage *ncm)
1532 const struct CommandTableEntry *cte1 = (const struct CommandTableEntry *) ncm->entry1;
1533 const struct CommandTableEntry *cte2 = (const struct CommandTableEntry *) ncm->entry2;
1534 LONG col1 = ncm->sort_type & MUIV_NList_TitleMark_ColMask;
1535 LONG col2 = ncm->sort_type2 & MUIV_NList_TitleMark2_ColMask;
1536 LONG Result = 0;
1538 if (ncm->sort_type != MUIV_NList_SortType_None)
1540 // primary sorting
1541 switch (col1)
1543 case 0: // sort by full name
1544 if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
1545 Result = Stricmp(GetLocString(cte2->cte_NameMsgId), GetLocString(cte1->cte_NameMsgId));
1546 else
1547 Result = Stricmp(GetLocString(cte1->cte_NameMsgId), GetLocString(cte2->cte_NameMsgId));
1548 break;
1549 case 1: // sort by internal name
1550 if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
1551 Result = Stricmp(cte2->cte_Command, cte1->cte_Command);
1552 else
1553 Result = Stricmp(cte1->cte_Command, cte2->cte_Command);
1554 break;
1555 default:
1556 break;
1559 if (0 == Result && col1 != col2)
1561 // Secondary sorting
1562 switch (col2)
1564 case 0: // sort by full name
1565 if (ncm->sort_type2 & MUIV_NList_TitleMark2_TypeMask)
1566 Result = Stricmp(GetLocString(cte2->cte_NameMsgId), GetLocString(cte1->cte_NameMsgId));
1567 else
1568 Result = Stricmp(GetLocString(cte1->cte_NameMsgId), GetLocString(cte2->cte_NameMsgId));
1569 break;
1570 case 1: // sort by internal name
1571 if (ncm->sort_type2 & MUIV_NList_TitleMark2_TypeMask)
1572 Result = Stricmp(cte2->cte_Command, cte1->cte_Command);
1573 else
1574 Result = Stricmp(cte1->cte_Command, cte2->cte_Command);
1575 break;
1576 default:
1577 break;
1582 return Result;
1585 //----------------------------------------------------------------------------
1587 static SAVEDS(LONG) INTERRUPT CmdListPopupOpenHookFunc(struct Hook *hook, Object *list, Object *str)
1589 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
1590 ULONG entries = 0;
1591 ULONG n;
1592 CONST_STRPTR string = "";
1593 size_t length;
1595 get(list, MUIA_NList_Entries, &entries);
1596 get(inst->mpb_Objects[OBJNDX_StringCmd], MUIA_String_Contents, &string);
1598 length = strlen(string);
1600 d1(KPrintF(__FILE__ "/%s/%ld: string=<%s> entries=%lu length=%lu\n", __FUNC__, __LINE__, string, entries, length));
1602 for (n = 0; n < entries; n++)
1604 struct CommandTableEntry *cte = NULL;
1606 DoMethod(list, MUIM_NList_GetEntry, n, &cte);
1607 if (cte)
1609 if (0 == Strnicmp(cte->cte_Command, string, length))
1611 d1(KPrintF(__FILE__ "/%s/%ld: found!\n", __FUNC__, __LINE__, cte));
1612 set(list, MUIA_NList_Active, n);
1613 DoMethod(list, MUIM_NList_Jump, n);
1614 break;
1619 return TRUE;
1622 //----------------------------------------------------------------------------
1624 static SAVEDS(APTR) INTERRUPT TreeConstructFunc(struct Hook *hook, APTR obj, struct MUIP_NListtree_ConstructMessage *ltcm)
1626 struct MenuListEntry *mle = AllocPooled(ltcm->MemPool, sizeof(struct MenuListEntry));
1628 d1(kprintf("%s/%s/%ld: obj=%08lx ltcm=%08lx memPool=%08lx UserData=%08lx\n", \
1629 __FILE__, __FUNC__, __LINE__, obj, ltcm, ltcm->MemPool, ltcm->UserData));
1630 d1(kprintf("%s/%s/%ld: mle=%08lx\n", __FILE__, __FUNC__, __LINE__, mle));
1632 if (mle)
1634 const struct MenuInsertEntry *mie = (const struct MenuInsertEntry *) ltcm->UserData;
1635 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
1637 if (ltcm->Name)
1638 stccpy(mle->llist_name, ltcm->Name, sizeof(mle->llist_name));
1639 else
1640 strcpy(mle->llist_name, "");
1642 d1(KPrintF("%s/%s/%ld: llist_name=<%s> mtre_type=%ld\n", __FILE__, __FUNC__, __LINE__, mle->llist_name, mie->mie_TreeEntry->mtre_type));
1644 d1(KPrintF("%s/%s/%ld: mtre_iconnames=%08lx\n", __FILE__, __FUNC__, __LINE__, mie->mie_TreeEntry->MenuCombo.MenuTree.mtre_iconnames));
1645 if ((mie->mie_TreeEntry->mtre_flags & MTREFLGF_IconNames) &&
1646 mie->mie_TreeEntry->MenuCombo.MenuTree.mtre_iconnames)
1648 stccpy(mle->llist_UnselectedIconName, mie->mie_TreeEntry->MenuCombo.MenuTree.mtre_iconnames,
1649 sizeof(mle->llist_UnselectedIconName));
1650 stccpy(mle->llist_SelectedIconName,
1651 mie->mie_TreeEntry->MenuCombo.MenuTree.mtre_iconnames + 1 + strlen(mie->mie_TreeEntry->MenuCombo.MenuTree.mtre_iconnames),
1652 sizeof(mle->llist_SelectedIconName));
1654 d1(KPrintF("%s/%s/%ld: llist_UnselectedIconName=<%s> llist_SelectedIconName=<%s>\n", __FILE__, __FUNC__, __LINE__, mle->llist_UnselectedIconName, mle->llist_SelectedIconName));
1656 mle->llist_UnSelImageIndex = ++inst->mpb_TreeImageIndex;
1658 mle->llist_UnSelImageObj = DataTypesImageObject,
1659 MUIA_ScaDtpic_Name, (ULONG) mle->llist_UnselectedIconName,
1660 End;
1662 d1(KPrintF("%s/%s/%ld: llist_UnSelImageObj=%08lx\n", __FILE__, __FUNC__, __LINE__, mle->llist_UnSelImageObj));
1664 DoMethod(obj, MUIM_NList_UseImage, mle->llist_UnSelImageObj, mle->llist_UnSelImageIndex, 0);
1666 else
1668 mle->llist_UnSelImageIndex = 0;
1669 strcpy(mle->llist_UnselectedIconName, "");
1670 strcpy(mle->llist_SelectedIconName, "");
1673 ltcm->UserData = mle;
1674 ltcm->Name = mle->llist_name;
1675 mle->llist_EntryType = mie->mie_TreeEntry->mtre_type;
1676 mle->llist_Flags = mie->mie_MenuFlags;
1678 d1(kprintf("%s/%s/%ld: EntryName=<%s> mie_MenuFlags=%02lx EntryType=%ld\n", \
1679 __FILE__, __FUNC__, __LINE__, ltcm->Name, mie->mie_MenuFlags, mie->mie_TreeEntry->mtre_type));
1681 d1(kprintf("%s/%s/%ld: llist_HotKey=%08lx mtre_hotkey=%08lx\n", \
1682 __FILE__, __FUNC__, __LINE__, mle->llist_HotKey, mie->mie_TreeEntry->MenuCombo.MenuTree.mtre_hotkey));
1684 stccpy(mle->llist_HotKey, mie->mie_TreeEntry->MenuCombo.MenuTree.mtre_hotkey, sizeof(mle->llist_HotKey));
1686 if (SCAMENUTYPE_Command == mle->llist_EntryType)
1688 d1(kprintf("%s/%s/%ld: llist_name=%08lx mcom_name=%08lx\n", \
1689 __FILE__, __FUNC__, __LINE__, mle->llist_name, mie->mie_TreeEntry->MenuCombo.MenuCommand.mcom_name));
1691 stccpy(mle->llist_name,
1692 mie->mie_TreeEntry->MenuCombo.MenuCommand.mcom_name ? mie->mie_TreeEntry->MenuCombo.MenuCommand.mcom_name : (STRPTR) "",
1693 sizeof(mle->llist_name));
1695 mle->llist_Priority = mie->mie_TreeEntry->MenuCombo.MenuCommand.mcom_pri;
1696 mle->llist_CommandType = mie->mie_TreeEntry->MenuCombo.MenuCommand.mcom_type;
1697 mle->llist_CommandFlags = mie->mie_TreeEntry->MenuCombo.MenuCommand.mcom_flags;
1698 mle->llist_Stack = mie->mie_TreeEntry->MenuCombo.MenuCommand.mcom_stack;
1702 return mle;
1705 static SAVEDS(void) INTERRUPT TreeDestructFunc(struct Hook *hook, APTR obj, struct MUIP_NListtree_DestructMessage *ltdm)
1707 struct MenuListEntry *mle = (struct MenuListEntry *) ltdm->UserData;
1709 d1(kprintf("%s/%s/%ld: mle=%08lx\n", __FILE__, __FUNC__, __LINE__, mle));
1711 if (mle)
1713 if (mle->llist_UnSelImageObj)
1715 DoMethod(obj, MUIM_NList_UseImage, NULL, mle->llist_UnSelImageIndex, 0);
1717 MUI_DisposeObject(mle->llist_UnSelImageObj);
1718 mle->llist_UnSelImageObj = NULL;
1720 FreePooled(ltdm->MemPool, mle, sizeof(struct MenuListEntry));
1723 ltdm->UserData = NULL;
1726 static SAVEDS(ULONG) INTERRUPT TreeDisplayFunc(struct Hook *hook, APTR obj, struct MUIP_NListtree_DisplayMessage *ltdm)
1728 static CONST_STRPTR EntryTypeNames[] =
1730 "\33b\33u", // MainMenu
1731 "\33b", // Menu
1732 "", // MenuItem
1733 "\33i", // Command
1734 "\33b\338" // ToolsMenu
1736 struct MenuListEntry *mle = (struct MenuListEntry *) ltdm->TreeNode->tn_User;
1738 d1(kprintf("%s/%s/%ld: mle=%08lx\n", __FILE__, __FUNC__, __LINE__, mle));
1740 if (mle)
1742 ltdm->Preparse[0] = (STRPTR) EntryTypeNames[mle->llist_EntryType];
1744 d1(kprintf("%s/%s/%ld: EntryName=<%s> commandType=%ld\n", \
1745 __FILE__, __FUNC__, __LINE__, mle->llist_name, mle->llist_CommandType));
1747 switch (mle->llist_EntryType)
1749 case SCAMENUTYPE_Command:
1750 ltdm->Array[0] = mle->llist_name;
1751 ltdm->Array[1] = "";
1752 break;
1753 case SCAMENUTYPE_MenuItem:
1754 if (0 == strlen(ltdm->TreeNode->tn_Name))
1755 ltdm->Array[0] = GetLocString(MSGID_BARNAME);
1756 else
1758 if (mle->llist_UnSelImageObj)
1760 snprintf(mle->llist_MenuItemName, sizeof(mle->llist_MenuItemName),
1761 "\33o[%ld]%s",
1762 (long)mle->llist_UnSelImageIndex, ltdm->TreeNode->tn_Name);
1763 ltdm->Array[0] = mle->llist_MenuItemName;
1765 else
1767 ltdm->Array[0] = ltdm->TreeNode->tn_Name;
1770 ltdm->Array[1] = mle->llist_HotKey;
1771 break;
1772 default:
1773 ltdm->Array[0] = ltdm->TreeNode->tn_Name;
1774 ltdm->Array[1] = "";
1775 break;
1779 return 0;
1782 //----------------------------------------------------------------------------
1784 static SAVEDS(ULONG) INTERRUPT ImagePopAslFileStartHookFunc(struct Hook *hook, Object *o, Msg msg)
1786 struct TagItem *TagList = (struct TagItem *) msg;
1787 // struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
1789 d1(KPrintF("%s/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
1791 while (TAG_END != TagList->ti_Tag)
1792 TagList++;
1794 TagList->ti_Tag = ASLFR_DrawersOnly;
1795 TagList->ti_Data = FALSE;
1796 TagList++;
1798 // TagList->ti_Tag = ASLFR_InitialFile;
1799 // TagList->ti_Data = (ULONG) inst->fpb_FileName;
1800 // TagList++;
1802 TagList->ti_Tag = ASLFR_InitialDrawer;
1803 TagList->ti_Data = (ULONG) "THEME:FileTypes/";
1804 TagList++;
1806 TagList->ti_Tag = TAG_END;
1808 return TRUE;
1811 //----------------------------------------------------------------------------
1813 static STRPTR GetLocString(ULONG MsgId)
1815 struct ScalosMenu_LocaleInfo li;
1817 li.li_Catalog = MenuPrefsCatalog;
1818 #ifndef __amigaos4__
1819 li.li_LocaleBase = LocaleBase;
1820 #else
1821 li.li_ILocale = ILocale;
1822 #endif
1824 return (STRPTR) GetScalosMenuString(&li, MsgId);
1827 static void TranslateStringArray(STRPTR *stringArray)
1829 while (*stringArray)
1831 *stringArray = GetLocString((ULONG) *stringArray);
1832 stringArray++;
1836 static void TranslateNewMenu(struct NewMenu *nm)
1838 while (nm && NM_END != nm->nm_Type)
1840 if (NM_BARLABEL != nm->nm_Label)
1841 nm->nm_Label = GetLocString((ULONG) nm->nm_Label);
1843 if (nm->nm_CommKey)
1844 nm->nm_CommKey = GetLocString((ULONG) nm->nm_CommKey);
1846 nm++;
1850 //----------------------------------------------------------------------------
1852 static SAVEDS(APTR) INTERRUPT ResetToDefaultsHookFunc(struct Hook *hook, Object *o, Msg msg)
1854 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
1856 d1(KPrintF("%s/%s//%ld: START\n", __FILE__, __FUNC__, __LINE__));
1858 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Quiet, TRUE);
1859 set(inst->mpb_Objects[OBJNDX_HiddenListTree], MUIA_NListtree_Quiet, TRUE);
1860 d1(KPrintF("%s/%s//%ld: \n", __FILE__, __FUNC__, __LINE__));
1862 // Remove main menu contents
1863 ClearMenuList(inst);
1864 d1(KPrintF("%s/%s//%ld: \n", __FILE__, __FUNC__, __LINE__));
1866 set(inst->mpb_MainMenuNode.mpn_Listtree,
1867 MUIA_NListtree_Active, (ULONG) inst->mpb_MainMenuNode.mpn_ListNode);
1869 d1(KPrintF("%s/%s//%ld: \n", __FILE__, __FUNC__, __LINE__));
1871 AddDefaultMenuContents(inst);
1873 d1(KPrintF("%s/%s//%ld: \n", __FILE__, __FUNC__, __LINE__));
1875 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree], MUIM_NListtree_Close,
1876 MUIV_NListtree_Close_ListNode_Root, MUIV_NListtree_Close_TreeNode_All, 0);
1878 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Quiet, FALSE);
1879 set(inst->mpb_Objects[OBJNDX_HiddenListTree], MUIA_NListtree_Quiet, FALSE);
1881 d1(KPrintF("%s/%s//%ld: END\n", __FILE__, __FUNC__, __LINE__));
1883 return 0;
1886 //----------------------------------------------------------------------------
1888 static SAVEDS(APTR) INTERRUPT OpenHookFunc(struct Hook *hook, Object *o, Msg msg)
1890 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
1892 if (NULL == inst->mpb_LoadReq)
1894 inst->mpb_LoadReq = MUI_AllocAslRequestTags(ASL_FileRequest,
1895 ASLFR_InitialFile, "Menu.pre",
1896 ASLFR_Flags1, FRF_DOPATTERNS,
1897 ASLFR_InitialDrawer, "SYS:Prefs/presets",
1898 ASLFR_InitialPattern, "#?.(pre|prefs)",
1899 ASLFR_UserData, inst,
1900 ASLFR_IntuiMsgFunc, &inst->mpb_Hooks[HOOKNDX_AslIntuiMsg],
1901 TAG_END);
1903 if (inst->mpb_LoadReq)
1905 BOOL Result;
1906 struct Window *win = NULL;
1908 get(inst->mpb_Objects[OBJNDX_WIN_Main], MUIA_Window_Window, &win);
1910 //AslRequest(
1911 Result = MUI_AslRequestTags(inst->mpb_LoadReq,
1912 ASLFR_Window, win,
1913 ASLFR_SleepWindow, TRUE,
1914 ASLFR_TitleText, GetLocString(MSGID_MENU_PROJECT_OPEN),
1915 TAG_END);
1917 if (Result)
1919 BPTR dirLock = Lock(inst->mpb_LoadReq->fr_Drawer, ACCESS_READ);
1921 if (dirLock)
1923 BPTR oldDir = CurrentDir(dirLock);
1925 ClearMenuList(inst);
1926 ReadPrefsFile(inst, inst->mpb_LoadReq->fr_File, FALSE);
1928 CurrentDir(oldDir);
1929 UnLock(dirLock);
1934 return 0;
1938 static SAVEDS(APTR) INTERRUPT MergeHookFunc(struct Hook *hook, Object *o, Msg msg)
1940 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
1942 if (NULL == inst->mpb_LoadReq)
1944 inst->mpb_LoadReq = MUI_AllocAslRequestTags(ASL_FileRequest,
1945 ASLFR_InitialFile, "Menu.pre",
1946 ASLFR_Flags1, FRF_DOPATTERNS,
1947 ASLFR_InitialDrawer, "SYS:Prefs/presets",
1948 ASLFR_InitialPattern, "#?.(pre|prefs)",
1949 ASLFR_UserData, inst,
1950 ASLFR_IntuiMsgFunc, &inst->mpb_Hooks[HOOKNDX_AslIntuiMsg],
1951 TAG_END);
1953 if (inst->mpb_LoadReq)
1955 BOOL Result;
1956 struct Window *win = NULL;
1958 get(inst->mpb_Objects[OBJNDX_WIN_Main], MUIA_Window_Window, &win);
1960 //AslRequest(
1961 Result = MUI_AslRequestTags(inst->mpb_LoadReq,
1962 ASLFR_Window, win,
1963 ASLFR_SleepWindow, TRUE,
1964 ASLFR_TitleText, GetLocString(MSGID_MENU_PROJECT_MERGE_ASLTITLE),
1965 TAG_END);
1967 if (Result)
1969 BPTR dirLock = Lock(inst->mpb_LoadReq->fr_Drawer, ACCESS_READ);
1971 if (dirLock)
1973 BPTR oldDir = CurrentDir(dirLock);
1975 ReadPrefsFile(inst, inst->mpb_LoadReq->fr_File, FALSE);
1977 SetChangedFlag(inst, TRUE);
1979 CurrentDir(oldDir);
1980 UnLock(dirLock);
1985 return 0;
1988 static SAVEDS(APTR) INTERRUPT LastSavedHookFunc(struct Hook *hook, Object *o, Msg msg)
1990 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
1992 ClearMenuList(inst);
1993 ReadPrefsFile(inst, "ENVARC:Scalos/Menu13.prefs", FALSE);
1994 SetChangedFlag(inst, TRUE);
1996 return 0;
1999 static SAVEDS(APTR) INTERRUPT RestoreHookFunc(struct Hook *hook, Object *o, Msg msg)
2001 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
2003 ClearMenuList(inst);
2004 ReadPrefsFile(inst, "ENV:Scalos/Menu13.prefs", FALSE);
2005 SetChangedFlag(inst, TRUE);
2007 return 0;
2010 static SAVEDS(APTR) INTERRUPT SaveAsHookFunc(struct Hook *hook, Object *o, Msg msg)
2012 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
2014 if (NULL == inst->mpb_SaveReq)
2016 CONST_STRPTR InitialDrawer;
2017 CONST_STRPTR InitialFile;
2019 if (inst->mpb_LoadReq)
2021 InitialDrawer = inst->mpb_LoadReq->fr_Drawer;
2022 InitialFile = inst->mpb_LoadReq->fr_File;
2024 else
2026 InitialDrawer = "SYS:Prefs/presets";
2027 InitialFile = "Menu.pre";
2030 inst->mpb_SaveReq = MUI_AllocAslRequestTags(ASL_FileRequest,
2031 ASLFR_InitialFile, InitialFile,
2032 ASLFR_DoSaveMode, TRUE,
2033 ASLFR_InitialDrawer, InitialDrawer,
2034 ASLFR_UserData, inst,
2035 ASLFR_IntuiMsgFunc, &inst->mpb_Hooks[HOOKNDX_AslIntuiMsg],
2036 TAG_END);
2038 if (inst->mpb_SaveReq)
2040 BOOL Result;
2041 struct Window *win = NULL;
2043 get(inst->mpb_Objects[OBJNDX_WIN_Main], MUIA_Window_Window, &win);
2045 //AslRequest(
2046 Result = MUI_AslRequestTags(inst->mpb_SaveReq,
2047 ASLFR_TitleText, GetLocString(MSGID_MENU_PROJECT_SAVEAS),
2048 ASLFR_Window, win,
2049 ASLFR_SleepWindow, TRUE,
2050 TAG_END);
2052 if (Result)
2054 BPTR dirLock = Lock(inst->mpb_SaveReq->fr_Drawer, ACCESS_READ);
2056 if (dirLock)
2058 BPTR oldDir = CurrentDir(dirLock);
2060 WritePrefsFile(inst, inst->mpb_SaveReq->fr_File);
2062 CurrentDir(oldDir);
2063 UnLock(dirLock);
2068 return 0;
2072 static SAVEDS(APTR) INTERRUPT AboutHookFunc(struct Hook *hook, Object *o, Msg msg)
2074 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
2076 MUI_Request(inst->mpb_Objects[OBJNDX_APP_Main], inst->mpb_Objects[OBJNDX_WIN_Main], 0, NULL,
2077 GetLocString(MSGID_ABOUTREQOK),
2078 GetLocString(MSGID_ABOUTREQFORMAT),
2079 MajorVersion, MinorVersion, COMPILER_STRING, CURRENTYEAR);
2081 return 0;
2084 //----------------------------------------------------------------------------
2086 static SAVEDS(APTR) INTERRUPT RenameEntryHookFunc(struct Hook *hook, Object *o, Msg msg)
2088 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
2089 struct MUI_NListtree_TreeNode *TreeNode;
2091 if (inst->mpb_QuietFlag)
2092 return 0;
2094 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
2095 MUIM_NListtree_GetEntry,
2096 MUIV_NListtree_GetEntry_ListNode_Active,
2097 MUIV_NListtree_GetEntry_Position_Active, 0);
2099 if (TreeNode)
2101 struct MenuListEntry *mle = (struct MenuListEntry *) TreeNode->tn_User;
2102 STRPTR newName = "";
2103 BOOL MayAddCommand, MayHaveHotkey;
2105 SetChangedFlag(inst, TRUE);
2107 get(inst->mpb_Objects[OBJNDX_NameString], MUIA_String_Contents, &newName);
2109 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Quiet, TRUE);
2111 stccpy(mle->llist_name, newName, sizeof(mle->llist_name));
2113 if (0 == strlen(newName))
2115 // Remove all children from the new "=== Bar ==="
2116 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
2117 MUIM_NListtree_Remove,
2118 TreeNode,
2119 MUIV_NListtree_Remove_TreeNode_All);
2121 // BAR may not have a hotkey
2122 strcpy(mle->llist_HotKey, "");
2124 TreeNode->tn_Flags |= TNF_NOSIGN;
2126 else
2128 TreeNode->tn_Flags &= ~TNF_NOSIGN;
2131 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
2132 MUIM_NListtree_Rename,
2133 TreeNode,
2134 newName,
2137 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Quiet, FALSE);
2139 MayAddCommand = (strlen(mle->llist_name) > 0) &&
2140 ((SCAMENUTYPE_MenuItem == mle->llist_EntryType)
2141 || (SCAMENUTYPE_Command == mle->llist_EntryType));
2143 MayHaveHotkey = (strlen(mle->llist_name) > 0)
2144 && SCAMENUTYPE_MenuItem == mle->llist_EntryType;
2146 set(inst->mpb_Objects[OBJNDX_StringHotkey], MUIA_Disabled, !MayHaveHotkey);
2147 set(inst->mpb_Objects[OBJNDX_NewCommandButton], MUIA_Disabled, !MayAddCommand);
2150 return 0;
2154 static SAVEDS(APTR) INTERRUPT ChangeHotkeyHookFunc(struct Hook *hook, Object *o, Msg msg)
2156 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
2157 STRPTR newHotKey = *(STRPTR *) msg;
2158 struct MUI_NListtree_TreeNode *TreeNode;
2160 if (inst->mpb_QuietFlag)
2161 return 0;
2163 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
2164 MUIM_NListtree_GetEntry,
2165 MUIV_NListtree_GetEntry_ListNode_Active,
2166 MUIV_NListtree_GetEntry_Position_Active, 0);
2168 if (TreeNode)
2170 struct MenuListEntry *mle = (struct MenuListEntry *) TreeNode->tn_User;
2172 SetChangedFlag(inst, TRUE);
2174 mle->llist_HotKey[0] = *newHotKey;
2175 mle->llist_HotKey[1] = '\0';
2177 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
2178 MUIM_NListtree_Redraw,
2179 TreeNode,
2183 return 0;
2186 static SAVEDS(APTR) INTERRUPT ChangeEntry3HookFunc(struct Hook *hook, Object *o, Msg msg)
2188 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
2189 struct MUI_NListtree_TreeNode *TreeNode;
2191 if (inst->mpb_QuietFlag)
2192 return 0;
2194 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
2195 MUIM_NListtree_GetEntry,
2196 MUIV_NListtree_GetEntry_ListNode_Active,
2197 MUIV_NListtree_GetEntry_Position_Active, 0);
2199 if (TreeNode)
2201 struct MenuListEntry *mle = (struct MenuListEntry *) TreeNode->tn_User;
2203 if (SCAMENUTYPE_Command == mle->llist_EntryType)
2205 STRPTR string = NULL;
2206 ULONG Value = 0;
2207 LONG sValue = 0;
2209 SetChangedFlag(inst, TRUE);
2211 get(inst->mpb_Objects[OBJNDX_StringCmd], MUIA_String_Contents, &string);
2212 stccpy(mle->llist_name, string, sizeof(mle->llist_name));
2214 get(inst->mpb_Objects[OBJNDX_CycleGad], MUIA_Cycle_Active, &Value);
2215 mle->llist_CommandType = Value;
2217 SwitchPopButton(inst, Value);
2219 get(inst->mpb_Objects[OBJNDX_CheckArgs], MUIA_Selected, &Value);
2220 if (Value)
2221 mle->llist_CommandFlags |= MCOMFLGF_Args;
2222 else
2223 mle->llist_CommandFlags &= ~MCOMFLGF_Args;
2225 EnableCommandArgumentGadgets(inst, mle);
2227 get(inst->mpb_Objects[OBJNDX_StringStack], MUIA_String_Integer, &mle->llist_Stack);
2229 get(inst->mpb_Objects[OBJNDX_SliderPriority], MUIA_Numeric_Value, &sValue);
2230 mle->llist_Priority = sValue;
2232 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree], MUIM_NList_Redraw, MUIV_NList_Redraw_Active);
2236 return 0;
2240 static SAVEDS(APTR) INTERRUPT ChangeUnselectedImageHookFunc(struct Hook *hook, Object *o, Msg msg)
2242 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
2243 STRPTR NewImage = *(STRPTR *) msg;
2244 struct MUI_NListtree_TreeNode *TreeNode;
2246 if (inst->mpb_QuietFlag)
2247 return 0;
2249 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(o,
2250 MUIM_NListtree_GetEntry,
2251 MUIV_NListtree_GetEntry_ListNode_Active,
2252 MUIV_NListtree_GetEntry_Position_Active, 0);
2254 if (TreeNode)
2256 struct MenuListEntry *mle = (struct MenuListEntry *) TreeNode->tn_User;
2258 SetChangedFlag(inst, TRUE);
2260 stccpy(mle->llist_UnselectedIconName, NewImage, sizeof(mle->llist_UnselectedIconName));
2261 set(inst->mpb_Objects[OBJNDX_DtImage_UnselectedImage], MUIA_ScaDtpic_Name, (ULONG) mle->llist_UnselectedIconName);
2263 if (mle->llist_UnSelImageObj)
2265 MUI_DisposeObject(mle->llist_UnSelImageObj);
2266 mle->llist_UnSelImageObj = NULL;
2268 DoMethod(o, MUIM_NList_UseImage, mle->llist_UnSelImageObj, mle->llist_UnSelImageIndex, 0);
2270 if (0 == mle->llist_UnSelImageIndex)
2271 mle->llist_UnSelImageIndex = ++inst->mpb_TreeImageIndex;
2273 if (strlen(mle->llist_UnselectedIconName) > 0)
2275 mle->llist_UnSelImageObj = DataTypesImageObject,
2276 MUIA_ScaDtpic_Name, (ULONG) mle->llist_UnselectedIconName,
2277 End;
2278 DoMethod(o, MUIM_NList_UseImage, mle->llist_UnSelImageObj, mle->llist_UnSelImageIndex, 0);
2281 DoMethod(o,
2282 MUIM_NListtree_Redraw,
2283 TreeNode,
2287 return 0;
2291 static SAVEDS(APTR) INTERRUPT ChangeSelectedImageHookFunc(struct Hook *hook, Object *o, Msg msg)
2293 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
2294 STRPTR NewImage = *(STRPTR *) msg;
2295 struct MUI_NListtree_TreeNode *TreeNode;
2297 if (inst->mpb_QuietFlag)
2298 return 0;
2300 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(o,
2301 MUIM_NListtree_GetEntry,
2302 MUIV_NListtree_GetEntry_ListNode_Active,
2303 MUIV_NListtree_GetEntry_Position_Active, 0);
2305 if (TreeNode)
2307 struct MenuListEntry *mle = (struct MenuListEntry *) TreeNode->tn_User;
2309 SetChangedFlag(inst, TRUE);
2311 stccpy(mle->llist_SelectedIconName, NewImage, sizeof(mle->llist_SelectedIconName));
2312 set(inst->mpb_Objects[OBJNDX_DtImage_SelectedImage], MUIA_ScaDtpic_Name, (ULONG) mle->llist_SelectedIconName);
2314 DoMethod(o,
2315 MUIM_NListtree_Redraw,
2316 TreeNode,
2320 return 0;
2324 static SAVEDS(APTR) INTERRUPT SelectEntryHookFunc(struct Hook *hook, Object *o, Msg msg)
2326 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
2327 struct MUI_NListtree_TreeNode *TreeNode = *(struct MUI_NListtree_TreeNode **) msg;
2329 if (inst->mpb_QuietFlag)
2330 return 0;
2332 inst->mpb_QuietFlag = TRUE;
2334 if (TreeNode)
2336 struct MenuListEntry *mle = (struct MenuListEntry *) TreeNode->tn_User;
2338 if (mle)
2340 struct MUI_NListtree_TreeNode *tnShadow;
2341 BOOL MayAddNewMenu, MayAddNewItem, MayAddCommand;
2342 BOOL MayChangeName, MayDelete, MayHaveHotkey;
2343 BOOL MayHaveImage;
2344 enum MenuEntryType menuType;
2345 ULONG Count, MaxCount;
2347 Count = DoMethod(inst->mpb_Objects[OBJNDX_MainListTree], MUIM_NListtree_GetNr,
2348 TreeNode, MUIV_NListtree_GetNr_Flag_CountLevel);
2350 menuType = GetMenuEntryType(inst, TreeNode);
2351 MaxCount = GetMaxCountForEntry(menuType);
2353 MayAddNewMenu = (SCAMENUTYPE_Command != mle->llist_EntryType) &&
2354 Count < MaxCount &&
2355 menuType < MENUENTRY_SubItem;
2357 d1(kprintf("%s/%s/%ld: menuType=%lu EntryCount=%lu MaxCount=%lu\n", \
2358 __FILE__, __FUNC__, __LINE__, menuType, Count, MaxCount));
2360 MayAddNewItem = ((SCAMENUTYPE_MainMenu != mle->llist_EntryType) || (mle->llist_Flags & LLISTFLGF_PopupMenu)) &&
2361 Count < MaxCount &&
2362 (!(mle->llist_Flags & LLISTFLGF_MayNotHaveChildren) || (mle->llist_Flags & LLISTFLGF_PopupMenu));
2364 MayAddCommand = (mle->llist_name && strlen(mle->llist_name) > 0) &&
2365 ((SCAMENUTYPE_MenuItem == mle->llist_EntryType)
2366 || (SCAMENUTYPE_Command == mle->llist_EntryType));
2368 MayChangeName = (SCAMENUTYPE_Command != mle->llist_EntryType)
2369 && (SCAMENUTYPE_MainMenu != mle->llist_EntryType)
2370 && !(mle->llist_Flags & LLISTFLGF_NameNotSetable);
2372 MayDelete = !(mle->llist_Flags & LLISTFLGF_NotRemovable);
2374 MayHaveHotkey = (strlen(mle->llist_name) > 0)
2375 && SCAMENUTYPE_MenuItem == mle->llist_EntryType;
2377 MayHaveImage = (mle->llist_name && strlen(mle->llist_name) > 0) &&
2378 IsPopupMenu(inst, TreeNode) &&
2379 (SCAMENUTYPE_Menu == mle->llist_EntryType
2380 || SCAMENUTYPE_MenuItem == mle->llist_EntryType);
2382 if (SCAMENUTYPE_Command == mle->llist_EntryType)
2384 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
2385 MUIM_NListtree_GetEntry, TreeNode, MUIV_NListtree_GetEntry_Position_Parent, 0);
2388 // Cannot cut or copy entire main/tool/popup menus
2389 if ((SCAMENUTYPE_MainMenu == mle->llist_EntryType)
2390 || (SCAMENUTYPE_ToolsMenu == mle->llist_EntryType))
2392 set(inst->mpb_Objects[OBJNDX_Menu_Copy], MUIA_Menuitem_Enabled, FALSE);
2393 set(inst->mpb_Objects[OBJNDX_Menu_Cut], MUIA_Menuitem_Enabled, FALSE);
2395 else
2397 set(inst->mpb_Objects[OBJNDX_Menu_Copy], MUIA_Menuitem_Enabled, TRUE);
2398 set(inst->mpb_Objects[OBJNDX_Menu_Cut], MUIA_Menuitem_Enabled, TRUE);
2401 d1(kprintf("%s/%s/%ld: tn_Name=%08lx\n", __FILE__, __FUNC__, __LINE__, TreeNode->tn_Name));
2403 set(inst->mpb_Objects[OBJNDX_NameString], MUIA_String_Contents, (ULONG) TreeNode->tn_Name);
2404 set(inst->mpb_Objects[OBJNDX_StringHotkey], MUIA_String_Contents, (ULONG) mle->llist_HotKey);
2405 set(inst->mpb_Objects[OBJNDX_PopAsl_UnselectedImage], MUIA_String_Contents, (ULONG) mle->llist_UnselectedIconName);
2406 set(inst->mpb_Objects[OBJNDX_PopAsl_SelectedImage], MUIA_String_Contents, (ULONG) mle->llist_SelectedIconName);
2407 set(inst->mpb_Objects[OBJNDX_DtImage_UnselectedImage], MUIA_ScaDtpic_Name, (ULONG) mle->llist_UnselectedIconName);
2408 set(inst->mpb_Objects[OBJNDX_DtImage_SelectedImage], MUIA_ScaDtpic_Name, (ULONG) mle->llist_SelectedIconName);
2410 set(inst->mpb_Objects[OBJNDX_DelButton], MUIA_Disabled, !MayDelete);
2411 set(inst->mpb_Objects[OBJNDX_NameString], MUIA_Disabled, !MayChangeName);
2412 set(inst->mpb_Objects[OBJNDX_NewItemButton], MUIA_Disabled, !MayAddNewItem);
2413 set(inst->mpb_Objects[OBJNDX_NewCommandButton], MUIA_Disabled, !MayAddCommand);
2414 set(inst->mpb_Objects[OBJNDX_NewMenuButton], MUIA_Disabled, !MayAddNewMenu);
2415 set(inst->mpb_Objects[OBJNDX_PopAsl_UnselectedImage], MUIA_Disabled, !MayHaveImage);
2416 set(inst->mpb_Objects[OBJNDX_PopAsl_SelectedImage], MUIA_Disabled, !MayHaveImage);
2418 set(inst->mpb_Objects[OBJNDX_Menu_CollapseSelected], MUIA_Menuitem_Enabled, TRUE);
2419 set(inst->mpb_Objects[OBJNDX_Menu_ExpandSelected], MUIA_Menuitem_Enabled, TRUE);
2421 set(inst->mpb_Objects[OBJNDX_StringHotkey], MUIA_Disabled, !MayHaveHotkey);
2422 set(inst->mpb_Objects[OBJNDX_Group_String], MUIA_Disabled, (SCAMENUTYPE_Command != mle->llist_EntryType));
2423 set(inst->mpb_Objects[OBJNDX_Group_CmdProperties], MUIA_Disabled, (SCAMENUTYPE_Command != mle->llist_EntryType));
2425 tnShadow = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_ListTreeClipboard],
2426 MUIM_NListtree_GetEntry,
2427 MUIV_NListtree_Insert_ListNode_Root,
2428 MUIV_NListtree_GetEntry_Position_Head,
2431 if (tnShadow)
2433 if (MayPasteBelow(inst, TreeNode, tnShadow))
2435 set(inst->mpb_Objects[OBJNDX_Menu_Paste], MUIA_Menuitem_Enabled, TRUE);
2437 else if (MayPasteOnto(inst, TreeNode, tnShadow))
2439 set(inst->mpb_Objects[OBJNDX_Menu_Paste], MUIA_Menuitem_Enabled, TRUE);
2441 else
2443 set(inst->mpb_Objects[OBJNDX_Menu_Paste], MUIA_Menuitem_Enabled, FALSE);
2446 else
2448 set(inst->mpb_Objects[OBJNDX_Menu_Paste], MUIA_Menuitem_Enabled, FALSE);
2451 if (SCAMENUTYPE_Command == mle->llist_EntryType)
2453 SwitchPopButton(inst, mle->llist_CommandType);
2455 set(inst->mpb_Objects[OBJNDX_StringCmd], MUIA_String_Contents, (ULONG) mle->llist_name);
2456 set(inst->mpb_Objects[OBJNDX_StringStack], MUIA_String_Integer, (ULONG) mle->llist_Stack);
2457 set(inst->mpb_Objects[OBJNDX_SliderPriority], MUIA_Numeric_Value, (LONG) mle->llist_Priority);
2458 set(inst->mpb_Objects[OBJNDX_CycleGad], MUIA_Cycle_Active, (ULONG) mle->llist_CommandType);
2461 else
2463 set(inst->mpb_Objects[OBJNDX_StringCmd], MUIA_String_Contents, (ULONG) "");
2466 EnableCommandArgumentGadgets(inst, mle);
2469 else
2471 set(inst->mpb_Objects[OBJNDX_Menu_Copy], MUIA_Menuitem_Enabled, FALSE);
2472 set(inst->mpb_Objects[OBJNDX_Menu_Cut], MUIA_Menuitem_Enabled, FALSE);
2473 set(inst->mpb_Objects[OBJNDX_Menu_CollapseSelected], MUIA_Menuitem_Enabled, FALSE);
2474 set(inst->mpb_Objects[OBJNDX_Menu_ExpandSelected], MUIA_Menuitem_Enabled, FALSE);
2476 set(inst->mpb_Objects[OBJNDX_NameString], MUIA_Disabled, TRUE);
2477 set(inst->mpb_Objects[OBJNDX_StringHotkey], MUIA_Disabled, TRUE);
2478 set(inst->mpb_Objects[OBJNDX_DelButton], MUIA_Disabled, TRUE);
2479 set(inst->mpb_Objects[OBJNDX_Group_String], MUIA_Disabled, TRUE);
2480 set(inst->mpb_Objects[OBJNDX_Group_CmdProperties], MUIA_Disabled, TRUE);
2481 set(inst->mpb_Objects[OBJNDX_PopAsl_UnselectedImage], MUIA_Disabled, TRUE);
2482 set(inst->mpb_Objects[OBJNDX_PopAsl_SelectedImage], MUIA_Disabled, TRUE);
2483 #if 0
2484 set(inst->mpb_Objects[OBJNDX_Menu_Paste], MUIA_Menuitem_Enabled, FALSE);
2485 #endif
2488 inst->mpb_QuietFlag = FALSE;
2490 return 0;
2493 static SAVEDS(APTR) INTERRUPT PopButtonHookFunc(struct Hook *hook, Object *o, Msg msg)
2495 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
2496 struct MenuListEntry *mle;
2497 struct FileRequester *Req;
2498 struct MUI_NListtree_TreeNode *TreeNode;
2499 ULONG CommandType = 0;
2501 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
2502 MUIM_NListtree_GetEntry,
2503 MUIV_NListtree_GetEntry_ListNode_Active,
2504 MUIV_NListtree_GetEntry_Position_Active, 0);
2505 if (NULL == TreeNode)
2506 return 0;
2508 get(inst->mpb_Objects[OBJNDX_CycleGad], MUIA_Cycle_Active, &CommandType);
2510 mle = (struct MenuListEntry *) TreeNode->tn_User;
2511 Req = MUI_AllocAslRequest(ASL_FileRequest, NULL);
2513 if (Req)
2515 char FileName[512];
2516 struct Window *win = NULL;
2517 BOOL Result;
2518 STRPTR p, path = NULL;
2519 BOOL drawersOnly = FALSE;
2520 ULONG AslTitle = MSGID_IMPORTNAME;
2522 get(inst->mpb_Objects[OBJNDX_StringCmd], MUIA_String_Contents, &path);
2523 get(inst->mpb_Objects[OBJNDX_WIN_Main], MUIA_Window_Window, &win);
2525 switch (CommandType)
2527 case SCAMENUCMDTYPE_AmigaDOS:
2528 AslTitle = MSGID_POPUP_ASLTITLE_AMIGADOS;
2529 break;
2530 case SCAMENUCMDTYPE_Workbench:
2531 AslTitle = MSGID_POPUP_ASLTITLE_WORKBENCH;
2532 break;
2533 case SCAMENUCMDTYPE_IconWindow:
2534 drawersOnly = TRUE;
2535 AslTitle = MSGID_POPUP_ASLTITLE_ICONWINDOW;
2536 break;
2537 case SCAMENUCMDTYPE_ARexx:
2538 AslTitle = MSGID_POPUP_ASLTITLE_AREXX;
2539 break;
2540 case SCAMENUCMDTYPE_Plugin:
2541 AslTitle = MSGID_POPUP_ASLTITLE_MENUPLUGIN;
2542 if (0 == strlen(path))
2543 strcpy(path, "scalos:Plugins/Menu/");
2544 break;
2545 default:
2546 break;
2549 if (drawersOnly)
2550 strcpy(FileName, "");
2551 else
2552 stccpy(FileName, FilePart(path), sizeof(FileName));
2554 p = PathPart(path);
2555 *p = '\0';
2557 d1(kprintf("%s/%s//%ld: InitialFile=<%s> InitialDrawer=<%s>\n", __FILE__, __FUNC__, __LINE__, FileName, path));
2558 d1(kprintf("%s/%s//%ld: DrawersOnly=%ld\n", __FILE__, __FUNC__, __LINE__, drawersOnly));
2560 Result = MUI_AslRequestTags(Req,
2561 ASLFR_TitleText, GetLocString(MSGID_MENU_PROJECT_SAVEAS),
2562 ASLFR_Window, win,
2563 ASLFR_SleepWindow, TRUE,
2564 ASLFR_TitleText, GetLocString(AslTitle),
2565 ASLFR_Flags1, FRF_DOPATTERNS,
2566 ASLFR_InitialFile, FileName,
2567 ASLFR_InitialDrawer, path,
2568 ASLFR_DrawersOnly, drawersOnly,
2569 TAG_END);
2571 if (Result)
2573 struct DiskObject *icon;
2575 SetChangedFlag(inst, TRUE);
2577 d1(kprintf("%s/%s//%ld: fr_Drawer=<%s> fr_File=<%s>\n", __FILE__, __FUNC__, __LINE__, Req->fr_Drawer, Req->fr_File));
2579 stccpy(FileName, Req->fr_Drawer, sizeof(FileName));
2581 if (!drawersOnly)
2582 AddPart(FileName, Req->fr_File, sizeof(FileName));
2584 d1(kprintf("%s/%s//%ld: FileName=<%s>\n", __FILE__, __FUNC__, __LINE__, FileName));
2586 set(inst->mpb_Objects[OBJNDX_StringCmd], MUIA_String_Contents, (ULONG) FileName);
2587 stccpy(mle->llist_name, FileName, sizeof(mle->llist_name));
2589 icon = GetDiskObject(FileName);
2590 if (icon)
2592 STRPTR ToolString;
2593 ULONG ToolPri = 0;
2595 get(inst->mpb_Objects[OBJNDX_SliderPriority], MUIA_Numeric_Value, &ToolPri);
2596 set(inst->mpb_Objects[OBJNDX_StringStack], MUIA_String_Integer, icon->do_StackSize);
2598 ToolString = FindToolType(icon->do_ToolTypes, "TOOLPRI");
2599 if (ToolString)
2601 long long1;
2602 sscanf(ToolString, "%ld", &long1);
2603 ToolPri = long1;
2606 set(inst->mpb_Objects[OBJNDX_SliderPriority], MUIA_Numeric_Value, (LONG) ToolPri);
2608 FreeDiskObject(icon);
2611 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree], MUIM_NList_Redraw, MUIV_NList_Redraw_Active);
2615 return 0;
2619 static SAVEDS(APTR) INTERRUPT AddMenuHookFunc(struct Hook *hook, Object *o, Msg msg)
2621 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
2622 struct MUI_NListtree_TreeNode *ParentNode;
2623 struct MUI_NListtree_TreeNode *PrevNode;
2624 struct MenuInsertEntry mie;
2625 struct ScalosMenuTree mTree;
2627 memset(&mTree, 0, sizeof(mTree));
2628 mTree.mtre_type = SCAMENUTYPE_Menu;
2629 mie.mie_TreeEntry = &mTree;
2630 mie.mie_MenuFlags = 0;
2632 SetChangedFlag(inst, TRUE);
2634 ParentNode = GetParentNodeForMenu(inst, &PrevNode);
2636 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
2637 MUIM_NListtree_Insert, GetLocString(MSGID_NEW_MENU),
2638 &mie,
2639 ParentNode, PrevNode, MUIV_NListtree_Insert_Flag_Active | TNF_OPEN | TNF_LIST);
2641 // try to activate menu name string gadget
2642 set(inst->mpb_Objects[OBJNDX_WIN_Main], MUIA_Window_ActiveObject,
2643 (ULONG) inst->mpb_Objects[OBJNDX_NameString]);
2645 return 0;
2649 static SAVEDS(APTR) INTERRUPT AddCommandHookFunc(struct Hook *hook, Object *o, Msg msg)
2651 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
2652 struct MUI_NListtree_TreeNode *ParentNode;
2653 struct MUI_NListtree_TreeNode *TreeNode;
2655 SetChangedFlag(inst, TRUE);
2657 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
2658 MUIM_NListtree_GetEntry, 0, MUIV_NListtree_GetEntry_Position_Active, 0);
2660 if (TreeNode)
2662 struct MenuListEntry *mle = (struct MenuListEntry *) TreeNode->tn_User;
2663 struct MenuInsertEntry mie;
2664 struct ScalosMenuTree mTree;
2666 memset(&mTree, 0, sizeof(mTree));
2667 mTree.mtre_type = SCAMENUTYPE_Command;
2668 mie.mie_TreeEntry = &mTree;
2669 mie.mie_MenuFlags = 0;
2671 switch (mle->llist_EntryType)
2673 case SCAMENUTYPE_MainMenu:
2674 case SCAMENUTYPE_Menu:
2675 case SCAMENUTYPE_ToolsMenu:
2676 break;
2678 case SCAMENUTYPE_MenuItem:
2679 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
2680 MUIM_NListtree_Insert, "",
2681 &mie,
2682 TreeNode, MUIV_NListtree_Insert_PrevNode_Tail,
2683 MUIV_NListtree_Insert_Flag_Active);
2685 // try to activate command name string gadget
2686 set(inst->mpb_Objects[OBJNDX_WIN_Main], MUIA_Window_ActiveObject,
2687 (ULONG) inst->mpb_Objects[OBJNDX_StringCmd]);
2688 break;
2690 case SCAMENUTYPE_Command:
2691 ParentNode = TreeNode;
2693 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
2694 MUIM_NListtree_GetEntry, TreeNode,
2695 MUIV_NListtree_GetEntry_Position_Parent, 0);
2697 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
2698 MUIM_NListtree_Insert, "",
2699 &mie,
2700 TreeNode, ParentNode,
2701 MUIV_NListtree_Insert_Flag_Active);
2703 // try to activate command name string gadget
2704 set(inst->mpb_Objects[OBJNDX_WIN_Main], MUIA_Window_ActiveObject,
2705 (ULONG) inst->mpb_Objects[OBJNDX_StringCmd]);
2706 break;
2710 return 0;
2714 static SAVEDS(APTR) INTERRUPT AddMenuItemHookFunc(struct Hook *hook, Object *o, Msg msg)
2716 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
2717 struct MUI_NListtree_TreeNode *ParentNode;
2718 struct MUI_NListtree_TreeNode *PrevNode;
2720 SetChangedFlag(inst, TRUE);
2722 ParentNode = GetParentNodeForMenuItem(inst, &PrevNode);
2724 if (ParentNode)
2726 struct MUI_NListtree_TreeNode *newNode;
2727 struct MenuInsertEntry mie;
2728 struct ScalosMenuTree mTree;
2730 memset(&mTree, 0, sizeof(mTree));
2731 mTree.mtre_type = SCAMENUTYPE_MenuItem;
2732 mie.mie_TreeEntry = &mTree;
2733 mie.mie_MenuFlags = 0;
2735 newNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
2736 MUIM_NListtree_Insert, GetLocString(MSGID_NEW_ITEM),
2737 &mie,
2738 ParentNode, PrevNode,
2739 MUIV_NListtree_Insert_Flag_Active | TNF_OPEN | TNF_LIST);
2741 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree], MUIM_NListtree_GetNr,
2742 newNode, MUIV_NListtree_GetNr_Flag_CountLevel);
2744 // try to activate menu name string gadget
2745 set(inst->mpb_Objects[OBJNDX_WIN_Main], MUIA_Window_ActiveObject,
2746 (ULONG) inst->mpb_Objects[OBJNDX_NameString]);
2748 d1(kprintf("%s/%s/%ld: Node Count=%ld\n", __FILE__, __FUNC__, __LINE__, Count));
2751 return 0;
2755 static SAVEDS(APTR) INTERRUPT RemoveEntryHookFunc(struct Hook *hook, Object *o, Msg msg)
2757 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
2759 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree], MUIM_NListtree_Remove, MUIV_NListtree_Remove_ListNode_Active,
2760 MUIV_NListtree_Remove_TreeNode_Active, 0);
2762 SetChangedFlag(inst, TRUE);
2764 return 0;
2767 //----------------------------------------------------------------------------
2769 static LONG ReadPrefsFile(struct MenuPrefsInst *inst, CONST_STRPTR Filename, BOOL Quiet)
2771 LONG Result;
2772 struct IFFHandle *iff;
2773 BOOL iffOpened = FALSE;
2774 struct ScalosMenuChunk *menuChunk = NULL;
2776 set(inst->mpb_Objects[OBJNDX_MainListView], MUIA_NListtree_Quiet, TRUE);
2778 d1(kprintf("%s/%s//%ld: LocaleBase=%08lx IFFParseBase=%08lx\n", __FILE__, __FUNC__, __LINE__, LocaleBase, IFFParseBase));
2780 do {
2781 iff = AllocIFF();
2782 if (NULL == iff)
2784 Result = IoErr();
2785 break;
2788 InitIFFasDOS(iff);
2790 iff->iff_Stream = (IPTR)Open(Filename, MODE_OLDFILE);
2791 if (0 == iff->iff_Stream)
2793 Result = IoErr();
2794 break;
2797 Result = OpenIFF(iff, IFFF_READ);
2798 if (RETURN_OK != Result)
2799 break;
2801 iffOpened = TRUE;
2803 Result = StopChunks(iff, StopChunkList, 2);
2804 if (RETURN_OK != Result)
2805 break;
2807 while (1)
2809 struct ContextNode *cn;
2811 Result = ParseIFF(iff, IFFPARSE_SCAN);
2812 d1(kprintf("%s/%s/%ld: Result=%ld\n", __FILE__, __FUNC__, __LINE__, Result));
2813 if (RETURN_OK != Result)
2814 break;
2816 cn = CurrentChunk(iff);
2818 d1(kprintf("%s/%s//%ld: cn=%08lx\n", __FILE__, __FUNC__, __LINE__, cn));
2819 if (NULL == cn)
2820 break;
2822 if (ID_MENU == cn->cn_ID)
2824 LONG Actual;
2826 menuChunk = malloc(cn->cn_Size);
2828 d1(kprintf("%s/%s//%ld: menuChunk=%08lx\n", __FILE__, __FUNC__, __LINE__, menuChunk));
2829 if (NULL == menuChunk)
2830 break;
2832 Actual = ReadChunkBytes(iff, menuChunk, cn->cn_Size);
2833 if (Actual != cn->cn_Size)
2834 break;
2836 menuChunk->smch_MenuID = SCA_BE2WORD(menuChunk->smch_MenuID);
2837 menuChunk->smch_Entries = SCA_BE2WORD(menuChunk->smch_Entries);
2839 d1(kprintf("%s/%s/%ld: MenuID=%ld Entries=%ld\n", \
2840 __FILE__, __FUNC__, __LINE__, menuChunk->smch_MenuID, menuChunk->smch_Entries));
2842 AddAddresses(menuChunk->smch_Menu, (UBYTE *) menuChunk);
2844 switch (menuChunk->smch_MenuID)
2846 case SCMID_MainMenu:
2847 GenerateMenuList(inst, menuChunk->smch_Menu,
2848 inst->mpb_MainMenuNode.mpn_Listtree,
2849 inst->mpb_MainMenuNode.mpn_ListNode);
2850 break;
2851 case SCMID_Popup_Disk:
2852 GenerateMenuList(inst, menuChunk->smch_Menu,
2853 inst->mpb_PopMenuNode[POPMENUINDEX_Disk].mpn_Listtree,
2854 inst->mpb_PopMenuNode[POPMENUINDEX_Disk].mpn_ListNode);
2855 break;
2856 case SCMID_Popup_Drawer:
2857 GenerateMenuList(inst, menuChunk->smch_Menu,
2858 inst->mpb_PopMenuNode[POPMENUINDEX_Drawer].mpn_Listtree,
2859 inst->mpb_PopMenuNode[POPMENUINDEX_Drawer].mpn_ListNode);
2860 break;
2861 case SCMID_Popup_Tool:
2862 GenerateMenuList(inst, menuChunk->smch_Menu,
2863 inst->mpb_PopMenuNode[POPMENUINDEX_ToolProject].mpn_Listtree,
2864 inst->mpb_PopMenuNode[POPMENUINDEX_ToolProject].mpn_ListNode);
2865 break;
2866 case SCMID_Popup_Trashcan:
2867 GenerateMenuList(inst, menuChunk->smch_Menu,
2868 inst->mpb_PopMenuNode[POPMENUINDEX_Trashcan].mpn_Listtree,
2869 inst->mpb_PopMenuNode[POPMENUINDEX_Trashcan].mpn_ListNode);
2870 break;
2871 case SCMID_Popup_Window:
2872 GenerateMenuList(inst, menuChunk->smch_Menu,
2873 inst->mpb_PopMenuNode[POPMENUINDEX_Window].mpn_Listtree,
2874 inst->mpb_PopMenuNode[POPMENUINDEX_Window].mpn_ListNode);
2875 break;
2876 case SCMID_Popup_AppIcon:
2877 GenerateMenuList(inst, menuChunk->smch_Menu,
2878 inst->mpb_PopMenuNode[POPMENUINDEX_AppIcon].mpn_Listtree,
2879 inst->mpb_PopMenuNode[POPMENUINDEX_AppIcon].mpn_ListNode);
2880 break;
2881 case SCMID_Popup_Desktop:
2882 GenerateMenuList(inst, menuChunk->smch_Menu,
2883 inst->mpb_PopMenuNode[POPMENUINDEX_Desktop].mpn_Listtree,
2884 inst->mpb_PopMenuNode[POPMENUINDEX_Desktop].mpn_ListNode);
2885 break;
2888 free(menuChunk);
2889 menuChunk = NULL;
2893 d1(kprintf("%s/%s/%ld: Result=%ld\n", __FILE__, __FUNC__, __LINE__, Result));
2894 if (IFFERR_EOF == Result)
2895 Result = RETURN_OK;
2896 } while (0);
2898 set(inst->mpb_Objects[OBJNDX_MainListView], MUIA_NListtree_Quiet, FALSE);
2900 if (menuChunk)
2901 free(menuChunk);
2903 if (iff)
2905 if (iffOpened)
2906 CloseIFF(iff);
2908 if (iff->iff_Stream)
2909 Close((BPTR)iff->iff_Stream);
2911 FreeIFF(iff);
2914 if (RETURN_OK != Result && !Quiet)
2916 char Buffer[120];
2918 Fault(Result, "", Buffer, sizeof(Buffer) - 1);
2920 // MUI_RequestA()
2921 MUI_Request(inst->mpb_Objects[OBJNDX_APP_Main], inst->mpb_Objects[OBJNDX_WIN_Main], 0, NULL,
2922 GetLocString(MSGID_ABOUTREQOK),
2923 GetLocString(MSGID_REQTITLE_READERROR),
2924 Filename,
2925 Buffer);
2928 // DoMethod(ScalosPenList, MUIM_NList_Redraw, MUIV_NList_Redraw_All);
2930 d1(kprintf("%s/%s/%ld: Result=%ld\n", __FILE__, __FUNC__, __LINE__, Result));
2932 return Result;
2936 static LONG WritePrefsFile(struct MenuPrefsInst *inst, CONST_STRPTR Filename)
2938 struct IFFHandle *iff;
2939 LONG Result;
2940 BOOL IffOpen = FALSE;
2942 do {
2943 static const struct PrefHeader prefHeader = { 1, 0, 0L };
2945 iff = AllocIFF();
2946 if (NULL == iff)
2948 Result = IoErr();
2949 break;
2952 InitIFFasDOS(iff);
2954 iff->iff_Stream = (IPTR)Open(Filename, MODE_NEWFILE);
2955 if (0 == iff->iff_Stream)
2957 // ... try to create missing directories here
2958 STRPTR FilenameCopy;
2960 Result = IoErr();
2961 d1(kprintf("%s/%s/%ld: Result=%ld\n", __FILE__, __FUNC__, __LINE__, Result));
2963 FilenameCopy = AllocVec(1 + strlen(Filename), MEMF_PUBLIC);
2965 if (FilenameCopy)
2967 STRPTR lp;
2969 strcpy(FilenameCopy, Filename);
2971 lp = PathPart(FilenameCopy);
2972 if (lp)
2974 BPTR dirLock;
2976 *lp = '\0';
2977 dirLock = CreateDir(FilenameCopy);
2979 if (dirLock)
2980 UnLock(dirLock);
2982 iff->iff_Stream = (IPTR)Open(Filename, MODE_NEWFILE);
2983 if (0 == iff->iff_Stream)
2984 Result = IoErr();
2985 else
2986 Result = RETURN_OK;
2989 FreeVec(FilenameCopy);
2992 d1(kprintf("%s/%s/%ld: Result=%ld\n", __FILE__, __FUNC__, __LINE__, Result));
2993 if (RETURN_OK != Result)
2994 break;
2997 Result = OpenIFF(iff, IFFF_WRITE);
2998 if (RETURN_OK != Result)
2999 break;
3001 IffOpen = TRUE;
3003 Result = PushChunk(iff, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN);
3004 if (RETURN_OK != Result)
3005 break;
3007 Result = PushChunk(iff, 0, ID_PRHD, IFFSIZE_UNKNOWN);
3008 if (RETURN_OK != Result)
3009 break;
3011 if (WriteChunkBytes(iff, (APTR) &prefHeader, sizeof(prefHeader)) < 0)
3013 Result = IoErr();
3014 break;
3017 Result = PopChunk(iff);
3018 if (RETURN_OK != Result)
3019 break;
3021 Result = SaveMenuNode(inst,
3022 iff, &inst->mpb_MainMenuNode, SCMID_MainMenu);
3023 if (RETURN_OK != Result)
3024 break;
3026 Result = SaveMenuNode(inst,
3027 iff, &inst->mpb_PopMenuNode[POPMENUINDEX_Disk], SCMID_Popup_Disk);
3028 if (RETURN_OK != Result)
3029 break;
3031 Result = SaveMenuNode(inst,
3032 iff, &inst->mpb_PopMenuNode[POPMENUINDEX_Drawer], SCMID_Popup_Drawer);
3033 if (RETURN_OK != Result)
3034 break;
3036 Result = SaveMenuNode(inst,
3037 iff, &inst->mpb_PopMenuNode[POPMENUINDEX_ToolProject], SCMID_Popup_Tool);
3038 if (RETURN_OK != Result)
3039 break;
3041 Result = SaveMenuNode(inst,
3042 iff, &inst->mpb_PopMenuNode[POPMENUINDEX_Trashcan], SCMID_Popup_Trashcan);
3043 if (RETURN_OK != Result)
3044 break;
3046 Result = SaveMenuNode(inst,
3047 iff, &inst->mpb_PopMenuNode[POPMENUINDEX_Window], SCMID_Popup_Window);
3048 if (RETURN_OK != Result)
3049 break;
3051 Result = SaveMenuNode(inst,
3052 iff, &inst->mpb_PopMenuNode[POPMENUINDEX_AppIcon], SCMID_Popup_AppIcon);
3053 if (RETURN_OK != Result)
3054 break;
3056 Result = SaveMenuNode(inst,
3057 iff, &inst->mpb_PopMenuNode[POPMENUINDEX_Desktop], SCMID_Popup_Desktop);
3058 if (RETURN_OK != Result)
3059 break;
3061 Result = PopChunk(iff);
3062 if (RETURN_OK != Result)
3063 break;
3065 } while (0);
3067 if (iff)
3069 if (IffOpen)
3070 CloseIFF(iff);
3072 if (iff->iff_Stream)
3074 Close((BPTR)iff->iff_Stream);
3075 iff->iff_Stream = 0;
3078 FreeIFF(iff);
3081 if (RETURN_OK == Result)
3083 if (inst->mpb_fCreateIcons)
3084 SaveIcon(inst, Filename);
3086 else
3088 char Buffer[120];
3090 Fault(Result, "", Buffer, sizeof(Buffer) - 1);
3092 // MUI_RequestA()
3093 MUI_Request(inst->mpb_Objects[OBJNDX_APP_Main], inst->mpb_Objects[OBJNDX_WIN_Main], 0, NULL,
3094 GetLocString(MSGID_ABOUTREQOK),
3095 GetLocString(MSGID_REQTITLE_SAVEERROR),
3096 Filename,
3097 Buffer);
3100 return Result;
3104 static LONG SaveMenuNode(struct MenuPrefsInst *inst, struct IFFHandle *iff,
3105 const struct MenuPrefsPopMenuNode *TreeNode, enum ScalosMenuChunkId ChunkID)
3107 LONG Result;
3108 struct ScalosMenuChunk *mChunk = NULL;
3110 do {
3111 const struct MUI_NListtree_TreeNode *SubNode;
3112 size_t StringSpaceSize = 0;
3113 STRPTR StringSpace;
3114 UWORD nodeCount;
3115 size_t Length;
3116 struct ScalosMenuTree *MenuTreeSpace;
3118 SubNode = (const struct MUI_NListtree_TreeNode *) DoMethod(TreeNode->mpn_Listtree,
3119 MUIM_NListtree_GetEntry, TreeNode->mpn_ListNode,
3120 MUIV_NListtree_GetEntry_Position_Head,
3122 if(NULL == SubNode)
3124 Result = RETURN_OK;
3125 break;
3128 nodeCount = CountMenuEntries(inst, TreeNode->mpn_Listtree, SubNode, &StringSpaceSize);
3130 Length = sizeof(struct ScalosMenuChunk) + (nodeCount * sizeof(struct ScalosMenuChunk)) + StringSpaceSize;
3132 mChunk = calloc(1, Length);
3133 if (NULL == mChunk)
3135 Result = ERROR_NO_FREE_STORE;
3136 break;
3139 d1(kprintf("%s/%s/%ld: mChunk=%08lx Length=%lu\n", __FILE__, __FUNC__, __LINE__, mChunk, Length));
3141 StringSpace = (STRPTR) &mChunk->smch_Menu[nodeCount];
3143 mChunk->smch_MenuID = SCA_WORD2BE(ChunkID);
3144 mChunk->smch_Entries = SCA_WORD2BE(nodeCount);
3146 d1(kprintf("%s/%s/%ld: ChunkID=%ld Count=%ld StringSpaceSize=%lu\n", \
3147 __FILE__, __FUNC__, __LINE__, mChunk->smch_MenuID, mChunk->smch_Entries, StringSpaceSize));
3149 MenuTreeSpace = mChunk->smch_Menu;
3151 Result = BuildMenuTree(inst, TreeNode->mpn_Listtree, SubNode, &MenuTreeSpace, &StringSpace, NULL);
3152 if (RETURN_OK != Result)
3153 break;
3155 RemoveAddresses(mChunk->smch_Menu, (UBYTE *) mChunk);
3157 Result = PushChunk(iff, 0, ID_MENU, IFFSIZE_UNKNOWN);
3158 if (RETURN_OK != Result)
3159 break;
3161 if (Length != WriteChunkBytes(iff, (APTR) mChunk, Length))
3163 Result = IoErr();
3164 break;
3167 Result = PopChunk(iff);
3168 if (RETURN_OK != Result)
3169 break;
3170 } while (0);
3172 if (mChunk)
3173 free(mChunk);
3175 return Result;
3179 static UWORD CountMenuEntries(struct MenuPrefsInst *inst, Object *ListTree,
3180 const struct MUI_NListtree_TreeNode *TreeNode, size_t *StringSpace)
3182 UWORD Count = 0;
3184 while (TreeNode)
3186 const struct MUI_NListtree_TreeNode *SubNode;
3187 const struct MenuListEntry *mle = (struct MenuListEntry *) TreeNode->tn_User;
3189 d1(kprintf("%s/%s/%ld: TreeNode=%08lx <%s>\n", \
3190 __FILE__, __FUNC__, __LINE__, TreeNode, TreeNode->tn_Name));
3192 Count++;
3194 *StringSpace += 1 + strlen(mle->llist_name);
3196 if (strlen(mle->llist_UnselectedIconName) > 0
3197 || strlen(mle->llist_SelectedIconName) > 0)
3199 *StringSpace += 1 + strlen(mle->llist_UnselectedIconName)
3200 + 1 + strlen(mle->llist_SelectedIconName);
3203 SubNode = (const struct MUI_NListtree_TreeNode *) DoMethod(ListTree,
3204 MUIM_NListtree_GetEntry, TreeNode, MUIV_NListtree_GetEntry_Position_Head,
3207 if (SubNode)
3208 Count += CountMenuEntries(inst, ListTree, SubNode, StringSpace);
3210 TreeNode = (const struct MUI_NListtree_TreeNode *) DoMethod(ListTree,
3211 MUIM_NListtree_GetEntry, TreeNode, MUIV_NListtree_GetEntry_Position_Next,
3212 MUIV_NListtree_GetEntry_Flag_SameLevel);
3215 return Count;
3219 static LONG BuildMenuTree(struct MenuPrefsInst *inst, Object *ListTree,
3220 const struct MUI_NListtree_TreeNode *TreeNode,
3221 struct ScalosMenuTree **MenuSpace, STRPTR *StringSpace,
3222 struct ScalosMenuTree **Parent)
3224 LONG Result = RETURN_OK;
3226 while (TreeNode)
3228 struct ScalosMenuTree *mTree = *(struct ScalosMenuTree **) MenuSpace;
3229 const struct MUI_NListtree_TreeNode *SubNode;
3230 const struct MenuListEntry *mle = (struct MenuListEntry *) TreeNode->tn_User;
3231 STRPTR MenuName;
3233 d1(KPrintF("%s/%s/%ld: TreeNode=%08lx <%s> mTree=%08lx\n", \
3234 __FILE__, __FUNC__, __LINE__, TreeNode, TreeNode->tn_Name ? TreeNode->tn_Name : (STRPTR) "===BAR===", mTree));
3236 if (Parent)
3237 *Parent = mTree;
3239 mTree->mtre_Next = NULL;
3240 mTree->mtre_tree = NULL;
3242 mTree->mtre_type = mle->llist_EntryType;
3243 mTree->mtre_flags = mle->llist_Flags;
3245 if (strlen(mle->llist_name) > 0)
3247 MenuName = AddMenuString(mle->llist_name, StringSpace);
3249 else
3251 MenuName = NULL;
3254 *MenuSpace = mTree + 1;
3256 if (SCAMENUTYPE_Command == mTree->mtre_type)
3258 mTree->MenuCombo.MenuCommand.mcom_flags = mle->llist_CommandFlags;
3259 mTree->MenuCombo.MenuCommand.mcom_type = mle->llist_CommandType;
3260 mTree->MenuCombo.MenuCommand.mcom_stack = mle->llist_Stack;
3261 mTree->MenuCombo.MenuCommand.mcom_pri = mle->llist_Priority;
3262 mTree->MenuCombo.MenuCommand.mcom_name = MenuName;
3264 else
3266 if (strlen(mle->llist_UnselectedIconName) > 0
3267 || strlen(mle->llist_SelectedIconName) > 0)
3269 STRPTR IconName;
3271 IconName = AddMenuString(mle->llist_UnselectedIconName, StringSpace);
3272 AddMenuString(mle->llist_SelectedIconName, StringSpace);
3273 mTree->MenuCombo.MenuTree.mtre_iconnames = IconName;
3275 mTree->mtre_flags |= MTREFLGF_IconNames;
3277 else
3279 mTree->MenuCombo.MenuTree.mtre_iconnames = NULL;
3280 mTree->mtre_flags &= ~MTREFLGF_IconNames;
3283 d1(KPrintF("%s/%s/%ld: mtre_name=<%s> mtre_flags=%02lx mtre_iconnames=%08lx\n", \
3284 __FILE__, __FUNC__, __LINE__, mTree->MenuCombo.MenuTree.mtre_name, \
3285 mTree->mtre_flags, mTree->MenuCombo.MenuTree.mtre_iconnames));
3287 stccpy(mTree->MenuCombo.MenuTree.mtre_hotkey, mle->llist_HotKey,
3288 sizeof(mTree->MenuCombo.MenuTree.mtre_hotkey));
3289 mTree->MenuCombo.MenuTree.mtre_name = MenuName;
3292 SubNode = (const struct MUI_NListtree_TreeNode *) DoMethod(ListTree,
3293 MUIM_NListtree_GetEntry, TreeNode, MUIV_NListtree_GetEntry_Position_Head,
3296 if (SubNode)
3298 Result = BuildMenuTree(inst, ListTree, SubNode, MenuSpace, StringSpace, &mTree->mtre_tree);
3299 if (RETURN_OK != Result)
3300 break;
3303 TreeNode = (const struct MUI_NListtree_TreeNode *) DoMethod(ListTree,
3304 MUIM_NListtree_GetEntry, TreeNode, MUIV_NListtree_GetEntry_Position_Next,
3305 MUIV_NListtree_GetEntry_Flag_SameLevel);
3307 if (TreeNode)
3308 Parent = &mTree->mtre_Next;
3311 return Result;
3315 static STRPTR AddMenuString(CONST_STRPTR MenuString, STRPTR *StringSpace)
3317 STRPTR MenuName = *StringSpace;
3319 strcpy(MenuName, MenuString);
3320 *StringSpace = (APTR) (MenuName + 1 + strlen(MenuName));
3322 return MenuName;
3326 static void RemoveAddresses(struct ScalosMenuTree *MenuTree, const UBYTE *BaseAddr)
3328 while (MenuTree)
3330 struct ScalosMenuTree *MenuTreeNext = MenuTree->mtre_Next;
3332 if (SCAMENUTYPE_Command == MenuTree->mtre_type)
3334 if (MenuTree->MenuCombo.MenuCommand.mcom_name)
3336 MenuTree->MenuCombo.MenuCommand.mcom_name -= (ULONG) BaseAddr;
3337 MenuTree->MenuCombo.MenuCommand.mcom_name = (APTR) SCA_LONG2BE(MenuTree->MenuCombo.MenuCommand.mcom_name);
3339 MenuTree->MenuCombo.MenuCommand.mcom_stack = SCA_LONG2BE(MenuTree->MenuCombo.MenuCommand.mcom_stack);
3341 else
3343 if (MenuTree->MenuCombo.MenuTree.mtre_name)
3345 MenuTree->MenuCombo.MenuTree.mtre_name -= (ULONG) BaseAddr;
3346 MenuTree->MenuCombo.MenuTree.mtre_name = (APTR) SCA_LONG2BE(MenuTree->MenuCombo.MenuTree.mtre_name);
3349 if ((MenuTree->mtre_flags & MTREFLGF_IconNames) && MenuTree->MenuCombo.MenuTree.mtre_iconnames)
3351 MenuTree->MenuCombo.MenuTree.mtre_iconnames -= (ULONG) BaseAddr;
3352 MenuTree->MenuCombo.MenuTree.mtre_iconnames = (APTR) SCA_LONG2BE(MenuTree->MenuCombo.MenuTree.mtre_iconnames);
3355 d1(KPrintF("%s/%s/%ld: mtre_name=<%s> mtre_flags=%02lx mtre_iconnames=%08lx\n", \
3356 __FILE__, __FUNC__, __LINE__, MenuTree->MenuCombo.MenuTree.mtre_name, \
3357 MenuTree->mtre_flags, MenuTree->MenuCombo.MenuTree.mtre_iconnames));
3359 if (MenuTree->mtre_tree)
3361 RemoveAddresses(MenuTree->mtre_tree, BaseAddr);
3362 MenuTree->mtre_tree = (struct ScalosMenuTree *) (((UBYTE *) MenuTree->mtre_tree) - (ULONG) BaseAddr);
3363 MenuTree->mtre_tree = (APTR)SCA_LONG2BE(MenuTree->mtre_tree);
3365 if (MenuTree->mtre_Next)
3367 MenuTree->mtre_Next = (struct ScalosMenuTree *) (((UBYTE *) MenuTree->mtre_Next) - (ULONG) BaseAddr);
3368 MenuTree->mtre_Next = (APTR)SCA_LONG2BE(MenuTree->mtre_Next);
3371 MenuTree = MenuTreeNext;
3376 static LONG SaveIcon(struct MenuPrefsInst *inst, CONST_STRPTR IconName)
3378 struct DiskObject *icon, *allocIcon;
3380 static UBYTE ImageData[] =
3382 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
3383 0x00, 0x00, 0x07, 0xFF, 0x80, 0x00, 0x40, 0x00, 0x00, 0x00, 0x18, 0x00, 0x60, 0x00, 0x10, 0x00,
3384 0x00, 0x00, 0x20, 0xFC, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x41, 0x02, 0x08, 0x00, 0x0C, 0x00,
3385 0x00, 0x00, 0x40, 0x82, 0x08, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x40, 0x82, 0x08, 0x00, 0x0C, 0x00,
3386 0x00, 0x00, 0x21, 0x04, 0x08, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x1E, 0x18, 0x10, 0x00, 0x0C, 0x00,
3387 0x00, 0x00, 0x00, 0x60, 0x20, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x00, 0x0C, 0x00,
3388 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x02, 0x1C, 0x00, 0x00, 0x0C, 0x00,
3389 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x0C, 0x00,
3390 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x0C, 0x00,
3391 0x40, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00,
3392 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0x00,
3393 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x00, 0x00,
3394 0xD5, 0x55, 0x55, 0x55, 0x55, 0x56, 0x00, 0x00, 0xD5, 0x55, 0x50, 0x00, 0x55, 0x55, 0x80, 0x00,
3395 0xD5, 0x55, 0x47, 0xFF, 0x95, 0x55, 0x60, 0x00, 0xD5, 0x55, 0x5F, 0x03, 0xE5, 0x55, 0x50, 0x00,
3396 0xD5, 0x55, 0x3E, 0x55, 0xF5, 0x55, 0x50, 0x00, 0xD5, 0x55, 0x3F, 0x55, 0xF5, 0x55, 0x50, 0x00,
3397 0xD5, 0x55, 0x3F, 0x55, 0xF5, 0x55, 0x50, 0x00, 0xD5, 0x55, 0x5E, 0x53, 0xF5, 0x55, 0x50, 0x00,
3398 0xD5, 0x55, 0x41, 0x47, 0xE5, 0x55, 0x50, 0x00, 0xD5, 0x55, 0x55, 0x1F, 0xD5, 0x55, 0x50, 0x00,
3399 0xD5, 0x55, 0x55, 0x7F, 0x15, 0x55, 0x50, 0x00, 0xD5, 0x55, 0x54, 0xFC, 0x55, 0x55, 0x50, 0x00,
3400 0xD5, 0x55, 0x55, 0xE1, 0x55, 0x55, 0x50, 0x00, 0xD5, 0x55, 0x54, 0xF5, 0x55, 0x55, 0x50, 0x00,
3401 0xD5, 0x55, 0x55, 0x05, 0x55, 0x55, 0x50, 0x00, 0xD5, 0x55, 0x54, 0xF5, 0x55, 0x55, 0x50, 0x00,
3402 0xD5, 0x55, 0x54, 0xF5, 0x55, 0x55, 0x50, 0x00, 0x35, 0x55, 0x55, 0x05, 0x55, 0x55, 0x50, 0x00,
3403 0x0D, 0x55, 0x55, 0x55, 0x55, 0x55, 0x50, 0x00, 0x03, 0x55, 0x55, 0x55, 0x55, 0x55, 0x50, 0x00,
3404 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3407 static struct Image NormalImage =
3409 0, 0, 54, 23,
3411 (UWORD *)ImageData,
3412 3, 0,
3413 NULL
3416 static STRPTR defToolTypes[] =
3418 "ACTION=USE",
3419 NULL
3422 static struct DiskObject DefaultIcon =
3424 WB_DISKMAGIC, WB_DISKVERSION,
3427 NULL,
3428 0, 0, 54, 24,
3429 GFLG_GADGIMAGE | GFLG_GADGHBOX,
3430 GACT_RELVERIFY | GACT_IMMEDIATE,
3431 GTYP_BOOLGADGET,
3432 &NormalImage, NULL,
3433 NULL,
3435 NULL,
3437 NULL
3440 WBPROJECT,
3441 NULL,
3442 defToolTypes,
3443 NO_ICON_POSITION, NO_ICON_POSITION,
3444 NULL,
3445 NULL,
3446 8192
3449 icon = allocIcon = GetDiskObject("ENV:sys/def_ScaMenuPrefs");
3450 if (NULL == icon)
3451 icon = allocIcon = GetDiskObject("ENV:sys/def_pref");
3452 if (NULL == icon)
3453 icon = &DefaultIcon;
3455 if (icon)
3457 STRPTR oldDefaultTool = icon->do_DefaultTool;
3459 icon->do_DefaultTool = (STRPTR) inst->mpb_ProgramName;
3461 PutDiskObject((STRPTR) IconName, icon);
3463 icon->do_DefaultTool = oldDefaultTool;
3465 if (allocIcon)
3466 FreeDiskObject(allocIcon);
3469 return 0;
3473 static void ClearMenuList(struct MenuPrefsInst *inst)
3475 short n;
3477 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Quiet, TRUE);
3479 DoMethod(inst->mpb_MainMenuNode.mpn_Listtree, MUIM_NListtree_Remove,
3480 inst->mpb_MainMenuNode.mpn_ListNode, MUIV_NListtree_Remove_TreeNode_All, 0);
3482 for (n=0; n<Sizeof(inst->mpb_PopMenuNode); n++)
3484 DoMethod(inst->mpb_PopMenuNode[n].mpn_Listtree, MUIM_NListtree_Remove,
3485 inst->mpb_PopMenuNode[n].mpn_ListNode,
3486 MUIV_NListtree_Remove_TreeNode_All, 0);
3489 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Quiet, FALSE);
3493 static void AddAddresses(struct ScalosMenuTree *MenuTree, const UBYTE *BaseAddr)
3495 while (MenuTree)
3497 if (SCAMENUTYPE_Command == MenuTree->mtre_type)
3499 MenuTree->MenuCombo.MenuCommand.mcom_name = (APTR) SCA_BE2LONG(MenuTree->MenuCombo.MenuCommand.mcom_name);
3500 if (MenuTree->MenuCombo.MenuCommand.mcom_name)
3501 MenuTree->MenuCombo.MenuCommand.mcom_name += (ULONG) BaseAddr;
3502 MenuTree->MenuCombo.MenuCommand.mcom_stack = SCA_BE2LONG(MenuTree->MenuCombo.MenuCommand.mcom_stack);
3504 else
3506 MenuTree->MenuCombo.MenuTree.mtre_name = (APTR) SCA_BE2LONG(MenuTree->MenuCombo.MenuTree.mtre_name);
3507 if (MenuTree->MenuCombo.MenuTree.mtre_name)
3508 MenuTree->MenuCombo.MenuTree.mtre_name += (ULONG) BaseAddr;
3510 if (MenuTree->mtre_flags & MTREFLGF_IconNames)
3512 MenuTree->MenuCombo.MenuTree.mtre_iconnames = (APTR) SCA_BE2LONG(MenuTree->MenuCombo.MenuTree.mtre_iconnames);
3513 if (MenuTree->MenuCombo.MenuTree.mtre_iconnames)
3515 MenuTree->MenuCombo.MenuTree.mtre_iconnames += (ULONG) BaseAddr;
3517 else
3519 MenuTree->MenuCombo.MenuTree.mtre_iconnames = NULL;
3522 else
3524 MenuTree->MenuCombo.MenuTree.mtre_iconnames = NULL;
3527 d1(KPrintF("%s/%s/%ld: mtre_name=<%s> mtre_flags=%02lx mtre_iconnames=%08lx\n", \
3528 __FILE__, __FUNC__, __LINE__, MenuTree->MenuCombo.MenuTree.mtre_name, \
3529 MenuTree->mtre_flags, MenuTree->MenuCombo.MenuTree.mtre_iconnames));
3530 d1(KPrintF("%s/%s/%ld: mtre_iconnames=<%s>\n", \
3531 __FILE__, __FUNC__, __LINE__, MenuTree->MenuCombo.MenuTree.mtre_iconnames \
3532 ? MenuTree->MenuCombo.MenuTree.mtre_iconnames : (STRPTR) ""));
3534 MenuTree->mtre_tree = (APTR) SCA_BE2LONG(MenuTree->mtre_tree);
3535 if (MenuTree->mtre_tree)
3537 MenuTree->mtre_tree = (struct ScalosMenuTree *) (((UBYTE *) MenuTree->mtre_tree) + (ULONG) BaseAddr);
3538 AddAddresses(MenuTree->mtre_tree, BaseAddr);
3540 MenuTree->mtre_Next = SCA_BE2LONG(MenuTree->mtre_Next);
3541 if (MenuTree->mtre_Next)
3543 MenuTree->mtre_Next = (struct ScalosMenuTree *) (((UBYTE *) MenuTree->mtre_Next) + (ULONG) BaseAddr);
3545 MenuTree = MenuTree->mtre_Next;
3550 static void GenerateMenuList(struct MenuPrefsInst *inst, struct ScalosMenuTree *mTree,
3551 Object *ListTree, struct MUI_NListtree_TreeNode *MenuNode)
3553 while (mTree)
3555 struct MenuInsertEntry mie;
3556 struct MUI_NListtree_TreeNode *TreeNode;
3557 ULONG MenuType = mTree->mtre_type;
3558 ULONG Flags = 0;
3559 ULONG pos;
3561 mie.mie_TreeEntry = mTree;
3562 mie.mie_MenuFlags = 0;
3564 d1(KPrintF("%s/%s/%ld: mTree=%08lx Type=%ld\n", __FILE__, __FUNC__, __LINE__, mTree, MenuType));
3566 switch (MenuType)
3568 case SCAMENUTYPE_Command:
3569 d1(kprintf("%s/%s/%ld: Command name <%s> ListNode=<%s>\n", \
3570 __FILE__, __FUNC__, __LINE__, mTree->MenuCombo.MenuCommand.mcom_name, MenuNode->tn_Name));
3572 DoMethod(ListTree,
3573 MUIM_NListtree_Insert, "",
3574 &mie,
3575 MenuNode, MUIV_NListtree_Insert_PrevNode_Tail, 0);
3576 break;
3578 default:
3579 d1(KPrintF("%s/%s/%ld: Menu name <%s> ListNode=<%s>\n", \
3580 __FILE__, __FUNC__, __LINE__, mTree->MenuCombo.MenuTree.mtre_name, MenuNode->tn_Name));
3582 if (SCAMENUTYPE_ToolsMenu == mTree->mtre_type)
3583 mie.mie_MenuFlags |= LLISTFLGF_NotRemovable;
3585 Flags |= TNF_LIST;
3587 //.menu
3588 if (NULL == mTree->MenuCombo.MenuTree.mtre_name || 0 == strlen(mTree->MenuCombo.MenuTree.mtre_name))
3589 Flags |= TNF_NOSIGN;
3591 if (SCAMENUTYPE_ToolsMenu != MenuType)
3593 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(ListTree,
3594 MUIM_NListtree_Insert, mTree->MenuCombo.MenuTree.mtre_name ? mTree->MenuCombo.MenuTree.mtre_name : (STRPTR) "",
3595 &mie,
3596 MenuNode, MUIV_NListtree_Insert_PrevNode_Tail, Flags);
3598 else
3600 TreeNode = NULL;
3602 for (pos=0; ; pos++)
3604 struct MenuListEntry *mle;
3606 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(ListTree,
3607 MUIM_NListtree_GetEntry, NULL, pos, 0);
3609 if (NULL == TreeNode)
3610 break;
3612 mle = (struct MenuListEntry *) TreeNode->tn_User;
3614 if (SCAMENUTYPE_ToolsMenu == mle->llist_EntryType)
3615 break;
3618 if (NULL == TreeNode)
3620 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(ListTree,
3621 MUIM_NListtree_Insert, mTree->MenuCombo.MenuTree.mtre_name ? mTree->MenuCombo.MenuTree.mtre_name : (STRPTR) "",
3622 &mie,
3623 MenuNode, MUIV_NListtree_Insert_PrevNode_Tail, Flags);
3627 if (mTree->mtre_tree)
3628 GenerateMenuList(inst, mTree->mtre_tree, ListTree, TreeNode);
3629 break;
3632 mTree = mTree->mtre_Next;
3637 static SAVEDS(APTR) INTERRUPT ImportTDHookFunc(struct Hook *hook, Object *o, Msg msg)
3639 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
3640 char FileName[1000];
3641 BPTR fd;
3643 if (!RequestTdFile(inst, FileName, sizeof(FileName)))
3644 return NULL;
3646 fd = Open(FileName, MODE_OLDFILE);
3647 if (fd)
3649 char Line[512];
3650 struct MUI_NListtree_TreeNode *MenuNode = NULL;
3651 struct MUI_NListtree_TreeNode *ItemNode = NULL;
3652 struct MUI_NListtree_TreeNode *SubNode = NULL;
3653 struct MUI_NListtree_TreeNode *CmdNode = NULL;
3654 struct MenuInsertEntry mie;
3655 struct ScalosMenuTree mTree;
3657 memset(&mTree, 0, sizeof(mTree));
3658 mie.mie_TreeEntry = &mTree;
3659 mie.mie_MenuFlags = 0;
3661 ClearMenuList(inst);
3663 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree], MUIM_NListtree_Close,
3664 MUIV_NListtree_Close_ListNode_Root,
3665 MUIV_NListtree_Close_TreeNode_All,
3668 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Quiet, TRUE);
3669 inst->mpb_QuietFlag = TRUE;
3671 while (NULL != FGets(fd, Line, sizeof(Line) - 1))
3673 STRPTR lp;
3675 StripLF(Line);
3676 lp = stpblk(Line);
3678 if (CmpWord("TITLE", lp))
3680 lp = NextWord(lp);
3682 CmdNode = SubNode = ItemNode = NULL;
3683 mTree.mtre_type = SCAMENUTYPE_Menu;
3685 MenuNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
3686 MUIM_NListtree_Insert, lp,
3687 &mie,
3688 &inst->mpb_MainMenuNode,
3689 MenuNode ? MenuNode : (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
3690 MUIV_NListtree_Insert_Flag_Active | TNF_OPEN | TNF_LIST);
3692 continue;
3694 if (CmpWord("ITEM", lp))
3696 lp = NextWord(lp);
3698 if (NULL == MenuNode)
3699 break;
3701 CmdNode = SubNode = NULL;
3702 mTree.mtre_type = SCAMENUTYPE_MenuItem;
3704 ItemNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
3705 MUIM_NListtree_Insert, lp,
3706 &mie,
3707 MenuNode,
3708 ItemNode ? ItemNode : (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
3709 MUIV_NListtree_Insert_Flag_Active | TNF_OPEN | TNF_LIST);
3711 continue;
3713 if (CmpWord("ITEMBAR", lp))
3715 if (NULL == MenuNode)
3716 break;
3718 CmdNode = SubNode = NULL;
3719 mTree.mtre_type = SCAMENUTYPE_MenuItem;
3721 ItemNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
3722 MUIM_NListtree_Insert, "",
3723 &mie,
3724 MenuNode,
3725 ItemNode ? ItemNode : (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
3726 MUIV_NListtree_Insert_Flag_Active | TNF_OPEN | TNF_LIST | TNF_NOSIGN);
3728 continue;
3730 if (CmpWord("(CLI)", lp))
3732 struct MUI_NListtree_TreeNode *ParentNode;
3733 struct MenuListEntry *mle;
3734 ULONG StackSize;
3736 if (SubNode)
3737 ParentNode = SubNode;
3738 else
3739 ParentNode = ItemNode;
3741 if (NULL == ParentNode)
3742 break;
3744 lp = NextWord(lp);
3746 StackSize = atoi(lp);
3748 lp = NextWord(lp);
3750 mTree.mtre_type = SCAMENUTYPE_Command;
3752 CmdNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
3753 MUIM_NListtree_Insert, lp,
3754 &mie,
3755 ParentNode,
3756 CmdNode ? CmdNode : (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
3757 MUIV_NListtree_Insert_Flag_Active);
3759 mle = (struct MenuListEntry *) CmdNode->tn_User;
3761 mle->llist_Stack = StackSize;
3762 mle->llist_CommandType = SCAMENUCMDTYPE_AmigaDOS;
3764 continue;
3766 if (CmpWord("(WB)", lp))
3768 struct MUI_NListtree_TreeNode *ParentNode;
3769 struct MenuListEntry *mle;
3771 if (SubNode)
3772 ParentNode = SubNode;
3773 else
3774 ParentNode = ItemNode;
3776 if (NULL == ParentNode)
3777 break;
3779 lp = NextWord(lp);
3781 mTree.mtre_type = SCAMENUTYPE_Command;
3783 CmdNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
3784 MUIM_NListtree_Insert, lp,
3785 &mie,
3786 ParentNode,
3787 CmdNode ? CmdNode : (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
3788 MUIV_NListtree_Insert_Flag_Active);
3790 mle = (struct MenuListEntry *) CmdNode->tn_User;
3792 mle->llist_CommandType = SCAMENUCMDTYPE_Workbench;
3793 mle->llist_Stack = DEFAULT_STACKSIZE;
3795 continue;
3797 if (CmpWord("HOTKEY", lp))
3799 struct MUI_NListtree_TreeNode *ParentNode;
3800 struct MenuListEntry *mle;
3802 if (SubNode)
3803 ParentNode = SubNode;
3804 else
3805 ParentNode = ItemNode;
3807 if (NULL == ParentNode)
3808 break;
3810 lp = NextWord(lp);
3812 mle = (struct MenuListEntry *) ParentNode->tn_User;
3814 stccpy(mle->llist_HotKey, lp, sizeof(mle->llist_HotKey));
3816 continue;
3818 if (CmpWord("SUB", lp))
3820 lp = NextWord(lp);
3822 if (NULL == ItemNode)
3823 break;
3825 CmdNode = NULL;
3826 mTree.mtre_type = SCAMENUTYPE_Menu;
3828 SubNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
3829 MUIM_NListtree_Insert, lp,
3830 &mie,
3831 ItemNode,
3832 SubNode ? SubNode : (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
3833 MUIV_NListtree_Insert_Flag_Active | TNF_OPEN | TNF_LIST);
3835 continue;
3839 Close(fd);
3841 inst->mpb_QuietFlag = FALSE;
3842 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Quiet, FALSE);
3844 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree], MUIM_NListtree_Open,
3845 MUIV_NListtree_Open_ListNode_Root,
3846 MUIV_NListtree_Open_TreeNode_All,
3850 SetChangedFlag(inst, TRUE);
3852 return NULL;
3856 static BOOL RequestTdFile(struct MenuPrefsInst *inst, char *FileName, size_t MaxLen)
3858 struct FileRequester *Req = MUI_AllocAslRequest(ASL_FileRequest, NULL);
3859 BOOL Result = FALSE;
3861 if (Req)
3863 struct Window *win = NULL;
3865 get(inst->mpb_Objects[OBJNDX_WIN_Main], MUIA_Window_Window, &win);
3867 // MUI_AslRequest()
3868 Result = MUI_AslRequestTags(Req,
3869 ASLFR_TitleText, GetLocString(MSGID_TITLE_IMPORTTD),
3870 ASLFR_InitialFile, "ToolsDaemon.menu",
3871 ASLFR_InitialDrawer, "S:",
3872 ASLFR_Window, win,
3873 ASLFR_SleepWindow, TRUE,
3874 ASLFR_Flags1, FRF_DOPATTERNS,
3875 TAG_END);
3877 if (Result)
3879 stccpy(FileName, Req->fr_Drawer, MaxLen);
3880 AddPart(FileName, Req->fr_File, MaxLen);
3884 return Result;
3888 static BOOL RequestParmFile(struct MenuPrefsInst *inst, char *FileName, size_t MaxLen)
3890 struct FileRequester *Req = MUI_AllocAslRequest(ASL_FileRequest, NULL);
3891 BOOL Result = FALSE;
3893 if (Req)
3895 struct Window *win = NULL;
3897 get(inst->mpb_Objects[OBJNDX_WIN_Main], MUIA_Window_Window, &win);
3899 // MUI_AslRequest()
3900 Result = MUI_AslRequestTags(Req,
3901 ASLFR_TitleText, GetLocString(MSGID_TITLE_IMPORTP),
3902 ASLFR_InitialFile, "ParM.cfg",
3903 ASLFR_InitialDrawer, "",
3904 ASLFR_Window, win,
3905 ASLFR_SleepWindow, TRUE,
3906 ASLFR_Flags1, FRF_DOPATTERNS,
3907 TAG_END);
3909 if (Result)
3911 stccpy(FileName, Req->fr_Drawer, MaxLen);
3912 AddPart(FileName, Req->fr_File, MaxLen);
3916 return Result;
3920 static BOOL CmpWord(CONST_STRPTR Cmd, CONST_STRPTR Line)
3922 while (*Line && (tolower(*Cmd) == tolower(*Line)))
3924 Cmd++;
3925 Line++;
3928 return (BOOL) ('\0' == *Cmd && ('\0' == *Line || isspace(*Line)));
3932 static void StripLF(STRPTR Line)
3934 size_t Len = strlen(Line);
3936 Line += Len - 1;
3938 if ('\n' == *Line)
3939 *Line = '\0';
3943 static STRPTR NextWord(STRPTR lp)
3945 if ('"' == *lp)
3947 lp++; // skip leading '"'
3948 while (*lp && '"' != *lp)
3949 lp++;
3950 if ('"' == *lp)
3951 lp++; // skip trailing '"'
3953 else
3955 while (*lp && !isspace(*lp))
3956 lp++;
3959 return stpblk(lp);
3963 static void CopyWord(STRPTR dest, CONST_STRPTR src, size_t MaxLen)
3965 if ('"' == *src)
3967 src++; // skip leading '"'
3968 while (*src && '"' != *src && MaxLen > 1)
3970 *dest++ = *src++;
3971 MaxLen--;
3974 else
3976 while (*src && !isspace(*src) && MaxLen > 1)
3978 *dest++ = *src++;
3979 MaxLen--;
3983 *dest = '\0';
3987 static SAVEDS(APTR) INTERRUPT ImportPHookFunc(struct Hook *hook, Object *o, Msg msg)
3989 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
3990 char FileName[1000];
3991 BPTR fd;
3993 if (!RequestParmFile(inst, FileName, sizeof(FileName)))
3994 return NULL;
3996 fd = Open(FileName, MODE_OLDFILE);
3997 // fd = Open("ParM.cfg", MODE_OLDFILE);
3998 if (fd)
4000 struct MUI_NListtree_TreeNode *MenuNode = NULL;
4001 struct MUI_NListtree_TreeNode *ItemNode = NULL;
4002 struct MUI_NListtree_TreeNode *SubNode = NULL;
4003 struct MUI_NListtree_TreeNode *CmdNode;
4004 char Line[512];
4005 struct MenuInsertEntry mie;
4006 struct ScalosMenuTree mTree;
4008 memset(&mTree, 0, sizeof(mTree));
4009 mie.mie_TreeEntry = &mTree;
4010 mie.mie_MenuFlags = 0;
4012 ClearMenuList(inst);
4014 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree], MUIM_NListtree_Close,
4015 MUIV_NListtree_Close_ListNode_Root,
4016 MUIV_NListtree_Close_TreeNode_All,
4019 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Quiet, TRUE);
4020 inst->mpb_QuietFlag = TRUE;
4022 while (NULL != FGets(fd, Line, sizeof(Line) - 1))
4024 char ItemName[100];
4025 STRPTR lp;
4027 StripLF(Line);
4028 lp = stpblk(Line);
4030 if ('#' == *lp || 0 == strlen(lp))
4031 continue;
4033 if (CmpWord("MENU", lp))
4035 lp = NextWord(lp);
4037 CopyWord(ItemName, lp, sizeof(ItemName));
4039 d1(kprintf("%s/%s/%ld: ITEM <%s> Menu=%08lx Item=%08lx Sub=%08lx\n", \
4040 __FILE__, __FUNC__, __LINE__, ItemName, MenuNode, ItemNode, SubNode));
4042 SubNode = ItemNode = NULL;
4043 mTree.mtre_type = SCAMENUTYPE_Menu;
4045 MenuNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4046 MUIM_NListtree_Insert, ItemName,
4047 &mie,
4048 &inst->mpb_MainMenuNode,
4049 MenuNode ? MenuNode : (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Head,
4050 TNF_OPEN | TNF_LIST);
4052 continue;
4054 if (CmpWord("ITEM", lp))
4056 struct MenuListEntry *mle;
4057 char HotKey[2];
4059 lp = NextWord(lp);
4061 if (NULL == MenuNode)
4062 break;
4064 CmdNode = NULL;
4065 strcpy(HotKey, "");
4067 if ('{' == *lp)
4069 HotKey[0] = lp[1];
4070 lp = NextWord(lp);
4073 CopyWord(ItemName, lp, sizeof(ItemName));
4075 d1(kprintf("%s/%s/%ld: ITEM <%s> Menu=%08lx Item=%08lx Sub=%08lx\n", \
4076 __FILE__, __FUNC__, __LINE__, ItemName, MenuNode, ItemNode, SubNode));
4078 mTree.mtre_type = SCAMENUTYPE_MenuItem;
4080 ItemNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4081 MUIM_NListtree_Insert, ItemName,
4082 &mie,
4083 SubNode ? SubNode : MenuNode,
4084 ItemNode ? ItemNode : (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
4085 TNF_OPEN | TNF_LIST);
4087 mle = (struct MenuListEntry *) ItemNode->tn_User;
4089 stccpy(mle->llist_HotKey, HotKey, sizeof(mle->llist_HotKey));
4091 lp = NextWord(stpblk(lp));
4093 if (CmpWord("WB", lp))
4095 lp = NextWord(lp);
4096 mTree.mtre_type = SCAMENUTYPE_Command;
4098 CmdNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4099 MUIM_NListtree_Insert, lp,
4100 &mie,
4101 ItemNode,
4102 CmdNode ? CmdNode : (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
4105 mle = (struct MenuListEntry *) CmdNode->tn_User;
4107 mle->llist_CommandType = SCAMENUCMDTYPE_Workbench;
4108 mle->llist_Stack = DEFAULT_STACKSIZE;
4110 else if (CmpWord("RUN", lp) || CmpWord("SHELL", lp))
4112 lp = NextWord(lp);
4113 mTree.mtre_type = SCAMENUTYPE_Command;
4115 CmdNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4116 MUIM_NListtree_Insert, lp,
4117 &mie,
4118 ItemNode,
4119 CmdNode ? CmdNode : (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
4122 mle = (struct MenuListEntry *) CmdNode->tn_User;
4124 mle->llist_Stack = DEFAULT_STACKSIZE;
4125 mle->llist_CommandType = SCAMENUCMDTYPE_AmigaDOS;
4128 continue;
4130 if (CmpWord("BARLABEL", lp))
4132 if (NULL == MenuNode)
4133 break;
4135 SubNode = NULL;
4136 mTree.mtre_type = SCAMENUTYPE_MenuItem;
4138 ItemNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4139 MUIM_NListtree_Insert, "",
4140 &mie,
4141 MenuNode,
4142 ItemNode ? ItemNode : (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
4143 TNF_LIST | TNF_NOSIGN);
4145 continue;
4147 if (CmpWord("SUBMENU", lp))
4149 lp = NextWord(lp);
4151 if (SubNode)
4152 break;
4154 CopyWord(ItemName, lp, sizeof(ItemName));
4156 d1(kprintf("%s/%s/%ld: SUBMENU <%s> Menu=%08lx Item=%08lx Sub=%08lx\n", \
4157 __FILE__, __FUNC__, __LINE__, ItemName, MenuNode, ItemNode, SubNode));
4159 mTree.mtre_type = SCAMENUTYPE_Menu;
4161 SubNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4162 MUIM_NListtree_Insert, ItemName,
4163 &mie,
4164 MenuNode,
4165 ItemNode ? ItemNode : (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
4166 TNF_OPEN | TNF_LIST);
4168 continue;
4170 if (CmpWord("ENDSUBMENU", lp))
4172 d1(kprintf("%s/%s/%ld: ENDSUBMENU Menu=%08lx Item=%08lx Sub=%08lx\n", \
4173 __FILE__, __FUNC__, __LINE__, MenuNode, ItemNode, SubNode));
4175 if (NULL == SubNode)
4176 break;
4178 ItemNode = SubNode;
4179 SubNode = NULL;
4181 continue;
4185 Close(fd);
4187 inst->mpb_QuietFlag = FALSE;
4189 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Quiet, FALSE);
4191 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree], MUIM_NListtree_Open,
4192 MUIV_NListtree_Open_ListNode_Root,
4193 MUIV_NListtree_Open_TreeNode_All,
4197 SetChangedFlag(inst, TRUE);
4199 return NULL;
4203 //----------------------------------------------------------------------------
4205 static SAVEDS(APTR) INTERRUPT CollapseSelectedHookFunc(struct Hook *hook, Object *o, Msg msg)
4207 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
4208 struct MUI_NListtree_TreeNode *tn;
4210 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NList_Quiet, MUIV_NList_Quiet_Full);
4212 tn = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4213 MUIM_NListtree_GetEntry,
4214 MUIV_NListtree_GetEntry_ListNode_Active,
4215 MUIV_NListtree_GetEntry_Position_Active,
4217 d1(kprintf("%s/%ld: active tn=%08lx <%s>\n", __FUNC__, __LINE__, tn, tn ? tn->tn_Name : (STRPTR) ""));
4219 if (tn)
4221 struct MUI_NListtree_TreeNode *tnChild;
4223 tnChild = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4224 MUIM_NListtree_GetEntry,
4226 MUIV_NListtree_GetEntry_Position_Head,
4228 d1(kprintf("%s/%ld: Head tn=%08lx <%s>\n", __FUNC__, __LINE__, tnChild, tnChild ? tnChild->tn_Name : (STRPTR) ""));
4230 if (tnChild)
4232 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Active, (ULONG) tnChild);
4234 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4235 MUIM_NListtree_Close,
4236 MUIV_NListtree_Close_ListNode_Active,
4237 MUIV_NListtree_Close_TreeNode_All,
4241 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Active, (ULONG) tn);
4244 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4245 MUIM_NListtree_Close,
4246 MUIV_NListtree_Close_ListNode_Active,
4250 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NList_Quiet, MUIV_NList_Quiet_None);
4252 return NULL;
4255 //----------------------------------------------------------------------------
4257 static SAVEDS(APTR) INTERRUPT ExpandSelectedHookFunc(struct Hook *hook, Object *o, Msg msg)
4259 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
4260 struct MUI_NListtree_TreeNode *tn;
4262 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NList_Quiet, MUIV_NList_Quiet_Full);
4264 tn = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4265 MUIM_NListtree_GetEntry,
4266 MUIV_NListtree_GetEntry_ListNode_Active,
4267 MUIV_NListtree_GetEntry_Position_Active,
4269 d1(kprintf("%s/%ld: active tn=%08lx <%s>\n", __FUNC__, __LINE__, tn, tn ? tn->tn_Name : (STRPTR) ""));
4271 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4272 MUIM_NListtree_Open,
4273 MUIV_NListtree_Open_ListNode_Active,
4274 MUIV_NListtree_Open_TreeNode_Active,
4277 if (tn)
4279 struct MUI_NListtree_TreeNode *tnChild;
4281 tnChild = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4282 MUIM_NListtree_GetEntry,
4284 MUIV_NListtree_GetEntry_Position_Head,
4286 d1(kprintf("%s/%ld: Head tn=%08lx <%s>\n", __FUNC__, __LINE__, tnChild, tnChild ? tnChild->tn_Name : (STRPTR) ""));
4288 if (tnChild)
4290 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Active, (ULONG) tnChild);
4292 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4293 MUIM_NListtree_Open,
4294 MUIV_NListtree_Open_ListNode_Active,
4295 MUIV_NListtree_Open_TreeNode_All,
4299 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Active, (ULONG) tn);
4302 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NList_Quiet, MUIV_NList_Quiet_None);
4304 return NULL;
4307 //----------------------------------------------------------------------------
4309 static SAVEDS(APTR) INTERRUPT CollapseAllHookFunc(struct Hook *hook, Object *o, Msg msg)
4311 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
4313 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree], MUIM_NListtree_Close,
4314 MUIV_NListtree_Close_ListNode_Root, MUIV_NListtree_Close_TreeNode_All, 0);
4316 return 0;
4319 //----------------------------------------------------------------------------
4321 static SAVEDS(APTR) INTERRUPT ExpandAllHookFunc(struct Hook *hook, Object *o, Msg msg)
4323 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
4325 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree], MUIM_NListtree_Open,
4326 MUIV_NListtree_Open_ListNode_Root, MUIV_NListtree_Open_TreeNode_All, 0);
4328 return 0;
4331 //----------------------------------------------------------------------------
4333 static SAVEDS(APTR) INTERRUPT CmdSelectedHookFunc(struct Hook *hook, Object *o, Msg msg)
4335 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
4336 struct CommandTableEntry *cte = NULL;
4338 DoMethod(inst->mpb_Objects[OBJNDX_CmdListView], MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &cte);
4339 if (cte)
4341 set(inst->mpb_Objects[OBJNDX_StringCmd], MUIA_String_Contents, (ULONG) cte->cte_Command);
4343 DoMethod(inst->mpb_Objects[OBJNDX_PopObject], MUIM_Popstring_Close, 0);
4345 ChangeEntry3HookFunc(hook, o, msg);
4348 return 0;
4351 //----------------------------------------------------------------------------
4353 static SAVEDS(APTR) INTERRUPT ContextMenuTriggerHookFunc(struct Hook *hook, Object *o, Msg msg)
4355 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
4356 Object *MenuObj = *((Object **) msg);
4357 ULONG MenuHookIndex = 0;
4358 struct Hook *MenuHook = NULL;
4360 d1(kprintf("%s/%s//%ld: MenuObj=%08lx\n", __FILE__, __FUNC__, __LINE__, MenuObj));
4361 d1(kprintf("%s/%s//%ld: msg=%08lx *msg=%08lx\n", __FILE__, __FUNC__, __LINE__, msg, *((ULONG *) msg)));
4363 get(MenuObj, MUIA_UserData, &MenuHookIndex);
4365 if (MenuHookIndex > 0 && MenuHookIndex < HOOKNDX_MAX)
4366 MenuHook = &inst->mpb_Hooks[MenuHookIndex];
4368 d1(kprintf("%s/%s//%ld: MenuHook=%08lx\n", __FILE__, __FUNC__, __LINE__, MenuHook));
4369 if (MenuHook)
4370 DoMethod(inst->mpb_Objects[OBJNDX_Group_Main], MUIM_CallHook, MenuHook, 0);
4372 return NULL;
4376 static SAVEDS(APTR) INTERRUPT AppMessageHookFunc(struct Hook *hook, Object *o, Msg msg)
4378 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
4379 struct AppMessage *AppMsg = *(struct AppMessage **) msg;
4380 struct MUI_NListtree_TreeNode *TreeNode = NULL;
4382 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Quiet, TRUE);
4384 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4385 MUIM_NListtree_GetEntry, MUIV_NListtree_GetEntry_ListNode_Active,
4386 MUIV_NListtree_GetEntry_Position_Active, 0);
4388 if (TreeNode)
4390 struct MUI_NListtree_TreeNode *ParentNode = (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail;
4391 LONG n;
4393 for (n=0; n<AppMsg->am_NumArgs; )
4395 struct MenuListEntry *mle = (struct MenuListEntry *) TreeNode->tn_User;
4396 char Buffer[1000];
4397 STRPTR FileName;
4399 if (!NameFromLock(AppMsg->am_ArgList[n].wa_Lock, Buffer, sizeof(Buffer)))
4400 break;
4401 if (AppMsg->am_ArgList[n].wa_Name && strlen(AppMsg->am_ArgList[n].wa_Name) > 0)
4402 AddPart(Buffer, AppMsg->am_ArgList[n].wa_Name, sizeof(Buffer));
4404 FileName = FilePart(Buffer);
4406 switch (mle->llist_EntryType)
4408 case SCAMENUTYPE_MainMenu:
4409 d1(kprintf("%s/%s/%ld: insert at SCAMENUTYPE_MainMenu\n", __FILE__, __FUNC__, __LINE__));
4410 if (mle->llist_Flags & LLISTFLGF_MayNotHaveChildren)
4412 AppMessage_Menu(inst, &TreeNode, &ParentNode, &AppMsg->am_ArgList[n], Buffer, FileName);
4413 n++;
4415 else
4417 struct MenuInsertEntry mie;
4418 struct ScalosMenuTree mTree;
4420 memset(&mTree, 0, sizeof(mTree));
4421 mie.mie_TreeEntry = &mTree;
4422 mie.mie_MenuFlags = 0;
4423 mTree.mtre_type = SCAMENUTYPE_Menu;
4425 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4426 MUIM_NListtree_Insert, "DragIn Menu",
4427 &mie,
4428 TreeNode, ParentNode, TNF_OPEN | TNF_LIST);
4430 break;
4432 case SCAMENUTYPE_Menu:
4433 case SCAMENUTYPE_ToolsMenu:
4434 d1(kprintf("%s/%s/%ld: insert at SCAMENUTYPE_Menu\n", __FILE__, __FUNC__, __LINE__));
4435 AppMessage_Menu(inst, &TreeNode, &ParentNode, &AppMsg->am_ArgList[n], Buffer, FileName);
4436 n++;
4437 break;
4439 case SCAMENUTYPE_MenuItem:
4440 d1(kprintf("%s/%s/%ld: insert at SCAMENUTYPE_MenuItem\n", __FILE__, __FUNC__, __LINE__));
4441 ParentNode = TreeNode;
4442 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4443 MUIM_NListtree_GetEntry, TreeNode, MUIV_NListtree_GetEntry_Position_Parent, 0);
4445 AppMessage_Menu(inst, &TreeNode, &ParentNode, &AppMsg->am_ArgList[n], Buffer, FileName);
4446 n++;
4447 break;
4449 case SCAMENUTYPE_Command:
4450 d1(kprintf("%s/%s/%ld: insert at SCAMENUTYPE_Command\n", __FILE__, __FUNC__, __LINE__));
4451 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4452 MUIM_NListtree_GetEntry, TreeNode, MUIV_NListtree_GetEntry_Position_Parent, 0);
4453 break;
4455 default:
4456 break;
4461 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Quiet, FALSE);
4463 return 0;
4467 static struct MUI_NListtree_TreeNode *AppMessage_Menu(struct MenuPrefsInst *inst,
4468 struct MUI_NListtree_TreeNode **TreeNode,
4469 struct MUI_NListtree_TreeNode **ParentNode, const struct WBArg *wbArg,
4470 CONST_STRPTR Path, CONST_STRPTR FileName)
4472 struct MUI_NListtree_TreeNode *NewTreeNode;
4473 struct MenuListEntry *mle;
4474 struct MenuInsertEntry mie;
4475 struct ScalosMenuTree mTree;
4477 memset(&mTree, 0, sizeof(mTree));
4478 mie.mie_TreeEntry = &mTree;
4479 mie.mie_MenuFlags = 0;
4481 d1(kprintf("%s/%s/%ld: listnode=%08lx <%s> prevtreenode=%08lx\n", \
4482 __FILE__, __FUNC__, __LINE__, *TreeNode, (*TreeNode)->tn_Name, *ParentNode));
4484 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
4485 SetChangedFlag(inst, TRUE);
4487 mTree.mtre_type = SCAMENUTYPE_MenuItem;
4489 *TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4490 MUIM_NListtree_Insert, FileName,
4491 &mie,
4492 *TreeNode, *ParentNode, TNF_OPEN | TNF_LIST);
4494 d1(kprintf("%s/%s/%ld: listnode=%08lx <%s> prevtreenode=%08lx\n", \
4495 __FILE__, __FUNC__, __LINE__, *TreeNode, (*TreeNode)->tn_Name, *ParentNode));
4497 mTree.mtre_type = SCAMENUTYPE_Command;
4499 NewTreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4500 MUIM_NListtree_Insert, "",
4501 &mie,
4502 *TreeNode, MUIV_NListtree_Insert_PrevNode_Tail, 0);
4503 if (NULL == NewTreeNode)
4504 return NULL;
4506 mle = (struct MenuListEntry *) NewTreeNode->tn_User;
4508 stccpy(mle->llist_name, Path, sizeof(mle->llist_name));
4510 mle->llist_Stack = DEFAULT_STACKSIZE;
4511 mle->llist_Priority = 0;
4513 if (FileName && strlen(FileName) > 0)
4514 mle->llist_CommandType = SCAMENUCMDTYPE_Workbench;
4515 else
4516 mle->llist_CommandType = SCAMENUCMDTYPE_IconWindow;
4518 return NewTreeNode;
4521 //----------------------------------------------------------------------------
4523 static SAVEDS(APTR) INTERRUPT SettingsChangedHookFunc(struct Hook *hook, Object *o, Msg msg)
4525 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
4527 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
4528 SetChangedFlag(inst, TRUE);
4530 return NULL;
4533 //----------------------------------------------------------------------------
4535 static SAVEDS(void) INTERRUPT AslIntuiMsgHookFunc(struct Hook *hook, Object *o, Msg msg)
4537 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
4538 struct IntuiMessage *iMsg = (struct IntuiMessage *) msg;
4540 if (IDCMP_REFRESHWINDOW == iMsg->Class)
4542 DoMethod(inst->mpb_Objects[OBJNDX_APP_Main], MUIM_Application_CheckRefresh);
4546 //----------------------------------------------------------------------------
4548 static SAVEDS(void) INTERRUPT HideObsoleteHookFunc(struct Hook *hook, Object *o, Msg msg)
4550 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
4551 ULONG HideObsolete = 0;
4553 //TODO
4554 get(inst->mpb_Objects[OBJNDX_Menu_HideObsolete], MUIA_Menuitem_Checked, &HideObsolete);
4555 inst->mpb_HideObsoletePopupMenus = HideObsolete;
4557 d1(KPrintF("%s/%s/%ld: mpb_HideObsoletePopupMenus=%ld\n", __FILE__, __FUNC__, __LINE__, inst->mpb_HideObsoletePopupMenus));
4559 set(inst->mpb_Objects[OBJNDX_MainListView], MUIA_NListtree_Quiet, TRUE);
4560 set(inst->mpb_Objects[OBJNDX_HiddenListTree], MUIA_NListtree_Quiet, TRUE);
4562 if (inst->mpb_HideObsoletePopupMenus)
4564 // Move obsolete entries from OBJNDX_MainListTree to OBJNDX_HiddenListTree
4565 MoveMenuTree(inst, OBJNDX_HiddenListTree, OBJNDX_MainListTree, POPMENUINDEX_Disk);
4566 MoveMenuTree(inst, OBJNDX_HiddenListTree, OBJNDX_MainListTree, POPMENUINDEX_Drawer);
4567 MoveMenuTree(inst, OBJNDX_HiddenListTree, OBJNDX_MainListTree, POPMENUINDEX_ToolProject);
4568 MoveMenuTree(inst, OBJNDX_HiddenListTree, OBJNDX_MainListTree, POPMENUINDEX_Trashcan);
4569 MoveMenuTree(inst, OBJNDX_HiddenListTree, OBJNDX_MainListTree, POPMENUINDEX_AppIcon);
4571 else
4573 // Move obsolete entries from OBJNDX_HiddenListTree to OBJNDX_MainListTree
4574 MoveMenuTree(inst, OBJNDX_MainListTree, OBJNDX_HiddenListTree, POPMENUINDEX_Disk);
4575 MoveMenuTree(inst, OBJNDX_MainListTree, OBJNDX_HiddenListTree, POPMENUINDEX_Drawer);
4576 MoveMenuTree(inst, OBJNDX_MainListTree, OBJNDX_HiddenListTree, POPMENUINDEX_ToolProject);
4577 MoveMenuTree(inst, OBJNDX_MainListTree, OBJNDX_HiddenListTree, POPMENUINDEX_Trashcan);
4578 MoveMenuTree(inst, OBJNDX_MainListTree, OBJNDX_HiddenListTree, POPMENUINDEX_AppIcon);
4581 set(inst->mpb_Objects[OBJNDX_MainListView], MUIA_NListtree_Quiet, FALSE);
4582 set(inst->mpb_Objects[OBJNDX_HiddenListTree], MUIA_NListtree_Quiet, FALSE);
4584 d1(KPrintF("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
4587 //----------------------------------------------------------------------------
4589 static SAVEDS(void) INTERRUPT MenuCopyHookFunc(struct Hook *hook, Object *o, Msg msg)
4591 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
4592 struct MUI_NListtree_TreeNode *TreeNode;
4594 d1(KPrintF("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4596 if (inst->mpb_QuietFlag)
4597 return;
4599 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4600 MUIM_NListtree_GetEntry,
4601 MUIV_NListtree_GetEntry_ListNode_Active,
4602 MUIV_NListtree_GetEntry_Position_Active, 0);
4604 if (TreeNode)
4606 DoMethod(inst->mpb_Objects[OBJNDX_ListTreeClipboard], MUIM_NListtree_Clear);
4608 CopyFileTypesEntry(inst,
4609 (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_ListNode_Root,
4610 (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
4611 TreeNode,
4612 OBJNDX_ListTreeClipboard,
4613 OBJNDX_MainListTree);
4616 d1(KPrintF("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
4619 //----------------------------------------------------------------------------
4621 static SAVEDS(void) INTERRUPT MenuCutHookFunc(struct Hook *hook, Object *o, Msg msg)
4623 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
4624 struct MUI_NListtree_TreeNode *TreeNode;
4626 d1(KPrintF("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4628 if (inst->mpb_QuietFlag)
4629 return;
4631 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4632 MUIM_NListtree_GetEntry,
4633 MUIV_NListtree_GetEntry_ListNode_Active,
4634 MUIV_NListtree_GetEntry_Position_Active, 0);
4636 if (TreeNode)
4638 DoMethod(inst->mpb_Objects[OBJNDX_ListTreeClipboard], MUIM_NListtree_Clear);
4640 CopyFileTypesEntry(inst,
4641 (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_ListNode_Root,
4642 (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
4643 TreeNode,
4644 OBJNDX_ListTreeClipboard,
4645 OBJNDX_MainListTree);
4647 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree], MUIM_NListtree_Remove,
4648 MUIV_NListtree_Remove_ListNode_Active,
4649 MUIV_NListtree_Remove_TreeNode_Active, 0);
4652 d1(KPrintF("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
4655 //----------------------------------------------------------------------------
4657 static SAVEDS(void) INTERRUPT MenuPasteHookFunc(struct Hook *hook, Object *o, Msg msg)
4659 struct MenuPrefsInst *inst = (struct MenuPrefsInst *) hook->h_Data;
4660 struct MUI_NListtree_TreeNode *tn;
4662 d1(KPrintF("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4664 tn = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4665 MUIM_NListtree_GetEntry,
4666 MUIV_NListtree_GetEntry_ListNode_Active,
4667 MUIV_NListtree_GetEntry_Position_Active,
4669 d1(kprintf("%s/%ld: active tn=%08lx <%s>\n", __FUNC__, __LINE__, tn, tn ? tn->tn_Name : (STRPTR) ""));
4671 if (tn)
4673 struct MUI_NListtree_TreeNode *tnParent;
4674 struct MUI_NListtree_TreeNode *tnShadow;
4676 tnParent = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4677 MUIM_NListtree_GetEntry,
4679 MUIV_NListtree_GetEntry_Position_Parent,
4682 tnShadow = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_ListTreeClipboard],
4683 MUIM_NListtree_GetEntry,
4684 MUIV_NListtree_Insert_ListNode_Root,
4685 MUIV_NListtree_GetEntry_Position_Head,
4688 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NList_Quiet, MUIV_NList_Quiet_Full);
4690 if (MayPasteBelow(inst, tn, tnShadow))
4692 CopyFileTypesEntry(inst,
4693 tnParent, tn,
4694 tnShadow,
4695 OBJNDX_MainListTree, OBJNDX_ListTreeClipboard);
4697 // EntryHasChanged(inst, tnParent);
4699 else if (MayPasteOnto(inst, tn, tnShadow))
4701 CopyFileTypesEntry(inst,
4702 tn, (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
4703 tnShadow,
4704 OBJNDX_MainListTree, OBJNDX_ListTreeClipboard);
4706 // EntryHasChanged(inst, tn);
4709 set(inst->mpb_Objects[OBJNDX_MainListTree], MUIA_NList_Quiet, MUIV_NList_Quiet_None);
4711 DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4712 MUIM_NListtree_Redraw,
4717 d1(KPrintF("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
4720 //----------------------------------------------------------------------------
4722 static struct MUI_NListtree_TreeNode *MoveMenuTree(struct MenuPrefsInst *inst,
4723 ULONG DestListtreeIndex, ULONG SrcListtreeIndex, ULONG EntryIndex)
4725 struct MUI_NListtree_TreeNode *NewNode = NULL;
4727 if (inst->mpb_PopMenuNode[EntryIndex].mpn_ListNode &&
4728 inst->mpb_PopMenuNode[EntryIndex].mpn_Listtree == inst->mpb_Objects[SrcListtreeIndex])
4730 // Create new entry in dest listtree
4731 NewNode = CopyMenuEntry(inst,
4732 inst->mpb_Objects[DestListtreeIndex],
4733 inst->mpb_Objects[SrcListtreeIndex],
4734 inst->mpb_PopMenuNode[EntryIndex].mpn_ListNode,
4735 MUIV_NListtree_Insert_ListNode_Root);
4736 if (NewNode)
4738 // remove old entry (w/ subentries) from src listtree
4739 DoMethod(inst->mpb_PopMenuNode[EntryIndex].mpn_Listtree,
4740 MUIM_NListtree_Remove,
4741 MUIV_NListtree_Remove_ListNode_Root,
4742 inst->mpb_PopMenuNode[EntryIndex].mpn_ListNode,
4745 // remember new entry
4746 inst->mpb_PopMenuNode[EntryIndex].mpn_Listtree = inst->mpb_Objects[DestListtreeIndex];
4747 inst->mpb_PopMenuNode[EntryIndex].mpn_ListNode = NewNode;
4751 return NewNode;
4754 //----------------------------------------------------------------------------
4756 static struct MUI_NListtree_TreeNode *CopyFileTypesEntry(struct MenuPrefsInst *inst,
4757 struct MUI_NListtree_TreeNode *tnToListNode, struct MUI_NListtree_TreeNode *tnToPrevNode,
4758 struct MUI_NListtree_TreeNode *tnFrom, ULONG destList, ULONG srcList)
4760 struct MenuListEntry *mleFrom = (struct MenuListEntry *) tnFrom->tn_User;
4761 struct MenuListEntry *mleTo;
4762 struct MUI_NListtree_TreeNode *tnNew;
4763 struct MUI_NListtree_TreeNode *tnChild;
4764 struct MenuInsertEntry mie;
4765 struct ScalosMenuTree mTree;
4766 STRPTR IconNames = NULL;
4768 memset(&mTree, 0, sizeof(mTree));
4769 mie.mie_TreeEntry = &mTree;
4771 if (NULL == tnFrom)
4772 return NULL;
4774 tnChild = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[srcList],
4775 MUIM_NListtree_GetEntry,
4776 tnFrom,
4777 MUIV_NListtree_GetEntry_Position_Head,
4780 mTree.mtre_type = mleFrom->llist_EntryType;
4781 mie.mie_MenuFlags = mleFrom->llist_Flags;
4783 switch (mleFrom->llist_EntryType)
4785 case SCAMENUTYPE_Menu:
4786 case SCAMENUTYPE_ToolsMenu:
4787 case SCAMENUTYPE_MenuItem:
4788 stccpy(mTree.MenuCombo.MenuTree.mtre_hotkey, mleFrom->llist_HotKey,
4789 sizeof(mTree.MenuCombo.MenuTree.mtre_hotkey));
4791 if (strlen(mleFrom->llist_UnselectedIconName) > 0
4792 || strlen(mleFrom->llist_SelectedIconName) > 0)
4794 size_t len = 2 + strlen(mleFrom->llist_UnselectedIconName) + strlen(mleFrom->llist_SelectedIconName);
4796 IconNames = malloc(len);
4797 if (IconNames)
4799 strcpy(IconNames, mleFrom->llist_UnselectedIconName);
4800 strcpy(IconNames + 1 + strlen(IconNames), mleFrom->llist_SelectedIconName);
4802 mTree.mtre_flags |= MTREFLGF_IconNames;
4805 break;
4806 case SCAMENUTYPE_Command:
4807 mTree.MenuCombo.MenuCommand.mcom_type = mleFrom->llist_CommandType;
4808 mTree.MenuCombo.MenuCommand.mcom_flags = mleFrom->llist_CommandFlags;
4809 mTree.MenuCombo.MenuCommand.mcom_pri = mleFrom->llist_Priority;
4810 mTree.MenuCombo.MenuCommand.mcom_stack = mleFrom->llist_Stack;
4811 break;
4812 default:
4813 break;
4816 tnNew = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[destList],
4817 MUIM_NListtree_Insert,
4818 tnFrom->tn_Name,
4819 &mie,
4820 tnToListNode,
4821 tnToPrevNode,
4822 tnFrom->tn_Flags);
4824 if (IconNames)
4825 free(IconNames);
4827 mleTo = (struct MenuListEntry *) tnNew->tn_User;
4829 *mleTo = *mleFrom;
4831 // Copy Children
4832 while (tnChild)
4834 d1(kprintf("%s/%ld: tnChild=%08lx <%s>\n", __FUNC__, __LINE__, tnChild, tnChild->tn_Name));
4836 CopyFileTypesEntry(inst,
4837 tnNew, (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail,
4838 tnChild, destList, srcList);
4840 tnChild = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[srcList],
4841 MUIM_NListtree_GetEntry,
4842 tnChild,
4843 MUIV_NListtree_GetEntry_Position_Next,
4847 return tnNew;
4850 //----------------------------------------------------------------------------
4852 static LONG CopyMenuTree(struct MenuPrefsInst *inst,
4853 Object *ListTreeDest, Object *ListTreeSrc,
4854 struct MUI_NListtree_TreeNode *Src, struct MUI_NListtree_TreeNode *DestParent)
4856 LONG Result = RETURN_OK;
4858 d1(KPrintF("%s/%s/%ld: START\n", __FILE__, __FUNC__, __LINE__));
4860 while (Src)
4862 CopyMenuEntry(inst, ListTreeDest, ListTreeSrc, Src, DestParent);
4864 Src = (struct MUI_NListtree_TreeNode *) DoMethod(ListTreeSrc,
4865 MUIM_NListtree_GetEntry,
4866 Src,
4867 MUIV_NListtree_GetEntry_Position_Next,
4868 MUIV_NListtree_GetEntry_Flag_SameLevel);
4869 d1(KPrintF("%s/%s/%ld: Src=%08lx\n", __FILE__, __FUNC__, __LINE__, Src));
4872 d1(KPrintF("%s/%s/%ld: END Result=%ld\n", __FILE__, __FUNC__, __LINE__, Result));
4874 return Result;
4877 //----------------------------------------------------------------------------
4879 static struct MUI_NListtree_TreeNode *CopyMenuEntry(struct MenuPrefsInst *inst,
4880 Object *ListTreeDest, Object *ListTreeSrc,
4881 struct MUI_NListtree_TreeNode *Src, struct MUI_NListtree_TreeNode *DestParent)
4883 const struct MenuListEntry *mleSrc = (struct MenuListEntry *) Src->tn_User;
4884 struct MUI_NListtree_TreeNode *NewNode;
4886 d1(KPrintF("%s/%s/%ld: TreeNode=%08lx <%s> DestParent=%08lx\n", \
4887 __FILE__, __FUNC__, __LINE__, Src, Src->tn_Name ? Src->tn_Name : (STRPTR) "===BAR===", DestParent));
4889 NewNode = (struct MUI_NListtree_TreeNode *) DoMethod(ListTreeDest,
4890 MUIM_NListtree_Insert, Src->tn_Name,
4892 DestParent,
4893 MUIV_NListtree_Insert_PrevNode_Tail,
4894 Src->tn_Flags);
4895 if (NewNode)
4897 struct MenuListEntry *mleDest = (struct MenuListEntry *) NewNode->tn_User;
4898 struct MUI_NListtree_TreeNode *SubNode;
4900 // Clone entry
4901 *mleDest = *mleSrc;
4903 SubNode = (struct MUI_NListtree_TreeNode *) DoMethod(ListTreeSrc,
4904 MUIM_NListtree_GetEntry,
4905 Src,
4906 MUIV_NListtree_GetEntry_Position_Head,
4909 d1(KPrintF("%s/%s/%ld: SubNode=%08lx\n", __FILE__, __FUNC__, __LINE__, SubNode));
4910 if (SubNode)
4912 CopyMenuTree(inst,
4913 ListTreeDest,
4914 ListTreeSrc,
4915 SubNode,
4916 NewNode);
4920 return NewNode;
4923 //----------------------------------------------------------------------------
4925 static void EnableCommandArgumentGadgets(struct MenuPrefsInst *inst, const struct MenuListEntry *mle)
4927 switch (mle->llist_CommandType)
4929 case SCAMENUCMDTYPE_AmigaDOS:
4930 case SCAMENUCMDTYPE_Workbench:
4931 set(inst->mpb_Objects[OBJNDX_CheckArgs], MUIA_Disabled, FALSE);
4932 set(inst->mpb_Objects[OBJNDX_CheckArgs], MUIA_Selected, (mle->llist_CommandFlags & MCOMFLGF_Args));
4933 set(inst->mpb_Objects[OBJNDX_SliderPriority], MUIA_Disabled, FALSE);
4934 set(inst->mpb_Objects[OBJNDX_StringStack], MUIA_Disabled, FALSE);
4935 break;
4937 case SCAMENUCMDTYPE_Command:
4938 case SCAMENUCMDTYPE_IconWindow:
4939 case SCAMENUCMDTYPE_ARexx:
4940 case SCAMENUCMDTYPE_Plugin:
4941 set(inst->mpb_Objects[OBJNDX_CheckArgs], MUIA_Disabled, TRUE);
4942 set(inst->mpb_Objects[OBJNDX_CheckArgs], MUIA_Selected, FALSE);
4943 set(inst->mpb_Objects[OBJNDX_SliderPriority], MUIA_Disabled, TRUE);
4944 set(inst->mpb_Objects[OBJNDX_StringStack], MUIA_Disabled, TRUE);
4945 break;
4949 //----------------------------------------------------------------------------
4951 static BOOL IsPopupMenu(struct MenuPrefsInst *inst, struct MUI_NListtree_TreeNode *TreeNode)
4953 struct MUI_NListtree_TreeNode *ParentNode;
4954 BOOL IsPopupMenu = FALSE;
4956 // find root of this TreeNode
4957 ParentNode = TreeNode;
4958 while (ParentNode)
4960 if (inst->mpb_MainMenuNode.mpn_ListNode != ParentNode)
4962 short n;
4964 for (n = 0; n < Sizeof(inst->mpb_PopMenuNode); n++)
4966 if (inst->mpb_PopMenuNode[n].mpn_ListNode == ParentNode)
4968 IsPopupMenu = TRUE;
4969 break;
4974 ParentNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
4975 MUIM_NListtree_GetEntry, ParentNode, MUIV_NListtree_GetEntry_Position_Parent, 0);
4977 d1(kprintf("%s/%s/%ld: Parent=%08lx\n", __FILE__, __FUNC__, __LINE__, ParentNode));
4980 return IsPopupMenu;
4983 //----------------------------------------------------------------------------
4985 static enum MenuEntryType GetMenuEntryType(struct MenuPrefsInst *inst,
4986 struct MUI_NListtree_TreeNode *TreeNode)
4988 struct MenuListEntry *mle = (struct MenuListEntry *) TreeNode->tn_User;
4989 struct MUI_NListtree_TreeNode *ParentNode;
4990 BOOL IsMainMenu = FALSE;
4991 BOOL IsPopupMenu = FALSE;
4992 ULONG Level = 0;
4994 if (NULL == mle)
4995 return MENUENTRY_Invalid;
4997 if (SCAMENUTYPE_Command == mle->llist_EntryType)
4999 // Get parent menu entry for command
5000 TreeNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
5001 MUIM_NListtree_GetEntry, TreeNode, MUIV_NListtree_GetEntry_Position_Parent, 0);
5003 mle = (struct MenuListEntry *) TreeNode->tn_User;
5006 // find root of this TreeNode
5007 ParentNode = TreeNode;
5008 while (ParentNode)
5010 if (inst->mpb_MainMenuNode.mpn_ListNode == ParentNode)
5011 IsMainMenu = TRUE;
5012 else
5014 short n;
5016 for (n = 0; n < Sizeof(inst->mpb_PopMenuNode); n++)
5018 if (inst->mpb_PopMenuNode[n].mpn_ListNode == ParentNode)
5020 IsPopupMenu = TRUE;
5021 break;
5026 Level++;
5028 ParentNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
5029 MUIM_NListtree_GetEntry, ParentNode, MUIV_NListtree_GetEntry_Position_Parent, 0);
5031 d1(kprintf("%s/%s/%ld: Parent=%08lx\n", __FILE__, __FUNC__, __LINE__, ParentNode));
5034 if (IsMainMenu)
5036 Level -= 2;
5037 // Level 0 = MainMenu
5038 // Level 1 = Menu entry
5039 // Level 2 = MenuItem
5040 // Level 3 = SubItem
5042 else if (IsPopupMenu)
5044 Level--;
5045 // Level 1 = Popup Menu
5046 // Level 2 = MenuItem
5047 // Level 3 = SubItem
5049 else
5050 return MENUENTRY_Invalid;
5052 d1(kprintf("%s/%s/%ld: IsMainMenu=%ld IsPopupMenu=%ld Level=%ld\n", \
5053 __FILE__, __FUNC__, __LINE__, IsMainMenu, IsPopupMenu, Level));
5055 switch (mle->llist_EntryType)
5057 case SCAMENUTYPE_Menu:
5058 case SCAMENUTYPE_MainMenu:
5059 case SCAMENUTYPE_ToolsMenu:
5060 Level++; // Check applies to Menu children
5061 break;
5062 default:
5063 break;
5066 switch (Level)
5068 case 1: // Menu
5069 return MENUENTRY_Menu;
5070 break;
5071 case 2: // MenuItem
5072 return MENUENTRY_MenuItem;
5073 break;
5074 case 3: // SubItem
5075 return MENUENTRY_SubItem;
5076 break;
5077 default: // should never occur
5078 return MENUENTRY_Invalid;
5079 break;
5083 //----------------------------------------------------------------------------
5085 static ULONG GetMaxCountForEntry(enum MenuEntryType type)
5087 switch (type)
5089 case MENUENTRY_Menu:
5090 return MAX_MENU;
5091 break;
5092 case MENUENTRY_MenuItem:
5093 return MAX_MENUITEM;
5094 break;
5095 case MENUENTRY_SubItem:
5096 return MAX_SUBITEM;
5097 break;
5098 default:
5099 return 0;
5100 break;
5104 //----------------------------------------------------------------------------
5106 void _XCEXIT(long x)
5110 //----------------------------------------------------------------------------
5112 static void SwitchPopButton(struct MenuPrefsInst *inst, UBYTE CommandType)
5114 if (SCAMENUCMDTYPE_Command == CommandType)
5116 set(inst->mpb_Objects[OBJNDX_PopObject], MUIA_ShowMe, TRUE);
5117 set(inst->mpb_Objects[OBJNDX_Popbutton], MUIA_ShowMe, FALSE);
5119 else
5121 set(inst->mpb_Objects[OBJNDX_PopObject], MUIA_ShowMe, FALSE);
5122 set(inst->mpb_Objects[OBJNDX_Popbutton], MUIA_ShowMe, TRUE);
5127 //----------------------------------------------------------------------------
5129 DISPATCHER(myNListTree)
5131 struct MenuPrefsInst *inst = NULL;
5132 ULONG Result;
5134 d1(kprintf("%s/%s/%ld: MethodID=%08lx\n", __FILE__, __FUNC__, __LINE__, msg->MethodID));
5136 switch(msg->MethodID)
5138 case MUIM_ContextMenuChoice:
5140 struct MUIP_ContextMenuChoice *cmc = (struct MUIP_ContextMenuChoice *) msg;
5141 Object *MenuObj;
5142 ULONG MenuHookIndex = 0;
5143 struct Hook *MenuHook = NULL;
5145 get(obj, MUIA_NList_PrivateData, &inst);
5147 d1(kprintf("%s/%s//%ld: MUIM_ContextMenuChoice item=%08lx\n", __FILE__, __FUNC__, __LINE__, cmc->item));
5149 MenuObj = cmc->item;
5151 d1(kprintf("%s/%s//%ld: MenuObj=%08lx\n", __FILE__, __FUNC__, __LINE__, MenuObj));
5152 d1(kprintf("%s/%s//%ld: msg=%08lx *msg=%08lx\n", __FILE__, __FUNC__, __LINE__, msg, *((ULONG *) msg)));
5154 get(MenuObj, MUIA_UserData, &MenuHookIndex);
5156 if (MenuHookIndex > 0 && MenuHookIndex < HOOKNDX_MAX)
5157 MenuHook = &inst->mpb_Hooks[MenuHookIndex];
5159 d1(kprintf("%s/%s//%ld: MenuHook=%08lx\n", __FILE__, __FUNC__, __LINE__, MenuHook));
5160 if (MenuHook)
5161 DoMethod(inst->mpb_Objects[OBJNDX_Group_Main], MUIM_CallHook, MenuHook, 0);
5163 Result = 0;
5165 break;
5167 case MUIM_NList_TestPos:
5169 struct TestPosArg
5171 ULONG MethodID;
5172 LONG x, y;
5173 struct MUI_NList_TestPos_Result *res;
5175 struct TestPosArg *tpa = (struct TestPosArg *) msg;
5177 get(obj, MUIA_NList_PrivateData, &inst);
5179 if (inst->mpb_PageIsActive)
5180 Result = DoSuperMethodA(cl, obj, msg);
5181 else
5183 Result = 0;
5184 tpa->res->entry = tpa->res->column = -1;
5187 d1(kprintf("%s/%s//%ld: MUIM_NList_TestPos Result=%08lx x=%ld y=%ld tpr=%08lx entry=%ld column=%ld\n", \
5188 __FILE__, __FUNC__, __LINE__, Result, tpa->x, tpa->y, tpa->res, tpa->res->entry, tpa->res->column));
5190 break;
5192 case MUIM_DragDrop:
5193 get(obj, MUIA_NList_PrivateData, &inst);
5194 SetChangedFlag(inst, TRUE);
5195 Result = DoSuperMethodA(cl, obj, msg);
5196 break;
5198 case MUIM_NList_DropType:
5200 struct MUIP_NList_DropType *dr = (struct MUIP_NList_DropType *)msg;
5201 struct MUI_NListtree_TreeNode *tnTo, *tnFrom;
5202 struct MUI_NListtree_TestPos_Result res;
5204 get(obj, MUIA_NList_PrivateData, &inst);
5206 inst->mpb_MenuTreeMayDrop = FALSE;
5208 Result = DoSuperMethodA(cl, obj, msg);
5209 d1(KPrintF("%s/%ld: DropType=%ld pos=%ld\n", __FUNC__, __LINE__, *(dr->type), *(dr->pos)));
5211 DoMethod(obj, MUIM_NListtree_TestPos, dr->mousex, dr->mousey, &res);
5213 tnTo = res.tpr_TreeNode;
5215 tnFrom = MUIV_NListtree_Active_Off;
5216 get(obj, MUIA_NListtree_Active, &tnFrom);
5218 d1(KPrintF("%s/%ld: tnFrom=%08lx tnTo=%08lx\n", __FUNC__, __LINE__, tnFrom, tnTo));
5220 if (tnTo && tnFrom)
5222 switch (*(dr->type))
5224 case MUIV_NListtree_DropType_None:
5225 case MUIV_NListtree_DropType_Sorted:
5226 default:
5227 break;
5228 case MUIV_NListtree_DropType_Above:
5229 case MUIV_NListtree_DropType_Below:
5230 if (MayPasteBelow(inst, tnTo, tnFrom))
5231 inst->mpb_MenuTreeMayDrop = TRUE;
5232 break;
5233 case MUIV_NListtree_DropType_Onto:
5234 if (MayPasteOnto(inst, tnTo, tnFrom))
5235 inst->mpb_MenuTreeMayDrop = TRUE;
5236 break;
5238 d1(KPrintF("%s/%ld: DropType=%ld\n", __FUNC__, __LINE__, *(dr->type)));
5241 break;
5243 // we catch MUIM_DragReport because we want to restrict some dragging for some special objects
5244 case MUIM_DragReport:
5246 get(obj, MUIA_NList_PrivateData, &inst);
5248 d1(KPrintF("%s/%ld: MUIM_DragReport\n", __FUNC__, __LINE__));
5250 Result = DoSuperMethodA(cl, obj, msg);
5251 if (!inst->mpb_MenuTreeMayDrop)
5252 Result = MUIV_DragReport_Abort;
5254 d1(KPrintF("%s/%ld: MUIM_DragReport\n", __FUNC__, __LINE__));
5256 break;
5257 default:
5258 Result = DoSuperMethodA(cl, obj, msg);
5261 return Result;
5263 DISPATCHER_END
5266 static Object *CreatePrefsImage(void)
5268 #include "MenuPrefsImage.h"
5269 Object *img;
5271 // First try to load datatypes image from THEME: tree
5272 img = DataTypesImageObject,
5273 MUIA_ScaDtpic_Name, (ULONG) "THEME:prefs/plugins/menu",
5274 MUIA_ScaDtpic_FailIfUnavailable, TRUE,
5275 End; //DataTypesMCCObject
5277 if (NULL == img)
5278 img = IMG(MenuPrefs, MENUPREFS); // use built-in fallback image
5280 return img;
5284 static void InitHooks(struct MenuPrefsInst *inst)
5286 ULONG n;
5288 for (n=0; n<HOOKNDX_MAX; n++)
5290 inst->mpb_Hooks[n] = MenuPrefsHooks[n];
5291 inst->mpb_Hooks[n].h_Data = inst;
5296 static void SetChangedFlag(struct MenuPrefsInst *inst, BOOL changed)
5298 if (changed != inst->mpb_Changed)
5300 set(inst->mpb_Objects[OBJNDX_Lamp_Changed],
5301 MUIA_Lamp_Color, changed ? MUIV_Lamp_Color_Ok : MUIV_Lamp_Color_Off);
5302 inst->mpb_Changed = changed;
5307 static void AddDefaultMenuContents(struct MenuPrefsInst *inst)
5309 ULONG n;
5310 struct MUI_NListtree_TreeNode *LastNode[4];
5311 Object *Listtree = NULL;
5312 struct MenuInsertEntry mie;
5313 struct ScalosMenuTree mTree;
5315 mie.mie_TreeEntry = &mTree;
5317 inst->mpb_QuietFlag = TRUE;
5319 for (n = 0; n < DefaultMenuEntries; n++)
5321 struct MUI_NListtree_TreeNode *ParentNode;
5322 CONST_STRPTR MenuName;
5323 struct MUI_NListtree_TreeNode *NewNode;
5324 struct MenuListEntry *mle;
5325 ULONG InsertFlags;
5327 memset(&mTree, 0, sizeof(mTree));
5329 switch (DefaultMenu[n].dme_ParentNode)
5331 case DEFAULTPARENTNODE_MainMenu:
5332 Listtree = inst->mpb_MainMenuNode.mpn_Listtree;
5333 ParentNode = inst->mpb_MainMenuNode.mpn_ListNode;
5334 d1(KPrintF("%s/%s//%ld: DEFAULTPARENTNODE_MainMenu Listtree=%08lx\n", __FILE__, __FUNC__, __LINE__, Listtree));
5335 break;
5336 case DEFAULTPARENTNODE_Popup_Disk:
5337 Listtree = inst->mpb_PopMenuNode[POPMENUINDEX_Disk].mpn_Listtree;
5338 ParentNode = inst->mpb_PopMenuNode[POPMENUINDEX_Disk].mpn_ListNode;
5339 d1(KPrintF("%s/%s//%ld:DEFAULTPARENTNODE_Popup_Disk Listtree=%08lx\n", __FILE__, __FUNC__, __LINE__, Listtree));
5340 break;
5341 case DEFAULTPARENTNODE_Popup_Drawer:
5342 Listtree = inst->mpb_PopMenuNode[POPMENUINDEX_Drawer].mpn_Listtree;
5343 ParentNode = inst->mpb_PopMenuNode[POPMENUINDEX_Drawer].mpn_ListNode;
5344 d1(KPrintF("%s/%s//%ld: DEFAULTPARENTNODE_Popup_Drawer Listtree=%08lx\n", __FILE__, __FUNC__, __LINE__, Listtree));
5345 break;
5346 case DEFAULTPARENTNODE_Popup_ToolProject:
5347 Listtree = inst->mpb_PopMenuNode[POPMENUINDEX_ToolProject].mpn_Listtree;
5348 ParentNode = inst->mpb_PopMenuNode[POPMENUINDEX_ToolProject].mpn_ListNode;
5349 d1(KPrintF("%s/%s//%ld: DEFAULTPARENTNODE_Popup_ToolProject Listtree=%08lx\n", __FILE__, __FUNC__, __LINE__, Listtree));
5350 break;
5351 case DEFAULTPARENTNODE_Popup_Trashcan:
5352 Listtree = inst->mpb_PopMenuNode[POPMENUINDEX_ToolProject].mpn_Listtree;
5353 ParentNode = inst->mpb_PopMenuNode[POPMENUINDEX_Trashcan].mpn_ListNode;
5354 d1(KPrintF("%s/%s//%ld: DEFAULTPARENTNODE_Popup_Trashcan Listtree=%08lx\n", __FILE__, __FUNC__, __LINE__, Listtree));
5355 break;
5356 case DEFAULTPARENTNODE_Popup_Window:
5357 Listtree = inst->mpb_PopMenuNode[POPMENUINDEX_Window].mpn_Listtree;
5358 ParentNode = inst->mpb_PopMenuNode[POPMENUINDEX_Window].mpn_ListNode;
5359 d1(KPrintF("%s/%s//%ld: DEFAULTPARENTNODE_Popup_Window Listtree=%08lx\n", __FILE__, __FUNC__, __LINE__, Listtree));
5360 break;
5361 case DEFAULTPARENTNODE_Popup_AppIcon:
5362 Listtree = inst->mpb_PopMenuNode[POPMENUINDEX_AppIcon].mpn_Listtree;
5363 ParentNode = inst->mpb_PopMenuNode[POPMENUINDEX_AppIcon].mpn_ListNode;
5364 d1(KPrintF("%s/%s//%ld: DEFAULTPARENTNODE_Popup_AppIcon Listtree=%08lx\n", __FILE__, __FUNC__, __LINE__, Listtree));
5365 break;
5366 case DEFAULTPARENTNODE_Popup_Desktop:
5367 Listtree = inst->mpb_PopMenuNode[POPMENUINDEX_Desktop].mpn_Listtree;
5368 ParentNode = inst->mpb_PopMenuNode[POPMENUINDEX_Desktop].mpn_ListNode;
5369 d1(KPrintF("%s/%s//%ld: DEFAULTPARENTNODE_Popup_Desktop Listtree=%08lx\n", __FILE__, __FUNC__, __LINE__, Listtree));
5370 break;
5371 case DEFAULTPARENTNODE_LastInsertedMenu:
5372 case DEFAULTPARENTNODE_LastInsertedMenuItem:
5373 ParentNode = LastNode[DefaultMenu[n].dme_Level - 1];
5374 break;
5375 case DEFAULTPARENTNODE_LastInserted:
5376 default:
5377 ParentNode = (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_ListNode_LastInserted;
5378 break;
5381 InsertFlags = MUIV_NListtree_Insert_Flag_Active;
5383 if (SCAMENUTYPE_Command == DefaultMenu[n].dme_EntryType)
5385 MenuName = (CONST_STRPTR) DefaultMenu[n].dme_NameId;
5386 mTree.MenuCombo.MenuCommand.mcom_name = (STRPTR) MenuName;
5388 else
5390 if (DefaultMenu[n].dme_NameId)
5391 MenuName = GetLocString(DefaultMenu[n].dme_NameId);
5392 else
5393 MenuName = "";
5394 InsertFlags |= TNF_OPEN | TNF_LIST;
5397 d1(KPrintF("%s/%s//%ld: Listtree=%08lx ParentNode=%08lx\n", __FILE__, __FUNC__, __LINE__, Listtree, ParentNode));
5399 mTree.mtre_type = DefaultMenu[n].dme_EntryType;
5400 mie.mie_MenuFlags = 0;
5402 switch (DefaultMenu[n].dme_EntryType)
5404 case SCAMENUTYPE_Menu:
5405 case SCAMENUTYPE_ToolsMenu:
5406 case SCAMENUTYPE_MenuItem:
5407 stccpy(mTree.MenuCombo.MenuTree.mtre_hotkey, GetLocString(DefaultMenu[n].dme_MenuShortId), sizeof(mle->llist_HotKey));
5408 break;
5409 case SCAMENUTYPE_Command:
5410 mTree.MenuCombo.MenuCommand.mcom_type = DefaultMenu[n].dme_CmdType;
5411 mTree.MenuCombo.MenuCommand.mcom_flags = DefaultMenu[n].dme_CmdFlags;
5412 mTree.MenuCombo.MenuCommand.mcom_pri = DefaultMenu[n].dme_CmdPri;
5413 mTree.MenuCombo.MenuCommand.mcom_stack = DefaultMenu[n].dme_CmdStackSize;
5414 break;
5415 default:
5416 break;
5419 DoMethod(Listtree,
5420 MUIM_NListtree_Insert, MenuName,
5421 &mie,
5422 ParentNode,
5423 MUIV_NListtree_Insert_PrevNode_Tail,
5424 InsertFlags);
5426 d1(KPrintF("%s/%s//%ld: Listtree=%08lx NewNode=%08lx\n", __FILE__, __FUNC__, __LINE__, Listtree, NewNode));
5427 NewNode = (struct MUI_NListtree_TreeNode *) DoMethod(Listtree,
5428 MUIM_NListtree_GetEntry,
5429 ParentNode,
5430 MUIV_NListtree_GetEntry_Position_Tail, 0);
5431 d1(KPrintF("%s/%s//%ld: Listtree=%08lx NewNode=%08lx\n", __FILE__, __FUNC__, __LINE__, Listtree, NewNode));
5432 if (NewNode)
5433 mle = (struct MenuListEntry *) NewNode->tn_User;
5434 else
5435 mle = NULL;
5437 if (mle)
5439 switch (DefaultMenu[n].dme_EntryType)
5441 case SCAMENUTYPE_Menu:
5442 case SCAMENUTYPE_ToolsMenu:
5443 case SCAMENUTYPE_MenuItem:
5444 LastNode[DefaultMenu[n].dme_Level] = NewNode;
5445 break;
5446 default:
5447 break;
5452 inst->mpb_QuietFlag = FALSE;
5455 //-----------------------------------------------------------------
5457 static void ParseToolTypes(struct MenuPrefsInst *inst, struct MUIP_ScalosPrefs_ParseToolTypes *ptt)
5459 STRPTR tt;
5461 d1(kprintf("%s/%ld: start ptt=%08lx tooltypes=%08lx\n", __FUNC__, __LINE__, ptt, ptt->ToolTypes));
5462 d1(kprintf("%s/%ld: start tooltypes=%08lx %08lx %08lx\n", __FUNC__, __LINE__, ptt, ptt->ToolTypes[0], ptt->ToolTypes[1], ptt->ToolTypes[2]));
5464 tt = FindToolType(ptt->ToolTypes, "HIDEOBSOLETE");
5465 d1(kprintf("%s/%ld: tt=%08lx\n", __FUNC__, __LINE__, tt));
5466 if (tt)
5468 d1(kprintf("%s/%ld:\n", __FUNC__, __LINE__));
5470 if (MatchToolValue(tt, "YES"))
5471 inst->mpb_HideObsoletePopupMenus = TRUE;
5472 else if (MatchToolValue(tt, "NO"))
5473 inst->mpb_HideObsoletePopupMenus = FALSE;
5475 d1(kprintf("%s/%ld:\n", __FUNC__, __LINE__));
5478 if (inst->mpb_Objects[OBJNDX_Menu_HideObsolete])
5479 set(inst->mpb_Objects[OBJNDX_Menu_HideObsolete], MUIA_Menuitem_Checked, inst->mpb_HideObsoletePopupMenus);
5481 CallHookPkt(&inst->mpb_Hooks[HOOKNDX_HideObsolete],
5482 inst->mpb_Objects[OBJNDX_APP_Main], 0);
5484 d1(kprintf("%s/%ld: end\n", __FUNC__, __LINE__));
5487 //----------------------------------------------------------------------------
5489 BOOL initPlugin(struct PluginBase *PluginBase)
5491 ULONG n;
5493 MajorVersion = PluginBase->pl_LibNode.lib_Version;
5494 MinorVersion = PluginBase->pl_LibNode.lib_Revision;
5496 d1(kprintf("%s/%s//%ld:\n", __FILE__, __FUNC__, __LINE__));
5498 d1(kprintf("%s/%s//%ld: MenuPrefsLibBase=%08lx procName=<%s>\n", __FILE__, __FUNC__, __LINE__, \
5499 PluginBase, FindTask(NULL)->tc_Node.ln_Name));
5501 d1(kprintf("%s/%s//%ld:\n", __FILE__, __FUNC__, __LINE__));
5503 if (!OpenLibraries())
5504 return FALSE;
5506 d1(kprintf("%s/%s//%ld:\n", __FILE__, __FUNC__, __LINE__));
5508 #if !defined(__amigaos4__) && !defined(__AROS__)
5509 if (_STI_240_InitMemFunctions())
5510 return FALSE;
5511 #endif
5513 d1(kprintf("%s/%s//%ld:\n", __FILE__, __FUNC__, __LINE__));
5515 MenuPrefsClass = MUI_CreateCustomClass(&PluginBase->pl_LibNode, MUIC_Group,
5516 NULL, sizeof(struct MenuPrefsInst), DISPATCHER_REF(MenuPrefs));
5518 d1(kprintf("%s/%s//%ld: MenuPrefsClass=%08lx\n", __FILE__, __FUNC__, __LINE__, MenuPrefsClass));
5519 if (NULL == MenuPrefsClass)
5520 return FALSE;
5522 for (n=0; n<Sizeof(CommandsTable); n++)
5523 CommandsArray[n] = &CommandsTable[n];
5524 CommandsArray[Sizeof(CommandsTable)] = NULL;
5526 d1(KPrintF("%s/%s//%ld:\n", __FILE__, __FUNC__, __LINE__));
5528 if (LocaleBase)
5530 if (NULL == MenuPrefsLocale)
5531 MenuPrefsLocale = OpenLocale(NULL);
5533 if (MenuPrefsLocale)
5535 if (NULL == MenuPrefsCatalog)
5537 MenuPrefsCatalog = OpenCatalog(MenuPrefsLocale,
5538 (STRPTR) "Scalos/ScalosMenu.catalog", NULL);
5543 if (!StaticsTranslated)
5545 StaticsTranslated = TRUE;
5547 TranslateStringArray(CmdModeStrings);
5548 TranslateNewMenu(ContextMenus);
5551 if (NULL == myNListTreeClass)
5553 myNListTreeClass = MUI_CreateCustomClass(NULL, MUIC_NListtree,
5554 NULL, 0, DISPATCHER_REF(myNListTree));
5557 d1(KPrintF("%s/%s//%ld: myNListTreeClass=%08lx\n", __FILE__, __FUNC__, __LINE__, myNListTreeClass));
5559 if (NULL == myNListTreeClass)
5560 return FALSE; // Failure
5562 if (NULL == DataTypesImageClass)
5563 DataTypesImageClass = InitDtpicClass();
5565 d1(KPrintF("%s/%s//%ld: DataTypesImageClass=%08lx\n", __FILE__, __FUNC__, __LINE__, DataTypesImageClass));
5567 if (NULL == DataTypesImageClass)
5568 return FALSE; // Failure
5571 d1(KPrintF("%s/%s//%ld: success\n", __FILE__, __FUNC__, __LINE__));
5573 return TRUE; // Success
5576 //----------------------------------------------------------------------------
5578 static void InsertMenuRootEntries(struct MenuPrefsInst *inst)
5580 struct MenuInsertEntry mie;
5581 struct ScalosMenuTree mTree;
5583 memset(&mTree, 0, sizeof(mTree));
5584 mie.mie_TreeEntry = &mTree;
5585 mTree.mtre_type = SCAMENUTYPE_MainMenu;
5587 mie.mie_MenuFlags = LLISTFLGF_NotRemovable | LLISTFLGF_NameNotSetable;
5588 inst->mpb_MainMenuNode.mpn_Listtree = inst->mpb_Objects[OBJNDX_MainListTree];
5589 inst->mpb_MainMenuNode.mpn_ListNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_MainMenuNode.mpn_Listtree,
5590 MUIM_NListtree_Insert, GetLocString(MSGID_MAINMENUNAME),
5591 &mie,
5592 MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail,
5593 MUIV_NListtree_Insert_Flag_Active | TNF_OPEN | TNF_LIST);
5595 mie.mie_MenuFlags = LLISTFLGF_NotRemovable | LLISTFLGF_NameNotSetable | LLISTFLGF_MayNotHaveChildren | LLISTFLGF_PopupMenu;
5596 inst->mpb_PopMenuNode[POPMENUINDEX_Disk].mpn_Listtree = GetMenuEntryListtree(inst);
5597 inst->mpb_PopMenuNode[POPMENUINDEX_Disk].mpn_ListNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_PopMenuNode[POPMENUINDEX_Disk].mpn_Listtree,
5598 MUIM_NListtree_Insert, GetLocString(MSGID_POPMENUNAME1),
5599 &mie,
5600 MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail,
5601 TNF_OPEN | TNF_LIST);
5603 mie.mie_MenuFlags = LLISTFLGF_NotRemovable | LLISTFLGF_NameNotSetable | LLISTFLGF_MayNotHaveChildren | LLISTFLGF_PopupMenu;
5604 inst->mpb_PopMenuNode[POPMENUINDEX_Drawer].mpn_Listtree = GetMenuEntryListtree(inst);
5605 inst->mpb_PopMenuNode[POPMENUINDEX_Drawer].mpn_ListNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_PopMenuNode[POPMENUINDEX_Drawer].mpn_Listtree,
5606 MUIM_NListtree_Insert, GetLocString(MSGID_POPMENUNAME2),
5607 &mie,
5608 MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail,
5609 TNF_OPEN | TNF_LIST);
5611 mie.mie_MenuFlags = LLISTFLGF_NotRemovable | LLISTFLGF_NameNotSetable | LLISTFLGF_MayNotHaveChildren | LLISTFLGF_PopupMenu;
5612 inst->mpb_PopMenuNode[POPMENUINDEX_ToolProject].mpn_Listtree = GetMenuEntryListtree(inst);
5613 inst->mpb_PopMenuNode[POPMENUINDEX_ToolProject].mpn_ListNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_PopMenuNode[POPMENUINDEX_ToolProject].mpn_Listtree,
5614 MUIM_NListtree_Insert, GetLocString(MSGID_POPMENUNAME3),
5615 &mie,
5616 MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail,
5617 TNF_OPEN | TNF_LIST);
5619 mie.mie_MenuFlags = LLISTFLGF_NotRemovable | LLISTFLGF_NameNotSetable | LLISTFLGF_MayNotHaveChildren | LLISTFLGF_PopupMenu;
5620 inst->mpb_PopMenuNode[POPMENUINDEX_Trashcan].mpn_Listtree = GetMenuEntryListtree(inst);
5621 inst->mpb_PopMenuNode[POPMENUINDEX_Trashcan].mpn_ListNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_PopMenuNode[POPMENUINDEX_Trashcan].mpn_Listtree,
5622 MUIM_NListtree_Insert, GetLocString(MSGID_POPMENUNAME4),
5623 &mie,
5624 MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail,
5625 TNF_OPEN | TNF_LIST);
5627 mie.mie_MenuFlags = LLISTFLGF_NotRemovable | LLISTFLGF_NameNotSetable | LLISTFLGF_MayNotHaveChildren | LLISTFLGF_PopupMenu;
5628 inst->mpb_PopMenuNode[POPMENUINDEX_Window].mpn_Listtree = inst->mpb_Objects[OBJNDX_MainListTree];
5629 inst->mpb_PopMenuNode[POPMENUINDEX_Window].mpn_ListNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_PopMenuNode[POPMENUINDEX_Window].mpn_Listtree,
5630 MUIM_NListtree_Insert, GetLocString(MSGID_POPMENUNAME5),
5631 &mie,
5632 MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail,
5633 TNF_OPEN | TNF_LIST);
5635 mie.mie_MenuFlags = LLISTFLGF_NotRemovable | LLISTFLGF_NameNotSetable | LLISTFLGF_MayNotHaveChildren | LLISTFLGF_PopupMenu;
5636 inst->mpb_PopMenuNode[POPMENUINDEX_AppIcon].mpn_Listtree = GetMenuEntryListtree(inst);
5637 inst->mpb_PopMenuNode[POPMENUINDEX_AppIcon].mpn_ListNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_PopMenuNode[POPMENUINDEX_AppIcon].mpn_Listtree,
5638 MUIM_NListtree_Insert, GetLocString(MSGID_POPMENUNAME6),
5639 &mie,
5640 MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail,
5641 TNF_OPEN | TNF_LIST);
5643 mie.mie_MenuFlags = LLISTFLGF_NotRemovable | LLISTFLGF_NameNotSetable | LLISTFLGF_MayNotHaveChildren | LLISTFLGF_PopupMenu;
5644 inst->mpb_PopMenuNode[POPMENUINDEX_Desktop].mpn_Listtree = inst->mpb_Objects[OBJNDX_MainListTree];
5645 inst->mpb_PopMenuNode[POPMENUINDEX_Desktop].mpn_ListNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_PopMenuNode[POPMENUINDEX_Desktop].mpn_Listtree,
5646 MUIM_NListtree_Insert, GetLocString(MSGID_POPMENUNAME7),
5647 &mie,
5648 MUIV_NListtree_Insert_ListNode_Root, MUIV_NListtree_Insert_PrevNode_Tail,
5649 TNF_OPEN | TNF_LIST);
5652 //----------------------------------------------------------------------------
5654 static Object *GetMenuEntryListtree(struct MenuPrefsInst *inst)
5656 return inst->mpb_Objects[inst->mpb_HideObsoletePopupMenus ? OBJNDX_HiddenListTree : OBJNDX_MainListTree];
5659 //----------------------------------------------------------------------------
5661 static struct MUI_NListtree_TreeNode *GetParentNodeForMenu(struct MenuPrefsInst *inst, struct MUI_NListtree_TreeNode **PrevNode)
5663 struct MUI_NListtree_TreeNode *ParentNode;
5664 BOOL Finished = FALSE;
5666 *PrevNode = (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail;
5668 ParentNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
5669 MUIM_NListtree_GetEntry, 0, MUIV_NListtree_GetEntry_Position_Active, 0);
5671 while (ParentNode && !Finished)
5673 struct MenuListEntry *mle = (struct MenuListEntry *) ParentNode->tn_User;
5675 switch (mle->llist_EntryType)
5677 case SCAMENUTYPE_MainMenu:
5678 case SCAMENUTYPE_Menu:
5679 case SCAMENUTYPE_ToolsMenu:
5680 Finished = TRUE;
5681 break;
5683 case SCAMENUTYPE_MenuItem:
5684 case SCAMENUTYPE_Command:
5685 *PrevNode = ParentNode;
5686 ParentNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
5687 MUIM_NListtree_GetEntry, ParentNode,
5688 MUIV_NListtree_GetEntry_Position_Parent, 0);
5689 break;
5693 return ParentNode;
5696 //----------------------------------------------------------------------------
5698 static struct MUI_NListtree_TreeNode *GetParentNodeForMenuItem(struct MenuPrefsInst *inst, struct MUI_NListtree_TreeNode **PrevNode)
5700 struct MUI_NListtree_TreeNode *ParentNode;
5702 *PrevNode = (struct MUI_NListtree_TreeNode *) MUIV_NListtree_Insert_PrevNode_Tail;
5704 ParentNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
5705 MUIM_NListtree_GetEntry, 0, MUIV_NListtree_GetEntry_Position_Active, 0);
5707 while (ParentNode)
5709 struct MenuListEntry *mle = (struct MenuListEntry *) ParentNode->tn_User;
5711 if ((SCAMENUTYPE_MainMenu == mle->llist_EntryType)
5712 && (mle->llist_Flags & LLISTFLGF_MayNotHaveChildren))
5713 break;
5715 if (SCAMENUTYPE_Menu == mle->llist_EntryType)
5716 break;
5717 if (SCAMENUTYPE_ToolsMenu == mle->llist_EntryType)
5718 break;
5720 *PrevNode = ParentNode;
5721 ParentNode = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
5722 MUIM_NListtree_GetEntry, ParentNode,
5723 MUIV_NListtree_GetEntry_Position_Parent, 0);
5726 return ParentNode;
5729 //----------------------------------------------------------------------------
5731 static BOOL MayPasteOnto(struct MenuPrefsInst *inst,
5732 struct MUI_NListtree_TreeNode *tnTo, struct MUI_NListtree_TreeNode *tnFrom)
5734 const struct MenuListEntry *fteFrom = (const struct MenuListEntry *) tnFrom->tn_User;
5735 const struct MenuListEntry *fteTo = (const struct MenuListEntry *) tnTo->tn_User;
5736 BOOL MayPaste = FALSE;
5738 d1(kprintf("%s/%ld: fteTo=%08lx <%s> %ld fteFrom=%08lx <%s> %ld\n", __FUNC__, __LINE__, \
5739 fteTo, tnTo->tn_Name, fteTo->llist_EntryType, fteFrom, tnFrom->tn_Name, fteFrom->llist_EntryType));
5741 if (fteTo->llist_EntryType >= ENTRYTYPE_MAX || fteFrom->llist_EntryType >= ENTRYTYPE_MAX)
5742 return FALSE;
5744 d1(kprintf("%s/%ld: MayPaste=%ld\n", __FUNC__, __LINE__, \
5745 MayPasteIntoMatrix[fteTo->llist_EntryType][fteFrom->llist_EntryType]));
5747 if (MayPasteIntoMatrix[fteTo->llist_EntryType][fteFrom->llist_EntryType])
5749 MayPaste = TRUE;
5751 if ((SCAMENUTYPE_MainMenu == fteTo->llist_EntryType)
5752 && (SCAMENUTYPE_Menu != fteFrom->llist_EntryType)
5753 && !IsPopupMenu(inst, tnTo))
5755 // Only menus may be dropped onto Main menu
5756 MayPaste = FALSE;
5758 if ( 0 == strlen(tnTo->tn_Name) )
5760 // Nothing may be dropped onto a separator
5761 MayPaste = FALSE;
5765 return MayPaste;
5768 //----------------------------------------------------------------------------
5770 static struct MUI_NListtree_TreeNode *MayPasteBelow(struct MenuPrefsInst *inst,
5771 struct MUI_NListtree_TreeNode *tnTo, struct MUI_NListtree_TreeNode *tnFrom)
5773 const struct MenuListEntry *fteFrom = (const struct MenuListEntry *) tnFrom->tn_User;
5774 const struct MenuListEntry *fteTo = (const struct MenuListEntry *) tnTo->tn_User;
5775 struct MUI_NListtree_TreeNode *tn;
5776 BOOL Result = FALSE;
5778 d1(KPrintF("%s/%ld: START fteTo=%08lx <%s> %ld fteFrom=%08lx <%s> %ld\n", __FUNC__, __LINE__, \
5779 fteTo, tnTo->tn_Name, fteTo->llist_EntryType, fteFrom, tnFrom->tn_Name, fteFrom->llist_EntryType));
5781 do {
5782 if (fteTo->llist_EntryType >= ENTRYTYPE_MAX || fteFrom->llist_EntryType >= ENTRYTYPE_MAX)
5783 break;
5785 if (tnTo->tn_Flags & TNF_OPEN)
5787 tn = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
5788 MUIM_NListtree_GetEntry,
5789 tnTo,
5790 MUIV_NListtree_GetEntry_Position_Head,
5791 MUIV_NListtree_GetEntry_Flag_Visible);
5792 d1(KPrintF("%s/%ld: tn=%08lx\n", __FUNC__, __LINE__, tn));
5794 if (tn)
5795 break;
5798 do {
5799 tn = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
5800 MUIM_NListtree_GetEntry,
5801 tnTo,
5802 MUIV_NListtree_GetEntry_Position_Next,
5803 MUIV_NListtree_GetEntry_Flag_SameLevel | MUIV_NListtree_GetEntry_Flag_Visible);
5804 d1(KPrintF("%s/%ld: tn=%08lx\n", __FUNC__, __LINE__, tn));
5805 if (tn)
5806 break;
5808 tnTo = (struct MUI_NListtree_TreeNode *) DoMethod(inst->mpb_Objects[OBJNDX_MainListTree],
5809 MUIM_NListtree_GetEntry,
5810 tnTo,
5811 MUIV_NListtree_GetEntry_Position_Parent,
5812 MUIV_NListtree_GetEntry_Flag_Visible);
5813 d1(KPrintF("%s/%ld: tnTo=%08lx\n", __FUNC__, __LINE__, tnTo));
5815 if (tnTo)
5817 fteTo = (const struct MenuListEntry *) tnTo->tn_User;
5819 Result = MayPasteAfterMatrix[fteTo->llist_EntryType][fteFrom->llist_EntryType];
5821 } while (tnTo && !Result);
5823 if (NULL == tnTo)
5824 break;
5826 Result = MayPasteAfterMatrix[fteTo->llist_EntryType][fteFrom->llist_EntryType];
5827 } while (0);
5829 d1(KPrintF("%s/%ld: END MayPaste=%ld\n", __FUNC__, __LINE__, Result));
5831 return Result ? tnTo : NULL;
5834 //----------------------------------------------------------------------------
5836 #ifdef __amigaos4__
5838 static char *stpblk(const char *q)
5840 while (q && *q && isspace((int) *q))
5841 q++;
5843 return (char *) q;
5846 #elif !defined(__SASC) && !defined(__AROS__)
5847 // Replacement for SAS/C library functions
5849 #if !defined(__MORPHOS__)
5851 static char *stpblk(const char *q)
5853 while (q && *q && isspace((int) *q))
5854 q++;
5856 return (char *) q;
5859 static size_t stccpy(char *dest, const char *src, size_t MaxLen)
5861 size_t Count = 0;
5863 while (*src && MaxLen > 1)
5865 *dest++ = *src++;
5866 MaxLen--;
5867 Count++;
5869 *dest = '\0';
5870 Count++;
5872 return Count;
5874 #endif /*__MORPHOS__*/
5876 void exit(int x)
5878 (void) x;
5879 while (1)
5883 APTR _WBenchMsg;
5885 #endif