Debian Codegraph @

generic/bltTed.c

raw symbols ◀ ▶ SCIP
4 Debian patches touch this file
1 /*
2 * bltTed.c --
3 *
4 * This module implements an editor for the table geometry
5 * manager in the BLT toolkit.
6 *
7 * Copyright 1995 by AT&T Bell Laboratories.
8 * Permission to use, copy, modify, and distribute this software
9 * and its documentation for any purpose and without fee is hereby
10 * granted, provided that the above copyright notice appear in all
11 * copies and that both that the copyright notice and warranty
12 * disclaimer appear in supporting documentation, and that the
13 * names of AT&T Bell Laboratories any of their entities not be used
14 * in advertising or publicity pertaining to distribution of the
15 * software without specific, written prior permission.
16 *
17 * AT&T disclaims all warranties with regard to this software, including
18 * all implied warranties of merchantability and fitness. In no event
19 * shall AT&T be liable for any special, indirect or consequential
20 * damages or any damages whatsoever resulting from loss of use, data
21 * or profits, whether in an action of contract, negligence or other
22 * tortuous action, arising out of or in connection with the use or
23 * performance of this software.
24 *
25 * Table editor was created by George Howlett.
26 */
27
28 #include "bltInt.h"
29
30 #include "bltTable.h"
31
32 extern Tk_CustomOption bltDistanceOption;
33 extern Tk_CustomOption bltDashesOption;
34
35 typedef struct TedStruct Ted;
36
37 #define TABLE_THREAD_KEY "BLT Table Data"
38
39 typedef struct {
40 Blt_HashTable tableTable; /* Hash table of table structures keyed by
41 * the address of the reference Tk window */
42 } TableData;
43
44
45 typedef struct {
46 int flags;
47 Tcl_Interp *interp;
48 Tk_Window tkwin; /* Entry window */
49 Entry *entryPtr; /* Entry it represents */
50 Table *tablePtr; /* Table where it can be found */
51 Ted *tedPtr; /* Table editor */
52 int mapped; /* Indicates if the debugging windows are
53 * mapped */
54 } EntryRep;
55
56
57 typedef struct {
58 Tk_Font font;
59 XColor *widgetColor;
60 XColor *cntlColor;
61 XColor *normalFg, *normalBg;
62 XColor *activeFg, *activeBg;
63
64 Tk_Cursor cursor; /* Cursor to display inside of this window */
65 Pixmap stipple;
66
67 GC drawGC; /* GC to draw grid, outlines */
68 GC fillGC; /* GC to fill entry area */
69 GC widgetFillGC; /* GC to fill widget area */
70 GC cntlGC; /* GC to fill rectangles */
71
72 } EntryAttributes;
73
74 typedef struct {
75 int count;
76 XRectangle *array;
77 } Rectangles;
78
79 struct TedStruct {
80 int gridLineWidth; /* Width of grid lines */
81 int buttonHeight; /* Height of row/column buttons */
82 int cavityPad; /* Extra padding to add to entry cavity */
83 int minSize; /* Minimum size for partitions */
84
85 EditorDrawProc *drawProc;
86 EditorDestroyProc *destroyProc;
87
88 Display *display;
89 Tk_Font font;
90 Table *tablePtr; /* Pointer to table being debugged */
91 Tcl_Interp *interp;
92 int flags;
93 Tk_Window tkwin; /* Grid window */
94 Tk_Window input; /* InputOnly window to receive events */
95 int inputIsSibling;
96
97 /* Form the grid */
98 XSegment *segArr;
99 int nSegs;
100 XRectangle *padRectArr;
101 int nPadRects;
102 XRectangle *widgetPadRectArr;
103 int nWidgetPadRects;
104
105 XRectangle *cntlRectArr;
106 int nCntlRects;
107
108 XRectangle *rectArr;
109 int nRects;
110
111 XRectangle activeRectArr[5];
112 int spanActive;
113
114 GC rectGC; /* GC to fill rectangles */
115 GC drawGC; /* GC to draw grid, outlines */
116 GC fillGC; /* GC to fill window */
117 GC spanGC; /* GC to fill spans */
118 GC padRectGC; /* GC to draw padding */
119
120 Tk_3DBorder border; /* Border to use with buttons */
121 int relief;
122 int borderWidth; /* Border width of buttons */
123 XColor *normalBg;
124 XColor *padColor;
125 XColor *gridColor;
126 XColor *buttonColor;
127 XColor *spanColor;
128
129 Pixmap padStipple;
130 Pixmap spanStipple;
131 Blt_Dashes dashes;
132 char *fileName; /* If non-NULL, indicates name of file
133 * to write final table output to */
134 int mapped; /* Indicates if the debugging windows are
135 * mapped */
136 int gripSize;
137 int doubleBuffer;
138 Tk_Cursor cursor;
139 Blt_Chain *chainPtr;
140 int nextWindowId;
141
142 EntryAttributes attributes; /* Entry attributes */
143 };
144
145 #define REDRAW_PENDING (1<<0) /* A DoWhenIdle handler has already
146 * been queued to redraw the window */
147 #define LAYOUT_PENDING (1<<1)
148
149 /*
150 *
151 *
152 * |Cavity|1|2|
153 *
154 *
155 */
156 #define DEF_ENTRY_ACTIVE_BG_MONO RGB_BLACK
157 #define DEF_ENTRY_ACTIVE_FG_MONO RGB_WHITE
158 #define DEF_ENTRY_ACTIVE_BACKGROUND RGB_BLACK
159 #define DEF_ENTRY_ACTIVE_FOREGROUND RGB_WHITE
160 #define DEF_ENTRY_CURSOR (char *)NULL
161 #define DEF_ENTRY_FONT "*-Courier-Bold-R-Normal-*-100-*"
162 #define DEF_ENTRY_NORMAL_BACKGROUND RGB_BLUE
163 #define DEF_ENTRY_NORMAL_BG_MONO RGB_BLACK
164 #define DEF_ENTRY_NORMAL_FOREGROUND RGB_WHITE
165 #define DEF_ENTRY_NORMAL_FG_MONO RGB_WHITE
166 #define DEF_ENTRY_WIDGET_BACKGROUND RGB_GREEN
167 #define DEF_ENTRY_CONTROL_BACKGROUND RGB_YELLOW
168 #define DEF_ENTRY_WIDGET_BG_MONO RGB_BLACK
169 #define DEF_ENTRY_STIPPLE "gray50"
170 #define DEF_GRID_BACKGROUND RGB_WHITE
171 #define DEF_GRID_BG_MONO RGB_WHITE
172 #define DEF_GRID_CURSOR "crosshair"
173 #define DEF_GRID_DASHES (char *)NULL
174 #define DEF_GRID_FOREGROUND RGB_BLACK
175 #define DEF_GRID_FG_MONO RGB_BLACK
176 #define DEF_GRID_FONT "*-Courier-Bold-R-Normal-*-100-*"
177 #define DEF_GRID_LINE_WIDTH "1"
178 #define DEF_GRID_PAD_COLOR RGB_RED
179 #define DEF_GRID_PAD_MONO RGB_BLACK
180 #define DEF_GRID_PAD_STIPPLE "gray25"
181 #define DEF_GRID_PAD_CAVITY "0"
182 #define DEF_GRID_PAD_MIN "8"
183 #define DEF_ROWCOL_BACKGROUND RGB_RED
184 #define DEF_ROWCOL_BG_MONO RGB_BLACK
185 #define DEF_ROWCOL_BORDER_COLOR RGB_RED
186 #define DEF_ROWCOL_BORDER_MONO RGB_BLACK
187 #define DEF_ROWCOL_BORDERWIDTH "2"
188 #define DEF_ROWCOL_HEIGHT "8"
189 #define DEF_ROWCOL_RELIEF "raised"
190 #define DEF_SPAN_STIPPLE "gray50"
191 #define DEF_SPAN_COLOR RGB_BLACK
192 #define DEF_SPAN_MONO RGB_BLACK
193 #define DEF_SPAN_GRIP_SIZE "5"
194 #define DEF_GRID_DOUBLE_BUFFER "1"
195
196 static Tk_ConfigSpec configSpecs[] =
197 {
198 {TK_CONFIG_BORDER, "-bg", "tedBorder", (char *)NULL,
199 DEF_ROWCOL_BORDER_COLOR, Tk_Offset(Ted, border), TK_CONFIG_COLOR_ONLY},
200 {TK_CONFIG_BORDER, "-bg", "tedBorder", (char *)NULL,
201 DEF_ROWCOL_BORDER_MONO, Tk_Offset(Ted, border), TK_CONFIG_MONO_ONLY},
202 {TK_CONFIG_COLOR, "-background", "tedBackground", (char *)NULL,
203 DEF_GRID_BACKGROUND, Tk_Offset(Ted, normalBg), TK_CONFIG_COLOR_ONLY},
204 {TK_CONFIG_COLOR, "-background", "tedBackground", (char *)NULL,
205 DEF_GRID_BG_MONO, Tk_Offset(Ted, normalBg), TK_CONFIG_MONO_ONLY},
206 {TK_CONFIG_CURSOR, "-cursor", "cursor", (char *)NULL,
207 DEF_GRID_CURSOR, Tk_Offset(Ted, cursor), TK_CONFIG_NULL_OK},
208 {TK_CONFIG_COLOR, "-gridcolor", "gridColor", (char *)NULL,
209 DEF_GRID_FOREGROUND, Tk_Offset(Ted, gridColor), TK_CONFIG_COLOR_ONLY},
210 {TK_CONFIG_COLOR, "-gridcolor", "gridColor", (char *)NULL,
211 DEF_GRID_FG_MONO, Tk_Offset(Ted, gridColor), TK_CONFIG_MONO_ONLY},
212 {TK_CONFIG_COLOR, "-buttoncolor", "buttonColor", (char *)NULL,
213 DEF_ROWCOL_BACKGROUND, Tk_Offset(Ted, buttonColor), TK_CONFIG_COLOR_ONLY},
214 {TK_CONFIG_COLOR, "-buttoncolor", "buttonColor", (char *)NULL,
215 DEF_ROWCOL_BG_MONO, Tk_Offset(Ted, buttonColor), TK_CONFIG_MONO_ONLY},
216 {TK_CONFIG_COLOR, "-padcolor", "padColor", (char *)NULL,
217 DEF_GRID_PAD_COLOR, Tk_Offset(Ted, padColor), TK_CONFIG_COLOR_ONLY},
218 {TK_CONFIG_COLOR, "-padcolor", "padColor", (char *)NULL,
219 DEF_GRID_PAD_MONO, Tk_Offset(Ted, padColor), TK_CONFIG_MONO_ONLY},
220 {TK_CONFIG_BITMAP, "-padstipple", "padStipple", (char *)NULL,
221 DEF_GRID_PAD_STIPPLE, Tk_Offset(Ted, padStipple), TK_CONFIG_NULL_OK},
222 {TK_CONFIG_FONT, "-font", "font", (char *)NULL,
223 DEF_GRID_FONT, Tk_Offset(Ted, font), 0},
224 {TK_CONFIG_CUSTOM, "-gridlinewidth", "gridLineWidth", (char *)NULL,
225 DEF_GRID_LINE_WIDTH, Tk_Offset(Ted, gridLineWidth),
226 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
227 {TK_CONFIG_CUSTOM, "-buttonheight", "buttonHeight", (char *)NULL,
228 DEF_ROWCOL_HEIGHT, Tk_Offset(Ted, buttonHeight),
229 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
230 {TK_CONFIG_CUSTOM, "-cavitypad", "cavityPad", (char *)NULL,
231 DEF_GRID_PAD_CAVITY, Tk_Offset(Ted, cavityPad),
232 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
233 {TK_CONFIG_CUSTOM, "-minsize", "minSize", (char *)NULL,
234 DEF_GRID_PAD_MIN, Tk_Offset(Ted, minSize),
235 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
236 {TK_CONFIG_CUSTOM, "-dashes", "dashes", (char *)NULL,
237 DEF_GRID_DASHES, Tk_Offset(Ted, dashes),
238 TK_CONFIG_NULL_OK, &bltDashesOption},
239 {TK_CONFIG_RELIEF, "-relief", "relief", (char *)NULL,
240 DEF_ROWCOL_RELIEF, Tk_Offset(Ted, relief), TK_CONFIG_DONT_SET_DEFAULT},
241 {TK_CONFIG_CUSTOM, "-borderwidth", "borderWidth", (char *)NULL,
242 DEF_ROWCOL_BORDERWIDTH, Tk_Offset(Ted, borderWidth),
243 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
244 {TK_CONFIG_CURSOR, "-entrycursor", "entryCursor", (char *)NULL,
245 DEF_ENTRY_CURSOR, Tk_Offset(Ted, attributes.cursor),
246 TK_CONFIG_NULL_OK},
247 {TK_CONFIG_FONT, "-entryfont", "entryFont", (char *)NULL,
248 DEF_ENTRY_FONT, Tk_Offset(Ted, attributes.font), 0},
249 {TK_CONFIG_BITMAP, "-entrystipple", "entryStipple", (char *)NULL,
250 DEF_ENTRY_STIPPLE, Tk_Offset(Ted, attributes.stipple),
251 TK_CONFIG_NULL_OK},
252 {TK_CONFIG_COLOR, "-widgetbackground", "widgetBackground", (char *)NULL,
253 DEF_ENTRY_WIDGET_BACKGROUND, Tk_Offset(Ted, attributes.widgetColor),
254 TK_CONFIG_COLOR_ONLY},
255 {TK_CONFIG_COLOR, "-widgetbackground", "widgetBackground", (char *)NULL,
256 DEF_ENTRY_WIDGET_BG_MONO, Tk_Offset(Ted, attributes.widgetColor),
257 TK_CONFIG_MONO_ONLY},
258 {TK_CONFIG_COLOR, "-controlbackground", "controlBackground", (char *)NULL,
259 DEF_ENTRY_CONTROL_BACKGROUND, Tk_Offset(Ted, attributes.cntlColor),
260 TK_CONFIG_COLOR_ONLY},
261 {TK_CONFIG_COLOR, "-controlbackground", "controlBackground", (char *)NULL,
262 DEF_ENTRY_WIDGET_BG_MONO, Tk_Offset(Ted, attributes.cntlColor),
263 TK_CONFIG_MONO_ONLY},
264 {TK_CONFIG_COLOR, "-entrybackground", "entryBackground", (char *)NULL,
265 DEF_ENTRY_NORMAL_BACKGROUND, Tk_Offset(Ted, attributes.normalBg),
266 TK_CONFIG_COLOR_ONLY},
267 {TK_CONFIG_COLOR, "-entrybackground", "entryBackground", (char *)NULL,
268 DEF_ENTRY_NORMAL_BG_MONO, Tk_Offset(Ted, attributes.normalBg),
269 TK_CONFIG_MONO_ONLY},
270 {TK_CONFIG_COLOR, "-entryactivebackground", "entryActiveBackground", (char *)NULL,
271 DEF_ENTRY_ACTIVE_BACKGROUND, Tk_Offset(Ted, attributes.activeBg),
272 TK_CONFIG_COLOR_ONLY},
273 {TK_CONFIG_COLOR, "-entryactivebackground", "entryActiveBackground", (char *)NULL,
274 DEF_ENTRY_ACTIVE_BG_MONO, Tk_Offset(Ted, attributes.activeBg),
275 TK_CONFIG_MONO_ONLY},
276 {TK_CONFIG_COLOR, "-entryactiveforeground", "entryActiveForeground", (char *)NULL,
277 DEF_ENTRY_ACTIVE_FOREGROUND, Tk_Offset(Ted, attributes.activeFg),
278 TK_CONFIG_COLOR_ONLY},
279 {TK_CONFIG_COLOR, "-entryactiveforeground", "entryActiveForeground", (char *)NULL,
280 DEF_ENTRY_ACTIVE_FG_MONO, Tk_Offset(Ted, attributes.activeFg),
281 TK_CONFIG_MONO_ONLY},
282 {TK_CONFIG_COLOR, "-entryforeground", "entryForeground", (char *)NULL,
283 DEF_ENTRY_NORMAL_FOREGROUND, Tk_Offset(Ted, attributes.normalFg),
284 TK_CONFIG_COLOR_ONLY},
285 {TK_CONFIG_COLOR, "-entryforeground", "entryForeground", (char *)NULL,
286 DEF_ENTRY_NORMAL_FG_MONO, Tk_Offset(Ted, attributes.normalFg),
287 TK_CONFIG_MONO_ONLY},
288 {TK_CONFIG_COLOR, "-spancolor", "spanColor", (char *)NULL,
289 DEF_SPAN_COLOR, Tk_Offset(Ted, spanColor), TK_CONFIG_COLOR_ONLY},
290 {TK_CONFIG_COLOR, "-spancolor", "spanColor", (char *)NULL,
291 DEF_SPAN_MONO, Tk_Offset(Ted, spanColor), TK_CONFIG_MONO_ONLY},
292 {TK_CONFIG_BITMAP, "-spanstipple", "spanStipple", (char *)NULL,
293 DEF_SPAN_STIPPLE, Tk_Offset(Ted, spanStipple), TK_CONFIG_NULL_OK},
294 {TK_CONFIG_CUSTOM, "-gripsize", "gripSize", (char *)NULL,
295 DEF_SPAN_GRIP_SIZE, Tk_Offset(Ted, gripSize),
296 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
297 {TK_CONFIG_BOOLEAN, "-dbl", "doubleBuffer", (char *)NULL,
298 DEF_GRID_DOUBLE_BUFFER, Tk_Offset(Ted, doubleBuffer),
299 TK_CONFIG_DONT_SET_DEFAULT},
300 {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
301 };
302
303
304 static void DrawEditor _ANSI_ARGS_((Editor *editor));
305 static void DestroyEditor _ANSI_ARGS_((DestroyData destroyData));
306 static void DisplayTed _ANSI_ARGS_((ClientData clientData));
307 static void DestroyTed _ANSI_ARGS_((DestroyData destroyData));
308 static void DisplayEntry _ANSI_ARGS_((ClientData clientData));
•309 #if 0
310 static void DestroyEntry _ANSI_ARGS_((DestroyData destoryData));
•311 #endif
312
313 static Tcl_CmdProc TedCmd;
•314 #if 0
315 static Tk_EventProc EntryEventProc;
•316 #endif
317 static Tk_EventProc TedEventProc;
318
319 /*
320 *----------------------------------------------------------------------
321 *
322 * EventuallyRedraw --
323 *
324 * Queues a request to redraw the text window at the next idle
325 * point.
326 *
327 * Results:
328 * None.
329 *
330 * Side effects:
331 * Information gets redisplayed. Right now we don't do selective
332 * redisplays: the whole window will be redrawn. This doesn't
333 * seem to hurt performance noticeably, but if it does then this
334 * could be changed.
335 *
336 *----------------------------------------------------------------------
337 */
338 static void
339 EventuallyRedraw(tedPtr)
340 Ted *tedPtr; /* Information about editor. */
341 {
342 if ((tedPtr->tkwin != NULL) && !(tedPtr->flags & REDRAW_PENDING)) {
343 tedPtr->flags |= REDRAW_PENDING;
344 Tcl_DoWhenIdle(DisplayTed, tedPtr);
345 }
346 }
347
348 /*
349 *----------------------------------------------------------------------
350 *
351 * EventuallyRedraw --
352 *
353 * Queues a request to redraw the text window at the next idle
354 * point.
355 *
356 * Results:
357 * None.
358 *
359 * Side effects:
360 * Information gets redisplayed. Right now we don't do selective
361 * redisplays: the whole window will be redrawn. This doesn't
362 * seem to hurt performance noticeably, but if it does then this
363 * could be changed.
364 *
365 *----------------------------------------------------------------------
366 */
•367 #if 0
368 static void
369 EventuallyRedrawEntry(repPtr)
370 EntryRep *repPtr; /* Information about editor. */
371 {
372 if ((repPtr->tkwin != NULL) && !(repPtr->flags & REDRAW_PENDING)) {
373 repPtr->flags |= REDRAW_PENDING;
374 Tcl_DoWhenIdle(DisplayEntry, repPtr);
375 }
376 }
•377 #endif
378
379 /*
380 * --------------------------------------------------------------
381 *
382 * EntryEventProc --
383 *
384 * This procedure is invoked by the Tk dispatcher for various
385 * events on the editing grid for the table.
386 *
387 * Results:
388 * None.
389 *
390 * Side effects:
391 * When the window gets deleted, internal structures get
392 * cleaned up. When it gets exposed, it is redisplayed.
393 *
394 * --------------------------------------------------------------
395 */
•396 #if 0
397 static void
398 EntryEventProc(clientData, eventPtr)
399 ClientData clientData; /* Information about window. */
400 XEvent *eventPtr; /* Information about event. */
401 {
402 EntryRep *repPtr = (EntryRep *) clientData;
403
404 if (eventPtr->type == ConfigureNotify) {
405 EventuallyRedrawEntry(repPtr);
406 } else if (eventPtr->type == Expose) {
407 if (eventPtr->xexpose.count == 0) {
408 EventuallyRedrawEntry(repPtr);
409 }
410 } else if (eventPtr->type == DestroyNotify) {
411 repPtr->tkwin = NULL;
412 if (repPtr->flags & REDRAW_PENDING) {
413 Tcl_CancelIdleCall(DisplayEntry, repPtr);
414 }
415 Tcl_EventuallyFree(repPtr, DestroyEntry);
416 }
417 }
•418 #endif
419
420 /*
421 * --------------------------------------------------------------
422 *
423 * TedEventProc --
424 *
425 * This procedure is invoked by the Tk dispatcher for various
426 * events on the editing grid for the table.
427 *
428 * Results:
429 * None.
430 *
431 * Side effects:
432 * When the window gets deleted, internal structures get
433 * cleaned up. When it gets exposed, it is redisplayed.
434 *
435 * --------------------------------------------------------------
436 */
437 static void
438 TedEventProc(clientData, eventPtr)
439 ClientData clientData; /* Information about window. */
440 XEvent *eventPtr; /* Information about event. */
441 {
442 Ted *tedPtr = (Ted *) clientData;
443
444 if (eventPtr->type == ConfigureNotify) {
445 EventuallyRedraw(tedPtr);
446 } else if (eventPtr->type == Expose) {
447 if (eventPtr->xexpose.count == 0) {
448 EventuallyRedraw(tedPtr);
449 }
450 } else if (eventPtr->type == DestroyNotify) {
451 tedPtr->tkwin = NULL;
452 if (tedPtr->flags & REDRAW_PENDING) {
453 Tcl_CancelIdleCall(DisplayTed, tedPtr);
454 }
455 Tcl_EventuallyFree(tedPtr, DestroyTed);
456 }
457 }
458
459 /*
460 * ----------------------------------------------------------------------------
461 *
462 * CreateGrid --
463 *
464 * ----------------------------------------------------------------------------
465 */
466 static int
467 CreateGrid(tedPtr)
468 Ted *tedPtr;
469 {
470 Tcl_Interp *interp;
471 Tk_Window tkwin;
472 Tk_Window master;
473 /*
474 * Create a sibling window to cover the master window. It will
475 * be stacked just above the master window.
476 */
477 interp = tedPtr->tablePtr->interp;
478 master = tedPtr->tablePtr->tkwin;
479 tkwin = Tk_CreateWindow(interp, master, "ted_%output%", (char *)NULL);
480 if (tkwin == NULL) {
481 return TCL_ERROR;
482 }
483 Tk_SetClass(tkwin, "BltTed");
484 Tk_CreateEventHandler(tkwin, ExposureMask | StructureNotifyMask,
485 TedEventProc, tedPtr);
486 Tk_MoveResizeWindow(tkwin, 0, 0, Tk_Width(master), Tk_Height(master));
487 Tk_RestackWindow(tkwin, Below, (Tk_Window)NULL);
488 Tk_MapWindow(tkwin);
489 tedPtr->tkwin = tkwin;
490 return TCL_OK;
491 }
492
493 /*
494 * ----------------------------------------------------------------------------
495 *
496 * CreateEventWindow --
497 *
498 * ----------------------------------------------------------------------------
499 */
500 static int
501 CreateEventWindow(tedPtr)
502 Ted *tedPtr;
503 {
504 Tcl_Interp *interp;
505 Tk_Window tkwin;
506 Tk_Window master;
507 Tk_Window parent;
508
509 interp = tedPtr->tablePtr->interp;
510 master = tedPtr->tablePtr->tkwin;
511 /*
512 * Create an InputOnly window which sits above the table to
513 * collect and dispatch user events.
514 */
515 if (Tk_IsTopLevel(master)) {
516 /*
517 * If master is a top-level window, it's also the parent of
518 * the widgets (it can't have a sibling).
519 * In this case, the InputOnly window is a child of the
520 * master instead of a sibling.
521 */
522 parent = master;
523 tkwin = Tk_CreateWindow(interp, parent, "ted_%input%", (char *)NULL);
524 if (tkwin != NULL) {
525 Tk_ResizeWindow(tkwin, Tk_Width(parent), Tk_Height(parent));
526 }
527 tedPtr->inputIsSibling = 0;
528 } else {
529 char *namePtr; /* Name of InputOnly window. */
530
531 parent = Tk_Parent(master);
532 namePtr = Blt_Malloc(strlen(Tk_Name(master)) + 5);
533 sprintf(namePtr, "ted_%s", Tk_Name(master));
534 tkwin = Tk_CreateWindow(interp, parent, namePtr, (char *)NULL);
535 Blt_Free(namePtr);
536 if (tkwin != NULL) {
537 Tk_MoveResizeWindow(tkwin, Tk_X(master), Tk_Y(master),
538 Tk_Width(master), Tk_Height(master));
539 }
540 tedPtr->inputIsSibling = 1;
541 }
542 if (tkwin == NULL) {
543 return TCL_ERROR;
544 }
545 Blt_MakeTransparentWindowExist(tkwin, Tk_WindowId(parent), TRUE);
546 Tk_RestackWindow(tkwin, Above, (Tk_Window)NULL);
547 Tk_MapWindow(tkwin);
548 tedPtr->input = tkwin;
549 return TCL_OK;
550 }
551
552 /*
553 * ----------------------------------------------------------------------------
554 *
555 * CreateEntry --
556 *
557 * ----------------------------------------------------------------------------
558 */
•559 #if 0
560 static int
561 CreateEntry(tedPtr, entryPtr)
562 Ted *tedPtr;
563 Entry *entryPtr;
564 {
565 Tk_Window tkwin, master;
566 char string[200];
567 EntryRep *repPtr;
568 Blt_ChainLink *linkPtr;
569
570 repPtr = Blt_Calloc(1, sizeof(EntryRep));
571 assert(repPtr);
572 repPtr->tablePtr = tedPtr->tablePtr;
573 repPtr->tedPtr = tedPtr;
574 repPtr->interp = tedPtr->interp;
575 repPtr->entryPtr = entryPtr;
576 repPtr->mapped = 0;
577
578 /*
579 * Create a sibling window to cover the master window. It will
580 * be stacked just above the master window.
581 */
582
583 master = tedPtr->tablePtr->tkwin;
584 sprintf(string, "bltTed%d", tedPtr->nextWindowId);
585 tedPtr->nextWindowId++;
586 tkwin = Tk_CreateWindow(tedPtr->interp, master, string, (char *)NULL);
587 if (tkwin == NULL) {
588 Blt_Free(repPtr);
589 return TCL_ERROR;
590 }
591 Tk_SetClass(tkwin, "BltTed");
592 Tk_CreateEventHandler(tkwin, ExposureMask | StructureNotifyMask,
593 EntryEventProc, repPtr);
594 repPtr->tkwin = tkwin;
595 linkPtr = Blt_ChainNewLink();
596 Blt_ChainSetValue(linkPtr, repPtr);
597 Blt_ChainLinkAfter(tedPtr->chainPtr, linkPtr, (Blt_ChainLink *)NULL);
598 return TCL_OK;
599 }
600
601 /*
602 * ----------------------------------------------------------------------------
603 *
604 * DestroyEntry --
605 *
606 * ----------------------------------------------------------------------------
607 */
608 static void
609 DestroyEntry(data)
610 DestroyData data;
611 {
612 EntryRep *repPtr = (EntryRep *)data;
613 Blt_ChainLink *linkPtr;
614 Entry *entryPtr;
615
616 for (linkPtr = Blt_ChainFirstLink(repPtr->tedPtr->chainPtr);
617 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
618 entryPtr = Blt_ChainGetValue(linkPtr);
619 if (entryPtr == repPtr->entryPtr) {
620 Blt_ChainDeleteLink(repPtr->tedPtr->chainPtr, linkPtr);
621 Blt_Free(repPtr);
622 return;
623 }
624 }
625 }
•626 #endif
627
628 /*
629 * ----------------------------------------------------------------------------
630 *
631 * DisplayEntry --
632 *
633 * ----------------------------------------------------------------------------
634 */
635 static void
636 DisplayEntry(clientData)
637 ClientData clientData;
638 {
639 EntryRep *repPtr = (EntryRep *) clientData;
640 Ted *tedPtr;
641 Entry *entryPtr;
642 Tk_Window tkwin;
643 int x, y, width, height;
644
645 repPtr->flags &= ~REDRAW_PENDING;
646 if ((repPtr->tkwin == NULL) || (repPtr->entryPtr == NULL)) {
647 return;
648 }
649 if (!Tk_IsMapped(repPtr->tkwin)) {
650 return;
651 }
652 tedPtr = repPtr->tedPtr;
653 entryPtr = repPtr->entryPtr;
654 tkwin = repPtr->tkwin;
655
656 /*
657 * Check if the entry size and position.
658 * Move and resize the window accordingly.
659 */
660 x = Tk_X(entryPtr->tkwin) - (entryPtr->padLeft + tedPtr->cavityPad);
661 y = Tk_Y(entryPtr->tkwin) - (entryPtr->padTop + tedPtr->cavityPad);
662 width = Tk_Width(entryPtr->tkwin) + PADDING(entryPtr->padX) +
663 (2 * tedPtr->cavityPad);
664 height = Tk_Height(entryPtr->tkwin) + PADDING(entryPtr->padY) +
665 (2 * tedPtr->cavityPad);
666
667
668 if ((Tk_X(tkwin) != x) || (Tk_Y(tkwin) != y) ||
669 (Tk_Width(tkwin) != width) || (Tk_Height(tkwin) != height)) {
670 Tk_MoveResizeWindow(tkwin, x, y, width, height);
671 Tk_RestackWindow(tkwin, Above, (Tk_Window)NULL);
672 }
673 /* Clear the background of the entry */
674
675 XFillRectangle(Tk_Display(tkwin), Tk_WindowId(tkwin),
676 tedPtr->attributes.fillGC, 0, 0, width, height);
677
678 /* Draw the window */
679
680 x = entryPtr->padLeft + tedPtr->cavityPad;
681 y = entryPtr->padTop + tedPtr->cavityPad;
682
683 XFillRectangle(Tk_Display(tkwin), Tk_WindowId(tkwin),
684 tedPtr->attributes.widgetFillGC, x, y, Tk_Width(entryPtr->tkwin),
685 Tk_Height(entryPtr->tkwin));
686 XDrawRectangle(Tk_Display(tkwin), Tk_WindowId(tkwin),
687 tedPtr->attributes.drawGC, x, y, Tk_Width(entryPtr->tkwin),
688 Tk_Height(entryPtr->tkwin));
689 }
690
691 /*
692 * ----------------------------------------------------------------------------
693 *
694 * FindEditor --
695 *
696 * Searches for a table associated with the window given by its
697 * pathname. This window represents the master window of the table.
698 *
699 * Errors may occur because
700 * 1) pathName does not represent a valid Tk window or
701 * 2) the window is not associated with any table as its master.
702 *
703 * Results:
704 * If a table entry exists, a pointer to the Table structure is
705 * returned. Otherwise NULL is returned.
706 *
707 * ----------------------------------------------------------------------------
708 */
709 static Ted *
710 FindEditor(clientData, interp, pathName)
711 ClientData clientData; /* Thread-specific data. */
712 Tcl_Interp *interp; /* Interpreter to report errors back to */
713 char *pathName; /* Path name of the master window */
714 {
715 Table *tablePtr;
716
717 if (Blt_GetTable(clientData, interp, pathName, &tablePtr) != TCL_OK) {
718 return NULL;
719 }
720 if (tablePtr->editPtr == NULL) {
721 Tcl_AppendResult(interp, "no editor exists for table \"",
722 Tk_PathName(tablePtr->tkwin), "\"", (char *)NULL);
723 return NULL;
724 }
725 return (Ted *) tablePtr->editPtr;
726 }
727
728 /*
729 * ----------------------------------------------------------------------------
730 *
731 * CreateTed --
732 *
733 * ----------------------------------------------------------------------------
734 */
735 static Ted *
736 CreateTed(tablePtr, interp)
737 Table *tablePtr;
738 Tcl_Interp *interp;
739 {
740 Ted *tedPtr;
741
742 tedPtr = Blt_Calloc(1, sizeof(Ted));
743 assert(tedPtr);
744 tedPtr->nextWindowId = 0;
745 tedPtr->interp = interp;
746 tedPtr->tablePtr = tablePtr;
747 tedPtr->gridLineWidth = 1;
748 tedPtr->buttonHeight = 0;
749 tedPtr->cavityPad = 0;
750 tedPtr->minSize = 3;
751 tedPtr->gripSize = 5;
752 tedPtr->drawProc = DrawEditor;
753 tedPtr->destroyProc = DestroyEditor;
754 tedPtr->display = Tk_Display(tablePtr->tkwin);
755 tedPtr->relief = TK_RELIEF_RAISED;
756 tedPtr->borderWidth = 2;
757 tedPtr->doubleBuffer = 1;
758 tedPtr->chainPtr = Blt_ChainCreate();
759 /* Create the grid window */
760
761 if (CreateGrid(tedPtr) != TCL_OK) {
762 return NULL;
763 }
764 /* Create an InputOnly window to collect user events */
765 if (CreateEventWindow(tedPtr) != TCL_OK) {
766 return NULL;
767 }
768 tablePtr->editPtr = (Editor *)tedPtr;
769 return tedPtr;
770 }
771
772 /*
773 * ----------------------------------------------------------------------------
774 *
775 * DestroyTed --
776 *
777 * ----------------------------------------------------------------------------
778 */
779 static void
780 DestroyTed(freeProcData)
781 DestroyData freeProcData;
782 {
783 Ted *tedPtr = (Ted *) freeProcData;
784
785 if (tedPtr->rectArr != NULL) {
786 Blt_Free(tedPtr->rectArr);
787 }
788 if (tedPtr->segArr != NULL) {
789 Blt_Free(tedPtr->segArr);
790 }
791 if (tedPtr->fillGC != NULL) {
792 Tk_FreeGC(tedPtr->display, tedPtr->fillGC);
793 }
794 if (tedPtr->drawGC != NULL) {
795 Tk_FreeGC(tedPtr->display, tedPtr->drawGC);
796 }
797 if (tedPtr->rectGC != NULL) {
798 Tk_FreeGC(tedPtr->display, tedPtr->rectGC);
799 }
800 if (tedPtr->padRectGC != NULL) {
801 Tk_FreeGC(tedPtr->display, tedPtr->padRectGC);
802 }
803 /* Is this save ? */
804 tedPtr->tablePtr->editPtr = NULL;
805 Blt_Free(tedPtr);
806
807 }
808
809 /*
810 * ----------------------------------------------------------------------------
811 *
812 * ConfigureTed --
813 *
814 * This procedure is called to process an argv/argc list in order to
815 * configure the table geometry manager.
816 *
817 * Results:
818 * The return value is a standard Tcl result. If TCL_ERROR is
819 * returned, then interp->result contains an error message.
820 *
821 * Side effects:
822 * Table configuration options (padx, pady, rows, columns, etc) get
823 * set. The table is recalculated and arranged at the next idle
824 * point.
825 *
826 * ----------------------------------------------------------------------------
827 */
828 static int
829 ConfigureTed(tedPtr, argc, argv, flags)
830 Ted *tedPtr;
831 int argc;
•832 CONST char **argv; /* Option-value pairs */
833 int flags;
834 {
835 XGCValues gcValues;
836 GC newGC;
837 unsigned long gcMask;
838
•839 if (Blt_ConfigureWidget(tedPtr->interp, tedPtr->tkwin, configSpecs,
840 argc, argv, (char *)tedPtr, flags) != TCL_OK) {
841 return TCL_ERROR;
842 }
843 /* GC for filling background of edit window */
844
845 gcMask = GCForeground;
846 gcValues.foreground = tedPtr->normalBg->pixel;
847 newGC = Tk_GetGC(tedPtr->tkwin, gcMask, &gcValues);
848 if (tedPtr->fillGC != NULL) {
849 Tk_FreeGC(tedPtr->display, tedPtr->fillGC);
850 }
851 tedPtr->fillGC = newGC;
852
853 /* GC for drawing grid lines */
854
855 gcMask = (GCForeground | GCBackground | GCLineWidth | GCLineStyle |
856 GCCapStyle | GCJoinStyle | GCFont);
857 gcValues.font = Tk_FontId(tedPtr->font);
858 gcValues.foreground = tedPtr->gridColor->pixel;
859 gcValues.background = tedPtr->normalBg->pixel;
860 gcValues.line_width = LineWidth(tedPtr->gridLineWidth);
861 gcValues.cap_style = CapRound;
862 gcValues.join_style = JoinRound;
863 gcValues.line_style = LineSolid;
864 if (LineIsDashed(tedPtr->dashes)) {
865 gcValues.line_style = LineOnOffDash;
866 }
867 newGC = Blt_GetPrivateGC(tedPtr->tkwin, gcMask, &gcValues);
868 if (tedPtr->drawGC != NULL) {
869 Blt_FreePrivateGC(tedPtr->display, tedPtr->drawGC);
870 }
871 if (LineIsDashed(tedPtr->dashes)) {
872 XSetDashes(tedPtr->display, newGC, 0,
873 (CONST char *)tedPtr->dashes.values,
874 strlen((char *)tedPtr->dashes.values));
875 }
876 tedPtr->drawGC = newGC;
877
878 /* GC for button rectangles */
879
880 gcMask = GCForeground;
881 gcValues.foreground = tedPtr->buttonColor->pixel;
882 newGC = Tk_GetGC(tedPtr->tkwin, gcMask, &gcValues);
883 if (tedPtr->rectGC != NULL) {
884 Tk_FreeGC(tedPtr->display, tedPtr->rectGC);
885 }
886 tedPtr->rectGC = newGC;
887
888 /* GC for button rectangles */
889
890 gcMask = GCForeground;
891 gcValues.foreground = tedPtr->padColor->pixel;
892 if (tedPtr->padStipple != None) {
893 gcMask |= GCStipple | GCFillStyle;
894 gcValues.stipple = tedPtr->padStipple;
895 gcValues.fill_style = FillStippled;
896 }
897 newGC = Tk_GetGC(tedPtr->tkwin, gcMask, &gcValues);
898 if (tedPtr->padRectGC != NULL) {
899 Tk_FreeGC(tedPtr->display, tedPtr->padRectGC);
900 }
901 tedPtr->padRectGC = newGC;
902
903 /* GC for filling entrys */
904
905 gcMask = GCForeground;
906 gcValues.foreground = tedPtr->attributes.normalBg->pixel;
907 if (tedPtr->attributes.stipple != None) {
908 gcMask |= GCStipple | GCFillStyle;
909 gcValues.stipple = tedPtr->attributes.stipple;
910 gcValues.fill_style = FillStippled;
911 }
912 newGC = Tk_GetGC(tedPtr->tkwin, gcMask, &gcValues);
913 if (tedPtr->attributes.fillGC != NULL) {
914 Tk_FreeGC(tedPtr->display, tedPtr->attributes.fillGC);
915 }
916 tedPtr->attributes.fillGC = newGC;
917
918 /* GC for drawing entrys */
919
920 gcMask = GCForeground | GCBackground | GCFont;
921 gcValues.foreground = tedPtr->attributes.normalFg->pixel;
922 gcValues.background = tedPtr->attributes.normalBg->pixel;
923 gcValues.font = Tk_FontId(tedPtr->attributes.font);
924 newGC = Tk_GetGC(tedPtr->tkwin, gcMask, &gcValues);
925 if (tedPtr->attributes.drawGC != NULL) {
926 Blt_FreePrivateGC(tedPtr->display, tedPtr->attributes.drawGC);
927 }
928 tedPtr->attributes.drawGC = newGC;
929
930 /* GC for filling widget rectangles */
931
932 gcMask = GCForeground;
933 gcValues.foreground = tedPtr->attributes.widgetColor->pixel;
934 newGC = Tk_GetGC(tedPtr->tkwin, gcMask, &gcValues);
935 if (tedPtr->attributes.widgetFillGC != NULL) {
936 Tk_FreeGC(tedPtr->display, tedPtr->attributes.widgetFillGC);
937 }
938 tedPtr->attributes.widgetFillGC = newGC;
939
940 gcMask = GCForeground;
941 gcValues.foreground = tedPtr->attributes.cntlColor->pixel;
942 newGC = Tk_GetGC(tedPtr->tkwin, gcMask, &gcValues);
943 if (tedPtr->attributes.cntlGC != NULL) {
944 Tk_FreeGC(tedPtr->display, tedPtr->attributes.cntlGC);
945 }
946 tedPtr->attributes.cntlGC = newGC;
947
948 /* GC for filling span rectangle */
949
950 gcMask = GCForeground;
951 gcValues.foreground = tedPtr->spanColor->pixel;
952 if (tedPtr->spanStipple != None) {
953 gcMask |= GCStipple | GCFillStyle;
954 gcValues.stipple = tedPtr->spanStipple;
955 gcValues.fill_style = FillStippled;
956 }
957 newGC = Tk_GetGC(tedPtr->tkwin, gcMask, &gcValues);
958 if (tedPtr->spanGC != NULL) {
959 Tk_FreeGC(tedPtr->display, tedPtr->spanGC);
960 }
961 tedPtr->spanGC = newGC;
962
963 /* Define cursor for grid events */
964 if (tedPtr->cursor != None) {
965 Tk_DefineCursor(tedPtr->input, tedPtr->cursor);
966 } else {
967 Tk_UndefineCursor(tedPtr->input);
968 }
969 return TCL_OK;
970 }
971
972
973 static void
974 LayoutGrid(tedPtr)
975 Ted *tedPtr;
976 {
977 int needed;
978 XSegment *segArr;
979 Table *tablePtr;
980 Blt_ChainLink *linkPtr;
981 RowColumn *rcPtr;
982 int startX, endX;
983 int startY, endY;
984 int count;
985
986 tablePtr = tedPtr->tablePtr;
987 if (tedPtr->segArr != NULL) {
988 Blt_Free(tedPtr->segArr);
989 tedPtr->segArr = NULL;
990 }
991 tedPtr->nSegs = 0;
992 if ((tablePtr->nRows == 0) || (tablePtr->nColumns == 0)) {
993 return;
994 }
995 needed = tablePtr->nRows + tablePtr->nColumns + 2;
996 segArr = Blt_Calloc(needed, sizeof(XSegment));
997 if (segArr == NULL) {
998 return;
999 }
1000 linkPtr = Blt_ChainFirstLink(tablePtr->columnInfo.chainPtr);
1001 rcPtr = Blt_ChainGetValue(linkPtr);
1002 startX = rcPtr->offset - tedPtr->gridLineWidth;
1003
1004 linkPtr = Blt_ChainLastLink(tablePtr->columnInfo.chainPtr);
1005 rcPtr = Blt_ChainGetValue(linkPtr);
1006 endX = rcPtr->offset + rcPtr->size - 1;
1007
1008 linkPtr = Blt_ChainFirstLink(tablePtr->rowInfo.chainPtr);
1009 rcPtr = Blt_ChainGetValue(linkPtr);
1010 startY = rcPtr->offset - tedPtr->gridLineWidth;
1011
1012 linkPtr = Blt_ChainLastLink(tablePtr->rowInfo.chainPtr);
1013 rcPtr = Blt_ChainGetValue(linkPtr);
1014 endY = rcPtr->offset + rcPtr->size - 1;
1015
1016 count = 0; /* Reset segment counter */
1017
1018 for (linkPtr = Blt_ChainFirstLink(tablePtr->rowInfo.chainPtr);
1019 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
1020 rcPtr = Blt_ChainGetValue(linkPtr);
1021 segArr[count].x1 = startX;
1022 segArr[count].x2 = endX;
1023 segArr[count].y1 = segArr[count].y2 = rcPtr->offset -
1024 tedPtr->gridLineWidth;
1025 count++;
1026 }
1027 segArr[count].x1 = startX;
1028 segArr[count].x2 = endX;
1029 segArr[count].y1 = segArr[count].y2 = endY;
1030 count++;
1031
1032 for (linkPtr = Blt_ChainFirstLink(tablePtr->columnInfo.chainPtr);
1033 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
1034 rcPtr = Blt_ChainGetValue(linkPtr);
1035 segArr[count].y1 = startY;
1036 segArr[count].y2 = endY;
1037 segArr[count].x1 = segArr[count].x2 = rcPtr->offset -
1038 tedPtr->gridLineWidth;
1039 count++;
1040 }
1041 segArr[count].x1 = segArr[count].x2 = endX;
1042 segArr[count].y1 = startY;
1043 segArr[count].y2 = endY;
1044 count++;
1045 assert(count == needed);
1046 if (tedPtr->segArr != NULL) {
1047 Blt_Free(tedPtr->segArr);
1048 }
1049 tedPtr->segArr = segArr;
1050 tedPtr->nSegs = count;
1051 }
1052
1053
1054 static void
1055 LayoutPads(tedPtr)
1056 Ted *tedPtr;
1057 {
1058 int needed;
1059 XRectangle *rectArr, *rectPtr;
1060 Table *tablePtr;
1061 Blt_ChainLink *linkPtr;
1062 RowColumn *rcPtr;
1063 int startX, endX;
1064 int startY, endY;
1065 int count;
1066
1067 tablePtr = tedPtr->tablePtr;
1068 if (tedPtr->padRectArr != NULL) {
1069 Blt_Free(tedPtr->padRectArr);
1070 tedPtr->padRectArr = NULL;
1071 }
1072 tedPtr->nPadRects = 0;
1073 if ((tablePtr->nRows == 0) || (tablePtr->nColumns == 0)) {
1074 return;
1075 }
1076 needed = 2 * (tablePtr->nRows + tablePtr->nColumns);
1077 rectArr = Blt_Calloc(needed, sizeof(XRectangle));
1078 if (rectArr == NULL) {
1079 return;
1080 }
1081 linkPtr = Blt_ChainFirstLink(tablePtr->columnInfo.chainPtr);
1082 rcPtr = Blt_ChainGetValue(linkPtr);
1083 startX = rcPtr->offset;
1084
1085 linkPtr = Blt_ChainLastLink(tablePtr->columnInfo.chainPtr);
1086 rcPtr = Blt_ChainGetValue(linkPtr);
1087 endX = (rcPtr->offset + rcPtr->size);
1088
1089 linkPtr = Blt_ChainFirstLink(tablePtr->rowInfo.chainPtr);
1090 rcPtr = Blt_ChainGetValue(linkPtr);
1091 startY = rcPtr->offset;
1092
1093 linkPtr = Blt_ChainLastLink(tablePtr->rowInfo.chainPtr);
1094 rcPtr = Blt_ChainGetValue(linkPtr);
1095 endY = (rcPtr->offset + rcPtr->size);
1096
1097 count = 0; /* Reset segment counter */
1098 rectPtr = rectArr;
1099 for (linkPtr = Blt_ChainFirstLink(tablePtr->rowInfo.chainPtr);
1100 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
1101 rcPtr = Blt_ChainGetValue(linkPtr);
1102 if (rcPtr->pad.side1 > 0) {
1103 rectPtr->x = startX;
1104 rectPtr->y = rcPtr->offset;
1105 rectPtr->height = rcPtr->pad.side1;
1106 rectPtr->width = endX - startX - 1;
1107 rectPtr++, count++;
1108 }
1109 if (rcPtr->pad.side2 > 0) {
1110 rectPtr->x = startX;
1111 rectPtr->y = rcPtr->offset + rcPtr->size - rcPtr->pad.side2 - 1;
1112 rectPtr->height = rcPtr->pad.side2;
1113 rectPtr->width = endX - startX - 1;
1114 rectPtr++, count++;
1115 }
1116 }
1117 for (linkPtr = Blt_ChainFirstLink(tablePtr->columnInfo.chainPtr);
1118 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
1119 rcPtr = Blt_ChainGetValue(linkPtr);
1120 if (rcPtr->pad.side1 > 0) {
1121 rectPtr->x = rcPtr->offset;
1122 rectPtr->y = startY;
1123 rectPtr->height = endY - startY - 1;
1124 rectPtr->width = rcPtr->pad.side1;
1125 rectPtr++, count++;
1126 }
1127 if (rcPtr->pad.side2 > 0) {
1128 rectPtr->x = rcPtr->offset + rcPtr->size - rcPtr->pad.side2;
1129 rectPtr->y = startY;
1130 rectPtr->height = endY - startY - 1;
1131 rectPtr->width = rcPtr->pad.side2;
1132 rectPtr++, count++;
1133 }
1134 }
1135 if (count == 0) {
1136 Blt_Free(rectArr);
1137 return;
1138 }
1139 tedPtr->padRectArr = rectArr;
1140 tedPtr->nPadRects = count;
1141 }
1142
1143 static void
1144 LayoutEntries(tedPtr)
1145 Ted *tedPtr;
1146 {
1147 Entry *entryPtr;
1148 XRectangle *rectArr;
1149 int needed;
1150 int count;
1151 Blt_ChainLink *linkPtr;
1152
1153 if (tedPtr->widgetPadRectArr != NULL) {
1154 Blt_Free(tedPtr->widgetPadRectArr);
1155 tedPtr->widgetPadRectArr = NULL;
1156 }
1157 tedPtr->nWidgetPadRects = 0;
1158
1159 needed = Blt_ChainGetLength(tedPtr->tablePtr->chainPtr);
1160 rectArr = Blt_Calloc(needed, sizeof(XRectangle));
1161 if (rectArr == NULL) {
1162 return;
1163 }
1164 /* Draw any entry windows */
1165 count = 0;
1166 for (linkPtr = Blt_ChainFirstLink(tedPtr->tablePtr->chainPtr);
1167 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
1168 entryPtr = Blt_ChainGetValue(linkPtr);
1169 if ((PADDING(entryPtr->padX) + PADDING(entryPtr->padY)) == 0) {
1170 continue;
1171 }
1172 rectArr[count].x = Tk_X(entryPtr->tkwin) - entryPtr->padLeft;
1173 rectArr[count].y = Tk_Y(entryPtr->tkwin) - entryPtr->padTop;
1174 rectArr[count].width = Tk_Width(entryPtr->tkwin) +
1175 PADDING(entryPtr->padX);
1176 rectArr[count].height = Tk_Height(entryPtr->tkwin) +
1177 PADDING(entryPtr->padY);
1178 count++;
1179 }
1180 if (count == 0) {
1181 Blt_Free(rectArr);
1182 return;
1183 }
1184 tedPtr->widgetPadRectArr = rectArr;
1185 tedPtr->nWidgetPadRects = count;
1186 }
1187
1188 static void
1189 LayoutControlEntries(tedPtr)
1190 Ted *tedPtr;
1191 {
1192 Entry *entryPtr;
1193 XRectangle *rectArr;
1194 int needed;
1195 int count;
1196 Table *tablePtr = tedPtr->tablePtr;
1197 Blt_ChainLink *linkPtr;
1198 RowColumn *rcPtr;
1199
1200 if (tedPtr->cntlRectArr != NULL) {
1201 Blt_Free(tedPtr->cntlRectArr);
1202 tedPtr->cntlRectArr = NULL;
1203 }
1204 tedPtr->nCntlRects = 0;
1205
1206 needed = (tablePtr->nRows + tablePtr->nColumns);
1207 rectArr = Blt_Calloc(needed, sizeof(XRectangle));
1208 if (rectArr == NULL) {
1209 return;
1210 }
1211 /* Draw any entry windows */
1212 count = 0;
1213 for (linkPtr = Blt_ChainFirstLink(tablePtr->columnInfo.chainPtr);
1214 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
1215 rcPtr = Blt_ChainGetValue(linkPtr);
1216 entryPtr = rcPtr->control;
1217 if (entryPtr != NULL) {
1218 rectArr[count].x = Tk_X(entryPtr->tkwin) - entryPtr->padLeft;
1219 rectArr[count].y = Tk_Y(entryPtr->tkwin) - entryPtr->padTop;
1220 rectArr[count].width = Tk_Width(entryPtr->tkwin) +
1221 PADDING(entryPtr->padX);
1222 rectArr[count].height = Tk_Height(entryPtr->tkwin) +
1223 PADDING(entryPtr->padY);
1224 count++;
1225 }
1226 }
1227 for (linkPtr = Blt_ChainFirstLink(tablePtr->rowInfo.chainPtr);
1228 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
1229 rcPtr = Blt_ChainGetValue(linkPtr);
1230 entryPtr = rcPtr->control;
1231 if (entryPtr != NULL) {
1232 rectArr[count].x = Tk_X(entryPtr->tkwin) - entryPtr->padLeft;
1233 rectArr[count].y = Tk_Y(entryPtr->tkwin) - entryPtr->padTop;
1234 rectArr[count].width = Tk_Width(entryPtr->tkwin) +
1235 PADDING(entryPtr->padX);
1236 rectArr[count].height = Tk_Height(entryPtr->tkwin) +
1237 PADDING(entryPtr->padY);
1238 count++;
1239 }
1240 }
1241 if (count == 0) {
1242 Blt_Free(rectArr);
1243 return;
1244 }
1245 tedPtr->cntlRectArr = rectArr;
1246 tedPtr->nCntlRects = count;
1247 }
1248
1249 static void
1250 LayoutButtons(tedPtr)
1251 Ted *tedPtr;
1252 {
1253 int needed;
1254 XRectangle *rectArr;
1255 Table *tablePtr;
1256 Blt_ChainLink *linkPtr;
1257 RowColumn *rcPtr;
1258 int count;
1259
1260 tablePtr = tedPtr->tablePtr;
1261 if ((tablePtr->nRows == 0) || (tablePtr->nColumns == 0)) {
1262 if (tedPtr->rectArr != NULL) {
1263 Blt_Free(tedPtr->rectArr);
1264 }
1265 tedPtr->rectArr = NULL;
1266 tedPtr->nRects = 0;
1267 return; /* Nothing to display, empty table */
1268 }
1269 needed = 2 * (tablePtr->nRows + tablePtr->nColumns);
1270 rectArr = Blt_Calloc(needed, sizeof(XRectangle));
1271 if (rectArr == NULL) {
1272 return; /* Can't allocate rectangles */
1273 }
1274 count = 0;
1275 for (linkPtr = Blt_ChainFirstLink(tablePtr->rowInfo.chainPtr);
1276 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
1277 rcPtr = Blt_ChainGetValue(linkPtr);
1278 rectArr[count].x = 0;
1279 rectArr[count].y = rcPtr->offset - rcPtr->pad.side1;
1280 rectArr[count].width = tedPtr->buttonHeight;
1281 rectArr[count].height = rcPtr->size - 2;
1282 count++;
1283 rectArr[count].x = Tk_Width(tedPtr->tkwin) - tedPtr->buttonHeight;
1284 rectArr[count].y = rcPtr->offset - rcPtr->pad.side1;
1285 rectArr[count].width = tedPtr->buttonHeight;
1286 rectArr[count].height = rcPtr->size - 2;
1287 count++;
1288 }
1289 for (linkPtr = Blt_ChainFirstLink(tablePtr->columnInfo.chainPtr);
1290 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
1291 rcPtr = Blt_ChainGetValue(linkPtr);
1292 rectArr[count].x = rcPtr->offset - rcPtr->pad.side1;
1293 rectArr[count].y = 0;
1294 rectArr[count].width = rcPtr->size - 2;
1295 rectArr[count].height = tedPtr->buttonHeight;
1296 count++;
1297 rectArr[count].x = rcPtr->offset - rcPtr->pad.side1;
1298 rectArr[count].y = Tk_Height(tedPtr->tkwin) - tedPtr->buttonHeight;
1299 rectArr[count].width = rcPtr->size - 2;
1300 rectArr[count].height = tedPtr->buttonHeight;
1301 count++;
1302 }
1303 assert(count == needed);
1304 if (tedPtr->rectArr != NULL) {
1305 Blt_Free(tedPtr->rectArr);
1306 }
1307 tedPtr->rectArr = rectArr;
1308 tedPtr->nRects = count;
1309 }
1310
1311
1312 static void
1313 DisplayTed(clientData)
1314 ClientData clientData;
1315 {
1316 Ted *tedPtr = (Ted *) clientData;
1317 Tk_Window master;
1318 Tk_Window tkwin;
1319 Blt_ChainLink *linkPtr;
1320 EntryRep *repPtr;
1321 Drawable drawable;
1322 Pixmap pixmap;
1323
1324 #ifdef notdef
1325 fprintf(stderr, "display grid\n");
1326 #endif
1327 tedPtr->flags &= ~REDRAW_PENDING;
1328 if (!Tk_IsMapped(tedPtr->tkwin)) {
1329 return;
1330 }
1331 /*
1332 * Check if the master window has changed size and resize the
1333 * grid and input windows accordingly.
1334 */
1335 master = tedPtr->tablePtr->tkwin;
1336 if ((Tk_Width(master) != Tk_Width(tedPtr->tkwin)) ||
1337 (Tk_Height(master) != Tk_Height(tedPtr->tkwin))) {
1338 #ifdef notdef
1339 fprintf(stderr, "resizing windows\n");
1340 #endif
1341 Tk_ResizeWindow(tedPtr->tkwin, Tk_Width(master), Tk_Height(master));
1342 Tk_ResizeWindow(tedPtr->input, Tk_Width(master), Tk_Height(master));
1343 if (tedPtr->inputIsSibling) {
1344 Tk_MoveWindow(tedPtr->input, Tk_X(master), Tk_X(master));
1345 }
1346 tedPtr->flags |= LAYOUT_PENDING;
1347 }
1348 if (tedPtr->flags & LAYOUT_PENDING) {
1349 #ifdef notdef
1350 fprintf(stderr, "layout of grid\n");
1351 #endif
1352 LayoutPads(tedPtr);
1353 LayoutEntries(tedPtr);
1354 LayoutControlEntries(tedPtr);
1355 LayoutGrid(tedPtr);
1356 LayoutButtons(tedPtr);
1357 tedPtr->flags &= ~LAYOUT_PENDING;
1358 }
1359 tkwin = tedPtr->tkwin;
1360
1361 pixmap = None; /* Suppress compiler warning. */
1362 drawable = Tk_WindowId(tkwin);
1363 if (tedPtr->doubleBuffer) {
1364 /* Create an off-screen pixmap for semi-smooth scrolling. */
1365 pixmap = Tk_GetPixmap(tedPtr->display, Tk_WindowId(tkwin),
1366 Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));
1367 drawable = pixmap;
1368 }
1369 /* Clear the background of the grid */
1370
1371 XFillRectangle(Tk_Display(tkwin), drawable, tedPtr->fillGC, 0, 0,
1372 Tk_Width(tkwin), Tk_Height(tkwin));
1373
1374 /* Draw the row and column buttons */
1375
1376 if (tedPtr->nRects > 0) {
1377 int i;
1378
1379 for (i = 0; i < tedPtr->nRects; i++) {
1380 Blt_Fill3DRectangle(tkwin, drawable, tedPtr->border,
1381 tedPtr->rectArr[i].x, tedPtr->rectArr[i].y,
1382 tedPtr->rectArr[i].width, tedPtr->rectArr[i].height,
1383 tedPtr->borderWidth, tedPtr->relief);
1384 }
1385 #ifdef notdef
1386 XFillRectangles(tedPtr->display, drawable, tedPtr->rectGC,
1387 tedPtr->rectArr, tedPtr->nRects);
1388 XDrawRectangles(tedPtr->display, drawable, tedPtr->drawGC,
1389 tedPtr->rectArr, tedPtr->nRects);
1390 #endif
1391 }
1392 if (tedPtr->nPadRects > 0) {
1393 XFillRectangles(tedPtr->display, drawable, tedPtr->padRectGC,
1394 tedPtr->padRectArr, tedPtr->nPadRects);
1395 }
1396 if (tedPtr->spanActive) {
1397 XFillRectangles(tedPtr->display, drawable, tedPtr->spanGC,
1398 tedPtr->activeRectArr, 1);
1399 XFillRectangles(tedPtr->display, drawable, tedPtr->drawGC,
1400 tedPtr->activeRectArr + 1, 4);
1401 }
1402 if (tedPtr->nWidgetPadRects > 0) {
1403 XFillRectangles(tedPtr->display, drawable, tedPtr->attributes.fillGC,
1404 tedPtr->widgetPadRectArr, tedPtr->nWidgetPadRects);
1405 }
1406 if (tedPtr->nCntlRects > 0) {
1407 XFillRectangles(tedPtr->display, drawable, tedPtr->attributes.cntlGC,
1408 tedPtr->cntlRectArr, tedPtr->nCntlRects);
1409 }
1410 /* Draw the grid lines */
1411 if (tedPtr->nSegs > 0) {
1412 XDrawSegments(tedPtr->display, drawable, tedPtr->drawGC,
1413 tedPtr->segArr, tedPtr->nSegs);
1414 }
1415 #ifndef notdef
1416 /* Draw any entry windows */
1417 for (linkPtr = Blt_ChainFirstLink(tedPtr->chainPtr); linkPtr != NULL;
1418 linkPtr = Blt_ChainNextLink(linkPtr)) {
1419 repPtr = Blt_ChainGetValue(linkPtr);
1420 if (repPtr->mapped) {
1421 DisplayEntry(repPtr);
1422 }
1423 }
1424 #endif
1425 if (tedPtr->doubleBuffer) {
1426 XCopyArea(tedPtr->display, drawable, Tk_WindowId(tkwin), tedPtr->fillGC,
1427 0, 0, Tk_Width(tkwin), Tk_Height(tkwin), 0, 0);
1428 Tk_FreePixmap(tedPtr->display, pixmap);
1429 }
1430 }
1431
1432
1433 static void
1434 DrawEditor(editPtr)
1435 Editor *editPtr;
1436 {
1437 Ted *tedPtr = (Ted *) editPtr;
1438
1439 tedPtr->flags |= LAYOUT_PENDING;
1440 if ((tedPtr->tkwin != NULL) && !(tedPtr->flags & REDRAW_PENDING)) {
1441 tedPtr->flags |= REDRAW_PENDING;
1442 #ifdef notdef
1443 fprintf(stderr, "from draw editor\n");
1444 #endif
1445 Tcl_DoWhenIdle(DisplayTed, tedPtr);
1446 }
1447 }
1448
1449 static void
1450 DestroyEditor(destroyData)
1451 DestroyData destroyData;
1452 {
1453 Ted *tedPtr = (Ted *) destroyData;
1454
1455 tedPtr->tkwin = NULL;
1456 if (tedPtr->flags & REDRAW_PENDING) {
1457 Tcl_CancelIdleCall(DisplayTed, tedPtr);
1458 }
1459 Tcl_EventuallyFree(tedPtr, DestroyTed);
1460 }
1461
1462 /*
1463 * ----------------------------------------------------------------------------
1464 *
1465 * EditOp --
1466 *
1467 * Processes an argv/argc list of table entries to add and configure
1468 * new widgets into the table. A table entry consists of the
1469 * window path name, table index, and optional configuration options.
1470 * The first argument in the argv list is the name of the table. If
1471 * no table exists for the given window, a new one is created.
1472 *
1473 * Results:
1474 * Returns a standard Tcl result. If an error occurred, TCL_ERROR is
1475 * returned and an error message is left in interp->result.
1476 *
1477 * Side Effects:
1478 * Memory is allocated, a new master table is possibly created, etc.
1479 * The table is re-computed and arranged at the next idle point.
1480 *
1481 * ----------------------------------------------------------------------------
1482 */
1483 static int
1484 EditOp(dataPtr, interp, argc, argv)
1485 TableInterpData *dataPtr; /* Interpreter-specific data. */
1486 Tcl_Interp *interp; /* Interpreter to return list of names to */
1487 int argc; /* Number of arguments */
1488 char **argv;
1489 {
1490 Table *tablePtr;
1491 Ted *tedPtr;
1492
1493 if (Blt_GetTable(dataPtr, interp, argv[2], &tablePtr) != TCL_OK) {
1494 return TCL_ERROR;
1495 }
1496 if (tablePtr->editPtr != NULL) { /* Already editing this table */
1497 tedPtr = (Ted *) tablePtr->editPtr;
1498 } else {
1499 tedPtr = CreateTed(tablePtr, interp);
1500 if (tedPtr == NULL) {
1501 return TCL_ERROR;
1502 }
1503 }
1504 if (ConfigureTed(tedPtr, argc - 3, argv + 3, 0) != TCL_OK) {
1505 tedPtr->tkwin = NULL;
1506 if (tedPtr->flags & REDRAW_PENDING) {
1507 Tcl_CancelIdleCall(DisplayTed, tedPtr);
1508 }
1509 Tcl_EventuallyFree(tedPtr, DestroyTed);
1510 return TCL_ERROR;
1511 }
1512 /* Rearrange the table */
1513 if (!(tablePtr->flags & ARRANGE_PENDING)) {
1514 tablePtr->flags |= ARRANGE_PENDING;
1515 Tcl_DoWhenIdle(tablePtr->arrangeProc, tablePtr);
1516 }
•1517 Tcl_SetResult(interp, (char*)Tk_PathName(tedPtr->tkwin), TCL_VOLATILE);
1518 tedPtr->flags |= LAYOUT_PENDING;
1519 EventuallyRedraw(tedPtr);
1520 return TCL_OK;
1521 }
1522
1523 /*
1524 * ----------------------------------------------------------------------------
1525 *
1526 * CgetCmd --
1527 *
1528 * Results:
1529 * The return value is a standard Tcl result. If TCL_ERROR is
1530 * returned, then interp->result contains an error message.
1531 *
1532 * ----------------------------------------------------------------------------
1533 */
1534 /*ARGSUSED*/
1535 static int
1536 CgetOp(dataPtr, interp, argc, argv)
1537 TableInterpData *dataPtr; /* Interpreter-specific data. */
1538 Tcl_Interp *interp; /* Interpreter to report results back to */
1539 int argc; /* Not used. */
1540 char **argv; /* Option-value pairs */
1541 {
1542 Ted *tedPtr;
1543
1544 tedPtr = FindEditor(dataPtr, interp, argv[2]);
1545 if (tedPtr == NULL) {
1546 return TCL_ERROR;
1547 }
1548 return Tk_ConfigureValue(interp, tedPtr->tkwin, configSpecs,
1549 (char *)tedPtr, argv[3], 0);
1550 }
1551
1552 /*
1553 * ----------------------------------------------------------------------------
1554 *
1555 * ConfigureCmd --
1556 *
1557 * This procedure is called to process an argv/argc list in order to
1558 * configure the table geometry manager.
1559 *
1560 * Results:
1561 * The return value is a standard Tcl result. If TCL_ERROR is
1562 * returned, then interp->result contains an error message.
1563 *
1564 * Side effects:
1565 * Table configuration options (padx, pady, rows, columns, etc) get
1566 * set. The table is recalculated and arranged at the next idle
1567 * point.
1568 *
1569 * ----------------------------------------------------------------------------
1570 */
1571 static int
1572 ConfigureOp(dataPtr, interp, argc, argv)
1573 TableInterpData *dataPtr; /* Interpreter-specific data. */
1574 Tcl_Interp *interp; /* Interpreter to report results back to */
1575 int argc;
1576 char **argv; /* Option-value pairs */
1577 {
1578 Ted *tedPtr;
1579
1580 tedPtr = FindEditor(dataPtr, interp, argv[2]);
1581 if (tedPtr == NULL) {
1582 return TCL_ERROR;
1583 }
1584 if (argc == 3) {
1585 return Tk_ConfigureInfo(interp, tedPtr->tkwin, configSpecs,
1586 (char *)tedPtr, (char *)NULL, 0);
1587 } else if (argc == 4) {
1588 return Tk_ConfigureInfo(interp, tedPtr->tkwin, configSpecs,
1589 (char *)tedPtr, argv[3], 0);
1590 }
1591 if (ConfigureTed(tedPtr, argc - 3, argv + 3,
1592 TK_CONFIG_ARGV_ONLY) != TCL_OK) {
1593 return TCL_ERROR;
1594 }
1595 EventuallyRedraw(tedPtr);
1596 return TCL_OK;
1597 }
1598
1599 /*
1600 * ----------------------------------------------------------------------------
1601 *
1602 * SelectOp --
1603 *
1604 * ----------------------------------------------------------------------------
1605 */
1606 /*ARGSUSED*/
1607 static int
1608 SelectOp(dataPtr, interp, argc, argv)
1609 TableInterpData *dataPtr; /* Interpreter-specific data. */
1610 Tcl_Interp *interp; /* Interpreter to return list of names to */
1611 int argc; /* Not used. */
1612 char **argv;
1613 {
1614 Table *tablePtr;
1615 Ted *tedPtr;
1616 Entry *entryPtr;
1617 int active;
1618 int x, y, width, height;
1619 int ix, iy;
1620 Blt_ChainLink *linkPtr;
1621 Tk_Window tkwin;
1622
1623 /* ted select master @x,y */
1624 tkwin = Tk_MainWindow(interp);
1625 tedPtr = FindEditor(dataPtr, interp, argv[2]);
1626 if (tedPtr == NULL) {
1627 return TCL_ERROR;
1628 }
1629 if (Blt_GetXY(interp, tkwin, argv[3], &ix, &iy) != TCL_OK) {
1630 return TCL_ERROR;
1631 }
1632 tablePtr = tedPtr->tablePtr;
1633 active = 0;
1634 for (linkPtr = Blt_ChainFirstLink(tablePtr->chainPtr);
1635 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
1636 entryPtr = Blt_ChainGetValue(linkPtr);
1637 x = entryPtr->x - entryPtr->padX.side1;
1638 y = entryPtr->y - entryPtr->padY.side1;
1639 width = Tk_Width(entryPtr->tkwin) + PADDING(entryPtr->padX);
1640 height = Tk_Height(entryPtr->tkwin) + PADDING(entryPtr->padY);
1641 if ((ix >= x) && (ix <= (x + width)) &&
1642 (iy >= y) && (iy <= (y + height))) {
1643 int left, right, top, bottom;
1644 int last;
1645 int grip;
1646 RowColumn *rcPtr;
1647
1648 last = entryPtr->column.rcPtr->index + entryPtr->column.span - 1;
1649 linkPtr = Blt_ChainGetNthLink(tablePtr->columnInfo.chainPtr, last);
1650 rcPtr = Blt_ChainGetValue(linkPtr);
1651
1652 /* Calculate the span rectangle */
1653 left = (entryPtr->column.rcPtr->offset -
1654 entryPtr->column.rcPtr->pad.side1);
1655 right = (rcPtr->offset - rcPtr->pad.side1) + rcPtr->size;
1656
1657 top = (entryPtr->row.rcPtr->offset -
1658 entryPtr->row.rcPtr->pad.side1);
1659
1660 last = entryPtr->row.rcPtr->index + entryPtr->row.span - 1;
1661 linkPtr = Blt_ChainGetNthLink(tablePtr->rowInfo.chainPtr, last);
1662 rcPtr = Blt_ChainGetValue(linkPtr);
1663 bottom = (rcPtr->offset - rcPtr->pad.side1) + rcPtr->size;
1664
1665 tedPtr->activeRectArr[0].x = left;
1666 tedPtr->activeRectArr[0].y = top;
1667 tedPtr->activeRectArr[0].width = (right - left);
1668 tedPtr->activeRectArr[0].height = (bottom - top);
1669
1670 grip = tedPtr->gripSize;
1671 tedPtr->activeRectArr[1].x = (left + right - grip) / 2;
1672 tedPtr->activeRectArr[1].y = top;
1673 tedPtr->activeRectArr[1].width = grip - 1;
1674 tedPtr->activeRectArr[1].height = grip - 1;
1675
1676 tedPtr->activeRectArr[2].x = left;
1677 tedPtr->activeRectArr[2].y = (top + bottom - grip) / 2;
1678 tedPtr->activeRectArr[2].width = grip - 1;
1679 tedPtr->activeRectArr[2].height = grip - 1;
1680
1681 tedPtr->activeRectArr[3].x = (left + right - grip) / 2;
1682 tedPtr->activeRectArr[3].y = bottom - grip;
1683 tedPtr->activeRectArr[3].width = grip - 1;
1684 tedPtr->activeRectArr[3].height = grip - 1;
1685
1686 tedPtr->activeRectArr[4].x = right - grip;
1687 tedPtr->activeRectArr[4].y = (top + bottom - grip) / 2;
1688 tedPtr->activeRectArr[4].width = grip - 1;
1689 tedPtr->activeRectArr[4].height = grip - 1;
1690
•1691 Tcl_SetResult(interp, (char*)Tk_PathName(entryPtr->tkwin), TCL_VOLATILE);
1692 active = 1;
1693 break;
1694 }
1695 }
1696 if ((active) || (active != tedPtr->spanActive)) {
1697 tedPtr->spanActive = active;
1698 EventuallyRedraw(tedPtr);
1699 }
1700 return TCL_OK;
1701 }
1702
1703 /*
1704 * ----------------------------------------------------------------------------
1705 *
1706 * EditOp --
1707 *
1708 * Processes an argv/argc list of table entries to add and configure
1709 * new widgets into the table. A table entry consists of the
1710 * window path name, table index, and optional configuration options.
1711 * The first argument in the argv list is the name of the table. If
1712 * no table exists for the given window, a new one is created.
1713 *
1714 * Results:
1715 * Returns a standard Tcl result. If an error occurred, TCL_ERROR is
1716 * returned and an error message is left in interp->result.
1717 *
1718 * Side Effects:
1719 * Memory is allocated, a new master table is possibly created, etc.
1720 * The table is re-computed and arranged at the next idle point.
1721 *
1722 * ----------------------------------------------------------------------------
1723 */
1724 static int
1725 RepOp(dataPtr, interp, argc, argv)
1726 TableInterpData *dataPtr; /* Interpreter-specific data. */
1727 Tcl_Interp *interp; /* Interpreter to return list of names to */
1728 int argc; /* Number of arguments */
1729 char **argv;
1730 {
1731 Tk_Window tkwin;
1732 Table *tablePtr;
1733 Ted *tedPtr;
1734
1735 /* ted rep master index */
1736 tkwin = Tk_NameToWindow(interp, argv[3], Tk_MainWindow(interp));
1737 if (tkwin == NULL) {
1738 return TCL_ERROR;
1739 }
1740 if (Blt_GetTable(dataPtr, interp, argv[2], &tablePtr) != TCL_OK) {
1741 return TCL_ERROR;
1742 }
1743 if (tablePtr->editPtr != NULL) { /* Already editing this table */
1744 tedPtr = (Ted *) tablePtr->editPtr;
1745 } else {
1746 tedPtr = CreateTed(tablePtr, interp);
1747 if (tedPtr == NULL) {
1748 return TCL_ERROR;
1749 }
1750 }
1751 if (ConfigureTed(tedPtr, argc - 3, argv + 3, 0) != TCL_OK) {
1752 tedPtr->tkwin = NULL;
1753 if (tedPtr->flags & REDRAW_PENDING) {
1754 Tcl_CancelIdleCall(DisplayTed, tedPtr);
1755 }
1756 Tcl_EventuallyFree(tedPtr, DestroyTed);
1757 return TCL_ERROR;
1758 }
1759 /* Rearrange the table */
1760 if (!(tablePtr->flags & ARRANGE_PENDING)) {
1761 tablePtr->flags |= ARRANGE_PENDING;
1762 Tcl_DoWhenIdle(tablePtr->arrangeProc, tablePtr);
1763 }
•1764 Tcl_SetResult(interp, (char*)Tk_PathName(tedPtr->tkwin), TCL_VOLATILE);
1765 tedPtr->flags |= LAYOUT_PENDING;
1766 EventuallyRedraw(tedPtr);
1767 return TCL_OK;
1768 }
1769
1770 /*
1771 * ----------------------------------------------------------------------------
1772 *
1773 * Command options for the table editor.
1774 *
1775 * The fields for Blt_OperSpec are as follows:
1776 *
1777 * - option name
1778 * - minimum number of characters required to disambiguate the option name.
1779 * - function associated with command option.
1780 * - minimum number of arguments required.
1781 * - maximum number of arguments allowed (0 indicates no limit).
1782 * - usage string
1783 *
1784 * ----------------------------------------------------------------------------
1785 */
1786 static Blt_OpSpec opSpecs[] =
1787 {
1788 {"cget", 2, (Blt_Op)CgetOp, 4, 4, "master option",},
1789 {"configure", 2, (Blt_Op)ConfigureOp, 3, 0,
1790 "master ?option...?",},
1791 {"edit", 1, (Blt_Op)EditOp, 3, 0, "master ?options...?",},
1792 {"rep", 1, (Blt_Op)RepOp, 2, 0, "master index ?options...?",},
1793 {"select", 1, (Blt_Op)SelectOp, 4, 0, "master @x,y",},
1794 /* {"forget", 1, (Blt_Op)ForgetOp, 3, 0, "master ?master...?",},
1795 {"index", 1, (Blt_Op)IndexOp, 3, 0, "master ?item...?",}, */
1796 };
1797 static int nSpecs = sizeof(opSpecs) / sizeof(Blt_OpSpec);
1798
1799 /*
1800 * ----------------------------------------------------------------------------
1801 *
1802 * TedCmd --
1803 *
1804 * This procedure is invoked to process the Tcl command that
1805 * corresponds to the table geometry manager. See the user
1806 * documentation for details on what it does.
1807 *
1808 * Results:
1809 * A standard Tcl result.
1810 *
1811 * Side effects:
1812 * See the user documentation.
1813 *
1814 * ----------------------------------------------------------------------------
1815 */
1816 static int
1817 TedCmd(clientData, interp, argc, argv)
1818 ClientData clientData; /* Thread-specific data. */
1819 Tcl_Interp *interp;
1820 int argc;
1821 char **argv;
1822 {
1823 Blt_Op proc;
1824 int result;
1825
1826 proc = Blt_GetOp(interp, nSpecs, opSpecs, BLT_OP_ARG1, argc, argv, 0);
1827 if (proc == NULL) {
1828 return TCL_ERROR;
1829 }
1830 result = (*proc) (clientData, interp, argc, argv);
1831 return result;
1832 }
1833
1834 static TableData *
1835 GetTableInterpData(interp)
1836 Tcl_Interp *interp;
1837 {
1838 TableData *dataPtr;
1839 Tcl_InterpDeleteProc *proc;
1840
1841 dataPtr = (TableData *)Tcl_GetAssocData(interp, TABLE_THREAD_KEY, &proc);
1842 assert(dataPtr);
1843 return dataPtr;
1844 }
1845
1846 /*
1847 * ----------------------------------------------------------------------------
1848 *
1849 * Blt_TedInit --
1850 *
1851 * This procedure is invoked to initialize the Tcl command that
1852 * corresponds to the table geometry manager.
1853 *
1854 * Results:
1855 * None.
1856 *
1857 * Side effects:
1858 * Creates the new command and adds an entry into a global Tcl
1859 * associative array.
1860 *
1861 * ---------------------------------------------------------------------------
1862 */
1863 int
1864 Blt_TedInit(interp)
1865 Tcl_Interp *interp;
1866 {
1867 static Blt_CmdSpec cmdSpec = {"ted", TedCmd, };
1868 TableData *dataPtr;
1869
1870 dataPtr = GetTableInterpData(interp);
1871 cmdSpec.clientData = dataPtr;
1872 if (Blt_InitCmd(interp, "blt", &cmdSpec) == NULL) {
1873 return TCL_ERROR;
1874 }
1875 return TCL_OK;
1876 }