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