Annotation of OpenXM_contrib2/asir2000/plot/ox_plot_xevent.c, Revision 1.29
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.29 ! saito 48: * $OpenXM: OpenXM_contrib2/asir2000/plot/ox_plot_xevent.c,v 1.28 2007/01/30 00:28:26 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"
1.8 takayama 55: #include <X11/Xaw/MenuButton.h>
56: #include <X11/Xaw/Paned.h>
1.14 noro 57:
1.24 noro 58: static void Quit();
1.26 ohara 59: static void print_canvas(Widget w, struct canvas *can, XtPointer calldata);
60: static void output_to_printer(Widget w, struct canvas *can, XtPointer calldata);
61: static void print_canvas_to_file(Widget w, struct canvas *can, XtPointer calldata);
62: static void printing_method(Widget w, struct canvas *can, XtPointer calldata);
1.24 noro 63:
1.23 noro 64: static Atom wm_delete_window;
65:
1.24 noro 66: void SetWM_Proto(Widget w)
67: {
68: XtOverrideTranslations(w,
69: XtParseTranslationTable("<Message>WM_PROTOCOLS: quit()"));
70: XSetWMProtocols(display,XtWindow(w),&wm_delete_window,1);
71: }
72:
1.23 noro 73: static void quit(Widget w, XEvent *ev, String *params,Cardinal *nparams)
74: {
75: XBell(display,0);
76: }
77:
1.14 noro 78: /* XXX : these lines are in plotg.c, but ld says they are not defined */
79: #if __DARWIN__
80: int stream;
81:
82: DISPLAY *display;
83: CURSOR normalcur,runningcur,errorcur;
84:
85: #if defined(VISUAL)
86: POINT start_point, end_point;
87: SIZE cansize;
88: #else
89: Window rootwin;
90: GC drawGC,dashGC,hlGC,scaleGC,clearGC,xorGC,colorGC,cdrawGC;
91: XFontStruct *sffs;
92: #endif
93:
94: struct canvas *canvas[MAXCANVAS];
1.19 noro 95: struct canvas *closed_canvas[MAXCANVAS];
1.14 noro 96: struct canvas *current_can;
97: #endif /* __DARWIN__ */
1.1 noro 98:
99: #ifdef ABS
100: #undef ABS
101: #define ABS(a) ((a)>0?(a):-(a))
102: #endif
103:
104: static char *dname;
105: static int depth,scrn;
106:
1.13 noro 107: extern JMP_BUF ox_env;
1.1 noro 108: static Widget toplevel;
109: static XtAppContext app_con;
110:
111: static int busy;
112:
113: static struct PlotResources {
114: Pixel ForePixel,BackPixel,DashPixel;
115: char *ForeName,*BackName,*DashName;
116: Boolean Reverse;
1.18 noro 117: Boolean UpsideDown;
1.1 noro 118: } PlotResources;
119:
120: #define forePixel PlotResources.ForePixel
121: #define backPixel PlotResources.BackPixel
122: #define dashPixel PlotResources.DashPixel
123: #define foreName PlotResources.ForeName
124: #define backName PlotResources.BackName
125: #define dashName PlotResources.DashName
126: #define reverse PlotResources.Reverse
1.18 noro 127: #define upsidedown PlotResources.UpsideDown
1.1 noro 128:
1.29 ! saito 129: Pixel BackPixel;
! 130:
1.1 noro 131: Cursor create_cursor();
132:
133: #define blackPixel BlackPixel(display,scrn)
134: #define whitePixel WhitePixel(display,scrn)
135:
136: #define LABELWIDTH 150
137:
138: process_xevent() {
139: XEvent ev;
140:
141: while ( XPending(display) ) {
142: XtAppNextEvent(app_con,&ev);
143: XtDispatchEvent(&ev);
144: }
145: }
146:
147: /* event handlers */
148:
149: static POINT spos,cpos;
150:
151: void press(w,can,ev)
152: Widget w;
153: struct canvas *can;
154: XButtonEvent *ev;
155: {
156: POINT p;
157:
158: switch ( ev->button ) {
159: case Button1:
160: XC(spos) = ev->x; YC(spos) = ev->y; cpos = spos; break;
161: case Button3:
162: XC(p) = ev->x; YC(p) = ev->y; draw_coord(can,&p); break;
163: default:
164: break;
165: }
166: }
167:
168: void motion(w,can,ev)
169: Widget w;
170: struct canvas *can;
171: XMotionEvent *ev;
172: {
173:
174: POINT o,p;
175:
176: if ( ev->state & Button1Mask ) {
177: o = cpos; XC(cpos) = ev->x; YC(cpos) = ev->y;
178: draw_frame(can->window,spos,o,cpos);
179: } else if ( ev->state & Button3Mask ) {
180: XC(p) = ev->x; YC(p) = ev->y;
181: draw_coord(can,p);
182: }
183: }
184:
185: void release(w,can,ev)
186: Widget w;
187: struct canvas *can;
188: XButtonEvent *ev;
189: {
190: POINT e;
191:
192: switch ( ev->button ) {
193: case Button1:
194: e.x = ev->x; e.y = ev->y;
195: draw_frame0(can->window,spos,e);
1.22 noro 196: if ( !busy
197: && can->mode != MODE_INTERACTIVE
198: && can->mode != MODE_POLARPLOT) {
1.1 noro 199: if ( can->mode == MODE_PLOT )
200: plot_resize(can,spos,e);
201: else
202: ifplot_resize(can,spos,e);
203: }
204: break;
205: default:
206: break;
207: }
208: }
209:
210: void structure(w,can,ev)
211: Widget w;
212: struct canvas *can;
213: XEvent *ev;
214: {
215: switch ( ev->xany.type ) {
216: case Expose:
217: if ( !ev->xexpose.count )
218: redraw_canvas(can);
219: break;
220: case ConfigureNotify:
221: redraw_canvas(can); break;
222: default:
223: break;
224: }
225: }
226:
227: static int lindex;
228:
229: void lpress(w,can,ev)
230: Widget w;
231: struct canvas *can;
232: XButtonEvent *ev;
233: {
234: lindex = (can->height-ev->y)/(can->height/can->nzstep);
235: draw_level(can,lindex,hlGC);
236: }
237:
238: void jumpproc(w,can,percent)
239: Widget w;
240: struct canvas *can;
241: float *percent;
242: {
243: int index;
244:
245: index = can->nzstep * (1.0-*percent);
246: if ( index == lindex )
247: return;
248: if ( lindex >= 0 )
249: draw_level(can,lindex,drawGC);
250: lindex = index;
251: draw_level(can,lindex,hlGC);
252: }
253:
254: void jumpproc_m(w,can,percent)
255: Widget w;
256: struct canvas *can;
257: float *percent;
258: {
259: int index;
260:
261: index = can->nzstep * (1.0-*percent);
262: if ( index != lindex ) {
263: draw_level(can,lindex,drawGC);
264: draw_level(can,lindex,hlGC);
265: }
266: }
267:
268: void lrelease(w,can,ev)
269: Widget w;
270: struct canvas *can;
271: XButtonEvent *ev;
272: {
273: draw_level(can,lindex,drawGC); lindex = -1;
274: }
275:
276: void lrelease_m(w,can,ev)
277: Widget w;
278: struct canvas *can;
279: XButtonEvent *ev;
280: {
281: lindex = -1;
282: }
283:
284: draw_level(can,index,gc)
285: struct canvas *can;
286: int index;
287: GC gc;
288: {
289: Pixmap pix;
290: struct pa *pa;
291: int i,len;
292: POINT *p;
293: Arg arg[2];
294: char buf[BUFSIZ];
295:
296: if ( busy || can->wide || index < 0 || index > can->nzstep )
297: return;
298: pix = can->pix; pa = &can->pa[index]; len = pa->length; p = pa->pos;
299: for ( i = 0; i < len; i++ )
300: XDrawPoint(display,pix,gc,p[i].x,p[i].y);
301: sprintf(buf,"level:%g",can->zmin+(can->zmax-can->zmin)*index/can->nzstep);
302: XtSetArg(arg[0],XtNlabel,buf); XtSetArg(arg[1],XtNwidth,LABELWIDTH);
303: XtSetValues(can->level,arg,2);
304: copy_to_canvas(can);
305: }
306:
307: draw_frame(window,spos,opos,epos)
308: Window window;
309: POINT spos,opos,epos;
310: {
311: if ( XC(opos) != XC(epos) || YC(opos) != YC(epos) )
312: draw_frame0(window,spos,opos);
313: draw_frame0(window,spos,epos);
314: }
315:
316: draw_frame0(window,spos,epos)
317: Window window;
318: POINT spos,epos;
319: {
320: int ulx,uly,w,h;
321:
322: ulx = MIN(XC(spos),XC(epos)); uly = MIN(YC(spos),YC(epos));
323: w = ABS(XC(spos)-XC(epos)); h = ABS(YC(spos)-YC(epos));
324: if ( !w || !h )
325: return;
326: XDrawRectangle(display,window,xorGC,ulx,uly,w,h);
327: XFlush(display);
328: }
329:
330: draw_coord(can,pos)
331: struct canvas *can;
332: POINT pos;
333: {
334: char buf[BUFSIZ];
335: Arg arg[2];
336: double x,y,xmin,ymax,dx,dy;
337:
338: if ( can->wide ) {
339: dx = 10*(can->xmax-can->xmin); dy = 10*(can->ymax-can->ymin);
340: xmin = (can->xmax+can->xmin-dx)/2;
341: ymax = (can->ymax+can->ymin+dy)/2;
342: } else {
343: dx = can->xmax-can->xmin; dy = can->ymax-can->ymin;
344: xmin = can->xmin; ymax = can->ymax;
345: }
346: x = xmin+XC(pos)*dx/can->width;
347: y = ymax-YC(pos)*dy/can->height;
348: sprintf(buf,"%s:%g",can->vx?can->vx->name:"horiz",x);
349: XtSetArg(arg[0],XtNlabel,buf); XtSetArg(arg[1],XtNwidth,LABELWIDTH);
350: XtSetValues(can->xcoord,arg,2);
351: sprintf(buf,"%s:%g",can->vy?can->vy->name:"vert",y);
352: XtSetArg(arg[0],XtNlabel,buf); XtSetArg(arg[1],XtNwidth,LABELWIDTH);
353: XtSetValues(can->ycoord,arg,2);
354: }
355:
356: redraw_canvas(can)
357: struct canvas *can;
358: {
359: if ( can->wide )
360: draw_wideframe(can);
361: else
362: copy_to_canvas(can);
363: }
364:
365: search_canvas()
366: {
367: int i;
368:
369: for ( i = 0; i < MAXCANVAS; i++ )
370: if ( !canvas[i] ) {
371: canvas[i] = (struct canvas *)MALLOC(sizeof(struct canvas));
372: canvas[i]->index = i; return i;
373: }
374: }
375:
376: search_active_canvas()
377: {
378: int i;
379:
380: for ( i = 0; i < MAXCANVAS; i++ )
381: if ( canvas[i] )
382: return i;
383: return -1;
384: }
385:
1.19 noro 386: void popup_canvas(index)
387: {
1.20 noro 388: clear_pixmap(canvas[index]);
1.19 noro 389: XtPopup(canvas[index]->shell,XtGrabNone);
1.20 noro 390: copy_to_canvas(canvas[index]);
1.19 noro 391: }
1.4 takayama 392:
1.1 noro 393: void destroy_canvas(w,can,calldata)
394: Widget w;
395: struct canvas *can;
396: XtPointer calldata;
397: {
398: XtPopdown(can->shell);
1.19 noro 399: /* XtDestroyWidget(can->shell); */
1.1 noro 400: XFlush(display);
401: if ( can == current_can ) {
402: reset_busy(can); current_can = 0;
403: }
1.19 noro 404: if ( closed_canvas[can->index] )
405: XtDestroyWidget(closed_canvas[can->index]->shell);
406: closed_canvas[can->index] = can;
1.1 noro 407: canvas[can->index] = 0;
408: }
409:
410: void precise_canvas(w,can,calldata)
411: Widget w;
412: struct canvas *can;
413: XtPointer calldata;
414: {
415: if ( can->precise )
416: can->precise = 0;
417: else
418: can->precise = 1;
419: }
420:
421: void wide_canvas(w,can,calldata)
422: Widget w;
423: struct canvas *can;
424: XtPointer calldata;
425: {
426: if ( can->wide ) {
427: can->wide = 0; copy_to_canvas(can);
428: } else {
429: can->wide = 1; draw_wideframe(can);
430: }
431: }
432:
433: void noaxis_canvas(w,can,calldata)
434: Widget w;
435: struct canvas *can;
436: XtPointer calldata;
437: {
438: if ( can->noaxis )
439: can->noaxis = 0;
440: else
441: can->noaxis = 1;
442: if ( can->wide )
443: draw_wideframe(can);
444: else
445: copy_to_canvas(can);
446: }
447:
448: toggle_button(w,flag)
449: Widget w;
450: int flag;
451: {
452: Arg arg[2];
453:
454: if ( flag ) {
455: XtSetArg(arg[0],XtNforeground,backPixel);
456: XtSetArg(arg[1],XtNbackground,forePixel);
457: } else {
458: XtSetArg(arg[0],XtNforeground,forePixel);
459: XtSetArg(arg[1],XtNbackground,backPixel);
460: }
461: XtSetValues(w,arg,2); XFlush(display);
462: }
463:
464: draw_wideframe(can)
465: struct canvas *can;
466: {
467: struct canvas fakecan;
468: double xmin,xmax,ymin,ymax,xmid,ymid,dx,dy;
469: POINT s,e;
470:
471: fakecan = *can;
472: dx = 10*(can->xmax-can->xmin); dy = 10*(can->ymax-can->ymin);
473: xmid = (can->xmax+can->xmin)/2; ymid = (can->ymax+can->ymin)/2;
474:
475: fakecan.xmin = xmid-dx/2; fakecan.xmax = xmid+dx/2;
476: fakecan.ymin = ymid-dy/2; fakecan.ymax = ymid+dy/2;
477:
478: XFillRectangle(display,can->window,clearGC,
479: 0,0,can->width,can->height);
480: pline(display,&fakecan,can->window);
481: XC(s) = can->width*9/20; YC(s) = can->height*9/20;
482: XC(e) = can->width*11/20; YC(e) = can->height*11/20;
483: draw_frame0(can->window,s,e);
484: }
485:
486: create_popup(parent,name,str,shell,dialog)
487: Widget parent;
488: char *name,*str;
489: Widget *shell,*dialog;
490: {
491: Arg arg[3];
492: Position x,y;
493:
494: XtTranslateCoords(parent,0,0,&x,&y);
495: XtSetArg(arg[0],XtNx,x); XtSetArg(arg[1],XtNy,y);
496: *shell = XtCreatePopupShell(name,transientShellWidgetClass,parent,arg,2);
497: XtSetArg(arg[0],XtNlabel,str);
498: *dialog = XtCreateManagedWidget("dialog",dialogWidgetClass,*shell,arg,1);
499: }
500:
501: warning(can,s)
502: struct canvas *can;
503: char *s;
504: {
505: void popdown_warning();
506: Widget warnshell,warndialog;
507: Position x,y;
508: Arg arg[3];
509:
510: if ( !can->shell )
511: return;
512: create_popup(can->shell,"warning",s,&warnshell,&warndialog);
513: XawDialogAddButton(warndialog,"dismiss",popdown_warning,warnshell);
514: XtPopup(warnshell,XtGrabNone);
1.24 noro 515: SetWM_Proto(warnshell);
1.1 noro 516: }
517:
518: void popdown_warning(w,client,call)
519: Widget w;
520: XtPointer client,call;
521: {
522: XtPopdown(client); XtDestroyWidget(client);
523: }
524:
525: void show_formula(w,can,calldata)
526: Widget w;
527: struct canvas *can;
528: XtPointer calldata;
529: {
530: void popdown_formula();
531: Widget fshell,fdialog;
532: char buf[BUFSIZ];
533:
534: soutput_init(buf); sprintexpr(CO,(Obj)can->formula);
535: create_popup(can->shell,"formula",buf,&fshell,&fdialog);
536: XawDialogAddButton(fdialog,"dismiss",popdown_formula,w);
537: XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
1.24 noro 538: SetWM_Proto(fshell);
1.1 noro 539: }
540:
541: void popdown_formula(w,fbutton,call)
542: Widget w,fbutton;
543: XtPointer call;
544: {
545: Widget shell = XtParent(XtParent(w));
546: XtPopdown(shell); XtDestroyWidget(shell);
547: XtSetSensitive(fbutton,True);
548: }
549:
550: #define NormalSelection ButtonPressMask|ButtonReleaseMask|Button1MotionMask|Button3MotionMask|StructureNotifyMask| ExposureMask
551:
552: create_canvas(can)
553: struct canvas *can;
554: {
555: XEvent event;
556: Widget box,frame,commands,
1.4 takayama 557: coords,quit,print,wide,precise,canvas,formula;
1.1 noro 558: Window window;
559: Pixmap pix;
560: int i,width,height;
561: Arg arg[6];
562: char buf[BUFSIZ];
563:
1.29 ! saito 564: XImage *image;
! 565:
1.1 noro 566: width = can->width; height = can->height;
567:
1.21 noro 568: sprintf(buf,"%s : %d", can->wname?can->wname:"Plot",can->index);
1.1 noro 569: XtSetArg(arg[0],XtNiconName,buf);
570: can->shell =
571: XtCreatePopupShell("shell",topLevelShellWidgetClass,toplevel,arg,1);
572:
573: XtSetArg(arg[0],XtNhSpace,0);
574: XtSetArg(arg[1],XtNvSpace,0);
575: XtSetArg(arg[2],XtNborderWidth,0);
576: box = XtCreateManagedWidget("box",boxWidgetClass,can->shell,arg,3);
577:
578: frame = XtCreateManagedWidget("form",formWidgetClass,box,NULL,0);
579:
580: XtSetArg(arg[0],XtNorientation,XtorientHorizontal);
581: XtSetArg(arg[1],XtNborderWidth,0);
582: commands = XtCreateManagedWidget("commands",boxWidgetClass,frame,arg,2);
583:
584: quit = XtCreateManagedWidget("quit",commandWidgetClass,commands,NULL,0);
585: XtAddCallback(quit,XtNcallback,destroy_canvas,can);
1.4 takayama 586: print = XtCreateManagedWidget("print",commandWidgetClass,commands,NULL,0);
587: XtAddCallback(print,XtNcallback,print_canvas,can);
1.1 noro 588: can->wideb = wide =
589: XtCreateManagedWidget("wide",toggleWidgetClass,commands,NULL,0);
590: XtAddCallback(wide,XtNcallback,wide_canvas,can);
591: can->preciseb = precise =
592: XtCreateManagedWidget("precise",toggleWidgetClass,commands,NULL,0);
593: XtAddCallback(precise,XtNcallback,precise_canvas,can);
594: formula =
595: XtCreateManagedWidget("formula",commandWidgetClass,commands,NULL,0);
596: XtAddCallback(formula,XtNcallback,show_formula,can);
597: can->noaxisb =
598: XtCreateManagedWidget("noaxis",toggleWidgetClass,commands,NULL,0);
599: XtAddCallback(can->noaxisb,XtNcallback,noaxis_canvas,can);
600:
601: XtSetArg(arg[0],XtNfromVert,commands);
602: XtSetArg(arg[1],XtNwidth,width);
603: XtSetArg(arg[2],XtNheight,height);
604: canvas = XtCreateManagedWidget("canvas",simpleWidgetClass,frame,arg,3);
605:
606: XtSetArg(arg[0],XtNfromVert,canvas);
607: XtSetArg(arg[1],XtNheight,5);
608: XtSetArg(arg[2],XtNwidth,width);
609: XtSetArg(arg[3],XtNorientation,XtorientHorizontal);
610: XtSetArg(arg[4],XtNsensitive,False);
611: can->xdone =
612: XtCreateManagedWidget("xdone",scrollbarWidgetClass,frame,arg,5);
613:
614: XtSetArg(arg[0],XtNfromHoriz,canvas);
615: XtSetArg(arg[1],XtNfromVert,commands);
616: XtSetArg(arg[2],XtNwidth,5);
617: XtSetArg(arg[3],XtNheight,height);
618: XtSetArg(arg[4],XtNorientation,XtorientVertical);
619: XtSetArg(arg[5],XtNsensitive,False);
620: can->ydone =
621: XtCreateManagedWidget("ydone",scrollbarWidgetClass,frame,arg,6);
622:
623: XtSetArg(arg[0],XtNfromVert,can->xdone);
624: XtSetArg(arg[1],XtNorientation,XtorientHorizontal);
625: XtSetArg(arg[2],XtNborderWidth,0);
626: coords = XtCreateManagedWidget("coords",boxWidgetClass,frame,arg,3);
627:
628: XtSetArg(arg[0],XtNwidth,LABELWIDTH);
629: can->xcoord = XtCreateManagedWidget("xcoord",labelWidgetClass,coords,arg,1);
630: XtSetArg(arg[0],XtNwidth,LABELWIDTH);
631: can->ycoord = XtCreateManagedWidget("ycoord",labelWidgetClass,coords,arg,1);
632:
633: XtAddEventHandler(canvas,ButtonPressMask,False,press,can);
634: XtAddEventHandler(canvas,ButtonReleaseMask,False,release,can);
635: XtAddEventHandler(canvas,Button1MotionMask,False,motion,can);
636: XtAddEventHandler(canvas,Button3MotionMask,False,motion,can);
637: XtAddEventHandler(canvas,StructureNotifyMask,False,structure,can);
638: XtAddEventHandler(canvas,ExposureMask,False,structure,can);
639:
640: if ( can->mode == MODE_CONPLOT ) {
641: Widget scale;
642:
643: XtSetArg(arg[0],XtNwidth,LABELWIDTH);
644: can->level = XtCreateManagedWidget("level",labelWidgetClass,
645: commands,arg,1);
646:
647: XtSetArg(arg[0],XtNsensitive,True);
648: XtSetValues(can->ydone,arg,1);
649: if ( depth >= 2 ) {
650: XtAddCallback(can->ydone,XtNjumpProc,jumpproc,can);
651: XtAddEventHandler(can->ydone,ButtonReleaseMask,False,lrelease,can);
652: } else {
653: XtAddCallback(can->ydone,XtNjumpProc,jumpproc_m,can);
654: XtAddEventHandler(can->ydone,ButtonReleaseMask,False,lrelease_m,can);
655: }
656: }
657: if ( can->mode != MODE_IFPLOT || !qpcheck((Obj)can->formula) )
658: XtSetSensitive(precise,False);
659: XtPopup(can->shell,XtGrabNone);
1.24 noro 660: SetWM_Proto(can->shell);
1.1 noro 661: window = can->window = XtWindow(canvas);
662: pix = can->pix = XCreatePixmap(display,window,width,height,depth);
663: XFillRectangle(display,pix,clearGC,0,0,width,height);
1.29 ! saito 664: image = XGetImage(display, can->pix, 0, 0, can->width, can->height,
! 665: -1, ZPixmap);
! 666: BackPixel = XGetPixel(image,0,0);
1.1 noro 667: XDefineCursor(display,window,normalcur);
668: XFlush(display);
669: current_can = can;
670: }
671:
672: alloc_pixmap(can)
673: struct canvas *can;
674: {
675: can->pix = XCreatePixmap(display,can->window,
676: can->width,can->height,depth);
677: XFillRectangle(display,can->pix,clearGC,0,0,can->width,can->height);
678: }
679:
680: static XrmOptionDescRec options[] = {
1.18 noro 681: {"-upsidedown","*upsidedown",XrmoptionNoArg,"on"},
1.1 noro 682: {"-reverse","*reverse",XrmoptionNoArg,"on"},
683: {"-fg","*foreground",XrmoptionSepArg,NULL},
684: {"-bg","*background",XrmoptionSepArg,NULL},
685: };
686:
687: #define offset(name) XtOffset(struct PlotResources *,name)
688:
689: static XtResource resources[] = {
1.18 noro 690: {"upsidedown","UpsideDown",XtRBoolean,sizeof(Boolean),
691: offset(UpsideDown),XtRBoolean,&upsidedown},
1.1 noro 692: {"reverse","Reverse",XtRBoolean,sizeof(Boolean),
693: offset(Reverse),XtRBoolean,&reverse},
694: {"foreground","Foreground",XtRString,sizeof(char *),
695: offset(ForeName),XtRString,NULL},
696: {"foreground","Foreground",XtRPixel,sizeof(Pixel),
697: offset(ForePixel),XtRPixel,(XtPointer)&forePixel},
698: {"background","Background",XtRString,sizeof(char *),
699: offset(BackName),XtRString,NULL},
700: {"background","Background",XtRPixel,sizeof(Pixel),
701: offset(BackPixel),XtRPixel,(XtPointer)&backPixel},
702: {"dash","Dash",XtRString,sizeof(char *),
703: offset(DashName),XtRString,NULL},
704: {"dash","Dash",XtRPixel,sizeof(Pixel),
705: offset(DashPixel),XtRPixel,(XtPointer)&dashPixel},
706: };
707:
1.24 noro 708: static XtActionsRec actions_table[] = {
709: {"quit",Quit},
710: };
711:
712: static void Quit(Widget w, XEvent *ev, String *params,Cardinal *nparams)
713: {
714: XBell(XtDisplay(w),0);
715: }
716:
1.12 noro 717: int init_plot_display(argc,argv)
1.1 noro 718: int argc;
719: char **argv;
720: {
721: int ac;
722: char **av;
723: unsigned int tmp;
724:
725: for ( ac = argc, av = argv; ac; ac--, av++ )
1.12 noro 726: if ( !strcmp(*av,"nox") )
727: return 0;
728: else if ( index(*av,':') )
1.1 noro 729: dname = *av;
730: XtToolkitInitialize();
731: app_con = XtCreateApplicationContext();
1.24 noro 732: XtAppAddActions(app_con,actions_table, XtNumber(actions_table));
1.1 noro 733: display = XtOpenDisplay(app_con,dname,"plot","Plot",
734: options,XtNumber(options),&argc,argv);
735: if ( !display ) {
736: fprintf(stderr,"Can't open display\n");
1.12 noro 737: return 0;
1.1 noro 738: }
739: toplevel = XtAppCreateShell(0,"Plot",applicationShellWidgetClass,
740: display,0,0);
741:
742: forePixel = blackPixel; backPixel = whitePixel;
743: dashPixel = blackPixel;
744: XtGetApplicationResources(toplevel,&PlotResources,
745: resources,XtNumber(resources),NULL,0);
746: display = XtDisplay(toplevel);
747: scrn = DefaultScreen(display);
748: depth = DefaultDepth(display,scrn);
749: rootwin = RootWindow(display,scrn);
750:
1.23 noro 751: /* for handling DELETE message */
752: wm_delete_window = XInternAtom(display,"WM_DELETE_WINDOW",False);
753: XtOverrideTranslations(toplevel,
754: XtParseTranslationTable("<Message>WM_PROTOCOLS: quit()"));
755:
1.1 noro 756: if ( reverse ) {
757: tmp = forePixel; forePixel = backPixel; backPixel = tmp;
758: }
759:
760: create_gc();
761: create_font();
762: create_cursors();
1.12 noro 763: return 1;
1.1 noro 764: }
765:
766: static char *scalefont = "*-8-80-*";
767:
768: create_font() {
769: Font sfid;
770:
771: sfid = XLoadFont(display,scalefont);
772: sffs = XQueryFont(display,sfid);
773: XSetFont(display,scaleGC,sfid);
774: }
775:
776: create_gc() {
777: static XColor color = {0,0x0,0x0,0x0,DoRed|DoGreen|DoBlue,0};
778: int i,b,step;
779:
780: drawGC = XCreateGC(display,rootwin,0,NULL);
781: dashGC = XCreateGC(display,rootwin,0,NULL);
782: hlGC = XCreateGC(display,rootwin,0,NULL);
783: clearGC = XCreateGC(display,rootwin,0,NULL);
784: scaleGC = XCreateGC(display,rootwin,0,NULL);
785: xorGC = XCreateGC(display,rootwin,0,NULL);
786: colorGC = XCreateGC(display,rootwin,0,NULL);
1.11 noro 787: cdrawGC = XCreateGC(display,rootwin,0,NULL);
1.1 noro 788: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,drawGC);
789: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,dashGC);
790: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,clearGC);
791: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,scaleGC);
792: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,xorGC);
793: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,colorGC);
1.11 noro 794: XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,cdrawGC);
1.1 noro 795: XSetForeground(display,drawGC,forePixel);
796: XSetForeground(display,scaleGC,forePixel);
797: XSetForeground(display,clearGC,backPixel);
798: XSetForeground(display,xorGC,forePixel^backPixel);
799: XSetFunction(display,xorGC,GXxor);
800: XSetForeground(display,dashGC,dashPixel);
801: XSetLineAttributes(display,dashGC,1,LineOnOffDash,CapButt,JoinRound);
802:
803: color.red = color.green = color.blue = 0xffff/2;
804: XAllocColor(display,DefaultColormap(display,scrn),&color);
805: XSetForeground(display,hlGC,color.pixel);
806: color.red = 0xffff; color.green = color.blue = 0;
807: XAllocColor(display,DefaultColormap(display,scrn),&color);
808: XSetForeground(display,colorGC,color.pixel);
1.11 noro 809: }
810:
811: set_drawcolor(c)
812: unsigned int c;
813: {
814: XColor color = {0,0x0,0x0,0x0,DoRed|DoGreen|DoBlue,0};
815:
816: color.red = (c&0xff0000)>>8;
817: color.green = (c&0xff00);
818: color.blue = (c&0xff)<<8;
819: XAllocColor(display,DefaultColormap(display,scrn),&color);
820: XSetForeground(display,cdrawGC,color.pixel);
1.1 noro 821: }
822:
823: create_cursors() {
824: static XColor fg = {0, 0x0, 0x0, 0x0,DoRed|DoGreen|DoBlue,0};
825: static XColor bg = {0, 0xffff, 0xffff, 0xffff,DoRed|DoGreen|DoBlue,0};
826:
827: XAllocColor(display,DefaultColormap(display,scrn),&fg);
828: XAllocColor(display,DefaultColormap(display,scrn),&bg);
829: normalcur = create_cursor(h_bits,h_m_bits,h_width,h_height,
830: h_x_hot,h_y_hot,&fg,&bg);
831: runningcur = create_cursor(ht_bits,ht_m_bits,ht_width,ht_height,
832: ht_width/2,ht_height/2,&fg,&bg);
833: errorcur = create_cursor(m_bits,m_m_bits,m_width,m_height,
834: m_width/2,m_height/2,&fg,&bg);
835: }
836:
837: Cursor create_cursor(image,mask,width,height,xhot,yhot,fg,bg)
838: char *image,*mask;
839: int width,height,xhot,yhot;
840: XColor *fg,*bg;
841: {
842: Pixmap ipix,mpix;
843:
844: ipix = XCreateBitmapFromData(display,rootwin,image,width,height);
845: mpix = XCreateBitmapFromData(display,rootwin,mask,width,height);
846: return XCreatePixmapCursor(display,ipix,mpix,fg,bg,xhot,yhot);
847: }
848:
849: copy_to_canvas(can)
850: struct canvas *can;
851: {
852: if ( display ) {
1.25 noro 853: if ( can->color ) {
854: set_drawcolor(can->color);
855: XCopyArea(display,can->pix,can->window,
856: cdrawGC,0,0,can->width,can->height,0,0);
857: } else
858: XCopyArea(display,can->pix,can->window,
859: drawGC,0,0,can->width,can->height,0,0);
1.1 noro 860: pline(display,can,can->window);
861: XFlush(display);
862: }
863: }
864:
865: copy_subimage(subcan,can,pos)
866: struct canvas *subcan,*can;
867: XPoint pos;
868: {
869: if ( display ) {
870: XCopyArea(display,subcan->pix,can->pix,
871: drawGC,0,0,subcan->width,subcan->height,pos.x,pos.y);
872: XFlush(display);
873: }
874: }
875:
876: #include <signal.h>
877: #include <fcntl.h>
878:
879: set_selection() {
880: if ( current_can ) {
881: XSelectInput(display,current_can->window,0);
882: XFlush(display);
883: }
884: }
885:
886: reset_selection() {
887: if ( current_can ) {
888: XSelectInput(display,current_can->window,NormalSelection);
889: XFlush(display);
890: }
891: }
892:
893: set_busy(can)
894: struct canvas *can;
895: {
896: busy = 1;
897: XtSetSensitive(can->wideb,False);
898: XtSetSensitive(can->preciseb,False);
899: XtSetSensitive(can->noaxisb,False);
900: XFlush(display);
901: }
902:
903: reset_busy(can)
904: struct canvas *can;
905: {
906: busy = 0;
907: if ( can->window ) {
908: XtSetSensitive(can->wideb,True);
909: XtSetSensitive(can->noaxisb,True);
910: if ( can->mode == MODE_IFPLOT && qpcheck((Obj)can->formula) )
911: XtSetSensitive(can->preciseb,True);
912: XFlush(display);
913: }
914: }
915:
916: reset_current_computation()
917: {
918: if ( current_can ) {
919: reset_selection(); reset_busy(current_can);
920: define_cursor(current_can->window,normalcur);
921: }
1.8 takayama 922: }
923:
924: static struct canvas *Can;
925: /* void print_canvas(Widget w,struct canvas *can, XtPointer calldata); */
926: static void output_to_file(Widget , XtPointer, XtPointer );
927: static void output_to_ps_printer(Widget , XtPointer, XtPointer );
928: static void cancel_output_to_file(Widget , XtPointer,XtPointer);
929: static void generate_psfile(struct canvas *can, FILE *fp);
930: static void set_printing_method(Widget,XtPointer,XtPointer);
931: static void method_is_not_available();
932: static Widget PrintDialog;
933: static Widget PrintDialog_lp;
934: static Widget W;
935: static char *Fname = NULL;
936: static char *PrinterName = NULL;
937: #define PRINTING_METHOD_BITMAP 0
938: #define PRINTING_METHOD_VECTOR 1
939: static int PrintingMethod = PRINTING_METHOD_BITMAP;
940: static String Printing_methods[]={
941: "bitMap","vector",
942: };
943: static int N_printing_methods = 2;
944:
945: /*
946: static Widget create_printing_method_bar(Widget parent) {
947: Widget panel, button;
948: int i,n;
949: Arg wargs[1];
950: panel = XtCreateManagedWidget("printing methods",panedWidgetClass,
951: parent,NULL,0);
952: for (i=0; i<N_printing_methods; i++) {
953: button = XtCreateManagedWidget(Printing_methods[i],menuButtonWidgetClass,
954: panel,NULL,0);
955: fprintf(stderr,"button=%x\n",(int) button);
956: XtAddCallback(button,XtNcallback,set_printing_method,(XtPointer) i);
957: }
958: return(panel);
959: }
960: */
961:
962:
963: static void print_canvas(w,can,calldata)
964: Widget w;
965: struct canvas *can;
966: XtPointer calldata;
967: {
1.29 ! saito 968: Widget fshell,fdialog;
! 969: extern struct canvas *Can;
! 970: extern Widget W;
! 971: Widget entry;
! 972: int i;
! 973: Arg arg[1];
! 974:
! 975: W = w;
! 976: Can = can;
! 977: create_popup(can->shell,"Print/Output PS file","",&fshell,&fdialog);
! 978: XawDialogAddButton(fdialog,"print",output_to_printer,w);
! 979: XawDialogAddButton(fdialog,"output PS file",print_canvas_to_file,w);
! 980: XawDialogAddButton(fdialog,"method",printing_method,w);
! 981: XawDialogAddButton(fdialog,"dismiss",cancel_output_to_file,w);
! 982: XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
! 983: SetWM_Proto(fshell);
! 984: }
! 985:
! 986: static void set_printing_method(Widget w,XtPointer number,XtPointer call_data)
! 987: {
! 988: Widget shell;
! 989: extern int PrintingMethod;
! 990: PrintingMethod = (int) number;
! 991: fprintf(stderr,"PrintingMethod=%d\n",number);
! 992: shell = XtParent(XtParent(w));
! 993: XtPopdown(shell); XtDestroyWidget(shell);
1.8 takayama 994: }
995:
996: static void printing_method(w,can,calldata)
1.29 ! saito 997: Widget w;
! 998: struct canvas *can;
! 999: XtPointer calldata;
1.8 takayama 1000: {
1.29 ! saito 1001: Arg arg[10];
! 1002: int i,n;
! 1003: Widget fshell,fdialog;
! 1004: extern struct canvas *Can;
! 1005: extern int PrintingMethod;
! 1006:
! 1007: w = W;
! 1008: can = Can;
! 1009: create_popup(can->shell,"Printing method",Printing_methods[PrintingMethod],
! 1010: &fshell,&fdialog);
! 1011: n = 0;
! 1012: XtSetArg(arg[n], XtNlabel, "Method: "); n++;
! 1013: XtSetArg(arg[n], XtNvalue, Printing_methods[PrintingMethod]); n++;
! 1014: XtSetValues(fdialog,arg,n);
! 1015: for (i=0; i<N_printing_methods; i++) {
! 1016: XawDialogAddButton(
! 1017: fdialog,Printing_methods[i],set_printing_method,(XtPointer) i);
! 1018: }
! 1019: XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
! 1020: SetWM_Proto(fshell);
1.8 takayama 1021: }
1022: static void print_canvas_to_file(w,can,calldata)
1.29 ! saito 1023: Widget w;
! 1024: struct canvas *can;
! 1025: XtPointer calldata;
! 1026: {
! 1027: FILE *fp;
! 1028: Arg arg[10];
! 1029: int n;
! 1030: static char *psfile = NULL;
! 1031: Widget fshell,fdialog;
! 1032: extern struct canvas *Can;
! 1033: extern Widget PrintDialog;
! 1034: extern char *Fname;
! 1035:
! 1036: w = W;
! 1037: can = Can;
! 1038: if (psfile == NULL || Fname == NULL) psfile = "ox_plot.eps";
! 1039: else psfile = Fname;
! 1040: create_popup(can->shell,"Output as PS file",psfile,&fshell,&fdialog);
! 1041: n = 0;
! 1042: XtSetArg(arg[n], XtNlabel, "File : "); n++;
! 1043: XtSetArg(arg[n], XtNvalue, psfile); n++;
! 1044: XtSetValues(fdialog,arg,n);
! 1045: XawDialogAddButton(fdialog,"output to file",output_to_file,w);
! 1046: XawDialogAddButton(fdialog,"cancel",cancel_output_to_file,w);
! 1047: PrintDialog = fdialog;
! 1048: XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
! 1049: SetWM_Proto(fshell);
1.8 takayama 1050: }
1051: static void output_to_printer(w,can,calldata)
1.29 ! saito 1052: Widget w;
! 1053: struct canvas *can;
! 1054: XtPointer calldata;
! 1055: {
! 1056: FILE *fp;
! 1057: Arg arg[10];
! 1058: int n;
! 1059: static char *psfile = NULL;
! 1060: Widget fshell,fdialog;
! 1061: extern struct canvas *Can;
! 1062: extern Widget PrintDialog_lp;
! 1063: extern char *PrinterName;
! 1064:
! 1065: w = W;
! 1066: can = Can;
! 1067: if (psfile == NULL || PrinterName == NULL) psfile = "lp";
! 1068: else psfile = PrinterName;
! 1069: create_popup(can->shell,"Output PS file to printer",psfile,&fshell,&fdialog);
! 1070: n = 0;
! 1071: XtSetArg(arg[n], XtNlabel, "PS Printer Name : "); n++;
! 1072: XtSetArg(arg[n], XtNvalue, psfile); n++;
! 1073: XtSetValues(fdialog,arg,n);
! 1074: XawDialogAddButton(fdialog,"output to PS printer",output_to_ps_printer,w);
! 1075: XawDialogAddButton(fdialog,"cancel",cancel_output_to_file,w);
! 1076: PrintDialog_lp = fdialog;
! 1077: XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
! 1078: SetWM_Proto(fshell);
1.8 takayama 1079: }
1080:
1.29 ! saito 1081: static void cancel_output_to_file(w,fbutton,call)
! 1082: Widget w;
! 1083: XtPointer fbutton, call;
1.8 takayama 1084: {
1.29 ! saito 1085: Widget shell = XtParent(XtParent(w));
! 1086: XtPopdown(shell); XtDestroyWidget(shell);
! 1087: XtSetSensitive(fbutton,True);
1.8 takayama 1088: }
1089:
1090: static void output_to_file(w,fbutton,call)
1.29 ! saito 1091: Widget w;
! 1092: XtPointer fbutton, call;
1.8 takayama 1093: {
1.29 ! saito 1094: char *fname;
! 1095: FILE *fp;
! 1096: int i;
! 1097: char *m;
! 1098: extern struct canvas *Can;
! 1099: extern Widget PrintDialog;
! 1100: extern int PrintingMethod;
! 1101: Widget shell = XtParent(XtParent(w));
! 1102:
! 1103: if (PrintingMethod == PRINTING_METHOD_BITMAP) {
! 1104: TODO;
! 1105: }else{
! 1106: method_is_not_available();
! 1107: XtPopdown(shell); XtDestroyWidget(shell);
! 1108: XtSetSensitive(fbutton,True);
! 1109: return;
! 1110: }
1.8 takayama 1111:
1.29 ! saito 1112: fname = XawDialogGetValueString(PrintDialog);
! 1113: Fname = (char *)malloc(sizeof(char)*strlen(fname)+1);
! 1114: strcpy(Fname,fname);
! 1115: for (i=0; i<strlen(Fname); i++) {
! 1116: if (Fname[i] == 0xd || Fname[i] == 0xa) {
! 1117: Fname[i] = 0; break;
! 1118: }
! 1119: }
! 1120: fprintf(stderr,"fname=%s\n",Fname); fflush(NULL);
! 1121: fp = fopen(Fname,"w");
! 1122: if (fp == NULL) {
! 1123: warning(Can,"Could not open the output file.");
! 1124: }else{
! 1125: generate_psfile(Can,fp);
! 1126: fclose(fp);
1.8 takayama 1127: }
1128:
1.29 ! saito 1129: XtPopdown(shell); XtDestroyWidget(shell);
! 1130: XtSetSensitive(fbutton,True);
1.8 takayama 1131: }
1132:
1133: static void output_to_ps_printer(w,fbutton,call)
1.29 ! saito 1134: Widget w;
! 1135: XtPointer fbutton, call;
1.8 takayama 1136: {
1.29 ! saito 1137: char *printerName;
! 1138: FILE *fp;
! 1139: extern struct canvas *Can;
! 1140: extern Widget PrintDialog_lp;
! 1141: char fname[256];
! 1142: char cmd[512];
! 1143: static int id = 0;
! 1144: int i;
! 1145: Widget shell = XtParent(XtParent(w));
! 1146:
! 1147: if (PrintingMethod == PRINTING_METHOD_BITMAP) {
! 1148: }else{
! 1149: method_is_not_available();
! 1150: XtPopdown(shell); XtDestroyWidget(shell);
! 1151: XtSetSensitive(fbutton,True);
! 1152: return;
! 1153: }
1.8 takayama 1154:
1.29 ! saito 1155: sprintf(fname,"/tmp/ox_plot_%d.eps",(int) getpid(),id++);
1.8 takayama 1156:
1.29 ! saito 1157: printerName = XawDialogGetValueString(PrintDialog_lp);
! 1158: PrinterName = (char *)malloc(sizeof(char)*strlen(printerName)+1);
! 1159: strcpy(PrinterName,printerName);
! 1160: for (i=0; i<strlen(PrinterName); i++) {
! 1161: if (PrinterName[i] == 0xd || PrinterName[i] == 0xa) {
! 1162: PrinterName[i] = 0; break;
! 1163: }
! 1164: }
! 1165: fprintf(stderr,"printerName=%s\n",PrinterName); fflush(NULL);
! 1166: fp = fopen(fname,"w");
! 1167: if (fp == NULL) {
! 1168: warning(Can,"Could not open the output file.");
! 1169: }else{
! 1170: generate_psfile(Can,fp);
! 1171: fclose(fp);
1.8 takayama 1172: }
1173:
1.29 ! saito 1174: sprintf(cmd,"lpr -P%s %s",PrinterName,fname);
! 1175: if (system(cmd)) {
! 1176: warning(Can,"Unknown printer?");
! 1177: }
! 1178: sprintf(cmd,"rm -f %s",fname);
! 1179: system(cmd);
! 1180: XtPopdown(shell); XtDestroyWidget(shell);
! 1181: XtSetSensitive(fbutton,True);
1.8 takayama 1182: }
1183:
1184: /* test sequence
1185: ox_launch(0,"ox_plot");
1186: ifplot(x^2-y^3);
1.27 saito 1187: drawcircle(0,0,100,0xff000,0);
1.8 takayama 1188: */
1.15 takayama 1189: static int getColorSizeOfImageForPS(int xsize,int ysize,XImage *image,
1190: struct xcolorForPS **tableOfxcolorForPS);
1191:
1.8 takayama 1192: static void generate_psfile(can,fp)
1.29 ! saito 1193: struct canvas *can;
! 1194: FILE *fp;
1.8 takayama 1195: {
1.29 ! saito 1196: int x,y;
! 1197: XImage *image;
! 1198: int color[1];
! 1199: int colorSize = 1;
! 1200: char *m;
! 1201: struct xcolorForPS *tableOfxcolorForPS;
! 1202: extern int PrintingMethod;
! 1203: fprintf(stderr,"generate_psfile\n");
! 1204: if (PrintingMethod == PRINTING_METHOD_BITMAP) {
! 1205: if ( display ) {
! 1206: fprintf(stderr,"generate_psfile: output to a file.\n");
! 1207: image = XGetImage(display,can->pix,
1.8 takayama 1208: 0,0,can->width,can->height,-1,ZPixmap);
1.29 ! saito 1209: color[0] = 0; /* black line */
! 1210: PSFromImage(fp,image,can);
! 1211: }else{
! 1212: fprintf(stderr,"Cannot print on this system\n");
! 1213: }
1.8 takayama 1214: }else{
1.29 ! saito 1215: method_is_not_available();
1.8 takayama 1216: }
1.29 ! saito 1217: fflush(NULL);
1.8 takayama 1218: }
1219:
1220: static void method_is_not_available() {
1221: char *m;
1222: #define MSG1 "Printing method \""
1223: #define MSG2 "\" is not available for this picture."
1224: m = (char *)malloc(strlen(MSG1)+strlen(MSG2)+strlen(Printing_methods[PrintingMethod])+1);
1225: strcpy(m,MSG1);
1226: strcat(m,Printing_methods[PrintingMethod]);
1227: strcat(m,MSG2);
1228: warning(Can,m);
1.9 noro 1229: }
1230:
1231: clear_pixmap(can)
1232: struct canvas *can;
1233: {
1234: XFillRectangle(display,can->pix,clearGC,0,0,can->width,can->height);
1235: XFlush(display);
1.1 noro 1236: }
1.15 takayama 1237:
1238: /*
1239: The following functions are used to generate color postscript file.
1240: */
1241: /* In order to count colorSize, binary tree (sm_btree) is used. */
1242: static struct sm_btree *sm_newNode(unsigned long v);
1243: static int sm_insert(struct sm_btree *node,unsigned long v);
1244: static int sm_count(struct sm_btree *rootp);
1.17 takayama 1245:
1.15 takayama 1246: struct sm_btree {
1247: unsigned long p;
1248: struct sm_btree * left;
1249: struct sm_btree * right;
1250: };
1251: static struct sm_btree *sm_newNode(unsigned long v) {
1252: struct sm_btree * n;
1253: n = (struct sm_btree *)MALLOC(sizeof(struct sm_btree));
1254: if (n == NULL) { fprintf(stderr,"No more memory.\n"); exit(10); }
1255: n->p = v;
1256: n->left = NULL;
1257: n->right = NULL;
1258: return n;
1259: }
1260: static int sm_insert(struct sm_btree *node,unsigned long v)
1261: {
1262: if (node->p == v) return;
1263: if (node->p > v) {
1264: if (node->left == NULL) {
1265: node->left = sm_newNode(v);
1266: return;
1267: }
1268: sm_insert(node->left,v);
1269: }
1270: if (node->p < v) {
1271: if (node->right == NULL) {
1272: node->right = sm_newNode(v);
1273: return;
1274: }
1275: sm_insert(node->right,v);
1276: }
1277: }
1278: static int sm_count(struct sm_btree *rootp)
1279: {
1280: if (rootp == NULL) return 0;
1281: return (1+sm_count(rootp->left)+sm_count(rootp->right));
1282: }
1283:
1.16 takayama 1284: static int setTableOfxcolorForPS(struct sm_btree *rootp,
1285: struct xcolorForPS *table,int k,int size)
1286: {
1287: int m;
1288: m = k;
1289: if (rootp == NULL) return;
1290: if (k >= size) {
1291: warning(Can,"internal error of setTableOfxcolorForPS");
1292: }
1293: if (rootp->left != NULL) {
1294: m = setTableOfxcolorForPS(rootp->left,table,k,size);
1295: }
1296:
1297: (table[m]).pixel = rootp->p;
1298: m++;
1299: if (rootp->right != NULL) {
1300: m = setTableOfxcolorForPS(rootp->right,table,m,size);
1301: }
1302: return m;
1303: }
1304:
1305:
1.15 takayama 1306: static int getColorSizeOfImageForPS(int xsize,int ysize,XImage *image,
1307: struct xcolorForPS **tableOfxcolorForPS)
1308: {
1309: int x,y;
1310: int size;
1311: struct sm_btree root;
1312: struct xcolorForPS *table;
1.16 takayama 1313: XStandardColormap scm;
1314: Colormap cm;
1315: XColor color;
1316: XColor white;
1317: int screen,i;
1318:
1.15 takayama 1319: root.p = 0;
1320: root.left = NULL; root.right=NULL;
1321: /* get color size */
1322: for (x=0; x<xsize; x++) {
1323: for (y=0; y<ysize; y++) {
1324: sm_insert(&root,XGetPixel(image,x,y));
1325: }
1326: }
1327: size=sm_count(&root);
1328:
1329: table = (struct xcolorForPS *)MALLOC((size+1)*sizeof(struct xcolorForPS));
1330: if (table == NULL) {
1331: fprintf(stderr,"No more memory in getColorSizeOfImageForPS.\n");
1332: return 0;
1333: }
1334: /* Set rgb values standing for the pixel values.
1335: */
1.16 takayama 1336: if (setTableOfxcolorForPS(&root,table,0,size) != size) {
1337: warning(Can,"internal error.");
1338: return ;
1339: }
1340:
1341: screen = DefaultScreen(display);
1342: cm = DefaultColormap(display,screen);
1343: /* BUG: it does not work.
1344: if (!XGetStandardColormap(display,RootWindow(display,DefaultScreen(display)),&scm,XA_RGB_DEFAULT_MAP)) {
1345: warning(Can,"failed to open the X Standard Colormap.");
1346: scm.red_max = 0xffff;
1347: scm.green_max = 0xffff;
1348: scm.blue_max = 0xffff;
1349: }
1350: */
1351: /* Set by hand. */
1352: scm.red_max = 0xffff;
1353: scm.green_max = 0xffff;
1354: scm.blue_max = 0xffff;
1355: XParseColor(display,cm,"White",&white);
1356: for (i=0; i<size; i++) {
1357: color.pixel=(table[i]).pixel;
1358: /*
1359: {
1360: char s[254];
1361: sprintf(s,"%ld",color.pixel);
1362: warning(Can,s);
1363: }
1364: */
1365: XQueryColor(display,cm,&color);
1366: (table[i]).r = ((double) color.red)/((double) scm.red_max);
1367: (table[i]).g = ((double) color.green)/((double) scm.green_max);
1368: (table[i]).b = ((double) color.blue)/((double) scm.blue_max);
1369: if ((table[i]).r > 1.0) (table[i]).r = 1.0;
1370: if ((table[i]).g > 1.0) (table[i]).g = 1.0;
1371: if ((table[i]).b > 1.0) (table[i]).b = 1.0;
1372: if (color.red == white.red && color.green == white.green
1373: && color.blue == white.blue) {
1374: (table[i]).print = 0;
1375: }else{
1376: (table[i]).print = 1;
1377: }
1378: }
1.15 takayama 1379:
1380: *tableOfxcolorForPS = table;
1381: return size;
1382: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>