[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.9

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.9     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/plot/ox_plot_xevent.c,v 1.8 2000/10/24 01:53:53 takayama 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);
                    152:                        if ( !busy ) {
                    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);
                    707:        XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,drawGC);
                    708:        XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,dashGC);
                    709:        XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,clearGC);
                    710:        XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,scaleGC);
                    711:        XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,xorGC);
                    712:        XCopyGC(display,DefaultGC(display,scrn),(1L<<(GCLastBit+1))-1,colorGC);
                    713:        XSetForeground(display,drawGC,forePixel);
                    714:        XSetForeground(display,scaleGC,forePixel);
                    715:        XSetForeground(display,clearGC,backPixel);
                    716:        XSetForeground(display,xorGC,forePixel^backPixel);
                    717:        XSetFunction(display,xorGC,GXxor);
                    718:        XSetForeground(display,dashGC,dashPixel);
                    719:        XSetLineAttributes(display,dashGC,1,LineOnOffDash,CapButt,JoinRound);
                    720:
                    721:        color.red = color.green = color.blue = 0xffff/2;
                    722:        XAllocColor(display,DefaultColormap(display,scrn),&color);
                    723:        XSetForeground(display,hlGC,color.pixel);
                    724:        color.red = 0xffff; color.green = color.blue = 0;
                    725:        XAllocColor(display,DefaultColormap(display,scrn),&color);
                    726:        XSetForeground(display,colorGC,color.pixel);
                    727: }
                    728:
                    729: create_cursors() {
                    730:        static XColor fg = {0, 0x0, 0x0, 0x0,DoRed|DoGreen|DoBlue,0};
                    731:        static XColor bg = {0, 0xffff, 0xffff, 0xffff,DoRed|DoGreen|DoBlue,0};
                    732:
                    733:        XAllocColor(display,DefaultColormap(display,scrn),&fg);
                    734:        XAllocColor(display,DefaultColormap(display,scrn),&bg);
                    735:        normalcur = create_cursor(h_bits,h_m_bits,h_width,h_height,
                    736:                h_x_hot,h_y_hot,&fg,&bg);
                    737:        runningcur = create_cursor(ht_bits,ht_m_bits,ht_width,ht_height,
                    738:                ht_width/2,ht_height/2,&fg,&bg);
                    739:        errorcur = create_cursor(m_bits,m_m_bits,m_width,m_height,
                    740:                m_width/2,m_height/2,&fg,&bg);
                    741: }
                    742:
                    743: Cursor create_cursor(image,mask,width,height,xhot,yhot,fg,bg)
                    744: char *image,*mask;
                    745: int width,height,xhot,yhot;
                    746: XColor *fg,*bg;
                    747: {
                    748:        Pixmap ipix,mpix;
                    749:
                    750:        ipix = XCreateBitmapFromData(display,rootwin,image,width,height);
                    751:        mpix = XCreateBitmapFromData(display,rootwin,mask,width,height);
                    752:        return XCreatePixmapCursor(display,ipix,mpix,fg,bg,xhot,yhot);
                    753: }
                    754:
                    755: copy_to_canvas(can)
                    756: struct canvas *can;
                    757: {
                    758:        if ( display ) {
                    759:                XCopyArea(display,can->pix,can->window,
                    760:                        drawGC,0,0,can->width,can->height,0,0);
                    761:                pline(display,can,can->window);
                    762:                XFlush(display);
                    763:        }
                    764: }
                    765:
                    766: copy_subimage(subcan,can,pos)
                    767: struct canvas *subcan,*can;
                    768: XPoint pos;
                    769: {
                    770:        if ( display ) {
                    771:                XCopyArea(display,subcan->pix,can->pix,
                    772:                        drawGC,0,0,subcan->width,subcan->height,pos.x,pos.y);
                    773:                XFlush(display);
                    774:        }
                    775: }
                    776:
                    777: #include <signal.h>
                    778: #include <fcntl.h>
                    779:
                    780: set_selection() {
                    781:        if ( current_can ) {
                    782:                XSelectInput(display,current_can->window,0);
                    783:                XFlush(display);
                    784:        }
                    785: }
                    786:
                    787: reset_selection() {
                    788:        if ( current_can ) {
                    789:                XSelectInput(display,current_can->window,NormalSelection);
                    790:                XFlush(display);
                    791:        }
                    792: }
                    793:
                    794: set_busy(can)
                    795: struct canvas *can;
                    796: {
                    797:        busy = 1;
                    798:        XtSetSensitive(can->wideb,False);
                    799:        XtSetSensitive(can->preciseb,False);
                    800:        XtSetSensitive(can->noaxisb,False);
                    801:        XFlush(display);
                    802: }
                    803:
                    804: reset_busy(can)
                    805: struct canvas *can;
                    806: {
                    807:        busy = 0;
                    808:        if ( can->window ) {
                    809:                XtSetSensitive(can->wideb,True);
                    810:                XtSetSensitive(can->noaxisb,True);
                    811:                if ( can->mode == MODE_IFPLOT && qpcheck((Obj)can->formula) )
                    812:                        XtSetSensitive(can->preciseb,True);
                    813:                XFlush(display);
                    814:        }
                    815: }
                    816:
                    817: reset_current_computation()
                    818: {
                    819:        if ( current_can ) {
                    820:                reset_selection(); reset_busy(current_can);
                    821:                define_cursor(current_can->window,normalcur);
                    822:        }
1.8       takayama  823: }
                    824:
                    825: static struct canvas *Can;
                    826: /* void print_canvas(Widget w,struct canvas *can, XtPointer calldata); */
                    827: static void output_to_file(Widget , XtPointer, XtPointer );
                    828: static void output_to_ps_printer(Widget , XtPointer, XtPointer );
                    829: static void cancel_output_to_file(Widget , XtPointer,XtPointer);
                    830: static void generate_psfile(struct canvas *can, FILE *fp);
                    831: static void set_printing_method(Widget,XtPointer,XtPointer);
                    832: static void method_is_not_available();
                    833: static Widget PrintDialog;
                    834: static Widget PrintDialog_lp;
                    835: static Widget W;
                    836: static char *Fname = NULL;
                    837: static char *PrinterName = NULL;
                    838: #define PRINTING_METHOD_BITMAP 0
                    839: #define PRINTING_METHOD_VECTOR 1
                    840: static int PrintingMethod = PRINTING_METHOD_BITMAP;
                    841: static String Printing_methods[]={
                    842:   "bitMap","vector",
                    843: };
                    844: static int N_printing_methods = 2;
                    845:
                    846: /*
                    847: static Widget create_printing_method_bar(Widget parent) {
                    848:   Widget panel, button;
                    849:   int i,n;
                    850:   Arg wargs[1];
                    851:   panel = XtCreateManagedWidget("printing methods",panedWidgetClass,
                    852:                                                                parent,NULL,0);
                    853:   for (i=0; i<N_printing_methods; i++) {
                    854:        button = XtCreateManagedWidget(Printing_methods[i],menuButtonWidgetClass,
                    855:                                                                   panel,NULL,0);
                    856:        fprintf(stderr,"button=%x\n",(int) button);
                    857:        XtAddCallback(button,XtNcallback,set_printing_method,(XtPointer) i);
                    858:   }
                    859:   return(panel);
                    860: }
                    861: */
                    862:
                    863:
                    864: static void print_canvas(w,can,calldata)
                    865:         Widget w;
                    866:         struct canvas *can;
                    867:         XtPointer calldata;
                    868: {
                    869:   Widget fshell,fdialog;
                    870:   extern struct canvas *Can;
                    871:   extern Widget W;
                    872:   Widget entry;
                    873:   int i;
                    874:   Arg arg[1];
                    875:   static void output_to_printer();
                    876:   static void print_canvas_to_file();
                    877:   static void printing_method();
                    878:
                    879:   W = w;
                    880:   Can = can;
                    881:   create_popup(can->shell,"Print/Output PS file","",&fshell,&fdialog);
                    882:   XawDialogAddButton(fdialog,"print",output_to_printer,w);
                    883:   XawDialogAddButton(fdialog,"output PS file",print_canvas_to_file,w);
                    884:   XawDialogAddButton(fdialog,"method",printing_method,w);
                    885:   XawDialogAddButton(fdialog,"dismiss",cancel_output_to_file,w);
                    886:   XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
                    887: }
                    888:
                    889: static void set_printing_method(Widget w,XtPointer number,XtPointer call_data) {
                    890:   Widget shell;
                    891:   extern int PrintingMethod;
                    892:   PrintingMethod = (int) number;
                    893:   fprintf(stderr,"PrintingMethod=%d\n",number);
                    894:   shell = XtParent(XtParent(w));
                    895:   XtPopdown(shell); XtDestroyWidget(shell);
                    896: }
                    897:
                    898: static void printing_method(w,can,calldata)
                    899:         Widget w;
                    900:         struct canvas *can;
                    901:         XtPointer calldata;
                    902: {
                    903:   Arg arg[10];
                    904:   int i,n;
                    905:   Widget fshell,fdialog;
                    906:   extern struct canvas *Can;
                    907:   extern int PrintingMethod;
                    908:
                    909:   w = W;
                    910:   can = Can;
                    911:   create_popup(can->shell,"Printing method",Printing_methods[PrintingMethod],
                    912:                           &fshell,&fdialog);
                    913:   n = 0;
                    914:   XtSetArg(arg[n], XtNlabel, "Method: "); n++;
                    915:   XtSetArg(arg[n], XtNvalue, Printing_methods[PrintingMethod]); n++;
                    916:   XtSetValues(fdialog,arg,n);
                    917:   for (i=0; i<N_printing_methods; i++) {
                    918:        XawDialogAddButton(fdialog,Printing_methods[i],set_printing_method,(XtPointer) i);
                    919:   }
                    920:   XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
                    921: }
                    922: static void print_canvas_to_file(w,can,calldata)
                    923:         Widget w;
                    924:         struct canvas *can;
                    925:         XtPointer calldata;
                    926: {
                    927:   FILE *fp;
                    928:   Arg arg[10];
                    929:   int n;
                    930:   static char *psfile = NULL;
                    931:   Widget fshell,fdialog;
                    932:   extern struct canvas *Can;
                    933:   extern Widget PrintDialog;
                    934:   extern char *Fname;
                    935:
                    936:   w = W;
                    937:   can = Can;
                    938:   if (psfile == NULL || Fname == NULL) psfile = "ox_plot.eps";
                    939:   else psfile = Fname;
                    940:   create_popup(can->shell,"Output as PS file",psfile,&fshell,&fdialog);
                    941:   n = 0;
                    942:   XtSetArg(arg[n], XtNlabel, "File : "); n++;
                    943:   XtSetArg(arg[n], XtNvalue, psfile); n++;
                    944:   XtSetValues(fdialog,arg,n);
                    945:   XawDialogAddButton(fdialog,"output to file",output_to_file,w);
                    946:   XawDialogAddButton(fdialog,"cancel",cancel_output_to_file,w);
                    947:   PrintDialog = fdialog;
                    948:   XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
                    949: }
                    950: static void output_to_printer(w,can,calldata)
                    951:         Widget w;
                    952:         struct canvas *can;
                    953:         XtPointer calldata;
                    954: {
                    955:   FILE *fp;
                    956:   Arg arg[10];
                    957:   int n;
                    958:   static char *psfile = NULL;
                    959:   Widget fshell,fdialog;
                    960:   extern struct canvas *Can;
                    961:   extern Widget PrintDialog_lp;
                    962:   extern char *PrinterName;
                    963:
                    964:   w = W;
                    965:   can = Can;
                    966:   if (psfile  == NULL || PrinterName == NULL) psfile = "lp";
                    967:   else psfile = PrinterName;
                    968:   create_popup(can->shell,"Output PS file to printer",psfile,&fshell,&fdialog);
                    969:   n = 0;
                    970:   XtSetArg(arg[n], XtNlabel, "PS Printer Name : "); n++;
                    971:   XtSetArg(arg[n], XtNvalue, psfile); n++;
                    972:   XtSetValues(fdialog,arg,n);
                    973:   XawDialogAddButton(fdialog,"output to PS printer",output_to_ps_printer,w);
                    974:   XawDialogAddButton(fdialog,"cancel",cancel_output_to_file,w);
                    975:   PrintDialog_lp = fdialog;
                    976:   XtSetSensitive(w,False); XtPopup(fshell,XtGrabNone);
                    977: }
                    978:
                    979: static void cancel_output_to_file(w,fbutton,call)
                    980:         Widget w;
                    981:         XtPointer fbutton, call;
                    982: {
                    983:   Widget shell = XtParent(XtParent(w));
                    984:   XtPopdown(shell); XtDestroyWidget(shell);
                    985:   XtSetSensitive(fbutton,True);
                    986: }
                    987:
                    988: static void output_to_file(w,fbutton,call)
                    989:         Widget w;
                    990:         XtPointer fbutton, call;
                    991: {
                    992:   char *fname;
                    993:   FILE *fp;
                    994:   int i;
                    995:   char *m;
                    996:   extern struct canvas *Can;
                    997:   extern Widget PrintDialog;
                    998:   extern int PrintingMethod;
                    999:   Widget shell = XtParent(XtParent(w));
                   1000:
                   1001:   if (PrintingMethod == PRINTING_METHOD_BITMAP) {
                   1002:   }else{
                   1003:        method_is_not_available();
                   1004:        XtPopdown(shell); XtDestroyWidget(shell);
                   1005:        XtSetSensitive(fbutton,True);
                   1006:        return;
                   1007:   }
                   1008:
                   1009:   fname = XawDialogGetValueString(PrintDialog);
                   1010:   Fname = (char *)malloc(sizeof(char)*strlen(fname)+1);
                   1011:   strcpy(Fname,fname);
                   1012:   for (i=0; i<strlen(Fname); i++) {
                   1013:        if (Fname[i] == 0xd || Fname[i] == 0xa) {
                   1014:          Fname[i] = 0; break;
                   1015:        }
                   1016:   }
                   1017:   fprintf(stderr,"fname=%s\n",Fname); fflush(NULL);
                   1018:   fp = fopen(Fname,"w");
                   1019:   if (fp == NULL) {
                   1020:        warning(Can,"Could not open the output file.");
                   1021:   }else{
                   1022:        generate_psfile(Can,fp);
                   1023:        fclose(fp);
                   1024:   }
                   1025:
                   1026:   XtPopdown(shell); XtDestroyWidget(shell);
                   1027:   XtSetSensitive(fbutton,True);
                   1028: }
                   1029:
                   1030: static void output_to_ps_printer(w,fbutton,call)
                   1031:         Widget w;
                   1032:         XtPointer fbutton, call;
                   1033: {
                   1034:   char *printerName;
                   1035:   FILE *fp;
                   1036:   extern struct canvas *Can;
                   1037:   extern Widget PrintDialog_lp;
                   1038:   char fname[256];
                   1039:   char cmd[512];
                   1040:   static int id = 0;
                   1041:   int i;
                   1042:   Widget shell = XtParent(XtParent(w));
                   1043:
                   1044:   if (PrintingMethod == PRINTING_METHOD_BITMAP) {
                   1045:   }else{
                   1046:        method_is_not_available();
                   1047:        XtPopdown(shell); XtDestroyWidget(shell);
                   1048:        XtSetSensitive(fbutton,True);
                   1049:        return;
                   1050:   }
                   1051:
                   1052:   sprintf(fname,"/tmp/ox_plot_%d.eps",(int) getpid(),id++);
                   1053:
                   1054:   printerName = XawDialogGetValueString(PrintDialog_lp);
                   1055:   PrinterName = (char *)malloc(sizeof(char)*strlen(printerName)+1);
                   1056:   strcpy(PrinterName,printerName);
                   1057:   for (i=0; i<strlen(PrinterName); i++) {
                   1058:        if (PrinterName[i] == 0xd || PrinterName[i] == 0xa) {
                   1059:          PrinterName[i] = 0; break;
                   1060:        }
                   1061:   }
                   1062:   fprintf(stderr,"printerName=%s\n",PrinterName); fflush(NULL);
                   1063:   fp = fopen(fname,"w");
                   1064:   if (fp == NULL) {
                   1065:        warning(Can,"Could not open the output file.");
                   1066:   }else{
                   1067:        generate_psfile(Can,fp);
                   1068:        fclose(fp);
                   1069:   }
                   1070:
                   1071:   sprintf(cmd,"lpr -P%s %s",PrinterName,fname);
                   1072:   if (system(cmd)) {
                   1073:        warning(Can,"Unknown printer?");
                   1074:   }
                   1075:   sprintf(cmd,"rm -f %s",fname);
                   1076:   system(cmd);
                   1077:   XtPopdown(shell); XtDestroyWidget(shell);
                   1078:   XtSetSensitive(fbutton,True);
                   1079: }
                   1080:
                   1081:
                   1082: /* test sequence
                   1083:    ox_launch(0,"ox_plot");
                   1084:    ifplot(x^2-y^3);
                   1085:    drawcircle(0,0,100,0,0);
                   1086:    */
                   1087: static void generate_psfile(can,fp)
                   1088:         struct canvas *can;
                   1089:         FILE *fp;
                   1090: {
                   1091:   int x,y;
                   1092:   XImage *image;
                   1093:   int color[1];
                   1094:   int colorSize = 1;
                   1095:   char *m;
                   1096:   extern int PrintingMethod;
                   1097:   fprintf(stderr,"generate_psfile\n");
                   1098:   if (PrintingMethod == PRINTING_METHOD_BITMAP) {
                   1099:        if ( display ) {
                   1100:          fprintf(stderr,"generate_psfile: output to a file.\n");
                   1101:          image = XGetImage(display,can->pix,
                   1102:                                                0,0,can->width,can->height,-1,ZPixmap);
                   1103:          color[0] = 0; /* balck line */
                   1104:          generatePS_from_image(fp,image,can->width,can->height,color,colorSize,can);
                   1105:        }else{
                   1106:          fprintf(stderr,"Cannot print on this system\n");
                   1107:        }
                   1108:   }else{
                   1109:        method_is_not_available();
                   1110:   }
                   1111:   fflush(NULL);
                   1112: }
                   1113:
                   1114: static void method_is_not_available() {
                   1115:   char *m;
                   1116: #define MSG1 "Printing method \""
                   1117: #define MSG2 "\" is not available for this picture."
                   1118:   m = (char *)malloc(strlen(MSG1)+strlen(MSG2)+strlen(Printing_methods[PrintingMethod])+1);
                   1119:   strcpy(m,MSG1);
                   1120:   strcat(m,Printing_methods[PrintingMethod]);
                   1121:   strcat(m,MSG2);
                   1122:   warning(Can,m);
1.9     ! noro     1123: }
        !          1124:
        !          1125: clear_pixmap(can)
        !          1126: struct canvas *can;
        !          1127: {
        !          1128:        XFillRectangle(display,can->pix,clearGC,0,0,can->width,can->height);
        !          1129:        XFlush(display);
1.1       noro     1130: }

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