home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 514b.lha / GadgetED_v2.3 / Source / text.c < prev    next >
C/C++ Source or Header  |  1991-06-08  |  6KB  |  224 lines

  1. /*----------------------------------------------------------------------*
  2.    text.c Version 2.3 -  © Copyright 1990-91 Jaba Development
  3.  
  4.    Author : Jan van den Baard
  5.    Purpose: Text requester for adding and modifying gadget texts
  6.  *----------------------------------------------------------------------*/
  7.  
  8. static UBYTE UNDOBUFFER[80];
  9. static SHORT MainPairs2[] =
  10.  { 0,0,291,0
  11.  };
  12. static struct Border MainBorder2 =
  13.  { 2,12,0,0,JAM1,2,MainPairs2,NULL
  14.  };
  15. static SHORT MainPairs1[] =
  16.  { 0,0,291,0,291,106,0,106,0,0
  17.  };
  18. static struct Border MainBorder1 =
  19.  { 2,1,0,0,JAM1,5,MainPairs1,&MainBorder2
  20.  };
  21.  
  22. static struct IntuiText GT =
  23.  { 0,0,JAM1,88,3,NULL,(UBYTE *)"Edit GadgetText",NULL
  24.  };
  25. static struct IntuiText WT =
  26.  { 0,0,JAM1,88,3,NULL,(UBYTE *)"Edit WindowText",NULL
  27.  };
  28. static struct IntuiText RT =
  29.  { 0,0,JAM1,76,3,NULL,(UBYTE *)"Edit RequesterText",NULL
  30.  };
  31. static struct IntuiText MainText1 =
  32.  { 0,0,JAM1,114,35,NULL,(UBYTE *)"DrawModes",>
  33.  };
  34.  
  35. static SHORT OCPairs[] =
  36.  { 0,0,133,0,133,26,0,26,0,0
  37.  };
  38. static struct Border OCBorder =
  39.  { -1,-1,0,0,JAM1,5,OCPairs,NULL
  40.  };
  41.  
  42. static struct IntuiText CANCELText =
  43.  { 0,0,JAM1,42,9,NULL,(UBYTE *)"CANCEL",NULL
  44.  };
  45. static struct Gadget CANCEL =
  46.  { NULL,152,77,132,25,NULL,RELVERIFY,BOOLGADGET,
  47.    (APTR)&OCBorder,NULL,&CANCELText,NULL,NULL,6,NULL
  48.  };
  49.  
  50. static struct IntuiText OKText =
  51.  { 0,0,JAM1,58,9,NULL,(UBYTE *)"OK",NULL
  52.  };
  53. static struct Gadget OK =
  54.  { &CANCEL,13,77,132,25,NULL,RELVERIFY,BOOLGADGET,
  55.    (APTR)&OCBorder,NULL,&OKText,NULL,NULL,5,NULL
  56.  };
  57.  
  58. static SHORT DRMDPairs[] =
  59.  { 0,0,133,0,133,12,0,12,0,0
  60.  };
  61. static struct Border DRMDBorder =
  62.  { -1,-1,0,0,JAM1,5,DRMDPairs,NULL
  63.  };
  64.  
  65. static struct IntuiText IVText =
  66.  { 0,0,JAM1,30,2,NULL,(UBYTE *)"INVERSVID",NULL
  67.  };
  68. static struct Gadget IV =
  69.  { &OK,152,60,132,11,NULL,GADGIMMEDIATE+TOGGLESELECT,BOOLGADGET,
  70.    (APTR)&DRMDBorder,NULL,&IVText,NULL,NULL,4,NULL
  71.  };
  72.  
  73. static struct IntuiText J2Text =
  74.  { 0,0,JAM1,49,2,NULL,(UBYTE *)"JAM2",NULL
  75.  };
  76. static struct Gadget J2 =
  77.  { &IV,13,60,132,11,NULL,GADGIMMEDIATE+TOGGLESELECT,BOOLGADGET,
  78.    (APTR)&DRMDBorder,NULL,&J2Text,1,NULL,3,NULL
  79.  };
  80.  
  81. static struct IntuiText CMText =
  82.  { 0,0,JAM1,27,2,NULL,(UBYTE *)"COMPLEMENT",NULL
  83.  };
  84. static struct Gadget CM =
  85.  { &J2,152,45,132,11,NULL,GADGIMMEDIATE+TOGGLESELECT,BOOLGADGET,
  86.    (APTR)&DRMDBorder,NULL,&CMText,NULL,NULL,2,NULL
  87.  };
  88.  
  89. static struct IntuiText J1Text =
  90.  { 0,0,JAM1,50,2,NULL,(UBYTE *)"JAM1",NULL
  91.  };
  92. static struct Gadget J1 =
  93.  { &CM,13,45,132,11,NULL,GADGIMMEDIATE+TOGGLESELECT,BOOLGADGET,
  94.    (APTR)&DRMDBorder,NULL,&J1Text,4,NULL,1,NULL
  95.  };
  96.  
  97. static UBYTE ITBuff[80];
  98. static struct StringInfo ITInfo =
  99.  { ITBuff,UNDOBUFFER,0,80,0,0,0,0,0,0,0,0,NULL
  100.  };
  101. static SHORT ITPairs[] =
  102.  { 0,0,273,0,273,9,0,9,0,0
  103.  };
  104. static struct Border ITBorder =
  105.  { -1,-1,2,0,JAM1,5,ITPairs,NULL
  106.  };
  107. static struct IntuiText ITText =
  108.  { 0,0,JAM1,0,-10,NULL,(UBYTE *)"Enter or edit text :",NULL
  109.  };
  110. static struct Gadget IT =
  111.  { &J1,13,24,272,8,NULL,STRINGCENTER,STRGADGET,
  112.    (APTR)&ITBorder,NULL,&ITText,NULL,(APTR)&ITInfo,0,NULL
  113.  };
  114.  
  115. struct NewWindow text_req =
  116.  { 12,15,296,109,0,1,GADGETUP+GADGETDOWN,
  117.    NOCAREREFRESH+SMART_REFRESH+ACTIVATE+RMBTRAP,
  118.    NULL,NULL,NULL,NULL,NULL,0,0,0,0,CUSTOMSCREEN
  119.  };
  120.  
  121. static struct RastPort *rp;
  122.  
  123. extern struct Window      *MainWindow;
  124. extern struct Screen      *MainScreen;
  125. extern struct Gadget      *Gadget;
  126. extern struct MemoryChain  Memory;
  127. extern USHORT              FrontPen, BackPen;
  128.  
  129. /*
  130.  * put up the text editor
  131.  */
  132. struct IntuiText *edit_text(gadget,mode,num,which)
  133.    struct Gadget *gadget;
  134.    LONG          mode;
  135.    SHORT         num;
  136.    USHORT        which;
  137. {
  138.    struct Window    *w;
  139.    struct IntuiText *t,*t1, *GetPtr();
  140.    BOOL             running = TRUE, Add;
  141.    USHORT           gp,i;
  142.  
  143.    if(mode)
  144.    {   t = GetPtr(gadget,num);
  145.        strcpy((char *)ITBuff,(char *)t->IText);
  146.    }
  147.    else ITBuff[0] = 0;
  148.    text_req.Screen = MainScreen;
  149.    if(NOT(w = OpenWindow(&text_req))) return;
  150.    disable_window();
  151.    rp = w->RPort;
  152.    if(NOT which) MainText1.NextText       = >
  153.    if(which == 1) MainText1.NextText      = &WT;
  154.    else if(which == 2) MainText1.NextText = &RT;
  155.    draw(w,&IT,&MainBorder1,&MainText1);
  156.    DeSelectGList(w,&J1,NULL,4);
  157.    if(mode)
  158.    {   if(TestBits((ULONG)t->DrawMode,JAM2)) SelectGadget(w,&J2,NULL);
  159.        else SelectGadget(w,&J1,NULL);
  160.        if(TestBits((ULONG)t->DrawMode,COMPLEMENT))
  161.             SelectGadget(w,&CM,NULL);
  162.        if(TestBits((ULONG)t->DrawMode,INVERSVID))
  163.             SelectGadget(w,&IV,NULL);
  164.    }
  165.    else if(NOT mode) SelectGadget(w,&J1,NULL);
  166.    do
  167.    {    for(i=0;i<3;i++) ActivateGadget(&IT,w,NULL);
  168.         Wait(1 << w->UserPort->mp_SigBit);
  169.         while(read_msg(w))
  170.         {   gp = Gadget->GadgetID;
  171.             if(gp == 5)
  172.             {   running = FALSE;
  173.                 Add = TRUE;
  174.             }
  175.             if(gp == 6)
  176.             {   running = FALSE;
  177.                 Add = FALSE;
  178.             }
  179.             if(gp == 1 OR gp == 3)
  180.             {   MutualExclude(w,Gadget,&J1,NULL);
  181.                 SelectGadget(w,Gadget,NULL);
  182.             }
  183.        }
  184.    } while(running == TRUE);
  185.    CloseWindow(w);
  186.    if((Add == TRUE) AND (ITBuff[0] != 0) AND (NOT mode))
  187.    {   if(NOT(t = (struct IntuiText *)
  188.          Alloc(&Memory,(ULONG)sizeof(struct IntuiText))))
  189.        {   Error("Out of memory !");
  190.            enable_window();
  191.            return(NULL);
  192.        }
  193.        if(NOT(t->IText = (UBYTE *)Alloc(&Memory,80L)))
  194.        {   FreeItem(&Memory,t,(long)sizeof(struct IntuiText));
  195.            Error("Out of memory !");
  196.            enable_window();
  197.            return(NULL);
  198.        }
  199.        if((t1 = gadget->GadgetText))
  200.        {   while(1)
  201.            {   if(NOT t1->NextText) break;
  202.                t1 = t1->NextText;
  203.            }
  204.            t1->NextText = t;
  205.        }
  206.        else gadget->GadgetText = t;
  207.    }
  208.    if(Add == TRUE)
  209.    {   strcpy((char *)t->IText,(char *)ITBuff);
  210.        t->DrawMode = NULL;
  211.        if(SelectTest(&J1)) t->DrawMode = JAM1;
  212.        if(SelectTest(&J2)) t->DrawMode = JAM2;
  213.        if(SelectTest(&IV)) t->DrawMode |= INVERSVID;
  214.        if(SelectTest(&CM)) t->DrawMode |= COMPLEMENT;
  215.        t->FrontPen = FrontPen;
  216.        t->BackPen  = BackPen;
  217.        enable_window();
  218.        if(mode) return(NULL);
  219.        return(t);
  220.    }
  221.    enable_window();
  222.    return(NULL);
  223. }
  224.