Debian Codegraph @

generic/bltTabnotebook.c

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