2 Copyright 2003-2008, The AROS Development Team. All rights reserved.
6 // #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/types.h>
9 #include <utility/tagitem.h>
10 #include <libraries/asl.h>
11 #include <libraries/mui.h>
12 #include <prefs/locale.h>
13 #include <prefs/prefhdr.h>
15 #include <zune/customclasses.h>
16 #include <zune/prefseditor.h>
18 #include <proto/exec.h>
19 #include <proto/intuition.h>
20 #include <proto/utility.h>
21 #include <proto/muimaster.h>
22 #include <proto/dos.h>
23 #include <proto/iffparse.h>
29 #include <aros/debug.h>
32 #include "page_country.h"
33 #include "registertab.h"
35 /*** String Data ************************************************************/
37 /*** Instance Data **********************************************************/
39 typedef struct MUI_CountryPic
41 char *strings_country
;
46 struct MUI_CountryData
52 unsigned int nr_countries
;
57 struct MUI_CustomClass
*Country_CLASS
;
59 /*** Helpers *****************************************************************/
61 #define MAX_COUNTRY_LEN 256
63 /*******************************
64 * prepare for fill_country_list
65 *******************************/
67 STATIC VOID
init_country_list(struct MUI_CountryData
*data
) {
69 struct CountryEntry
*entry
;
72 char filename
[MAX_COUNTRY_LEN
];
83 ForeachNode(&country_list
, entry
)
88 D(bug("[country class] nr of countries: %d\n",data
->nr_countries
));
90 data
->pic
=AllocVec(sizeof(struct MUI_CountryPic
*) * (data
->nr_countries
+1),MEMF_CLEAR
);
93 ForeachNode(&country_list
, entry
)
95 data
->pic
[i
]=AllocVec(sizeof(struct MUI_CountryPic
),MEMF_CLEAR
);
97 snprintf(filename
,MAX_COUNTRY_LEN
-1,
98 "LOCALE:Flags/Countries/%s",entry
->lve
.realname
);
100 if ((lock
= Lock(filename
, ACCESS_READ
)) != NULL
) {
101 data
->pic
[i
]->pic
=(APTR
) MUI_NewObject("Dtpic.mui",
102 MUIA_Dtpic_Name
,(ULONG
) filename
,
106 if(!data
->pic
[i
]->pic
)
108 D(bug("[country class] Picture %s failed to load\n",filename
));
112 D(bug("[country class] Picture %s loaded: %lx\n",filename
,data
->pic
[i
]->pic
));
116 if(data
->pic
[i
]->pic
)
118 data
->pic
[i
]->list_pic
=(Object
*) DoMethod(data
->child
,
119 MUIM_List_CreateImage
,data
->pic
[i
]->pic
,
124 data
->pic
[i
]->list_pic
=NULL
; /* should be ok */
125 D(bug("ERROR: [country class] data->pic[%d]->pic is NULL!\n",i
));
127 data
->pic
[i
]->strings_country
=AllocVec(sizeof(char) * MAX_COUNTRY_LEN
,MEMF_CLEAR
);
128 snprintf(data
->pic
[i
]->strings_country
,
129 MAX_COUNTRY_LEN
,"\33O[%08lx] %s",
130 (long unsigned int) data
->pic
[i
]->list_pic
,
131 entry
->lve
.name
); /* 64-bit !? */
133 DoMethod(data
->child
,
134 MUIM_List_InsertSingle
, data
->pic
[i
]->strings_country
,
135 MUIV_List_Insert_Bottom
);
140 /* we did remember that */
141 nnset(data
->child
, MUIA_List_Active
, data
->active
);
144 /*** Methods ****************************************************************
148 Object
*Country_New(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
150 struct MUI_CountryData
*data
;
151 struct TagItem
*tstate
, *tag
;
153 D(bug("[country class] Country Class New\n"));
156 * country flags are at the moment 17 pixels high
157 * MUIA_List_MinLineHeight, 18 leaves at least one
158 * pixel space between the images
159 * If images ever get bigger, this should be
163 obj
= (Object
*) DoSuperNewTags(
166 MUIA_List_MinLineHeight
, 18,
172 D(bug("ERROR: [country class] DoSuperNewTags failed!\n"));
176 data
= INST_DATA(cl
, obj
);
178 tstate
=((struct opSet
*)msg
)->ops_AttrList
;
179 while ((tag
= (struct TagItem
*) NextTagItem((APTR
) &tstate
)))
184 data
->prefs
= (Object
*) tag
->ti_Data
;
193 DoMethod(obj
, MUIM_Notify
, MUIA_List_Active
, MUIV_EveryTime
, (IPTR
) data
->prefs
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
);
199 /**************************************************************
200 * seems like you can only call CreateImage after the list
201 * is setup, which is quite late. So we do it, after
202 * the list is shown. Nice? Not really. Maybe I did
203 * not understand, why this needs to be.
204 **************************************************************/
205 static IPTR
Country_Fill(struct IClass
*cl
, Object
*obj
, struct MUIP_Show
*msg
)
207 struct MUI_CountryData
*data
= INST_DATA(cl
, obj
);
211 ret
=DoSuperMethodA(cl
, obj
, (Msg
)msg
);
213 init_country_list(data
);
218 /******************************************
219 * According to the MUI docs, you should
220 * call DeleteImage and Dispose during
222 ******************************************/
223 static IPTR
Country_Cleanup(struct IClass
*cl
, Object
*obj
, struct MUIP_Cleanup
*msg
)
225 struct MUI_CountryData
*data
= INST_DATA(cl
, obj
);
228 D(bug("[country class] Country_Cleanup\n"));
232 for(i
=0; i
<data
->nr_countries
; i
++)
236 if(data
->pic
[i
]->list_pic
)
238 DoMethod(data
->child
,
239 MUIM_List_DeleteImage
,data
->pic
[i
]->list_pic
);
240 data
->pic
[i
]->list_pic
=NULL
;
242 if(data
->pic
[i
]->pic
)
244 DoMethod(data
->pic
[i
]->pic
,OM_DISPOSE
);
245 data
->pic
[i
]->pic
=NULL
;
252 D(bug("[country class] Country_Cleanup and !data->filled!?\n"));
255 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
258 static IPTR
Country_Dispose(struct IClass
*cl
, Object
*obj
, Msg msg
)
260 struct MUI_CountryData
*data
= INST_DATA(cl
, obj
);
263 D(bug("[country class] Country_Dispose\n"));
266 return DoSuperMethodA(cl
, obj
, msg
);
268 for(i
=0;i
<data
->nr_countries
;i
++)
272 if(data
->pic
[i
]->strings_country
)
274 FreeVec(data
->pic
[i
]->strings_country
);
276 FreeVec(data
->pic
[i
]);
280 return DoSuperMethodA(cl
, obj
, msg
);
283 /*** Get ******************************************************************/
284 static IPTR
Country_Get(struct IClass
*cl
, Object
*obj
, struct opGet
*msg
)
286 struct MUI_CountryData
*data
= INST_DATA(cl
, obj
);
287 struct CountryEntry
*entry
;
293 switch (msg
->opg_AttrID
)
296 get(data
->child
, MUIA_List_Active
, &nr
);
299 ForeachNode(&country_list
, entry
) {
302 rc
= (ULONG
)entry
->lve
.realname
;
309 *msg
->opg_Storage
= 0;
315 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
318 *msg
->opg_Storage
= rc
;
322 /*** Set ******************************************************************/
323 static IPTR
Country_Set(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
325 struct MUI_CountryData
*data
= INST_DATA(cl
, obj
);
326 struct TagItem
*tstate
, *tag
;
327 struct CountryEntry
*entry
;
332 tstate
= msg
->ops_AttrList
;
335 while ((tag
= (struct TagItem
*) NextTagItem((APTR
) &tstate
)))
343 ForeachNode(&country_list
, entry
) {
344 if(!stricmp(entry
->lve
.realname
, (STRPTR
)tag
->ti_Data
))
353 D(bug("ERROR: [country class] could not find >%s< !?\n",tag
->ti_Data
));
359 nnset(data
->child
, MUIA_List_Active
, nr
);
371 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
377 MUI_Redraw(obj
, MADF_DRAWOBJECT
);
383 /*** Setup ******************************************************************/
385 BOOPSI_DISPATCHER(IPTR
, Country_Dispatcher
, cl
, obj
, msg
)
387 switch (msg
->MethodID
)
389 case OM_NEW
: return (IPTR
) Country_New(cl
, obj
, (struct opSet
*)msg
);
390 case MUIM_Show
: return Country_Fill(cl
, obj
, (struct MUIP_Show
*)msg
);
391 case OM_GET
: return Country_Get(cl
, obj
, (APTR
)msg
);
392 case OM_SET
: return Country_Set(cl
, obj
, (APTR
)msg
);
393 case MUIM_Cleanup
: return Country_Cleanup(cl
, obj
, (struct MUIP_Cleanup
*)msg
);
394 case OM_DISPOSE
: return Country_Dispose(cl
, obj
, msg
);
397 return DoSuperMethodA(cl
, obj
, msg
);
399 BOOPSI_DISPATCHER_END
404 const struct __MUIBuiltinClass _MUIP_Country_desc
=
408 sizeof(struct MUI_CountryData
),
409 (void*)Country_Dispatcher
414 Country_CLASS
=MUI_CreateCustomClass(NULL
,MUIC_List
,NULL
,sizeof(struct MUI_CountryData
), &Country_Dispatcher
);
421 MUI_DeleteCustomClass(Country_CLASS
);