#include #include #include /* Added X Windows Toolkit #includes */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* Enclosure and scroll region handles */ static Widget drawingPane; static Widget dPane; static Widget modeButton; static Widget nodeNameLabel; static Widget shapeNameLabel; static Widget fileNameLabel; static Widget filterNameLabel; static Widget msgNameLabel; static Widget msg1NameLabel; /* Widget handles for file name/filter name edit text items */ static Widget errorNameText; static Widget fileNameText; static Widget filterNameText; static Widget nodeNameText; static Widget shapeNameText; static Widget sizeNameText; static Widget nullModeButton; static Widget insertModeButton; static Widget deleteModeButton; static Widget moveModeButton; /* Macro definitions */ #define TRUE 1 #define FALSE 0 #define MARGIN 8 /* A margin of MARGIN pixels exists around the graph */ #define FILENAMELEN 60 #define FILENAMEWMDTH FILENAMELEN*6 #define MAXERROR 400 #define INX 230 #define INY 57 /* Strings to hold the file and filter names */ char fileNameString[FILENAMELEN+2]; char filterNameString[FILENAMELEN+2]; char shapeNameString[FILENAMELEN+2]; char errorNameString[MAXERROR]; #include "ged.h" #include "embed_ops.h" #include "view_hand.h" #include "drawing.h" #include "tool_static.h" extern void change_mode_to(); static XrmOptionDescRec options[] = { {"-hspace", "*Box.hSpace", XrmoptionSepArg, NULL}, {"-vspace", "*Box.vSpace", XrmoptionSepArg, NULL}, }; /* all for init_box1 */ void Quit ( Widget w, caddr_t client_data, caddr_t call_data ) { exit ( 0 ); } static void init_box1 ( Widget wbox1 ) { static Widget box1, box2; static Widget quitButton; static Widget readButton; static Widget writeButton; static Widget filterButton; static Widget clearButton; static Widget redrawButton; static Widget nameButton; Arg args[2]; box1 = XtCreateManagedWidget ("butencl", boxWidgetClass, wbox1, NULL, ZERO ); quitButton = XtCreateManagedWidget("Quit", commandWidgetClass, box1, NULL, 0 ); XtAddCallback(quitButton, XtNcallback, Quit, 0); readButton = XtCreateManagedWidget("Read", commandWidgetClass, box1, NULL, 0 ); XtAddCallback(readButton, XtNcallback, read_file, 0); writeButton = XtCreateManagedWidget("Write", commandWidgetClass, box1, NULL, 0 ); XtAddCallback(writeButton, XtNcallback, write_file, 0); filterButton = XtCreateManagedWidget("Filter", commandWidgetClass, box1, NULL, 0 ); XtAddCallback(filterButton, XtNcallback, do_filter, 0); clearButton = XtCreateManagedWidget("Clear", commandWidgetClass, box1, NULL, 0 ); XtAddCallback(clearButton, XtNcallback, deleteall, 0); redrawButton = XtCreateManagedWidget("Redraw", commandWidgetClass, box1, NULL, 0 ); XtAddCallback(redrawButton, XtNcallback, drawgraph, 0); nameButton = XtCreateManagedWidget("Name", commandWidgetClass, box1, NULL, 0 ); XtAddCallback(nameButton, XtNcallback, name_points, 0); /* XtSetArg(args[0], XtNorientation, (XtArgVal) XawOrientHorizontal); box2 = XtCreateManagedWidget ("butenc2", formWidgetClass, box1, NULL, ZERO ); */ msgNameLabel = XtCreateManagedWidget ("filterlabel", labelWidgetClass, box1, msgNameLabelArgs, XtNumber(msgNameLabelArgs) ); nullModeButton = XtCreateManagedWidget("Null", toggleWidgetClass, box1, nullModeButtonArgs, XtNumber(nullModeButtonArgs) ); insertModeButton = XtCreateManagedWidget("Insert", toggleWidgetClass, box1, insertModeButtonArgs, XtNumber(insertModeButtonArgs) ); deleteModeButton = XtCreateManagedWidget("Delete", toggleWidgetClass, box1, deleteModeButtonArgs, XtNumber(deleteModeButtonArgs) ); moveModeButton = XtCreateManagedWidget("Move", toggleWidgetClass, box1, moveModeButtonArgs, XtNumber(moveModeButtonArgs) ); XtVaSetValues(nullModeButton, XtNstate, TRUE, NULL); } /* ---------------------------- drawing area --------------------------- */ static void init_draw_area(wbox) Widget wbox; { static Widget drawingAreaBox; static Widget drawingArea; drawingAreaBox = XtCreateManagedWidget ("drawingbox", formWidgetClass, wbox, NULL, ZERO ); /* Create a viewport (scrolling area) to be used to hold the drawing */ drawingArea = XtCreateManagedWidget("drawing", viewportWidgetClass, drawingAreaBox, drawingAreaArgs, XtNumber(drawingAreaArgs) ); /* Create a generic drawing canvas within the viewport */ drawingPane = XtCreateManagedWidget("pane", drawingWidgetClass, drawingArea, drawingPaneArgs, XtNumber(drawingPaneArgs) ); } init_box0(wbox1) Widget wbox1; { static Widget box0; box0 = XtCreateManagedWidget ("butencl", boxWidgetClass, wbox1, NULL, ZERO ); fileNameLabel = XtCreateManagedWidget ("filelabel", labelWidgetClass, box0, fileNameLabelArgs, XtNumber(fileNameLabelArgs) ); fileNameText = XtCreateManagedWidget ("filename", asciiTextWidgetClass, box0, fileNameTextArgs, XtNumber(fileNameTextArgs) ); filterNameLabel = XtCreateManagedWidget ("filelabel", labelWidgetClass, box0, filterNameLabelArgs, XtNumber(filterNameLabelArgs) ); filterNameText = XtCreateManagedWidget ("filename", asciiTextWidgetClass, box0, filterNameTextArgs, XtNumber(filterNameTextArgs) ); } static void msgbox (drawingSection) Widget drawingSection; { static Widget msgNameTextBox; msgNameTextBox = XtCreateManagedWidget ("errorsbox", formWidgetClass, drawingSection, NULL, ZERO); errorNameText = XtCreateManagedWidget ("error", asciiTextWidgetClass, msgNameTextBox, errorNameTextArgs, XtNumber(errorNameTextArgs) ); } /* ------------------------*/ /* init canvas control */ /* ------------------------*/ static void init_canvas (toplevel) Widget toplevel; { static Widget vhandlew; static char ca[10]; vhandlew = XtCreateManagedWidget ("section", panedWidgetClass, toplevel, NULL, 0 ); init_box0(vhandlew); init_box1(vhandlew); init_draw_area(vhandlew); msgbox(vhandlew); } void init_views(argc, argv) int argc; char **argv; { Widget toplevel, topwidget; Arg args[2]; /* Top Level initialization - The top level is just a box with things in it */ toplevel = XtInitialize( "Test", "Menu-Editor", options, XtNumber(options), &argc, argv ); /* Set argument for buttons etc, to allow parent to resize them */ XtSetArg(args[1], XtNallowShellResize, TRUE); XtSetValues (toplevel, args, TWO); /* Create the top level form widget */ /* This widget encloses all other widgets and controls their placing */ init_canvas (toplevel); /* Realize the window structure */ XtRealizeWidget (toplevel); XtMainLoop(); } /* --------------------- buttons (mouse) action --------------------- */ static void canvas_keys(w, closure, event) Widget w; caddr_t closure; XEvent *event; { printf("It is a key action\n"); } static void canvas_button1down(w, closure, event) Widget w; caddr_t closure; XEvent *event; { int x=event->xbutton.x-MARGIN, y=event->xbutton.y-MARGIN; /* Left mouse button pressed */ if (mode () == M_MODE) move_down (x, y); else pnt (x, y); } static void canvas_button1up(w, closure, event) Widget w; caddr_t closure; XEvent *event; { int x=event->xbutton.x-MARGIN, y=event->xbutton.y-MARGIN; /* Left mouse button released */ if (mode () == M_MODE) move_up (x, y); } static void canvas_button2up(w, closure, event) Widget w; caddr_t closure; XEvent *event; { } static void canvas_button1motion(w, closure, event) Widget w; caddr_t closure; XEvent *event; { /* Dragging */ } static void canvas_button2motion(w, closure, event) Widget w; caddr_t closure; XEvent *event; { /* Dragging */ } static void canvas_button3down(w, closure, event) Widget w; caddr_t closure; XEvent *event; { int x=event->xbutton.x-MARGIN, y=event->xbutton.y-MARGIN; /* Right mouse button pressed */ if (mode () == M_MODE) move_down (x, y); } static void canvas_button3up(w, closure, event) Widget w; caddr_t closure; XEvent *event; { int x=event->xbutton.x-MARGIN, y=event->xbutton.y-MARGIN; /* Right mouse button released */ if (mode () == M_MODE) move_up (x, y); } static void canvas_button2down(w, closure, event) Widget w; caddr_t closure; XEvent *event; { int x=event->xbutton.x-MARGIN, y=event->xbutton.y-MARGIN; line (x, y); } static void canvas_button3motion(w, closure, event) Widget w; caddr_t closure; XEvent *event; { int x=event->xbutton.x-MARGIN, y=event->xbutton.y-MARGIN; /* Dragging */ if (mode () == M_MODE) drag (x, y); } void read_file (w, closure, call_data ) Widget w; caddr_t closure, call_data; { msg("read file action"); cgoread ( fileNameString ); } void read_append_file (w, closure, call_data ) Widget w; caddr_t closure, call_data; { cgoread_app ( fileNameString ); drawgraph (); } void write_file (w, closure, call_data ) Widget w; caddr_t closure, call_data; { msg("write file action"); cgowrite ( fileNameString ); } void do_filter(w, closure, call_data ) Widget w; caddr_t closure, call_data; { msg("do filter action"); filter ( filterNameString ); } static void null_mode(w, closure, call_data ) Widget w; caddr_t closure, call_data; { XtVaSetValues(nullModeButton, XtNstate, TRUE, NULL); XtVaSetValues(insertModeButton, XtNstate, FALSE, NULL); XtVaSetValues(deleteModeButton, XtNstate, FALSE, NULL); XtVaSetValues(moveModeButton, XtNstate, FALSE, NULL); change_mode_to(N_MODE); } static void insert_mode(w, closure, call_data ) Widget w; caddr_t closure, call_data; { XtVaSetValues(nullModeButton, XtNstate, FALSE, NULL); XtVaSetValues(insertModeButton, XtNstate, TRUE, NULL); XtVaSetValues(deleteModeButton, XtNstate, FALSE, NULL); XtVaSetValues(moveModeButton, XtNstate, FALSE, NULL); change_mode_to(I_MODE); } static void delete_mode(w, closure, call_data ) Widget w; caddr_t closure, call_data; { XtVaSetValues(nullModeButton, XtNstate, FALSE, NULL); XtVaSetValues(insertModeButton, XtNstate, FALSE, NULL); XtVaSetValues(deleteModeButton, XtNstate, TRUE, NULL); XtVaSetValues(moveModeButton, XtNstate, FALSE, NULL); change_mode_to(D_MODE); } static void move_mode(w, closure, call_data ) Widget w; caddr_t closure, call_data; { XtVaSetValues(nullModeButton, XtNstate, FALSE, NULL); XtVaSetValues(insertModeButton, XtNstate, FALSE, NULL); XtVaSetValues(deleteModeButton, XtNstate, FALSE, NULL); XtVaSetValues(moveModeButton, XtNstate, TRUE, NULL); change_mode_to(M_MODE); } /* ------------------- drawing funtions FALSE-draw, TRUE-rub; -------------------- */ void draw_marker ( int xco, int yco ) { DrawingFillOval( drawingPane, xco-8+MARGIN, yco-8+MARGIN, 16, 16, FALSE ); } void rub_marker (xco, yco) int xco, yco; { DrawingFillOval( drawingPane, xco-8+MARGIN-1, yco-8+MARGIN-1, 18, 18, TRUE ); } void invert_marker (xco, yco) int xco, yco; { DrawingFillOval( drawingPane, xco-8+MARGIN-1, yco-8+MARGIN-1, 18, 18, TRUE ); DrawingDrawOval( drawingPane, xco-8+MARGIN, yco-8+MARGIN, 16, 16, FALSE ); } /* Update procedure - used by other modules to avoid having to do a complete */ /* redraw of the screen for each update */ void draw_update() { DrawingUpdate(drawingPane); } /*--------------------------------------------------------------------------- * draw_line -- draw a line between two points *--------------------------------------------------------------------------- */ void draw_line(f_xco, f_yco, s_xco, s_yco) int f_xco, f_yco, s_xco, s_yco; { DrawingDrawLine(drawingPane, f_xco+MARGIN, f_yco+MARGIN, s_xco+MARGIN, s_yco+MARGIN, FALSE ); } /*--------------------------------------------------------------------------- * rub_line -- erase a line between two points *--------------------------------------------------------------------------- */ void rub_line(f_xco, f_yco, s_xco, s_yco) int f_xco, f_yco, s_xco, s_yco; { DrawingDrawLine(drawingPane, f_xco+MARGIN, f_yco+MARGIN, s_xco+MARGIN, s_yco+MARGIN, TRUE ); } void clear_canvas ( void ) { DrawingClear(drawingPane); DrawingUpdate(drawingPane); } static void give_help ( void ) { msg("No help available"); } /*--------------------------------------------------------------------------- * name_points -- name the points on the graph *--------------------------------------------------------------------------- */ static void name_points ( void ) { point *pptr; int i; char number[30]; for (i = 0; i < GSQRD; i++) { pptr = hash[i]; while (pptr->nextp != NULL) { int x_dist; pptr = pptr->nextp; (void) sprintf (number, "%d", pptr->name); x_dist = 4 * strlen (number); DrawingWriteText( drawingPane, pptr->X, pptr->Y, number ); } } DrawingUpdate( drawingPane ); } /*--------------------------------------------------------------------------- * drawgraph -- draw the graph *--------------------------------------------------------------------------- */ void drawgraph ( void ) { void draw_marker (), draw_line (), invert_marker (); point *pptr, *tptr; cpoint *cptr; int i; DrawingClear(drawingPane); for (i = 0; i < GSQRD; i++) { pptr = hash[i]; while (pptr->nextp != NULL) { pptr = pptr->nextp; draw_marker(pptr->X, pptr->Y); cptr = pptr->cplist; while (cptr->nextcp != NULL) { cptr = cptr->nextcp; tptr = getxy (hash, cptr->pname); if (tptr != NULL) draw_line(pptr->X, pptr->Y, tptr->X, tptr->Y); } } } if (fep_selected ()) { pptr = first_end_point (); invert_marker (pptr->X, pptr->Y); } DrawingUpdate(drawingPane); } void msg ( char *message ) { strcpy ( errorNameString, message ); XtVaSetValues ( errorNameText, XtNstring, errorNameString, NULL ); }