Debian Codegraph @

generic/bltTabset.c

raw symbols ◀ ▶
Source reconstructed at patch state 1 of 4 — not the installed (fully patched) source.
4 Debian patches touch this file
1 /*
2 * bltTabset.c --
3 *
4 * This module implements a tabset widget for the BLT toolkit.
5 *
6 * Copyright 1998 Lucent Technologies, Inc.
7 *
8 * Permission to use, copy, modify, and distribute this software and
9 * 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 names
13 * of Lucent Technologies or any of their entities not be used in
14 * advertising or publicity pertaining to distribution of the software
15 * without specific, written prior permission.
16 *
17 * Lucent Technologies disclaims all warranties with regard to this
18 * software, including all implied warranties of merchantability and
19 * fitness. In no event shall Lucent Technologies be liable for any
20 * special, indirect or consequential damages or any damages
21 * whatsoever resulting from loss of use, data or profits, whether in
22 * an action of contract, negligence or other tortuous action, arising
23 * out of or in connection with the use or performance of this
24 * software.
25 *
26 * Tabset widget created by George A. Howlett ([email protected])
27 * Extensive cleanups and enhancements by Peter MacDonald.
28 *
29 */
30
31 #include "bltInt.h"
32
33 #ifndef NO_TABSET
34 #include "bltBind.h"
35 #include "bltChain.h"
36 #include "bltHash.h"
37 #include "bltTile.h"
38
39 #if (TK_MAJOR_VERSION == 4)
40 #define TK_REPARENTED 0x2000
41 #endif
42
43 #define INVALID_FAIL 0
44 #define INVALID_OK 1
45
46 /*
47 * The macro below is used to modify a "char" value (e.g. by casting
48 * it to an unsigned character) so that it can be used safely with
49 * macros such as isspace.
50 */
51 #define CLAMP(val,low,hi) \
52 (((val) < (low)) ? (low) : ((val) > (hi)) ? (hi) : (val))
53
54 #define GAP 1
55 #define SELECT_PADX 4
56 #define SELECT_PADY 2
57 #define OUTER_PAD 0
58 #define LABEL_PAD 1
59 #define LABEL_PADX 2
60 #define LABEL_PADY 2
61 #define IMAGE_PAD 1
62 #define CORNER_OFFSET 3
63
64 #define TAB_SCROLL_OFFSET 10
65
66 #define SLANT_NONE 0
67 #define SLANT_LEFT 1
68 #define SLANT_RIGHT 2
69 #define SLANT_BOTH (SLANT_LEFT | SLANT_RIGHT)
70
71 #define END (-1)
72 #define ODD(x) ((x) | 0x01)
73
74 #define TABWIDTH(s, t) \
75 ((s)->side & SIDE_VERTICAL) ? (t)->height : (t)->width)
76 #define TABHEIGHT(s, t) \
77 ((s)->side & SIDE_VERTICAL) ? (t)->height : (t)->width)
78
79 #define VPORTWIDTH(s) \
80 (((s)->side & SIDE_HORIZONTAL) ? (Tk_Width((s)->tkwin) - 2 * (s)->inset) : \
81 (Tk_Height((s)->tkwin) - 2 * (s)->inset))
82
83 #define VPORTHEIGHT(s) \
84 (((s)->side & SIDE_VERTICAL) ? (Tk_Width((s)->tkwin) - 2 * (s)->inset) : \
85 (Tk_Height((s)->tkwin) - 2 * (s)->inset))
86
87 #define GETATTR(t,attr) \
88 (((t)->attr != NULL) ? (t)->attr : (t)->setPtr->defTabStyle.attr)
89
90 /*
91 * ----------------------------------------------------------------------------
92 *
93 * Internal widget flags:
94 *
95 * TABSET_LAYOUT The layout of the widget needs to be
96 * recomputed.
97 *
98 * TABSET_REDRAW A redraw request is pending for the widget.
99 *
100 * TABSET_DIRTY Reconfigure tabs.
101 *
102 * TABSET_SCROLL A scroll request is pending.
103 *
104 * TABSET_FOCUS The widget is receiving keyboard events.
105 * Draw the focus highlight border around the
106 * widget.
107 *
108 * TABSET_MULTIPLE_TIER Tabset is using multiple tiers.
109 *
110 * TABSET_STATIC Tabset does not scroll.
111 *
112 * ---------------------------------------------------------------------------
113 */
114 #define TABSET_LAYOUT (1<<0)
115 #define TABSET_REDRAW (1<<1)
116 #define TABSET_SCROLL (1<<2)
117 #define TABSET_DIRTY (1<<3)
118 #define TABSET_FOCUS (1<<4)
119 #define TABSET_DESTROYED (1<<5)
120
121 #define TABSET_STATIC (1<<8)
122 #define TABSET_MULTIPLE_TIER (1<<9)
123
124 #define PERFORATION_ACTIVE (1<<10)
125
126 #define SIDE_TOP (1<<0)
127 #define SIDE_RIGHT (1<<1)
128 #define SIDE_LEFT (1<<2)
129 #define SIDE_BOTTOM (1<<3)
130
131 #define SIDE_VERTICAL (SIDE_LEFT | SIDE_RIGHT)
132 #define SIDE_HORIZONTAL (SIDE_TOP | SIDE_BOTTOM)
133
134 #define TAB_LABEL (ClientData)0
135 #define TAB_PERFORATION (ClientData)1
136 #define TAB_IMAGE (ClientData)2
137 #define TAB_LEFTIMAGE (ClientData)3
138 #define TAB_STARTIMAGE (ClientData)4
139 #define TAB_ENDIMAGE (ClientData)5
140
141 #define DEF_TABSET_ACTIVE_BACKGROUND RGB_GREY90
142 #define DEF_TABSET_ACTIVE_BG_MONO STD_ACTIVE_BG_MONO
143 #define DEF_TABSET_ACTIVE_FOREGROUND STD_ACTIVE_FOREGROUND
144 #define DEF_TABSET_ACTIVE_FG_MONO STD_ACTIVE_FG_MONO
145 #define DEF_TABSET_ANCHOR "center"
146 #define DEF_TABSET_BG_MONO STD_NORMAL_BG_MONO
147 #define DEF_TABSET_BACKGROUND STD_NORMAL_BACKGROUND
148 #define DEF_TABSET_BORDERWIDTH "1"
149 #define DEF_TABSET_COMMAND (char *)NULL
150 #define DEF_TABSET_CURSOR (char *)NULL
151 #define DEF_TABSET_DASHES "1"
152 #define DEF_TABSET_FOREGROUND STD_NORMAL_FOREGROUND
153 #define DEF_TABSET_FG_MONO STD_NORMAL_FG_MONO
154 #define DEF_TABSET_FONT STD_FONT
155 #define DEF_TABSET_GAP "1"
156 #define DEF_TABSET_HEIGHT "0"
157 #define DEF_TABSET_HIGHLIGHT_BACKGROUND STD_NORMAL_BACKGROUND
158 #define DEF_TABSET_HIGHLIGHT_BG_MONO STD_NORMAL_BG_MONO
159 #define DEF_TABSET_HIGHLIGHT_COLOR RGB_BLACK
160 #define DEF_TABSET_HIGHLIGHT_WIDTH "2"
161 #define DEF_TABSET_NORMAL_BACKGROUND STD_NORMAL_BACKGROUND
162 #define DEF_TABSET_NORMAL_FG_MONO STD_ACTIVE_FG_MONO
163 #define DEF_TABSET_OUTER_PAD "0"
164 #define DEF_TABSET_RELIEF "sunken"
165 #define DEF_TABSET_ROTATE "0.0"
166 #define DEF_TABSET_SCROLL_INCREMENT "0"
167 #define DEF_TABSET_SELECT_BACKGROUND "#d9d9d9"
168 #define DEF_TABSET_SELECT_BG_MONO STD_SELECT_BG_MONO
169 #define DEF_TABSET_SELECT_BORDERWIDTH "1"
170 #define DEF_TABSET_SELECT_CMD (char *)NULL
171 #define DEF_TABSET_SELECT_FOREGROUND STD_SELECT_FOREGROUND
172 #define DEF_TABSET_SELECT_FG_MONO STD_SELECT_FG_MONO
173 #define DEF_TABSET_SELECT_MODE "multiple"
174 #define DEF_TABSET_SELECT_RELIEF "raised"
175 #define DEF_TABSET_SELECT_PAD "5"
176 #define DEF_TABSET_SHADOW_COLOR RGB_BLACK
177 #define DEF_TABSET_SIDE "top"
178 #define DEF_TABSET_SLANT "none"
179 #define DEF_TABSET_TAB_BACKGROUND "#c0c0c0"
180 #define DEF_TABSET_TAB_BG_MONO STD_SELECT_BG_MONO
181 #define DEF_TABSET_TAB_RELIEF "raised"
182 #define DEF_TABSET_TAKE_FOCUS "1"
183 #define DEF_TABSET_TEXT_COLOR STD_NORMAL_FOREGROUND
184 #define DEF_TABSET_TEXT_MONO STD_NORMAL_FG_MONO
185 #define DEF_TABSET_TEXT_SIDE "right"
186 #define DEF_TABSET_TIERS "1"
187 #define DEF_TABSET_TILE (char *)NULL
188 #define DEF_TABSET_WIDTH "0"
189 #define DEF_TABSET_SAME_WIDTH "no"
190 #define DEF_TABSET_FILL_WIDTH "yes"
191 #define DEF_TABSET_TEAROFF "yes"
192 #define DEF_TABSET_TRANSIENT "yes"
193 #define DEF_TABSET_PAGE_WIDTH "0"
194 #define DEF_TABSET_PAGE_HEIGHT "0"
195
196 #define DEF_TAB_ACTIVE_BG (char *)NULL
197 #define DEF_TAB_ACTIVE_FG (char *)NULL
198 #define DEF_TAB_ANCHOR "center"
199 #define DEF_TAB_BG (char *)NULL
200 #define DEF_TAB_COMMAND (char *)NULL
201 #define DEF_TAB_DATA (char *)NULL
202 #define DEF_TAB_FG (char *)NULL
203 #define DEF_TAB_FILL "none"
204 #define DEF_TAB_FONT (char *)NULL
205 #define DEF_TAB_HEIGHT "0"
206 #define DEF_TAB_HIDDEN "0"
207 #define DEF_TAB_IMAGE (char *)NULL
208 #define DEF_TAB_IPAD "0"
209 #define DEF_TAB_PAD "0"
210 #define DEF_TAB_PERF_COMMAND (char *)NULL
211 #define DEF_TAB_SELECT_BG (char *)NULL
212 #define DEF_TAB_SELECT_BORDERWIDTH "1"
213 #define DEF_TAB_SELECT_CMD (char *)NULL
214 #define DEF_TAB_SELECT_FG (char *)NULL
215 #define DEF_TAB_SHADOW (char *)NULL
216 #define DEF_TAB_STATE "normal"
217 #define DEF_TAB_STIPPLE "BLT"
218 #define DEF_TAB_BIND_TAGS "all"
219 #define DEF_TAB_TEXT (char *)NULL
220 #define DEF_TAB_UNDERLINE "-1"
221 #define DEF_TAB_VISUAL (char *)NULL
222 #define DEF_TAB_WIDTH "0"
223 #define DEF_TAB_WINDOW (char *)NULL
224
225 typedef struct TabsetStruct Tabset;
226
227 static void EmbeddedWidgetGeometryProc _ANSI_ARGS_((ClientData, Tk_Window));
228 static void EmbeddedWidgetCustodyProc _ANSI_ARGS_((ClientData, Tk_Window));
229
230 static Tk_GeomMgr tabMgrInfo =
231 {
232 "tabset", /* Name of geometry manager used by winfo */
233 EmbeddedWidgetGeometryProc, /* Procedure to for new geometry requests */
234 EmbeddedWidgetCustodyProc, /* Procedure when window is taken away */
235 };
236
237 extern Tk_CustomOption bltDashesOption;
238 extern Tk_CustomOption bltFillOption;
239 extern Tk_CustomOption bltDistanceOption;
240 extern Tk_CustomOption bltPositiveDistanceOption;
241 extern Tk_CustomOption bltPositiveCountOption;
242 extern Tk_CustomOption bltListOption;
243 extern Tk_CustomOption bltPadOption;
244 extern Tk_CustomOption bltShadowOption;
245 extern Tk_CustomOption bltStateOption;
246 extern Tk_CustomOption bltTileOption;
247 extern Tk_CustomOption bltUidOption;
248
249 static int StringToImage _ANSI_ARGS_((ClientData clientData,
250 Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
251 int offset));
252 static char *ImageToString _ANSI_ARGS_((ClientData clientData,
253 Tk_Window tkwin, char *widgRec, int offset,
254 Tcl_FreeProc **freeProcPtrPtr));
255
256 static int StringToWindow _ANSI_ARGS_((ClientData clientData,
257 Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
258 int offset));
259 static char *WindowToString _ANSI_ARGS_((ClientData clientData,
260 Tk_Window tkwin, char *widgRec, int offset,
261 Tcl_FreeProc **freeProcPtrPtr));
262
263 static int StringToSide _ANSI_ARGS_((ClientData clientData,
264 Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
265 int offset));
266 static char *SideToString _ANSI_ARGS_((ClientData clientData,
267 Tk_Window tkwin, char *widgRec, int offset,
268 Tcl_FreeProc **freeProcPtrPtr));
269
270 static int StringToSlant _ANSI_ARGS_((ClientData clientData,
271 Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
272 int offset));
273 static char *SlantToString _ANSI_ARGS_((ClientData clientData,
274 Tk_Window tkwin, char *widgRec, int offset,
275 Tcl_FreeProc **freeProcPtrPtr));
276
277 /*
278 * Contains a pointer to the widget that's currently being configured.
279 * This is used in the custom configuration parse routine for images.
280 */
281 static Tabset *tabSet;
282
283 static Tk_CustomOption imageOption =
284 {
285 StringToImage, ImageToString, (ClientData)&tabSet,
286 };
287
288 static Tk_CustomOption sideOption =
289 {
290 StringToSide, SideToString, (ClientData)0,
291 };
292
293 static Tk_CustomOption windowOption =
294 {
295 StringToWindow, WindowToString, (ClientData)0,
296 };
297
298 static Tk_CustomOption slantOption =
299 {
300 StringToSlant, SlantToString, (ClientData)0,
301 };
302
303 /*
304 * TabImage --
305 *
306 * When multiple instances of an image are displayed in the
307 * same widget, this can be inefficient in terms of both memory
308 * and time. We only need one instance of each image, regardless
309 * of number of times we use it. And searching/deleting instances
310 * can be very slow as the list gets large.
311 *
312 * The workaround, employed below, is to maintain a hash table of
313 * images that maintains a reference count for each image.
314 */
315
316 typedef struct TabImageStruct {
317 int refCount; /* Reference counter for this image. */
318 Tk_Image tkImage; /* The Tk image being cached. */
319 int width, height; /* Dimensions of the cached image. */
320 Blt_HashEntry *hashPtr; /* Hash table pointer to the image. */
321
322 } *TabImage;
323
324 #define ImageHeight(image) ((image)->height)
325 #define ImageWidth(image) ((image)->width)
326 #define ImageBits(image) ((image)->tkImage)
327
328 #define TAB_VISIBLE (1<<0)
329 #define TAB_REDRAW (1<<2)
330
331 typedef struct {
332 char *name; /* Identifier for tab entry */
333 int state; /* State of the tab: Disabled, active, or
334 * normal. */
335 unsigned int flags;
336
337 int tier; /* Index of tier [1..numTiers] containing
338 * this tab. */
339
340 int worldX, worldY; /* Position of the tab in world coordinates. */
341 int worldWidth, worldHeight;/* Dimensions of the tab, corrected for
342 * orientation (-side). It includes the
343 * border, padding, label, etc. */
344 int screenX, screenY;
345 short int screenWidth, screenHeight; /* */
346
347 Tabset *setPtr; /* Tabset that includes this
348 * tab. Needed for callbacks can pass
349 * only a tab pointer. */
350 Blt_Uid tags;
351
352 /*
353 * Tab label:
354 */
355 Blt_Uid text; /* String displayed as the tab's label. */
356 TabImage image; /* Image displayed as the label. */
357 TabImage image2; /* Image displayed as the second icon. */
358
359 short int textWidth, textHeight;
360 short int labelWidth, labelHeight;
361 Blt_Pad iPadX, iPadY; /* Internal padding around the text */
362
363 Tk_Font font;
364
365 /*
366 * Normal:
367 */
368 XColor *textColor; /* Text color */
369 Tk_3DBorder border; /* Background color and border for tab.*/
370
371 /*
372 * Selected: Tab is currently selected.
373 */
374 XColor *selColor; /* Selected text color */
375 Tk_3DBorder selBorder; /* 3D border of selected folder. */
376
377 /*
378 * Active: Mouse passes over the tab.
379 */
380 Tk_3DBorder activeBorder; /* Active background color. */
381 XColor *activeFgColor; /* Active text color */
382
383 Shadow shadow;
384 Pixmap stipple; /* Stipple for outline of embedded window
385 * when torn off. */
386 /*
387 * Embedded widget information:
388 */
389 Tk_Window tkwin; /* Widget to be mapped when the tab is
390 * selected. If NULL, don't make
391 * space for the page. */
392
393 int reqWidth, reqHeight; /* If non-zero, overrides the
394 * requested dimensions of the
395 * embedded widget. */
396
397 Tk_Window container; /* The window containing the embedded
398 * widget. Does not necessarily have
399 * to be the parent. */
400
401 Tk_Anchor anchor; /* Anchor: indicates how the embedded
402 * widget is positioned within the
403 * extra space on the page. */
404
405 Blt_Pad padX, padY; /* Padding around embedded widget */
406
407 int fill; /* Indicates how the window should
408 * fill the page. */
409
410 /*
411 * Auxillary information:
412 */
413 Blt_Uid command; /* Command (malloc-ed) invoked when the tab
414 * is selected */
415 Blt_Uid data; /* This value isn't used in C code.
416 * It may be used by clients in Tcl bindings
417 * to associate extra data (other than the
418 * label or name) with the tab. */
419
420 Blt_ChainLink *linkPtr; /* Pointer to where the tab resides in the
421 * list of tabs. */
422 Blt_Uid perfCommand; /* Command (malloc-ed) invoked when the tab
423 * is selected */
424 GC textGC;
425 GC backGC;
426 Blt_Tile tile;
427 short iX, iY, iW, iH; /* Needed by "nearest" to determine if over icon/label*/
428 short tX, tY, tW, tH;
429 short i2X, i2Y, i2W, i2H;
430 int underline; /* Char to underline in tab. */
431 int hidden; /* Tab is hidden. */
432 char *textDisp; /* Actual displayed text, after truncation. */
433 char *tornWin; /* Name of window torn off. */
434 } Tab;
435
436 static Tk_ConfigSpec tabConfigSpecs[] =
437 {
438 {TK_CONFIG_BORDER, "-activebackground", "activeBackground",
439 "ActiveBackground", DEF_TAB_ACTIVE_BG,
440 Tk_Offset(Tab, activeBorder), TK_CONFIG_NULL_OK},
441 {TK_CONFIG_COLOR, "-activeforeground", "activeForeground",
442 "ActiveForeground", DEF_TAB_ACTIVE_FG,
443 Tk_Offset(Tab, activeFgColor), TK_CONFIG_NULL_OK},
444 {TK_CONFIG_ANCHOR, "-anchor", "tabAnchor", "TabAnchor",
445 DEF_TAB_ANCHOR, Tk_Offset(Tab, anchor), TK_CONFIG_DONT_SET_DEFAULT},
446 {TK_CONFIG_BORDER, "-background", "tabBackground", "TabBackground",
447 (char *)NULL, Tk_Offset(Tab, border), TK_CONFIG_NULL_OK},
448 {TK_CONFIG_SYNONYM, "-bg", "tabBackground", (char *)NULL, (char *)NULL, 0, 0},
449 {TK_CONFIG_CUSTOM, "-bindtags", "bindTags", "BindTags",
450 DEF_TAB_BIND_TAGS, Tk_Offset(Tab, tags),
451 TK_CONFIG_NULL_OK, &bltUidOption},
452 {TK_CONFIG_CUSTOM, "-command", "command", "Command",
453 DEF_TAB_COMMAND, Tk_Offset(Tab, command),
454 TK_CONFIG_NULL_OK, &bltUidOption},
455 {TK_CONFIG_CUSTOM, "-data", "data", "data",
456 DEF_TAB_DATA, Tk_Offset(Tab, data),
457 TK_CONFIG_NULL_OK, &bltUidOption},
458 {TK_CONFIG_SYNONYM, "-fg", "tabForeground", (char *)NULL, (char *)NULL, 0, 0},
459 {TK_CONFIG_CUSTOM, "-fill", "fill", "Fill",
460 DEF_TAB_FILL, Tk_Offset(Tab, fill),
461 TK_CONFIG_DONT_SET_DEFAULT, &bltFillOption},
462 {TK_CONFIG_COLOR, "-foreground", "tabForeground", "TabForeground",
463 (char *)NULL, Tk_Offset(Tab, textColor), TK_CONFIG_NULL_OK},
464 {TK_CONFIG_FONT, "-font", "tabFont", "TabFont",
465 (char *)NULL, Tk_Offset(Tab, font), TK_CONFIG_NULL_OK},
466 {TK_CONFIG_INT, "-hidden", "hidden", "Hidden",
467 DEF_TAB_HIDDEN, Tk_Offset(Tab, hidden), 0, 0},
468 {TK_CONFIG_CUSTOM, "-image", "image", "image",
469 DEF_TAB_IMAGE, Tk_Offset(Tab, image),
470 TK_CONFIG_NULL_OK, &imageOption},
471 {TK_CONFIG_CUSTOM, "-leftimage", "leftImage", "LeftImage",
472 DEF_TAB_IMAGE, Tk_Offset(Tab, image2),
473 TK_CONFIG_NULL_OK, &imageOption},
474 {TK_CONFIG_CUSTOM, "-ipadx", "iPadX", "PadX",
475 DEF_TAB_IPAD, Tk_Offset(Tab, iPadX),
476 TK_CONFIG_DONT_SET_DEFAULT, &bltPadOption},
477 {TK_CONFIG_CUSTOM, "-ipady", "iPadY", "PadY",
478 DEF_TAB_IPAD, Tk_Offset(Tab, iPadY),
479 TK_CONFIG_DONT_SET_DEFAULT, &bltPadOption},
480 {TK_CONFIG_CUSTOM, "-padx", "padX", "PadX",
481 DEF_TAB_PAD, Tk_Offset(Tab, padX), 0, &bltPadOption},
482 {TK_CONFIG_CUSTOM, "-pady", "padY", "PadY",
483 DEF_TAB_PAD, Tk_Offset(Tab, padY), 0, &bltPadOption},
484 {TK_CONFIG_CUSTOM, "-perforationcommand", "perforationcommand",
485 "PerforationCommand",
486 DEF_TAB_PERF_COMMAND, Tk_Offset(Tab, perfCommand),
487 TK_CONFIG_NULL_OK, &bltUidOption},
488 {TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Background",
489 DEF_TAB_SELECT_BG, Tk_Offset(Tab, selBorder), TK_CONFIG_NULL_OK},
490 {TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Foreground",
491 DEF_TAB_SELECT_FG, Tk_Offset(Tab, selColor), TK_CONFIG_NULL_OK},
492 {TK_CONFIG_CUSTOM, "-shadow", "shadow", "Shadow",
493 DEF_TAB_SHADOW, Tk_Offset(Tab, shadow),
494 TK_CONFIG_NULL_OK, &bltShadowOption},
495 {TK_CONFIG_CUSTOM, "-state", "state", "State",
496 DEF_TAB_STATE, Tk_Offset(Tab, state),
497 TK_CONFIG_DONT_SET_DEFAULT, &bltStateOption},
498 {TK_CONFIG_BITMAP, "-stipple", "stipple", "Stipple",
499 NULL, Tk_Offset(Tab, stipple), TK_CONFIG_NULL_OK},
500 {TK_CONFIG_CUSTOM, "-text", "Text", "Text",
501 DEF_TAB_TEXT, Tk_Offset(Tab, text),
502 TK_CONFIG_NULL_OK, &bltUidOption},
503 {TK_CONFIG_CUSTOM, "-tile", "tabTile", "TabTile",
504 (char *)NULL, Tk_Offset(Tab, tile), TK_CONFIG_NULL_OK,
505 &bltTileOption},
506 {TK_CONFIG_STRING, "-tornwindow", "tornWindow",
507 "String", (char *)NULL,
508 Tk_Offset(Tab, tornWin), TK_CONFIG_NULL_OK},
509 {TK_CONFIG_INT, "-underline", "underline", "Underline",
510 DEF_TAB_UNDERLINE, Tk_Offset(Tab, underline), 0, 0},
511 {TK_CONFIG_CUSTOM, "-window", "window", "Window",
512 DEF_TAB_WINDOW, Tk_Offset(Tab, tkwin),
513 TK_CONFIG_NULL_OK, &windowOption},
514 {TK_CONFIG_CUSTOM, "-windowheight", "windowHeight", "WindowHeight",
515 DEF_TAB_HEIGHT, Tk_Offset(Tab, reqHeight),
516 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
517 {TK_CONFIG_CUSTOM, "-windowwidth", "windowWidth", "WindowWidth",
518 DEF_TAB_WIDTH, Tk_Offset(Tab, reqWidth),
519 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
520 {TK_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL,
521 (char *)NULL, 0, 0}
522 };
523
524 /*
525 * TabAttributes --
526 */
527 typedef struct {
528 Tk_Window tkwin; /* Default window to map pages. */
529
530 int reqWidth, reqHeight; /* Requested tab size. */
531 int constWidth;
532 int fillWidth;
533 int borderWidth; /* Width of 3D border around the tab's
534 * label. */
535 int pad; /* Extra padding of a tab entry */
536
537 XColor *activeFgColor; /* Active foreground. */
538 Tk_3DBorder activeBorder; /* Active background. */
539 XColor *selColor; /* Selected foreground. */
540 Tk_Font font;
541 XColor *textColor;
542
543 Tk_3DBorder border; /* Normal background. */
544 Tk_3DBorder selBorder; /* Selected background. */
545 Tk_3DBorder labelBorder; /* Normal label background. */
546
547 Blt_Dashes dashes;
548 GC normalGC, activeGC;
549 int relief;
550 char *command;
551 char *perfCommand; /* Command (malloc-ed) invoked when the tab
552 * is selected */
553 double rotate;
554 int textSide;
555 TabImage image; /* Image displayed as the label. */
556 TabImage image2; /* Image displayed as the second icon. */
557
558 } TabAttributes;
559
560 struct TabsetStruct {
561 Tk_Window tkwin; /* Window that embodies the widget.
562 * NULL means that the window has been
563 * destroyed but the data structures
564 * haven't yet been cleaned up.*/
565
566 Display *display; /* Display containing widget; needed,
567 * among other things, to release
568 * resources after tkwin has already
569 * gone away. */
570
571 Tcl_Interp *interp; /* Interpreter associated with widget. */
572
573 Tcl_Command cmdToken; /* Token for widget's command. */
574
575 unsigned int flags; /* For bitfield definitions, see below */
576
577 int inset; /* Total width of all borders, including
578 * traversal highlight and 3-D border.
579 * Indicates how much interior stuff must
580 * be offset from outside edges to leave
581 * room for borders. */
582
583 int inset2; /* Total width of 3-D folder border + corner,
584 * Indicates how much interior stuff must
585 * be offset from outside edges of folder.*/
586
587 int yPad; /* Extra offset for selected tab. Only
588 * for single tiers. */
589
590 int pageTop; /* Offset from top of tabset to the
591 * start of the page. */
592
593 Tk_Cursor cursor; /* X Cursor */
594
595 Tk_3DBorder border; /* 3D border surrounding the window. */
596 int borderWidth; /* Width of 3D border. */
597 int relief; /* 3D border relief. */
598
599 XColor *shadowColor; /* Shadow color around folder. */
600 /*
601 * Focus highlight ring
602 */
603 int highlightWidth; /* Width in pixels of highlight to draw
604 * around widget when it has the focus.
605 * <= 0 means don't draw a highlight. */
606 XColor *highlightBgColor; /* Color for drawing traversal highlight
607 * area when highlight is off. */
608 XColor *highlightColor; /* Color for drawing traversal highlight. */
609
610 GC highlightGC; /* GC for focus highlight. */
611
612 char *takeFocus; /* Says whether to select this widget during
613 * tab traveral operations. This value isn't
614 * used in C code, but for the widget's Tcl
615 * bindings. */
616
617
618 int side; /* How tabset is oriented: either SIDE_LEFT,
619 * SIDE_RIGHT, SIDE_TOP, or SIDE_BOTTOM. */
620
621 int slant;
622 int overlap;
623 int gap;
624 int tabWidth, tabHeight;
625 int xSelectPad, ySelectPad; /* Padding around label of the selected tab. */
626 int outerPad; /* Padding around the exterior of the tabset
627 * and folder. */
628
629 TabAttributes defTabStyle; /* Global attribute information specific to
630 * tabs. */
631 Blt_Tile tile;
632 Blt_Tile bgtile;
633 Blt_Tile seltile;
634
635 int reqWidth, reqHeight; /* Requested dimensions of the tabset
636 * window. */
637 int pageWidth, pageHeight; /* Dimensions of a page in the folder. */
638 int reqPageWidth, reqPageHeight; /* Requested dimensions of a page. */
639
640 int lastX, lastY;
641 /*
642 * Scrolling information:
643 */
644 int worldWidth;
645 int scrollOffset; /* Offset of viewport in world coordinates. */
646 char *scrollCmdPrefix; /* Command strings to control scrollbar.*/
647
648 int scrollUnits; /* Smallest unit of scrolling for tabs. */
649
650 /*
651 * Scanning information:
652 */
653 int scanAnchor; /* Scan anchor in screen coordinates. */
654 int scanOffset; /* Offset of the start of the scan in world
655 * coordinates.*/
656
657
658 int corner; /* Number of pixels to offset next point
659 * when drawing corners of the folder. */
660 int reqTiers; /* Requested number of tiers. Zero means to
661 * dynamically scroll if there are too many
662 * tabs to be display on a single tier. */
663 int nTiers; /* Actual number of tiers. */
664
665 Blt_HashTable imageTable;
666
667 Tab *selectPtr; /* The currently selected tab.
668 * (i.e. its page is displayed). */
669
670 Tab *activePtr; /* Tab last located under the pointer.
671 * It is displayed with its active
672 * foreground/background colors. */
673
674 Tab *focusPtr; /* Tab currently receiving focus. */
675
676 Tab *startPtr; /* The first tab on the first tier. */
677
678 Blt_Chain *chainPtr; /* List of tab entries. Used to
679 * arrange placement of tabs. */
680
681 Blt_HashTable tabTable; /* Hash table of tab entries. Used for
682 * lookups of tabs by name. */
683
684 int nVisible; /* Number of tabs that are currently visible
685 * in the view port. */
686
687 Blt_BindTable bindTable; /* Tab binding information */
688 Blt_HashTable tagTable; /* Table of bind tags. */
689
690 int tearoff;
691 int transient; /* Make window transient on tearoff. */
692 short pX, pY, pW, pH;
693 Tk_Anchor anchor;
694 int gapLeft;
695 TabImage startImage; /* Image displayed at start . */
696 TabImage endImage; /* Image displayed end of tabs. */
697 short siX, siY, eiX, eiY;
698 int autoAccel;
699 int hMin; /* Start/end image min size. */
700 Pixmap stipple; /* Stipple for outline of embedded window */
701 int truncLen; /* Truncate displayed text at this length. */
702 char *ellipsis; /* Append to truncated text. */
703 Shadow shadow;
704 };
705
706 static Tk_ConfigSpec configSpecs[] =
707 {
708 {TK_CONFIG_BORDER, "-activebackground", "activeBackground",
709 "activeBackground",
710 DEF_TABSET_ACTIVE_BACKGROUND, Tk_Offset(Tabset, defTabStyle.activeBorder),
711 TK_CONFIG_COLOR_ONLY|TK_CONFIG_NULL_OK},
712 {TK_CONFIG_BORDER, "-activebackground", "activeBackground",
713 "activeBackground",
714 DEF_TABSET_ACTIVE_BG_MONO, Tk_Offset(Tabset, defTabStyle.activeBorder),
715 TK_CONFIG_MONO_ONLY|TK_CONFIG_NULL_OK},
716 {TK_CONFIG_COLOR, "-activeforeground", "activeForeground",
717 "activeForeground", DEF_TABSET_ACTIVE_FOREGROUND,
718 Tk_Offset(Tabset, defTabStyle.activeFgColor), TK_CONFIG_COLOR_ONLY|TK_CONFIG_NULL_OK},
719 {TK_CONFIG_COLOR, "-activeforeground", "activeForeground",
720 "activeForeground", DEF_TABSET_ACTIVE_FG_MONO,
721 Tk_Offset(Tabset, defTabStyle.activeFgColor), TK_CONFIG_MONO_ONLY|TK_CONFIG_NULL_OK},
722 {TK_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor",
723 DEF_TABSET_ANCHOR, Tk_Offset(Tabset, anchor), 0},
724 {TK_CONFIG_BORDER, "-background", "background", "Background",
725 DEF_TABSET_BG_MONO, Tk_Offset(Tabset, border), TK_CONFIG_MONO_ONLY},
726 {TK_CONFIG_BORDER, "-background", "background", "Background",
727 DEF_TABSET_BACKGROUND, Tk_Offset(Tabset, border), TK_CONFIG_COLOR_ONLY},
728 {TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *)NULL, (char *)NULL, 0, 0},
729 {TK_CONFIG_SYNONYM, "-bg", "background", (char *)NULL, (char *)NULL, 0, 0},
730 {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
731 DEF_TABSET_CURSOR, Tk_Offset(Tabset, cursor), TK_CONFIG_NULL_OK},
732 {TK_CONFIG_CUSTOM, "-borderwidth", "borderWidth", "BorderWidth",
733 DEF_TABSET_BORDERWIDTH, Tk_Offset(Tabset, borderWidth),
734 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
735 {TK_CONFIG_CUSTOM, "-dashes", "dashes", "Dashes",
736 DEF_TABSET_DASHES, Tk_Offset(Tabset, defTabStyle.dashes),
737 TK_CONFIG_NULL_OK, &bltDashesOption},
738 {TK_CONFIG_STRING, "-ellipsis", "ellipsis", "Ellipise",
739 "...", Tk_Offset(Tabset, ellipsis), TK_CONFIG_NULL_OK},
740 {TK_CONFIG_CUSTOM, "-endimage", "endImage", "EndImage",
741 (char *)NULL, Tk_Offset(Tabset, endImage),
742 TK_CONFIG_NULL_OK, &imageOption},
743 {TK_CONFIG_SYNONYM, "-fg", "tabForeground", (char *)NULL,
744 (char *)NULL, 0, 0},
745 {TK_CONFIG_BOOLEAN, "-fillwidth", "fillWidth", "FillWidth",
746 DEF_TABSET_FILL_WIDTH, Tk_Offset(Tabset, defTabStyle.fillWidth),
747 0},
748 {TK_CONFIG_FONT, "-font", "font", "Font",
749 DEF_TABSET_FONT, Tk_Offset(Tabset, defTabStyle.font), 0},
750 {TK_CONFIG_SYNONYM, "-foreground", "tabForeground", (char *)NULL,
751 (char *)NULL, 0, 0},
752 {TK_CONFIG_PIXELS, "-gap", "gap", "Gap",
753 DEF_TABSET_GAP, Tk_Offset(Tabset, gap),
754 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
755 {TK_CONFIG_PIXELS, "-gapleft", "gapLeft", "GapLeft",
756 DEF_TABSET_GAP, Tk_Offset(Tabset, gapLeft),
757 0, &bltDistanceOption},
758 {TK_CONFIG_CUSTOM, "-height", "height", "Height",
759 DEF_TABSET_HEIGHT, Tk_Offset(Tabset, reqHeight),
760 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
761 {TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground",
762 "HighlightBackground",
763 DEF_TABSET_HIGHLIGHT_BACKGROUND, Tk_Offset(Tabset, highlightBgColor),
764 TK_CONFIG_COLOR_ONLY},
765 {TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground",
766 "HighlightBackground",
767 DEF_TABSET_HIGHLIGHT_BG_MONO, Tk_Offset(Tabset, highlightBgColor),
768 TK_CONFIG_MONO_ONLY},
769 {TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
770 DEF_TABSET_HIGHLIGHT_COLOR, Tk_Offset(Tabset, highlightColor), 0},
771 {TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",
772 "HighlightThickness",
773 DEF_TABSET_HIGHLIGHT_WIDTH, Tk_Offset(Tabset, highlightWidth),
774 TK_CONFIG_DONT_SET_DEFAULT},
775 {TK_CONFIG_CUSTOM, "-image", "image", "image",
776 DEF_TAB_IMAGE, Tk_Offset(Tabset, defTabStyle.image),
777 TK_CONFIG_NULL_OK, &imageOption},
778 {TK_CONFIG_BORDER, "-labelbackground", "labelBackground", "Background",
779 (char *)NULL, Tk_Offset(Tabset, defTabStyle.labelBorder),
780 TK_CONFIG_NULL_OK},
781 {TK_CONFIG_INT, "-labelmax", "labelMax", "LabelMax",
782 "0", Tk_Offset(Tabset, truncLen), 0, 0},
783 {TK_CONFIG_CUSTOM, "-leftimage", "leftImage", "LeftImage",
784 DEF_TAB_IMAGE, Tk_Offset(Tabset, defTabStyle.image2),
785 TK_CONFIG_NULL_OK, &imageOption},
786 {TK_CONFIG_CUSTOM, "-outerpad", "outerPad", "OuterPad",
787 DEF_TABSET_OUTER_PAD, Tk_Offset(Tabset, outerPad),
788 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
789 {TK_CONFIG_CUSTOM, "-pageheight", "pageHeight", "PageHeight",
790 DEF_TABSET_PAGE_HEIGHT, Tk_Offset(Tabset, reqPageHeight),
791 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
792 {TK_CONFIG_CUSTOM, "-pagewidth", "pageWidth", "PageWidth",
793 DEF_TABSET_PAGE_WIDTH, Tk_Offset(Tabset, reqPageWidth),
794 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
795 {TK_CONFIG_STRING, "-perforationcommand", "perforationcommand",
796 "PerforationCommand",
797 DEF_TAB_PERF_COMMAND, Tk_Offset(Tabset, defTabStyle.perfCommand),
798 TK_CONFIG_NULL_OK, &bltUidOption},
799 {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
800 DEF_TABSET_RELIEF, Tk_Offset(Tabset, relief), 0},
801 {TK_CONFIG_DOUBLE, "-rotate", "rotate", "Rotate",
802 DEF_TABSET_ROTATE, Tk_Offset(Tabset, defTabStyle.rotate),
803 TK_CONFIG_DONT_SET_DEFAULT},
804 {TK_CONFIG_BOOLEAN, "-samewidth", "sameWidth", "SameWidth",
805 DEF_TABSET_SAME_WIDTH, Tk_Offset(Tabset, defTabStyle.constWidth),
806 TK_CONFIG_DONT_SET_DEFAULT},
807 {TK_CONFIG_STRING, "-scrollcommand", "scrollCommand", "ScrollCommand",
808 (char *)NULL, Tk_Offset(Tabset, scrollCmdPrefix), TK_CONFIG_NULL_OK},
809 {TK_CONFIG_CUSTOM, "-scrollincrement", "scrollIncrement",
810 "ScrollIncrement",
811 DEF_TABSET_SCROLL_INCREMENT, Tk_Offset(Tabset, scrollUnits),
812 TK_CONFIG_DONT_SET_DEFAULT, &bltPositiveDistanceOption},
813 {TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground",
814 DEF_TABSET_SELECT_BG_MONO, Tk_Offset(Tabset, defTabStyle.selBorder),
815 TK_CONFIG_MONO_ONLY|TK_CONFIG_NULL_OK},
816 {TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground",
817 DEF_TABSET_SELECT_BACKGROUND, Tk_Offset(Tabset, defTabStyle.selBorder),
818 TK_CONFIG_COLOR_ONLY|TK_CONFIG_NULL_OK},
819 {TK_CONFIG_STRING, "-selectcommand", "selectCommand", "SelectCommand",
820 DEF_TABSET_SELECT_CMD, Tk_Offset(Tabset, defTabStyle.command),
821 TK_CONFIG_NULL_OK},
822 {TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background",
823 DEF_TABSET_SELECT_FG_MONO, Tk_Offset(Tabset, defTabStyle.selColor),
824 TK_CONFIG_MONO_ONLY|TK_CONFIG_NULL_OK},
825 {TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background",
826 DEF_TABSET_SELECT_FOREGROUND, Tk_Offset(Tabset, defTabStyle.selColor),
827 TK_CONFIG_COLOR_ONLY|TK_CONFIG_NULL_OK},
828 {TK_CONFIG_CUSTOM, "-selecttile", "selectTile", "SelectTile",
829 (char *)NULL, Tk_Offset(Tabset, seltile), TK_CONFIG_NULL_OK,
830 &bltTileOption},
831 {TK_CONFIG_CUSTOM, "-selectpad", "selectPad", "SelectPad",
832 DEF_TABSET_SELECT_PAD, Tk_Offset(Tabset, xSelectPad),
833 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
834 {TK_CONFIG_CUSTOM, "-shadow", "shadow", "Shadow",
835 DEF_TAB_SHADOW, Tk_Offset(Tabset, shadow),
836 TK_CONFIG_NULL_OK, &bltShadowOption},
837 {TK_CONFIG_COLOR, "-shadowcolor", "shadowColor", "ShadowColor",
838 DEF_TABSET_SHADOW_COLOR, Tk_Offset(Tabset, shadowColor), 0},
839 {TK_CONFIG_CUSTOM, "-side", "side", "side",
840 DEF_TABSET_SIDE, Tk_Offset(Tabset, side),
841 TK_CONFIG_DONT_SET_DEFAULT, &sideOption},
842 {TK_CONFIG_CUSTOM, "-slant", "slant", "Slant",
843 DEF_TABSET_SLANT, Tk_Offset(Tabset, slant),
844 TK_CONFIG_DONT_SET_DEFAULT, &slantOption},
845 {TK_CONFIG_CUSTOM, "-startimage", "startImage", "StartImage",
846 (char *)NULL, Tk_Offset(Tabset, startImage),
847 TK_CONFIG_NULL_OK, &imageOption},
848 {TK_CONFIG_BITMAP, "-stipple", "stipple", "Stipple",
849 DEF_TAB_STIPPLE, Tk_Offset(Tabset, stipple), TK_CONFIG_NULL_OK},
850 {TK_CONFIG_BORDER, "-tabbackground", "tabBackground", "Background",
851 DEF_TABSET_TAB_BG_MONO, Tk_Offset(Tabset, defTabStyle.border),
852 TK_CONFIG_MONO_ONLY},
853 {TK_CONFIG_BORDER, "-tabbackground", "tabBackground", "Background",
854 DEF_TABSET_TAB_BACKGROUND, Tk_Offset(Tabset, defTabStyle.border),
855 TK_CONFIG_COLOR_ONLY},
856 {TK_CONFIG_CUSTOM, "-tabborderwidth", "tabBorderWidth", "BorderWidth",
857 DEF_TABSET_BORDERWIDTH, Tk_Offset(Tabset, defTabStyle.borderWidth),
858 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
859 {TK_CONFIG_COLOR, "-tabforeground", "tabForeground", "Foreground",
860 DEF_TABSET_TEXT_COLOR, Tk_Offset(Tabset, defTabStyle.textColor),
861 TK_CONFIG_COLOR_ONLY},
862 {TK_CONFIG_COLOR, "-tabforeground", "tabForeground", "Foreground",
863 DEF_TABSET_TEXT_MONO, Tk_Offset(Tabset, defTabStyle.textColor),
864 TK_CONFIG_MONO_ONLY},
865 {TK_CONFIG_RELIEF, "-tabrelief", "tabRelief", "TabRelief",
866 DEF_TABSET_TAB_RELIEF, Tk_Offset(Tabset, defTabStyle.relief), 0},
867 {TK_CONFIG_CUSTOM, "-tabtile", "tabTile", "Tile",
868 (char *)NULL, Tk_Offset(Tabset, tile), TK_CONFIG_NULL_OK,
869 &bltTileOption},
870 {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",
871 DEF_TABSET_TAKE_FOCUS, Tk_Offset(Tabset, takeFocus), TK_CONFIG_NULL_OK},
872 {TK_CONFIG_BOOLEAN, "-tearoff", "tearoff", "Tearoff",
873 DEF_TABSET_TEAROFF, Tk_Offset(Tabset, tearoff),
874 TK_CONFIG_DONT_SET_DEFAULT},
875 {TK_CONFIG_BOOLEAN, "-transient", "transient", "Transient",
876 DEF_TABSET_TRANSIENT, Tk_Offset(Tabset, transient),
877 TK_CONFIG_DONT_SET_DEFAULT},
878 {TK_CONFIG_CUSTOM, "-textside", "textSide", "TextSide",
879 DEF_TABSET_TEXT_SIDE, Tk_Offset(Tabset, defTabStyle.textSide),
880 TK_CONFIG_DONT_SET_DEFAULT, &sideOption},
881 {TK_CONFIG_CUSTOM, "-tiers", "tiers", "Tiers",
882 DEF_TABSET_TIERS, Tk_Offset(Tabset, reqTiers),
883 0, &bltPositiveCountOption},
884 {TK_CONFIG_CUSTOM, "-tile", "tile", "TabTile",
885 (char *)NULL, Tk_Offset(Tabset, bgtile), TK_CONFIG_NULL_OK,
886 &bltTileOption},
887 {TK_CONFIG_CUSTOM, "-width", "width", "Width",
888 DEF_TABSET_WIDTH, Tk_Offset(Tabset, reqWidth),
889 TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
890 {TK_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL,
891 (char *)NULL, 0, 0}
892 };
893
894 /* Forward Declarations */
895 static void DestroyTabset _ANSI_ARGS_((DestroyData dataPtr));
896 static void DestroyTearoff _ANSI_ARGS_((DestroyData dataPtr));
897 static void EmbeddedWidgetEventProc _ANSI_ARGS_((ClientData clientdata,
898 XEvent *eventPtr));
899 static void TearoffEventProc _ANSI_ARGS_((ClientData clientdata,
900 XEvent *eventPtr));
901 static void TabsetEventProc _ANSI_ARGS_((ClientData clientdata,
902 XEvent *eventPtr));
903 static void DrawLabel _ANSI_ARGS_((Tabset *setPtr, Tab *tabPtr,
904 Drawable drawable));
905 static void DrawFolder _ANSI_ARGS_((Tabset *setPtr, Tab *tabPtr,
906 Drawable drawable));
907 static void DisplayTabset _ANSI_ARGS_((ClientData clientData));
908 static void DisplayTearoff _ANSI_ARGS_((ClientData clientData));
909 static void TabsetInstDeletedCmd _ANSI_ARGS_((ClientData clientdata));
910 static int TabsetInstCmd _ANSI_ARGS_((ClientData clientdata,
911 Tcl_Interp *interp, int argc, char **argv));
912 static void GetWindowRectangle _ANSI_ARGS_((Tab *tabPtr, Tk_Window parent,
913 int tearOff, XRectangle *rectPtr));
914 static void ArrangeWindow _ANSI_ARGS_((Tk_Window tkwin, XRectangle *rectPtr,
915 int force));
916 static void EventuallyRedraw _ANSI_ARGS_((Tabset *setPtr));
917 static void EventuallyRedrawTearoff _ANSI_ARGS_((Tab *tabPtr));
918 static void ComputeLayout _ANSI_ARGS_((Tabset *setPtr));
919 static void DrawOuterBorders _ANSI_ARGS_((Tabset *setPtr, Drawable drawable));
920
921 static Tk_ImageChangedProc ImageChangedProc;
922 static Blt_TileChangedProc TileChangedProc;
923 static Blt_BindTagProc GetTags;
924 static Blt_BindPickProc PickTab;
925 /* static Tcl_IdleProc AdoptWindow; */
926 static Tcl_CmdProc TabsetCmd;
927
928 static void widgetWorldChanged(ClientData clientData);
929
930 static Tk_ClassProcs tabsetClass = {
931 sizeof(Tk_ClassProcs), /* size */
932 widgetWorldChanged, /* worldChangedProc */
933 };
934
935 static ClientData
936 MakeTag(
937 Tabset *setPtr,
938 char *tagName)
939 {
940 Blt_HashEntry *hPtr;
941 int isNew;
942
943 hPtr = Blt_CreateHashEntry(&(setPtr->tagTable), tagName, &isNew);
944 assert(hPtr);
945 return Blt_GetHashKey(&(setPtr->tagTable), hPtr);
946 }
947
948 /*
949 *----------------------------------------------------------------------
950 *
951 * WorldToScreen --
952 *
953 * Converts world coordinates to screen coordinates. Note that
954 * the world view is always tabs up.
955 *
956 * Results:
957 * The screen coordinates are returned via *xScreenPtr and *yScreenPtr.
958 *
959 *----------------------------------------------------------------------
960 */
961 static void
962 WorldToScreen(
963 Tabset *setPtr,
964 int x, int y,
965 int *xScreenPtr, int *yScreenPtr)
966 {
967 int sx, sy;
968
969 sx = sy = 0; /* Suppress compiler warning. */
970
971 /* Translate world X-Y to screen coordinates */
972 /*
973 * Note that the world X-coordinate is translated by the selected label's
974 * X padding. This is done only to keep the scroll range is between
975 * 0.0 and 1.0, rather adding/subtracting the pad in various locations.
976 * It may be changed back in the future.
977 */
978 x += (setPtr->inset + setPtr->xSelectPad - setPtr->scrollOffset);
979 y += setPtr->inset + setPtr->yPad;
980
981 switch (setPtr->side) {
982 case SIDE_TOP:
983 sx = x, sy = y; /* Do nothing */
984 break;
985 case SIDE_RIGHT:
986 sx = Tk_Width(setPtr->tkwin) - y;
987 sy = x;
988 break;
989 case SIDE_LEFT:
990 sx = y, sy = x; /* Flip coordinates */
991 break;
992 case SIDE_BOTTOM:
993 sx = x;
994 sy = Tk_Height(setPtr->tkwin) - y;
995 break;
996 }
997 *xScreenPtr = sx;
998 *yScreenPtr = sy;
999 }
1000
1001 /*
1002 *----------------------------------------------------------------------
1003 *
1004 * EventuallyRedraw --
1005 *
1006 * Queues a request to redraw the widget at the next idle point.
1007 *
1008 * Results:
1009 * None.
1010 *
1011 * Side effects:
1012 * Information gets redisplayed. Right now we don't do selective
1013 * redisplays: the whole window will be redrawn.
1014 *
1015 *----------------------------------------------------------------------
1016 */
1017 static void
1018 EventuallyRedraw(Tabset *setPtr)
1019 {
1020 if ((setPtr->tkwin != NULL) && !(setPtr->flags & TABSET_REDRAW)) {
1021 setPtr->flags |= TABSET_REDRAW;
1022 Tcl_DoWhenIdle(DisplayTabset, setPtr);
1023 }
1024 }
1025
1026 /*
1027 *----------------------------------------------------------------------
1028 *
1029 * EventuallyRedrawTearoff --
1030 *
1031 * Queues a request to redraw the tearoff at the next idle point.
1032 *
1033 * Results:
1034 * None.
1035 *
1036 * Side effects:
1037 * Information gets redisplayed. Right now we don't do selective
1038 * redisplays: the whole window will be redrawn.
1039 *
1040 *----------------------------------------------------------------------
1041 */
1042 static void
1043 EventuallyRedrawTearoff(tabPtr)
1044 Tab *tabPtr;
1045 {
1046 if ((tabPtr->tkwin != NULL) && !(tabPtr->flags & TAB_REDRAW)) {
1047 tabPtr->flags |= TAB_REDRAW;
1048 Tcl_DoWhenIdle(DisplayTearoff, tabPtr);
1049 }
1050 }
1051
1052 /*
1053 *----------------------------------------------------------------------
1054 *
1055 * ImageChangedProc
1056 *
1057 * This routine is called whenever an image displayed in a tab
1058 * changes. In this case, we assume that everything will change
1059 * and queue a request to re-layout and redraw the entire tabset.
1060 *
1061 * Results:
1062 * None.
1063 *
1064 *----------------------------------------------------------------------
1065 */
1066 /* ARGSUSED */
1067 static void
1068 ImageChangedProc(
1069 ClientData clientData,
1070 int x, int y, int width, int height, /* Not used. */
1071 int imageWidth, int imageHeight)/* Not used. */
1072 {
1073 Tabset *setPtr = clientData;
1074
1075 setPtr->flags |= (TABSET_LAYOUT | TABSET_SCROLL);
1076 EventuallyRedraw(setPtr);
1077 }
1078
1079 /*
1080 *----------------------------------------------------------------------
1081 *
1082 * GetImage --
1083 *
1084 * This is a wrapper procedure for Tk_GetImage. The problem is
1085 * that if the same image is used repeatedly in the same widget,
1086 * the separate instances are saved in a linked list. This makes
1087 * it especially slow to destroy the widget. As a workaround,
1088 * this routine hashes the image and maintains a reference count
1089 * for it.
1090 *
1091 * Results:
1092 * Returns a pointer to the new image.
1093 *
1094 *----------------------------------------------------------------------
1095 */
1096 static TabImage
1097 GetImage(
1098 Tabset *setPtr,
1099 Tcl_Interp *interp,
1100 Tk_Window tkwin,
1101 char *name)
1102 {
1103 struct TabImageStruct *imagePtr;
1104 int isNew;
1105 Blt_HashEntry *hPtr;
1106
1107 hPtr = Blt_CreateHashEntry(&(setPtr->imageTable), (char *)name, &isNew);
1108 if (isNew) {
1109 Tk_Image tkImage;
1110 int width, height;
1111
1112 tkImage = Tk_GetImage(interp, tkwin, name, ImageChangedProc, setPtr);
1113 if (tkImage == NULL) {
1114 Blt_DeleteHashEntry(&(setPtr->imageTable), hPtr);
1115 return NULL;
1116 }
1117 Tk_SizeOfImage(tkImage, &width, &height);
1118 imagePtr = Blt_Malloc(sizeof(struct TabImageStruct));
1119 imagePtr->tkImage = tkImage;
1120 imagePtr->hashPtr = hPtr;
1121 imagePtr->refCount = 1;
1122 imagePtr->width = width;
1123 imagePtr->height = height;
1124 Blt_SetHashValue(hPtr, imagePtr);
1125 } else {
1126 imagePtr = Blt_GetHashValue(hPtr);
1127 imagePtr->refCount++;
1128 }
1129 return imagePtr;
1130 }
1131
1132 /*
1133 *----------------------------------------------------------------------
1134 *
1135 * FreeImage --
1136 *
1137 * Releases the image if it's not being used anymore by this
1138 * widget. Note there may be several uses of the same image
1139 * by many tabs.
1140 *
1141 * Results:
1142 * None.
1143 *
1144 * Side Effects:
1145 * The reference count is decremented and the image is freed
1146 * is it's not being used anymore.
1147 *
1148 *----------------------------------------------------------------------
1149 */
1150 static void
1151 FreeImage(
1152 Tabset *setPtr,
1153 struct TabImageStruct *imagePtr)
1154 {
1155 imagePtr->refCount--;
1156 if (imagePtr->refCount == 0) {
1157 Blt_DeleteHashEntry(&(setPtr->imageTable), imagePtr->hashPtr);
1158 Tk_FreeImage(imagePtr->tkImage);
1159 Blt_Free(imagePtr);
1160 }
1161 }
1162
1163 /*
1164 *----------------------------------------------------------------------
1165 *
1166 * StringToImage --
1167 *
1168 * Converts an image name into a Tk image token.
1169 *
1170 * Results:
1171 * If the string is successfully converted, TCL_OK is returned.
1172 * Otherwise, TCL_ERROR is returned and an error message is left
1173 * in interpreter's result field.
1174 *
1175 *----------------------------------------------------------------------
1176 */
1177 /*ARGSUSED*/
1178 static int
1179 StringToImage(clientData, interp, tkwin, string, widgRec, offset)
1180 ClientData clientData; /* Contains a pointer to the tabset containing
1181 * this image. */
1182 Tcl_Interp *interp; /* Interpreter to send results back to */
1183 Tk_Window tkwin; /* Window associated with the tabset. */
1184 char *string; /* String representation */
1185 char *widgRec; /* Widget record */
1186 int offset; /* Offset to field in structure */
1187 {
1188 Tabset *setPtr = *(Tabset **)clientData;
1189 TabImage *imagePtr = (TabImage *) (widgRec + offset);
1190 TabImage image;
1191
1192 image = NULL;
1193 if ((string != NULL) && (*string != '\0')) {
1194 image = GetImage(setPtr, interp, tkwin, string);
1195 if (image == NULL) {
1196 return TCL_ERROR;
1197 }
1198 }
1199 if (*imagePtr != NULL) {
1200 FreeImage(setPtr, *imagePtr);
1201 }
1202 *imagePtr = image;
1203 return TCL_OK;
1204 }
1205
1206 /*
1207 *----------------------------------------------------------------------
1208 *
1209 * ImageToString --
1210 *
1211 * Converts the Tk image back to its string representation (i.e.
1212 * its name).
1213 *
1214 * Results:
1215 * The name of the image is returned.
1216 *
1217 *----------------------------------------------------------------------
1218 */
1219 /*ARGSUSED*/
1220 static char *
1221 ImageToString(clientData, tkwin, widgRec, offset, freeProcPtr)
1222 ClientData clientData; /* Pointer to tabset containing image. */
1223 Tk_Window tkwin; /* Not used. */
1224 char *widgRec; /* Widget record */
1225 int offset; /* Offset of field in record */
1226 Tcl_FreeProc **freeProcPtr; /* Memory deallocation scheme to use */
1227 {
1228 Tabset *setPtr = *(Tabset **)clientData;
1229 TabImage *imagePtr = (TabImage *) (widgRec + offset);
1230
1231 if (*imagePtr == NULL) {
1232 return "";
1233 }
1234 return Blt_GetHashKey(&(setPtr->imageTable), (*imagePtr)->hashPtr);
1235 }
1236
1237 /*
1238 *----------------------------------------------------------------------
1239 *
1240 * StringToWindow --
1241 *
1242 * Converts a window name into Tk window.
1243 *
1244 * Results:
1245 * If the string is successfully converted, TCL_OK is returned.
1246 * Otherwise, TCL_ERROR is returned and an error message is left
1247 * in interpreter's result field.
1248 *
1249 *----------------------------------------------------------------------
1250 */
1251 /*ARGSUSED*/
1252 static int
1253 StringToWindow(clientData, interp, parent, string, widgRec, offset)
1254 ClientData clientData; /* Not used. */
1255 Tcl_Interp *interp; /* Interpreter to send results back to */
1256 Tk_Window parent; /* Parent window */
1257 char *string; /* String representation. */
1258 char *widgRec; /* Widget record */
1259 int offset; /* Offset to field in structure */
1260 {
1261 Tab *tabPtr = (Tab *)widgRec;
1262 Tk_Window *tkwinPtr = (Tk_Window *)(widgRec + offset);
1263 Tk_Window old, tkwin;
1264 Tabset *setPtr;
1265
1266 old = *tkwinPtr;
1267 tkwin = NULL;
1268 setPtr = tabPtr->setPtr;
1269 if ((string != NULL) && (*string != '\0')) {
1270 tkwin = Tk_NameToWindow(interp, string, parent);
1271 if (tkwin == NULL) {
1272 return TCL_ERROR;
1273 }
1274 if (tkwin == old) {
1275 return TCL_OK;
1276 }
1277 /*
1278 * Allow only widgets that are children of the tabset to be
1279 * embedded into the page. This way we can make assumptions about
1280 * the window based upon its parent; either it's the tabset window
1281 * or it has been torn off.
1282 */
1283 parent = Tk_Parent(tkwin);
1284 if (parent != setPtr->tkwin) {
1285 Tcl_AppendResult(interp, "can't manage \"", Tk_PathName(tkwin),
1286 "\" in tabset \"", Tk_PathName(setPtr->tkwin), "\"",
1287 (char *)NULL);
1288 return TCL_ERROR;
1289 }
1290 Tk_ManageGeometry(tkwin, &tabMgrInfo, tabPtr);
1291 Tk_CreateEventHandler(tkwin, StructureNotifyMask,
1292 EmbeddedWidgetEventProc, tabPtr);
1293
1294 /*
1295 * We need to make the window to exist immediately. If the
1296 * window is torn off (placed into another container window),
1297 * the timing between the container and the its new child
1298 * (this window) gets tricky. This should work for Tk 4.2.
1299 */
1300 Tk_MakeWindowExist(tkwin);
1301 }
1302 if (old != NULL) {
1303 if (tabPtr->container != NULL) {
1304 Tcl_EventuallyFree(tabPtr, DestroyTearoff);
1305 }
1306 Tk_DeleteEventHandler(old, StructureNotifyMask,
1307 EmbeddedWidgetEventProc, tabPtr);
1308 Tk_ManageGeometry(old, (Tk_GeomMgr *) NULL, tabPtr);
1309 Tk_UnmapWindow(old);
1310 }
1311 *tkwinPtr = tkwin;
1312 return TCL_OK;
1313 }
1314
1315 /*
1316 *----------------------------------------------------------------------
1317 *
1318 * WindowToString --
1319 *
1320 * Converts the Tk window back to its string representation (i.e.
1321 * its name).
1322 *
1323 * Results:
1324 * The name of the window is returned.
1325 *
1326 *----------------------------------------------------------------------
1327 */
1328 /*ARGSUSED*/
1329 static char *
1330 WindowToString(clientData, parent, widgRec, offset, freeProcPtr)
1331 ClientData clientData; /* Not used. */
1332 Tk_Window parent; /* Not used. */
1333 char *widgRec; /* Widget record */
1334 int offset; /* Offset of field in record */
1335 Tcl_FreeProc **freeProcPtr; /* Memory deallocation scheme to use */
1336 {
1337 Tk_Window tkwin = *(Tk_Window *)(widgRec + offset);
1338
1339 if (tkwin == NULL) {
1340 return "";
1341 }
1342 return Tk_PathName(tkwin);
1343 }
1344
1345 /*
1346 *----------------------------------------------------------------------
1347 *
1348 * StringToSide --
1349 *
1350 * Converts "left", "right", "top", "bottom", into a numeric token
1351 * designating the side of the tabset which to display tabs.
1352 *
1353 * Results:
1354 * If the string is successfully converted, TCL_OK is returned.
1355 * Otherwise, TCL_ERROR is returned and an error message is left
1356 * in interpreter's result field.
1357 *
1358 *----------------------------------------------------------------------
1359 */
1360 /*ARGSUSED */
1361 static int
1362 StringToSide(clientData, interp, parent, string, widgRec, offset)
1363 ClientData clientData; /* Not used. */
1364 Tcl_Interp *interp; /* Interpreter to send results back to */
1365 Tk_Window parent; /* Parent window */
1366 char *string; /* Option value string */
1367 char *widgRec; /* Widget record */
1368 int offset; /* offset to field in structure */
1369 {
1370 int *sidePtr = (int *)(widgRec + offset);
1371 char c;
1372 unsigned int length;
1373
1374 c = string[0];
1375 length = strlen(string);
1376 if ((c == 'l') && (strncmp(string, "left", length) == 0)) {
1377 *sidePtr = SIDE_LEFT;
1378 } else if ((c == 'r') && (strncmp(string, "right", length) == 0)) {
1379 *sidePtr = SIDE_RIGHT;
1380 } else if ((c == 't') && (strncmp(string, "top", length) == 0)) {
1381 *sidePtr = SIDE_TOP;
1382 } else if ((c == 'b') && (strncmp(string, "bottom", length) == 0)) {
1383 *sidePtr = SIDE_BOTTOM;
1384 } else {
1385 Tcl_AppendResult(interp, "bad side \"", string,
1386 "\": should be left, right, top, or bottom", (char *)NULL);
1387 return TCL_ERROR;
1388 }
1389 return TCL_OK;
1390 }
1391
1392 /*
1393 *----------------------------------------------------------------------
1394 *
1395 * SideToString --
1396 *
1397 * Converts the window into its string representation (its name).
1398 *
1399 * Results:
1400 * The name of the window is returned.
1401 *
1402 *----------------------------------------------------------------------
1403 */
1404 /*ARGSUSED*/
1405 static char *
1406 SideToString(clientData, parent, widgRec, offset, freeProcPtr)
1407 ClientData clientData; /* Not used. */
1408 Tk_Window parent; /* Not used. */
1409 char *widgRec; /* Widget record */
1410 int offset; /* offset of windows array in record */
1411 Tcl_FreeProc **freeProcPtr; /* Memory deallocation scheme to use */
1412 {
1413 int side = *(int *)(widgRec + offset);
1414
1415 switch (side) {
1416 case SIDE_LEFT:
1417 return "left";
1418 case SIDE_RIGHT:
1419 return "right";
1420 case SIDE_BOTTOM:
1421 return "bottom";
1422 case SIDE_TOP:
1423 return "top";
1424 }
1425 return "unknown side value";
1426 }
1427
1428 /*
1429 *----------------------------------------------------------------------
1430 *
1431 * StringToSlant --
1432 *
1433 * Converts the slant style string into its numeric representation.
1434 *
1435 * Valid style strings are:
1436 *
1437 * "none" Both sides are straight.
1438 * "left" Left side is slanted.
1439 * "right" Right side is slanted.
1440 * "both" Both sides are slanted.
1441 *
1442 *----------------------------------------------------------------------
1443 */
1444 /*ARGSUSED*/
1445 static int
1446 StringToSlant(clientData, interp, tkwin, string, widgRec, offset)
1447 ClientData clientData; /* Not used. */
1448 Tcl_Interp *interp; /* Interpreter to send results back to */
1449 Tk_Window tkwin; /* Not used. */
1450 char *string; /* String representation of attribute. */
1451 char *widgRec; /* Widget record */
1452 int offset; /* Offset of field in widget record. */
1453 {
1454 int *slantPtr = (int *)(widgRec + offset);
1455 unsigned int length;
1456 char c;
1457
1458 c = string[0];
1459 length = strlen(string);
1460 if ((c == 'n') && (strncmp(string, "none", length) == 0)) {
1461 *slantPtr = SLANT_NONE;
1462 } else if ((c == 'l') && (strncmp(string, "left", length) == 0)) {
1463 *slantPtr = SLANT_LEFT;
1464 } else if ((c == 'r') && (strncmp(string, "right", length) == 0)) {
1465 *slantPtr = SLANT_RIGHT;
1466 } else if ((c == 'b') && (strncmp(string, "both", length) == 0)) {
1467 *slantPtr = SLANT_BOTH;
1468 } else {
1469 Tcl_AppendResult(interp, "bad argument \"", string,
1470 "\": should be \"none\", \"left\", \"right\", or \"both\"",
1471 (char *)NULL);
1472 return TCL_ERROR;
1473 }
1474 return TCL_OK;
1475 }
1476
1477 /*
1478 *----------------------------------------------------------------------
1479 *
1480 * SlantToString --
1481 *
1482 * Returns the slant style string based upon the slant flags.
1483 *
1484 * Results:
1485 * The slant style string is returned.
1486 *
1487 *----------------------------------------------------------------------
1488 */
1489 /*ARGSUSED*/
1490 static char *
1491 SlantToString(clientData, tkwin, widgRec, offset, freeProcPtr)
1492 ClientData clientData; /* Not used. */
1493 Tk_Window tkwin; /* Not used. */
1494 char *widgRec; /* Widget structure record. */
1495 int offset; /* Offset of field in widget record. */
1496 Tcl_FreeProc **freeProcPtr; /* Not used. */
1497 {
1498 int slant = *(int *)(widgRec + offset);
1499
1500 switch (slant) {
1501 case SLANT_LEFT:
1502 return "left";
1503 case SLANT_RIGHT:
1504 return "right";
1505 case SLANT_NONE:
1506 return "none";
1507 case SLANT_BOTH:
1508 return "both";
1509 default:
1510 return "unknown value";
1511 }
1512 }
1513
1514
1515 static int
1516 WorldY(tabPtr)
1517 Tab *tabPtr;
1518 {
1519 int tier;
1520
1521 tier = tabPtr->setPtr->nTiers - tabPtr->tier;
1522 return tier * tabPtr->setPtr->tabHeight;
1523 }
1524
1525 static int
1526 TabIndex(setPtr, tabPtr)
1527 Tabset *setPtr;
1528 Tab *tabPtr;
1529 {
1530 Tab *t2Ptr;
1531 int count;
1532 Blt_ChainLink *linkPtr;
1533
1534 count = 0;
1535 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
1536 linkPtr = Blt_ChainNextLink(linkPtr)) {
1537 t2Ptr = Blt_ChainGetValue(linkPtr);
1538 if (t2Ptr == tabPtr) {
1539 return count;
1540 }
1541 count++;
1542 }
1543 return -1;
1544 }
1545
1546 /*
1547 * ----------------------------------------------------------------------
1548 *
1549 * RenumberTiers --
1550 *
1551 * In multi-tier mode, we need to find the start of the tier
1552 * containing the newly selected tab.
1553 *
1554 * Tiers are draw from the last tier to the first, so that
1555 * the the lower-tiered tabs will partially cover the bottoms
1556 * of tab directly above it. This simplifies the drawing of
1557 * tabs because we don't worry how tabs are clipped by their
1558 * neighbors.
1559 *
1560 * In addition, tabs are re-marked with the correct tier number.
1561 *
1562 * Results:
1563 * None.
1564 *
1565 * Side Effects:
1566 * Renumbering the tab's tier will change the vertical placement
1567 * of the tab (i.e. shift tiers).
1568 *
1569 * ----------------------------------------------------------------------
1570 */
1571 static void
1572 RenumberTiers(setPtr, tabPtr)
1573 Tabset *setPtr;
1574 Tab *tabPtr;
1575 {
1576 int tier;
1577 Tab *prevPtr;
1578 Blt_ChainLink *linkPtr, *lastPtr;
1579
1580 setPtr->focusPtr = setPtr->selectPtr = tabPtr;
1581 Blt_SetFocusItem(setPtr->bindTable, setPtr->focusPtr, NULL);
1582
1583 tier = tabPtr->tier;
1584 for (linkPtr = Blt_ChainPrevLink(tabPtr->linkPtr); linkPtr != NULL;
1585 linkPtr = lastPtr) {
1586 lastPtr = Blt_ChainPrevLink(linkPtr);
1587 prevPtr = Blt_ChainGetValue(linkPtr);
1588 if (prevPtr->hidden) continue;
1589 if ((prevPtr == NULL) || (prevPtr->tier != tier)) {
1590 break;
1591 }
1592 tabPtr = prevPtr;
1593 }
1594 setPtr->startPtr = tabPtr;
1595 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
1596 linkPtr = Blt_ChainNextLink(linkPtr)) {
1597 tabPtr = Blt_ChainGetValue(linkPtr);
1598 if (tabPtr->hidden) continue;
1599 tabPtr->tier = (tabPtr->tier - tier + 1);
1600 if (tabPtr->tier < 1) {
1601 tabPtr->tier += setPtr->nTiers;
1602 }
1603 tabPtr->worldY = WorldY(tabPtr);
1604 }
1605 }
1606
1607 /*
1608 * ----------------------------------------------------------------------
1609 *
1610 * TabExists --
1611 *
1612 * Searches for a tab based upon its name.
1613 *
1614 * Results:
1615 * Returns TRUE if the tab exists, FALSE otherwise.
1616 *
1617 * ----------------------------------------------------------------------
1618 */
1619 static int
1620 TabExists(setPtr, string)
1621 Tabset *setPtr;
1622 char *string;
1623 {
1624 Blt_HashEntry *hPtr;
1625
1626 hPtr = Blt_FindHashEntry(&(setPtr->tabTable), string);
1627 return (hPtr != NULL);
1628 }
1629
1630 /*
1631 * ----------------------------------------------------------------------
1632 *
1633 * GetTabByName --
1634 *
1635 * Searches for a tab based upon its name.
1636 *
1637 * Results:
1638 * A standard Tcl result. An error message is generated if
1639 * the tab can't be found.
1640 *
1641 * Side Effects:
1642 * If the tab is found, *tabPtrPtr will contain the pointer to the
1643 * tab structure.
1644 *
1645 * ----------------------------------------------------------------------
1646 */
1647 static int
1648 GetTabByName(setPtr, string, tabPtrPtr)
1649 Tabset *setPtr;
1650 char *string;
1651 Tab **tabPtrPtr;
1652 {
1653 Blt_HashEntry *hPtr;
1654 *tabPtrPtr = NULL;
1655
1656 hPtr = Blt_FindHashEntry(&(setPtr->tabTable), string);
1657 if (hPtr != NULL) {
1658 *tabPtrPtr = (Tab *)Blt_GetHashValue(hPtr);
1659 return TCL_OK;
1660 }
1661 Tcl_AppendResult(setPtr->interp, "can't find tab named \"", string,
1662 "\" in \"", Tk_PathName(setPtr->tkwin), "\"", (char *)NULL);
1663 return TCL_ERROR;
1664 }
1665
1666 /*
1667 *----------------------------------------------------------------------
1668 *
1669 * PickTab --
1670 *
1671 * Searches the tab located within the given screen X-Y coordinates
1672 * in the viewport. Note that tabs overlap slightly, so that its
1673 * important to search from the innermost tier out.
1674 *
1675 * Results:
1676 * Returns the pointer to the tab. If the pointer isn't contained
1677 * by any tab, NULL is returned.
1678 *
1679 *----------------------------------------------------------------------
1680 */
1681 static ClientData
1682 PickTab(clientData, x, y, contextPtr)
1683 ClientData clientData;
1684 int x, y; /* Screen coordinates to test. */
1685 ClientData *contextPtr; /* (out) If non-NULL, will contain the
1686 * context of the tab selected. */
1687 {
1688 Tabset *setPtr = clientData; /* Tabset widget record. */
1689 Tab *tabPtr;
1690 Blt_ChainLink *linkPtr;
1691
1692 tabPtr = setPtr->selectPtr;
1693 if (setPtr->startImage && contextPtr != NULL) {
1694 if (setPtr->startImage && x>=setPtr->siX &&
1695 x<(setPtr->siX+setPtr->startImage->width) &&
1696 y>=setPtr->siY && y<(setPtr->siY+setPtr->startImage->height)) {
1697 *contextPtr = TAB_STARTIMAGE;
1698 return setPtr->selectPtr;
1699 }
1700 }
1701 if (setPtr->endImage && contextPtr != NULL) {
1702 if (setPtr->endImage && x>=setPtr->eiX
1703 && x<(setPtr->eiX+setPtr->endImage->width)
1704 && y>=setPtr->eiY && y<(setPtr->eiY+setPtr->endImage->height)) {
1705 *contextPtr = TAB_ENDIMAGE;
1706 return setPtr->selectPtr;
1707 }
1708 }
1709
1710 if ((setPtr->tearoff) && (tabPtr != NULL) &&
1711 (tabPtr->container == NULL) && (tabPtr->tkwin != NULL)) {
1712 int top, bottom, left, right;
1713 int sx, sy;
1714
1715 /* Check first for perforation on the selected tab. */
1716 WorldToScreen(setPtr, tabPtr->worldX + 2,
1717 tabPtr->worldY + tabPtr->worldHeight + 4, &sx, &sy);
1718 if (setPtr->side & SIDE_HORIZONTAL) {
1719 left = sx - 2;
1720 right = left + tabPtr->screenWidth;
1721 top = sy - 4;
1722 bottom = sy + 4;
1723 } else {
1724 left = sx - 4;
1725 right = sx + 4;
1726 top = sy - 2;
1727 bottom = top + tabPtr->screenHeight;
1728 }
1729 if ((x >= left) && (y >= top) && (x < right) && (y < bottom)) {
1730 if (contextPtr != NULL) {
1731 *contextPtr = TAB_PERFORATION;
1732 }
1733 return tabPtr;
1734 }
1735 }
1736 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
1737 linkPtr = Blt_ChainNextLink(linkPtr)) {
1738 tabPtr = Blt_ChainGetValue(linkPtr);
1739 if (!(tabPtr->flags & TAB_VISIBLE)) {
1740 continue;
1741 }
1742 if (tabPtr->hidden) continue;
1743 if ((x >= tabPtr->screenX) && (y >= tabPtr->screenY) &&
1744 (x <= (tabPtr->screenX + tabPtr->screenWidth)) &&
1745 (y < (tabPtr->screenY + tabPtr->screenHeight))) {
1746 ClientData cType = TAB_LABEL;
1747
1748 if (tabPtr->iW && (x >= tabPtr->iX)
1749 && (x < (tabPtr->iX + tabPtr->iW))
1750 && (y >= tabPtr->iY) && (y < (tabPtr->iY + tabPtr->iH))) {
1751 cType = TAB_IMAGE;
1752 }
1753 if (tabPtr->i2W && (x >= tabPtr->i2X)
1754 && (x < (tabPtr->i2X + tabPtr->i2W))
1755 && (y >= tabPtr->i2Y) && (y < (tabPtr->i2Y + tabPtr->i2H))) {
1756 cType = TAB_LEFTIMAGE;
1757 }
1758 if (contextPtr != NULL) {
1759 *contextPtr = cType;
1760 }
1761 return tabPtr;
1762 }
1763 }
1764 return NULL;
1765 }
1766
1767 static Tab *
1768 TabNext(tabPtr, wrap)
1769 Tab *tabPtr;
1770 int wrap;
1771 {
1772 if (tabPtr != NULL) {
1773 Blt_ChainLink *linkPtr;
1774 Tabset *setPtr = tabPtr->setPtr;
1775
1776 linkPtr = Blt_ChainNextLink(tabPtr->linkPtr);
1777 if (linkPtr == NULL && wrap) {
1778 wrap = 0;
1779 linkPtr = Blt_ChainFirstLink(setPtr->chainPtr);
1780 }
1781 while (linkPtr != NULL) {
1782 tabPtr = Blt_ChainGetValue(linkPtr);
1783 if (!tabPtr->hidden) break;
1784 linkPtr = Blt_ChainNextLink(tabPtr->linkPtr);
1785 if (linkPtr == NULL && wrap) {
1786 wrap = 0;
1787 linkPtr = Blt_ChainFirstLink(setPtr->chainPtr);
1788 }
1789 }
1790 }
1791 if (tabPtr && tabPtr->hidden) tabPtr = NULL;
1792 return tabPtr;
1793 }
1794
1795 static Tab *
1796 TabPrev(tabPtr, wrap)
1797 Tab *tabPtr;
1798 int wrap;
1799 {
1800 if (tabPtr != NULL) {
1801 Blt_ChainLink *linkPtr;
1802 Tabset *setPtr = tabPtr->setPtr;
1803
1804 linkPtr = Blt_ChainPrevLink(tabPtr->linkPtr);
1805 if (linkPtr == NULL && wrap) {
1806 wrap = 0;
1807 linkPtr = Blt_ChainLastLink(setPtr->chainPtr);
1808 }
1809 while (linkPtr != NULL) {
1810 tabPtr = Blt_ChainGetValue(linkPtr);
1811 if (!tabPtr->hidden) break;
1812 linkPtr = Blt_ChainPrevLink(tabPtr->linkPtr);
1813 if (linkPtr == NULL && wrap) {
1814 wrap = 0;
1815 linkPtr = Blt_ChainLastLink(setPtr->chainPtr);
1816 }
1817 }
1818 }
1819 if (tabPtr && tabPtr->hidden) tabPtr = NULL;
1820 return tabPtr;
1821 }
1822
1823
1824 static Tab *
1825 TabLeft(tabPtr)
1826 Tab *tabPtr;
1827 {
1828 if (tabPtr != NULL) {
1829 Tab *newPtr;
1830 newPtr = TabPrev(tabPtr, 0);
1831 if (newPtr && newPtr->tier == tabPtr->tier) {
1832 tabPtr = newPtr;
1833 }
1834 }
1835 return tabPtr;
1836 }
1837
1838 static Tab *
1839 TabRight(tabPtr)
1840 Tab *tabPtr;
1841 {
1842 if (tabPtr != NULL) {
1843 Tab *newPtr;
1844 newPtr = TabNext(tabPtr, 0);
1845 if (newPtr && newPtr->tier == tabPtr->tier) {
1846 tabPtr = newPtr;
1847 }
1848 }
1849 return tabPtr;
1850 }
1851
1852 static Tab *
1853 TabUp(tabPtr)
1854 Tab *tabPtr;
1855 {
1856 if (tabPtr != NULL) {
1857 Tabset *setPtr;
1858 int x, y;
1859 int worldX, worldY;
1860
1861 setPtr = tabPtr->setPtr;
1862 worldX = tabPtr->worldX + (tabPtr->worldWidth / 2);
1863 worldY = tabPtr->worldY - (setPtr->tabHeight / 2);
1864 WorldToScreen(setPtr, worldX, worldY, &x, &y);
1865
1866 tabPtr = PickTab(setPtr, x, y, NULL);
1867 if (tabPtr == NULL) {
1868 /*
1869 * We might have inadvertly picked the gap between two tabs,
1870 * so if the first pick fails, try again a little to the left.
1871 */
1872 WorldToScreen(setPtr, worldX + setPtr->gap, worldY, &x, &y);
1873 tabPtr = PickTab(setPtr, x, y, NULL);
1874 }
1875 if ((tabPtr == NULL) &&
1876 (setPtr->focusPtr->tier < (setPtr->nTiers - 1))) {
1877 WorldToScreen(setPtr, worldX, worldY - setPtr->tabHeight, &x, &y);
1878 tabPtr = PickTab(setPtr, x, y, NULL);
1879 }
1880 if (tabPtr == NULL) {
1881 tabPtr = setPtr->focusPtr;
1882 }
1883 }
1884 return tabPtr;
1885 }
1886
1887 static Tab *
1888 TabDown(tabPtr)
1889 Tab *tabPtr;
1890 {
1891 if (tabPtr != NULL) {
1892 Tabset *setPtr;
1893 int x, y;
1894 int worldX, worldY;
1895
1896 setPtr = tabPtr->setPtr;
1897 worldX = tabPtr->worldX + (tabPtr->worldWidth / 2);
1898 worldY = tabPtr->worldY + (3 * setPtr->tabHeight) / 2;
1899 WorldToScreen(setPtr, worldX, worldY, &x, &y);
1900 tabPtr = PickTab(setPtr, x, y, NULL);
1901 if (tabPtr == NULL) {
1902 /*
1903 * We might have inadvertly picked the gap between two tabs,
1904 * so if the first pick fails, try again a little to the left.
1905 */
1906 WorldToScreen(setPtr, worldX - setPtr->gap, worldY, &x, &y);
1907 tabPtr = PickTab(setPtr, x, y, NULL);
1908 }
1909 if ((tabPtr == NULL) && (setPtr->focusPtr->tier > 2)) {
1910 WorldToScreen(setPtr, worldX, worldY + setPtr->tabHeight, &x, &y);
1911 tabPtr = PickTab(setPtr, x, y, NULL);
1912 }
1913 if (tabPtr == NULL) {
1914 tabPtr = setPtr->focusPtr;
1915 }
1916 }
1917 return tabPtr;
1918 }
1919
1920 /*
1921 *----------------------------------------------------------------------
1922 *
1923 * GetTabByIndex --
1924 *
1925 * Converts a string representing a tab index into a tab pointer.
1926 * The index may be in one of the following forms:
1927 *
1928 * number Tab at position in the list of tabs.
1929 * @x,y Tab closest to the specified X-Y screen coordinates.
1930 * "active" Tab mouse is located over.
1931 * "focus" Tab is the widget's focus.
1932 * "select" Currently selected tab.
1933 * "right" Next tab from the focus tab.
1934 * "left" Previous tab from the focus tab.
1935 * "up" Next tab from the focus tab.
1936 * "down" Previous tab from the focus tab.
1937 * "end" Last tab in list.
1938 *
1939 * Results:
1940 * If the string is successfully converted, TCL_OK is returned.
1941 * The pointer to the node is returned via tabPtrPtr.
1942 * Otherwise, TCL_ERROR is returned and an error message is left
1943 * in interpreter's result field.
1944 *
1945 *----------------------------------------------------------------------
1946 */
1947 static int
1948 GetTabByIndex(setPtr, string, tabPtrPtr, allowNull)
1949 Tabset *setPtr;
1950 char *string;
1951 Tab **tabPtrPtr;
1952 int allowNull; /* Allow NULL tabPtr */
1953 {
1954 Tab *tabPtr;
1955 Blt_ChainLink *linkPtr;
1956 int position;
1957 char c;
1958
1959 c = string[0];
1960 tabPtr = NULL;
1961 if (setPtr->focusPtr == NULL) {
1962 setPtr->focusPtr = setPtr->selectPtr;
1963 Blt_SetFocusItem(setPtr->bindTable, setPtr->focusPtr, NULL);
1964 }
1965 if ((isdigit(UCHAR(c))) &&
1966 (Tcl_GetInt(setPtr->interp, string, &position) == TCL_OK)) {
1967 linkPtr = Blt_ChainGetNthLink(setPtr->chainPtr, position);
1968 if (linkPtr == NULL) {
1969 Tcl_AppendResult(setPtr->interp, "can't find tab \"", string,
1970 "\" in \"", Tk_PathName(setPtr->tkwin), "\": no such index",
1971 (char *)NULL);
1972 return TCL_ERROR;
1973 }
1974 tabPtr = Blt_ChainGetValue(linkPtr);
1975 } else if ((c == 'a') && (strcmp(string, "active") == 0)) {
1976 tabPtr = setPtr->activePtr;
1977 } else if ((c == 'c') && (strcmp(string, "current") == 0)) {
1978 tabPtr = (Tab *)Blt_GetCurrentItem(setPtr->bindTable);
1979 } else if ((c == 's') && (strcmp(string, "select") == 0)) {
1980 tabPtr = setPtr->selectPtr;
1981 } else if ((c == 'f') && (strcmp(string, "focus") == 0)) {
1982 tabPtr = setPtr->focusPtr;
1983 } else if ((c == 'p') && (strcmp(string, "prev") == 0)) {
1984 tabPtr = TabPrev(setPtr->focusPtr, 1);
1985 } else if ((c == 'n') && (strcmp(string, "next") == 0)) {
1986 tabPtr = TabNext(setPtr->focusPtr, 1);
1987 } else if ((c == 'u') && (strcmp(string, "up") == 0)) {
1988 switch (setPtr->side) {
1989 case SIDE_LEFT:
1990 case SIDE_RIGHT:
1991 tabPtr = TabLeft(setPtr->focusPtr);
1992 break;
1993
1994 case SIDE_BOTTOM:
1995 tabPtr = TabDown(setPtr->focusPtr);
1996 break;
1997
1998 case SIDE_TOP:
1999 tabPtr = TabUp(setPtr->focusPtr);
2000 break;
2001 }
2002 } else if ((c == 'd') && (strcmp(string, "down") == 0)) {
2003 switch (setPtr->side) {
2004 case SIDE_LEFT:
2005 case SIDE_RIGHT:
2006 tabPtr = TabRight(setPtr->focusPtr);
2007 break;
2008
2009 case SIDE_BOTTOM:
2010 tabPtr = TabUp(setPtr->focusPtr);
2011 break;
2012
2013 case SIDE_TOP:
2014 tabPtr = TabDown(setPtr->focusPtr);
2015 break;
2016 }
2017 } else if ((c == 'l') && (strcmp(string, "left") == 0)) {
2018 switch (setPtr->side) {
2019 case SIDE_LEFT:
2020 tabPtr = TabUp(setPtr->focusPtr);
2021 break;
2022
2023 case SIDE_RIGHT:
2024 tabPtr = TabDown(setPtr->focusPtr);
2025 break;
2026
2027 case SIDE_BOTTOM:
2028 case SIDE_TOP:
2029 tabPtr = TabLeft(setPtr->focusPtr);
2030 break;
2031 }
2032 } else if ((c == 'r') && (strcmp(string, "right") == 0)) {
2033 switch (setPtr->side) {
2034 case SIDE_LEFT:
2035 tabPtr = TabDown(setPtr->focusPtr);
2036 break;
2037
2038 case SIDE_RIGHT:
2039 tabPtr = TabUp(setPtr->focusPtr);
2040 break;
2041
2042 case SIDE_BOTTOM:
2043 case SIDE_TOP:
2044 tabPtr = TabRight(setPtr->focusPtr);
2045 break;
2046 }
2047 } else if ((c == 'e') && (strcmp(string, "end") == 0)) {
2048 linkPtr = Blt_ChainLastLink(setPtr->chainPtr);
2049 if (linkPtr != NULL) {
2050 tabPtr = Blt_ChainGetValue(linkPtr);
2051 }
2052 if (tabPtr && tabPtr->hidden) { tabPtr = TabPrev(tabPtr, 0); }
2053 } else if ((c == 'b') && (strcmp(string, "begin") == 0)) {
2054 linkPtr = Blt_ChainFirstLink(setPtr->chainPtr);
2055 if (linkPtr != NULL) {
2056 tabPtr = Blt_ChainGetValue(linkPtr);
2057 }
2058 if (tabPtr && tabPtr->hidden) { tabPtr = TabNext(tabPtr, 0); }
2059 } else if (c == '@') {
2060 int x, y;
2061
2062 if (Blt_GetXY(setPtr->interp, setPtr->tkwin, string, &x, &y)
2063 != TCL_OK) {
2064 return TCL_ERROR;
2065 }
2066 tabPtr = PickTab(setPtr, x, y, NULL);
2067 } else {
2068 Tcl_AppendResult(setPtr->interp, "can't find tab \"", string,
2069 "\" in \"", Tk_PathName(setPtr->tkwin), "\"", (char *)NULL);
2070 return TCL_ERROR;
2071 }
2072 *tabPtrPtr = tabPtr;
2073 Tcl_ResetResult(setPtr->interp);
2074
2075 if ((!allowNull) && (tabPtr == NULL)) {
2076 Tcl_AppendResult(setPtr->interp, "can't find tab \"", string,
2077 "\" in \"", Tk_PathName(setPtr->tkwin), "\"", (char *)NULL);
2078 return TCL_ERROR;
2079 }
2080 return TCL_OK;
2081 }
2082
2083 /*
2084 * Try name, then ind.
2085 */
2086 static int
2087 GetTabByNameInd(setPtr, string, tabPtrPtr)
2088 Tabset *setPtr;
2089 char *string;
2090 Tab **tabPtrPtr;
2091 {
2092 if (GetTabByName(setPtr, string, tabPtrPtr) == TCL_OK) {
2093 return TCL_OK;
2094 }
2095 Tcl_ResetResult(setPtr->interp);
2096 if (GetTabByIndex(setPtr, string, tabPtrPtr) != TCL_OK) {
2097 return TCL_ERROR; /* Can't find node. */
2098 }
2099 return TCL_OK;
2100 }
2101
2102 static int
2103 GetTabByIndName(
2104 Tabset *setPtr,
2105 char *string,
2106 Tab **tabPtrPtr)
2107 {
2108 if (GetTabByIndex(setPtr, string, tabPtrPtr) == TCL_OK) {
2109 return TCL_OK;
2110 }
2111 Tcl_ResetResult(setPtr->interp);
2112 if (GetTabByName(setPtr, string, tabPtrPtr) != TCL_OK) {
2113 return TCL_ERROR; /* Can't find node. */
2114 }
2115 return TCL_OK;
2116 }
2117
2118 static Tab *
2119 NextOrLastTab(tabPtr)
2120 Tab *tabPtr;
2121 {
2122 if (tabPtr->linkPtr != NULL) {
2123 Blt_ChainLink *linkPtr;
2124
2125 linkPtr = Blt_ChainNextLink(tabPtr->linkPtr);
2126 if (linkPtr == NULL) {
2127 linkPtr = Blt_ChainPrevLink(tabPtr->linkPtr);
2128 }
2129 while (linkPtr != NULL) {
2130 tabPtr = Blt_ChainGetValue(linkPtr);
2131 if (!tabPtr->hidden) { return tabPtr; }
2132 linkPtr = Blt_ChainNextLink(tabPtr->linkPtr);
2133 }
2134 }
2135 return NULL;
2136 }
2137
2138 /*
2139 * --------------------------------------------------------------
2140 *
2141 * EmbeddedWidgetEventProc --
2142 *
2143 * This procedure is invoked by the Tk dispatcher for various
2144 * events on embedded widgets contained in the tabset.
2145 *
2146 * Results:
2147 * None.
2148 *
2149 * Side effects:
2150 * When an embedded widget gets deleted, internal structures get
2151 * cleaned up. When it gets resized, the tabset is redisplayed.
2152 *
2153 * --------------------------------------------------------------
2154 */
2155 static void
2156 EmbeddedWidgetEventProc(clientData, eventPtr)
2157 ClientData clientData; /* Information about the tab window. */
2158 XEvent *eventPtr; /* Information about event. */
2159 {
2160 Tab *tabPtr = clientData;
2161
2162 if ((tabPtr == NULL) || (tabPtr->tkwin == NULL)) {
2163 return;
2164 }
2165 switch (eventPtr->type) {
2166 case ConfigureNotify:
2167 /*
2168 * If the window's requested size changes, redraw the window.
2169 * But only if it's currently the selected page.
2170 */
2171 if ((tabPtr->container == NULL) && (Tk_IsMapped(tabPtr->tkwin)) &&
2172 (tabPtr->setPtr->selectPtr == tabPtr)) {
2173 EventuallyRedraw(tabPtr->setPtr);
2174 }
2175 break;
2176
2177 case DestroyNotify:
2178 /*
2179 * Mark the tab as deleted by dereferencing the Tk window
2180 * pointer. Redraw the window only if the tab is currently
2181 * visible.
2182 */
2183 if ((Tk_IsMapped(tabPtr->tkwin)) &&
2184 (tabPtr->setPtr->selectPtr == tabPtr)) {
2185 EventuallyRedraw(tabPtr->setPtr);
2186 }
2187 Tk_DeleteEventHandler(tabPtr->tkwin, StructureNotifyMask,
2188 EmbeddedWidgetEventProc, tabPtr);
2189 tabPtr->tkwin = NULL;
2190 break;
2191
2192 }
2193 }
2194
2195 /*
2196 * ----------------------------------------------------------------------
2197 *
2198 * EmbeddedWidgetCustodyProc --
2199 *
2200 * This procedure is invoked when a tab window has been
2201 * stolen by another geometry manager. The information and
2202 * memory associated with the tab window is released.
2203 *
2204 * Results:
2205 * None.
2206 *
2207 * Side effects:
2208 * Arranges for the widget formerly associated with the tab
2209 * window to have its layout re-computed and arranged at the
2210 * next idle point.
2211 *
2212 * ---------------------------------------------------------------------
2213 */
2214 /* ARGSUSED */
2215 static void
2216 EmbeddedWidgetCustodyProc(clientData, tkwin)
2217 ClientData clientData; /* Information about the former tab window. */
2218 Tk_Window tkwin; /* Not used. */
2219 {
2220 Tab *tabPtr = clientData;
2221 Tabset *setPtr;
2222
2223 if ((tabPtr == NULL) || (tabPtr->tkwin == NULL)) {
2224 return;
2225 }
2226 setPtr = tabPtr->setPtr;
2227 if (tabPtr->container != NULL) {
2228 Tcl_EventuallyFree(tabPtr, DestroyTearoff);
2229 }
2230 /*
2231 * Mark the tab as deleted by dereferencing the Tk window
2232 * pointer. Redraw the window only if the tab is currently
2233 * visible.
2234 */
2235 if (tabPtr->tkwin != NULL) {
2236 if (Tk_IsMapped(tabPtr->tkwin) && (setPtr->selectPtr == tabPtr)) {
2237 setPtr->flags |= (TABSET_LAYOUT | TABSET_SCROLL);
2238 EventuallyRedraw(setPtr);
2239 }
2240 Tk_DeleteEventHandler(tabPtr->tkwin, StructureNotifyMask,
2241 EmbeddedWidgetEventProc, tabPtr);
2242 tabPtr->tkwin = NULL;
2243 }
2244 }
2245
2246 /*
2247 * -------------------------------------------------------------------------
2248 *
2249 * EmbeddedWidgetGeometryProc --
2250 *
2251 * This procedure is invoked by Tk_GeometryRequest for tab
2252 * windows managed by the widget.
2253 *
2254 * Results:
2255 * None.
2256 *
2257 * Side effects:
2258 * Arranges for tkwin, and all its managed siblings, to be
2259 * repacked and drawn at the next idle point.
2260 *
2261 * ------------------------------------------------------------------------
2262 */
2263 /* ARGSUSED */
2264 static void
2265 EmbeddedWidgetGeometryProc(clientData, tkwin)
2266 ClientData clientData; /* Information about window that got new
2267 * preferred geometry. */
2268 Tk_Window tkwin; /* Other Tk-related information about the
2269 * window. */
2270 {
2271 Tab *tabPtr = clientData;
2272
2273 if ((tabPtr == NULL) || (tabPtr->tkwin == NULL)) {
2274 fprintf(stderr, "%s: line %d \"tkwin is null\"", __FILE__, __LINE__);
2275 return;
2276 }
2277 tabPtr->setPtr->flags |= (TABSET_LAYOUT | TABSET_SCROLL);
2278 EventuallyRedraw(tabPtr->setPtr);
2279 }
2280
2281 /*
2282 * ----------------------------------------------------------------------
2283 *
2284 * DestroyTab --
2285 *
2286 * ----------------------------------------------------------------------
2287 */
2288 static void
2289 DestroyTab(setPtr, tabPtr)
2290 Tabset *setPtr;
2291 Tab *tabPtr;
2292 {
2293 Blt_HashEntry *hPtr;
2294
2295 if (tabPtr->flags & TAB_REDRAW) {
2296 Tcl_CancelIdleCall(DisplayTearoff, tabPtr);
2297 }
2298 if (tabPtr->container != NULL) {
2299 Tk_DestroyWindow(tabPtr->container);
2300 }
2301 if (tabPtr->tkwin != NULL) {
2302 Tk_ManageGeometry(tabPtr->tkwin, (Tk_GeomMgr *)NULL, tabPtr);
2303 Tk_DeleteEventHandler(tabPtr->tkwin, StructureNotifyMask,
2304 EmbeddedWidgetEventProc, tabPtr);
2305 if (Tk_IsMapped(tabPtr->tkwin)) {
2306 Tk_UnmapWindow(tabPtr->tkwin);
2307 }
2308 }
2309 if (tabPtr == setPtr->activePtr) {
2310 setPtr->activePtr = NULL;
2311 }
2312 if (tabPtr == setPtr->selectPtr) {
2313 setPtr->selectPtr = NextOrLastTab(tabPtr);
2314 }
2315 if (tabPtr == setPtr->focusPtr) {
2316 setPtr->focusPtr = setPtr->selectPtr;
2317 Blt_SetFocusItem(setPtr->bindTable, setPtr->focusPtr, NULL);
2318 }
2319 if (tabPtr == setPtr->startPtr) {
2320 setPtr->startPtr = NULL;
2321 }
2322 Tk_FreeOptions(tabConfigSpecs, (char *)tabPtr, setPtr->display, 0);
2323 if (tabPtr->text != NULL) {
2324 Blt_FreeUid(tabPtr->text);
2325 }
2326 if (tabPtr->textDisp != NULL) {
2327 Blt_Free(tabPtr->textDisp);
2328 }
2329 hPtr = Blt_FindHashEntry(&(setPtr->tabTable), tabPtr->name);
2330 assert(hPtr);
2331 Blt_DeleteHashEntry(&(setPtr->tabTable), hPtr);
2332
2333 if (tabPtr->image != NULL) {
2334 FreeImage(setPtr, tabPtr->image);
2335 }
2336 if (tabPtr->image2 != NULL) {
2337 FreeImage(setPtr, tabPtr->image2);
2338 }
2339 if (tabPtr->name != NULL) {
2340 Blt_Free(tabPtr->name);
2341 }
2342 if (tabPtr->textGC != NULL) {
2343 Tk_FreeGC(setPtr->display, tabPtr->textGC);
2344 }
2345 if (tabPtr->backGC != NULL) {
2346 Tk_FreeGC(setPtr->display, tabPtr->backGC);
2347 }
2348 if (tabPtr->command != NULL) {
2349 Blt_FreeUid(tabPtr->command);
2350 }
2351 if (tabPtr->linkPtr != NULL) {
2352 Blt_ChainDeleteLink(setPtr->chainPtr, tabPtr->linkPtr);
2353 }
2354 if (tabPtr->tags != NULL) {
2355 Blt_FreeUid(tabPtr->tags);
2356 }
2357 if (tabPtr->shadow.color != NULL) {
2358 Tk_FreeColor(tabPtr->shadow.color);
2359 }
2360 Blt_DeleteBindings(setPtr->bindTable, tabPtr);
2361 Blt_Free(tabPtr);
2362 }
2363
2364 /*
2365 * ----------------------------------------------------------------------
2366 *
2367 * CreateTab --
2368 *
2369 * Creates a new tab structure. A tab contains information about
2370 * the state of the tab and its embedded window.
2371 *
2372 * Results:
2373 * Returns a pointer to the new tab structure.
2374 *
2375 * ----------------------------------------------------------------------
2376 */
2377 static Tab *
2378 CreateTab(setPtr, name)
2379 Tabset *setPtr;
2380 char *name;
2381 {
2382 Tab *tabPtr;
2383 Blt_HashEntry *hPtr;
2384 int isNew, nLen, idx=1;
2385
2386 tabPtr = Blt_Calloc(1, sizeof(Tab));
2387 assert(tabPtr);
2388 tabPtr->setPtr = setPtr;
2389 nLen = strlen(name);
2390 if (nLen>=5 && strcmp(name+nLen-5,"#auto") == 0) {
2391 Tcl_DString dStr;
2392 Tcl_DStringInit(&dStr);
2393 nLen -= 5;
2394 if (nLen == 0) nLen = 1;
2395 for (;;) {
2396 Tcl_DStringSetLength(&dStr, 0);
2397 Tcl_DStringAppend(&dStr, name, nLen);
2398 Tcl_DStringAppend(&dStr, Blt_Itoa(idx), -1);
2399 idx++;
2400 tabPtr->name = Tcl_DStringValue(&dStr);
2401 hPtr = Blt_FindHashEntry(&(setPtr->tabTable), tabPtr->name);
2402 if (hPtr == NULL) break;
2403 }
2404 tabPtr->name = Blt_Strdup(tabPtr->name);
2405 Tcl_DStringFree(&dStr);
2406 } else {
2407 tabPtr->name = Blt_Strdup(name);
2408 }
2409 tabPtr->text = Blt_GetUid(tabPtr->name);
2410 tabPtr->fill = FILL_NONE;
2411 tabPtr->anchor = TK_ANCHOR_CENTER;
2412 tabPtr->container = NULL;
2413 tabPtr->state = STATE_NORMAL;
2414 hPtr = Blt_CreateHashEntry(&(setPtr->tabTable), tabPtr->name, &isNew);
2415 Blt_SetHashValue(hPtr, tabPtr);
2416 return tabPtr;
2417 }
2418
2419 /*
2420 *----------------------------------------------------------------------
2421 *
2422 * TileChangedProc
2423 *
2424 * Stub for image change notifications. Since we immediately draw
2425 * the image into a pixmap, we don't really care about image changes.
2426 *
2427 * It would be better if Tk checked for NULL proc pointers.
2428 *
2429 * Results:
2430 * None.
2431 *
2432 *----------------------------------------------------------------------
2433 */
2434 /*ARGSUSED*/
2435 static void
2436 TileChangedProc(clientData, tile)
2437 ClientData clientData;
2438 Blt_Tile tile; /* Not used. */
2439 {
2440 Tabset *setPtr = clientData;
2441
2442 if (setPtr->tkwin != NULL) {
2443 EventuallyRedraw(setPtr);
2444 }
2445 }
2446
2447 static int
2448 ConfigureTab(setPtr, tabPtr)
2449 Tabset *setPtr;
2450 Tab *tabPtr;
2451 {
2452 GC newGC;
2453 XGCValues gcValues;
2454 unsigned long gcMask;
2455 int labelWidth, labelHeight;
2456 Tk_Font font;
2457 Tk_3DBorder border;
2458
2459 TabImage image;
2460 TabImage image2;
2461
2462 image = GETATTR(tabPtr, image);
2463 image2 = GETATTR(tabPtr, image2);
2464
2465 font = GETATTR(tabPtr, font);
2466 labelWidth = labelHeight = 0;
2467 if (tabPtr->text != NULL) {
2468 TextStyle ts;
2469 double rotWidth, rotHeight;
2470 int tLen, eLen;
2471
2472 Blt_InitTextStyle(&ts);
2473 ts.font = font;
2474 if (setPtr->shadow.offset>0) {
2475 ts.shadow.offset = setPtr->shadow.offset;
2476 } else {
2477 ts.shadow.offset = tabPtr->shadow.offset;
2478 }
2479 ts.padX.side1 = ts.padX.side2 = 2;
2480 if (tabPtr->textDisp != NULL) {
2481 Blt_Free(tabPtr->textDisp);
2482 }
2483 tLen = strlen(tabPtr->text);
2484 eLen = (setPtr->ellipsis?strlen(setPtr->ellipsis):0);
2485 tabPtr->textDisp = Blt_Malloc(tLen + eLen + 2);
2486 if (setPtr->truncLen <= 0 || tLen <= (setPtr->truncLen+eLen)) {
2487 strcpy(tabPtr->textDisp, tabPtr->text);
2488 } else {
2489 strncpy(tabPtr->textDisp, tabPtr->text, setPtr->truncLen);
2490 tabPtr->textDisp[setPtr->truncLen] = 0;
2491 if (eLen) {
2492 strcat(tabPtr->textDisp, setPtr->ellipsis);
2493 }
2494 }
2495 Blt_GetTextExtents(&ts, tabPtr->textDisp, &labelWidth, &labelHeight);
2496 Blt_GetBoundingBox(labelWidth, labelHeight, setPtr->defTabStyle.rotate,
2497 &rotWidth, &rotHeight, (Point2D *)NULL);
2498 labelWidth = ROUND(rotWidth);
2499 labelHeight = ROUND(rotHeight);
2500 }
2501 tabPtr->textWidth = (short int)labelWidth;
2502 tabPtr->textHeight = (short int)labelHeight;
2503 if (image != NULL) {
2504 int width, height;
2505
2506 width = ImageWidth(image) + 2 * IMAGE_PAD;
2507 height = ImageHeight(image) + 2 * IMAGE_PAD;
2508 if (setPtr->defTabStyle.textSide & SIDE_VERTICAL) {
2509 labelWidth += width;
2510 labelHeight = MAX(labelHeight, height);
2511 } else {
2512 labelHeight += height;
2513 labelWidth = MAX(labelWidth, width);
2514 }
2515 }
2516 if (image2 != NULL) {
2517 int width, height;
2518
2519 width = ImageWidth(image2) + 2 * IMAGE_PAD;
2520 height = ImageHeight(image2) + 2 * IMAGE_PAD;
2521 if (setPtr->defTabStyle.textSide & SIDE_VERTICAL) {
2522 labelWidth += (width + setPtr->gapLeft);
2523 labelHeight = MAX(labelHeight, height);
2524 } else {
2525 labelHeight += (height + setPtr->gapLeft);
2526 labelWidth = MAX(labelWidth, width);
2527 }
2528 }
2529 labelWidth += PADDING(tabPtr->iPadX);
2530 labelHeight += PADDING(tabPtr->iPadY);
2531
2532 tabPtr->labelWidth = ODD(labelWidth);
2533 tabPtr->labelHeight = ODD(labelHeight);
2534
2535 newGC = NULL;
2536 if (tabPtr->text != NULL) {
2537 XColor *colorPtr;
2538
2539 gcMask = GCForeground | GCFont;
2540 colorPtr = GETATTR(tabPtr, textColor);
2541 gcValues.foreground = colorPtr->pixel;
2542 gcValues.font = Tk_FontId(font);
2543 newGC = Tk_GetGC(setPtr->tkwin, gcMask, &gcValues);
2544 }
2545 if (tabPtr->textGC != NULL) {
2546 Tk_FreeGC(setPtr->display, tabPtr->textGC);
2547 }
2548 tabPtr->textGC = newGC;
2549
2550 gcMask = GCForeground;
2551 gcValues.fill_style = FillStippled;
2552 border = GETATTR(tabPtr, border);
2553 gcValues.foreground = Tk_3DBorderColor(border)->pixel;
2554 gcValues.stipple = (tabPtr->stipple ? tabPtr->stipple : setPtr->stipple);
2555 if (gcValues.stipple != None) {
2556 gcMask |= GCStipple | GCFillStyle;
2557 gcValues.fill_style = FillStippled;
2558 }
2559 newGC = Tk_GetGC(setPtr->tkwin, gcMask, &gcValues);
2560 if (tabPtr->backGC != NULL) {
2561 Tk_FreeGC(setPtr->display, tabPtr->backGC);
2562 }
2563 tabPtr->backGC = newGC;
2564 /*
2565 * GC for tiled background.
2566 */
2567 if (tabPtr->tile != NULL) {
2568 Blt_SetTileChangedProc(tabPtr->tile, TileChangedProc, setPtr);
2569 }
2570 if (tabPtr->flags & TAB_VISIBLE) {
2571 EventuallyRedraw(setPtr);
2572 }
2573 return TCL_OK;
2574 }
2575
2576 /*
2577 * --------------------------------------------------------------
2578 *
2579 * TearoffEventProc --
2580 *
2581 * This procedure is invoked by the Tk dispatcher for various
2582 * events on the tearoff widget.
2583 *
2584 * Results:
2585 * None.
2586 *
2587 * Side effects:
2588 * When the tearoff gets deleted, internal structures get
2589 * cleaned up. When it gets resized or exposed, it's redisplayed.
2590 *
2591 * --------------------------------------------------------------
2592 */
2593 static void
2594 TearoffEventProc(clientData, eventPtr)
2595 ClientData clientData; /* Information about the tab window. */
2596 XEvent *eventPtr; /* Information about event. */
2597 {
2598 Tab *tabPtr = clientData;
2599
2600 if ((tabPtr == NULL) || (tabPtr->tkwin == NULL) ||
2601 (tabPtr->container == NULL)) {
2602 return;
2603 }
2604 switch (eventPtr->type) {
2605 case Expose:
2606 if (eventPtr->xexpose.count == 0) {
2607 EventuallyRedrawTearoff(tabPtr);
2608 }
2609 break;
2610
2611 case ConfigureNotify:
2612 EventuallyRedrawTearoff(tabPtr);
2613 break;
2614
2615 case DestroyNotify:
2616 if (tabPtr->flags & TAB_REDRAW) {
2617 tabPtr->flags &= ~TAB_REDRAW;
2618 Tcl_CancelIdleCall(DisplayTearoff, clientData);
2619 }
2620 Tk_DestroyWindow(tabPtr->container);
2621 tabPtr->container = NULL;
2622 break;
2623
2624 }
2625 }
2626
2627 /*
2628 * ----------------------------------------------------------------------------
2629 *
2630 * GetReqWidth --
2631 *
2632 * Returns the width requested by the embedded tab window and
2633 * any requested padding around it. This represents the requested
2634 * width of the page.
2635 *
2636 * Results:
2637 * Returns the requested width of the page.
2638 *
2639 * ----------------------------------------------------------------------------
2640 */
2641 static int
2642 GetReqWidth(tabPtr)
2643 Tab *tabPtr;
2644 {
2645 int width;
2646
2647 if (tabPtr->reqWidth > 0) {
2648 width = tabPtr->reqWidth;
2649 } else {
2650 width = Tk_ReqWidth(tabPtr->tkwin);
2651 }
2652 width += PADDING(tabPtr->padX) +
2653 2 * Tk_Changes(tabPtr->tkwin)->border_width;
2654 if (width < 1) {
2655 width = 1;
2656 }
2657 return width;
2658 }
2659
2660 /*
2661 * ----------------------------------------------------------------------------
2662 *
2663 * GetReqHeight --
2664 *
2665 * Returns the height requested by the window and padding around
2666 * the window. This represents the requested height of the page.
2667 *
2668 * Results:
2669 * Returns the requested height of the page.
2670 *
2671 * ----------------------------------------------------------------------------
2672 */
2673 static int
2674 GetReqHeight(tabPtr)
2675 Tab *tabPtr;
2676 {
2677 int height;
2678
2679 if (tabPtr->reqHeight > 0) {
2680 height = tabPtr->reqHeight;
2681 } else {
2682 height = Tk_ReqHeight(tabPtr->tkwin);
2683 }
2684 height += PADDING(tabPtr->padY) +
2685 2 * Tk_Changes(tabPtr->tkwin)->border_width;
2686 if (height < 1) {
2687 height = 1;
2688 }
2689 return height;
2690 }
2691
2692 /*
2693 * ----------------------------------------------------------------------------
2694 *
2695 * TranslateAnchor --
2696 *
2697 * Translate the coordinates of a given bounding box based upon the
2698 * anchor specified. The anchor indicates where the given xy position
2699 * is in relation to the bounding box.
2700 *
2701 * nw --- n --- ne
2702 * | | x,y ---+
2703 * w center e | |
2704 * | | +-----+
2705 * sw --- s --- se
2706 *
2707 * Results:
2708 * The translated coordinates of the bounding box are returned.
2709 *
2710 * ----------------------------------------------------------------------------
2711 */
2712 static void
2713 TranslateAnchor(
2714 int dx, int dy, /* Difference between outer and inner regions
2715 */
2716 Tk_Anchor anchor, /* Direction of the anchor */
2717 int *xPtr, int *yPtr,
2718 int slant)
2719 {
2720 int x, y, w, e;
2721
2722 x = y = w = e = 0;
2723 switch (anchor) {
2724 case TK_ANCHOR_NW: /* Upper left corner */
2725 w = 1;
2726 break;
2727 case TK_ANCHOR_W: /* Left center */
2728 w = 1;
2729 y = (dy / 2);
2730 break;
2731 case TK_ANCHOR_SW: /* Lower left corner */
2732 y = dy;
2733 w = 1;
2734 break;
2735 case TK_ANCHOR_N: /* Top center */
2736 x = (dx / 2);
2737 break;
2738 case TK_ANCHOR_CENTER: /* Centered */
2739 x = (dx / 2);
2740 y = (dy / 2);
2741 break;
2742 case TK_ANCHOR_S: /* Bottom center */
2743 x = (dx / 2);
2744 y = dy;
2745 break;
2746 case TK_ANCHOR_NE: /* Upper right corner */
2747 x = dx;
2748 e = 1;
2749 break;
2750 case TK_ANCHOR_E: /* Right center */
2751 x = dx;
2752 y = (dy / 2);
2753 e = 1;
2754 break;
2755 case TK_ANCHOR_SE: /* Lower right corner */
2756 x = dx;
2757 y = dy;
2758 e = 1;
2759 break;
2760 }
2761 if (slant) {
2762 if (w) {
2763 x += 20;
2764 }
2765 if (e) {
2766 x -= 20;
2767 }
2768 }
2769 *xPtr = (*xPtr) + x;
2770 *yPtr = (*yPtr) + y;
2771 }
2772
2773
2774 static void
2775 GetWindowRectangle(
2776 Tab *tabPtr,
2777 Tk_Window parent,
2778 int tearoff,
2779 XRectangle *rectPtr)
2780 {
2781 int pad;
2782 Tabset *setPtr;
2783 int cavityWidth, cavityHeight;
2784 int width, height;
2785 int dx, dy;
2786 int x, y;
2787
2788 setPtr = tabPtr->setPtr;
2789 pad = setPtr->inset + setPtr->inset2;
2790
2791 if (!tearoff) {
2792 switch (setPtr->side) {
2793 case SIDE_RIGHT:
2794 case SIDE_BOTTOM:
2795 x = setPtr->inset + setPtr->inset2;
2796 y = setPtr->inset + setPtr->inset2;
2797 break;
2798
2799 case SIDE_LEFT:
2800 x = setPtr->pageTop;
2801 y = setPtr->inset + setPtr->inset2;
2802 break;
2803
2804 case SIDE_TOP:
2805 x = setPtr->inset + setPtr->inset2;
2806 y = setPtr->pageTop;
2807 break;
2808 }
2809
2810 if (setPtr->side & SIDE_VERTICAL) {
2811 cavityWidth = Tk_Width(setPtr->tkwin) - (setPtr->pageTop + pad);
2812 cavityHeight = Tk_Height(setPtr->tkwin) - (2 * pad);
2813 } else {
2814 cavityWidth = Tk_Width(setPtr->tkwin) - (2 * pad);
2815 cavityHeight = Tk_Height(setPtr->tkwin) - (setPtr->pageTop + pad);
2816 }
2817
2818 } else {
2819 x = setPtr->inset + setPtr->inset2;
2820 #define TEAR_OFF_TAB_SIZE 5
2821 y = setPtr->inset + setPtr->inset2 + setPtr->yPad + setPtr->outerPad +
2822 TEAR_OFF_TAB_SIZE;
2823 cavityWidth = Tk_Width(parent) - (2 * pad);
2824 cavityHeight = Tk_Height(parent) - (y + pad);
2825 }
2826 cavityWidth -= PADDING(tabPtr->padX);
2827 cavityHeight -= PADDING(tabPtr->padY);
2828 if (cavityWidth < 1) {
2829 cavityWidth = 1;
2830 }
2831 if (cavityHeight < 1) {
2832 cavityHeight = 1;
2833 }
2834 width = GetReqWidth(tabPtr);
2835 height = GetReqHeight(tabPtr);
2836
2837 /*
2838 * Resize the embedded window is of the following is true:
2839 *
2840 * 1) It's been torn off.
2841 * 2) The -fill option (horizontal or vertical) is set.
2842 * 3) the window is bigger than the cavity.
2843 */
2844 if ((tearoff) || (cavityWidth < width) || (tabPtr->fill & FILL_X)) {
2845 width = cavityWidth;
2846 }
2847 if ((tearoff) || (cavityHeight < height) || (tabPtr->fill & FILL_Y)) {
2848 height = cavityHeight;
2849 }
2850 dx = (cavityWidth - width);
2851 dy = (cavityHeight - height);
2852 if ((dx > 0) || (dy > 0)) {
2853 TranslateAnchor(dx, dy, tabPtr->anchor, &x, &y, 0);
2854 }
2855 /* Remember that X11 windows must be at least 1 pixel. */
2856 if (width < 1) {
2857 width = 1;
2858 }
2859 if (height < 1) {
2860 height = 1;
2861 }
2862 rectPtr->x = (short)(x + tabPtr->padLeft);
2863 rectPtr->y = (short)(y + tabPtr->padTop);
2864 rectPtr->width = (short)width;
2865 rectPtr->height = (short)height;
2866 }
2867
2868 static void
2869 ArrangeWindow(
2870 Tk_Window tkwin,
2871 XRectangle *rectPtr,
2872 int force)
2873 {
2874 if ((force) ||
2875 (rectPtr->x != Tk_X(tkwin)) ||
2876 (rectPtr->y != Tk_Y(tkwin)) ||
2877 (rectPtr->width != Tk_Width(tkwin)) ||
2878 (rectPtr->height != Tk_Height(tkwin))) {
2879 Tk_MoveResizeWindow(tkwin, rectPtr->x, rectPtr->y, rectPtr->width,
2880 rectPtr->height);
2881 }
2882 if (!Tk_IsMapped(tkwin)) {
2883 Tk_MapWindow(tkwin);
2884 }
2885 }
2886
2887
2888 /*ARGSUSED*/
2889 static void
2890 GetTags(table, object, context, list)
2891 Blt_BindTable table;
2892 ClientData object;
2893 ClientData context; /* Not used. */
2894 Blt_List list;
2895 {
2896 Tab *tabPtr = (Tab *)object;
2897 Tabset *setPtr;
2898
2899 setPtr = (Tabset *)table->clientData;
2900 if (context == TAB_PERFORATION) {
2901 Blt_ListAppend(list, MakeTag(setPtr, "Perforation"), 0);
2902 } else if (context == TAB_IMAGE) {
2903 Blt_ListAppend(list, MakeTag(setPtr, "Image"), 0);
2904 Blt_ListAppend(list, MakeTag(setPtr, "all"), 0);
2905 } else if (context == TAB_LEFTIMAGE) {
2906 Blt_ListAppend(list, MakeTag(setPtr, "Leftimage"), 0);
2907 Blt_ListAppend(list, MakeTag(setPtr, "all"), 0);
2908 } else if (context == TAB_STARTIMAGE) {
2909 Blt_ListAppend(list, MakeTag(setPtr, "Startimage"), 0);
2910 } else if (context == TAB_ENDIMAGE) {
2911 Blt_ListAppend(list, MakeTag(setPtr, "Endimage"), 0);
2912 } else if (context == TAB_LABEL) {
2913 Blt_ListAppend(list, MakeTag(setPtr, tabPtr->name), 0);
2914 if (tabPtr->tags != NULL) {
2915 int nNames;
2916 char **names;
2917 register char **p;
2918
2919 /*
2920 * This is a space/time trade-off in favor of space. The tags
2921 * are stored as character strings in a hash table. That way,
2922 * tabs can share the strings. It's likely that they will. The
2923 * down side is that the same string is split over an over again.
2924 */
2925 if (strcmp(tabPtr->tags,"all") == 0) {
2926 Blt_ListAppend(list, MakeTag(setPtr, "all"), 0);
2927 } else if (Tcl_SplitList((Tcl_Interp *)NULL, tabPtr->tags, &nNames,
2928 &names) == TCL_OK) {
2929 for (p = names; *p != NULL; p++) {
2930 Blt_ListAppend(list, MakeTag(setPtr, *p), 0);
2931 }
2932 Blt_Free(names);
2933 }
2934 }
2935 }
2936 }
2937
2938 /*
2939 * --------------------------------------------------------------
2940 *
2941 * TabsetEventProc --
2942 *
2943 * This procedure is invoked by the Tk dispatcher for various
2944 * events on tabset widgets.
2945 *
2946 * Results:
2947 * None.
2948 *
2949 * Side Effects:
2950 * When the window gets deleted, internal structures get
2951 * cleaned up. When it gets exposed, it is redisplayed.
2952 *
2953 * --------------------------------------------------------------
2954 */
2955 static void
2956 TabsetEventProc(clientData, eventPtr)
2957 ClientData clientData; /* Information about window. */
2958 XEvent *eventPtr; /* Information about event. */
2959 {
2960 Tabset *setPtr = clientData;
2961
2962 if ((setPtr->flags & TABSET_DESTROYED)) return;
2963
2964 switch (eventPtr->type) {
2965 case Expose:
2966 if (eventPtr->xexpose.count == 0) {
2967 EventuallyRedraw(setPtr);
2968 }
2969 break;
2970
2971 case ConfigureNotify:
2972 setPtr->flags |= (TABSET_LAYOUT | TABSET_SCROLL);
2973 EventuallyRedraw(setPtr);
2974 break;
2975
2976 case FocusIn:
2977 case FocusOut:
2978 if (eventPtr->xfocus.detail != NotifyInferior) {
2979 if (eventPtr->type == FocusIn) {
2980 setPtr->flags |= TABSET_FOCUS;
2981 } else {
2982 setPtr->flags &= ~TABSET_FOCUS;
2983 }
2984 EventuallyRedraw(setPtr);
2985 }
2986 break;
2987
2988 case DestroyNotify:
2989 if (setPtr->tkwin != NULL) {
2990 setPtr->tkwin = NULL;
2991 Tcl_DeleteCommandFromToken(setPtr->interp, setPtr->cmdToken);
2992 }
2993 setPtr->flags |= TABSET_DESTROYED;
2994 if (setPtr->flags & TABSET_REDRAW) {
2995 Tcl_CancelIdleCall(DisplayTabset, setPtr);
2996 }
2997 Tcl_EventuallyFree(setPtr, DestroyTabset);
2998 break;
2999
3000 }
3001 }
3002
3003 /*
3004 * ----------------------------------------------------------------------
3005 *
3006 * DestroyTabset --
3007 *
3008 * This procedure is invoked by Tcl_EventuallyFree or Tcl_Release
3009 * to clean up the internal structure of the widget at a safe
3010 * time (when no-one is using it anymore).
3011 *
3012 * Results:
3013 * None.
3014 *
3015 * Side Effects:
3016 * Everything associated with the widget is freed up.
3017 *
3018 * ----------------------------------------------------------------------
3019 */
3020 static void
3021 DestroyTabset(dataPtr)
3022 DestroyData dataPtr; /* Pointer to the widget record. */
3023 {
3024 Tabset *setPtr = (Tabset *)dataPtr;
3025 Tab *tabPtr;
3026 Blt_ChainLink *linkPtr;
3027
3028 if (setPtr->highlightGC != NULL) {
3029 Tk_FreeGC(setPtr->display, setPtr->highlightGC);
3030 }
3031 if (setPtr->tile != NULL) {
3032 Blt_FreeTile(setPtr->tile);
3033 }
3034 if (setPtr->bgtile != NULL) {
3035 Blt_FreeTile(setPtr->bgtile);
3036 }
3037 if (setPtr->seltile != NULL) {
3038 Blt_FreeTile(setPtr->seltile);
3039 }
3040 if (setPtr->defTabStyle.activeGC != NULL) {
3041 Blt_FreePrivateGC(setPtr->display, setPtr->defTabStyle.activeGC);
3042 }
3043 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
3044 linkPtr = Blt_ChainNextLink(linkPtr)) {
3045 tabPtr = Blt_ChainGetValue(linkPtr);
3046 tabPtr->linkPtr = NULL;
3047 DestroyTab(setPtr, tabPtr);
3048 }
3049 if (setPtr->defTabStyle.image2 != NULL) {
3050 FreeImage(setPtr, setPtr->defTabStyle.image2);
3051 }
3052 if (setPtr->defTabStyle.image != NULL) {
3053 Blt_Free(setPtr->defTabStyle.image);
3054 }
3055 if (setPtr->shadow.color != NULL) {
3056 Tk_FreeColor(setPtr->shadow.color);
3057 }
3058
3059 Blt_ChainDestroy(setPtr->chainPtr);
3060 Blt_DestroyBindingTable(setPtr->bindTable);
3061 Blt_DeleteHashTable(&(setPtr->tabTable));
3062 Blt_DeleteHashTable(&(setPtr->tagTable));
3063 Tk_FreeOptions(configSpecs, (char *)setPtr, setPtr->display, 0);
3064 Blt_Free(setPtr);
3065 }
3066
3067 static void
3068 widgetWorldChanged(ClientData clientData)
3069 {
3070 Tabset *setPtr = (Tabset *)clientData;
3071 setPtr->flags |= (TABSET_LAYOUT | TABSET_SCROLL | TABSET_DIRTY);
3072
3073 EventuallyRedraw(setPtr);
3074 }
3075
3076
3077 /*
3078 * ----------------------------------------------------------------------
3079 *
3080 * CreateTabset --
3081 *
3082 * ----------------------------------------------------------------------
3083 */
3084 static Tabset *
3085 CreateTabset(
3086 Tcl_Interp *interp,
3087 Tk_Window tkwin)
3088 {
3089 Tabset *setPtr;
3090
3091 setPtr = Blt_Calloc(1, sizeof(Tabset));
3092 assert(setPtr);
3093
3094 Tk_SetClass(tkwin, "Tabset");
3095 setPtr->tkwin = tkwin;
3096 setPtr->display = Tk_Display(tkwin);
3097 setPtr->interp = interp;
3098
3099 setPtr->flags |= (TABSET_LAYOUT | TABSET_SCROLL);
3100 setPtr->side = SIDE_TOP;
3101 setPtr->borderWidth = setPtr->highlightWidth = 0;
3102 setPtr->ySelectPad = SELECT_PADY;
3103 setPtr->xSelectPad = SELECT_PADX;
3104 setPtr->relief = TK_RELIEF_SUNKEN;
3105 setPtr->defTabStyle.relief = TK_RELIEF_RAISED;
3106 setPtr->defTabStyle.borderWidth = 1;
3107 setPtr->defTabStyle.constWidth = FALSE;
3108 setPtr->defTabStyle.textSide = SIDE_RIGHT;
3109 setPtr->scrollUnits = 2;
3110 setPtr->corner = CORNER_OFFSET;
3111 setPtr->gap = GAP;
3112 setPtr->outerPad = OUTER_PAD;
3113 setPtr->slant = SLANT_NONE;
3114 setPtr->overlap = 0;
3115 setPtr->tearoff = TRUE;
3116 setPtr->bindTable = Blt_CreateBindingTable(interp, tkwin, setPtr, PickTab,
3117 GetTags);
3118 setPtr->chainPtr = Blt_ChainCreate();
3119 Blt_InitHashTable(&(setPtr->tabTable), BLT_STRING_KEYS);
3120 Blt_InitHashTable(&(setPtr->imageTable), BLT_STRING_KEYS);
3121 Blt_InitHashTable(&(setPtr->tagTable), BLT_STRING_KEYS);
3122 #if (TK_MAJOR_VERSION > 4)
3123 Blt_SetWindowInstanceData(tkwin, setPtr);
3124 #endif
3125 Tk_SetClassProcs(tkwin, &tabsetClass, (ClientData)setPtr);
3126
3127 return setPtr;
3128 }
3129
3130 /*
3131 * ----------------------------------------------------------------------
3132 *
3133 * ConfigureTabset --
3134 *
3135 * This procedure is called to process an argv/argc list, plus
3136 * the Tk option database, in order to configure (or reconfigure)
3137 * the widget.
3138 *
3139 * Results:
3140 * The return value is a standard Tcl result. If TCL_ERROR is
3141 * returned, then interp->result contains an error message.
3142 *
3143 * Side Effects:
3144 * Configuration information, such as text string, colors, font,
3145 * etc. get set for setPtr; old resources get freed, if there
3146 * were any. The widget is redisplayed.
3147 *
3148 * ----------------------------------------------------------------------
3149 */
3150 static int
3151 ConfigureTabset(
3152 Tcl_Interp *interp, /* Interpreter to report errors. */
3153 Tabset *setPtr, /* Information about widget; may or
3154 * may not already have values for
3155 * some fields. */
3156 int argc,
3157 char **argv,
3158 int flags)
3159 {
3160 XGCValues gcValues;
3161 unsigned long gcMask;
3162 GC newGC;
3163 XColor *activeColor; /* Active foreground. */
3164
3165 tabSet = setPtr;
3166 if (Blt_ConfigureWidget(interp, setPtr->tkwin, configSpecs, argc, argv,
3167 (char *)setPtr, flags) != TCL_OK) {
3168 return TCL_ERROR;
3169 }
3170 if (Blt_ConfigModified(configSpecs, interp, "-width", "-height",
3171 "-gap*", "-samewidth", "-tiers", "-fillwidth", "-*side",
3172 "-slant", "-startimage", "-endimage", "-image", "-leftimage",
3173 "-stipple",
3174 (char *)NULL)) {
3175 setPtr->flags |= (TABSET_LAYOUT | TABSET_SCROLL | TABSET_DIRTY);
3176 }
3177 if ((setPtr->reqHeight > 0) && (setPtr->reqWidth > 0)) {
3178 Tk_GeometryRequest(setPtr->tkwin, setPtr->reqWidth, setPtr->reqHeight);
3179 }
3180 /*
3181 * GC for focus highlight.
3182 */
3183 gcMask = GCForeground;
3184 gcValues.foreground = setPtr->highlightColor->pixel;
3185 newGC = Tk_GetGC(setPtr->tkwin, gcMask, &gcValues);
3186 if (setPtr->highlightGC != NULL) {
3187 Tk_FreeGC(setPtr->display, setPtr->highlightGC);
3188 }
3189 setPtr->highlightGC = newGC;
3190
3191 /*
3192 * GC for tiled background.
3193 */
3194 if (setPtr->tile != NULL) {
3195 Blt_SetTileChangedProc(setPtr->tile, TileChangedProc, setPtr);
3196 }
3197 if (setPtr->bgtile != NULL) {
3198 Blt_SetTileChangedProc(setPtr->bgtile, TileChangedProc, setPtr);
3199 }
3200 if (setPtr->seltile != NULL) {
3201 Blt_SetTileChangedProc(setPtr->seltile, TileChangedProc, setPtr);
3202 }
3203 /*
3204 * GC for active line.
3205 */
3206 activeColor = setPtr->defTabStyle.activeFgColor;
3207 if (activeColor == NULL) {
3208 activeColor = setPtr->defTabStyle.textColor;
3209 }
3210 gcMask = GCForeground | GCLineWidth | GCLineStyle | GCCapStyle;
3211 gcValues.foreground = activeColor->pixel;
3212 gcValues.line_width = 0;
3213 gcValues.cap_style = CapProjecting;
3214 gcValues.line_style = (LineIsDashed(setPtr->defTabStyle.dashes))
3215 ? LineOnOffDash : LineSolid;
3216
3217 newGC = Blt_GetPrivateGC(setPtr->tkwin, gcMask, &gcValues);
3218 if (LineIsDashed(setPtr->defTabStyle.dashes)) {
3219 setPtr->defTabStyle.dashes.offset = 2;
3220 Blt_SetDashes(setPtr->display, newGC, &(setPtr->defTabStyle.dashes));
3221 }
3222 if (setPtr->defTabStyle.activeGC != NULL) {
3223 Blt_FreePrivateGC(setPtr->display, setPtr->defTabStyle.activeGC);
3224 }
3225 setPtr->defTabStyle.activeGC = newGC;
3226
3227 setPtr->defTabStyle.rotate = FMOD(setPtr->defTabStyle.rotate, 360.0);
3228 if (setPtr->defTabStyle.rotate < 0.0) {
3229 setPtr->defTabStyle.rotate += 360.0;
3230 }
3231 setPtr->inset = setPtr->highlightWidth + setPtr->borderWidth +
3232 setPtr->outerPad;
3233 if (Blt_ConfigModified(configSpecs, interp, "-font", "-*foreground", "-rotate",
3234 "-*background", "-*side", "-*pad", "-*width", "-*thickness",
3235 "-trunclabel", "-ellipsis", (char *)NULL)) {
3236 Blt_ChainLink *linkPtr;
3237 Tab *tabPtr;
3238
3239 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
3240 linkPtr = Blt_ChainNextLink(linkPtr)) {
3241 tabPtr = Blt_ChainGetValue(linkPtr);
3242 ConfigureTab(setPtr, tabPtr);
3243 }
3244 setPtr->flags |= (TABSET_LAYOUT | TABSET_SCROLL);
3245 }
3246 setPtr->inset2 = setPtr->defTabStyle.borderWidth + setPtr->corner;
3247 EventuallyRedraw(setPtr);
3248 return TCL_OK;
3249 }
3250
3251 /*
3252 * --------------------------------------------------------------
3253 *
3254 * Tabset operations
3255 *
3256 * --------------------------------------------------------------
3257 */
3258 /*
3259 *----------------------------------------------------------------------
3260 *
3261 * ActivateOp --
3262 *
3263 * Selects the tab to appear active.
3264 *
3265 *----------------------------------------------------------------------
3266 */
3267 /*ARGSUSED*/
3268 static int
3269 ActivateOp(setPtr, interp, argc, argv)
3270 Tabset *setPtr;
3271 Tcl_Interp *interp;
3272 int argc; /* Not used. */
3273 char **argv;
3274 {
3275 Tab *tabPtr;
3276 Tab *actPtr, *selPtr;
3277 Drawable drawable;
3278
3279 if (argv[2][0] == '\0') {
3280 tabPtr = NULL;
3281 } else if (GetTabByIndName(setPtr, argv[2], &tabPtr) != TCL_OK) {
3282 return TCL_ERROR;
3283 }
3284 if ((tabPtr != NULL) && (tabPtr->state == STATE_DISABLED)) {
3285 tabPtr = NULL;
3286 }
3287 actPtr = setPtr->activePtr;
3288 setPtr->activePtr = tabPtr;
3289 drawable = Tk_WindowId(setPtr->tkwin);
3290 if (tabPtr != actPtr) {
3291 int redraw;
3292
3293 selPtr = setPtr->selectPtr;
3294 redraw = FALSE;
3295 if (actPtr != NULL) {
3296 redraw = TRUE; /* TODO: Redraw of just label is broken? */
3297 if ((selPtr != NULL) &&
3298 ((actPtr == TabLeft(selPtr)) || (actPtr == TabRight(selPtr)))) {
3299 redraw = TRUE;
3300 }
3301 if ((selPtr != NULL) && (actPtr->tier == 2) &&
3302 (actPtr->worldX + actPtr->worldWidth) >= (selPtr->worldX) &&
3303 (actPtr->worldX < (selPtr->worldX + selPtr->worldWidth))) {
3304 redraw = TRUE;
3305 } else {
3306 DrawLabel(setPtr, actPtr, drawable);
3307 }
3308 }
3309 if ((tabPtr != NULL) && (!redraw)) {
3310 if ((selPtr != NULL) &&
3311 ((tabPtr == TabLeft(selPtr)) || (tabPtr == TabRight(selPtr)))) {
3312 redraw = TRUE;
3313 }
3314 if ((selPtr != NULL) && (tabPtr->tier == 2) &&
3315 (tabPtr->worldX + tabPtr->worldWidth) >= (selPtr->worldX) &&
3316 (tabPtr->worldX < (selPtr->worldX + selPtr->worldWidth))) {
3317 redraw = TRUE;
3318 } else {
3319 DrawLabel(setPtr, tabPtr, drawable);
3320 }
3321 }
3322 DrawOuterBorders(setPtr, drawable);
3323 if (redraw) {
3324 EventuallyRedraw(setPtr);
3325 }
3326 }
3327 return TCL_OK;
3328 }
3329 /*
3330 *----------------------------------------------------------------------
3331 *
3332 * BindOp --
3333 *
3334 * .t bind index sequence command
3335 *
3336 *----------------------------------------------------------------------
3337 */
3338 /*ARGSUSED*/
3339 static int
3340 BindOp(
3341 Tabset *setPtr,
3342 Tcl_Interp *interp,
3343 int argc, /* Not used. */
3344 char **argv)
3345 {
3346 if (argc == 2) {
3347 Blt_HashEntry *hPtr;
3348 Blt_HashSearch cursor;
3349 char *tagName;
3350
3351 for (hPtr = Blt_FirstHashEntry(&(setPtr->tagTable), &cursor);
3352 hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
3353 tagName = Blt_GetHashKey(&(setPtr->tagTable), hPtr);
3354 Tcl_AppendElement(interp, tagName);
3355 }
3356 return TCL_OK;
3357 }
3358 return Blt_ConfigureBindings(interp, setPtr->bindTable,
3359 MakeTag(setPtr, argv[2]), argc - 3, argv + 3);
3360 }
3361
3362 /*
3363 *----------------------------------------------------------------------
3364 *
3365 * CgetOp --
3366 *
3367 *----------------------------------------------------------------------
3368 */
3369 /*ARGSUSED*/
3370 static int
3371 CgetOp(
3372 Tabset *setPtr,
3373 Tcl_Interp *interp,
3374 int argc, /* Not used. */
3375 char **argv)
3376 {
3377 tabSet = setPtr;
3378 return Tk_ConfigureValue(interp, setPtr->tkwin, configSpecs,
3379 (char *)setPtr, argv[2], 0);
3380 }
3381
3382 /*
3383 *----------------------------------------------------------------------
3384 *
3385 * ConfigureOp --
3386 *
3387 * This procedure is called to process an argv/argc list, plus
3388 * the Tk option database, in order to configure (or reconfigure)
3389 * the widget.
3390 *
3391 * Results:
3392 * A standard Tcl result. If TCL_ERROR is returned, then
3393 * interp->result contains an error message.
3394 *
3395 * Side Effects:
3396 * Configuration information, such as text string, colors, font,
3397 * etc. get set for setPtr; old resources get freed, if there
3398 * were any. The widget is redisplayed.
3399 *
3400 *----------------------------------------------------------------------
3401 */
3402 static int
3403 ConfigureOp(
3404 Tabset *setPtr,
3405 Tcl_Interp *interp,
3406 int argc,
3407 char **argv)
3408 {
3409 tabSet = setPtr;
3410 if (argc == 2) {
3411 return Tk_ConfigureInfo(interp, setPtr->tkwin, configSpecs,
3412 (char *)setPtr, (char *)NULL, 0);
3413 } else if (argc == 3) {
3414 return Tk_ConfigureInfo(interp, setPtr->tkwin, configSpecs,
3415 (char *)setPtr, argv[2], 0);
3416 }
3417 if (ConfigureTabset(interp, setPtr, argc - 2, argv + 2,
3418 TK_CONFIG_ARGV_ONLY) != TCL_OK) {
3419 return TCL_ERROR;
3420 }
3421 EventuallyRedraw(setPtr);
3422 return TCL_OK;
3423 }
3424
3425 /*
3426 *----------------------------------------------------------------------
3427 *
3428 * DeleteOp --
3429 *
3430 * Deletes tab from the set. Deletes either a range of
3431 * tabs or a single node.
3432 *
3433 *----------------------------------------------------------------------
3434 */
3435 /*ARGSUSED*/
3436 static int
3437 DeleteOp(
3438 Tabset *setPtr,
3439 Tcl_Interp *interp,
3440 int argc, /* Not used. */
3441 char **argv)
3442 {
3443 Tab *firstPtr, *lastPtr;
3444
3445 lastPtr = NULL;
3446 if (GetTabByIndName(setPtr, argv[2], &firstPtr) != TCL_OK) {
3447 return TCL_ERROR;
3448 }
3449 if ((argc == 4) &&
3450 (GetTabByIndName(setPtr, argv[3], &lastPtr) != TCL_OK)) {
3451 return TCL_ERROR;
3452 }
3453 if (lastPtr == NULL) {
3454 DestroyTab(setPtr, firstPtr);
3455 } else {
3456 Tab *tabPtr;
3457 Blt_ChainLink *linkPtr, *nextLinkPtr;
3458
3459 tabPtr = NULL; /* Suppress compiler warning. */
3460
3461 /* Make sure that the first tab is before the last. */
3462 for (linkPtr = firstPtr->linkPtr; linkPtr != NULL;
3463 linkPtr = Blt_ChainNextLink(linkPtr)) {
3464 tabPtr = Blt_ChainGetValue(linkPtr);
3465 if (tabPtr == lastPtr) {
3466 break;
3467 }
3468 }
3469 if (tabPtr != lastPtr) {
3470 return TCL_OK;
3471 }
3472 linkPtr = firstPtr->linkPtr;
3473 while (linkPtr != NULL) {
3474 nextLinkPtr = Blt_ChainNextLink(linkPtr);
3475 tabPtr = Blt_ChainGetValue(linkPtr);
3476 DestroyTab(setPtr, tabPtr);
3477 linkPtr = nextLinkPtr;
3478 if (tabPtr == lastPtr) {
3479 break;
3480 }
3481 }
3482 }
3483 setPtr->flags |= (TABSET_LAYOUT | TABSET_SCROLL);
3484 EventuallyRedraw(setPtr);
3485 return TCL_OK;
3486 }
3487
3488 /*
3489 *----------------------------------------------------------------------
3490 *
3491 * FocusOp --
3492 *
3493 * Selects the tab to get focus.
3494 *
3495 *----------------------------------------------------------------------
3496 */
3497 /*ARGSUSED*/
3498 static int
3499 FocusOp(
3500 Tabset *setPtr,
3501 Tcl_Interp *interp,
3502 int argc, /* Not used. */
3503 char **argv)
3504 {
3505 Tab *tabPtr;
3506
3507 if (GetTabByIndName(setPtr, argv[2], &tabPtr) != TCL_OK) {
3508 return TCL_ERROR;
3509 }
3510 if (tabPtr != NULL) {
3511 setPtr->focusPtr = tabPtr;
3512 Blt_SetFocusItem(setPtr->bindTable, setPtr->focusPtr, NULL);
3513 EventuallyRedraw(setPtr);
3514 }
3515 return TCL_OK;
3516 }
3517
3518 /*
3519 *----------------------------------------------------------------------
3520 *
3521 * IndexOp --
3522 *
3523 * Converts a string representing a tab index.
3524 *
3525 * Results:
3526 * A standard Tcl result. Interp->result will contain the
3527 * identifier of each index found. If an index could not be found,
3528 * then the serial identifier will be the empty string.
3529 *
3530 *----------------------------------------------------------------------
3531 */
3532 /*ARGSUSED*/
3533 static int
3534 IndexOp(
3535 Tabset *setPtr,
3536 Tcl_Interp *interp,
3537 int argc,
3538 char **argv)
3539 {
3540 Tab *tabPtr;
3541 int search;
3542
3543 #define SEARCH_NAMES 1
3544 #define SEARCH_INDICES 2
3545 #define SEARCH_BOTH 3
3546 search = SEARCH_INDICES;
3547 search = SEARCH_BOTH;
3548 if (argc == 4) {
3549 if (strcmp(argv[2], "-index") == 0) {
3550 search = SEARCH_INDICES;
3551 } else if (strcmp(argv[2], "-name") == 0) {
3552 search = SEARCH_NAMES;
3553 } else if (strcmp(argv[2], "-both") == 0) {
3554 search = SEARCH_BOTH;
3555 } else {
3556 Tcl_AppendResult(interp, "bad switch \"", argv[2],
3557 "\": should be \"-index\", \"-name\" or \"-both\"", (char *)NULL);
3558 return TCL_ERROR;
3559 }
3560 argv++;
3561 }
3562 if (search == SEARCH_BOTH) {
3563 if ((GetTabByName(setPtr, argv[2], &tabPtr) != TCL_OK) &&
3564 (GetTabByIndex(setPtr, argv[2], &tabPtr, INVALID_OK) != TCL_OK)) {
3565 return TCL_ERROR;
3566 }
3567 } else if (search == SEARCH_INDICES) {
3568 if (GetTabByIndex(setPtr, argv[2], &tabPtr, INVALID_OK) != TCL_OK) {
3569 return TCL_ERROR;
3570 }
3571 } else {
3572 if (GetTabByName(setPtr, argv[2], &tabPtr) != TCL_OK) {
3573 return TCL_ERROR;
3574 }
3575 }
3576 if (tabPtr == NULL) {
3577 Tcl_SetResult(interp, "", TCL_STATIC);
3578 } else {
3579 Tcl_SetResult(interp, Blt_Itoa(TabIndex(setPtr, tabPtr)),
3580 TCL_VOLATILE);
3581 }
3582 return TCL_OK;
3583 }
3584
3585 /*
3586 *----------------------------------------------------------------------
3587 *
3588 * GetOp --
3589 *
3590 * Converts a tab index into the tab identifier.
3591 *
3592 * Results:
3593 * A standard Tcl result. Interp->result will contain the
3594 * identifier of each index found. If an index could not be found,
3595 * then the serial identifier will be the empty string.
3596 *
3597 *----------------------------------------------------------------------
3598 */
3599 /*ARGSUSED*/
3600 static int
3601 GetOp(
3602 Tabset *setPtr,
3603 Tcl_Interp *interp,
3604 int argc, /* Not used. */
3605 char **argv)
3606 {
3607 Tab *tabPtr;
3608
3609 if (GetTabByIndName(setPtr, argv[2], &tabPtr) != TCL_OK) {
3610 return TCL_ERROR;
3611 }
3612 if (tabPtr == NULL) {
3613 Tcl_SetResult(interp, "", TCL_STATIC);
3614 } else {
3615 Tcl_SetResult(interp, tabPtr->name, TCL_VOLATILE);
3616 }
3617 return TCL_OK;
3618 }
3619
3620 /*
3621 *----------------------------------------------------------------------
3622 *
3623 * InsertOp --
3624 *
3625 * Add new entries into a tab set.
3626 *
3627 * .t insert end label option-value label option-value...
3628 *
3629 *----------------------------------------------------------------------
3630 */
3631 /*ARGSUSED*/
3632 static int
3633 InsertOp(
3634 Tabset *setPtr,
3635 Tcl_Interp *interp,
3636 int argc, /* Not used. */
3637 char **argv)
3638 {
3639 Tab *tabPtr;
3640 register int i;
3641 char **options;
3642 Blt_ChainLink *linkPtr, *beforeLinkPtr;
3643 int start, count, result = TCL_OK;
3644 char c;
3645 Tcl_DString dStr;
3646
3647 Tcl_DStringInit(&dStr);
3648 c = argv[2][0];
3649 if ((c == 'e') && (strcmp(argv[2], "end") == 0)) {
3650 beforeLinkPtr = NULL;
3651 } else if (isdigit(UCHAR(c))) {
3652 int position;
3653
3654 if (Tcl_GetInt(interp, argv[2], &position) != TCL_OK) {
3655 result = TCL_ERROR;
3656 goto finish;
3657 }
3658 if (position < 0) {
3659 beforeLinkPtr = Blt_ChainFirstLink(setPtr->chainPtr);
3660 } else if (position > Blt_ChainGetLength(setPtr->chainPtr)) {
3661 beforeLinkPtr = NULL;
3662 } else {
3663 beforeLinkPtr = Blt_ChainGetNthLink(setPtr->chainPtr, position);
3664 }
3665 } else {
3666 Tab *beforePtr;
3667
3668 if (GetTabByIndName(setPtr, argv[2], &beforePtr)
3669 != TCL_OK) {
3670 result = TCL_ERROR;
3671 goto finish;
3672 }
3673 beforeLinkPtr = beforePtr->linkPtr;
3674 }
3675 tabSet = setPtr;
3676 setPtr->flags |= (TABSET_LAYOUT | TABSET_SCROLL);
3677 EventuallyRedraw(setPtr);
3678 for (i = 3; i < argc || (argc == 3 && i == 3); /*empty*/ ) {
3679 const char *tName;
3680
3681 if (argc <= 3 || argv[i][0] == 0) {
3682 tName = "#auto";
3683 } else {
3684 tName = argv[i];
3685 }
3686 if (TabExists(setPtr, tName)) {
3687 Tcl_AppendResult(setPtr->interp, "tab \"", tName,
3688 "\" already exists in \"", Tk_PathName(setPtr->tkwin), "\"",
3689 (char *)NULL);
3690 result = TCL_ERROR;
3691 goto finish;
3692 }
3693 tabPtr = CreateTab(setPtr, tName, &dStr);
3694 if (tabPtr == NULL) {
3695 result = TCL_ERROR;
3696 goto finish;
3697 }
3698 /*
3699 * Count the option-value pairs that follow. Count until we
3700 * spot one that doesn't look like a configuration option (i.e.
3701 * doesn't start with a minus "-").
3702 */
3703 i++;
3704 start = i;
3705 for ( /*empty*/ ; i < argc; i += 2) {
3706 if (argv[i][0] != '-') {
3707 break;
3708 }
3709 }
3710 count = i - start;
3711 options = argv + start;
3712 if (Blt_ConfigureWidgetComponent(interp, setPtr->tkwin, tabPtr->name,
3713 "Tab", tabConfigSpecs, count, options, (char *)tabPtr, 0)
3714 != TCL_OK) {
3715 DestroyTab(setPtr, tabPtr);
3716 result = TCL_ERROR;
3717 goto finish;
3718 }
3719 if (ConfigureTab(setPtr, tabPtr) != TCL_OK) {
3720 DestroyTab(setPtr, tabPtr);
3721 result = TCL_ERROR;
3722 goto finish;
3723 }
3724 linkPtr = Blt_ChainNewLink();
3725 if (beforeLinkPtr == NULL) {
3726 Blt_ChainAppendLink(setPtr->chainPtr, linkPtr);
3727 } else {
3728 Blt_ChainLinkBefore(setPtr->chainPtr, linkPtr, beforeLinkPtr);
3729 }
3730 tabPtr->linkPtr = linkPtr;
3731 Blt_ChainSetValue(linkPtr, tabPtr);
3732 /*Tcl_DStringAppendElement(&dStr, Blt_Itoa(TabIndex(setPtr, tabPtr))); */
3733 Tcl_DStringAppendElement(&dStr, tabPtr->name);
3734 }
3735 finish:
3736 if (result == TCL_OK) {
3737 Tcl_DStringResult(interp, &dStr);
3738 } else {
3739 Tcl_DStringFree(&dStr);
3740 }
3741 return result;
3742
3743 }
3744
3745 /*
3746 * Preprocess the command string for percent substitution.
3747 */
3748 static void
3749 PercentSubst(
3750 Tabset *setPtr,
3751 Tab *tabPtr,
3752 char *command,
3753 Tcl_DString *resultPtr)
3754 {
3755 register char *last, *p;
3756 /*
3757 * Get the full path name of the node, in case we need to
3758 * substitute for it.
3759 */
3760 Tcl_DStringInit(resultPtr);
3761 for (last = p = command; *p != '\0'; p++) {
3762 if (*p == '%') {
3763 char *string;
3764 char buf[3];
3765
3766 if (p > last) {
3767 *p = '\0';
3768 Tcl_DStringAppend(resultPtr, last, -1);
3769 *p = '%';
3770 }
3771 switch (*(p + 1)) {
3772 case '%': /* Percent sign */
3773 string = "%";
3774 break;
3775 case 'W': /* Widget name */
3776 string = Tk_PathName(setPtr->tkwin);
3777 break;
3778 case 'i': /* Tab Index */
3779 string = Blt_Itoa(TabIndex(setPtr, tabPtr));
3780 break;
3781 case 'n': /* Tab name */
3782 string = tabPtr->name;
3783 break;
3784 default:
3785 if (*(p + 1) == '\0') {
3786 p--;
3787 }
3788 buf[0] = *p, buf[1] = *(p + 1), buf[2] = '\0';
3789 string = buf;
3790 break;
3791 }
3792 Tcl_DStringAppend(resultPtr, string, -1);
3793 p++;
3794 last = p + 1;
3795 }
3796 }
3797 if (p > last) {
3798 *p = '\0';
3799 Tcl_DStringAppend(resultPtr, last, -1);
3800 }
3801 }
3802
3803 /*
3804 *----------------------------------------------------------------------
3805 *
3806 * InvokeOp --
3807 *
3808 * This procedure is called to invoke a selection command.
3809 *
3810 * .h invoke index
3811 *
3812 * Results:
3813 * A standard Tcl result. If TCL_ERROR is returned, then
3814 * interp->result contains an error message.
3815 *
3816 * Side Effects:
3817 * Configuration information, such as text string, colors, font,
3818 * etc. get set; old resources get freed, if there were any.
3819 * The widget is redisplayed if needed.
3820 *
3821 *----------------------------------------------------------------------
3822 */
3823 /*ARGSUSED*/
3824 static int
3825 InvokeOp(
3826 Tabset *setPtr,
3827 Tcl_Interp *interp, /* Not used. */
3828 int argc,
3829 char **argv)
3830 {
3831 Tab *tabPtr;
3832 char *command;
3833
3834 if (GetTabByIndName(setPtr, argv[2], &tabPtr) != TCL_OK) {
3835 return TCL_ERROR;
3836 }
3837 if ((tabPtr == NULL) || (tabPtr->state == STATE_DISABLED)) {
3838 return TCL_OK;
3839 }
3840 Tcl_Preserve(tabPtr);
3841 command = GETATTR(tabPtr, command);
3842 if (command != NULL) {
3843 Tcl_DString dString;
3844 int result;
3845
3846 PercentSubst(setPtr, tabPtr, command, &dString);
3847 result = Tcl_GlobalEval(setPtr->interp, Tcl_DStringValue(&dString));
3848 Tcl_DStringFree(&dString);
3849 if (result != TCL_OK) {
3850 return TCL_ERROR;
3851 }
3852 }
3853 Tcl_Release(tabPtr);
3854 return TCL_OK;
3855 }
3856
3857 /*
3858 *----------------------------------------------------------------------
3859 *
3860 * MoveOp --
3861 *
3862 * Moves a tab to a new location.
3863 *
3864 *----------------------------------------------------------------------
3865 */
3866 /*ARGSUSED*/
3867 static int
3868 MoveOp(
3869 Tabset *setPtr,
3870 Tcl_Interp *interp,
3871 int argc, /* Not used. */
3872 char **argv)
3873 {
3874 Tab *tabPtr, *linkPtr;
3875 int before;
3876
3877 if (GetTabByIndName(setPtr, argv[2], &tabPtr) != TCL_OK) {
3878 return TCL_ERROR;
3879 }
3880 if ((tabPtr == NULL) || (tabPtr->state == STATE_DISABLED)) {
3881 return TCL_OK;
3882 }
3883 if ((argv[3][0] == 'b') && (strcmp(argv[3], "before") == 0)) {
3884 before = 1;
3885 } else if ((argv[3][0] == 'a') && (strcmp(argv[3], "after") == 0)) {
3886 before = 0;
3887 } else {
3888 Tcl_AppendResult(interp, "bad key word \"", argv[3],
3889 "\": should be \"after\" or \"before\"", (char *)NULL);
3890 return TCL_ERROR;
3891 }
3892 if (GetTabByIndName(setPtr, argv[4], &linkPtr) != TCL_OK) {
3893 return TCL_ERROR;
3894 }
3895 if (tabPtr == linkPtr) {
3896 return TCL_OK;
3897 }
3898 Blt_ChainUnlinkLink(setPtr->chainPtr, tabPtr->linkPtr);
3899 if (before) {
3900 Blt_ChainLinkBefore(setPtr->chainPtr, tabPtr->linkPtr, linkPtr->linkPtr);
3901 } else {
3902 Blt_ChainLinkAfter(setPtr->chainPtr, tabPtr->linkPtr, linkPtr->linkPtr);
3903 }
3904 setPtr->flags |= (TABSET_LAYOUT | TABSET_SCROLL);
3905 EventuallyRedraw(setPtr);
3906 return TCL_OK;
3907 }
3908
3909 /*ARGSUSED*/
3910 static int
3911 NearestOp(setPtr, interp, argc, argv)
3912 Tabset *setPtr;
3913 Tcl_Interp *interp;
3914 int argc; /* Not used. */
3915 char **argv;
3916 {
3917 int x, y; /* Screen coordinates of the test point. */
3918 Tab *tabPtr;
3919 int dw, dh;
3920 char coords[200];
3921
3922 coords[0] = 0;
3923 dw = Tk_Width(setPtr->tkwin);
3924 dh = Tk_Height(setPtr->tkwin);
3925 tabPtr = NULL;
3926 if ((Tk_GetPixels(interp, setPtr->tkwin, argv[2], &x) != TCL_OK) ||
3927 (Tk_GetPixels(interp, setPtr->tkwin, argv[3], &y) != TCL_OK)) {
3928 return TCL_ERROR;
3929 }
3930 if (setPtr->nVisible > 0) {
3931 tabPtr = PickTab(setPtr, x, y, NULL);
3932 if (tabPtr != NULL) {
3933 Tcl_SetResult(interp, tabPtr->name, TCL_VOLATILE);
3934 }
3935 }
3936 if (argc > 4) {
3937 char *where;
3938 int lx, ly;
3939
3940 where = "";
3941 lx = x;
3942 ly = y;
3943 if (setPtr->startImage && lx>=setPtr->siX &&
3944 lx<(setPtr->siX+setPtr->startImage->width) &&
3945 ly>=setPtr->siY && ly<(setPtr->siY+setPtr->startImage->height)) {
3946 where = "startimage";
3947 if (argc > 5) {
3948 sprintf(coords, "%d %d %d %d",
3949 setPtr->siX, setPtr->siY, (setPtr->siX+setPtr->startImage->width),
3950 (setPtr->siY+setPtr->startImage->height));
3951 }
3952 goto done;
3953 }
3954 if (setPtr->endImage && lx>=setPtr->eiX &&
3955 lx<(setPtr->eiX+setPtr->endImage->width) &&
3956 ly>=setPtr->eiY && ly<(setPtr->eiY+setPtr->endImage->height)) {
3957 where = "endimage";
3958 if (argc > 5) {
3959 sprintf(coords, "%d %d %d %d",
3960 setPtr->eiX, setPtr->eiY, (setPtr->eiX+setPtr->endImage->width),
3961 (setPtr->eiY+setPtr->endImage->height));
3962 }
3963 goto done;
3964 }
3965 if (tabPtr == NULL) {
3966 goto done;
3967 }
3968 if (tabPtr->iW && (lx >= tabPtr->iX) && (lx < (tabPtr->iX + tabPtr->iW)) &&
3969 (ly >= tabPtr->iY) && (ly < (tabPtr->iY + tabPtr->iH))) {
3970 where = "image";
3971 if (argc > 5) {
3972 sprintf(coords, "%d %d %d %d",
3973 (tabPtr->iX), (tabPtr->iY), (tabPtr->iX + tabPtr->iW),
3974 (tabPtr->iY + tabPtr->iH));
3975 }
3976 goto done;
3977 }
3978 if (tabPtr->i2W && (lx >= tabPtr->i2X) && (lx < (tabPtr->i2X + tabPtr->i2W)) &&
3979 (ly >= tabPtr->i2Y) && (ly < (tabPtr->i2Y + tabPtr->i2H))) {
3980 where = "leftimage";
3981 if (argc > 5) {
3982 sprintf(coords, "%d %d %d %d",
3983 tabPtr->i2X, tabPtr->i2Y, tabPtr->i2X + tabPtr->i2W,
3984 tabPtr->i2Y + tabPtr->i2H);
3985 }
3986 goto done;
3987 }
3988 if (setPtr->pW && (lx >= setPtr->pX) && (lx < (setPtr->pX + setPtr->pW)) &&
3989 (ly >= setPtr->pY) && (ly < (setPtr->pY + setPtr->pH))) {
3990 where = "perforation";
3991 if (argc > 5) {
3992 sprintf(coords, "%d %d %d %d",
3993 setPtr->pX, setPtr->pY, setPtr->pX + setPtr->pW,
3994 setPtr->pY + setPtr->pH);
3995 }
3996 goto done;
3997 }
3998 if (tabPtr->tW && (lx >= tabPtr->tX) && (lx < (tabPtr->tX + tabPtr->tW)) &&
3999 (ly >= tabPtr->tY) && (ly < (tabPtr->tY + tabPtr->tH))) {
4000 where = "text";
4001 if (argc > 5) {
4002 sprintf(coords, "%d %d %d %d",
4003 tabPtr->tX, tabPtr->tY, tabPtr->tX + tabPtr->tW,
4004 tabPtr->tY + tabPtr->tH);
4005 }
4006 goto done;
4007 }
4008
4009
4010 done:
4011 if (Tcl_SetVar(interp, argv[4], where, TCL_LEAVE_ERR_MSG) == NULL) {
4012 return TCL_ERROR;
4013 }
4014 if (argc > 5) {
4015 if (Tcl_SetVar(interp, argv[5], coords, TCL_LEAVE_ERR_MSG) == NULL) {
4016 return TCL_ERROR;
4017 }
4018 }
4019
4020 }
4021 return TCL_OK;
4022 }
4023
4024 /*ARGSUSED*/
4025 static int
4026 CoordsOp(setPtr, interp, argc, argv)
4027 Tabset *setPtr;
4028 Tcl_Interp *interp;
4029 int argc; /* Not used. */
4030 char **argv;
4031 {
4032 Tab *tabPtr;
4033 int optInd;
4034 char coords[200];
4035 Tcl_Obj *objPtr;
4036
4037 enum optInd {
4038 OP_STARTIMAGE, OP_ENDIMAGE, OP_IMAGE, OP_LEFTIMAGE, OP_PERF, OP_TEXT
4039 };
4040 static char *optArr[] = {
4041 "startimage", "endimage", "image", "leftimage", "perforation", "text", 0
4042 };
4043
4044 coords[0] = 0;
4045 tabPtr = NULL;
4046 objPtr = Tcl_NewStringObj(argv[2], -1);
4047 if (Tcl_GetIndexFromObj(interp, objPtr, optArr, "option", 0, &optInd) != TCL_OK) {
4048 Tcl_DecrRefCount(objPtr);
4049 return TCL_ERROR;
4050 }
4051 Tcl_DecrRefCount(objPtr);
4052 if (argc>3 && GetTabByIndex(setPtr, argv[3], &tabPtr) != TCL_OK) {
4053 return TCL_ERROR; /* Can't find node. */
4054 }
4055 if (tabPtr == NULL && optInd != OP_STARTIMAGE && optInd != OP_STARTIMAGE) {
4056 Tcl_AppendResult(interp, "must provide a tab", 0);
4057 return TCL_ERROR;
4058 }
4059
4060 switch (optInd) {
4061 case OP_STARTIMAGE:
4062 if (setPtr->startImage) {
4063 sprintf(coords, "%d %d %d %d",
4064 setPtr->siX, setPtr->siY, (setPtr->siX+setPtr->startImage->width),
4065 (setPtr->siY+setPtr->startImage->height));
4066 }
4067 break;
4068 case OP_ENDIMAGE:
4069 if (setPtr->endImage) {
4070 sprintf(coords, "%d %d %d %d",
4071 setPtr->eiX, setPtr->eiY, (setPtr->eiX+setPtr->endImage->width),
4072 (setPtr->eiY+setPtr->endImage->height));
4073 }
4074 break;
4075 case OP_IMAGE:
4076 if (tabPtr->iW) {
4077 sprintf(coords, "%d %d %d %d",
4078 (tabPtr->iX), (tabPtr->iY), (tabPtr->iX + tabPtr->iW),
4079 (tabPtr->iY + tabPtr->iH));
4080 }
4081 break;
4082 case OP_LEFTIMAGE:
4083 if (tabPtr->i2W) {
4084 sprintf(coords, "%d %d %d %d",
4085 tabPtr->i2X, tabPtr->i2Y, tabPtr->i2X + tabPtr->i2W,
4086 tabPtr->i2Y + tabPtr->i2H);
4087 }
4088 break;
4089 case OP_PERF:
4090 if (setPtr->pW) {
4091 sprintf(coords, "%d %d %d %d",
4092 setPtr->pX, setPtr->pY, setPtr->pX + setPtr->pW,
4093 setPtr->pY + setPtr->pH);
4094 }
4095 break;
4096 case OP_TEXT:
4097 if (tabPtr->tW) {
4098 sprintf(coords, "%d %d %d %d",
4099 tabPtr->tX, tabPtr->tY, tabPtr->tX + tabPtr->tW,
4100 tabPtr->tY + tabPtr->tH);
4101 }
4102 break;
4103 }
4104
4105 Tcl_SetObjResult(interp, Tcl_NewStringObj(coords, -1));
4106 return TCL_OK;
4107 }
4108
4109 /*
4110 *----------------------------------------------------------------------
4111 *
4112 * SelectOp --
4113 *
4114 * This procedure is called to select a tab.
4115 *
4116 * .h select index
4117 *
4118 * Results:
4119 * A standard Tcl result. If TCL_ERROR is returned, then
4120 * interp->result contains an error message.
4121 *
4122 * Side Effects:
4123 * Configuration information, such as text string, colors, font,
4124 * etc. get set; old resources get freed, if there were any.
4125 * The widget is redisplayed if needed.
4126 *
4127 *----------------------------------------------------------------------
4128 */
4129 /*ARGSUSED*/
4130 static int
4131 SelectOp(
4132 Tabset *setPtr,
4133 Tcl_Interp *interp,
4134 int argc,
4135 char **argv)
4136 {
4137 Tab *tabPtr;
4138
4139 if (GetTabByIndName(setPtr, argv[2], &tabPtr) != TCL_OK) {
4140 return TCL_ERROR;
4141 }
4142 if ((tabPtr == NULL) || (tabPtr->state == STATE_DISABLED)) {
4143 return TCL_OK;
4144 }
4145 if (tabPtr->hidden) {
4146 Tcl_AppendResult(interp, "can not select hidden tab", 0);
4147 return TCL_ERROR;
4148 }
4149 if ((setPtr->selectPtr != NULL) && (setPtr->selectPtr != tabPtr) &&
4150 (setPtr->selectPtr->tkwin != NULL)) {
4151 if (setPtr->selectPtr->container == NULL) {
4152 if (Tk_IsMapped(setPtr->selectPtr->tkwin)) {
4153 Tk_UnmapWindow(setPtr->selectPtr->tkwin);
4154 }
4155 } else {
4156 /* Redraw now unselected container. */
4157 EventuallyRedrawTearoff(setPtr->selectPtr);
4158 }
4159 }
4160 setPtr->selectPtr = tabPtr;
4161 if ((setPtr->nTiers > 1) && setPtr->startPtr &&
4162 (tabPtr->tier != setPtr->startPtr->tier)) {
4163 RenumberTiers(setPtr, tabPtr);
4164 Blt_PickCurrentItem(setPtr->bindTable);
4165 }
4166 setPtr->flags |= (TABSET_SCROLL);
4167 if (tabPtr->container != NULL) {
4168 EventuallyRedrawTearoff(tabPtr);
4169 }
4170 EventuallyRedraw(setPtr);
4171 return TCL_OK;
4172 }
4173
4174 static int
4175 ViewOp(
4176 Tabset *setPtr,
4177 Tcl_Interp *interp,
4178 int argc,
4179 char **argv)
4180 {
4181 int width;
4182
4183 width = VPORTWIDTH(setPtr);
4184 if (argc == 2) {
4185 double fract;
4186
4187 /*
4188 * Note: we are bounding the fractions between 0.0 and 1.0 to
4189 * support the "canvas"-style of scrolling.
4190 */
4191
4192 fract = (double)setPtr->scrollOffset / setPtr->worldWidth;
4193 Tcl_AppendElement(interp, Blt_Dtoa(interp, CLAMP(fract, 0.0, 1.0)));
4194 fract = (double)(setPtr->scrollOffset + width) / setPtr->worldWidth;
4195 Tcl_AppendElement(interp, Blt_Dtoa(interp, CLAMP(fract, 0.0, 1.0)));
4196 return TCL_OK;
4197 }
4198 if (Blt_GetScrollInfo(interp, argc - 2, argv + 2, &(setPtr->scrollOffset),
4199 setPtr->worldWidth, width, setPtr->scrollUnits,
4200 BLT_SCROLL_MODE_CANVAS) != TCL_OK) {
4201 return TCL_ERROR;
4202 }
4203 setPtr->flags |= TABSET_SCROLL;
4204 EventuallyRedraw(setPtr);
4205 return TCL_OK;
4206 }
4207
4208
4209 #if 0
4210 /* OBSOLETE */
4211 static void
4212 AdoptWindow( ClientData clientData)
4213 {
4214 Tab *tabPtr = clientData;
4215 int x, y;
4216 Tabset *setPtr = tabPtr->setPtr;
4217
4218 x = setPtr->inset + setPtr->inset2 + tabPtr->padLeft;
4219 #define TEAR_OFF_TAB_SIZE 5
4220 y = setPtr->inset + setPtr->inset2 + setPtr->yPad +
4221 setPtr->outerPad + TEAR_OFF_TAB_SIZE + tabPtr->padTop;
4222 Blt_RelinkWindow(tabPtr->tkwin, tabPtr->container, x, y);
4223 Tk_MapWindow(tabPtr->tkwin);
4224 }
4225 #endif
4226
4227 static void
4228 DestroyTearoff(dataPtr)
4229 DestroyData dataPtr;
4230 {
4231 Tab *tabPtr = (Tab *)dataPtr;
4232
4233 if (tabPtr->container != NULL) {
4234 Tabset *setPtr;
4235 Tk_Window tkwin;
4236 setPtr = tabPtr->setPtr;
4237
4238 tkwin = tabPtr->container;
4239 if (tabPtr->flags & TAB_REDRAW) {
4240 Tcl_CancelIdleCall(DisplayTearoff, tabPtr);
4241 }
4242 Tk_DeleteEventHandler(tkwin, StructureNotifyMask, TearoffEventProc,
4243 tabPtr);
4244 if (tabPtr->tkwin != NULL) {
4245 XRectangle rect;
4246
4247 GetWindowRectangle(tabPtr, setPtr->tkwin, FALSE, &rect);
4248 Blt_RelinkWindow(tabPtr->tkwin, setPtr->tkwin, rect.x, rect.y);
4249 if (tabPtr == setPtr->selectPtr) {
4250 ArrangeWindow(tabPtr->tkwin, &rect, TRUE);
4251 } else {
4252 Tk_UnmapWindow(tabPtr->tkwin);
4253 }
4254 }
4255 Tk_DestroyWindow(tkwin);
4256 tabPtr->container = NULL;
4257 }
4258 }
4259
4260 #if 0
4261 /* Obsolete. Now uses "wm manage" */
4262 static int
4263 CreateTearoff(
4264 Tabset *setPtr,
4265 char *name,
4266 Tab *tabPtr)
4267 {
4268 Tk_Window tkwin;
4269 int width, height;
4270
4271 tkwin = Tk_CreateWindowFromPath(setPtr->interp, setPtr->tkwin, name,
4272 (char *)NULL);
4273 if (tkwin == NULL) {
4274 return TCL_ERROR;
4275 }
4276 tabPtr->container = tkwin;
4277 if (Tk_WindowId(tkwin) == None) {
4278 Tk_MakeWindowExist(tkwin);
4279 }
4280 Tk_SetClass(tkwin, "Tearoff");
4281 Tk_CreateEventHandler(tkwin, (ExposureMask | StructureNotifyMask),
4282 TearoffEventProc, tabPtr);
4283 if (Tk_WindowId(tabPtr->tkwin) == None) {
4284 Tk_MakeWindowExist(tabPtr->tkwin);
4285 }
4286 width = Tk_Width(tabPtr->tkwin);
4287 if (width < 2) {
4288 width = (tabPtr->reqWidth > 0)
4289 ? tabPtr->reqWidth : Tk_ReqWidth(tabPtr->tkwin);
4290 }
4291 width += PADDING(tabPtr->padX) + 2 *
4292 Tk_Changes(tabPtr->tkwin)->border_width;
4293 width += 2 * (setPtr->inset2 + setPtr->inset);
4294 #define TEAR_OFF_TAB_SIZE 5
4295 height = Tk_Height(tabPtr->tkwin);
4296 if (height < 2) {
4297 height = (tabPtr->reqHeight > 0)
4298 ? tabPtr->reqHeight : Tk_ReqHeight(tabPtr->tkwin);
4299 }
4300 height += PADDING(tabPtr->padY) +
4301 2 * Tk_Changes(tabPtr->tkwin)->border_width;
4302 height += setPtr->inset + setPtr->inset2 + setPtr->yPad +
4303 TEAR_OFF_TAB_SIZE + setPtr->outerPad;
4304 Tk_GeometryRequest(tkwin, width, height);
4305 Tk_UnmapWindow(tabPtr->tkwin);
4306 /* Tk_MoveWindow(tabPtr->tkwin, 0, 0); */
4307 Tcl_SetResult(setPtr->interp, Tk_PathName(tkwin), TCL_VOLATILE);
4308 #ifdef WIN32
4309 AdoptWindow(tabPtr);
4310 #else
4311 Tcl_DoWhenIdle(AdoptWindow, tabPtr);
4312 #endif
4313 return TCL_OK;
4314 }
4315 #endif
4316
4317 /*ARGSUSED*/
4318 static int
4319 SeeOp(
4320 Tabset *setPtr,
4321 Tcl_Interp *interp, /* Not used. */
4322 int argc,
4323 char **argv)
4324 {
4325 Tab *tabPtr;
4326 int left, right, width;
4327
4328 if (GetTabByIndName(setPtr, argv[2], &tabPtr) != TCL_OK) {
4329 return TCL_ERROR;
4330 }
4331 if (tabPtr == NULL) {
4332 return TCL_OK;
4333 }
4334
4335 width = VPORTWIDTH(setPtr);
4336 left = setPtr->scrollOffset + setPtr->xSelectPad;
4337 right = setPtr->scrollOffset + width - setPtr->xSelectPad;
4338
4339 /* If the tab is partially obscured, scroll so that it's
4340 * entirely in view. */
4341 if (tabPtr->worldX < left) {
4342 setPtr->scrollOffset = tabPtr->worldX - TAB_SCROLL_OFFSET;
4343 } else if ((tabPtr->worldX + tabPtr->worldWidth) >= right) {
4344 Blt_ChainLink *linkPtr;
4345
4346 setPtr->scrollOffset = tabPtr->worldX + tabPtr->worldWidth -
4347 (width - 2 * setPtr->xSelectPad);
4348 linkPtr = Blt_ChainNextLink(tabPtr->linkPtr);
4349 if (linkPtr != NULL) {
4350 Tab *nextPtr;
4351
4352 nextPtr = Blt_ChainGetValue(linkPtr);
4353 if (nextPtr->tier == tabPtr->tier) {
4354 setPtr->scrollOffset += TAB_SCROLL_OFFSET;
4355 }
4356 }
4357 }
4358 setPtr->flags |= TABSET_SCROLL;
4359 EventuallyRedraw(setPtr);
4360 return TCL_OK;
4361 }
4362
4363
4364 /*
4365 *----------------------------------------------------------------------
4366 *
4367 * TabCgetOp --
4368 *
4369 * .h tab cget index option
4370 *
4371 *----------------------------------------------------------------------
4372 */
4373 /*ARGSUSED*/
4374 static int
4375 TabCgetOp(setPtr, interp, argc, argv)
4376 Tabset *setPtr;
4377 Tcl_Interp *interp;
4378 int argc; /* Not used. */
4379 char **argv;
4380 {
4381 Tab *tabPtr;
4382
4383 if (GetTabByNameInd(setPtr, argv[3], &tabPtr) != TCL_OK) {
4384 return TCL_ERROR;
4385 }
4386 tabSet = setPtr;
4387 return Tk_ConfigureValue(interp, setPtr->tkwin, tabConfigSpecs,
4388 (char *)tabPtr, argv[4], 0);
4389 }
4390
4391 /*
4392 *----------------------------------------------------------------------
4393 *
4394 * TabConfigureOp --
4395 *
4396 * This procedure is called to process a list of configuration
4397 * options database, in order to reconfigure the options for
4398 * one or more tabs in the widget.
4399 *
4400 * .h tab configure index ?index...? ?option value?...
4401 *
4402 * Results:
4403 * A standard Tcl result. If TCL_ERROR is returned, then
4404 * interp->result contains an error message.
4405 *
4406 * Side Effects:
4407 * Configuration information, such as text string, colors, font,
4408 * etc. get set; old resources get freed, if there were any.
4409 * The widget is redisplayed if needed.
4410 *
4411 *----------------------------------------------------------------------
4412 */
4413 static int
4414 TabConfigureOp(setPtr, interp, argc, argv)
4415 Tabset *setPtr;
4416 Tcl_Interp *interp;
4417 int argc;
4418 char **argv;
4419 {
4420 int nTabs, nOpts, result;
4421 char **options;
4422 register int i;
4423 Tab *tabPtr;
4424
4425 /* Figure out where the option value pairs begin */
4426 argc -= 3;
4427 argv += 3;
4428 for (i = 0; i < argc; i++) {
4429 if (argv[i][0] == '-') {
4430 if (i == 0) {
4431 Tcl_AppendResult(interp, "no tab specified", 0);
4432 return TCL_ERROR;
4433 }
4434 break;
4435 }
4436 if (GetTabByNameInd(setPtr, argv[i], &tabPtr) != TCL_OK) {
4437 return TCL_ERROR; /* Can't find node. */
4438 }
4439 }
4440 nTabs = i; /* Number of tab indices specified */
4441 nOpts = argc - i; /* Number of options specified */
4442 options = argv + i; /* Start of options in argv */
4443
4444 for (i = 0; i < nTabs; i++) {
4445 GetTabByNameInd(setPtr, argv[i], &tabPtr);
4446 if (nOpts == 0) {
4447 return Tk_ConfigureInfo(interp, setPtr->tkwin, tabConfigSpecs,
4448 (char *)tabPtr, (char *)NULL, 0);
4449 } else if (nOpts == 1) {
4450 return Tk_ConfigureInfo(interp, setPtr->tkwin, tabConfigSpecs,
4451 (char *)tabPtr, argv[i+nOpts], 0);
4452 }
4453 tabSet = setPtr;
4454 Tcl_Preserve(tabPtr);
4455 result = Blt_ConfigureWidget(interp, setPtr->tkwin, tabConfigSpecs,
4456 nOpts, options, (char *)tabPtr, TK_CONFIG_ARGV_ONLY);
4457 if (result == TCL_OK || nOpts>=2) {
4458 result = ConfigureTab(setPtr, tabPtr);
4459 }
4460 Tcl_Release(tabPtr);
4461 setPtr->flags |= (TABSET_LAYOUT | TABSET_SCROLL);
4462 if (Blt_ConfigModified(tabConfigSpecs, interp, "-hidden", (char *)NULL)) {
4463 setPtr->flags |= (TABSET_DIRTY);
4464 }
4465 EventuallyRedraw(setPtr);
4466 if (result == TCL_ERROR) {
4467 return TCL_ERROR;
4468 }
4469 }
4470 return TCL_OK;
4471 }
4472
4473 /*
4474 *----------------------------------------------------------------------
4475 *
4476 * TabDockallOp --
4477 *
4478 * .h tab dockall
4479 *
4480 *----------------------------------------------------------------------
4481 */
4482 /*ARGSUSED*/
4483 static int
4484 TabDockallOp(setPtr, interp, argc, argv)
4485 Tabset *setPtr;
4486 Tcl_Interp *interp;
4487 int argc; /* Not used. */
4488 char **argv; /* Not used. */
4489 {
4490 Tab *tabPtr;
4491 Blt_ChainLink *linkPtr;
4492
4493 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
4494 linkPtr = Blt_ChainNextLink(linkPtr)) {
4495 tabPtr = Blt_ChainGetValue(linkPtr);
4496 if (tabPtr->container != NULL) {
4497 Tcl_EventuallyFree(tabPtr, DestroyTearoff);
4498 }
4499 }
4500 return TCL_OK;
4501 }
4502
4503 /*
4504 *----------------------------------------------------------------------
4505 *
4506 * TabPageHeight --
4507 *
4508 * .h tab pageheight
4509 *
4510 *----------------------------------------------------------------------
4511 */
4512 /*ARGSUSED*/
4513 static int
4514 TabPageHeight(setPtr, interp, argc, argv)
4515 Tabset *setPtr;
4516 Tcl_Interp *interp;
4517 int argc; /* Not used. */
4518 char **argv; /* Not used. */
4519 {
4520 Tcl_SetResult(interp, Blt_Itoa(VPORTHEIGHT(setPtr)), TCL_VOLATILE);
4521 return TCL_OK;
4522 }
4523
4524 /*
4525 *----------------------------------------------------------------------
4526 *
4527 * TabPageWidth --
4528 *
4529 * .h tab pagewidth
4530 *
4531 *----------------------------------------------------------------------
4532 */
4533 /*ARGSUSED*/
4534 static int
4535 TabPageWidth(setPtr, interp, argc, argv)
4536 Tabset *setPtr;
4537 Tcl_Interp *interp;
4538 int argc; /* Not used. */
4539 char **argv; /* Not used. */
4540 {
4541 Tcl_SetResult(interp, Blt_Itoa(VPORTWIDTH(setPtr)), TCL_VOLATILE);
4542 return TCL_OK;
4543 }
4544
4545
4546 /*
4547 *----------------------------------------------------------------------
4548 *
4549 * TabNamesOp --
4550 *
4551 * .h tab names pattern
4552 *
4553 *----------------------------------------------------------------------
4554 */
4555 /*ARGSUSED*/
4556 static int
4557 TabNamesOp(setPtr, interp, argc, argv)
4558 Tabset *setPtr;
4559 Tcl_Interp *interp;
4560 int argc; /* Not used. */
4561 char **argv; /* Not used. */
4562 {
4563 Tab *tabPtr;
4564 Blt_ChainLink *linkPtr;
4565 Tcl_DString dStr;
4566 Tcl_DStringInit(&dStr);
4567
4568 if (argc == 3) {
4569 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
4570 linkPtr = Blt_ChainNextLink(linkPtr)) {
4571 tabPtr = Blt_ChainGetValue(linkPtr);
4572 Tcl_DStringAppendElement(&dStr, tabPtr->name);
4573 }
4574 } else {
4575 register int i;
4576
4577 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
4578 linkPtr = Blt_ChainNextLink(linkPtr)) {
4579 tabPtr = Blt_ChainGetValue(linkPtr);
4580 for (i = 3; i < argc; i++) {
4581 if (Tcl_StringMatch(tabPtr->name, argv[i])) {
4582 Tcl_DStringAppendElement(&dStr, tabPtr->name);
4583 break;
4584 }
4585 }
4586 }
4587 }
4588 Tcl_DStringResult(interp, &dStr);
4589 return TCL_OK;
4590 }
4591 /*
4592 *----------------------------------------------------------------------
4593 *
4594 * TabNumberOp --
4595 *
4596 * .h tab number nameorindex
4597 *
4598 *----------------------------------------------------------------------
4599 */
4600 /*ARGSUSED*/
4601 static int
4602 TabNumberOp(setPtr, interp, argc, argv)
4603 Tabset *setPtr;
4604 Tcl_Interp *interp;
4605 int argc; /* Not used. */
4606 char **argv;
4607 {
4608 Tab *tabPtr, *tPtr;
4609 int n = 0;
4610 Blt_ChainLink *linkPtr;
4611
4612 if (GetTabByIndName(setPtr, argv[3], &tabPtr) != TCL_OK) {
4613 return TCL_ERROR;
4614 }
4615 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
4616 linkPtr = Blt_ChainNextLink(linkPtr)) {
4617 tPtr = Blt_ChainGetValue(linkPtr);
4618 if (tPtr == tabPtr) {
4619 Tcl_SetObjResult(interp, Tcl_NewIntObj(n));
4620 break;
4621 }
4622 n++;
4623 }
4624 return TCL_OK;
4625 }
4626
4627 /*
4628 *----------------------------------------------------------------------
4629 *
4630 * TabSelectOp --
4631 *
4632 * .h tab select nameorindex
4633 *
4634 *----------------------------------------------------------------------
4635 */
4636 /*ARGSUSED*/
4637 static int
4638 TabSelectOp(setPtr, interp, argc, argv)
4639 Tabset *setPtr;
4640 Tcl_Interp *interp;
4641 int argc; /* Not used. */
4642 char **argv;
4643 {
4644 int result;
4645 Tcl_DString dStr;
4646 Tab *tabPtr;
4647
4648 if (GetTabByIndName(setPtr, argv[3], &tabPtr) != TCL_OK) {
4649 return TCL_ERROR;
4650 }
4651
4652 if (tabPtr && tabPtr->hidden) {
4653 Tcl_AppendResult(interp, "can not select hidden tab", 0);
4654 return TCL_ERROR;
4655 }
4656 Tcl_DStringInit(&dStr);
4657 Tcl_DStringAppendElement(&dStr, "::blt::TabsetSelect");
4658 Tcl_DStringAppendElement(&dStr, argv[0]);
4659 Tcl_DStringAppendElement(&dStr, argv[3]);
4660 result = Tcl_GlobalEval(interp, Tcl_DStringValue(&dStr));
4661 Tcl_DStringFree(&dStr);
4662 return result;
4663 }
4664
4665 /*
4666 *----------------------------------------------------------------------
4667 *
4668 * TabTearoffOp --
4669 *
4670 * .h tearoff ?index?
4671 *
4672 *----------------------------------------------------------------------
4673 */
4674 /*ARGSUSED*/
4675 static int
4676 TabTearoffOp(setPtr, interp, argc, argv)
4677 Tabset *setPtr;
4678 Tcl_Interp *interp;
4679 int argc; /* Not used. */
4680 char **argv;
4681 {
4682 Tab *tabPtr;
4683 Tcl_DString dStr;
4684
4685 if (argc<=3) {
4686 Blt_ChainLink *linkPtr;
4687 Tcl_DStringInit(&dStr);
4688
4689 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
4690 linkPtr = Blt_ChainNextLink(linkPtr)) {
4691 tabPtr = Blt_ChainGetValue(linkPtr);
4692 if (tabPtr->tornWin != NULL) {
4693 Tcl_DStringAppendElement(&dStr, tabPtr->name);
4694 }
4695 }
4696 Tcl_DStringResult(interp, &dStr);
4697 return TCL_OK;
4698 }
4699 if (GetTabByIndName(setPtr, argv[3], &tabPtr) != TCL_OK) {
4700 return TCL_ERROR;
4701 }
4702 if (tabPtr == NULL) {
4703 return TCL_OK; /* No-op */
4704 }
4705 if (tabPtr->tornWin != NULL) {
4706 Tcl_SetObjResult(interp, Tcl_NewStringObj(tabPtr->tornWin, -1));
4707 } else {
4708 Tcl_SetObjResult(interp, Tcl_NewStringObj(argv[0], -1));
4709 }
4710 return TCL_OK;
4711 }
4712
4713 /*
4714 *----------------------------------------------------------------------
4715 *
4716 * TearoffOp --
4717 *
4718 * .h tearoff ?index ?tab? ?
4719 *
4720 *----------------------------------------------------------------------
4721 */
4722 /*ARGSUSED*/
4723 static int
4724 TearoffOp(setPtr, interp, argc, argv)
4725 Tabset *setPtr;
4726 Tcl_Interp *interp;
4727 int argc; /* Not used. */
4728 char **argv;
4729 {
4730 Tab *tabPtr;
4731 int result;
4732 Tcl_DString dStr;
4733
4734 if (argc<=2) {
4735 Blt_ChainLink *linkPtr;
4736 Tcl_DStringInit(&dStr);
4737
4738 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
4739 linkPtr = Blt_ChainNextLink(linkPtr)) {
4740 tabPtr = Blt_ChainGetValue(linkPtr);
4741 if (tabPtr->tornWin != NULL) {
4742 Tcl_DStringAppendElement(&dStr, tabPtr->name);
4743 }
4744 }
4745 Tcl_DStringResult(interp, &dStr);
4746 return TCL_OK;
4747 }
4748 if (GetTabByIndName(setPtr, argv[2], &tabPtr) != TCL_OK) {
4749 return TCL_ERROR;
4750 }
4751 if ((tabPtr->state == STATE_DISABLED)) {
4752 return TCL_OK; /* No-op */
4753 }
4754 Tcl_Preserve(tabPtr);
4755 result = TCL_OK;
4756
4757 Tcl_ResetResult(interp);
4758
4759 Tcl_DStringInit(&dStr);
4760 Tcl_DStringAppendElement(&dStr, "::blt::TabsetTearoff");
4761 Tcl_DStringAppendElement(&dStr, argv[0]);
4762 Tcl_DStringAppendElement(&dStr, argv[2]);
4763 result = Tcl_GlobalEval(interp, Tcl_DStringValue(&dStr));
4764 Tcl_DStringFree(&dStr);
4765 Tcl_Release(tabPtr);
4766 EventuallyRedraw(setPtr);
4767 return result;
4768 }
4769
4770 /*
4771 *----------------------------------------------------------------------
4772 *
4773 * TabOp --
4774 *
4775 * This procedure handles tab operations.
4776 *
4777 * Results:
4778 * A standard Tcl result.
4779 *
4780 *----------------------------------------------------------------------
4781 */
4782 static Blt_OpSpec tabOps[] =
4783 {
4784 {"cget", 2, (Blt_Op)TabCgetOp, 5, 5, "nameOrIndex option",},
4785 {"configure", 2, (Blt_Op)TabConfigureOp, 4, 0,
4786 "nameOrIndex ?option value?...",},
4787 {"dockall", 1, (Blt_Op)TabDockallOp, 3, 3, "" },
4788 {"names", 1, (Blt_Op)TabNamesOp, 3, 0, "?pattern...?",},
4789 {"number", 1, (Blt_Op)TabNumberOp, 4, 4, "tab",},
4790 {"pageheight", 5, (Blt_Op)TabPageHeight, 3, 3, "", },
4791 {"pagewidth", 5, (Blt_Op)TabPageWidth, 3, 3, "", },
4792 {"select", 1, (Blt_Op)TabSelectOp, 4, 4, "nameOrIndex",},
4793 {"tearoff", 1, (Blt_Op)TabTearoffOp, 3, 4, "?index?",},
4794 };
4795
4796 static int nTabOps = sizeof(tabOps) / sizeof(Blt_OpSpec);
4797
4798 static int
4799 TabOp(setPtr, interp, argc, argv)
4800 Tabset *setPtr;
4801 Tcl_Interp *interp;
4802 int argc;
4803 char **argv;
4804 {
4805 Blt_Op proc;
4806 int result;
4807
4808 proc = Blt_GetOp(interp, nTabOps, tabOps, BLT_OP_ARG2, argc, argv, 0);
4809 if (proc == NULL) {
4810 return TCL_ERROR;
4811 }
4812 result = (*proc) (setPtr, interp, argc, argv);
4813 return result;
4814 }
4815
4816 /*
4817 *----------------------------------------------------------------------
4818 *
4819 * PerforationActivateOp --
4820 *
4821 * This procedure is called to activate (highlight) the
4822 * perforation.
4823 *
4824 * .h perforation activate boolean
4825 *
4826 * Results:
4827 * A standard Tcl result. If TCL_ERROR is returned, then
4828 * interp->result contains an error message.
4829 *
4830 *----------------------------------------------------------------------
4831 */
4832 /*ARGSUSED*/
4833 static int
4834 PerforationActivateOp(setPtr, interp, argc, argv)
4835 Tabset *setPtr;
4836 Tcl_Interp *interp; /* Not used. */
4837 int argc;
4838 char **argv;
4839 {
4840 int bool;
4841
4842 if (Tcl_GetBoolean(interp, argv[3], &bool) != TCL_OK) {
4843 return TCL_ERROR;
4844 }
4845 if (bool) {
4846 setPtr->flags |= PERFORATION_ACTIVE;
4847 } else {
4848 setPtr->flags &= ~PERFORATION_ACTIVE;
4849 }
4850 EventuallyRedraw(setPtr);
4851 return TCL_OK;
4852 }
4853
4854 /*
4855 *----------------------------------------------------------------------
4856 *
4857 * PerforationInvokeOp --
4858 *
4859 * This procedure is called to invoke a perforation command.
4860 *
4861 * .t perforation invoke
4862 *
4863 * Results:
4864 * A standard Tcl result. If TCL_ERROR is returned, then
4865 * interp->result contains an error message.
4866 *
4867 *----------------------------------------------------------------------
4868 */
4869 /*ARGSUSED*/
4870 static int
4871 PerforationInvokeOp(setPtr, interp, argc, argv)
4872 Tabset *setPtr;
4873 Tcl_Interp *interp; /* Not used. */
4874 int argc;
4875 char **argv;
4876 {
4877
4878 if (setPtr->selectPtr != NULL) {
4879 char *cmd;
4880
4881 cmd = GETATTR(setPtr->selectPtr, perfCommand);
4882 if (cmd != NULL) {
4883 Tcl_DString dString;
4884 int result;
4885
4886 PercentSubst(setPtr, setPtr->selectPtr, cmd, &dString);
4887 Tcl_Preserve(setPtr);
4888 result = Tcl_GlobalEval(interp, Tcl_DStringValue(&dString));
4889 Tcl_Release(setPtr);
4890 Tcl_DStringFree(&dString);
4891 if (result != TCL_OK) {
4892 return TCL_ERROR;
4893 }
4894 }
4895 }
4896 return TCL_OK;
4897 }
4898
4899 /*
4900 *----------------------------------------------------------------------
4901 *
4902 * PerforationOp --
4903 *
4904 * This procedure handles tab operations.
4905 *
4906 * Results:
4907 * A standard Tcl result.
4908 *
4909 *----------------------------------------------------------------------
4910 */
4911 static Blt_OpSpec perforationOps[] =
4912 {
4913 {"activate", 1, (Blt_Op)PerforationActivateOp, 4, 4, "boolean" },
4914 {"invoke", 1, (Blt_Op)PerforationInvokeOp, 3, 3, "",},
4915 };
4916
4917 static int nPerforationOps = sizeof(perforationOps) / sizeof(Blt_OpSpec);
4918
4919 static int
4920 PerforationOp(setPtr, interp, argc, argv)
4921 Tabset *setPtr;
4922 Tcl_Interp *interp;
4923 int argc;
4924 char **argv;
4925 {
4926 Blt_Op proc;
4927 int result;
4928
4929 proc = Blt_GetOp(interp, nPerforationOps, perforationOps, BLT_OP_ARG2,
4930 argc, argv, 0);
4931 if (proc == NULL) {
4932 return TCL_ERROR;
4933 }
4934 result = (*proc) (setPtr, interp, argc, argv);
4935 return result;
4936 }
4937
4938 /*
4939 *----------------------------------------------------------------------
4940 *
4941 * ScanOp --
4942 *
4943 * Implements the quick scan.
4944 *
4945 *----------------------------------------------------------------------
4946 */
4947 /*ARGSUSED*/
4948 static int
4949 ScanOp(setPtr, interp, argc, argv)
4950 Tabset *setPtr;
4951 Tcl_Interp *interp;
4952 int argc; /* Not used. */
4953 char **argv;
4954 {
4955 int x, y;
4956 char c;
4957 unsigned int length;
4958 int oper;
4959
4960 #define SCAN_MARK 1
4961 #define SCAN_DRAGTO 2
4962 c = argv[2][0];
4963 length = strlen(argv[2]);
4964 if ((c == 'm') && (strncmp(argv[2], "mark", length) == 0)) {
4965 oper = SCAN_MARK;
4966 } else if ((c == 'd') && (strncmp(argv[2], "dragto", length) == 0)) {
4967 oper = SCAN_DRAGTO;
4968 } else {
4969 Tcl_AppendResult(interp, "bad scan operation \"", argv[2],
4970 "\": should be either \"mark\" or \"dragto\"", (char *)NULL);
4971 return TCL_ERROR;
4972 }
4973 if ((Tk_GetPixels(interp, setPtr->tkwin, argv[3], &x) != TCL_OK) ||
4974 (Tk_GetPixels(interp, setPtr->tkwin, argv[4], &y) != TCL_OK)) {
4975 return TCL_ERROR;
4976 }
4977 if (oper == SCAN_MARK) {
4978 if (setPtr->side & SIDE_VERTICAL) {
4979 setPtr->scanAnchor = y;
4980 } else {
4981 setPtr->scanAnchor = x;
4982 }
4983 setPtr->scanOffset = setPtr->scrollOffset;
4984 } else {
4985 int offset, delta;
4986
4987 if (setPtr->side & SIDE_VERTICAL) {
4988 delta = setPtr->scanAnchor - y;
4989 } else {
4990 delta = setPtr->scanAnchor - x;
4991 }
4992 offset = setPtr->scanOffset + (10 * delta);
4993 offset = Blt_AdjustViewport(offset, setPtr->worldWidth,
4994 VPORTWIDTH(setPtr), setPtr->scrollUnits, BLT_SCROLL_MODE_CANVAS);
4995 setPtr->scrollOffset = offset;
4996 setPtr->flags |= TABSET_SCROLL;
4997 EventuallyRedraw(setPtr);
4998 }
4999 return TCL_OK;
5000 }
5001
5002 /*ARGSUSED*/
5003 static int
5004 SizeOp(setPtr, interp, argc, argv)
5005 Tabset *setPtr;
5006 Tcl_Interp *interp;
5007 int argc; /* Not used. */
5008 char **argv; /* Not used. */
5009 {
5010 Tcl_SetResult(interp, Blt_Itoa(Blt_ChainGetLength(setPtr->chainPtr)),
5011 TCL_VOLATILE);
5012 return TCL_OK;
5013 }
5014
5015
5016 static int
5017 CountTabs(setPtr)
5018 Tabset *setPtr;
5019 {
5020 int count;
5021 int width, height;
5022 Blt_ChainLink *linkPtr;
5023 register Tab *tabPtr;
5024 register int pageWidth, pageHeight;
5025 int labelWidth, labelHeight;
5026 int tabWidth, tabHeight;
5027
5028 pageWidth = pageHeight = 0;
5029 count = 0;
5030
5031 labelWidth = labelHeight = 0;
5032
5033 /*
5034 * Pass 1: Figure out the maximum area needed for a label and a
5035 * page. Both the label and page dimensions are adjusted
5036 * for orientation. In addition, reset the visibility
5037 * flags and reorder the tabs.
5038 */
5039 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5040 linkPtr = Blt_ChainNextLink(linkPtr)) {
5041 tabPtr = Blt_ChainGetValue(linkPtr);
5042
5043 /* Reset visibility flag and order of tabs. */
5044
5045 tabPtr->flags &= ~TAB_VISIBLE;
5046 if (tabPtr->hidden) continue;
5047 count++;
5048
5049 if (tabPtr->tkwin != NULL) {
5050 width = GetReqWidth(tabPtr);
5051 if (pageWidth < width) {
5052 pageWidth = width;
5053 }
5054 height = GetReqHeight(tabPtr);
5055 if (pageHeight < height) {
5056 pageHeight = height;
5057 }
5058 }
5059 if (labelWidth < tabPtr->labelWidth) {
5060 labelWidth = tabPtr->labelWidth;
5061 }
5062 if (labelHeight < tabPtr->labelHeight) {
5063 labelHeight = tabPtr->labelHeight;
5064 }
5065 }
5066
5067 setPtr->overlap = 0;
5068
5069 /* Allow start/end image size to force tab size bigger. */
5070 if (setPtr->side & SIDE_VERTICAL) {
5071 if (setPtr->hMin > labelWidth) labelWidth = setPtr->hMin;
5072 } else {
5073 if (setPtr->hMin > labelHeight) labelHeight = setPtr->hMin;
5074 }
5075
5076 /*
5077 * Pass 2: Set the individual sizes of each tab. This is different
5078 * for constant and variable width tabs. Add the extra space
5079 * needed for slanted tabs, now that we know maximum tab
5080 * height.
5081 */
5082 if (setPtr->defTabStyle.constWidth) {
5083 int slant;
5084
5085 tabWidth = 2 * setPtr->inset2;
5086 tabHeight = setPtr->inset2 /* + 4 */;
5087
5088 if (setPtr->side & SIDE_VERTICAL) {
5089 tabWidth += labelHeight;
5090 tabHeight += labelWidth;
5091 slant = labelWidth;
5092 } else {
5093 tabWidth += labelWidth;
5094 tabHeight += labelHeight;
5095 slant = labelHeight;
5096 }
5097 if (setPtr->slant & SLANT_LEFT) {
5098 tabWidth += slant;
5099 setPtr->overlap += tabHeight / 2;
5100 }
5101 if (setPtr->slant & SLANT_RIGHT) {
5102 tabWidth += slant;
5103 setPtr->overlap += tabHeight / 2;
5104 }
5105 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5106 linkPtr = Blt_ChainNextLink(linkPtr)) {
5107 tabPtr = Blt_ChainGetValue(linkPtr);
5108 tabPtr->worldWidth = tabWidth;
5109 tabPtr->worldHeight = tabHeight;
5110 }
5111 } else {
5112 int slant;
5113
5114 tabWidth = tabHeight = 0;
5115 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5116 linkPtr = Blt_ChainNextLink(linkPtr)) {
5117 tabPtr = Blt_ChainGetValue(linkPtr);
5118 if (tabPtr->hidden) continue;
5119
5120 width = 2 * setPtr->inset2;
5121 height = setPtr->inset2 /* + 4 */;
5122 if (setPtr->side & SIDE_VERTICAL) {
5123 width += tabPtr->labelHeight;
5124 height += labelWidth;
5125 slant = labelWidth;
5126 } else {
5127 width += tabPtr->labelWidth;
5128 height += labelHeight;
5129 slant = labelHeight;
5130 }
5131 width += (setPtr->slant & SLANT_LEFT) ? slant : setPtr->corner;
5132 width += (setPtr->slant & SLANT_RIGHT) ? slant : setPtr->corner;
5133
5134 tabPtr->worldWidth = width; /* + 2 * (setPtr->corner + setPtr->xSelectPad) */ ;
5135 tabPtr->worldHeight = height;
5136
5137 if (tabWidth < width) {
5138 tabWidth = width;
5139 }
5140 if (tabHeight < height) {
5141 tabHeight = height;
5142 }
5143 }
5144 if (setPtr->slant & SLANT_LEFT) {
5145 setPtr->overlap += tabHeight / 2;
5146 }
5147 if (setPtr->slant & SLANT_RIGHT) {
5148 setPtr->overlap += tabHeight / 2;
5149 }
5150 }
5151
5152 setPtr->tabWidth = tabWidth;
5153 setPtr->tabHeight = tabHeight;
5154
5155 /*
5156 * Let the user override any page dimension.
5157 */
5158 setPtr->pageWidth = pageWidth;
5159 setPtr->pageHeight = pageHeight;
5160 if (setPtr->reqPageWidth > 0) {
5161 setPtr->pageWidth = setPtr->reqPageWidth;
5162 }
5163 if (setPtr->reqPageHeight > 0) {
5164 setPtr->pageHeight = setPtr->reqPageHeight;
5165 }
5166 return count;
5167 }
5168
5169
5170 static void
5171 WidenTabs(setPtr, startPtr, nTabs, adjustment)
5172 Tabset *setPtr;
5173 Tab *startPtr;
5174 int nTabs;
5175 int adjustment;
5176 {
5177 register Tab *tabPtr;
5178 register int i;
5179 int ration;
5180 Blt_ChainLink *linkPtr;
5181 int x, sImg;
5182 int vert = (setPtr->side & SIDE_VERTICAL);
5183
5184 sImg = 0;
5185
5186 if (setPtr->startImage) {
5187 sImg = (vert?setPtr->startImage->height:setPtr->startImage->width);
5188 }
5189
5190 x = startPtr->tier;
5191 while (adjustment > 0) {
5192 ration = adjustment / nTabs;
5193 if (ration == 0) {
5194 ration = 1;
5195 }
5196 linkPtr = startPtr->linkPtr;
5197 for (i = 0; (linkPtr != NULL) && (adjustment > 0); ) {
5198 tabPtr = Blt_ChainGetValue(linkPtr);
5199 if (!tabPtr->hidden) {
5200 adjustment -= ration;
5201 tabPtr->worldWidth += ration;
5202 assert(x == tabPtr->tier);
5203 i++;
5204 }
5205 linkPtr = Blt_ChainNextLink(linkPtr);
5206 if (i>=nTabs) break;
5207 }
5208 }
5209 /*
5210 * Go back and reset the world X-coordinates of the tabs,
5211 * now that their widths have changed.
5212 */
5213 x = sImg;
5214 linkPtr = startPtr->linkPtr;
5215 for (i = 0; (i < nTabs) && (linkPtr != NULL); ) {
5216 tabPtr = Blt_ChainGetValue(linkPtr);
5217 if (!tabPtr->hidden) {
5218 tabPtr->worldX = x;
5219 x += tabPtr->worldWidth + setPtr->gap - setPtr->overlap;
5220 i++;
5221 if (i>=nTabs) break;
5222 }
5223 linkPtr = Blt_ChainNextLink(linkPtr);
5224 }
5225 }
5226
5227
5228 static Blt_ChainLink *ChainNextLinkVis(Blt_ChainLink *linkPtr) {
5229 Tab *tabPtr;
5230 while (linkPtr) {
5231 linkPtr = Blt_ChainNextLink(linkPtr);
5232 if (linkPtr == NULL) break;
5233 tabPtr = Blt_ChainGetValue(linkPtr);
5234 if (!tabPtr->hidden) { return linkPtr; }
5235 }
5236 return linkPtr;
5237 }
5238
5239 /* If ntiers>1 adjust last row to fill it out. */
5240 static void
5241 AdjustTabSizes(setPtr, nTabs)
5242 Tabset *setPtr;
5243 int nTabs;
5244 {
5245 int tabsPerTier;
5246 int total, count, extra;
5247 Tab *startPtr, *nextPtr;
5248 Blt_ChainLink *linkPtr;
5249 register Tab *tabPtr;
5250 int x, maxWidth, sImg, eImg;
5251 int vert = (setPtr->side & SIDE_VERTICAL);
5252
5253 sImg = 0;
5254 eImg = 0;
5255
5256 if (setPtr->startImage) {
5257 sImg = (vert?setPtr->startImage->height:setPtr->startImage->width);
5258 }
5259 if (setPtr->endImage) {
5260 eImg = (vert?setPtr->endImage->height:setPtr->endImage->width);
5261 }
5262
5263 tabsPerTier = (nTabs + (setPtr->nTiers - 1)) / setPtr->nTiers;
5264 x = sImg;
5265 maxWidth = 0;
5266 if (setPtr->defTabStyle.constWidth) {
5267 register int i;
5268
5269 linkPtr = Blt_ChainFirstLink(setPtr->chainPtr);
5270 count = 1;
5271 while (linkPtr != NULL) {
5272 for (i = 0; i < tabsPerTier;) {
5273 tabPtr = Blt_ChainGetValue(linkPtr);
5274 if (tabPtr->hidden) {
5275 linkPtr = Blt_ChainNextLink(linkPtr);
5276 continue;
5277 }
5278 i++;
5279 if (i>=tabsPerTier) break;
5280 tabPtr->tier = count;
5281 tabPtr->worldX = x;
5282 x += tabPtr->worldWidth + setPtr->gap - setPtr->overlap;
5283 linkPtr = Blt_ChainNextLink(linkPtr);
5284 if (x > maxWidth) {
5285 maxWidth = x;
5286 }
5287 if (linkPtr == NULL) {
5288 goto done;
5289 }
5290 }
5291 count++;
5292 x = sImg;
5293 }
5294 }
5295 done:
5296 /* Add to tab widths to fill out row. */
5297 if (((nTabs % tabsPerTier) != 0) && (setPtr->defTabStyle.constWidth)) {
5298 return;
5299 }
5300 if (!setPtr->defTabStyle.fillWidth) {
5301 return;
5302 }
5303
5304 startPtr = NULL;
5305 count = total = 0;
5306 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5307 /*empty*/ ) {
5308 tabPtr = Blt_ChainGetValue(linkPtr);
5309 linkPtr = ChainNextLinkVis(linkPtr);
5310 if (tabPtr->hidden) {
5311 continue;
5312 }
5313 if (startPtr == NULL) {
5314 startPtr = tabPtr;
5315 }
5316 count++;
5317 total += tabPtr->worldWidth + setPtr->gap - setPtr->overlap;
5318 if (linkPtr != NULL) {
5319 nextPtr = Blt_ChainGetValue(linkPtr);
5320 if (tabPtr->tier == nextPtr->tier) {
5321 continue;
5322 }
5323 }
5324 total += setPtr->overlap;
5325 extra = setPtr->worldWidth - total;
5326 assert(count > 0);
5327 if (extra > 0) {
5328 WidenTabs(setPtr, startPtr, count, extra);
5329 }
5330 count = total = 0;
5331 startPtr = NULL;
5332 }
5333 }
5334
5335 /*
5336 *
5337 * tabWidth = textWidth + gap + (2 * (pad + outerBW));
5338 *
5339 * tabHeight = textHeight + 2 * (pad + outerBW) + topMargin;
5340 *
5341 */
5342 static void
5343 ComputeLayout(setPtr)
5344 Tabset *setPtr;
5345 {
5346 int width;
5347 Blt_ChainLink *linkPtr;
5348 Tab *tabPtr;
5349 int x, extra, sImg, eImg, vert;
5350 int siw, sih, eiw, eih;
5351 int nTiers, nTabs;
5352
5353 setPtr->nTiers = 0;
5354 setPtr->pageTop = 0;
5355 setPtr->worldWidth = 1;
5356 setPtr->yPad = 0;
5357 sImg = 0;
5358 eImg = 0;
5359 setPtr->hMin = 0;
5360 siw = sih = eiw = eih = 0;
5361 vert = (setPtr->side & SIDE_VERTICAL);
5362
5363 if (setPtr->startImage) {
5364 sih = setPtr->startImage->height;
5365 siw = setPtr->startImage->width;
5366 if (vert) {
5367 sImg = sih;
5368 setPtr->hMin = siw;
5369 } else {
5370 sImg = siw;
5371 setPtr->hMin = sih;
5372 }
5373 }
5374 if (setPtr->endImage) {
5375 eih = setPtr->endImage->height;
5376 eiw = setPtr->endImage->width;
5377 if (vert) {
5378 eImg = eih;
5379 if (eiw>setPtr->hMin) setPtr->hMin = eiw;
5380 } else {
5381 eImg = eiw;
5382 if (eih>setPtr->hMin) setPtr->hMin = eih;
5383 }
5384 if (sImg < eImg) { sImg = eImg; }
5385 }
5386
5387 nTabs = CountTabs(setPtr);
5388 if (nTabs == 0) {
5389 return;
5390 }
5391 /* Reset the pointers to the selected and starting tab. */
5392 if (setPtr->selectPtr == NULL || setPtr->selectPtr->hidden) {
5393 setPtr->selectPtr = NULL;
5394 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr);
5395 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
5396 if (linkPtr == NULL) continue;
5397 tabPtr = Blt_ChainGetValue(linkPtr);
5398 if (tabPtr->hidden) continue;
5399 setPtr->selectPtr = tabPtr;
5400 break;
5401 }
5402 }
5403 if (setPtr->selectPtr == NULL) {
5404 return;
5405 }
5406 if (setPtr->startPtr == NULL) {
5407 setPtr->startPtr = setPtr->selectPtr;
5408 }
5409 if (setPtr->focusPtr == NULL) {
5410 setPtr->focusPtr = setPtr->selectPtr;
5411 Blt_SetFocusItem(setPtr->bindTable, setPtr->focusPtr, NULL);
5412 }
5413
5414 if (setPtr->side & SIDE_VERTICAL) {
5415 width = Tk_Height(setPtr->tkwin) -
5416 2 * (setPtr->corner + setPtr->xSelectPad) - eImg;
5417 } else {
5418 width = Tk_Width(setPtr->tkwin) - (2 * setPtr->inset) -
5419 setPtr->xSelectPad - setPtr->corner - eImg;
5420 }
5421 setPtr->flags |= TABSET_STATIC;
5422 if (setPtr->reqTiers > 1) {
5423 int total, maxWidth;
5424
5425 /* Static multiple tier mode. */
5426
5427 /* Sum tab widths and determine the number of tiers needed. */
5428 nTiers = 1;
5429 total = x = sImg;
5430 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5431 linkPtr = Blt_ChainNextLink(linkPtr)) {
5432 tabPtr = Blt_ChainGetValue(linkPtr);
5433 if (tabPtr->hidden) continue;
5434 if ((x + tabPtr->worldWidth) > width) {
5435 nTiers++;
5436 x = sImg;
5437 }
5438 tabPtr->worldX = x;
5439 tabPtr->tier = nTiers;
5440 extra = tabPtr->worldWidth + setPtr->gap - setPtr->overlap;
5441 total += extra, x += extra;
5442 }
5443 maxWidth = width;
5444
5445 if (nTiers > setPtr->reqTiers) {
5446 /*
5447 * The tabs do not fit into the requested number of tiers.
5448 * Go into scrolling mode.
5449 */
5450 width = ((total + setPtr->tabWidth) / setPtr->reqTiers);
5451 x = sImg;
5452 nTiers = 1;
5453 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr);
5454 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
5455 tabPtr = Blt_ChainGetValue(linkPtr);
5456 if (tabPtr->hidden) continue;
5457 tabPtr->tier = nTiers;
5458 /*
5459 * Keep adding tabs to a tier until we overfill it.
5460 */
5461 tabPtr->worldX = x;
5462 x += tabPtr->worldWidth + setPtr->gap - setPtr->overlap;
5463 if (x > width) {
5464 nTiers++;
5465 if (x > maxWidth) {
5466 maxWidth = x;
5467 }
5468 x = sImg;
5469 }
5470 }
5471 setPtr->flags &= ~TABSET_STATIC;
5472 }
5473 setPtr->worldWidth = maxWidth - sImg;
5474 setPtr->nTiers = nTiers;
5475
5476 if (nTiers > 1) {
5477 AdjustTabSizes(setPtr, nTabs);
5478 }
5479 if (setPtr->flags & TABSET_STATIC) {
5480 setPtr->worldWidth = VPORTWIDTH(setPtr);
5481 } else {
5482 /* Do you add an offset ? */
5483 setPtr->worldWidth += (setPtr->xSelectPad + setPtr->corner);
5484 }
5485 setPtr->worldWidth += setPtr->overlap;
5486 if (setPtr->selectPtr != NULL) {
5487 RenumberTiers(setPtr, setPtr->selectPtr);
5488 }
5489 } else {
5490 /*
5491 * Scrollable single tier mode.
5492 */
5493 nTiers = 1;
5494 x = sImg;
5495 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5496 linkPtr = Blt_ChainNextLink(linkPtr)) {
5497 tabPtr = Blt_ChainGetValue(linkPtr);
5498 if (tabPtr->hidden) continue;
5499 tabPtr->tier = nTiers;
5500 tabPtr->worldX = x;
5501 tabPtr->worldY = 0;
5502 x += tabPtr->worldWidth + setPtr->gap - setPtr->overlap;
5503 }
5504 setPtr->worldWidth = x + setPtr->corner - setPtr->gap +
5505 setPtr->xSelectPad + setPtr->overlap;
5506 setPtr->flags &= ~TABSET_STATIC;
5507 }
5508 if (nTiers == 1) {
5509 setPtr->yPad = setPtr->ySelectPad;
5510 }
5511 setPtr->nTiers = nTiers;
5512 setPtr->pageTop = setPtr->inset + setPtr->yPad /* + 4 */ +
5513 (setPtr->nTiers * setPtr->tabHeight) + setPtr->inset2;
5514
5515 if (setPtr->side & SIDE_VERTICAL) {
5516 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5517 linkPtr = Blt_ChainNextLink(linkPtr)) {
5518 tabPtr = Blt_ChainGetValue(linkPtr);
5519 if (tabPtr->hidden) continue;
5520 tabPtr->screenWidth = (short int)setPtr->tabHeight;
5521 tabPtr->screenHeight = (short int)tabPtr->worldWidth;
5522 }
5523 } else {
5524 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5525 linkPtr = Blt_ChainNextLink(linkPtr)) {
5526 tabPtr = Blt_ChainGetValue(linkPtr);
5527 if (tabPtr->hidden) continue;
5528 tabPtr->screenWidth = (short int)tabPtr->worldWidth;
5529 tabPtr->screenHeight = (short int)setPtr->tabHeight;
5530 }
5531 }
5532 switch (setPtr->side) {
5533 case SIDE_RIGHT:
5534 setPtr->siX = Tk_Width(setPtr->tkwin) - siw - setPtr->inset;
5535 setPtr->siY = setPtr->inset;
5536 setPtr->eiX = Tk_Width(setPtr->tkwin) - eiw - setPtr->inset;
5537 setPtr->eiY = Tk_Height(setPtr->tkwin) - eih - setPtr->inset;
5538 break;
5539
5540 case SIDE_BOTTOM:
5541 setPtr->siX = setPtr->inset;
5542 setPtr->siY = Tk_Height(setPtr->tkwin) - sih - setPtr->inset;
5543 setPtr->eiX = Tk_Width(setPtr->tkwin) - eiw - setPtr->inset;
5544 setPtr->eiY = Tk_Height(setPtr->tkwin) - eih - setPtr->inset;
5545 break;
5546
5547 case SIDE_LEFT:
5548 setPtr->siX = setPtr->inset;
5549 setPtr->siY = setPtr->inset;
5550 setPtr->eiX = setPtr->inset;
5551 setPtr->eiY = Tk_Height(setPtr->tkwin) - eih - setPtr->inset;
5552 break;
5553
5554 case SIDE_TOP:
5555 setPtr->siX = setPtr->inset/2;
5556 if (sih>=setPtr->tabHeight) {
5557 setPtr->siY = 0; /* setPtr->inset; */
5558 } else {
5559 setPtr->siY = (setPtr->tabHeight-sih)/2;
5560 }
5561 if (eih>=setPtr->tabHeight) {
5562 setPtr->eiY = 0; /* setPtr->inset; */
5563 } else {
5564 setPtr->eiY = (setPtr->tabHeight-eih)/2;
5565 }
5566 setPtr->eiX = Tk_Width(setPtr->tkwin) - eiw - setPtr->inset/2;
5567 break;
5568 }
5569 }
5570
5571 static void
5572 ComputeVisibleTabs(setPtr)
5573 Tabset *setPtr;
5574 {
5575 int nVisibleTabs;
5576 register Tab *tabPtr;
5577 Blt_ChainLink *linkPtr;
5578
5579 setPtr->nVisible = 0;
5580 if (Blt_ChainGetLength(setPtr->chainPtr) == 0) {
5581 return;
5582 }
5583 nVisibleTabs = 0;
5584 if (setPtr->flags & TABSET_STATIC) {
5585
5586 /* Static multiple tier mode. */
5587
5588 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5589 linkPtr = Blt_ChainNextLink(linkPtr)) {
5590 tabPtr = Blt_ChainGetValue(linkPtr);
5591 if (tabPtr->hidden) continue;
5592 tabPtr->flags |= TAB_VISIBLE;
5593 nVisibleTabs++;
5594 }
5595 } else {
5596 int width, offset;
5597 /*
5598 * Scrollable (single or multiple) tier mode.
5599 */
5600 offset = setPtr->scrollOffset - (setPtr->outerPad + setPtr->xSelectPad);
5601 width = VPORTWIDTH(setPtr) + setPtr->scrollOffset +
5602 2 * setPtr->outerPad;
5603 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5604 linkPtr = Blt_ChainNextLink(linkPtr)) {
5605 tabPtr = Blt_ChainGetValue(linkPtr);
5606 if (tabPtr->hidden) {
5607 tabPtr->flags &= ~TAB_VISIBLE;
5608 continue;
5609 }
5610 if ((tabPtr->worldX >= width) ||
5611 ((tabPtr->worldX + tabPtr->worldWidth) < offset)) {
5612 tabPtr->flags &= ~TAB_VISIBLE;
5613 } else {
5614 tabPtr->flags |= TAB_VISIBLE;
5615 nVisibleTabs++;
5616 }
5617 }
5618 }
5619 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5620 linkPtr = Blt_ChainNextLink(linkPtr)) {
5621 tabPtr = Blt_ChainGetValue(linkPtr);
5622 if (tabPtr->hidden) continue;
5623 tabPtr->screenX = tabPtr->screenY = -1000;
5624 if (tabPtr->flags & TAB_VISIBLE) {
5625 WorldToScreen(setPtr, tabPtr->worldX, tabPtr->worldY,
5626 &(tabPtr->screenX), &(tabPtr->screenY));
5627 switch (setPtr->side) {
5628 case SIDE_RIGHT:
5629 tabPtr->screenX -= setPtr->tabHeight;
5630 break;
5631
5632 case SIDE_BOTTOM:
5633 tabPtr->screenY -= setPtr->tabHeight;
5634 break;
5635 }
5636 }
5637 }
5638 setPtr->nVisible = nVisibleTabs;
5639 Blt_PickCurrentItem(setPtr->bindTable);
5640 }
5641
5642
5643 static void
5644 Draw3DFolder(setPtr, tabPtr, drawable, side, pointArr, nPoints)
5645 Tabset *setPtr;
5646 Tab *tabPtr;
5647 Drawable drawable;
5648 int side;
5649 XPoint pointArr[];
5650 int nPoints;
5651 {
5652 GC gc;
5653 int relief, borderWidth;
5654 Tk_3DBorder border;
5655 Blt_Tile tile = (tabPtr->tile?tabPtr->tile:setPtr->tile);
5656 /* tile = setPtr->tile; Bug: tabPtr->tile needs to set offset */
5657
5658 if (tabPtr == setPtr->selectPtr) {
5659 border = GETATTR(tabPtr, selBorder);
5660 if (setPtr->seltile) {
5661 tile = setPtr->seltile;
5662 }
5663
5664 } else {
5665 border = tabPtr->border;
5666 }
5667 if (border == NULL) {
5668 border = setPtr->defTabStyle.border;
5669 }
5670 relief = setPtr->defTabStyle.relief;
5671 if ((side == SIDE_RIGHT) || (side == SIDE_TOP)) {
5672 borderWidth = -setPtr->defTabStyle.borderWidth;
5673 if (relief == TK_RELIEF_SUNKEN) {
5674 relief = TK_RELIEF_RAISED;
5675 } else if (relief == TK_RELIEF_RAISED) {
5676 relief = TK_RELIEF_SUNKEN;
5677 }
5678 } else {
5679 borderWidth = setPtr->defTabStyle.borderWidth;
5680 }
5681 /* Draw the outline of the folder. */
5682 gc = Tk_GCForColor(setPtr->shadowColor, drawable);
5683 XDrawLines(setPtr->display, drawable, gc, pointArr, nPoints, CoordModeOrigin);
5684 /* And the folder itself. */
5685 if (Blt_HasTile(tile)) {
5686 Blt_TilePolygon(setPtr->tkwin, drawable, tile, pointArr,
5687 nPoints);
5688 Tk_Draw3DPolygon(setPtr->tkwin, drawable, border, pointArr, nPoints,
5689 borderWidth, relief);
5690 } else {
5691 Tk_Fill3DPolygon(setPtr->tkwin, drawable, border, pointArr, nPoints,
5692 borderWidth, relief);
5693 }
5694 }
5695
5696 /*
5697 * x,y
5698 * |1|2|3| 4 |3|2|1|
5699 *
5700 * 1. tab border width
5701 * 2. corner offset
5702 * 3. label pad
5703 * 4. label width
5704 *
5705 *
5706 */
5707 static void
5708 DrawLabel(setPtr, tabPtr, drawable)
5709 Tabset *setPtr;
5710 Tab *tabPtr;
5711 Drawable drawable;
5712 {
5713 int x, y, dx, dy;
5714 int tx, ty, ix, iy, i2x, i2y, iw, ih, iw2, ih2;
5715 int imgWidth, imgHeight;
5716 int img2Width, img2Height;
5717 int active, selected, labelbg = 0;
5718 XColor *fgColor, *bgColor;
5719 Tk_3DBorder border;
5720 GC gc;
5721
5722 TabImage image;
5723 TabImage image2;
5724
5725 if (!(tabPtr->flags & TAB_VISIBLE)) {
5726 return;
5727 }
5728 x = tabPtr->screenX;
5729 y = tabPtr->screenY;
5730
5731 active = (setPtr->activePtr == tabPtr);
5732 selected = (setPtr->selectPtr == tabPtr);
5733
5734 fgColor = GETATTR(tabPtr, textColor);
5735 border = GETATTR(tabPtr, border);
5736 image = GETATTR(tabPtr, image);
5737 image2 = GETATTR(tabPtr, image2);
5738 if (selected) {
5739 border = GETATTR(tabPtr, selBorder);
5740 }
5741 if (border == NULL) {
5742 border = GETATTR(tabPtr, border);
5743 }
5744 bgColor = Tk_3DBorderColor(border);
5745 if (active) {
5746 Tk_3DBorder activeBorder;
5747
5748 activeBorder = GETATTR(tabPtr, activeBorder);
5749 if (activeBorder == NULL) {
5750 activeBorder = GETATTR(tabPtr, border);
5751 }
5752 bgColor = Tk_3DBorderColor(activeBorder);
5753 } else if (setPtr->defTabStyle.labelBorder != NULL) {
5754 bgColor = Tk_3DBorderColor(setPtr->defTabStyle.labelBorder);
5755 }
5756 dx = 0;
5757 dy = 0;
5758 TranslateAnchor(
5759 (tabPtr->screenWidth - tabPtr->labelWidth),
5760 (tabPtr->screenHeight - tabPtr->labelHeight),
5761 setPtr->anchor, &dx, &dy, setPtr->slant);
5762 /*dx = (tabPtr->screenWidth - tabPtr->labelWidth) / 2;
5763 dy = (tabPtr->screenHeight - tabPtr->labelHeight) / 2;*/
5764
5765
5766 /*
5767 * The label position is computed with screen coordinates. This
5768 * is because both text and image components are oriented in
5769 * screen coordinate space, and not according to the orientation
5770 * of the tabs themselves. That's why we have to consider the
5771 * side when correcting for left/right slants.
5772 */
5773 switch (setPtr->side) {
5774 case SIDE_TOP:
5775 case SIDE_BOTTOM:
5776 if (setPtr->slant == SLANT_LEFT) {
5777 x += setPtr->overlap;
5778 } else if (setPtr->slant == SLANT_RIGHT) {
5779 x -= setPtr->overlap;
5780 }
5781 break;
5782 case SIDE_LEFT:
5783 case SIDE_RIGHT:
5784 if (setPtr->slant == SLANT_LEFT) {
5785 y += setPtr->overlap;
5786 } else if (setPtr->slant == SLANT_RIGHT) {
5787 y -= setPtr->overlap;
5788 }
5789 break;
5790 }
5791
5792 /*
5793 * Draw the active or normal background color over the entire
5794 * label area. This includes both the tab's text and image.
5795 * The rectangle should be 2 pixels wider/taller than this
5796 * area. So if the label consists of just an image, we get an
5797 * halo around the image when the tab is active.
5798 */
5799 gc = Tk_GCForColor(bgColor, drawable);
5800 if ((Blt_HasTile(setPtr->tile) == 0 && Blt_HasTile(tabPtr->tile) == 0 ) || active || selected) {
5801 if (selected == 0 || Blt_HasTile(setPtr->seltile) == 0 || setPtr->defTabStyle.labelBorder != NULL) {
5802 XFillRectangle(setPtr->display, drawable, gc, x + dx, y + dy,
5803 tabPtr->labelWidth, tabPtr->labelHeight);
5804 }
5805 if ((setPtr->flags & TABSET_FOCUS) && (setPtr->focusPtr == tabPtr)) {
5806 XDrawRectangle(setPtr->display, drawable, setPtr->defTabStyle.activeGC,
5807 x + dx, y + dy, tabPtr->labelWidth - 1, tabPtr->labelHeight - 1);
5808 }
5809 } else if (labelbg) {
5810 XFillRectangle(setPtr->display, drawable, gc, x + dx, y + dy,
5811 tabPtr->labelWidth, tabPtr->labelHeight);
5812 }
5813 tx = ty = ix = iy = 0; /* Suppress compiler warning. */
5814
5815 iw = ih = imgWidth = imgHeight = 0;
5816 if (image != NULL) {
5817 iw = imgWidth = ImageWidth(image);
5818 ih = imgHeight = ImageHeight(image);
5819 }
5820 img2Width = img2Height = 0;
5821 if (image2 != NULL) {
5822 iw2 = img2Width = ImageWidth(image2);
5823 ih2 = img2Height = ImageHeight(image2);
5824 if (image == NULL) {
5825 iw = img2Width;
5826 ih = img2Height;
5827 }
5828
5829 }
5830 switch (setPtr->defTabStyle.textSide) {
5831 case SIDE_LEFT:
5832 tx = x + dx + tabPtr->iPadX.side1;
5833 ty = y + (tabPtr->screenHeight - tabPtr->textHeight) / 2;
5834 ix = tx + tabPtr->textWidth + IMAGE_PAD;
5835 iy = y + (tabPtr->screenHeight - ih) / 2;
5836 break;
5837 case SIDE_RIGHT:
5838 ix = x + dx + tabPtr->iPadX.side1 + IMAGE_PAD;
5839 iy = y + (tabPtr->screenHeight - ih) / 2;
5840 tx = ix + imgWidth;
5841 ty = y + (tabPtr->screenHeight - tabPtr->textHeight) / 2;
5842 break;
5843 case SIDE_BOTTOM:
5844 iy = y + dy + tabPtr->iPadY.side1 + IMAGE_PAD;
5845 ix = x + (tabPtr->screenWidth - iw) / 2;
5846 ty = iy + imgHeight;
5847 tx = x + (tabPtr->screenWidth - tabPtr->textWidth) / 2;
5848 break;
5849 case SIDE_TOP:
5850 tx = x + (tabPtr->screenWidth - tabPtr->textWidth) / 2;
5851 ty = y + dy + tabPtr->iPadY.side1 + IMAGE_PAD;
5852 ix = x + (tabPtr->screenWidth - iw) / 2;
5853 iy = ty + tabPtr->textHeight;
5854 break;
5855 }
5856 if (image == NULL) {
5857 tabPtr->iW = 0;
5858 } else {
5859 tabPtr->iX = ix;
5860 tabPtr->iY = iy;
5861 tabPtr->iW = imgWidth;
5862 tabPtr->iH = imgHeight;
5863 Tk_RedrawImage(ImageBits(image), 0, 0, imgWidth, imgHeight,
5864 drawable, ix, iy);
5865 }
5866 if (tabPtr->text == NULL) {
5867 tabPtr->tW = 0;
5868 } else {
5869 TextStyle ts;
5870 XColor *activeColor;
5871 Shadow *shadow;
5872
5873 shadow = (tabPtr->shadow.offset? &tabPtr->shadow : &setPtr->shadow);
5874 activeColor = fgColor;
5875 if (selected) {
5876 activeColor = GETATTR(tabPtr, selColor);
5877 } else if (active) {
5878 activeColor = GETATTR(tabPtr, activeFgColor);
5879 }
5880 if (activeColor == NULL) {
5881 activeColor = GETATTR(tabPtr, textColor);
5882 }
5883 Blt_SetDrawTextStyle(&ts, GETATTR(tabPtr, font), tabPtr->textGC,
5884 fgColor, activeColor, shadow->color,
5885 setPtr->defTabStyle.rotate, TK_ANCHOR_NW, TK_JUSTIFY_LEFT,
5886 0, shadow->offset);
5887 ts.underline = tabPtr->underline;
5888 ts.state = tabPtr->state;
5889 ts.border = border;
5890 ts.padX.side1 = ts.padX.side2 = 2;
5891 if ((selected) || (active)) {
5892 ts.state |= STATE_ACTIVE;
5893 }
5894 Blt_DrawText(setPtr->tkwin, drawable, tabPtr->textDisp, &ts, tx, ty);
5895 tabPtr->tX = tx;
5896 tabPtr->tY = ty;
5897 tabPtr->tW = ts.width;
5898 tabPtr->tH = ts.height;
5899 }
5900 if (image2 == NULL) {
5901 tabPtr->i2W = 0;
5902 return;
5903 }
5904 switch (setPtr->defTabStyle.textSide) {
5905 case SIDE_LEFT:
5906 i2x = ix + imgWidth + IMAGE_PAD + setPtr->gapLeft;
5907 i2y = y + (tabPtr->screenHeight - ih2) / 2;
5908 break;
5909 case SIDE_RIGHT:
5910 i2x = ix + imgWidth + tabPtr->textWidth + IMAGE_PAD + setPtr->gapLeft;
5911 i2y = y + (tabPtr->screenHeight - ih2) / 2;
5912 break;
5913 case SIDE_BOTTOM:
5914 i2y = iy + imgHeight + tabPtr->textHeight + IMAGE_PAD + setPtr->gapLeft;
5915 i2x = x + (tabPtr->screenWidth - iw2) / 2;
5916 break;
5917 case SIDE_TOP:
5918 i2y = iy + imgHeight + IMAGE_PAD + setPtr->gapLeft;
5919 i2x = x + (tabPtr->screenWidth - iw2) / 2;
5920 break;
5921 }
5922 tabPtr->i2X = i2x;
5923 tabPtr->i2Y = i2y;
5924 tabPtr->i2W = img2Width;
5925 tabPtr->i2H = img2Height;
5926 Tk_RedrawImage(ImageBits(image2), 0, 0, img2Width, img2Height,
5927 drawable, i2x, i2y);
5928 }
5929
5930
5931 static void
5932 DrawPerforation(setPtr, tabPtr, drawable)
5933 Tabset *setPtr;
5934 Tab *tabPtr;
5935 Drawable drawable;
5936 {
5937 XPoint pointArr[2];
5938 int x, y;
5939 int segmentWidth, max;
5940 Tk_3DBorder border, perfBorder;
5941
5942 if ((tabPtr->container != NULL) || (tabPtr->tkwin == NULL)) {
5943 return;
5944 }
5945 WorldToScreen(setPtr, tabPtr->worldX + 2,
5946 tabPtr->worldY + tabPtr->worldHeight + 2, &x, &y);
5947 border = GETATTR(tabPtr, selBorder);
5948 if (border == NULL) {
5949 border = GETATTR(tabPtr, border);
5950 }
5951 segmentWidth = 3;
5952 if (setPtr->flags & PERFORATION_ACTIVE) {
5953 perfBorder = GETATTR(tabPtr, activeBorder);
5954 } else {
5955 perfBorder = GETATTR(tabPtr, selBorder);
5956 }
5957 if (perfBorder == NULL) {
5958 perfBorder = GETATTR(tabPtr, border);
5959 }
5960 setPtr->pW = 0;
5961 if (setPtr->side & SIDE_HORIZONTAL) {
5962 pointArr[0].x = x;
5963 pointArr[0].y = pointArr[1].y = y;
5964 max = tabPtr->screenX + tabPtr->screenWidth - 2;
5965 if (Blt_HasTile(setPtr->tile) == 0 && Blt_HasTile(setPtr->seltile) == 0) {
5966 Blt_Fill3DRectangle(setPtr->tkwin, drawable, perfBorder,
5967 x - 2, y - 4, tabPtr->screenWidth, 8, 0, TK_RELIEF_FLAT);
5968 }
5969 setPtr->pX = x - 2;
5970 setPtr->pY = y - 4;
5971 setPtr->pW = tabPtr->screenWidth;
5972 setPtr->pH = 8;
5973 while (pointArr[0].x < max) {
5974 pointArr[1].x = pointArr[0].x + segmentWidth;
5975 if (pointArr[1].x > max) {
5976 pointArr[1].x = max;
5977 }
5978 Tk_Draw3DPolygon(setPtr->tkwin, drawable, border, pointArr, 2, 1,
5979 TK_RELIEF_RAISED);
5980 pointArr[0].x += 2 * segmentWidth;
5981 }
5982 } else {
5983 pointArr[0].x = pointArr[1].x = x;
5984 pointArr[0].y = y;
5985 max = tabPtr->screenY + tabPtr->screenHeight - 2;
5986 if (Blt_HasTile(setPtr->tile) == 0) {
5987 Blt_Fill3DRectangle(setPtr->tkwin, drawable, perfBorder,
5988 x - 4, y - 2, 8, tabPtr->screenHeight, 0, TK_RELIEF_FLAT);
5989 }
5990 setPtr->pX = x - 4;
5991 setPtr->pY = y - 2;
5992 setPtr->pH = tabPtr->screenHeight;
5993 setPtr->pW = 8;
5994 while (pointArr[0].y < max) {
5995 pointArr[1].y = pointArr[0].y + segmentWidth;
5996 if (pointArr[1].y > max) {
5997 pointArr[1].y = max;
5998 }
5999 Tk_Draw3DPolygon(setPtr->tkwin, drawable, border, pointArr, 2, 1,
6000 TK_RELIEF_RAISED);
6001 pointArr[0].y += 2 * segmentWidth;
6002 }
6003 }
6004 }
6005
6006 #define NextPoint(px, py) \
6007 pointPtr->x = (px), pointPtr->y = (py), pointPtr++, nPoints++
6008 #define EndPoint(px, py) \
6009 pointPtr->x = (px), pointPtr->y = (py), nPoints++
6010
6011 #define BottomLeft(px, py) \
6012 NextPoint((px) + setPtr->corner, (py)), \
6013 NextPoint((px), (py) - setPtr->corner)
6014
6015 #define TopLeft(px, py) \
6016 NextPoint((px), (py) + setPtr->corner), \
6017 NextPoint((px) + setPtr->corner, (py))
6018
6019 #define TopRight(px, py) \
6020 NextPoint((px) - setPtr->corner, (py)), \
6021 NextPoint((px), (py) + setPtr->corner)
6022
6023 #define BottomRight(px, py) \
6024 NextPoint((px), (py) - setPtr->corner), \
6025 NextPoint((px) - setPtr->corner, (py))
6026
6027
6028 /*
6029 * From the left edge:
6030 *
6031 * |a|b|c|d|e| f |d|e|g|h| i |h|g|e|d|f| j |e|d|c|b|a|
6032 *
6033 * a. highlight ring
6034 * b. tabset 3D border
6035 * c. outer gap
6036 * d. page border
6037 * e. page corner
6038 * f. gap + select pad
6039 * g. label pad x (worldX)
6040 * h. internal pad x
6041 * i. label width
6042 * j. rest of page width
6043 *
6044 * worldX, worldY
6045 * |
6046 * |
6047 * * 4+ . . +5
6048 * 3+ +6
6049 * . .
6050 * . .
6051 * 1+. . .2+ +7 . . . .+8
6052 * 0+ +9
6053 * . .
6054 * . .
6055 *13+ +10
6056 * 12+-------------------------+11
6057 *
6058 */
6059 static void
6060 DrawFolder(setPtr, tabPtr, drawable)
6061 Tabset *setPtr;
6062 Tab *tabPtr;
6063 Drawable drawable;
6064 {
6065 XPoint pointArr[16];
6066 XPoint *pointPtr;
6067 int width, height;
6068 int left, bottom, right, top, yBot, yTop;
6069 int x, y;
6070 register int i;
6071 int nPoints;
6072
6073 width = VPORTWIDTH(setPtr);
6074 height = VPORTHEIGHT(setPtr);
6075
6076 x = tabPtr->worldX;
6077 y = tabPtr->worldY;
6078
6079 nPoints = 0;
6080 pointPtr = pointArr;
6081
6082 /* Remember these are all world coordinates. */
6083 /*
6084 * x Left side of tab.
6085 * y Top of tab.
6086 * yTop Top of folder.
6087 * yBot Bottom of the tab.
6088 * left Left side of the folder.
6089 * right Right side of the folder.
6090 * top Top of folder.
6091 * bottom Bottom of folder.
6092 */
6093 left = setPtr->scrollOffset - setPtr->xSelectPad;
6094 right = left + width;
6095 yTop = y + tabPtr->worldHeight;
6096 yBot = setPtr->pageTop - (setPtr->inset + setPtr->yPad);
6097 top = yBot - setPtr->inset2 /* - 4 */;
6098
6099 if (setPtr->pageHeight == 0) {
6100 bottom = yBot + 2 * setPtr->corner;
6101 } else {
6102 bottom = height - setPtr->yPad - 1;
6103 }
6104 if (tabPtr != setPtr->selectPtr) {
6105
6106 /*
6107 * Case 1: Unselected tab
6108 *
6109 * * 3+ . . +4
6110 * 2+ +5
6111 * . .
6112 * 1+ +6
6113 * 0+ . . +7
6114 *
6115 */
6116
6117 if (setPtr->slant & SLANT_LEFT) {
6118 NextPoint(x, yBot);
6119 NextPoint(x, yTop);
6120 NextPoint(x + setPtr->tabHeight, y);
6121 } else {
6122 BottomLeft(x, yBot);
6123 TopLeft(x, y);
6124 }
6125 x += tabPtr->worldWidth;
6126 if (setPtr->slant & SLANT_RIGHT) {
6127 NextPoint(x - setPtr->tabHeight, y);
6128 NextPoint(x, yTop);
6129 NextPoint(x, yBot);
6130 } else {
6131 TopRight(x, y);
6132 BottomRight(x, yBot);
6133 }
6134
6135 } else if (!(tabPtr->flags & TAB_VISIBLE)) {
6136
6137 /*
6138 * Case 2: Selected tab not visible in viewport. Draw folder only.
6139 *
6140 * * 3+ . . +4
6141 * 2+ +5
6142 * . .
6143 * 1+ +6
6144 * 0+------+7
6145 *
6146 */
6147
6148 TopLeft(left, top);
6149 TopRight(right, top);
6150 BottomRight(right, bottom);
6151 BottomLeft(left, bottom);
6152 } else {
6153 int flags;
6154 int tabWidth;
6155
6156 x -= setPtr->xSelectPad;
6157 y -= setPtr->yPad;
6158 tabWidth = tabPtr->worldWidth + 2 * setPtr->xSelectPad;
6159
6160 #define CLIP_NONE 0
6161 #define CLIP_LEFT (1<<0)
6162 #define CLIP_RIGHT (1<<1)
6163 flags = 0;
6164 if (x < left) {
6165 flags |= CLIP_LEFT;
6166 }
6167 if ((x + tabWidth) > right) {
6168 flags |= CLIP_RIGHT;
6169 }
6170 switch (flags) {
6171 case CLIP_NONE:
6172
6173 /*
6174 * worldX, worldY
6175 * |
6176 * * 4+ . . +5
6177 * 3+ +6
6178 * . .
6179 * . .
6180 * 1+. . .2+ +7 . . . .+8
6181 * 0+ +9
6182 * . .
6183 * . .
6184 *13+ +10
6185 * 12+-------------------------+11
6186 */
6187
6188 if (x < (left + setPtr->corner)) {
6189 NextPoint(left, top);
6190 } else {
6191 TopLeft(left, top);
6192 }
6193 if (setPtr->slant & SLANT_LEFT) {
6194 NextPoint(x, yTop);
6195 NextPoint(x + setPtr->tabHeight + setPtr->yPad, y);
6196 } else {
6197 NextPoint(x, top);
6198 TopLeft(x, y);
6199 }
6200 x += tabWidth;
6201 if (setPtr->slant & SLANT_RIGHT) {
6202 NextPoint(x - setPtr->tabHeight - setPtr->yPad, y);
6203 NextPoint(x, yTop);
6204 } else {
6205 TopRight(x, y);
6206 NextPoint(x, top);
6207 }
6208 if (x > (right - setPtr->corner)) {
6209 NextPoint(right, top + setPtr->corner);
6210 } else {
6211 TopRight(right, top);
6212 }
6213 BottomRight(right, bottom);
6214 BottomLeft(left, bottom);
6215 break;
6216
6217 case CLIP_LEFT:
6218
6219 /*
6220 * worldX, worldY
6221 * |
6222 * * 4+ . . +5
6223 * 3+ +6
6224 * . .
6225 * . .
6226 * 2+ +7 . . . .+8
6227 * 1+ . . . +0 +9
6228 * . .
6229 * . .
6230 * 13+ +10
6231 * 12+--------+11
6232 */
6233
6234 NextPoint(left, yBot);
6235 if (setPtr->slant & SLANT_LEFT) {
6236 NextPoint(x, yBot);
6237 NextPoint(x, yTop);
6238 NextPoint(x + setPtr->tabHeight + setPtr->yPad, y);
6239 } else {
6240 BottomLeft(x, yBot);
6241 TopLeft(x, y);
6242 }
6243
6244 x += tabWidth;
6245 if (setPtr->slant & SLANT_RIGHT) {
6246 NextPoint(x - setPtr->tabHeight - setPtr->yPad, y);
6247 NextPoint(x, yTop);
6248 NextPoint(x, top);
6249 } else {
6250 TopRight(x, y);
6251 NextPoint(x, top);
6252 }
6253 if (x > (right - setPtr->corner)) {
6254 NextPoint(right, top + setPtr->corner);
6255 } else {
6256 TopRight(right, top);
6257 }
6258 /* TopRight(right, top); */
6259 BottomRight(right, bottom);
6260 BottomLeft(left, bottom);
6261 break;
6262
6263 case CLIP_RIGHT:
6264
6265 /*
6266 * worldX, worldY
6267 * |
6268 * * 9+ . . +10
6269 * 8+ +11
6270 * . .
6271 * . .
6272 * 6+ . . . .7+ +12
6273 * 5+ 0+ . . . +13
6274 * . .
6275 * . .
6276 * 4+ +1
6277 * 3+-------+2
6278 */
6279
6280 NextPoint(right, yBot);
6281 BottomRight(right, bottom);
6282 BottomLeft(left, bottom);
6283 /* TopLeft(left, top); */
6284 if (x < (left + setPtr->corner)) {
6285 NextPoint(left, top);
6286 } else {
6287 TopLeft(left, top);
6288 }
6289 NextPoint(x, top);
6290
6291 if (setPtr->slant & SLANT_LEFT) {
6292 NextPoint(x, yTop);
6293 NextPoint(x + setPtr->tabHeight + setPtr->yPad, y);
6294 } else {
6295 TopLeft(x, y);
6296 }
6297 x += tabWidth;
6298 if (setPtr->slant & SLANT_RIGHT) {
6299 NextPoint(x - setPtr->tabHeight - setPtr->yPad, y);
6300 NextPoint(x, yTop);
6301 NextPoint(x, yBot);
6302 } else {
6303 TopRight(x, y);
6304 BottomRight(x, yBot);
6305 }
6306 break;
6307
6308 case (CLIP_LEFT | CLIP_RIGHT):
6309
6310 /*
6311 * worldX, worldY
6312 * |
6313 * * 4+ . . . . . . . . +5
6314 * 3+ +6
6315 * . .
6316 * . .
6317 * 1+ +7
6318 * 2+ 0+ +9 .+8
6319 * . .
6320 * . .
6321 * 13+ +10
6322 * 12+-------+11
6323 */
6324
6325 NextPoint(left, yBot);
6326 if (setPtr->slant & SLANT_LEFT) {
6327 NextPoint(x, yBot);
6328 NextPoint(x, yTop);
6329 NextPoint(x + setPtr->tabHeight + setPtr->yPad, y);
6330 } else {
6331 BottomLeft(x, yBot);
6332 TopLeft(x, y);
6333 }
6334 x += tabPtr->worldWidth;
6335 if (setPtr->slant & SLANT_RIGHT) {
6336 NextPoint(x - setPtr->tabHeight - setPtr->yPad, y);
6337 NextPoint(x, yTop);
6338 NextPoint(x, yBot);
6339 } else {
6340 TopRight(x, y);
6341 BottomRight(x, yBot);
6342 }
6343 NextPoint(right, yBot);
6344 BottomRight(right, bottom);
6345 BottomLeft(left, bottom);
6346 break;
6347 }
6348 }
6349 EndPoint(pointArr[0].x, pointArr[0].y);
6350 for (i = 0; i < nPoints; i++) {
6351 WorldToScreen(setPtr, pointArr[i].x, pointArr[i].y, &x, &y);
6352 pointArr[i].x = x;
6353 pointArr[i].y = y;
6354 }
6355 Draw3DFolder(setPtr, tabPtr, drawable, setPtr->side, pointArr, nPoints);
6356 DrawLabel(setPtr, tabPtr, drawable);
6357 if (tabPtr->container != NULL) {
6358 XRectangle rect;
6359
6360 /* Draw a rectangle covering the spot representing the window */
6361 GetWindowRectangle(tabPtr, setPtr->tkwin, FALSE, &rect);
6362 XFillRectangles(setPtr->display, drawable, tabPtr->backGC,
6363 &rect, 1);
6364 }
6365 }
6366
6367 static void
6368 DrawOuterBorders(setPtr, drawable)
6369 Tabset *setPtr;
6370 Drawable drawable;
6371 {
6372 /*
6373 * Draw 3D border just inside of the focus highlight ring. We
6374 * draw the border even if the relief is flat so that any tabs
6375 * that hang over the edge will be clipped.
6376 */
6377 if (setPtr->borderWidth > 0) {
6378 Blt_Draw3DRectangle(setPtr->tkwin, drawable, setPtr->border,
6379 setPtr->highlightWidth, setPtr->highlightWidth,
6380 Tk_Width(setPtr->tkwin) - 2 * setPtr->highlightWidth,
6381 Tk_Height(setPtr->tkwin) - 2 * setPtr->highlightWidth,
6382 setPtr->borderWidth, setPtr->relief);
6383 }
6384 /* Draw focus highlight ring. */
6385 if (setPtr->highlightWidth > 0) {
6386 XColor *color;
6387 GC gc;
6388
6389 color = (setPtr->flags & TABSET_FOCUS)
6390 ? setPtr->highlightColor : setPtr->highlightBgColor;
6391 gc = Tk_GCForColor(color, drawable);
6392 Tk_DrawFocusHighlight(setPtr->tkwin, gc, setPtr->highlightWidth,
6393 drawable);
6394 }
6395 }
6396
6397 /*
6398 * ----------------------------------------------------------------------
6399 *
6400 * DisplayTabset --
6401 *
6402 * This procedure is invoked to display the widget.
6403 *
6404 * Recomputes the layout of the widget if necessary. This is
6405 * necessary if the world coordinate system has changed.
6406 * Sets the vertical and horizontal scrollbars. This is done
6407 * here since the window width and height are needed for the
6408 * scrollbar calculations.
6409 *
6410 * Results:
6411 * None.
6412 *
6413 * Side effects:
6414 * The widget is redisplayed.
6415 *
6416 * ----------------------------------------------------------------------
6417 */
6418 static void
6419 DisplayTabset(clientData)
6420 ClientData clientData; /* Information about widget. */
6421 {
6422 Tabset *setPtr = clientData;
6423 Pixmap drawable;
6424 int width, height, count = 0;
6425
6426 if ((setPtr->flags & TABSET_DESTROYED)) return;
6427
6428 setPtr->flags &= ~TABSET_REDRAW;
6429 if (setPtr->tkwin == NULL) {
6430 return; /* Window has been destroyed. */
6431 }
6432 if (setPtr->flags & TABSET_LAYOUT) {
6433 /* Avoid bug of all tabs invisible. */
6434 setPtr->flags |= TABSET_SCROLL;
6435 }
6436
6437 if (setPtr->flags & TABSET_DIRTY) {
6438 Blt_ChainLink *linkPtr;
6439 Tab *tabPtr;
6440 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
6441 linkPtr = Blt_ChainNextLink(linkPtr)) {
6442 tabPtr = Blt_ChainGetValue(linkPtr);
6443 ConfigureTab(setPtr, tabPtr);
6444 }
6445 setPtr->flags &= ~TABSET_DIRTY;
6446 }
6447
6448 if (setPtr->flags & TABSET_LAYOUT) {
6449 ComputeLayout(setPtr);
6450 setPtr->flags &= ~TABSET_LAYOUT;
6451 }
6452 if ((setPtr->reqHeight == 0) || (setPtr->reqWidth == 0)) {
6453 /*int inspad = setPtr->inset + setPtr->inset2;*/
6454 int inspad = 2*setPtr->inset;
6455 int rw, rh;
6456
6457 width = height = 0;
6458 if (setPtr->side & SIDE_VERTICAL) {
6459 height = setPtr->worldWidth;
6460 } else {
6461 width = setPtr->worldWidth;
6462 }
6463 if (setPtr->reqWidth > 0) {
6464 width = setPtr->reqWidth;
6465 } else if (setPtr->pageWidth > 0) {
6466 width = setPtr->pageWidth;
6467 }
6468 if (setPtr->reqHeight > 0) {
6469 height = setPtr->reqHeight;
6470 } else if (setPtr->pageHeight > 0) {
6471 height = setPtr->pageHeight;
6472 }
6473 if (setPtr->side & SIDE_VERTICAL) {
6474 width += setPtr->pageTop + inspad;
6475 height += inspad;
6476 } else {
6477 height += setPtr->pageTop + inspad;
6478 width += inspad;
6479 }
6480 rw = Tk_ReqWidth(setPtr->tkwin) ;
6481 rh = Tk_ReqHeight(setPtr->tkwin);
6482 if ((rw != width) || (rh != height)) {
6483 Tk_GeometryRequest(setPtr->tkwin, width, height);
6484 }
6485 }
6486 if (setPtr->flags & TABSET_SCROLL) {
6487 width = VPORTWIDTH(setPtr);
6488 setPtr->scrollOffset = Blt_AdjustViewport(setPtr->scrollOffset,
6489 setPtr->worldWidth, width, setPtr->scrollUnits,
6490 BLT_SCROLL_MODE_CANVAS);
6491 if (setPtr->scrollCmdPrefix != NULL && Tk_Width(setPtr->tkwin)>1) {
6492 Blt_UpdateScrollbar(setPtr->interp, setPtr->scrollCmdPrefix,
6493 (double)setPtr->scrollOffset / setPtr->worldWidth,
6494 (double)(setPtr->scrollOffset + width) / setPtr->worldWidth);
6495 }
6496 ComputeVisibleTabs(setPtr);
6497 setPtr->flags &= ~TABSET_SCROLL;
6498 }
6499 if (!Tk_IsMapped(setPtr->tkwin)) {
6500 return;
6501 }
6502 height = Tk_Height(setPtr->tkwin);
6503 drawable = Tk_GetPixmap(setPtr->display, Tk_WindowId(setPtr->tkwin),
6504 Tk_Width(setPtr->tkwin), Tk_Height(setPtr->tkwin),
6505 Tk_Depth(setPtr->tkwin));
6506
6507 /*
6508 * Clear the background and tile pixmap. Fill in case transparent.
6509 */
6510 Blt_Fill3DRectangle(setPtr->tkwin, drawable, setPtr->border, 0, 0,
6511 Tk_Width(setPtr->tkwin), height, 0, TK_RELIEF_FLAT);
6512 /* if (Blt_HasTile(setPtr->tile)) {
6513 Blt_SetTileOrigin(setPtr->tkwin, setPtr->tile, 0, 0);
6514 Blt_TileRectangle(setPtr->tkwin, drawable, setPtr->tile, 0, 0,
6515 Tk_Width(setPtr->tkwin), height);
6516 }*/
6517
6518 if (Blt_HasTile(setPtr->bgtile)) {
6519 Blt_SetTileOrigin(setPtr->tkwin, setPtr->bgtile, 0, 0);
6520 Blt_TileRectangle(setPtr->tkwin, drawable, setPtr->bgtile, 0, 0,
6521 Tk_Width(setPtr->tkwin), height);
6522 }
6523
6524 if (setPtr->nVisible > 0) {
6525 register int i;
6526 register Tab *tabPtr;
6527 Blt_ChainLink *linkPtr;
6528
6529 linkPtr = setPtr->startPtr->linkPtr;
6530 for (i = 0; i < Blt_ChainGetLength(setPtr->chainPtr); i++) {
6531 linkPtr = Blt_ChainPrevLink(linkPtr);
6532 if (linkPtr == NULL) {
6533 linkPtr = Blt_ChainLastLink(setPtr->chainPtr);
6534 }
6535 tabPtr = Blt_ChainGetValue(linkPtr);
6536 if ((tabPtr != setPtr->selectPtr) &&
6537 (tabPtr->flags & TAB_VISIBLE)) {
6538 DrawFolder(setPtr, tabPtr, drawable);
6539 count++;
6540 }
6541 }
6542 DrawFolder(setPtr, setPtr->selectPtr, drawable);
6543 if (count == 0) {
6544 /* Bug: somehow all tabs got marked invisble. */
6545 setPtr->flags |= (TABSET_LAYOUT|TABSET_SCROLL);
6546 }
6547 if (setPtr->tearoff) {
6548 DrawPerforation(setPtr, setPtr->selectPtr, drawable);
6549 }
6550
6551 if ((setPtr->selectPtr->tkwin != NULL) &&
6552 (setPtr->selectPtr->container == NULL)) {
6553 XRectangle rect;
6554
6555 GetWindowRectangle(setPtr->selectPtr, setPtr->tkwin, FALSE, &rect);
6556 ArrangeWindow(setPtr->selectPtr->tkwin, &rect, 0);
6557 }
6558 }
6559 if (setPtr->startImage && setPtr->startImage->width) {
6560 Tk_RedrawImage(ImageBits(setPtr->startImage), 0, 0,
6561 setPtr->startImage->width, setPtr->startImage->height,
6562 drawable, setPtr->siX, setPtr->siY);
6563 }
6564 if (setPtr->endImage && setPtr->endImage->width) {
6565 Tk_RedrawImage(ImageBits(setPtr->endImage), 0, 0,
6566 setPtr->endImage->width, setPtr->endImage->height,
6567 drawable, setPtr->eiX, setPtr->eiY);
6568 }
6569 DrawOuterBorders(setPtr, drawable);
6570 XCopyArea(setPtr->display, drawable, Tk_WindowId(setPtr->tkwin),
6571 setPtr->highlightGC, 0, 0, Tk_Width(setPtr->tkwin), height, 0, 0);
6572 Tk_FreePixmap(setPtr->display, drawable);
6573 }
6574
6575 /*
6576 * From the left edge:
6577 *
6578 * |a|b|c|d|e| f |d|e|g|h| i |h|g|e|d|f| j |e|d|c|b|a|
6579 *
6580 * a. highlight ring
6581 * b. tabset 3D border
6582 * c. outer gap
6583 * d. page border
6584 * e. page corner
6585 * f. gap + select pad
6586 * g. label pad x (worldX)
6587 * h. internal pad x
6588 * i. label width
6589 * j. rest of page width
6590 *
6591 * worldX, worldY
6592 * |
6593 * |
6594 * * 4+ . . +5
6595 * 3+ +6
6596 * . .
6597 * . .
6598 * 1+. . .2+ +7 . . . .+8
6599 * 0+ +9
6600 * . .
6601 * . .
6602 *13+ +10
6603 * 12+-------------------------+11
6604 *
6605 */
6606 static void
6607 DisplayTearoff(clientData)
6608 ClientData clientData;
6609 {
6610 Tabset *setPtr;
6611 Tab *tabPtr;
6612 Drawable drawable;
6613 XPoint pointArr[16];
6614 XPoint *pointPtr;
6615 int width, height;
6616 int left, bottom, right, top;
6617 int x, y;
6618 int nPoints;
6619 Tk_Window tkwin;
6620 Tk_Window parent;
6621 XRectangle rect;
6622
6623 tabPtr = clientData;
6624 if (tabPtr == NULL) {
6625 return;
6626 }
6627 tabPtr->flags &= ~TAB_REDRAW;
6628 setPtr = tabPtr->setPtr;
6629 if (setPtr->tkwin == NULL) {
6630 return;
6631 }
6632 tkwin = tabPtr->container;
6633 drawable = Tk_WindowId(tkwin);
6634
6635 /*
6636 * Clear the background either by tiling a pixmap or filling with
6637 * a solid color. Tiling takes precedence.
6638 */
6639 Blt_Fill3DRectangle(tkwin, drawable, setPtr->border, 0, 0,
6640 Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
6641 if (Blt_HasTile(setPtr->tile)) {
6642 Blt_SetTileOrigin(tkwin, setPtr->tile, 0, 0);
6643 Blt_TileRectangle(tkwin, drawable, setPtr->tile, 0, 0,
6644 Tk_Width(tkwin), Tk_Height(tkwin));
6645 }
6646
6647 width = Tk_Width(tkwin) - 2 * setPtr->inset;
6648 height = Tk_Height(tkwin) - 2 * setPtr->inset;
6649 x = setPtr->inset + setPtr->gap + setPtr->corner;
6650 y = setPtr->inset;
6651
6652 left = setPtr->inset;
6653 right = setPtr->inset + width;
6654 top = setPtr->inset + setPtr->corner + setPtr->xSelectPad;
6655 bottom = setPtr->inset + height;
6656
6657 /*
6658 * worldX, worldY
6659 * |
6660 * * 4+ . . +5
6661 * 3+ +6
6662 * . .
6663 * . .
6664 * 1+. . .2+ +7 . . . .+8
6665 * 0+ +9
6666 * . .
6667 * . .
6668 *13+ +10
6669 * 12+-------------------------+11
6670 */
6671
6672 nPoints = 0;
6673 pointPtr = pointArr;
6674
6675 TopLeft(left, top);
6676 NextPoint(x, top);
6677 TopLeft(x, y);
6678 x += tabPtr->worldWidth;
6679 TopRight(x, y);
6680 NextPoint(x, top);
6681 TopRight(right, top);
6682 BottomRight(right, bottom);
6683 BottomLeft(left, bottom);
6684 EndPoint(pointArr[0].x, pointArr[0].y);
6685 Draw3DFolder(setPtr, tabPtr, drawable, SIDE_TOP, pointArr, nPoints);
6686
6687 parent = (tabPtr->container == NULL) ? setPtr->tkwin : tabPtr->container;
6688 GetWindowRectangle(tabPtr, parent, TRUE, &rect);
6689 ArrangeWindow(tabPtr->tkwin, &rect, TRUE);
6690
6691 /* Draw 3D border. */
6692 if ((setPtr->borderWidth > 0) && (setPtr->relief != TK_RELIEF_FLAT)) {
6693 Blt_Draw3DRectangle(tkwin, drawable, setPtr->border, 0, 0,
6694 Tk_Width(tkwin), Tk_Height(tkwin), setPtr->borderWidth,
6695 setPtr->relief);
6696 }
6697 }
6698
6699 /*
6700 * --------------------------------------------------------------
6701 *
6702 * TabsetCmd --
6703 *
6704 * This procedure is invoked to process the "tabset" command.
6705 * See the user documentation for details on what it does.
6706 *
6707 * Results:
6708 * A standard Tcl result.
6709 *
6710 * Side effects:
6711 * See the user documentation.
6712 *
6713 * --------------------------------------------------------------
6714 */
6715 static Blt_OpSpec tabsetOps[] =
6716 {
6717 {"activate", 1, (Blt_Op)ActivateOp, 3, 3, "index",},
6718 {"bind", 1, (Blt_Op)BindOp, 2, 5, "index ?sequence command?",},
6719 {"cget", 2, (Blt_Op)CgetOp, 3, 3, "option",},
6720 {"configure", 3, (Blt_Op)ConfigureOp, 2, 0, "?option value?...",},
6721 {"coords", 3, (Blt_Op)CoordsOp, 3, 4, "element ?index?",},
6722 {"delete", 1, (Blt_Op)DeleteOp, 2, 0, "first ?last?",},
6723 {"focus", 1, (Blt_Op)FocusOp, 3, 3, "index",},
6724 {"get", 1, (Blt_Op)GetOp, 3, 3, "index",},
6725 {"index", 3, (Blt_Op)IndexOp, 3, 5, "string",},
6726 {"insert", 3, (Blt_Op)InsertOp, 3, 0,
6727 "index name ?name...? ?option value?",},
6728 {"invoke", 3, (Blt_Op)InvokeOp, 3, 3, "index",},
6729 {"move", 1, (Blt_Op)MoveOp, 5, 5, "name after|before index",},
6730 {"nearest", 1, (Blt_Op)NearestOp, 4, 6, "x y ?varName? ?coordsVar?",},
6731 {"perforation", 1, (Blt_Op)PerforationOp, 2, 0, "args",},
6732 {"scan", 2, (Blt_Op)ScanOp, 5, 5, "dragto|mark x y",},
6733 {"see", 3, (Blt_Op)SeeOp, 3, 3, "index",},
6734 {"select", 3, (Blt_Op)SelectOp, 3, 3, "index",},
6735 {"size", 2, (Blt_Op)SizeOp, 2, 2, "",},
6736 {"tab", 1, (Blt_Op)TabOp, 2, 0, "oper args",},
6737 {"tearoff", 1, (Blt_Op)TearoffOp, 2, 3, "?index?",},
6738 {"view", 1, (Blt_Op)ViewOp, 2, 5,
6739 "?moveto fract? ?scroll number what?",},
6740 };
6741
6742 static int nTabsetOps = sizeof(tabsetOps) / sizeof(Blt_OpSpec);
6743
6744 static int
6745 TabsetInstCmd(clientData, interp, argc, argv)
6746 ClientData clientData; /* Information about the widget. */
6747 Tcl_Interp *interp; /* Interpreter to report errors back to. */
6748 int argc; /* Number of arguments. */
6749 char **argv; /* Vector of argument strings. */
6750 {
6751 Blt_Op proc;
6752 Tabset *setPtr = clientData;
6753 int result;
6754
6755 if ((setPtr->flags & TABSET_DESTROYED)) return TCL_OK;
6756
6757 proc = Blt_GetOp(interp, nTabsetOps, tabsetOps, BLT_OP_ARG1,
6758 argc, argv, 0);
6759 if (proc == NULL) {
6760 return TCL_ERROR;
6761 }
6762 Tcl_Preserve(setPtr);
6763 result = (*proc) (setPtr, interp, argc, argv);
6764 Tcl_Release(setPtr);
6765 return result;
6766 }
6767
6768 /*
6769 *----------------------------------------------------------------------
6770 *
6771 * TabsetInstDeletedCmd --
6772 *
6773 * This procedure can be called if the window was destroyed
6774 * (tkwin will be NULL) and the command was deleted
6775 * automatically. In this case, we need to do nothing.
6776 *
6777 * Otherwise this routine was called because the command was
6778 * deleted. Then we need to clean-up and destroy the widget.
6779 *
6780 * Results:
6781 * None.
6782 *
6783 * Side Effects:
6784 * The widget is destroyed.
6785 *
6786 *----------------------------------------------------------------------
6787 */
6788 static void
6789 TabsetInstDeletedCmd(clientData)
6790 ClientData clientData; /* Pointer to widget record for widget. */
6791 {
6792 Tabset *setPtr = clientData;
6793
6794 if (setPtr->tkwin != NULL) {
6795 Tk_Window tkwin;
6796
6797 tkwin = setPtr->tkwin;
6798 setPtr->tkwin = NULL;
6799 Tk_DestroyWindow(tkwin);
6800 #ifdef ITCL_NAMESPACES
6801 Itk_SetWidgetCommand(tkwin, (Tcl_Command) NULL);
6802 #endif /* ITCL_NAMESPACES */
6803 }
6804 }
6805
6806 /*
6807 * ------------------------------------------------------------------------
6808 *
6809 * TabsetCmd --
6810 *
6811 * This procedure is invoked to process the Tcl command that
6812 * corresponds to a widget managed by this module. See the user
6813 * documentation for details on what it does.
6814 *
6815 * Results:
6816 * A standard Tcl result.
6817 *
6818 * Side Effects:
6819 * See the user documentation.
6820 *
6821 * -----------------------------------------------------------------------
6822 */
6823 /* ARGSUSED */
6824 static int
6825 TabsetCmd(clientData, interp, argc, argv)
6826 ClientData clientData; /* Main window associated with interpreter. */
6827 Tcl_Interp *interp; /* Current interpreter. */
6828 int argc; /* Number of arguments. */
6829 char **argv; /* Argument strings. */
6830 {
6831 Tabset *setPtr;
6832 Tk_Window tkwin;
6833 unsigned int mask;
6834 Tcl_CmdInfo cmdInfo;
6835
6836 if (argc < 2) {
6837 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
6838 " pathName ?option value?...\"", (char *)NULL);
6839 return TCL_ERROR;
6840 }
6841 tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), argv[1],
6842 (char *)NULL);
6843 if (tkwin == NULL) {
6844 return TCL_ERROR;
6845 }
6846 setPtr = CreateTabset(interp, tkwin);
6847 if (ConfigureTabset(interp, setPtr, argc - 2, argv + 2, 0) != TCL_OK) {
6848 Tk_DestroyWindow(setPtr->tkwin);
6849 return TCL_ERROR;
6850 }
6851 mask = (ExposureMask | StructureNotifyMask | FocusChangeMask);
6852 Tk_CreateEventHandler(tkwin, mask, TabsetEventProc, setPtr);
6853 setPtr->cmdToken = Tcl_CreateCommand(interp, argv[1], TabsetInstCmd,
6854 setPtr, TabsetInstDeletedCmd);
6855 #ifdef ITCL_NAMESPACES
6856 Itk_SetWidgetCommand(setPtr->tkwin, setPtr->cmdToken);
6857 #endif
6858
6859 /*
6860 * Try to invoke a procedure to initialize various bindings on
6861 * tabs. Source the file containing the procedure now if the
6862 * procedure isn't currently defined. We deferred this to now so
6863 * that the user could set the variable "blt_library" within the
6864 * script.
6865 */
6866 if (!Tcl_GetCommandInfo(interp, "blt::TabsetInit", &cmdInfo)) {
6867 static char initCmd[] = "source [file join $blt_library tabset.tcl]";
6868
6869 if (Tcl_GlobalEval(interp, initCmd) != TCL_OK) {
6870 char info[200];
6871
6872 sprintf(info, "\n (while loading bindings for %s)", argv[0]);
6873 Tcl_AddErrorInfo(interp, info);
6874 Tk_DestroyWindow(setPtr->tkwin);
6875 return TCL_ERROR;
6876 }
6877 }
6878 if (Tcl_VarEval(interp, "blt::TabsetInit ", argv[1], (char *)NULL)
6879 != TCL_OK) {
6880 Tk_DestroyWindow(setPtr->tkwin);
6881 return TCL_ERROR;
6882 }
6883 Tcl_SetResult(interp, Tk_PathName(setPtr->tkwin), TCL_VOLATILE);
6884 return TCL_OK;
6885 }
6886
6887 int
6888 Blt_TabsetInit(interp)
6889 Tcl_Interp *interp;
6890 {
6891 static Blt_CmdSpec cmdSpec =
6892 {
6893 "tabset", TabsetCmd,
6894 };
6895
6896 if (Blt_InitCmd(interp, "blt", &cmdSpec) == NULL) {
6897 return TCL_ERROR;
6898 }
6899 return TCL_OK;
6900 }
6901
6902 #endif /* NO_TABSET */