home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / ui / helper.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-24  |  10.8 KB  |  386 lines

  1. /**
  2.    GRAB Graph Layout and Browser System
  3.  
  4.    Copyright (c) 1987, 1988, 1989 Stanford University
  5.    Copyright (c) 1989, Tera Computer Company
  6.  **/
  7.  
  8.   /**
  9.      This file I found somewhere in the InterViews 2.5 bin source files 
  10.      A few names have been changed.  It implements the help screens.
  11.    **/
  12.  
  13. #include "helper.h"
  14. #include "textedit.h"
  15. #include "liststring.h"
  16. #include "istring.h"
  17. #include <InterViews/box.h>
  18. #include <InterViews/border.h>
  19. #include <InterViews/button.h>
  20. #include <InterViews/canvas.h>
  21. #include <InterViews/event.h>
  22. #include <InterViews/font.h>
  23. #include <InterViews/frame.h>
  24. #include <InterViews/glue.h>
  25. #include <InterViews/graphic.h>
  26. #include <InterViews/interactor.h>
  27. #include <InterViews/message.h>
  28. #include <InterViews/painter.h>
  29. #include <InterViews/sensor.h>
  30. #include <InterViews/shape.h>
  31. #include <InterViews/world.h>
  32.  
  33. // TextBox creates TextEdit to display its text
  34. // and stores its underlying Interactor.  TextBox won't delete the
  35. // TextEdit so its derived classes can put them in boxes which will
  36. // delete them when the boxes are deleted.
  37.  
  38. TextBox::TextBox (Interactor* u, StringList* s, Graphic* g) 
  39. {
  40.     SetCanvasType(CanvasSaveUnder); // speed up expose redrawing if possible
  41.     input = allEvents;
  42.     input->Reference();
  43.     tedit = new TextEdit(s, g);
  44.     underlying = u;
  45. }
  46.  
  47. TextBox::~TextBox()
  48. {
  49.     delete tedit;
  50. }
  51.  
  52. // SetUnderlying sets the underlying Interactor over which the
  53. // TextBox will pop up itself.
  54.  
  55. void TextBox::SetUnderlying (Interactor* u) 
  56. {
  57.     underlying = u;
  58. }
  59.  
  60. // PopUp pops up the TextBox centered over the underlying
  61. // Interactor's canvas.
  62.  
  63. void TextBox::PopUp () 
  64. {
  65.     World* world = underlying->GetWorld();
  66.     Coord x, y;
  67.     underlying->Align(Center, 0, 0, x, y);
  68.     underlying->GetRelative(x, y, world);
  69.     world->InsertTransient(this, underlying, x, y, Center);
  70. }
  71.  
  72. // Disappear removes the TextBox.  Since the user should see
  73. // warnings only once, Disappear clears the warning's text so the next
  74. // PopUp won't display it.
  75.  
  76. void TextBox::Disappear () 
  77. {
  78.     Parent()->Remove(this);
  79.     Sync();
  80. }
  81.  
  82. // Pager creates its button states and initializes its view.
  83.  
  84. Pager::Pager (Interactor* u, StringList* s, Graphic* g) : (u, s, g) 
  85. {
  86.     SetClassName("Pager");
  87.  
  88.     VBox* vbox = new VBox();
  89.     vbox->Insert(tedit);
  90.     vbox->Insert(new HBorder);
  91.     StringList* s2 = new StringList();
  92.     s2->Append(new StringNode (
  93.         " Left Button for Previous Page, Right Button For Next Page"));
  94.     s2->Append(new StringNode (
  95.         "                    Middle Button To Quit"));
  96.     TextEdit* instr = new TextEdit(s2, g);
  97.     vbox->Insert(instr);
  98.     Insert(new Frame(vbox));
  99. }
  100.  
  101. // Display pops up the Pager, lets the user choose the next or the 
  102. // previous page, removes the Pager, and returns the choice.
  103.  
  104. char Pager::Display () 
  105. {
  106.     PopUp();
  107.  
  108.     int previous = false;
  109.     int next = false;
  110.     int exit = false;
  111.  
  112.     while (!previous && !next && !exit) 
  113.     {
  114.     Event e;
  115.     Read(e);
  116.  
  117.     if (e.eventType == UpEvent ) 
  118.     {
  119.         switch (e.button) 
  120.         {
  121.             case LEFTMOUSE:
  122.             previous = true;
  123.             break;
  124.             case RIGHTMOUSE:
  125.             next = true;
  126.             break;
  127.             case MIDDLEMOUSE:
  128.             exit = true;
  129.             break;
  130.             default:
  131.             break;
  132.         }
  133.     } 
  134.     }
  135.  
  136.     Disappear();
  137.  
  138.     char answer = 'n';
  139.     answer = previous ? 'p' : answer;
  140.     answer = exit ? 'e' : answer;
  141.     return answer;
  142. }
  143.  
  144.  
  145. // Reconfig pads Pager's shape to make the view look less crowded.
  146.  
  147. void Pager::Reconfig () 
  148. {
  149.     TextBox::Reconfig();
  150.     Font* font = output->GetFont();
  151.     shape->width += 4 * font->Width("mmmm");
  152.     shape->height += 4 * font->Height();
  153. }
  154.  
  155. static char page1[][maxline] = 
  156. {
  157.     " ",
  158.     " BROWSE, CHANGE, AND EDIT MODES",
  159.     " ",
  160.     " There are three major modes of operation in Xgrab:  browse mode, ",
  161.     " change mode, and edit mode.  The current mode is indicated by an X in",
  162.     " the box to the left of the mode name in the buttons area.",
  163.     " When you are in browse or change mode, you cannot make any major",
  164.     " changes to the graph being viewed.  When you are in edit mode, you can.",
  165.     " The mouse buttons have different semantics when you are in different",
  166.     " modes.  The next help page will explain the semantics of the mouse when",
  167.     " in browse mode, the page after that will explain the semantics of the",
  168.     " mouse when in change mode, and the pages after that will explain the",
  169.     " semantics of the mouse when in edit mode.",
  170.     ""
  171. };
  172.  
  173. static char page2[][maxline] = 
  174. {
  175.     " ",
  176.     " BROWSE MODE:  LEFT MOUSE BUTTON",
  177.     " ",
  178.     " Placing the cursor over a node and clicking the left mouse button will",
  179.     " change the color and brush attributes of the incoming and/or outgoing",
  180.     " edges of that node, according to the values in the built-in attributes",
  181.     " display.  Whether in or out edges (or both or neither) are affected",
  182.     " depends on the values of the 'change in edges' and 'change out edges",
  183.     " options.",
  184.     " ",
  185.     " ",
  186.     " BROWSE MODE:  MIDDLE MOUSE BUTTON",
  187.     "  ",
  188.     " Placing the cursor over a node and clicking the middle mouse button will",
  189.     " reset the color and brush attributes of the incoming and/or outgoing",
  190.     " edges of that node to their default values, according to the values in",
  191.     " the built-in attributes display.  Whether in or out edges (or both or",
  192.     " neither) are affected depends on the values of the 'change in edges'",
  193.     " and 'change out edges' options.",
  194.     "  ",
  195.     "  ",
  196.     " BROWSE MODE:  RIGHT MOUSE BUTTON",
  197.     "  ",
  198.     " Placing the cursor over a node or edge and clicking the right mouse",
  199.     " button will display the user-defined attributes of the node or edge in",
  200.     " a box in the upper left corner.  The 'graph attributes' menu controls",
  201.     " which attributes are displayed.  If the right mouse button is clicked",
  202.     " over empty space, the previous node/edge attributes display disappears.",
  203.     ""
  204. };
  205.  
  206. static char page3[][maxline] = 
  207. {
  208.     " ",
  209.     " CHANGE MODE:  LEFT MOUSE BUTTON",
  210.     " ",
  211.     " Placing the cursor over a node or edge and clicking the left mouse",
  212.     " button will change the color and brush (and shape, for nodes) attributes",
  213.     " of that node/edge, according to the values in the built-in attributes",
  214.     " display.",
  215.     " ",
  216.     " ",
  217.     " CHANGE MODE:  MIDDLE MOUSE BUTTON",
  218.     "  ",
  219.     " Placing the cursor over a node or edge and clicking the middle mouse",
  220.     " button will reset the color and brush (and shape, for nodes) attributes",
  221.     " of that node/edge to their default values, according to the values in",
  222.     " the built-in attributes display.",
  223.     "  ",
  224.     "  ",
  225.     " CHANGE MODE:  RIGHT MOUSE BUTTON",
  226.     "  ",
  227.     " Placing the cursor over a node or edge and clicking the right mouse",
  228.     " button will cycle through the color and brush (and shape, for nodes)",
  229.     " attributes for that node/edge, according to the values in the built-in",
  230.     " attributes display.",
  231.     ""
  232. };
  233.  
  234. static char page4[][maxline] = 
  235. {
  236.     " ",
  237.     " EDIT MODE:  LEFT MOUSE BUTTON",
  238.     "  ",
  239.     " The left mouse button is used to insert nodes and edges into the",
  240.     " graph.  A node can be inserted into the graph by clicking the left",
  241.     " mouse button when the cursor is not over an existing node.  After",
  242.     " the button is clicked, there will be a prompt on the status line",
  243.     " asking you to type in the name of the new node.  After you type in",
  244.     " the name of the new node and hit <return>, the new node will be",
  245.     " drawn.  If you wish to cancel this command, place the cursor over",
  246.     " the cancel button in the dialogbox and click a mouse button",
  247.     "  ",
  248.     " An edge can be inserted into the graph by pressing the left mouse",
  249.     " button when the cursor is over an existing node, holding the button",
  250.     " down until you have moved the cursor to the destination node, and",
  251.     " then releasing the button.  If you release the button when the cursor",
  252.     " is not over a node, a dummy node will be created at the position where",
  253.     " you released the button.  You can proceed to drop more dummy nodes or",
  254.     " to terminate the edge by clicking the button when the cursor is over",
  255.     " a non-dummy node.",
  256.     ""
  257. };
  258.  
  259. static char page5[][maxline] = 
  260. {
  261.     " ",
  262.     " EDIT MODE:  MIDDLE MOUSE BUTTON",
  263.     "  ",
  264.     " The middle mouse button is used to move nodes.  Press and hold the",
  265.     " middle button while the cursor is over a node, and you can \"drag\"",
  266.     " the node around in the window.  Releasing the middle button will",
  267.     " place the node at its new position.",
  268.     "  ",
  269.     "  ",
  270.     " EDIT MODE:  RIGHT MOUSE BUTTON",
  271.     "  ",
  272.     " The right mouse button is used to delete nodes and edges.  A node",
  273.     " can be deleted by clicking the right mouse button when the cursor is",
  274.     " positioned on a node.  An edge can be deleted by clicking the right",
  275.     " mouse button when the cursor is positioned on an edge.",
  276.     ""
  277. };
  278.  
  279. static char page6[][maxline] = 
  280. {
  281.     " ",
  282.     " ",
  283.     " See the document \"How To Use Xgrab\" for more",
  284.     " information.",
  285.     " ",
  286.     " ",
  287.     ""
  288. };
  289.  
  290. Helper::Helper(Interactor *i, Graphic *g) 
  291. {
  292.     helppagers[0] = MakePager(1, i, g);   
  293.     helppagers[1] = MakePager(2, i, g);   
  294.     helppagers[2] = MakePager(3, i, g);   
  295.     helppagers[3] = MakePager(4, i, g);   
  296.     helppagers[4] = MakePager(5, i, g);   
  297.     helppagers[5] = MakePager(6, i, g);   
  298.     currpage = 0;
  299. }
  300.  
  301. static const char exitchar = 'e';
  302.  
  303. void Helper::DoHelp()
  304. {
  305.     char c;
  306.  
  307.     currpage = 0;
  308.  
  309.     do
  310.     {
  311.     c = (helppagers[currpage])->Display();
  312.  
  313.     switch (c)
  314.     {
  315.         case 'p':
  316.             if (currpage >= 1) 
  317.            /* if there is a page to go back to */
  318.         {
  319.             currpage--;
  320.         }
  321.         break;
  322.         case 'n':
  323.         currpage++;
  324.         if (currpage >= maxhelppage)
  325.         {
  326.             c = exitchar;
  327.         }
  328.         break;
  329.         default:
  330.         break;
  331.     }
  332.     } while (c != exitchar);
  333. }
  334.  
  335. Pager* Helper::MakePager(int num, Interactor* i, Graphic *g)
  336. {
  337.     int j;
  338.     StringList* s = new StringList();
  339.  
  340.       /** 
  341.          Very stupid, but I can't get my string arrays passed the way I'd
  342.          like, so it will have to do.
  343.        **/
  344.     switch (num) 
  345.     {
  346.     case 1:
  347.         for (j = 0; strcmp(page1[j], ""); j++)
  348.             {
  349.                 s->Append(new StringNode(page1[j]));
  350.             }
  351.         break;
  352.     case 2:
  353.         for (j = 0; strcmp(page2[j], ""); j++)
  354.             {
  355.                 s->Append(new StringNode(page2[j]));
  356.             }
  357.         break;
  358.     case 3:
  359.         for (j = 0; strcmp(page3[j], ""); j++)
  360.             {
  361.                 s->Append(new StringNode(page3[j]));
  362.             }
  363.         break;
  364.     case 4:
  365.         for (j = 0; strcmp(page4[j], ""); j++)
  366.             {
  367.                 s->Append(new StringNode(page4[j]));
  368.             }
  369.         break;
  370.     case 5:
  371.         for (j = 0; strcmp(page5[j], ""); j++)
  372.             {
  373.                 s->Append(new StringNode(page5[j]));
  374.             }
  375.         break;
  376.     case 6:
  377.         for (j = 0; strcmp(page6[j], ""); j++)
  378.             {
  379.                 s->Append(new StringNode(page6[j]));
  380.             }
  381.         break;
  382.     }
  383.  
  384.     return new Pager(i, s, g);
  385. }
  386.