tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / MUI.MiamiPanel / Classes / muimiamipanel_class_if.c
blob5b026988bc14cd09c6bb4a3734a7b37c148bff7b
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 "muimiamipanel_intern.h"
11 #include "muimiamipanel_locale.h"
12 #include "muimiamipanel_misc.h"
13 #include "muimiamipanel_commands.h"
15 #include <mui/Busy_mcc.h>
17 /***********************************************************************/
19 struct MiamiPanelIfClass_DATA
21 Object *this;
23 Object *g;
24 Object *name;
25 Object *slabel;
26 Object *state;
27 Object *busy;
28 Object *lbutton;
30 Object *ontime;
31 Object *traffic;
32 Object *rate;
33 Object *speed;
35 APTR cmenu;
36 APTR cmtitle;
37 APTR cmonline;
38 APTR cmoffline;
40 UBYTE namev[16];
41 long unitv;
42 ULONG ontimev;
43 ULONG statev;
45 ULONG scale;
47 ULONG flags;
50 enum
52 FLG_UseBusyBar = 1<<0,
53 FLG_BusyBarInUse = 1<<1,
56 /***********************************************************************/
58 #define SHOW_ALL (MIAMIPANELV_Init_Flags_ShowStatusButton|MIAMIPANELV_Init_Flags_ShowSpeed|MIAMIPANELV_Init_Flags_ShowDataTransferRate|MIAMIPANELV_Init_Flags_ShowUpTime|MIAMIPANELV_Init_Flags_ShowTotal)
60 static struct MiamiPanelBase_intern *MiamiPanelBaseIntern;
62 static ULONG
63 MUIPC_If__OM_NEW(struct IClass *CLASS,Object *self,struct opSet *message)
65 struct MiamiPanelIfClass_DATA temp;
66 struct TagItem *attrs = message->ops_AttrList, *tag;
67 struct MPS_Prefs *prefs = (struct MPS_Prefs *)GetTagData(MPA_Prefs,NULL,attrs);
68 ULONG show, lbutton, ontime, traffic, rate, speed, some;
69 UBYTE *name;
71 memset(&temp,0,sizeof(temp));
73 name = (UBYTE *)GetTagData(MPA_If_Name,NULL,attrs);
74 temp.unitv = GetTagData(MPA_If_Unit,-1,attrs);
76 show = (tag = FindTagItem(MPA_Show,attrs)) ? tag->ti_Data : SHOW_ALL;
77 lbutton = show & MIAMIPANELV_Init_Flags_ShowStatusButton;
78 ontime = show & MIAMIPANELV_Init_Flags_ShowUpTime;
79 traffic = show & MIAMIPANELV_Init_Flags_ShowTotal;
80 rate = show & MIAMIPANELV_Init_Flags_ShowDataTransferRate;
81 speed = show & MIAMIPANELV_Init_Flags_ShowSpeed;
82 some = ontime || traffic || rate || speed;
84 if (self = (Object *)DoSuperNewTags
86 CLASS, self, NULL,
88 Child, temp.g = HGroup,
90 Child, temp.name = TextObject,
91 MUIA_Text_PreParse, MUIX_B MUIX_U MUIX_C,
92 MUIA_Font, MUIV_Font_Big,
93 MUIA_FixWidthTxt, "XXXXXXXX",
94 End,
96 //Child, temp.slabel = olabel1(MSG_IF_Title_State, MiamiPanelBaseIntern),
98 Child, temp.state = TextObject,
99 //MUIA_Frame, MUIV_Frame_Text,
100 //MUIA_Background, MUII_TextBack,
101 End,
103 lbutton ? Child : TAG_IGNORE, lbutton ? (temp.lbutton = NewObject(MiamiPanelBaseIntern->mpb_lbuttonClass->mcc_Class, NULL, TAG_DONE)) : NULL,
104 End,
106 /*some ? Child : TAG_IGNORE, some ? HGroup,
107 MUIA_Weight, 0,
108 Child, RectangleObject, MUIA_Weight, 10, End,
109 Child, RectangleObject, MUIA_Rectangle_HBar, TRUE, End,
110 Child, RectangleObject, MUIA_Weight, 10, End,
111 End : 0,*/
113 some ? Child : TAG_IGNORE, some ? VSpace(4) : 0,
115 some ? Child : TAG_IGNORE, some ? ColGroup(2),
116 ontime ? Child : TAG_IGNORE, ontime ? olabel(MSG_IF_Title_OnTime, MiamiPanelBaseIntern) : NULL,
117 ontime ? Child : TAG_IGNORE, ontime ? (temp.ontime = NewObject(MiamiPanelBaseIntern->mpb_timeTextClass->mcc_Class, NULL, TAG_DONE)) : NULL,
119 traffic ? Child : TAG_IGNORE, traffic ? olabel(MSG_IF_Title_Traffic, MiamiPanelBaseIntern) : NULL,
120 traffic ? Child : TAG_IGNORE, traffic ? (temp.traffic = NewObject(MiamiPanelBaseIntern->mpb_trafficClass->mcc_Class, NULL, MPA_Prefs, prefs, TAG_DONE)) : NULL,
122 rate ? Child : TAG_IGNORE, rate ? olabel(MSG_IF_Title_Rate, MiamiPanelBaseIntern) : NULL,
123 rate ? Child : TAG_IGNORE, rate ? (temp.rate = NewObject(MiamiPanelBaseIntern->mpb_rateClass->mcc_Class, NULL, MPA_Prefs, prefs, TAG_DONE)) : NULL,
125 speed ? Child : TAG_IGNORE, speed ? olabel(MSG_IF_Title_Speed, MiamiPanelBaseIntern) : NULL,
126 speed ? Child : TAG_IGNORE, speed ? (temp.speed = TextObject, End) : NULL,
127 End : 0,
129 TAG_MORE,attrs))
131 struct MiamiPanelIfClass_DATA *data = INST_DATA(CLASS,self);
133 CopyMem(&temp,data,sizeof(struct MiamiPanelIfClass_DATA));
135 data->busy = BusyObject,
136 MUIA_Weight, 50,
137 MUIA_Busy_ShowHideIH, TRUE,
138 MUIA_Busy_Speed, MUIV_Busy_Speed_User,
139 End;
141 if (data->cmenu = (APTR)GetTagData(MUIA_ContextMenu,NULL,attrs))
143 data->cmtitle = (APTR)DoMethod(data->cmenu,MUIM_FindUData,MSG_Menu_Project);
144 data->cmonline = (APTR)DoMethod(data->cmenu,MUIM_FindUData,MSG_IFGroup_CItem_Online);
145 data->cmoffline = (APTR)DoMethod(data->cmenu,MUIM_FindUData,MSG_IFGroup_CItem_Offline);
148 if (data->lbutton)
149 DoMethod(data->lbutton,MUIM_Notify,MUIA_Pressed,0,(ULONG)self,1,MPM_If_Switch);
151 if (data->rate)
153 struct ifnode *ifnode;
155 if (ifnode = findIFNode(prefs,name)) data->scale = ifnode->scale;
156 else data->scale = DEF_Scale;
158 set(data->rate,MUIA_Gauge_Max,data->scale);
161 data->this = self;
163 message->MethodID = OM_SET;
164 DoMethodA(self,(Msg)message);
165 message->MethodID = OM_NEW;
168 return (ULONG)self;
171 /***********************************************************************/
173 static void
174 showBar(Object *self,struct MiamiPanelIfClass_DATA *data,ULONG show)
176 if (data->busy)
178 Object *parent;
180 get(self,MUIA_Parent,&parent);
181 if (parent) DoMethod(parent,MUIM_Group_InitChange);
182 DoMethod(data->g,MUIM_Group_InitChange);
184 if (show)
186 DoMethod(data->g,OM_ADDMEMBER,(ULONG)data->busy);
187 DoMethod(data->g,MUIM_Group_Sort,(ULONG)data->name,/*(ULONG)data->slabel,*/(ULONG)data->state,(ULONG)data->busy,(ULONG)data->lbutton,NULL);
189 else DoMethod(data->g,OM_REMMEMBER,(ULONG)data->busy);
191 DoMethod(data->g,MUIM_Group_ExitChange);
192 if (parent) DoMethod(parent,MUIM_Group_ExitChange);
196 /***********************************************************************/
198 static ULONG
199 changeState(Object *self,struct MiamiPanelIfClass_DATA *data,ULONG state)
201 ULONG sstring, busy;
203 if (state & MIAMIPANELV_AddInterface_State_GoingOnline) state = MIAMIPANELV_AddInterface_State_GoingOnline, sstring = MSG_IF_Status_GoingOnline, busy = TRUE;
204 else if (state & MIAMIPANELV_AddInterface_State_GoingOffline) state = MIAMIPANELV_AddInterface_State_GoingOffline, sstring = MSG_IF_Status_GoingOffline, busy = TRUE;
205 else if (state & MIAMIPANELV_AddInterface_State_Suspending) state = MIAMIPANELV_AddInterface_State_Suspending, sstring = MSG_IF_Status_Suspending, busy = TRUE;
206 else if (state & MIAMIPANELV_AddInterface_State_Offline) state = MIAMIPANELV_AddInterface_State_Offline, sstring = MSG_IF_Status_Offline, busy = FALSE;
207 else if (state & MIAMIPANELV_AddInterface_State_Online) state = MIAMIPANELV_AddInterface_State_Online, sstring = MSG_IF_Status_Online, busy = FALSE;
208 else if (state & MIAMIPANELV_AddInterface_State_Suspended) state = MIAMIPANELV_AddInterface_State_Suspended, sstring = MSG_IF_Status_Suspended, busy = FALSE;
209 else state = MIAMIPANELV_AddInterface_State_Offline, sstring = MSG_IF_Status_Offline, busy = FALSE;
211 data->statev = state;
213 if (data->lbutton) set(data->lbutton,MPA_LButton_State,state);
214 set(data->state,MUIA_Text_Contents, __(sstring));
216 if ((data->flags & FLG_UseBusyBar) && !BOOLSAME(data->flags & FLG_BusyBarInUse,busy))
217 showBar(self,data,busy);
219 if (busy) data->flags |= FLG_BusyBarInUse;
220 else data->flags &= ~FLG_BusyBarInUse;
222 return 0;
225 /***********************************************************************/
227 static ULONG
228 MUIPC_If__OM_SET(struct IClass *CLASS,Object *self,struct opSet *message)
230 struct MiamiPanelIfClass_DATA *data = INST_DATA(CLASS,self);
231 struct TagItem *tag;
232 struct TagItem *tstate;
234 for (tstate = message->ops_AttrList; tag = NextTagItem(&tstate); )
236 ULONG tidata = tag->ti_Data;
238 switch(tag->ti_Tag)
240 case MPA_If_Name:
241 stccpy(data->namev,(UBYTE *)tidata,sizeof(data->namev));
242 set(data->name,MUIA_Text_Contents,tidata);
243 break;
245 case MPA_If_State:
246 changeState(self,data,tidata);
247 break;
249 case MPA_If_Ontime:
250 data->ontimev = tidata;
251 break;
253 case MPA_If_Now:
254 if (data->ontime) set(data->ontime,MPA_Value,tidata-data->ontimev);
255 break;
257 case MPA_If_Traffic:
258 if (data->traffic) set(data->traffic,MPA_Value,tidata);
259 break;
261 case MPA_If_Rate:
262 if (data->rate) set(data->rate,MPA_Value,tidata);
263 break;
265 case MPA_If_Speed:
266 if (data->speed) set(data->speed,MUIA_Text_Contents,tidata);
267 break;
269 case MPA_Prefs:
270 if (!BOOLSAME(data->flags & FLG_UseBusyBar,PREFS(tidata)->flags & MPV_Flags_UseBusyBar))
272 if (PREFS(tidata)->flags & MPV_Flags_UseBusyBar) data->flags |= FLG_UseBusyBar;
273 else data->flags &= ~FLG_UseBusyBar;
275 if (data->flags & FLG_BusyBarInUse)
276 showBar(self,data,data->flags & FLG_UseBusyBar);
279 if (data->rate)
281 struct ifnode *ifnode;
283 if (ifnode = findIFNode(PREFS(tidata),data->namev))
284 set(data->rate, MUIA_Gauge_Max, (data->scale = ifnode->scale));
286 break;
290 return DoSuperMethodA(CLASS,self,(Msg)message);
293 /***********************************************************************/
295 static ULONG
296 MUIPC_If__OM_GET(struct IClass *CLASS,Object *self,struct opGet *message)
298 struct MiamiPanelIfClass_DATA *data = INST_DATA(CLASS,self);
300 switch(message->opg_AttrID)
302 case MPA_If_Unit: *message->opg_Storage = data->unitv; return TRUE;
303 case MPA_If_State: *message->opg_Storage = data->statev; return TRUE;
304 case MPA_If_Name: *message->opg_Storage = (ULONG)data->namev; return TRUE;
305 case MPA_If_Scale: *message->opg_Storage = data->scale; return TRUE;
306 default: return DoSuperMethodA(CLASS,self,(Msg)message);
310 /***********************************************************************/
312 static ULONG
313 MUIPC_If__MPM_If_Switch(struct IClass *CLASS,Object *self,Msg message)
315 struct MiamiPanelIfClass_DATA *data = INST_DATA(CLASS,self);
317 switch (data->statev)
319 case MIAMIPANELV_AddInterface_State_GoingOnline:
320 case MIAMIPANELV_AddInterface_State_Online:
321 MiamiPanelFun(MIAMIPANELV_CallBack_Code_UnitOffline,data->unitv);
322 break;
324 case MIAMIPANELV_AddInterface_State_Suspending:
325 case MIAMIPANELV_AddInterface_State_Suspended:
326 break;
328 default:
329 MiamiPanelFun(MIAMIPANELV_CallBack_Code_UnitOnline,data->unitv);
330 break;
333 return 0;
336 /***********************************************************************/
338 static ULONG
339 MUIPC_If__MUIM_ContextMenuBuild(struct IClass *CLASS,Object *self,struct MUIP_ContextMenuBuild *message)
341 struct MiamiPanelIfClass_DATA *data = INST_DATA(CLASS,self);
343 if (data->cmenu)
345 ULONG on, off;
347 switch (data->statev)
349 case MIAMIPANELV_AddInterface_State_GoingOnline:
350 case MIAMIPANELV_AddInterface_State_Online:
351 on = FALSE;
352 off = TRUE;
353 break;
355 case MIAMIPANELV_AddInterface_State_Suspending:
356 case MIAMIPANELV_AddInterface_State_Suspended:
357 on = off = FALSE;
358 break;
360 default:
361 on = TRUE;
362 off = FALSE;
363 break;
366 set(data->cmtitle,MUIA_Menu_Title, data->namev);
367 set(data->cmonline,MUIA_Menuitem_Enabled,on);
368 set(data->cmoffline,MUIA_Menuitem_Enabled,off);
370 if (data->rate)
371 set((Object *)DoMethod(data->cmenu,MUIM_FindUData,valueToID(data->scale)),MUIA_Menuitem_Checked,TRUE);
373 return (ULONG)data->cmenu;
376 return DoSuperMethodA(CLASS,self,(Msg)message);
379 /***********************************************************************/
381 static ULONG
382 MUIPC_If__MUIM_ContextMenuChoice(struct IClass *CLASS,Object *self,struct MUIP_ContextMenuChoice *message)
384 struct MiamiPanelIfClass_DATA *data = INST_DATA(CLASS,self);
385 ULONG item = muiUserData(message->item);
387 switch (item)
389 case MSG_IFGroup_CItem_Online:
390 case MSG_IFGroup_CItem_Offline:
391 DoMethod(data->this,MPM_If_Switch);
392 break;
394 case TAG_SCALE_1: case TAG_SCALE_2: case TAG_SCALE_3:
395 case TAG_SCALE_4: case TAG_SCALE_5: case TAG_SCALE_6:
396 case TAG_SCALE_7: case TAG_SCALE_8:
397 if (data->rate)
399 data->scale = IDToValue((ULONG)item, MiamiPanelBaseIntern);
400 set(data->rate,MUIA_Gauge_Max,data->scale);
402 break;
405 return 0;
408 /***********************************************************************/
410 BOOPSI_DISPATCHER(IPTR, MUIPC_If_Dispatcher, CLASS, self, message)
412 switch (message->MethodID)
414 case OM_NEW: return MUIPC_If__OM_NEW(CLASS,self,(APTR)message);
415 case OM_SET: return MUIPC_If__OM_SET(CLASS,self,(APTR)message);
416 case OM_GET: return MUIPC_If__OM_GET(CLASS,self,(APTR)message);
417 case MUIM_ContextMenuChoice: return MUIPC_If__MUIM_ContextMenuChoice(CLASS,self,(APTR)message);
418 case MUIM_ContextMenuBuild: return MUIPC_If__MUIM_ContextMenuBuild(CLASS,self,(APTR)message);
419 case MPM_If_Switch: return MUIPC_If__MPM_If_Switch(CLASS,self,(APTR)message);
420 default: return DoSuperMethodA(CLASS,self,message);
422 return 0;
424 BOOPSI_DISPATCHER_END
426 /***********************************************************************/
428 ULONG
429 MUIPC_If_ClassInit(struct MiamiPanelBase_intern *MiamiPanelBase)
431 MiamiPanelBaseIntern = MiamiPanelBase;
432 return (ULONG)(MiamiPanelBaseIntern->mpb_ifClass = MUI_CreateCustomClass(NULL, MUIC_Group, NULL, sizeof(struct MiamiPanelIfClass_DATA), MUIPC_If_Dispatcher));
435 /***********************************************************************/