home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d548 / labelmaker.lha / LabelMaker / LabelMakerV1.5.lzh / LabelMaker.c < prev    next >
C/C++ Source or Header  |  1991-07-22  |  57KB  |  1,985 lines

  1. #include <intuition/intuition.h>
  2. #include <exec/memory.h>
  3. #include <graphics/gfx.h>
  4. #include <graphics/clip.h>
  5. #include <graphics/layers.h>
  6. #include <graphics/text.h>
  7. #include <libraries/dos.h>
  8. #include <libraries/dosextens.h>
  9. #include <libraries/diskfont.h>
  10. #include "ArpBase.h"
  11. #include "LabelDef.h"
  12.  
  13.  
  14. struct IntuitionBase *IntuitionBase;
  15. struct GfxBase *GfxBase;
  16. struct LayersBase *LayersBase;
  17. struct DiskfontBase *DiskfontBase;
  18. struct ArpBase *ArpBase;
  19. struct Process *LabelProcess;
  20. struct AvailFontsHeader *MyAvlFntsHeader;
  21. struct Screen *CtrlScreen;
  22. struct Window *CtrlWindow, *EditWindow, *OldReqWindow;
  23. struct RastPort *crp, *erp, *wrp, *prp, *brp;
  24. struct ViewPort *cvp;
  25. struct Preferences OldPrefs, NewPrefs;
  26.  
  27. struct LabelText *FirstText, *CurrText, *SelectedText;
  28.  
  29. struct FileRequester *MyFileReq;
  30.  
  31. extern struct NewScreen LabelScreenData;
  32. extern struct NewWindow EditWinData, LabelWinData;
  33. extern struct NewWindow MessWinData, BoolWinData, SetUpWinData;
  34. extern struct Image CtrlMenuImage, EditMenuImage, TitleStripImage;
  35. extern struct Image LMessTextImage, DefaultMenuImage;
  36. extern struct Gadget TextGadg, ContinueGadg, GirlGadg, WholeTextGadg;
  37. extern struct Gadget NoGadg, YesGadg, LabelGapGadg;
  38. extern struct StringInfo TextInfo, LabelGapInfo, PrintWidthInfo;
  39. extern struct StringInfo PrintHeightInfo;
  40. extern UWORD MyColorMap[16], DefaultMap[16], GirlCMap[16];
  41. extern USHORT Pointer[3][41];
  42. extern BYTE InformationText[2][14][51], WholeText[257];
  43.  
  44.  
  45. int NumberOfFonts, IsArc, Last_Data, rm, LabelSkip;
  46. int PrintWidth, PrintHeight, FontBufferSize;
  47.  
  48. UWORD FullColorMap[32];
  49.  
  50. LONG PicLeftEdge, PicTopEdge, PicWidth, PicHeight, PicOn;
  51.  
  52. BYTE FileName[34], DirName[34];
  53.  
  54. #define NO_FAULT 0
  55. #define NO_INTUI 1
  56. #define NO_GRAFX 2
  57. #define NO_LAYER 3
  58. #define NO_DISKF 4
  59. #define NO_LSCRN 5
  60. #define NO_WRAST 6
  61. #define NO_PRAST 7
  62. #define NO_BRAST 8
  63. #define NO_LWIND 9
  64. #define NO_FONTS 10
  65. #define NO_FONTO 11
  66. #define NO_MEMOR 12
  67. #define NO_ARPLB 13
  68. #define NO_EWIND 14
  69.  
  70.  
  71. struct LabelText DefaultLabelText =
  72. {
  73.  0,0,
  74.  "topaz",9,
  75.  LTS_PLAIN,
  76.  LTA_LEFT,
  77.  LTP_FREE,
  78.  LTB_NONE,
  79.  1,0,
  80.  "...",
  81.  NULL,
  82.  NULL,
  83.  NULL
  84. };
  85.  
  86.  
  87.  
  88. int
  89. MouseState()
  90. {
  91.  struct IntuiMessage *MyMess;
  92.  LONG Art, back, Ort;
  93.  APTR *Wo;
  94.  struct Gadget *NoWarnGadg;
  95.  
  96.  back =0;
  97.  if ( MyMess = (struct IntuiMessage *) GetMsg( CtrlWindow->UserPort))
  98.    {
  99.     Art = MyMess->Class;
  100.     Wo = MyMess->IAddress;
  101.     ReplyMsg( MyMess);
  102.     if ( Art == GADGETUP)
  103.       {
  104.        NoWarnGadg = (struct Gadget *) Wo;
  105.        Ort = NoWarnGadg->GadgetID;
  106.        if ( Ort == 16)
  107.          {
  108.           back = 1;
  109.          }
  110.       }
  111.    }
  112.  return( back);
  113. }
  114.  
  115.  
  116.  
  117. int
  118. StrICmp( a, b)
  119. char *a, *b;
  120. {
  121.  while (( *a)&&( toupper( *a) == toupper( *b)))
  122.    {
  123.     a++;
  124.     b++;
  125.    }
  126.   return( toupper( *a) - toupper( *b));
  127. }
  128.  
  129.  
  130.  
  131. int
  132. CompareAvailFonts(FirstA, SecondA)
  133. struct AvailFonts *FirstA, *SecondA;
  134. {
  135.  int back;
  136.  struct TextAttr *First  = &FirstA->af_Attr;
  137.  struct TextAttr *Second = &SecondA->af_Attr;
  138.  
  139.  if (!(back = StrICmp( (char *)First->ta_Name, (char*)Second->ta_Name)))
  140.    {
  141.     back = ( First->ta_YSize < Second->ta_YSize)? -1:
  142.            ( First->ta_YSize == Second->ta_YSize)? 0 :1;
  143.    }
  144.  return( back);
  145. }
  146.  
  147.  
  148.  
  149. struct RastPort
  150. *OpenRastPort( Width, Height, Depth)
  151. int Width, Height, Depth;
  152. {
  153.  struct BitMap *MyBM;
  154.  struct RastPort *MyRP;
  155.  struct Layer_Info *MyLI;
  156.  struct Layer *MyLR;
  157.  PLANEPTR The_Planes[8];
  158.  int t, i, PlaneSize, fault, Planes_OK;
  159.  int MemSize;
  160.  
  161.  
  162.  MemSize = AvailMem( MEMF_PUBLIC);
  163.  MyBM = NULL;
  164.  MyRP = NULL;
  165.  MyLI = NULL;
  166.  MyLR = NULL;
  167.  PlaneSize = RASSIZE( Width, Height);
  168.  Planes_OK =1;
  169.  fault =1;
  170.  t =0;
  171.  while((t < Depth)&& Planes_OK)
  172.    {
  173.     Planes_OK = (The_Planes[t] = (PLANEPTR) AllocMem( PlaneSize,
  174.                                    MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR))? 1: 0;
  175.     t++;
  176.    }
  177.  t--;
  178.  if ( Planes_OK)
  179.    {
  180.     MyBM = (struct BitMap *)
  181.             AllocMem( sizeof( struct BitMap), MEMF_PUBLIC|MEMF_CLEAR);
  182.     if ( MyBM)
  183.       {
  184.        InitBitMap( MyBM, Depth, Width, Height);
  185.        for( i =0; i < Depth; i++)
  186.          {
  187.           MyBM->Planes[i] = The_Planes[i];
  188.          }
  189.        MyLI = (struct Layer_Info *)NewLayerInfo();
  190.        if (MyLI)
  191.          {
  192.           MyLR = (struct Layer *)
  193.                   CreateUpfrontLayer( MyLI, MyBM, 0, 0, Width -1, Height -1,
  194.                                       LAYERSIMPLE, NULL);
  195.           if (MyLR)
  196.             {
  197.              MyRP = MyLR->rp;
  198.              fault = 0;
  199.             }
  200.          }
  201.       }
  202.    }
  203.  if ( fault)
  204.    {
  205.     if (MyLI) DisposeLayerInfo( MyLI);
  206.     if (MyBM) FreeMem( MyBM, sizeof( struct BitMap));
  207.     i =0;
  208.     while((i < t) && The_Planes[i])
  209.       {
  210.        FreeMem( The_Planes[i], PlaneSize);
  211.        i++;
  212.       }
  213.    }
  214.  MemSize -= AvailMem( MEMF_PUBLIC);
  215.  return( MyRP);
  216. }
  217.  
  218.  
  219.  
  220. void
  221. CloseRastPort( The_RP)
  222. struct RastPort *The_RP;
  223. {
  224.  struct Layer_Info *MyLI;
  225.  struct Layer *MyLR;
  226.  struct BitMap *MyBM;
  227.  int t, Depth, PlaneSize;
  228.  int MemSize;
  229.  
  230.  
  231.  MemSize = AvailMem( MEMF_PUBLIC);
  232.  MyBM = The_RP->BitMap;
  233.  MyLR = The_RP->Layer;
  234.  MyLI = MyLR->LayerInfo;
  235.  Depth = MyBM->Depth;
  236.  PlaneSize = MyBM->BytesPerRow * MyBM->Rows;
  237.  DeleteLayer( MyLI, MyLR);
  238.  DisposeLayerInfo( MyLI);
  239.  for( t=0; t < Depth; t++)
  240.    {
  241.     FreeMem( MyBM->Planes[t], PlaneSize);
  242.    }
  243.  FreeMem( MyBM, sizeof( struct BitMap));
  244.  MemSize = AvailMem( MEMF_PUBLIC) - MemSize;
  245. }
  246.  
  247.  
  248.  
  249. void
  250. LMMessage( The_Message)
  251. BYTE *The_Message;
  252. {
  253.  struct Window *MessWindow;
  254.  struct RastPort *mrp;
  255.  struct ViewPort *mvp;
  256.  struct IntuiMessage *MyMess;
  257.  int MessLength, TitlePos;
  258.  LONG Art;
  259.  BYTE Nu_Message[79];
  260.  
  261.  strncpy( Nu_Message, The_Message, 78);
  262.  Nu_Message[78] =0;
  263.  MessLength = strlen( Nu_Message)*8 + 16;
  264.  if (MessLength < 171 ) MessLength = 171;
  265.  TitlePos = ( MessLength - 155)/2;
  266.  MessWinData.Width  = MessLength;
  267.  MessWinData.Height = 50;
  268.  MessWinData.LeftEdge = (640- MessLength)/2;
  269.  MessWinData.TopEdge = 70;
  270.  MessWinData.Screen = CtrlScreen;
  271.  if (MessWindow = (struct Window *) OpenWindow(&MessWinData))
  272.    {
  273.     mrp = MessWindow->RPort;
  274.     mvp = &CtrlScreen->ViewPort;
  275.     LoadRGB4( mvp, DefaultMap, 16);
  276.     SetDrMd( mrp, JAM2);
  277.     SetAPen( mrp, 1);
  278.     RectFill( mrp, 0, 0, MessLength -1, 49);
  279.     SetAPen( mrp, 0);
  280.     RectFill( mrp, 2, 1, MessLength -3, 48);
  281.     SetAPen( mrp, 1);
  282.     RectFill( mrp, 4, 2, MessLength -5, 47);
  283.     SetAPen( mrp, 0);
  284.     RectFill( mrp, 2, 15, MessLength -3, 15);
  285.     SetAPen( mrp, 1);
  286.     DrawImage( mrp, &LMessTextImage, TitlePos, 2);
  287.     SetAPen( mrp, 0);
  288.     SetBPen( mrp, 1);
  289.     Move( mrp, 8, 24);
  290.     Text( mrp, Nu_Message, strlen( Nu_Message));
  291.     SetAPen( mrp, 1);
  292.     RefreshGadgets( &ContinueGadg, MessWindow, NULL);
  293.     Art = NULL;
  294.     while ( Art != GADGETUP)
  295.       {
  296.        if (MyMess = (struct IntuiMessage *) GetMsg( MessWindow->UserPort))
  297.          {
  298.           Art = MyMess->Class;
  299.           ReplyMsg( MyMess);
  300.          }
  301.       }
  302.     LoadRGB4( mvp, MyColorMap, 16);
  303.     CloseWindow( MessWindow);
  304.    }
  305. }
  306.  
  307.  
  308.  
  309. int
  310. LMDecision( The_Message)
  311. BYTE *The_Message;
  312. {
  313.  struct Window *BoolWindow;
  314.  struct RastPort *brp;
  315.  struct ViewPort *bvp;
  316.  struct IntuiMessage *MyMess;
  317.  int MessLength, TitlePos;
  318.  LONG Art, Ort;
  319.  BYTE Nu_Message[79];
  320.  
  321.  strncpy( Nu_Message, The_Message, 78);
  322.  Nu_Message[78] =0;
  323.  MessLength = strlen( Nu_Message)*8 + 16;
  324.  if (MessLength < 171 ) MessLength = 171;
  325.  TitlePos = ( MessLength - 155)/2;
  326.  BoolWinData.Width  = MessLength;
  327.  BoolWinData.Height = 50;
  328.  BoolWinData.LeftEdge = (640- MessLength)/2;
  329.  BoolWinData.TopEdge = 70;
  330.  BoolWinData.Screen = CtrlScreen;
  331.  if (BoolWindow = (struct Window *) OpenWindow(&BoolWinData))
  332.    {
  333.     brp = BoolWindow->RPort;
  334.     bvp = &CtrlScreen->ViewPort;
  335.     LoadRGB4( bvp, DefaultMap, 16);
  336.     SetDrMd( brp, JAM2);
  337.     SetAPen( brp, 1);
  338.     RectFill( brp, 0, 0, MessLength -1, 49);
  339.     SetAPen( brp, 0);
  340.     RectFill( brp, 2, 1, MessLength -3, 48);
  341.     SetAPen( brp, 1);
  342.     RectFill( brp, 4, 2, MessLength -5, 47);
  343.     SetAPen( brp, 0);
  344.     RectFill( brp, 2, 15, MessLength -3, 15);
  345.     SetAPen( brp, 1);
  346.     DrawImage( brp, &LMessTextImage, TitlePos, 2);
  347.     SetAPen( brp, 0);
  348.     SetBPen( brp, 1);
  349.     Move( brp, 8, 24);
  350.     Text( brp, Nu_Message, strlen( Nu_Message));
  351.     SetAPen( brp, 1);
  352.     RefreshGadgets( &YesGadg, BoolWindow, NULL);
  353.     RefreshGadgets( &NoGadg, BoolWindow, NULL);
  354.     Art = NULL;
  355.     Ort = 0;
  356.     while (( Ort != 1)&&(Ort != 2))
  357.       {
  358.        if (MyMess = (struct IntuiMessage *) GetMsg( BoolWindow->UserPort))
  359.          {
  360.           Art = MyMess->Class;
  361.           if ( Art == GADGETUP)
  362.             {
  363.              Ort = MyMess->IAddress->GadgetID;
  364.             }
  365.           ReplyMsg( MyMess);
  366.          }
  367.       }
  368.     LoadRGB4( bvp, MyColorMap, 16);
  369.     CloseWindow( BoolWindow);
  370.    }
  371.  return( (Ort == 1) ? 1: 0);
  372. }
  373.  
  374.  
  375.  
  376. int
  377. LMFilePatch( The_Message)
  378. BYTE *The_Message;
  379. {
  380.  struct Window *BoolWindow;
  381.  struct RastPort *brp;
  382.  struct ViewPort *bvp;
  383.  struct IntuiMessage *MyMess;
  384.  int MessLength, TitlePos;
  385.  LONG Art, Ort;
  386.  BYTE Nu_Message[79];
  387.  
  388.  strncpy( Nu_Message, The_Message, 78);
  389.  Nu_Message[78] =0;
  390.  MessLength = strlen( Nu_Message)*8 + 16;
  391.  if (MessLength < 304 ) MessLength = 304;
  392.  if (MessLength > 630 ) MessLength = 630;
  393.  TitlePos = ( MessLength - 155)/2;
  394.  BoolWinData.Width  = MessLength;
  395.  BoolWinData.Height = 60;
  396.  BoolWinData.LeftEdge = (640- MessLength)/2;
  397.  BoolWinData.TopEdge = 75;
  398.  BoolWinData.Screen = CtrlScreen;
  399.  YesGadg.NextGadget = &WholeTextGadg;
  400.  if (BoolWindow = (struct Window *) OpenWindow(&BoolWinData))
  401.    {
  402.     brp = BoolWindow->RPort;
  403.     bvp = &CtrlScreen->ViewPort;
  404.     LoadRGB4( bvp, DefaultMap, 16);
  405.     SetDrMd( brp, JAM2);
  406.     SetAPen( brp, 1);
  407.     RectFill( brp, 0, 0, MessLength -1, 59);
  408.     SetAPen( brp, 0);
  409.     RectFill( brp, 2, 1, MessLength -3, 58);
  410.     SetAPen( brp, 1);
  411.     RectFill( brp, 4, 2, MessLength -5, 57);
  412.     SetAPen( brp, 0);
  413.     RectFill( brp, 2, 15, MessLength -3, 15);
  414.     SetAPen( brp, 1);
  415.     DrawImage( brp, &LMessTextImage, TitlePos, 2);
  416.     SetAPen( brp, 0);
  417.     SetBPen( brp, 1);
  418.     Move( brp, 8, 24);
  419.     Text( brp, Nu_Message, strlen( Nu_Message));
  420.     SetAPen( brp, 1);
  421.     RefreshGadgets( &YesGadg, BoolWindow, NULL);
  422.     RefreshGadgets( &NoGadg, BoolWindow, NULL);
  423.     ActivateGadget( &WholeTextGadg, BoolWindow, NULL);
  424.     Art = NULL;
  425.     Ort = 0;
  426.     while (( Ort != 1)&&(Ort != 2))
  427.       {
  428.        if (MyMess = (struct IntuiMessage *) GetMsg( BoolWindow->UserPort))
  429.          {
  430.           Art = MyMess->Class;
  431.           if ( Art == GADGETUP)
  432.             {
  433.              Ort = MyMess->IAddress->GadgetID;
  434.             }
  435.           ReplyMsg( MyMess);
  436.          }
  437.       }
  438.     LoadRGB4( bvp, MyColorMap, 16);
  439.     CloseWindow( BoolWindow);
  440.    }
  441.  YesGadg.NextGadget = NULL;
  442.  return( (Ort == 1) ? 1: 0);
  443. }
  444.  
  445.  
  446.  
  447. void
  448. LMInformation()
  449. {
  450.  struct Window *MessWindow;
  451.  struct RastPort *mrp;
  452.  struct ViewPort *mvp;
  453.  struct IntuiMessage *MyMess;
  454.  LONG Art, Ort;
  455.  int MessLength, t, TitlePos, ScreenShown;
  456.  
  457.  MessLength = strlen( &InformationText[0][0])*8 + 16 +115;
  458.  if (MessLength < 171 ) MessLength = 171;
  459.  if (MessLength > 626 ) MessLength = 626;
  460.  TitlePos = (MessLength - 155)/2;
  461.  MessWinData.Width  = MessLength;
  462.  MessWinData.Height = 148;
  463.  MessWinData.LeftEdge = (640- MessLength)/2;
  464.  MessWinData.TopEdge = 25;
  465.  MessWinData.Screen = CtrlScreen;
  466.  ContinueGadg.NextGadget = &GirlGadg;
  467.  if (MessWindow = (struct Window *) OpenWindow(&MessWinData))
  468.    {
  469.     mrp = MessWindow->RPort;
  470.     mvp = &CtrlScreen->ViewPort;
  471.     LoadRGB4( mvp, GirlCMap, 16);
  472.     SetDrMd( mrp, JAM2);
  473.     SetAPen( mrp, 1);
  474.     RectFill( mrp, 0, 0, MessLength -1, 147);
  475.     SetAPen( mrp, 0);
  476.     RectFill( mrp, 2, 1, MessLength -3, 146);
  477.     SetAPen( mrp, 1);
  478.     RectFill( mrp, 4, 2, MessLength -5, 145);
  479.     SetAPen( mrp, 0);
  480.     RectFill( mrp, 2, 15, MessLength -3, 15);
  481.     SetAPen( mrp, 1);
  482.     DrawImage( mrp, &LMessTextImage, TitlePos, 2);
  483.     SetAPen( mrp, 0);
  484.     SetBPen( mrp, 1);
  485.     for ( t=0; t < 14; t++)
  486.       {
  487.        Move( mrp, 8, 24 + t*9);
  488.        Text( mrp, &InformationText[0][t][0],
  489.                   strlen( &InformationText[0][t][0]));
  490.       }
  491.     RefreshGList( &ContinueGadg, MessWindow, NULL, 1);
  492.     ScreenShown = 0;
  493.     Art = NULL;
  494.     Ort = 0;
  495.     while ( Ort != 2)
  496.       {
  497.        if (MyMess = (struct IntuiMessage *) GetMsg( MessWindow->UserPort))
  498.          {
  499.           Art = MyMess->Class;
  500.           if (Art == GADGETUP)
  501.             {
  502.              Ort = MyMess->IAddress->GadgetID;
  503.             }
  504.           ReplyMsg( MyMess);
  505.           if ((Ort == 1)&&(Art == GADGETUP))
  506.             {
  507.              ScreenShown ^= 1;
  508.              for ( t=0; t < 14; t++)
  509.                {
  510.                 Move( mrp, 8, 24 + t*9);
  511.                 Text( mrp, &InformationText[ScreenShown][t][0],
  512.                            strlen( &InformationText[ScreenShown][t][0]));
  513.                }
  514.              RefreshGadgets( &GirlGadg, MessWindow, NULL);
  515.             }
  516.          }
  517.       }
  518.     LoadRGB4( mvp, MyColorMap, 16);
  519.     CloseWindow( MessWindow);
  520.     ContinueGadg.NextGadget = NULL;
  521.    }
  522. }
  523.  
  524.  
  525.  
  526. void
  527. PointerState( Which)
  528. int Which;
  529. {
  530.  if (( Which > -1)&&( Which < 3))
  531.    {
  532.     CopyMem( &Pointer[Which][0], &NewPrefs.PointerMatrix[0], 72);
  533.     CopyMem( MyColorMap, FullColorMap, 32);
  534.     NewPrefs.XOffset = Pointer[Which][36];
  535.     NewPrefs.YOffset = Pointer[Which][37];
  536.     FullColorMap[17] = Pointer[Which][38];
  537.     FullColorMap[18] = Pointer[Which][39];
  538.     FullColorMap[19] = Pointer[Which][40];
  539.     SetPrefs( &NewPrefs, sizeof( struct Preferences), FALSE);
  540.     LoadRGB4( cvp, FullColorMap, 32);
  541.    }
  542. }
  543.  
  544.  
  545.  
  546. int
  547. OpenEnvironment()
  548. {
  549.  int fault, PointerBack;
  550.  
  551.  FontBufferSize =0;
  552.  PointerBack =0;
  553.  OldReqWindow = NULL;
  554.  fault = (IntuitionBase = (struct IntuitionBase *)
  555.           OpenLibrary("intuition.library",0L))? NO_FAULT: NO_INTUI;
  556.  if (!fault)
  557.    {
  558.     fault = (GfxBase =(struct GfxBase *)OpenLibrary("graphics.library",0L))?
  559.             NO_FAULT: NO_GRAFX;
  560.    }
  561.  if (!fault)
  562.    {
  563.     fault = (LayersBase =(struct LayersBase *)OpenLibrary("layers.library",0L))?
  564.              NO_FAULT: NO_LAYER;
  565.    }
  566.  if (!fault)
  567.    {
  568.     fault = (DiskfontBase = OpenLibrary("diskfont.library",0L))?
  569.              NO_FAULT: NO_DISKF;
  570.    }
  571.  if (!fault)
  572.    {
  573.     fault = (CtrlScreen = (struct Screen *) OpenScreen( &LabelScreenData))?
  574.             NO_FAULT: NO_LSCRN;
  575.    }
  576.  if (!fault)
  577.    {
  578.     ShowTitle( CtrlScreen, FALSE);
  579.     fault = (wrp = (struct RastPort *) OpenRastPort( 320, 184, 4))?
  580.             NO_FAULT: NO_WRAST;
  581.    }
  582.  if (!fault)
  583.    {
  584.     fault = (prp = (struct RastPort *) OpenRastPort( 320, 184, 4))?
  585.             NO_FAULT: NO_PRAST;
  586.    }
  587.  if (!fault)
  588.    {
  589.     fault = (brp = (struct RastPort *) OpenRastPort( 320, 184, 4))?
  590.             NO_FAULT: NO_BRAST;
  591.    }
  592.  if (!fault)
  593.    {
  594.     LabelWinData.Screen = CtrlScreen;
  595.     fault = (CtrlWindow = (struct Window *) OpenWindow( &LabelWinData))?
  596.             NO_FAULT:NO_LWIND;
  597.    }
  598.  if (!fault)
  599.    {
  600.     if (ArpBase = (struct Library *) OpenLibrary("arp.library",0L))
  601.       {
  602.        if (!(MyFileReq = ArpAllocFreq()))
  603.          {
  604.           CloseLibrary( ArpBase);
  605.           ArpBase = NULL;
  606.          }
  607.       }
  608.     GetPrefs( &OldPrefs, sizeof( struct Preferences));
  609.     GetPrefs( &NewPrefs, sizeof( struct Preferences));
  610.     cvp = &CtrlScreen->ViewPort;
  611.     crp = CtrlWindow->RPort;
  612.     LoadRGB4( cvp, &MyColorMap[0], 16L);
  613.     DrawImage( crp, &TitleStripImage, 0, 0);
  614.     DrawImage( crp, &CtrlMenuImage, 512, 14);
  615.     CopyMem( MyColorMap, FullColorMap, 32);
  616.     PointerState( 2);
  617.     PointerBack =2;
  618.    }
  619.  if (!fault)
  620.    {
  621.     fault = (FontBufferSize = AvailFonts( NULL, 0, AFF_DISK | AFF_MEMORY))?
  622.             NO_FAULT: NO_FONTO;
  623.    }
  624.  if (!fault)
  625.    {
  626.     fault = (MyAvlFntsHeader = (struct AvailFontsHeader *)
  627.                AllocMem( FontBufferSize, MEMF_CLEAR | MEMF_PUBLIC))?
  628.             NO_FAULT: NO_MEMOR;
  629.    }
  630.  if (!fault)
  631.    {
  632.     fault = (!(AvailFonts( MyAvlFntsHeader, FontBufferSize, AFF_DISK | AFF_MEMORY)))?
  633.             NO_FAULT: NO_FONTS;
  634.    }
  635.  if (!fault)
  636.    {
  637.     NumberOfFonts = MyAvlFntsHeader->afh_NumEntries;
  638.     qsort( &MyAvlFntsHeader[1], NumberOfFonts, sizeof( struct AvailFonts),
  639.            CompareAvailFonts);
  640.     if (LabelProcess = (struct Process *) FindTask(NULL))
  641.       {
  642.        OldReqWindow = (struct Window *) LabelProcess->pr_WindowPtr;
  643.        LabelProcess->pr_WindowPtr = CtrlWindow;
  644.       }
  645.     if ( ArpBase == NULL) LMMessage("You really should use the ARP.LIBRARY");
  646.    }
  647.  if (PointerBack) PointerState( 0);
  648.  return( fault);
  649. }
  650.  
  651.  
  652.  
  653. void
  654. CloseEnvironment( How_Far)
  655. int How_Far;
  656. {
  657.  switch( How_Far)
  658.    {
  659.     case NO_FAULT: if (OldReqWindow && LabelProcess)
  660.                      {
  661.                       LabelProcess->pr_WindowPtr = OldReqWindow;
  662.                      }
  663.     case NO_FONTS: if ( ArpBase) CloseLibrary( ArpBase);
  664.                    FreeMem( MyAvlFntsHeader, FontBufferSize);
  665.     case NO_MEMOR: SetPrefs( &OldPrefs, sizeof( struct Preferences), FALSE);
  666.     case NO_FONTO: CloseWindow( CtrlWindow);
  667.     case NO_LWIND: CloseRastPort( brp);
  668.     case NO_BRAST: CloseRastPort( prp);
  669.     case NO_PRAST: CloseRastPort( wrp);
  670.     case NO_WRAST: CloseScreen( CtrlScreen);
  671.     case NO_LSCRN: CloseLibrary( DiskfontBase);
  672.     case NO_DISKF: CloseLibrary( LayersBase);
  673.     case NO_LAYER: CloseLibrary( GfxBase);
  674.     case NO_GRAFX: CloseLibrary( IntuitionBase);
  675.                    break;
  676.     case NO_INTUI: puts("Someone has stolen your ROMs !!!");
  677.                    break;
  678.     default:       puts("Illegal shutdown code received.");
  679.                    break;
  680.    }
  681. }
  682.  
  683.  
  684.  
  685. int
  686. FindAttrNo( The_Font, The_Size)
  687. BYTE *The_Font;
  688. int  The_Size;
  689. {
  690.  int count, found;
  691.  BYTE buffer[50];
  692.  struct AvailFonts *FirstAvail;
  693.  struct TextAttr *MyAttr;
  694.  BYTE errBuff[80];
  695.  
  696.  count = 0;
  697.  found = 0;
  698.  FirstAvail = &MyAvlFntsHeader[1];
  699.  while ((count < NumberOfFonts)&&(found ==0))
  700.    {
  701.     strcpy( buffer, The_Font);
  702.     strcat( buffer, ".font");
  703.     MyAttr = &(FirstAvail + count)->af_Attr;
  704.     found = (strcmp( buffer, MyAttr->ta_Name) == 0)? 1: 0;
  705.     if ( The_Size != MyAttr->ta_YSize)
  706.       {
  707.        found = 0;
  708.       }
  709.     count++;
  710.    }
  711.  if (found == 0)
  712.    {
  713.     strcpy( errBuff, The_Font);
  714.     sprintf(buffer,"%d", The_Size);
  715.     strcat( errBuff, buffer);
  716.     strcat( errBuff, " not available!");
  717.     LMMessage( errBuff);
  718.    }
  719.  return( count -1);
  720. }
  721.  
  722.  
  723.  
  724. int
  725. FindBottom( Start, The_Text)
  726. struct LabelText *Start, *The_Text;
  727. {
  728.  struct LabelText *Curr, *MaxText;
  729.  int MaxPos, CurrPos;
  730.  
  731.  Curr = FindStart( FirstText);
  732.  if ( Curr != NULL)
  733.    {
  734.     MaxPos = 0;
  735.     MaxText = NULL;
  736.     while ( Curr != NULL)
  737.       {
  738.        CurrPos = (Curr->TopEdge) +(Curr->Width);
  739.        if (( CurrPos > MaxPos)&&(The_Text != Curr))
  740.          {
  741.           MaxPos = CurrPos;
  742.           MaxText = Curr;
  743.          }
  744.        Curr = Curr->NextText;
  745.       }
  746.    }
  747.  return( MaxPos);
  748. }
  749.  
  750.  
  751.  
  752. int
  753. ReadASC( fh, Data, how)
  754. struct FileHandle *fh;
  755. BYTE *Data;
  756. int how;
  757. {
  758.  int Back;
  759.  
  760.  if (how == 0)
  761.    {
  762.     Back = 1;
  763.     *Data = Last_Data;
  764.     rm = 1;
  765.    }
  766.  else
  767.    {
  768.     Back = Read( fh, Data, 1L);
  769.     Last_Data = *Data;
  770.    }
  771.  return( Back);
  772. }
  773.  
  774.  
  775.  
  776. void
  777. ReadASCText( fh, Text, confirm)
  778. struct FileHandle *fh;
  779. BYTE *Text;
  780. int *confirm;
  781. {
  782.  BYTE data;
  783.  int count;
  784.  
  785.  data = 0;
  786.  while((data != 34)&&((*confirm) == 1))
  787.    {
  788.     *confirm = ReadASC( fh, &data, rm);
  789.    }
  790.  count =0;
  791.  data = 0;
  792.  while((data != 34)&&((*confirm) == 1)&&(count < 60))
  793.    {
  794.     *confirm = ReadASC( fh, &data, rm);
  795.     if (data != 34)
  796.       {
  797.        Text[count] = data;
  798.        count++;
  799.       }
  800.    }
  801.  Text[count] =0;
  802. }
  803.  
  804.  
  805.  
  806. int
  807. ReadASCNumber( fh, confirm)
  808. struct FileHandle *fh;
  809. int *confirm;
  810. {
  811.  int So_far, ok;
  812.  BYTE data;
  813.  
  814.  So_far =0;
  815.  ok = 1;
  816.  while(((*confirm) ==1)&&(ok != 0))
  817.    {
  818.     *confirm = ReadASC( fh, &data, rm);
  819.     if ((data > 47)&&(data < 58))
  820.       {
  821.        So_far *= 10;
  822.        So_far += data - 48;
  823.        ok = 1;
  824.       }
  825.     else
  826.       {
  827.        ok =0;
  828.       }
  829.    }
  830.  rm = 0;
  831.  return( So_far);
  832. }
  833.  
  834.  
  835.  
  836. struct LabelText
  837. *ReadTextFile( TextFileName)
  838. BYTE *TextFileName;
  839. {
  840.  struct FileHandle *InFile;
  841.  struct LabelText *Curr;
  842.  int StillMore;
  843.  int The_Place, The_Style, The_Align, The_Top, The_Size, The_BgCol;
  844.  int The_FgCol, The_Border;
  845.  int The_AttrNo, Text_Finished, MissTries;
  846.  BYTE The_Font[21], The_Text[61];
  847.  BYTE Data, MyBuffer[80];
  848.  
  849.  Curr = NULL;
  850.  MissTries =0;
  851.  if (InFile = (struct FileHandle *) Open( TextFileName, MODE_OLDFILE))
  852.    {
  853.     PointerState( 2);
  854.     DeleteAllTexts( FindStart( FirstText));
  855.     FirstText = NULL;
  856.     StillMore = 1;
  857.     rm = 1;
  858.     while (( StillMore == 1)&&(MissTries < 25))
  859.       {
  860.        The_Top = 0;
  861.        strcpy(The_Font,"topaz");
  862.        The_Text[0] =0;
  863.        The_Size    = 9;
  864.        The_Style   = LTS_PLAIN;
  865.        The_Place   = LTP_FREE;
  866.        The_Align   = LTA_LEFT;
  867.        The_Border  = LTB_NONE;
  868.        The_BgCol   = 1;
  869.        The_FgCol   = 0;
  870.        The_AttrNo  = 0;
  871.        Text_Finished = 0;
  872.        while (( StillMore ==1)&&(Text_Finished == 0)&&(MissTries < 25))
  873.          {
  874.           StillMore = ReadASC( InFile, &Data, rm);
  875.           if (( Data > 96)&&( Data < 123))
  876.             {
  877.              Data = Data - 32;
  878.             }
  879.           switch (Data)
  880.             {
  881.              case 'U': The_Style |= LTS_UNDERLINED;
  882.                        break;
  883.              case 'B': The_Style |= LTS_BOLD;
  884.                        break;
  885.              case 'I': The_Style |= LTS_ITALIC;
  886.                        break;
  887.              case 'L': The_Align = LTA_LEFT;
  888.                        break;
  889.              case 'R': The_Align = LTA_RIGHT;
  890.                        break;
  891.              case 'M': The_Align = LTA_CENTERED;
  892.                        break;
  893.              case 'O': The_Border = LTB_TOP;
  894.                        break;
  895.              case 'G': The_Border = LTB_BOTTOM;
  896.                        break;
  897.              case 'S': The_Border = LTB_SIDES;
  898.                        break;
  899.              case 'V': The_Top = FindBottom( FindStart( FirstText), NULL);
  900.                        if (The_Top > LABEL_BOTTOM) The_Top = 0;
  901.                        The_Place =0;
  902.                        break;
  903.              case 'D': The_Top = ReadASCNumber( InFile, &StillMore);
  904.                        The_Place =1;
  905.                        break;
  906.              case 'P': The_BgCol = ReadASCNumber( InFile, &StillMore);
  907.                        break;
  908.              case 'C': The_FgCol = ReadASCNumber( InFile, &StillMore);
  909.                        break;
  910.              case 'F': ReadASCText( InFile, MyBuffer, &StillMore);
  911.                        strncpy( The_Font, MyBuffer, 21);
  912.                        The_Size = ReadASCNumber( InFile, &StillMore);
  913.                        break;
  914.              case 'T': ReadASCText( InFile, MyBuffer, &StillMore);
  915.                        strncpy( The_Text, MyBuffer, 61);
  916.                        break;
  917.              case  32:
  918.              case  10:
  919.              case  13:
  920.              case  44:
  921.              case 127: break;
  922.              case  59: Text_Finished = 1;
  923.                        break;
  924.              default:  MissTries++;
  925.                        break;
  926.             }
  927.           if( Text_Finished == 1)
  928.             {
  929.              The_AttrNo = FindAttrNo( The_Font, The_Size);
  930.              Curr = CreateText( The_Font, The_Size, The_Style, The_Align,
  931.                                 The_Place, The_Border, The_BgCol,
  932.                                 The_FgCol,  The_Text, The_AttrNo);
  933.              if ( Curr != NULL)
  934.                {
  935.                 ChangeCoords( Curr, The_Top);
  936.                }
  937.              if ( FirstText == NULL) FirstText = Curr;
  938.              AddText( FindEnd( FirstText), Curr);
  939.             }
  940.          }
  941.       }
  942.     Close( InFile);
  943.     PointerState( 0);
  944.    }
  945.  if ( MissTries > 24)
  946.    {
  947.     LMMessage("I've read too many illegal characters");
  948.    }
  949.  return( Curr);
  950. }
  951.  
  952.  
  953.  
  954. ClearLabelArea()
  955. {
  956.  SetAPen( crp, 0);
  957.  RectFill( crp, LABEL_LEFT,  LABEL_BACK +1,
  958.                 LABEL_RIGHT, LABEL_BACK +1);
  959.  RectFill( crp, LABEL_LEFT,  LABEL_STRIP_END +1,
  960.                 LABEL_RIGHT, LABEL_STRIP_END +1);
  961.  SetAPen( crp, 1);
  962.  RectFill( crp, LABEL_LEFT,  LABEL_TOP,
  963.                 LABEL_RIGHT, LABEL_BACK);
  964.  RectFill( crp, LABEL_LEFT,  LABEL_STRIP_START,
  965.                 LABEL_RIGHT, LABEL_STRIP_END);
  966.  RectFill( crp, LABEL_LEFT,  LABEL_START,
  967.                 LABEL_RIGHT, LABEL_BOTTOM);
  968. }
  969.  
  970.  
  971.  
  972. void
  973. ComplRect( rstprt, LeftEdge, TopEdge, Width, Height)
  974. struct RastPort *rstprt;
  975. int LeftEdge, TopEdge, Width, Height;
  976. {
  977.  int RightEdge, BottomEdge;
  978.  
  979.  SetAPen( rstprt, 7);
  980.  SetDrMd( rstprt, JAM2|COMPLEMENT);
  981.  RightEdge  = ( Width < 1)? LeftEdge: LeftEdge + Width -1;
  982.  BottomEdge = (Height < 1)? TopEdge : TopEdge + Height -1;
  983.  RectFill( rstprt, LeftEdge, TopEdge, RightEdge, BottomEdge);
  984.  SetDrMd( rstprt, JAM2);
  985.  SetAPen( rstprt, 1);
  986. }
  987.  
  988.  
  989.  
  990. MakeADOSStr( Dir, Name, Full)
  991. BYTE *Dir, *Name , *Full;
  992. {
  993.  int l;
  994.  
  995.  strcpy( Full, Dir);
  996.  l = strlen( Full);
  997.  if ((strlen( Dir) != 0)&&(Full[l -1] != 58))
  998.    {
  999.     Full[l]    = 47;
  1000.     Full[l +1] = 0;
  1001.    }
  1002.  strcat( Full, Name);
  1003. }
  1004.  
  1005.  
  1006.  
  1007. void
  1008. AttrToName( ThatAttr, ThatName)
  1009. struct TextAttr *ThatAttr;
  1010. UBYTE *ThatName;
  1011. {
  1012.  int length;
  1013.  
  1014.  strcpy( ThatName, ThatAttr->ta_Name);
  1015.  length = strlen( ThatName) -5;
  1016.  if (length > 13) length = 13;
  1017.  if (length < 1) length = 1;
  1018.  ThatName[length] = 47;
  1019.  sprintf( &ThatName[length +1], "%d", ThatAttr->ta_YSize);
  1020. }
  1021.  
  1022.  
  1023.  
  1024. void
  1025. PaintLabelText( The_Text)
  1026. struct LabelText *The_Text;
  1027. {
  1028.  struct AvailFonts *First_Avail;
  1029.  struct TextAttr *The_Attr;
  1030.  struct TextFont *The_Font;
  1031.  LONG The_Style, The_BgCol, The_Base, The_Length, The_Size, t, Offset;
  1032.  LONG The_Enable, The_Border, The_FgCol, The_Width, The_DrawX;
  1033.  
  1034.  if ( The_Text != NULL)
  1035.    {
  1036.     SetAPen( wrp, 1);
  1037.     SetBPen( wrp, 1);
  1038.     SetDrMd( wrp, JAM2);
  1039.     RectFill( wrp, 0, 0, LABEL_WIDTH -1, LABEL_HEIGHT -1);
  1040.     First_Avail = &MyAvlFntsHeader[1];
  1041.     The_Attr = &(First_Avail + The_Text->AttrNumber)->af_Attr;
  1042.     if ((The_Font = (struct TextFont*) OpenDiskFont( The_Attr))!= NULL)
  1043.       {
  1044.        if (SetFont( wrp, The_Font))
  1045.          {
  1046.           The_Base   = The_Font->tf_Baseline;
  1047.           The_BgCol  = (LONG)(The_Text->BgColor);
  1048.           The_FgCol  = (LONG)(The_Text->FgColor);
  1049.           The_Border = (LONG)(The_Text->Border);
  1050.           The_Width  = (LONG)(The_Text->Width);
  1051.           The_Enable = AskSoftStyle( wrp);
  1052.           SetSoftStyle( wrp, (LONG)(The_Text->Style), The_Enable);
  1053.           The_Length = TextLength( wrp, The_Text->Text,
  1054.                                         strlen( The_Text->Text));
  1055.           The_DrawX = ( The_Border & LTB_SIDES)? 4: 0;
  1056.           The_Base += ( The_Border & LTB_TOP)? 2: 1;
  1057.           switch( The_Text->Alignment)
  1058.             {
  1059.              case LTA_LEFT:     Offset = The_DrawX;
  1060.                                 break;
  1061.              case LTA_RIGHT:    Offset = LABEL_WIDTH - The_Length - The_DrawX;
  1062.                                 break;
  1063.              case LTA_CENTERED: Offset = (LABEL_WIDTH - The_Length )/2;
  1064.                                  break;
  1065.             }
  1066.           SetAPen( wrp, The_BgCol);
  1067.           RectFill( wrp, 0, 0, LABEL_WIDTH -1, The_Width -1);
  1068.           SetAPen( wrp, 0);
  1069.           if ( The_Border & LTB_TOP)    RectFill( wrp, 0, 0,
  1070.                                             LABEL_WIDTH -1, 0);
  1071.           if ( The_Border & LTB_BOTTOM) RectFill( wrp, 0, The_Width -1,
  1072.                                             LABEL_WIDTH -1, The_Width -1);
  1073.           if ( The_Border & LTB_SIDES)
  1074.             {
  1075.              RectFill( wrp, 0, 0, 1, The_Width -1);
  1076.              RectFill( wrp, LABEL_WIDTH -2, 0, LABEL_WIDTH -1, The_Width -1);
  1077.             }
  1078.           SetAPen( wrp, The_FgCol);
  1079.           SetBPen( wrp, The_BgCol);
  1080.           Move( wrp, Offset, The_Base);
  1081.           Text( wrp, The_Text->Text, strlen( The_Text->Text));
  1082.           if (The_Text->TopEdge <(LABEL_STRIP_END - LABEL_TOP))
  1083.             {
  1084.              for ( t=0; t < LABEL_WIDTH; t++)
  1085.                {
  1086.                 ClipBlit( wrp, t, 0,
  1087.                           brp, LABEL_WIDTH -1-t, 0,
  1088.                                1, The_Width, 0xc0);
  1089.                }
  1090.              for ( t=0; t < The_Width; t++)
  1091.                {
  1092.                 ClipBlit( brp, 0, t,
  1093.                           wrp, 0, The_Width -1 -t, LABEL_WIDTH, 1, 0xc0);
  1094.                }
  1095.             }
  1096.          }
  1097.        CloseFont( The_Font);
  1098.       }
  1099.    }
  1100. }
  1101.  
  1102.  
  1103.  
  1104. void
  1105. DrawLabelText( The_Text)
  1106. struct LabelText *The_Text;
  1107. {
  1108.  if ( The_Text != NULL)
  1109.    {
  1110.     PaintLabelText( The_Text);
  1111.     if ((The_Text->TopEdge + The_Text->Width) > LABEL_HEIGHT)
  1112.       {
  1113.        The_Text->TopEdge = LABEL_HEIGHT - The_Text->Width;
  1114.       }
  1115.     ClipBlit( wrp, 0,0,
  1116.               crp, LABEL_LEFT, (LONG)(The_Text->TopEdge)+LABEL_TOP,
  1117.               LABEL_WIDTH, (LONG)(The_Text->Width), 0xc0);
  1118.    }
  1119. }
  1120.  
  1121.  
  1122.  
  1123. void
  1124. DrawLabelPic()
  1125. {
  1126.  if (PicOn != 0)
  1127.    {
  1128.     ClipBlit( prp, 0,0, crp, LABEL_LEFT+PicLeftEdge, LABEL_TOP + PicTopEdge,
  1129.               PicWidth, PicHeight, 0xc0);
  1130.    }
  1131. }
  1132.  
  1133.  
  1134.  
  1135. ReDrawLabel( StartText)
  1136. struct LabelText *StartText;
  1137. {
  1138.  struct LabelText *One_Text;
  1139.  
  1140.  PointerState( 2);
  1141.  ClearLabelArea();
  1142.  if ( PicOn == 1)
  1143.    {
  1144.     DrawLabelPic();
  1145.    }
  1146.  One_Text = FindStart( StartText);
  1147.  while ( One_Text != NULL)
  1148.    {
  1149.     DrawLabelText( One_Text);
  1150.     One_Text = One_Text->NextText;
  1151.    }
  1152.  PointerState( 0);
  1153. }
  1154.  
  1155.  
  1156.  
  1157. PartialRedraw( StartText, ExcludeText)
  1158. struct LabelText *StartText, *ExcludeText;
  1159. {
  1160.  struct LabelText *One_Text;
  1161.  
  1162.  PointerState( 2);
  1163.  ClearLabelArea();
  1164.  if (( PicOn == 1)&&(ExcludeText))
  1165.    {
  1166.     DrawLabelPic();
  1167.    }
  1168.  One_Text = FindStart( StartText);
  1169.  while ( One_Text != NULL)
  1170.    {
  1171.     if ( One_Text != ExcludeText) DrawLabelText( One_Text);
  1172.     One_Text = One_Text->NextText;
  1173.    }
  1174.  PointerState( 0);
  1175. }
  1176.  
  1177.  
  1178.  
  1179. struct LabelText
  1180. *Do_Edit_Text( The_Text)
  1181. struct LabelText *The_Text;
  1182. {
  1183.  int Ort, Art;
  1184.  struct LabelText *ReturnText;
  1185.  struct IntuiMessage *MyMess;
  1186.  struct AvailFonts *FirstAvail;
  1187.  struct TextAttr *HelpAttr;
  1188.  int CurrAlign, CurrStyle, CurrPlace, CurrFontNo, Wo, CurrBgCol;
  1189.  int CurrFgCol, CurrBorder;
  1190.  char FontName[40], *FoundSlash;
  1191.  int t, FontHeight;
  1192.  
  1193.  
  1194.  ReturnText = NULL;
  1195.  EditWinData.Screen = CtrlScreen;
  1196.  if ( EditWindow = (struct Window *) OpenWindow( &EditWinData))
  1197.    {
  1198.     PointerState( 1);
  1199.     erp = EditWindow->RPort;
  1200.     FirstAvail = (struct AvailFonts *) &MyAvlFntsHeader[1];
  1201.     if ( The_Text != NULL)
  1202.       {
  1203.        CurrStyle  = The_Text->Style;
  1204.        CurrAlign  = The_Text->Alignment;
  1205.        CurrPlace  = The_Text->Placement;
  1206.        CurrBorder = The_Text->Border;
  1207.        CurrBgCol  = The_Text->BgColor;
  1208.        CurrFgCol  = The_Text->FgColor;
  1209.        CurrFontNo = The_Text->AttrNumber;
  1210.        strcpy( TextInfo.Buffer, &(The_Text->Text[0]));
  1211.        TextInfo.NumChars = strlen( TextInfo.Buffer);
  1212.        TextInfo.BufferPos = 0;
  1213.       }
  1214.     else
  1215.       {
  1216.        CurrStyle  = DefaultLabelText.Style;
  1217.        CurrAlign  = DefaultLabelText.Alignment;
  1218.        CurrPlace  = DefaultLabelText.Placement;
  1219.        CurrBorder = DefaultLabelText.Border;
  1220.        CurrBgCol  = DefaultLabelText.BgColor;
  1221.        CurrFgCol  = DefaultLabelText.FgColor;
  1222.        CurrFontNo = DefaultLabelText.AttrNumber;
  1223.        strcpy( TextInfo.Buffer, &(DefaultLabelText.Text[0]));
  1224.        TextInfo.NumChars = strlen( TextInfo.Buffer);
  1225.        TextInfo.BufferPos = 0;
  1226.       }
  1227.     DrawImage( erp, &EditMenuImage, 0,0);
  1228.  
  1229.     for (t=0; t < 16; t++)   /* Draw color tables */
  1230.       {
  1231.        SetAPen( erp, t);
  1232.        RectFill( erp, 48 + t*18, 29, 65+ t*18, 37);
  1233.        RectFill( erp, 48 + t*18, 41, 65+ t*18, 49);
  1234.       }
  1235.     for( t =0; t < 3; t++)   /* Select style fields */
  1236.       {
  1237.        if (CurrStyle & (1<<t))
  1238.          {
  1239.           ComplRect( erp, 268 + t*24, 4, 22, 11);
  1240.          }
  1241.       }
  1242.     for( t =0; t < 3; t++)   /* Select border fields */
  1243.       {
  1244.        if ((CurrBorder & (1<<t)) != 0)
  1245.          {
  1246.           ComplRect( erp, 268 + t*24, 16, 22, 11);
  1247.          }
  1248.       }
  1249.     ComplRect( erp, 46 + CurrPlace*24, 16, 22, 11);
  1250.     ComplRect( erp, 140 + CurrAlign*24, 16, 22, 11);
  1251.     ComplRect( erp, 52 + CurrBgCol* 18, 31, 10, 5);
  1252.     ComplRect( erp, 52 + CurrFgCol* 18, 43, 10, 5);
  1253.     AttrToName(&(FirstAvail +CurrFontNo)->af_Attr, FontName);
  1254.     Move( erp, 96, 12);
  1255.     Text( erp, FontName, strlen( FontName));
  1256.     ActivateGadget( &TextGadg, EditWindow, NULL);
  1257.     Ort = 1;
  1258.     while ((Ort > 0)&&(Ort < 17))
  1259.       {
  1260.        if ( MyMess = (struct IntuiMessage *) GetMsg( EditWindow->UserPort))
  1261.          {
  1262.           Ort = MyMess->IAddress->GadgetID;
  1263.           Art = MyMess->Class;
  1264.           Wo  = MyMess->MouseX;
  1265.           ReplyMsg( MyMess);
  1266.           if (( Ort > 2)&&( Ort < 6))
  1267.             {
  1268.              t = Ort - 3;
  1269.              ComplRect( erp, 268 + t*24, 4, 22, 11);
  1270.              CurrStyle ^= 1<<t;
  1271.             }
  1272.           else
  1273.             {
  1274.              if (( Ort > 5)&&( Ort < 8))
  1275.                {
  1276.                 ComplRect( erp, 46 + CurrPlace*24, 16, 22, 11);
  1277.                 CurrPlace = Ort -6;
  1278.                 ComplRect( erp, 46 + CurrPlace*24, 16, 22, 11);
  1279.                }
  1280.              else
  1281.                {
  1282.                 if (( Ort > 7)&&( Ort < 11))
  1283.                   {
  1284.                    ComplRect( erp, 140 + CurrAlign*24, 16, 22, 11);
  1285.                    CurrAlign = Ort -8;
  1286.                    ComplRect( erp, 140 + CurrAlign*24, 16, 22, 11);
  1287.                   }
  1288.                 else
  1289.                   {
  1290.                    if (( Ort > 10)&&( Ort < 14))
  1291.                      {
  1292.                       t = Ort - 11;
  1293.                       ComplRect( erp, 268 + t*24, 16, 22, 11);
  1294.                       CurrBorder ^= 1<<t;
  1295.                      }
  1296.                    else
  1297.                      {
  1298.                       switch (Ort)
  1299.                         {
  1300.                          case 1: if (CurrFontNo > 0)
  1301.                                    {
  1302.                                     SetAPen( erp, 0);
  1303.                                     RectFill( erp, 94, 4, 216, 14);
  1304.                                     SetAPen( erp, 1);
  1305.                                     CurrFontNo--;
  1306.                                     AttrToName(
  1307.                                       &(FirstAvail +CurrFontNo)->af_Attr,
  1308.                                       FontName);
  1309.                                     Move( erp, 96, 12);
  1310.                                     Text( erp, FontName, strlen( FontName));
  1311.                                    }
  1312.                                  break;
  1313.                          case 2: if ((CurrFontNo +1) < NumberOfFonts)
  1314.                                    {
  1315.                                     SetAPen( erp, 0);
  1316.                                     RectFill( erp, 94, 4, 216, 14);
  1317.                                     SetAPen( erp, 1);
  1318.                                     CurrFontNo++;
  1319.                                     AttrToName(
  1320.                                       &(FirstAvail +CurrFontNo)->af_Attr,
  1321.                                       FontName);
  1322.                                     Move( erp, 96, 12);
  1323.                                     Text( erp, FontName, strlen( FontName));
  1324.                                    }
  1325.                                  break;
  1326.                          case 14: t = (Wo - 48)/18;
  1327.                                   if ( t != CurrFgCol)
  1328.                                     {
  1329.                                      ComplRect( erp, 52 + CurrBgCol* 18, 31,
  1330.                                                      10, 5);
  1331.                                      CurrBgCol = t;
  1332.                                      if (CurrBgCol > 15) CurrBgCol = 15;
  1333.                                      if (CurrBgCol < 0)  CurrBgCol = 0;
  1334.                                      ComplRect( erp, 52 + CurrBgCol* 18, 31,
  1335.                                                      10, 5);
  1336.                                     }
  1337.                                   break;
  1338.                          case 15:
  1339.                                   t = (Wo - 48)/18;
  1340.                                   if ( t != CurrBgCol)
  1341.                                     {
  1342.                                      ComplRect( erp, 52 + CurrFgCol* 18, 43,
  1343.                                                      10, 5);
  1344.                                      CurrFgCol = t;
  1345.                                      if (CurrFgCol > 15) CurrFgCol = 15;
  1346.                                      if (CurrFgCol < 0)  CurrFgCol = 0;
  1347.                                      ComplRect( erp, 52 + CurrFgCol* 18, 43,
  1348.                                                      10, 5);
  1349.                                     }
  1350.                                   break;
  1351.                         }
  1352.                      }
  1353.                   }
  1354.                }
  1355.             }
  1356.          }
  1357.       }
  1358.     if ( Ort == 17)
  1359.       {
  1360.        IsArc =0;
  1361.        HelpAttr = &(FirstAvail +CurrFontNo)->af_Attr;
  1362.        FontHeight = HelpAttr->ta_YSize;
  1363.        strcpy( FontName, HelpAttr->ta_Name);
  1364.        t = strlen( FontName) -5;
  1365.        FontName[t] = 0;
  1366.        if ( The_Text == NULL)
  1367.          {
  1368.           ReturnText = CreateText( FontName, FontHeight, CurrStyle,
  1369.                                    CurrAlign, CurrPlace, CurrBorder,
  1370.                                    CurrBgCol, CurrFgCol, TextInfo.Buffer,
  1371.                                    CurrFontNo);
  1372.           if ( ReturnText != NULL)
  1373.             {
  1374.              if ( FirstText == NULL)
  1375.                {
  1376.                 FirstText = ReturnText;
  1377.                }
  1378.              else
  1379.                {
  1380.                 InsertText( FindEnd( FirstText), ReturnText, 2);
  1381.                }
  1382.              CurrText = ReturnText;
  1383.             }
  1384.          }
  1385.        else
  1386.          {
  1387.           ChangeText( The_Text, FontName, FontHeight, CurrStyle, CurrAlign,
  1388.                       CurrPlace, CurrBorder, CurrBgCol, CurrFgCol,
  1389.                       TextInfo.Buffer, CurrFontNo);
  1390.           CurrText = The_Text;
  1391.          }
  1392.       }
  1393.     PointerState( 0);
  1394.     CloseWindow( EditWindow);
  1395.    }
  1396.  return( ReturnText);
  1397. }
  1398.  
  1399.  
  1400.  
  1401. void
  1402. ToggleText( The_Text)
  1403. struct LabelText *The_Text;
  1404. {
  1405.  if ( The_Text)
  1406.    {
  1407.     ComplRect( crp, LABEL_LEFT, (long)(The_Text->TopEdge +LABEL_TOP),
  1408.                     LABEL_WIDTH, (long)(The_Text->Width) );
  1409.    }
  1410. }
  1411.  
  1412.  
  1413.  
  1414. struct LabelText
  1415. *GetSelectedText( y)
  1416. int y;
  1417. {
  1418.  struct LabelText *Curr;
  1419.  int t;
  1420.  
  1421.  Curr = FindEnd( FirstText);
  1422.  if (Curr != NULL)
  1423.    {
  1424.     while ( (Curr->PrevText != NULL)&&
  1425.            (! ((Curr->TopEdge <= y)&&
  1426.                ((Curr->TopEdge +Curr->Width) >= y))))
  1427.       {
  1428.        Curr = Curr->PrevText;
  1429.       }
  1430.     if ( (Curr->PrevText == NULL)&&
  1431.            (! ((Curr->TopEdge <= y)&&
  1432.                ((Curr->TopEdge +Curr->Width) >= y))))
  1433.       {
  1434.        Curr = NULL;
  1435.       }
  1436.    }
  1437.  return( Curr);
  1438. }
  1439.  
  1440.  
  1441.  
  1442. struct LabelText
  1443. *PlaceSelectedText( The_Text)
  1444. struct LabelText *The_Text;
  1445. {
  1446.  struct LabelText *Curr;
  1447.  int x, y, y0, yk, YSize, YLimit;
  1448.  int CurrPos, MaxPos, YMSize, ExitNow, PosFlag;
  1449.  
  1450.  if ( The_Text != NULL)
  1451.    {
  1452.     PointerState( 1);
  1453.     if ( The_Text->Placement == 0)
  1454.       {
  1455.        MaxPos = FindBottom( FirstText, The_Text);
  1456.        if (MaxPos <= (LABEL_HEIGHT -(LONG)(The_Text->Width)))
  1457.          {
  1458.           ChangeCoords( The_Text, MaxPos);
  1459.          }
  1460.        else
  1461.          {
  1462.           The_Text->Placement =1;
  1463.          }
  1464.       }
  1465.     if ( The_Text->Placement != 0)
  1466.       {
  1467.        The_Text->TopEdge  = LABEL_STRIP_END - LABEL_TOP;
  1468.        PosFlag = FALSE;
  1469.        PartialRedraw( FindStart( The_Text), The_Text);
  1470.        PointerState( 2);
  1471.        PaintLabelText( The_Text);
  1472.        PointerState( 1);
  1473.        YSize = The_Text->Width;
  1474.        YMSize = YSize / 2;
  1475.        y0 = CtrlScreen->MouseY - YMSize;
  1476.        YLimit = LABEL_BOTTOM - YSize +1;
  1477.        if ( YLimit < 0)
  1478.          {
  1479.           YLimit = LABEL_TOP;
  1480.           YSize = 8;
  1481.          }
  1482.        if ( y0 > YLimit) y0 = YLimit;
  1483.        if ( y0 < LABEL_TOP) y0 = LABEL_TOP;
  1484.        y = y0;
  1485.        ExitNow = 0;
  1486.        ClipBlit( crp, LABEL_LEFT, y, brp, 0, 0, LABEL_WIDTH, YSize, 0xca);
  1487.        ClipBlit( wrp, 0, 0, crp, LABEL_LEFT, y, LABEL_WIDTH, YSize, 0xca);
  1488.        while ( ! ExitNow)
  1489.          {
  1490.           ExitNow = (ExitNow)? 1: MouseState();
  1491.           y0 = y;
  1492.           while (( y == y0)&&( !ExitNow))
  1493.             {
  1494.              ExitNow = (ExitNow)? 1: MouseState();
  1495.              y = CtrlScreen->MouseY - YMSize;
  1496.              if ( y > YLimit) y = YLimit;
  1497.              if ( y < LABEL_TOP)  y = LABEL_TOP;
  1498.              yk = y - LABEL_TOP;
  1499.              if ((yk <(LABEL_STRIP_END - LABEL_TOP))&&(!PosFlag))
  1500.                {
  1501.                 PointerState( 2);
  1502.                 ClipBlit( brp, 0, 0, crp, LABEL_LEFT, y0,LABEL_WIDTH, YSize, 0xca);
  1503.                 The_Text->TopEdge  = yk;
  1504.                 PaintLabelText( The_Text);
  1505.                 PosFlag = TRUE;
  1506.                 ClipBlit( crp, LABEL_LEFT, y0, brp, 0, 0, LABEL_WIDTH, YSize, 0xca);
  1507.                 PointerState( 1);
  1508.                }
  1509.              else
  1510.                {
  1511.                 if ((yk >=(LABEL_STRIP_END - LABEL_TOP))&&(PosFlag))
  1512.                   {
  1513.                    PointerState( 2);
  1514.                    ClipBlit( brp, 0, 0, crp, LABEL_LEFT, y0,LABEL_WIDTH, YSize, 0xca);
  1515.                    The_Text->TopEdge  = yk;
  1516.                    PaintLabelText( The_Text);
  1517.                    PosFlag = FALSE;
  1518.                    ClipBlit( crp, LABEL_LEFT, y0, brp, 0, 0, LABEL_WIDTH, YSize, 0xca);
  1519.                    PointerState( 1);
  1520.                   }
  1521.                }
  1522.             }
  1523.           ClipBlit( brp, 0, 0, crp, LABEL_LEFT, y0,LABEL_WIDTH, YSize, 0xca);
  1524.           ClipBlit( crp, LABEL_LEFT, y, brp, 0, 0, LABEL_WIDTH, YSize, 0xca);
  1525.           ClipBlit( wrp, 0, 0, crp, LABEL_LEFT, y, LABEL_WIDTH, YSize, 0xca);
  1526.          }
  1527.        ChangeCoords( The_Text, y - LABEL_TOP);
  1528.       }
  1529.     Curr = FindStart( FirstText);
  1530.     if (Curr != NULL)
  1531.       {
  1532.        while ( (Curr->NextText != NULL)&&
  1533.               (! ((Curr->TopEdge < y)&&(Curr->NextText->TopEdge > y))))
  1534.          {
  1535.           Curr = Curr->NextText;
  1536.          }
  1537.        ReplaceText( CurrText, The_Text, 2);
  1538.        ReDrawLabel( FindStart( FirstText));
  1539.       }
  1540.    }
  1541.  while( MouseState() !=0);
  1542.  PointerState( 0);
  1543.  return( Curr);
  1544. }
  1545.  
  1546.  
  1547.  
  1548. void
  1549. PlacePic()
  1550. {
  1551.  int x, x0, y, y0, XLimit, YLimit, YMSize, XMSize, ExitNow;
  1552.  
  1553.  if (PicOn != 0)
  1554.    {
  1555.     PartialRedraw( FindStart( FirstText), NULL);
  1556.     PointerState( 1);
  1557.     XLimit = LABEL_RIGHT - PicWidth +1;
  1558.     YLimit = LABEL_BOTTOM - PicHeight +1;
  1559.     XMSize = PicWidth / 2;
  1560.     YMSize = PicHeight / 2;
  1561.     y0 = CtrlScreen->MouseY -YMSize;
  1562.     x0 = CtrlScreen->MouseX -XMSize;
  1563.     if ( y0 > YLimit)     y0 = YLimit;
  1564.     if ( y0 < LABEL_TOP)  y0 = LABEL_TOP;
  1565.     if ( x0 > XLimit)     x0 = XLimit;
  1566.     if ( x0 < LABEL_LEFT) x0 = LABEL_LEFT;
  1567.     y = y0;
  1568.     x = x0;
  1569.     ClipBlit( crp, x, y, brp, 0, 0, PicWidth, PicHeight, 0xca);
  1570.     ClipBlit( prp, 0, 0, crp, x, y, PicWidth, PicHeight, 0xca);
  1571.     ExitNow =0;
  1572.     while ( !ExitNow)
  1573.       {
  1574.        ExitNow = (ExitNow)? 1: MouseState();
  1575.        y0 = y;
  1576.        x0 = x;
  1577.        while (( y == y0)&&(x == x0)&&( !ExitNow))
  1578.          {
  1579.           ExitNow = (ExitNow)? 1: MouseState();
  1580.           y = CtrlScreen->MouseY -YMSize;
  1581.           x = CtrlScreen->MouseX -XMSize;
  1582.           if ( y > YLimit)     y = YLimit;
  1583.           if ( y < LABEL_TOP)  y = LABEL_TOP;
  1584.           if ( x > XLimit)     x = XLimit;
  1585.           if ( x < LABEL_LEFT) x = LABEL_LEFT;
  1586.          }
  1587.        ClipBlit( brp, 0, 0, crp, x0, y0, PicWidth, PicHeight, 0xca);
  1588.        ClipBlit( crp, x, y, brp, 0, 0, PicWidth, PicHeight, 0xca);
  1589.        ClipBlit( prp, 0, 0, crp, x, y, PicWidth, PicHeight, 0xca);
  1590.       }
  1591.     PicTopEdge  = y - LABEL_TOP;
  1592.     PicLeftEdge = x - LABEL_LEFT;
  1593.     PicOn = 1;
  1594.     PointerState( 0);
  1595.    }
  1596. }
  1597.  
  1598.  
  1599.  
  1600. GetMeFileName( The_Message )
  1601. BYTE *The_Message;
  1602. {
  1603.  int ok;
  1604.  BYTE *OldDir, *OldFile, *OldHail;
  1605.  
  1606.  ok =0;
  1607.  if ( ArpBase != NULL)
  1608.    {
  1609.     OldHail = MyFileReq->fr_Hail;
  1610.     OldFile = MyFileReq->fr_File;
  1611.     OldDir  = MyFileReq->fr_Dir;
  1612.     MyFileReq->fr_Hail = The_Message;
  1613.     MyFileReq->fr_File = FileName;
  1614.     MyFileReq->fr_Dir = DirName;
  1615.     MyFileReq->fr_Window = CtrlWindow;
  1616.     ok = FileRequest( MyFileReq);
  1617.     MyFileReq->fr_Hail = OldHail;
  1618.     MyFileReq->fr_File = OldFile;
  1619.     MyFileReq->fr_Dir  = OldDir;
  1620.     if (ok != 0)
  1621.       {
  1622.        MakeADOSStr( DirName, FileName, WholeText);
  1623.        ok =1;
  1624.       }
  1625.    }
  1626.  else
  1627.    {
  1628.     ok = LMFilePatch( The_Message);
  1629.    }
  1630.  return( ok);
  1631. }
  1632.  
  1633.  
  1634. int
  1635. SetDefaults()
  1636. {
  1637.  struct Window *SetUpWindow;
  1638.  struct RastPort *srp;
  1639.  struct ViewPort *svp;
  1640.  struct IntuiMessage *MyMess;
  1641.  struct Gadget *NoWarnGadg;
  1642.  struct LabelText *TempTextBuffer;
  1643.  LONG Art, Ort;
  1644.  
  1645.  SetUpWinData.Screen = CtrlScreen;
  1646.  sprintf(PrintWidthInfo.Buffer, "%d", PrintWidth);
  1647.  PrintWidthInfo.BufferPos = 0;
  1648.  PrintWidthInfo.DispPos =0;
  1649.  PrintWidthInfo.NumChars = strlen( PrintWidthInfo.Buffer);
  1650.  PrintWidthInfo.LongInt = PrintWidth;
  1651.  
  1652.  sprintf(PrintHeightInfo.Buffer, "%d", PrintHeight);
  1653.  PrintHeightInfo.BufferPos = 0;
  1654.  PrintHeightInfo.DispPos =0;
  1655.  PrintHeightInfo.NumChars = strlen( PrintHeightInfo.Buffer);
  1656.  PrintHeightInfo.LongInt = PrintHeight;
  1657.  
  1658.  sprintf(LabelGapInfo.Buffer, "%d", LabelSkip);
  1659.  LabelGapInfo.BufferPos = 0;
  1660.  LabelGapInfo.DispPos =0;
  1661.  LabelGapInfo.NumChars = strlen( LabelGapInfo.Buffer);
  1662.  LabelGapInfo.LongInt = LabelSkip;
  1663.  
  1664.  if (SetUpWindow = (struct Window *) OpenWindow(&SetUpWinData))
  1665.    {
  1666.     srp = SetUpWindow->RPort;
  1667.     svp = &CtrlScreen->ViewPort;
  1668.     LoadRGB4( svp, DefaultMap, 16);
  1669.     DrawImage( srp, &DefaultMenuImage, 0, 0);
  1670.     SetAPen( srp, 1);
  1671.     SetBPen( srp, 0);
  1672.     RefreshGadgets( &LabelGapGadg, SetUpWindow, NULL);
  1673.     ActivateGadget( &LabelGapGadg, SetUpWindow, NULL);
  1674.     Art = NULL;
  1675.     Ort = 0;
  1676.     while (( Ort != 5)&&(Ort != 6))
  1677.       {
  1678.        if (MyMess = (struct IntuiMessage *) GetMsg( SetUpWindow->UserPort))
  1679.          {
  1680.           Art = MyMess->Class;
  1681.           NoWarnGadg = (struct Gadget *)MyMess->IAddress;
  1682.           ReplyMsg( MyMess);
  1683.           if ( Art == GADGETUP)
  1684.             {
  1685.              Ort = NoWarnGadg->GadgetID;
  1686.              if ( Ort == 4)
  1687.                {
  1688.                 TempTextBuffer = CurrText;
  1689.                 Do_Edit_Text( &DefaultLabelText);
  1690.                 CurrText = TempTextBuffer;
  1691.                }
  1692.             }
  1693.          }
  1694.       }
  1695.     LoadRGB4( svp, MyColorMap, 16);
  1696.     CloseWindow( SetUpWindow);
  1697.     if ( Ort == 5)
  1698.       {
  1699.        LabelSkip   = LabelGapInfo.LongInt;
  1700.        PrintWidth  = PrintWidthInfo.LongInt;
  1701.        PrintHeight = PrintHeightInfo.LongInt;
  1702.       }
  1703.    }
  1704. }
  1705.  
  1706.  
  1707.  
  1708. main()
  1709. {
  1710.  struct IntuiMessage *MyMess;
  1711.  struct LabelText *HelpText;
  1712.  int Ort, Art, Do_Draw, help, ContOn, AllIsLost;
  1713.  int Environment, MsY;
  1714.  
  1715.  
  1716.  if (( Environment = OpenEnvironment()) == 0)
  1717.    {
  1718.     LabelSkip =0;
  1719.     PrintWidth = 2666;
  1720.     PrintHeight = 2555;
  1721.     PicOn = 0;
  1722.     PointerState( 0);
  1723.     ClearLabelArea();
  1724.     FirstText = NULL;
  1725.     CurrText = NULL;
  1726.     SelectedText = NULL;
  1727.     IsArc =1;
  1728.     Ort = 1;
  1729.     AllIsLost =0;
  1730.     while (( Ort > 0)&&( Ort < 17)&&(AllIsLost == 0))
  1731.       {
  1732.        if ( MyMess = (struct IntuiMessage *)
  1733.                      GetMsg( CtrlWindow->UserPort))
  1734.          {
  1735.           Ort = MyMess->IAddress->GadgetID;
  1736.           Art = MyMess->Class;
  1737.           MsY = MyMess->MouseY;
  1738.           ReplyMsg( MyMess);
  1739.           if (Art == GADGETUP)
  1740.             {
  1741.              switch( Ort)
  1742.                {
  1743.                 case 1: if (IsArc != 1)
  1744.                           {
  1745.                            ContOn =
  1746.                                LMDecision("Discard this label?");
  1747.                           }
  1748.                         else
  1749.                           {
  1750.                            ContOn =1;
  1751.                           }
  1752.                         if (ContOn == 1)
  1753.                           {
  1754.                            if (SelectedText)
  1755.                              {
  1756.                               ToggleText( SelectedText);
  1757.                               SelectedText = NULL;
  1758.                              }
  1759.                            help = GetMeFileName("Enter the label to load");
  1760.                            if ( help != 0)
  1761.                              {
  1762.                               CurrText = LoadLabel( WholeText);
  1763.                               LoadRGB4( cvp, MyColorMap, 8L);
  1764.                               if (CurrText != NULL)
  1765.                                 {
  1766.                                  ReDrawLabel( FindStart( CurrText));
  1767.                                 }
  1768.                              }
  1769.                           }
  1770.                         break;
  1771.                 case 2: help = GetMeFileName("Enter the label to save");
  1772.                         if ( help != 0)
  1773.                           {
  1774.                            if (SelectedText)
  1775.                              {
  1776.                               ToggleText( SelectedText);
  1777.                               SelectedText = NULL;
  1778.                              }
  1779.                            help = SaveLabel( WholeText);
  1780.                            if ( help != -1)
  1781.                              {
  1782.                               ReDrawLabel( FindStart( CurrText));
  1783.                               IsArc =1;
  1784.                              }
  1785.                           }
  1786.                         break;
  1787.                 case 3: if ( PicOn == 1)
  1788.                           {
  1789.                            ContOn = LMDecision("Discard current picture?");
  1790.                           }
  1791.                         else
  1792.                           {
  1793.                            ContOn =1;
  1794.                           }
  1795.                         if (ContOn == 1)
  1796.                           {
  1797.                            if (SelectedText)
  1798.                              {
  1799.                               ToggleText( SelectedText);
  1800.                               SelectedText = NULL;
  1801.                              }
  1802.                            help = GetMeFileName("Enter the picture to load");
  1803.                            if ( help != 0)
  1804.                              {
  1805.                               if (LoadPicture( prp, WholeText)==0)
  1806.                                 {
  1807.                                  LoadRGB4( cvp, MyColorMap, 8L);
  1808.                                  PlacePic();
  1809.                                  IsArc =0;
  1810.                                 }
  1811.                               ReDrawLabel( FindStart( CurrText));
  1812.                              }
  1813.                           }
  1814.                         break;
  1815.                 case 4: if ( FirstText != NULL)
  1816.                           {
  1817.                            ContOn = LMDecision("Discard currents Texts?");
  1818.                           }
  1819.                         else
  1820.                           {
  1821.                            ContOn =1;
  1822.                           }
  1823.                         if (ContOn == 1)
  1824.                           {
  1825.                            if (SelectedText)
  1826.                              {
  1827.                               ToggleText( SelectedText);
  1828.                               SelectedText = NULL;
  1829.                              }
  1830.                            help = GetMeFileName("Enter the text to load");
  1831.                            if ( help != 0)
  1832.                              {
  1833.                               HelpText = ReadTextFile( WholeText);
  1834.                               if ( HelpText != NULL)
  1835.                                 {
  1836.                                  ReDrawLabel( FindStart( FirstText));
  1837.                                  CurrText = FindEnd( FirstText);
  1838.                                  IsArc = 0;
  1839.                                 }
  1840.                               else
  1841.                                 {
  1842.                                  DeleteAllTexts( FindStart( FirstText));
  1843.                                 }
  1844.                              }
  1845.                           }
  1846.                         break;
  1847.                 case 5: if (SelectedText)
  1848.                           {
  1849.                            ToggleText( SelectedText);
  1850.                            SelectedText = NULL;
  1851.                           }
  1852.                         if ( CurrText = Do_Edit_Text( NULL))
  1853.                           {
  1854.                            PlaceSelectedText( CurrText);
  1855.                           }
  1856.                         break;
  1857.                 case 6: if ( SelectedText)
  1858.                           {
  1859.                            ToggleText( SelectedText);
  1860.                            Do_Edit_Text( SelectedText);
  1861.                            ReDrawLabel( FindStart( SelectedText));
  1862.                            SelectedText = NULL;
  1863.                           }
  1864.                         else
  1865.                           {
  1866.                            LMMessage("You have to select a text first!");
  1867.                           }
  1868.                         break;
  1869.                 case 7: if ( SelectedText)
  1870.                           {
  1871.                            ToggleText( SelectedText);
  1872.                            PlaceSelectedText( SelectedText);
  1873.                            SelectedText = NULL;
  1874.                            IsArc = 0;
  1875.                           }
  1876.                         else
  1877.                           {
  1878.                            LMMessage("You have to select a text first!");
  1879.                           }
  1880.                         break;
  1881.                 case 8: PlacePic();
  1882.                         ReDrawLabel( FindStart( CurrText));
  1883.                         SelectedText = NULL;
  1884.                         IsArc =0;
  1885.                         break;
  1886.                 case 9: if ( SelectedText)
  1887.                           {
  1888.                            ToggleText( SelectedText);
  1889.                            CurrText = DeleteText( SelectedText);
  1890.                            if ( FirstText == SelectedText)
  1891.                              {
  1892.                               FirstText = CurrText;
  1893.                              }
  1894.                            ReDrawLabel( FindStart( CurrText));
  1895.                            IsArc =0;
  1896.                            SelectedText = NULL;
  1897.                           }
  1898.                         else
  1899.                           {
  1900.                            LMMessage("You have to select a text first!");
  1901.                           }
  1902.                         break;
  1903.                case 10: PicOn = 2;
  1904.                         if (SelectedText)
  1905.                           {
  1906.                            ToggleText( SelectedText);
  1907.                            SelectedText = NULL;
  1908.                           }
  1909.                         ReDrawLabel( FindStart( CurrText));
  1910.                         IsArc =0;
  1911.                         break;
  1912.                case 11: if (IsArc != 1)
  1913.                           {
  1914.                            ContOn = LMDecision("Delete unsaved label?");
  1915.                           }
  1916.                         else
  1917.                           {
  1918.                            ContOn =1;
  1919.                           }
  1920.                         if (ContOn == 1)
  1921.                           {
  1922.                            DeleteAllTexts( FindStart( FirstText));
  1923.                            FirstText = NULL;
  1924.                            CurrText = NULL;
  1925.                            SelectedText = NULL;
  1926.                            PicOn = 0;
  1927.                            CopyMem( DefaultMap, MyColorMap, 16L);
  1928.                            ClearLabelArea();
  1929.                            LoadRGB4( cvp, MyColorMap, 8L);
  1930.                            IsArc = 1;
  1931.                           }
  1932.                         break;
  1933.                case 12: ReDrawLabel( FindStart( CurrText));
  1934.                         DumpLabel( CtrlScreen);
  1935.                         SelectedText = NULL;
  1936.                         break;
  1937.                case 13: SetDefaults();
  1938.                         if (SelectedText)
  1939.                           {
  1940.                            ToggleText( SelectedText);
  1941.                            SelectedText = NULL;
  1942.                           }
  1943.                         ReDrawLabel( FindStart( CurrText));
  1944.                         break;
  1945.                case 14: LMInformation();
  1946.                         break;
  1947.                case 15: if (IsArc != 1)
  1948.                           {
  1949.                            ContOn = LMDecision("Discard current label?");
  1950.                           }
  1951.                         else
  1952.                           {
  1953.                            ContOn =1;
  1954.                           }
  1955.                         if (ContOn == 1)
  1956.                           {
  1957.                            ContOn = LMDecision("Really quit this program?");
  1958.                            if (ContOn == 1) AllIsLost = 1;
  1959.                           }
  1960.                         break;
  1961.                case 16: HelpText = GetSelectedText( MsY - LABEL_TOP);
  1962.                         ToggleText( SelectedText);
  1963.                         if (HelpText)
  1964.                           {
  1965.                            SelectedText = ( HelpText == SelectedText)?
  1966.                                           NULL:
  1967.                                           HelpText;
  1968.                            ToggleText( SelectedText);
  1969.                           }
  1970.                         else
  1971.                           {
  1972.                            SelectedText = NULL;
  1973.                           }
  1974.                         break;
  1975.                }
  1976.              if ( CurrText == NULL) CurrText = FirstText;
  1977.             }
  1978.          }
  1979.       }
  1980.    }
  1981.  DeleteAllTexts( FindStart(FirstText));
  1982.  CloseEnvironment( Environment);
  1983. }
  1984.  
  1985.