Debian Codegraph @

pTk/mTk/tixGeneric/tixInputO.c

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