tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / MUI.MiamiPanel / Classes / muimiamipanel_class_ifgroup.c
blob2c98ab22b5bf1b06186c0f28014541ca27d63d46
2 #include <proto/dos.h>
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>
10 #include <stdio.h>
11 #include <stdlib.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
22 Object *app;
24 Object *space;
25 APTR cmenu;
27 int children;
28 int refresh;
30 ULONG show;
32 struct MUI_InputHandlerNode ih;
34 ULONG flags;
37 enum
39 FLG_Setup = 1<<0,
40 FLG_Handler = 1<<1,
41 FLG_BWin = 1<<2,
42 FLG_Bar = 1<<3,
43 FLG_SkipBar = 1<<4,
46 /***********************************************************************/
48 #define NMX(x) ((1<<8)-1-(1<<x))
50 static ULONG cMenuIDs[] =
52 MSG_Menu_Project,
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)),
72 MEND
75 static struct MiamiPanelBase_intern *MiamiPanelBaseIntern;
77 static ULONG
78 MUIPC_IfGroup__OM_NEW(struct IClass *CLASS,Object *self,struct opSet *message)
80 struct TagItem *attrs = message->ops_AttrList;
81 Object *space;
83 if (self = (Object *)DoSuperNewTags
85 CLASS, self, NULL,
87 MUIA_Frame, MUIV_Frame_Virtual,
88 //MUIA_Background, MUII_GroupBack,
89 MUIA_HelpNode, "IFGroup",
90 Child, space = RectangleObject, /*MUIA_Background, MUII_GroupBack, */End,
91 TAG_MORE,attrs))
93 struct MiamiPanelIfGroupClass_DATA *data = INST_DATA(CLASS,self);
95 data->space = space;
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))
102 Object *cmscale;
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;
112 return (ULONG)self;
115 /***********************************************************************/
117 static ULONG
118 MUIPC_IfGroup__OM_SET(struct IClass *CLASS,Object *self,struct opSet *message)
120 struct MiamiPanelIfGroupClass_DATA *data = INST_DATA(CLASS,self);
121 struct TagItem *tag;
122 struct TagItem *tstate;
124 for (tstate = message->ops_AttrList; tag = NextTagItem(&tstate); )
126 ULONG tidata = tag->ti_Data;
128 switch(tag->ti_Tag)
130 case MPA_Prefs:
131 if (PREFS(tidata)->flags & MPV_Flags_BWin)
132 data->flags |= FLG_BWin;
133 else data->flags &= ~FLG_BWin;
134 break;
136 case MPA_SkipBar:
137 if (tidata) data->flags |= FLG_SkipBar;
138 else
140 ULONG vh;
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);
151 else
153 data->flags &= ~FLG_Bar;
154 set(_app(self),MPA_Bar,FALSE);
157 break;
161 return DoSuperMethodA(CLASS,self,(Msg)message);
164 /***********************************************************************/
166 static ULONG
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 /***********************************************************************/
181 static ULONG
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;
202 return TRUE;
205 /***********************************************************************/
207 static ULONG
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 /***********************************************************************/
219 static ULONG
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)
228 ULONG bar;
229 ULONG vh;
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);
243 return TRUE;
246 /***********************************************************************/
248 static Object *
249 findInterface(Object *self,long unit)
251 struct List *l;
252 Object *cstate;
253 Object *child;
255 get(self,MUIA_Group_ChildList,&l);
256 cstate = (Object *)l->lh_Head;
258 while (child = NextObject(&cstate))
260 long u;
262 if (get(child,MPA_If_Unit,&u) && (u==unit))
263 return child;
266 return NULL;
269 /***********************************************************************/
271 static Object *
272 findNextChild(Object *self,Object *from,struct MiamiPanelIfGroupClass_DATA *data)
274 struct List *l;
275 Object *cstate;
276 Object *child, *space;
277 ULONG next;
279 get(self,MUIA_Group_ChildList,&l);
280 cstate = (Object *)l->lh_Head;
281 space = data->space;
282 next = 0;
284 while (child = NextObject(&cstate))
286 if (child==from) next = 1;
287 else if (next && child!=space) return child;
290 return NULL;
293 /***********************************************************************/
295 static void
296 addInterface(struct IClass *CLASS,Object *self,struct MiamiPanelIfGroupClass_DATA *data,struct MPS_Msg_AddInterface *message)
298 Object *child, *bar;
299 struct MPS_Prefs *prefs;
301 if (data->children)
302 bar = RectangleObject,
303 MUIA_Weight, 0,
304 MUIA_Rectangle_HBar, TRUE,
305 MUIA_FixHeightTxt, "X",
306 End;
307 else bar = NULL;
309 get(_app(self),MPA_Prefs,&prefs);
311 if (child = NewObject(MiamiPanelBaseIntern->mpb_ifGroupClass->mcc_Class,
312 NULL,
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,
321 MPA_Prefs, prefs,
322 TAG_DONE))
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);
334 data->children++;
336 else if (bar) MUI_DisposeObject(bar);
339 /***********************************************************************/
341 static void
342 delInterface(struct IClass *CLASS,Object *self,struct MiamiPanelIfGroupClass_DATA *data,struct MPS_Msg_DelInterface *message)
344 Object *child;
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);
363 data->children--;
367 /***********************************************************************/
369 static void
370 setInterfaceState(struct IClass *CLASS,Object *self,struct MiamiPanelIfGroupClass_DATA *data,struct MPS_Msg_SetInterfaceState *message)
372 Object *child;
374 if (child = findInterface(self,message->unit))
375 SetAttrs(child,MPA_If_State, message->state,
376 MPA_If_Ontime, message->ontime,
377 TAG_DONE);
380 /***********************************************************************/
382 static void
383 setInterfaceSpeed(struct IClass *CLASS,Object *self,struct MiamiPanelIfGroupClass_DATA *data,struct MPS_Msg_SetInterfaceSpeed *message)
385 Object *child;
387 if (child = findInterface(self,message->unit))
388 set(child,MPA_If_Speed,message->speed);
391 /***********************************************************************/
393 static void
394 interfaceReport(struct IClass *CLASS,Object *self,struct MiamiPanelIfGroupClass_DATA *data,struct MPS_Msg_InterfaceReport *message)
396 Object *child;
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,
402 TAG_DONE);
405 /***********************************************************************/
407 static void
408 refreshName(struct IClass *CLASS,Object *self,struct MiamiPanelIfGroupClass_DATA *data,struct MPS_Msg_RefreshName *message)
410 Object *child;
412 if (child = findInterface(self,message->unit))
413 set(child,MPA_If_Name,message->name);
416 /***********************************************************************/
418 static ULONG
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;
423 ULONG res;
425 res = 0;
427 while (mpsg = (struct MPS_Msg *)GetMsg(MiamiPanelBaseIntern->mpb_port))
429 res++;
431 switch (mpsg->type)
433 case MPV_Msg_Type_Cleanup:
434 DoMethod(_app(self),MUIM_Application_PushMethod,(ULONG)_app(self),2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
435 break;
437 case MPV_Msg_Type_AddInterface:
438 addInterface(CLASS,self,data,(APTR)mpsg);
439 break;
441 case MPV_Msg_Type_DelInterface:
442 delInterface(CLASS,self,data,(APTR)mpsg);
443 break;
445 case MPV_Msg_Type_SetInterfaceState:
446 setInterfaceState(CLASS,self,data,(APTR)mpsg);
447 break;
449 case MPV_Msg_Type_SetInterfaceSpeed:
450 setInterfaceSpeed(CLASS,self,data,(APTR)mpsg);
451 break;
453 case MPV_Msg_Type_InterfaceReport:
454 interfaceReport(CLASS,self,data,(APTR)mpsg);
455 break;
457 case MPV_Msg_Type_RefreshName:
458 refreshName(CLASS,self,data,(APTR)mpsg);
459 break;
461 case MPV_Msg_Type_ToFront:
463 ULONG iconified;
465 get(_app(self),MUIA_Application_Iconified,&iconified);
466 if (iconified) set(_app(self),MUIA_Application_Iconified,FALSE);
467 else
468 if (data->flags & FLG_Setup) set(_win(self),MUIA_Window_Open,TRUE);
469 else DisplayBeep(0);
470 break;
473 case MPV_Msg_Type_InhibitRefresh:
475 struct MPS_Msg_InhibitRefresh *m = (struct MPS_Msg_InhibitRefresh *)mpsg;
477 if (m->val)
479 if (!data->refresh++)
480 DoMethod(self,MUIM_Group_InitChange);
482 else
483 if (data->refresh && !--data->refresh)
484 DoMethod(self,MUIM_Group_ExitChange);
485 break;
488 default:
489 break;
492 if (mpsg->flags & MPV_Msg_Flags_Reply) ReplyMsg((struct Message *)mpsg);
493 else freeMsg(mpsg, MiamiPanelBaseIntern);
496 return res;
499 /***********************************************************************/
501 static ULONG
502 MUIPC_IfGroup__MPM_IfGroup_GrabIFList(struct IClass *CLASS,Object *self,Msg message)
504 struct List *l;
505 Object *cstate;
506 Object *child;
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))
517 UBYTE *name;
518 ULONG scale;
520 if (get(child,MPA_If_Name,&name))
522 get(child,MPA_If_Scale,&scale);
523 createIFNode(prefs,name,scale, MiamiPanelBaseIntern);
527 return NULL;
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);
546 return 0;
548 BOOPSI_DISPATCHER_END
550 /***********************************************************************/
552 static ULONG defScales[] =
554 6000,
555 12000,
556 32000,
557 64000,
558 128000,
559 256000,
560 512000,
561 1024000,
565 struct TagItem scales[] =
567 TAG_SCALE_1, 6000,
568 TAG_SCALE_2, 12000,
569 TAG_SCALE_3, 32000,
570 TAG_SCALE_4, 64000,
571 TAG_SCALE_5, 128000,
572 TAG_SCALE_6, 256000,
573 TAG_SCALE_7, 512000,
574 TAG_SCALE_8, 1024000,
575 TAG_DONE
578 static UBYTE scaleStrings[TAG_SCALE_LAST-TAG_SCALE-1][64];
580 ULONG
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))
586 struct NewMenu *nm;
587 struct TagItem *t;
588 UBYTE *scaleFmt;
589 BPTR file;
590 ULONG *ids;
591 int i;
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))
597 UBYTE buf[32];
599 i = 0;
601 while (FGets(file,buf,sizeof(buf)))
603 UBYTE *s;
605 for (s = buf; *s && *s!='\n' && *s!='\r'; s++);
606 *s = 0;
608 if (!*buf || *buf==';') continue;
610 scales[i++].ti_Data = atoi(buf);
611 if (i==TAG_SCALE_LAST-TAG_SCALE-1) break;
614 Close(file);
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++);
628 return TRUE;
631 return FALSE;
634 /***********************************************************************/