Mercurial > hg > aim92
comparison xaim/initialise.c @ 0:5242703e91d3 tip
Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author | tomwalters |
---|---|
date | Fri, 20 May 2011 15:19:45 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5242703e91d3 |
---|---|
1 /* | |
2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1993 | |
3 =========================================================================== | |
4 | |
5 Permission to use, copy, modify, and distribute this software without fee | |
6 is hereby granted for research purposes, provided that this copyright | |
7 notice appears in all copies and in all supporting documentation, and that | |
8 the software is not redistributed for any fee (except for a nominal | |
9 shipping charge). Anyone wanting to incorporate all or part of this | |
10 software in a commercial product must obtain a license from the Medical | |
11 Research Council. | |
12 | |
13 The MRC makes no representations about the suitability of this | |
14 software for any purpose. It is provided "as is" without express or | |
15 implied warranty. | |
16 | |
17 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING | |
18 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL | |
19 THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES | |
20 OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
21 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |
22 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |
23 SOFTWARE. | |
24 */ | |
25 /* | |
26 * initailise.c | |
27 * --------- | |
28 * Initialises lots of X things. | |
29 * | |
30 * M. Akeroyd. July 1993. version 1.10 | |
31 * Revisions: MAA: Christmas 1993. | |
32 * | |
33 */ | |
34 | |
35 | |
36 | |
37 #include <X11/Xlib.h> | |
38 #include <X11/Xutil.h> | |
39 #include <X11/Xos.h> | |
40 #include <X11/Xatom.h> | |
41 #include <stdio.h> | |
42 | |
43 #include "xreview.h" | |
44 #include "./xreview.bitmap" | |
45 #include <X11/cursorfont.h> | |
46 | |
47 | |
48 | |
49 /* General variables ....*/ | |
50 | |
51 extern char progname[MAX_STRING_LENGTH]; | |
52 | |
53 extern char *data_pointer; | |
54 extern long location[MAX_FRAMES]; | |
55 | |
56 | |
57 | |
58 /* X ....................*/ | |
59 | |
60 extern char display_name[MAX_STRING_LENGTH]; | |
61 extern char fontname[MAX_STRING_LENGTH]; | |
62 | |
63 extern Display *display; | |
64 extern int screen_num; | |
65 extern Screen *screen_ptr; | |
66 extern int depth; | |
67 extern unsigned int display_width, display_height; | |
68 | |
69 extern toplevelWindow control; | |
70 extern toplevelWindow axes; | |
71 extern Pixmap stipple_pixmap; | |
72 extern XImage *reviewimage; | |
73 extern Cursor cursor; | |
74 | |
75 extern GC button_gc; | |
76 extern XFontStruct *font_info; | |
77 extern int planemask; | |
78 | |
79 | |
80 /* .ctn ..................*/ | |
81 | |
82 extern int no_frames; | |
83 extern int width_ctn, height_ctn; | |
84 extern int x_ctn, y_ctn; | |
85 extern int reviewimage_bytesperline; | |
86 extern int reviewimage_bitmap_pad; | |
87 | |
88 | |
89 /* Command line ..........*/ | |
90 extern double scale; | |
91 extern int new_axes_x, new_axes_y; | |
92 extern int new_control_x, new_control_y; | |
93 | |
94 extern int axes_xflag, axes_yflag; | |
95 extern int controls_xflag, controls_yflag; | |
96 extern int verboseflag; | |
97 extern int titleflag; | |
98 extern int depthflag; | |
99 extern int reversevideoflag; | |
100 extern int byteorderflag; | |
101 | |
102 | |
103 | |
104 /*--------------------------------------------------------------------------*/ | |
105 /*--------------------------------------------------------------------------*/ | |
106 | |
107 | |
108 | |
109 | |
110 void initialise_X_screen() | |
111 { | |
112 display = XOpenDisplay(display_name); | |
113 if (display == NULL) { | |
114 fprintf(stderr, "xreview : cannot connect to X server %s\n", XDisplayName(display_name)); | |
115 exit(-1);} | |
116 | |
117 screen_num = DefaultScreen(display); | |
118 screen_ptr = DefaultScreenOfDisplay(display); | |
119 | |
120 display_width = DisplayWidth(display, screen_num); | |
121 display_height = DisplayHeight(display, screen_num); | |
122 } | |
123 | |
124 | |
125 | |
126 /*--------------------------------------------------------------------------*/ | |
127 /*--------------------------------------------------------------------------*/ | |
128 | |
129 | |
130 | |
131 void initialise_axes_window(char *inputfn, char *titlestring, FILE *inputfp, char *argv[], int argc) | |
132 { | |
133 char tempstring[MAX_STRING_LENGTH]; | |
134 int status; | |
135 | |
136 /*-----------------------------------*/ | |
137 | |
138 /* Set title to either the filename, "stdin", ot the -title option. */ | |
139 if (inputfp == stdin){ | |
140 strcpy(tempstring, "stdin"); | |
141 axes.window_name = tempstring; | |
142 axes.icon_name = tempstring;} | |
143 else { | |
144 axes.window_name = inputfn; | |
145 axes.icon_name = inputfn;} | |
146 | |
147 if (titleflag == ON){ | |
148 axes.window_name = titlestring; | |
149 axes.icon_name = titlestring; } | |
150 | |
151 /* Copy size off .ctn header */ | |
152 axes.width = width_ctn; | |
153 axes.height = height_ctn; | |
154 | |
155 /* Copy position off header */ | |
156 axes.x = x_ctn; | |
157 axes.y = y_ctn; | |
158 if (x_ctn == -1) | |
159 axes.x = display_width/2 - axes.width/2; | |
160 if (y_ctn == -1) | |
161 axes.y = display_height/2 - axes.height/2; | |
162 | |
163 /* If user requests new position, honour it */ | |
164 if (axes_xflag == ON) | |
165 axes.x = new_axes_x; | |
166 if (axes_yflag == ON) | |
167 axes.y = new_axes_y; | |
168 | |
169 /*---------------------------------*/ | |
170 | |
171 axes.win = XCreateSimpleWindow(display, RootWindow(display, screen_num), \ | |
172 axes.x, axes.y, axes.width, axes.height,\ | |
173 axes.border_width, \ | |
174 BlackPixel(display, screen_num), \ | |
175 WhitePixel(display, screen_num)); | |
176 | |
177 axes.icon_pixmap = XCreateBitmapFromData(display, axes.win, xreview_bits, \ | |
178 xreview_width, xreview_height); | |
179 axes.gc = XCreateGC(display, axes.win, axes.valuemask, &axes.values); | |
180 | |
181 axes.line_width = LINE_WIDTH_X; | |
182 axes.line_style = LINE_STYLE_X; | |
183 axes.cap_style = CAP_STYLE_X; | |
184 axes.join_style = JOIN_STYLE_X; | |
185 axes.foreground = BlackPixel(display, screen_num); | |
186 | |
187 XSelectInput(display, axes.win, ExposureMask | KeyPressMask | \ | |
188 ButtonPressMask | StructureNotifyMask); | |
189 XSetFont(display, axes.gc, font_info->fid); | |
190 if (reversevideoflag == OFF) { | |
191 XSetForeground(display, axes.gc, axes.foreground); | |
192 XSetBackground(display, axes.gc, WhitePixel(display, screen_num));} | |
193 else{ | |
194 XSetBackground(display, axes.gc, axes.foreground); | |
195 XSetForeground(display, axes.gc, WhitePixel(display, screen_num));} | |
196 | |
197 XSetLineAttributes(display, axes.gc, axes.line_width, axes.line_style,\ | |
198 axes.cap_style, axes.join_style); | |
199 XSetPlaneMask(display, axes.gc, planemask); | |
200 XDefineCursor(display, axes.win, cursor); | |
201 | |
202 axes.window_size = BIG_ENOUGH_X; | |
203 | |
204 /*---------------------------------*/ | |
205 /* Window Manager bits. Assume R4. */ | |
206 | |
207 axes.size_hints.flags = PPosition | PSize | PMinSize | PMaxSize; | |
208 axes.size_hints.min_width = axes.width; | |
209 axes.size_hints.max_width = axes.width; | |
210 axes.size_hints.min_height = axes.height; | |
211 axes.size_hints.max_height = axes.height; | |
212 | |
213 axes.wm_hints.initial_state = NormalState; | |
214 axes.wm_hints.input = True; | |
215 axes.wm_hints.icon_pixmap = axes.icon_pixmap; | |
216 axes.wm_hints.flags = StateHint | IconPixmapHint | InputHint; | |
217 | |
218 axes.class_hints.res_name = progname; | |
219 axes.class_hints.res_class = "Xreview"; | |
220 | |
221 status = XStringListToTextProperty(&axes.window_name, 1, &axes.windowName); | |
222 if (status == 0) { | |
223 if (verboseflag == ON) fprintf(stderr, "\n"); | |
224 fprintf(stderr,"xreview : structure allocation for cartoon windowName failed.\n"); | |
225 exit(-1); } | |
226 | |
227 status = XStringListToTextProperty(&axes.icon_name, 1, &axes.iconName); | |
228 if (status == 0) { | |
229 if (verboseflag == ON) fprintf(stderr, "\n"); | |
230 fprintf(stderr,"xreview : structure allocation for cartoon iconName failed.\n"); | |
231 exit(-1); } | |
232 | |
233 XSetWMProperties(display, axes.win, &axes.windowName, &axes.iconName, \ | |
234 argv, argc, \ | |
235 &axes.size_hints, &axes.wm_hints, &axes.class_hints); | |
236 | |
237 } | |
238 | |
239 | |
240 | |
241 /*----------------------------------------------------------------------*/ | |
242 /*----------------------------------------------------------------------*/ | |
243 | |
244 | |
245 | |
246 void initialise_control_window(char *inputfn, char *titlestring, FILE *inputfp, char *argv[], int argc) | |
247 { | |
248 char tempstring[MAX_STRING_LENGTH]; | |
249 int status; | |
250 | |
251 /*----------------------------------*/ | |
252 | |
253 control.window_name = "xreview controls"; | |
254 control.icon_name = "Controls"; | |
255 | |
256 control.width = (int) CONTROL_WIDTH * scale; | |
257 control.height = (int) CONTROL_HEIGHT * scale; | |
258 | |
259 control.x = CONTROL_X; | |
260 control.y = CONTROL_Y; | |
261 | |
262 /* If user requests new position, honour it */ | |
263 if (controls_xflag == ON) | |
264 control.x = new_control_x; | |
265 if (controls_yflag == ON) | |
266 control.y = new_control_y; | |
267 | |
268 /*---------------------------------*/ | |
269 | |
270 control.win = XCreateSimpleWindow(display, RootWindow(display, screen_num), \ | |
271 control.x, control.y, control.width, \ | |
272 control.height, control.border_width, \ | |
273 BlackPixel(display, screen_num), \ | |
274 WhitePixel(display, screen_num)); | |
275 | |
276 control.icon_pixmap = XCreateBitmapFromData(display, control.win, \ | |
277 xreview_bits, \ | |
278 xreview_width, xreview_height); | |
279 control.gc = XCreateGC(display, control.win, \ | |
280 control.valuemask, &control.values); | |
281 | |
282 control.line_width = LINE_WIDTH_X; | |
283 control.line_style = LINE_STYLE_X; | |
284 control.cap_style = CAP_STYLE_X; | |
285 control.join_style = JOIN_STYLE_X; | |
286 control.foreground = BlackPixel(display, screen_num); | |
287 | |
288 XSelectInput(display, control.win, \ | |
289 ExposureMask | KeyPressMask | \ | |
290 ButtonPressMask | StructureNotifyMask); | |
291 XSetFont(display, control.gc, font_info->fid); | |
292 XSetForeground(display, control.gc, control.foreground); | |
293 XSetLineAttributes(display, control.gc, control.line_width, \ | |
294 control.line_style,control.cap_style, control.join_style); | |
295 XDefineCursor(display, control.win, cursor); | |
296 XSetWindowBackgroundPixmap(display, control.win, stipple_pixmap); | |
297 | |
298 control.window_size = BIG_ENOUGH_X; | |
299 | |
300 /*---------------------------------*/ | |
301 /* Window Manager bits. Assume R4. */ | |
302 | |
303 control.size_hints.flags = PPosition | PSize | PMinSize | PMaxSize; | |
304 control.size_hints.min_width = control.width; | |
305 control.size_hints.min_height = control.height; | |
306 control.size_hints.max_width = control.width; | |
307 control.size_hints.max_height = control.height; | |
308 | |
309 control.wm_hints.initial_state = NormalState; | |
310 control.wm_hints.input = True; | |
311 control.wm_hints.icon_pixmap = control.icon_pixmap; | |
312 control.wm_hints.flags = StateHint | IconPixmapHint | InputHint; | |
313 | |
314 control.class_hints.res_name = "xreview controls"; | |
315 control.class_hints.res_class = "Xreview"; | |
316 | |
317 status = XStringListToTextProperty(&control.window_name, 1, &control.windowName); | |
318 if (status == 0) { | |
319 if (verboseflag == ON) fprintf(stderr, "\n"); | |
320 fprintf(stderr,"xreview : structure allocation for Controls windowName failed.\n"); | |
321 exit(-1); } | |
322 | |
323 status = XStringListToTextProperty(&control.icon_name, 1, &control.iconName); | |
324 if (status == 0) { | |
325 if (verboseflag == ON) fprintf(stderr, "\n"); | |
326 fprintf(stderr,"xreview : structure allocation for Controls iconName failed.\n"); | |
327 exit(-1); } | |
328 | |
329 XSetWMProperties(display, control.win,&control.windowName,&control.iconName,\ | |
330 argv, argc, \ | |
331 &control.size_hints,&control.wm_hints,&control.class_hints); | |
332 | |
333 } | |
334 | |
335 | |
336 | |
337 /*--------------------------------------------------------------------*/ | |
338 /*--------------------------------------------------------------------*/ | |
339 | |
340 | |
341 | |
342 void initialise_image() | |
343 { | |
344 int offset = 0; | |
345 | |
346 if (depthflag == MONO) | |
347 reviewimage = XCreateImage(display, DefaultVisual(display, screen_num),\ | |
348 depth, XYBitmap, \ | |
349 offset, data_pointer, axes.width, axes.height,\ | |
350 reviewimage_bitmap_pad, reviewimage_bytesperline); | |
351 else | |
352 reviewimage = XCreateImage(display, DefaultVisual(display, screen_num),\ | |
353 depth, XYPixmap, \ | |
354 offset, data_pointer, axes.width, axes.height,\ | |
355 reviewimage_bitmap_pad, reviewimage_bytesperline); | |
356 | |
357 if (byteorderflag == DEC) { | |
358 (*reviewimage).byte_order = LSBFirst; | |
359 (*reviewimage).bitmap_bit_order = LSBFirst; | |
360 (*reviewimage).bitmap_pad = 32;} | |
361 | |
362 if (byteorderflag == SUN) { | |
363 (*reviewimage).byte_order = MSBFirst; | |
364 (*reviewimage).bitmap_bit_order = MSBFirst; | |
365 (*reviewimage).bitmap_pad = 32;} | |
366 | |
367 } | |
368 | |
369 | |
370 | |
371 | |
372 /*----------------------------------------------------------------------*/ | |
373 /*----------------------------------------------------------------------*/ | |
374 | |
375 | |
376 | |
377 | |
378 void exit_xreview() | |
379 { | |
380 reviewimage->data = (char *) location[1]; | |
381 XDestroyImage(reviewimage); | |
382 XUnloadFont(display, font_info->fid); | |
383 XFreeGC(display, axes.gc); | |
384 XFreeGC(display, control.gc); | |
385 XFreeGC(display, button_gc); | |
386 XCloseDisplay(display); | |
387 if (verboseflag==ON) fprintf(stderr, "\n"); | |
388 exit(1); | |
389 } | |
390 | |
391 | |
392 | |
393 /* The end.*/ | |
394 /*-------------------------------------------------------------------------*/ | |
395 /*-------------------------------------------------------------------------*/ | |
396 | |
397 | |
398 | |
399 | |
400 |