Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / network / stacks / AROSTCP / MUI.MiamiPanel / muimiamipanel_misc.c
blob3e011c6d2abdc93d8e8c842196b2e5bfb959c2e6
2 #include <proto/exec.h>
3 #include <proto/intuition.h>
4 #include <proto/muimaster.h>
5 #include <proto/utility.h>
7 #include <mui/Urltext_mcc.h>
9 #include "muimiamipanel_intern.h"
10 #include "muimiamipanel_misc.h"
11 #include "muimiamipanel_locale.h"
13 /***********************************************************************/
15 #if !defined(__MORPHOS____) && !defined(__AROS__)
16 ULONG STDARGS
17 DoSuperNew(struct IClass *cl, Object *obj, ULONG tag1,...)
19 return DoSuperMethod(cl, obj, OM_NEW, &tag1, NULL);
21 #endif
23 /***********************************************************************/
25 Object *
26 ovfixspace(void)
28 return RectangleObject,
29 MUIA_FixHeightTxt, "A",
30 End;
33 /****************************************************************************/
35 Object *
36 ohfixspace(void)
38 return RectangleObject,
39 MUIA_FixWidthTxt, "A",
40 End;
43 /****************************************************************************/
45 Object *
46 otextitem(void)
48 return TextObject,
49 MUIA_Text_Contents, "-",
50 MUIA_Text_SetMax, TRUE,
51 End;
54 /****************************************************************************/
56 Object *
57 obartitle(ULONG id, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
59 return MUI_MakeObject(MUIO_BarTitle, __(id));
62 /****************************************************************************/
64 Object *
65 owspace(ULONG weight)
67 return RectangleObject,
68 MUIA_Weight, weight,
69 End;
72 /****************************************************************************/
74 Object *
75 olabel(ULONG id, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
77 return Label(__(id));
80 /****************************************************************************/
82 Object *
83 olabel1(ULONG id, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
85 return Label1(__(id));
88 /****************************************************************************/
90 Object *
91 ollabel1(ULONG id, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
93 return LLabel1(__(id));
96 /***********************************************************************/
98 Object *
99 olabel2(ULONG id, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
101 return Label2(__(id));
104 /***********************************************************************/
106 Object *
107 obutton(ULONG label, ULONG help, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
109 register Object *obj;
111 if (obj = MUI_MakeObject(MUIO_Button, __(label)))
112 SetAttrs(obj, MUIA_CycleChain, TRUE,
113 MUIA_ShortHelp, __(help),
114 TAG_DONE);
116 return obj;
119 /***********************************************************************/
121 Object *
122 ourlText(UBYTE *url, UBYTE *text, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
124 return UrltextObject,
125 MUIA_Urltext_Text, text,
126 MUIA_Urltext_Url, url,
127 MUIA_Urltext_SetMax, 0,
128 End;
131 /***********************************************************************/
133 Object *
134 ocheck(ULONG key, ULONG help, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
136 register Object *obj;
138 if (obj = MUI_MakeObject(MUIO_Checkmark, __(key)))
139 SetAttrs(obj, MUIA_CycleChain, TRUE, MUIA_ShortHelp, __(help), TAG_DONE);
141 return obj;
144 /***********************************************************************/
146 Object *
147 ocycle(ULONG key, UBYTE **entries, ULONG help, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
149 register Object *obj;
151 if (obj = MUI_MakeObject(MUIO_Cycle, __(key), (ULONG)entries))
152 SetAttrs(obj, MUIA_CycleChain, TRUE, MUIA_ShortHelp,__(help), TAG_DONE);
154 return obj;
157 /***********************************************************************/
159 ULONG
160 openWindow(Object *app, Object *win, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
162 ULONG v;
164 if (win)
166 set(win, MUIA_Window_Open, TRUE);
167 get(win, MUIA_Window_Open, &v);
168 if (!v) get(app, MUIA_Application_Iconified, &v);
170 else v = FALSE;
172 if (!v) DisplayBeep(0);
174 return v;
177 /***********************************************************************/
179 void
180 grouping(UBYTE *source, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
182 UBYTE buf[256];
183 register UBYTE *s, *d, c = MiamiPanelBaseIntern->mpb_groupSep[0];
184 int j;
186 for (j = 3, s = source+strlen(source)-1, d = buf; s>=source; j--, d++, s--)
188 if (!j)
190 j = 3;
191 *d++ = c;
194 *d = *s;
196 *d = 0;
198 for (s = buf+strlen(buf)-1, d = source; s>=buf; d++, s--) *d = *s;
199 *d = 0;
202 /***********************************************************************/
204 #if !defined(__AROS__)
205 #ifdef __MORPHOS__
206 void
207 sprintf(UBYTE *to, UBYTE *fmt,...)
209 va_list args;
211 va_start(args, fmt);
212 VNewRawDoFmt(fmt, (APTR)0, to, args);
213 va_end(args);
215 #else
216 static UWORD fmtfunc[] = { 0x16c0, 0x4e75 };
218 void
219 sprintf(UBYTE *to, UBYTE *fmt,...)
221 RawDoFmt(fmt, &fmt+1, (APTR)fmtfunc, to);
223 #endif
224 #endif /* !__AROS__ */
226 /***********************************************************************/
228 #if !defined(__AROS__)
229 #ifdef __MORPHOS__
230 static void
231 snprintfStuff(void)
233 register struct stream *s = (struct stream *)REG_A3;
234 register UBYTE c = (UBYTE)REG_D0;
235 #else
236 static void ASM
237 snprintfStuff(REG(d0, UBYTE c), REG(a3, struct stream *s))
239 #endif
241 if (!s->stop)
243 if (++s->counter>=s->size)
245 *(s->buf) = 0;
246 s->stop = 1;
248 else *(s->buf++) = c;
252 #ifdef __MORPHOS__
253 static struct EmulLibEntry snprintfStuffTrap = {TRAP_LIB, 0, (void *)&snprintfStuff};
254 #endif
257 int STDARGS
258 snprintf(UBYTE *buf, int size, UBYTE *fmt,...)
260 struct stream s;
261 #ifdef __MORPHOS__
262 va_list va;
264 va_start(va,fmt);
265 #endif
267 s.buf = buf;
268 s.size = size;
269 s.counter = 0;
270 s.stop = 0;
272 #ifdef __MORPHOS__
273 RawDoFmt(fmt, va->overflow_arg_area, (APTR)&snprintfStuffTrap, &s);
274 va_end(va);
275 #else
276 RawDoFmt(fmt, &fmt+1, (APTR)snprintfStuff, &s);
277 #endif
279 return s.counter-1;
281 #endif
283 /****************************************************************************/
285 ** The following functions are used
286 ** to handle the per interface scale
289 ULONG
290 IDToValue(Tag tag, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
292 return GetTagData(tag, 0, scales);
294 /****************************************************************************/
297 valueToID(ULONG val)
299 register struct TagItem *t;
301 for (t = scales; (t->ti_Tag!=TAG_DONE) && (t->ti_Data!=val); t++);
303 return t->ti_Tag;
306 /****************************************************************************/
308 struct ifnode *
309 createIFNode(struct MPS_Prefs *prefs,UBYTE *name,ULONG scale, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
311 register struct ifnode *ifnode;
313 ObtainSemaphore(&MiamiPanelBaseIntern->mpb_memSem);
315 if (ifnode = AllocPooled(MiamiPanelBaseIntern->mpb_pool, sizeof(struct ifnode)))
317 stccpy(ifnode->name,name, sizeof(ifnode->name));
318 ifnode->scale = scale;
320 AddHead((struct List *)&prefs->iflist, (struct Node *)ifnode);
323 ReleaseSemaphore(&MiamiPanelBaseIntern->mpb_memSem);
325 return ifnode;
328 /****************************************************************************/
330 struct ifnode *
331 findIFNode(struct MPS_Prefs *prefs,UBYTE *name)
333 register struct ifnode *ifnode;
335 for (ifnode = (struct ifnode *)prefs->iflist.mlh_Head; ifnode->link.mln_Succ; ifnode = (struct ifnode *)ifnode->link.mln_Succ)
336 if (!strcmp(ifnode->name,name)) break;
338 return (ifnode->link.mln_Succ) ? ifnode : NULL;
341 /****************************************************************************/
343 void
344 freeIFList(struct MPS_Prefs *prefs, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
346 register struct Node *node;
348 ObtainSemaphore(&MiamiPanelBaseIntern->mpb_memSem);
350 while (node = RemHead((struct List *)&prefs->iflist))
351 FreePooled(MiamiPanelBaseIntern->mpb_pool, node, sizeof(struct ifnode));
353 ReleaseSemaphore(&MiamiPanelBaseIntern->mpb_memSem);
356 /****************************************************************************/
358 void
359 moveMinList(struct MinList *to,struct MinList *from, struct MiamiPanelBase_intern *MiamiPanelBaseIntern)
361 register struct Node *node;
363 while (node = RemTail((struct List *)from)) AddTail((struct List *)to, node);
366 /****************************************************************************/
368 #ifdef __MORPHOS__
369 void *
370 memcpy(void *to,const void *from,size_t len)
372 CopyMem((APTR)from, (APTR)to, len);
374 return to;
376 #endif
378 /****************************************************************************/