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 / text.c < prev    next >
C/C++ Source or Header  |  1991-09-15  |  6KB  |  204 lines

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