Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / gadtools / stringclass.c
blobfbaf517e24136ef4ce03b44b67c110aec873d6eb
1 /*
2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Internal GadTools string class.
6 Lang: English
7 */
10 #include <proto/exec.h>
11 #include <exec/libraries.h>
12 #include <exec/memory.h>
13 #include <proto/dos.h>
14 #include <intuition/classes.h>
15 #include <intuition/classusr.h>
16 #include <intuition/gadgetclass.h>
17 #include <intuition/imageclass.h>
18 #include <intuition/intuition.h>
19 #include <intuition/cghooks.h>
20 #include <graphics/rastport.h>
21 #include <graphics/text.h>
22 #include <utility/tagitem.h>
23 #include <devices/inputevent.h>
24 #include <proto/alib.h>
25 #include <proto/utility.h>
27 #include <string.h> /* memset() */
29 #define SDEBUG 0
30 #define DEBUG 0
31 #include <aros/debug.h>
33 #include "gadtools_intern.h"
35 /**********************************************************************************************/
37 #define GadToolsBase ((struct GadToolsBase_intern *)cl->cl_UserData)
39 /**********************************************************************************************/
41 IPTR GTString__OM_NEW(Class *cl, Object *o, struct opSet *msg)
43 struct TagItem *tag, tags[] =
45 {TAG_IGNORE , 0UL }, /* 0 STRINGA_TextVal */
46 {TAG_IGNORE , 0UL }, /* 1 STRINGA_LongVal */
47 {TAG_IGNORE , 0UL }, /* 2 STRINGA_MaxChars */
48 {TAG_IGNORE , 0UL }, /* 3 STRINGA_EditHook */
49 {TAG_MORE , 0UL }
51 struct TagItem *tstate = msg->ops_AttrList;
53 LONG labelplace = GV_LabelPlace_Left;
54 struct DrawInfo *dri = NULL;
55 struct TextAttr *tattr = NULL;
56 LONG gadgetkind = STRING_KIND;
58 struct Gadget *retval = NULL;
60 EnterFunc(bug("String::SetNew()\n"));
62 while ((tag = NextTagItem(&tstate)))
64 IPTR tidata = tag->ti_Data;
66 switch (tag->ti_Tag)
68 case GTA_GadgetKind:
69 gadgetkind = tidata;
70 break;
72 case GTST_String:
73 tags[0].ti_Tag = STRINGA_TextVal;
74 tags[0].ti_Data = tidata;
75 break;
77 case GTIN_Number:
78 tags[1].ti_Tag = STRINGA_LongVal;
79 tags[1].ti_Data = tidata;
80 break;
82 /* Another weird inconsistency of AmigaOS GUI objects:
83 ** For intuition and strgclass gadgets, MaxChars includes trailing
84 ** zero, but this is NOT true for gadtools string gadgets
86 case GTIN_MaxChars:
87 case GTST_MaxChars:
88 tags[2].ti_Tag = STRINGA_MaxChars;
89 tags[2].ti_Data = ((WORD)tidata) + 1;
90 break;
92 /* case GTIN_EditHook: Duplicate case value */
93 case GTST_EditHook:
94 tags[3].ti_Tag = STRINGA_EditHook;
95 tags[3].ti_Data = tidata;
96 break;
98 case GA_LabelPlace:
99 labelplace = tidata;
100 break;
102 case GA_DrawInfo:
103 dri = (struct DrawInfo *)tidata;
104 break;
105 case GA_TextAttr:
106 tattr = (struct TextAttr *)tidata;
107 break;
112 tags[4].ti_Data = (IPTR)msg->ops_AttrList;
114 retval = (struct Gadget *)DoSuperMethod(cl, o, msg->MethodID, (IPTR) tags, (IPTR) msg->ops_GInfo);
116 D(bug("Returned from supermethod: %p\n", retval));
118 if ((msg->MethodID == OM_NEW) && (retval != NULL))
120 struct StringData *data = INST_DATA(cl, retval);
121 struct TagItem fitags[] =
123 {IA_Width , 0UL },
124 {IA_Height , 0UL },
125 {IA_Resolution , 0UL },
126 {IA_FrameType , FRAME_RIDGE },
127 {IA_EdgesOnly , TRUE },
128 {TAG_DONE , 0UL }
131 fitags[0].ti_Data = retval->Width;
132 fitags[1].ti_Data = retval->Height;
133 fitags[2].ti_Data = (dri->dri_Resolution.X << 16) + dri->dri_Resolution.Y;
135 data->labelplace = labelplace;
136 data->frame = NULL;
137 data->font = NULL;
138 data->gadgetkind = gadgetkind;
140 D(bug("Creating frame image"));
142 data->frame = NewObjectA(NULL, FRAMEICLASS, fitags);
144 D(bug("Created frame image: %p", data->frame));
145 if (!data->frame)
147 CoerceMethod(cl, (Object *)retval, OM_DISPOSE);
149 retval = NULL;
152 if (tattr)
154 data->font = OpenFont(tattr);
156 if (data->font)
158 struct TagItem sftags[] = {{STRINGA_Font, (IPTR)NULL}, {TAG_DONE, }};
160 sftags[0].ti_Data = (IPTR)data->font;
162 DoSuperMethod(cl, (Object *)retval, OM_SET, (IPTR) sftags, NULL);
167 ReturnPtr ("String::SetNew", IPTR, (IPTR)retval);
171 /**********************************************************************************************/
173 IPTR GTString__OM_GET(Class *cl, Object *o, struct opGet *msg)
175 struct StringData *data = INST_DATA(cl, o);
176 struct opGet cloned_msg = *msg;
177 IPTR retval = 0;
179 switch(cloned_msg.opg_AttrID)
181 case GTA_GadgetKind:
182 case GTA_ChildGadgetKind:
183 *(msg->opg_Storage) = data->gadgetkind;
184 retval = 1UL;
185 break;
187 case GTST_String:
188 cloned_msg.opg_AttrID = STRINGA_TextVal;
189 break;
191 case GTIN_Number:
192 cloned_msg.opg_AttrID = STRINGA_LongVal;
193 break;
195 default:
196 break;
199 if (!retval) retval = DoSuperMethodA(cl, o, (Msg)&cloned_msg);
201 return retval;
204 /**********************************************************************************************/
206 IPTR GTString__GM_RENDER(Class *cl, struct Gadget *g, struct gpRender *msg)
208 IPTR retval;
210 EnterFunc(bug("String::Render()\n"));
211 retval = DoSuperMethodA(cl, (Object *)g, (Msg)msg);
213 D(bug("Superclass render OK\n"));
215 if (msg->gpr_Redraw == GREDRAW_REDRAW)
217 struct StringData *data = INST_DATA(cl, g);
219 WORD x, y;
221 struct TagItem itags[] =
223 {IA_Width, 0L},
224 {IA_Height, 0L},
225 {TAG_DONE,}
228 D(bug("Full redraw\n"));
230 /* center image position, we assume image top and left is 0 */
231 itags[0].ti_Data = g->Width + BORDERSTRINGSPACINGX * 2;
232 itags[1].ti_Data = g->Height + BORDERSTRINGSPACINGY * 2;
234 SetAttrsA((Object *)data->frame, itags);
236 x = g->LeftEdge - BORDERSTRINGSPACINGX;
237 y = g->TopEdge - BORDERSTRINGSPACINGY;
239 DrawImageState(msg->gpr_RPort,
240 (struct Image *)data->frame,
241 x, y,
242 IDS_NORMAL,
243 msg->gpr_GInfo->gi_DrInfo);
245 /* render label */
246 renderlabel(GadToolsBase, g, msg->gpr_RPort, data->labelplace);
248 } /* if (whole gadget should be redrawn) */
250 ReturnInt ("String::Render", IPTR, retval);
253 /**********************************************************************************************/
255 IPTR GTString__OM_DISPOSE(Class *cl, Object *o, Msg msg)
257 struct StringData *data = INST_DATA(cl, o);
259 if (data->frame) DisposeObject(data->frame);
260 if (data->font) CloseFont(data->font);
262 return DoSuperMethodA(cl, o, (Msg)msg);
265 /**********************************************************************************************/