2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
10 #include <proto/exec.h>
11 #include <proto/dos.h>
12 #include <proto/utility.h>
13 #include <proto/intuition.h>
14 #include <exec/memory.h>
15 #include <intuition/screens.h>
16 #include <intuition/icclass.h>
17 #include <intuition/cghooks.h>
18 #include <intuition/imageclass.h>
19 #include <intuition/gadgetclass.h>
22 #include "asl_intern.h"
28 #include <aros/debug.h>
30 /*******************************************************************************************/
34 * temporarily..until included in our includes
37 /********************************************************************************/
38 /* imageclass.h AROS extensions */
40 #ifndef SYSIA_WithBorder
41 #define SYSIA_WithBorder IA_FGPen /* default: TRUE */
45 #define SYSIA_Style IA_BGPen /* default: SYSISTYLE_NORMAL */
47 #define SYSISTYLE_NORMAL 0
48 #define SYSISTYLE_GADTOOLS 1 /* to get arrow images in gadtools look */
53 /*******************************************************************************************/
55 #define G(x) ((struct Gadget *)(x))
56 #define EG(x) ((struct ExtGadget *)(x))
58 /*******************************************************************************************/
60 static const struct TagItem arrowinc_to_prop
[] =
66 static const struct TagItem arrowdec_to_prop
[] =
72 static const struct TagItem prop_to_lv
[] =
74 {PGA_Top
, ASLLV_TopPixel
},
78 static const struct TagItem lv_to_prop
[] =
80 {ASLLV_TopPixel
, PGA_Top
},
81 {ASLLV_TotalPixels
, PGA_Total
},
82 {ASLLV_VisiblePixels
, PGA_Visible
},
83 {ASLLV_DeltaFactor
, ASLSC_DeltaFactor
},
88 /*******************************************************************************************/
90 BOOL
makescrollergadget(struct ScrollerGadget
*scrollergad
, struct LayoutData
*ld
,
91 struct TagItem
*tags
, struct AslBase_intern
*AslBase
)
93 struct TagItem extraproptags
[] =
95 {PGA_NotifyBehaviour
, PG_BEHAVIOUR_NICE
},
96 {PGA_RenderBehaviour
, PG_BEHAVIOUR_NICE
},
100 struct TagItem
*ti
, *h_ti
, *w_ti
;
101 WORD x
= 0, y
= 0, w
= 0, h
= 0, aw
, ah
;
103 BOOL freehoriz
= (GetTagData(PGA_Freedom
, FREEVERT
, tags
) == FREEHORIZ
);
106 if ((ti
= FindTagItem(GA_Left
, tags
)))
109 } else if ((ti
= FindTagItem(GA_RelRight
, tags
)))
111 x
= ti
->ti_Data
; flags
|= GFLG_RELRIGHT
;
114 if ((ti
= FindTagItem(GA_Top
, tags
)))
117 } else if ((ti
= FindTagItem(GA_RelBottom
, tags
)))
119 y
= ti
->ti_Data
; flags
|= GFLG_RELBOTTOM
;
122 if ((w_ti
= FindTagItem(GA_Width
, tags
)))
125 } else if ((w_ti
= FindTagItem(GA_RelWidth
, tags
)))
127 w
= w_ti
->ti_Data
; flags
|= GFLG_RELWIDTH
;
130 if ((h_ti
= FindTagItem(GA_Height
, tags
)))
133 } else if ((h_ti
= FindTagItem(GA_RelHeight
, tags
)))
135 h
= h_ti
->ti_Data
; flags
|= GFLG_RELHEIGHT
;
142 if (w_ti
) w_ti
->ti_Data
= w
;
146 if (h_ti
) h_ti
->ti_Data
= h
;
149 extraproptags
[2].ti_Data
= (IPTR
)tags
;
150 if ((scrollergad
->prop
= NewObjectA(AslBase
->aslpropclass
, NULL
, extraproptags
)))
152 struct TagItem arrow_tags
[] =
154 {GA_Left
, freehoriz
? x
+ w
- 1 : x
},
155 {GA_Top
, freehoriz
? y
: y
+ h
- 1 },
158 {GA_RelVerify
, TRUE
},
159 {GA_Immediate
, TRUE
},
160 {GA_Previous
, (IPTR
)scrollergad
->prop
},
161 {GA_ID
, ID_ARROWDEC
},
165 if (flags
& GFLG_RELRIGHT
) arrow_tags
[0].ti_Tag
= GA_RelRight
;
166 if (flags
& GFLG_RELWIDTH
)
168 arrow_tags
[0].ti_Tag
= GA_RelRight
;
169 if (freehoriz
) arrow_tags
[0].ti_Data
+= 2;
172 if (flags
& GFLG_RELBOTTOM
) arrow_tags
[1].ti_Tag
= GA_RelBottom
;
173 if (flags
& GFLG_RELHEIGHT
)
175 arrow_tags
[1].ti_Tag
= GA_RelBottom
;
176 if (!freehoriz
) arrow_tags
[1].ti_Data
+= 2;
179 if ((scrollergad
->arrow1
= NewObjectA(AslBase
->aslarrowclass
, NULL
, arrow_tags
)))
183 arrow_tags
[0].ti_Data
+= aw
;
185 arrow_tags
[1].ti_Data
+= ah
;
187 arrow_tags
[6].ti_Data
= (IPTR
)scrollergad
->arrow1
;
188 arrow_tags
[7].ti_Data
= ID_ARROWINC
;
190 if ((scrollergad
->arrow2
= NewObjectA(AslBase
->aslarrowclass
, NULL
, arrow_tags
)))
192 struct TagItem image_tags
[] =
194 {SYSIA_Which
, freehoriz
? LEFTIMAGE
: UPIMAGE
},
195 {SYSIA_DrawInfo
, (IPTR
)ld
->ld_Dri
},
196 {SYSIA_Style
, SYSISTYLE_GADTOOLS
},
203 if ((im
= NewObjectA(NULL
, SYSICLASS
, image_tags
)))
205 SetAttrs(scrollergad
->arrow1
, GA_Image
, (IPTR
)im
,
208 image_tags
[0].ti_Data
= (freehoriz
? RIGHTIMAGE
: DOWNIMAGE
);
210 if ((im
= NewObjectA(NULL
, SYSICLASS
, image_tags
)))
212 #if USE_SAFE_NOTIFYING
213 struct TagItem ic_tags
[] =
215 {ICA_MAP
, (IPTR
) prop_to_lv
},
219 if ((scrollergad
->prop_ic
= NewObjectA(NULL
, ICCLASS
, ic_tags
)))
221 ic_tags
[0].ti_Data
= (IPTR
)lv_to_prop
;
223 if ((scrollergad
->listview_ic
= NewObjectA(NULL
, ICCLASS
, ic_tags
)))
226 struct TagItem set_tags
[] =
228 {ICA_TARGET
, (IPTR
) scrollergad
->prop
},
229 {ICA_MAP
, (IPTR
) arrowdec_to_prop
},
233 SetAttrs(scrollergad
->arrow2
, GA_Image
, (IPTR
)im
,
236 SetAttrsA(scrollergad
->arrow1
, set_tags
);
237 set_tags
[1].ti_Data
= (IPTR
)arrowinc_to_prop
;
238 SetAttrsA(scrollergad
->arrow2
, set_tags
);
242 #if USE_SAFE_NOTIFYING
244 } /* if ((scrollergad->listview_ic = NewObjectA(NULL, ICCLASS, ic_tags))) */
246 } /* if ((scrollergad->prop_ic = NewObjectA(NULL, ICCLASS, ic_tags))) */
250 } /* if ((im = NewObjectA(NULL, SYSICLASS, image_tags))) */
252 } /* if ((im = NewObject(NULL, SYSICLASS, image_tags))) */
254 } /* if ((scrollergad->arrow2 = NewObjectA(NULL, BUTTONGCLASS, arrow_tags))) */
256 } /* if (scrollergad->arrow1 = NewObjectA(NULL, BUTTONGCLASS, arrow_tags)) */
258 } /* if ((scrollergad->prop = NewObjectA(AslBase->aslpropclass, NULL, tags))) */
260 if (!result
) killscrollergadget(scrollergad
, AslBase
);
265 /*******************************************************************************************/
267 void killscrollergadget(struct ScrollerGadget
*scrollergad
, struct AslBase_intern
*AslBase
)
269 if (scrollergad
->prop
) DisposeObject(scrollergad
->prop
);
270 scrollergad
->prop
= NULL
;
272 if (scrollergad
->arrow1
)
274 if (G(scrollergad
->arrow1
)->GadgetRender
) DisposeObject(G(scrollergad
->arrow1
)->GadgetRender
);
275 DisposeObject(scrollergad
->arrow1
);
277 scrollergad
->arrow1
= NULL
;
279 if (scrollergad
->arrow2
)
281 if (G(scrollergad
->arrow2
)->GadgetRender
) DisposeObject(G(scrollergad
->arrow2
)->GadgetRender
);
282 DisposeObject(scrollergad
->arrow2
);
284 scrollergad
->arrow2
= NULL
;
286 #if USE_SAFE_NOTIFYING
287 if (scrollergad
->prop_ic
) DisposeObject(scrollergad
->prop_ic
);
288 scrollergad
->prop_ic
= NULL
;
290 if (scrollergad
->listview_ic
) DisposeObject(scrollergad
->listview_ic
);
291 scrollergad
->listview_ic
= NULL
;
295 /*******************************************************************************************/
297 void getgadgetcoords(struct Gadget
*gad
, struct GadgetInfo
*gi
, WORD
*x
, WORD
*y
, WORD
*w
, WORD
*h
)
299 *x
= gad
->LeftEdge
+ ((gad
->Flags
& GFLG_RELRIGHT
) ? gi
->gi_Domain
.Width
- 1 : 0);
300 *y
= gad
->TopEdge
+ ((gad
->Flags
& GFLG_RELBOTTOM
) ? gi
->gi_Domain
.Height
- 1 : 0);
301 *w
= gad
->Width
+ ((gad
->Flags
& GFLG_RELWIDTH
) ? gi
->gi_Domain
.Width
: 0);
302 *h
= gad
->Height
+ ((gad
->Flags
& GFLG_RELHEIGHT
) ? gi
->gi_Domain
.Height
: 0);
305 /*******************************************************************************************/
307 void getgadgetbounds(struct Gadget
*gad
, struct GadgetInfo
*gi
, WORD
*x
, WORD
*y
, WORD
*w
, WORD
*h
)
309 if (!(gad
->Flags
& GFLG_EXTENDED
) ||
310 !(EG(gad
)->MoreFlags
& GMORE_BOUNDS
))
312 return getgadgetcoords(gad
, gi
, x
, y
, w
, h
);
315 *x
= EG(gad
)->BoundsLeftEdge
+ ((gad
->Flags
& GFLG_RELRIGHT
) ? gi
->gi_Domain
.Width
- 1 : 0);
316 *y
= EG(gad
)->BoundsTopEdge
+ ((gad
->Flags
& GFLG_RELBOTTOM
) ? gi
->gi_Domain
.Height
- 1 : 0);
317 *w
= EG(gad
)->BoundsWidth
+ ((gad
->Flags
& GFLG_RELWIDTH
) ? gi
->gi_Domain
.Width
: 0);
318 *h
= EG(gad
)->BoundsHeight
+ ((gad
->Flags
& GFLG_RELHEIGHT
) ? gi
->gi_Domain
.Height
: 0);
321 /*******************************************************************************************/
323 void connectscrollerandlistview(struct ScrollerGadget
*scrollergad
, Object
*listview
,
324 struct AslBase_intern
*AslBase
)
326 #if USE_SAFE_NOTIFYING
328 struct TagItem ic_tags
[] =
330 {ICA_TARGET
, (IPTR
)listview
},
334 /* ICA_TARGET of prop ic is listview gadget */
335 SetAttrsA(scrollergad
->prop_ic
, ic_tags
);
337 /* ICA_TARGET of listview ic is prop gadget */
338 ic_tags
[0].ti_Data
= (IPTR
)scrollergad
->prop
;
339 SetAttrsA(scrollergad
->listview_ic
, ic_tags
);
341 /* ICA_TARGET of listview gadget is listview ic */
342 ic_tags
[0].ti_Data
= (IPTR
)scrollergad
->listview_ic
;
343 SetAttrsA(listview
, ic_tags
);
345 /* ICA_TARGET of prop gadget is prop ic */
346 ic_tags
[0].ti_Data
= (IPTR
)scrollergad
->prop_ic
;
347 SetAttrsA(scrollergad
->prop
, ic_tags
);
351 struct TagItem ic_tags
[] =
353 {ICA_TARGET
, (IPTR
)listview
},
354 {ICA_MAP
, (IPTR
)prop_to_lv
},
358 #warning This would not work in AmigaOS, because there gadgetclass is really lame and does not check for notifying loops
360 SetAttrsA(scrollergad
->prop
, ic_tags
);
362 ic_tags
[0].ti_Data
= (IPTR
)scrollergad
->prop
;
363 ic_tags
[1].ti_Data
= (IPTR
)lv_to_prop
;
365 SetAttrsA(listview
, ic_tags
);
370 /*******************************************************************************************/
372 void FreeObjects(Object
**first
, Object
**last
, struct AslBase_intern
*AslBase
)
376 for(objptr
= first
; objptr
!= last
+ 1; objptr
++)
380 DisposeObject(*objptr
);
386 /*******************************************************************************************/