Metatarget for copying of testfile fixed.
[AROS.git] / workbench / libs / reqtools / boopsi.c
blob329ee217320e25978e86ffea92bcfd57e6957553
1 #include <graphics/gfxbase.h>
2 #include <graphics/rastport.h>
3 #include <graphics/text.h>
4 #include <intuition/intuition.h>
5 #include <intuition/imageclass.h>
6 #include <intuition/intuition.h>
7 #ifdef __AROS__
8 #include <aros/asmcall.h>
9 #endif
11 #include "filereq.h"
13 #include <string.h>
15 extern struct IClass *ButtonImgClass;
17 extern ULONG ASM myTextLength (ASM_REGPARAM(a1, const char *,),
18 ASM_REGPARAM(a0, struct TextAttr *,),
19 ASM_REGPARAM(a3, UBYTE *,),
20 ASM_REGPARAM(a2, struct Image *,),
21 ASM_REGPARAM(d7, ULONG,));
23 const UWORD defaultpens[] =
25 1, 0, 1, 2, 1, 3, 1, 0, 2
28 /****************************************************************************************/
30 char KeyFromStr(char *string, char underchar)
32 char c, ret = 0;
34 while ((c = *string++))
36 if (c == underchar)
38 ret = ToUpper(*string);
39 break;
43 return ret;
46 /****************************************************************************************/
48 ULONG myTextLength(const char *str, struct TextAttr *attr, UBYTE *underscore,
49 struct Image *im, ULONG do_lod)
51 struct RastPort temprp;
52 struct TextFont *font = NULL;
53 WORD pixellen = 0;
55 InitRastPort(&temprp);
57 if (attr)
59 font = OpenFont(attr);
60 if (font)
62 SetFont(&temprp, font);
64 else
66 SetFont(&temprp, GfxBase->DefaultFont);
69 else
71 SetFont(&temprp, GfxBase->DefaultFont);
74 if (str)
76 struct LocalObjData *lod = (struct LocalObjData *)0xDEADBEAF;
77 char c;
78 const char *str2;
79 WORD len = strlen(str), underoff;
81 if (do_lod)
83 im->PlaneOnOff = 0;
85 lod = INST_DATA(ButtonImgClass, im);
86 lod->lod_UnderOff = len;
88 im->Height = temprp.TxHeight;
91 pixellen = TextLength(&temprp, str, len);
93 str2 = str;
95 underoff = -1;
97 while((c = *str2++))
99 underoff++;
101 if (c == *underscore)
103 pixellen -= TextLength(&temprp, underscore, 1);
105 if (do_lod)
107 im->PlaneOnOff = *str2; /* store code of underscored key */
108 lod->lod_UnderOff = underoff; /* store offset of underscore */
109 lod->lod_RestLen = len - underoff - 1; /* store len of remaining string */
110 lod->lod_UnderY = temprp.TxBaseline + 2; /* Y position of underscore */
112 lod->lod_UnderWidth = TextLength(&temprp, str2, 1);
114 break;
118 } /* if (str) */
120 if (font) CloseFont(font);
122 return pixellen;
125 /****************************************************************************************/
127 #define imsg ((struct impDraw *)msg)
129 #ifdef __AROS__
130 AROS_UFH3(IPTR, myBoopsiDispatch,
131 AROS_UFHA(Class *, cl, A0),
132 AROS_UFHA(struct Image *, im, A2),
133 AROS_UFHA(Msg, msg, A1))
135 AROS_USERFUNC_INIT
136 #else
137 IPTR myBoopsiDispatch(REGPARAM(a0, Class *, cl),
138 REGPARAM(a2, struct Image *, im),
139 REGPARAM(a1, Msg, msg))
141 #endif
142 struct LocalObjData *data;
143 struct TextFont *font, *oldfont;
144 struct RastPort *rp;
145 struct Gadget *gad;
146 UWORD *pens;
147 WORD xpos, ypos;
148 IPTR retval = 0;
150 switch(msg->MethodID)
152 case OM_NEW:
153 retval = DoSuperMethodA(cl, (Object *)im, msg);
154 if (retval)
156 UBYTE underscorechar;
157 union {
158 struct {
159 WORD Width;
160 WORD Height;
161 } size;
162 ULONG magic;
163 } __tmp;
165 im = (struct Image *)retval;
167 data = INST_DATA(cl, im);
168 data->lod_IData = *(struct InitData *)im->ImageData;
170 underscorechar = (UBYTE)data->lod_IData.idata_Underscore;
172 im->Width = myTextLength(data->lod_IData.idata_Label,
173 data->lod_IData.idata_TextAttr,
174 &underscorechar,
176 cl->cl_InstOffset /* for C Routines its not really more than a flag */
179 /* Calculate text position if we have a gadget */
181 if ((gad = data->lod_IData.idata_Gadget))
183 im->LeftEdge = (gad->Width - im->Width) / 2;
184 im->TopEdge = (gad->Height - im->Height) / 2;
188 im->ImageData = (UWORD *)im;
189 __tmp.magic = BUTTON_MAGIC_LONGWORD;
190 im->Width = __tmp.size.Width;
191 im->Height = __tmp.size.Height;
193 break;
195 case IM_DRAW:
196 data = INST_DATA(cl, im);
198 rp = imsg->imp_RPort;
200 SetDrMd(rp, JAM1);
201 oldfont = rp->Font;
202 font = OpenFont(data->lod_IData.idata_TextAttr);
204 if (font)
205 SetFont(rp, font);
206 else
207 SetFont(rp, GfxBase->DefaultFont);
209 SetSoftStyle(rp, data->lod_IData.idata_TextAttr->ta_Style, data->lod_IData.idata_TextAttr->ta_Style);
211 xpos = imsg->imp_Offset.X;
212 ypos = imsg->imp_Offset.Y;
214 pens = imsg->imp_DrInfo->dri_Pens;
215 if (!pens) pens = (UWORD *)defaultpens;
217 if ((gad = data->lod_IData.idata_Gadget))
219 xpos = gad->LeftEdge;
220 ypos = gad->TopEdge;
222 SetAPen(rp, pens[(imsg->imp_State == IDS_SELECTED) ? FILLPEN : BACKGROUNDPEN]);
224 RectFill(rp, xpos,
225 ypos,
226 gad->LeftEdge + gad->Width - 1,
227 gad->TopEdge + gad->Height -1 );
228 im->PlanePick = (imsg->imp_State == IDS_SELECTED) ? FILLTEXTPEN : TEXTPEN;
231 xpos += im->LeftEdge;
232 ypos += im->TopEdge;
234 SetAPen(rp, pens[im->PlanePick]);
236 Move(rp, xpos, ypos + rp->TxBaseline);
238 /* Draw first part of text (entire text if no underscore */
240 if (data->lod_UnderOff)
241 Text(rp, data->lod_IData.idata_Label, data->lod_UnderOff);
243 /* Is there an underscore in text */
245 if (im->PlaneOnOff)
247 /* First draw rest of text */
249 xpos = rp->cp_x;
251 Text(rp, data->lod_IData.idata_Label + data->lod_UnderOff + 1, data->lod_RestLen);
253 /* Draw underscore */
255 Move(rp, xpos, ypos + data->lod_UnderY);
256 Draw(rp, xpos + data->lod_UnderWidth - 1, ypos + data->lod_UnderY);
259 if (gad)
261 struct TagItem beveltags[] =
263 {GT_VisualInfo , (IPTR)data->lod_IData.idata_VisualInfo },
264 {GTBB_Recessed , TRUE },
265 {TAG_DONE }
268 if (imsg->imp_State != IDS_SELECTED) beveltags[1].ti_Tag = TAG_IGNORE;
270 /* draw bevelbox around gadget container (recessed if selected) */
272 DrawBevelBoxA(rp,
273 gad->LeftEdge,
274 gad->TopEdge,
275 gad->Width,
276 gad->Height,
277 beveltags);
280 SetFont(rp, oldfont);
281 if (font) CloseFont(font);
282 break;
284 default:
285 retval = DoSuperMethodA(cl, (Object *)im, msg);
286 break;
288 } /* switch(msg->MethodID) */
290 return retval;
291 #ifdef __AROS__
292 AROS_USERFUNC_EXIT
293 #endif
296 /****************************************************************************************/
297 /****************************************************************************************/