Repository navigation
Expand file tree
/
Copy pathindicatorclass.c
More file actions
377 lines (335 loc) · 8.88 KB
/
Copy pathindicatorclass.c
File metadata and controls
377 lines (335 loc) · 8.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/*
* @(#) $Header$
*
* BGUI library
* indicatorclass.c
*
* (C) Copyright 1998 Manuel Lemos.
* (C) Copyright 1996-1997 Ian J. Einman.
* (C) Copyright 1993-1996 Jaba Development.
* (C) Copyright 1993-1996 Jan van den Baard.
* All Rights Reserved.
*
* $Log$
* Revision 42.2 2004/06/16 20:16:48 verhaegs
* Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
*
* Revision 42.1 2000/05/15 19:27:01 stegerg
* another hundreds of REG() macro replacements in func headers/protos.
*
* Revision 42.0 2000/05/09 22:09:12 mlemos
* Bumped to revision 42.0 before handing BGUI to AROS team
*
* Revision 41.11 2000/05/09 19:54:25 mlemos
* Merged with the branch Manuel_Lemos_fixes.
*
* Revision 41.10.2.1 1998/03/01 19:55:15 mlemos
* Fixed short allocation for indicator text string.
*
* Revision 41.10 1998/02/25 21:12:15 mlemos
* Bumping to 41.10
*
* Revision 1.1 1998/02/25 17:08:33 mlemos
* Ian sources
*
*
*/
/// Class definitions.
#include "include/classdefs.h"
/*
* Object instance data.
*/
typedef struct id_ {
UWORD id_Flags; /* see below */
Object *id_Text; /* the text to display */
IPTR id_Args[1]; /* Args to the label */
LONG id_Min; /* minimum indication */
LONG id_Max; /* maximum indication */
LONG id_Level; /* Current level */
UWORD id_Justification; /* label justification */
struct TextFont *id_Font; /* use this font */
UWORD id_MinSize; /* pre-calculated min size */
} ID;
#define IDF_INVALID_MINSIZE (1<<0) /* re-calculate minsize */
#define ID_ENTRY(tag, offset, flags) PACK_ENTRY(INDIC_TAGSTART, tag, id_, offset, flags)
#define ID_FLAG(tag, flag) PACK_LONGBIT(INDIC_TAGSTART, tag, id_, bd_Flags, PKCTRL_BIT, flag)
static ULONG IndicatorPackTable[] =
{
PACK_STARTTABLE(INDIC_TAGSTART),
ID_ENTRY(INDIC_Justification, id_Justification, PKCTRL_UWORD),
ID_ENTRY(INDIC_Min, id_Min, PKCTRL_LONG),
ID_ENTRY(INDIC_Max, id_Max, PKCTRL_LONG),
ID_ENTRY(INDIC_Level, id_Level, PKCTRL_LONG),
PACK_ENDTABLE
};
static void SetLevel(ID *id, LONG level)
{
id->id_Level = level;
id->id_Args[0] = (IPTR)level;
}
///
/// OM_NEW
/*
* Create a shiny new object.
*/
METHOD(IClassNew, struct opSet *, ops)
{
ID *id;
struct TagItem *tags;
IPTR rc;
tags = DefTagList(BGUI_INDICATOR_GADGET, ops->ops_AttrList);
/*
* Let the superclass create us an object.
*/
if ((rc = NewSuperObject(cl, obj, tags)))
{
struct TagItem *tstate;
struct TagItem *tag;
id = INST_DATA(cl, rc);
/*
* Initialize the local instance
* data.
*/
id->id_Justification = IDJ_LEFT;
id->id_Max = 100;
id->id_Text = BGUI_NewObject(BGUI_TEXT_GRAPHIC, TEXTA_Args, &id->id_Args[0], TAG_DONE);
BGUI_PackStructureTags((APTR)id, IndicatorPackTable, tags);
tstate = tags;
while ((tag = NextTagItem(&tstate))) {
if (tag->ti_Tag == INDIC_Level) {
SetLevel(id, (LONG)tag->ti_Data);
}
}
/*
* are we setup OK?
*/
if (!id->id_Text || (id->id_Min > id->id_Max))
{
AsmCoerceMethod(cl, (Object *)rc, OM_DISPOSE);
rc = 0;
}
DoSetMethodNG((Object *)rc, INDIC_FormatString, "%ld", TAG_DONE);
};
FreeTagItems(tags);
return rc;
}
METHOD_END
///
/// OM_DISPOSE
/*
* Hmm, they want us out of here.
*/
METHOD(IClassDispose, Msg, msg)
{
ID *id = INST_DATA(cl, obj);
/*
* Dispose of the text graphic.
*/
if (id->id_Text) DisposeObject(id->id_Text);
/*
* And let the superclass take
* care of the rest.
*/
return AsmDoSuperMethodA(cl, obj, msg);
}
METHOD_END
///
/// OM_SET, OM_UPDATE
/*
* Set/Update object attributes.
*/
METHOD(IClassSetUpdate, struct opUpdate *, opu)
{
ID *id = INST_DATA(cl, obj);
IPTR data;
struct TagItem *tstate = opu->opu_AttrList;
struct TagItem *tag;
BOOL update = FALSE;
LONG old_level = id->id_Level;
UBYTE *full_format;
/*
* First we let the superclass have a go at it.
*/
AsmDoSuperMethodA(cl, obj, (Msg)opu);
/*
* Set attributes.
*/
BGUI_PackStructureTags((APTR)id, IndicatorPackTable, opu->opu_AttrList);
while ((tag = NextTagItem(&tstate)))
{
data = tag->ti_Data;
switch (tag->ti_Tag)
{
/*
* Intercept the font.
*/
case BT_TextFont:
id->id_Font = (struct TextFont *)data;
id->id_Flags |= IDF_INVALID_MINSIZE;
break;
case INDIC_FormatString:
if ((full_format = BGUI_AllocPoolMem(3 + strlen((UBYTE *)data))))
{
sprintf(full_format, "\033l%s", (UBYTE *)data);
DoSetMethodNG(id->id_Text, TEXTA_Text, full_format, TEXTA_CopyText, TRUE, TAG_DONE);
BGUI_FreePoolMem(full_format);
};
case INDIC_Justification:
update = TRUE;
break;
case INDIC_Level:
SetLevel(id, (LONG)data);
update = TRUE;
break;
};
};
if (id->id_Level < id->id_Min) id->id_Level = id->id_Min;
if (id->id_Level > id->id_Max) id->id_Level = id->id_Max;
if (id->id_Level != old_level) update = TRUE;
/*
* Refresh gadget?
*/
if (update) DoRenderMethod(obj, opu->opu_GInfo, GREDRAW_REDRAW);
return 1;
}
METHOD_END
///
/// OM_GET
METHOD(IClassGet, struct opGet *, opg)
{
ID *id = INST_DATA(cl, obj);
ULONG rc = 1;
Tag attr = opg->opg_AttrID;
IPTR *store = opg->opg_Storage;
switch (attr)
{
case INDIC_FormatString:
Get_Attr(id->id_Text, TEXTA_Text, store);
*store += 2;
break;
default:
/*
* First we see if the attribute they want is known to us. If not
* we pass it onto the superclass.
*/
rc = BGUI_UnpackStructureTag((UBYTE *)id, IndicatorPackTable, attr, store);
if (!rc) rc = AsmDoSuperMethodA(cl, obj, (Msg)opg);
break;
};
return rc;
}
METHOD_END
///
/// BASE_RENDER
/*
* Render the object.
*/
METHOD(IClassRender, struct bmRender *, bmr)
{
ID *id = INST_DATA(cl, obj);
BC *bc = BASE_DATA(obj);
struct BaseInfo *bi = bmr->bmr_BInfo;
UBYTE *str = NULL;
/*
* Render the baseclass.
*/
AsmDoSuperMethodA(cl, obj, (Msg)bmr);
/*
* Setup the font.
*/
if (id->id_Font) BSetFont(bi, id->id_Font);
Get_Attr(id->id_Text, TEXTA_Text, (IPTR *)&str);
if (str)
{
switch (id->id_Justification)
{
case IDJ_LEFT:
str[1] = 'l';
break;
case IDJ_RIGHT:
str[1] = 'r';
break;
case IDJ_CENTER:
str[1] = 'c';
break;
}
BSetDPenA(bi, TEXTPEN);
DoMethod(id->id_Text, TEXTM_RENDER, bi, &bc->bc_InnerBox);
};
return 1;
}
METHOD_END
///
/// GM_HITTEST
/*
* This object cannot be hit.
*/
METHOD(IClassHitTest, Msg, msg)
{
return 0;
}
METHOD_END
///
/// BASE_DIMENSIONS
/*
* Our parent group needs to know
* something about our dimensions.
*/
METHOD(IClassDimensions, struct bmDimensions *, bmd)
{
ID *id = INST_DATA(cl, obj);
struct RastPort *rp = bmd->bmd_BInfo->bi_RPort;
UWORD mw, mh, w, h;
LONG old_level = id->id_Level;
mw = mh = w = h = 0;
/*
* Compute size of minimum level.
*/
SetLevel(id, id->id_Min);
DoMethod(id->id_Text, TEXTM_DIMENSIONS, rp, &mw, &mh);
/*
* Compute size of maximum level.
*/
SetLevel(id, id->id_Max);
DoMethod(id->id_Text, TEXTM_DIMENSIONS, rp, &w, &h);
if (mw < w) mw = w;
if (mh < h) mh = h;
SetLevel(id, old_level);
/*
* Add the width of an average digit.
*/
mw += TextWidthNum(rp, "0123456789", 10) / 10;
/*
* Setup minimum dimensions.
*/
return CalcDimensions(cl, obj, bmd, mw, mh);
}
METHOD_END
///
/// Class initialization.
/*
* Function table.
*/
STATIC DPFUNC ClassFunc[] =
{
{ BASE_RENDER, IClassRender, },
{ BASE_DIMENSIONS, IClassDimensions, },
{ OM_NEW, IClassNew, },
{ OM_SET, IClassSetUpdate, },
{ OM_UPDATE, IClassSetUpdate, },
{ OM_GET, IClassGet, },
{ OM_DISPOSE, IClassDispose, },
{ GM_HITTEST, IClassHitTest, },
{ DF_END, NULL },
};
/*
* Simple class initialization
*/
makeproto Class *InitIndicatorClass(void)
{
return BGUI_MakeClass(CLASS_SuperClassBGUI, BGUI_BASE_GADGET,
CLASS_ObjectSize, sizeof(ID),
CLASS_DFTable, ClassFunc,
TAG_DONE);
}
///