tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / MUI.MiamiPanel / Classes / muimiamipanel_class_rate.c
blob2d1cec3d94d798530856dbc8a8663d0e7d2048bf
2 #include <proto/intuition.h>
3 #include <proto/muimaster.h>
4 #include <proto/utility.h>
6 #include <libraries/mui.h>
7 #include <libraries/gadtools.h>
9 #include <stdio.h>
10 #include <string.h>
12 #include "muimiamipanel_intern.h"
13 #include "muimiamipanel_locale.h"
14 #include "muimiamipanel_misc.h"
16 /***********************************************************************/
18 static UBYTE *bpss, *Kbss, *Mbss;
20 struct MiamiPanelRateClass_DATA
22 ULONG rate;
23 ULONG flags;
24 UBYTE cont[36];
27 enum
29 FLG_Short = 1<<0,
30 FLG_NoGrouping = 1<<1,
33 /***********************************************************************/
35 static struct MiamiPanelBase_intern *MiamiPanelBaseIntern;
37 static ULONG
38 MUIPC_Rate__OM_NEW(struct IClass *CLASS,Object *self,struct opSet *message)
40 register struct TagItem *attrs = message->ops_AttrList;
42 if (self = (Object *)DoSuperNewTags
44 CLASS, self, NULL,
46 MUIA_Frame, MUIV_Frame_Gauge,
47 MUIA_Gauge_Horiz, TRUE,
48 MUIA_Gauge_InfoText, "0",
49 TAG_MORE, attrs))
51 message->MethodID = OM_SET;
52 DoMethodA(self,(Msg)message);
53 message->MethodID = OM_NEW;
56 return (ULONG)self;
59 /***********************************************************************/
61 static ULONG
62 MUIPC_Rate__OM_SET(struct IClass *CLASS,Object *self,struct opSet *message)
64 register struct MiamiPanelRateClass_DATA *data = INST_DATA(CLASS,self);
65 register struct TagItem *tag;
66 struct TagItem *tstate;
67 register ULONG redraw;
69 for (redraw = FALSE, tstate = message->ops_AttrList; tag = NextTagItem(&tstate); )
71 register ULONG tidata = tag->ti_Data;
73 switch(tag->ti_Tag)
75 case MPA_Prefs:
76 if (!BOOLSAME(PREFS(tidata)->flags & MPV_Flags_RateShort,data->flags & FLG_Short) ||
77 !BOOLSAME(PREFS(tidata)->flags & MPV_Flags_RateNoGrouping,data->flags & FLG_NoGrouping))
79 if (PREFS(tidata)->flags & MPV_Flags_RateShort) data->flags |= FLG_Short;
80 else data->flags &= ~FLG_Short;
82 if (PREFS(tidata)->flags & MPV_Flags_RateNoGrouping) data->flags |= FLG_NoGrouping;
83 else data->flags &= ~FLG_NoGrouping;
85 redraw = TRUE;
87 break;
89 case MPA_Value:
90 if (data->rate!=tidata)
92 data->rate = tidata;
93 redraw = TRUE;
95 SetSuperAttrs(CLASS, self, MUIA_Gauge_Current, tidata, TAG_DONE);
96 break;
100 if (redraw)
102 UBYTE cont[36];
103 register ULONG rate = data->rate;
105 if (data->flags & FLG_Short)
107 UBYTE buf[16], *dp = MiamiPanelBaseIntern->mpb_decPoint;
108 ULONG q, r;
110 if (rate>=1000000)
112 q = rate/1000000;
113 r = rate%1000000;
114 sprintf(buf, "%u", q);
115 r = r/1000;
116 if (!(data->flags & FLG_NoGrouping)) grouping(buf, MiamiPanelBaseIntern);
117 sprintf(cont,"%s%s%3.3lu %s",buf,dp,r,Mbss);
119 else
121 q = rate/1000;
122 r = rate%1000;
123 sprintf(buf, "%u", q);
124 if (!(data->flags & FLG_NoGrouping)) grouping(buf, MiamiPanelBaseIntern);
125 sprintf(cont,"%s%s%1.1lu %s",buf,dp,(r<100) ? 0 : r,Kbss);
128 else
130 sprintf(cont, "%u", rate);
131 if (!(data->flags & FLG_NoGrouping)) grouping(cont, MiamiPanelBaseIntern);
132 strcat(cont," ");
133 strcat(cont,bpss);
136 sprintf(data->cont,"\33l%s",cont);
137 SetSuperAttrs(CLASS, self, MUIA_Gauge_InfoText, data->cont,TAG_DONE);
140 return DoSuperMethodA(CLASS,self,(Msg)message);
143 /***********************************************************************/
145 BOOPSI_DISPATCHER(IPTR, MUIPC_Rate_Dispatcher, CLASS, self, message)
147 switch (message->MethodID)
149 case OM_SET: return MUIPC_Rate__OM_SET(CLASS,self,(APTR)message);
150 case OM_NEW: return MUIPC_Rate__OM_NEW(CLASS,self,(APTR)message);
151 default: return DoSuperMethodA(CLASS,self,message);
153 return 0;
155 BOOPSI_DISPATCHER_END
157 /***********************************************************************/
159 ULONG
160 MUIPC_Rate_ClassInit(struct MiamiPanelBase_intern *MiamiPanelBase)
162 MiamiPanelBaseIntern = MiamiPanelBase;
163 if (MiamiPanelBaseIntern->mpb_rateClass = MUI_CreateCustomClass(NULL,MUIC_Gauge,NULL,sizeof(struct MiamiPanelRateClass_DATA), MUIPC_Rate_Dispatcher))
165 bpss = __(MSG_Rate_Bs);
166 Kbss = __(MSG_Rate_KBs);
167 Mbss = __(MSG_Rate_MBs);
169 return TRUE;
172 return FALSE;
175 /***********************************************************************/