2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
9 /*********************************************************************************************/
14 /*********************************************************************************************/
16 static struct Gadget
*gadlist
, *countrygad
, *gad
;
17 static struct Hook lvhook
;
18 static WORD domleft
, domtop
, domwidth
, domheight
;
19 static WORD max_flagw
, max_flagh
;
20 static WORD active_country
= 0;
21 static BOOL page_active
;
23 /*********************************************************************************************/
25 static LONG
country_init(void)
27 struct CountryEntry
*entry
;
28 static UBYTE filename
[256];
30 if (!DataTypesBase
) return TRUE
;
32 ForeachNode(&country_list
, entry
)
34 strcpy(filename
, "LOCALE:Flags/Countries");
35 AddPart(filename
, entry
->lve
.realname
, 256);
37 entry
->dto
= NewDTObject(filename
, DTA_GroupID
, GID_PICTURE
,
38 OBP_Precision
, PRECISION_IMAGE
,
39 PDTA_Screen
, (IPTR
)scr
,
41 PDTA_FreeSourceBitMap
, TRUE
,
42 PDTA_DestMode
, PMODE_V43
,
43 PDTA_UseFriendBitMap
, TRUE
,
50 DoMethod(entry
->dto
, DTM_PROCLAYOUT
, (IPTR
) NULL
, 1);
52 GetDTAttrs(entry
->dto
, PDTA_DestBitMap
, (IPTR
) &entry
->flagbm
, TAG_DONE
);
55 GetDTAttrs(entry
->dto
, PDTA_BitMap
, (IPTR
) &entry
->flagbm
, TAG_DONE
);
58 GetDTAttrs(entry
->dto
, DTA_NominalHoriz
, (IPTR
) &val
, TAG_DONE
);
59 entry
->flagw
= (WORD
)val
;
61 GetDTAttrs(entry
->dto
, DTA_NominalVert
, (IPTR
) &val
, TAG_DONE
);
62 entry
->flagh
= (WORD
)val
;
66 if (entry
->flagw
> max_flagw
) max_flagw
= entry
->flagw
;
67 if (entry
->flagh
> max_flagh
) max_flagh
= entry
->flagh
;
69 if (GetBitMapAttr(scr
->RastPort
.BitMap
, BMA_DEPTH
) >= 15)
73 bm
= AllocBitMap(entry
->flagw
,
75 GetBitMapAttr(scr
->RastPort
.BitMap
, BMA_DEPTH
),
76 BMF_MINPLANES
| BMF_INTERLEAVED
,
77 scr
->RastPort
.BitMap
);
81 BltBitMap(entry
->flagbm
, 0, 0, bm
, 0, 0, entry
->flagw
, entry
->flagh
, 192, 255, 0);
82 DisposeDTObject(entry
->dto
);
91 DisposeDTObject(entry
->dto
);
95 } /* if (entry->dto) */
97 } /* ForeachNode(&country_list, entry) */
102 /*********************************************************************************************/
104 static IPTR
LVRenderHook(struct Hook
*hook
, struct Node
*node
, struct LVDrawMsg
*msg
)
108 if (msg
->lvdm_MethodID
== LV_DRAW
)
110 struct DrawInfo
*dri
= msg
->lvdm_DrawInfo
;
111 struct RastPort
*rp
= msg
->lvdm_RastPort
;
113 WORD min_x
= msg
->lvdm_Bounds
.MinX
;
114 WORD min_y
= msg
->lvdm_Bounds
.MinY
;
115 WORD max_x
= msg
->lvdm_Bounds
.MaxX
;
116 WORD max_y
= msg
->lvdm_Bounds
.MaxY
;
118 UWORD erasepen
= BACKGROUNDPEN
;
122 switch (msg
->lvdm_State
)
125 case LVR_SELECTEDDISABLED
:
130 case LVR_NORMALDISABLED
:
133 struct TextExtent te
;
134 struct CountryEntry
*ce
;
137 SetAPen(rp
, dri
->dri_Pens
[erasepen
]);
138 RectFill(rp
, min_x
, min_y
, max_x
, max_y
);
140 ce
= (struct CountryEntry
*)node
;
143 BltBitMapRastPort(ce
->flagbm
,
148 (min_y
+ max_y
+ 1 - ce
->flagh
) / 2,
154 if (max_flagh
) min_x
+= max_flagw
+ 3;
156 numfit
= TextFit(rp
, node
->ln_Name
, strlen(node
->ln_Name
),
157 &te
, NULL
, 1, max_x
- min_x
+ 1, max_y
- min_y
+ 1);
159 SetAPen(rp
, dri
->dri_Pens
[TEXTPEN
]);
162 Move(rp
, min_x
, (min_y
+ max_y
+ 1 - rp
->Font
->tf_YSize
) / 2 + rp
->Font
->tf_Baseline
);
163 Text(rp
, node
->ln_Name
, numfit
);
173 retval
= LVCB_UNKNOWN
;
179 /*********************************************************************************************/
181 static LONG
country_makegadgets(void)
186 gad
= CreateContext(&gadlist
);
188 ng
.ng_LeftEdge
= domleft
;
189 ng
.ng_TopEdge
= domtop
;
190 ng
.ng_Width
= domwidth
;
191 ng
.ng_Height
= domheight
;
192 ng
.ng_GadgetText
= NULL
;
194 ng
.ng_GadgetID
= MSG_GAD_TAB_COUNTRY
;
196 ng
.ng_VisualInfo
= vi
;
198 itemheight
= dri
->dri_Font
->tf_YSize
;
199 if (max_flagh
> itemheight
) itemheight
= max_flagh
;
202 lvhook
.h_Entry
= HookEntry
;
203 lvhook
.h_SubEntry
= LVRenderHook
;
205 gad
= countrygad
= CreateGadget(LISTVIEW_KIND
, gad
, &ng
, GTLV_Labels
, (IPTR
)&country_list
,
206 GTLV_ShowSelected
, (IPTR
) NULL
,
207 GTLV_Selected
, active_country
,
208 GTLV_MakeVisible
, active_country
,
209 GTLV_ItemHeight
, itemheight
,
210 GTLV_CallBack
, (IPTR
)&lvhook
,
214 return gad
? TRUE
: FALSE
;
217 /*********************************************************************************************/
219 static void country_cleanup(void)
221 struct CountryEntry
*entry
;
223 ForeachNode(&country_list
, entry
)
227 DisposeDTObject(entry
->dto
);
229 else if (entry
->flagbm
)
231 FreeBitMap(entry
->flagbm
);
235 if (gadlist
) FreeGadgets(gadlist
);
239 /*********************************************************************************************/
241 static LONG
country_input(struct IntuiMessage
*msg
)
243 struct CountryEntry
*entry
;
246 if (msg
->Class
== IDCMP_GADGETUP
)
248 struct Gadget
*gad
= (struct Gadget
*)msg
->IAddress
;
250 switch(gad
->GadgetID
)
252 case MSG_GAD_TAB_COUNTRY
:
253 if ((entry
= (struct CountryEntry
*)FindListNode(&country_list
, msg
->Code
)))
255 if (active_country
!= msg
->Code
)
257 active_country
= msg
->Code
;
258 strcpy(localeprefs
.lp_CountryName
, entry
->lve
.realname
);
259 LoadCountry(localeprefs
.lp_CountryName
, &localeprefs
.lp_CountryData
);
265 } /* switch(gad->GadgetID) */
267 } /* if (msg->Class == IDCMP_GADGETUP) */
268 else if (msg
->Class
== IDCMP_RAWKEY
)
272 case RAWKEY_NM_WHEEL_UP
:
273 ScrollListview(countrygad
, -1);
276 case RAWKEY_NM_WHEEL_DOWN
:
277 ScrollListview(countrygad
, 1);
285 /*********************************************************************************************/
287 static void country_prefs_changed(void)
289 struct CountryEntry
*entry
;
294 ForeachNode(&country_list
, entry
)
296 if (Stricmp(localeprefs
.lp_CountryName
, entry
->lve
.realname
) == 0)
306 struct Window
*winparam
= page_active
? win
: NULL
;
308 GT_SetGadgetAttrs(countrygad
, winparam
, NULL
, GTLV_Selected
, active_country
,
309 GTLV_MakeVisible
, active_country
,
314 /*********************************************************************************************/
316 LONG
page_country_handler(LONG cmd
, IPTR param
)
323 retval
= country_init();
329 case PAGECMD_GETMINWIDTH
:
333 case PAGECMD_GETMINHEIGHT
:
337 case PAGECMD_SETDOMLEFT
:
341 case PAGECMD_SETDOMTOP
:
345 case PAGECMD_SETDOMWIDTH
:
349 case PAGECMD_SETDOMHEIGHT
:
353 case PAGECMD_MAKEGADGETS
:
354 retval
= country_makegadgets();
357 case PAGECMD_ADDGADGETS
:
360 GT_SetGadgetAttrs(countrygad
, NULL
, NULL
, GTLV_MakeVisible
, active_country
, TAG_DONE
);
361 AddGList(win
, gadlist
, -1, -1, NULL
);
362 GT_RefreshWindow(win
, NULL
);
363 RefreshGList(gadlist
, win
, NULL
, -1);
369 case PAGECMD_REMGADGETS
:
372 if (gadlist
) RemoveGList(win
, gadlist
, -1);
378 case PAGECMD_PREFS_CHANGED
:
379 country_prefs_changed();
382 case PAGECMD_HANDLEINPUT
:
383 retval
= country_input((struct IntuiMessage
*)param
);
386 case PAGECMD_CLEANUP
: