disable the unrecognized nls flag
[AROS-Contrib.git] / bgui / infoclass.c
blob3f3836a3fe0b6c63d9a4a9530e819b2b18cb4336
1 /*
2 * @(#) $Header$
4 * BGUI library
5 * infoclass.c
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.
13 * $Log$
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:14 mlemos
21 * Bumped to revision 42.0 before handing BGUI to AROS team
23 * Revision 41.11 2000/05/09 19:54:27 mlemos
24 * Merged with the branch Manuel_Lemos_fixes.
26 * Revision 41.10.2.1 1998/11/29 22:51:52 mlemos
27 * Removed needless code of OM_GET.
29 * Revision 41.10 1998/02/25 21:12:18 mlemos
30 * Bumping to 41.10
32 * Revision 1.1 1998/02/25 17:08:37 mlemos
33 * Ian sources
38 /// Class definitions.
39 #include "include/classdefs.h"
42 * Object instance data.
44 typedef struct {
45 ULONG id_Flags; /* See below. */
46 Object *id_Text; /* Text graphic. */
47 UWORD id_MinLines; /* Minimum Number of lines displayed. */
48 } ID;
50 #define IDF_FIXWIDTH (1<<0) /* Width not smaller than the text. */
51 #define IDF_FIXHEIGHT (1<<1) /* Width not smaller than the text. */
53 ///
54 /// OM_NEW
56 * Create a shiny new object.
58 METHOD(InfoClassNew, struct opSet *, ops)
60 ID *id;
61 struct TagItem *tags;
62 IPTR rc;
63 ULONG ho, vo;
65 tags = DefTagList(BGUI_INFO_GADGET, ops->ops_AttrList);
68 * First we let the superclass setup an object for us.
70 if ((rc = NewSuperObject(cl, obj, tags)))
72 id = INST_DATA(cl, rc);
74 if ((id->id_Text = BGUI_NewObject(BGUI_TEXT_GRAPHIC, TEXTA_CopyText, TRUE, TAG_DONE)))
77 * Pick up frame offsets.
79 ho = GetTagData(INFO_HorizOffset, 8, tags);
80 vo = GetTagData(INFO_VertOffset, 6, tags);
82 if (ho) ho--;
83 if (vo) vo--;
85 DoSetMethodNG((Object *)rc, BT_LeftOffset, ho, BT_RightOffset, ho, BT_TopOffset, vo, BT_BottomOffset, vo,
86 TAG_MORE, tags);
88 else
91 * Failure!
93 AsmCoerceMethod(cl, (Object *)rc, OM_DISPOSE);
94 rc = 0;
97 FreeTagItems(tags);
99 return rc;
101 METHOD_END
103 /// OM_SET, OM_UPDATE
105 * Change the object attributes.
107 METHOD(InfoClassSetUpdate, struct opSet *, ops)
109 ID *id = INST_DATA(cl, obj);
110 struct TagItem *tstate = ops->ops_AttrList;
111 struct TagItem *tag;
112 BOOL vc = FALSE;
113 ULONG data;
116 * First we let the superclass have a go at it.
118 AsmDoSuperMethodA(cl, obj, (Msg)ops);
121 * Change attributes we know.
123 while ((tag = NextTagItem(&tstate)))
125 data = tag->ti_Data;
126 switch (tag->ti_Tag)
128 case INFO_TextFormat:
129 vc = TRUE;
130 DoSetMethodNG(id->id_Text, TEXTA_Text, data, TAG_DONE);
131 break;
133 case INFO_Args:
134 vc = TRUE;
135 DoSetMethodNG(id->id_Text, TEXTA_Args, data, TAG_DONE);
136 break;
138 case INFO_MinLines:
139 id->id_MinLines = data;
140 break;
142 case INFO_FixTextWidth:
143 if (data) id->id_Flags |= IDF_FIXWIDTH;
144 else id->id_Flags &= ~IDF_FIXWIDTH;
145 break;
147 case INFO_FixTextHeight:
148 if (data) id->id_Flags |= IDF_FIXHEIGHT;
149 else id->id_Flags &= ~IDF_FIXHEIGHT;
150 break;
155 * Sanity check.
157 if (id->id_MinLines < 1) id->id_MinLines = 1;
160 * Change visually?
162 if (vc && ops->ops_GInfo) DoRenderMethod(obj, ops->ops_GInfo, GREDRAW_REDRAW);
164 return 1;
166 METHOD_END
168 /// BASE_RENDER
170 * Render the object.
172 METHOD(InfoClassRender, struct bmRender *, bmr)
174 ID *id = INST_DATA(cl, obj);
175 BC *bc = BASE_DATA(obj);
176 struct BaseInfo *bi = bmr->bmr_BInfo;
179 * Render the baseclass.
181 AsmDoSuperMethodA(cl, obj, (Msg)bmr);
184 * Setup the font.
186 if (bc->bc_TextFont) BSetFont(bi, bc->bc_TextFont);
189 * Render the text.
191 BSetDPenA(bi, TEXTPEN);
192 DoMethod(id->id_Text, TEXTM_RENDER, bi, &bc->bc_InnerBox);
194 return 1;
196 METHOD_END
198 /// GM_HITTEST
200 * We do not respond to clicking.
202 METHOD(InfoClassHitTest, struct gpHitTest *, gph)
204 return 0;
206 METHOD_END
208 /// OM_DIPOSE
210 * Dispose of ourselves.
212 METHOD(InfoClassDispose, Msg, msg)
214 ID *id = INST_DATA(cl, obj);
217 * Free the text graphic.
219 if (id->id_Text) DisposeObject(id->id_Text);
221 return AsmDoSuperMethodA(cl, obj, msg);
223 METHOD_END
225 /// BASE_DIMENSIONS
227 * They want our dimensions.
229 METHOD(InfoClassDimensions, struct bmDimensions *, bmd)
231 ID *id = INST_DATA(cl, obj);
232 BC *bc = BASE_DATA(obj);
233 struct BaseInfo *bi = bmd->bmd_BInfo;
234 UWORD mw, mh;
237 * Setup font.
239 if (bc->bc_TextFont) BSetFont(bi, bc->bc_TextFont);
241 DoMethod(id->id_Text, TEXTM_DIMENSIONS, bi->bi_RPort, &mw, &mh);
244 * Fix text size?
246 if (!(id->id_Flags & IDF_FIXWIDTH)) mw = 16;
247 if (!(id->id_Flags & IDF_FIXHEIGHT)) mh = id->id_MinLines * bi->bi_RPort->TxHeight;
249 return CalcDimensions(cl, obj, bmd, mw, mh);
251 METHOD_END
253 /// Class initialization.
255 * Function table.
257 STATIC DPFUNC ClassFunc[] = {
258 { BASE_RENDER, InfoClassRender, },
259 { BASE_DIMENSIONS, InfoClassDimensions, },
261 { OM_NEW, InfoClassNew, },
262 { OM_SET, InfoClassSetUpdate, },
263 { OM_UPDATE, InfoClassSetUpdate, },
264 { OM_DISPOSE, InfoClassDispose, },
265 { GM_HITTEST, InfoClassHitTest, },
266 { DF_END, NULL, },
270 * Simple class initialization.
272 makeproto Class *InitInfoClass( void )
274 return BGUI_MakeClass(CLASS_SuperClassBGUI, BGUI_BASE_GADGET,
275 CLASS_ObjectSize, sizeof(ID),
276 CLASS_DFTable, ClassFunc,
277 TAG_DONE);