Merged in v 26.12.
[AROS-Contrib.git] / mui / classes / thebar / mcc / dragbar.c
blobe87f2ccfe6c1cf43827f606201ca133865fb34dc
1 /***************************************************************************
3 TheBar.mcc - Next Generation Toolbar MUI Custom Class
4 Copyright (C) 2003-2005 Alfonso Ranieri
5 Copyright (C) 2005-2013 by TheBar.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 TheBar class Support Site: http://www.sf.net/projects/thebar
19 $Id$
21 ***************************************************************************/
23 #include "class.h"
25 /***********************************************************************/
27 struct data
29 Object *bar;
30 long pshine;
31 long pshadow;
32 long pfill;
33 ULONG flags;
36 enum
38 FLG_Horiz = 1<<0,
39 FLG_ShowMe = 1<<1,
40 FLG_UseDragBarFill = 1<<2,
43 /***********************************************************************/
45 static IPTR
46 mNew(struct IClass *cl,Object *obj,struct opSet *msg)
48 ENTER();
50 if ((obj = (Object *)DoSuperNew(cl,obj,
51 MUIA_InputMode, MUIV_InputMode_Immediate,
52 MUIA_ShowSelState, FALSE,
53 isFlagSet(lib_flags,BASEFLG_MUI20) ? TAG_IGNORE : MUIA_CustomBackfill, TRUE,
54 TAG_DONE)))
56 struct data *data = INST_DATA(cl,obj);
58 data->bar = (Object *)GetTagData(MUIA_TheButton_TheBar,FALSE,msg->ops_AttrList);
59 data->flags = (GetTagData(MUIA_Group_Horiz,FALSE,msg->ops_AttrList) ? FLG_Horiz : 0) |
60 (GetTagData(MUIA_ShowMe,TRUE,msg->ops_AttrList) ? FLG_ShowMe : 0);
63 RETURN((IPTR)obj);
64 return (IPTR)obj;
67 /***********************************************************************/
69 static IPTR
70 mGet(struct IClass *cl,Object *obj,struct opGet *msg)
72 struct data *data = INST_DATA(cl,obj);
73 IPTR result = FALSE;
75 ENTER();
77 switch (msg->opg_AttrID)
79 case MUIA_TheButton_Spacer: *msg->opg_Storage = MUIV_TheButton_Spacer_DragBar; result = TRUE; break;
80 case MUIA_ShowMe: *msg->opg_Storage = isFlagSet(data->flags, FLG_ShowMe) ? TRUE : FALSE; result = TRUE; break;
81 default: result = DoSuperMethodA(cl,obj,(Msg)msg);
84 RETURN(result);
85 return result;
88 /***********************************************************************/
90 static IPTR
91 mSets(struct IClass *cl,Object *obj,struct opSet *msg)
93 struct data *data = INST_DATA(cl,obj);
94 struct TagItem *tag;
95 struct TagItem *tstate;
96 IPTR result = 0;
98 ENTER();
100 for(tstate = msg->ops_AttrList; (tag = NextTagItem((APTR)&tstate)); )
102 ULONG tidata = tag->ti_Data;
104 switch (tag->ti_Tag)
106 case MUIA_Pressed:
107 if (tidata)
109 struct Window *window = (struct Window *)xget(_win(obj), MUIA_Window_Window);
111 DoMethod(_app(obj),MUIM_Application_PushMethod,(IPTR)data->bar,4,MUIM_DoDrag,window->MouseX-_mleft(obj),window->MouseY-_mtop(obj),0);
113 break;
115 case MUIA_Group_Horiz:
116 if (tidata) setFlag(data->flags,FLG_Horiz);
117 else clearFlag(data->flags,FLG_Horiz);
118 break;
120 case MUIA_ShowMe:
121 if (BOOLSAME(isFlagSet(data->flags,FLG_ShowMe),tidata))
122 tag->ti_Data = TAG_IGNORE;
123 else
125 if (tidata) setFlag(data->flags,FLG_ShowMe);
126 else clearFlag(data->flags,FLG_ShowMe);
128 break;
132 result = DoSuperMethodA(cl,obj,(Msg)msg);
134 RETURN(result);
135 return result;
138 /***********************************************************************/
140 static IPTR
141 mSetup(struct IClass *cl,Object *obj,Msg msg)
143 struct data *data = INST_DATA(cl,obj);
144 APTR pen;
145 ULONG *val;
147 ENTER();
149 if (!DoSuperMethodA(cl,obj,(Msg)msg))
151 RETURN(FALSE);
152 return FALSE;
155 if (!getconfigitem(cl,obj,MUICFG_TheBar_DragBarShinePen,&pen))
156 pen = MUIDEF_TheBar_DragBarShinePen;
157 data->pshine = MUI_ObtainPen(muiRenderInfo(obj),(struct MUI_PenSpec *)pen,0);
159 if (!getconfigitem(cl,obj,MUICFG_TheBar_DragBarShadowPen,&pen))
160 pen = MUIDEF_TheBar_DragBarShadowPen;
161 data->pshadow = MUI_ObtainPen(muiRenderInfo(obj),(struct MUI_PenSpec *)pen,0);
163 if (getconfigitem(cl,obj,MUICFG_TheBar_UseDragBarFillPen,&val) ? *val : MUIDEF_TheBar_UseDragBarFillPen)
165 if (!getconfigitem(cl,obj,MUICFG_TheBar_DragBarFillPen,&pen))
166 pen = MUIDEF_TheBar_DragBarFillPen;
167 data->pfill = MUI_ObtainPen(muiRenderInfo(obj),(struct MUI_PenSpec *)pen,0);
169 setFlag(data->flags,FLG_UseDragBarFill);
172 RETURN(TRUE);
173 return TRUE;
176 /***********************************************************************/
178 static IPTR
179 mCleanup(struct IClass *cl,Object *obj,Msg msg)
181 struct data *data = INST_DATA(cl,obj);
182 IPTR result = 0;
184 ENTER();
186 MUI_ReleasePen(muiRenderInfo(obj),data->pshine);
187 MUI_ReleasePen(muiRenderInfo(obj),data->pshadow);
188 if (data->flags & FLG_UseDragBarFill)
190 MUI_ReleasePen(muiRenderInfo(obj),data->pfill);
191 clearFlag(data->flags, FLG_UseDragBarFill);
194 result = DoSuperMethodA(cl,obj,msg);
196 RETURN(result);
197 return result;
200 /***********************************************************************/
202 static IPTR
203 mAskMinMax(struct IClass *cl,Object *obj,struct MUIP_AskMinMax *msg)
205 struct data *data = INST_DATA(cl,obj);
207 ENTER();
209 DoSuperMethodA(cl,obj,(Msg)msg);
211 if (isFlagSet(data->flags,FLG_Horiz))
213 msg->MinMaxInfo->MinWidth += 9;
214 msg->MinMaxInfo->MinHeight += 4;
215 msg->MinMaxInfo->DefWidth += 9;
216 msg->MinMaxInfo->DefHeight += 4;
217 msg->MinMaxInfo->MaxWidth += 9;
218 msg->MinMaxInfo->MaxHeight = MBQ_MUI_MAXMAX;
220 else
222 msg->MinMaxInfo->MinWidth += 4;
223 msg->MinMaxInfo->MinHeight += 9;
224 msg->MinMaxInfo->DefWidth += 4;
225 msg->MinMaxInfo->DefHeight += 9;
226 msg->MinMaxInfo->MaxWidth = MBQ_MUI_MAXMAX;
227 msg->MinMaxInfo->MaxHeight += 9;
230 RETURN(0);
231 return 0;
234 /***********************************************************************/
236 static IPTR
237 mDraw(struct IClass *cl,Object *obj,struct MUIP_Draw *msg)
239 struct data *data = INST_DATA(cl,obj);
241 ENTER();
243 DoSuperMethodA(cl,obj,(Msg)msg);
245 if(isFlagSet(msg->flags, MADF_DRAWUPDATE) || isFlagSet(msg->flags, MADF_DRAWOBJECT))
247 struct RastPort rp;
248 WORD l, t, r, b;
250 memcpy(&rp,_rp(obj),sizeof(rp));
252 l = _mleft(obj);
253 t = _mtop(obj);
254 r = _mright(obj);
255 b = _mbottom(obj);
257 if (isFlagSet(data->flags,FLG_Horiz))
259 SetAPen(&rp,MUIPEN(data->pshine));
260 Move(&rp,l,b-1);
261 Draw(&rp,l,t);
262 Draw(&rp,l+3,t);
264 if (isFlagSet(data->flags,FLG_UseDragBarFill))
266 SetAPen(&rp,MUIPEN(data->pfill));
267 RectFill(&rp,l+1,t+1,l+2,b-1);
270 SetAPen(&rp,MUIPEN(data->pshadow));
271 Move(&rp,l+3,t+1);
272 Draw(&rp,l+3,b);
273 Draw(&rp,l,b);
275 else
277 SetAPen(&rp,MUIPEN(data->pshine));
278 Move(&rp,r-1,t);
279 Draw(&rp,l,t);
280 Draw(&rp,l,t+3);
282 if (isFlagSet(data->flags,FLG_UseDragBarFill))
284 SetAPen(&rp,MUIPEN(data->pfill));
285 RectFill(&rp,l+1,t+1,r-1,t+2);
288 SetAPen(&rp,MUIPEN(data->pshadow));
289 Move(&rp,l+1,t+3);
290 Draw(&rp,r,t+3);
291 Draw(&rp,r,t);
295 RETURN(0);
296 return 0;
299 /***********************************************************************/
301 static IPTR
302 mBackfill(struct IClass *cl,Object *obj,struct MUIP_Backfill *msg)
304 struct data *data = INST_DATA(cl,obj);
305 IPTR result = 0;
307 ENTER();
309 if (data->bar)
311 result = DoMethod(data->bar,MUIM_Backfill,msg->left,
312 msg->top,
313 msg->right,
314 msg->bottom,
315 msg->left+msg->xoffset,
316 msg->top+msg->yoffset,
319 else
321 result = DoSuperMethod(cl,obj,MUIM_DrawBackground,msg->left,
322 msg->top,
323 msg->right-msg->left+1,
324 msg->bottom-msg->top+1,
325 msg->xoffset,
326 msg->yoffset,
330 RETURN(result);
331 return result;
334 /***********************************************************************/
336 DISPATCHER(DragBarDispatcher)
338 switch(msg->MethodID)
340 case OM_NEW: return mNew(cl,obj,(APTR)msg);
341 case OM_GET: return mGet(cl,obj,(APTR)msg);
342 case OM_SET: return mSets(cl,obj,(APTR)msg);
343 case MUIM_AskMinMax: return mAskMinMax(cl,obj,(APTR)msg);
344 case MUIM_Draw: return mDraw(cl,obj,(APTR)msg);
345 case MUIM_Backfill: return mBackfill(cl,obj,(APTR)msg);
346 case MUIM_Setup: return mSetup(cl,obj,(APTR)msg);
347 case MUIM_Cleanup: return mCleanup(cl,obj,(APTR)msg);
348 default: return DoSuperMethodA(cl,obj,msg);
352 /***********************************************************************/
354 BOOL
355 initDragBarClass(void)
357 BOOL result = FALSE;
359 ENTER();
361 if ((lib_dragBarClass = MUI_CreateCustomClass(NULL,(STRPTR)MUIC_Area,NULL,sizeof(struct data),ENTRY(DragBarDispatcher))))
363 if(isFlagSet(lib_flags, BASEFLG_MUI20))
364 lib_dragBarClass->mcc_Class->cl_ID = (STRPTR)"TheBar_DragBar";
366 result = TRUE;
369 RETURN(result);
370 return result;
373 /***********************************************************************/