tomwalters@0: /* tomwalters@0: Copyright (c) Applied Psychology Unit, Medical Research Council. 1993 tomwalters@0: =========================================================================== tomwalters@0: tomwalters@0: Permission to use, copy, modify, and distribute this software without fee tomwalters@0: is hereby granted for research purposes, provided that this copyright tomwalters@0: notice appears in all copies and in all supporting documentation, and that tomwalters@0: the software is not redistributed for any fee (except for a nominal tomwalters@0: shipping charge). Anyone wanting to incorporate all or part of this tomwalters@0: software in a commercial product must obtain a license from the Medical tomwalters@0: Research Council. tomwalters@0: tomwalters@0: The MRC makes no representations about the suitability of this tomwalters@0: software for any purpose. It is provided "as is" without express or tomwalters@0: implied warranty. tomwalters@0: tomwalters@0: THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING tomwalters@0: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL tomwalters@0: THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES tomwalters@0: OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, tomwalters@0: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, tomwalters@0: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS tomwalters@0: SOFTWARE. tomwalters@0: */ tomwalters@0: /* tomwalters@0: * initailise.c tomwalters@0: * --------- tomwalters@0: * Initialises lots of X things. tomwalters@0: * tomwalters@0: * M. Akeroyd. July 1993. version 1.10 tomwalters@0: * Revisions: MAA: Christmas 1993. tomwalters@0: * tomwalters@0: */ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include tomwalters@0: tomwalters@0: #include "xreview.h" tomwalters@0: #include "./xreview.bitmap" tomwalters@0: #include tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* General variables ....*/ tomwalters@0: tomwalters@0: extern char progname[MAX_STRING_LENGTH]; tomwalters@0: tomwalters@0: extern char *data_pointer; tomwalters@0: extern long location[MAX_FRAMES]; tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* X ....................*/ tomwalters@0: tomwalters@0: extern char display_name[MAX_STRING_LENGTH]; tomwalters@0: extern char fontname[MAX_STRING_LENGTH]; tomwalters@0: tomwalters@0: extern Display *display; tomwalters@0: extern int screen_num; tomwalters@0: extern Screen *screen_ptr; tomwalters@0: extern int depth; tomwalters@0: extern unsigned int display_width, display_height; tomwalters@0: tomwalters@0: extern toplevelWindow control; tomwalters@0: extern toplevelWindow axes; tomwalters@0: extern Pixmap stipple_pixmap; tomwalters@0: extern XImage *reviewimage; tomwalters@0: extern Cursor cursor; tomwalters@0: tomwalters@0: extern GC button_gc; tomwalters@0: extern XFontStruct *font_info; tomwalters@0: extern int planemask; tomwalters@0: tomwalters@0: tomwalters@0: /* .ctn ..................*/ tomwalters@0: tomwalters@0: extern int no_frames; tomwalters@0: extern int width_ctn, height_ctn; tomwalters@0: extern int x_ctn, y_ctn; tomwalters@0: extern int reviewimage_bytesperline; tomwalters@0: extern int reviewimage_bitmap_pad; tomwalters@0: tomwalters@0: tomwalters@0: /* Command line ..........*/ tomwalters@0: extern double scale; tomwalters@0: extern int new_axes_x, new_axes_y; tomwalters@0: extern int new_control_x, new_control_y; tomwalters@0: tomwalters@0: extern int axes_xflag, axes_yflag; tomwalters@0: extern int controls_xflag, controls_yflag; tomwalters@0: extern int verboseflag; tomwalters@0: extern int titleflag; tomwalters@0: extern int depthflag; tomwalters@0: extern int reversevideoflag; tomwalters@0: extern int byteorderflag; tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /*--------------------------------------------------------------------------*/ tomwalters@0: /*--------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void initialise_X_screen() tomwalters@0: { tomwalters@0: display = XOpenDisplay(display_name); tomwalters@0: if (display == NULL) { tomwalters@0: fprintf(stderr, "xreview : cannot connect to X server %s\n", XDisplayName(display_name)); tomwalters@0: exit(-1);} tomwalters@0: tomwalters@0: screen_num = DefaultScreen(display); tomwalters@0: screen_ptr = DefaultScreenOfDisplay(display); tomwalters@0: tomwalters@0: display_width = DisplayWidth(display, screen_num); tomwalters@0: display_height = DisplayHeight(display, screen_num); tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /*--------------------------------------------------------------------------*/ tomwalters@0: /*--------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void initialise_axes_window(char *inputfn, char *titlestring, FILE *inputfp, char *argv[], int argc) tomwalters@0: { tomwalters@0: char tempstring[MAX_STRING_LENGTH]; tomwalters@0: int status; tomwalters@0: tomwalters@0: /*-----------------------------------*/ tomwalters@0: tomwalters@0: /* Set title to either the filename, "stdin", ot the -title option. */ tomwalters@0: if (inputfp == stdin){ tomwalters@0: strcpy(tempstring, "stdin"); tomwalters@0: axes.window_name = tempstring; tomwalters@0: axes.icon_name = tempstring;} tomwalters@0: else { tomwalters@0: axes.window_name = inputfn; tomwalters@0: axes.icon_name = inputfn;} tomwalters@0: tomwalters@0: if (titleflag == ON){ tomwalters@0: axes.window_name = titlestring; tomwalters@0: axes.icon_name = titlestring; } tomwalters@0: tomwalters@0: /* Copy size off .ctn header */ tomwalters@0: axes.width = width_ctn; tomwalters@0: axes.height = height_ctn; tomwalters@0: tomwalters@0: /* Copy position off header */ tomwalters@0: axes.x = x_ctn; tomwalters@0: axes.y = y_ctn; tomwalters@0: if (x_ctn == -1) tomwalters@0: axes.x = display_width/2 - axes.width/2; tomwalters@0: if (y_ctn == -1) tomwalters@0: axes.y = display_height/2 - axes.height/2; tomwalters@0: tomwalters@0: /* If user requests new position, honour it */ tomwalters@0: if (axes_xflag == ON) tomwalters@0: axes.x = new_axes_x; tomwalters@0: if (axes_yflag == ON) tomwalters@0: axes.y = new_axes_y; tomwalters@0: tomwalters@0: /*---------------------------------*/ tomwalters@0: tomwalters@0: axes.win = XCreateSimpleWindow(display, RootWindow(display, screen_num), \ tomwalters@0: axes.x, axes.y, axes.width, axes.height,\ tomwalters@0: axes.border_width, \ tomwalters@0: BlackPixel(display, screen_num), \ tomwalters@0: WhitePixel(display, screen_num)); tomwalters@0: tomwalters@0: axes.icon_pixmap = XCreateBitmapFromData(display, axes.win, xreview_bits, \ tomwalters@0: xreview_width, xreview_height); tomwalters@0: axes.gc = XCreateGC(display, axes.win, axes.valuemask, &axes.values); tomwalters@0: tomwalters@0: axes.line_width = LINE_WIDTH_X; tomwalters@0: axes.line_style = LINE_STYLE_X; tomwalters@0: axes.cap_style = CAP_STYLE_X; tomwalters@0: axes.join_style = JOIN_STYLE_X; tomwalters@0: axes.foreground = BlackPixel(display, screen_num); tomwalters@0: tomwalters@0: XSelectInput(display, axes.win, ExposureMask | KeyPressMask | \ tomwalters@0: ButtonPressMask | StructureNotifyMask); tomwalters@0: XSetFont(display, axes.gc, font_info->fid); tomwalters@0: if (reversevideoflag == OFF) { tomwalters@0: XSetForeground(display, axes.gc, axes.foreground); tomwalters@0: XSetBackground(display, axes.gc, WhitePixel(display, screen_num));} tomwalters@0: else{ tomwalters@0: XSetBackground(display, axes.gc, axes.foreground); tomwalters@0: XSetForeground(display, axes.gc, WhitePixel(display, screen_num));} tomwalters@0: tomwalters@0: XSetLineAttributes(display, axes.gc, axes.line_width, axes.line_style,\ tomwalters@0: axes.cap_style, axes.join_style); tomwalters@0: XSetPlaneMask(display, axes.gc, planemask); tomwalters@0: XDefineCursor(display, axes.win, cursor); tomwalters@0: tomwalters@0: axes.window_size = BIG_ENOUGH_X; tomwalters@0: tomwalters@0: /*---------------------------------*/ tomwalters@0: /* Window Manager bits. Assume R4. */ tomwalters@0: tomwalters@0: axes.size_hints.flags = PPosition | PSize | PMinSize | PMaxSize; tomwalters@0: axes.size_hints.min_width = axes.width; tomwalters@0: axes.size_hints.max_width = axes.width; tomwalters@0: axes.size_hints.min_height = axes.height; tomwalters@0: axes.size_hints.max_height = axes.height; tomwalters@0: tomwalters@0: axes.wm_hints.initial_state = NormalState; tomwalters@0: axes.wm_hints.input = True; tomwalters@0: axes.wm_hints.icon_pixmap = axes.icon_pixmap; tomwalters@0: axes.wm_hints.flags = StateHint | IconPixmapHint | InputHint; tomwalters@0: tomwalters@0: axes.class_hints.res_name = progname; tomwalters@0: axes.class_hints.res_class = "Xreview"; tomwalters@0: tomwalters@0: status = XStringListToTextProperty(&axes.window_name, 1, &axes.windowName); tomwalters@0: if (status == 0) { tomwalters@0: if (verboseflag == ON) fprintf(stderr, "\n"); tomwalters@0: fprintf(stderr,"xreview : structure allocation for cartoon windowName failed.\n"); tomwalters@0: exit(-1); } tomwalters@0: tomwalters@0: status = XStringListToTextProperty(&axes.icon_name, 1, &axes.iconName); tomwalters@0: if (status == 0) { tomwalters@0: if (verboseflag == ON) fprintf(stderr, "\n"); tomwalters@0: fprintf(stderr,"xreview : structure allocation for cartoon iconName failed.\n"); tomwalters@0: exit(-1); } tomwalters@0: tomwalters@0: XSetWMProperties(display, axes.win, &axes.windowName, &axes.iconName, \ tomwalters@0: argv, argc, \ tomwalters@0: &axes.size_hints, &axes.wm_hints, &axes.class_hints); tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /*----------------------------------------------------------------------*/ tomwalters@0: /*----------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void initialise_control_window(char *inputfn, char *titlestring, FILE *inputfp, char *argv[], int argc) tomwalters@0: { tomwalters@0: char tempstring[MAX_STRING_LENGTH]; tomwalters@0: int status; tomwalters@0: tomwalters@0: /*----------------------------------*/ tomwalters@0: tomwalters@0: control.window_name = "xreview controls"; tomwalters@0: control.icon_name = "Controls"; tomwalters@0: tomwalters@0: control.width = (int) CONTROL_WIDTH * scale; tomwalters@0: control.height = (int) CONTROL_HEIGHT * scale; tomwalters@0: tomwalters@0: control.x = CONTROL_X; tomwalters@0: control.y = CONTROL_Y; tomwalters@0: tomwalters@0: /* If user requests new position, honour it */ tomwalters@0: if (controls_xflag == ON) tomwalters@0: control.x = new_control_x; tomwalters@0: if (controls_yflag == ON) tomwalters@0: control.y = new_control_y; tomwalters@0: tomwalters@0: /*---------------------------------*/ tomwalters@0: tomwalters@0: control.win = XCreateSimpleWindow(display, RootWindow(display, screen_num), \ tomwalters@0: control.x, control.y, control.width, \ tomwalters@0: control.height, control.border_width, \ tomwalters@0: BlackPixel(display, screen_num), \ tomwalters@0: WhitePixel(display, screen_num)); tomwalters@0: tomwalters@0: control.icon_pixmap = XCreateBitmapFromData(display, control.win, \ tomwalters@0: xreview_bits, \ tomwalters@0: xreview_width, xreview_height); tomwalters@0: control.gc = XCreateGC(display, control.win, \ tomwalters@0: control.valuemask, &control.values); tomwalters@0: tomwalters@0: control.line_width = LINE_WIDTH_X; tomwalters@0: control.line_style = LINE_STYLE_X; tomwalters@0: control.cap_style = CAP_STYLE_X; tomwalters@0: control.join_style = JOIN_STYLE_X; tomwalters@0: control.foreground = BlackPixel(display, screen_num); tomwalters@0: tomwalters@0: XSelectInput(display, control.win, \ tomwalters@0: ExposureMask | KeyPressMask | \ tomwalters@0: ButtonPressMask | StructureNotifyMask); tomwalters@0: XSetFont(display, control.gc, font_info->fid); tomwalters@0: XSetForeground(display, control.gc, control.foreground); tomwalters@0: XSetLineAttributes(display, control.gc, control.line_width, \ tomwalters@0: control.line_style,control.cap_style, control.join_style); tomwalters@0: XDefineCursor(display, control.win, cursor); tomwalters@0: XSetWindowBackgroundPixmap(display, control.win, stipple_pixmap); tomwalters@0: tomwalters@0: control.window_size = BIG_ENOUGH_X; tomwalters@0: tomwalters@0: /*---------------------------------*/ tomwalters@0: /* Window Manager bits. Assume R4. */ tomwalters@0: tomwalters@0: control.size_hints.flags = PPosition | PSize | PMinSize | PMaxSize; tomwalters@0: control.size_hints.min_width = control.width; tomwalters@0: control.size_hints.min_height = control.height; tomwalters@0: control.size_hints.max_width = control.width; tomwalters@0: control.size_hints.max_height = control.height; tomwalters@0: tomwalters@0: control.wm_hints.initial_state = NormalState; tomwalters@0: control.wm_hints.input = True; tomwalters@0: control.wm_hints.icon_pixmap = control.icon_pixmap; tomwalters@0: control.wm_hints.flags = StateHint | IconPixmapHint | InputHint; tomwalters@0: tomwalters@0: control.class_hints.res_name = "xreview controls"; tomwalters@0: control.class_hints.res_class = "Xreview"; tomwalters@0: tomwalters@0: status = XStringListToTextProperty(&control.window_name, 1, &control.windowName); tomwalters@0: if (status == 0) { tomwalters@0: if (verboseflag == ON) fprintf(stderr, "\n"); tomwalters@0: fprintf(stderr,"xreview : structure allocation for Controls windowName failed.\n"); tomwalters@0: exit(-1); } tomwalters@0: tomwalters@0: status = XStringListToTextProperty(&control.icon_name, 1, &control.iconName); tomwalters@0: if (status == 0) { tomwalters@0: if (verboseflag == ON) fprintf(stderr, "\n"); tomwalters@0: fprintf(stderr,"xreview : structure allocation for Controls iconName failed.\n"); tomwalters@0: exit(-1); } tomwalters@0: tomwalters@0: XSetWMProperties(display, control.win,&control.windowName,&control.iconName,\ tomwalters@0: argv, argc, \ tomwalters@0: &control.size_hints,&control.wm_hints,&control.class_hints); tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /*--------------------------------------------------------------------*/ tomwalters@0: /*--------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void initialise_image() tomwalters@0: { tomwalters@0: int offset = 0; tomwalters@0: tomwalters@0: if (depthflag == MONO) tomwalters@0: reviewimage = XCreateImage(display, DefaultVisual(display, screen_num),\ tomwalters@0: depth, XYBitmap, \ tomwalters@0: offset, data_pointer, axes.width, axes.height,\ tomwalters@0: reviewimage_bitmap_pad, reviewimage_bytesperline); tomwalters@0: else tomwalters@0: reviewimage = XCreateImage(display, DefaultVisual(display, screen_num),\ tomwalters@0: depth, XYPixmap, \ tomwalters@0: offset, data_pointer, axes.width, axes.height,\ tomwalters@0: reviewimage_bitmap_pad, reviewimage_bytesperline); tomwalters@0: tomwalters@0: if (byteorderflag == DEC) { tomwalters@0: (*reviewimage).byte_order = LSBFirst; tomwalters@0: (*reviewimage).bitmap_bit_order = LSBFirst; tomwalters@0: (*reviewimage).bitmap_pad = 32;} tomwalters@0: tomwalters@0: if (byteorderflag == SUN) { tomwalters@0: (*reviewimage).byte_order = MSBFirst; tomwalters@0: (*reviewimage).bitmap_bit_order = MSBFirst; tomwalters@0: (*reviewimage).bitmap_pad = 32;} tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /*----------------------------------------------------------------------*/ tomwalters@0: /*----------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void exit_xreview() tomwalters@0: { tomwalters@0: reviewimage->data = (char *) location[1]; tomwalters@0: XDestroyImage(reviewimage); tomwalters@0: XUnloadFont(display, font_info->fid); tomwalters@0: XFreeGC(display, axes.gc); tomwalters@0: XFreeGC(display, control.gc); tomwalters@0: XFreeGC(display, button_gc); tomwalters@0: XCloseDisplay(display); tomwalters@0: if (verboseflag==ON) fprintf(stderr, "\n"); tomwalters@0: exit(1); tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* The end.*/ tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: