2 ** OpenURL - MUI preferences for openurl.library
4 ** Written by Troels Walsted Hansen <troels@thule.no>
5 ** Placed in the public domain.
8 ** - Alfonso Ranieri <alforan@tin.it>
9 ** - Stefan Kost <ensonic@sonicpulse.de>
11 ** Ported to OS4 by Alexandre Balaban <alexandre@balaban.name>
13 ** Handle the all thing
18 #define CATCOMP_NUMBERS
20 #include "OpenURL_rev.h"
21 #include "libraries/openurl.h"
23 /**************************************************************************/
32 struct DiskObject
*icon
;
35 /**************************************************************************/
40 static struct NewMenu menu
[] =
42 MTITLE(MSG_Menu_Project
),
43 MITEM(MSG_Menu_About
),
44 MITEM(MSG_Menu_AboutMUI
),
50 MTITLE(MSG_Menu_Prefs
),
54 MITEM(MSG_Menu_LastSaveds
),
55 MITEM(MSG_Menu_Restore
),
56 MITEM(MSG_Menu_Defaults
),
69 static STRPTR usedClasses
[] =
81 mNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
83 Object
*strip
, *win
, *pens
;
85 if (obj
= (Object
*)DoSuperNew(cl
,obj
,
86 MUIA_Application_Title
, PRG
,
87 MUIA_Application_Version
, "$VER: "PRGNAME
,
88 MUIA_Application_Author
, APPAUTHOR
,
89 MUIA_Application_Copyright
, getString(MSG_App_Copyright
),
90 MUIA_Application_Description
, getString(MSG_App_Description
),
91 MUIA_Application_HelpFile
, APPHELP
,
92 MUIA_Application_Base
, APPBASENAME
,
93 MUIA_Application_Menustrip
, strip
= MUI_MakeObject(MUIO_MenustripNM
,(ULONG
)menu
,MUIO_MenustripNM_CommandKeyCheck
),
94 MUIA_Application_UsedClasses
, usedClasses
,
95 MUIA_Application_Window
, win
= winObject
, End
,
96 MUIA_Application_Window
, pens
= pensObject
, End
,
97 TAG_MORE
,msg
->ops_AttrList
))
99 struct data
*data
= INST_DATA(cl
,obj
);
108 if (data
->icon
= GetDiskObject("PROGDIR:OpenURL"))
109 superset(cl
,obj
,MUIA_Application_DiskObject
,data
->icon
);
115 DoMethod(pens
,MUIM_Notify
,MUIA_Window_CloseRequest
,TRUE
,MUIV_Notify_Self
,3,MUIM_Set
,MUIA_Window_Open
,FALSE
);
119 DoMethod((Object
*)DoMethod(strip
,MUIM_FindUData
,MSG_Menu_About
),MUIM_Notify
,MUIA_Menuitem_Trigger
,MUIV_EveryTime
,(ULONG
)obj
,1,MUIM_App_About
);
120 DoMethod((Object
*)DoMethod(strip
,MUIM_FindUData
,MSG_Menu_AboutMUI
),MUIM_Notify
,MUIA_Menuitem_Trigger
,MUIV_EveryTime
,(ULONG
)obj
,2,MUIM_Application_AboutMUI
,(ULONG
)win
);
121 DoMethod((Object
*)DoMethod(strip
,MUIM_FindUData
,MSG_Menu_Hide
),MUIM_Notify
,MUIA_Menuitem_Trigger
,MUIV_EveryTime
,(ULONG
)obj
,3,MUIM_Set
,MUIA_Application_Iconified
,TRUE
);
122 DoMethod((Object
*)DoMethod(strip
,MUIM_FindUData
,MSG_Menu_Quit
),MUIM_Notify
,MUIA_Menuitem_Trigger
,MUIV_EveryTime
,(ULONG
)obj
,2,MUIM_Application_ReturnID
,MUIV_Application_ReturnID_Quit
);
124 DoMethod((Object
*)DoMethod(strip
,MUIM_FindUData
,MSG_Menu_Save
),MUIM_Notify
,MUIA_Menuitem_Trigger
,MUIV_EveryTime
,(ULONG
)win
,2,MUIM_Win_StorePrefs
,MUIV_Win_StorePrefs_Save
);
125 DoMethod((Object
*)DoMethod(strip
,MUIM_FindUData
,MSG_Menu_Use
),MUIM_Notify
,MUIA_Menuitem_Trigger
,MUIV_EveryTime
,(ULONG
)win
,2,MUIM_Win_StorePrefs
,MUIV_Win_StorePrefs_Use
);
126 DoMethod((Object
*)DoMethod(strip
,MUIM_FindUData
,MSG_Menu_LastSaveds
),MUIM_Notify
,MUIA_Menuitem_Trigger
,MUIV_EveryTime
,(ULONG
)obj
,2,MUIM_App_GetPrefs
,MUIV_App_GetPrefs_LastSaveds
);
127 DoMethod((Object
*)DoMethod(strip
,MUIM_FindUData
,MSG_Menu_Restore
),MUIM_Notify
,MUIA_Menuitem_Trigger
,MUIV_EveryTime
,(ULONG
)obj
,2,MUIM_App_GetPrefs
,MUIV_App_GetPrefs_Restore
);
128 DoMethod((Object
*)DoMethod(strip
,MUIM_FindUData
,MSG_Menu_Defaults
),MUIM_Notify
,MUIA_Menuitem_Trigger
,MUIV_EveryTime
,(ULONG
)obj
,2,MUIM_App_GetPrefs
,MUIV_App_GetPrefs_Defaults
);
129 DoMethod((Object
*)DoMethod(strip
,MUIM_FindUData
,MSG_Menu_MUI
),MUIM_Notify
,MUIA_Menuitem_Trigger
,MUIV_EveryTime
,(ULONG
)obj
,2,MUIM_Application_OpenConfigWindow
,0);
130 DoMethod((Object
*)DoMethod(strip
,MUIM_FindUData
,MSG_Menu_Pens
),MUIM_Notify
,MUIA_Menuitem_Trigger
,MUIV_EveryTime
,(ULONG
)pens
,3,MUIM_Set
,MUIA_Window_Open
,TRUE
);
133 DoSuperMethod(cl
,obj
,MUIM_Notify
,MUIA_Application_MenuHelp
,MUIV_EveryTime
,MUIV_Notify_Self
,
134 5,MUIM_Application_ShowHelp
,(ULONG
)win
,(ULONG
)APPHELP
,(ULONG
)"MENUS",0);
137 ** Setup default lamps pens
139 DoMethod(pens
,MUIM_Pens_Change
);
142 ** Load list formats and pens prefs
144 DoSuperMethod(cl
,obj
,MUIM_Application_Load
,(ULONG
)MUIV_Application_Load_ENV
);
147 ** Try to get OpenURL prefs and open window
149 if (!DoMethod(win
,MUIM_Win_GetPrefs
,MUIV_Win_GetPrefs_Restore
) || !openWindow(obj
,win
))
151 CoerceMethod(cl
,obj
,OM_DISPOSE
);
160 /***********************************************************************/
163 mDispose(struct IClass
*cl
,Object
*obj
,Msg msg
)
165 struct data
*data
= INST_DATA(cl
,obj
);
166 struct DiskObject
*icon
= data
->icon
;
170 ** Because of users hate an app that saves on disc
171 ** at any exit, we check if something changed
173 if (DoMethod(data
->win
,MUIM_App_CheckSave
) || DoMethod(data
->pens
,MUIM_App_CheckSave
))
175 DoSuperMethod(cl
,obj
,MUIM_Application_Save
,(ULONG
)MUIV_Application_Save_ENV
);
176 DoSuperMethod(cl
,obj
,MUIM_Application_Save
,(ULONG
)MUIV_Application_Save_ENVARC
);
179 res
= DoSuperMethodA(cl
,obj
,msg
);
181 if (icon
) FreeDiskObject(icon
);
186 /***********************************************************************/
188 ** We just care of pens
192 mSets(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
194 struct MUI_PenSpec
**specs
;
196 if (specs
= (struct MUI_PenSpec
**)GetTagData(MUIA_App_Pens
,(ULONG
)NULL
,msg
->ops_AttrList
))
198 struct data
*data
= INST_DATA(cl
,obj
);
200 set(data
->win
,MUIA_App_Pens
,specs
);
203 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
206 /***********************************************************************/
209 findWinObjByAttr(Object
*app
,ULONG attr
,ULONG val
)
211 struct List
*winlist
;
215 /* return the window object which supports OM_GET on attr, and
216 whose value of attr == val */
218 get(app
,MUIA_Application_WindowList
,&winlist
);
219 state
= winlist
->lh_Head
;
221 while(obj
= NextObject(&state
))
225 if (get(obj
,attr
,&value
) && (value
==val
)) break;
231 /**************************************************************************/
234 mOpenWin(struct IClass
*cl
,Object
*obj
,struct MUIP_App_OpenWin
*msg
)
236 Object
*win
= findWinObjByAttr(obj
,msg
->IDAttr
,msg
->IDVal
);
240 set(obj
,MUIA_Application_Sleep
,TRUE
);
242 win
= NewObject(msg
->Class
, NULL
,
243 msg
->IDAttr
, msg
->IDVal
,
244 TAG_MORE
, &msg
->InitAttrs
);
246 if (win
) DoMethod(obj
,OM_ADDMEMBER
,(ULONG
)win
);
248 set(obj
,MUIA_Application_Sleep
,FALSE
);
251 return openWindow(obj
,win
);
254 /**************************************************************************/
257 mCloseWin(struct IClass
*cl
,Object
*obj
,struct MUIP_App_CloseWin
*msg
)
259 struct data
*data
= INST_DATA(cl
,obj
);
260 Object
*win
= findWinObjByAttr(obj
,msg
->IDAttr
,msg
->IDVal
);
264 set(win
,MUIA_Window_Open
,FALSE
);
265 DoMethod(obj
,OM_REMMEMBER
,(ULONG
)win
);
266 MUI_DisposeObject(win
);
268 if (((struct URL_Node
*)msg
->IDVal
)->Flags
& UNF_NEW
)
269 DoMethod(data
->win
,MUIM_Win_Delete
,msg
->IDVal
);
275 /**************************************************************************/
278 mOpenConfigWindow(struct IClass
*cl
,Object
*obj
,Msg msg
)
282 set(obj
,MUIA_Application_Sleep
,TRUE
);
283 res
= DoSuperMethodA(cl
,obj
,(Msg
)msg
);
284 set(obj
,MUIA_Application_Sleep
,FALSE
);
289 /***********************************************************************/
292 mDisposeWin(struct IClass
*cl
,Object
*obj
,struct MUIP_App_DisposeWin
*msg
)
294 struct data
*data
= INST_DATA(cl
,obj
);
295 Object
*win
= msg
->win
;
297 set(win
,MUIA_Window_Open
,FALSE
);
298 DoSuperMethod(cl
,obj
,OM_REMMEMBER
,(ULONG
)win
);
299 MUI_DisposeObject(win
);
301 if (win
==data
->about
) data
->about
= NULL
;
302 else if (win
==data
->aboutMUI
) data
->aboutMUI
= NULL
;
307 /***********************************************************************/
310 mAboutMUI(struct IClass
*cl
,Object
*obj
, Msg msg
)
312 struct data
*data
= INST_DATA(cl
,obj
);
314 superset(cl
,obj
,MUIA_Application_Sleep
,TRUE
);
318 if (data
->aboutMUI
= AboutmuiObject
,
319 MUIA_HelpNode
, "MUI",
320 MUIA_Aboutmui_Application
, obj
,
321 MUIA_Window_RefWindow
, data
->win
,
323 DoMethod(data
->aboutMUI
,MUIM_Notify
,MUIA_Window_CloseRequest
,TRUE
,(ULONG
)obj
,5,
324 MUIM_Application_PushMethod
,(ULONG
)obj
,2,MUIM_App_DisposeWin
,(ULONG
)data
->aboutMUI
);
327 openWindow(obj
,data
->aboutMUI
);
329 superset(cl
,obj
,MUIA_Application_Sleep
,FALSE
);
334 /***********************************************************************/
337 mAbout(struct IClass
*cl
,Object
*obj
,Msg msg
)
339 struct data
*data
= INST_DATA(cl
,obj
);
341 superset(cl
,obj
,MUIA_Application_Sleep
,TRUE
);
345 if (g_aboutClass
|| initAboutClass())
347 if (data
->about
= aboutObject
,
348 MUIA_Aboutmui_Application
, obj
,
349 MUIA_Window_RefWindow
, data
->win
,
352 DoSuperMethod(cl
,obj
,OM_ADDMEMBER
,(ULONG
)data
->about
);
353 DoMethod(data
->about
,MUIM_Notify
,MUIA_Window_CloseRequest
,TRUE
,(ULONG
)obj
,5,
354 MUIM_Application_PushMethod
,(ULONG
)obj
,2,MUIM_App_DisposeWin
,(ULONG
)data
->about
);
359 openWindow(obj
,data
->about
);
361 superset(cl
,obj
,MUIA_Application_Sleep
,FALSE
);
366 /***********************************************************************/
369 closeAllWindows(Object
*app
)
381 get(app
,MUIA_Application_WindowList
,&list
);
382 mstate
= (Object
*)list
->lh_Head
;
384 while (win
= NextObject(&mstate
))
388 get(win
,MUIA_App_IsSubWin
,&ok
);
391 set(win
,MUIA_Window_Open
,FALSE
);
392 DoMethod(app
,OM_REMMEMBER
,(ULONG
)win
);
393 MUI_DisposeObject(win
);
403 /***********************************************************************/
406 mGetPrefs(struct IClass
*cl
,Object
*obj
,struct MUIP_App_GetPrefs
*msg
)
408 struct data
*data
= INST_DATA(cl
,obj
);
410 set(obj
,MUIA_Application_Sleep
,TRUE
);
412 closeAllWindows(obj
);
413 DoMethod(data
->win
,MUIM_Win_GetPrefs
,msg
->mode
);
415 set(obj
,MUIA_Application_Sleep
,FALSE
);
420 /***********************************************************************/
426 switch (msg
->MethodID
)
428 case OM_NEW
: return mNew(cl
,obj
,(APTR
)msg
);
429 case OM_DISPOSE
: return mDispose(cl
,obj
,(APTR
)msg
);
430 case OM_SET
: return mSets(cl
,obj
,(APTR
)msg
);
432 case MUIM_Application_AboutMUI
: return mAboutMUI(cl
,obj
,(APTR
)msg
);
433 case MUIM_Application_OpenConfigWindow
: return mOpenConfigWindow(cl
,obj
,(APTR
)msg
);
435 case MUIM_App_OpenWin
: return mOpenWin(cl
,obj
,(APTR
)msg
);
436 case MUIM_App_CloseWin
: return mCloseWin(cl
,obj
,(APTR
)msg
);
437 case MUIM_App_About
: return mAbout(cl
,obj
,(APTR
)msg
);
438 case MUIM_App_DisposeWin
: return mDisposeWin(cl
,obj
,(APTR
)msg
);
439 case MUIM_App_GetPrefs
: return mGetPrefs(cl
,obj
,(APTR
)msg
);
441 default: return DoSuperMethodA(cl
,obj
,msg
);
445 M_DISPEND(dispatcher
)
447 /**************************************************************************/
452 if (g_appClass
= MUI_CreateCustomClass(NULL
,MUIC_Application
,NULL
,sizeof(struct data
),DISP(dispatcher
)))
454 localizeNewMenu(menu
);
462 /**************************************************************************/
465 disposeAppClass(void)
467 if (g_appClass
) MUI_DeleteCustomClass(g_appClass
);
470 /**************************************************************************/