Annotation of OpenXM_contrib2/asir2000/plot/ox_plot_xevent.c, Revision 1.4
1.2 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
47: *
1.4 ! takayama 48: * $OpenXM: OpenXM_contrib2/asir2000/plot/ox_plot_xevent.c,v 1.3 2000/08/22 05:04:31 noro Exp $
1.2 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52: #include "ox.h"
53: #include "ifplot.h"
54: #include "cursor.h"
55:
56: #ifdef ABS
57: #undef ABS
58: #define ABS(a) ((a)>0?(a):-(a))
59: #endif
60:
61: static char *dname;
62: static int remotes;
63: static int depth,scrn;
64:
65: extern jmp_buf ox_env;
66: static Widget toplevel;
67: static XtAppContext app_con;
68:
69: static int busy;
70:
71: static struct PlotResources {
72: Pixel ForePixel,BackPixel,DashPixel;
73: char *ForeName,*BackName,*DashName;
74: Boolean Reverse;
75: } PlotResources;
76:
77: #define forePixel PlotResources.ForePixel
78: #define backPixel PlotResources.BackPixel
79: #define dashPixel PlotResources.DashPixel
80: #define foreName PlotResources.ForeName
81: #define backName PlotResources.BackName
82: #define dashName PlotResources.DashName
83: #define reverse PlotResources.Reverse
84:
85: Cursor create_cursor();
86:
87: #define blackPixel BlackPixel(display,scrn)
88: #define whitePixel WhitePixel(display,scrn)
89:
90: #define LABELWIDTH 150
91:
92: process_xevent() {
93: XEvent ev;
94:
95: while ( XPending(display) ) {
96: XtAppNextEvent(app_con,&ev);
97: XtDispatchEvent(&ev);
98: }
99: }
100:
101: /* event handlers */
102:
103: static POINT spos,cpos;
104:
105: void press(w,can,ev)
106: Widget w;
107: struct canvas *can;
108: XButtonEvent *ev;
109: {
110: POINT p;
111:
112: switch ( ev->button ) {
113: case Button1:
114: XC(spos) = ev->x; YC(spos) = ev->y; cpos = spos; break;
115: case Button3:
116: XC(p) = ev->x; YC(p) = ev->y; draw_coord(can,&p); break;
117: default:
118: break;
119: }
120: }
121:
122: void motion(w,can,ev)
123: Widget w;
124: struct canvas *can;
125: XMotionEvent *ev;
126: {
127:
128: POINT o,p;
129:
130: if ( ev->state & Button1Mask ) {
131: o = cpos; XC(cpos) = ev->x; YC(cpos) = ev->y;
132: draw_frame(can->window,spos,o,cpos);
133: } else if ( ev->state & Button3Mask ) {
134: XC(p) = ev->x; YC(p) = ev->y;
135: draw_coord(can,p);
136: }
137: }
138:
139: void release(w,can,ev)
140: Widget w;
141: struct canvas *can;
142: XButtonEvent *ev;
143: {
144: POINT e;
145:
146: switch ( ev->button ) {
147: case Button1:
148: e.x = ev->x; e.y = ev->y;
149: draw_frame0(can->window,spos,e);
150: if ( !busy ) {
151: if ( can->mode == MODE_PLOT )
152: plot_resize(can,spos,e);
153: else
154: ifplot_resize(can,spos,e);
155: }
156: break;
157: default:
158: break;
159: }
160: }
161:
162: void structure(w,can,ev)
163: Widget w;
164: struct canvas *can;
165: XEvent *ev;
166: {
167: switch ( ev->xany.type ) {
168: case Expose:
169: if ( !ev->xexpose.count )
170: redraw_canvas(can);
171: break;
172: case ConfigureNotify:
173: redraw_canvas(can); break;
174: default:
175: break;
176: }
177: }
178:
179: static int lindex;
180:
181: void lpress(w,can,ev)
182: Widget w;
183: struct canvas *can;
184: XButtonEvent *ev;
185: {
186: lindex = (can->height-ev->y)/(can->height/can->nzstep);
187: draw_level(can,lindex,hlGC);
188: }
189:
190: void jumpproc(w,can,percent)
191: Widget w;
192: struct canvas *can;
193: float *percent;
194: {
195: int index;
196:
197: index = can->nzstep * (1.0-*percent);
198: if ( index == lindex )
199: return;
200: if ( lindex >= 0 )
201: draw_level(can,lindex,drawGC);
202: lindex = index;
203: draw_level(can,lindex,hlGC);
204: }
205:
206: void jumpproc_m(w,can,percent)
207: Widget w;
208: struct canvas *can;
209: float *percent;
210: {
211: int index;
212:
213: index = can->nzstep * (1.0-*percent);
214: if ( index != lindex ) {
215: draw_level(can,lindex,drawGC);
216: draw_level(can,lindex,hlGC);
217: }
218: }
219:
220: void lrelease(w,can,ev)
221: Widget w;
222: struct canvas *can;
223: XButtonEvent *ev;
224: {
225: draw_level(can,lindex,drawGC); lindex = -1;
226: }
227:
228: void lrelease_m(w,can,ev)
229: Widget w;
230: struct canvas *can;
231: XButtonEvent *ev;
232: {
233: lindex = -1;
234: }
235:
236: draw_level(can,index,gc)
237: struct canvas *can;
238: int index;
239: GC gc;
240: {
241: Pixmap pix;
242: struct pa *pa;
243: int i,len;
244: POINT *p;
245: Arg arg[2];
246: char buf[BUFSIZ];
247:
248: if ( busy || can->wide || index < 0 || index > can->nzstep )
249: return;
250: pix = can->pix; pa = &can->pa[index]; len = pa->length; p = pa->pos;
251: for ( i = 0; i < len; i++ )
252: XDrawPoint(display,pix,gc,p[i].x,p[i].y);
253: sprintf(buf,"level:%g",can->zmin+(can->zmax-can->zmin)*index/can->nzstep);
254: XtSetArg(arg[0],XtNlabel,buf); XtSetArg(arg[1],XtNwidth,LABELWIDTH);
255: XtSetValues(can->level,arg,2);
256: copy_to_canvas(can);
257: }
258:
259: draw_frame(window,spos,opos,epos)
260: Window window;
261: POINT spos,opos,epos;
262: {
263: if ( XC(opos) != XC(epos) || YC(opos) != YC(epos) )
264: draw_frame0(window,spos,opos);
265: draw_frame0(window,spos,epos);
266: }
267:
268: draw_frame0(window,spos,epos)
269: Window window;
270: POINT spos,epos;
271: {
272: int ulx,uly,w,h;
273:
274: ulx = MIN(XC(spos),XC(epos)); uly = MIN(YC(spos),YC(epos));
275: w = ABS(XC(spos)-XC(epos)); h = ABS(YC(spos)-YC(epos));
276: if ( !w || !h )
277: return;
278: XDrawRectangle(display,window,xorGC,ulx,uly,w,h);
279: XFlush(display);
280: }
281:
282: draw_coord(can,pos)
283: struct canvas *can;
284: POINT pos;
285: {
286: char buf[BUFSIZ];
287: Arg arg[2];
288: double x,y,xmin,ymax,dx,dy;
289:
290: if ( can->wide ) {
291: dx = 10*(can->xmax-can->xmin); dy = 10*(can->ymax-can->ymin);
292: xmin = (can->xmax+can->xmin-dx)/2;
293: ymax = (can->ymax+can->ymin+dy)/2;
294: } else {
295: dx = can->xmax-can->xmin; dy = can->ymax-can->ymin;
296: xmin = can->xmin; ymax = can->ymax;
297: }
298: x = xmin+XC(pos)*dx/can->width;
299: y = ymax-YC(pos)*dy/can->height;
300: sprintf(buf,"%s:%g",can->vx?can->vx->name:"horiz",x);
301: XtSetArg(arg[0],XtNlabel,buf); XtSetArg(arg[1],XtNwidth,LABELWIDTH);
302: XtSetValues(can->xcoord,arg,2);
303: sprintf(buf,"%s:%g",can->vy?can->vy->name:"vert",y);
304: XtSetArg(arg[0],XtNlabel,buf); XtSetArg(arg[1],XtNwidth,LABELWIDTH);
305: XtSetValues(can->ycoord,arg,2);
306: }
307:
308: redraw_canvas(can)
309: struct canvas *can;
310: {
311: if ( can->wide )
312: draw_wideframe(can);
313: else
314: copy_to_canvas(can);
315: }
316:
317: search_canvas()
318: {
319: int i;
320:
321: for ( i = 0; i < MAXCANVAS; i++ )
322: if ( !canvas[i] ) {
323: canvas[i] = (struct canvas *)MALLOC(sizeof(struct canvas));
324: canvas[i]->index = i; return i;
325: }
326: }
327:
328: search_active_canvas()
329: {
330: int i;
331:
332: for ( i = 0; i < MAXCANVAS; i++ )
333: if ( canvas[i] )
334: return i;
335: return -1;
336: }
337:
1.4 ! takayama 338:
! 339: #define PRINT_XOFFSET 100
! 340: #define PRINT_YOFFSET 100
! 341: static struct canvas *Can;
! 342: /* void print_canvas(Widget w,struct canvas *can, XtPointer calldata); */
! 343: static void output_to_file(Widget , XtPointer, XtPointer );
! 344: static void output_to_ps_printer(Widget , XtPointer, XtPointer );
! 345: static void cancel_output_to_file(Widget , XtPointer,XtPointer);
! 346: static void generate_psfile(struct canvas *can, FILE *fp);
! 347: static Widget PrintDialog;
! 348: static Widget PrintDialog_lp;
! 349: static Widget W;
! 350:
! 351: static void print_canvas(w,can,calldata)
! 352: Widget w;
! 353: struct canvas *can;
! 354: XtPointer calldata;
! 355: {
! 356: Widget fshell,fdialog;
! 357: extern struct canvas *Can;
! 358: extern Widget W;
! 359: static void output_to_printer();
! 360: static void print_canvas_to_file();
! 361:
! 362: W = w;
! 363: Can = can;
! 364: create_popup(can->shell,"Print/Output PS file","",&fshell,&fdialog);
! 365: XawDialogAddButton(fdialog,"print",output_to_printer,w);
! 366: XawDialogAddButton(fdialog,"Output PS file",print_canvas_to_file,w);
! 367: XawDialogAddButton(fdialog,"cancel",cancel_output_to_file,w);
! 368: XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
! 369: }
! 370: static void print_canvas_to_file(w,can,calldata)
! 371: Widget w;
! 372: struct canvas *can;
! 373: XtPointer calldata;
! 374: {
! 375: FILE *fp;
! 376: Arg arg[10];
! 377: int n;
! 378: char psfile[50];
! 379: Widget fshell,fdialog;
! 380: extern struct canvas *Can;
! 381: extern Widget PrintDialog;
! 382:
! 383: w = W;
! 384: can = Can;
! 385: strcpy(psfile,"ox_plot.eps");
! 386: create_popup(can->shell,"Output as PS file",psfile,&fshell,&fdialog);
! 387: n = 0;
! 388: XtSetArg(arg[n], XtNlabel, "File : "); n++;
! 389: XtSetArg(arg[n], XtNvalue, psfile); n++;
! 390: XtSetValues(fdialog,arg,n);
! 391: XawDialogAddButton(fdialog,"output to file",output_to_file,w);
! 392: XawDialogAddButton(fdialog,"cancel",cancel_output_to_file,w);
! 393: PrintDialog = fdialog;
! 394: XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
! 395: }
! 396: static void output_to_printer(w,can,calldata)
! 397: Widget w;
! 398: struct canvas *can;
! 399: XtPointer calldata;
! 400: {
! 401: FILE *fp;
! 402: Arg arg[10];
! 403: int n;
! 404: char psfile[50];
! 405: Widget fshell,fdialog;
! 406: extern struct canvas *Can;
! 407: extern Widget PrintDialog_lp;
! 408:
! 409: w = W;
! 410: can = Can;
! 411: strcpy(psfile,"xerox");
! 412: create_popup(can->shell,"Output PS file to printer",psfile,&fshell,&fdialog);
! 413: n = 0;
! 414: XtSetArg(arg[n], XtNlabel, "PS Printer Name : "); n++;
! 415: XtSetArg(arg[n], XtNvalue, psfile); n++;
! 416: XtSetValues(fdialog,arg,n);
! 417: XawDialogAddButton(fdialog,"output to PS printer",output_to_ps_printer,w);
! 418: XawDialogAddButton(fdialog,"cancel",cancel_output_to_file,w);
! 419: PrintDialog_lp = fdialog;
! 420: XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
! 421: }
! 422:
! 423: static void cancel_output_to_file(w,fbutton,call)
! 424: Widget w;
! 425: XtPointer fbutton, call;
! 426: {
! 427: Widget shell = XtParent(XtParent(w));
! 428: XtPopdown(shell); XtDestroyWidget(shell);
! 429: XtSetSensitive(fbutton,True);
! 430: }
! 431:
! 432: static void output_to_file(w,fbutton,call)
! 433: Widget w;
! 434: XtPointer fbutton, call;
! 435: {
! 436: char *fname;
! 437: FILE *fp;
! 438: extern struct canvas *Can;
! 439: extern Widget PrintDialog;
! 440: Widget shell = XtParent(XtParent(w));
! 441:
! 442: fname = XawDialogGetValueString(PrintDialog);
! 443: fprintf(stderr,"fname=%s\n",fname); fflush(NULL);
! 444: fp = fopen(fname,"w");
! 445: if (fp == NULL) {
! 446: warning(Can,"Could not open the output file.");
! 447: }else{
! 448: generate_psfile(Can,fp);
! 449: fclose(fp);
! 450: }
! 451:
! 452: XtPopdown(shell); XtDestroyWidget(shell);
! 453: XtSetSensitive(fbutton,True);
! 454: }
! 455:
! 456: static void output_to_ps_printer(w,fbutton,call)
! 457: Widget w;
! 458: XtPointer fbutton, call;
! 459: {
! 460: char *printerName;
! 461: FILE *fp;
! 462: extern struct canvas *Can;
! 463: extern Widget PrintDialog_lp;
! 464: char fname[256];
! 465: char cmd[512];
! 466: static int id = 0;
! 467: Widget shell = XtParent(XtParent(w));
! 468:
! 469: sprintf(fname,"/tmp/ox_plot_%d.eps",(int) getpid(),id++);
! 470:
! 471: printerName = XawDialogGetValueString(PrintDialog_lp);
! 472: fprintf(stderr,"printerName=%s\n",printerName); fflush(NULL);
! 473: fp = fopen(fname,"w");
! 474: if (fp == NULL) {
! 475: warning(Can,"Could not open the output file.");
! 476: }else{
! 477: generate_psfile(Can,fp);
! 478: fclose(fp);
! 479: }
! 480:
! 481: sprintf(cmd,"lpr -P%s %s",printerName,fname);
! 482: if (system(cmd)) {
! 483: warning(Can,"Unknown printer?");
! 484: }
! 485: sprintf(cmd,"rm -f %s",fname);
! 486: system(cmd);
! 487: XtPopdown(shell); XtDestroyWidget(shell);
! 488: XtSetSensitive(fbutton,True);
! 489: }
! 490:
! 491:
! 492: /* test sequence
! 493: ox_launch(0,"ox_plot");
! 494: ifplot(x^2-y^3);
! 495: drawcircle(0,0,100,0,0);
! 496: */
! 497: static void generate_psfile(can,fp)
! 498: struct canvas *can;
! 499: FILE *fp;
! 500: {
! 501: int x,y;
! 502: XImage *image;
! 503: int color;
! 504: fprintf(stderr,"generate_psfile\n");
! 505: if ( display ) {
! 506: fprintf(stderr,"generate_psfile: output to a file.\n");
! 507: fprintf(fp,"%%!\n");
! 508: fprintf(fp,"%%%%BoundingBox: %d %d %d %d \n",PRINT_XOFFSET,PRINT_YOFFSET,
! 509: PRINT_XOFFSET+can->width+1,PRINT_YOFFSET+can->height+1);
! 510: fprintf(fp,"%%This is generated by ifplot\n");
! 511: fprintf(fp,"/ifplot_putpixel { /oxcolor 2 1 roll def \n");
! 512: fprintf(fp," /yyy 2 1 roll def /xxx 2 1 roll def \n");
! 513: fprintf(fp," gsave newpath xxx yyy .5 0 360 arc \n");
! 514: fprintf(fp," .3 oxcolor .04 mul add setgray fill grestore \n");
! 515: fprintf(fp,"} def \n");
! 516: fprintf(fp,"%% newpath .... stroke \n");
! 517: image = XGetImage(display,can->pix,
! 518: 0,0,can->width,can->height,-1,ZPixmap);
! 519: for (x=0; x<can->width; x++) {
! 520: for (y=0; y<can->height; y++) {
! 521: if ((color = (int) XGetPixel(image,x,y)) == 1) {
! 522: /* white background */
! 523: }else {
! 524: fprintf(fp,"%d %d %d ifplot_putpixel \n",PRINT_XOFFSET+x,
! 525: PRINT_YOFFSET+can->height-y,color);
! 526: }
! 527: }
! 528: }
! 529: /* pline(display,can,can->window); */
! 530: fprintf(fp,"showpage \n");
! 531: }else{
! 532: fprintf(stderr,"Cannot print on this system\n");
! 533: }
! 534: fflush(NULL);
! 535: }
! 536:
1.1 noro 537: void destroy_canvas(w,can,calldata)
538: Widget w;
539: struct canvas *can;
540: XtPointer calldata;
541: {
542: XtPopdown(can->shell);
543: XtDestroyWidget(can->shell);
544: XFlush(display);
545: if ( can == current_can ) {
546: reset_busy(can); current_can = 0;
547: }
548: canvas[can->index] = 0;
549: }
550:
551: void precise_canvas(w,can,calldata)
552: Widget w;
553: struct canvas *can;
554: XtPointer calldata;
555: {
556: if ( can->precise )
557: can->precise = 0;
558: else
559: can->precise = 1;
560: }
561:
562: void wide_canvas(w,can,calldata)
563: Widget w;
564: struct canvas *can;
565: XtPointer calldata;
566: {
567: if ( can->wide ) {
568: can->wide = 0; copy_to_canvas(can);
569: } else {
570: can->wide = 1; draw_wideframe(can);
571: }
572: }
573:
574: void noaxis_canvas(w,can,calldata)
575: Widget w;
576: struct canvas *can;
577: XtPointer calldata;
578: {
579: if ( can->noaxis )
580: can->noaxis = 0;
581: else
582: can->noaxis = 1;
583: if ( can->wide )
584: draw_wideframe(can);
585: else
586: copy_to_canvas(can);
587: }
588:
589: toggle_button(w,flag)
590: Widget w;
591: int flag;
592: {
593: Arg arg[2];
594:
595: if ( flag ) {
596: XtSetArg(arg[0],XtNforeground,backPixel);
597: XtSetArg(arg[1],XtNbackground,forePixel);
598: } else {
599: XtSetArg(arg[0],XtNforeground,forePixel);
600: XtSetArg(arg[1],XtNbackground,backPixel);
601: }
602: XtSetValues(w,arg,2); XFlush(display);
603: }
604:
605: draw_wideframe(can)
606: struct canvas *can;
607: {
608: struct canvas fakecan;
609: double xmin,xmax,ymin,ymax,xmid,ymid,dx,dy;
610: POINT s,e;
611:
612: fakecan = *can;
613: dx = 10*(can->xmax-can->xmin); dy = 10*(can->ymax-can->ymin);
614: xmid = (can->xmax+can->xmin)/2; ymid = (can->ymax+can->ymin)/2;
615:
616: fakecan.xmin = xmid-dx/2; fakecan.xmax = xmid+dx/2;
617: fakecan.ymin = ymid-dy/2; fakecan.ymax = ymid+dy/2;
618:
619: XFillRectangle(display,can->window,clearGC,
620: 0,0,can->width,can->height);
621: pline(display,&fakecan,can->window);
622: XC(s) = can->width*9/20; YC(s) = can->height*9/20;
623: XC(e) = can->width*11/20; YC(e) = can->height*11/20;
624: draw_frame0(can->window,s,e);
625: }
626:
627: create_popup(parent,name,str,shell,dialog)
628: Widget parent;
629: char *name,*str;
630: Widget *shell,*dialog;
631: {
632: Arg arg[3];
633: Position x,y;
634:
635: XtTranslateCoords(parent,0,0,&x,&y);
636: XtSetArg(arg[0],XtNx,x); XtSetArg(arg[1],XtNy,y);
637: *shell = XtCreatePopupShell(name,transientShellWidgetClass,parent,arg,2);
638: XtSetArg(arg[0],XtNlabel,str);
639: *dialog = XtCreateManagedWidget("dialog",dialogWidgetClass,*shell,arg,1);
640: }
641:
642: warning(can,s)
643: struct canvas *can;
644: char *s;
645: {
646: void popdown_warning();
647: Widget warnshell,warndialog;
648: Position x,y;
649: Arg arg[3];
650:
651: if ( !can->shell )
652: return;
653: create_popup(can->shell,"warning",s,&warnshell,&warndialog);
654: XawDialogAddButton(warndialog,"dismiss",popdown_warning,warnshell);
655: XtPopup(warnshell,XtGrabNone);
656: }
657:
658: void popdown_warning(w,client,call)
659: Widget w;
660: XtPointer client,call;
661: {
662: XtPopdown(client); XtDestroyWidget(client);
663: }
664:
665: void show_formula(w,can,calldata)
666: Widget w;
667: struct canvas *can;
668: XtPointer calldata;
669: {
670: void popdown_formula();
671: Widget fshell,fdialog;
672: char buf[BUFSIZ];
673:
674: soutput_init(buf); sprintexpr(CO,(Obj)can->formula);
675: create_popup(can->shell,"formula",buf,&fshell,&fdialog);
676: XawDialogAddButton(fdialog,"dismiss",popdown_formula,w);
677: XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
678: }
679:
680: void popdown_formula(w,fbutton,call)
681: Widget w,fbutton;
682: XtPointer call;
683: {
684: Widget shell = XtParent(XtParent(w));
685: XtPopdown(shell); XtDestroyWidget(shell);
686: XtSetSensitive(fbutton,True);
687: }
688:
689: #define NormalSelection ButtonPressMask|ButtonReleaseMask|Button1MotionMask|Button3MotionMask|StructureNotifyMask| ExposureMask
690:
691: create_canvas(can)
692: struct canvas *can;
693: {
694: XEvent event;
695: Widget box,frame,commands,
1.4 ! takayama 696: coords,quit,print,wide,precise,canvas,formula;
1.1 noro 697: Window window;
698: Pixmap pix;
699: int i,width,height;
700: Arg arg[6];
701: char buf[BUFSIZ];
702:
703: width = can->width; height = can->height;
704:
705: sprintf(buf,"%s : %d/%d", can->wname?can->wname:"Plot",
706: remotes,can->index);
707: XtSetArg(arg[0],XtNiconName,buf);
708: can->shell =
709: XtCreatePopupShell("shell",topLevelShellWidgetClass,toplevel,arg,1);
710:
711: XtSetArg(arg[0],XtNhSpace,0);
712: XtSetArg(arg[1],XtNvSpace,0);
713: XtSetArg(arg[2],XtNborderWidth,0);
714: box = XtCreateManagedWidget("box",boxWidgetClass,can->shell,arg,3);
715:
716: frame = XtCreateManagedWidget("form",formWidgetClass,box,NULL,0);
717:
718: XtSetArg(arg[0],XtNorientation,XtorientHorizontal);
719: XtSetArg(arg[1],XtNborderWidth,0);
720: commands = XtCreateManagedWidget("commands",boxWidgetClass,frame,arg,2);
721:
722: quit = XtCreateManagedWidget("quit",commandWidgetClass,commands,NULL,0);
723: XtAddCallback(quit,XtNcallback,destroy_canvas,can);
1.4 ! takayama 724: print = XtCreateManagedWidget("print",commandWidgetClass,commands,NULL,0);
! 725: XtAddCallback(print,XtNcallback,print_canvas,can);
1.1 noro 726: can->wideb = wide =
727: XtCreateManagedWidget("wide",toggleWidgetClass,commands,NULL,0);
728: XtAddCallback(wide,XtNcallback,wide_canvas,can);
729: can->preciseb = precise =
730: XtCreateManagedWidget("precise",toggleWidgetClass,commands,NULL,0);
731: XtAddCallback(precise,XtNcallback,precise_canvas,can);
732: formula =
733: XtCreateManagedWidget("formula",commandWidgetClass,commands,NULL,0);
734: XtAddCallback(formula,XtNcallback,show_formula,can);
735: can->noaxisb =
736: XtCreateManagedWidget("noaxis",toggleWidgetClass,commands,NULL,0);
737: XtAddCallback(can->noaxisb,XtNcallback,noaxis_canvas,can);
738:
739: XtSetArg(arg[0],XtNfromVert,commands);
740: XtSetArg(arg[1],XtNwidth,width);
741: XtSetArg(arg[2],XtNheight,height);
742: canvas = XtCreateManagedWidget("canvas",simpleWidgetClass,frame,arg,3);
743:
744: XtSetArg(arg[0],XtNfromVert,canvas);
745: XtSetArg(arg[1],XtNheight,5);
746: XtSetArg(arg[2],XtNwidth,width);
747: XtSetArg(arg[3],XtNorientation,XtorientHorizontal);
748: XtSetArg(arg[4],XtNsensitive,False);
749: can->xdone =
750: XtCreateManagedWidget("xdone",scrollbarWidgetClass,frame,arg,5);
751:
752: XtSetArg(arg[0],XtNfromHoriz,canvas);
753: XtSetArg(arg[1],XtNfromVert,commands);
754: XtSetArg(arg[2],XtNwidth,5);
755: XtSetArg(arg[3],XtNheight,height);
756: XtSetArg(arg[4],XtNorientation,XtorientVertical);
757: XtSetArg(arg[5],XtNsensitive,False);
758: can->ydone =
759: XtCreateManagedWidget("ydone",scrollbarWidgetClass,frame,arg,6);
760:
761: XtSetArg(arg[0],XtNfromVert,can->xdone);
762: XtSetArg(arg[1],XtNorientation,XtorientHorizontal);
763: XtSetArg(arg[2],XtNborderWidth,0);
764: coords = XtCreateManagedWidget("coords",boxWidgetClass,frame,arg,3);
765:
766: XtSetArg(arg[0],XtNwidth,LABELWIDTH);
767: can->xcoord = XtCreateManagedWidget("xcoord",labelWidgetClass,coords,arg,1);
768: XtSetArg(arg[0],XtNwidth,LABELWIDTH);
769: can->ycoord = XtCreateManagedWidget("ycoord",labelWidgetClass,coords,arg,1);
770:
771: XtAddEventHandler(canvas,ButtonPressMask,False,press,can);
772: XtAddEventHandler(canvas,ButtonReleaseMask,False,release,can);
773: XtAddEventHandler(canvas,Button1MotionMask,False,motion,can);
774: XtAddEventHandler(canvas,Button3MotionMask,False,motion,can);
775: XtAddEventHandler(canvas,StructureNotifyMask,False,structure,can);
776: XtAddEventHandler(canvas,ExposureMask,False,structure,can);
777:
778: if ( can->mode == MODE_CONPLOT ) {
779: Widget scale;
780:
781: XtSetArg(arg[0],XtNwidth,LABELWIDTH);
782: can->level = XtCreateManagedWidget("level",labelWidgetClass,
783: commands,arg,1);
784:
785: XtSetArg(arg[0],XtNsensitive,True);
786: XtSetValues(can->ydone,arg,1);
787: if ( depth >= 2 ) {
788: XtAddCallback(can->ydone,XtNjumpProc,jumpproc,can);
789: XtAddEventHandler(can->ydone,ButtonReleaseMask,False,lrelease,can);
790: } else {
791: XtAddCallback(can->ydone,XtNjumpProc,jumpproc_m,can);
792: XtAddEventHandler(can->ydone,ButtonReleaseMask,False,lrelease_m,can);
793: }
794: }
795: if ( can->mode != MODE_IFPLOT || !qpcheck((Obj)can->formula) )
796: XtSetSensitive(precise,False);
797: XtPopup(can->shell,XtGrabNone);
798:
799: window = can->window = XtWindow(canvas);
800: pix = can->pix = XCreatePixmap(display,window,width,height,depth);
801: XFillRectangle(display,pix,clearGC,0,0,width,height);
802: XDefineCursor(display,window,normalcur);
803: XFlush(display);
804: current_can = can;
805: }
806:
807: alloc_pixmap(can)
808: struct canvas *can;
809: {
810: can->pix = XCreatePixmap(display,can->window,
811: can->width,can->height,depth);
812: XFillRectangle(display,can->pix,clearGC,0,0,can->width,can->height);
813: }
814:
815: static XrmOptionDescRec options[] = {
816: {"-reverse","*reverse",XrmoptionNoArg,"on"},
817: {"-fg","*foreground",XrmoptionSepArg,NULL},
818: {"-bg","*background",XrmoptionSepArg,NULL},
819: };
820:
821: #define offset(name) XtOffset(struct PlotResources *,name)
822:
823: static XtResource resources[] = {
824: {"reverse","Reverse",XtRBoolean,sizeof(Boolean),
825: offset(Reverse),XtRBoolean,&reverse},
826: {"foreground","Foreground",XtRString,sizeof(char *),
827: offset(ForeName),XtRString,NULL},
828: {"foreground","Foreground",XtRPixel,sizeof(Pixel),
829: offset(ForePixel),XtRPixel,(XtPointer)&forePixel},
830: {"background","Background",XtRString,sizeof(char *),
831: offset(BackName),XtRString,NULL},
832: {"background","Background",XtRPixel,sizeof(Pixel),
833: offset(BackPixel),XtRPixel,(XtPointer)&backPixel},
834: {"dash","Dash",XtRString,sizeof(char *),
835: offset(DashName),XtRString,NULL},
836: {"dash","Dash",XtRPixel,sizeof(Pixel),
837: offset(DashPixel),XtRPixel,(XtPointer)&dashPixel},
838: };
839:
840: init_plot_display(argc,argv)
841: int argc;
842: char **argv;
843: {
844: int ac;
845: char **av;
846: unsigned int tmp;
847:
848: for ( ac = argc, av = argv; ac; ac--, av++ )
849: if ( index(*av,':') )
850: dname = *av;
851: XtToolkitInitialize();
852: app_con = XtCreateApplicationContext();
853: display = XtOpenDisplay(app_con,dname,"plot","Plot",
854: options,XtNumber(options),&argc,argv);
855: if ( !display ) {
856: fprintf(stderr,"Can't open display\n");
857: exit(1);
858: }
859: toplevel = XtAppCreateShell(0,"Plot",applicationShellWidgetClass,
860: display,0,0);
861:
862: forePixel = blackPixel; backPixel = whitePixel;
863: dashPixel = blackPixel;
864: XtGetApplicationResources(toplevel,&PlotResources,
865: resources,XtNumber(resources),NULL,0);
866: display = XtDisplay(toplevel);
867: scrn = DefaultScreen(display);
868: depth = DefaultDepth(display,scrn);
869: rootwin = RootWindow(display,scrn);
870:
871: if ( reverse ) {
872: tmp = forePixel; forePixel = backPixel; backPixel = tmp;
873: }
874:
875: create_gc();
876: create_font();
877: create_cursors();
878: }
879:
880: static char *scalefont = "*-8-80-*";
881:
882: create_font() {
883: Font sfid;
884:
885: sfid = XLoadFont(display,scalefont);
886: sffs = XQueryFont(display,sfid);
887: XSetFont(display,scaleGC,sfid);
888: }
889:
890: create_gc() {
891: static XColor color = {0,0x0,0x0,0x0,DoRed|DoGreen|DoBlue,0};
892: int i,b,step;
893:
894: drawGC = XCreateGC(display,rootwin,0,NULL);
895: dashGC = XCreateGC(display,rootwin,0,NULL);
896: hlGC = XCreateGC(display,rootwin,0,NULL);
897: clearGC = XCreateGC(display,rootwin,0,NULL);
898: scaleGC = XCreateGC(display,rootwin,0,NULL);
899: xorGC = XCreateGC(display,rootwin,0,NULL);
900: colorGC = XCreateGC(display,rootwin,0,NULL);
901: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,drawGC);
902: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,dashGC);
903: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,clearGC);
904: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,scaleGC);
905: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,xorGC);
906: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,colorGC);
907: XSetForeground(display,drawGC,forePixel);
908: XSetForeground(display,scaleGC,forePixel);
909: XSetForeground(display,clearGC,backPixel);
910: XSetForeground(display,xorGC,forePixel^backPixel);
911: XSetFunction(display,xorGC,GXxor);
912: XSetForeground(display,dashGC,dashPixel);
913: XSetLineAttributes(display,dashGC,1,LineOnOffDash,CapButt,JoinRound);
914:
915: color.red = color.green = color.blue = 0xffff/2;
916: XAllocColor(display,DefaultColormap(display,scrn),&color);
917: XSetForeground(display,hlGC,color.pixel);
918: color.red = 0xffff; color.green = color.blue = 0;
919: XAllocColor(display,DefaultColormap(display,scrn),&color);
920: XSetForeground(display,colorGC,color.pixel);
921: }
922:
923: create_cursors() {
924: static XColor fg = {0, 0x0, 0x0, 0x0,DoRed|DoGreen|DoBlue,0};
925: static XColor bg = {0, 0xffff, 0xffff, 0xffff,DoRed|DoGreen|DoBlue,0};
926:
927: XAllocColor(display,DefaultColormap(display,scrn),&fg);
928: XAllocColor(display,DefaultColormap(display,scrn),&bg);
929: normalcur = create_cursor(h_bits,h_m_bits,h_width,h_height,
930: h_x_hot,h_y_hot,&fg,&bg);
931: runningcur = create_cursor(ht_bits,ht_m_bits,ht_width,ht_height,
932: ht_width/2,ht_height/2,&fg,&bg);
933: errorcur = create_cursor(m_bits,m_m_bits,m_width,m_height,
934: m_width/2,m_height/2,&fg,&bg);
935: }
936:
937: Cursor create_cursor(image,mask,width,height,xhot,yhot,fg,bg)
938: char *image,*mask;
939: int width,height,xhot,yhot;
940: XColor *fg,*bg;
941: {
942: Pixmap ipix,mpix;
943:
944: ipix = XCreateBitmapFromData(display,rootwin,image,width,height);
945: mpix = XCreateBitmapFromData(display,rootwin,mask,width,height);
946: return XCreatePixmapCursor(display,ipix,mpix,fg,bg,xhot,yhot);
947: }
948:
949: copy_to_canvas(can)
950: struct canvas *can;
951: {
952: if ( display ) {
953: XCopyArea(display,can->pix,can->window,
954: drawGC,0,0,can->width,can->height,0,0);
955: pline(display,can,can->window);
956: XFlush(display);
957: }
958: }
959:
960: copy_subimage(subcan,can,pos)
961: struct canvas *subcan,*can;
962: XPoint pos;
963: {
964: if ( display ) {
965: XCopyArea(display,subcan->pix,can->pix,
966: drawGC,0,0,subcan->width,subcan->height,pos.x,pos.y);
967: XFlush(display);
968: }
969: }
970:
971: #include <signal.h>
972: #include <fcntl.h>
973:
974: set_selection() {
975: if ( current_can ) {
976: XSelectInput(display,current_can->window,0);
977: XFlush(display);
978: }
979: }
980:
981: reset_selection() {
982: if ( current_can ) {
983: XSelectInput(display,current_can->window,NormalSelection);
984: XFlush(display);
985: }
986: }
987:
988: set_busy(can)
989: struct canvas *can;
990: {
991: busy = 1;
992: XtSetSensitive(can->wideb,False);
993: XtSetSensitive(can->preciseb,False);
994: XtSetSensitive(can->noaxisb,False);
995: XFlush(display);
996: }
997:
998: reset_busy(can)
999: struct canvas *can;
1000: {
1001: busy = 0;
1002: if ( can->window ) {
1003: XtSetSensitive(can->wideb,True);
1004: XtSetSensitive(can->noaxisb,True);
1005: if ( can->mode == MODE_IFPLOT && qpcheck((Obj)can->formula) )
1006: XtSetSensitive(can->preciseb,True);
1007: XFlush(display);
1008: }
1009: }
1010:
1011: reset_current_computation()
1012: {
1013: if ( current_can ) {
1014: reset_selection(); reset_busy(current_can);
1015: define_cursor(current_can->window,normalcur);
1016: }
1017: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>