Debian Codegraph @

pTk/mTk/tixGeneric/tixGeometry.c

raw symbols SCIP
1
2 /* $Id: tixGeometry.c,v 1.1.1.1 2000/05/17 11:08:42 idiscovery Exp $ */
3
4 /*
5 * tixGeometry.c --
6 *
7 * TCL bindings of TK Geometry Management functions.
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 #include "tixPort.h"
17 #include "tix.h"
18
19 static Tcl_HashTable clientTable; /* hash table for geometry managers */
20
21 static void StructureProc _ANSI_ARGS_((ClientData clientData,
22 XEvent *eventPtr));
23 static void GeoReqProc _ANSI_ARGS_((ClientData clientData,
24 Tk_Window tkwin));
25 static void GeoLostSlaveProc _ANSI_ARGS_((ClientData clientData,
26 Tk_Window tkwin));
27
28 typedef struct ClientStruct {
29 Tcl_Interp * interp;
30 Tk_Window tkwin;
31 char * command;
32 unsigned isDeleted : 1;
33 } ClientStruct;
34
35 static Tk_GeomMgr geoType = {
36 "tixGeometry", /* name */
37 GeoReqProc, /* requestProc */
38 GeoLostSlaveProc, /* lostSlaveProc */
39 };
40
41 /*----------------------------------------------------------------------
42 *
43 * Geometry Management Hooks
44 *
45 *
46 *----------------------------------------------------------------------
47 */
48 /*----------------------------------------------------------------------
49 *
50 * The following functions handles the geometry requests of the clients
51 *
52 *----------------------------------------------------------------------
53 */
54
55 static void FreeClientStruct(clientData)
56 ClientData clientData;
57 {
58 ClientStruct * cnPtr = (ClientStruct *) clientData;
59
60 ckfree((char*)cnPtr->command);
61 ckfree((char*)cnPtr);
62 }
63
64 /* This function is called when the clients initiates a geometry
65 * request i.e., a button changes its text and now needs a larger
66 * width
67 *
68 */
69 static void
70 GeoReqProc(clientData, tkwin)
71 ClientData clientData; /* Information about
72 * window that got new preferred
73 * geometry. */
74 Tk_Window tkwin; /* Other Tk-related information
75 * about the window. */
76 {
77 ClientStruct * cnPtr = (ClientStruct *) clientData;
78 int result;
79
80 if (cnPtr->isDeleted) {
81 return;
82 }
83
84 result = Tix_GlobalVarEval(cnPtr->interp, cnPtr->command, " -request ",
85 Tk_PathName(cnPtr->tkwin), (char*)NULL);
86
87 if (result != TCL_OK) {
88 Tcl_AddErrorInfo(cnPtr->interp,
89 "\n (geometry request command executed by tixManageGeometry)");
90 Tk_BackgroundError(cnPtr->interp);
91 }
92 }
93
94 /*
95 * This function is called when the clients is grabbed by another
96 * geometry manager. %% Should inform with a -lost call
97 */
98 static void
99 GeoLostSlaveProc(clientData, tkwin)
100 ClientData clientData; /* Information about
101 * window that got new preferred
102 * geometry. */
103 Tk_Window tkwin; /* Other Tk-related information
104 * about the window. */
105 {
106 ClientStruct * cnPtr = (ClientStruct *) clientData;
107 Tcl_HashEntry * hashPtr;
108 int result;
109
110 if (cnPtr->isDeleted) {
111 return;
112 }
113
114 result = Tix_GlobalVarEval(cnPtr->interp, cnPtr->command, " -lostslave ",
115 Tk_PathName(cnPtr->tkwin), (char*)NULL);
116
117 if (result != TCL_OK) {
118 Tcl_AddErrorInfo(cnPtr->interp,
119 "\n (geometry request command executed by tixManageGeometry)");
120 Tk_BackgroundError(cnPtr->interp);
121 }
122
123 hashPtr = Tcl_FindHashEntry(&clientTable, (char *)tkwin);
124 if (hashPtr) {
125 Tcl_DeleteHashEntry(hashPtr);
126 }
127 cnPtr->isDeleted = 1;
128 Tk_EventuallyFree((ClientData) cnPtr, (Tix_FreeProc*)FreeClientStruct);
129 }
130
131
132 static void StructureProc(clientData, eventPtr)
133 ClientData clientData;
134 XEvent *eventPtr;
135 {
136 ClientStruct * cnPtr = (ClientStruct *) clientData;
137 Tcl_HashEntry * hashPtr;
138
139 if (eventPtr->type == DestroyNotify) {
140 if (cnPtr->isDeleted) {
141 return;
142 }
143
144 hashPtr = Tcl_FindHashEntry(&clientTable, (char *)cnPtr->tkwin);
145 if (hashPtr) {
146 Tcl_DeleteHashEntry(hashPtr);
147 }
148 cnPtr->isDeleted = 1;
149 Tk_EventuallyFree((ClientData) cnPtr, (Tix_FreeProc*)FreeClientStruct);
150 }
151 }
152
153
154 /*
155 *
156 * argv[1] = clientPathName
157 * argv[2] = managerCommand <-- can have arguments
158 *
159 * %% add possibility to delete a manager
160 *
161 */
162 TIX_DEFINE_CMD(Tix_ManageGeometryCmd)
163 {
164 Tk_Window topLevel = (Tk_Window)clientData;
165 Tk_Window tkwin;
166 ClientStruct * cnPtr;
167 Tcl_HashEntry * hashPtr;
168 int isNew;
169 static int inited = 0;
170
171 if (argc!=3) {
172 return Tix_ArgcError(interp, argc, argv, 1, "pathname command");
173 }
174
175 if ((tkwin = Tk_NameToWindow(interp, argv[1], topLevel)) == NULL) {
176 return TCL_ERROR;
177 }
178
179 if (!inited) {
180 Tcl_InitHashTable(&clientTable, TCL_ONE_WORD_KEYS);
181 inited = 1;
182 }
183
184 hashPtr = Tcl_CreateHashEntry(&clientTable, (char *)tkwin, &isNew);
185
186 if (!isNew) {
187 cnPtr = (ClientStruct *) Tcl_GetHashValue(hashPtr);
188 ckfree(cnPtr->command);
189 cnPtr->command = tixStrDup(argv[2]);
190 } else {
191 cnPtr = (ClientStruct *) ckalloc(sizeof(ClientStruct));
192 cnPtr->tkwin = tkwin;
193 cnPtr->interp = interp;
194 cnPtr->command = tixStrDup(argv[2]);
195 cnPtr->isDeleted = 0;
196 Tcl_SetHashValue(hashPtr, cnPtr);
197
198 Tk_ManageGeometry(tkwin, &geoType, (ClientData)cnPtr);
199 Tk_CreateEventHandler(tkwin, StructureNotifyMask,
200 StructureProc, (ClientData)cnPtr);
201 }
202
203 return TCL_OK;
204 }
205
206 /*----------------------------------------------------------------------
207 *
208 * The following are TCL bindings for the TK geometry functions.
209 *
210 *----------------------------------------------------------------------
211 */
212
213 /*
214 *
215 * argv[1] = clientPathName
216 * argv[2] = req width
217 * argv[3] = req height
218 *
219 */
220 TIX_DEFINE_CMD(Tix_GeometryRequestCmd)
221 {
222 Tk_Window topLevel = (Tk_Window)clientData;
223 Tk_Window tkwin;
224 int reqWidth;
225 int reqHeight;
226
227 if (argc != 4) {
228 return Tix_ArgcError(interp, argc, argv, 1,
229 "pathname reqwidth reqheight");
230 }
231
232 if ((tkwin = Tk_NameToWindow(interp, argv[1], topLevel)) == NULL) {
233 return TCL_ERROR;
234 }
235
236 if (Tk_GetPixels(interp, tkwin, argv[2], &reqWidth) != TCL_OK) {
237 return TCL_ERROR;
238 }
239
240 if (Tk_GetPixels(interp, tkwin, argv[3], &reqHeight) != TCL_OK) {
241 return TCL_ERROR;
242 }
243
244 Tk_GeometryRequest(tkwin, reqWidth, reqHeight);
245 return TCL_OK;
246 }
247
248 /*
249 *
250 * argv[1] = clientPathName
251 * argv[2] = width
252 * argv[3] = height
253 * argv[4] = width
254 * argv[5] = height
255 *
256 */
257 TIX_DEFINE_CMD(Tix_MoveResizeWindowCmd)
258 {
259 Tk_Window topLevel = (Tk_Window)clientData;
260 Tk_Window tkwin;
261 int x, y;
262 int width;
263 int height;
264
265 if (argc != 6) {
266 return Tix_ArgcError(interp, argc, argv, 1,
267 "pathname x y width height");
268 }
269
270 if ((tkwin = Tk_NameToWindow(interp, argv[1], topLevel)) == NULL) {
271 return TCL_ERROR;
272 }
273
274 if (Tk_GetPixels(interp, tkwin, argv[2], &x) != TCL_OK) {
275 return TCL_ERROR;
276 }
277
278 if (Tk_GetPixels(interp, tkwin, argv[3], &y) != TCL_OK) {
279 return TCL_ERROR;
280 }
281
282 if (Tk_GetPixels(interp, tkwin, argv[4], &width) != TCL_OK) {
283 return TCL_ERROR;
284 }
285
286 if (Tk_GetPixels(interp, tkwin, argv[5], &height) != TCL_OK) {
287 return TCL_ERROR;
288 }
289
290 Tk_MoveResizeWindow(tkwin, x, y, width, height);
291 return TCL_OK;
292 }
293
294 /*
295 *
296 * argv[1] = clientPathName
297 *
298 */
299 TIX_DEFINE_CMD(Tix_MapWindowCmd)
300 {
301 Tk_Window topLevel = (Tk_Window)clientData;
302 Tk_Window tkwin;
303
304 if (argc != 2) {
305 return Tix_ArgcError(interp, argc, argv, 1, "pathname");
306 }
307
308 if ((tkwin = Tk_NameToWindow(interp, argv[1], topLevel)) == NULL) {
309 return TCL_ERROR;
310 }
311
312 Tk_MapWindow(tkwin);
313 return TCL_OK;
314 }
315
316 /*
317 * Tix_FlushXCmd -- calls XFlush()
318 * argv[1] = pathName
319 *
320 */
321 TIX_DEFINE_CMD(Tix_FlushXCmd)
322 {
323 Tk_Window topLevel = (Tk_Window)clientData;
324 Tk_Window tkwin;
325
326 if (argc != 2) {
327 return Tix_ArgcError(interp, argc, argv, 1, "pathname");
328 }
329
330 if ((tkwin = Tk_NameToWindow(interp, argv[1], topLevel)) == NULL) {
331 return TCL_ERROR;
332 }
333
334 #ifndef _WINDOWS
335 XFlush(Tk_Display(tkwin));
336 #endif
337 return TCL_OK;
338 }
339
340 /*
341 *
342 * argv[1] = clientPathName
343 *
344 */
345 TIX_DEFINE_CMD(Tix_UnmapWindowCmd)
346 {
347 Tk_Window topLevel = (Tk_Window)clientData;
348 Tk_Window tkwin;
349
350 if (argc != 2) {
351 return Tix_ArgcError(interp, argc, argv, 1, "pathname");
352 }
353
354 if ((tkwin = Tk_NameToWindow(interp, argv[1], topLevel)) == NULL) {
355 return TCL_ERROR;
356 }
357
358 Tk_UnmapWindow(tkwin);
359 return TCL_OK;
360 }
361
362 /*
363 *
364 * argv[1] = clientPathName
365 *
366 */
367 TIX_DEFINE_CMD(Tix_RaiseWindowCmd)
368 {
369 Tk_Window topLevel = (Tk_Window)clientData;
370 Tk_Window tkwin;
371
372 if (argc != 2) {
373 return Tix_ArgcError(interp, argc, argv, 1, "pathname");
374 }
375
376 if ((tkwin = Tk_NameToWindow(interp, argv[1], topLevel)) == NULL) {
377 return TCL_ERROR;
378 }
379
380 XRaiseWindow(Tk_Display(tkwin), Tk_WindowId(tkwin));
381 return TCL_OK;
382 }