SFS moved to core
[AROS-Contrib.git] / ScalosV2 / PanelClass.c
blobc1bdc2bc4423faf6849e2694b23494a3f3cb9fd6
1 // :ts=4 (Tabsize)
3 /*
4 ** Amiga Workbench® Replacement
5 **
6 ** (C) Copyright 1999,2000 Aliendesign
7 ** Stefan Sommerfeld, Jörg Rebenstorf
8 **
9 ** Redistribution and use in source and binary forms are permitted provided that
10 ** the above copyright notice and this paragraph are duplicated in all such
11 ** forms and that any documentation, advertising materials, and other
12 ** materials related to such distribution and use acknowledge that the
13 ** software was developed by Aliendesign.
14 ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
15 ** WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
16 ** MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 #include <proto/alib.h>
20 #include <proto/utility.h>
21 #include <proto/intuition.h>
22 #include <proto/graphics.h>
23 #include <intuition/classusr.h>
24 #include <graphics/gfx.h>
25 #include <stdlib.h>
27 #include "Scalos.h"
28 #include "PanelClass.h"
29 #include "SubRoutines.h"
31 #include "scalos_protos.h"
32 #include "Debug.h"
34 LONG oldright;
36 /****** Panel.scalos/--background *******************************************
38 * Panel class provides an interface for Lists. It's just a plane where the
39 * list elements can be displayed. Any scrolling and clipping will be
40 * handled by this class.
42 *****************************************************************************
44 // /
46 /** Init
48 static ULONG Panel_Init(struct SC_Class *cl, Object *obj, struct opSet *msg, struct PanelInst *inst)
50 if (SC_DoSuperMethodA(cl, obj, (Msg) msg))
52 inst->backbitmap = (Object *) GetTagData(SCCA_Panel_Background, 0,msg->ops_AttrList);
53 return(TRUE);
55 return(FALSE);
57 // /
59 /** Setup
61 static ULONG Panel_Setup(struct SC_Class *cl, Object *obj, Msg msg, struct PanelInst *inst)
63 if (SC_DoSuperMethodA(cl,obj,msg))
65 if (inst->backbitmap)
66 if (!(SC_DoMethod(inst->backbitmap, SCCM_Graphic_PreThinkScreen, scRenderInfo(obj)->screenobj)))
67 return(FALSE);
68 if ((inst->clipregion = NewRegion()))
69 return(TRUE);
71 inst->oldleftpos = 0x8000;
73 return(FALSE);
75 // /
77 /** Show
79 static void Panel_Show(struct SC_Class *cl, Object *obj, struct SCCP_Area_Show *msg, struct PanelInst *inst)
81 struct Rectangle rect;
83 SC_DoSuperMethodA(cl,obj,(Msg) msg);
85 ClearRegion(inst->clipregion);
86 rect.MinX = _scleft(obj);
87 rect.MinY = _sctop(obj);
88 rect.MaxX = _scright(obj);
89 rect.MaxY = _scbottom(obj);
90 OrRectRegion(inst->clipregion,&rect);
92 if (msg->action == SCCV_Area_Action_Resize)
94 if ((_scleft(obj) == inst->oldleftpos) && (_sctop(obj) == inst->oldtoppos))
96 // if ((_scright(obj) > inst->oldright) || (_scbottom(obj) > inst->oldbottom))
98 if ((inst->refreshregion = NewRegion()))
100 OrRectRegion(inst->refreshregion,&rect);
101 rect.MaxX = inst->oldright;
102 rect.MaxY = inst->oldbottom;
103 ClearRectRegion(inst->refreshregion,&rect);
108 else
110 if (inst->backbitmap)
111 if (!(SC_DoMethod(inst->backbitmap, SCCM_Graphic_PreThinkWindow, scRenderInfo(obj)->rport, msg->action)))
113 SC_DoMethod(inst->backbitmap, SCCM_Graphic_PostThinkScreen);
114 SC_DisposeObject(inst->backbitmap);
115 inst->backbitmap = NULL;
121 // /
123 /** Hide
125 static void Panel_Hide(struct SC_Class *cl, Object *obj, struct SCCP_Area_Hide *msg, struct PanelInst *inst)
127 if (msg->action != SCCV_Area_Action_Resize)
129 if (inst->backbitmap)
130 if (!(SC_DoMethod(inst->backbitmap, SCCM_Graphic_PostThinkWindow, msg->action)))
132 SC_DoMethod(inst->backbitmap, SCCM_Graphic_PostThinkScreen);
133 SC_DisposeObject(inst->backbitmap);
134 inst->backbitmap = NULL;
137 SC_DoSuperMethodA(cl, obj, (Msg) msg);
139 // /
141 /** Cleanup
143 static void Panel_Cleanup(struct SC_Class *cl, Object *obj, Msg msg, struct PanelInst *inst)
145 if(inst->backbitmap)
146 SC_DoMethod(inst->backbitmap, SCCM_Graphic_PostThinkScreen);
147 DisposeRegion(inst->clipregion);
149 SC_DoSuperMethodA(cl, obj, msg);
151 // /
153 /** Exit
155 static void Panel_Exit(struct SC_Class *cl, Object *obj, Msg msg, struct PanelInst *inst)
157 if(inst->backbitmap)
158 SC_DisposeObject(inst->backbitmap);
160 SC_DoSuperMethodA(cl, obj, msg);
162 // /
164 /** AskMinMax
166 static void Panel_AskMinMax(struct SC_Class *cl, Object *obj, struct SCCP_Area_AskMinMax *msg, struct PanelInst *inst)
168 SC_DoSuperMethodA(cl,obj, (Msg) msg);
169 msg->sizes->minwidth += 1;
170 msg->sizes->minheight += 1;
171 msg->sizes->maxwidth = SCCV_Area_MaxSize;
172 msg->sizes->maxheight = SCCV_Area_MaxSize;
173 msg->sizes->defwidth += 100;
174 msg->sizes->defheight += 100;
176 // /
178 /** SetIDCMP
180 static void Panel_SetIDCMP(struct SC_Class *cl, Object *obj, struct SCCP_Area_SetIDCMP *msg, struct PanelInst *inst)
182 msg->IDCMP |= inst->idcmp;
183 SC_DoSuperMethodA(cl, obj, (Msg) msg);
185 // /
187 /** BeginDraw
189 static ULONG Panel_BeginDraw(struct SC_Class *cl, Object *obj, struct SCCP_Area_BeginDraw *msg, struct PanelInst *inst)
191 if (SC_DoSuperMethodA(cl, obj, (Msg) msg))
193 SC_DoMethod(_scwinobj(obj),SCCM_Window_SetClipRegion,inst->clipregion);
194 return(TRUE);
196 return(FALSE);
198 // /
200 /** EndDraw
202 static void Panel_EndDraw(struct SC_Class *cl, Object *obj, struct SCCP_Area_EndDraw *msg, struct PanelInst *inst)
204 SC_DoMethod(_scwinobj(obj),SCCM_Window_ClearClipRegion);
206 SC_DoSuperMethodA(cl, obj, (Msg) msg);
208 // /
211 /** Draw
213 static void Panel_Draw(struct SC_Class *cl, Object *obj, struct SCCP_Area_Draw *msg, struct PanelInst *inst)
215 SC_DoSuperMethodA(cl, obj, (Msg) msg);
217 DEBUG3("Old Size %ld,%ld : %ld\n",inst->oldright,inst->oldbottom,oldright);
218 DEBUG2("New Size %ld,%ld\n",_scright(obj),_scbottom(obj));
220 oldright = _scright(obj);
221 if (inst->refreshregion)
223 SC_DoMethod(_scwinobj(obj),SCCM_Window_SetClipRegion,inst->refreshregion);
225 if (inst->backbitmap)
226 DoMethod(inst->backbitmap,SCCM_Bitmap_Fill, _scleft(obj), _sctop(obj), _scright(obj), _scbottom(obj), inst->left, inst->top,SCCV_Bitmap_Fill_BlitType_Clipped);
227 else
228 EraseRect(_scrport(obj), _scleft(obj), _sctop(obj), _scright(obj), _scbottom(obj));
230 SC_DoMethod(obj,SCCM_Panel_Redraw,SCCV_Area_Drawtype_Complete);
232 SC_DoMethod(_scwinobj(obj),SCCM_Window_ClearClipRegion);
234 DisposeRegion(inst->refreshregion);
236 inst->refreshregion = NULL;
238 else
241 SC_DoMethod(_scwinobj(obj),SCCM_Window_SetClipRegion,inst->clipregion);
243 if (inst->backbitmap)
244 DoMethod(inst->backbitmap,SCCM_Bitmap_Fill, _scleft(obj), _sctop(obj), _scright(obj), _scbottom(obj), inst->left, inst->top,SCCV_Bitmap_Fill_BlitType_Clipped);
245 else
246 EraseRect(_scrport(obj), _scleft(obj), _sctop(obj), _scright(obj), _scbottom(obj));
248 SC_DoMethod(obj,SCCM_Panel_Redraw,SCCV_Area_Drawtype_Complete);
250 SC_DoMethod(_scwinobj(obj),SCCM_Window_ClearClipRegion);
252 inst->oldleft = inst->left;
253 inst->oldtop = inst->top;
255 inst->oldleftpos = _scleft(obj);
256 inst->oldtoppos = _sctop(obj);
257 inst->oldright = _scright(obj);
258 inst->oldbottom = _scbottom(obj);
261 void drawScroll(struct SC_Class *cl, Object *obj,struct PanelInst *inst)
263 if (SC_DoMethod(_scwinobj(obj), SCCM_Window_BeginDraw,obj))
265 if ((inst->oldleft != inst->left) || (inst->oldtop != inst->top))
267 struct Region *region;
268 struct Rectangle rect;
269 LONG diffx = inst->left - inst->oldleft;
270 LONG diffy = inst->top - inst->oldtop;
272 if (((_scwidth(obj)/2) < abs(diffx)) || ((_scheight(obj)/2) < abs(diffy)))
274 if (inst->backbitmap)
275 DoMethod(inst->backbitmap,SCCM_Bitmap_Fill, _scleft(obj), _sctop(obj), _scright(obj), _scbottom(obj), inst->left, inst->top,SCCV_Bitmap_Fill_BlitType_Clipped);
276 else
277 EraseRect(_scrport(obj), _scleft(obj), _sctop(obj), _scright(obj), _scbottom(obj));
279 SC_DoMethod(obj,SCCM_Panel_Redraw,SCCV_Area_Drawtype_Complete);
281 else
283 if ((region = NewRegion()))
285 rect.MinX = _scleft(obj);
286 rect.MinY = _sctop(obj);
287 rect.MaxX = _scright(obj);
288 rect.MaxY = _scbottom(obj);
289 OrRectRegion(region, &rect);
291 rect.MinX -= diffx;
292 rect.MinY -= diffy;
293 rect.MaxX -= diffx + 1;
294 rect.MaxY -= diffy + 1;
295 ClearRectRegion(region, &rect);
297 ScrollWindowRaster(scRenderInfo(obj)->window, diffx, diffy,
298 _scleft(obj), _sctop(obj), _scright(obj), _scbottom(obj));
300 if (inst->backbitmap)
302 if (diffx < 0)
303 DoMethod(inst->backbitmap,SCCM_Bitmap_Fill, _scleft(obj), _sctop(obj), _scleft(obj) - diffx - 1, _scbottom(obj), inst->left, inst->top,SCCV_Bitmap_Fill_BlitType_Clipped);
304 else
305 DoMethod(inst->backbitmap,SCCM_Bitmap_Fill, _scright(obj) - diffx, _sctop(obj), _scright(obj), _scbottom(obj), inst->left + _scwidth(obj) - diffx, inst->top, SCCV_Bitmap_Fill_BlitType_Clipped);
307 if (diffy < 0)
308 DoMethod(inst->backbitmap,SCCM_Bitmap_Fill, _scleft(obj), _sctop(obj), _scright(obj), _sctop(obj) - diffy - 1, inst->left, inst->top,SCCV_Bitmap_Fill_BlitType_Clipped);
309 else
310 DoMethod(inst->backbitmap,SCCM_Bitmap_Fill, _scleft(obj), _scbottom(obj) - diffy, _scright(obj), _scbottom(obj), inst->left, inst->top + _scheight(obj) - diffy, SCCV_Bitmap_Fill_BlitType_Clipped);
314 SC_DoMethod(_scwinobj(obj),SCCM_Window_SetClipRegion,region);
315 SC_DoMethod(obj,SCCM_Panel_Redraw,SCCV_Area_Drawtype_Complete);
316 SC_DoMethod(_scwinobj(obj),SCCM_Window_ClearClipRegion);
317 DisposeRegion(region);
322 else
324 SC_DoMethod(obj,SCCM_Panel_Redraw,SCCV_Area_Drawtype_Update);
328 inst->oldleft = inst->left;
329 inst->oldtop = inst->top;
331 inst->oldleftpos = _scleft(obj);
332 inst->oldtoppos = _sctop(obj);
333 inst->oldright = _scright(obj);
334 inst->oldbottom = _scbottom(obj);
336 SC_DoMethod(_scwinobj(obj), SCCM_Window_EndDraw,obj);
338 // /
340 /** Set
342 static void Panel_Set(struct SC_Class *cl, Object *obj, struct opSet *msg, struct PanelInst *inst)
344 struct TagItem *taglist = msg->ops_AttrList;
345 struct TagItem **tags = &taglist;
346 struct TagItem *tag;
347 BOOL redraw = FALSE;
349 while ((tag = NextTagItem(tags)))
351 switch (tag->ti_Tag)
353 case SCCA_Panel_Left :
354 inst->left = tag->ti_Data;
355 redraw = TRUE;
356 break;
357 case SCCA_Panel_Top :
358 inst->top = tag->ti_Data;
359 redraw = TRUE;
360 break;
363 if (redraw)
364 drawScroll(cl,obj,inst);
366 SC_DoSuperMethodA(cl, obj, (Msg) msg);
368 // /
370 /** Redraw
372 static void Panel_Redraw(struct SC_Class *cl, Object *obj, Msg msg, struct PanelInst *inst)
375 // /
377 /** Get
379 static ULONG Panel_Get(struct SC_Class *cl, Object *obj, struct opGet *msg, struct PanelInst *inst)
381 if (msg->opg_AttrID == SCCA_Panel_Left)
383 *(msg->opg_Storage) = (LONG) inst->left;
384 return( TRUE );
386 if (msg->opg_AttrID == SCCA_Panel_Top)
388 *(msg->opg_Storage) = (LONG) inst->top;
389 return( TRUE );
391 if (msg->opg_AttrID == SCCA_Area_StaticContents)
393 *(msg->opg_Storage) = FALSE;
394 return( TRUE );
396 return(SC_DoSuperMethodA(cl,obj,(Msg) msg));
398 // /
400 /*-------------------------- MethodList --------------------------------*/
402 struct SC_MethodData PanelMethods[] =
404 { SCCM_Panel_Redraw, (ULONG) Panel_Redraw, sizeof(ULONG), 0, NULL},
405 { SCCM_Init, (ULONG) Panel_Init, 0, 0, NULL },
406 { SCCM_Exit, (ULONG) Panel_Exit, 0, 0, NULL },
407 { SCCM_Area_Draw, (ULONG) Panel_Draw, 0, 0, NULL },
408 { SCCM_Area_BeginDraw, (ULONG) Panel_BeginDraw, 0, 0, NULL },
409 { SCCM_Area_EndDraw, (ULONG) Panel_EndDraw, 0, 0, NULL },
410 { SCCM_Area_Setup, (ULONG) Panel_Setup, 0, 0, NULL},
411 { SCCM_Area_Cleanup, (ULONG) Panel_Cleanup, 0, 0, NULL },
412 { SCCM_Area_Show, (ULONG) Panel_Show, 0, 0, NULL },
413 { SCCM_Area_Hide, (ULONG) Panel_Hide, 0, 0, NULL },
414 { SCCM_Area_AskMinMax, (ULONG) Panel_AskMinMax, 0, 0, NULL },
415 { SCCM_Area_SetIDCMP, (ULONG) Panel_SetIDCMP, 0, 0, NULL },
416 { OM_SET, (ULONG) Panel_Set, 0, 0, NULL },
417 { OM_GET, (ULONG) Panel_Get, 0, 0, NULL },
418 { SCMETHOD_DONE, NULL, 0, 0, NULL }