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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [tix/] [generic/] [tixInputO.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tixInputO.c --
3
 *
4
 *      This module implements "InputOnly" widgets.
5
 *
6
 * Copyright (c) 1996, Expert Interface Technologies
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
 *
12
 */
13
 
14
#include <tkInt.h>
15
#include <tixPort.h>
16
#include <tix.h>
17
 
18
/*
19
 * A data structure of the following type is kept for each
20
 * widget managed by this file:
21
 */
22
 
23
typedef struct Tix_InputOnlyStruct {
24
    Tk_Window tkwin;            /* Window that embodies the widget.  NULL
25
                                 * means window has been deleted but
26
                                 * widget record hasn't been cleaned up yet. */
27
    Tcl_Command widgetCmd;      /* Token for button's widget command. */
28
    Display *display;           /* X's token for the window's display. */
29
    Tcl_Interp *interp;         /* Interpreter associated with widget. */
30
 
31
    /*
32
     * Information used when displaying widget:
33
     */
34
    int width;
35
    int height;
36
 
37
    /* Cursor */
38
    Cursor cursor;              /* Current cursor for window, or None. */
39
    int changed;
40
} Tix_InputOnly;
41
 
42
typedef Tix_InputOnly   WidgetRecord;
43
typedef Tix_InputOnly * WidgetPtr;
44
 
45
/*
46
 * hint:: Place these into a default.f file
47
 */
48
#define DEF_INPUTONLY_CURSOR            ""
49
#define DEF_INPUTONLY_WIDTH             "0"
50
#define DEF_INPUTONLY_HEIGHT            "0"
51
 
52
/*
53
 * Information used for argv parsing.
54
 */
55
static Tk_ConfigSpec configSpecs[] = {
56
 
57
    {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
58
       DEF_INPUTONLY_CURSOR, Tk_Offset(WidgetRecord, cursor),
59
       TK_CONFIG_NULL_OK},
60
 
61
    {TK_CONFIG_PIXELS, "-height", "height", "Height",
62
       DEF_INPUTONLY_HEIGHT, Tk_Offset(WidgetRecord, height), 0},
63
 
64
    {TK_CONFIG_PIXELS, "-width", "width", "Width",
65
       DEF_INPUTONLY_WIDTH, Tk_Offset(WidgetRecord, width), 0},
66
 
67
 
68
    {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
69
        (char *) NULL, 0, 0}
70
};
71
 
72
/*
73
 * Forward declarations for procedures defined later in this file:
74
 */
75
 
76
static void             WidgetCmdDeletedProc _ANSI_ARGS_((
77
                            ClientData clientData));
78
static int              WidgetConfigure _ANSI_ARGS_((Tcl_Interp *interp,
79
                            WidgetPtr wPtr, int argc, char **argv,
80
                            int flags));
81
static void             WidgetDestroy _ANSI_ARGS_((ClientData clientData));
82
static void             WidgetEventProc _ANSI_ARGS_((ClientData clientData,
83
                            XEvent *eventPtr));
84
static int              WidgetCommand _ANSI_ARGS_((ClientData clientData,
85
                            Tcl_Interp *, int argc, char **argv));
86
static void             Tix_MakeInputOnlyWindowExist _ANSI_ARGS_((
87
                            WidgetPtr wPtr));
88
 
89
 
90
#define INPUT_ONLY_EVENTS_MASK \
91
  KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonReleaseMask| \
92
  EnterWindowMask|LeaveWindowMask|PointerMotionMask| \
93
  VisibilityChangeMask|SubstructureNotifyMask| \
94
  FocusChangeMask|PropertyChangeMask
95
 
96
static XSetWindowAttributes inputOnlyAtts = {
97
    None,                       /* background_pixmap */
98
    0,                           /* background_pixel */
99
    None,                       /* border_pixmap */
100
    0,                           /* border_pixel */
101
    ForgetGravity,              /* bit_gravity */
102
    NorthWestGravity,           /* win_gravity */
103
    NotUseful,                  /* backing_store */
104
    (unsigned) ~0,               /* backing_planes */
105
    0,                           /* backing_pixel */
106
    False,                      /* save_under */
107
    INPUT_ONLY_EVENTS_MASK,     /* event_mask */
108
    0,                           /* do_not_propagate_mask */
109
    False,                      /* override_redirect */
110
    None,                       /* colormap */
111
    None                        /* cursor */
112
};
113
 
114
 
115
static
116
void Tix_MakeInputOnlyWindowExist(wPtr)
117
    WidgetPtr wPtr;
118
{
119
    TkWindow* winPtr;
120
    Tcl_HashEntry *hPtr;
121
    int new;
122
    Window parent;
123
 
124
    winPtr = (TkWindow*) wPtr->tkwin;
125
    inputOnlyAtts.cursor = winPtr->atts.cursor;
126
 
127
 
128
    if (winPtr->flags & TK_TOP_LEVEL) {
129
        parent = XRootWindow(winPtr->display, winPtr->screenNum);
130
    } else {
131
        if (winPtr->parentPtr->window == None) {
132
            Tk_MakeWindowExist((Tk_Window) winPtr->parentPtr);
133
        }
134
        parent = winPtr->parentPtr->window;
135
    }
136
 
137
    winPtr->window = XCreateWindow(winPtr->display,
138
        parent,
139
        winPtr->changes.x, winPtr->changes.y,
140
        (unsigned) winPtr->changes.width,
141
        (unsigned) winPtr->changes.height,
142
        0, 0,
143
        InputOnly,
144
        CopyFromParent,
145
        CWEventMask|CWCursor,
146
        &inputOnlyAtts);
147
 
148
    hPtr = Tcl_CreateHashEntry(&winPtr->dispPtr->winTable,
149
        (char *) winPtr->window, &new);
150
    Tcl_SetHashValue(hPtr, winPtr);
151
 
152
    winPtr->dirtyAtts = 0;
153
    winPtr->dirtyChanges = 0;
154
#ifdef TK_USE_INPUT_METHODS
155
    winPtr->inputContext = NULL;
156
#endif /* TK_USE_INPUT_METHODS */
157
}
158
 
159
/*
160
 *--------------------------------------------------------------
161
 *
162
 * Tix_InputOnlyCmd --
163
 *
164
 *      This procedure is invoked to process the "inputOnly" Tcl
165
 *      command.  It creates a new "InputOnly" widget.
166
 *
167
 * Results:
168
 *      A standard Tcl result.
169
 *
170
 * Side effects:
171
 *      A new widget is created and configured.
172
 *
173
 *--------------------------------------------------------------
174
 */
175
int
176
Tix_InputOnlyCmd(clientData, interp, argc, argv)
177
    ClientData clientData;      /* Main window associated with
178
                                 * interpreter. */
179
    Tcl_Interp *interp;         /* Current interpreter. */
180
    int argc;                   /* Number of arguments. */
181
    char **argv;                /* Argument strings. */
182
{
183
    Tk_Window main = (Tk_Window) clientData;
184
    WidgetPtr wPtr;
185
    Tk_Window tkwin;
186
 
187
    if (argc < 2) {
188
        Tcl_AppendResult(interp, "wrong # args:  should be \"",
189
                argv[0], " pathName ?options?\"", (char *) NULL);
190
        return TCL_ERROR;
191
    }
192
 
193
    tkwin = Tk_CreateWindowFromPath(interp, main, argv[1], (char *) NULL);
194
    if (tkwin == NULL) {
195
        return TCL_ERROR;
196
    }
197
 
198
    /*
199
     * Allocate and initialize the widget record.
200
     */
201
    wPtr = (WidgetPtr) ckalloc(sizeof(WidgetRecord));
202
    wPtr->tkwin         = tkwin;
203
    wPtr->display       = Tk_Display(tkwin);
204
    wPtr->interp        = interp;
205
    wPtr->width         = 0;
206
    wPtr->height        = 0;
207
    wPtr->cursor        = None;
208
    wPtr->changed       = 0;
209
 
210
    Tk_SetClass(tkwin, "TixInputOnly");
211
 
212
    Tix_MakeInputOnlyWindowExist(wPtr);
213
 
214
    Tk_CreateEventHandler(wPtr->tkwin, StructureNotifyMask,
215
        WidgetEventProc, (ClientData) wPtr);
216
    wPtr->widgetCmd = Tcl_CreateCommand(interp, Tk_PathName(wPtr->tkwin),
217
        WidgetCommand, (ClientData) wPtr, WidgetCmdDeletedProc);
218
    if (WidgetConfigure(interp, wPtr, argc-2, argv+2, 0) != TCL_OK) {
219
        Tk_DestroyWindow(wPtr->tkwin);
220
        return TCL_ERROR;
221
    }
222
 
223
    interp->result = Tk_PathName(wPtr->tkwin);
224
    return TCL_OK;
225
}
226
 
227
/*
228
 *--------------------------------------------------------------
229
 *
230
 * WidgetCommand --
231
 *
232
 *      This procedure is invoked to process the Tcl command
233
 *      that corresponds to a widget managed by this module.
234
 *      See the user documentation for details on what it does.
235
 *
236
 * Results:
237
 *      A standard Tcl result.
238
 *
239
 * Side effects:
240
 *      See the user documentation.
241
 *
242
 *--------------------------------------------------------------
243
 */
244
static int
245
WidgetCommand(clientData, interp, argc, argv)
246
    ClientData clientData;              /* Information about the widget. */
247
    Tcl_Interp *interp;                 /* Current interpreter. */
248
    int argc;                           /* Number of arguments. */
249
    char **argv;                        /* Argument strings. */
250
{
251
    WidgetPtr wPtr = (WidgetPtr) clientData;
252
    int result = TCL_OK;
253
    int length;
254
    char c;
255
 
256
    if (argc < 2) {
257
        Tcl_AppendResult(interp, "wrong # args: should be \"",
258
                argv[0], " option ?arg arg ...?\"", (char *) NULL);
259
        return TCL_ERROR;
260
    }
261
 
262
    Tk_Preserve((ClientData) wPtr);
263
    c = argv[1][0];
264
    length = strlen(argv[1]);
265
    if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0)) {
266
        if (argc == 2) {
267
            result = Tk_ConfigureInfo(interp, wPtr->tkwin, configSpecs,
268
                    (char *) wPtr, (char *) NULL, 0);
269
        } else if (argc == 3) {
270
            result = Tk_ConfigureInfo(interp, wPtr->tkwin, configSpecs,
271
                    (char *) wPtr, argv[2], 0);
272
        } else {
273
            result = WidgetConfigure(interp, wPtr, argc-2, argv+2,
274
                    TK_CONFIG_ARGV_ONLY);
275
        }
276
    }
277
    else if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0)) {
278
        if (argc == 3) {
279
            return Tk_ConfigureValue(interp, wPtr->tkwin, configSpecs,
280
                (char *)wPtr, argv[2], 0);
281
        } else {
282
            return Tix_ArgcError(interp, argc, argv, 2, "option");
283
        }
284
    } else {
285
        Tcl_AppendResult(interp, "bad option \"", argv[1],
286
                "\":  must be cget or configure", (char *) NULL);
287
        goto error;
288
    }
289
 
290
    Tk_Release((ClientData) wPtr);
291
    return result;
292
 
293
    error:
294
    Tk_Release((ClientData) wPtr);
295
    return TCL_ERROR;
296
}
297
 
298
/*
299
 *----------------------------------------------------------------------
300
 *
301
 * WidgetConfigure --
302
 *
303
 *      This procedure is called to process an argv/argc list in
304
 *      conjunction with the Tk option database to configure (or
305
 *      reconfigure) a InputOnly widget.
306
 *
307
 * Results:
308
 *      The return value is a standard Tcl result.  If TCL_ERROR is
309
 *      returned, then interp->result contains an error message.
310
 *
311
 * Side effects:
312
 *      Configuration information, such as colors, border width,
313
 *      etc. get set for wPtr;  old resources get freed,
314
 *      if there were any.
315
 *
316
 *----------------------------------------------------------------------
317
 */
318
static int
319
WidgetConfigure(interp, wPtr, argc, argv, flags)
320
    Tcl_Interp *interp;                 /* Used for error reporting. */
321
    WidgetPtr wPtr;                     /* Information about widget. */
322
    int argc;                           /* Number of valid entries in argv. */
323
    char **argv;                        /* Arguments. */
324
    int flags;                          /* Flags to pass to
325
                                         * Tk_ConfigureWidget. */
326
{
327
    if (Tk_ConfigureWidget(interp, wPtr->tkwin, configSpecs,
328
        argc, argv, (char *) wPtr, flags) != TCL_OK) {
329
 
330
        return TCL_ERROR;
331
    }
332
 
333
    Tk_GeometryRequest(wPtr->tkwin, wPtr->width, wPtr->height);
334
 
335
    return TCL_OK;
336
}
337
 
338
/*
339
 *--------------------------------------------------------------
340
 *
341
 * WidgetEventProc --
342
 *
343
 *      This procedure is invoked by the Tk dispatcher for various
344
 *      events on InputOnlys.
345
 *
346
 * Results:
347
 *      None.
348
 *
349
 * Side effects:
350
 *      When the window gets deleted, internal structures get
351
 *      cleaned up.  When it gets exposed, it is redisplayed.
352
 *
353
 *--------------------------------------------------------------
354
 */
355
 
356
static void
357
WidgetEventProc(clientData, eventPtr)
358
    ClientData clientData;      /* Information about window. */
359
    XEvent *eventPtr;           /* Information about event. */
360
{
361
    WidgetPtr wPtr = (WidgetPtr) clientData;
362
 
363
    switch (eventPtr->type) {
364
      case DestroyNotify:
365
        if (wPtr->tkwin != NULL) {
366
            wPtr->tkwin = NULL;
367
            Tcl_DeleteCommand(wPtr->interp,
368
                Tcl_GetCommandName(wPtr->interp, wPtr->widgetCmd));
369
        }
370
        Tk_EventuallyFree((ClientData) wPtr, (Tix_FreeProc*)WidgetDestroy);
371
        break;
372
 
373
      case MapNotify:
374
      case ConfigureNotify:
375
        break;
376
    }
377
}
378
 
379
/*
380
 *----------------------------------------------------------------------
381
 *
382
 * WidgetDestroy --
383
 *
384
 *      This procedure is invoked by Tk_EventuallyFree or Tk_Release
385
 *      to clean up the internal structure of a InputOnly at a safe time
386
 *      (when no-one is using it anymore).
387
 *
388
 * Results:
389
 *      None.
390
 *
391
 * Side effects:
392
 *      Everything associated with the InputOnly is freed up.
393
 *
394
 *----------------------------------------------------------------------
395
 */
396
 
397
static void
398
WidgetDestroy(clientData)
399
    ClientData clientData;      /* Info about my widget. */
400
{
401
    WidgetPtr wPtr = (WidgetPtr) clientData;
402
 
403
    Tk_FreeOptions(configSpecs, (char *) wPtr, wPtr->display, 0);
404
    ckfree((char *) wPtr);
405
}
406
 
407
/*
408
 *----------------------------------------------------------------------
409
 *
410
 * WidgetCmdDeletedProc --
411
 *
412
 *      This procedure is invoked when a widget command is deleted.  If
413
 *      the widget isn't already in the process of being destroyed,
414
 *      this command destroys it.
415
 *
416
 * Results:
417
 *      None.
418
 *
419
 * Side effects:
420
 *      The widget is destroyed.
421
 *
422
 *----------------------------------------------------------------------
423
 */
424
static void
425
WidgetCmdDeletedProc(clientData)
426
    ClientData clientData;      /* Pointer to widget record for widget. */
427
{
428
    WidgetPtr wPtr = (WidgetPtr) clientData;
429
 
430
    /*
431
     * This procedure could be invoked either because the window was
432
     * destroyed and the command was then deleted (in which case tkwin
433
     * is NULL) or because the command was deleted, and then this procedure
434
     * destroys the widget.
435
     */
436
    if (wPtr->tkwin != NULL) {
437
        Tk_Window tkwin = wPtr->tkwin;
438
        wPtr->tkwin = NULL;
439
        Tk_DestroyWindow(tkwin);
440
    }
441
}

powered by: WebSVN 2.1.0

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