add casts to zune macros to silence some warnings
[tangerine.git] / workbench / libs / asl / fontstyleclass.c
blobbf6dcc503e69c98b23316072a0ebaeab2c0f9666
1 /*
2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <proto/utility.h>
8 #include <proto/intuition.h>
9 #include <proto/graphics.h>
10 #include <proto/layers.h>
12 #include <exec/memory.h>
13 #include <intuition/screens.h>
14 #include <intuition/cghooks.h>
15 #include <intuition/imageclass.h>
16 #include <intuition/gadgetclass.h>
17 #include <graphics/gfx.h>
18 #include <graphics/text.h>
20 #include <string.h>
22 #include "asl_intern.h"
23 #include "layout.h"
25 #define SDEBUG 0
26 #define DEBUG 0
28 #include <aros/debug.h>
30 #define CLASS_ASLBASE ((struct AslBase_intern *)cl->cl_UserData)
31 #define HOOK_ASLBASE ((struct AslBase_intern *)hook->h_Data)
33 #define AslBase CLASS_ASLBASE
35 /********************** ASL FONTPREVIEW CLASS **************************************************/
37 static const UBYTE gadindextostylemap[3] =
39 FSF_BOLD,
40 FSF_ITALIC,
41 FSF_UNDERLINED
44 /***********************************************************************************/
46 IPTR AslFontStyle__OM_NEW(Class * cl, Object * o, struct opSet * msg)
48 struct AslFontStyleData *data;
49 struct TagItem fitags[] =
51 {IA_FrameType, FRAME_BUTTON},
52 {IA_EdgesOnly, FALSE },
53 {TAG_DONE, 0UL}
55 STRPTR *labelarray;
57 o = (Object *)DoSuperMethodA(cl, o, (Msg)msg);
59 if (o)
61 data = INST_DATA(cl, o);
63 data->frame = NewObjectA(NULL, FRAMEICLASS, fitags);
65 data->style = GetTagData(ASLFS_Style, FS_NORMAL, msg->ops_AttrList);
67 if ((labelarray = (STRPTR *)GetTagData(ASLFS_LabelArray, 0, msg->ops_AttrList)))
69 data->text[0] = labelarray[0];
70 data->text[1] = labelarray[1];
71 data->text[2] = labelarray[2];
73 else
75 data->text[0] = "B";
76 data->text[1] = "I";
77 data->text[2] = "U";
80 } /* if (o) */
82 return (IPTR)o;
85 /***********************************************************************************/
87 IPTR AslFontStyle__OM_DISPOSE(Class * cl, Object * o, Msg msg)
89 struct AslFontStyleData *data;
90 IPTR retval;
92 data = INST_DATA(cl, o);
93 if (data->frame) DisposeObject(data->frame);
95 retval = DoSuperMethodA(cl, o, msg);
97 return retval;
100 /***********************************************************************************/
102 IPTR AslFontStyle__OM_SET(Class * cl, Object * o, struct opSet * msg)
104 struct AslFontStyleData *data;
105 struct TagItem *tag;
106 const struct TagItem *tstate = msg->ops_AttrList;
107 struct RastPort *rp;
108 BOOL redraw = FALSE;
109 IPTR retval;
111 data = INST_DATA(cl, o);
113 retval = DoSuperMethodA(cl, o, (Msg)msg);
115 while((tag = NextTagItem(&tstate)))
117 switch(tag->ti_Tag)
119 case ASLFS_Style:
120 data->style = tag->ti_Data;
121 redraw = TRUE;
122 break;
127 if (redraw)
129 if ((rp = ObtainGIRPort(msg->ops_GInfo)))
131 struct gpRender gpr;
133 gpr.MethodID = GM_RENDER;
134 gpr.gpr_GInfo = msg->ops_GInfo;
135 gpr.gpr_RPort = rp;
136 gpr.gpr_Redraw = GREDRAW_UPDATE;
138 DoMethodA(o, (Msg)&gpr);
140 ReleaseGIRPort(rp);
144 return retval;
148 /***********************************************************************************/
150 IPTR AslFontStyle__OM_GET(Class *cl, Object *o, struct opGet *msg)
152 struct AslFontStyleData *data = INST_DATA(cl, o);
154 IPTR retval = 1;
156 switch(msg->opg_AttrID)
158 case ASLFS_Style:
159 *msg->opg_Storage = data->style;
160 break;
162 default:
163 retval = DoSuperMethodA(cl, o, (Msg)msg);
164 break;
167 return retval;
171 /***********************************************************************************/
173 IPTR AslFontStyle__GM_RENDER(Class *cl, struct Gadget *g, struct gpRender *msg)
175 struct AslFontStyleData *data;
176 struct RastPort *rp;
177 WORD x, y, w, h, i, sw;
179 getgadgetcoords(g, msg->gpr_GInfo, &x, &y, &w, &h);
181 data = INST_DATA(cl, g);
182 rp = msg->gpr_RPort;
184 sw = w / 3;
186 if (data->frame)
188 SetAttrs(data->frame, IA_Width, sw,
189 IA_Height, h,
190 TAG_DONE);
193 for(i = 0; i < 3; i++)
195 struct TextExtent te;
196 BOOL set;
198 set = (data->style & gadindextostylemap[i]) ? TRUE : FALSE;
200 if (data->frame)
203 DrawImageState(rp,
204 (struct Image *)data->frame,
207 set ? IDS_SELECTED : IDS_NORMAL,
208 msg->gpr_GInfo->gi_DrInfo);
211 SetSoftStyle(rp, gadindextostylemap[i], AskSoftStyle(rp));
212 SetAPen(rp, msg->gpr_GInfo->gi_DrInfo->dri_Pens[set ? HIGHLIGHTTEXTPEN : TEXTPEN]);
213 SetDrMd(rp, JAM1);
215 TextExtent(rp, data->text[i], strlen(data->text[i]), &te);
216 w = te.te_Extent.MaxX - te.te_Extent.MinX + 1;
218 Move(rp,
219 x + (sw - w) / 2 - te.te_Extent.MinX,
220 y + (h - rp->TxHeight) / 2 + rp->TxBaseline);
221 Text(rp, data->text[i], strlen(data->text[i]));
223 x += sw;
226 return 0;
229 /***********************************************************************************/
231 IPTR AslFontStyle__GM_GOACTIVE(Class *cl, struct Gadget *g, struct gpInput *msg)
233 struct AslFontStyleData *data;
234 struct RastPort *rp;
235 WORD x, y, w, h;
237 if (!msg->gpi_IEvent) return GMR_NOREUSE;
239 getgadgetcoords(g, msg->gpi_GInfo, &x, &y, &w, &h);
241 data = INST_DATA(cl, g);
243 w /= 3;
244 x = msg->gpi_Mouse.X / w;
245 if (x < 0) x = 0; else if (x > 2) x = 2;
247 data->style ^= gadindextostylemap[x];
249 if ((rp = ObtainGIRPort(msg->gpi_GInfo)))
251 struct gpRender gpr;
253 gpr.MethodID = GM_RENDER;
254 gpr.gpr_GInfo = msg->gpi_GInfo;
255 gpr.gpr_RPort = rp;
256 gpr.gpr_Redraw = GREDRAW_UPDATE;
258 DoMethodA((Object *)g, (Msg)&gpr);
260 ReleaseGIRPort(rp);
263 *msg->gpi_Termination = data->style;
265 return GMR_NOREUSE | GMR_VERIFY;
269 /***********************************************************************************/