~ubuntu-branches/ubuntu/dapper/perl-tk/dapper

« back to all changes in this revision

Viewing changes to pTk/mTk/generic/tkCanvBmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2006-01-16 16:54:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060116165402-1ppygm8hh8ahel2x
Tags: 1:804.027-2
* Incorporate changes from NMU (Thanks to Steve Kowalik.
  Closes: #348086)
* debian/control: Update Standards-Version (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *      This file implements bitmap items for canvas widgets.
5
5
 *
6
6
 * Copyright (c) 1992-1994 The Regents of the University of California.
7
 
 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
 
7
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
8
8
 *
9
9
 * See the file "license.terms" for information on usage and redistribution
10
10
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
11
 *
12
 
 * RCS: @(#) $Id: tkCanvBmap.c,v 1.2 1998/09/14 18:23:04 stanton Exp $
 
12
 * RCS: @(#) $Id: tkCanvBmap.c,v 1.7.2.1 2003/04/18 21:56:47 hobbs Exp $
13
13
 */
14
14
 
15
15
#include "tkInt.h"
45
45
 */
46
46
 
47
47
static Tk_CustomOption stateOption = {
48
 
    Tk_StateParseProc,
49
 
    Tk_StatePrintProc, (ClientData) 2
 
48
    TkStateParseProc,
 
49
    TkStatePrintProc, (ClientData) 2
50
50
};
51
51
static Tk_CustomOption tagsOption = {
52
52
    Tk_CanvasTagsParseProc,
93
93
 */
94
94
 
95
95
static int              BitmapCoords _ANSI_ARGS_((Tcl_Interp *interp,
96
 
                            Tk_Canvas canvas, Tk_Item *itemPtr, int argc,
97
 
                            char **argv));
 
96
                            Tk_Canvas canvas, Tk_Item *itemPtr, int objc,
 
97
                            Tcl_Obj *CONST objv[]));
98
98
static int              BitmapToArea _ANSI_ARGS_((Tk_Canvas canvas,
99
99
                            Tk_Item *itemPtr, double *rectPtr));
100
100
static double           BitmapToPoint _ANSI_ARGS_((Tk_Canvas canvas,
104
104
static void             ComputeBitmapBbox _ANSI_ARGS_((Tk_Canvas canvas,
105
105
                            BitmapItem *bmapPtr));
106
106
static int              ConfigureBitmap _ANSI_ARGS_((Tcl_Interp *interp,
107
 
                            Tk_Canvas canvas, Tk_Item *itemPtr, int argc,
108
 
                            char **argv, int flags));
109
 
static int              CreateTkBitmap _ANSI_ARGS_((Tcl_Interp *interp,
 
107
                            Tk_Canvas canvas, Tk_Item *itemPtr, int objc,
 
108
                            Tcl_Obj *CONST objv[], int flags));
 
109
static int              TkcCreateBitmap _ANSI_ARGS_((Tcl_Interp *interp,
110
110
                            Tk_Canvas canvas, struct Tk_Item *itemPtr,
111
 
                            int argc, char **argv));
 
111
                            int objc, Tcl_Obj *CONST objv[]));
112
112
static void             DeleteBitmap _ANSI_ARGS_((Tk_Canvas canvas,
113
113
                            Tk_Item *itemPtr, Display *display));
114
114
static void             DisplayBitmap _ANSI_ARGS_((Tk_Canvas canvas,
128
128
Tk_ItemType tkBitmapType = {
129
129
    "bitmap",                           /* name */
130
130
    sizeof(BitmapItem),                 /* itemSize */
131
 
    CreateTkBitmap,                     /* createProc */
 
131
    TkcCreateBitmap,                    /* createProc */
132
132
    configSpecs,                        /* configSpecs */
133
133
    ConfigureBitmap,                    /* configureProc */
134
134
    BitmapCoords,                       /* coordProc */
135
135
    DeleteBitmap,                       /* deleteProc */
136
136
    DisplayBitmap,                      /* displayProc */
137
 
    TK_ITEM_VISITOR_SUPPORT|TK_CONFIG_OBJS,/* flags */
 
137
    TK_CONFIG_OBJS,                     /* flags */
138
138
    BitmapToPoint,                      /* pointProc */
139
139
    BitmapToArea,                       /* areaProc */
140
140
    BitmapToPostscript,                 /* postscriptProc */
146
146
    (Tk_ItemInsertProc *) NULL,         /* insertProc */
147
147
    (Tk_ItemDCharsProc *) NULL,         /* dTextProc */
148
148
    (Tk_ItemType *) NULL,               /* nextPtr */
149
 
    (Tk_ItemBboxProc *) ComputeBitmapBbox,/* bboxProc */
150
 
    Tk_Offset(Tk_VisitorType, visitBitmap), /* acceptProc */
151
 
    (Tk_ItemGetCoordProc *) NULL,       /* getCoordProc */
152
 
    (Tk_ItemSetCoordProc *) NULL        /* setCoordProc */
153
149
};
154
 
 
 
150
 
155
151
/*
156
152
 *--------------------------------------------------------------
157
153
 *
158
 
 * CreateBitmap --
 
154
 * TkcCreateBitmap --
159
155
 *
160
156
 *      This procedure is invoked to create a new bitmap
161
157
 *      item in a canvas.
163
159
 * Results:
164
160
 *      A standard Tcl return value.  If an error occurred in
165
161
 *      creating the item, then an error message is left in
166
 
 *      interp->result;  in this case itemPtr is left uninitialized,
 
162
 *      the interp's result;  in this case itemPtr is left uninitialized,
167
163
 *      so it can be safely freed by the caller.
168
164
 *
169
165
 * Side effects:
173
169
 */
174
170
 
175
171
static int
176
 
CreateTkBitmap(interp, canvas, itemPtr, argc, argv)
 
172
TkcCreateBitmap(interp, canvas, itemPtr, objc, objv)
177
173
    Tcl_Interp *interp;                 /* Interpreter for error reporting. */
178
174
    Tk_Canvas canvas;                   /* Canvas to hold new item. */
179
175
    Tk_Item *itemPtr;                   /* Record to hold new item;  header
180
176
                                         * has been initialized by caller. */
181
 
    int argc;                           /* Number of arguments in argv. */
182
 
    char **argv;                        /* Arguments describing rectangle. */
 
177
    int objc;                           /* Number of arguments in objv. */
 
178
    Tcl_Obj *CONST objv[];              /* Arguments describing rectangle. */
183
179
{
184
180
    BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
185
181
    int i;
186
182
 
187
 
    if (argc==1) {
188
 
        i = 1;
189
 
    } else {
190
 
        char *arg = Tcl_GetStringFromObj(objv[1], NULL);
191
 
        if (((argc>1) && (arg[0] == '-')
192
 
                && (arg[1] >= 'a') && (arg[1] <= 'z'))) {
193
 
            i = 1;
194
 
        } else {
195
 
            i = 2;
196
 
        }
197
 
    }
198
 
 
199
 
    if (argc < i) {
200
 
        Tcl_AppendResult(interp, "wrong # args: should be \"",
201
 
                Tk_PathName(Tk_CanvasTkwin(canvas)), " create ",
202
 
                itemPtr->typePtr->name, " x y ?options?\"",
203
 
                (char *) NULL);
204
 
        return TCL_ERROR;
 
183
    if (objc == 0) {
 
184
        panic("canvas did not pass any coords\n");
205
185
    }
206
186
 
207
187
    /*
222
202
 
223
203
    /*
224
204
     * Process the arguments to fill in the item record.
 
205
     * Only 1 (list) or 2 (x y) coords are allowed.
225
206
     */
226
207
 
227
 
    if ((BitmapCoords(interp, canvas, itemPtr, i, argv) != TCL_OK)) {
 
208
    if (objc == 1) {
 
209
        i = 1;
 
210
    } else {
 
211
        char *arg = Tcl_GetString(objv[1]);
 
212
        i = 2;
 
213
        if ((arg[0] == '-') && (arg[1] >= 'a') && (arg[1] <= 'z')) {
 
214
            i = 1;
 
215
        }
 
216
    }
 
217
    if (BitmapCoords(interp, canvas, itemPtr, i, objv) != TCL_OK) {
228
218
        goto error;
229
219
    }
230
 
    if (ConfigureBitmap(interp, canvas, itemPtr, argc-i, argv+i, 0) == TCL_OK) {
 
220
    if (ConfigureBitmap(interp, canvas, itemPtr, objc-i, objv+i, 0)
 
221
            == TCL_OK) {
231
222
        return TCL_OK;
232
223
    }
233
224
 
235
226
    DeleteBitmap(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas)));
236
227
    return TCL_ERROR;
237
228
}
238
 
 
 
229
 
239
230
/*
240
231
 *--------------------------------------------------------------
241
232
 *
246
237
 *      details on what it does.
247
238
 *
248
239
 * Results:
249
 
 *      Returns TCL_OK or TCL_ERROR, and sets interp->result.
 
240
 *      Returns TCL_OK or TCL_ERROR, and sets the interp's result.
250
241
 *
251
242
 * Side effects:
252
243
 *      The coordinates for the given item may be changed.
255
246
 */
256
247
 
257
248
static int
258
 
BitmapCoords(interp, canvas, itemPtr, argc, argv)
 
249
BitmapCoords(interp, canvas, itemPtr, objc, objv)
259
250
    Tcl_Interp *interp;                 /* Used for error reporting. */
260
251
    Tk_Canvas canvas;                   /* Canvas containing item. */
261
252
    Tk_Item *itemPtr;                   /* Item whose coordinates are to be
262
253
                                         * read or modified. */
263
 
    int argc;                           /* Number of coordinates supplied in
264
 
                                         * argv. */
265
 
    char **argv;                        /* Array of coordinates: x1, y1,
 
254
    int objc;                           /* Number of coordinates supplied in
 
255
                                         * objv. */
 
256
    Tcl_Obj *CONST objv[];              /* Array of coordinates: x1, y1,
266
257
                                         * x2, y2, ... */
267
258
{
268
259
    BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
269
 
    char x[TCL_DOUBLE_SPACE];
270
260
 
271
 
    if (argc == 0) {
 
261
    if (objc == 0) {
272
262
        Tcl_Obj *obj = Tcl_NewObj();
273
263
        Tcl_Obj *subobj = Tcl_NewDoubleObj(bmapPtr->x);
274
264
        Tcl_ListObjAppendElement(interp, obj, subobj);
275
265
        subobj = Tcl_NewDoubleObj(bmapPtr->y);
276
266
        Tcl_ListObjAppendElement(interp, obj, subobj);
277
267
        Tcl_SetObjResult(interp, obj);
278
 
    } else if (argc <3) {
279
 
        if (argc==1) {
280
 
            if (Tcl_ListObjGetElements(interp, objv[0], &argc, &argv) != TCL_OK) {
 
268
    } else if (objc < 3) {
 
269
        if (objc == 1) {
 
270
            if (Tcl_ListObjGetElements(interp, objv[0], &objc,
 
271
                    (Tcl_Obj ***) &objv) != TCL_OK) {
281
272
                return TCL_ERROR;
282
 
            } else if (argc != 2) {
283
 
                sprintf(x,"%d",argc);
284
 
                Tcl_AppendResult(interp, "wrong # coordinates: expected 2, got ",
285
 
                x, (char *) NULL);
 
273
            } else if (objc != 2) {
 
274
                char buf[64 + TCL_INTEGER_SPACE];
 
275
 
 
276
                sprintf(buf, "wrong # coordinates: expected 2, got %d", objc);
 
277
                Tcl_SetResult(interp, buf, TCL_VOLATILE);
286
278
                return TCL_ERROR;
287
279
            }
288
280
        }
289
 
        if ((Tk_CanvasGetCoordFromObj(interp, canvas, objv[0], &bmapPtr->x) != TCL_OK)
290
 
                || (Tk_CanvasGetCoordFromObj(interp, canvas, objv[1], &bmapPtr->y)
291
 
                    != TCL_OK)) {
 
281
        if ((Tk_CanvasGetCoordFromObj(interp, canvas, objv[0],
 
282
                &bmapPtr->x) != TCL_OK)
 
283
                || (Tk_CanvasGetCoordFromObj(interp, canvas, objv[1],
 
284
                        &bmapPtr->y) != TCL_OK)) {
292
285
            return TCL_ERROR;
293
286
        }
294
287
        ComputeBitmapBbox(canvas, bmapPtr);
295
288
    } else {
296
 
        sprintf(x,"%d",argc);
297
 
        Tcl_AppendResult(interp, "wrong # coordinates: expected 0 or 2, got ",
298
 
        x, (char *) NULL);
 
289
        char buf[64 + TCL_INTEGER_SPACE];
 
290
 
 
291
        sprintf(buf, "wrong # coordinates: expected 0 or 2, got %d", objc);
 
292
        Tcl_SetResult(interp, buf, TCL_VOLATILE);
299
293
        return TCL_ERROR;
300
294
    }
301
295
    return TCL_OK;
302
296
}
303
 
 
 
297
 
304
298
/*
305
299
 *--------------------------------------------------------------
306
300
 *
311
305
 *
312
306
 * Results:
313
307
 *      A standard Tcl result code.  If an error occurs, then
314
 
 *      an error message is left in interp->result.
 
308
 *      an error message is left in the interp's result.
315
309
 *
316
310
 * Side effects:
317
311
 *      Configuration information may be set for itemPtr.
320
314
 */
321
315
 
322
316
static int
323
 
ConfigureBitmap(interp, canvas, itemPtr, argc, argv, flags)
 
317
ConfigureBitmap(interp, canvas, itemPtr, objc, objv, flags)
324
318
    Tcl_Interp *interp;         /* Used for error reporting. */
325
319
    Tk_Canvas canvas;           /* Canvas containing itemPtr. */
326
320
    Tk_Item *itemPtr;           /* Bitmap item to reconfigure. */
327
 
    int argc;                   /* Number of elements in argv.  */
328
 
    char **argv;                /* Arguments describing things to configure. */
 
321
    int objc;                   /* Number of elements in objv.  */
 
322
    Tcl_Obj *CONST objv[];      /* Arguments describing things to configure. */
329
323
    int flags;                  /* Flags to pass to Tk_ConfigureWidget. */
330
324
{
331
325
    BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
339
333
    Tk_State state;
340
334
 
341
335
    tkwin = Tk_CanvasTkwin(canvas);
342
 
    if (Tk_ConfigureWidget(interp, tkwin, configSpecs, argc, argv,
343
 
            (char *) bmapPtr, flags|TK_CONFIG_OBJS) != TCL_OK) {
 
336
    if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc, 
 
337
            objv, (char *) bmapPtr, flags|TK_CONFIG_OBJS)) {
344
338
        return TCL_ERROR;
345
339
    }
346
340
 
361
355
 
362
356
    if (state==TK_STATE_HIDDEN) {
363
357
        ComputeBitmapBbox(canvas, bmapPtr);
364
 
        return TCL_OK;  
 
358
        return TCL_OK;
365
359
    }
366
360
    fgColor = bmapPtr->fgColor;
367
361
    bgColor = bmapPtr->bgColor;
416
410
 
417
411
    return TCL_OK;
418
412
}
419
 
 
 
413
 
420
414
/*
421
415
 *--------------------------------------------------------------
422
416
 *
474
468
        Tk_FreeGC(display, bmapPtr->gc);
475
469
    }
476
470
}
477
 
 
 
471
 
478
472
/*
479
473
 *--------------------------------------------------------------
480
474
 *
575
569
    bmapPtr->header.x2 = x + width;
576
570
    bmapPtr->header.y2 = y + height;
577
571
}
578
 
 
 
572
 
579
573
/*
580
574
 *--------------------------------------------------------------
581
575
 *
685
679
        XSetClipOrigin(display, bmapPtr->gc, 0, 0);
686
680
    }
687
681
}
688
 
 
 
682
 
689
683
/*
690
684
 *--------------------------------------------------------------
691
685
 *
743
737
 
744
738
    return hypot(xDiff, yDiff);
745
739
}
746
 
 
 
740
 
747
741
/*
748
742
 *--------------------------------------------------------------
749
743
 *
789
783
    }
790
784
    return 0;
791
785
}
792
 
 
 
786
 
793
787
/*
794
788
 *--------------------------------------------------------------
795
789
 *
825
819
    bmapPtr->y = originY + scaleY*(bmapPtr->y - originY);
826
820
    ComputeBitmapBbox(canvas, bmapPtr);
827
821
}
828
 
 
 
822
 
829
823
/*
830
824
 *--------------------------------------------------------------
831
825
 *
857
851
    bmapPtr->y += deltaY;
858
852
    ComputeBitmapBbox(canvas, bmapPtr);
859
853
}
860
 
 
 
854
 
861
855
/*
862
856
 *--------------------------------------------------------------
863
857
 *
869
863
 * Results:
870
864
 *      The return value is a standard Tcl result.  If an error
871
865
 *      occurs in generating Postscript then an error message is
872
 
 *      left in interp->result, replacing whatever used to be there.
 
866
 *      left in the interp's result, replacing whatever used to be there.
873
867
 *      If no error occurs, then Postscript for the item is appended
874
868
 *      to the result.
875
869
 *
894
888
    double x, y;
895
889
    int width, height, rowsAtOnce, rowsThisTime;
896
890
    int curRow;
897
 
    char buffer[200];
 
891
    char buffer[100 + TCL_DOUBLE_SPACE * 2 + TCL_INTEGER_SPACE * 4];
898
892
 
899
893
    if (bmapPtr->bitmap == None) {
900
894
        return TCL_OK;
928
922
    if (bmapPtr->bgColor != NULL) {
929
923
        sprintf(buffer,
930
924
                "%.15g %.15g moveto %d 0 rlineto 0 %d rlineto %d %s\n",
931
 
                x, y, width, height, -width,"0 rlineto closepath");
 
925
                x, y, width, height, -width, "0 rlineto closepath");
932
926
        Tcl_AppendResult(interp, buffer, (char *) NULL);
933
927
        if (Tk_CanvasPsColor(interp, canvas, bmapPtr->bgColor) != TCL_OK) {
934
928
            return TCL_ERROR;
977
971
    }
978
972
    return TCL_OK;
979
973
}
 
974