/* SCCS-info %W% %E% */ /*--------------------------------------------------------------------*/ /* */ /* VCG : Visualization of Compiler Graphs */ /* -------------------------------------- */ /* */ /* file: X11devcl.c */ /* version: 1.00.00 */ /* creation: 9.4.93 */ /* author: I. Lemke (...-Version 0.99.99) */ /* G. Sander (Version 1.00.00-...) */ /* Universitaet des Saarlandes, 66041 Saarbruecken */ /* ESPRIT Project #5399 Compare */ /* description: Device driver for X11, Hide Class Dialog Box */ /* status: in work */ /* */ /*--------------------------------------------------------------------*/ #ifndef lint static char *id_string="$Id: X11devcl.c,v 1.9 1995/02/08 11:11:14 sander Exp $"; #endif /* * Copyright (C) 1993-2005 Saarland University * * This program and documentation is free software; you can redistribute * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * The software is available per anonymous ftp at ftp.cs.uni-sb.de. * Contact sander@cs.uni-sb.de for additional information. */ /* * $Log: X11devcl.c,v $ * Revision 1.9 1995/02/08 11:11:14 sander * Distribution version 1.3. * * Revision 1.8 1994/12/23 18:12:45 sander * Manhatten layout added. * Option interface cleared. * infobox behaviour improved. * First version of fisheye (carthesian). * Options Noedge and nonode. * * Revision 1.7 1994/11/23 14:50:47 sander * Drawing speed improved by removing some superfluous XSyncs. * * Revision 1.6 1994/08/09 14:00:40 sander * XLoadQuery-Font-Debugging removed again. * * Revision 1.5 1994/08/03 13:58:44 sander * Horizontal order mechanism changed. * Attribute horizontal_order for edges added. * * Revision 1.4 1994/08/02 15:36:12 sander * Minor change. Some debugmessages added. * * Revision 1.3 1994/06/07 14:09:59 sander * Splines implemented. * HP-UX, Linux, AIX, Sun-Os, IRIX compatibility tested. * The tool is now ready to be distributed. * * Revision 1.2 1994/05/16 08:56:03 sander * shape attribute (boxes, rhombs, ellipses, triangles) added. * * Revision 1.1 1994/05/05 08:20:30 sander * Initial revision * */ /************************************************************************ * Device driver for X11: Hide Classes Dialog Box * ---------------------------------------------- * * This module contains the management of the dialog box that appears * if we want to hide or expose edge classes. * * This file provides the following functions: * ------------------------------------------ * * x11_init_classes_dialog(rd,rs) initialize the dialogbox. * x11_destroy_classes_dialog(rd,rs) destroys the dialogbox. * * x11_print_classes_dialog() * * This function opens the dialog box that allows to hide or expose * edge classes. On successful exit (Okay-button), the classes are * updated, such that they become valid at the next relayout. * On every exit, the dialog box is closed. The function returns 1, * if the Okay-button was pressed. * ************************************************************************/ #include #include #include #include "globals.h" #ifdef X11 #include #include #include #include #include #include #include #include "main.h" #include "options.h" #include "grammar.h" #include "alloc.h" #include "folding.h" #include "X11devcl.h" /*--------------------------------------------------------------------*/ #undef EVENT_DEBUG /* Types * ===== */ /* Selection points: On/Off-Buttons, Radio/Buttons, Touch Buttons * Radio-Buttons are On-buttons, i.e. they don't go off, if we retouch * them. Further, all radio buttons of one section have the same glob. */ typedef struct gs_selection_point { Window w; /* Window of the point */ char *t; /* Text of the point */ int x; /* X-Position */ int y; /* Y-Position */ int is; /* actual value */ int sel; /* value, if the point is selected */ int *glob; /* corresponding global value */ char key; /* key action */ } GS_SEL_POINT; /* Prototypes * ========== */ /* from X11dev.c */ char *class_num _PP((int n)); void gs_exit _PP((int x)); void do_gblExpose _PP((XEvent *eventp)); void do_gblConfigureNotify _PP((XEvent *eventp)); static void allocateDialogBox _PP((void)); static Window allocate_selection_point _PP((int x,int y)); static Window allocate_button _PP((int x,int y)); static Window allocate_general_button _PP((int x,int y,int w,int h)); static void allocate_class_table _PP((void)); static void draw_dialog_box _PP((void)); static void draw_text _PP(( int x, int y, char *m)); static void draw_underl_text _PP(( int x, int y, char *m)); static void draw_dialog_point _PP((Window w, int color)); static void normalize_point _PP((Window w)); #ifdef EVENT_DEBUG static void prologue _PP((XEvent *eventp, char *event_name)); #else #define prologue(a,b) #endif static void dialog_main_loop _PP((void)); static void do_KeyPress _PP((XEvent *eventp)); static void do_ButtonPress _PP((XEvent *eventp)); static void do_EnterNotify _PP((XEvent *eventp)); static void do_LeaveNotify _PP((XEvent *eventp)); static void do_Expose _PP((XEvent *eventp)); static void do_ConfigureNotify _PP((XEvent *eventp)); /* Positions and Sizes * =================== */ /* Size of the dialog box */ int dial_width; int dial_height; /* Size of a normal point */ #define POINT_W 10 /* Size of a normal button */ #define BUTTON_W 120 /* Variables * ========= */ /* Dialog handling: On success (i.e. Okay-Button), success becomes 1 */ static int dialog_notready = 1; static int dialog_success = 0; /* On-Off-points are buttons that switch their state if we select them */ int max_onoff_points; static GS_SEL_POINT *on_off_point = NULL; /* Root displays */ static Display *root_display; /* Root display */ static int root_screen; /* and its screen number */ /* Windows */ static Window dialog_window; static Window okay_button; static Window cancel_button; /* Mouse Buttons */ #define G_MOUSE_LEFT 1 #define G_MOUSE_RIGHT 3 /* the panel font */ extern char Xfontname[512]; static XFontStruct *dialog_font = NULL; /* Flag wheter the dialog_box is initialized */ static int dialog_box_there = 0; /*--------------------------------------------------------------------*/ /* Dialog box initialization and entry points */ /*--------------------------------------------------------------------*/ /* Initialize the dialog box * ------------------------- * This is done once at the beginning. */ #ifdef ANSI_C void x11_init_classes_dialog(Display *rd, int rs) #else void x11_init_classes_dialog(rd, rs) Display *rd; int rs; #endif { debugmessage("x11_init_classes_dialog",""); if (dialog_box_there) return; root_display = rd; root_screen = rs; debugmessage("before XLoadQueryFont",""); dialog_font = XLoadQueryFont(root_display,Xfontname); debugmessage("after XLoadQueryFont",""); if (!dialog_font) { Fatal_error("Font not found. Please use option -font",""); } allocateDialogBox(); dialog_box_there = 1; debugmessage("end of x11_init_classes_dialog",""); } /* Destroy the dialog box * ---------------------- * This is done once on ExitDevice. */ #ifdef ANSI_C void x11_destroy_classes_dialog(Display *rd, int rs) #else void x11_destroy_classes_dialog(rd, rs) Display *rd; int rs; #endif { if (!dialog_box_there) return; XDestroyWindow(root_display,dialog_window); dialog_box_there = 0; } /* Allocate the Dialog Box * ----------------------- * Scrollbar-Thumbs are returned in last_tmb; */ static Window last_tmb; static char x11_win_label[1024]; #ifdef ANSI_C static void allocateDialogBox(void) #else static void allocateDialogBox() #endif { Window rret1, rret2; XSetWindowAttributes attr; unsigned long mask = 0L; int i; unsigned int j; int xpos, ypos; XSizeHints hints; debugmessage("allocateDialogBox",""); /* select for all events */ attr.event_mask = KeyPressMask | ButtonPressMask | EnterWindowMask | ExposureMask | StructureNotifyMask | SubstructureNotifyMask | FocusChangeMask | OwnerGrabButtonMask; attr.background_pixel = XWhitePixel(root_display,root_screen); attr.border_pixel = XBlackPixel(root_display,root_screen); mask |= (CWBackPixel | CWBorderPixel | CWEventMask); (void)XQueryPointer(root_display,RootWindow(root_display, root_screen), &rret1, &rret2,&xpos, &ypos, &i, &i, &j); allocate_class_table(); dialog_window = XCreateWindow(root_display, RootWindow(root_display, root_screen), xpos, ypos, dial_width, dial_height, Xmyborderwidth, (int)CopyFromParent, InputOutput, (Visual *)CopyFromParent, mask, &attr); hints.flags = PPosition; hints.x = xpos; hints.y = ypos; strcpy(x11_win_label, "VCG "); strcat(x11_win_label, Dataname); strcat(x11_win_label, " Edge Classes"); XStoreName(root_display, dialog_window, x11_win_label); XSetNormalHints(root_display, dialog_window, &hints); XDefineCursor(root_display,dialog_window, XCreateFontCursor(root_display,XC_left_ptr)); for (i=0; ixpos1) xpos1 = len; } for (i=1; ixpos2) xpos2 = len; } for (i=2; ixpos3) xpos3 = len; } if (xpos1+xpos2+xpos3+110<220+2*BUTTON_W) { diff = 220+2*BUTTON_W - (xpos1+xpos2+xpos3+110); mpart = (220+2*BUTTON_W-110)/3; add1 = mpart - xpos1; if (add1<0) add1 = 0; add2 = mpart - xpos2; if (add2<0) add2 = 0; add3 = mpart - xpos3; if (add3<0) add3 = 0; xpos1 += (diff * add1)/(add1+add2+add3); xpos2 += (diff * add2)/(add1+add2+add3); xpos3 += (diff * add3)/(add1+add2+add3); } for (i=0; iserial, e->send_event ? "Yes" : "No", e->window); } #endif /* EVENT_DEBUG */ /* Keypress Events * --------------- */ #ifdef ANSI_C static void do_KeyPress (XEvent *eventp) #else static void do_KeyPress (eventp) XEvent *eventp; #endif { XKeyEvent *e = (XKeyEvent *) eventp; KeySym ks; int nbytes, i; char str[256+1]; char lk, uk; nbytes = XLookupString (e, str, 256, &ks, NULL); if (nbytes < 0) nbytes = 0; if (nbytes > 256) nbytes = 256; str[nbytes] = '\0'; if (nbytes==1) { /* No operation on ' ' */ if (str[0]==' ') return; for (i=0; iwindow; act_scroll_window = w; for (i=0; iwindow; for (i=0; iwindow; for (i=0; iwindow==dialog_window) { if ((e->width>12)&&(e->height>12)&&(!box_exposed)) { draw_dialog_box(); box_exposed = 1; } } else box_exposed = 0; do_gblExpose(eventp); } /* Resize or move a window * ----------------------- */ #ifdef ANSI_C static void do_ConfigureNotify (XEvent *eventp) #else static void do_ConfigureNotify (eventp) XEvent *eventp; #endif { XConfigureEvent *e = (XConfigureEvent *) eventp; if (e->window==dialog_window) { XResizeWindow(root_display, dialog_window, dial_width, dial_height); draw_dialog_box(); } else do_gblConfigureNotify(eventp); } /*--------------------------------------------------------------------*/ #endif /* X11 */