added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / tools / commodities / startmenu / main.c
blob7d707804c168805d4eb9200046b412f70df52e39
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <intuition/intuition.h>
7 #include <intuition/intuitionbase.h>
8 #include <graphics/gfx.h>
9 #include <graphics/gfxbase.h>
10 #include <cybergraphx/cybergraphics.h>
11 #include <libraries/commodities.h>
12 #include <libraries/locale.h>
13 #include <proto/exec.h>
14 #include <proto/dos.h>
15 #include <proto/intuition.h>
16 #include <proto/graphics.h>
17 #include <proto/cybergraphics.h>
18 #include <proto/layers.h>
19 #include <proto/commodities.h>
20 #include <proto/locale.h>
21 #include <proto/alib.h>
23 #include <aros/debug.h>
25 #include <stdio.h>
26 #include <stdlib.h>
28 #define CATCOMP_NUMBERS
29 #define CATCOMP_STRINGS
30 #define CATCOMP_ARRAY
32 #include "../strings.h"
34 #include "main.h"
35 #include "support.h"
36 #include "settings.h"
37 #include "logodata.h"
39 /************************************************************************************/
41 UBYTE version[] = "$VER: StartMenu 0.2 (13.10.2001)";
43 #define ARG_TEMPLATE "CX_PRIORITY=PRI/N/K,HIDE/S"
45 #define ARG_PRI 0
46 #define ARG_HIDE 1
47 #define NUM_ARGS 2
49 struct IntuitionBase *IntuitionBase = NULL;
50 struct GfxBase *GfxBase = NULL;
51 struct Library *CyberGfxBase = NULL;
52 struct Library *LayersBase = NULL;
53 struct Library *CxBase = NULL;
54 struct LocaleBase *LocaleBase = NULL;
56 /* Libraries to open */
57 struct LibTable
59 APTR lT_Library;
60 STRPTR lT_Name;
61 ULONG lT_Version;
63 libTable[] =
65 { &IntuitionBase, "intuition.library", 39L },
66 { &GfxBase, "graphics.library", 39L },
67 { &CyberGfxBase, "cybergraphics.library", 39L },
68 { &LayersBase, "layers.library", 39L },
69 { &CxBase, "commodities.library", 39L },
70 { NULL }
73 static struct NewBroker nb =
75 NB_VERSION,
76 NULL,
77 NULL,
78 NULL,
79 NBU_NOTIFY | NBU_UNIQUE,
82 NULL,
86 static struct Catalog *catalogPtr;
88 static struct MsgPort *cxport;
90 static struct RDArgs *myargs;
91 static struct Screen *scr;
92 static struct Window *panelwin;
93 static struct DrawInfo *dri;
94 static struct TextFont *scrfont;
95 static struct RastPort *panelrp;
97 static CxObj *cxbroker, *cxcust;
98 static UBYTE *logodata;
99 static ULONG *logopal;
100 static UWORD *scrpens;
101 static ULONG cxmask, panelmask;
102 static WORD scrfontw, scrfonth, logowidth, logoheight, logocols, logomod;
103 static WORD logobutwidth, logobutheight, panelbutheight, panelwidth, panelheight, visiblepanelheight;
104 static WORD panelstuffy, logobutposx, logobutposy, logoposx, logoposy;
105 static WORD scrwidth, scrheight, scrdepth, shinepen, shadowpen, bgpen;
106 static WORD textpen, hitextpen;
107 static BOOL quitme, disabled, is_truecolor, panellogodown;
109 static LONG args[NUM_ARGS];
110 static char s[256];
112 static struct Task *maintask;
113 static ULONG actionbit;
114 static ULONG actionmask;
116 static BOOL tohide;
117 static BOOL hidden;
118 #define MINIMUM_VISIBLE 3
120 STRPTR getCatalog(struct Catalog *catalogPtr, ULONG id)
122 STRPTR string;
124 if(catalogPtr)
125 string = GetCatalogStr(catalogPtr, id, CatCompArray[id].cca_Str);
126 else
127 string = CatCompArray[id].cca_Str;
129 return(string);
132 static void HideAction(CxMsg *msg,CxObj *obj)
134 struct InputEvent *ie = (struct InputEvent *)CxMsgData(msg);
136 if (ie->ie_Class == IECLASS_RAWMOUSE)
138 tohide = ie->ie_position.ie_xy.ie_y < (scrheight - visiblepanelheight);
139 if (tohide != hidden)
141 hidden = tohide;
142 Signal(maintask, actionmask);
147 static void HandleHide(void)
149 if (tohide)
150 while (--visiblepanelheight > MINIMUM_VISIBLE)
151 MoveWindow(panelwin, 0, 1);
152 else
153 while (++visiblepanelheight < panelheight)
154 MoveWindow(panelwin, 0, -1);
157 /************************************************************************************/
159 static void Cleanup(char *msg)
161 struct Message *cxmsg;
162 struct LibTable *tmpLibTable = libTable;
164 if(msg)
166 printf("%s", msg);
169 if(IntuitionBase)
171 if(panelwin)
172 CloseWindow(panelwin);
174 if(dri)
175 FreeScreenDrawInfo(scr, dri);
177 if(scr)
178 UnlockPubScreen(0, scr);
181 if(CxBase)
182 if (cxbroker)
183 DeleteCxObjAll(cxbroker);
185 if(cxport)
187 while((cxmsg = GetMsg(cxport)))
189 ReplyMsg(cxmsg);
191 DeleteMsgPort(cxport);
194 if(myargs)
195 FreeArgs(myargs);
197 if(LocaleBase)
199 CloseCatalog(catalogPtr);
200 CloseLibrary((struct Library *)LocaleBase); /* Passing NULL is valid */
201 kprintf("Closed locale.library!\n");
204 while(tmpLibTable->lT_Name) /* Check for name rather than pointer */
206 if((*(struct Library **)tmpLibTable->lT_Library))
208 CloseLibrary((*(struct Library **)tmpLibTable->lT_Library));
209 kprintf("Closed %s!\n", tmpLibTable->lT_Name);
212 tmpLibTable++;
215 if(actionbit)
216 FreeSignal(actionbit);
218 exit(0);
221 /************************************************************************************/
223 static void DosError(void)
225 Fault(IoErr(),0,s,255);
226 Cleanup(s);
229 /************************************************************************************/
231 static void Init(void)
233 #if USE_LOGO2
234 logopal = logo2_pal;
235 logodata = logo2_data;
237 logowidth = LOGO2_WIDTH;
238 logoheight = LOGO2_HEIGHT;
239 logocols = LOGO2_COLORS;
240 logomod = LOGO2_MODULO;
241 #else
242 logopal = logo1_pal;
243 logodata = logo1_data;
245 logowidth = LOGO1_WIDTH;
246 logoheight = LOGO1_HEIGHT;
247 logocols = LOGO1_COLORS;
248 logomod = LOGO1_MODULO;
249 #endif
252 /************************************************************************************/
254 static void OpenLibs(void)
256 struct LibTable *tmpLibTable = libTable;
257 UBYTE tmpString[128]; /* petah: What if library name plus error message exceeds 128 bytes? */
259 if((LocaleBase = (struct LocaleBase *)OpenLibrary("locale.library", 40)))
261 catalogPtr = OpenCatalog(NULL, "Sys/Commodities.catalog", OC_BuiltInLanguage, "english", TAG_DONE);
263 else
264 kprintf("Warning: Can't open locale.library V40!\n");
266 while(tmpLibTable->lT_Library)
268 if(!((*(struct Library **)tmpLibTable->lT_Library = OpenLibrary(tmpLibTable->lT_Name, tmpLibTable->lT_Version))))
270 sprintf(tmpString, getCatalog(catalogPtr, MSG_CANT_OPEN_LIB), tmpLibTable->lT_Name, tmpLibTable->lT_Version);
271 Cleanup(tmpString);
273 else
274 kprintf("Library %s opened!\n", tmpLibTable->lT_Name);
276 tmpLibTable++;
280 /************************************************************************************/
282 static void GetArguments(void)
284 if (!(myargs = ReadArgs(ARG_TEMPLATE, args, 0)))
286 DosError();
289 if (args[ARG_PRI]) nb.nb_Pri = *(LONG *)args[ARG_PRI];
292 /************************************************************************************/
294 static void InitCX(void)
296 if (!(cxport = CreateMsgPort()))
298 Cleanup(getCatalog(catalogPtr, MSG_CANT_CREATE_MSGPORT));
301 nb.nb_Port = cxport;
303 cxmask = 1L << cxport->mp_SigBit;
305 if (!(cxbroker = CxBroker(&nb, 0)))
307 Cleanup(getCatalog(catalogPtr, MSG_CANT_CREATE_BROKER));
310 if (args[ARG_HIDE])
312 if (!(cxcust = CxCustom(HideAction, 0)))
314 Cleanup(getCatalog(catalogPtr, MSG_CANT_CREATE_CUSTOM));
317 AttachCxObj(cxbroker, cxcust);
319 ActivateCxObj(cxbroker, 1);
323 /***********************************************************************************/
325 static void GetVisual(void)
327 if (!(scr = LockPubScreen(NULL)))
329 Cleanup(getCatalog(catalogPtr, MSG_CANT_LOCK_SCR));
332 if (!(dri = GetScreenDrawInfo(scr)))
334 Cleanup("Can't get screen drawinfo! (This shouldn't happen?!)\n");
337 scrwidth = scr->Width;
338 scrheight = scr->Height;
340 scrdepth = GetBitMapAttr(scr->RastPort.BitMap, BMA_DEPTH);
341 if (scrdepth > 8) is_truecolor = TRUE;
343 scrfont = dri->dri_Font;
344 scrfontw = scrfont->tf_XSize;
345 scrfonth = scrfont->tf_YSize;
347 scrpens = dri->dri_Pens;
348 shinepen = scrpens[SHINEPEN];
349 shadowpen = scrpens[SHADOWPEN];
350 bgpen = scrpens[BACKGROUNDPEN];
351 textpen = scrpens[TEXTPEN];
352 hitextpen = scrpens[HIGHLIGHTTEXTPEN];
356 /***********************************************************************************/
358 static void RenderPanelLogo(BOOL recessed)
360 RenderFrame(panelrp,
361 dri,
362 logobutposx,
363 logobutposy,
364 logobutposx + logobutwidth - 1,
365 logobutposy + logobutheight - 1,
366 recessed);
368 if (is_truecolor)
370 FillPixelArray(panelrp,
371 logobutposx + 1,
372 logobutposy + 1,
373 logobutwidth - 2,
374 logobutheight - 2,
375 logopal[0]);
377 WriteLUTPixelArray(logodata,
380 logomod,
381 panelrp,
382 logopal,
383 logoposx + (recessed ? 1 : 0),
384 logoposy + (recessed ? 1 : 0),
385 logowidth,
386 logoheight,
387 CTABFMT_XRGB8);
392 /***********************************************************************************/
394 static void RenderPanelWin(void)
396 if (!panelwin) return;
398 RenderFrame(panelrp, dri, 0, 0, panelwidth - 1, panelheight -1, FALSE);
400 SetAPen(panelrp, bgpen);
401 RectFill(panelrp, 1, 1, panelwidth - 2, panelheight - 2);
403 RenderPanelLogo(panellogodown);
406 /***********************************************************************************/
408 static void MakePanelWin(void)
410 WORD h1, h2;
412 h1 = scrfonth + BUTTON_EXTRA_HEIGHT;
413 h2 = logoheight + LOGO_EXTRA_HEIGHT;
415 panelwidth = scrwidth;
417 panelbutheight = (h1 > h2) ? h1 : h2;
418 panelheight = panelbutheight + PANEL_EXTRA_HEIGHT;
419 panelstuffy = (panelheight - panelbutheight) / 2;
421 logobutwidth = logowidth + LOGO_EXTRA_WIDTH;
422 logobutheight = panelbutheight;
424 logobutposx = LOGO_POS_X;
425 logobutposy = panelstuffy;
427 logoposx = logobutposx + LOGO_EXTRA_WIDTH / 2;
428 logoposy = logobutposy + (logobutheight - logoheight) / 2;
430 panelwin = OpenWindowTags(0, WA_PubScreen, scr,
431 WA_Left, 0,
432 WA_Top, scrheight - panelheight,
433 WA_Width, scrwidth,
434 WA_Height, panelheight,
435 WA_Borderless, TRUE,
436 WA_RMBTrap, TRUE,
437 WA_SimpleRefresh, FALSE,
438 WA_BackFill, LAYERS_NOBACKFILL,
439 WA_IDCMP, IDCMP_MOUSEBUTTONS | IDCMP_REFRESHWINDOW,
440 TAG_DONE);
442 if(!panelwin)
443 Cleanup(getCatalog(catalogPtr, MSG_CANT_CREATE_WIN));
445 visiblepanelheight = panelheight;
447 if(args[ARG_HIDE] && (panelwin->WLayer->LayerInfo->Flags & LIFLG_SUPPORTS_OFFSCREEN_LAYERS))
449 maintask = FindTask(0);
450 actionbit = AllocSignal(-1);
451 actionmask = 1 << actionbit;
453 tohide = TRUE;
454 hidden = TRUE;
455 HandleHide();
457 else
458 args[ARG_HIDE] = actionbit = actionmask = 0;
460 panelmask = 1L << panelwin->UserPort->mp_SigBit;
461 panelrp = panelwin->RPort;
463 SetFont(panelrp, scrfont);
465 RenderPanelWin();
468 /************************************************************************************/
470 static void HandleCx(void)
472 CxMsg *msg;
474 while((msg = (CxMsg *)GetMsg(cxport)))
476 switch(CxMsgType(msg))
478 case CXM_COMMAND:
479 switch(CxMsgID(msg))
481 case CXCMD_DISABLE:
482 ActivateCxObj(cxbroker,0L);
483 disabled = TRUE;
484 break;
486 case CXCMD_ENABLE:
487 ActivateCxObj(cxbroker,1L);
488 disabled = FALSE;
489 break;
491 case CXCMD_KILL:
492 quitme = TRUE;
493 break;
495 } /* switch(CxMsgID(msg)) */
496 break;
498 } /* switch (CxMsgType(msg))*/
500 ReplyMsg((struct Message *)msg);
502 } /* while((msg = (CxMsg *)GetMsg(cxport))) */
505 /************************************************************************************/
507 static void HandlePanel(void)
509 struct IntuiMessage *msg;
511 while((msg = (struct IntuiMessage *)GetMsg(panelwin->UserPort)))
513 switch(msg->Class)
515 case IDCMP_REFRESHWINDOW:
516 BeginRefresh(panelwin);
517 RenderPanelWin();
518 EndRefresh(panelwin, TRUE);
519 break;
521 } /* switch(msg->Class) */
523 } /* while ((msg = (struct IntuiMessage *)GetMsg(panelwin->UserPort))) */
526 /************************************************************************************/
528 static void HandleAll(void)
530 ULONG sigs;
532 while(!quitme)
534 sigs = Wait(cxmask | panelmask | actionmask | SIGBREAKF_CTRL_C);
536 if (sigs & actionmask) HandleHide();
537 if (sigs & cxmask) HandleCx();
538 if (sigs & panelmask) HandlePanel();
539 if (sigs & SIGBREAKF_CTRL_C) quitme = TRUE;
541 } /* while(!quitme) */
545 /************************************************************************************/
547 int main(void)
549 Init();
550 OpenLibs();
552 nb.nb_Name = getCatalog(catalogPtr, MSG_STARTMENU_CXNAME);
553 nb.nb_Title = getCatalog(catalogPtr, MSG_STARTMENU_CXTITLE);
554 nb.nb_Descr = getCatalog(catalogPtr, MSG_STARTMENU_CXDESCR);
556 GetArguments();
557 GetVisual();
558 MakePanelWin();
559 InitCX();
560 HandleAll();
561 Cleanup(0);
563 return 0;
567 /************************************************************************************/