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
21 ***************************************************************************/
25 /***********************************************************************/
40 FLG_UseDragBarFill
= 1<<2,
43 /***********************************************************************/
46 mNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
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
,
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);
67 /***********************************************************************/
70 mGet(struct IClass
*cl
,Object
*obj
,struct opGet
*msg
)
72 struct data
*data
= INST_DATA(cl
,obj
);
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
);
88 /***********************************************************************/
91 mSets(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
93 struct data
*data
= INST_DATA(cl
,obj
);
95 struct TagItem
*tstate
;
100 for(tstate
= msg
->ops_AttrList
; (tag
= NextTagItem((APTR
)&tstate
)); )
102 ULONG tidata
= tag
->ti_Data
;
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);
115 case MUIA_Group_Horiz
:
116 if (tidata
) setFlag(data
->flags
,FLG_Horiz
);
117 else clearFlag(data
->flags
,FLG_Horiz
);
121 if (BOOLSAME(isFlagSet(data
->flags
,FLG_ShowMe
),tidata
))
122 tag
->ti_Data
= TAG_IGNORE
;
125 if (tidata
) setFlag(data
->flags
,FLG_ShowMe
);
126 else clearFlag(data
->flags
,FLG_ShowMe
);
132 result
= DoSuperMethodA(cl
,obj
,(Msg
)msg
);
138 /***********************************************************************/
141 mSetup(struct IClass
*cl
,Object
*obj
,Msg msg
)
143 struct data
*data
= INST_DATA(cl
,obj
);
149 if (!DoSuperMethodA(cl
,obj
,(Msg
)msg
))
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
);
176 /***********************************************************************/
179 mCleanup(struct IClass
*cl
,Object
*obj
,Msg msg
)
181 struct data
*data
= INST_DATA(cl
,obj
);
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
);
200 /***********************************************************************/
203 mAskMinMax(struct IClass
*cl
,Object
*obj
,struct MUIP_AskMinMax
*msg
)
205 struct data
*data
= INST_DATA(cl
,obj
);
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
;
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;
234 /***********************************************************************/
237 mDraw(struct IClass
*cl
,Object
*obj
,struct MUIP_Draw
*msg
)
239 struct data
*data
= INST_DATA(cl
,obj
);
243 DoSuperMethodA(cl
,obj
,(Msg
)msg
);
245 if(isFlagSet(msg
->flags
, MADF_DRAWUPDATE
) || isFlagSet(msg
->flags
, MADF_DRAWOBJECT
))
250 memcpy(&rp
,_rp(obj
),sizeof(rp
));
257 if (isFlagSet(data
->flags
,FLG_Horiz
))
259 SetAPen(&rp
,MUIPEN(data
->pshine
));
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
));
277 SetAPen(&rp
,MUIPEN(data
->pshine
));
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
));
299 /***********************************************************************/
302 mBackfill(struct IClass
*cl
,Object
*obj
,struct MUIP_Backfill
*msg
)
304 struct data
*data
= INST_DATA(cl
,obj
);
311 result
= DoMethod(data
->bar
,MUIM_Backfill
,msg
->left
,
315 msg
->left
+msg
->xoffset
,
316 msg
->top
+msg
->yoffset
,
321 result
= DoSuperMethod(cl
,obj
,MUIM_DrawBackground
,msg
->left
,
323 msg
->right
-msg
->left
+1,
324 msg
->bottom
-msg
->top
+1,
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 /***********************************************************************/
355 initDragBarClass(void)
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";
373 /***********************************************************************/