1 // GadgetBarTextClass.c
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>
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>
36 #include <proto/scalos.h>
38 #include <clib/alib_protos.h>
41 #include <datatypes/iconobject.h>
42 #include <scalos/scalos.h>
43 #include <scalos/GadgetBar.h>
49 #include "scalos_structures.h"
50 #include "functions.h"
51 #include "Variables.h"
53 //----------------------------------------------------------------------------
56 // 20011101 jl initial history
57 //----------------------------------------------------------------------------
59 // local data definitions
61 struct GadgetBarTextClassInst
64 struct TextFont
*gbtcl_Font
;
65 struct TTFontFamily
*gbtcl_TTFont
; // TTengine font
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 //----------------------------------------------------------------------------
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
),
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
)
120 switch (msg
->MethodID
)
123 Result
= GadgetBarText_New(cl
, o
, msg
);
126 Result
= GadgetBarText_Dispose(cl
, o
, msg
);
129 Result
= GadgetBarText_Set(cl
, o
, msg
);
132 Result
= GadgetBarText_Get(cl
, o
, msg
);
135 Result
= GadgetBarText_Render(cl
, o
, msg
);
138 Result
= GadgetBarText_Layout(cl
, o
, msg
);
141 Result
= GadgetBarText_HelpTest(cl
, o
, msg
);
148 Result
= DoSuperMethodA(cl
, o
, msg
);
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
);
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
)
202 struct TextExtent tExt
;
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
));
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
;
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
;
246 case GA_Top
: // required since gadgetclass attribute is [IS] - no support for [G]
247 *(opg
->opg_Storage
) = (IPTR
) gg
->TopEdge
;
249 case GA_Width
: // required since gadgetclass attribute is [IS] - no support for [G]
250 *(opg
->opg_Storage
) = (IPTR
) gg
->Width
;
252 case GA_Height
: // required since gadgetclass attribute is [IS] - no support for [G]
253 *(opg
->opg_Storage
) = (IPTR
) gg
->Height
;
256 *(opg
->opg_Storage
) = (IPTR
) inst
->gbtcl_Text
;
258 case GBTDTA_TextFont
:
259 *(opg
->opg_Storage
) = (IPTR
) inst
->gbtcl_Font
;
262 *(opg
->opg_Storage
) = inst
->gbtcl_TextPen
;
265 *(opg
->opg_Storage
) = inst
->gbtcl_BGPen
;
267 case GBTDTA_DrawMode
:
268 *(opg
->opg_Storage
) = inst
->gbtcl_DrawMode
;
270 case GBTDTA_Justification
:
271 *(opg
->opg_Storage
) = inst
->gbtcl_Justification
;
273 case GBTDTA_SoftStyle
:
274 *(opg
->opg_Storage
) = inst
->gbtcl_SoftStyle
;
277 Result
= DoSuperMethodA(cl
, o
, msg
);
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
)
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__
));
358 inst
->gbtcl_DrawMode
);
360 inst
->gbtcl_Chars
= strlen(inst
->gbtcl_Text
);
362 Scalos_TextExtent(&rp
,
365 &inst
->gbtcl_Extent
);
367 if (inst
->gbtcl_Extent
.te_Width
> gg
->Width
)
369 inst
->gbtcl_Chars
= Scalos_TextFit(&rp
,
379 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
381 NewHeight
= inst
->gbtcl_Extent
.te_Height
+ 1 + 1;
383 NewWidth
= inst
->gbtcl_Extent
.te_Width
+ 1 + 1;
385 if (gg
->Width
< NewWidth
)
386 gg
->Width
= gg
->BoundsWidth
= NewWidth
;
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
));
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
;
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
,
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
,
431 inst
->gbtcl_DrawMode
);
433 d1(kprintf("%s/%s/%ld: \n", __FILE__
, __FUNC__
, __LINE__
));
438 switch (inst
->gbtcl_Justification
)
440 case GACT_STRINGLEFT
:
442 case GACT_STRINGRIGHT
:
443 x
+= gg
->Width
- inst
->gbtcl_Extent
.te_Extent
.MaxX
;
445 case GACT_STRINGCENTER
:
446 x
+= (gg
->Width
- inst
->gbtcl_Extent
.te_Width
) / 2;
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
);
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
);
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__
));
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__
));
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
)
506 //----------------------------------------------------------------------------