home *** CD-ROM | disk | FTP | other *** search
- /**
- GRAB Graph Layout and Browser System
-
- Copyright (c) 1987, 1988, 1989 Stanford University
- Copyright (c) 1989, Tera Computer Company
- **/
-
- /**
- This file I found somewhere in the InterViews 2.5 bin source files
- A few names have been changed. It implements the help screens.
- **/
-
- #include "helper.h"
- #include "textedit.h"
- #include "liststring.h"
- #include "istring.h"
- #include <InterViews/box.h>
- #include <InterViews/border.h>
- #include <InterViews/button.h>
- #include <InterViews/canvas.h>
- #include <InterViews/event.h>
- #include <InterViews/font.h>
- #include <InterViews/frame.h>
- #include <InterViews/glue.h>
- #include <InterViews/graphic.h>
- #include <InterViews/interactor.h>
- #include <InterViews/message.h>
- #include <InterViews/painter.h>
- #include <InterViews/sensor.h>
- #include <InterViews/shape.h>
- #include <InterViews/world.h>
-
- // TextBox creates TextEdit to display its text
- // and stores its underlying Interactor. TextBox won't delete the
- // TextEdit so its derived classes can put them in boxes which will
- // delete them when the boxes are deleted.
-
- TextBox::TextBox (Interactor* u, StringList* s, Graphic* g)
- {
- SetCanvasType(CanvasSaveUnder); // speed up expose redrawing if possible
- input = allEvents;
- input->Reference();
- tedit = new TextEdit(s, g);
- underlying = u;
- }
-
- TextBox::~TextBox()
- {
- delete tedit;
- }
-
- // SetUnderlying sets the underlying Interactor over which the
- // TextBox will pop up itself.
-
- void TextBox::SetUnderlying (Interactor* u)
- {
- underlying = u;
- }
-
- // PopUp pops up the TextBox centered over the underlying
- // Interactor's canvas.
-
- void TextBox::PopUp ()
- {
- World* world = underlying->GetWorld();
- Coord x, y;
- underlying->Align(Center, 0, 0, x, y);
- underlying->GetRelative(x, y, world);
- world->InsertTransient(this, underlying, x, y, Center);
- }
-
- // Disappear removes the TextBox. Since the user should see
- // warnings only once, Disappear clears the warning's text so the next
- // PopUp won't display it.
-
- void TextBox::Disappear ()
- {
- Parent()->Remove(this);
- Sync();
- }
-
- // Pager creates its button states and initializes its view.
-
- Pager::Pager (Interactor* u, StringList* s, Graphic* g) : (u, s, g)
- {
- SetClassName("Pager");
-
- VBox* vbox = new VBox();
- vbox->Insert(tedit);
- vbox->Insert(new HBorder);
- StringList* s2 = new StringList();
- s2->Append(new StringNode (
- " Left Button for Previous Page, Right Button For Next Page"));
- s2->Append(new StringNode (
- " Middle Button To Quit"));
- TextEdit* instr = new TextEdit(s2, g);
- vbox->Insert(instr);
- Insert(new Frame(vbox));
- }
-
- // Display pops up the Pager, lets the user choose the next or the
- // previous page, removes the Pager, and returns the choice.
-
- char Pager::Display ()
- {
- PopUp();
-
- int previous = false;
- int next = false;
- int exit = false;
-
- while (!previous && !next && !exit)
- {
- Event e;
- Read(e);
-
- if (e.eventType == UpEvent )
- {
- switch (e.button)
- {
- case LEFTMOUSE:
- previous = true;
- break;
- case RIGHTMOUSE:
- next = true;
- break;
- case MIDDLEMOUSE:
- exit = true;
- break;
- default:
- break;
- }
- }
- }
-
- Disappear();
-
- char answer = 'n';
- answer = previous ? 'p' : answer;
- answer = exit ? 'e' : answer;
- return answer;
- }
-
-
- // Reconfig pads Pager's shape to make the view look less crowded.
-
- void Pager::Reconfig ()
- {
- TextBox::Reconfig();
- Font* font = output->GetFont();
- shape->width += 4 * font->Width("mmmm");
- shape->height += 4 * font->Height();
- }
-
- static char page1[][maxline] =
- {
- " ",
- " BROWSE, CHANGE, AND EDIT MODES",
- " ",
- " There are three major modes of operation in Xgrab: browse mode, ",
- " change mode, and edit mode. The current mode is indicated by an X in",
- " the box to the left of the mode name in the buttons area.",
- " When you are in browse or change mode, you cannot make any major",
- " changes to the graph being viewed. When you are in edit mode, you can.",
- " The mouse buttons have different semantics when you are in different",
- " modes. The next help page will explain the semantics of the mouse when",
- " in browse mode, the page after that will explain the semantics of the",
- " mouse when in change mode, and the pages after that will explain the",
- " semantics of the mouse when in edit mode.",
- ""
- };
-
- static char page2[][maxline] =
- {
- " ",
- " BROWSE MODE: LEFT MOUSE BUTTON",
- " ",
- " Placing the cursor over a node and clicking the left mouse button will",
- " change the color and brush attributes of the incoming and/or outgoing",
- " edges of that node, according to the values in the built-in attributes",
- " display. Whether in or out edges (or both or neither) are affected",
- " depends on the values of the 'change in edges' and 'change out edges",
- " options.",
- " ",
- " ",
- " BROWSE MODE: MIDDLE MOUSE BUTTON",
- " ",
- " Placing the cursor over a node and clicking the middle mouse button will",
- " reset the color and brush attributes of the incoming and/or outgoing",
- " edges of that node to their default values, according to the values in",
- " the built-in attributes display. Whether in or out edges (or both or",
- " neither) are affected depends on the values of the 'change in edges'",
- " and 'change out edges' options.",
- " ",
- " ",
- " BROWSE MODE: RIGHT MOUSE BUTTON",
- " ",
- " Placing the cursor over a node or edge and clicking the right mouse",
- " button will display the user-defined attributes of the node or edge in",
- " a box in the upper left corner. The 'graph attributes' menu controls",
- " which attributes are displayed. If the right mouse button is clicked",
- " over empty space, the previous node/edge attributes display disappears.",
- ""
- };
-
- static char page3[][maxline] =
- {
- " ",
- " CHANGE MODE: LEFT MOUSE BUTTON",
- " ",
- " Placing the cursor over a node or edge and clicking the left mouse",
- " button will change the color and brush (and shape, for nodes) attributes",
- " of that node/edge, according to the values in the built-in attributes",
- " display.",
- " ",
- " ",
- " CHANGE MODE: MIDDLE MOUSE BUTTON",
- " ",
- " Placing the cursor over a node or edge and clicking the middle mouse",
- " button will reset the color and brush (and shape, for nodes) attributes",
- " of that node/edge to their default values, according to the values in",
- " the built-in attributes display.",
- " ",
- " ",
- " CHANGE MODE: RIGHT MOUSE BUTTON",
- " ",
- " Placing the cursor over a node or edge and clicking the right mouse",
- " button will cycle through the color and brush (and shape, for nodes)",
- " attributes for that node/edge, according to the values in the built-in",
- " attributes display.",
- ""
- };
-
- static char page4[][maxline] =
- {
- " ",
- " EDIT MODE: LEFT MOUSE BUTTON",
- " ",
- " The left mouse button is used to insert nodes and edges into the",
- " graph. A node can be inserted into the graph by clicking the left",
- " mouse button when the cursor is not over an existing node. After",
- " the button is clicked, there will be a prompt on the status line",
- " asking you to type in the name of the new node. After you type in",
- " the name of the new node and hit <return>, the new node will be",
- " drawn. If you wish to cancel this command, place the cursor over",
- " the cancel button in the dialogbox and click a mouse button",
- " ",
- " An edge can be inserted into the graph by pressing the left mouse",
- " button when the cursor is over an existing node, holding the button",
- " down until you have moved the cursor to the destination node, and",
- " then releasing the button. If you release the button when the cursor",
- " is not over a node, a dummy node will be created at the position where",
- " you released the button. You can proceed to drop more dummy nodes or",
- " to terminate the edge by clicking the button when the cursor is over",
- " a non-dummy node.",
- ""
- };
-
- static char page5[][maxline] =
- {
- " ",
- " EDIT MODE: MIDDLE MOUSE BUTTON",
- " ",
- " The middle mouse button is used to move nodes. Press and hold the",
- " middle button while the cursor is over a node, and you can \"drag\"",
- " the node around in the window. Releasing the middle button will",
- " place the node at its new position.",
- " ",
- " ",
- " EDIT MODE: RIGHT MOUSE BUTTON",
- " ",
- " The right mouse button is used to delete nodes and edges. A node",
- " can be deleted by clicking the right mouse button when the cursor is",
- " positioned on a node. An edge can be deleted by clicking the right",
- " mouse button when the cursor is positioned on an edge.",
- ""
- };
-
- static char page6[][maxline] =
- {
- " ",
- " ",
- " See the document \"How To Use Xgrab\" for more",
- " information.",
- " ",
- " ",
- ""
- };
-
- Helper::Helper(Interactor *i, Graphic *g)
- {
- helppagers[0] = MakePager(1, i, g);
- helppagers[1] = MakePager(2, i, g);
- helppagers[2] = MakePager(3, i, g);
- helppagers[3] = MakePager(4, i, g);
- helppagers[4] = MakePager(5, i, g);
- helppagers[5] = MakePager(6, i, g);
- currpage = 0;
- }
-
- static const char exitchar = 'e';
-
- void Helper::DoHelp()
- {
- char c;
-
- currpage = 0;
-
- do
- {
- c = (helppagers[currpage])->Display();
-
- switch (c)
- {
- case 'p':
- if (currpage >= 1)
- /* if there is a page to go back to */
- {
- currpage--;
- }
- break;
- case 'n':
- currpage++;
- if (currpage >= maxhelppage)
- {
- c = exitchar;
- }
- break;
- default:
- break;
- }
- } while (c != exitchar);
- }
-
- Pager* Helper::MakePager(int num, Interactor* i, Graphic *g)
- {
- int j;
- StringList* s = new StringList();
-
- /**
- Very stupid, but I can't get my string arrays passed the way I'd
- like, so it will have to do.
- **/
- switch (num)
- {
- case 1:
- for (j = 0; strcmp(page1[j], ""); j++)
- {
- s->Append(new StringNode(page1[j]));
- }
- break;
- case 2:
- for (j = 0; strcmp(page2[j], ""); j++)
- {
- s->Append(new StringNode(page2[j]));
- }
- break;
- case 3:
- for (j = 0; strcmp(page3[j], ""); j++)
- {
- s->Append(new StringNode(page3[j]));
- }
- break;
- case 4:
- for (j = 0; strcmp(page4[j], ""); j++)
- {
- s->Append(new StringNode(page4[j]));
- }
- break;
- case 5:
- for (j = 0; strcmp(page5[j], ""); j++)
- {
- s->Append(new StringNode(page5[j]));
- }
- break;
- case 6:
- for (j = 0; strcmp(page6[j], ""); j++)
- {
- s->Append(new StringNode(page6[j]));
- }
- break;
- }
-
- return new Pager(i, s, g);
- }
-