/* SCCS-info %W% %E% */ /*--------------------------------------------------------------------*/ /* */ /* VCG : Visualization of Compiler Graphs */ /* -------------------------------------- */ /* */ /* file: X11devvw.c */ /* version: 1.00.00 */ /* creation: 12.1.95 */ /* 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, View Dialog Box */ /* status: in work */ /* */ /*--------------------------------------------------------------------*/ #ifndef lint static char *id_string="$Id: X11devvw.c,v 1.2 1995/02/08 16:15: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: X11devvw.c,v $ * Revision 1.2 1995/02/08 16:15:14 sander * Small bug with K&R C solved. * * Revision 1.1 1995/02/08 11:11:14 sander * Initial revision * */ /************************************************************************ * Device driver for X11: View Dialog Box * -------------------------------------- * * This module contains the management of the dialog box that appears * if we want to change the view. * * This file provides the following functions: * ------------------------------------------ * * x11_init_view_dialog(rd,rs) initialize the dialogbox. * x11_destroy_view_dialog(rd,rs) destroys the dialogbox. * * x11_print_view_dialog() * * This function opens the dialog box that allows to change the * view parameters. On successful exit (Okay-button), the * view parameters are updated, such that they become valid * at the next draw_main. 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 "steps.h" #include "fisheye.h" #include "X11devvw.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; /* Horizontal integer scroll bars */ typedef struct gs_scroll_bar { Window ws; /* Window of the bar itself */ Window wt; /* Window of the scroll thumb */ Window wl; /* Window of the left toucher */ Window wr; /* Window of the left toucher */ char *t; /* Text of the scroll bar */ char *f; /* Format of the value */ int xt; /* X-Position of the text */ int xv; /* X-Position of the value */ int xb; /* X-Position of the bar */ int y; /* Y-Position */ int len; /* Length of scrollbar */ long is; /* actual value */ long *glob; /* corresponding global value */ #ifdef ANSI_C void (*rf)(int); /* read function */ void (*sf)(void); /* set function */ #else void (*rf)(); void (*sf)(); #endif } GS_SCROLL_BAR; /* Prototypes * ========== */ /* from X11dev.c */ void gs_exit _PP((int x)); void do_gblExpose _PP((XEvent *eventp)); void do_gblConfigureNotify _PP((XEvent *eventp)); void m_validate_fe _PP((void)); 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 Window allocate_scroll_bar _PP((int x,int y,int len)); 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 draw_sizes _PP((void)); 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_ButtonRelease _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)); static void do_MotionNotify _PP((XEvent *eventp)); static void do_apply _PP((void)); static void read_fishdistscrollbar _PP((int val)); static void set_fishdistscrollbar _PP((void)); /* Positions and Sizes * =================== */ /* Size of the dialog box */ #define DIAL_W 580 #define DIAL_H 170 /* Size of a normal point */ #define POINT_W 10 /* Size of a normal button */ #define BUTTON_W 116 /* Sizes of a scrollbar and its thumb */ #define SCROLL_W 200 #define SCROLLBAR_LEN 15 /* Variables * ========= */ /* View variable */ static int myview = 0; /* If it is fisheye with fixed width */ static int fixed_width = 0; /* 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 */ #define MAX_ONOFF_POINTS 4 static GS_SEL_POINT on_off_point[MAX_ONOFF_POINTS] = { /* window, text , xpos, ypos, isval, selval , globvar , key */ { 0 , "edges", 5, 108, 0, 0 , &supress_edges , 'e' }, { 0 , "nodes", 5, 126, 0, 0 , &supress_nodes , 'n' }, { 0 , "splines" , 5, 144, 0, 1 , &G_spline , 's' }, { 0 , "fixed radius",200,108, 0, 1 , &fixed_width , 'f' } }; #define FIXED_WBUT 3 /* Touch-points are buttons that don't their change state if we select them. * Instead, some other actions are performed. They don't correspond to * global variables. */ #define MAX_TOUCH_POINTS 0 static GS_SEL_POINT touch_point[1]; #ifdef NEVERNEVERNEVER static GS_SEL_POINT touch_point[MAX_TOUCH_POINTS] = { /* window, text , xpos, ypos, isval, selval, globvar , key */ }; #endif /* Radio buttons are partitioned into those that have the same global * variable. If a radio-button is selected, all other radio buttons * of the same partition became unselected. */ #define MAX_RADIO_POINTS 3 static GS_SEL_POINT radio_point[MAX_RADIO_POINTS] = { /* window, text ,xpos,ypos,isval, selval , globvar , key */ { 0 , "normal view" , 5, 36, 0, 0 , &myview, 'v' }, { 0 , "cartesian fisheye", 5, 54, 0, CSCF_VIEW, &myview, 'c' }, { 0 , "polar fisheye" , 5, 72, 0, PSCF_VIEW, &myview, 'p' } }; #define NORM_VW 0 /* Horizontal long scrollbars are used to change a value by the read and * set functions. Here, these values must be long values. */ #define MAX_HSCROLLBARS 1 #ifdef ANSI_C static GS_SCROLL_BAR hscrollbar[MAX_HSCROLLBARS] = { { 0, 0, 0, 0, "Radius:" ,"%d%", 200, 270, 320, 126, SCROLL_W, 0, &gfishdist , &read_fishdistscrollbar, &set_fishdistscrollbar } }; #else static GS_SCROLL_BAR hscrollbar[MAX_HSCROLLBARS] = { { 0, 0, 0, 0, "Radius:" ,"%ld%", 200, 270, 320, 126, SCROLL_W, 0, &gfishdist , read_fishdistscrollbar, set_fishdistscrollbar } }; #endif #define GFISHDIST 0 /* 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 test_button; static Window cancel_button; /* Cursors */ static Cursor standardCursor; /* Remembered old cursor */ static Cursor workingCursor; /* If the tool is busy */ static Cursor scrollCursor; static Cursor leftscrollCursor; static Cursor rightscrollCursor; /* 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 whether 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_view_dialog(Display *rd, int rs) #else void x11_init_view_dialog(rd, rs) Display *rd; int rs; #endif { if (dialog_box_there) return; root_display = rd; root_screen = rs; dialog_font = XLoadQueryFont(root_display,Xfontname); if (!dialog_font) { Fatal_error("Font not found. Please use option -font",""); } allocateDialogBox(); dialog_box_there = 1; } /* Destroy the dialog box * ---------------------- * This is done once on ExitDevice. */ #ifdef ANSI_C void x11_destroy_view_dialog(Display *rd, int rs) #else void x11_destroy_view_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 Window last_left; static Window last_right; 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; /* select for all events */ attr.event_mask = KeyPressMask | ButtonPressMask | ButtonReleaseMask | 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); dialog_window = XCreateWindow(root_display, RootWindow(root_display, root_screen), xpos, ypos, DIAL_W, DIAL_H, 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, " View"); XStoreName(root_display, dialog_window, x11_win_label); XSetNormalHints(root_display, dialog_window, &hints); standardCursor = XCreateFontCursor(root_display,XC_left_ptr); workingCursor = XCreateFontCursor(root_display,XC_watch); scrollCursor = XCreateFontCursor(root_display,XC_sb_h_double_arrow); leftscrollCursor = XCreateFontCursor(root_display,XC_sb_left_arrow); rightscrollCursor = XCreateFontCursor(root_display,XC_sb_right_arrow); XDefineCursor(root_display,dialog_window, standardCursor); for (i=0; i no Fixed Width */ if (radio_point[NORM_VW].is == radio_point[NORM_VW].sel) { on_off_point[FIXED_WBUT].is = on_off_point[FIXED_WBUT].sel-1; if (redraw) draw_dialog_point(on_off_point[FIXED_WBUT].w,0); } } /*--------------------------------------------------------------------*/ /* Redraw routine */ /*--------------------------------------------------------------------*/ /* Draw dialog box * --------------- */ static char mxbuffer[256]; #ifdef ANSI_C static void draw_dialog_box(void) #else static void draw_dialog_box() #endif { int i; XSetForeground(root_display, XDefaultGC(root_display, root_screen), XWhitePixel(root_display, root_screen)); XFillRectangle(root_display, (Drawable)dialog_window, XDefaultGC(root_display, root_screen), 0,0, DIAL_W, DIAL_H); XSetForeground(root_display, XDefaultGC(root_display, root_screen), XBlackPixel(root_display, root_screen)); i = XTextWidth(dialog_font,"Cancel (Esc)",strlen("Cancel (Esc)")); i = (BUTTON_W-i)/2; XDrawString(root_display, (Drawable)cancel_button, XDefaultGC(root_display, root_screen), i,18,"Cancel (Esc)",strlen("Cancel (Esc)")); i = XTextWidth(dialog_font,"Okay",strlen("Okay")); i = (BUTTON_W-i)/2; XDrawString(root_display, (Drawable)okay_button, XDefaultGC(root_display, root_screen), i,18,"Okay",strlen("Okay")); i = XTextWidth(dialog_font,"Apply",strlen("Apply")); i = (BUTTON_W-i)/2; XDrawString(root_display, (Drawable)test_button, XDefaultGC(root_display, root_screen), i,18,"Apply",strlen("Apply")); draw_underl_text(5,18, "General View"); draw_underl_text(5,90, "General Parameter"); draw_underl_text(200,90,"Fisheye Parameter"); special_constraints(0, -1); 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,j; 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; ix); draw_sizes(); } } for (i=0; ibutton==G_MOUSE_LEFT) hscrollbar[i].is -= 200; else hscrollbar[i].is -= 10; (*(hscrollbar[i].sf))(); draw_sizes(); } if (act_scroll_window==hscrollbar[i].wr) { if (hscrollbar[i].is < MAXLONG-200) { if (e->button==G_MOUSE_LEFT) hscrollbar[i].is += 200; else hscrollbar[i].is += 10; } (*(hscrollbar[i].sf))(); draw_sizes(); } } if (w==okay_button) { dialog_notready = 0; dialog_success = 1; } else if (w==cancel_button) { dialog_notready = 0; dialog_success = 0; } else if (w==test_button) { do_apply(); } } /* Button Release * -------------- */ #ifdef ANSI_C static void do_ButtonRelease (XEvent *eventp) #else static void do_ButtonRelease (eventp) XEvent *eventp; #endif { XButtonEvent *e = (XButtonEvent *) eventp; int i; if (act_scroll_window && (e->window!=act_scroll_window)) { for (i=0; ix); break; } } if (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_W,DIAL_H); draw_dialog_box(); } else do_gblConfigureNotify(eventp); } /* Motion with pressed button * -------------------------- */ #ifdef ANSI_C static void do_MotionNotify (XEvent *eventp) #else static void do_MotionNotify (eventp) XEvent *eventp; #endif { int i; XMotionEvent *e = (XMotionEvent *) eventp; for (i=0; ix); break; } } if (i= hscrollbar[GFISHDIST].len) val = hscrollbar[GFISHDIST].len - SCROLLBAR_LEN; XMoveResizeWindow(root_display,hscrollbar[GFISHDIST].wt, val,0,SCROLLBAR_LEN,6); hscrollbar[GFISHDIST].is = 30L + 50L*(long)val; } #ifdef ANSI_C static void set_fishdistscrollbar(void) #else static void set_fishdistscrollbar() #endif { int val; if (hscrollbar[GFISHDIST].is<30L) hscrollbar[GFISHDIST].is = 30L; val = (int)((hscrollbar[GFISHDIST].is - 30L) / 50L); if (val<0) val = 0; if (val+SCROLLBAR_LEN >= hscrollbar[GFISHDIST].len) val = hscrollbar[GFISHDIST].len - SCROLLBAR_LEN; XMoveResizeWindow(root_display, hscrollbar[GFISHDIST].wt, val,0,SCROLLBAR_LEN,6); } /*--------------------------------------------------------------------*/ #endif /* X11 */