forwarding build fix when MUIA_Scrollgroup_AutoBars is defined (NicJA).
[AROS-Contrib.git] / scalos / main / DtImageClass.c
blobe12cbd8d5b8853b246f0fa9c70594bb9a067437e
1 // DtImageClass.c
2 // $Date$
3 // $Revision$
6 #include <exec/types.h>
7 #include <graphics/gels.h>
8 #include <graphics/gfxmacros.h>
9 #include <graphics/rastport.h>
10 #include <intuition/classes.h>
11 #include <intuition/classusr.h>
12 #include <intuition/imageclass.h>
13 #include <intuition/newmouse.h>
14 #include <utility/hooks.h>
15 #include <libraries/gadtools.h>
16 #include <datatypes/pictureclass.h>
17 #include <workbench/workbench.h>
18 #include <workbench/startup.h>
19 #include <cybergraphx/cybergraphics.h>
20 #include <dos/dostags.h>
21 #include <dos/datetime.h>
23 #define __USE_SYSBASE
25 #include <proto/dos.h>
26 #include <proto/exec.h>
27 #include <proto/layers.h>
28 #include <proto/intuition.h>
29 #include <proto/graphics.h>
30 #include <proto/utility.h>
31 #include <proto/locale.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 <scalos/scalos.h>
42 #include <scalos/GadgetBar.h>
44 #include <stdlib.h>
45 #include <stdio.h>
46 #include <string.h>
48 #include "scalos_structures.h"
49 #include "DtImageClass.h"
50 #include "functions.h"
51 #include "Variables.h"
53 //----------------------------------------------------------------------------
55 // local data definitions
57 struct DtImageClassInst
59 struct DatatypesImage *bmicl_DtImage;
60 struct DatatypesImage *bmicl_SelDtImage;
61 struct DatatypesImage *bmicl_DisabledDtImage;
64 //----------------------------------------------------------------------------
66 // local functions
68 static SAVEDS(IPTR) INTERRUPT DtImageClassDispatcher(Class *cl, Object *o, Msg msg);
69 static IPTR DtImage_New(Class *cl, Object *o, Msg msg);
70 static ULONG DtImage_Dispose(Class *cl, Object *o, Msg msg);
71 static ULONG DtImage_Draw(Class *cl, Object *o, Msg msg);
72 static ULONG DtImage_Get(Class *cl, Object *o, Msg msg);
74 //----------------------------------------------------------------------------
76 // public data items :
78 //----------------------------------------------------------------------------
80 Class *initDtImageClass(void)
82 Class *DtImageClass;
84 DtImageClass = MakeClass( NULL,
85 (STRPTR) IMAGECLASS,
86 NULL,
87 sizeof(struct DtImageClassInst),
88 0 );
90 if (DtImageClass)
92 // initialize the cl_Dispatcher Hook
93 SETHOOKFUNC(DtImageClass->cl_Dispatcher, DtImageClassDispatcher);
96 return DtImageClass;
99 //----------------------------------------------------------------------------
101 static SAVEDS(IPTR) INTERRUPT DtImageClassDispatcher(Class *cl, Object *o, Msg msg)
103 ULONG Result;
105 switch (msg->MethodID)
107 case OM_NEW:
108 Result = DtImage_New(cl, o, msg);
109 break;
110 case OM_DISPOSE:
111 Result = DtImage_Dispose(cl, o, msg);
112 break;
113 case IM_DRAW:
114 Result = DtImage_Draw(cl, o, msg);
115 break;
116 case OM_GET:
117 Result = DtImage_Get(cl, o, msg);
118 break;
119 default:
120 Result = DoSuperMethodA(cl, o, msg);
121 break;
124 return Result;
127 //----------------------------------------------------------------------------
129 static IPTR DtImage_New(Class *cl, Object *o, Msg msg)
131 struct opSet *ops = (struct opSet *) msg;
132 struct DtImageClassInst *inst;
133 CONST_STRPTR ImageName;
134 ULONG Width, Height;
136 o = (Object *) DoSuperMethodA(cl, o, msg);
137 d1(KPrintF("%s/%s/%ld: o=%08lx\n", __FILE__, __FUNC__, __LINE__, o));
138 if (NULL == o)
139 return 0;
141 inst = INST_DATA(cl, o);
143 memset(inst, 0, sizeof(struct DtImageClassInst));
145 ImageName = (CONST_STRPTR) GetTagData(DTIMG_ImageName, (IPTR) "", ops->ops_AttrList);
146 d1(KPrintF("%s/%s/%ld: o=%08lx ImageName=<%s>\n", __FILE__, __FUNC__, __LINE__, o, ImageName));
148 inst->bmicl_DtImage = CreateDatatypesImage(ImageName, 0);
149 d1(KPrintF("%s/%s/%ld: bmicl_DtImage=%08lx\n", __FILE__, __FUNC__, __LINE__, inst->bmicl_DtImage));
150 if (NULL == inst->bmicl_DtImage)
152 DoMethod(o, OM_DISPOSE);
153 return 0;
156 // Selected image is optional
157 ImageName = (CONST_STRPTR) GetTagData(DTIMG_SelImageName, (IPTR) "", ops->ops_AttrList);
158 d1(KPrintF("%s/%s/%ld: o=%08lx SelImageName=<%s>\n", __FILE__, __FUNC__, __LINE__, o, ImageName));
160 if (ImageName && strlen(ImageName) > 0)
161 inst->bmicl_SelDtImage = CreateDatatypesImage(ImageName, 0);
162 d1(KPrintF("%s/%s/%ld: bmicl_SelDtImage=%08lx\n", __FILE__, __FUNC__, __LINE__, inst->bmicl_SelDtImage));
164 // Disabled image is optional
165 ImageName = (CONST_STRPTR) GetTagData(DTIMG_DisabledImageName, (IPTR) "", ops->ops_AttrList);
166 d1(KPrintF("%s/%s/%ld: o=%08lx DisabledImageName=<%s>\n", __FILE__, __FUNC__, __LINE__, o, ImageName));
168 if (ImageName && strlen(ImageName) > 0)
169 inst->bmicl_DisabledDtImage = CreateDatatypesImage(ImageName, 0);
170 d1(KPrintF("%s/%s/%ld: bmicl_DisabledDtImage=%08lx\n", __FILE__, __FUNC__, __LINE__, inst->bmicl_DisabledDtImage));
174 // set dimensions in superclass
175 Width = inst->bmicl_DtImage->dti_BitMapHeader->bmh_Width;
176 Height = inst->bmicl_DtImage->dti_BitMapHeader->bmh_Height;
178 if (inst->bmicl_SelDtImage)
180 // use largest dimensions of normal and selected images
181 if (inst->bmicl_SelDtImage->dti_BitMapHeader->bmh_Width > Width)
182 Width = inst->bmicl_SelDtImage->dti_BitMapHeader->bmh_Width;
183 if (inst->bmicl_SelDtImage->dti_BitMapHeader->bmh_Height > Height)
184 Height = inst->bmicl_SelDtImage->dti_BitMapHeader->bmh_Height;
187 SetAttrs(o,
188 IA_Width, Width,
189 IA_Height, Height,
190 TAG_END);
192 return (IPTR) o;
195 //----------------------------------------------------------------------------
197 static ULONG DtImage_Dispose(Class *cl, Object *o, Msg msg)
199 struct DtImageClassInst *inst = INST_DATA(cl, o);
201 d1(KPrintF("%s/%s/%ld: o=%08lx bmicl_DtImage=%08lx\n", __FILE__, __FUNC__, __LINE__, o, inst->bmicl_DtImage));
203 DisposeDatatypesImage(&inst->bmicl_DtImage);
204 DisposeDatatypesImage(&inst->bmicl_SelDtImage);
205 DisposeDatatypesImage(&inst->bmicl_DisabledDtImage);
207 return DoSuperMethodA(cl, o, msg);
210 //----------------------------------------------------------------------------
212 static ULONG DtImage_Draw(Class *cl, Object *o, Msg msg)
214 struct impDraw *imp = (struct impDraw *) msg;
215 struct DtImageClassInst *inst = INST_DATA(cl, o);
216 struct Image *img = (struct Image *) o;
217 struct DatatypesImage *dtImg;
219 d1(KPrintF("%s/%s/%ld: o=%08lx Left=%ld Top=%ld\n", __FILE__, __FUNC__, __LINE__, o, img->LeftEdge, img->TopEdge));
220 d1(KPrintF("%s/%s/%ld: Width=%ld Height=%ld imp_State=%ld\n", __FILE__, __FUNC__, __LINE__, img->Width, img->Height, imp->imp_State));
221 d1(KPrintF("%s/%s/%ld: bmicl_SelDtImage=%08lx\n", __FILE__, __FUNC__, __LINE__, inst->bmicl_SelDtImage));
223 if ((IDS_SELECTED == imp->imp_State) && inst->bmicl_SelDtImage)
225 dtImg = inst->bmicl_SelDtImage;
227 else if ((IDS_DISABLED == imp->imp_State) && inst->bmicl_DisabledDtImage)
229 dtImg = inst->bmicl_DisabledDtImage;
231 else
233 dtImg = inst->bmicl_DtImage;
236 if (dtImg)
238 LONG x, y;
240 x = img->LeftEdge + imp->imp_Offset.X;
241 y = img->TopEdge + imp->imp_Offset.Y;
243 // if normal and selected images have different dimensions, center image in bounding rectangle
244 x += (img->Width - dtImg->dti_BitMapHeader->bmh_Width) / 2;
245 y += (img->Height - dtImg->dti_BitMapHeader->bmh_Height) / 2;
247 d1(kprintf("%s/%s/%ld: x=%ld y=%ld\n", __FILE__, __FUNC__, __LINE__, x, y));
249 DtImageDraw(dtImg,
250 imp->imp_RPort,
253 dtImg->dti_BitMapHeader->bmh_Width,
254 dtImg->dti_BitMapHeader->bmh_Height
258 if ((IDS_DISABLED == imp->imp_State) && NULL == inst->bmicl_DisabledDtImage)
260 static UWORD myPattern[] =
261 { 0x8888, 0x2222 };
262 LONG x, y;
264 x = img->LeftEdge + imp->imp_Offset.X;
265 y = img->TopEdge + imp->imp_Offset.Y;
267 // if normal and selected images have different dimensions, center image in bounding rectangle
268 x += (img->Width - dtImg->dti_BitMapHeader->bmh_Width) / 2;
269 y += (img->Height - dtImg->dti_BitMapHeader->bmh_Height) / 2;
271 SetABPenDrMd(imp->imp_RPort, 1, 0, JAM1);
272 SetAfPt(imp->imp_RPort, myPattern, 1);
274 RectFill(imp->imp_RPort, x, y,
275 x + img->Width - 1,
276 y + img->Height - 1);
279 d1(kprintf("%s/%s/%ld: END\n", __FILE__, __FUNC__, __LINE__));
281 return 1;
284 //----------------------------------------------------------------------------
286 static ULONG DtImage_Get(Class *cl, Object *o, Msg msg)
288 struct opGet *opg = (struct opGet *) msg;
289 struct DtImageClassInst *inst = INST_DATA(cl, o);
290 ULONG Result = 1;
292 if (NULL == opg->opg_Storage)
293 return 0;
295 switch (opg->opg_AttrID)
297 case IA_SupportsDisable:
298 *(opg->opg_Storage) = (ULONG) (NULL != inst->bmicl_DisabledDtImage);
299 break;
300 default:
301 Result = DoSuperMethodA(cl, o, msg);
302 break;
305 return Result;
308 //----------------------------------------------------------------------------