2 Copyright © 1995-1997 Stefan Stuntz.
3 Copyright © 2009-2010, The AROS Development Team.
10 #include <proto/alib.h>
11 #include <proto/asl.h>
12 #include <proto/muimaster.h>
13 #include <proto/muiscreen.h>
14 #include <proto/intuition.h>
18 #include "screenpanel_class.h"
19 #include "screenlist_class.h"
20 #include "mainwindow_class.h"
22 /****************************************************************************************/
24 enum { MEN_OPEN
=1, MEN_APPEND
, MEN_SAVEAS
, MEN_ABOUT
, MEN_QUIT
, MEN_LASTSAVED
, MEN_RESTORE
,MEN_MUI
};
26 struct NewMenu MainMenu
[] =
28 { NM_TITLE
, (STRPTR
)MSG_MENU_PROJECT
, 0 ,0,0,(APTR
)0 },
29 { NM_ITEM
, (STRPTR
)MSG_MENU_PROJECT_OPEN
,"O",0,0,(APTR
)MEN_OPEN
},
30 { NM_ITEM
, (STRPTR
)MSG_MENU_PROJECT_APPEND
,"P",0,0,(APTR
)MEN_APPEND
},
31 { NM_ITEM
, (STRPTR
)MSG_MENU_PROJECT_SAVEAS
,"A",0,0,(APTR
)MEN_SAVEAS
},
32 { NM_ITEM
, (STRPTR
)NM_BARLABEL
, 0 ,0,0,(APTR
)0 },
33 { NM_ITEM
, (STRPTR
)MSG_MENU_PROJECT_ABOUT
,"?",0,0,(APTR
)MEN_ABOUT
},
34 { NM_ITEM
, (STRPTR
)NM_BARLABEL
, 0 ,0,0,(APTR
)0 },
35 { NM_ITEM
, (STRPTR
)MSG_MENU_PROJECT_QUIT
,"Q",0,0,(APTR
)MEN_QUIT
},
37 { NM_TITLE
, (STRPTR
)MSG_MENU_EDIT
, 0 ,0,0,(APTR
)0 },
38 { NM_ITEM
, (STRPTR
)MSG_MENU_EDIT_LASTSAVED
,"L",0,0,(APTR
)MEN_LASTSAVED
},
39 { NM_ITEM
, (STRPTR
)MSG_MENU_EDIT_RESTORE
,"R",0,0,(APTR
)MEN_RESTORE
},
41 { NM_TITLE
, (STRPTR
)MSG_MENU_SETTINGS
, 0 ,0,0,(APTR
)0 },
42 { NM_ITEM
, (STRPTR
)MSG_MENU_SETTINGS_MUI
, 0 ,0,0,(APTR
)MEN_MUI
},
44 { NM_END
,NULL
,0,0,0,(APTR
)0 },
47 /****************************************************************************************/
49 struct MainWindow_Data
54 /****************************************************************************************/
56 IPTR
MainWindow_Finish(struct IClass
*cl
, Object
*obj
, struct MUIP_MainWindow_Finish
*msg
)
58 struct MainWindow_Data
*data
= INST_DATA(cl
, obj
);
60 DoMethod(data
->PA_Screens
, MUIM_ScreenList_Save
, PSD_FILENAME_USE
);
62 DoMethod(data
->PA_Screens
, MUIM_ScreenList_Save
, PSD_FILENAME_SAVE
);
64 ((Object
*)xget(obj
, MUIA_ApplicationObject
),
65 MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
71 /****************************************************************************************/
73 IPTR
MainWindow_About(struct IClass
*cl
, Object
*obj
, Msg msg
)
75 struct MainWindow_Data
*data
= INST_DATA(cl
, obj
);
76 Object
*app
= (Object
*)xget(obj
, MUIA_ApplicationObject
);
77 static const char AboutText
[] = "\33b\33cPSI - Public Screen Inspector\33n\n\33cVersion: %s\n\33c%s\n\n\33c%s %ld\n\33cARexx-Port: %s";
80 app
, obj
, 0, NULL
, GetStr(MSG_BUTTON_OK
), (char *)AboutText
,
81 ((char *)xget(app
, MUIA_Application_Version
)) + 10,
82 ((char *)xget(app
, MUIA_Application_Copyright
)),
83 GetStr(MSG_ABOUT_NUMBEROFSCREENS
),
84 xget(data
->PA_Screens
, MUIA_List_Entries
),
85 ((char *)xget(app
, MUIA_Application_Base
))
91 /****************************************************************************************/
93 VOID
IntuiMsgFunc(struct Hook
*hook
, struct FileRequester
*req
, struct IntuiMessage
*imsg
)
95 if (imsg
->Class
== IDCMP_REFRESHWINDOW
)
96 DoMethod(req
->fr_UserData
, MUIM_Application_CheckRefresh
);
99 /****************************************************************************************/
101 CONST_STRPTR
getfilename(Object
*win
, CONST_STRPTR title
, BOOL save
)
103 static char buf
[512];
104 struct FileRequester
*req
;
105 struct Window
*w
= NULL
;
106 static LONG left
= -1, top
= -1, width
= -1, height
= -1;
107 Object
*app
= (Object
*)xget(win
, MUIA_ApplicationObject
);
109 static struct Hook IntuiMsgHook
;
111 IntuiMsgHook
.h_Entry
= HookEntry
;
112 IntuiMsgHook
.h_SubEntry
= (HOOKFUNC
)IntuiMsgFunc
;
114 get(win
, MUIA_Window_Window
, &w
);
117 left
= w
->LeftEdge
+ w
->BorderLeft
+ 2;
118 top
= w
->TopEdge
+ w
->BorderTop
+ 2;
119 width
= w
->Width
- w
->BorderLeft
- w
->BorderRight
- 4;
120 height
= w
->Height
- w
->BorderTop
- w
->BorderBottom
- 4;
123 if ((req
= MUI_AllocAslRequestTags(ASL_FileRequest
,
125 ASLFR_TitleText
, title
,
126 ASLFR_InitialLeftEdge
, left
,
127 ASLFR_InitialTopEdge
, top
,
128 ASLFR_InitialWidth
, width
,
129 ASLFR_InitialHeight
, height
,
130 ASLFR_InitialDrawer
, "envarc:Zune",
131 ASLFR_InitialPattern
, "#?.iff",
132 ASLFR_DoSaveMode
, save
,
133 ASLFR_DoPatterns
, TRUE
,
134 ASLFR_RejectIcons
, TRUE
,
135 ASLFR_UserData
, app
,
136 ASLFR_IntuiMsgFunc
, &IntuiMsgHook
,
139 set(app
, MUIA_Application_Sleep
, TRUE
);
140 if (MUI_AslRequestTags(req
, TAG_DONE
))
145 stccpy(buf
, req
->fr_Drawer
, sizeof(buf
));
146 AddPart(buf
, req
->fr_File
, sizeof(buf
));
148 left
= req
->fr_LeftEdge
;
149 top
= req
->fr_TopEdge
;
150 width
= req
->fr_Width
;
151 height
= req
->fr_Height
;
153 MUI_FreeAslRequest(req
);
154 set(app
, MUIA_Application_Sleep
, FALSE
);
160 /****************************************************************************************/
162 IPTR
MainWindow_Open(struct IClass
*cl
, Object
*obj
, struct MUIP_MainWindow_Open
*msg
)
164 struct MainWindow_Data
*data
= INST_DATA(cl
, obj
);
165 CONST_STRPTR title
= msg
->append
? GetStr(MSG_TITLE_APPEND
) : GetStr(MSG_TITLE_OPEN
);
167 if ((name
= getfilename(obj
, title
, FALSE
)) && *name
)
169 if (!msg
->append
) DoMethod(data
->PA_Screens
, MUIM_ScreenPanel_CloseWindows
);
170 DoMethod(data
->PA_Screens
, MUIM_ScreenList_Load
, name
, msg
->append
? FALSE
: TRUE
);
176 /****************************************************************************************/
178 IPTR
MainWindow_SaveAs(struct IClass
*cl
, Object
*obj
, Msg msg
)
180 struct MainWindow_Data
*data
= INST_DATA(cl
, obj
);
181 CONST_STRPTR title
= GetStr(MSG_TITLE_SAVE
);
183 if ((name
= getfilename(obj
, title
, TRUE
)) && *name
)
185 DoMethod(data
->PA_Screens
, MUIM_ScreenList_Save
, name
);
191 /****************************************************************************************/
193 IPTR
MainWindow_Restore(struct IClass
*cl
, Object
*obj
, struct MUIP_MainWindow_Restore
*msg
)
195 struct MainWindow_Data
*data
= INST_DATA(cl
, obj
);
196 DoMethod(data
->PA_Screens
, MUIM_ScreenPanel_CloseWindows
);
197 DoMethod(data
->PA_Screens
, MUIM_ScreenList_Load
, msg
->envarc
? PSD_FILENAME_SAVE
: PSD_FILENAME_USE
, TRUE
);
202 /****************************************************************************************/
204 IPTR
MainWindow_New(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
212 if ((obj
= (Object
*)DoSuperNewTags(cl
, obj
, NULL
,
213 MUIA_Window_Title
, "PSI - Public Screen Inspector",
214 MUIA_Window_ID
, MAKE_ID('M','A','I','N'),
215 MUIA_Window_Menustrip
, strip
= MUI_MakeObject(MUIO_MenustripNM
, MainMenu
, 0),
216 WindowContents
, VGroup
,
217 Child
, PA_Screens
= NewObject(CL_ScreenPanel
->mcc_Class
, NULL
, TAG_DONE
),
218 Child
, MUI_MakeObject(MUIO_HBar
, 2),
219 Child
, HGroup
, MUIA_Group_SameSize
, TRUE
,
220 Child
, BT_Save
= MakeButton(MSG_BUTTON_SAVE
),
222 Child
, BT_Use
= MakeButton(MSG_BUTTON_USE
),
224 Child
, BT_Cancel
= MakeButton(MSG_BUTTON_CANCEL
),
227 TAG_MORE
, msg
->ops_AttrList
)))
229 struct MainWindow_Data
*data
= INST_DATA(cl
, obj
);
231 data
->PA_Screens
= PA_Screens
;
233 DoMethod(obj
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
, obj
, 2, MUIM_MainWindow_Finish
, 0);
234 DoMethod(BT_Cancel
, MUIM_Notify
, MUIA_Pressed
, FALSE
, obj
, 2, MUIM_MainWindow_Finish
, 0);
235 DoMethod(BT_Use
, MUIM_Notify
, MUIA_Pressed
, FALSE
, obj
, 2, MUIM_MainWindow_Finish
, 1);
236 DoMethod(BT_Save
, MUIM_Notify
, MUIA_Pressed
, FALSE
, obj
, 2, MUIM_MainWindow_Finish
, 2);
240 (Object
*)DoMethod(strip
, MUIM_FindUData
, MEN_ABOUT
),
241 MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
, obj
, 1, MUIM_MainWindow_About
245 (Object
*)DoMethod(strip
, MUIM_FindUData
, MEN_OPEN
),
246 MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
, obj
, 2, MUIM_MainWindow_Open
, 0
250 (Object
*)DoMethod(strip
, MUIM_FindUData
, MEN_APPEND
),
251 MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
, obj
, 2, MUIM_MainWindow_Open
, 1
255 (Object
*)DoMethod(strip
, MUIM_FindUData
, MEN_SAVEAS
),
256 MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
, obj
, 1, MUIM_MainWindow_SaveAs
260 (Object
*)DoMethod(strip
, MUIM_FindUData
, MEN_QUIT
),
261 MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
, obj
, 2, MUIM_MainWindow_Finish
, 0
265 (Object
*)DoMethod(strip
, MUIM_FindUData
, MEN_LASTSAVED
),
266 MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
, obj
, 2, MUIM_MainWindow_Restore
, 1
270 (Object
*)DoMethod(strip
, MUIM_FindUData
, MEN_RESTORE
),
271 MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
, obj
, 2, MUIM_MainWindow_Restore
, 0
275 (Object
*)DoMethod(strip
, MUIM_FindUData
, MEN_MUI
),
276 MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
, MUIV_Notify_Application
,
277 2, MUIM_Application_OpenConfigWindow
, 0
280 DoMethod(PA_Screens
, MUIM_ScreenList_Load
, PSD_FILENAME_USE
, TRUE
);
282 set(BT_Save
, MUIA_ShortHelp
, GetStr(MSG_HELP_SAVE
));
283 set(BT_Use
, MUIA_ShortHelp
, GetStr(MSG_HELP_USE
));
284 set(BT_Cancel
, MUIA_ShortHelp
, GetStr(MSG_HELP_CANCEL
));
292 /****************************************************************************************/
294 BOOPSI_DISPATCHER(IPTR
, MainWindow_Dispatcher
, cl
, obj
, msg
)
296 switch (msg
->MethodID
)
298 case OM_NEW
: return MainWindow_New (cl
,obj
,(APTR
)msg
);
299 case MUIM_MainWindow_Finish
: return MainWindow_Finish (cl
,obj
,(APTR
)msg
);
300 case MUIM_MainWindow_About
: return MainWindow_About (cl
,obj
,(APTR
)msg
);
301 case MUIM_MainWindow_Open
: return MainWindow_Open (cl
,obj
,(APTR
)msg
);
302 case MUIM_MainWindow_SaveAs
: return MainWindow_SaveAs (cl
,obj
,(APTR
)msg
);
303 case MUIM_MainWindow_Restore
: return MainWindow_Restore(cl
,obj
,(APTR
)msg
);
305 case MUIM_ScreenPanel_CloseWindows
:
306 case MUIM_ScreenPanel_Update
:
307 case MUIM_ScreenList_Find
:
309 struct MainWindow_Data
*data
= INST_DATA(cl
, obj
);
310 return DoMethodA(data
->PA_Screens
, msg
);
314 return DoSuperMethodA(cl
,obj
,msg
);
316 BOOPSI_DISPATCHER_END
318 /****************************************************************************************/
320 VOID
MainWindow_Init(VOID
)
322 CL_MainWindow
= MUI_CreateCustomClass
324 NULL
, MUIC_Window
, NULL
, sizeof(struct MainWindow_Data
), MainWindow_Dispatcher
328 /****************************************************************************************/
330 VOID
MainWindow_Exit(VOID
)
333 MUI_DeleteCustomClass(CL_MainWindow
);