Debian Codegraph @

libsrc/idi/cidi/x11/idilocal3.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2009 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /***********************************************************************
29 *
30 * file idilocal3.c
31 *
32 * IDI Device Dependent Routines
33 * (XWindows version)
34 *
35 * V 1.00 940630 K. Banse ESO - Garching
36 *
37 * file idilocal3.c : contains the following routines
38 *
39 * draw_curs : Draw different cursor shapes
40 * draw_rroi : Draw Rectangular ROI;
41 * draw_croi : Draw Circular ROI;
42 * destroy : destroy Xstructures + free related memory
43 * exposed : look for Expose events
44 * stopped : look for Exit button events
45 * iconify : iconify (or not) display window
46 * send_event : send an event to a window
47 *
48
49 090424 last modif
50 ************************************************************************/
51
52 # include <idi.h>
53 # include <idistruct.h>
54 # include <x11defs.h>
55 # include <filedef.h>
56 # include <proto_idi.h>
57
58 #include <stdio.h>
59
60
61
62 extern int CGN_OPEN(), CGN_CNVT(), OSY_SLEEP();
63 extern int osaopen(), osaread(), osaclose();
64 extern long int osaseek();
65
66 static int crossize = 20;
67 static int cursrad = 4, zoomf = 20;
68 static int xysiz[2], xy1off[2], xy2off[2] = {0,0};
69
70 static CONF_DATA *conf;
71 static MEM_DATA *mema, *memb;
72
73
74 /*
75
76 */
77
78 /* ---- draw cursor -------------------------------------------- */
79
80 /* flag = 0, first time
81 = 1, normal mode
82 = 2, last time */
83
84
85 void draw_curs(dspno,flag,dysize,curno,xcur,ycur,cursh,curcol)
86 int dspno, flag, dysize, curno, xcur, ycur, cursh, curcol;
87
88 {
89 int no, x1, x2, y1, y2, x3, x4, y3, y4;
90 int xx1, xx2, yy1, yy2, xx3, xx4, yy3, yy4;
91 int k, tmpx;
92 static int count0[MAX_DEV], count1[MAX_DEV];
93
94
95 /* erase old cursor */
96
97 no = ididev[dspno].screen;
98 if (flag > 0)
99 {
100 if (curno == 0)
101 XDrawSegments(mydisp[no],mwndw[dspno],gcdraw[dspno],
102 &curso0[dspno][0],count0[dspno]);
103 else
104 XDrawSegments(mydisp[no],mwndw[dspno],gcdraw[dspno],
105 &curso1[dspno][0],count1[dspno]);
106
107 if (flag > 1) return;
108 }
109
110
111 ycur = dysize - ycur;
112
113 xx1 = xx2 = xx3 = xx4 = 0;
114 yy1 = yy2 = yy3 = yy4 = 0;
115
116 if (cursh == II_CROSSHAIR)
117 {
118 k = 2;
119 x1 = 0;
120 y1 = ycur;
121 x2 = 2000; /* let X do the clipping ... */
122 y2 = y1;
123 x3 = xcur;
124 y3 = 0;
125 x4 = x3;
126 y4 = dysize;
127 }
128
129 else if (cursh == II_SMALCROSS)
130 {
131 k = 2;
132 tmpx = 7;
133 x1 = xcur - tmpx;
134 y1 = ycur;
135 x2 = xcur + tmpx;
136 y2 = y1;
137 x3 = xcur;
138 y3 = y1 - tmpx;
139 x4 = x3;
140 y4 = y1 + tmpx;
141 }
142
143 else if (cursh == II_OPNCROSS)
144 {
145 k = 4;
146 tmpx = crossize - 4;
147 x1 = xcur - crossize;
148 y1 = ycur;
149 x2 = x1 + tmpx;
150 y2 = y1;
151 xx1 = xcur + crossize;
152 yy1 = y1;
153 xx2 = xx1 - tmpx;
154 yy2 = y1;
155
156 x3 = xcur;
157 y3 = ycur - crossize;
158 x4 = x3;
159 y4 = y3 + tmpx;
160 xx3 = x3;
161 yy3 = ycur + crossize;
162 xx4 = x3;
163 yy4 = yy3 - tmpx;
164 }
165 /* the default is II_CROSS ... */
166 else
167 {
168 k = 2;
169 x1 = xcur - crossize;
170 y1 = ycur;
171 x2 = xcur + crossize;
172 y2 = y1;
173 x3 = xcur;
174 y3 = y1 - crossize;
175 x4 = x3;
176 y4 = y1 + crossize;
177 }
178
179
180 if (curno == 0)
181 {
182 count0[dspno] = k;
183 curso0[dspno][0].x1 = x1;
184 curso0[dspno][0].y1 = y1;
185 curso0[dspno][0].x2 = x2;
186 curso0[dspno][0].y2 = y2;
187 curso0[dspno][1].x1 = x3;
188 curso0[dspno][1].y1 = y3;
189 curso0[dspno][1].x2 = x4;
190 curso0[dspno][1].y2 = y4;
191 if (count0[dspno] > 2)
192 {
193 curso0[dspno][2].x1 = xx1;
194 curso0[dspno][2].y1 = yy1;
195 curso0[dspno][2].x2 = xx2;
196 curso0[dspno][2].y2 = yy2;
197 curso0[dspno][3].x1 = xx3;
198 curso0[dspno][3].y1 = yy3;
199 curso0[dspno][3].x2 = xx4;
200 curso0[dspno][3].y2 = yy4;
201 }
202 XDrawSegments(mydisp[no],mwndw[dspno],gcdraw[dspno],
203 &curso0[dspno][0],count0[dspno]);
204 }
205
206 else
207 {
208 count1[dspno] = k;
209 curso1[dspno][0].x1 = x1;
210 curso1[dspno][0].y1 = y1;
211 curso1[dspno][0].x2 = x2;
212 curso1[dspno][0].y2 = y2;
213 curso1[dspno][1].x1 = x3;
214 curso1[dspno][1].y1 = y3;
215 curso1[dspno][1].x2 = x4;
216 curso1[dspno][1].y2 = y4;
217 if (count1[dspno] > 2)
218 {
219 curso1[dspno][2].x1 = xx1;
220 curso1[dspno][2].y1 = yy1;
221 curso1[dspno][2].x2 = xx2;
222 curso1[dspno][2].y2 = yy2;
223 curso1[dspno][3].x1 = xx3;
224 curso1[dspno][3].y1 = yy3;
225 curso1[dspno][3].x2 = xx4;
226 curso1[dspno][3].y2 = yy4;
227 }
228 XDrawSegments(mydisp[no],mwndw[dspno],gcdraw[dspno],
229 &curso1[dspno][0],count1[dspno]);
230 }
231
232 if ((k = ididev[dspno].curswin) > -1)
233 {
234 conf = ididev [dspno].confptr;
235 mema = conf->memory[conf->memid];
236 conf = ididev [k].confptr;
237 memb = conf->memory[0]; /* single memory */
238 if (mema->load_dir == 0) ycur = dysize - ycur;
239
240 if (xcur < cursrad) /* extract 11x11 subwindow */
241 xy1off[0] = 0;
242 else
243 xy1off[0] = xcur - cursrad;
244 if (ycur < cursrad)
245 xy1off[1] = 0;
246 else
247 xy1off[1] = ycur - cursrad;
248 tmpx = 2*cursrad + 1;
249 if ((xcur+tmpx) >= ididev[dspno].xsize)
250 xysiz[0] = ididev[dspno].xsize - xcur;
251 else
252 xysiz[0] = tmpx;
253 if ((ycur+tmpx) >= dysize)
254 xysiz[1] = dysize - ycur;
255 else
256 xysiz[1] = tmpx;
257
258 copy_mem(dspno,mema,xy1off,memb,xy2off,xysiz,zoomf);
259 smv(2,k,memb,0,memb->xscroll,memb->yscroll,memb->xsize,memb->ysize,0,0);
260 zoomcross[0].x1 = 61;
261 zoomcross[0].y1 = 90;
262 zoomcross[0].x2 = 120;
263 zoomcross[0].y2 = 90;
264 zoomcross[1].x1 = 90;
265 zoomcross[1].y1 = 61;
266 zoomcross[1].x2 = 90;
267 zoomcross[1].y2 = 120;
268 XDrawSegments(mydisp[ididev[k].screen],mwndw[k],gcima[k],
269 zoomcross,2);
270 zoomcross[0].x1 ++;
271 zoomcross[0].y1 ++;
272 zoomcross[0].x2 ++;
273 zoomcross[0].y2 ++;
274 zoomcross[1].x1 ++;
275 zoomcross[1].y1 ++;
276 zoomcross[1].x2 ++;
277 zoomcross[1].y2 ++;
278 XDrawSegments(mydisp[ididev[k].screen],mwndw[k],gcdraw[k],
279 zoomcross,2);
280 }
281 }
282
283 /*
284
285 */
286
287 /* ---- draw rectangular ROI ----------------------------------------- */
288
289 void draw_rroi(dspno,flag,dysize,x0,y0,x1,y1,roicol)
290 int dspno, flag, dysize, x0, y0, x1, y1, roicol;
291
292 {
293 int yd0, yd1, k, no, tmpx;
294 static int countr[MAX_DEV];
295
296
297 /* erase old ROI */
298
299 no = ididev[dspno].screen;
300 if (flag > 0)
301 {
302 if (countr[dspno] == 5)
303 XDrawSegments(mydisp[no],mwndw[dspno],gcdraw[dspno],
304 &roio[dspno][1],1);
305 else
306 XDrawSegments(mydisp[no],mwndw[dspno],gcdraw[dspno],
307 &roio[dspno][0],countr[dspno]);
308
309 if (flag > 1) return;
310 }
311
312
313 yd0 = dysize - y0;
314 yd1 = dysize - y1;
315
316 roio[dspno][0].x1 = x0;
317 roio[dspno][0].y1 = yd0;
318 roio[dspno][0].x2 = x1;
319 roio[dspno][0].y2 = yd0;
320
321 roio[dspno][1].x1 = x1;
322 roio[dspno][1].y1 = yd0;
323 roio[dspno][1].x2 = x1;
324 roio[dspno][1].y2 = yd1;
325
326 roio[dspno][2].x1 = x1;
327 roio[dspno][2].y1 = yd1;
328 roio[dspno][2].x2 = x0;
329 roio[dspno][2].y2 = yd1;
330
331 roio[dspno][3].x1 = x0;
332 roio[dspno][3].y1 = yd1;
333 roio[dspno][3].x2 = x0;
334 roio[dspno][3].y2 = yd0;
335
336
337 /* check, if ROI collapses to a line (or point) */
338
339 countr[dspno] = 4;
340 if (y0 == y1) countr[dspno] = 1;
341 if (x0 == x1) countr[dspno] = 5;
342
343 if (countr[dspno] == 5)
344 XDrawSegments(mydisp[no],mwndw[dspno],gcdraw[dspno],
345 &roio[dspno][1],1);
346 else
347 XDrawSegments(mydisp[no],mwndw[dspno],gcdraw[dspno],
348 &roio[dspno][0],countr[dspno]);
349
350 if ((k = ididev[dspno].curswin) > -1)
351 {
352 conf = ididev [dspno].confptr;
353 mema = conf->memory[conf->memid];
354 conf = ididev [k].confptr;
355 memb = conf->memory[0]; /* single memory */
356 if (mema->load_dir == 0) yd0 = dysize - yd0; /* ycur <= dysize-ycur */
357
358 if (x0 < cursrad) /* extract 11x11 subwindow */
359 xy1off[0] = 0;
360 else
361 xy1off[0] = x0 - cursrad;
362 if (yd0 < cursrad)
363 xy1off[1] = 0;
364 else
365 xy1off[1] = yd0 - cursrad;
366 tmpx = 2*cursrad + 1;
367 if ((x0+tmpx) >= ididev[dspno].xsize)
368 xysiz[0] = ididev[dspno].xsize - x0;
369 else
370 xysiz[0] = tmpx;
371 if ((yd0+tmpx) >= dysize)
372 xysiz[1] = dysize - yd0;
373 else
374 xysiz[1] = tmpx;
375
376 copy_mem(dspno,mema,xy1off,memb,xy2off,xysiz,zoomf);
377 smv(2,k,memb,0,memb->xscroll,memb->yscroll,memb->xsize,memb->ysize,0,0);
378 zoomcross[0].x1 = 61;
379 zoomcross[0].y1 = 90;
380 zoomcross[0].x2 = 120;
381 zoomcross[0].y2 = 90;
382 zoomcross[1].x1 = 90;
383 zoomcross[1].y1 = 61;
384 zoomcross[1].x2 = 90;
385 zoomcross[1].y2 = 120;
386 XDrawSegments(mydisp[ididev[k].screen],mwndw[k],gcima[k],
387 zoomcross,2);
388 zoomcross[0].x1 ++;
389 zoomcross[0].y1 ++;
390 zoomcross[0].x2 ++;
391 zoomcross[0].y2 ++;
392 zoomcross[1].x1 ++;
393 zoomcross[1].y1 ++;
394 zoomcross[1].x2 ++;
395 zoomcross[1].y2 ++;
396 XDrawSegments(mydisp[ididev[k].screen],mwndw[k],gcdraw[k],
397 zoomcross,2);
398 }
399 }
400
401 /*
402
403 */
404
405 /* ---- draw circular ROI ----------------------------------------- */
406
407 /*
408 x0, y0 - center coords
409 r1, r2, r3 - radius of inner, middle and outer circle
410 */
411
412 void draw_croi(dspno,flag,dysize,x0,y0,r1,r2,r3,roicol)
413 int dspno, flag, dysize, x0, y0, r1, r2, r3, roicol;
414
415 {
416 register int wti, wtm, wto;
417 int k, yd0, no, tmpx;
418 static int ang1 = 0;
419 static int ang2 = 23040; /* 64 * 360 deg. */
420 static int ulxi[MAX_DEV], ulyi[MAX_DEV], ulxm[MAX_DEV];
421 static int ulym[MAX_DEV], ulxo[MAX_DEV], ulyo[MAX_DEV];
422 static int countr[MAX_DEV];
423 static unsigned int wi[MAX_DEV], wm[MAX_DEV], wo[MAX_DEV];
424
425 #define SZA 4
426 #define SZB 8
427
428
429 /* erase old roi */
430
431 no = ididev[dspno].screen;
432 if (flag > 0)
433 {
434 if (countr[dspno] == 1) /* just a single point */
435 XDrawPoint(mydisp[no],mwndw[dspno],gcdraw[dspno],
436 ulxi[dspno],ulyi[dspno]);
437 else
438 {
439 XDrawSegments(mydisp[no],mwndw[dspno],gcdraw[dspno],
440 &roio[dspno][0],4);
441
442 XDrawArc(mydisp[no],mwndw[dspno],gcdraw[dspno],
443 ulxi[dspno],ulyi[dspno],wi[dspno],wi[dspno],ang1,ang2);
444 if (wm[dspno] != 1)
445 XDrawArc(mydisp[no],mwndw[dspno],gcdraw[dspno],
446 ulxm[dspno],ulym[dspno],wm[dspno],wm[dspno],ang1,ang2);
447 if (wo[dspno] != 1)
448 XDrawArc(mydisp[no],mwndw[dspno],gcdraw[dspno],
449 ulxo[dspno],ulyo[dspno],wo[dspno],wo[dspno],ang1,ang2);
450 }
451
452 if (flag > 1) return;
453 }
454
455
456 yd0 = dysize - y0;
457
458 roio[dspno][0].x1 = x0 - SZB;
459 roio[dspno][0].y1 = yd0;
460 roio[dspno][0].x2 = x0 - SZA;
461 roio[dspno][0].y2 = yd0;
462 roio[dspno][1].x1 = x0 + SZB;
463 roio[dspno][1].y1 = yd0;
464 roio[dspno][1].x2 = x0 + SZA;
465 roio[dspno][1].y2 = yd0;
466 roio[dspno][2].x1 = x0;
467 roio[dspno][2].y1 = yd0 - SZB;
468 roio[dspno][2].x2 = x0;
469 roio[dspno][2].y2 = yd0 - SZA;
470 roio[dspno][3].x1 = x0;
471 roio[dspno][3].y1 = yd0 + SZB;
472 roio[dspno][3].x2 = x0;
473 roio[dspno][3].y2 = yd0 + SZA;
474
475
476 /* determine width (= height) of surrounding rectangle */
477
478 wti = r1 + r1 + 1; /* always > 0 */
479 wtm = r2 + r2 + 1;
480 wto = r3 + r3 + 1;
481
482 if (wtm == wti) wtm = 1;
483 if (wto == wti)
484 wto = 1;
485 else if (wto == wtm)
486 wto = 1;
487
488 wi[dspno] = wti;
489 wm[dspno] = wtm;
490 wo[dspno] = wto;
491
492 ulxi[dspno] = x0 - r1; ulyi[dspno] = yd0 - r1; /* upper left corners */
493 ulxm[dspno] = x0 - r2; ulym[dspno] = yd0 - r2;
494 ulxo[dspno] = x0 - r3; ulyo[dspno] = yd0 - r3;
495
496
497 /* check, if ROI collapses to a point */
498
499
500 if ((r1 == 0) && (r2 == 0) && (r3 == 0))
501 {
502 countr[dspno] = 1;
503 XDrawPoint(mydisp[no],mwndw[dspno],gcdraw[dspno],ulxi[dspno],ulyi[dspno]);
504 }
505 else
506 {
507 countr[dspno] = 99;
508
509 XDrawSegments(mydisp[no],mwndw[dspno],gcdraw[dspno],
510 &roio[dspno][0],4);
511
512 XDrawArc(mydisp[no],mwndw[dspno],gcdraw[dspno],
513 ulxi[dspno],ulyi[dspno],wi[dspno],wi[dspno],ang1,ang2);
514 if (wm[dspno] != 1)
515 XDrawArc(mydisp[no],mwndw[dspno],gcdraw[dspno],
516 ulxm[dspno],ulym[dspno],wm[dspno],wm[dspno],ang1,ang2);
517 if (wo[dspno] != 1)
518 XDrawArc(mydisp[no],mwndw[dspno],gcdraw[dspno],
519 ulxo[dspno],ulyo[dspno],wo[dspno],wo[dspno],ang1,ang2);
520 }
521
522 if ((k = ididev[dspno].curswin) > -1)
523 {
524 conf = ididev [dspno].confptr;
525 mema = conf->memory[conf->memid];
526 conf = ididev [k].confptr;
527 memb = conf->memory[0]; /* single memory */
528 if (mema->load_dir == 0) yd0 = dysize - yd0; /* ycur <= dysize-ycur */
529
530 if (x0 < cursrad) /* extract 11x11 subwindow */
531 xy1off[0] = 0;
532 else
533 xy1off[0] = x0 - cursrad;
534 if (yd0 < cursrad)
535 xy1off[1] = 0;
536 else
537 xy1off[1] = yd0 - cursrad;
538 tmpx = 2*cursrad + 1;
539 if ((x0+tmpx) >= ididev[dspno].xsize)
540 xysiz[0] = ididev[dspno].xsize - x0;
541 else
542 xysiz[0] = tmpx;
543 if ((yd0+tmpx) >= dysize)
544 xysiz[1] = dysize - yd0;
545 else
546 xysiz[1] = tmpx;
547
548 copy_mem(dspno,mema,xy1off,memb,xy2off,xysiz,zoomf);
549 smv(2,k,memb,0,memb->xscroll,memb->yscroll,memb->xsize,memb->ysize,0,0);
550 zoomcross[0].x1 = 61;
551 zoomcross[0].y1 = 90;
552 zoomcross[0].x2 = 120;
553 zoomcross[0].y2 = 90;
554 zoomcross[1].x1 = 90;
555 zoomcross[1].y1 = 61;
556 zoomcross[1].x2 = 90;
557 zoomcross[1].y2 = 120;
558 XDrawSegments(mydisp[ididev[k].screen],mwndw[k],gcima[k],
559 zoomcross,2);
560 zoomcross[0].x1 ++;
561 zoomcross[0].y1 ++;
562 zoomcross[0].x2 ++;
563 zoomcross[0].y2 ++;
564 zoomcross[1].x1 ++;
565 zoomcross[1].y1 ++;
566 zoomcross[1].x2 ++;
567 zoomcross[1].y2 ++;
568 XDrawSegments(mydisp[ididev[k].screen],mwndw[k],gcdraw[k],
569 zoomcross,2);
570 }
571 }
572
573 /*
574
575 */
576 /* ---- Destroy Xstructures ----------------------------------- */
577
578 void destroy(dspno,stri)
579 int dspno;
580 char *stri;
581
582 {
583 int i, no;
584
585 CONF_DATA *conf;
586 MEM_DATA *mem;
587
588
589
590 no = ididev[dspno].screen;
591 if (*stri == 'h') /* hardcopy stuff */
592 XDestroyImage(hcopy[dspno]);
593
594 else if (*stri == 'a') /* alpha memory stuff */
595 {
596 XFreeGC(mydisp[no],gcalph[dspno]);
597 XDestroyWindow(mydisp[no],alphwnd[dspno]);
598 }
599
600 else if (*stri == 'l') /* LUT bar stuff */
601 {
602 XDestroyImage(lutxima[dspno]);
603 XFreeGC(mydisp[no],gclut[dspno]);
604 XDestroyWindow(mydisp[no],lutwnd[dspno]);
605 }
606
607 else if (*stri == 'm') /* all memories in configuration */
608 {
609 conf = ididev[dspno].confptr;
610
611 for (i=0; i<conf->nmem; i++)
612 {
613 mem = conf->memory[i];
614 if (mem->mmbm != (char *) 0)
615 {
616 if (mem->pixmap == 1) XFreePixmap(mydisp[no],mxpix[dspno][i]);
617 XDestroyImage(mxima[dspno][i]);
618 }
619 }
620 }
621
622 else if (*stri == 'd') /* main display stuff */
623 {
624 XFreeGC(mydisp[no],gcdraw[dspno]);
625 XFreeGC(mydisp[no],gcima[dspno]);
626 XDestroyWindow(mydisp[no],mwndw[dspno]);
627 }
628
629 }
630
631 /*
632
633 */
634
635 /* ---- process Expose events ----------------------------------- */
636
637 int exposed(wstno,dispno)
638 int wstno, dispno;
639
640 {
641 int dspno, nk, k, i ;
642 int oldw, oldh;
643
644 MEM_DATA *mem;
645 CONF_DATA *conf;
646 INTBAR *bar;
647
648
649 /* process an Expose event for single screen + display window */
650
651 if (wstno >= 0)
652 {
653 cle_events: /* get rid of all Expose events */
654 k = XCheckTypedWindowEvent
655 (mydisp[wstno],mwndw[dispno],Expose,&myevent);
656 if (k != 0) goto cle_events;
657
658 bar = ididev[dispno].bar;
659 if (bar != 0) /* process color bar */
660 {
661 if (bar->wp != 0)
662 idi_putimage(mydisp[wstno],lutwnd[dispno],gclut[dispno],
663 lutxima[dispno],0,0,0,0,bar->xsize,bar->ysize);
664 }
665 conf = ididev[dispno].confptr;
666
667 for (i=0; i<conf->nmem; i++)
668 {
669 mem = conf->memory[i];
670 if (mem->visibility == 1)
671 {
672 allrefr(dispno,mem,i,1); /* refresh memory */
673 if ( (ididev[dispno].alpno >= 90) && (conf->overlay != i) )
674 alprfr(dispno,conf->alpmem[i]); /* refresh alpha memory */
675 }
676 }
677 return II_SUCCESS;
678 }
679
680
681 /* test for all screens + display/graphic windows
682 if an Expose or ConfigureNotify event occurred */
683
684 for (nk=0; nk<MAX_WST; nk++)
685 {
686 if (Xworkst[nk].name[0] != '\0')
687 {
688 for (dspno=0; dspno<MAX_DEV; dspno++)
689 {
690 if (ididev[dspno].devname[0] != '\0')
691 {
692 k = XCheckTypedWindowEvent
693 (mydisp[nk],mwndw[dspno],ConfigureNotify,&myevent);
694 if (k != 0)
695 { /* move on to last event */
696 clean_confev:
697 k = XCheckTypedWindowEvent
698 (mydisp[nk],mwndw[dspno],ConfigureNotify,&myevent);
699 if (k != 0) goto clean_confev;
700
701 oldw = ididev[dspno].xsize; /* to comapre size */
702 ididev[dspno].xsize = myevent.xconfigure.width;
703 oldh = ididev[dspno].ysize;
704 ididev[dspno].ysize =
705 myevent.xconfigure.height - ididev[dspno].alphy - 2;
706
707 if (ididev[dspno].hcopy != (char *) 0)
708 { /* see if we had a hardcopy */
709 destroy(dspno,"hcopy");
710 ididev[dspno].hcopy = (char *) 0;
711 }
712
713 conf = ididev[dspno].confptr;
714 mem = conf->memory[0];
715 if ((mem->xsize < ididev[dspno].xsize) ||
716 (mem->ysize < ididev[dspno].ysize))
717 {
718 for (i=0; i<conf->nmem; i++)
719 {
720 mem = conf->memory[i];
721 if (mem->mmbm != (char *) 0)
722 {
723 if (mem->pixmap == 1)
724 XFreePixmap(mydisp[nk],mxpix[dspno][i]);
725 XDestroyImage(mxima[dspno][i]);
726 mem->mmbm = (char *) 0;
727 }
728 mem->xsize = ididev[dspno].xsize;
729 mem->ysize = ididev[dspno].ysize;
730 }
731 }
732
733 bar = ididev[dspno].bar;
734 if (bar != 0)
735 {
736 if (bar->wp == 1) /* LUT bar already created */
737 {
738 oldw -=ididev[dspno].xsize;
739 oldh -=ididev[dspno].ysize;
740 if ((oldw != 0) || (oldh != 0))
741 {
742 destroy(dspno,"lutbar");
743 if (bar->vis == 1)
744 crelutbar(dspno,bar);
745 else
746 bar->wp = 0;
747 }
748 }
749 }
750
751 if (ididev[dspno].alpno >= 90)
752 {
753 XDestroyWindow(mydisp[nk],alphwnd[dspno]);
754 ididev[dspno].alphx = ididev[dspno].xsize - 2;
755
756 alphwnd[dspno] = XCreateSimpleWindow(mydisp[nk],
757 mwndw[dspno],0,ididev[dspno].ysize,
758 ididev[dspno].alphx,ididev[dspno].alphy,
759 1,Xworkst[nk].white,Xworkst[nk].black);
760 if (alphwnd[dspno] == 0) return(WINOTOPN);
761 XMapRaised (mydisp[nk],alphwnd[dspno]);
762 alprfr(dspno,conf->alpmem[conf->memid]); /* refresh alpha */
763 }
764 return II_SUCCESS;
765 }
766
767
768 k = XCheckTypedWindowEvent
769 (mydisp[nk],mwndw[dspno],Expose,&myevent);
770 if (k != 0)
771 { /* move on to last event */
772 clean_expev:
773 k = XCheckTypedWindowEvent
774 (mydisp[nk],mwndw[dspno],Expose,&myevent);
775 if (k != 0) goto clean_expev;
776
777 if (ididev[dspno].bar != 0) /* process color bar */
778 {
779 if (ididev[dspno].bar->wp != 0)
780 idi_putimage(mydisp[nk],lutwnd[dspno],gclut[dspno],
781 lutxima[dspno],0,0,0,0,
782 ididev[dspno].bar->xsize,
783 ididev[dspno].bar->ysize);
784 }
785 conf = ididev[dspno].confptr;
786
787 for (i=0; i<conf->nmem; i++)
788 {
789 mem = conf->memory[i];
790 if (mem->visibility == 1)
791 {
792 allrefr(dspno,mem,i,1); /* refresh memory */
793 if ( (ididev[dspno].alpno >= 90) &&
794 (conf->overlay != i) )
795 alprfr(dspno,conf->alpmem[i]); /* refresh alpha */
796 }
797 }
798 }
799 }
800 }
801 }
802 }
803 return II_SUCCESS;
804 }
805
806 /*
807
808 */
809
810 /* ---- process Exit button events ----------------------------------- */
811
812 int stopped(dspno)
813 int dspno;
814
815 {
816 int no, k;
817
818
819 /* process an Exit button event for single screen + display window */
820
821 no = ididev[dspno].screen;
822 k = XCheckTypedWindowEvent
823 (mydisp[no],mwndw[dspno],ButtonPress,&myevent);
824 if (k == 0) return(0);
825
826
827 cle_events: /* get rid of all Expose events */
828 k = XCheckTypedWindowEvent
829 (mydisp[no],mwndw[dspno],ButtonPress,&myevent);
830 if (k != 0) goto cle_events;
831
832 if (myevent.xbutton.button != 1) /* if button 2 or 3 */
833 return (1);
834 else
835 return (0);
836
837 }
838
839 /*
840
841 */
842
843 /* ---- get fonts --------------------------------------- */
844
845 int font_load(flag,no,fontno)
846 int flag, no, *fontno;
847
848 {
849 int fp, k, np, j, jj, tmpx;
850
851 XFontStruct *xfp;
852
853 char record[104];
854 static char *fonts1[4] = {"fixed",
855 "-Adobe-Helvetica-Bold-R-Normal--18-180-75-75-P-103-ISO8859-1",
856 "-Adobe-Helvetica-Bold-R-Normal--24-240-75-75-P-138-ISO8859-1",
857 "-Adobe-Symbol-Medium-R-Normal--2*"};
858 static char *fonts2[4] = {"fixed",
859 "-Adobe-Helvetica-Bold-R-Normal--1*",
860 "-Adobe-Helvetica-Bold-R-Normal--2*",
861 "-Adobe-Symbol-Medium-R-Normal--2*"};
862
863
864
865
866 xfp = (XFontStruct *) 0;
867 fp = CGN_OPEN("MID_WORK:x11fonts.dat",READ); /* first, try `own' Font file */
868 if (fp <0) /* open system Font file */
869 fp = CGN_OPEN("MID_SYSTAB:x11fonts.dat",READ);
870
871 jj = np = 0;
872
873 if (flag == 0)
874 { /* here to initialize Fonts for display */
875 myfont[no][3] = XLoadQueryFont(mydisp[no],fonts1[3]);
876 if (myfont[no][3] == xfp)
877 myfont[no][3] = XLoadQueryFont(mydisp[no],fonts2[3]);
878 if (myfont[no][3] != xfp)
879 fontno[3] = 2; /* special font set */
880 else
881 fontno[3] = -1; /* special font not found */
882
883
884 if (fp == -1)
885 {
886 for (k=0; k<3; k++) fontno[k] = -1;
887 (void) printf("Could not open Fonts file MID_SYSTAB:x11fonts.dat\n");
888 }
889
890 for (k=0; k<3; k++)
891 {
892 if (fontno[k] > 0) /* font no. explicitely given */
893 {
894 (void)osaseek(fp,0L,FILE_START); /* always rewind file */
895 for (j=0; j<fontno[k]; j++) /* and move to given record */
896 jj = osaread(fp,record,100);
897
898 fontno[k] = -1; /* init to wrong data */
899 if (jj > 5)
900 {
901 for (np=0; np<jj; np++)
902 {
903 if (record[np] == ':')
904 {
905 np += 2; /* point to font name string */
906 fontno[k] = 1; /* we found it! */
907 break; /* get out of loop */
908 }
909 }
910 }
911 }
912
913 if (fontno[k] == 1)
914 {
915 myfont[no][k] = XLoadQueryFont(mydisp[no],&record[np]);
916 if (myfont[no][k] == xfp) fontno[k] = -1;
917 }
918
919 if (fontno[k] < 1)
920 { /* try two different defaults */
921 myfont[no][k] = XLoadQueryFont(mydisp[no],fonts1[k]);
922 if (myfont[no][k] == xfp)
923 myfont[no][k] = XLoadQueryFont(mydisp[no],fonts2[k]);
924 if (myfont[no][k] != xfp) fontno[k] = 2; /* indicate success */
925 }
926 }
927
928 if (fp != -1) (void)osaclose(fp);
929
930 tmpx = 0;
931 if (fontno[2] < 0) tmpx |= 4;
932 if (fontno[1] < 0) tmpx |= 2;
933 if (fontno[0] < 0) tmpx |= 1;
934
935 if (tmpx != 0)
936 {
937 switch (tmpx)
938 {
939 case 7:
940 (void) printf("could not get any font...\n");
941 return (-1);
942
943 case 6:
944 myfont[no][2] = myfont[no][0];
945 myfont[no][1] = myfont[no][0];
946 break;
947
948 case 5:
949 myfont[no][2] = myfont[no][1];
950 myfont[no][0] = myfont[no][1];
951 break;
952
953 case 4:
954 myfont[no][2] = myfont[no][1];
955 break;
956
957 case 3:
958 myfont[no][1] = myfont[no][2];
959 myfont[no][0] = myfont[no][2];
960 break;
961
962 case 2:
963 myfont[no][1] = myfont[no][0];
964 break;
965
966 case 1:
967 myfont[no][0] = myfont[no][1];
968 }
969 }
970
971 if (fontno[3] < 0) myfont[no][3] = myfont[no][0];
972 }
973
974 else
975 { /* load new Font for Font #4 */
976 if (fp == -1)
977 {
978 (void) printf("Could not open Fonts file MID_SYSTAB:x11fonts.dat\n");
979 return (-1);
980 }
981
982 k = -fontno[0]; /* new Font no. */
983 if (k < 1) return (-2);
984
985 (void)osaseek(fp,0L,FILE_START); /* always rewind file */
986 for (j=0; j<k; j++) /* and move to given record */
987 jj = osaread(fp,record,100);
988
989 if (jj > 5)
990 {
991 for (np=0; np<jj; np++)
992 {
993 if (record[np] == ':')
994 {
995 np += 2; /* point to font name string */
996 break; /* get out of loop */
997 }
998 }
999 }
1000
1001 (void)osaclose(fp);
1002
1003 if (myfont[no][3] != xfp) /* last font was o.k. */
1004 XFreeFont(mydisp[no],myfont[no][3]); /* release old Font */
1005
1006 myfont[no][3] = XLoadQueryFont(mydisp[no],&record[np]);
1007 if (myfont[no][3] == xfp)
1008 { /* invalid font string ... */
1009 (void) printf("Could not load Font:\n%s\n",&record[np]);
1010 myfont[no][3] = XLoadQueryFont(mydisp[no],"fixed");
1011 (void) printf("Use Font `fixed' instead\n");
1012 }
1013 }
1014
1015 return (0);
1016 }
1017
1018 /*
1019
1020 */
1021
1022 /* ---- iconify (de-iconify) display window ----------------------------- */
1023
1024 void iconify(dspno,flag)
1025 int dspno, flag;
1026
1027 {
1028 int no;
1029
1030
1031 no = ididev[dspno].screen;
1032 XUnmapWindow(mydisp[no],mwndw[dspno]); /* unmap window */
1033
1034 if (flag == 1)
1035 xwmh.initial_state = IconicState;
1036 else
1037 xwmh.initial_state = NormalState;
1038
1039 XSetWMHints(mydisp[no],mwndw[dspno],&xwmh);
1040 XMapRaised (mydisp[no],mwndw[dspno]); /* map as icon or window */
1041 }
1042
1043 /*
1044
1045 */
1046
1047 /* ---- send an event to a window -------------------------------------*/
1048
1049 void send_event(dspno)
1050 int dspno;
1051
1052 {
1053 int no, evtype, reclen, ibuf[8], dysize;
1054 int delindx, epsi2;
1055 long int evmask;
1056 static int delay = 1000; /* in msecs */
1057
1058 float rbuf;
1059
1060 double dbuf;
1061
1062 char evbuf[44];
1063
1064
1065 read_auto_cursor:
1066 reclen = osaread(auto_cursor_fid,evbuf,42);
1067 if (evbuf[0] == '!')
1068 goto read_auto_cursor; /* skip comment lines */
1069
1070 if (reclen > 0)
1071 {
1072 no = CGN_CNVT(evbuf,1,8,ibuf,&rbuf,&dbuf);
1073 if (no > 0)
1074 {
1075 evtype = ibuf[0];
1076 if (evtype > -1) goto do_events; /* (-1) => stop auto_cursor */
1077 }
1078 }
1079
1080 else if (reclen < 0) /* EOF reached */
1081 {
1082 (void) osaseek(auto_cursor_fid,0L,FILE_START); /* rewind file */
1083 goto read_auto_cursor;
1084 }
1085
1086 else
1087 goto read_auto_cursor; /* nothing there, skip */
1088
1089
1090 /* here we are, if we want to get back into interactive cursor input */
1091
1092 osaclose(auto_cursor_fid);
1093 auto_cursor_fid = -1; /* stop automatic event generation */
1094 evtype = 0;
1095 no = 1;
1096
1097
1098 /* beware, X11 has 0,0 at top left corner...
1099 the epsi2 business is needed for the way `curmove' works ... */
1100
1101 do_events:
1102 dysize = ididev[dspno].ysize - 1;
1103 epsi2 = 2; /* has to be synchronized with `epsi2' in idiutil2.c */
1104
1105 if (evtype == 1)
1106 { /* send ENTER (left Mouse Button) */
1107 delindx = 3; /* index of delay value */
1108 myevent.type = ButtonPress;
1109 myevent.xbutton.x = ibuf[1] - epsi2;
1110 myevent.xbutton.y = dysize - ibuf[2] + epsi2;
1111 myevent.xbutton.button = 1;
1112 }
1113
1114 else if (evtype == 2)
1115 { /* send arrow key input (for 2. cursor) */
1116 delindx = 2; /* index of delay value */
1117 myevent.type = KeyPress;
1118 myevent.xkey.keycode = (unsigned int) (ibuf[1]+100); /* is an unsigned no. */
1119 }
1120
1121 else /* send EXIT (right Mouse Button) */
1122 {
1123 delindx = 1; /* index of delay value */
1124 myevent.type = ButtonPress;
1125 if (no > 2)
1126 {
1127 myevent.xbutton.x = ibuf[1] - epsi2;
1128 myevent.xbutton.y = dysize - ibuf[2] + epsi2;
1129 }
1130 else
1131 {
1132 myevent.xbutton.x = 10; /* arbitrary values */
1133 myevent.xbutton.y = 10;
1134 }
1135 myevent.xbutton.button = 3;
1136 }
1137
1138
1139 evmask = 0;
1140 no = ididev[dspno].screen;
1141 (void) XSendEvent(mydisp[no],mwndw[dspno],False,evmask,&myevent);
1142
1143 if (no > delindx) delay = ibuf[delindx];
1144 if (delay > 0) OSY_SLEEP(delay,1);
1145 }