home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 568b.lha / PowerSource_v3.0 / source.lzh / source / GadgetED.c < prev    next >
C/C++ Source or Header  |  1991-09-15  |  20KB  |  692 lines

  1. /*----------------------------------------------------------------------*
  2.   GadgetED.c version 3.0 - © Copyright 1990-91 Jaba Development
  3.  
  4.   Autor   : Jan van den Baard
  5.   Purpose : main control program.
  6.  *----------------------------------------------------------------------*/
  7.  
  8. USHORT pointer[] =
  9.  { 0x0000,0x0000,0xffff,0xffff,0xc007,0xffff,0xaffb,0xffff,
  10.    0xa439,0xffff,0xd77d,0xffff,0xf6fd,0xffff,0xf43d,0xffff,
  11.    0xf7fd,0xffff,0xf70d,0xffff,0xf7dd,0xffff,0xd7bd,0xffff,
  12.    0xa709,0xffff,0xaffb,0xffff,0xc003,0xffff,0xffff,0xffff,
  13.    0x0000,0x0000,0x0000,0x0000 };
  14. USHORT Colors[] =
  15.  { 0x0000,0x0ecb,0x0f00,0x0ff0,0x00f0,0x00c0,0x0090,0x0060,
  16.    0x000f,0x000c,0x0009,0x0ff0,0x0cc0,0x0990,0x0f0f,0x0c0c,
  17.    0x0909,0x0a00,0x0000,0x0f00,0x0444,0x0555,0x0666,0x0777,
  18.    0x0888,0x0999,0x0aaa,0x0bbb,0x0ccc,0x0ddd,0x0fff,0x0f00 };
  19. USHORT info_data[] =
  20.  { 0xee00,0xc600,0xaa00,0xee00,0xee00,0xee00,0xee00,0xaa00,
  21.    0xc600,0xee00,0xfff0,0xef70,0xdfb0,0x8010,0xdfb0,0xef70,
  22.    0xfff0,0xee00,0xc600,0xaa00,0xee00,0xee00,0xee00,0xee00,
  23.    0xee00,0xee00,0xee00,0xfff0,0xeff0,0xdff0,0x8010,0xdff0,
  24.    0xeff0,0xfff0,0xfff0,0xbdf0,0xdbf0,0xe610,0xeff0,0xde10,
  25.    0xbff0,0xfff0,0xfff8,0xbdf8,0xdbf8,0xe708,0xe7f8,0xdb08,
  26.    0xbdf8,0xfff8 };
  27.  
  28. struct Image HEIGHT_image =
  29.  { 247,0,7,10,1,NULL,0x01,0x00,NULL };
  30. struct Image WIDTH_image  =
  31.  { 197,1,12,7,1,NULL,0x01,0x00,&HEIGHT_image };
  32. struct Image TOP_image    =
  33.  { 150,0,7,10,1,NULL,0x01,0x00,&WIDTH_image };
  34. struct Image LEFT_image   =
  35.  { 100,1,12,7,1,NULL,0x01,0x00,&TOP_image };
  36. struct Image YC_image     =
  37.  { 50,1,12,8,1,NULL,0x01,0x00,&LEFT_image };
  38. struct Image XC_image     =
  39.  { 0,1,13,8,1,NULL,0x01,0x00,&YC_image };
  40.  
  41. #define DATA_SIZE_TOTAL 100
  42. #define HEIGHT_OFFSET   0
  43. #define WIDTH_OFFSET    10
  44. #define TOP_OFFSET      17
  45. #define LEFT_OFFSET     27
  46. #define YC_OFFSET       34
  47. #define XC_OFFSET       42
  48.  
  49. UBYTE wdt[80]       = "Work Window";
  50. UBYTE wlb[MAXLABEL] = "new_window";
  51.  
  52. struct TextAttr std =
  53.  { (STRPTR)"topaz.font",8,FS_NORMAL,FPF_ROMFONT };
  54.  
  55. /*
  56.  * I'm not using the OS 2.0 headers but I still want the
  57.  * OS 2.0 look when running under OS 2.0. So I put a little quick
  58.  * and dirty hack here to make it possible.
  59.  */
  60. #define PensTag (1 << 31L) + 32 + 0x1A /* SA_Pens Tag      */
  61. #define Extended 0x1000                /* NS_EXTENDED Flag */
  62.  
  63. struct Tags {   /* A very short taglist with one item */
  64.     ULONG   Tag, *Param, End; };
  65.  
  66. UWORD   DriPens[10] = { /* The standard WBench dri-pens */
  67.     0,1,1,2,1,3,1,0,1,~0 };
  68. struct Tags st = {  /* Set up a simple tag list */
  69.     PensTag,(ULONG *)&DriPens[0],0L };
  70.  
  71. struct NewScreen ns_main =
  72.  { 0,0,640,STDSCREENHEIGHT,2,0,1,HIRES,CUSTOMSCREEN,&std,TITLE,NULL,NULL };
  73. /*
  74.  * When this is putten directly after the NewScreen structure and the
  75.  * Extented flag set (under 2.0) the system see's this as a ExtNewScreen
  76.  * structure.
  77.  */
  78. struct Tags *tg = &st;
  79.  
  80. struct NewWindow nw_main =
  81.  { 50,25,175,50,0,1,IDCMP_NM,FLAGS_NM,NULL,NULL,
  82.    (UBYTE *)&wdt,NULL,NULL,150,50,0,256,CUSTOMSCREEN };
  83.  
  84. char name[512];
  85.  
  86. struct FileSelector  *IODir = NULL;
  87. struct Window        *MainWindow = NULL;
  88. struct Screen        *MainScreen = NULL;
  89. struct RastPort      *MainRP;
  90. struct Process       *Proc;
  91. struct Gadget        *Gadget;
  92. struct MemoryChain    Memory;
  93. struct MemoryChain    Misc;
  94. struct GadgetList     Gadgets;
  95. struct SharedList     Images;
  96. struct Requester      dw;
  97. struct ge_prefs       prefs  = { TRUE,TRUE,TRUE };
  98. struct Gadget         TextGadget = { NULL,0,0,1,1,GADGHNONE,NULL,BOOLGADGET,
  99.                                      NULL,NULL,NULL,NULL,NULL,NULL,NULL };
  100.  
  101. struct IntuitionBase *IntuitionBase = NULL;
  102. struct GfxBase       *GfxBase       = NULL;
  103. struct ToolBase      *ToolBase      = NULL;
  104.  
  105. extern struct Library   *SysBase;
  106.  
  107. void set_info();
  108. void do_info();
  109.  
  110. APTR    sysreq      = (APTR)-1L;
  111. BYTE    Xoff        = -1, Yoff = 0;
  112. BOOL    Saved       = TRUE;
  113. BOOL    REQUESTER   = FALSE;
  114. BOOL    WORKBENCH   = FALSE;
  115. BOOL    WBSCREEN    = FALSE;
  116. ULONG   WindowFlags = WINDOWSIZING+WINDOWDRAG+WINDOWCLOSE+WINDOWDEPTH+NOCAREREFRESH+SMART_REFRESH+ACTIVATE;
  117. ULONG   IDCMPFlags  = GADGETUP+GADGETDOWN+CLOSEWINDOW;
  118. ULONG   Class;
  119. USHORT  BackFill    = 1, WDBackFill = 0;
  120. USHORT  Code, Qualifier, WBColors[4], LightSide = 2, DarkSide = 1;
  121. USHORT *pd, *data_pointer;
  122. USHORT  FrontPen = 1, BackPen = 0, GadgetCount = 0, id = 0, DEPTH;
  123. SHORT   MainX, MainY;
  124. char   *extension = ".PS";
  125.  
  126. extern struct MenuItem   SubItems[];
  127. extern struct Menu       Titles[];
  128. extern struct WBStartup *WBenchMsg;
  129. extern struct BorderList SBorders;
  130.  
  131. void set_coords();
  132. void do_coords();
  133.  
  134. /*
  135.  * free and close all resources
  136.  */
  137. VOID close_up(msg)
  138.  UBYTE *msg;
  139. {
  140.      Proc->pr_WindowPtr = sysreq;
  141.  
  142.      if(ToolBase) {
  143.          FreeGList();
  144.          free_all();
  145.          FreeMenuStrip();
  146.          if(IODir)         FreeFreq(IODir);
  147.                            OpenWorkBench();
  148.          if(MainWindow) {
  149.              ClearMenuStrip(MainWindow);
  150.              CloseWindow(MainWindow);
  151.          }
  152.          if(MainScreen)    CloseScreen(MainScreen);
  153.          FreeMemoryChain(&Misc);
  154.          FreeMemoryChain(&Memory);
  155.          CloseLibrary(ToolBase);
  156.      }
  157.      if(msg)           puts(msg);
  158.      exit(0);
  159. }
  160.  
  161. /*
  162.  * allocate open and setup all resources
  163.  */
  164. VOID open_libs()
  165. {
  166.      int i;
  167.  
  168.      if(NOT(ToolBase = (struct ToolBase *)
  169.       OpenLibrary("tool.library",8)))
  170.         close_up("   - ERROR: Can't find the tool.library V8++!");
  171.  
  172.      InitMemoryChain(&Misc,1024L);
  173.      InitMemoryChain(&Memory,(5*1024));
  174.  
  175.      GfxBase       = ToolBase->GfxBase;
  176.      IntuitionBase = ToolBase->IntuitionBase;
  177.  
  178.      for(i=0;i<4;i++)
  179.          WBColors[i] = (USHORT)GetRGB4(IntuitionBase->ActiveScreen->ViewPort.ColorMap,i);
  180.  
  181.      if(NOT(IODir = AllocFreq()))
  182.          close_up("   - ERROR: Out of memory !");
  183.  
  184.      if(NOT(pd = (USHORT *)
  185.      AllocItem(&Misc,(POINTERSIZE << 1),MEMF_CHIP+MEMF_CLEAR)))
  186.          close_up("   - ERROR: Out of memory !");
  187.      if(NOT(data_pointer = (USHORT *)
  188.      AllocItem(&Misc,DATA_SIZE_TOTAL,MEMF_CHIP+MEMF_CLEAR)))
  189.          close_up("   ERROR: Out of memory !");
  190.  
  191.      CopyMem((void *)&pointer,(void *)pd,(POINTERSIZE << 1));
  192.      CopyMem((void *)&info_data,(void *)data_pointer,DATA_SIZE_TOTAL);
  193.  
  194.      HEIGHT_image.ImageData = (USHORT *)&data_pointer[HEIGHT_OFFSET];
  195.      WIDTH_image.ImageData  = (USHORT *)&data_pointer[WIDTH_OFFSET];
  196.      TOP_image.ImageData    = (USHORT *)&data_pointer[TOP_OFFSET];
  197.      LEFT_image.ImageData   = (USHORT *)&data_pointer[LEFT_OFFSET];
  198.      YC_image.ImageData     = (USHORT *)&data_pointer[YC_OFFSET];
  199.      XC_image.ImageData     = (USHORT *)&data_pointer[XC_OFFSET];
  200. }
  201.  
  202. /*
  203.  * open up the main display
  204.  */
  205. VOID open_display()
  206. {
  207.      if(NOT MainScreen) {
  208.         if(SysBase->lib_Version >= 36)
  209.             ns_main.Type |= Extended;
  210.         if(NOT(MainScreen = OpenScreen(&ns_main)))
  211.              close_up("   - ERROR: Can't open a work screen !");
  212.      }
  213.      nw_main.Screen    = MainScreen;
  214.      nw_main.MaxHeight = MainScreen->Height;
  215.  
  216.      if(NOT(MainWindow = OpenWindow(&nw_main)))
  217.          close_up("   - ERROR: Can't open a work window !");
  218.  
  219.      if(TestBits((ULONG)prefs.flag_bits,GP_COORDS)) {
  220.         Forbid();
  221.         MainWindow->Flags |= REPORTMOUSE;
  222.         Permit();
  223.         set_coords();
  224.         do_coords();
  225.      }
  226.      MainRP = MainWindow->RPort;
  227. }
  228.  
  229. /*
  230.  * disable the edit window by putting up a little requester
  231.  */
  232. VOID disable_window()
  233. {
  234.     InitRequester(&dw);
  235.     dw.LeftEdge = 0;
  236.     dw.TopEdge  = 0;
  237.     dw.Width    = 1;
  238.     dw.Height   = 1;
  239.     dw.BackFill = 1;
  240.     Request(&dw,MainWindow);
  241. }
  242.  
  243. /*
  244.  * enable the edit window (remove the requester)
  245.  */
  246. VOID enable_window()
  247. {
  248.     EndRequest(&dw,MainWindow);
  249. }
  250.  
  251. /*
  252.  * show buisy pointer
  253.  */
  254. VOID buisy()
  255. {
  256.     SetPointer(MainWindow,(void *)pd,16,16,Xoff,Yoff);
  257. }
  258.  
  259. /*
  260.  * erase buisy pointer
  261.  */
  262. VOID ok()
  263. {
  264.     ClearPointer(MainWindow);
  265. }
  266.  
  267. /*
  268.  * change the depth of the edit screen
  269.  */
  270. VOID change_depth(depth)
  271.     ULONG depth;
  272. {
  273.     if(MainWindow) {
  274.         ClearMenuStrip(MainWindow);
  275.         CloseWindow(MainWindow);
  276.         MainWindow = NULL;
  277.     }
  278.     if(MainScreen) {
  279.         if(depth != MainScreen->BitMap.Depth OR WBSCREEN) {
  280.             CloseScreen(MainScreen);
  281.             MainScreen = NULL;
  282.         }
  283.     }
  284.     ns_main.Depth = depth;
  285.  
  286.     if(depth == 5) {
  287.         ns_main.ViewModes = NULL;
  288.         ns_main.Width     = 320;
  289.         if(NOT nw_main.MaxWidth) nw_main.MaxWidth  = 320;
  290.     } else {
  291.         ns_main.ViewModes = HIRES;
  292.         ns_main.Width     = 640;
  293.         if(NOT nw_main.MaxWidth) nw_main.MaxWidth  = 640;
  294.     }
  295.     open_display();
  296.     if(REQUESTER) {
  297.         SetDrMd(MainRP,JAM1);
  298.         SetAPen(MainRP,BackFill);
  299.         RectFill(MainRP,0,0,MainWindow->GZZWidth,MainWindow->GZZHeight);
  300.     }
  301.     SetMenu(MainWindow);
  302. }
  303.  
  304. /*
  305.  * load the preferences file (if available)
  306.  */
  307. VOID load_prefs()
  308. {
  309.     BPTR file;
  310.  
  311.     if((file = Open("DEVS:PowerSource.PREFS",MODE_OLDFILE))) {
  312.         if(Read(file,(char *)&prefs,sizeof(struct ge_prefs)) <= 0) {
  313.             Close(file);
  314.             Error("Error reading preferences !");
  315.             return;
  316.         }
  317.         Close(file);
  318.     }
  319. }
  320.  
  321. /*
  322.  * if a gadget has GRELWITH or GRELHEIGHT set and it's
  323.  * a BOOL or STRGADGET gadget with a border this routine
  324.  * sizes the border to fit around the gadget again after
  325.  * a resizing of the window.
  326.  */
  327. VOID grl()
  328. {
  329.     register struct Gadget   *g;
  330.     register struct MyGadget *mg;
  331.     register struct Border   *b;
  332.     register USHORT c1,c2;
  333.  
  334.     if(Gadgets.TailPred == (struct MyGadget *)&Gadgets) {
  335.         refresh();
  336.         return;
  337.     }
  338.  
  339.     while(read_msg(MainWindow));
  340.  
  341.     ModifyIDCMP(MainWindow,SIZEVERIFY);
  342.  
  343.     buisy();
  344.     disable_window();
  345.  
  346.     for(mg = Gadgets.Head; mg->Succ; mg = mg->Succ) {
  347.         g = &mg->Gadget;
  348.         un_grel(MainWindow,g);
  349.         if((TestBits((ULONG)g->Flags,GRELWIDTH)) OR (TestBits((ULONG)g->Flags,GRELHEIGHT))) {
  350.             if((NOT TestBits((ULONG)g->Flags,GADGIMAGE)) AND (NOT TestBits((ULONG)g->GadgetType,PROPGADGET))) {
  351.  
  352.                 b = (struct Border *)g->GadgetRender;
  353.  
  354.                 c1 = b->FrontPen;
  355.                 if(b->NextBorder)
  356.                     c2 = b->NextBorder->FrontPen;
  357.  
  358.                 if(g->Width < 9)
  359.                     g->Width = 9;
  360.                 if(g->Height < 9)
  361.                     g->Height = 9;
  362.  
  363.                 FreeRender(mg);
  364.                 add_border(mg);
  365.  
  366.                 b = (struct Border *)g->GadgetRender;
  367.                 b->FrontPen = c1;
  368.                 if(b->NextBorder)
  369.                     b->NextBorder->FrontPen = c2;
  370.  
  371.                 if(TestBits((ULONG)mg->SpecialFlags,OS20HIGHBORDER)) {
  372.                     b = (struct Border *)g->SelectRender;
  373.  
  374.                     b->FrontPen = c2;
  375.                     if(b->NextBorder)
  376.                         b->NextBorder->FrontPen = c1;
  377.                 }
  378.             }
  379.         }
  380.     }
  381.     grel(MainWindow,g);
  382.     enable_window();
  383.     ok();
  384.     while(read_msg(MainWindow));
  385.     ModifyIDCMP(MainWindow,nw_main.IDCMPFlags);
  386.     refresh();
  387. }
  388.  
  389. VOID sst(title)
  390.     char *title;
  391. {
  392.     struct RastPort *rp;
  393.  
  394.     SetWindowTitles(MainWindow,(char *)-1L,title);
  395.     rp = &MainScreen->RastPort;
  396.     SetAPen(rp,1);
  397.     RectFill(rp,0,0,MainScreen->Width,9); /* clear the title bar */
  398.     if(title) {
  399.         SetAPen(rp,0);
  400.         SetBPen(rp,1);
  401.         SetDrMd(rp,JAM2);
  402.         Move(rp,4,7);
  403.         Text(rp,title,strlen(title));
  404.     }
  405. }
  406.  
  407. void set_coords( void )
  408. {
  409.     struct RastPort *rp = &MainScreen->RastPort;
  410.  
  411.     YC_image.NextImage = NULL;
  412.  
  413.     DrawImage(rp,&XC_image,MainScreen->Width - 160,0);
  414. }
  415.  
  416. void do_coords( void )
  417. {
  418.     struct RastPort *rp = &MainScreen->RastPort;
  419.     SHORT   xx,yy;
  420.  
  421.     get_xy(&xx,&yy);
  422.  
  423.     SetAPen(rp,0);
  424.     SetBPen(rp,1);
  425.     SetDrMd(rp,JAM2);
  426.  
  427.     Move(rp,MainScreen->Width - 145,7);
  428.     FormatText(rp,"%-4ld",xx);
  429.     Move(rp,MainScreen->Width - 96,7);
  430.     FormatText(rp,"%-4ld",yy);
  431. }
  432.  
  433. /*
  434.  * setup the info display
  435.  */
  436. VOID set_info(how)
  437.     ULONG   how;
  438. {
  439.     struct RastPort *rp;
  440.  
  441.     if(NOT how) {
  442.         YC_image.NextImage  = &LEFT_image;
  443.         TOP_image.NextImage = &WIDTH_image;
  444.     } else if(how == 1) {
  445.         YC_image.NextImage  = &LEFT_image;
  446.         TOP_image.NextImage = NULL;
  447.     }
  448.  
  449.     rp = &MainScreen->RastPort;
  450.     sst(NULL);
  451.     DrawImage(rp,&XC_image,0,0);
  452. }
  453.  
  454. /*
  455.  * update the info line
  456.  */
  457. VOID do_info(text,x,y,x1,y1)
  458.     ULONG           text;
  459.     register SHORT x,y,x1,y1;
  460. {
  461.     char  mx[5],my[5],l[5],t[5],w[5],h[5];
  462.     SHORT xx,yy,tmp;
  463.     struct RastPort *rp;
  464.  
  465.     rp = &MainScreen->RastPort;
  466.  
  467.     get_xy(&xx,&yy);
  468.  
  469.     if(x1 < x) { tmp = x; x = x1; x1 = tmp; }
  470.     if(y1 < y) { tmp = y; y = y1; y1 = tmp; }
  471.  
  472.     SetAPen(rp,0);
  473.     SetBPen(rp,1);
  474.     SetDrMd(rp,JAM2);
  475.  
  476.     Move(rp,15,7);
  477.     FormatText(rp,"%-4ld",xx);
  478.     Move(rp,64,7);
  479.     FormatText(rp,"%-4ld",yy);
  480.  
  481.     Move(rp,114,7);
  482.     FormatText(rp,"%-4ld",x);
  483.     Move(rp,159,7);
  484.     FormatText(rp,"%-4ld",y);
  485.  
  486.     if(text == 1) return;
  487.  
  488.     Move(rp,211,7);
  489.     FormatText(rp,"%-3ld",x1-x);
  490.     Move(rp,256,7);
  491.     FormatText(rp,"%-3ld",y1-y);
  492. }
  493.  
  494. /*
  495.  * Check for the ".ps" extension.
  496.  */
  497. void CheckName( void )
  498. {
  499.     char    buf[4];
  500.     UWORD   i,len;
  501.  
  502.     len = strlen((char *)IODir->fr_FileName) - 3;
  503.  
  504.     for(i = 0; i < 3; i++, len++)
  505.         buf[i] = toupper(IODir->fr_FileName[len]);
  506.  
  507.     if(strncmp((char *)&buf[0],extension,3))
  508.         goto make;
  509.  
  510.     return;
  511. make:
  512.     strcat((char *)&name[0],extension);
  513.     strcat((char *)IODir->fr_FileName,extension);
  514. }
  515.  
  516.  
  517. long IsItADir( void )
  518. {
  519.     struct FileInfoBlock    *fib;
  520.     BPTR                     lock;
  521.     long                     ret = -1L;
  522.  
  523.     if((fib = (struct FileInfoBlock *)AllocMem((ULONG)sizeof(struct FileInfoBlock),MEMF_PUBLIC))) {
  524.         if((lock = Lock((char *)&name[0],ACCESS_READ))) {
  525.             Examine(lock,(BPTR)fib);
  526.             ret = fib->fib_DirEntryType;
  527.             UnLock(lock);
  528.         }
  529.         FreeMem(fib,(ULONG)sizeof(struct FileInfoBlock));
  530.     }
  531.     return(ret);
  532. }
  533.  
  534. long ParseName( void )
  535. {
  536.     char  buffer[512];
  537.     char *str;
  538.  
  539.     strcpy((char *)&buffer[0],(char *)&name[0]);
  540.     if(IsItADir() < 0) {
  541.         str = (char *)&buffer[strlen((char *)&buffer[0])];
  542.         while(*str != ':' AND *str != '/') {
  543.             if(str == (char *)&buffer[0]) goto pwb;
  544.             str--;
  545.         }
  546.         str++;
  547. pwb:
  548.         strcpy((char *)IODir->fr_FileName,str);
  549.         *str = 0;
  550.         strcpy((char *)IODir->fr_DirName,(char *)&buffer[0]);
  551.         CheckName();
  552.         return TRUE;
  553.     } else
  554.         strcpy((char *)IODir->fr_DirName,(char *)&buffer[0]);
  555.         return FALSE;
  556. }
  557.  
  558.  
  559. /*
  560.  * entry point
  561.  */
  562. VOID main(argc,argv)
  563.     ULONG argc;
  564.     char *argv[];
  565. {
  566.     SHORT x,y,x1,y1;
  567.     BOOL running = TRUE;
  568.     struct WBArg *wba;
  569.  
  570.     Proc = (struct Process *)FindTask(NULL);
  571.     sysreq = Proc->pr_WindowPtr;
  572.     Proc->pr_WindowPtr = (APTR)-1L;
  573.  
  574.     NewList((void *)&Gadgets);
  575.     NewList((void *)&Images);
  576.     NewList((void *)&SBorders);
  577.     open_libs();
  578.  
  579.     if(NOT argc) {
  580.         if(WBenchMsg->sm_NumArgs > 1) {
  581.             wba = WBenchMsg->sm_ArgList;
  582.             wba++;
  583.             strcpy((char *)&name[0],(char *)wba->wa_Name);
  584.             CurrentDir((struct FileLock *)wba->wa_Lock);
  585.             if(ParseName())
  586.                 ReadBinGadgets(TRUE);
  587.             else goto nono;
  588.         } else {
  589. nono:
  590.             load_prefs();
  591.             get_config(FALSE);
  592.             change_depth(DEPTH);
  593.             if(NOT WBSCREEN) LoadRGB4(&MainScreen->ViewPort,(void *)&Colors,(1 << DEPTH));
  594.         }
  595.     }
  596.     else if(argc == 1) {
  597. noway:
  598.         load_prefs();
  599.         get_config(FALSE);
  600.         change_depth(DEPTH);
  601.         if(NOT WBSCREEN) LoadRGB4(&MainScreen->ViewPort,(void *)&Colors,(1 << DEPTH));
  602.     } else if(argc > 2)
  603.         close_up("   - USAGE: PowerSource [name]");
  604.     else {
  605.         strcpy((char *)&name[0],argv[1]);
  606.         if(ParseName())
  607.             ReadBinGadgets(TRUE);
  608.         else
  609.             goto noway;
  610.     }
  611.  
  612.     do {
  613.         if(NOT TestBits((ULONG)prefs.flag_bits,GP_COORDS)) {
  614.             if(strlen((char *)&wdt[0]))
  615.                 SetWindowTitles(MainWindow,(char *)&wdt[0],(char *)TITLE);
  616.             else
  617.                 SetWindowTitles(MainWindow,(char *)-1L,(char *)TITLE);
  618.         } else {
  619.             set_coords();
  620.             do_coords();
  621.         }
  622.  
  623.         Wait(1 << MainWindow->UserPort->mp_SigBit);
  624.         while(read_msg(MainWindow)) {
  625.             if(Class != MOUSEMOVE AND TestBits((ULONG)prefs.flag_bits,GP_COORDS)) {
  626.                 set_coords();
  627.                 do_coords();
  628.             }
  629.             switch(Class) {
  630.                 case MOUSEMOVE:      do_coords();
  631.                                      break;
  632.  
  633.                 case GADGETUP:
  634.                 case GADGETDOWN:     break;
  635.  
  636.                 case ACTIVEWINDOW:   while(read_msg(MainWindow));
  637.                                      break;
  638.  
  639.                 case INACTIVEWINDOW: if(NOT IntuitionBase->ActiveWindow)
  640.                                          ActivateWindow(MainWindow);
  641.                                      break;
  642.  
  643.                 case NEWSIZE:        grl();
  644.                                      Saved = FALSE;
  645.                                      break;
  646.  
  647.                 case RAWKEY:         handle_keys(Code,Qualifier);
  648.                                      while(read_msg(MainWindow));
  649.                                      break;
  650.  
  651.                 case MENUPICK:       handle_menus(Code);
  652.                                      break;
  653.  
  654.                 case MOUSEBUTTONS:   if(Code == SELECTDOWN) {
  655.                                          switch_coords(FALSE);
  656.                                          set_info(0);
  657.                                          get_xy(&x,&y);
  658.                                          MainX = x;
  659.                                          MainY = y;
  660.                                          SetAPen(MainRP,FrontPen);
  661.                                          SetDrMd(MainRP,COMPLEMENT);
  662.                                          draw_box(MainWindow,MainX,MainY,x,y);
  663.                                          do_info(0,MainX,MainY,x,y);
  664.                                          while(Code == SELECTDOWN) {
  665.                                              while(read_msg(MainWindow));
  666.                                          }
  667.                                          while(Code != SELECTDOWN) {
  668.                                              while(read_msg(MainWindow)) {
  669.                                                  if(Class == MENUPICK) set_info(0);
  670.                                                  do_info(0,MainX,MainY,x,y);
  671.                                              }
  672.                                              get_xy(&x1,&y1);
  673.                                              if((x1 != x) OR (y1 != y)) {
  674.                                                  draw_box(MainWindow,MainX,MainY,x,y);
  675.                                                  get_xy(&x,&y);
  676.                                                  draw_box(MainWindow,MainX,MainY,x,y);
  677.                                                  do_info(0,MainX,MainY,x,y);
  678.                                              }
  679.                                          }
  680.                                          switch_coords(TRUE);
  681.                                          add_gadget(MainWindow,MainX,MainY,x,y);
  682.                                          refresh();
  683.                                      }
  684.                                      break;
  685.  
  686.                 default:             break;
  687.             }
  688.         }
  689.     } while(running == TRUE);
  690.     close_up("  - BYE BYE");
  691. }
  692.