2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
5 Desc: Internal GadTools string class.
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() */
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 */
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
;
73 tags
[0].ti_Tag
= STRINGA_TextVal
;
74 tags
[0].ti_Data
= tidata
;
78 tags
[1].ti_Tag
= STRINGA_LongVal
;
79 tags
[1].ti_Data
= tidata
;
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
88 tags
[2].ti_Tag
= STRINGA_MaxChars
;
89 tags
[2].ti_Data
= ((WORD
)tidata
) + 1;
92 /* case GTIN_EditHook: Duplicate case value */
94 tags
[3].ti_Tag
= STRINGA_EditHook
;
95 tags
[3].ti_Data
= tidata
;
103 dri
= (struct DrawInfo
*)tidata
;
106 tattr
= (struct TextAttr
*)tidata
;
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
[] =
125 {IA_Resolution
, 0UL },
126 {IA_FrameType
, FRAME_RIDGE
},
127 {IA_EdgesOnly
, TRUE
},
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
;
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
));
147 CoerceMethod(cl
, (Object
*)retval
, OM_DISPOSE
);
154 data
->font
= OpenFont(tattr
);
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
;
179 switch(cloned_msg
.opg_AttrID
)
182 case GTA_ChildGadgetKind
:
183 *(msg
->opg_Storage
) = data
->gadgetkind
;
188 cloned_msg
.opg_AttrID
= STRINGA_TextVal
;
192 cloned_msg
.opg_AttrID
= STRINGA_LongVal
;
199 if (!retval
) retval
= DoSuperMethodA(cl
, o
, (Msg
)&cloned_msg
);
204 /**********************************************************************************************/
206 IPTR
GTString__GM_RENDER(Class
*cl
, struct Gadget
*g
, struct gpRender
*msg
)
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
);
221 struct TagItem itags
[] =
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
,
243 msg
->gpr_GInfo
->gi_DrInfo
);
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 /**********************************************************************************************/