home *** CD-ROM | disk | FTP | other *** search
- /*
- * FIG : Facility for Interactive Generation of figures
- *
- * Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
- * January 1985.
- * 1st revision : Aug 1985.
- *
- * %W% %G%
- */
- #include "fig.h"
- #include "resources.h"
- #include "const.h"
- #include "paintop.h"
-
- /***************** import global variables and routines *******************/
-
- extern int cur_command;
- extern int errno;
- extern int action_on; /* tracker.c */
- extern int magnet_mode;
-
- extern int CANVAS_WIDTH, CANVAS_HEIGHT;
- extern null_proc();
- extern (*canvas_kbd_proc)();
- extern (*canvas_locmove_proc)();
- extern (*canvas_leftbut_proc)();
- extern (*canvas_middlebut_proc)();
- extern (*canvas_rightbut_proc)();
- extern null_proc();
- extern set_popupmenu();
-
-
- /*********************** local variables and routines ************************/
-
- static canvas_selected();
- static canvas_sighandler();
-
- static Arg canvas_args[] =
- {
- /* 0 */ { XtNlabel, (XtArgVal)"" },
- /* 1 */ { XtNwidth, (XtArgVal) 0 },
- /* 2 */ { XtNheight, (XtArgVal) 0 },
- /* 3 */ { XtNfromHoriz, (XtArgVal)NULL },
- /* 4 */ { XtNhorizDistance, (XtArgVal) 0 },
- /* 5 */ { XtNfromVert, (XtArgVal)NULL },
- /* 6 */ { XtNvertDistance, (XtArgVal) 0 },
- /* 7 */ { XtNtop, (XtArgVal)XtChainTop },
- /* 8 */ { XtNleft, (XtArgVal)XtChainLeft },
- };
-
- static void
-
- canvas_exposed(tool, event, params, nparams)
- TOOL tool;
- INPUTEVENT *event;
- String *params;
- Cardinal *nparams;
- {
- if (((XExposeEvent *)event)->count > 0)
- return;
- redisplay_canvas();
- redisplay_rulers();
- }
-
- static void
-
- set_pos(tool, event, params, nparams)
- TOOL tool;
- XEvent *event;
- String *params;
- Cardinal *nparams;
- {
- int x, y; /* fixed 3/12/89 from patch 3 */
- Window w;
- extern TOOL menu;
-
- XtGeometryResult result;
- XtWidgetGeometry request, reply_return;
- Dimension ww, hh, dw, dh;
-
- XTranslateCoordinates(tool_d, canvas_win, XDefaultRootWindow(tool_d),
- event->xbutton.x, event->xbutton.y, &x, &y, &w);
- request.request_mode = CWWidth | CWHeight;
- result = XtQueryGeometry((Widget)menu, &request, &reply_return);
-
- ww = reply_return.width;
- hh = reply_return.height;
- dw = DisplayWidth(tool_d, tool_sn);
- dh = DisplayHeight(tool_d, tool_sn);
- x = (x + ww > dw + 10) ? dw - ww + 10 : x;
- y = (y + hh > dh + 10) ? dh - hh + 10 : y;
-
- XtMoveWidget(menu, x-10, y-10);
- XWarpPointer(tool_d, None, DefaultRootWindow(tool_d),
- 0, 0, 0, 0, x, y);
- set_temp_cursor(&arrow_cursor); /* set cursor to arrow for popup menu */
- }
-
- XtActionsRec canvas_actions[] =
- {
- { "Event", (XtActionProc)canvas_selected },
- { "Expose", (XtActionProc)canvas_exposed },
- { "set_pos", (XtActionProc)set_pos },
- };
-
- static String canvas_translations =
- "<Motion>:Event()\n\
- <Btn1Down>:Event()\n\
- <Btn2Down>:Event()\n\
- <Btn3Down>:set_pos(popup_menu)MenuPopup(popup_menu)\n\
- <Key>:Event()\n\
- <Expose>:Expose()\n";
-
- static Arg canvas_color_args[] = {
- { XtNforeground, (XtArgVal) &x_fg_color.pixel },
- { XtNbackground, (XtArgVal) &x_bg_color.pixel },
- };
-
- init_canvas(tool)
- TOOL tool;
- {
- XColor fixcolors[2];
-
- canvas_args[1].value = CANVAS_WIDTH;
- canvas_args[2].value = CANVAS_HEIGHT;
- canvas_args[3].value = (XtArgVal)panel_sw; /* to the right of the panel */
- canvas_args[5].value = (XtArgVal)topruler_sw; /* below the top ruler */
- canvas_sw = XtCreateWidget("canvas", labelWidgetClass, tool,
- canvas_args, XtNumber(canvas_args));
- XtGetValues(canvas_sw, canvas_color_args, XtNumber(canvas_color_args));
-
- /* get the RGB values for recolor cursor use -- may want to have
- cursor color resource */
- fixcolors[0] = x_fg_color;
- fixcolors[1] = x_bg_color;
- XQueryColors(tool_d, DefaultColormapOfScreen(tool_s), fixcolors, 2);
- x_fg_color = fixcolors[0];
- x_bg_color = fixcolors[1];
-
- /* now fix the global GC */
- XSetState(tool_d, gc, x_fg_color.pixel, x_bg_color.pixel, GXcopy,
- AllPlanes);
-
- /* and recolor the cursors */
- recolor_cursors();
-
- canvas_leftbut_proc = null_proc;
- canvas_middlebut_proc = null_proc;
- canvas_rightbut_proc = null_proc;
- canvas_kbd_proc = canvas_locmove_proc = null_proc;
- XtAddActions(canvas_actions, XtNumber(canvas_actions));
- XtOverrideTranslations(canvas_sw,
- XtParseTranslationTable(canvas_translations));
- return (1);
- }
-
- setup_canvas()
- {
- canvas_rightbut_proc = set_popupmenu;
- canvas_win = XtWindow(canvas_sw);
- init_grid();
- }
-
- static
-
- canvas_selected(tool, event, params, nparams)
- TOOL tool;
- INPUTEVENT *event;
- String *params;
- Cardinal *nparams;
- {
- register int x, y, t;
- char buf[1];
- XButtonPressedEvent *be = (XButtonPressedEvent *)event;
- XKeyPressedEvent *ke = (XKeyPressedEvent *)event;
-
- x = event->x;
- y = event->y;
- if (magnet_mode)
- {
- x = ((t = x % 5) < 3) ? x - t - 1 : x + 5 - t - 1;
- y = ((t = y % 5) < 3) ? y - t - 1 : y + 5 - t - 1;
- }
- switch (event->type)
- {
- case MotionNotify:
- {
- Window rw, cw;
- static int sx = -10000, sy = -10000;
- int rx, ry, cx, cy;
- unsigned int mask;
-
- XQueryPointer(event->display, event->window,
- &rw, &cw,
- &rx, &ry,
- &cx, &cy,
- &mask);
- if(cx == sx && cy == sy) break;
- x = sx = cx;
- y = sy = cy;
- }
- set_rulermark(x, y);
- (*canvas_locmove_proc)(x, y);
- break;
- case ButtonPress:
- if (be->button & Button1)
- (*canvas_leftbut_proc)(x, y);
- else if (be->button & Button2)
- (*canvas_middlebut_proc)(x, y);
- break;
- case KeyPress:
- if (XLookupString(ke, buf, sizeof(buf), NULL, NULL) > 0)
- (*canvas_kbd_proc)((unsigned char)buf[0]);
- break;
- }
- }
-
- clear_canvas()
- {
- XClearArea(tool_d, canvas_win, 0, 0, 0, 0, False);
- }
-