OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [generic/] [tkCanvUtil.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tkCanvUtil.c --
3
 *
4
 *      This procedure contains a collection of utility procedures
5
 *      used by the implementations of various canvas item types.
6
 *
7
 * Copyright (c) 1994 Sun Microsystems, Inc.
8
 * Copyright (c) 1994 Sun Microsystems, Inc.
9
 *
10
 * See the file "license.terms" for information on usage and redistribution
11
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12
 *
13
 * RCS: @(#) $Id: tkCanvUtil.c,v 1.1.1.1 2002-01-16 10:25:51 markom Exp $
14
 */
15
 
16
#include "tk.h"
17
#include "tkCanvas.h"
18
#include "tkPort.h"
19
 
20
 
21
/*
22
 *----------------------------------------------------------------------
23
 *
24
 * Tk_CanvasTkwin --
25
 *
26
 *      Given a token for a canvas, this procedure returns the
27
 *      widget that represents the canvas.
28
 *
29
 * Results:
30
 *      The return value is a handle for the widget.
31
 *
32
 * Side effects:
33
 *      None.
34
 *
35
 *----------------------------------------------------------------------
36
 */
37
 
38
Tk_Window
39
Tk_CanvasTkwin(canvas)
40
    Tk_Canvas canvas;                   /* Token for the canvas. */
41
{
42
    TkCanvas *canvasPtr = (TkCanvas *) canvas;
43
    return canvasPtr->tkwin;
44
}
45
 
46
/*
47
 *----------------------------------------------------------------------
48
 *
49
 * Tk_CanvasDrawableCoords --
50
 *
51
 *      Given an (x,y) coordinate pair within a canvas, this procedure
52
 *      returns the corresponding coordinates at which the point should
53
 *      be drawn in the drawable used for display.
54
 *
55
 * Results:
56
 *      There is no return value.  The values at *drawableXPtr and
57
 *      *drawableYPtr are filled in with the coordinates at which
58
 *      x and y should be drawn.  These coordinates are clipped
59
 *      to fit within a "short", since this is what X uses in
60
 *      most cases for drawing.
61
 *
62
 * Side effects:
63
 *      None.
64
 *
65
 *----------------------------------------------------------------------
66
 */
67
 
68
void
69
Tk_CanvasDrawableCoords(canvas, x, y, drawableXPtr, drawableYPtr)
70
    Tk_Canvas canvas;                   /* Token for the canvas. */
71
    double x, y;                        /* Coordinates in canvas space. */
72
    short *drawableXPtr, *drawableYPtr; /* Screen coordinates are stored
73
                                         * here. */
74
{
75
    TkCanvas *canvasPtr = (TkCanvas *) canvas;
76
    double tmp;
77
 
78
    tmp = x - canvasPtr->drawableXOrigin;
79
    if (tmp > 0) {
80
        tmp += 0.5;
81
    } else {
82
        tmp -= 0.5;
83
    }
84
    if (tmp > 32767) {
85
        *drawableXPtr = 32767;
86
    } else if (tmp < -32768) {
87
        *drawableXPtr = -32768;
88
    } else {
89
        *drawableXPtr = (short) tmp;
90
    }
91
 
92
    tmp = y  - canvasPtr->drawableYOrigin;
93
    if (tmp > 0) {
94
        tmp += 0.5;
95
    } else {
96
        tmp -= 0.5;
97
    }
98
    if (tmp > 32767) {
99
        *drawableYPtr = 32767;
100
    } else if (tmp < -32768) {
101
        *drawableYPtr = -32768;
102
    } else {
103
        *drawableYPtr = (short) tmp;
104
    }
105
}
106
 
107
/*
108
 *----------------------------------------------------------------------
109
 *
110
 * Tk_CanvasWindowCoords --
111
 *
112
 *      Given an (x,y) coordinate pair within a canvas, this procedure
113
 *      returns the corresponding coordinates in the canvas's window.
114
 *
115
 * Results:
116
 *      There is no return value.  The values at *screenXPtr and
117
 *      *screenYPtr are filled in with the coordinates at which
118
 *      (x,y) appears in the canvas's window.  These coordinates
119
 *      are clipped to fit within a "short", since this is what X
120
 *      uses in most cases for drawing.
121
 *
122
 * Side effects:
123
 *      None.
124
 *
125
 *----------------------------------------------------------------------
126
 */
127
 
128
void
129
Tk_CanvasWindowCoords(canvas, x, y, screenXPtr, screenYPtr)
130
    Tk_Canvas canvas;                   /* Token for the canvas. */
131
    double x, y;                        /* Coordinates in canvas space. */
132
    short *screenXPtr, *screenYPtr;     /* Screen coordinates are stored
133
                                         * here. */
134
{
135
    TkCanvas *canvasPtr = (TkCanvas *) canvas;
136
    double tmp;
137
 
138
    tmp = x - canvasPtr->xOrigin;
139
    if (tmp > 0) {
140
        tmp += 0.5;
141
    } else {
142
        tmp -= 0.5;
143
    }
144
    if (tmp > 32767) {
145
        *screenXPtr = 32767;
146
    } else if (tmp < -32768) {
147
        *screenXPtr = -32768;
148
    } else {
149
        *screenXPtr = (short) tmp;
150
    }
151
 
152
    tmp = y  - canvasPtr->yOrigin;
153
    if (tmp > 0) {
154
        tmp += 0.5;
155
    } else {
156
        tmp -= 0.5;
157
    }
158
    if (tmp > 32767) {
159
        *screenYPtr = 32767;
160
    } else if (tmp < -32768) {
161
        *screenYPtr = -32768;
162
    } else {
163
        *screenYPtr = (short) tmp;
164
    }
165
}
166
 
167
/*
168
 *--------------------------------------------------------------
169
 *
170
 * Tk_CanvasGetCoord --
171
 *
172
 *      Given a string, returns a floating-point canvas coordinate
173
 *      corresponding to that string.
174
 *
175
 * Results:
176
 *      The return value is a standard Tcl return result.  If
177
 *      TCL_OK is returned, then everything went well and the
178
 *      canvas coordinate is stored at *doublePtr;  otherwise
179
 *      TCL_ERROR is returned and an error message is left in
180
 *      interp->result.
181
 *
182
 * Side effects:
183
 *      None.
184
 *
185
 *--------------------------------------------------------------
186
 */
187
 
188
int
189
Tk_CanvasGetCoord(interp, canvas, string, doublePtr)
190
    Tcl_Interp *interp;         /* Interpreter for error reporting. */
191
    Tk_Canvas canvas;           /* Canvas to which coordinate applies. */
192
    char *string;               /* Describes coordinate (any screen
193
                                 * coordinate form may be used here). */
194
    double *doublePtr;          /* Place to store converted coordinate. */
195
{
196
    TkCanvas *canvasPtr = (TkCanvas *) canvas;
197
    if (Tk_GetScreenMM(canvasPtr->interp, canvasPtr->tkwin, string,
198
            doublePtr) != TCL_OK) {
199
        return TCL_ERROR;
200
    }
201
    *doublePtr *= canvasPtr->pixelsPerMM;
202
    return TCL_OK;
203
}
204
 
205
/*
206
 *----------------------------------------------------------------------
207
 *
208
 * Tk_CanvasSetStippleOrigin --
209
 *
210
 *      This procedure sets the stipple origin in a graphics context
211
 *      so that stipples drawn with the GC will line up with other
212
 *      stipples previously drawn in the canvas.
213
 *
214
 * Results:
215
 *      None.
216
 *
217
 * Side effects:
218
 *      The graphics context is modified.
219
 *
220
 *----------------------------------------------------------------------
221
 */
222
 
223
void
224
Tk_CanvasSetStippleOrigin(canvas, gc)
225
    Tk_Canvas canvas;           /* Token for a canvas. */
226
    GC gc;                      /* Graphics context that is about to be
227
                                 * used to draw a stippled pattern as
228
                                 * part of redisplaying the canvas. */
229
 
230
{
231
    TkCanvas *canvasPtr = (TkCanvas *) canvas;
232
 
233
    XSetTSOrigin(canvasPtr->display, gc, -canvasPtr->drawableXOrigin,
234
            -canvasPtr->drawableYOrigin);
235
}
236
 
237
/*
238
 *----------------------------------------------------------------------
239
 *
240
 * Tk_CanvasGetTextInfo --
241
 *
242
 *      This procedure returns a pointer to a structure containing
243
 *      information about the selection and insertion cursor for
244
 *      a canvas widget.  Items such as text items save the pointer
245
 *      and use it to share access to the information with the generic
246
 *      canvas code.
247
 *
248
 * Results:
249
 *      The return value is a pointer to the structure holding text
250
 *      information for the canvas.  Most of the fields should not
251
 *      be modified outside the generic canvas code;  see the user
252
 *      documentation for details.
253
 *
254
 * Side effects:
255
 *      None.
256
 *
257
 *----------------------------------------------------------------------
258
 */
259
 
260
Tk_CanvasTextInfo *
261
Tk_CanvasGetTextInfo(canvas)
262
    Tk_Canvas canvas;                   /* Token for the canvas widget. */
263
{
264
    return &((TkCanvas *) canvas)->textInfo;
265
}
266
 
267
/*
268
 *--------------------------------------------------------------
269
 *
270
 * Tk_CanvasTagsParseProc --
271
 *
272
 *      This procedure is invoked during option processing to handle
273
 *      "-tags" options for canvas items.
274
 *
275
 * Results:
276
 *      A standard Tcl return value.
277
 *
278
 * Side effects:
279
 *      The tags for a given item get replaced by those indicated
280
 *      in the value argument.
281
 *
282
 *--------------------------------------------------------------
283
 */
284
 
285
int
286
Tk_CanvasTagsParseProc(clientData, interp, tkwin, value, widgRec, offset)
287
    ClientData clientData;              /* Not used.*/
288
    Tcl_Interp *interp;                 /* Used for reporting errors. */
289
    Tk_Window tkwin;                    /* Window containing canvas widget. */
290
    char *value;                        /* Value of option (list of tag
291
                                         * names). */
292
    char *widgRec;                      /* Pointer to record for item. */
293
    int offset;                         /* Offset into item (ignored). */
294
{
295
    register Tk_Item *itemPtr = (Tk_Item *) widgRec;
296
    int argc, i;
297
    char **argv;
298
    Tk_Uid *newPtr;
299
 
300
    /*
301
     * Break the value up into the individual tag names.
302
     */
303
 
304
    if (Tcl_SplitList(interp, value, &argc, &argv) != TCL_OK) {
305
        return TCL_ERROR;
306
    }
307
 
308
    /*
309
     * Make sure that there's enough space in the item to hold the
310
     * tag names.
311
     */
312
 
313
    if (itemPtr->tagSpace < argc) {
314
        newPtr = (Tk_Uid *) ckalloc((unsigned) (argc * sizeof(Tk_Uid)));
315
        for (i = itemPtr->numTags-1; i >= 0; i--) {
316
            newPtr[i] = itemPtr->tagPtr[i];
317
        }
318
        if (itemPtr->tagPtr != itemPtr->staticTagSpace) {
319
            ckfree((char *) itemPtr->tagPtr);
320
        }
321
        itemPtr->tagPtr = newPtr;
322
        itemPtr->tagSpace = argc;
323
    }
324
    itemPtr->numTags = argc;
325
    for (i = 0; i < argc; i++) {
326
        itemPtr->tagPtr[i] = Tk_GetUid(argv[i]);
327
    }
328
    ckfree((char *) argv);
329
    return TCL_OK;
330
}
331
 
332
/*
333
 *--------------------------------------------------------------
334
 *
335
 * Tk_CanvasTagsPrintProc --
336
 *
337
 *      This procedure is invoked by the Tk configuration code
338
 *      to produce a printable string for the "-tags" configuration
339
 *      option for canvas items.
340
 *
341
 * Results:
342
 *      The return value is a string describing all the tags for
343
 *      the item referred to by "widgRec".  In addition, *freeProcPtr
344
 *      is filled in with the address of a procedure to call to free
345
 *      the result string when it's no longer needed (or NULL to
346
 *      indicate that the string doesn't need to be freed).
347
 *
348
 * Side effects:
349
 *      None.
350
 *
351
 *--------------------------------------------------------------
352
 */
353
 
354
char *
355
Tk_CanvasTagsPrintProc(clientData, tkwin, widgRec, offset, freeProcPtr)
356
    ClientData clientData;              /* Ignored. */
357
    Tk_Window tkwin;                    /* Window containing canvas widget. */
358
    char *widgRec;                      /* Pointer to record for item. */
359
    int offset;                         /* Ignored. */
360
    Tcl_FreeProc **freeProcPtr;         /* Pointer to variable to fill in with
361
                                         * information about how to reclaim
362
                                         * storage for return string. */
363
{
364
    register Tk_Item *itemPtr = (Tk_Item *) widgRec;
365
 
366
    if (itemPtr->numTags == 0) {
367
        *freeProcPtr = (Tcl_FreeProc *) NULL;
368
        return "";
369
    }
370
    if (itemPtr->numTags == 1) {
371
        *freeProcPtr = (Tcl_FreeProc *) NULL;
372
        return (char *) itemPtr->tagPtr[0];
373
    }
374
    *freeProcPtr = TCL_DYNAMIC;
375
    return Tcl_Merge(itemPtr->numTags, (char **) itemPtr->tagPtr);
376
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.