3 #include <proto/intuition.h>
4 #include <proto/muimaster.h>
5 #include <proto/utility.h>
7 #include <libraries/mui.h>
8 #include <libraries/gadtools.h>
13 #include "muimiamipanel_intern.h"
14 #include "muimiamipanel_locale.h"
15 #include "muimiamipanel_misc.h"
16 #include "muimiamipanel_message.h"
18 /***********************************************************************/
20 struct MiamiPanelIfGroupClass_DATA
32 struct MUI_InputHandlerNode ih
;
46 /***********************************************************************/
48 #define NMX(x) ((1<<8)-1-(1<<x))
50 static ULONG cMenuIDs
[] =
53 MSG_IFGroup_CItem_Online
,
54 MSG_IFGroup_CItem_Offline
,
55 MSG_IFGroup_CItem_Scale
58 static struct NewMenu cMenu
[] =
60 MTITLE(MSG_Menu_Project
),
61 MITEM(MSG_IFGroup_CItem_Online
),
62 MITEM(MSG_IFGroup_CItem_Offline
),
63 MITEM(MSG_IFGroup_CItem_Scale
),
64 MXSUB(TAG_SCALE_1
,NMX(0)),
65 MXSUB(TAG_SCALE_2
,NMX(1)),
66 MXSUB(TAG_SCALE_3
,NMX(2)),
67 MXSUB(TAG_SCALE_4
,NMX(3)),
68 MXSUB(TAG_SCALE_5
,NMX(4)),
69 MXSUB(TAG_SCALE_6
,NMX(5)),
70 MXSUB(TAG_SCALE_7
,NMX(6)),
71 MXSUB(TAG_SCALE_8
,NMX(7)),
75 static struct MiamiPanelBase_intern
*MiamiPanelBaseIntern
;
78 MUIPC_IfGroup__OM_NEW(struct IClass
*CLASS
,Object
*self
,struct opSet
*message
)
80 struct TagItem
*attrs
= message
->ops_AttrList
;
83 if (self
= (Object
*)DoSuperNewTags
87 MUIA_Frame
, MUIV_Frame_Virtual
,
88 //MUIA_Background, MUII_GroupBack,
89 MUIA_HelpNode
, "IFGroup",
90 Child
, space
= RectangleObject
, /*MUIA_Background, MUII_GroupBack, */End
,
93 struct MiamiPanelIfGroupClass_DATA
*data
= INST_DATA(CLASS
,self
);
96 data
->show
= GetTagData(MPA_Show
,0,attrs
);
98 if (data
->cmenu
= MUI_MakeObject(MUIO_MenustripNM
,(ULONG
)cMenu
,0))
100 if (!(data
->show
& MIAMIPANELV_Init_Flags_ShowDataTransferRate
))
104 DoMethod(data
->cmenu
,MUIM_Family_Remove
,(ULONG
)(cmscale
= (Object
*)DoMethod(data
->cmenu
,MUIM_FindUData
,MSG_IFGroup_CItem_Scale
)));
105 MUI_DisposeObject(cmscale
);
109 data
->flags
|= FLG_Bar
;
115 /***********************************************************************/
118 MUIPC_IfGroup__OM_SET(struct IClass
*CLASS
,Object
*self
,struct opSet
*message
)
120 struct MiamiPanelIfGroupClass_DATA
*data
= INST_DATA(CLASS
,self
);
122 struct TagItem
*tstate
;
124 for (tstate
= message
->ops_AttrList
; tag
= NextTagItem(&tstate
); )
126 ULONG tidata
= tag
->ti_Data
;
131 if (PREFS(tidata
)->flags
& MPV_Flags_BWin
)
132 data
->flags
|= FLG_BWin
;
133 else data
->flags
&= ~FLG_BWin
;
137 if (tidata
) data
->flags
|= FLG_SkipBar
;
142 data
->flags
&= ~FLG_SkipBar
;
144 DoSuperMethod(CLASS
,self
,OM_GET
,MUIA_Virtgroup_Height
,(ULONG
)&vh
);
146 if (vh
>=_height(self
))
148 data
->flags
|= FLG_Bar
;
149 set(_app(self
),MPA_Bar
,TRUE
);
153 data
->flags
&= ~FLG_Bar
;
154 set(_app(self
),MPA_Bar
,FALSE
);
161 return DoSuperMethodA(CLASS
,self
,(Msg
)message
);
164 /***********************************************************************/
167 MUIPC_IfGroup__OM_DISPOSE(struct IClass
*CLASS
,Object
*self
,Msg message
)
169 struct MiamiPanelIfGroupClass_DATA
*data
= INST_DATA(CLASS
,self
);
171 if (data
->cmenu
) MUI_DisposeObject(data
->cmenu
);
173 if (data
->flags
& FLG_Handler
)
174 DoMethod(data
->app
,MUIM_Application_RemInputHandler
,(ULONG
)&data
->ih
);
176 return DoSuperMethodA(CLASS
,self
,message
);
179 /***********************************************************************/
182 MUIPC_IfGroup__MUIM_Setup(struct IClass
*CLASS
,Object
*self
,Msg message
)
184 struct MiamiPanelIfGroupClass_DATA
*data
= INST_DATA(CLASS
,self
);
186 if (!DoSuperMethodA(CLASS
,self
,message
)) return FALSE
;
188 if (!(data
->flags
& FLG_Handler
))
190 data
->app
= _app(self
);
191 memset(&data
->ih
,0,sizeof(data
->ih
));
192 data
->ih
.ihn_Object
= self
;
193 data
->ih
.ihn_Method
= MPM_IfGroup_HandleEvent
;
194 data
->ih
.ihn_Signals
= 1<<MiamiPanelBaseIntern
->mpb_port
->mp_SigBit
;
195 DoMethod(data
->app
,MUIM_Application_AddInputHandler
,(ULONG
)&data
->ih
);
197 data
->flags
|= FLG_Handler
;
200 data
->flags
|= FLG_Setup
;
205 /***********************************************************************/
208 MUIPC_IfGroup__MUIM_Cleanup(struct IClass
*CLASS
,Object
*self
,Msg message
)
210 struct MiamiPanelIfGroupClass_DATA
*data
= INST_DATA(CLASS
,self
);
212 data
->flags
&= ~FLG_Setup
;
214 return DoSuperMethodA(CLASS
,self
,message
);
217 /***********************************************************************/
220 MUIPC_IfGroup__MUIM_Show(struct IClass
*CLASS
,Object
*self
,Msg message
)
222 struct MiamiPanelIfGroupClass_DATA
*data
= INST_DATA(CLASS
,self
);
224 if (!DoSuperMethodA(CLASS
,self
,message
)) return FALSE
;
226 if (data
->flags
& FLG_BWin
)
231 DoSuperMethod(CLASS
,self
,OM_GET
,MUIA_Virtgroup_Height
,(ULONG
)&vh
);
233 if (!BOOLSAME(data
->flags
& FLG_Bar
,bar
= vh
>=_height(self
)))
235 if (bar
) data
->flags
|= FLG_Bar
;
236 else data
->flags
&= ~FLG_Bar
;
238 if (!(data
->flags
& FLG_SkipBar
))
239 DoMethod(_app(self
),MUIM_Application_PushMethod
,(ULONG
)_app(self
),3,MUIM_Set
,MPA_Bar
,(ULONG
)bar
);
246 /***********************************************************************/
249 findInterface(Object
*self
,long unit
)
255 get(self
,MUIA_Group_ChildList
,&l
);
256 cstate
= (Object
*)l
->lh_Head
;
258 while (child
= NextObject(&cstate
))
262 if (get(child
,MPA_If_Unit
,&u
) && (u
==unit
))
269 /***********************************************************************/
272 findNextChild(Object
*self
,Object
*from
,struct MiamiPanelIfGroupClass_DATA
*data
)
276 Object
*child
, *space
;
279 get(self
,MUIA_Group_ChildList
,&l
);
280 cstate
= (Object
*)l
->lh_Head
;
284 while (child
= NextObject(&cstate
))
286 if (child
==from
) next
= 1;
287 else if (next
&& child
!=space
) return child
;
293 /***********************************************************************/
296 addInterface(struct IClass
*CLASS
,Object
*self
,struct MiamiPanelIfGroupClass_DATA
*data
,struct MPS_Msg_AddInterface
*message
)
299 struct MPS_Prefs
*prefs
;
302 bar
= RectangleObject
,
304 MUIA_Rectangle_HBar
, TRUE
,
305 MUIA_FixHeightTxt
, "X",
309 get(_app(self
),MPA_Prefs
,&prefs
);
311 if (child
= NewObject(MiamiPanelBaseIntern
->mpb_ifGroupClass
->mcc_Class
,
313 MUIA_ObjectID
, MAKE_ID('i','f',(message
->unit
& 0xF0),(message
->unit
& 0xF)),
314 MUIA_ContextMenu
, data
->cmenu
,
315 MPA_Show
, data
->show
,
316 MPA_If_Unit
, message
->unit
,
317 MPA_If_Name
, message
->name
,
318 MPA_If_State
, message
->state
,
319 MPA_If_Ontime
, message
->ontime
,
320 MPA_If_Speed
, message
->speed
,
324 DoSuperMethod(CLASS
,self
,MUIM_Group_InitChange
);
326 DoSuperMethod(CLASS
,self
,OM_REMMEMBER
,(ULONG
)data
->space
);
328 if (bar
) DoSuperMethod(CLASS
,self
,OM_ADDMEMBER
,(ULONG
)bar
);
329 DoSuperMethod(CLASS
,self
,OM_ADDMEMBER
,(ULONG
)child
);
331 DoSuperMethod(CLASS
,self
,OM_ADDMEMBER
,(ULONG
)data
->space
);
333 DoSuperMethod(CLASS
,self
,MUIM_Group_ExitChange
);
336 else if (bar
) MUI_DisposeObject(bar
);
339 /***********************************************************************/
342 delInterface(struct IClass
*CLASS
,Object
*self
,struct MiamiPanelIfGroupClass_DATA
*data
,struct MPS_Msg_DelInterface
*message
)
346 if (child
= findInterface(self
,message
->unit
))
348 register Object
*next
;
350 DoSuperMethod(CLASS
,self
,MUIM_Group_InitChange
);
352 if (next
= findNextChild(self
, child
, data
))
354 DoSuperMethod(CLASS
,self
,OM_REMMEMBER
,(ULONG
)next
);
355 MUI_DisposeObject(next
);
358 DoSuperMethod(CLASS
,self
,OM_REMMEMBER
,(ULONG
)child
);
359 MUI_DisposeObject(child
);
361 DoSuperMethod(CLASS
,self
,MUIM_Group_ExitChange
);
367 /***********************************************************************/
370 setInterfaceState(struct IClass
*CLASS
,Object
*self
,struct MiamiPanelIfGroupClass_DATA
*data
,struct MPS_Msg_SetInterfaceState
*message
)
374 if (child
= findInterface(self
,message
->unit
))
375 SetAttrs(child
,MPA_If_State
, message
->state
,
376 MPA_If_Ontime
, message
->ontime
,
380 /***********************************************************************/
383 setInterfaceSpeed(struct IClass
*CLASS
,Object
*self
,struct MiamiPanelIfGroupClass_DATA
*data
,struct MPS_Msg_SetInterfaceSpeed
*message
)
387 if (child
= findInterface(self
,message
->unit
))
388 set(child
,MPA_If_Speed
,message
->speed
);
391 /***********************************************************************/
394 interfaceReport(struct IClass
*CLASS
,Object
*self
,struct MiamiPanelIfGroupClass_DATA
*data
,struct MPS_Msg_InterfaceReport
*message
)
398 if (child
= findInterface(self
,message
->unit
))
399 SetAttrs(child
,MPA_If_Rate
, message
->rate
,
400 MPA_If_Now
, message
->now
,
401 MPA_If_Traffic
, (ULONG
)&message
->total
,
405 /***********************************************************************/
408 refreshName(struct IClass
*CLASS
,Object
*self
,struct MiamiPanelIfGroupClass_DATA
*data
,struct MPS_Msg_RefreshName
*message
)
412 if (child
= findInterface(self
,message
->unit
))
413 set(child
,MPA_If_Name
,message
->name
);
416 /***********************************************************************/
419 MUIPC_IfGroup__MPM_IfGroup_HandleEvent(struct IClass
*CLASS
,Object
*self
,Msg message
)
421 struct MiamiPanelIfGroupClass_DATA
*data
= INST_DATA(CLASS
,self
);
422 struct MPS_Msg
*mpsg
;
427 while (mpsg
= (struct MPS_Msg
*)GetMsg(MiamiPanelBaseIntern
->mpb_port
))
433 case MPV_Msg_Type_Cleanup
:
434 DoMethod(_app(self
),MUIM_Application_PushMethod
,(ULONG
)_app(self
),2,MUIM_Application_ReturnID
,MUIV_Application_ReturnID_Quit
);
437 case MPV_Msg_Type_AddInterface
:
438 addInterface(CLASS
,self
,data
,(APTR
)mpsg
);
441 case MPV_Msg_Type_DelInterface
:
442 delInterface(CLASS
,self
,data
,(APTR
)mpsg
);
445 case MPV_Msg_Type_SetInterfaceState
:
446 setInterfaceState(CLASS
,self
,data
,(APTR
)mpsg
);
449 case MPV_Msg_Type_SetInterfaceSpeed
:
450 setInterfaceSpeed(CLASS
,self
,data
,(APTR
)mpsg
);
453 case MPV_Msg_Type_InterfaceReport
:
454 interfaceReport(CLASS
,self
,data
,(APTR
)mpsg
);
457 case MPV_Msg_Type_RefreshName
:
458 refreshName(CLASS
,self
,data
,(APTR
)mpsg
);
461 case MPV_Msg_Type_ToFront
:
465 get(_app(self
),MUIA_Application_Iconified
,&iconified
);
466 if (iconified
) set(_app(self
),MUIA_Application_Iconified
,FALSE
);
468 if (data
->flags
& FLG_Setup
) set(_win(self
),MUIA_Window_Open
,TRUE
);
473 case MPV_Msg_Type_InhibitRefresh
:
475 struct MPS_Msg_InhibitRefresh
*m
= (struct MPS_Msg_InhibitRefresh
*)mpsg
;
479 if (!data
->refresh
++)
480 DoMethod(self
,MUIM_Group_InitChange
);
483 if (data
->refresh
&& !--data
->refresh
)
484 DoMethod(self
,MUIM_Group_ExitChange
);
492 if (mpsg
->flags
& MPV_Msg_Flags_Reply
) ReplyMsg((struct Message
*)mpsg
);
493 else freeMsg(mpsg
, MiamiPanelBaseIntern
);
499 /***********************************************************************/
502 MUIPC_IfGroup__MPM_IfGroup_GrabIFList(struct IClass
*CLASS
,Object
*self
,Msg message
)
507 struct MPS_Prefs
*prefs
;
509 get(_app(self
),MPA_Prefs
,&prefs
);
510 freeIFList(prefs
, MiamiPanelBaseIntern
);
512 get(self
,MUIA_Group_ChildList
,&l
);
513 cstate
= (Object
*)l
->lh_Head
;
515 while (child
= NextObject(&cstate
))
520 if (get(child
,MPA_If_Name
,&name
))
522 get(child
,MPA_If_Scale
,&scale
);
523 createIFNode(prefs
,name
,scale
, MiamiPanelBaseIntern
);
530 /***********************************************************************/
532 BOOPSI_DISPATCHER(IPTR
, MUIPC_IfGroup_Dispatcher
, CLASS
, self
, message
)
534 switch (message
->MethodID
)
536 case OM_NEW
: return MUIPC_IfGroup__OM_NEW(CLASS
,self
,(APTR
)message
);
537 case OM_SET
: return MUIPC_IfGroup__OM_SET(CLASS
,self
,(APTR
)message
);
538 case OM_DISPOSE
: return MUIPC_IfGroup__OM_DISPOSE(CLASS
,self
,(APTR
)message
);
539 case MUIM_Setup
: return MUIPC_IfGroup__MUIM_Setup(CLASS
,self
,(APTR
)message
);
540 case MUIM_Cleanup
: return MUIPC_IfGroup__MUIM_Cleanup(CLASS
,self
,(APTR
)message
);
541 case MUIM_Show
: return MUIPC_IfGroup__MUIM_Show(CLASS
,self
,(APTR
)message
);
542 case MPM_IfGroup_HandleEvent
: return MUIPC_IfGroup__MPM_IfGroup_HandleEvent(CLASS
,self
,(APTR
)message
);
543 case MPM_IfGroup_GrabIFList
: return MUIPC_IfGroup__MPM_IfGroup_GrabIFList(CLASS
,self
,(APTR
)message
);
544 default: return DoSuperMethodA(CLASS
,self
,message
);
548 BOOPSI_DISPATCHER_END
550 /***********************************************************************/
552 static ULONG defScales
[] =
565 struct TagItem scales
[] =
574 TAG_SCALE_8
, 1024000,
578 static UBYTE scaleStrings
[TAG_SCALE_LAST
-TAG_SCALE
-1][64];
581 MUIPC_IfGroup_ClassInit(struct MiamiPanelBase_intern
*MiamiPanelBase
)
583 MiamiPanelBaseIntern
= MiamiPanelBase
;
584 if (MiamiPanelBaseIntern
->mpb_ifGroupClass
= MUI_CreateCustomClass(NULL
, MUIC_Virtgroup
,NULL
, sizeof(struct MiamiPanelIfGroupClass_DATA
), MUIPC_IfGroup_Dispatcher
))
593 for (i
= 0, ids
= defScales
; *ids
; ids
++, i
++) scales
[i
].ti_Data
= *ids
;
595 if (file
= Open("MIAMI:Libs/MUI.MiamiPanel.scales",MODE_OLDFILE
))
601 while (FGets(file
,buf
,sizeof(buf
)))
605 for (s
= buf
; *s
&& *s
!='\n' && *s
!='\r'; s
++);
608 if (!*buf
|| *buf
==';') continue;
610 scales
[i
++].ti_Data
= atoi(buf
);
611 if (i
==TAG_SCALE_LAST
-TAG_SCALE
-1) break;
617 scaleFmt
= __(MSG_IFGroup_CItem_ScaleFmt
);
619 for (i
= 0, t
= scales
; t
->ti_Tag
!=TAG_DONE
; i
++, t
++)
620 snprintf(scaleStrings
[i
],sizeof(scaleStrings
[i
]),scaleFmt
,t
->ti_Data
/1000);
622 for (ids
= cMenuIDs
, nm
= cMenu
; nm
->nm_Type
!=NM_END
; nm
++)
623 if (nm
->nm_Label
!=NM_BARLABEL
)
624 if (((ULONG
)nm
->nm_UserData
>TAG_SCALE
) && ((ULONG
)nm
->nm_UserData
<TAG_SCALE_LAST
))
625 nm
->nm_Label
= scaleStrings
[(ULONG
)nm
->nm_UserData
-TAG_SCALE
-1];
626 else nm
->nm_Label
= __(*ids
++);
634 /***********************************************************************/