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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [tk/] [mac/] [tkMacCursor.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tkMacCursor.c --
3
 *
4
 *      This file contains Macintosh specific cursor related routines.
5
 *
6
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
7
 *
8
 * See the file "license.terms" for information on usage and redistribution
9
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10
 *
11
 * RCS: @(#) $Id: tkMacCursor.c,v 1.1.1.1 2002-01-16 10:25:55 markom Exp $
12
 */
13
 
14
#include "tkPort.h"
15
#include "tkInt.h"
16
#include "tkMacInt.h"
17
 
18
#include <Resources.h>
19
#include <ToolUtils.h>
20
#include <Strings.h>
21
 
22
/*
23
 * There are three different ways to set the cursor on the Mac.
24
 */
25
#define ARROW   0        /* The arrow cursor. */
26
#define COLOR   1       /* Cursors of type crsr. */
27
#define NORMAL  2       /* Cursors of type CURS. */
28
 
29
/*
30
 * The following data structure contains the system specific data
31
 * necessary to control Windows cursors.
32
 */
33
 
34
typedef struct {
35
    TkCursor info;              /* Generic cursor info used by tkCursor.c */
36
    Handle macCursor;           /* Resource containing Macintosh cursor. */
37
    int type;                   /* Type of Mac cursor: arrow, crsr, CURS */
38
} TkMacCursor;
39
 
40
/*
41
 * The table below is used to map from the name of a predefined cursor
42
 * to its resource identifier.
43
 */
44
 
45
static struct CursorName {
46
    char *name;
47
    int id;
48
} cursorNames[] = {
49
    {"ibeam",           1},
50
    {"text",            1},
51
    {"xterm",           1},
52
    {"cross",           2},
53
    {"crosshair",       2},
54
    {"cross-hair",      2},
55
    {"plus",            3},
56
    {"watch",           4},
57
    {"arrow",           5},
58
    {NULL,              0}
59
};
60
 
61
/*
62
 * Declarations of static variables used in this file.
63
 */
64
 
65
static TkMacCursor * gCurrentCursor = NULL;  /* A pointer to the current
66
                                              * cursor. */
67
static int gResizeOverride = false;          /* A boolean indicating whether
68
                                              * we should use the resize
69
                                              * cursor during installations. */
70
static int gTkOwnsCursor = true;             /* A boolean indicating whether
71
                                                Tk owns the cursor.  If not (for
72
                                                instance, in the case where a Tk
73
                                                window is embedded in another app's
74
                                                window, and the cursor is out of
75
                                                the tk window, we will not attempt
76
                                                to adjust the cursor */
77
 
78
/*
79
 * Declarations of procedures local to this file
80
 */
81
 
82
static  void FindCursorByName _ANSI_ARGS_ ((TkMacCursor *macCursorPtr,
83
                     char *string));
84
 
85
/*
86
 *----------------------------------------------------------------------
87
 *
88
 * FindCursorByName --
89
 *
90
 *      Retrieve a system cursor by name, and fill the macCursorPtr
91
 *      structure.  If the cursor cannot be found, the macCursor field
92
 *      will be NULL.  The function first attempts to load a color
93
 *      cursor.  If that fails it will attempt to load a black & white
94
 *      cursor.
95
 *
96
 * Results:
97
 *      Fills the macCursorPtr record.
98
 *
99
 * Side effects:
100
 *      None
101
 *
102
 *----------------------------------------------------------------------
103
 */
104
 
105
void
106
FindCursorByName(
107
    TkMacCursor *macCursorPtr,
108
    char *string)
109
{
110
    Handle resource;
111
    Str255 curName;
112
 
113
    curName[0] = strlen(string);
114
    if (curName[0] > 255) {
115
        return;
116
    }
117
 
118
    strcpy((char *) curName + 1, string);
119
    resource = GetNamedResource('crsr', curName);
120
 
121
    if (resource != NULL) {
122
        short id;
123
        Str255 theName;
124
        ResType theType;
125
 
126
        HLock(resource);
127
        GetResInfo(resource, &id, &theType, theName);
128
        HUnlock(resource);
129
        macCursorPtr->macCursor = (Handle) GetCCursor(id);
130
        macCursorPtr->type = COLOR;
131
    }
132
 
133
    if (resource == NULL) {
134
        macCursorPtr->macCursor = GetNamedResource('CURS', curName);
135
        macCursorPtr->type = NORMAL;
136
    }
137
}
138
 
139
/*
140
 *----------------------------------------------------------------------
141
 *
142
 * TkGetCursorByName --
143
 *
144
 *      Retrieve a system cursor by name.
145
 *
146
 * Results:
147
 *      Returns a new cursor, or NULL on errors.
148
 *
149
 * Side effects:
150
 *      Allocates a new cursor.
151
 *
152
 *----------------------------------------------------------------------
153
 */
154
 
155
TkCursor *
156
TkGetCursorByName(
157
    Tcl_Interp *interp,         /* Interpreter to use for error reporting. */
158
    Tk_Window tkwin,            /* Window in which cursor will be used. */
159
    Tk_Uid string)              /* Description of cursor.  See manual entry
160
                                 * for details on legal syntax. */
161
{
162
    struct CursorName *namePtr;
163
    TkMacCursor *macCursorPtr;
164
 
165
    macCursorPtr = (TkMacCursor *) ckalloc(sizeof(TkMacCursor));
166
    macCursorPtr->info.cursor = (Tk_Cursor) macCursorPtr;
167
 
168
    /*
169
     * To find a cursor we must first determine if it is one of the
170
     * builtin cursors or the standard arrow cursor. Otherwise, we
171
     * attempt to load the cursor as a named Mac resource.
172
     */
173
 
174
    for (namePtr = cursorNames; namePtr->name != NULL; namePtr++) {
175
        if (strcmp(namePtr->name, string) == 0) {
176
            break;
177
        }
178
    }
179
 
180
 
181
    if (namePtr->name != NULL) {
182
        if (namePtr->id == 5) {
183
            macCursorPtr->macCursor = (Handle) -1;
184
            macCursorPtr->type = ARROW;
185
        } else {
186
            macCursorPtr->macCursor = (Handle) GetCursor(namePtr->id);
187
            macCursorPtr->type = NORMAL;
188
        }
189
    } else {
190
        FindCursorByName(macCursorPtr, string);
191
 
192
        if (macCursorPtr->macCursor == NULL) {
193
            char **argv;
194
            int argc, err;
195
 
196
            /*
197
             * The user may be trying to specify an XCursor with fore
198
             * & back colors. We don't want this to be an error, so pick
199
             * off the first word, and try again.
200
             */
201
 
202
            err = Tcl_SplitList(interp, string, &argc, &argv);
203
            if (err == TCL_OK ) {
204
                if (argc > 1) {
205
                    FindCursorByName(macCursorPtr, argv[0]);
206
                }
207
 
208
                ckfree((char *) argv);
209
            }
210
        }
211
    }
212
 
213
    if (macCursorPtr->macCursor == NULL) {
214
        ckfree((char *)macCursorPtr);
215
        Tcl_AppendResult(interp, "bad cursor spec \"", string, "\"",
216
                (char *) NULL);
217
        return NULL;
218
    } else {
219
        return (TkCursor *) macCursorPtr;
220
    }
221
}
222
 
223
/*
224
 *----------------------------------------------------------------------
225
 *
226
 * TkCreateCursorFromData --
227
 *
228
 *      Creates a cursor from the source and mask bits.
229
 *
230
 * Results:
231
 *      Returns a new cursor, or NULL on errors.
232
 *
233
 * Side effects:
234
 *      Allocates a new cursor.
235
 *
236
 *----------------------------------------------------------------------
237
 */
238
 
239
TkCursor *
240
TkCreateCursorFromData(
241
    Tk_Window tkwin,            /* Window in which cursor will be used. */
242
    char *source,               /* Bitmap data for cursor shape. */
243
    char *mask,                 /* Bitmap data for cursor mask. */
244
    int width, int height,      /* Dimensions of cursor. */
245
    int xHot, int yHot,         /* Location of hot-spot in cursor. */
246
    XColor fgColor,             /* Foreground color for cursor. */
247
    XColor bgColor)             /* Background color for cursor. */
248
{
249
    return NULL;
250
}
251
 
252
/*
253
 *----------------------------------------------------------------------
254
 *
255
 * TkFreeCursor --
256
 *
257
 *      This procedure is called to release a cursor allocated by
258
 *      TkGetCursorByName.
259
 *
260
 * Results:
261
 *      None.
262
 *
263
 * Side effects:
264
 *      The cursor data structure is deallocated.
265
 *
266
 *----------------------------------------------------------------------
267
 */
268
 
269
void
270
TkFreeCursor(
271
    TkCursor *cursorPtr)
272
{
273
    TkMacCursor *macCursorPtr = (TkMacCursor *) cursorPtr;
274
 
275
    switch (macCursorPtr->type) {
276
        case COLOR:
277
            DisposeCCursor((CCrsrHandle) macCursorPtr->macCursor);
278
            break;
279
        case NORMAL:
280
            ReleaseResource(macCursorPtr->macCursor);
281
            break;
282
    }
283
 
284
    if (macCursorPtr == gCurrentCursor) {
285
        gCurrentCursor = NULL;
286
    }
287
 
288
    ckfree((char *) macCursorPtr);
289
}
290
 
291
/*
292
 *----------------------------------------------------------------------
293
 *
294
 * TkMacInstallCursor --
295
 *
296
 *      Installs either the current cursor as defined by TkpSetCursor
297
 *      or a resize cursor as the cursor the Macintosh should currently
298
 *      display.
299
 *
300
 * Results:
301
 *      None.
302
 *
303
 * Side effects:
304
 *      Changes the Macintosh mouse cursor.
305
 *
306
 *----------------------------------------------------------------------
307
 */
308
 
309
void
310
TkMacInstallCursor(
311
    int resizeOverride)
312
{
313
    TkMacCursor *macCursorPtr = gCurrentCursor;
314
    CCrsrHandle ccursor;
315
    CursHandle cursor;
316
 
317
    gResizeOverride = resizeOverride;
318
 
319
    if (resizeOverride) {
320
        cursor = (CursHandle) GetNamedResource('CURS', "\presize");
321
        SetCursor(*cursor);
322
    } else if (macCursorPtr == NULL || macCursorPtr->type == ARROW) {
323
        SetCursor(&tcl_macQdPtr->arrow);
324
    } else {
325
        switch (macCursorPtr->type) {
326
            case COLOR:
327
                ccursor = (CCrsrHandle) macCursorPtr->macCursor;
328
                SetCCursor(ccursor);
329
                break;
330
            case NORMAL:
331
                cursor = (CursHandle) macCursorPtr->macCursor;
332
                SetCursor(*cursor);
333
                break;
334
        }
335
    }
336
}
337
 
338
/*
339
 *----------------------------------------------------------------------
340
 *
341
 * TkpSetCursor --
342
 *
343
 *      Set the current cursor and install it.
344
 *
345
 * Results:
346
 *      None.
347
 *
348
 * Side effects:
349
 *      Changes the current cursor.
350
 *
351
 *----------------------------------------------------------------------
352
 */
353
 
354
void
355
TkpSetCursor(
356
    TkpCursor cursor)
357
{
358
    if (!gTkOwnsCursor) {
359
        return;
360
    }
361
    if (cursor == None) {
362
        gCurrentCursor = NULL;
363
    } else {
364
        gCurrentCursor = (TkMacCursor *) cursor;
365
    }
366
 
367
    if (tkMacAppInFront) {
368
        TkMacInstallCursor(gResizeOverride);
369
    }
370
}
371
 
372
/*
373
 *----------------------------------------------------------------------
374
 *
375
 * Tk_MacTkOwnsCursor --
376
 *
377
 *      Sets whether Tk has the right to adjust the cursor.
378
 *
379
 * Results:
380
 *      None.
381
 *
382
 * Side effects:
383
 *      May keep Tk from changing the cursor.
384
 *
385
 *----------------------------------------------------------------------
386
 */
387
 
388
void Tk_MacTkOwnsCursor(
389
    int tkOwnsIt)
390
{
391
    gTkOwnsCursor = tkOwnsIt;
392
}

powered by: WebSVN 2.1.0

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