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

Annotation of OpenXM_contrib2/asir2000/plot/ox_plot_xevent.c, Revision 1.11

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

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