7 * (C) Copyright 1998 Manuel Lemos.
8 * (C) Copyright 1996-1997 Ian J. Einman.
9 * (C) Copyright 1993-1996 Jaba Development.
10 * (C) Copyright 1993-1996 Jan van den Baard.
11 * All Rights Reserved.
14 * Revision 42.2 2004/06/16 20:16:48 verhaegs
15 * Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
17 * Revision 42.1 2000/05/15 19:27:01 stegerg
18 * another hundreds of REG() macro replacements in func headers/protos.
20 * Revision 42.0 2000/05/09 22:09:12 mlemos
21 * Bumped to revision 42.0 before handing BGUI to AROS team
23 * Revision 41.11 2000/05/09 19:54:25 mlemos
24 * Merged with the branch Manuel_Lemos_fixes.
26 * Revision 41.10.2.1 1998/03/01 19:55:15 mlemos
27 * Fixed short allocation for indicator text string.
29 * Revision 41.10 1998/02/25 21:12:15 mlemos
32 * Revision 1.1 1998/02/25 17:08:33 mlemos
38 /// Class definitions.
39 #include "include/classdefs.h"
42 * Object instance data.
45 UWORD id_Flags
; /* see below */
46 Object
*id_Text
; /* the text to display */
47 IPTR id_Args
[1]; /* Args to the label */
48 LONG id_Min
; /* minimum indication */
49 LONG id_Max
; /* maximum indication */
50 LONG id_Level
; /* Current level */
51 UWORD id_Justification
; /* label justification */
52 struct TextFont
*id_Font
; /* use this font */
53 UWORD id_MinSize
; /* pre-calculated min size */
56 #define IDF_INVALID_MINSIZE (1<<0) /* re-calculate minsize */
58 #define ID_ENTRY(tag, offset, flags) PACK_ENTRY(INDIC_TAGSTART, tag, id_, offset, flags)
59 #define ID_FLAG(tag, flag) PACK_LONGBIT(INDIC_TAGSTART, tag, id_, bd_Flags, PKCTRL_BIT, flag)
61 static ULONG IndicatorPackTable
[] =
63 PACK_STARTTABLE(INDIC_TAGSTART
),
65 ID_ENTRY(INDIC_Justification
, id_Justification
, PKCTRL_UWORD
),
66 ID_ENTRY(INDIC_Min
, id_Min
, PKCTRL_LONG
),
67 ID_ENTRY(INDIC_Max
, id_Max
, PKCTRL_LONG
),
68 ID_ENTRY(INDIC_Level
, id_Level
, PKCTRL_LONG
),
73 static void SetLevel(ID
*id
, LONG level
)
76 id
->id_Args
[0] = (IPTR
)level
;
82 * Create a shiny new object.
84 METHOD(IClassNew
, struct opSet
*, ops
)
90 tags
= DefTagList(BGUI_INDICATOR_GADGET
, ops
->ops_AttrList
);
93 * Let the superclass create us an object.
95 if ((rc
= NewSuperObject(cl
, obj
, tags
)))
97 struct TagItem
*tstate
;
99 id
= INST_DATA(cl
, rc
);
102 * Initialize the local instance
105 id
->id_Justification
= IDJ_LEFT
;
107 id
->id_Text
= BGUI_NewObject(BGUI_TEXT_GRAPHIC
, TEXTA_Args
, &id
->id_Args
[0], TAG_DONE
);
109 BGUI_PackStructureTags((APTR
)id
, IndicatorPackTable
, tags
);
111 while ((tag
= NextTagItem(&tstate
))) {
112 if (tag
->ti_Tag
== INDIC_Level
) {
113 SetLevel(id
, (LONG
)tag
->ti_Data
);
120 if (!id
->id_Text
|| (id
->id_Min
> id
->id_Max
))
122 AsmCoerceMethod(cl
, (Object
*)rc
, OM_DISPOSE
);
125 DoSetMethodNG((Object
*)rc
, INDIC_FormatString
, "%ld", TAG_DONE
);
135 * Hmm, they want us out of here.
137 METHOD(IClassDispose
, Msg
, msg
)
139 ID
*id
= INST_DATA(cl
, obj
);
142 * Dispose of the text graphic.
144 if (id
->id_Text
) DisposeObject(id
->id_Text
);
147 * And let the superclass take
150 return AsmDoSuperMethodA(cl
, obj
, msg
);
154 /// OM_SET, OM_UPDATE
156 * Set/Update object attributes.
158 METHOD(IClassSetUpdate
, struct opUpdate
*, opu
)
160 ID
*id
= INST_DATA(cl
, obj
);
162 struct TagItem
*tstate
= opu
->opu_AttrList
;
165 LONG old_level
= id
->id_Level
;
169 * First we let the superclass have a go at it.
171 AsmDoSuperMethodA(cl
, obj
, (Msg
)opu
);
176 BGUI_PackStructureTags((APTR
)id
, IndicatorPackTable
, opu
->opu_AttrList
);
178 while ((tag
= NextTagItem(&tstate
)))
185 * Intercept the font.
188 id
->id_Font
= (struct TextFont
*)data
;
189 id
->id_Flags
|= IDF_INVALID_MINSIZE
;
192 case INDIC_FormatString
:
193 if ((full_format
= BGUI_AllocPoolMem(3 + strlen((UBYTE
*)data
))))
195 sprintf(full_format
, "\033l%s", (UBYTE
*)data
);
196 DoSetMethodNG(id
->id_Text
, TEXTA_Text
, full_format
, TEXTA_CopyText
, TRUE
, TAG_DONE
);
197 BGUI_FreePoolMem(full_format
);
199 case INDIC_Justification
:
203 SetLevel(id
, (LONG
)data
);
209 if (id
->id_Level
< id
->id_Min
) id
->id_Level
= id
->id_Min
;
210 if (id
->id_Level
> id
->id_Max
) id
->id_Level
= id
->id_Max
;
211 if (id
->id_Level
!= old_level
) update
= TRUE
;
216 if (update
) DoRenderMethod(obj
, opu
->opu_GInfo
, GREDRAW_REDRAW
);
223 METHOD(IClassGet
, struct opGet
*, opg
)
225 ID
*id
= INST_DATA(cl
, obj
);
227 Tag attr
= opg
->opg_AttrID
;
228 IPTR
*store
= opg
->opg_Storage
;
232 case INDIC_FormatString
:
233 Get_Attr(id
->id_Text
, TEXTA_Text
, store
);
239 * First we see if the attribute they want is known to us. If not
240 * we pass it onto the superclass.
242 rc
= BGUI_UnpackStructureTag((UBYTE
*)id
, IndicatorPackTable
, attr
, store
);
243 if (!rc
) rc
= AsmDoSuperMethodA(cl
, obj
, (Msg
)opg
);
254 METHOD(IClassRender
, struct bmRender
*, bmr
)
256 ID
*id
= INST_DATA(cl
, obj
);
257 BC
*bc
= BASE_DATA(obj
);
258 struct BaseInfo
*bi
= bmr
->bmr_BInfo
;
262 * Render the baseclass.
264 AsmDoSuperMethodA(cl
, obj
, (Msg
)bmr
);
269 if (id
->id_Font
) BSetFont(bi
, id
->id_Font
);
271 Get_Attr(id
->id_Text
, TEXTA_Text
, (IPTR
*)&str
);
275 switch (id
->id_Justification
)
287 BSetDPenA(bi
, TEXTPEN
);
288 DoMethod(id
->id_Text
, TEXTM_RENDER
, bi
, &bc
->bc_InnerBox
);
296 * This object cannot be hit.
298 METHOD(IClassHitTest
, Msg
, msg
)
306 * Our parent group needs to know
307 * something about our dimensions.
309 METHOD(IClassDimensions
, struct bmDimensions
*, bmd
)
311 ID
*id
= INST_DATA(cl
, obj
);
312 struct RastPort
*rp
= bmd
->bmd_BInfo
->bi_RPort
;
314 LONG old_level
= id
->id_Level
;
319 * Compute size of minimum level.
321 SetLevel(id
, id
->id_Min
);
323 DoMethod(id
->id_Text
, TEXTM_DIMENSIONS
, rp
, &mw
, &mh
);
326 * Compute size of maximum level.
328 SetLevel(id
, id
->id_Max
);
330 DoMethod(id
->id_Text
, TEXTM_DIMENSIONS
, rp
, &w
, &h
);
335 SetLevel(id
, old_level
);
338 * Add the width of an average digit.
340 mw
+= TextWidthNum(rp
, "0123456789", 10) / 10;
343 * Setup minimum dimensions.
345 return CalcDimensions(cl
, obj
, bmd
, mw
, mh
);
349 /// Class initialization.
353 STATIC DPFUNC ClassFunc
[] =
355 { BASE_RENDER
, IClassRender
, },
356 { BASE_DIMENSIONS
, IClassDimensions
, },
358 { OM_NEW
, IClassNew
, },
359 { OM_SET
, IClassSetUpdate
, },
360 { OM_UPDATE
, IClassSetUpdate
, },
361 { OM_GET
, IClassGet
, },
362 { OM_DISPOSE
, IClassDispose
, },
363 { GM_HITTEST
, IClassHitTest
, },
368 * Simple class initialization
370 makeproto Class
*InitIndicatorClass(void)
372 return BGUI_MakeClass(CLASS_SuperClassBGUI
, BGUI_BASE_GADGET
,
373 CLASS_ObjectSize
, sizeof(ID
),
374 CLASS_DFTable
, ClassFunc
,