2 Copyright © 2004, The AROS Development Team. All rights reserved.
3 This file is part of the SystemPrefsWindow class, which is distributed under
4 the terms of version 2.1 of the GNU Lesser General Public License.
9 #define MUIMASTER_YES_INLINE_STDARG
11 #include <proto/muimaster.h>
12 #include <proto/intuition.h>
13 #include <proto/utility.h>
14 #include <proto/locale.h>
16 #include <utility/tagitem.h>
17 #include <libraries/gadtools.h>
18 #include <libraries/mui.h>
19 #include <zune/prefseditor.h>
20 #include <zune/prefswindow.h>
22 #include "systemprefswindow.h"
23 #include "systemprefswindow_private.h"
29 #include <aros/debug.h>
31 /*** Macros *****************************************************************/
32 #define SETUP_INST_DATA struct SystemPrefsWindow_DATA *data = INST_DATA(CLASS, self)
34 /*** Locale functions *******************************************************/
35 CONST_STRPTR
MSG(struct Catalog
*catalog
, ULONG id
)
39 return GetCatalogStr(catalog
, id
, CatCompArray
[id
].cca_Str
);
43 return CatCompArray
[id
].cca_Str
;
47 #define _(id) MSG(catalog, (id))
48 #define __(id) (IPTR) MSG(catalog, (id))
50 /*** Utility functions ******************************************************/
51 Object
*MakeMenuitem(CONST_STRPTR text
)
53 CONST_STRPTR title
= NULL
,
56 if (text
!= NM_BARLABEL
&& text
[1] == '\0')
67 return (Object
*)MenuitemObject
,
68 MUIA_Menuitem_Title
, (IPTR
) title
,
70 MUIA_Menuitem_Shortcut
:
71 TAG_IGNORE
, (IPTR
) shortcut
,
75 /*** Methods ****************************************************************/
76 Object
*SystemPrefsWindow__OM_NEW
78 Class
*CLASS
, Object
*self
, struct opSet
*message
81 struct SystemPrefsWindow_DATA
*data
= NULL
;
82 struct TagItem
*tag
= NULL
;
83 struct Catalog
*catalog
= NULL
;
84 Object
*editor
, /* *importMI, *exportMI, */ *testMI
, *revertMI
,
85 *saveMI
, *useMI
, *cancelMI
;
87 tag
= FindTagItem(WindowContents
, message
->ops_AttrList
);
88 if (tag
!= NULL
) editor
= (Object
*) tag
->ti_Data
;
89 if (editor
== NULL
) return NULL
;
91 /*--- Initialize locale ------------------------------------------------*/
92 catalog
= OpenCatalogA
94 NULL
, "System/Classes/Zune/SystemPrefsWindow.catalog", NULL
97 /*--- Create object ----------------------------------------------------*/
98 self
= (Object
*) DoSuperNewTags
102 MUIA_Window_Title
, XGET(editor
, MUIA_PrefsEditor_Name
),
104 MUIA_Window_Menustrip
, (IPTR
) MenustripObject
,
105 Child
, (IPTR
) MenuObject
,
106 MUIA_Menu_Title
, __(MSG_MENU_PREFS
),
109 Child, (IPTR) importMI = MakeMenuitem(_(MSG_MENU_PREFS_IMPORT)),
110 Child, (IPTR) exportMI = MakeMenuitem(_(MSG_MENU_PREFS_EXPORT)),
111 Child, (IPTR) MakeMenuitem(NM_BARLABEL),
114 Child
, (IPTR
)(testMI
= MakeMenuitem(_(MSG_MENU_PREFS_TEST
))),
115 Child
, (IPTR
)(revertMI
= MakeMenuitem(_(MSG_MENU_PREFS_REVERT
))),
116 Child
, MakeMenuitem(NM_BARLABEL
),
117 Child
, (IPTR
)(saveMI
= MakeMenuitem(_(MSG_MENU_PREFS_SAVE
))),
118 Child
, (IPTR
)(useMI
= MakeMenuitem(_(MSG_MENU_PREFS_USE
))),
119 Child
, (IPTR
)(cancelMI
= MakeMenuitem(_(MSG_MENU_PREFS_CANCEL
))),
123 TAG_MORE
, (IPTR
) message
->ops_AttrList
129 data
= INST_DATA(CLASS
, self
);
130 data
->spwd_Catalog
= catalog
;
131 data
->spwd_Editor
= editor
;
133 /*-- Handle initial attribute values -------------------------------*/
134 SetAttrsA(self
, message
->ops_AttrList
);
136 /*-- Setup initial button states -----------------------------------*/
137 SET(self
, MUIA_PrefsWindow_Test_Disabled
, TRUE
);
138 SET(self
, MUIA_PrefsWindow_Revert_Disabled
, TRUE
);
139 SET(self
, MUIA_PrefsWindow_Save_Disabled
, TRUE
);
140 SET(self
, MUIA_PrefsWindow_Use_Disabled
, TRUE
);
142 /*-- Setup notifications -------------------------------------------*/
145 editor
, MUIM_Notify
, MUIA_PrefsEditor_Changed
, MUIV_EveryTime
,
146 (IPTR
) self
, 1, MUIM_SystemPrefsWindow_UpdateButtons
150 editor
, MUIM_Notify
, MUIA_PrefsEditor_Testing
, MUIV_EveryTime
,
151 (IPTR
) self
, 1, MUIM_SystemPrefsWindow_UpdateButtons
156 testMI
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
157 (IPTR
) self
, 1, MUIM_PrefsWindow_Test
161 revertMI
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
162 (IPTR
) self
, 1, MUIM_PrefsWindow_Revert
166 saveMI
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
167 (IPTR
) self
, 1, MUIM_PrefsWindow_Save
171 useMI
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
172 (IPTR
) self
, 1, MUIM_PrefsWindow_Use
176 cancelMI
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
177 (IPTR
) self
, 1, MUIM_PrefsWindow_Cancel
182 if (catalog
!= NULL
) CloseCatalog(catalog
);
188 IPTR SystemPrefsWindow__OM_DISPOSE
190 Class
*CLASS
, Object
*self
, Msg message
195 if (data
->spwd_Catalog
!= NULL
) CloseCatalog(data
->spwd_Catalog
);
197 return DoSuperMethodA(CLASS
, self
, message
);
200 IPTR SystemPrefsWindow__MUIM_SystemPrefsWindow_UpdateButtons
202 Class
*CLASS
, Object
*self
, Msg message
207 BOOL changed
= XGET(data
->spwd_Editor
, MUIA_PrefsEditor_Changed
);
208 BOOL testing
= XGET(data
->spwd_Editor
, MUIA_PrefsEditor_Testing
);
210 SET(self
, MUIA_PrefsWindow_Test_Disabled
, !changed
);
211 SET(self
, MUIA_PrefsWindow_Revert_Disabled
, !testing
);
213 SET(self
, MUIA_PrefsWindow_Save_Disabled
, !(changed
|| testing
));
214 SET(self
, MUIA_PrefsWindow_Use_Disabled
, !(changed
|| testing
));
219 IPTR SystemPrefsWindow__OM_SET
221 Class
*CLASS
, Object
*self
, struct opSet
*message
225 const struct TagItem
*tstate
= message
->ops_AttrList
;
228 while ((tag
= NextTagItem(&tstate
)) != NULL
)
232 case MUIA_PrefsWindow_Save_Disabled
:
233 if (!XGET(data
->spwd_Editor
, MUIA_PrefsEditor_CanSave
))
235 tag
->ti_Tag
= TAG_IGNORE
;
239 case MUIA_PrefsWindow_Test_Disabled
:
240 case MUIA_PrefsWindow_Revert_Disabled
:
241 if (!XGET(data
->spwd_Editor
, MUIA_PrefsEditor_CanTest
))
243 tag
->ti_Tag
= TAG_IGNORE
;
249 return DoSuperMethodA(CLASS
, self
, (Msg
) message
);
252 IPTR SystemPrefsWindow__MUIM_PrefsWindow_Test
254 Class
*CLASS
, Object
*self
, Msg message
259 if (!DoMethod(data
->spwd_Editor
, MUIM_PrefsEditor_Test
))
261 // FIXME: error reporting
268 IPTR SystemPrefsWindow__MUIM_PrefsWindow_Revert
270 Class
*CLASS
, Object
*self
, Msg message
275 if (!DoMethod(data
->spwd_Editor
, MUIM_PrefsEditor_Revert
))
277 // FIXME: error reporting
284 IPTR SystemPrefsWindow__MUIM_PrefsWindow_Save
286 Class
*CLASS
, Object
*self
, Msg message
291 if (!DoMethod(data
->spwd_Editor
, MUIM_PrefsEditor_Save
))
293 // FIXME: error reporting
299 _app(self
), MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
305 IPTR SystemPrefsWindow__MUIM_PrefsWindow_Use
307 Class
*CLASS
, Object
*self
, Msg message
312 if (!DoMethod(data
->spwd_Editor
, MUIM_PrefsEditor_Use
))
314 // FIXME: error reporting
320 _app(self
), MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
326 IPTR SystemPrefsWindow__MUIM_PrefsWindow_Cancel
328 Class
*CLASS
, Object
*self
, Msg message
333 if (!DoMethod(data
->spwd_Editor
, MUIM_PrefsEditor_Cancel
))
335 // FIXME: error reporting
341 _app(self
), MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit