2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
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>
22 #include "asl_intern.h"
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] =
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
},
57 o
= (Object
*)DoSuperMethodA(cl
, o
, (Msg
)msg
);
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];
85 /***********************************************************************************/
87 IPTR
AslFontStyle__OM_DISPOSE(Class
* cl
, Object
* o
, Msg msg
)
89 struct AslFontStyleData
*data
;
92 data
= INST_DATA(cl
, o
);
93 if (data
->frame
) DisposeObject(data
->frame
);
95 retval
= DoSuperMethodA(cl
, o
, msg
);
100 /***********************************************************************************/
102 IPTR
AslFontStyle__OM_SET(Class
* cl
, Object
* o
, struct opSet
* msg
)
104 struct AslFontStyleData
*data
;
106 const struct TagItem
*tstate
= msg
->ops_AttrList
;
111 data
= INST_DATA(cl
, o
);
113 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
115 while((tag
= NextTagItem(&tstate
)))
120 data
->style
= tag
->ti_Data
;
129 if ((rp
= ObtainGIRPort(msg
->ops_GInfo
)))
133 gpr
.MethodID
= GM_RENDER
;
134 gpr
.gpr_GInfo
= msg
->ops_GInfo
;
136 gpr
.gpr_Redraw
= GREDRAW_UPDATE
;
138 DoMethodA(o
, (Msg
)&gpr
);
148 /***********************************************************************************/
150 IPTR
AslFontStyle__OM_GET(Class
*cl
, Object
*o
, struct opGet
*msg
)
152 struct AslFontStyleData
*data
= INST_DATA(cl
, o
);
156 switch(msg
->opg_AttrID
)
159 *msg
->opg_Storage
= data
->style
;
163 retval
= DoSuperMethodA(cl
, o
, (Msg
)msg
);
171 /***********************************************************************************/
173 IPTR
AslFontStyle__GM_RENDER(Class
*cl
, struct Gadget
*g
, struct gpRender
*msg
)
175 struct AslFontStyleData
*data
;
177 WORD x
, y
, w
, h
, i
, sw
;
179 getgadgetcoords(g
, msg
->gpr_GInfo
, &x
, &y
, &w
, &h
);
181 data
= INST_DATA(cl
, g
);
188 SetAttrs(data
->frame
, IA_Width
, sw
,
193 for(i
= 0; i
< 3; i
++)
195 struct TextExtent te
;
198 set
= (data
->style
& gadindextostylemap
[i
]) ? TRUE
: FALSE
;
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
]);
215 TextExtent(rp
, data
->text
[i
], strlen(data
->text
[i
]), &te
);
216 w
= te
.te_Extent
.MaxX
- te
.te_Extent
.MinX
+ 1;
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
]));
229 /***********************************************************************************/
231 IPTR
AslFontStyle__GM_GOACTIVE(Class
*cl
, struct Gadget
*g
, struct gpInput
*msg
)
233 struct AslFontStyleData
*data
;
237 if (!msg
->gpi_IEvent
) return GMR_NOREUSE
;
239 getgadgetcoords(g
, msg
->gpi_GInfo
, &x
, &y
, &w
, &h
);
241 data
= INST_DATA(cl
, g
);
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
)))
253 gpr
.MethodID
= GM_RENDER
;
254 gpr
.gpr_GInfo
= msg
->gpi_GInfo
;
256 gpr
.gpr_Redraw
= GREDRAW_UPDATE
;
258 DoMethodA((Object
*)g
, (Msg
)&gpr
);
263 *msg
->gpi_Termination
= data
->style
;
265 return GMR_NOREUSE
| GMR_VERIFY
;
269 /***********************************************************************************/