forwarding build fix when MUIA_Scrollgroup_AutoBars is defined (NicJA).
[AROS-Contrib.git] / scalos / main / GadgetBarTextClass.c
blob298f988389f8eab0c9929b2b7426efa4a3f7f32a
1 // GadgetBarTextClass.c
2 // $Date$
3 // $Revision$
6 #include <exec/types.h>
7 #include <graphics/gels.h>
8 #include <graphics/rastport.h>
9 #include <intuition/classes.h>
10 #include <intuition/classusr.h>
11 #include <intuition/imageclass.h>
12 #include <intuition/newmouse.h>
13 #include <utility/hooks.h>
14 #include <libraries/gadtools.h>
15 #include <datatypes/pictureclass.h>
16 #include <workbench/workbench.h>
17 #include <workbench/startup.h>
18 #include <cybergraphx/cybergraphics.h>
19 #include <dos/dostags.h>
20 #include <dos/datetime.h>
22 #define __USE_SYSBASE
24 #include <proto/dos.h>
25 #include <proto/exec.h>
26 #include <proto/layers.h>
27 #include <proto/intuition.h>
28 #include <proto/graphics.h>
29 #include <proto/utility.h>
30 #include <proto/locale.h>
31 #include <proto/iconobject.h>
32 #include <proto/cybergraphics.h>
33 #include <proto/gadtools.h>
34 #include <proto/datatypes.h>
35 #include "debug.h"
36 #include <proto/scalos.h>
38 #include <clib/alib_protos.h>
40 #include <defs.h>
41 #include <datatypes/iconobject.h>
42 #include <scalos/scalos.h>
43 #include <scalos/GadgetBar.h>
45 #include <stdlib.h>
46 #include <stdio.h>
47 #include <string.h>
49 #include "scalos_structures.h"
50 #include "functions.h"
51 #include "Variables.h"
53 //----------------------------------------------------------------------------
54 // Revision history :
56 // 20011101 jl initial history
57 //----------------------------------------------------------------------------
59 // local data definitions
61 struct GadgetBarTextClassInst
63 STRPTR gbtcl_Text;
64 struct TextFont *gbtcl_Font;
65 struct TTFontFamily *gbtcl_TTFont; // TTengine font
66 WORD gbtcl_TextPen;
67 WORD gbtcl_BGPen;
68 WORD gbtcl_DrawMode;
69 WORD gbtcl_Justification; // GACT_STRINGLEFT, GACT_STRINGRIGHT, GACT_STRINGCENTER
70 ULONG gbtcl_SoftStyle; // FSF_BOLD, FSF_ITALIC, FSF_UNDERLINED, ...
71 struct TextExtent gbtcl_Extent;
72 ULONG gbtcl_Chars; // number of chars that fit within the gadget
73 BOOL gbtcl_NeedLayout;
76 //----------------------------------------------------------------------------
78 // local functions
80 static SAVEDS(IPTR) INTERRUPT GadgetBarTextClassDispatcher(Class *cl, Object *o, Msg msg);
81 static IPTR GadgetBarText_New(Class *cl, Object *o, Msg msg);
82 static ULONG GadgetBarText_Dispose(Class *cl, Object *o, Msg msg);
83 static ULONG GadgetBarText_Set(Class *cl, Object *o, Msg msg);
84 static ULONG GadgetBarText_Get(Class *cl, Object *o, Msg msg);
85 static ULONG GadgetBarText_Layout(Class *cl, Object *o, Msg msg);
86 static ULONG GadgetBarText_Render(Class *cl, Object *o, Msg msg);
87 static ULONG GadgetBarText_HelpTest(Class *cl, Object *o, Msg msg);
88 static BOOL GadgetBarText_PointInGadget(const struct ExtGadget *gg, WORD x, WORD y);
90 //----------------------------------------------------------------------------
92 // public data items :
94 //----------------------------------------------------------------------------
96 struct ScalosClass *initGadgetBarTextClass(const struct PluginClass *plug)
98 struct ScalosClass *GadgetBarTextClass;
100 GadgetBarTextClass = SCA_MakeScalosClass(plug->plug_classname,
101 plug->plug_superclassname,
102 sizeof(struct GadgetBarTextClassInst),
103 NULL);
105 if (GadgetBarTextClass)
107 // initialize the cl_Dispatcher Hook
108 SETHOOKFUNC(GadgetBarTextClass->sccl_class->cl_Dispatcher, GadgetBarTextClassDispatcher);
111 return GadgetBarTextClass;
114 //----------------------------------------------------------------------------
116 static SAVEDS(IPTR) INTERRUPT GadgetBarTextClassDispatcher(Class *cl, Object *o, Msg msg)
118 IPTR Result;
120 switch (msg->MethodID)
122 case OM_NEW:
123 Result = GadgetBarText_New(cl, o, msg);
124 break;
125 case OM_DISPOSE:
126 Result = GadgetBarText_Dispose(cl, o, msg);
127 break;
128 case OM_SET:
129 Result = GadgetBarText_Set(cl, o, msg);
130 break;
131 case OM_GET:
132 Result = GadgetBarText_Get(cl, o, msg);
133 break;
134 case GM_RENDER:
135 Result = GadgetBarText_Render(cl, o, msg);
136 break;
137 case GM_LAYOUT:
138 Result = GadgetBarText_Layout(cl, o, msg);
139 break;
140 case GM_HELPTEST:
141 Result = GadgetBarText_HelpTest(cl, o, msg);
142 break;
143 case GM_HITTEST:
144 return 0;
145 break;
147 default:
148 Result = DoSuperMethodA(cl, o, msg);
149 break;
152 return Result;
155 //----------------------------------------------------------------------------
157 static IPTR GadgetBarText_New(Class *cl, Object *o, Msg msg)
159 struct opSet *ops = (struct opSet *) msg;
160 struct GadgetBarTextClassInst *inst;
161 struct ExtGadget *gg;
163 o = (Object *) DoSuperMethodA(cl, o, msg);
164 if (NULL == o)
165 return 0;
167 inst = INST_DATA(cl, o);
168 gg = (struct ExtGadget *) o;
170 memset(inst, 0, sizeof(struct GadgetBarTextClassInst));
172 gg->Width = GetTagData(GA_Width, 0, ops->ops_AttrList);
173 gg->Height = GetTagData(GA_Height, 0, ops->ops_AttrList);
175 gg->BoundsWidth = gg->Width;
176 gg->BoundsHeight = gg->Height;
178 inst->gbtcl_NeedLayout = TRUE;
180 inst->gbtcl_Text = (STRPTR) GetTagData(GBTDTA_Text, (IPTR) "", ops->ops_AttrList);
181 inst->gbtcl_Font = (struct TextFont *) GetTagData(GBTDTA_TextFont, (IPTR) iInfos.xii_iinfos.ii_Screen->RastPort.Font, ops->ops_AttrList);
182 inst->gbtcl_TTFont = (struct TTFontFamily *) GetTagData(GBTDTA_TTFont, (IPTR) &ScreenTTFont, ops->ops_AttrList);
183 inst->gbtcl_TextPen = GetTagData(GBTDTA_TextPen, PalettePrefs.pal_driPens[TEXTPEN], ops->ops_AttrList);
184 inst->gbtcl_BGPen = GetTagData(GBTDTA_BgPen, PalettePrefs.pal_driPens[BACKGROUNDPEN], ops->ops_AttrList);
185 inst->gbtcl_DrawMode = GetTagData(GBTDTA_DrawMode, JAM1, ops->ops_AttrList);
186 inst->gbtcl_Justification = GetTagData(GBTDTA_Justification, GACT_STRINGCENTER, ops->ops_AttrList);
187 inst->gbtcl_SoftStyle = GetTagData(GBTDTA_SoftStyle, FS_NORMAL, ops->ops_AttrList);
189 if (inst->gbtcl_Text)
190 inst->gbtcl_Text = AllocCopyString(inst->gbtcl_Text);
192 d1(KPrintF("%s/%s/%ld: gbtcl_Font=%08lx\n", __FILE__, __FUNC__, __LINE__, inst->gbtcl_Font));
193 d1(KPrintF("%s/%s/%ld: tf_YSize=%lu\n", __FILE__, __FUNC__, __LINE__, inst->gbtcl_Font->tf_YSize));
194 d1(KPrintF("%s/%s/%ld: ttff=%08lx Normal=%08lx Bold=%08lx Italic=%08lx BoldItalic=%08lx\n", \
195 __LINE__, inst->gbtcl_TTFont, inst->gbtcl_TTFont->ttff_Normal, \
196 inst->gbtcl_TTFont->ttff_Bold, inst->gbtcl_TTFont->ttff_Italic, \
197 inst->gbtcl_TTFont->ttff_BoldItalic));
199 if (inst->gbtcl_Text)
201 struct RastPort rp;
202 struct TextExtent tExt;
204 InitRastPort(&rp);
205 Scalos_SetFont(&rp, inst->gbtcl_Font, inst->gbtcl_TTFont);
206 Scalos_TextExtent(&rp, inst->gbtcl_Text, strlen(inst->gbtcl_Text), &tExt);
208 if (gg->Height < tExt.te_Height)
209 gg->Height = tExt.te_Height;
210 if (gg->BoundsHeight < tExt.te_Height)
211 gg->BoundsHeight = tExt.te_Height;
213 d1(kprintf("%s/%s/%ld: gg=%08lx Width=%ld Height=%ld\n", __FILE__, __FUNC__, __LINE__, gg, gg->Width, gg->Height));
215 return (IPTR) o;
218 //----------------------------------------------------------------------------
220 static ULONG GadgetBarText_Dispose(Class *cl, Object *o, Msg msg)
222 struct GadgetBarTextClassInst *inst = INST_DATA(cl, o);
224 if (inst->gbtcl_Text)
225 FreeCopyString(inst->gbtcl_Text);
227 return DoSuperMethodA(cl, o, msg);
230 //----------------------------------------------------------------------------
232 static ULONG GadgetBarText_Get(Class *cl, Object *o, Msg msg)
234 struct opGet *opg = (struct opGet *) msg;
235 struct GadgetBarTextClassInst *inst = INST_DATA(cl, o);
236 struct Gadget *gg = (struct Gadget *) o;
237 ULONG Result = 1;
239 d1(KPrintF("%s/%s/%ld: AttrID=%08lx\n", __FILE__, __FUNC__, __LINE__, opg->opg_AttrID));
241 switch (opg->opg_AttrID)
243 case GA_Left: // required since gadgetclass attribute is [IS] - no support for [G]
244 *(opg->opg_Storage) = (IPTR) gg->LeftEdge;
245 break;
246 case GA_Top: // required since gadgetclass attribute is [IS] - no support for [G]
247 *(opg->opg_Storage) = (IPTR) gg->TopEdge;
248 break;
249 case GA_Width: // required since gadgetclass attribute is [IS] - no support for [G]
250 *(opg->opg_Storage) = (IPTR) gg->Width;
251 break;
252 case GA_Height: // required since gadgetclass attribute is [IS] - no support for [G]
253 *(opg->opg_Storage) = (IPTR) gg->Height;
254 break;
255 case GBTDTA_Text:
256 *(opg->opg_Storage) = (IPTR) inst->gbtcl_Text;
257 break;
258 case GBTDTA_TextFont:
259 *(opg->opg_Storage) = (IPTR) inst->gbtcl_Font;
260 break;
261 case GBTDTA_TextPen:
262 *(opg->opg_Storage) = inst->gbtcl_TextPen;
263 break;
264 case GBTDTA_BgPen:
265 *(opg->opg_Storage) = inst->gbtcl_BGPen;
266 break;
267 case GBTDTA_DrawMode:
268 *(opg->opg_Storage) = inst->gbtcl_DrawMode;
269 break;
270 case GBTDTA_Justification:
271 *(opg->opg_Storage) = inst->gbtcl_Justification;
272 break;
273 case GBTDTA_SoftStyle:
274 *(opg->opg_Storage) = inst->gbtcl_SoftStyle;
275 break;
276 default:
277 Result = DoSuperMethodA(cl, o, msg);
278 break;
281 return Result;
284 //----------------------------------------------------------------------------
286 static ULONG GadgetBarText_Set(Class *cl, Object *o, Msg msg)
288 struct GadgetBarTextClassInst *inst = INST_DATA(cl, o);
289 struct opSet *ops = (struct opSet *) msg;
290 struct ExtGadget *gg = (struct ExtGadget *) o;
292 if (FindTagItem(GBTDTA_Text, ops->ops_AttrList))
294 STRPTR NewText = (STRPTR) GetTagData(GBTDTA_Text, (IPTR) inst->gbtcl_Text, ops->ops_AttrList);
296 if (inst->gbtcl_Text)
297 FreeCopyString(inst->gbtcl_Text);
299 inst->gbtcl_Text = AllocCopyString(NewText);
300 inst->gbtcl_NeedLayout = TRUE;
303 inst->gbtcl_Font = (struct TextFont *) GetTagData(GBTDTA_TextFont, (IPTR) inst->gbtcl_Font, ops->ops_AttrList);
304 inst->gbtcl_TTFont = (struct TTFontFamily *) GetTagData(GBTDTA_TTFont, (IPTR) inst->gbtcl_TTFont, ops->ops_AttrList);
305 inst->gbtcl_TextPen = GetTagData(GBTDTA_TextPen, inst->gbtcl_TextPen, ops->ops_AttrList);
306 inst->gbtcl_BGPen = GetTagData(GBTDTA_BgPen, inst->gbtcl_BGPen, ops->ops_AttrList);
307 inst->gbtcl_DrawMode = GetTagData(GBTDTA_DrawMode, inst->gbtcl_DrawMode, ops->ops_AttrList);
308 inst->gbtcl_Justification = GetTagData(GBTDTA_Justification, inst->gbtcl_Justification, ops->ops_AttrList);
309 inst->gbtcl_SoftStyle = GetTagData(GBTDTA_SoftStyle, inst->gbtcl_SoftStyle, ops->ops_AttrList);
311 if ( FindTagItem(GBTDTA_TextFont, ops->ops_AttrList)
312 || FindTagItem(GBTDTA_TTFont, ops->ops_AttrList)
313 || FindTagItem(GBTDTA_DrawMode, ops->ops_AttrList)
314 || FindTagItem(GBTDTA_SoftStyle, ops->ops_AttrList)
315 || FindTagItem(GA_Width, ops->ops_AttrList)
316 || FindTagItem(GA_Height, ops->ops_AttrList) )
318 inst->gbtcl_NeedLayout = TRUE;
321 gg->BoundsLeftEdge = GetTagData(GA_Left, gg->BoundsLeftEdge, ops->ops_AttrList);
322 gg->BoundsTopEdge = GetTagData(GA_Top, gg->BoundsTopEdge, ops->ops_AttrList);
323 gg->BoundsWidth = GetTagData(GA_Width, gg->BoundsWidth, ops->ops_AttrList);
324 gg->BoundsHeight = GetTagData(GA_Height, gg->BoundsHeight, ops->ops_AttrList);
325 gg->Width = GetTagData(GA_Width, gg->Width, ops->ops_AttrList);
326 gg->Height = GetTagData(GA_Height, gg->Height, ops->ops_AttrList);
328 d1(kprintf("%s/%s/%ld: gg=%08lx Width=%ld Height=%ld\n", __FILE__, __FUNC__, __LINE__, gg, gg->Width, gg->Height));
330 return DoSuperMethodA(cl, o, msg);
333 //----------------------------------------------------------------------------
335 static ULONG GadgetBarText_Layout(Class *cl, Object *o, Msg msg)
337 struct gpLayout *gpl = (struct gpLayout *) msg;
338 struct GadgetBarTextClassInst *inst = INST_DATA(cl, o);
339 struct ExtGadget *gg = (struct ExtGadget *) o;
341 d1(KPrintF("%s/%s/%ld: Left=%ld Top=%ld gpl_Initial=%ld\n", \
342 __FILE__, __FUNC__, __LINE__, gg->LeftEdge, gg->TopEdge, gpl->gpl_Initial));
344 if (gpl->gpl_Initial)
346 struct RastPort rp;
347 WORD /* NewWidth, */ NewHeight;
349 Scalos_InitRastPort(&rp);
351 Scalos_SetFont(&rp, inst->gbtcl_Font, inst->gbtcl_TTFont);
353 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
355 SetABPenDrMd(&rp,
356 inst->gbtcl_TextPen,
357 inst->gbtcl_BGPen,
358 inst->gbtcl_DrawMode);
360 inst->gbtcl_Chars = strlen(inst->gbtcl_Text);
362 Scalos_TextExtent(&rp,
363 inst->gbtcl_Text,
364 inst->gbtcl_Chars,
365 &inst->gbtcl_Extent);
367 if (inst->gbtcl_Extent.te_Width > gg->Width)
369 inst->gbtcl_Chars = Scalos_TextFit(&rp,
370 inst->gbtcl_Text,
371 inst->gbtcl_Chars,
372 &inst->gbtcl_Extent,
373 NULL,
375 gg->Width,
376 gg->Height + 2);
379 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
381 NewHeight = inst->gbtcl_Extent.te_Height + 1 + 1;
382 #if 0
383 NewWidth = inst->gbtcl_Extent.te_Width + 1 + 1;
385 if (gg->Width < NewWidth)
386 gg->Width = gg->BoundsWidth = NewWidth;
387 #endif
388 if (gg->Height < NewHeight)
389 gg->Height = gg->BoundsHeight = NewHeight;
391 d1(kprintf("%s/%s/%ld: gg=%08lx Width=%ld Height=%ld\n", __FILE__, __FUNC__, __LINE__, gg, gg->Width, gg->Height));
393 Scalos_DoneRastPort(&rp);
395 inst->gbtcl_NeedLayout = FALSE;
398 d1(kprintf("%s/%s/%ld: gg=%08lx Width=%ld Height=%ld\n", __FILE__, __FUNC__, __LINE__, gg, gg->Width, gg->Height));
400 return 1;
403 //----------------------------------------------------------------------------
405 static ULONG GadgetBarText_Render(Class *cl, Object *o, Msg msg)
407 struct gpRender *gpr = (struct gpRender *) msg;
408 struct GadgetBarTextClassInst *inst = INST_DATA(cl, o);
409 struct ExtGadget *gg = (struct ExtGadget *) o;
410 WORD x, y;
412 d1(KPrintF("%s/%s/%ld: o=%08lx Left=%ld Top=%ld\n", __FILE__, __FUNC__, __LINE__, o, gg->LeftEdge, gg->TopEdge));
413 d1(kprintf("%s/%s/%ld: gg=%08lx Width=%ld Height=%ld\n", __FILE__, __FUNC__, __LINE__, gg, gg->Width, gg->Height));
415 if (inst->gbtcl_NeedLayout)
417 DoMethod(o, GM_LAYOUT,
418 (IPTR) gpr->gpr_GInfo,
419 TRUE);
422 Scalos_DoneRastPort(gpr->gpr_RPort);
423 Scalos_SetFont(gpr->gpr_RPort, inst->gbtcl_Font, inst->gbtcl_TTFont);
425 d1(kprintf("%s/%s/%ld: <%s\n", __FILE__, __FUNC__, __LINE__, inst->gbtcl_Text));
426 Scalos_SetSoftStyle(gpr->gpr_RPort, inst->gbtcl_SoftStyle, inst->gbtcl_SoftStyle, inst->gbtcl_TTFont);
428 SetABPenDrMd(gpr->gpr_RPort,
429 inst->gbtcl_TextPen,
430 inst->gbtcl_BGPen,
431 inst->gbtcl_DrawMode);
433 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
435 x = gg->LeftEdge;
436 y = gg->TopEdge;
438 switch (inst->gbtcl_Justification)
440 case GACT_STRINGLEFT:
441 break;
442 case GACT_STRINGRIGHT:
443 x += gg->Width - inst->gbtcl_Extent.te_Extent.MaxX;
444 break;
445 case GACT_STRINGCENTER:
446 x += (gg->Width - inst->gbtcl_Extent.te_Width) / 2;
447 break;
450 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
452 y += (gg->Height - inst->gbtcl_Extent.te_Height) / 2 + Scalos_GetFontBaseline(gpr->gpr_RPort);
454 #if 0
455 // DEBUG: draw border around text gadget
456 Move(gpr->gpr_RPort, gg->LeftEdge, gg->TopEdge);
457 Draw(gpr->gpr_RPort, gg->LeftEdge + gg->Width, gg->TopEdge);
458 Draw(gpr->gpr_RPort, gg->LeftEdge + gg->Width, gg->TopEdge + gg->Height);
459 Draw(gpr->gpr_RPort, gg->LeftEdge, gg->TopEdge + gg->Height);
460 Draw(gpr->gpr_RPort, gg->LeftEdge, gg->TopEdge);
461 #endif
463 Move(gpr->gpr_RPort, x, y);
464 Scalos_Text(gpr->gpr_RPort, inst->gbtcl_Text, inst->gbtcl_Chars);
466 d1(kprintf("%s/%s/%ld: \n", __FILE__, __FUNC__, __LINE__));
468 return 1;
471 //----------------------------------------------------------------------------
473 static ULONG GadgetBarText_HelpTest(Class *cl, Object *o, Msg msg)
475 struct gpHitTest *gpht = (struct gpHitTest *) msg;
477 d1(KPrintF("%s/%s/%ld: Object=%08lx\n", __FILE__, __FUNC__, __LINE__, o));
479 if (GadgetBarText_PointInGadget((struct ExtGadget *) o, gpht->gpht_Mouse.X, gpht->gpht_Mouse.Y))
481 d1(KPrintF("%s/%s/%ld: Result=GMR_HELPHIT\n", __FILE__, __FUNC__, __LINE__));
482 return GMR_HELPHIT;
485 d1(KPrintF("%s/%s/%ld: Result=GMR_NOHELPHIT\n", __FILE__, __FUNC__, __LINE__));
487 return GMR_NOHELPHIT;
490 //----------------------------------------------------------------------------
492 static BOOL GadgetBarText_PointInGadget(const struct ExtGadget *gg, WORD x, WORD y)
494 if (x < 0)
495 return FALSE;
496 if (y < 0)
497 return FALSE;
498 if (x >= gg->Width)
499 return FALSE;
500 if (y >= gg->Height)
501 return FALSE;
503 return TRUE;
506 //----------------------------------------------------------------------------