Debian Codegraph @

generic/bltTabset.c

raw symbols ◀ ▶ SCIP
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 CONST 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 CONST 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, (char *)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 char coords[200];
3920
3921 coords[0] = 0;
3922 tabPtr = NULL;
3923 if ((Tk_GetPixels(interp, setPtr->tkwin, argv[2], &x) != TCL_OK) ||
3924 (Tk_GetPixels(interp, setPtr->tkwin, argv[3], &y) != TCL_OK)) {
3925 return TCL_ERROR;
3926 }
3927 if (setPtr->nVisible > 0) {
3928 tabPtr = PickTab(setPtr, x, y, NULL);
3929 if (tabPtr != NULL) {
3930 Tcl_SetResult(interp, tabPtr->name, TCL_VOLATILE);
3931 }
3932 }
3933 if (argc > 4) {
3934 char *where;
3935 int lx, ly;
3936
3937 where = "";
3938 lx = x;
3939 ly = y;
3940 if (setPtr->startImage && lx>=setPtr->siX &&
3941 lx<(setPtr->siX+setPtr->startImage->width) &&
3942 ly>=setPtr->siY && ly<(setPtr->siY+setPtr->startImage->height)) {
3943 where = "startimage";
3944 if (argc > 5) {
3945 sprintf(coords, "%d %d %d %d",
3946 setPtr->siX, setPtr->siY, (setPtr->siX+setPtr->startImage->width),
3947 (setPtr->siY+setPtr->startImage->height));
3948 }
3949 goto done;
3950 }
3951 if (setPtr->endImage && lx>=setPtr->eiX &&
3952 lx<(setPtr->eiX+setPtr->endImage->width) &&
3953 ly>=setPtr->eiY && ly<(setPtr->eiY+setPtr->endImage->height)) {
3954 where = "endimage";
3955 if (argc > 5) {
3956 sprintf(coords, "%d %d %d %d",
3957 setPtr->eiX, setPtr->eiY, (setPtr->eiX+setPtr->endImage->width),
3958 (setPtr->eiY+setPtr->endImage->height));
3959 }
3960 goto done;
3961 }
3962 if (tabPtr == NULL) {
3963 goto done;
3964 }
3965 if (tabPtr->iW && (lx >= tabPtr->iX) && (lx < (tabPtr->iX + tabPtr->iW)) &&
3966 (ly >= tabPtr->iY) && (ly < (tabPtr->iY + tabPtr->iH))) {
3967 where = "image";
3968 if (argc > 5) {
3969 sprintf(coords, "%d %d %d %d",
3970 (tabPtr->iX), (tabPtr->iY), (tabPtr->iX + tabPtr->iW),
3971 (tabPtr->iY + tabPtr->iH));
3972 }
3973 goto done;
3974 }
3975 if (tabPtr->i2W && (lx >= tabPtr->i2X) && (lx < (tabPtr->i2X + tabPtr->i2W)) &&
3976 (ly >= tabPtr->i2Y) && (ly < (tabPtr->i2Y + tabPtr->i2H))) {
3977 where = "leftimage";
3978 if (argc > 5) {
3979 sprintf(coords, "%d %d %d %d",
3980 tabPtr->i2X, tabPtr->i2Y, tabPtr->i2X + tabPtr->i2W,
3981 tabPtr->i2Y + tabPtr->i2H);
3982 }
3983 goto done;
3984 }
3985 if (setPtr->pW && (lx >= setPtr->pX) && (lx < (setPtr->pX + setPtr->pW)) &&
3986 (ly >= setPtr->pY) && (ly < (setPtr->pY + setPtr->pH))) {
3987 where = "perforation";
3988 if (argc > 5) {
3989 sprintf(coords, "%d %d %d %d",
3990 setPtr->pX, setPtr->pY, setPtr->pX + setPtr->pW,
3991 setPtr->pY + setPtr->pH);
3992 }
3993 goto done;
3994 }
3995 if (tabPtr->tW && (lx >= tabPtr->tX) && (lx < (tabPtr->tX + tabPtr->tW)) &&
3996 (ly >= tabPtr->tY) && (ly < (tabPtr->tY + tabPtr->tH))) {
3997 where = "text";
3998 if (argc > 5) {
3999 sprintf(coords, "%d %d %d %d",
4000 tabPtr->tX, tabPtr->tY, tabPtr->tX + tabPtr->tW,
4001 tabPtr->tY + tabPtr->tH);
4002 }
4003 goto done;
4004 }
4005
4006
4007 done:
4008 if (Tcl_SetVar(interp, argv[4], where, TCL_LEAVE_ERR_MSG) == NULL) {
4009 return TCL_ERROR;
4010 }
4011 if (argc > 5) {
4012 if (Tcl_SetVar(interp, argv[5], coords, TCL_LEAVE_ERR_MSG) == NULL) {
4013 return TCL_ERROR;
4014 }
4015 }
4016
4017 }
4018 return TCL_OK;
4019 }
4020
4021 /*ARGSUSED*/
4022 static int
4023 CoordsOp(setPtr, interp, argc, argv)
4024 Tabset *setPtr;
4025 Tcl_Interp *interp;
4026 int argc; /* Not used. */
4027 char **argv;
4028 {
4029 Tab *tabPtr;
4030 int optInd;
4031 char coords[200];
4032 Tcl_Obj *objPtr;
4033
4034 enum optInd {
4035 OP_STARTIMAGE, OP_ENDIMAGE, OP_IMAGE, OP_LEFTIMAGE, OP_PERF, OP_TEXT
4036 };
4037 static char *optArr[] = {
4038 "startimage", "endimage", "image", "leftimage", "perforation", "text", 0
4039 };
4040
4041 coords[0] = 0;
4042 tabPtr = NULL;
4043 objPtr = Tcl_NewStringObj(argv[2], -1);
4044 if (Tcl_GetIndexFromObj(interp, objPtr, optArr, "option", 0, &optInd) != TCL_OK) {
4045 Tcl_DecrRefCount(objPtr);
4046 return TCL_ERROR;
4047 }
4048 Tcl_DecrRefCount(objPtr);
4049 if (argc>3 && GetTabByIndex(setPtr, argv[3], &tabPtr) != TCL_OK) {
4050 return TCL_ERROR; /* Can't find node. */
4051 }
4052 if (tabPtr == NULL && optInd != OP_STARTIMAGE && optInd != OP_STARTIMAGE) {
4053 Tcl_AppendResult(interp, "must provide a tab", 0);
4054 return TCL_ERROR;
4055 }
4056
4057 switch (optInd) {
4058 case OP_STARTIMAGE:
4059 if (setPtr->startImage) {
4060 sprintf(coords, "%d %d %d %d",
4061 setPtr->siX, setPtr->siY, (setPtr->siX+setPtr->startImage->width),
4062 (setPtr->siY+setPtr->startImage->height));
4063 }
4064 break;
4065 case OP_ENDIMAGE:
4066 if (setPtr->endImage) {
4067 sprintf(coords, "%d %d %d %d",
4068 setPtr->eiX, setPtr->eiY, (setPtr->eiX+setPtr->endImage->width),
4069 (setPtr->eiY+setPtr->endImage->height));
4070 }
4071 break;
4072 case OP_IMAGE:
4073 if (tabPtr->iW) {
4074 sprintf(coords, "%d %d %d %d",
4075 (tabPtr->iX), (tabPtr->iY), (tabPtr->iX + tabPtr->iW),
4076 (tabPtr->iY + tabPtr->iH));
4077 }
4078 break;
4079 case OP_LEFTIMAGE:
4080 if (tabPtr->i2W) {
4081 sprintf(coords, "%d %d %d %d",
4082 tabPtr->i2X, tabPtr->i2Y, tabPtr->i2X + tabPtr->i2W,
4083 tabPtr->i2Y + tabPtr->i2H);
4084 }
4085 break;
4086 case OP_PERF:
4087 if (setPtr->pW) {
4088 sprintf(coords, "%d %d %d %d",
4089 setPtr->pX, setPtr->pY, setPtr->pX + setPtr->pW,
4090 setPtr->pY + setPtr->pH);
4091 }
4092 break;
4093 case OP_TEXT:
4094 if (tabPtr->tW) {
4095 sprintf(coords, "%d %d %d %d",
4096 tabPtr->tX, tabPtr->tY, tabPtr->tX + tabPtr->tW,
4097 tabPtr->tY + tabPtr->tH);
4098 }
4099 break;
4100 }
4101
4102 Tcl_SetObjResult(interp, Tcl_NewStringObj(coords, -1));
4103 return TCL_OK;
4104 }
4105
4106 /*
4107 *----------------------------------------------------------------------
4108 *
4109 * SelectOp --
4110 *
4111 * This procedure is called to select a tab.
4112 *
4113 * .h select index
4114 *
4115 * Results:
4116 * A standard Tcl result. If TCL_ERROR is returned, then
4117 * interp->result contains an error message.
4118 *
4119 * Side Effects:
4120 * Configuration information, such as text string, colors, font,
4121 * etc. get set; old resources get freed, if there were any.
4122 * The widget is redisplayed if needed.
4123 *
4124 *----------------------------------------------------------------------
4125 */
4126 /*ARGSUSED*/
4127 static int
4128 SelectOp(
4129 Tabset *setPtr,
4130 Tcl_Interp *interp,
4131 int argc,
4132 char **argv)
4133 {
4134 Tab *tabPtr;
4135
4136 if (GetTabByIndName(setPtr, argv[2], &tabPtr) != TCL_OK) {
4137 return TCL_ERROR;
4138 }
4139 if ((tabPtr == NULL) || (tabPtr->state == STATE_DISABLED)) {
4140 return TCL_OK;
4141 }
4142 if (tabPtr->hidden) {
4143 Tcl_AppendResult(interp, "can not select hidden tab", 0);
4144 return TCL_ERROR;
4145 }
4146 if ((setPtr->selectPtr != NULL) && (setPtr->selectPtr != tabPtr) &&
4147 (setPtr->selectPtr->tkwin != NULL)) {
4148 if (setPtr->selectPtr->container == NULL) {
4149 if (Tk_IsMapped(setPtr->selectPtr->tkwin)) {
4150 Tk_UnmapWindow(setPtr->selectPtr->tkwin);
4151 }
4152 } else {
4153 /* Redraw now unselected container. */
4154 EventuallyRedrawTearoff(setPtr->selectPtr);
4155 }
4156 }
4157 setPtr->selectPtr = tabPtr;
4158 if ((setPtr->nTiers > 1) && setPtr->startPtr &&
4159 (tabPtr->tier != setPtr->startPtr->tier)) {
4160 RenumberTiers(setPtr, tabPtr);
4161 Blt_PickCurrentItem(setPtr->bindTable);
4162 }
4163 setPtr->flags |= (TABSET_SCROLL);
4164 if (tabPtr->container != NULL) {
4165 EventuallyRedrawTearoff(tabPtr);
4166 }
4167 EventuallyRedraw(setPtr);
4168 return TCL_OK;
4169 }
4170
4171 static int
4172 ViewOp(
4173 Tabset *setPtr,
4174 Tcl_Interp *interp,
4175 int argc,
4176 char **argv)
4177 {
4178 int width;
4179
4180 width = VPORTWIDTH(setPtr);
4181 if (argc == 2) {
4182 double fract;
4183
4184 /*
4185 * Note: we are bounding the fractions between 0.0 and 1.0 to
4186 * support the "canvas"-style of scrolling.
4187 */
4188
4189 fract = (double)setPtr->scrollOffset / setPtr->worldWidth;
4190 Tcl_AppendElement(interp, Blt_Dtoa(interp, CLAMP(fract, 0.0, 1.0)));
4191 fract = (double)(setPtr->scrollOffset + width) / setPtr->worldWidth;
4192 Tcl_AppendElement(interp, Blt_Dtoa(interp, CLAMP(fract, 0.0, 1.0)));
4193 return TCL_OK;
4194 }
4195 if (Blt_GetScrollInfo(interp, argc - 2, argv + 2, &(setPtr->scrollOffset),
4196 setPtr->worldWidth, width, setPtr->scrollUnits,
4197 BLT_SCROLL_MODE_CANVAS) != TCL_OK) {
4198 return TCL_ERROR;
4199 }
4200 setPtr->flags |= TABSET_SCROLL;
4201 EventuallyRedraw(setPtr);
4202 return TCL_OK;
4203 }
4204
4205
4206 #if 0
4207 /* OBSOLETE */
4208 static void
4209 AdoptWindow( ClientData clientData)
4210 {
4211 Tab *tabPtr = clientData;
4212 int x, y;
4213 Tabset *setPtr = tabPtr->setPtr;
4214
4215 x = setPtr->inset + setPtr->inset2 + tabPtr->padLeft;
4216 #define TEAR_OFF_TAB_SIZE 5
4217 y = setPtr->inset + setPtr->inset2 + setPtr->yPad +
4218 setPtr->outerPad + TEAR_OFF_TAB_SIZE + tabPtr->padTop;
4219 Blt_RelinkWindow(tabPtr->tkwin, tabPtr->container, x, y);
4220 Tk_MapWindow(tabPtr->tkwin);
4221 }
4222 #endif
4223
4224 static void
4225 DestroyTearoff(dataPtr)
4226 DestroyData dataPtr;
4227 {
4228 Tab *tabPtr = (Tab *)dataPtr;
4229
4230 if (tabPtr->container != NULL) {
4231 Tabset *setPtr;
4232 Tk_Window tkwin;
4233 setPtr = tabPtr->setPtr;
4234
4235 tkwin = tabPtr->container;
4236 if (tabPtr->flags & TAB_REDRAW) {
4237 Tcl_CancelIdleCall(DisplayTearoff, tabPtr);
4238 }
4239 Tk_DeleteEventHandler(tkwin, StructureNotifyMask, TearoffEventProc,
4240 tabPtr);
4241 if (tabPtr->tkwin != NULL) {
4242 XRectangle rect;
4243
4244 GetWindowRectangle(tabPtr, setPtr->tkwin, FALSE, &rect);
4245 Blt_RelinkWindow(tabPtr->tkwin, setPtr->tkwin, rect.x, rect.y);
4246 if (tabPtr == setPtr->selectPtr) {
4247 ArrangeWindow(tabPtr->tkwin, &rect, TRUE);
4248 } else {
4249 Tk_UnmapWindow(tabPtr->tkwin);
4250 }
4251 }
4252 Tk_DestroyWindow(tkwin);
4253 tabPtr->container = NULL;
4254 }
4255 }
4256
4257 #if 0
4258 /* Obsolete. Now uses "wm manage" */
4259 static int
4260 CreateTearoff(
4261 Tabset *setPtr,
4262 char *name,
4263 Tab *tabPtr)
4264 {
4265 Tk_Window tkwin;
4266 int width, height;
4267
4268 tkwin = Tk_CreateWindowFromPath(setPtr->interp, setPtr->tkwin, name,
4269 (char *)NULL);
4270 if (tkwin == NULL) {
4271 return TCL_ERROR;
4272 }
4273 tabPtr->container = tkwin;
4274 if (Tk_WindowId(tkwin) == None) {
4275 Tk_MakeWindowExist(tkwin);
4276 }
4277 Tk_SetClass(tkwin, "Tearoff");
4278 Tk_CreateEventHandler(tkwin, (ExposureMask | StructureNotifyMask),
4279 TearoffEventProc, tabPtr);
4280 if (Tk_WindowId(tabPtr->tkwin) == None) {
4281 Tk_MakeWindowExist(tabPtr->tkwin);
4282 }
4283 width = Tk_Width(tabPtr->tkwin);
4284 if (width < 2) {
4285 width = (tabPtr->reqWidth > 0)
4286 ? tabPtr->reqWidth : Tk_ReqWidth(tabPtr->tkwin);
4287 }
4288 width += PADDING(tabPtr->padX) + 2 *
4289 Tk_Changes(tabPtr->tkwin)->border_width;
4290 width += 2 * (setPtr->inset2 + setPtr->inset);
4291 #define TEAR_OFF_TAB_SIZE 5
4292 height = Tk_Height(tabPtr->tkwin);
4293 if (height < 2) {
4294 height = (tabPtr->reqHeight > 0)
4295 ? tabPtr->reqHeight : Tk_ReqHeight(tabPtr->tkwin);
4296 }
4297 height += PADDING(tabPtr->padY) +
4298 2 * Tk_Changes(tabPtr->tkwin)->border_width;
4299 height += setPtr->inset + setPtr->inset2 + setPtr->yPad +
4300 TEAR_OFF_TAB_SIZE + setPtr->outerPad;
4301 Tk_GeometryRequest(tkwin, width, height);
4302 Tk_UnmapWindow(tabPtr->tkwin);
4303 /* Tk_MoveWindow(tabPtr->tkwin, 0, 0); */
4304 Tcl_SetResult(setPtr->interp, Tk_PathName(tkwin), TCL_VOLATILE);
4305 #ifdef WIN32
4306 AdoptWindow(tabPtr);
4307 #else
4308 Tcl_DoWhenIdle(AdoptWindow, tabPtr);
4309 #endif
4310 return TCL_OK;
4311 }
4312 #endif
4313
4314 /*ARGSUSED*/
4315 static int
4316 SeeOp(
4317 Tabset *setPtr,
4318 Tcl_Interp *interp, /* Not used. */
4319 int argc,
4320 char **argv)
4321 {
4322 Tab *tabPtr;
4323 int left, right, width;
4324
4325 if (GetTabByIndName(setPtr, argv[2], &tabPtr) != TCL_OK) {
4326 return TCL_ERROR;
4327 }
4328 if (tabPtr == NULL) {
4329 return TCL_OK;
4330 }
4331
4332 width = VPORTWIDTH(setPtr);
4333 left = setPtr->scrollOffset + setPtr->xSelectPad;
4334 right = setPtr->scrollOffset + width - setPtr->xSelectPad;
4335
4336 /* If the tab is partially obscured, scroll so that it's
4337 * entirely in view. */
4338 if (tabPtr->worldX < left) {
4339 setPtr->scrollOffset = tabPtr->worldX - TAB_SCROLL_OFFSET;
4340 } else if ((tabPtr->worldX + tabPtr->worldWidth) >= right) {
4341 Blt_ChainLink *linkPtr;
4342
4343 setPtr->scrollOffset = tabPtr->worldX + tabPtr->worldWidth -
4344 (width - 2 * setPtr->xSelectPad);
4345 linkPtr = Blt_ChainNextLink(tabPtr->linkPtr);
4346 if (linkPtr != NULL) {
4347 Tab *nextPtr;
4348
4349 nextPtr = Blt_ChainGetValue(linkPtr);
4350 if (nextPtr->tier == tabPtr->tier) {
4351 setPtr->scrollOffset += TAB_SCROLL_OFFSET;
4352 }
4353 }
4354 }
4355 setPtr->flags |= TABSET_SCROLL;
4356 EventuallyRedraw(setPtr);
4357 return TCL_OK;
4358 }
4359
4360
4361 /*
4362 *----------------------------------------------------------------------
4363 *
4364 * TabCgetOp --
4365 *
4366 * .h tab cget index option
4367 *
4368 *----------------------------------------------------------------------
4369 */
4370 /*ARGSUSED*/
4371 static int
4372 TabCgetOp(setPtr, interp, argc, argv)
4373 Tabset *setPtr;
4374 Tcl_Interp *interp;
4375 int argc; /* Not used. */
4376 char **argv;
4377 {
4378 Tab *tabPtr;
4379
4380 if (GetTabByNameInd(setPtr, argv[3], &tabPtr) != TCL_OK) {
4381 return TCL_ERROR;
4382 }
4383 tabSet = setPtr;
4384 return Tk_ConfigureValue(interp, setPtr->tkwin, tabConfigSpecs,
4385 (char *)tabPtr, argv[4], 0);
4386 }
4387
4388 /*
4389 *----------------------------------------------------------------------
4390 *
4391 * TabConfigureOp --
4392 *
4393 * This procedure is called to process a list of configuration
4394 * options database, in order to reconfigure the options for
4395 * one or more tabs in the widget.
4396 *
4397 * .h tab configure index ?index...? ?option value?...
4398 *
4399 * Results:
4400 * A standard Tcl result. If TCL_ERROR is returned, then
4401 * interp->result contains an error message.
4402 *
4403 * Side Effects:
4404 * Configuration information, such as text string, colors, font,
4405 * etc. get set; old resources get freed, if there were any.
4406 * The widget is redisplayed if needed.
4407 *
4408 *----------------------------------------------------------------------
4409 */
4410 static int
4411 TabConfigureOp(setPtr, interp, argc, argv)
4412 Tabset *setPtr;
4413 Tcl_Interp *interp;
4414 int argc;
•4415 CONST char **argv;
4416 {
4417 int nTabs, nOpts, result;
•4418 CONST char **options;
4419 register int i;
4420 Tab *tabPtr;
4421
4422 /* Figure out where the option value pairs begin */
4423 argc -= 3;
4424 argv += 3;
4425 for (i = 0; i < argc; i++) {
4426 if (argv[i][0] == '-') {
4427 if (i == 0) {
4428 Tcl_AppendResult(interp, "no tab specified", 0);
4429 return TCL_ERROR;
4430 }
4431 break;
4432 }
4433 if (GetTabByNameInd(setPtr, argv[i], &tabPtr) != TCL_OK) {
4434 return TCL_ERROR; /* Can't find node. */
4435 }
4436 }
4437 nTabs = i; /* Number of tab indices specified */
4438 nOpts = argc - i; /* Number of options specified */
4439 options = argv + i; /* Start of options in argv */
4440
4441 for (i = 0; i < nTabs; i++) {
4442 GetTabByNameInd(setPtr, argv[i], &tabPtr);
4443 if (nOpts == 0) {
4444 return Tk_ConfigureInfo(interp, setPtr->tkwin, tabConfigSpecs,
4445 (char *)tabPtr, (char *)NULL, 0);
4446 } else if (nOpts == 1) {
4447 return Tk_ConfigureInfo(interp, setPtr->tkwin, tabConfigSpecs,
4448 (char *)tabPtr, argv[i+nOpts], 0);
4449 }
4450 tabSet = setPtr;
4451 Tcl_Preserve(tabPtr);
•4452 result = Blt_ConfigureWidget(interp, setPtr->tkwin, tabConfigSpecs,
4453 nOpts, options, (char *)tabPtr, TK_CONFIG_ARGV_ONLY);
4454 if (result == TCL_OK || nOpts>=2) {
4455 result = ConfigureTab(setPtr, tabPtr);
4456 }
4457 Tcl_Release(tabPtr);
4458 setPtr->flags |= (TABSET_LAYOUT | TABSET_SCROLL);
4459 if (Blt_ConfigModified(tabConfigSpecs, interp, "-hidden", (char *)NULL)) {
4460 setPtr->flags |= (TABSET_DIRTY);
4461 }
4462 EventuallyRedraw(setPtr);
4463 if (result == TCL_ERROR) {
4464 return TCL_ERROR;
4465 }
4466 }
4467 return TCL_OK;
4468 }
4469
4470 /*
4471 *----------------------------------------------------------------------
4472 *
4473 * TabDockallOp --
4474 *
4475 * .h tab dockall
4476 *
4477 *----------------------------------------------------------------------
4478 */
4479 /*ARGSUSED*/
4480 static int
4481 TabDockallOp(setPtr, interp, argc, argv)
4482 Tabset *setPtr;
4483 Tcl_Interp *interp;
4484 int argc; /* Not used. */
4485 char **argv; /* Not used. */
4486 {
4487 Tab *tabPtr;
4488 Blt_ChainLink *linkPtr;
4489
4490 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
4491 linkPtr = Blt_ChainNextLink(linkPtr)) {
4492 tabPtr = Blt_ChainGetValue(linkPtr);
4493 if (tabPtr->container != NULL) {
4494 Tcl_EventuallyFree(tabPtr, DestroyTearoff);
4495 }
4496 }
4497 return TCL_OK;
4498 }
4499
4500 /*
4501 *----------------------------------------------------------------------
4502 *
4503 * TabPageHeight --
4504 *
4505 * .h tab pageheight
4506 *
4507 *----------------------------------------------------------------------
4508 */
4509 /*ARGSUSED*/
4510 static int
4511 TabPageHeight(setPtr, interp, argc, argv)
4512 Tabset *setPtr;
4513 Tcl_Interp *interp;
4514 int argc; /* Not used. */
4515 char **argv; /* Not used. */
4516 {
4517 Tcl_SetResult(interp, Blt_Itoa(VPORTHEIGHT(setPtr)), TCL_VOLATILE);
4518 return TCL_OK;
4519 }
4520
4521 /*
4522 *----------------------------------------------------------------------
4523 *
4524 * TabPageWidth --
4525 *
4526 * .h tab pagewidth
4527 *
4528 *----------------------------------------------------------------------
4529 */
4530 /*ARGSUSED*/
4531 static int
4532 TabPageWidth(setPtr, interp, argc, argv)
4533 Tabset *setPtr;
4534 Tcl_Interp *interp;
4535 int argc; /* Not used. */
4536 char **argv; /* Not used. */
4537 {
4538 Tcl_SetResult(interp, Blt_Itoa(VPORTWIDTH(setPtr)), TCL_VOLATILE);
4539 return TCL_OK;
4540 }
4541
4542
4543 /*
4544 *----------------------------------------------------------------------
4545 *
4546 * TabNamesOp --
4547 *
4548 * .h tab names pattern
4549 *
4550 *----------------------------------------------------------------------
4551 */
4552 /*ARGSUSED*/
4553 static int
4554 TabNamesOp(setPtr, interp, argc, argv)
4555 Tabset *setPtr;
4556 Tcl_Interp *interp;
4557 int argc; /* Not used. */
4558 char **argv; /* Not used. */
4559 {
4560 Tab *tabPtr;
4561 Blt_ChainLink *linkPtr;
4562 Tcl_DString dStr;
4563 Tcl_DStringInit(&dStr);
4564
4565 if (argc == 3) {
4566 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
4567 linkPtr = Blt_ChainNextLink(linkPtr)) {
4568 tabPtr = Blt_ChainGetValue(linkPtr);
4569 Tcl_DStringAppendElement(&dStr, tabPtr->name);
4570 }
4571 } else {
4572 register int i;
4573
4574 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
4575 linkPtr = Blt_ChainNextLink(linkPtr)) {
4576 tabPtr = Blt_ChainGetValue(linkPtr);
4577 for (i = 3; i < argc; i++) {
4578 if (Tcl_StringMatch(tabPtr->name, argv[i])) {
4579 Tcl_DStringAppendElement(&dStr, tabPtr->name);
4580 break;
4581 }
4582 }
4583 }
4584 }
4585 Tcl_DStringResult(interp, &dStr);
4586 return TCL_OK;
4587 }
4588 /*
4589 *----------------------------------------------------------------------
4590 *
4591 * TabNumberOp --
4592 *
4593 * .h tab number nameorindex
4594 *
4595 *----------------------------------------------------------------------
4596 */
4597 /*ARGSUSED*/
4598 static int
4599 TabNumberOp(setPtr, interp, argc, argv)
4600 Tabset *setPtr;
4601 Tcl_Interp *interp;
4602 int argc; /* Not used. */
4603 char **argv;
4604 {
4605 Tab *tabPtr, *tPtr;
4606 int n = 0;
4607 Blt_ChainLink *linkPtr;
4608
4609 if (GetTabByIndName(setPtr, argv[3], &tabPtr) != TCL_OK) {
4610 return TCL_ERROR;
4611 }
4612 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
4613 linkPtr = Blt_ChainNextLink(linkPtr)) {
4614 tPtr = Blt_ChainGetValue(linkPtr);
4615 if (tPtr == tabPtr) {
4616 Tcl_SetObjResult(interp, Tcl_NewIntObj(n));
4617 break;
4618 }
4619 n++;
4620 }
4621 return TCL_OK;
4622 }
4623
4624 /*
4625 *----------------------------------------------------------------------
4626 *
4627 * TabSelectOp --
4628 *
4629 * .h tab select nameorindex
4630 *
4631 *----------------------------------------------------------------------
4632 */
4633 /*ARGSUSED*/
4634 static int
4635 TabSelectOp(setPtr, interp, argc, argv)
4636 Tabset *setPtr;
4637 Tcl_Interp *interp;
4638 int argc; /* Not used. */
4639 char **argv;
4640 {
4641 int result;
4642 Tcl_DString dStr;
4643 Tab *tabPtr;
4644
4645 if (GetTabByIndName(setPtr, argv[3], &tabPtr) != TCL_OK) {
4646 return TCL_ERROR;
4647 }
4648
4649 if (tabPtr && tabPtr->hidden) {
4650 Tcl_AppendResult(interp, "can not select hidden tab", 0);
4651 return TCL_ERROR;
4652 }
4653 Tcl_DStringInit(&dStr);
4654 Tcl_DStringAppendElement(&dStr, "::blt::TabsetSelect");
4655 Tcl_DStringAppendElement(&dStr, argv[0]);
4656 Tcl_DStringAppendElement(&dStr, argv[3]);
4657 result = Tcl_GlobalEval(interp, Tcl_DStringValue(&dStr));
4658 Tcl_DStringFree(&dStr);
4659 return result;
4660 }
4661
4662 /*
4663 *----------------------------------------------------------------------
4664 *
4665 * TabTearoffOp --
4666 *
4667 * .h tearoff ?index?
4668 *
4669 *----------------------------------------------------------------------
4670 */
4671 /*ARGSUSED*/
4672 static int
4673 TabTearoffOp(setPtr, interp, argc, argv)
4674 Tabset *setPtr;
4675 Tcl_Interp *interp;
4676 int argc; /* Not used. */
4677 char **argv;
4678 {
4679 Tab *tabPtr;
4680 Tcl_DString dStr;
4681
4682 if (argc<=3) {
4683 Blt_ChainLink *linkPtr;
4684 Tcl_DStringInit(&dStr);
4685
4686 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
4687 linkPtr = Blt_ChainNextLink(linkPtr)) {
4688 tabPtr = Blt_ChainGetValue(linkPtr);
4689 if (tabPtr->tornWin != NULL) {
4690 Tcl_DStringAppendElement(&dStr, tabPtr->name);
4691 }
4692 }
4693 Tcl_DStringResult(interp, &dStr);
4694 return TCL_OK;
4695 }
4696 if (GetTabByIndName(setPtr, argv[3], &tabPtr) != TCL_OK) {
4697 return TCL_ERROR;
4698 }
4699 if (tabPtr == NULL) {
4700 return TCL_OK; /* No-op */
4701 }
4702 if (tabPtr->tornWin != NULL) {
4703 Tcl_SetObjResult(interp, Tcl_NewStringObj(tabPtr->tornWin, -1));
4704 } else {
4705 Tcl_SetObjResult(interp, Tcl_NewStringObj(argv[0], -1));
4706 }
4707 return TCL_OK;
4708 }
4709
4710 /*
4711 *----------------------------------------------------------------------
4712 *
4713 * TearoffOp --
4714 *
4715 * .h tearoff ?index ?tab? ?
4716 *
4717 *----------------------------------------------------------------------
4718 */
4719 /*ARGSUSED*/
4720 static int
4721 TearoffOp(setPtr, interp, argc, argv)
4722 Tabset *setPtr;
4723 Tcl_Interp *interp;
4724 int argc; /* Not used. */
4725 char **argv;
4726 {
4727 Tab *tabPtr;
4728 int result;
4729 Tcl_DString dStr;
4730
4731 if (argc<=2) {
4732 Blt_ChainLink *linkPtr;
4733 Tcl_DStringInit(&dStr);
4734
4735 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
4736 linkPtr = Blt_ChainNextLink(linkPtr)) {
4737 tabPtr = Blt_ChainGetValue(linkPtr);
4738 if (tabPtr->tornWin != NULL) {
4739 Tcl_DStringAppendElement(&dStr, tabPtr->name);
4740 }
4741 }
4742 Tcl_DStringResult(interp, &dStr);
4743 return TCL_OK;
4744 }
4745 if (GetTabByIndName(setPtr, argv[2], &tabPtr) != TCL_OK) {
4746 return TCL_ERROR;
4747 }
4748 if ((tabPtr->state == STATE_DISABLED)) {
4749 return TCL_OK; /* No-op */
4750 }
4751 Tcl_Preserve(tabPtr);
4752 result = TCL_OK;
4753
4754 Tcl_ResetResult(interp);
4755
4756 Tcl_DStringInit(&dStr);
4757 Tcl_DStringAppendElement(&dStr, "::blt::TabsetTearoff");
4758 Tcl_DStringAppendElement(&dStr, argv[0]);
4759 Tcl_DStringAppendElement(&dStr, argv[2]);
4760 result = Tcl_GlobalEval(interp, Tcl_DStringValue(&dStr));
4761 Tcl_DStringFree(&dStr);
4762 Tcl_Release(tabPtr);
4763 EventuallyRedraw(setPtr);
4764 return result;
4765 }
4766
4767 /*
4768 *----------------------------------------------------------------------
4769 *
4770 * TabOp --
4771 *
4772 * This procedure handles tab operations.
4773 *
4774 * Results:
4775 * A standard Tcl result.
4776 *
4777 *----------------------------------------------------------------------
4778 */
4779 static Blt_OpSpec tabOps[] =
4780 {
4781 {"cget", 2, (Blt_Op)TabCgetOp, 5, 5, "nameOrIndex option",},
4782 {"configure", 2, (Blt_Op)TabConfigureOp, 4, 0,
4783 "nameOrIndex ?option value?...",},
4784 {"dockall", 1, (Blt_Op)TabDockallOp, 3, 3, "" },
4785 {"names", 1, (Blt_Op)TabNamesOp, 3, 0, "?pattern...?",},
4786 {"number", 1, (Blt_Op)TabNumberOp, 4, 4, "tab",},
4787 {"pageheight", 5, (Blt_Op)TabPageHeight, 3, 3, "", },
4788 {"pagewidth", 5, (Blt_Op)TabPageWidth, 3, 3, "", },
4789 {"select", 1, (Blt_Op)TabSelectOp, 4, 4, "nameOrIndex",},
4790 {"tearoff", 1, (Blt_Op)TabTearoffOp, 3, 4, "?index?",},
4791 };
4792
4793 static int nTabOps = sizeof(tabOps) / sizeof(Blt_OpSpec);
4794
4795 static int
4796 TabOp(setPtr, interp, argc, argv)
4797 Tabset *setPtr;
4798 Tcl_Interp *interp;
4799 int argc;
4800 char **argv;
4801 {
4802 Blt_Op proc;
4803 int result;
4804
4805 proc = Blt_GetOp(interp, nTabOps, tabOps, BLT_OP_ARG2, argc, argv, 0);
4806 if (proc == NULL) {
4807 return TCL_ERROR;
4808 }
4809 result = (*proc) (setPtr, interp, argc, argv);
4810 return result;
4811 }
4812
4813 /*
4814 *----------------------------------------------------------------------
4815 *
4816 * PerforationActivateOp --
4817 *
4818 * This procedure is called to activate (highlight) the
4819 * perforation.
4820 *
4821 * .h perforation activate boolean
4822 *
4823 * Results:
4824 * A standard Tcl result. If TCL_ERROR is returned, then
4825 * interp->result contains an error message.
4826 *
4827 *----------------------------------------------------------------------
4828 */
4829 /*ARGSUSED*/
4830 static int
4831 PerforationActivateOp(setPtr, interp, argc, argv)
4832 Tabset *setPtr;
4833 Tcl_Interp *interp; /* Not used. */
4834 int argc;
4835 char **argv;
4836 {
4837 int bool;
4838
4839 if (Tcl_GetBoolean(interp, argv[3], &bool) != TCL_OK) {
4840 return TCL_ERROR;
4841 }
4842 if (bool) {
4843 setPtr->flags |= PERFORATION_ACTIVE;
4844 } else {
4845 setPtr->flags &= ~PERFORATION_ACTIVE;
4846 }
4847 EventuallyRedraw(setPtr);
4848 return TCL_OK;
4849 }
4850
4851 /*
4852 *----------------------------------------------------------------------
4853 *
4854 * PerforationInvokeOp --
4855 *
4856 * This procedure is called to invoke a perforation command.
4857 *
4858 * .t perforation invoke
4859 *
4860 * Results:
4861 * A standard Tcl result. If TCL_ERROR is returned, then
4862 * interp->result contains an error message.
4863 *
4864 *----------------------------------------------------------------------
4865 */
4866 /*ARGSUSED*/
4867 static int
4868 PerforationInvokeOp(setPtr, interp, argc, argv)
4869 Tabset *setPtr;
4870 Tcl_Interp *interp; /* Not used. */
4871 int argc;
4872 char **argv;
4873 {
4874
4875 if (setPtr->selectPtr != NULL) {
4876 char *cmd;
4877
4878 cmd = GETATTR(setPtr->selectPtr, perfCommand);
4879 if (cmd != NULL) {
4880 Tcl_DString dString;
4881 int result;
4882
4883 PercentSubst(setPtr, setPtr->selectPtr, cmd, &dString);
4884 Tcl_Preserve(setPtr);
4885 result = Tcl_GlobalEval(interp, Tcl_DStringValue(&dString));
4886 Tcl_Release(setPtr);
4887 Tcl_DStringFree(&dString);
4888 if (result != TCL_OK) {
4889 return TCL_ERROR;
4890 }
4891 }
4892 }
4893 return TCL_OK;
4894 }
4895
4896 /*
4897 *----------------------------------------------------------------------
4898 *
4899 * PerforationOp --
4900 *
4901 * This procedure handles tab operations.
4902 *
4903 * Results:
4904 * A standard Tcl result.
4905 *
4906 *----------------------------------------------------------------------
4907 */
4908 static Blt_OpSpec perforationOps[] =
4909 {
4910 {"activate", 1, (Blt_Op)PerforationActivateOp, 4, 4, "boolean" },
4911 {"invoke", 1, (Blt_Op)PerforationInvokeOp, 3, 3, "",},
4912 };
4913
4914 static int nPerforationOps = sizeof(perforationOps) / sizeof(Blt_OpSpec);
4915
4916 static int
4917 PerforationOp(setPtr, interp, argc, argv)
4918 Tabset *setPtr;
4919 Tcl_Interp *interp;
4920 int argc;
4921 char **argv;
4922 {
4923 Blt_Op proc;
4924 int result;
4925
4926 proc = Blt_GetOp(interp, nPerforationOps, perforationOps, BLT_OP_ARG2,
4927 argc, argv, 0);
4928 if (proc == NULL) {
4929 return TCL_ERROR;
4930 }
4931 result = (*proc) (setPtr, interp, argc, argv);
4932 return result;
4933 }
4934
4935 /*
4936 *----------------------------------------------------------------------
4937 *
4938 * ScanOp --
4939 *
4940 * Implements the quick scan.
4941 *
4942 *----------------------------------------------------------------------
4943 */
4944 /*ARGSUSED*/
4945 static int
4946 ScanOp(setPtr, interp, argc, argv)
4947 Tabset *setPtr;
4948 Tcl_Interp *interp;
4949 int argc; /* Not used. */
4950 char **argv;
4951 {
4952 int x, y;
4953 char c;
4954 unsigned int length;
4955 int oper;
4956
4957 #define SCAN_MARK 1
4958 #define SCAN_DRAGTO 2
4959 c = argv[2][0];
4960 length = strlen(argv[2]);
4961 if ((c == 'm') && (strncmp(argv[2], "mark", length) == 0)) {
4962 oper = SCAN_MARK;
4963 } else if ((c == 'd') && (strncmp(argv[2], "dragto", length) == 0)) {
4964 oper = SCAN_DRAGTO;
4965 } else {
4966 Tcl_AppendResult(interp, "bad scan operation \"", argv[2],
4967 "\": should be either \"mark\" or \"dragto\"", (char *)NULL);
4968 return TCL_ERROR;
4969 }
4970 if ((Tk_GetPixels(interp, setPtr->tkwin, argv[3], &x) != TCL_OK) ||
4971 (Tk_GetPixels(interp, setPtr->tkwin, argv[4], &y) != TCL_OK)) {
4972 return TCL_ERROR;
4973 }
4974 if (oper == SCAN_MARK) {
4975 if (setPtr->side & SIDE_VERTICAL) {
4976 setPtr->scanAnchor = y;
4977 } else {
4978 setPtr->scanAnchor = x;
4979 }
4980 setPtr->scanOffset = setPtr->scrollOffset;
4981 } else {
4982 int offset, delta;
4983
4984 if (setPtr->side & SIDE_VERTICAL) {
4985 delta = setPtr->scanAnchor - y;
4986 } else {
4987 delta = setPtr->scanAnchor - x;
4988 }
4989 offset = setPtr->scanOffset + (10 * delta);
4990 offset = Blt_AdjustViewport(offset, setPtr->worldWidth,
4991 VPORTWIDTH(setPtr), setPtr->scrollUnits, BLT_SCROLL_MODE_CANVAS);
4992 setPtr->scrollOffset = offset;
4993 setPtr->flags |= TABSET_SCROLL;
4994 EventuallyRedraw(setPtr);
4995 }
4996 return TCL_OK;
4997 }
4998
4999 /*ARGSUSED*/
5000 static int
5001 SizeOp(setPtr, interp, argc, argv)
5002 Tabset *setPtr;
5003 Tcl_Interp *interp;
5004 int argc; /* Not used. */
5005 char **argv; /* Not used. */
5006 {
5007 Tcl_SetResult(interp, Blt_Itoa(Blt_ChainGetLength(setPtr->chainPtr)),
5008 TCL_VOLATILE);
5009 return TCL_OK;
5010 }
5011
5012
5013 static int
5014 CountTabs(setPtr)
5015 Tabset *setPtr;
5016 {
5017 int count;
5018 int width, height;
5019 Blt_ChainLink *linkPtr;
5020 register Tab *tabPtr;
5021 register int pageWidth, pageHeight;
5022 int labelWidth, labelHeight;
5023 int tabWidth, tabHeight;
5024
5025 pageWidth = pageHeight = 0;
5026 count = 0;
5027
5028 labelWidth = labelHeight = 0;
5029
5030 /*
5031 * Pass 1: Figure out the maximum area needed for a label and a
5032 * page. Both the label and page dimensions are adjusted
5033 * for orientation. In addition, reset the visibility
5034 * flags and reorder the tabs.
5035 */
5036 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5037 linkPtr = Blt_ChainNextLink(linkPtr)) {
5038 tabPtr = Blt_ChainGetValue(linkPtr);
5039
5040 /* Reset visibility flag and order of tabs. */
5041
5042 tabPtr->flags &= ~TAB_VISIBLE;
5043 if (tabPtr->hidden) continue;
5044 count++;
5045
5046 if (tabPtr->tkwin != NULL) {
5047 width = GetReqWidth(tabPtr);
5048 if (pageWidth < width) {
5049 pageWidth = width;
5050 }
5051 height = GetReqHeight(tabPtr);
5052 if (pageHeight < height) {
5053 pageHeight = height;
5054 }
5055 }
5056 if (labelWidth < tabPtr->labelWidth) {
5057 labelWidth = tabPtr->labelWidth;
5058 }
5059 if (labelHeight < tabPtr->labelHeight) {
5060 labelHeight = tabPtr->labelHeight;
5061 }
5062 }
5063
5064 setPtr->overlap = 0;
5065
5066 /* Allow start/end image size to force tab size bigger. */
5067 if (setPtr->side & SIDE_VERTICAL) {
5068 if (setPtr->hMin > labelWidth) labelWidth = setPtr->hMin;
5069 } else {
5070 if (setPtr->hMin > labelHeight) labelHeight = setPtr->hMin;
5071 }
5072
5073 /*
5074 * Pass 2: Set the individual sizes of each tab. This is different
5075 * for constant and variable width tabs. Add the extra space
5076 * needed for slanted tabs, now that we know maximum tab
5077 * height.
5078 */
5079 if (setPtr->defTabStyle.constWidth) {
5080 int slant;
5081
5082 tabWidth = 2 * setPtr->inset2;
5083 tabHeight = setPtr->inset2 /* + 4 */;
5084
5085 if (setPtr->side & SIDE_VERTICAL) {
5086 tabWidth += labelHeight;
5087 tabHeight += labelWidth;
5088 slant = labelWidth;
5089 } else {
5090 tabWidth += labelWidth;
5091 tabHeight += labelHeight;
5092 slant = labelHeight;
5093 }
5094 if (setPtr->slant & SLANT_LEFT) {
5095 tabWidth += slant;
5096 setPtr->overlap += tabHeight / 2;
5097 }
5098 if (setPtr->slant & SLANT_RIGHT) {
5099 tabWidth += slant;
5100 setPtr->overlap += tabHeight / 2;
5101 }
5102 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5103 linkPtr = Blt_ChainNextLink(linkPtr)) {
5104 tabPtr = Blt_ChainGetValue(linkPtr);
5105 tabPtr->worldWidth = tabWidth;
5106 tabPtr->worldHeight = tabHeight;
5107 }
5108 } else {
5109 int slant;
5110
5111 tabWidth = tabHeight = 0;
5112 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5113 linkPtr = Blt_ChainNextLink(linkPtr)) {
5114 tabPtr = Blt_ChainGetValue(linkPtr);
5115 if (tabPtr->hidden) continue;
5116
5117 width = 2 * setPtr->inset2;
5118 height = setPtr->inset2 /* + 4 */;
5119 if (setPtr->side & SIDE_VERTICAL) {
5120 width += tabPtr->labelHeight;
5121 height += labelWidth;
5122 slant = labelWidth;
5123 } else {
5124 width += tabPtr->labelWidth;
5125 height += labelHeight;
5126 slant = labelHeight;
5127 }
5128 width += (setPtr->slant & SLANT_LEFT) ? slant : setPtr->corner;
5129 width += (setPtr->slant & SLANT_RIGHT) ? slant : setPtr->corner;
5130
5131 tabPtr->worldWidth = width; /* + 2 * (setPtr->corner + setPtr->xSelectPad) */ ;
5132 tabPtr->worldHeight = height;
5133
5134 if (tabWidth < width) {
5135 tabWidth = width;
5136 }
5137 if (tabHeight < height) {
5138 tabHeight = height;
5139 }
5140 }
5141 if (setPtr->slant & SLANT_LEFT) {
5142 setPtr->overlap += tabHeight / 2;
5143 }
5144 if (setPtr->slant & SLANT_RIGHT) {
5145 setPtr->overlap += tabHeight / 2;
5146 }
5147 }
5148
5149 setPtr->tabWidth = tabWidth;
5150 setPtr->tabHeight = tabHeight;
5151
5152 /*
5153 * Let the user override any page dimension.
5154 */
5155 setPtr->pageWidth = pageWidth;
5156 setPtr->pageHeight = pageHeight;
5157 if (setPtr->reqPageWidth > 0) {
5158 setPtr->pageWidth = setPtr->reqPageWidth;
5159 }
5160 if (setPtr->reqPageHeight > 0) {
5161 setPtr->pageHeight = setPtr->reqPageHeight;
5162 }
5163 return count;
5164 }
5165
5166
5167 static void
5168 WidenTabs(setPtr, startPtr, nTabs, adjustment)
5169 Tabset *setPtr;
5170 Tab *startPtr;
5171 int nTabs;
5172 int adjustment;
5173 {
5174 register Tab *tabPtr;
5175 register int i;
5176 int ration;
5177 Blt_ChainLink *linkPtr;
5178 int x, sImg;
5179 int vert = (setPtr->side & SIDE_VERTICAL);
5180
5181 sImg = 0;
5182
5183 if (setPtr->startImage) {
5184 sImg = (vert?setPtr->startImage->height:setPtr->startImage->width);
5185 }
5186
5187 x = startPtr->tier;
5188 while (adjustment > 0) {
5189 ration = adjustment / nTabs;
5190 if (ration == 0) {
5191 ration = 1;
5192 }
5193 linkPtr = startPtr->linkPtr;
5194 for (i = 0; (linkPtr != NULL) && (adjustment > 0); ) {
5195 tabPtr = Blt_ChainGetValue(linkPtr);
5196 if (!tabPtr->hidden) {
5197 adjustment -= ration;
5198 tabPtr->worldWidth += ration;
5199 assert(x == tabPtr->tier);
5200 i++;
5201 }
5202 linkPtr = Blt_ChainNextLink(linkPtr);
5203 if (i>=nTabs) break;
5204 }
5205 }
5206 /*
5207 * Go back and reset the world X-coordinates of the tabs,
5208 * now that their widths have changed.
5209 */
5210 x = sImg;
5211 linkPtr = startPtr->linkPtr;
5212 for (i = 0; (i < nTabs) && (linkPtr != NULL); ) {
5213 tabPtr = Blt_ChainGetValue(linkPtr);
5214 if (!tabPtr->hidden) {
5215 tabPtr->worldX = x;
5216 x += tabPtr->worldWidth + setPtr->gap - setPtr->overlap;
5217 i++;
5218 if (i>=nTabs) break;
5219 }
5220 linkPtr = Blt_ChainNextLink(linkPtr);
5221 }
5222 }
5223
5224
5225 static Blt_ChainLink *ChainNextLinkVis(Blt_ChainLink *linkPtr) {
5226 Tab *tabPtr;
5227 while (linkPtr) {
5228 linkPtr = Blt_ChainNextLink(linkPtr);
5229 if (linkPtr == NULL) break;
5230 tabPtr = Blt_ChainGetValue(linkPtr);
5231 if (!tabPtr->hidden) { return linkPtr; }
5232 }
5233 return linkPtr;
5234 }
5235
5236 /* If ntiers>1 adjust last row to fill it out. */
5237 static void
5238 AdjustTabSizes(setPtr, nTabs)
5239 Tabset *setPtr;
5240 int nTabs;
5241 {
5242 int tabsPerTier;
5243 int total, count, extra;
5244 Tab *startPtr, *nextPtr;
5245 Blt_ChainLink *linkPtr;
5246 register Tab *tabPtr;
•5247 int x, maxWidth, sImg;
5248 int vert = (setPtr->side & SIDE_VERTICAL);
5249
5250 sImg = 0;
5251
5252 if (setPtr->startImage) {
5253 sImg = (vert?setPtr->startImage->height:setPtr->startImage->width);
5254 }
5255
5256 tabsPerTier = (nTabs + (setPtr->nTiers - 1)) / setPtr->nTiers;
5257 x = sImg;
5258 maxWidth = 0;
5259 if (setPtr->defTabStyle.constWidth) {
5260 register int i;
5261
5262 linkPtr = Blt_ChainFirstLink(setPtr->chainPtr);
5263 count = 1;
5264 while (linkPtr != NULL) {
5265 for (i = 0; i < tabsPerTier;) {
5266 tabPtr = Blt_ChainGetValue(linkPtr);
5267 if (tabPtr->hidden) {
5268 linkPtr = Blt_ChainNextLink(linkPtr);
5269 continue;
5270 }
5271 i++;
5272 if (i>=tabsPerTier) break;
5273 tabPtr->tier = count;
5274 tabPtr->worldX = x;
5275 x += tabPtr->worldWidth + setPtr->gap - setPtr->overlap;
5276 linkPtr = Blt_ChainNextLink(linkPtr);
5277 if (x > maxWidth) {
5278 maxWidth = x;
5279 }
5280 if (linkPtr == NULL) {
5281 goto done;
5282 }
5283 }
5284 count++;
5285 x = sImg;
5286 }
5287 }
5288 done:
5289 /* Add to tab widths to fill out row. */
5290 if (((nTabs % tabsPerTier) != 0) && (setPtr->defTabStyle.constWidth)) {
5291 return;
5292 }
5293 if (!setPtr->defTabStyle.fillWidth) {
5294 return;
5295 }
5296
5297 startPtr = NULL;
5298 count = total = 0;
5299 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5300 /*empty*/ ) {
5301 tabPtr = Blt_ChainGetValue(linkPtr);
5302 linkPtr = ChainNextLinkVis(linkPtr);
5303 if (tabPtr->hidden) {
5304 continue;
5305 }
5306 if (startPtr == NULL) {
5307 startPtr = tabPtr;
5308 }
5309 count++;
5310 total += tabPtr->worldWidth + setPtr->gap - setPtr->overlap;
5311 if (linkPtr != NULL) {
5312 nextPtr = Blt_ChainGetValue(linkPtr);
5313 if (tabPtr->tier == nextPtr->tier) {
5314 continue;
5315 }
5316 }
5317 total += setPtr->overlap;
5318 extra = setPtr->worldWidth - total;
5319 assert(count > 0);
5320 if (extra > 0) {
5321 WidenTabs(setPtr, startPtr, count, extra);
5322 }
5323 count = total = 0;
5324 startPtr = NULL;
5325 }
5326 }
5327
5328 /*
5329 *
5330 * tabWidth = textWidth + gap + (2 * (pad + outerBW));
5331 *
5332 * tabHeight = textHeight + 2 * (pad + outerBW) + topMargin;
5333 *
5334 */
5335 static void
5336 ComputeLayout(setPtr)
5337 Tabset *setPtr;
5338 {
5339 int width;
5340 Blt_ChainLink *linkPtr;
5341 Tab *tabPtr;
5342 int x, extra, sImg, eImg, vert;
5343 int siw, sih, eiw, eih;
5344 int nTiers, nTabs;
5345
5346 setPtr->nTiers = 0;
5347 setPtr->pageTop = 0;
5348 setPtr->worldWidth = 1;
5349 setPtr->yPad = 0;
5350 sImg = 0;
5351 eImg = 0;
5352 setPtr->hMin = 0;
5353 siw = sih = eiw = eih = 0;
5354 vert = (setPtr->side & SIDE_VERTICAL);
5355
5356 if (setPtr->startImage) {
5357 sih = setPtr->startImage->height;
5358 siw = setPtr->startImage->width;
5359 if (vert) {
5360 sImg = sih;
5361 setPtr->hMin = siw;
5362 } else {
5363 sImg = siw;
5364 setPtr->hMin = sih;
5365 }
5366 }
5367 if (setPtr->endImage) {
5368 eih = setPtr->endImage->height;
5369 eiw = setPtr->endImage->width;
5370 if (vert) {
5371 eImg = eih;
5372 if (eiw>setPtr->hMin) setPtr->hMin = eiw;
5373 } else {
5374 eImg = eiw;
5375 if (eih>setPtr->hMin) setPtr->hMin = eih;
5376 }
5377 if (sImg < eImg) { sImg = eImg; }
5378 }
5379
5380 nTabs = CountTabs(setPtr);
5381 if (nTabs == 0) {
5382 return;
5383 }
5384 /* Reset the pointers to the selected and starting tab. */
5385 if (setPtr->selectPtr == NULL || setPtr->selectPtr->hidden) {
5386 setPtr->selectPtr = NULL;
5387 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr);
5388 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
5389 if (linkPtr == NULL) continue;
5390 tabPtr = Blt_ChainGetValue(linkPtr);
5391 if (tabPtr->hidden) continue;
5392 setPtr->selectPtr = tabPtr;
5393 break;
5394 }
5395 }
5396 if (setPtr->selectPtr == NULL) {
5397 return;
5398 }
5399 if (setPtr->startPtr == NULL) {
5400 setPtr->startPtr = setPtr->selectPtr;
5401 }
5402 if (setPtr->focusPtr == NULL) {
5403 setPtr->focusPtr = setPtr->selectPtr;
5404 Blt_SetFocusItem(setPtr->bindTable, setPtr->focusPtr, NULL);
5405 }
5406
5407 if (setPtr->side & SIDE_VERTICAL) {
5408 width = Tk_Height(setPtr->tkwin) -
5409 2 * (setPtr->corner + setPtr->xSelectPad) - eImg;
5410 } else {
5411 width = Tk_Width(setPtr->tkwin) - (2 * setPtr->inset) -
5412 setPtr->xSelectPad - setPtr->corner - eImg;
5413 }
5414 setPtr->flags |= TABSET_STATIC;
5415 if (setPtr->reqTiers > 1) {
5416 int total, maxWidth;
5417
5418 /* Static multiple tier mode. */
5419
5420 /* Sum tab widths and determine the number of tiers needed. */
5421 nTiers = 1;
5422 total = x = sImg;
5423 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5424 linkPtr = Blt_ChainNextLink(linkPtr)) {
5425 tabPtr = Blt_ChainGetValue(linkPtr);
5426 if (tabPtr->hidden) continue;
5427 if ((x + tabPtr->worldWidth) > width) {
5428 nTiers++;
5429 x = sImg;
5430 }
5431 tabPtr->worldX = x;
5432 tabPtr->tier = nTiers;
5433 extra = tabPtr->worldWidth + setPtr->gap - setPtr->overlap;
5434 total += extra, x += extra;
5435 }
5436 maxWidth = width;
5437
5438 if (nTiers > setPtr->reqTiers) {
5439 /*
5440 * The tabs do not fit into the requested number of tiers.
5441 * Go into scrolling mode.
5442 */
5443 width = ((total + setPtr->tabWidth) / setPtr->reqTiers);
5444 x = sImg;
5445 nTiers = 1;
5446 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr);
5447 linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
5448 tabPtr = Blt_ChainGetValue(linkPtr);
5449 if (tabPtr->hidden) continue;
5450 tabPtr->tier = nTiers;
5451 /*
5452 * Keep adding tabs to a tier until we overfill it.
5453 */
5454 tabPtr->worldX = x;
5455 x += tabPtr->worldWidth + setPtr->gap - setPtr->overlap;
5456 if (x > width) {
5457 nTiers++;
5458 if (x > maxWidth) {
5459 maxWidth = x;
5460 }
5461 x = sImg;
5462 }
5463 }
5464 setPtr->flags &= ~TABSET_STATIC;
5465 }
5466 setPtr->worldWidth = maxWidth - sImg;
5467 setPtr->nTiers = nTiers;
5468
5469 if (nTiers > 1) {
5470 AdjustTabSizes(setPtr, nTabs);
5471 }
5472 if (setPtr->flags & TABSET_STATIC) {
5473 setPtr->worldWidth = VPORTWIDTH(setPtr);
5474 } else {
5475 /* Do you add an offset ? */
5476 setPtr->worldWidth += (setPtr->xSelectPad + setPtr->corner);
5477 }
5478 setPtr->worldWidth += setPtr->overlap;
5479 if (setPtr->selectPtr != NULL) {
5480 RenumberTiers(setPtr, setPtr->selectPtr);
5481 }
5482 } else {
5483 /*
5484 * Scrollable single tier mode.
5485 */
5486 nTiers = 1;
5487 x = sImg;
5488 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5489 linkPtr = Blt_ChainNextLink(linkPtr)) {
5490 tabPtr = Blt_ChainGetValue(linkPtr);
5491 if (tabPtr->hidden) continue;
5492 tabPtr->tier = nTiers;
5493 tabPtr->worldX = x;
5494 tabPtr->worldY = 0;
5495 x += tabPtr->worldWidth + setPtr->gap - setPtr->overlap;
5496 }
5497 setPtr->worldWidth = x + setPtr->corner - setPtr->gap +
5498 setPtr->xSelectPad + setPtr->overlap;
5499 setPtr->flags &= ~TABSET_STATIC;
5500 }
5501 if (nTiers == 1) {
5502 setPtr->yPad = setPtr->ySelectPad;
5503 }
5504 setPtr->nTiers = nTiers;
5505 setPtr->pageTop = setPtr->inset + setPtr->yPad /* + 4 */ +
5506 (setPtr->nTiers * setPtr->tabHeight) + setPtr->inset2;
5507
5508 if (setPtr->side & SIDE_VERTICAL) {
5509 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5510 linkPtr = Blt_ChainNextLink(linkPtr)) {
5511 tabPtr = Blt_ChainGetValue(linkPtr);
5512 if (tabPtr->hidden) continue;
5513 tabPtr->screenWidth = (short int)setPtr->tabHeight;
5514 tabPtr->screenHeight = (short int)tabPtr->worldWidth;
5515 }
5516 } else {
5517 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5518 linkPtr = Blt_ChainNextLink(linkPtr)) {
5519 tabPtr = Blt_ChainGetValue(linkPtr);
5520 if (tabPtr->hidden) continue;
5521 tabPtr->screenWidth = (short int)tabPtr->worldWidth;
5522 tabPtr->screenHeight = (short int)setPtr->tabHeight;
5523 }
5524 }
5525 switch (setPtr->side) {
5526 case SIDE_RIGHT:
5527 setPtr->siX = Tk_Width(setPtr->tkwin) - siw - setPtr->inset;
5528 setPtr->siY = setPtr->inset;
5529 setPtr->eiX = Tk_Width(setPtr->tkwin) - eiw - setPtr->inset;
5530 setPtr->eiY = Tk_Height(setPtr->tkwin) - eih - setPtr->inset;
5531 break;
5532
5533 case SIDE_BOTTOM:
5534 setPtr->siX = setPtr->inset;
5535 setPtr->siY = Tk_Height(setPtr->tkwin) - sih - 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_LEFT:
5541 setPtr->siX = setPtr->inset;
5542 setPtr->siY = setPtr->inset;
5543 setPtr->eiX = setPtr->inset;
5544 setPtr->eiY = Tk_Height(setPtr->tkwin) - eih - setPtr->inset;
5545 break;
5546
5547 case SIDE_TOP:
5548 setPtr->siX = setPtr->inset/2;
5549 if (sih>=setPtr->tabHeight) {
5550 setPtr->siY = 0; /* setPtr->inset; */
5551 } else {
5552 setPtr->siY = (setPtr->tabHeight-sih)/2;
5553 }
5554 if (eih>=setPtr->tabHeight) {
5555 setPtr->eiY = 0; /* setPtr->inset; */
5556 } else {
5557 setPtr->eiY = (setPtr->tabHeight-eih)/2;
5558 }
5559 setPtr->eiX = Tk_Width(setPtr->tkwin) - eiw - setPtr->inset/2;
5560 break;
5561 }
5562 }
5563
5564 static void
5565 ComputeVisibleTabs(setPtr)
5566 Tabset *setPtr;
5567 {
5568 int nVisibleTabs;
5569 register Tab *tabPtr;
5570 Blt_ChainLink *linkPtr;
5571
5572 setPtr->nVisible = 0;
5573 if (Blt_ChainGetLength(setPtr->chainPtr) == 0) {
5574 return;
5575 }
5576 nVisibleTabs = 0;
5577 if (setPtr->flags & TABSET_STATIC) {
5578
5579 /* Static multiple tier mode. */
5580
5581 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5582 linkPtr = Blt_ChainNextLink(linkPtr)) {
5583 tabPtr = Blt_ChainGetValue(linkPtr);
5584 if (tabPtr->hidden) continue;
5585 tabPtr->flags |= TAB_VISIBLE;
5586 nVisibleTabs++;
5587 }
5588 } else {
5589 int width, offset;
5590 /*
5591 * Scrollable (single or multiple) tier mode.
5592 */
5593 offset = setPtr->scrollOffset - (setPtr->outerPad + setPtr->xSelectPad);
5594 width = VPORTWIDTH(setPtr) + setPtr->scrollOffset +
5595 2 * setPtr->outerPad;
5596 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5597 linkPtr = Blt_ChainNextLink(linkPtr)) {
5598 tabPtr = Blt_ChainGetValue(linkPtr);
5599 if (tabPtr->hidden) {
5600 tabPtr->flags &= ~TAB_VISIBLE;
5601 continue;
5602 }
5603 if ((tabPtr->worldX >= width) ||
5604 ((tabPtr->worldX + tabPtr->worldWidth) < offset)) {
5605 tabPtr->flags &= ~TAB_VISIBLE;
5606 } else {
5607 tabPtr->flags |= TAB_VISIBLE;
5608 nVisibleTabs++;
5609 }
5610 }
5611 }
5612 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
5613 linkPtr = Blt_ChainNextLink(linkPtr)) {
5614 tabPtr = Blt_ChainGetValue(linkPtr);
5615 if (tabPtr->hidden) continue;
5616 tabPtr->screenX = tabPtr->screenY = -1000;
5617 if (tabPtr->flags & TAB_VISIBLE) {
5618 WorldToScreen(setPtr, tabPtr->worldX, tabPtr->worldY,
5619 &(tabPtr->screenX), &(tabPtr->screenY));
5620 switch (setPtr->side) {
5621 case SIDE_RIGHT:
5622 tabPtr->screenX -= setPtr->tabHeight;
5623 break;
5624
5625 case SIDE_BOTTOM:
5626 tabPtr->screenY -= setPtr->tabHeight;
5627 break;
5628 }
5629 }
5630 }
5631 setPtr->nVisible = nVisibleTabs;
5632 Blt_PickCurrentItem(setPtr->bindTable);
5633 }
5634
5635
5636 static void
5637 Draw3DFolder(setPtr, tabPtr, drawable, side, pointArr, nPoints)
5638 Tabset *setPtr;
5639 Tab *tabPtr;
5640 Drawable drawable;
5641 int side;
5642 XPoint pointArr[];
5643 int nPoints;
5644 {
5645 GC gc;
5646 int relief, borderWidth;
5647 Tk_3DBorder border;
5648 Blt_Tile tile = (tabPtr->tile?tabPtr->tile:setPtr->tile);
5649 /* tile = setPtr->tile; Bug: tabPtr->tile needs to set offset */
5650
5651 if (tabPtr == setPtr->selectPtr) {
5652 border = GETATTR(tabPtr, selBorder);
5653 if (setPtr->seltile) {
5654 tile = setPtr->seltile;
5655 }
5656
5657 } else {
5658 border = tabPtr->border;
5659 }
5660 if (border == NULL) {
5661 border = setPtr->defTabStyle.border;
5662 }
5663 relief = setPtr->defTabStyle.relief;
5664 if ((side == SIDE_RIGHT) || (side == SIDE_TOP)) {
5665 borderWidth = -setPtr->defTabStyle.borderWidth;
5666 if (relief == TK_RELIEF_SUNKEN) {
5667 relief = TK_RELIEF_RAISED;
5668 } else if (relief == TK_RELIEF_RAISED) {
5669 relief = TK_RELIEF_SUNKEN;
5670 }
5671 } else {
5672 borderWidth = setPtr->defTabStyle.borderWidth;
5673 }
5674 /* Draw the outline of the folder. */
5675 gc = Tk_GCForColor(setPtr->shadowColor, drawable);
5676 XDrawLines(setPtr->display, drawable, gc, pointArr, nPoints, CoordModeOrigin);
5677 /* And the folder itself. */
5678 if (Blt_HasTile(tile)) {
5679 Blt_TilePolygon(setPtr->tkwin, drawable, tile, pointArr,
5680 nPoints);
5681 Tk_Draw3DPolygon(setPtr->tkwin, drawable, border, pointArr, nPoints,
5682 borderWidth, relief);
5683 } else {
5684 Tk_Fill3DPolygon(setPtr->tkwin, drawable, border, pointArr, nPoints,
5685 borderWidth, relief);
5686 }
5687 }
5688
5689 /*
5690 * x,y
5691 * |1|2|3| 4 |3|2|1|
5692 *
5693 * 1. tab border width
5694 * 2. corner offset
5695 * 3. label pad
5696 * 4. label width
5697 *
5698 *
5699 */
5700 static void
5701 DrawLabel(setPtr, tabPtr, drawable)
5702 Tabset *setPtr;
5703 Tab *tabPtr;
5704 Drawable drawable;
5705 {
5706 int x, y, dx, dy;
5707 int tx, ty, ix, iy, i2x, i2y, iw, ih, iw2, ih2;
5708 int imgWidth, imgHeight;
5709 int img2Width, img2Height;
5710 int active, selected, labelbg = 0;
5711 XColor *fgColor, *bgColor;
5712 Tk_3DBorder border;
5713 GC gc;
5714
5715 TabImage image;
5716 TabImage image2;
5717
5718 if (!(tabPtr->flags & TAB_VISIBLE)) {
5719 return;
5720 }
5721 x = tabPtr->screenX;
5722 y = tabPtr->screenY;
5723
5724 active = (setPtr->activePtr == tabPtr);
5725 selected = (setPtr->selectPtr == tabPtr);
5726
5727 fgColor = GETATTR(tabPtr, textColor);
5728 border = GETATTR(tabPtr, border);
5729 image = GETATTR(tabPtr, image);
5730 image2 = GETATTR(tabPtr, image2);
5731 if (selected) {
5732 border = GETATTR(tabPtr, selBorder);
5733 }
5734 if (border == NULL) {
5735 border = GETATTR(tabPtr, border);
5736 }
5737 bgColor = Tk_3DBorderColor(border);
5738 if (active) {
5739 Tk_3DBorder activeBorder;
5740
5741 activeBorder = GETATTR(tabPtr, activeBorder);
5742 if (activeBorder == NULL) {
5743 activeBorder = GETATTR(tabPtr, border);
5744 }
5745 bgColor = Tk_3DBorderColor(activeBorder);
5746 } else if (setPtr->defTabStyle.labelBorder != NULL) {
5747 bgColor = Tk_3DBorderColor(setPtr->defTabStyle.labelBorder);
5748 }
5749 dx = 0;
5750 dy = 0;
5751 TranslateAnchor(
5752 (tabPtr->screenWidth - tabPtr->labelWidth),
5753 (tabPtr->screenHeight - tabPtr->labelHeight),
5754 setPtr->anchor, &dx, &dy, setPtr->slant);
5755 /*dx = (tabPtr->screenWidth - tabPtr->labelWidth) / 2;
5756 dy = (tabPtr->screenHeight - tabPtr->labelHeight) / 2;*/
5757
5758
5759 /*
5760 * The label position is computed with screen coordinates. This
5761 * is because both text and image components are oriented in
5762 * screen coordinate space, and not according to the orientation
5763 * of the tabs themselves. That's why we have to consider the
5764 * side when correcting for left/right slants.
5765 */
5766 switch (setPtr->side) {
5767 case SIDE_LEFT:
5768 case SIDE_RIGHT:
5769 if (setPtr->slant == SLANT_LEFT) {
5770 y += setPtr->overlap;
5771 } else if (setPtr->slant == SLANT_RIGHT) {
5772 y -= setPtr->overlap;
5773 }
5774 break;
•5775 case SIDE_TOP:
5776 case SIDE_BOTTOM:
5777 default:
5778 if (setPtr->slant == SLANT_LEFT) {
5779 x += setPtr->overlap;
5780 } else if (setPtr->slant == SLANT_RIGHT) {
5781 x -= setPtr->overlap;
5782 }
5783 break;
5784 }
5785
5786 /*
5787 * Draw the active or normal background color over the entire
5788 * label area. This includes both the tab's text and image.
5789 * The rectangle should be 2 pixels wider/taller than this
5790 * area. So if the label consists of just an image, we get an
5791 * halo around the image when the tab is active.
5792 */
5793 gc = Tk_GCForColor(bgColor, drawable);
5794 if ((Blt_HasTile(setPtr->tile) == 0 && Blt_HasTile(tabPtr->tile) == 0 ) || active || selected) {
5795 if (selected == 0 || Blt_HasTile(setPtr->seltile) == 0 || setPtr->defTabStyle.labelBorder != NULL) {
5796 XFillRectangle(setPtr->display, drawable, gc, x + dx, y + dy,
5797 tabPtr->labelWidth, tabPtr->labelHeight);
5798 }
5799 if ((setPtr->flags & TABSET_FOCUS) && (setPtr->focusPtr == tabPtr)) {
5800 XDrawRectangle(setPtr->display, drawable, setPtr->defTabStyle.activeGC,
5801 x + dx, y + dy, tabPtr->labelWidth - 1, tabPtr->labelHeight - 1);
5802 }
5803 } else if (labelbg) {
5804 XFillRectangle(setPtr->display, drawable, gc, x + dx, y + dy,
5805 tabPtr->labelWidth, tabPtr->labelHeight);
5806 }
5807 tx = ty = ix = iy = 0; /* Suppress compiler warning. */
5808
5809 iw = ih = imgWidth = imgHeight = 0;
5810 if (image != NULL) {
5811 iw = imgWidth = ImageWidth(image);
5812 ih = imgHeight = ImageHeight(image);
5813 }
•5814 iw2 = ih2 = img2Width = img2Height = 0;
5815 if (image2 != NULL) {
5816 iw2 = img2Width = ImageWidth(image2);
5817 ih2 = img2Height = ImageHeight(image2);
5818 if (image == NULL) {
5819 iw = img2Width;
5820 ih = img2Height;
5821 }
5822
5823 }
5824 switch (setPtr->defTabStyle.textSide) {
5825 case SIDE_LEFT:
5826 tx = x + dx + tabPtr->iPadX.side1;
5827 ty = y + (tabPtr->screenHeight - tabPtr->textHeight) / 2;
5828 ix = tx + tabPtr->textWidth + IMAGE_PAD;
5829 iy = y + (tabPtr->screenHeight - ih) / 2;
5830 break;
5831 case SIDE_RIGHT:
5832 ix = x + dx + tabPtr->iPadX.side1 + IMAGE_PAD;
5833 iy = y + (tabPtr->screenHeight - ih) / 2;
5834 tx = ix + imgWidth;
5835 ty = y + (tabPtr->screenHeight - tabPtr->textHeight) / 2;
5836 break;
5837 case SIDE_BOTTOM:
5838 iy = y + dy + tabPtr->iPadY.side1 + IMAGE_PAD;
5839 ix = x + (tabPtr->screenWidth - iw) / 2;
5840 ty = iy + imgHeight;
5841 tx = x + (tabPtr->screenWidth - tabPtr->textWidth) / 2;
5842 break;
5843 case SIDE_TOP:
•5844 default:
5845 tx = x + (tabPtr->screenWidth - tabPtr->textWidth) / 2;
5846 ty = y + dy + tabPtr->iPadY.side1 + IMAGE_PAD;
5847 ix = x + (tabPtr->screenWidth - iw) / 2;
5848 iy = ty + tabPtr->textHeight;
5849 break;
5850 }
5851 if (image == NULL) {
5852 tabPtr->iW = 0;
5853 } else {
5854 tabPtr->iX = ix;
5855 tabPtr->iY = iy;
5856 tabPtr->iW = imgWidth;
5857 tabPtr->iH = imgHeight;
5858 Tk_RedrawImage(ImageBits(image), 0, 0, imgWidth, imgHeight,
5859 drawable, ix, iy);
5860 }
5861 if (tabPtr->text == NULL) {
5862 tabPtr->tW = 0;
5863 } else {
5864 TextStyle ts;
5865 XColor *activeColor;
5866 Shadow *shadow;
5867
5868 shadow = (tabPtr->shadow.offset? &tabPtr->shadow : &setPtr->shadow);
5869 activeColor = fgColor;
5870 if (selected) {
5871 activeColor = GETATTR(tabPtr, selColor);
5872 } else if (active) {
5873 activeColor = GETATTR(tabPtr, activeFgColor);
5874 }
5875 if (activeColor == NULL) {
5876 activeColor = GETATTR(tabPtr, textColor);
5877 }
5878 Blt_SetDrawTextStyle(&ts, GETATTR(tabPtr, font), tabPtr->textGC,
5879 fgColor, activeColor, shadow->color,
5880 setPtr->defTabStyle.rotate, TK_ANCHOR_NW, TK_JUSTIFY_LEFT,
5881 0, shadow->offset);
5882 ts.underline = tabPtr->underline;
5883 ts.state = tabPtr->state;
5884 ts.border = border;
5885 ts.padX.side1 = ts.padX.side2 = 2;
5886 if ((selected) || (active)) {
5887 ts.state |= STATE_ACTIVE;
5888 }
5889 Blt_DrawText(setPtr->tkwin, drawable, tabPtr->textDisp, &ts, tx, ty);
5890 tabPtr->tX = tx;
5891 tabPtr->tY = ty;
5892 tabPtr->tW = ts.width;
5893 tabPtr->tH = ts.height;
5894 }
5895 if (image2 == NULL) {
5896 tabPtr->i2W = 0;
5897 return;
5898 }
5899 switch (setPtr->defTabStyle.textSide) {
5900 case SIDE_LEFT:
5901 i2x = ix + imgWidth + IMAGE_PAD + setPtr->gapLeft;
5902 i2y = y + (tabPtr->screenHeight - ih2) / 2;
5903 break;
5904 case SIDE_RIGHT:
5905 i2x = ix + imgWidth + tabPtr->textWidth + IMAGE_PAD + setPtr->gapLeft;
5906 i2y = y + (tabPtr->screenHeight - ih2) / 2;
5907 break;
5908 case SIDE_BOTTOM:
5909 i2y = iy + imgHeight + tabPtr->textHeight + IMAGE_PAD + setPtr->gapLeft;
5910 i2x = x + (tabPtr->screenWidth - iw2) / 2;
5911 break;
5912 case SIDE_TOP:
•5913 default:
5914 i2y = iy + imgHeight + IMAGE_PAD + setPtr->gapLeft;
5915 i2x = x + (tabPtr->screenWidth - iw2) / 2;
5916 break;
5917 }
5918 tabPtr->i2X = i2x;
5919 tabPtr->i2Y = i2y;
5920 tabPtr->i2W = img2Width;
5921 tabPtr->i2H = img2Height;
5922 Tk_RedrawImage(ImageBits(image2), 0, 0, img2Width, img2Height,
5923 drawable, i2x, i2y);
5924 }
5925
5926
5927 static void
5928 DrawPerforation(setPtr, tabPtr, drawable)
5929 Tabset *setPtr;
5930 Tab *tabPtr;
5931 Drawable drawable;
5932 {
5933 XPoint pointArr[2];
5934 int x, y;
5935 int segmentWidth, max;
5936 Tk_3DBorder border, perfBorder;
5937
5938 if ((tabPtr->container != NULL) || (tabPtr->tkwin == NULL)) {
5939 return;
5940 }
5941 WorldToScreen(setPtr, tabPtr->worldX + 2,
5942 tabPtr->worldY + tabPtr->worldHeight + 2, &x, &y);
5943 border = GETATTR(tabPtr, selBorder);
5944 if (border == NULL) {
5945 border = GETATTR(tabPtr, border);
5946 }
5947 segmentWidth = 3;
5948 if (setPtr->flags & PERFORATION_ACTIVE) {
5949 perfBorder = GETATTR(tabPtr, activeBorder);
5950 } else {
5951 perfBorder = GETATTR(tabPtr, selBorder);
5952 }
5953 if (perfBorder == NULL) {
5954 perfBorder = GETATTR(tabPtr, border);
5955 }
5956 setPtr->pW = 0;
5957 if (setPtr->side & SIDE_HORIZONTAL) {
5958 pointArr[0].x = x;
5959 pointArr[0].y = pointArr[1].y = y;
5960 max = tabPtr->screenX + tabPtr->screenWidth - 2;
5961 if (Blt_HasTile(setPtr->tile) == 0 && Blt_HasTile(setPtr->seltile) == 0) {
5962 Blt_Fill3DRectangle(setPtr->tkwin, drawable, perfBorder,
5963 x - 2, y - 4, tabPtr->screenWidth, 8, 0, TK_RELIEF_FLAT);
5964 }
5965 setPtr->pX = x - 2;
5966 setPtr->pY = y - 4;
5967 setPtr->pW = tabPtr->screenWidth;
5968 setPtr->pH = 8;
5969 while (pointArr[0].x < max) {
5970 pointArr[1].x = pointArr[0].x + segmentWidth;
5971 if (pointArr[1].x > max) {
5972 pointArr[1].x = max;
5973 }
5974 Tk_Draw3DPolygon(setPtr->tkwin, drawable, border, pointArr, 2, 1,
5975 TK_RELIEF_RAISED);
5976 pointArr[0].x += 2 * segmentWidth;
5977 }
5978 } else {
5979 pointArr[0].x = pointArr[1].x = x;
5980 pointArr[0].y = y;
5981 max = tabPtr->screenY + tabPtr->screenHeight - 2;
5982 if (Blt_HasTile(setPtr->tile) == 0) {
5983 Blt_Fill3DRectangle(setPtr->tkwin, drawable, perfBorder,
5984 x - 4, y - 2, 8, tabPtr->screenHeight, 0, TK_RELIEF_FLAT);
5985 }
5986 setPtr->pX = x - 4;
5987 setPtr->pY = y - 2;
5988 setPtr->pH = tabPtr->screenHeight;
5989 setPtr->pW = 8;
5990 while (pointArr[0].y < max) {
5991 pointArr[1].y = pointArr[0].y + segmentWidth;
5992 if (pointArr[1].y > max) {
5993 pointArr[1].y = max;
5994 }
5995 Tk_Draw3DPolygon(setPtr->tkwin, drawable, border, pointArr, 2, 1,
5996 TK_RELIEF_RAISED);
5997 pointArr[0].y += 2 * segmentWidth;
5998 }
5999 }
6000 }
6001
6002 #define NextPoint(px, py) \
6003 pointPtr->x = (px), pointPtr->y = (py), pointPtr++, nPoints++
6004 #define EndPoint(px, py) \
6005 pointPtr->x = (px), pointPtr->y = (py), nPoints++
6006
6007 #define BottomLeft(px, py) \
6008 NextPoint((px) + setPtr->corner, (py)), \
6009 NextPoint((px), (py) - setPtr->corner)
6010
6011 #define TopLeft(px, py) \
6012 NextPoint((px), (py) + setPtr->corner), \
6013 NextPoint((px) + setPtr->corner, (py))
6014
6015 #define TopRight(px, py) \
6016 NextPoint((px) - setPtr->corner, (py)), \
6017 NextPoint((px), (py) + setPtr->corner)
6018
6019 #define BottomRight(px, py) \
6020 NextPoint((px), (py) - setPtr->corner), \
6021 NextPoint((px) - setPtr->corner, (py))
6022
6023
6024 /*
6025 * From the left edge:
6026 *
6027 * |a|b|c|d|e| f |d|e|g|h| i |h|g|e|d|f| j |e|d|c|b|a|
6028 *
6029 * a. highlight ring
6030 * b. tabset 3D border
6031 * c. outer gap
6032 * d. page border
6033 * e. page corner
6034 * f. gap + select pad
6035 * g. label pad x (worldX)
6036 * h. internal pad x
6037 * i. label width
6038 * j. rest of page width
6039 *
6040 * worldX, worldY
6041 * |
6042 * |
6043 * * 4+ . . +5
6044 * 3+ +6
6045 * . .
6046 * . .
6047 * 1+. . .2+ +7 . . . .+8
6048 * 0+ +9
6049 * . .
6050 * . .
6051 *13+ +10
6052 * 12+-------------------------+11
6053 *
6054 */
6055 static void
6056 DrawFolder(setPtr, tabPtr, drawable)
6057 Tabset *setPtr;
6058 Tab *tabPtr;
6059 Drawable drawable;
6060 {
6061 XPoint pointArr[16];
6062 XPoint *pointPtr;
6063 int width, height;
6064 int left, bottom, right, top, yBot, yTop;
6065 int x, y;
6066 register int i;
6067 int nPoints;
6068
6069 width = VPORTWIDTH(setPtr);
6070 height = VPORTHEIGHT(setPtr);
6071
6072 x = tabPtr->worldX;
6073 y = tabPtr->worldY;
6074
6075 nPoints = 0;
6076 pointPtr = pointArr;
6077
6078 /* Remember these are all world coordinates. */
6079 /*
6080 * x Left side of tab.
6081 * y Top of tab.
6082 * yTop Top of folder.
6083 * yBot Bottom of the tab.
6084 * left Left side of the folder.
6085 * right Right side of the folder.
6086 * top Top of folder.
6087 * bottom Bottom of folder.
6088 */
6089 left = setPtr->scrollOffset - setPtr->xSelectPad;
6090 right = left + width;
6091 yTop = y + tabPtr->worldHeight;
6092 yBot = setPtr->pageTop - (setPtr->inset + setPtr->yPad);
6093 top = yBot - setPtr->inset2 /* - 4 */;
6094
6095 if (setPtr->pageHeight == 0) {
6096 bottom = yBot + 2 * setPtr->corner;
6097 } else {
6098 bottom = height - setPtr->yPad - 1;
6099 }
6100 if (tabPtr != setPtr->selectPtr) {
6101
6102 /*
6103 * Case 1: Unselected tab
6104 *
6105 * * 3+ . . +4
6106 * 2+ +5
6107 * . .
6108 * 1+ +6
6109 * 0+ . . +7
6110 *
6111 */
6112
6113 if (setPtr->slant & SLANT_LEFT) {
6114 NextPoint(x, yBot);
6115 NextPoint(x, yTop);
6116 NextPoint(x + setPtr->tabHeight, y);
6117 } else {
6118 BottomLeft(x, yBot);
6119 TopLeft(x, y);
6120 }
6121 x += tabPtr->worldWidth;
6122 if (setPtr->slant & SLANT_RIGHT) {
6123 NextPoint(x - setPtr->tabHeight, y);
6124 NextPoint(x, yTop);
6125 NextPoint(x, yBot);
6126 } else {
6127 TopRight(x, y);
6128 BottomRight(x, yBot);
6129 }
6130
6131 } else if (!(tabPtr->flags & TAB_VISIBLE)) {
6132
6133 /*
6134 * Case 2: Selected tab not visible in viewport. Draw folder only.
6135 *
6136 * * 3+ . . +4
6137 * 2+ +5
6138 * . .
6139 * 1+ +6
6140 * 0+------+7
6141 *
6142 */
6143
6144 TopLeft(left, top);
6145 TopRight(right, top);
6146 BottomRight(right, bottom);
6147 BottomLeft(left, bottom);
6148 } else {
6149 int flags;
6150 int tabWidth;
6151
6152 x -= setPtr->xSelectPad;
6153 y -= setPtr->yPad;
6154 tabWidth = tabPtr->worldWidth + 2 * setPtr->xSelectPad;
6155
6156 #define CLIP_NONE 0
6157 #define CLIP_LEFT (1<<0)
6158 #define CLIP_RIGHT (1<<1)
6159 flags = 0;
6160 if (x < left) {
6161 flags |= CLIP_LEFT;
6162 }
6163 if ((x + tabWidth) > right) {
6164 flags |= CLIP_RIGHT;
6165 }
6166 switch (flags) {
6167 case CLIP_NONE:
6168
6169 /*
6170 * worldX, worldY
6171 * |
6172 * * 4+ . . +5
6173 * 3+ +6
6174 * . .
6175 * . .
6176 * 1+. . .2+ +7 . . . .+8
6177 * 0+ +9
6178 * . .
6179 * . .
6180 *13+ +10
6181 * 12+-------------------------+11
6182 */
6183
6184 if (x < (left + setPtr->corner)) {
6185 NextPoint(left, top);
6186 } else {
6187 TopLeft(left, top);
6188 }
6189 if (setPtr->slant & SLANT_LEFT) {
6190 NextPoint(x, yTop);
6191 NextPoint(x + setPtr->tabHeight + setPtr->yPad, y);
6192 } else {
6193 NextPoint(x, top);
6194 TopLeft(x, y);
6195 }
6196 x += tabWidth;
6197 if (setPtr->slant & SLANT_RIGHT) {
6198 NextPoint(x - setPtr->tabHeight - setPtr->yPad, y);
6199 NextPoint(x, yTop);
6200 } else {
6201 TopRight(x, y);
6202 NextPoint(x, top);
6203 }
6204 if (x > (right - setPtr->corner)) {
6205 NextPoint(right, top + setPtr->corner);
6206 } else {
6207 TopRight(right, top);
6208 }
6209 BottomRight(right, bottom);
6210 BottomLeft(left, bottom);
6211 break;
6212
6213 case CLIP_LEFT:
6214
6215 /*
6216 * worldX, worldY
6217 * |
6218 * * 4+ . . +5
6219 * 3+ +6
6220 * . .
6221 * . .
6222 * 2+ +7 . . . .+8
6223 * 1+ . . . +0 +9
6224 * . .
6225 * . .
6226 * 13+ +10
6227 * 12+--------+11
6228 */
6229
6230 NextPoint(left, yBot);
6231 if (setPtr->slant & SLANT_LEFT) {
6232 NextPoint(x, yBot);
6233 NextPoint(x, yTop);
6234 NextPoint(x + setPtr->tabHeight + setPtr->yPad, y);
6235 } else {
6236 BottomLeft(x, yBot);
6237 TopLeft(x, y);
6238 }
6239
6240 x += tabWidth;
6241 if (setPtr->slant & SLANT_RIGHT) {
6242 NextPoint(x - setPtr->tabHeight - setPtr->yPad, y);
6243 NextPoint(x, yTop);
6244 NextPoint(x, top);
6245 } else {
6246 TopRight(x, y);
6247 NextPoint(x, top);
6248 }
6249 if (x > (right - setPtr->corner)) {
6250 NextPoint(right, top + setPtr->corner);
6251 } else {
6252 TopRight(right, top);
6253 }
6254 /* TopRight(right, top); */
6255 BottomRight(right, bottom);
6256 BottomLeft(left, bottom);
6257 break;
6258
6259 case CLIP_RIGHT:
6260
6261 /*
6262 * worldX, worldY
6263 * |
6264 * * 9+ . . +10
6265 * 8+ +11
6266 * . .
6267 * . .
6268 * 6+ . . . .7+ +12
6269 * 5+ 0+ . . . +13
6270 * . .
6271 * . .
6272 * 4+ +1
6273 * 3+-------+2
6274 */
6275
6276 NextPoint(right, yBot);
6277 BottomRight(right, bottom);
6278 BottomLeft(left, bottom);
6279 /* TopLeft(left, top); */
6280 if (x < (left + setPtr->corner)) {
6281 NextPoint(left, top);
6282 } else {
6283 TopLeft(left, top);
6284 }
6285 NextPoint(x, top);
6286
6287 if (setPtr->slant & SLANT_LEFT) {
6288 NextPoint(x, yTop);
6289 NextPoint(x + setPtr->tabHeight + setPtr->yPad, y);
6290 } else {
6291 TopLeft(x, y);
6292 }
6293 x += tabWidth;
6294 if (setPtr->slant & SLANT_RIGHT) {
6295 NextPoint(x - setPtr->tabHeight - setPtr->yPad, y);
6296 NextPoint(x, yTop);
6297 NextPoint(x, yBot);
6298 } else {
6299 TopRight(x, y);
6300 BottomRight(x, yBot);
6301 }
6302 break;
6303
6304 case (CLIP_LEFT | CLIP_RIGHT):
6305
6306 /*
6307 * worldX, worldY
6308 * |
6309 * * 4+ . . . . . . . . +5
6310 * 3+ +6
6311 * . .
6312 * . .
6313 * 1+ +7
6314 * 2+ 0+ +9 .+8
6315 * . .
6316 * . .
6317 * 13+ +10
6318 * 12+-------+11
6319 */
6320
6321 NextPoint(left, yBot);
6322 if (setPtr->slant & SLANT_LEFT) {
6323 NextPoint(x, yBot);
6324 NextPoint(x, yTop);
6325 NextPoint(x + setPtr->tabHeight + setPtr->yPad, y);
6326 } else {
6327 BottomLeft(x, yBot);
6328 TopLeft(x, y);
6329 }
6330 x += tabPtr->worldWidth;
6331 if (setPtr->slant & SLANT_RIGHT) {
6332 NextPoint(x - setPtr->tabHeight - setPtr->yPad, y);
6333 NextPoint(x, yTop);
6334 NextPoint(x, yBot);
6335 } else {
6336 TopRight(x, y);
6337 BottomRight(x, yBot);
6338 }
6339 NextPoint(right, yBot);
6340 BottomRight(right, bottom);
6341 BottomLeft(left, bottom);
6342 break;
6343 }
6344 }
6345 EndPoint(pointArr[0].x, pointArr[0].y);
6346 for (i = 0; i < nPoints; i++) {
6347 WorldToScreen(setPtr, pointArr[i].x, pointArr[i].y, &x, &y);
6348 pointArr[i].x = x;
6349 pointArr[i].y = y;
6350 }
6351 Draw3DFolder(setPtr, tabPtr, drawable, setPtr->side, pointArr, nPoints);
6352 DrawLabel(setPtr, tabPtr, drawable);
6353 if (tabPtr->container != NULL) {
6354 XRectangle rect;
6355
6356 /* Draw a rectangle covering the spot representing the window */
6357 GetWindowRectangle(tabPtr, setPtr->tkwin, FALSE, &rect);
6358 XFillRectangles(setPtr->display, drawable, tabPtr->backGC,
6359 &rect, 1);
6360 }
6361 }
6362
6363 static void
6364 DrawOuterBorders(setPtr, drawable)
6365 Tabset *setPtr;
6366 Drawable drawable;
6367 {
6368 /*
6369 * Draw 3D border just inside of the focus highlight ring. We
6370 * draw the border even if the relief is flat so that any tabs
6371 * that hang over the edge will be clipped.
6372 */
6373 if (setPtr->borderWidth > 0) {
6374 Blt_Draw3DRectangle(setPtr->tkwin, drawable, setPtr->border,
6375 setPtr->highlightWidth, setPtr->highlightWidth,
6376 Tk_Width(setPtr->tkwin) - 2 * setPtr->highlightWidth,
6377 Tk_Height(setPtr->tkwin) - 2 * setPtr->highlightWidth,
6378 setPtr->borderWidth, setPtr->relief);
6379 }
6380 /* Draw focus highlight ring. */
6381 if (setPtr->highlightWidth > 0) {
6382 XColor *color;
6383 GC gc;
6384
6385 color = (setPtr->flags & TABSET_FOCUS)
6386 ? setPtr->highlightColor : setPtr->highlightBgColor;
6387 gc = Tk_GCForColor(color, drawable);
6388 Tk_DrawFocusHighlight(setPtr->tkwin, gc, setPtr->highlightWidth,
6389 drawable);
6390 }
6391 }
6392
6393 /*
6394 * ----------------------------------------------------------------------
6395 *
6396 * DisplayTabset --
6397 *
6398 * This procedure is invoked to display the widget.
6399 *
6400 * Recomputes the layout of the widget if necessary. This is
6401 * necessary if the world coordinate system has changed.
6402 * Sets the vertical and horizontal scrollbars. This is done
6403 * here since the window width and height are needed for the
6404 * scrollbar calculations.
6405 *
6406 * Results:
6407 * None.
6408 *
6409 * Side effects:
6410 * The widget is redisplayed.
6411 *
6412 * ----------------------------------------------------------------------
6413 */
6414 static void
6415 DisplayTabset(clientData)
6416 ClientData clientData; /* Information about widget. */
6417 {
6418 Tabset *setPtr = clientData;
6419 Pixmap drawable;
6420 int width, height, count = 0;
6421
6422 if ((setPtr->flags & TABSET_DESTROYED)) return;
6423
6424 setPtr->flags &= ~TABSET_REDRAW;
6425 if (setPtr->tkwin == NULL) {
6426 return; /* Window has been destroyed. */
6427 }
6428 if (setPtr->flags & TABSET_LAYOUT) {
6429 /* Avoid bug of all tabs invisible. */
6430 setPtr->flags |= TABSET_SCROLL;
6431 }
6432
6433 if (setPtr->flags & TABSET_DIRTY) {
6434 Blt_ChainLink *linkPtr;
6435 Tab *tabPtr;
6436 for (linkPtr = Blt_ChainFirstLink(setPtr->chainPtr); linkPtr != NULL;
6437 linkPtr = Blt_ChainNextLink(linkPtr)) {
6438 tabPtr = Blt_ChainGetValue(linkPtr);
6439 ConfigureTab(setPtr, tabPtr);
6440 }
6441 setPtr->flags &= ~TABSET_DIRTY;
6442 }
6443
6444 if (setPtr->flags & TABSET_LAYOUT) {
6445 ComputeLayout(setPtr);
6446 setPtr->flags &= ~TABSET_LAYOUT;
6447 }
6448 if ((setPtr->reqHeight == 0) || (setPtr->reqWidth == 0)) {
6449 /*int inspad = setPtr->inset + setPtr->inset2;*/
6450 int inspad = 2*setPtr->inset;
6451 int rw, rh;
6452
6453 width = height = 0;
6454 if (setPtr->side & SIDE_VERTICAL) {
6455 height = setPtr->worldWidth;
6456 } else {
6457 width = setPtr->worldWidth;
6458 }
6459 if (setPtr->reqWidth > 0) {
6460 width = setPtr->reqWidth;
6461 } else if (setPtr->pageWidth > 0) {
6462 width = setPtr->pageWidth;
6463 }
6464 if (setPtr->reqHeight > 0) {
6465 height = setPtr->reqHeight;
6466 } else if (setPtr->pageHeight > 0) {
6467 height = setPtr->pageHeight;
6468 }
6469 if (setPtr->side & SIDE_VERTICAL) {
6470 width += setPtr->pageTop + inspad;
6471 height += inspad;
6472 } else {
6473 height += setPtr->pageTop + inspad;
6474 width += inspad;
6475 }
6476 rw = Tk_ReqWidth(setPtr->tkwin) ;
6477 rh = Tk_ReqHeight(setPtr->tkwin);
6478 if ((rw != width) || (rh != height)) {
6479 Tk_GeometryRequest(setPtr->tkwin, width, height);
6480 }
6481 }
6482 if (setPtr->flags & TABSET_SCROLL) {
6483 width = VPORTWIDTH(setPtr);
6484 setPtr->scrollOffset = Blt_AdjustViewport(setPtr->scrollOffset,
6485 setPtr->worldWidth, width, setPtr->scrollUnits,
6486 BLT_SCROLL_MODE_CANVAS);
6487 if (setPtr->scrollCmdPrefix != NULL && Tk_Width(setPtr->tkwin)>1) {
6488 Blt_UpdateScrollbar(setPtr->interp, setPtr->scrollCmdPrefix,
6489 (double)setPtr->scrollOffset / setPtr->worldWidth,
6490 (double)(setPtr->scrollOffset + width) / setPtr->worldWidth);
6491 }
6492 ComputeVisibleTabs(setPtr);
6493 setPtr->flags &= ~TABSET_SCROLL;
6494 }
6495 if (!Tk_IsMapped(setPtr->tkwin)) {
6496 return;
6497 }
6498 height = Tk_Height(setPtr->tkwin);
6499 drawable = Tk_GetPixmap(setPtr->display, Tk_WindowId(setPtr->tkwin),
6500 Tk_Width(setPtr->tkwin), Tk_Height(setPtr->tkwin),
6501 Tk_Depth(setPtr->tkwin));
6502
6503 /*
6504 * Clear the background and tile pixmap. Fill in case transparent.
6505 */
6506 Blt_Fill3DRectangle(setPtr->tkwin, drawable, setPtr->border, 0, 0,
6507 Tk_Width(setPtr->tkwin), height, 0, TK_RELIEF_FLAT);
6508 /* if (Blt_HasTile(setPtr->tile)) {
6509 Blt_SetTileOrigin(setPtr->tkwin, setPtr->tile, 0, 0);
6510 Blt_TileRectangle(setPtr->tkwin, drawable, setPtr->tile, 0, 0,
6511 Tk_Width(setPtr->tkwin), height);
6512 }*/
6513
6514 if (Blt_HasTile(setPtr->bgtile)) {
6515 Blt_SetTileOrigin(setPtr->tkwin, setPtr->bgtile, 0, 0);
6516 Blt_TileRectangle(setPtr->tkwin, drawable, setPtr->bgtile, 0, 0,
6517 Tk_Width(setPtr->tkwin), height);
6518 }
6519
6520 if (setPtr->nVisible > 0) {
6521 register int i;
6522 register Tab *tabPtr;
6523 Blt_ChainLink *linkPtr;
6524
6525 linkPtr = setPtr->startPtr->linkPtr;
6526 for (i = 0; i < Blt_ChainGetLength(setPtr->chainPtr); i++) {
6527 linkPtr = Blt_ChainPrevLink(linkPtr);
6528 if (linkPtr == NULL) {
6529 linkPtr = Blt_ChainLastLink(setPtr->chainPtr);
6530 }
6531 tabPtr = Blt_ChainGetValue(linkPtr);
6532 if ((tabPtr != setPtr->selectPtr) &&
6533 (tabPtr->flags & TAB_VISIBLE)) {
6534 DrawFolder(setPtr, tabPtr, drawable);
6535 count++;
6536 }
6537 }
6538 DrawFolder(setPtr, setPtr->selectPtr, drawable);
6539 if (count == 0) {
6540 /* Bug: somehow all tabs got marked invisble. */
6541 setPtr->flags |= (TABSET_LAYOUT|TABSET_SCROLL);
6542 }
6543 if (setPtr->tearoff) {
6544 DrawPerforation(setPtr, setPtr->selectPtr, drawable);
6545 }
6546
6547 if ((setPtr->selectPtr->tkwin != NULL) &&
6548 (setPtr->selectPtr->container == NULL)) {
6549 XRectangle rect;
6550
6551 GetWindowRectangle(setPtr->selectPtr, setPtr->tkwin, FALSE, &rect);
6552 ArrangeWindow(setPtr->selectPtr->tkwin, &rect, 0);
6553 }
6554 }
6555 if (setPtr->startImage && setPtr->startImage->width) {
6556 Tk_RedrawImage(ImageBits(setPtr->startImage), 0, 0,
6557 setPtr->startImage->width, setPtr->startImage->height,
6558 drawable, setPtr->siX, setPtr->siY);
6559 }
6560 if (setPtr->endImage && setPtr->endImage->width) {
6561 Tk_RedrawImage(ImageBits(setPtr->endImage), 0, 0,
6562 setPtr->endImage->width, setPtr->endImage->height,
6563 drawable, setPtr->eiX, setPtr->eiY);
6564 }
6565 DrawOuterBorders(setPtr, drawable);
6566 XCopyArea(setPtr->display, drawable, Tk_WindowId(setPtr->tkwin),
6567 setPtr->highlightGC, 0, 0, Tk_Width(setPtr->tkwin), height, 0, 0);
6568 Tk_FreePixmap(setPtr->display, drawable);
6569 }
6570
6571 /*
6572 * From the left edge:
6573 *
6574 * |a|b|c|d|e| f |d|e|g|h| i |h|g|e|d|f| j |e|d|c|b|a|
6575 *
6576 * a. highlight ring
6577 * b. tabset 3D border
6578 * c. outer gap
6579 * d. page border
6580 * e. page corner
6581 * f. gap + select pad
6582 * g. label pad x (worldX)
6583 * h. internal pad x
6584 * i. label width
6585 * j. rest of page width
6586 *
6587 * worldX, worldY
6588 * |
6589 * |
6590 * * 4+ . . +5
6591 * 3+ +6
6592 * . .
6593 * . .
6594 * 1+. . .2+ +7 . . . .+8
6595 * 0+ +9
6596 * . .
6597 * . .
6598 *13+ +10
6599 * 12+-------------------------+11
6600 *
6601 */
6602 static void
6603 DisplayTearoff(clientData)
6604 ClientData clientData;
6605 {
6606 Tabset *setPtr;
6607 Tab *tabPtr;
6608 Drawable drawable;
6609 XPoint pointArr[16];
6610 XPoint *pointPtr;
6611 int width, height;
6612 int left, bottom, right, top;
6613 int x, y;
6614 int nPoints;
6615 Tk_Window tkwin;
6616 Tk_Window parent;
6617 XRectangle rect;
6618
6619 tabPtr = clientData;
6620 if (tabPtr == NULL) {
6621 return;
6622 }
6623 tabPtr->flags &= ~TAB_REDRAW;
6624 setPtr = tabPtr->setPtr;
6625 if (setPtr->tkwin == NULL) {
6626 return;
6627 }
6628 tkwin = tabPtr->container;
6629 drawable = Tk_WindowId(tkwin);
6630
6631 /*
6632 * Clear the background either by tiling a pixmap or filling with
6633 * a solid color. Tiling takes precedence.
6634 */
6635 Blt_Fill3DRectangle(tkwin, drawable, setPtr->border, 0, 0,
6636 Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
6637 if (Blt_HasTile(setPtr->tile)) {
6638 Blt_SetTileOrigin(tkwin, setPtr->tile, 0, 0);
6639 Blt_TileRectangle(tkwin, drawable, setPtr->tile, 0, 0,
6640 Tk_Width(tkwin), Tk_Height(tkwin));
6641 }
6642
6643 width = Tk_Width(tkwin) - 2 * setPtr->inset;
6644 height = Tk_Height(tkwin) - 2 * setPtr->inset;
6645 x = setPtr->inset + setPtr->gap + setPtr->corner;
6646 y = setPtr->inset;
6647
6648 left = setPtr->inset;
6649 right = setPtr->inset + width;
6650 top = setPtr->inset + setPtr->corner + setPtr->xSelectPad;
6651 bottom = setPtr->inset + height;
6652
6653 /*
6654 * worldX, worldY
6655 * |
6656 * * 4+ . . +5
6657 * 3+ +6
6658 * . .
6659 * . .
6660 * 1+. . .2+ +7 . . . .+8
6661 * 0+ +9
6662 * . .
6663 * . .
6664 *13+ +10
6665 * 12+-------------------------+11
6666 */
6667
6668 nPoints = 0;
6669 pointPtr = pointArr;
6670
6671 TopLeft(left, top);
6672 NextPoint(x, top);
6673 TopLeft(x, y);
6674 x += tabPtr->worldWidth;
6675 TopRight(x, y);
6676 NextPoint(x, top);
6677 TopRight(right, top);
6678 BottomRight(right, bottom);
6679 BottomLeft(left, bottom);
6680 EndPoint(pointArr[0].x, pointArr[0].y);
6681 Draw3DFolder(setPtr, tabPtr, drawable, SIDE_TOP, pointArr, nPoints);
6682
6683 parent = (tabPtr->container == NULL) ? setPtr->tkwin : tabPtr->container;
6684 GetWindowRectangle(tabPtr, parent, TRUE, &rect);
6685 ArrangeWindow(tabPtr->tkwin, &rect, TRUE);
6686
6687 /* Draw 3D border. */
6688 if ((setPtr->borderWidth > 0) && (setPtr->relief != TK_RELIEF_FLAT)) {
6689 Blt_Draw3DRectangle(tkwin, drawable, setPtr->border, 0, 0,
6690 Tk_Width(tkwin), Tk_Height(tkwin), setPtr->borderWidth,
6691 setPtr->relief);
6692 }
6693 }
6694
6695 /*
6696 * --------------------------------------------------------------
6697 *
6698 * TabsetCmd --
6699 *
6700 * This procedure is invoked to process the "tabset" command.
6701 * See the user documentation for details on what it does.
6702 *
6703 * Results:
6704 * A standard Tcl result.
6705 *
6706 * Side effects:
6707 * See the user documentation.
6708 *
6709 * --------------------------------------------------------------
6710 */
6711 static Blt_OpSpec tabsetOps[] =
6712 {
6713 {"activate", 1, (Blt_Op)ActivateOp, 3, 3, "index",},
6714 {"bind", 1, (Blt_Op)BindOp, 2, 5, "index ?sequence command?",},
6715 {"cget", 2, (Blt_Op)CgetOp, 3, 3, "option",},
6716 {"configure", 3, (Blt_Op)ConfigureOp, 2, 0, "?option value?...",},
6717 {"coords", 3, (Blt_Op)CoordsOp, 3, 4, "element ?index?",},
6718 {"delete", 1, (Blt_Op)DeleteOp, 2, 0, "first ?last?",},
6719 {"focus", 1, (Blt_Op)FocusOp, 3, 3, "index",},
6720 {"get", 1, (Blt_Op)GetOp, 3, 3, "index",},
6721 {"index", 3, (Blt_Op)IndexOp, 3, 5, "string",},
6722 {"insert", 3, (Blt_Op)InsertOp, 3, 0,
6723 "index name ?name...? ?option value?",},
6724 {"invoke", 3, (Blt_Op)InvokeOp, 3, 3, "index",},
6725 {"move", 1, (Blt_Op)MoveOp, 5, 5, "name after|before index",},
6726 {"nearest", 1, (Blt_Op)NearestOp, 4, 6, "x y ?varName? ?coordsVar?",},
6727 {"perforation", 1, (Blt_Op)PerforationOp, 2, 0, "args",},
6728 {"scan", 2, (Blt_Op)ScanOp, 5, 5, "dragto|mark x y",},
6729 {"see", 3, (Blt_Op)SeeOp, 3, 3, "index",},
6730 {"select", 3, (Blt_Op)SelectOp, 3, 3, "index",},
6731 {"size", 2, (Blt_Op)SizeOp, 2, 2, "",},
6732 {"tab", 1, (Blt_Op)TabOp, 2, 0, "oper args",},
6733 {"tearoff", 1, (Blt_Op)TearoffOp, 2, 3, "?index?",},
6734 {"view", 1, (Blt_Op)ViewOp, 2, 5,
6735 "?moveto fract? ?scroll number what?",},
6736 };
6737
6738 static int nTabsetOps = sizeof(tabsetOps) / sizeof(Blt_OpSpec);
6739
6740 static int
6741 TabsetInstCmd(clientData, interp, argc, argv)
6742 ClientData clientData; /* Information about the widget. */
6743 Tcl_Interp *interp; /* Interpreter to report errors back to. */
6744 int argc; /* Number of arguments. */
6745 char **argv; /* Vector of argument strings. */
6746 {
6747 Blt_Op proc;
6748 Tabset *setPtr = clientData;
6749 int result;
6750
6751 if ((setPtr->flags & TABSET_DESTROYED)) return TCL_OK;
6752
6753 proc = Blt_GetOp(interp, nTabsetOps, tabsetOps, BLT_OP_ARG1,
6754 argc, argv, 0);
6755 if (proc == NULL) {
6756 return TCL_ERROR;
6757 }
6758 Tcl_Preserve(setPtr);
6759 result = (*proc) (setPtr, interp, argc, argv);
6760 Tcl_Release(setPtr);
6761 return result;
6762 }
6763
6764 /*
6765 *----------------------------------------------------------------------
6766 *
6767 * TabsetInstDeletedCmd --
6768 *
6769 * This procedure can be called if the window was destroyed
6770 * (tkwin will be NULL) and the command was deleted
6771 * automatically. In this case, we need to do nothing.
6772 *
6773 * Otherwise this routine was called because the command was
6774 * deleted. Then we need to clean-up and destroy the widget.
6775 *
6776 * Results:
6777 * None.
6778 *
6779 * Side Effects:
6780 * The widget is destroyed.
6781 *
6782 *----------------------------------------------------------------------
6783 */
6784 static void
6785 TabsetInstDeletedCmd(clientData)
6786 ClientData clientData; /* Pointer to widget record for widget. */
6787 {
6788 Tabset *setPtr = clientData;
6789
6790 if (setPtr->tkwin != NULL) {
6791 Tk_Window tkwin;
6792
6793 tkwin = setPtr->tkwin;
6794 setPtr->tkwin = NULL;
6795 Tk_DestroyWindow(tkwin);
6796 #ifdef ITCL_NAMESPACES
6797 Itk_SetWidgetCommand(tkwin, (Tcl_Command) NULL);
6798 #endif /* ITCL_NAMESPACES */
6799 }
6800 }
6801
6802 /*
6803 * ------------------------------------------------------------------------
6804 *
6805 * TabsetCmd --
6806 *
6807 * This procedure is invoked to process the Tcl command that
6808 * corresponds to a widget managed by this module. See the user
6809 * documentation for details on what it does.
6810 *
6811 * Results:
6812 * A standard Tcl result.
6813 *
6814 * Side Effects:
6815 * See the user documentation.
6816 *
6817 * -----------------------------------------------------------------------
6818 */
6819 /* ARGSUSED */
6820 static int
6821 TabsetCmd(clientData, interp, argc, argv)
6822 ClientData clientData; /* Main window associated with interpreter. */
6823 Tcl_Interp *interp; /* Current interpreter. */
6824 int argc; /* Number of arguments. */
6825 char **argv; /* Argument strings. */
6826 {
6827 Tabset *setPtr;
6828 Tk_Window tkwin;
6829 unsigned int mask;
6830 Tcl_CmdInfo cmdInfo;
6831
6832 if (argc < 2) {
6833 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
6834 " pathName ?option value?...\"", (char *)NULL);
6835 return TCL_ERROR;
6836 }
6837 tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), argv[1],
6838 (char *)NULL);
6839 if (tkwin == NULL) {
6840 return TCL_ERROR;
6841 }
6842 setPtr = CreateTabset(interp, tkwin);
•6843 if (ConfigureTabset(interp, setPtr, argc - 2, (CONST char **)argv + 2, 0) != TCL_OK) {
6844 Tk_DestroyWindow(setPtr->tkwin);
6845 return TCL_ERROR;
6846 }
6847 mask = (ExposureMask | StructureNotifyMask | FocusChangeMask);
6848 Tk_CreateEventHandler(tkwin, mask, TabsetEventProc, setPtr);
6849 setPtr->cmdToken = Tcl_CreateCommand(interp, argv[1], TabsetInstCmd,
6850 setPtr, TabsetInstDeletedCmd);
6851 #ifdef ITCL_NAMESPACES
6852 Itk_SetWidgetCommand(setPtr->tkwin, setPtr->cmdToken);
6853 #endif
6854
6855 /*
6856 * Try to invoke a procedure to initialize various bindings on
6857 * tabs. Source the file containing the procedure now if the
6858 * procedure isn't currently defined. We deferred this to now so
6859 * that the user could set the variable "blt_library" within the
6860 * script.
6861 */
6862 if (!Tcl_GetCommandInfo(interp, "blt::TabsetInit", &cmdInfo)) {
6863 static char initCmd[] = "source [file join $blt_library tabset.tcl]";
6864
6865 if (Tcl_GlobalEval(interp, initCmd) != TCL_OK) {
6866 char info[200];
6867
6868 sprintf(info, "\n (while loading bindings for %s)", argv[0]);
6869 Tcl_AddErrorInfo(interp, info);
6870 Tk_DestroyWindow(setPtr->tkwin);
6871 return TCL_ERROR;
6872 }
6873 }
6874 if (Tcl_VarEval(interp, "blt::TabsetInit ", argv[1], (char *)NULL)
6875 != TCL_OK) {
6876 Tk_DestroyWindow(setPtr->tkwin);
6877 return TCL_ERROR;
6878 }
6879 Tcl_SetResult(interp, Tk_PathName(setPtr->tkwin), TCL_VOLATILE);
6880 return TCL_OK;
6881 }
6882
6883 int
6884 Blt_TabsetInit(interp)
6885 Tcl_Interp *interp;
6886 {
6887 static Blt_CmdSpec cmdSpec =
6888 {
6889 "tabset", TabsetCmd,
6890 };
6891
6892 if (Blt_InitCmd(interp, "blt", &cmdSpec) == NULL) {
6893 return TCL_ERROR;
6894 }
6895 return TCL_OK;
6896 }
6897
6898 #endif /* NO_TABSET */