home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #3 / amigamamagazinepolishissue1998.iso / bazy / db3.4 / design.c < prev    next >
C/C++ Source or Header  |  1996-02-28  |  34KB  |  1,410 lines

  1.  
  2. #include <exec/types.h>
  3. #include <intuition/intuition.h>
  4. #include <libraries/gadtools.h>
  5. #include <proto/intuition.h>
  6. #include <proto/graphics.h>
  7. #include <proto/gadtools.h>
  8. #include <proto/utility.h>
  9. #include <proto/exec.h>            /* CopyMem() */
  10. #include <string.h>        /* strcpy */
  11. #include <stdlib.h>    /* abs() macro */
  12.  
  13. #include "Design.h"
  14. #include "dbGUI.h"
  15. #include "dbparser.h"
  16. #include "Toolbox.h"
  17. #include "DesignGUI.h"
  18. #include "Version.h"
  19.  
  20. #include "Pointers.h"
  21.  
  22. #include <stdio.h> // Diagnostics
  23.  
  24. /*
  25.  * Externs to make the new GadToolsBox interface work
  26.  * Remove "static" from these in DesignGUI.c
  27.  */
  28. extern struct Gadget         *VisGadgets[];
  29. extern struct Window         *VisWnd;
  30. extern struct NewMenu            DesignNewMenu[];
  31. extern struct Menu           *DesignMenus;
  32.  
  33. #define CURSORWIDTH 3
  34. #define DRAGTRESHOLD 6
  35. #define TOGGLE_LED *(UBYTE *)0xbfe001 ^= 2    /* Debug */
  36.  
  37. /* Handy macros */
  38. #define FLOOR(x,f) if ((x)<(f)) (x) = (f) 
  39.  
  40. /* Return codes from GadToolBox handlers */
  41. #define RET_OK 1
  42. #define RET_CANCEL 2
  43.  
  44.  
  45.  
  46. extern WORD LastLeftEdge;
  47. extern WORD LastTopEdge;        /* For nice layoutswitching */
  48.  
  49. extern void UpdateWindow(struct Pro *Pr);
  50. extern void UpdateDragBar(struct Pro *Pr);
  51.  
  52. typedef int Bool;    /* A char would be smaller, but will produce non-cast warnings */
  53.  
  54. typedef struct {
  55.     struct VisFldInfo *vf;
  56.     Bool after;    /* Has cursor passed field? (to the left or right of field) */
  57. } Cursor;
  58.  
  59.  
  60. struct EasyStruct ES_ViewDesignHelp =
  61. {
  62.     sizeof(struct EasyStruct),
  63.     0,
  64.     (STRPTR)"View design",
  65.     (STRPTR)    "\n"
  66.     "The purpose of this part of db is to allow you to add, edit, rearrange\n"
  67.     "and remove visual fields (gadgets) in the current view in a simple way\n"
  68.     "by using common mouse and key operations (db will write the RFF code).\n"
  69.     "\n"
  70.     "You pick new visual fields from the toolbox to the right. They may\n"
  71.     "later be edited with a simple doubleclick. To Resize and move them\n"
  72.     "around, point at them and drag the mouse (the right border of any visual\n"
  73.     "field is resize-sensitive).\n"
  74.     "\n"
  75.     "You can cut, copy and paste visual fields as expected and there is\n"
  76.     "also an undo to help you out.\n"
  77.     "\n"
  78.     "Visual fields are either separated by a space, tab, newline or double\n"
  79.     "newline. Use the keyboard to add and remove these separators.\n"
  80.     "\n"
  81.     "In this release you still need to use a text editor to specify the\n"
  82.     "INTERNAL fields, but that's simple; just write all names in one line,\n"
  83.     "separate them with tabs, add a newline, save it and load it into db.\n"
  84.     "\n"
  85.     "See the documentation for more information. Have fun!",
  86.     (STRPTR)"Ok"
  87. };
  88.  
  89.  
  90. /**********************************************************************/
  91. /*                              Globals                               */
  92. /**********************************************************************/
  93.  
  94. Cursor Crsr;
  95. struct VisFldInfo *Selected;    /* The selected field that has a rubberband */
  96. int DragCnt = 0;    /* Non-zero if dragging Selected. */
  97. Bool Sizing = FALSE;
  98.  
  99. struct Window *ToolBox = NULL;
  100.  
  101. /* GadToolBox handlers uses global variables */
  102. extern struct Pro *CurrentPro;
  103. struct VisFldInfo *Vf;
  104. extern char *RFFTagNames[];
  105.  
  106. /* The clipboard */
  107. struct VisFldInfo *Clip = NULL;
  108.  
  109. /**********************************************************************/
  110. /*                         Support functions                          */
  111. /**********************************************************************/
  112.  
  113. struct VisFldInfo *PrevVisFldInfo(struct Layout *Lay, struct VisFldInfo *vf)
  114. {
  115.     struct VisFldInfo *t = Lay->FirstVisFldInfo;
  116.     if (t == vf) return NULL;
  117.     for (; t; t = t->Next) if (t->Next == vf) return t;
  118.     return NULL; /* Safety */
  119. }
  120.  
  121. static void InitCursor(struct Layout *Lay, Cursor *crsr)
  122. {
  123.     crsr->vf = Lay->FirstVisFldInfo;
  124.     crsr->after = FALSE;
  125. }
  126.  
  127. static void GetCursorPosition(Cursor *crsr, WORD *x, WORD *y)
  128. {
  129.     /* Return position of cursor in (x,y) coords */
  130.     if (crsr->vf) {
  131.         *y = crsr->vf->Pos.YOffset;
  132.         *x = crsr->vf->Pos.XOffset;
  133.         *x += (crsr->after) ? crsr->vf->Pos.Width + CURSORWIDTH : -2*CURSORWIDTH;
  134.     }
  135.     else {
  136.         *x = OffX + FontX;            /* As in CalcAllPos() */
  137.         *y = OffY + (FontY >> 1);    /* As in CalcAllPos() */
  138.     }
  139. }
  140.  
  141. static int PreviousPosition(struct Layout *Lay, Cursor *crsr)
  142. {
  143.     /* Position cursor one step to the left (maybe up) */
  144.     /* Return FALSE if this is not possible */
  145.     struct VisFldInfo *vf;
  146.  
  147.     if (!crsr->vf) return FALSE;    /* No gadgets at all */
  148.  
  149.     if (crsr->after) {
  150.         crsr->after = FALSE;
  151.         return TRUE;
  152.     }
  153.     else if (vf = PrevVisFldInfo(Lay, crsr->vf)) {
  154.         crsr->vf = vf;
  155.         crsr->after = TRUE;
  156.         return TRUE;
  157.     }
  158.     return FALSE;
  159. }
  160.  
  161. static int NextPosition(struct Layout *Lay, Cursor *crsr)
  162. {
  163.     /* Position cursor one step to the right (maybe down) */
  164.     /* Return FALSE if this is not possible */
  165.  
  166.     if (!crsr->vf) return FALSE;    /* No gadgets at all */
  167.  
  168.     if (!crsr->after) {
  169.         crsr->after = TRUE;
  170.         return TRUE;
  171.     }
  172.     else if (crsr->vf->Next) {
  173.         crsr->vf = crsr->vf->Next;
  174.         crsr->after = FALSE;
  175.         return TRUE;
  176.     }
  177.     return FALSE;
  178. }
  179.  
  180.  
  181. static void DisplayCursor(struct RastPort *rp, WORD x, WORD y)
  182. {
  183.     /* Draws a cursor in complement colour at given position */
  184.     /* Deletes cursor at old position automatically */
  185.     /* Specify a negative coordinate in either x or y to remove cursor */
  186.     /* DisplayCursor assumes a locked cursorheight */
  187.  
  188.     static WORD oldx = -1, oldy = -1;
  189.  
  190.     SetDrMd(rp, COMPLEMENT);
  191.  
  192.     if (oldx>=0 && oldy>=0)
  193.         RectFill(rp, oldx, oldy, oldx+CURSORWIDTH-1, oldy+FontY+STRGADFRAMESHEIGHT-1);
  194.  
  195.     if (x>=0 && y>=0)
  196.         RectFill(rp, x, y, x+CURSORWIDTH-1, y+FontY+STRGADFRAMESHEIGHT-1);
  197.     oldx = x;
  198.     oldy = y;
  199. }
  200.  
  201. static void Rubberband(struct RastPort *rp, WORD left, WORD top, WORD width, WORD height, char handle)
  202. {
  203.     /* Draws a border rectangle in complement colour. Adds a handle square if "handle" is TRUE */
  204.     /* Deletes old rubberband automatically */
  205.     /* Specify a negative coordinate in either left or top to remove rubberband */
  206.     static WORD oldleft = -1, oldtop = -1, oldwidth=-1, oldheight=-1, oldhandle = 0;
  207.  
  208.  
  209.     SetDrMd(rp, COMPLEMENT);
  210.     left--; top--; width++; height++;
  211.  
  212.     if (oldleft>=0 && oldtop>=0) {
  213.         Move(rp, oldleft, oldtop);
  214.         Draw(rp, oldleft+oldwidth, oldtop);
  215.         Draw(rp, oldleft+oldwidth, oldtop+oldheight);
  216.         Draw(rp, oldleft, oldtop+oldheight);
  217.         Draw(rp, oldleft, oldtop);
  218.         if (oldhandle) { /* Draw a 3x4 square in the middle of the right border */
  219.             RectFill(rp, oldleft+oldwidth+1, oldtop+(oldheight>>1), oldleft+oldwidth+4, oldtop+(oldheight>>1)+2);
  220.         }
  221.     }
  222.  
  223.     if (left>=0 && top>=0) {
  224.         Move(rp, left, top);
  225.         Draw(rp, left+width, top);
  226.         Draw(rp, left+width, top+height);
  227.         Draw(rp, left, top+height);
  228.         Draw(rp, left, top);
  229.         if (handle) { /* Draw a 3x4 square in the middle of the right border */
  230.             RectFill(rp, left+width+1, top+(height>>1), left+width+4, top+(height>>1)+2);
  231.         }
  232.     }
  233.     oldleft = left; oldtop = top; oldwidth = width; oldheight = height; oldhandle = handle;
  234.  
  235. }
  236.  
  237.  
  238. void FollowMouse(struct Layout *Lay, WORD mx, WORD my)
  239. {
  240.     /* Moves the cursor to the position that is nearest to (x,y) */
  241.     Cursor nearest;
  242.     WORD x,y;
  243.     WORD nx, ny;
  244.  
  245.     if (!Crsr.vf) return;
  246.     while (PreviousPosition(Lay, &Crsr));    /* Go to the beginning */
  247.     nearest = Crsr;
  248.     GetCursorPosition(&nearest, &nx, &ny);
  249.  
  250.     while (NextPosition(Lay, &Crsr)) {
  251.         GetCursorPosition(&Crsr, &x, &y);
  252.         if (abs(my-y) < abs(my-ny)) {
  253.             nearest = Crsr;
  254.              GetCursorPosition(&nearest, &nx, &ny);
  255.         }
  256.         if (abs(my-y) == abs(my-ny))
  257.             if (abs(mx-x) < abs(mx-nx)) {
  258.                 nearest = Crsr;
  259.                  GetCursorPosition(&nearest, &nx, &ny);
  260.             }
  261.     }
  262.     Crsr = nearest;
  263.     DisplayCursor(Lay->Window->RPort, nx, ny);
  264. }
  265.  
  266. static struct VisFldInfo *VisFldHit(struct Layout *Lay, WORD x, WORD y)
  267. {
  268.     /* Returns the address of the VisFldInfo that is hit by (x,y) */
  269.     struct VisFldInfo *vf = NULL;
  270.     
  271.     for (vf = Lay->FirstVisFldInfo; vf; vf = vf->Next) {
  272.         if (x >= vf->Pos.XOffset && x < vf->Pos.XOffset+vf->Pos.Width &&
  273.              y >= vf->Pos.YOffset && y < vf->Pos.YOffset+vf->Pos.Height)
  274.              break;
  275.     }
  276.     return vf;
  277. }
  278.  
  279. static Bool SizeHit(struct VisFldInfo *hit, WORD mouseX)
  280. {
  281.     /* Return true if mouse is close to the right border of the "hit" field */
  282.     return (hit && (hit->Pos.XOffset + hit->Pos.Width - mouseX) < 5);
  283. }
  284.  
  285. void SelectVisFld(struct Layout *Lay, struct VisFldInfo *vf)
  286. {
  287.     if (Selected = vf) {
  288.         struct Space *sp = &Selected->Pos;
  289.         Rubberband(Lay->Window->RPort, sp->XOffset, sp->YOffset, sp->Width, sp->Height, 0);
  290.     }
  291.     else {
  292.         Rubberband(Lay->Window->RPort, -1, -1, -1, -1, 0);
  293.     }
  294. }
  295.  
  296.  
  297. static struct VisFldInfo *RemoveVisFldInfo(struct Layout *Lay, struct VisFldInfo *oldvf)
  298. {
  299.     /* Remove oldvf from the layout and handle all side effects this may have */
  300.  
  301.     struct VisFldInfo *prev;
  302.  
  303.     if (!oldvf) return NULL;
  304.     prev = PrevVisFldInfo(Lay, oldvf);
  305.  
  306.     if (prev) {
  307.         prev->Next = oldvf->Next;
  308.         if (oldvf->VisSep == '\n' || oldvf->VisSep == '\f') {    /* end of line */
  309.             prev->VisSep = oldvf->VisSep;
  310.             WriteVisTags(prev);    /* Update RFF tags in vf */
  311.         }
  312.     }
  313.     else Lay->FirstVisFldInfo = oldvf->Next;
  314.  
  315.     /* Handle cursor and rubberband */
  316.     if (Crsr.vf == oldvf) {
  317.         if (Crsr.vf->Next) Crsr.vf = Crsr.vf->Next;
  318.         else Crsr.vf = prev;    /* This might be NULL, and that's ok */
  319.     }
  320.     SelectVisFld(Lay, NULL);
  321.  
  322.     return oldvf;
  323. }
  324.  
  325.  
  326. static void InsertVisFldInfo(struct Layout *Lay, struct VisFldInfo *vf)
  327. {
  328.     /* Insert vf in the layout and handle all side effects this may have */
  329.     /* vf is placed at the cursor position */
  330.  
  331.     struct VisFldInfo **link_here;
  332.  
  333.     if (!Lay->FirstVisFldInfo) link_here = &Lay->FirstVisFldInfo;
  334.     else if (Crsr.after) {
  335.         link_here = &Crsr.vf->Next;
  336.         vf->VisSep = Crsr.vf->VisSep;
  337.         Crsr.vf->VisSep = ' ';
  338.         WriteVisTags(vf);
  339.         WriteVisTags(Crsr.vf);
  340.     }
  341.     else {
  342.         struct VisFldInfo *prevvf = PrevVisFldInfo(Lay, Crsr.vf);
  343.         if (!prevvf) link_here = &Lay->FirstVisFldInfo;
  344.         else link_here = &prevvf->Next;
  345.         vf->VisSep = ' ';
  346.     }
  347.     /* Link */
  348.     vf->Next = *link_here;
  349.     *link_here = vf;
  350.  
  351. //    SelectVisFld(Lay, vf);        /* Now, it's easy to spot the new field */
  352. }
  353.  
  354. int DeleteUndo(struct Layout *Lay)
  355. {
  356.     struct VisFldInfo *vf,*nextvf;
  357.     for (vf = Lay->FirstUndoVisFldInfo; vf; vf=nextvf) {
  358.         nextvf = vf->Next;
  359.         DeleteVisFldInfo(vf);
  360.     }
  361.     Lay->FirstUndoVisFldInfo = NULL;
  362.     OffMenu(CurrentPro->CurrentLayout->Window, FULLMENUNUM(1,0,NOSUB)); /* Edit->Undo */
  363.     return 0;
  364. }
  365.  
  366. Bool PerformUndo(struct Layout *Lay)
  367. {
  368.     struct VisFldInfo *tmp;
  369.     if (!Lay->FirstUndoVisFldInfo) return FALSE;
  370.     tmp = Lay->FirstVisFldInfo;
  371.     Lay->FirstVisFldInfo = Lay->FirstUndoVisFldInfo;
  372.     Lay->FirstUndoVisFldInfo = tmp;
  373.     
  374.     Crsr.vf = Lay->FirstVisFldInfo;
  375.     Selected = NULL;
  376.     return TRUE;
  377. }
  378.  
  379. Bool SaveUndo(struct Layout *Lay)
  380. {
  381.     struct VisFldInfo *vf, **link_here;
  382.     DeleteUndo(Lay);    /* Remove old undo */
  383.     link_here = &Lay->FirstUndoVisFldInfo;
  384.     for (vf = Lay->FirstVisFldInfo; vf; vf=vf->Next, link_here = &((*link_here)->Next)) {
  385.         if (!(*link_here = CopyVisFldInfo(vf))) return DeleteUndo(Lay);
  386.     }
  387.     OnMenu(CurrentPro->CurrentLayout->Window, FULLMENUNUM(1,0,NOSUB)); /* Edit->Undo */
  388.     CurrentPro->Modified |= PROMODIFIED;
  389.     return TRUE;
  390. }
  391.  
  392. static int Redraw(struct Pro *Pr, struct Layout *Lay)
  393. {
  394.     /* Recalculates all gadgets and redraws the updated window */
  395.     WORD ww, wh;
  396.     WORD x,y;
  397.     int ret;
  398.     Bool ok = TRUE;
  399.  
  400.     /* Tear down */
  401.     DisplayCursor(Lay->Window->RPort, -1, -1);
  402.     Rubberband(Lay->Window->RPort, -1, -1, -1, -1, 0);
  403.  
  404.     /* Rebuild with undo fallback */
  405.     do {
  406.         if ((ret = CalcAllPos(Pr, Lay, &ww, &wh)) >= 0) {
  407.             if ((ret = CreateAllGadgets(Pr, Lay, ww, wh, DESIGN_MODE)) >= 0) {
  408.                 if ((ret = AttachAllGadgets(Lay, ww, wh, DESIGN_MODE)) >= 0) {
  409.  
  410.                     DeleteAllGadgets(Lay, DESIGN_MODE);
  411.                     GetCursorPosition(&Crsr, &x, &y);
  412.                     DisplayCursor(Lay->Window->RPort, x, y);
  413.                     SelectVisFld(Lay, Selected);    /* Update rubberband */
  414.  
  415.                     /* Update pointer */
  416.                     if (SizeHit(VisFldHit(Lay, DB_Msg.MouseX, DB_Msg.MouseY), DB_Msg.MouseX))
  417.                         ChangePointer(Lay->Window, LRPointer);
  418.                     else RestorePointer(Lay->Window);
  419.                     return ret;
  420.                 }
  421.             }
  422.             DeleteAllGadgets(Lay, DESIGN_MODE);
  423.         }
  424.         DisplayBeep(Scr);
  425.         ok = PerformUndo(Lay);
  426.         DeleteUndo(Lay);
  427.     } while (ok);
  428.     return ret;        /* This is serious trouble */
  429. }
  430.  
  431.  
  432. int DoEdit(struct Pro *Pr, struct VisFldInfo *vf)
  433. {
  434.     /* Let the user perform the actual editing of a vf */
  435.     /* returns 0 if no changes has been made to vf */
  436.  
  437.     struct FldInfo *f;
  438.     BOOL quit = FALSE;
  439.  
  440.     if (OpenVisWindow()) return 0;
  441.  
  442.     /* Prepare gadgets */
  443.     GT_SetGadgetAttrs(VisGadgets[GD_VIS_NAME], VisWnd, NULL,
  444.         GTST_String, vf->Name,
  445.         TAG_END);
  446.  
  447.     GT_SetGadgetAttrs(VisGadgets[GD_VIS_SIZE], VisWnd, NULL,
  448.         GTIN_Number, vf->VisLen,
  449.         TAG_END);
  450.  
  451.     if (f = GetFldInfo(Pr, vf->Offset))
  452.         GT_SetGadgetAttrs(VisGadgets[GD_VIS_FIELD], VisWnd, NULL,
  453.             GTTX_Text, f->Name,
  454.             TAG_END);
  455.     else GT_SetGadgetAttrs(VisGadgets[GD_VIS_FIELD], VisWnd, NULL,
  456.             GTTX_Text, "<Select field>",
  457.             TAG_END);
  458.  
  459.     Vf = vf;        /* GadTooBox handlers use global variables */
  460.  
  461.     /* Handle input */
  462.     while (!quit) {
  463.         WaitPort(VisWnd->UserPort);
  464.         quit = HandleVisIDCMP();
  465.     }
  466.     CloseVisWindow();    /* GadToolBox automatically NULLs pointers */
  467.  
  468.     if (quit == RET_CANCEL) return 0;
  469.  
  470.     /* update vf */
  471.     strcpy(vf->Name, GetString(VisGadgets[GD_VIS_NAME]));
  472.     vf->VisLen = GetNumber(VisGadgets[GD_VIS_SIZE]);
  473.     WriteVisTags(vf);    /* Update RFF tags in vf */
  474.  
  475.     /* As user might have connected the vf to an internal field of cycle type,
  476.     * we must then remake the cycle list by reading the VisTags
  477.     */
  478.     if (ReadVisTags(Pr, vf) < 0) return 0;
  479.     /* vf->Offset and the tags has been updated inside GadToolBox */
  480.  
  481.     return 1;    /* Use */
  482. }
  483.  
  484. void ReplaceVisFldInfo(struct Layout *Lay, struct VisFldInfo *old, struct VisFldInfo *new)
  485. {
  486.     struct VisFldInfo *prev = PrevVisFldInfo(Lay, old);
  487.     new->Next = old->Next;
  488.     if (prev) prev->Next = new;
  489.     else Lay->FirstVisFldInfo = new;
  490.     
  491.     /* Don't forget to make sure that the cursor and rubberband points correctly */
  492.     if (Crsr.vf == old) Crsr.vf = new;
  493.     if (Selected == old) Selected = new;
  494. }
  495.  
  496.  
  497. static void EditVisFldInfo(struct Pro *Pr, struct Layout *Lay, struct VisFldInfo *vf)
  498. {
  499.     struct VisFldInfo *copy = CopyVisFldInfo(vf);
  500.     if (!copy) return;
  501.  
  502.     for (;;) {
  503.         if (!DoEdit(Pr, copy)) {        /* Cancel */
  504.             DeleteVisFldInfo(copy);
  505.             Redraw(Pr, Lay);
  506.             return;
  507.         }
  508.         else {
  509.             ReplaceVisFldInfo(Lay, vf, copy);
  510.             if (Redraw(Pr, Lay) < 0) {        /* Oops, this didn't fit on screen */
  511.                 ReplaceVisFldInfo(Lay, copy, vf);
  512.             }
  513.             else break;
  514.         }
  515.     }
  516.     DeleteVisFldInfo(vf);
  517. }
  518.  
  519. /**********************************************************************/
  520. /*                           Event handlers                           */
  521. /**********************************************************************/
  522.  
  523. static void CloseDesignWin(struct Layout *Lay)
  524. {
  525.     if (Lay->Window) {
  526.  
  527.         DisplayCursor(Lay->Window->RPort, -1, -1);                 /* Remove cursor */
  528.         Rubberband(Lay->Window->RPort, -1, -1, -1, -1, 0); /* Remove rubberband */
  529.  
  530.         /* Remember old window pos */
  531.         LastLeftEdge = Lay->Window->LeftEdge;
  532.         LastTopEdge = Lay->Window->TopEdge;
  533.         ClearMenuStrip(Lay->Window);
  534.         FreeMenus( DesignMenus );
  535.         DesignMenus = NULL;
  536.         CloseWindow(Lay->Window);
  537.         Lay->Window = NULL;
  538.     }
  539. }
  540.  
  541. static int RawKey(struct Pro *Pr, struct Layout *Lay)
  542. {
  543.     WORD x,y;
  544.     WORD oldx,oldy;
  545.     struct VisFldInfo *oldpos = Crsr.vf;
  546.  
  547.     switch (DB_Msg.Code) {
  548. /*        case RAW_F10:
  549.             Redraw(Pr, Lay);
  550.             return 0;
  551.             break;    // Looks nice :-)
  552.  
  553.         case RAW_F10-3:
  554.             DeleteUndo(Lay);
  555.             printf("DeleteUndo\n");
  556.             break;
  557.  
  558.         case RAW_F10-2:
  559.             SaveUndo(Lay);
  560.             printf("Save\n");
  561.             break;
  562.  
  563.         case RAW_F10-1:
  564.             PerformUndo(Lay);
  565.             Redraw(Pr, Lay);
  566.             break;
  567. */
  568.         case RAW_HELP:
  569.             EasyRequest(Lay->Window, &ES_ViewDesignHelp, NULL);
  570.             break;
  571.         case RAW_LEFT:
  572.             PreviousPosition(Lay, &Crsr);
  573.             break;
  574.  
  575.         case RAW_RIGHT:
  576.             NextPosition(Lay, &Crsr);
  577.             break;
  578.  
  579.         case RAW_UP:
  580.             GetCursorPosition(&Crsr, &oldx, &oldy);
  581.  
  582.             while (PreviousPosition(Lay, &Crsr)) {
  583.                 GetCursorPosition(&Crsr, &x, &y);
  584.                 if (y < oldy && x <= oldx) break;
  585.             }
  586.             break;
  587.  
  588.         case RAW_DOWN:
  589.             GetCursorPosition(&Crsr, &oldx, &oldy);
  590.  
  591.             while (NextPosition(Lay, &Crsr)) {
  592.                 GetCursorPosition(&Crsr, &x, &y);
  593.                 if (y > oldy) {
  594.                     oldy = y;
  595.                     break;
  596.                 }
  597.             }
  598.             while (NextPosition(Lay, &Crsr)) {
  599.                 GetCursorPosition(&Crsr, &x, &y);
  600.                 if (y > oldy || x > oldx) {
  601.                     PreviousPosition(Lay, &Crsr);
  602.                     break;
  603.                 }
  604.             }
  605.             break;
  606.     }
  607.     GetCursorPosition(&Crsr, &x, &y);
  608.     DisplayCursor(Lay->Window->RPort, x, y);
  609.     if (Crsr.vf != oldpos) SelectVisFld(Lay, NULL);    /* Cursor has moved, so clear rubberband */
  610.     
  611.     return 0;
  612. }
  613.  
  614.  
  615. static int VanillaKey(struct Pro *Pr, struct Layout *Lay)
  616. {
  617.     struct VisFldInfo *vf = NULL;
  618.  
  619.     char oldVisSep;
  620.  
  621.     SaveUndo(Lay);
  622.     switch (DB_Msg.Code) {
  623.         case '\r':
  624.             if (Crsr.after) vf = Crsr.vf;
  625.             else vf = PrevVisFldInfo(Lay, Crsr.vf);
  626.             if (!vf) break;
  627.             oldVisSep = vf->VisSep;
  628.             switch (vf->VisSep) {
  629.                 case ' ':
  630.                 case '\t':
  631.                     vf->VisSep = '\n';
  632.                     break;
  633.                 case '\n':
  634.                     vf->VisSep = '\f';
  635.                     break;
  636.             }
  637.             break;
  638.  
  639.         case '\t':
  640.             if (Crsr.after) vf = Crsr.vf;
  641.             else vf = PrevVisFldInfo(Lay, Crsr.vf);
  642.             if (!vf) break;
  643.             oldVisSep = vf->VisSep;
  644.             if (vf->VisSep == ' ') {
  645.                 vf->VisSep = '\t';
  646.             }
  647.             break;
  648.             
  649.         case '\b':
  650.             if (Crsr.after) break;
  651.             else vf = PrevVisFldInfo(Lay, Crsr.vf);
  652.             if (!vf) break;
  653.             oldVisSep = vf->VisSep;
  654.             switch (vf->VisSep) {
  655.                 case '\t':
  656.                 case '\n':
  657.                     vf->VisSep = ' ';
  658.                     break;
  659.                 case '\f':
  660.                     vf->VisSep = '\n';
  661.                     break;
  662.             }
  663.             break;
  664.  
  665.         case VANILLA_DEL:
  666.             if (Selected) {    /* Delete the selected field */
  667.                 SaveUndo(Lay);
  668.                 DeleteVisFldInfo(RemoveVisFldInfo(Lay, Selected));
  669.                 Redraw(Pr, Lay);
  670.                 return 0;
  671.             }
  672.             else {
  673.                 if (!Crsr.after) break;
  674.                 else vf = Crsr.vf;
  675.                 if (!vf) break;
  676.                 oldVisSep = vf->VisSep;
  677.                 switch (vf->VisSep) {
  678.                     case '\t':
  679.                     case '\n':
  680.                         vf->VisSep = ' ';
  681.                         break;
  682.                     case '\f':
  683.                         vf->VisSep = '\n';
  684.                         break;
  685.                 }
  686.             }
  687.             break;
  688.  
  689.         case VANILLA_ESC:
  690.             return 1;    /* Exit design mode */
  691.             break;
  692.     }
  693.  
  694.     if (vf && vf->VisSep != oldVisSep) {
  695.         if (Redraw(Pr, Lay) < 0) {        /* Oops, this didn't fit on screen */
  696.             DisplayBeep(Scr);
  697.             vf->VisSep = oldVisSep;
  698.             if (Redraw(Pr, Lay) < 0) ByeBye();        /* This should never happen */
  699.         }
  700.         WriteVisTags(vf);    /* Update RFF tags in vf */
  701.     }
  702.  
  703.     return 0;
  704. }
  705.  
  706.  
  707. int MouseButtons(struct Pro *Pr, struct Layout *Lay)
  708. {
  709.     static ULONG StartSeconds=0, StartMicros=0;
  710.     struct VisFldInfo *oldselected = Selected;
  711.  
  712.     if (Selected = VisFldHit(Lay, DB_Msg.MouseX, DB_Msg.MouseY)) {
  713.         struct Space *sp = &Selected->Pos;
  714.         Rubberband(Lay->Window->RPort, sp->XOffset, sp->YOffset, sp->Width, sp->Height, 0);
  715.  
  716.         if (DoubleClick(StartSeconds, StartMicros, DB_Msg.Seconds, DB_Msg.Micros) &&
  717.              Selected == oldselected) {
  718.             if (DragCnt) {    /* Cancel dragging */
  719.                 DragCnt = 0;
  720.                 RestorePointer(Lay->Window);
  721.             }
  722.             EditVisFldInfo(Pr, Lay, Selected);
  723.             StartSeconds = StartMicros = 0;    /* Prevent "triple clicks" */
  724.         }
  725.         else {
  726.             StartSeconds = DB_Msg.Seconds; StartMicros = DB_Msg.Micros;
  727.             if (Selected) {
  728.                 if (SizeHit(Selected, DB_Msg.MouseX)) {
  729.                     Sizing = TRUE;
  730.                     Forbid();
  731.                     Lay->Window->Flags |= WFLG_RMBTRAP;
  732.                     Permit();
  733.                 }
  734.                 else DragCnt = 1; /* Initiate dragging */
  735.             }
  736.         }
  737.     }
  738.     else {
  739.         Rubberband(Lay->Window->RPort, -1, -1, -1, -1, 0);
  740.         FollowMouse(Lay, DB_Msg.MouseX, DB_Msg.MouseY);
  741.     }
  742.     return 0;
  743. }
  744.  
  745.  
  746. static void ToolBoxClicked(struct Pro *Pr, struct Layout *Lay, int gadgetID)
  747. {
  748.     struct VisFldInfo *vf;
  749.  
  750.     /* Make a VisFldInfo */
  751.     if (!(vf = NewVisFldInfo())) return;
  752.     
  753.     /* Fill in type (string, cycle or checkbox) */
  754.     switch (gadgetID) {
  755.         case CheckBoxID:
  756.             CreateAndAddTag(&vf->VisTags, FTYP, STR_CHECKBOX);
  757.             vf->VisLen = 3;    /* smaller is better */
  758.             break;
  759.         case CycleID:
  760.             CreateAndAddTag(&vf->VisTags, FTYP, STR_CYCLE);
  761.             CreateAndAddTag(&vf->VisTags, CENT, "Apples");
  762.             CreateAndAddTag(&vf->VisTags, CENT, "Pears");
  763.             CreateAndAddTag(&vf->VisTags, CENT, "Bananas");
  764.             vf->VisLen = 16;    /* smaller is better */
  765.             break;
  766.     }
  767.     ReadVisTags(Pr, vf);    /* This way we get the cycle-list in vf */
  768.     vf->Name[0] = '\0'; 
  769.  
  770.     /* Release the user */
  771.     if (!DoEdit(Pr, vf)) {    /* Cancel */
  772.         DeleteVisFldInfo(vf);
  773.         return;
  774.     }
  775.  
  776.     InsertVisFldInfo(Lay, vf);        /* link it */
  777.  
  778.     if (Redraw(Pr, Lay) < 0) {        /* Oops, this didn't fit on screen */
  779.         DisplayBeep(Scr);
  780.         DeleteVisFldInfo(RemoveVisFldInfo(Lay, vf));
  781.         Redraw(Pr, Lay);
  782.     }
  783.     if (!Crsr.vf) Crsr.vf = Lay->FirstVisFldInfo;    /* Move cursor on-track */
  784. }
  785.  
  786. /**********************************************************************/
  787. /*                           IDCMP handler                            */
  788. /**********************************************************************/
  789.  
  790. static int DesignWindowIDCMP(struct Pro *Pr, struct Layout *Lay)
  791. {
  792.     struct IntuiMessage    *m;
  793.     struct MenuItem        *n;
  794.     int            (*func)(void);
  795.     struct Window *Win = Lay->Window;
  796.     ULONG signals, winsig, toolboxsig = 0;
  797.     BOOL running = TRUE;
  798.  
  799.     winsig = 1L << Win->UserPort->mp_SigBit;
  800.     if (ToolBox) toolboxsig = 1L << ToolBox->UserPort->mp_SigBit;
  801.  
  802.     for (;;) {
  803. //        WaitPort(Win->UserPort);
  804.         signals = Wait(winsig | toolboxsig);
  805.  
  806.         if (signals & winsig) {
  807.             while( m = GT_GetIMsg( Win->UserPort )) {
  808.  
  809.                 CopyMem(( char * )m, ( char * )&DB_Msg, (long)sizeof( struct IntuiMessage ));
  810.  
  811.                 GT_ReplyIMsg( m );
  812.                 
  813.                 switch ( DB_Msg.Class ) {
  814.                 
  815.                     case    IDCMP_REFRESHWINDOW:
  816.                         GT_BeginRefresh(Win);
  817.                         GT_EndRefresh(Win, TRUE );
  818.                         break;
  819.  
  820.                     case    IDCMP_CLOSEWINDOW:
  821.                         return 0;
  822.                         break;
  823.  
  824.                     case    IDCMP_NEWSIZE:
  825. //    //                    printf("IDCMP_NEWSIZE\n");
  826.                         if (!(Win->Flags & WFLG_ZOOMED)) Redraw(Pr, Lay);
  827.                         break;
  828.  
  829.                     case    IDCMP_VANILLAKEY:
  830. //    //                    printf("IDCMP_VANILLAKEY\n");
  831.                         running = VanillaKey(Pr, Lay);
  832.                         if (running) return running;
  833.                         break;
  834.  
  835.                     case    IDCMP_RAWKEY:
  836. //    //                    printf("IDCMP_RAWKEY\n");
  837.                         running = RawKey(Pr, Lay);
  838.                         break;
  839.  
  840.                     case    IDCMP_MOUSEMOVE:
  841.                         {
  842.                             if (Sizing) {
  843.                                 Selected->Pos.Width = DB_Msg.MouseX - Selected->Pos.XOffset;
  844.                                 FLOOR(Selected->Pos.Width, FontX+STRGADFRAMESWIDTH);
  845.                                 SelectVisFld(Lay, Selected);    /* Update rubberband */
  846.                                 break;
  847.                             }
  848.                             else if (DragCnt) {
  849.                                 if (DragCnt++ == DRAGTRESHOLD) {
  850.                                     ChangePointer(Win, MovePointer);
  851.                                     Forbid();
  852.                                     Win->Flags |= WFLG_RMBTRAP;
  853.                                     Permit();
  854.                                 }
  855.                                 FollowMouse(Lay, DB_Msg.MouseX, DB_Msg.MouseY);
  856.                             }
  857.                             else if (SizeHit(VisFldHit(Lay, DB_Msg.MouseX, DB_Msg.MouseY), DB_Msg.MouseX))
  858.                                 ChangePointer(Win, LRPointer);
  859.                             else RestorePointer(Win);
  860.                         }
  861. //                        printf("IDCMP_MOUSEMOVE\n");
  862.                         break;
  863.  
  864.                     case IDCMP_MOUSEBUTTONS:
  865.                         if (DB_Msg.Code == SELECTDOWN) {
  866.                             running = MouseButtons(Pr, Lay);
  867.                         }
  868.                         else if (DB_Msg.Code == SELECTUP) {
  869.                             if (Win->Flags & WFLG_RMBTRAP) {    /* Enable menu button again */
  870.                                 Forbid();
  871.                                 Win->Flags &= ~WFLG_RMBTRAP;
  872.                                 Permit();
  873.                             }
  874.                             if (DragCnt >= DRAGTRESHOLD) {
  875.                                 RestorePointer(Win);
  876.                                 if (Crsr.vf != Selected) {        /* Move it */
  877.                                     SaveUndo(Lay);
  878.                                     InsertVisFldInfo(Lay, RemoveVisFldInfo(Lay, Selected));
  879.                                     Redraw(Pr, Lay);
  880.                                 }
  881.                             }
  882.                             else if (Sizing) {
  883.                                 Sizing = FALSE;
  884.                                 SaveUndo(Lay);
  885.                                 Selected->VisLen = (Selected->Pos.Width+(FontX+1)/2-STRGADFRAMESWIDTH)/FontX;
  886.                                 WriteVisTags(Selected);    /* Update RFF tags in vf */
  887.                                 Redraw(Pr, Lay);
  888.                             }
  889.                             DragCnt = 0;
  890.                         }
  891.                         else if (DB_Msg.Code == MENUUP) { /* Cancel */
  892.                             if (Win->Flags & WFLG_RMBTRAP) {    /* Enable menu button again */
  893.                                 Forbid();
  894.                                 Win->Flags &= ~WFLG_RMBTRAP;
  895.                                 Permit();
  896.                             }
  897.  
  898.                             if (DragCnt) {    /* Cancel dragging */
  899.                                 DragCnt = 0;
  900.                                 RestorePointer(Win);
  901.                             }
  902.                             else if (Sizing) {    /* Cancel sizechange */
  903.                                 Sizing = FALSE;
  904.                                 Redraw(Pr, Lay);
  905.                             }
  906.                         }
  907.                         break;
  908.                         
  909.                     case IDCMP_MENUPICK:
  910.                         while( DB_Msg.Code != MENUNULL ) {
  911.                             n = ItemAddress( Win->MenuStrip, DB_Msg.Code );
  912.                             func = (int (*)(void))(GTMENUITEM_USERDATA( n ));
  913.                             running = func();
  914.                             if (running) return running;    /* The window has been closed! */
  915.                             DB_Msg.Code = n->NextSelect;
  916.                         }
  917.                         break;
  918.                 }
  919.             }
  920.         }    /* winsig signals */
  921.  
  922.         if (signals & toolboxsig) {
  923.             while( m = GT_GetIMsg( ToolBox->UserPort )) {
  924.  
  925.                 CopyMem(( char * )m, ( char * )&DB_Msg, (long)sizeof( struct IntuiMessage ));
  926.  
  927.                 GT_ReplyIMsg( m );
  928.                 
  929.                 switch ( DB_Msg.Class ) {
  930.                     case IDCMP_GADGETUP:
  931. //                        printf("Gadget up\n");
  932.                         ActivateWindow(Win);
  933.                         ToolBoxClicked(Pr, Lay, ((struct Gadget *)DB_Msg.IAddress)->GadgetID);
  934.                         break;
  935.                 }
  936.             }
  937.         } /* toolbox signals */
  938.     }
  939.  
  940.  
  941.     return( running );
  942. }
  943.  
  944.  
  945. static int DoOpenDesignWindow(struct Pro *Pr, struct Layout *Lay, WORD ww, WORD wh)
  946. {
  947.     /* Does the actual opening (in DESIGN_MODE) */
  948.     WORD leftedge, topedge;
  949.  
  950.     /* Position window nicely */
  951.     if (LastLeftEdge == -1) {    /* No previous window to use */
  952.         leftedge = (Scr->Width - ww) >> 1;    /* Middle */
  953.         topedge = (Scr->Height-wh) >> 1;        /* Middle */
  954.     }
  955.     else {
  956.         leftedge = LastLeftEdge;
  957.         topedge = LastTopEdge;
  958.     }
  959.  
  960.     /* We create this menu every time we enter view design */
  961.     if ( ! ( DesignMenus = CreateMenus( DesignNewMenu, TAG_DONE )))
  962.         return( 3L );
  963.  
  964.     LayoutMenus( DesignMenus, VisualInfo, GTMN_NewLookMenus, TRUE, TAG_DONE );
  965.  
  966.  
  967.     if ( ! ( Lay->Window = OpenWindowTags( NULL,
  968.                 WA_Left,       leftedge,
  969.                 WA_Top,        topedge,
  970.                 WA_Width,    ww,
  971.                 WA_Height,    wh,
  972.                 WA_IDCMP,    IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE|IDCMP_NEWSIZE|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  973.                 WA_Flags,    WFLG_REPORTMOUSE|WFLG_NEWLOOKMENUS|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  974.                 WA_Gadgets,    Lay->GList,
  975.                 WA_Title,    "Move the cursor and design!",
  976.                 WA_ScreenTitle,    "db v" VERSION_NUMBER "  View design",
  977.                 WA_PubScreen,    Scr,
  978.                 WA_Zoom,    DB_Zoom,
  979. //                WA_MenuHelp, TRUE,
  980.                 TAG_DONE )))
  981.     return WIN_ERR;
  982.  
  983.     SetMenuStrip( Lay->Window, DesignMenus );
  984.     GT_RefreshWindow( Lay->Window, NULL);
  985.  
  986.     /* Now detach all gadgets from the window as this is the design mode */
  987.     RemoveGList(Lay->Window, Lay->GList, -1);
  988.  
  989.     /* We delete the gadgets and just leave the imagery */
  990.     DeleteAllGadgets(Lay, DESIGN_MODE);
  991.  
  992.     /* For IDCMP handling used in this file */
  993.     WinSig = 1L << Lay->Window->UserPort->mp_SigBit;
  994.  
  995.     return 0;
  996. }
  997.  
  998. void FillClip(struct VisFldInfo *vf)
  999. {
  1000.     if (Clip) {
  1001.         DeleteVisFldInfo(Clip);
  1002.     }
  1003.     Clip = vf;
  1004. }
  1005.  
  1006. /**********************************************************************/
  1007. /*                        Interface functions                         */
  1008. /**********************************************************************/
  1009.  
  1010. void Design(struct Pro *Pr, struct Layout *Lay)
  1011. {
  1012.     /* This is the main function in the design system */
  1013.     WORD ww, wh;
  1014.     WORD x,y;
  1015.  
  1016. /*    ww = Lay->Window->Width;
  1017.     wh = Lay->Window->Height;
  1018. */
  1019.     CloseLayWin(Pr, Lay);
  1020.     CalcAllPos(Pr, Lay, &ww, &wh); // Shouldn't be nessesary as we reopen the window
  1021.     CreateAllGadgets(Pr, Lay, ww, wh, DESIGN_MODE);
  1022.     DoOpenDesignWindow(Pr, Lay, ww, wh);
  1023.  
  1024.     InitCursor(Lay, &Crsr);
  1025.     Selected = NULL;
  1026.     GetCursorPosition(&Crsr, &x, &y);
  1027.     DisplayCursor(Lay->Window->RPort, x, y);
  1028.  
  1029.     ToolBox = OpenToolBox(Lay->Window);    /* "Parent" window */
  1030.  
  1031.     DesignWindowIDCMP(Pr, Lay);
  1032.  
  1033.     DeleteUndo(Lay);
  1034.     FillClip(NULL);
  1035.  
  1036.     CloseDesignWin(Lay);
  1037.     if (ToolBox) {
  1038.         CloseToolBox(ToolBox);
  1039.         ToolBox = NULL;
  1040.     }
  1041.     OpenLayWin(Pr, Lay);
  1042.     UpdateWindow(Pr);
  1043.     UpdateDragBar(Pr);
  1044.  
  1045.     /* Back to db run-mode */
  1046. }
  1047.  
  1048.  
  1049.  
  1050. /**********************************************************************/
  1051. /*                        GadToolBox handlers                         */
  1052. /**********************************************************************/
  1053.  
  1054.  
  1055. int LISTClicked( void )
  1056. {
  1057.     /* routine when gadget "Object list" is clicked. */
  1058.     return 0;
  1059. }
  1060.  
  1061. int TOPClicked( void )
  1062. {
  1063.     /* routine when gadget "Top" is clicked. */
  1064.     return 0;
  1065. }
  1066.  
  1067. int UPClicked( void )
  1068. {
  1069.     /* routine when gadget "Up" is clicked. */
  1070.     return 0;
  1071. }
  1072.  
  1073. int DOWNClicked( void )
  1074. {
  1075.     /* routine when gadget "Down" is clicked. */
  1076.     return 0;
  1077. }
  1078.  
  1079. int BOTTOMClicked( void )
  1080. {
  1081.     /* routine when gadget "Bottom" is clicked. */
  1082.     return 0;
  1083. }
  1084.  
  1085. int NEWClicked( void )
  1086. {
  1087.     /* routine when gadget "_New..." is clicked. */
  1088.     return 0;
  1089. }
  1090.  
  1091. int EDITClicked( void )
  1092. {
  1093.     /* routine when gadget "_Edit..." is clicked. */
  1094.     return 0;
  1095. }
  1096.  
  1097. int COPYClicked( void )
  1098. {
  1099.     /* routine when gadget "Co_py" is clicked. */
  1100.     return 0;
  1101. }
  1102.  
  1103. int REMOVEClicked( void )
  1104. {
  1105.     /* routine when gadget "Remove" is clicked. */
  1106.     return 0;
  1107. }
  1108.  
  1109. int USEClicked( void )
  1110. {
  1111.     /* routine when gadget "_Use" is clicked. */
  1112.     return 0;
  1113. }
  1114.  
  1115. int CANCELClicked( void )
  1116. {
  1117.     /* routine when gadget "_Cancel" is clicked. */
  1118.     return 0;
  1119. }
  1120.  
  1121. int TAG_VALUEClicked( void )
  1122. {
  1123.     /* routine when gadget "_Value" is clicked. */
  1124.     return 0;
  1125. }
  1126.  
  1127. int TAG_IDClicked( void )
  1128. {
  1129.     /* routine when gadget "_ID" is clicked. */
  1130.     return 0;
  1131. }
  1132.  
  1133. int TAG_OKClicked( void )
  1134. {
  1135.     /* routine when gadget "_Ok" is clicked. */
  1136.     return 0;
  1137. }
  1138.  
  1139. int TAG_CANCELClicked( void )
  1140. {
  1141.     /* routine when gadget "_Cancel" is clicked. */
  1142.     return 0;
  1143. }
  1144.  
  1145. int NAME_NAMEClicked( void )
  1146. {
  1147.     /* routine when gadget "_Name" is clicked. */
  1148.     return 0;
  1149. }
  1150.  
  1151. int NAME_OKClicked( void )
  1152. {
  1153.     /* routine when gadget "_Ok" is clicked. */
  1154.     return 0;
  1155. }
  1156.  
  1157. int NAME_CANCELClicked( void )
  1158. {
  1159.     /* routine when gadget "_Cancel" is clicked. */
  1160.     return 0;
  1161. }
  1162.  
  1163. int FIELD_NAMEClicked( void )
  1164. {
  1165.     /* routine when gadget "_Name" is clicked. */
  1166.     return 0;
  1167. }
  1168.  
  1169. int FIELD_MAXLENClicked( void )
  1170. {
  1171.     /* routine when gadget "Max _length" is clicked. */
  1172.     return 0;
  1173. }
  1174.  
  1175. int FIELD_OKClicked( void )
  1176. {
  1177.     /* routine when gadget "_Ok" is clicked. */
  1178.     return 0;
  1179. }
  1180.  
  1181. int FIELD_CANCELClicked( void )
  1182. {
  1183.     /* routine when gadget "_Cancel" is clicked. */
  1184.     return 0;
  1185. }
  1186.  
  1187. int FIELD_MOREClicked( void )
  1188. {
  1189.     /* routine when gadget "_More..." is clicked. */
  1190.     return 0;
  1191. }
  1192.  
  1193. int VIS_NAMEClicked( void )
  1194. {
  1195.     /* routine when gadget "_Name" is clicked. */
  1196.     return 0;
  1197. }
  1198.  
  1199. int VIS_SIZEClicked( void )
  1200. {
  1201.     /* routine when gadget "Si_ze" is clicked. */
  1202.     return 0;
  1203. }
  1204.  
  1205. int VIS_OKClicked( void )
  1206. {
  1207.     /* routine when gadget "_Ok" is clicked. */
  1208.     return RET_OK;
  1209. }
  1210.  
  1211. int VIS_CANCELClicked( void )
  1212. {
  1213.     /* routine when gadget "_Cancel" is clicked. */
  1214.     return RET_CANCEL;
  1215. }
  1216.  
  1217. int VIS_MOREClicked( void )
  1218. {
  1219.     /* routine when gadget "_More..." is clicked. */
  1220.     return 0;
  1221. }
  1222.  
  1223. int VIS_SELECTClicked( void )
  1224. {
  1225.     /* routine when gadget "..." is clicked. */
  1226.     Select *s;
  1227.     struct FldInfo *f;
  1228.     BOOL again = TRUE;
  1229.  
  1230.  
  1231.     if (!(s = NewSelect())) {
  1232.         DisplayBeep(Scr);
  1233.         return 0;
  1234.     }
  1235.     for (f = CurrentPro->FirstFldInfo; f; f = f->Next)
  1236.         AddStringLast(s, f->Name);
  1237.  
  1238.     s->SelIndex = Vf->Offset;
  1239.     OpenSelect(s, VisWnd, "Select field", NULL);
  1240.     while (again) {
  1241.         WaitPort(s->SelWnd->UserPort);
  1242.         switch(HandleSelectIDCMP(s)) {
  1243.             case SEL_SELECT :
  1244.                 break;
  1245.             case SEL_OK :
  1246.                 Vf->Offset = s->SelIndex;
  1247.                 GT_SetGadgetAttrs(VisGadgets[GD_VIS_FIELD], VisWnd, NULL,
  1248.                     GTTX_Text, SelectedString(s),
  1249.                     TAG_END);
  1250.                 again = FALSE;
  1251.                 break;
  1252.             case SEL_CANCEL :
  1253.                 again = FALSE;
  1254.                 break;
  1255.             case SEL_HELP :
  1256.                 break;
  1257.         }
  1258.     }
  1259.  
  1260. /*    CloseSelect(s);
  1261.     RemoveAllStrings(s);
  1262. */
  1263.     DeleteSelect(s);
  1264.  
  1265.     return 0;
  1266. }
  1267.  
  1268. int MainCloseWindow( void )
  1269. {
  1270.     /* routine for "IDCMP_CLOSEWINDOW". */
  1271.     return 1;    /* i.e. Leave this mode */
  1272. }
  1273.  
  1274. int MainVanillaKey( void )
  1275. {
  1276.     /* routine for "IDCMP_VANILLAKEY". */
  1277.     return 0;
  1278. }
  1279.  
  1280. int MainRawKey( void )
  1281. {
  1282.     /* routine for "IDCMP_RAWKEY". */
  1283.     return 0;
  1284. }
  1285.  
  1286. int TagCloseWindow( void )
  1287. {
  1288.     /* routine for "IDCMP_CLOSEWINDOW". */
  1289.     return 0;
  1290. }
  1291.  
  1292. int TagVanillaKey( void )
  1293. {
  1294.     /* routine for "IDCMP_VANILLAKEY". */
  1295.     return 0;
  1296. }
  1297.  
  1298. int NameCloseWindow( void )
  1299. {
  1300.     /* routine for "IDCMP_CLOSEWINDOW". */
  1301.     return 0;
  1302. }
  1303.  
  1304. int NameVanillaKey( void )
  1305. {
  1306.     /* routine for "IDCMP_VANILLAKEY". */
  1307.     return 0;
  1308. }
  1309.  
  1310. int FieldCloseWindow( void )
  1311. {
  1312.     /* routine for "IDCMP_CLOSEWINDOW". */
  1313.     return 0;
  1314. }
  1315.  
  1316. int FieldVanillaKey( void )
  1317. {
  1318.     /* routine for "IDCMP_VANILLAKEY". */
  1319.     return 0;
  1320. }
  1321.  
  1322. int VisCloseWindow( void )
  1323. {
  1324.     /* routine for "IDCMP_CLOSEWINDOW". */
  1325.     return RET_CANCEL;
  1326. }
  1327.  
  1328. int VisVanillaKey( void )
  1329. {
  1330.     /* routine for "IDCMP_VANILLAKEY". */
  1331.  
  1332.     switch (ToUpper(VisMsg.Code)) {
  1333.     case 'N':
  1334.         ActivateGadget(VisGadgets[GD_VIS_NAME], VisWnd, NULL);
  1335.         break;
  1336.         
  1337.     case 'Z':
  1338.         ActivateGadget(VisGadgets[GD_VIS_SIZE], VisWnd, NULL);
  1339.         break;
  1340.         
  1341.     case 'O':
  1342.     case '\r':
  1343.         return VIS_OKClicked();
  1344.         break;
  1345.         
  1346.     case 'C':
  1347.     case VANILLA_ESC:
  1348.         return VIS_CANCELClicked();
  1349.         break;
  1350.     }
  1351.     return 0;
  1352. }
  1353.  
  1354. int DesignPROJECT_ABOUT( void )
  1355. {
  1356.     /* routine when (sub)item "About view design..." is selected. */
  1357.     EasyRequest(CurrentPro->CurrentLayout->Window, &ES_ViewDesignHelp, NULL);
  1358.     return 0;
  1359. }
  1360.  
  1361. int DesignPROJECT_EXIT( void )
  1362. {
  1363.     /* routine when (sub)item "Exit view design" is selected. */
  1364.     return 1;    /* Leave View design */
  1365. }
  1366.  
  1367. int DesignEDIT_UNDO( void )
  1368. {
  1369.     /* routine when (sub)item "Undo" is selected. */
  1370.  
  1371.     if (PerformUndo(CurrentPro->CurrentLayout))
  1372.         Redraw(CurrentPro, CurrentPro->CurrentLayout);
  1373.     else DisplayBeep(Scr);
  1374.     return 0;
  1375. }
  1376.  
  1377. int DesignEDIT_CUT( void )
  1378. {
  1379.     /* routine when (sub)item "Cut" is selected. */
  1380.  
  1381.     if (Selected) {
  1382.         SaveUndo(CurrentPro->CurrentLayout);
  1383.         FillClip(RemoveVisFldInfo(CurrentPro->CurrentLayout, Selected));
  1384.         OnMenu(CurrentPro->CurrentLayout->Window, FULLMENUNUM(1,4,NOSUB)); /* Edit->Paste */
  1385.         Redraw(CurrentPro, CurrentPro->CurrentLayout);
  1386.     }
  1387.     return 0;
  1388. }
  1389.  
  1390. int DesignEDIT_COPY( void )
  1391. {
  1392.     /* routine when (sub)item "Copy" is selected. */
  1393.  
  1394.     if (Selected) {
  1395.         FillClip(CopyVisFldInfo(Selected));
  1396.         OnMenu(CurrentPro->CurrentLayout->Window, FULLMENUNUM(1,4,NOSUB)); /* Edit->Paste */
  1397.     }
  1398.     return 0;
  1399. }
  1400.  
  1401. int DesignEDIT_PASTE( void )
  1402. {
  1403.     /* routine when (sub)item "Paste" is selected. */
  1404.  
  1405.     SaveUndo(CurrentPro->CurrentLayout);
  1406.     InsertVisFldInfo(CurrentPro->CurrentLayout, CopyVisFldInfo(Clip));
  1407.     Redraw(CurrentPro, CurrentPro->CurrentLayout);
  1408.     return 0;
  1409. }
  1410.