[BACK]Return to ox_plot_xevent.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2018 / plot

Annotation of OpenXM_contrib2/asir2018/plot/ox_plot_xevent.c, Revision 1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>