| 1 |
|
| 2 |
/* |
| 3 |
* bltHierbox.c -- |
| 4 |
* |
| 5 |
* This module implements an hierarchy widget for the BLT toolkit. |
| 6 |
* |
| 7 |
* Copyright -1998 Lucent Technologies, Inc. |
| 8 |
* |
| 9 |
* Permission to use, copy, modify, and distribute this software and |
| 10 |
* its documentation for any purpose and without fee is hereby |
| 11 |
* granted, provided that the above copyright notice appear in all |
| 12 |
* copies and that both that the copyright notice and warranty |
| 13 |
* disclaimer appear in supporting documentation, and that the names |
| 14 |
* of Lucent Technologies or any of their entities not be used in |
| 15 |
* advertising or publicity pertaining to distribution of the software |
| 16 |
* without specific, written prior permission. |
| 17 |
* |
| 18 |
* Lucent Technologies disclaims all warranties with regard to this |
| 19 |
* software, including all implied warranties of merchantability and |
| 20 |
* fitness. In no event shall Lucent Technologies be liable for any |
| 21 |
* special, indirect or consequential damages or any damages |
| 22 |
* whatsoever resulting from loss of use, data or profits, whether in |
| 23 |
* an action of contract, negligence or other tortuous action, arising |
| 24 |
* out of or in connection with the use or performance of this |
| 25 |
* software. |
| 26 |
* |
| 27 |
* The "hierbox" widget was created by George A. Howlett. |
| 28 |
*/ |
| 29 |
|
| 30 |
/* |
| 31 |
* TODO: |
| 32 |
* |
| 33 |
* BUGS: |
| 34 |
* 1. "open" operation should change scroll offset so that as many |
| 35 |
* new entries (up to half a screen) can be seen. |
| 36 |
* 2. "open" needs to adjust the scrolloffset so that the same entry |
| 37 |
* is seen at the same place. |
| 38 |
*/ |
| 39 |
|
| 40 |
#include "bltInt.h" |
| 41 |
|
| 42 |
#ifndef NO_HIERBOX |
| 43 |
#include "bltBind.h" |
| 44 |
#include "bltImage.h" |
| 45 |
#include "bltHash.h" |
| 46 |
#include "bltChain.h" |
| 47 |
#include "bltList.h" |
| 48 |
#include "bltTile.h" |
| 49 |
#include <X11/Xutil.h> |
| 50 |
#include <X11/Xatom.h> |
| 51 |
|
| 52 |
#if HAVE_UTF |
| 53 |
#else |
| 54 |
#define Tcl_NumUtfChars(s,n) (((n) == -1) ? strlen((s)) : (n)) |
| 55 |
#define Tcl_UtfAtIndex(s,i) ((s) + (i)) |
| 56 |
#endif |
| 57 |
|
| 58 |
#define SEPARATOR_NONE ((char *)-1) |
| 59 |
#define SEPARATOR_LIST ((char *)NULL) |
| 60 |
#define APPEND (-1) |
| 61 |
|
| 62 |
/* |
| 63 |
* The macro below is used to modify a "char" value (e.g. by casting |
| 64 |
* it to an unsigned character) so that it can be used safely with |
| 65 |
* macros such as isspace. |
| 66 |
*/ |
| 67 |
#define UCHAR(c) ((unsigned char) (c)) |
| 68 |
|
| 69 |
#define APPLY_BEFORE (1<<0) |
| 70 |
#define APPLY_OPEN_ONLY (1<<1) |
| 71 |
#define APPLY_RECURSE (1<<2) |
| 72 |
|
| 73 |
#define BUTTON_IPAD 1 |
| 74 |
#define BUTTON_SIZE 7 |
| 75 |
#define INSET_PAD 2 |
| 76 |
#define ICON_PADX 2 |
| 77 |
#define ICON_PADY 1 |
| 78 |
#define LABEL_PADX 3 |
| 79 |
#define LABEL_PADY 0 |
| 80 |
#define FOCUS_WIDTH 1 |
| 81 |
|
| 82 |
#define CLAMP(val,low,hi) \ |
| 83 |
(((val) < (low)) ? (low) : ((val) > (hi)) ? (hi) : (val)) |
| 84 |
#define ODD(x) ((x) | 0x01) |
| 85 |
#define TOGGLE(x, mask) \ |
| 86 |
(((x) & (mask)) ? ((x) & ~(mask)) : ((x) | (mask))) |
| 87 |
|
| 88 |
#define VPORTWIDTH(h) (Tk_Width((h)->tkwin) - 2 * (h)->inset) |
| 89 |
#define VPORTHEIGHT(h) (Tk_Height((h)->tkwin) - 2 * (h)->inset) |
| 90 |
|
| 91 |
#define WORLDX(h, sx) ((sx) - (h)->inset + (h)->xOffset) |
| 92 |
#define WORLDY(h, sy) ((sy) - (h)->inset + (h)->yOffset) |
| 93 |
|
| 94 |
#define SCREENX(h, wx) ((wx) - (h)->xOffset + (h)->inset) |
| 95 |
#define SCREENY(h, wy) ((wy) - (h)->yOffset + (h)->inset) |
| 96 |
|
| 97 |
#define LEVELWIDTH(d) (hboxPtr->levelInfo[(d)].width) |
| 98 |
#define LEVELX(d) (hboxPtr->levelInfo[(d)].x) |
| 99 |
|
| 100 |
#define GETFONT(h, f) (((f) == NULL) ? (h)->defFont : (f)) |
| 101 |
#define GETCOLOR(h, c) (((c) == NULL) ? (h)->defColor : (c)) |
| 102 |
|
| 103 |
/* |
| 104 |
* ---------------------------------------------------------------------------- |
| 105 |
* |
| 106 |
* Internal hierarchy widget flags: |
| 107 |
* |
| 108 |
* HIERBOX_LAYOUT The layout of the hierarchy needs to be |
| 109 |
* recomputed. |
| 110 |
* |
| 111 |
* HIERBOX_REDRAW A redraw request is pending for the widget. |
| 112 |
* |
| 113 |
* HIERBOX_XSCROLL X-scroll request is pending. |
| 114 |
* HIERBOX_YSCROLL Y-scroll request is pending. |
| 115 |
* HIERBOX_SCROLL Both X-scroll and Y-scroll requests are |
| 116 |
* pending. |
| 117 |
* |
| 118 |
* HIERBOX_FOCUS The widget is receiving keyboard events. |
| 119 |
* Draw the focus highlight border around the |
| 120 |
* widget. |
| 121 |
* |
| 122 |
* HIERBOX_DIRTY The hierarchy has changed, possibly invalidating |
| 123 |
* locations and pointers to entries. This widget |
| 124 |
* need to recompute its layout. |
| 125 |
* |
| 126 |
* HIERBOX_BORDERS The borders of the widget (highlight ring and |
| 127 |
* 3-D border) need to be redrawn. |
| 128 |
* |
| 129 |
* |
| 130 |
* Selection related flags: |
| 131 |
* |
| 132 |
* SELECTION_EXPORT Export the selection to X. |
| 133 |
* |
| 134 |
* SELECTION_PENDING A selection command idle task is pending. |
| 135 |
* |
| 136 |
* SELECTION_CLEAR Entry's selection flag is to be cleared. |
| 137 |
* |
| 138 |
* SELECTION_SET Entry's selection flag is to be set. |
| 139 |
* |
| 140 |
* SELECTION_TOGGLE Entry's selection flag is to be toggled. |
| 141 |
* |
| 142 |
* SELECTION_MASK Mask of selection set/clear/toggle flags. |
| 143 |
* |
| 144 |
* --------------------------------------------------------------------------- |
| 145 |
*/ |
| 146 |
#define HIERBOX_LAYOUT (1<<0) |
| 147 |
#define HIERBOX_REDRAW (1<<1) |
| 148 |
#define HIERBOX_XSCROLL (1<<2) |
| 149 |
#define HIERBOX_YSCROLL (1<<3) |
| 150 |
#define HIERBOX_SCROLL (HIERBOX_XSCROLL | HIERBOX_YSCROLL) |
| 151 |
#define HIERBOX_FOCUS (1<<4) |
| 152 |
#define HIERBOX_DIRTY (1<<5) |
| 153 |
#define HIERBOX_BORDERS (1<<6) |
| 154 |
|
| 155 |
#define SELECTION_PENDING (1<<15) |
| 156 |
#define SELECTION_EXPORT (1<<16) |
| 157 |
#define SELECTION_CLEAR (1<<17) |
| 158 |
#define SELECTION_SET (1<<18) |
| 159 |
#define SELECTION_TOGGLE (SELECTION_SET | SELECTION_CLEAR) |
| 160 |
#define SELECTION_MASK (SELECTION_SET | SELECTION_CLEAR) |
| 161 |
|
| 162 |
/* |
| 163 |
* ------------------------------------------------------------------------- |
| 164 |
* |
| 165 |
* Internal entry flags: |
| 166 |
* |
| 167 |
* ENTRY_BUTTON Indicates that a button needs to be |
| 168 |
* drawn for this entry. |
| 169 |
* |
| 170 |
* ENTRY_OPEN Indicates that the entry is open and |
| 171 |
* its subentries should also be displayed. |
| 172 |
* |
| 173 |
* ENTRY_MAPPED Indicates that the entry is mapped (i.e. |
| 174 |
* can be viewed by opening or scrolling. |
| 175 |
* |
| 176 |
* BUTTON_AUTO |
| 177 |
* BUTTON_SHOW |
| 178 |
* BUTTON_MASK |
| 179 |
* |
| 180 |
* ------------------------------------------------------------------------- |
| 181 |
*/ |
| 182 |
#define ENTRY_BUTTON (1<<0) |
| 183 |
#define ENTRY_OPEN (1<<2) |
| 184 |
#define ENTRY_MAPPED (1<<3) |
| 185 |
#define BUTTON_AUTO (1<<8) |
| 186 |
#define BUTTON_SHOW (1<<9) |
| 187 |
#define BUTTON_MASK (BUTTON_AUTO | BUTTON_SHOW) |
| 188 |
|
| 189 |
#define DEF_ENTRY_BACKGROUND (char *)NULL |
| 190 |
#define DEF_ENTRY_BG_MONO (char *)NULL |
| 191 |
#define DEF_ENTRY_BIND_TAGS "Entry all" |
| 192 |
#define DEF_ENTRY_BUTTON "auto" |
| 193 |
#define DEF_ENTRY_COMMAND (char *)NULL |
| 194 |
#define DEF_ENTRY_DATA (char *)NULL |
| 195 |
#define DEF_ENTRY_FOREGROUND (char *)NULL |
| 196 |
#define DEF_ENTRY_FG_MONO (char *)NULL |
| 197 |
#define DEF_ENTRY_FONT (char *)NULL |
| 198 |
#define DEF_ENTRY_ICONS (char *)NULL |
| 199 |
#define DEF_ENTRY_ACTIVE_ICONS (char *)NULL |
| 200 |
#define DEF_ENTRY_IMAGES (char *)NULL |
| 201 |
#define DEF_ENTRY_LABEL (char *)NULL |
| 202 |
#define DEF_ENTRY_SHADOW_COLOR (char *)NULL |
| 203 |
#define DEF_ENTRY_SHADOW_MONO (char *)NULL |
| 204 |
#define DEF_ENTRY_TEXT (char *)NULL |
| 205 |
|
| 206 |
#define DEF_BUTTON_ACTIVE_BACKGROUND RGB_WHITE |
| 207 |
#define DEF_BUTTON_ACTIVE_BG_MONO STD_ACTIVE_BG_MONO |
| 208 |
#define DEF_BUTTON_ACTIVE_FOREGROUND STD_ACTIVE_FOREGROUND |
| 209 |
#define DEF_BUTTON_ACTIVE_FG_MONO STD_ACTIVE_FG_MONO |
| 210 |
#define DEF_BUTTON_BORDERWIDTH "1" |
| 211 |
#if (TK_MAJOR_VERSION == 4) |
| 212 |
#define DEF_BUTTON_CLOSE_RELIEF "flat" |
| 213 |
#define DEF_BUTTON_OPEN_RELIEF "flat" |
| 214 |
#else |
| 215 |
#define DEF_BUTTON_CLOSE_RELIEF "solid" |
| 216 |
#define DEF_BUTTON_OPEN_RELIEF "solid" |
| 217 |
#endif |
| 218 |
#define DEF_BUTTON_IMAGES (char *)NULL |
| 219 |
#define DEF_BUTTON_NORMAL_BACKGROUND RGB_WHITE |
| 220 |
#define DEF_BUTTON_NORMAL_BG_MONO STD_NORMAL_BG_MONO |
| 221 |
#define DEF_BUTTON_NORMAL_FOREGROUND STD_NORMAL_FOREGROUND |
| 222 |
#define DEF_BUTTON_NORMAL_FG_MONO STD_NORMAL_FG_MONO |
| 223 |
#define DEF_BUTTON_SIZE "7" |
| 224 |
|
| 225 |
#define DEF_HIERBOX_ACTIVE_BACKGROUND RGB_LIGHTBLUE0 |
| 226 |
#define DEF_HIERBOX_ACTIVE_SELECT_BACKGROUND RGB_LIGHTBLUE1 |
| 227 |
#define DEF_HIERBOX_ACTIVE_BG_MONO STD_ACTIVE_BG_MONO |
| 228 |
#define DEF_HIERBOX_ACTIVE_FOREGROUND RGB_BLACK |
| 229 |
#define DEF_HIERBOX_ACTIVE_RELIEF "flat" |
| 230 |
#define DEF_HIERBOX_ACTIVE_STIPPLE "gray25" |
| 231 |
#define DEF_HIERBOX_ALLOW_DUPLICATES "yes" |
| 232 |
#define DEF_HIERBOX_BACKGROUND RGB_WHITE |
| 233 |
#define DEF_HIERBOX_BORDERWIDTH STD_BORDERWIDTH |
| 234 |
#define DEF_HIERBOX_COMMAND (char *)NULL |
| 235 |
#define DEF_HIERBOX_CURSOR (char *)NULL |
| 236 |
#define DEF_HIERBOX_DASHES "dot" |
| 237 |
#define DEF_HIERBOX_EXPORT_SELECTION "no" |
| 238 |
#define DEF_HIERBOX_FOREGROUND STD_NORMAL_FOREGROUND |
| 239 |
#define DEF_HIERBOX_FG_MONO STD_NORMAL_FG_MONO |
| 240 |
#define DEF_HIERBOX_FOCUS_DASHES "dot" |
| 241 |
#define DEF_HIERBOX_FOCUS_EDIT "no" |
| 242 |
#define DEF_HIERBOX_FOCUS_FOREGROUND STD_ACTIVE_FOREGROUND |
| 243 |
#define DEF_HIERBOX_FOCUS_FG_MONO STD_ACTIVE_FG_MONO |
| 244 |
#define DEF_HIERBOX_FONT STD_FONT |
| 245 |
#define DEF_HIERBOX_HEIGHT "400" |
| 246 |
#define DEF_HIERBOX_HIDE_ROOT "no" |
| 247 |
#define DEF_HIERBOX_HIGHLIGHT_BACKGROUND STD_NORMAL_BACKGROUND |
| 248 |
#define DEF_HIERBOX_HIGHLIGHT_BG_MONO STD_NORMAL_BG_MONO |
| 249 |
#define DEF_HIERBOX_HIGHLIGHT_COLOR RGB_BLACK |
| 250 |
#define DEF_HIERBOX_HIGHLIGHT_WIDTH "2" |
| 251 |
#define DEF_HIERBOX_LINE_COLOR RGB_GREY50 |
| 252 |
#define DEF_HIERBOX_LINE_MONO STD_NORMAL_FG_MONO |
| 253 |
#define DEF_HIERBOX_LINE_SPACING "0" |
| 254 |
#define DEF_HIERBOX_LINE_WIDTH "1" |
| 255 |
#define DEF_HIERBOX_MAKE_PATH "no" |
| 256 |
#define DEF_HIERBOX_NORMAL_BACKGROUND STD_NORMAL_BACKGROUND |
| 257 |
#define DEF_HIERBOX_NORMAL_FG_MONO STD_ACTIVE_FG_MONO |
| 258 |
#define DEF_HIERBOX_RELIEF "sunken" |
| 259 |
#define DEF_HIERBOX_SCROLL_INCREMENT "0" |
| 260 |
#define DEF_HIERBOX_SCROLL_MODE "hierbox" |
| 261 |
#define DEF_HIERBOX_SCROLL_TILE "no" |
| 262 |
#define DEF_HIERBOX_SELECT_BACKGROUND RGB_LIGHTSKYBLUE1 |
| 263 |
#define DEF_HIERBOX_SELECT_BG_MONO STD_SELECT_BG_MONO |
| 264 |
#define DEF_HIERBOX_SELECT_BORDERWIDTH "1" |
| 265 |
#define DEF_HIERBOX_SELECT_CMD (char *)NULL |
| 266 |
#define DEF_HIERBOX_SELECT_FOREGROUND STD_SELECT_FOREGROUND |
| 267 |
#define DEF_HIERBOX_SELECT_FG_MONO STD_SELECT_FG_MONO |
| 268 |
#define DEF_HIERBOX_SELECT_MODE "single" |
| 269 |
#define DEF_HIERBOX_SELECT_RELIEF "flat" |
| 270 |
#define DEF_HIERBOX_SEPARATOR (char *)NULL |
| 271 |
#define DEF_HIERBOX_SHOW_ROOT "yes" |
| 272 |
#define DEF_HIERBOX_SORT_SELECTION "no" |
| 273 |
#define DEF_HIERBOX_TAKE_FOCUS "1" |
| 274 |
#define DEF_HIERBOX_TEXT_COLOR STD_NORMAL_FOREGROUND |
| 275 |
#define DEF_HIERBOX_TEXT_MONO STD_NORMAL_FG_MONO |
| 276 |
#define DEF_HIERBOX_TILE (char *)NULL |
| 277 |
#define DEF_HIERBOX_TRIMLEFT "" |
| 278 |
#define DEF_HIERBOX_WIDTH "200" |
| 279 |
|
| 280 |
typedef struct HierboxStruct Hierbox; |
| 281 |
typedef struct EntryStruct Entry; |
| 282 |
typedef struct TreeStruct Tree; |
| 283 |
|
| 284 |
typedef int (CompareProc) _ANSI_ARGS_((Tcl_Interp *interp, char *name, |
| 285 |
char *pattern)); |
| 286 |
typedef int (ApplyProc) _ANSI_ARGS_((Hierbox *hboxPtr, Tree * treePtr)); |
| 287 |
typedef Tree *(IterProc) _ANSI_ARGS_((Tree * treePtr, unsigned int mask)); |
| 288 |
|
| 289 |
extern Tk_CustomOption bltDashesOption; |
| 290 |
extern Tk_CustomOption bltDistanceOption; |
| 291 |
extern Tk_CustomOption bltShadowOption; |
| 292 |
extern Tk_CustomOption bltTileOption; |
| 293 |
extern Tk_CustomOption bltUidOption; |
| 294 |
|
| 295 |
static Tk_OptionParseProc StringToButton; |
| 296 |
static Tk_OptionPrintProc ButtonToString; |
| 297 |
static Tk_OptionParseProc StringToImages; |
| 298 |
static Tk_OptionPrintProc ImagesToString; |
| 299 |
static Tk_OptionParseProc StringToScrollMode; |
| 300 |
static Tk_OptionPrintProc ScrollModeToString; |
| 301 |
static Tk_OptionParseProc StringToSeparator; |
| 302 |
static Tk_OptionPrintProc SeparatorToString; |
| 303 |
/* |
| 304 |
* Contains a pointer to the widget that's currently being configured. |
| 305 |
* This is used in the custom configuration parse routine for images. |
| 306 |
*/ |
| 307 |
static Hierbox *hierBox; |
| 308 |
|
| 309 |
static Tk_CustomOption imagesOption = |
| 310 |
{ |
| 311 |
StringToImages, ImagesToString, (ClientData)&hierBox, |
| 312 |
}; |
| 313 |
static Tk_CustomOption buttonOption = |
| 314 |
{ |
| 315 |
StringToButton, ButtonToString, (ClientData)0, |
| 316 |
}; |
| 317 |
static Tk_CustomOption scrollModeOption = |
| 318 |
{ |
| 319 |
StringToScrollMode, ScrollModeToString, (ClientData)0, |
| 320 |
}; |
| 321 |
static Tk_CustomOption separatorOption = |
| 322 |
{ |
| 323 |
StringToSeparator, SeparatorToString, (ClientData)0, |
| 324 |
}; |
| 325 |
/* |
| 326 |
* CachedImage -- |
| 327 |
* |
| 328 |
* Since instances of the same Tk image can be displayed in |
| 329 |
* different windows with possibly different color palettes, Tk |
| 330 |
* internally stores each instance in a linked list. But if |
| 331 |
* the instances are used in the same widget and therefore use |
| 332 |
* the same color palette, this adds a lot of overhead, |
| 333 |
* especially when deleting instances from the linked list. |
| 334 |
* |
| 335 |
* For the hierbox widget, we never need more than a single |
| 336 |
* instance of an image, regardless of how many times it's used. |
| 337 |
* So one solution is to cache the image, maintaining a reference |
| 338 |
* count for each image used in the widget. It's likely that the |
| 339 |
* hierarchy widget will use many instances of the same image |
| 340 |
* (for example the open/close icons). |
| 341 |
*/ |
| 342 |
|
| 343 |
typedef struct CachedImageStruct { |
| 344 |
Tk_Image tkImage; /* The Tk image being cached. */ |
| 345 |
int refCount; /* Reference count for this image. */ |
| 346 |
short int width, height; /* Dimensions of the cached image. */ |
| 347 |
Blt_HashEntry *hashPtr; /* Hash table pointer to the image. */ |
| 348 |
} *CachedImage; |
| 349 |
|
| 350 |
#define ImageHeight(image) ((image)->height) |
| 351 |
#define ImageWidth(image) ((image)->width) |
| 352 |
#define ImageBits(image) ((image)->tkImage) |
| 353 |
|
| 354 |
/* |
| 355 |
* Tree -- |
| 356 |
* |
| 357 |
* Structure representing a general order tree. |
| 358 |
* |
| 359 |
*/ |
| 360 |
struct TreeStruct { |
| 361 |
Blt_Uid nameId; /* String identifying the node within this |
| 362 |
* hierarchy. Does not necessarily have to |
| 363 |
* be unique. */ |
| 364 |
|
| 365 |
Entry *entryPtr; /* Points to the entry structure at this |
| 366 |
* node. */ |
| 367 |
|
| 368 |
Tree *parentPtr; /* Pointer to the parent node. |
| 369 |
* If NULL, this is the root node. */ |
| 370 |
|
| 371 |
Blt_Chain *chainPtr; /* Pointer to list of child nodes. The list |
| 372 |
* isn't allocated until the child nodes are |
| 373 |
* to be inserted. */ |
| 374 |
|
| 375 |
Blt_ChainLink *linkPtr; /* List link containing this node in parent. |
| 376 |
* This is used to remove the node from |
| 377 |
* its parent when destroying the node. */ |
| 378 |
|
| 379 |
short int level; /* The level of this node in the tree. */ |
| 380 |
}; |
| 381 |
|
| 382 |
/* |
| 383 |
* Entry -- |
| 384 |
* |
| 385 |
* Contains data-specific information how to represent the data |
| 386 |
* of a node of the hierarchy. |
| 387 |
* |
| 388 |
*/ |
| 389 |
struct EntryStruct { |
| 390 |
int worldX, worldY; /* X-Y position in world coordinates |
| 391 |
* where the entry is positioned. */ |
| 392 |
|
| 393 |
short int width, height; /* Dimensions of the entry. */ |
| 394 |
|
| 395 |
int lineHeight; /* Length of the vertical line segment. */ |
| 396 |
|
| 397 |
unsigned int flags; /* Flags for this entry. For the |
| 398 |
* definitions of the various bit |
| 399 |
* fields see below. */ |
| 400 |
|
| 401 |
Blt_Uid dataUid; /* This value isn't used in C code. |
| 402 |
* It may be used in Tcl bindings to |
| 403 |
* associate extra data (other than |
| 404 |
* the label, image, or text) with the |
| 405 |
* entry. */ |
| 406 |
|
| 407 |
Blt_Uid tags; /* List of binding tags for this |
| 408 |
* entry. Blt_Uid, not a string, |
| 409 |
* because in the typical case most |
| 410 |
* entries will have the same |
| 411 |
* bintags. */ |
| 412 |
Blt_HashEntry *hashPtr; /* Points the hash entry containing this |
| 413 |
* entry. This is how the node index is |
| 414 |
* stored--as the key of the hash entry. */ |
| 415 |
Hierbox *hboxPtr; |
| 416 |
|
| 417 |
Blt_Uid openCmd, closeCmd; /* Tcl commands to invoke when entries |
| 418 |
* are opened or closed. They override |
| 419 |
* those specified globally. */ |
| 420 |
/* |
| 421 |
* Button information: |
| 422 |
*/ |
| 423 |
short int buttonX, buttonY; /* X-Y coordinate offsets from to |
| 424 |
* upper left corner of the entry to |
| 425 |
* the upper-left corner of the |
| 426 |
* button. Used to pick the |
| 427 |
* button quickly */ |
| 428 |
|
| 429 |
CachedImage *icons; /* Tk images displayed for the entry. |
| 430 |
* The first image is the icon |
| 431 |
* displayed to the left of the |
| 432 |
* entry's label. The second is icon |
| 433 |
* displayed when entry is "open". */ |
| 434 |
|
| 435 |
GC iconGC; /* GC for drawing default bitmaps. */ |
| 436 |
|
| 437 |
short int iconWidth, iconHeight; |
| 438 |
/* Maximum dimensions for icons and |
| 439 |
* buttons for this entry. This is |
| 440 |
* used to align the button, icon, and |
| 441 |
* text. */ |
| 442 |
|
| 443 |
CachedImage *activeIcons; /* Tk images displayed for the entry. |
| 444 |
* The first image is the icon |
| 445 |
* displayed to the left of the |
| 446 |
* entry's label. The second is icon |
| 447 |
* displayed when entry is "open". */ |
| 448 |
|
| 449 |
short int levelX; /* X-coordinate offset of data image |
| 450 |
* or text for children nodes. */ |
| 451 |
/* |
| 452 |
* Label information: |
| 453 |
*/ |
| 454 |
short int labelWidth, labelHeight; |
| 455 |
char *labelText; /* Text displayed right of the icon. */ |
| 456 |
|
| 457 |
|
| 458 |
Tk_Font labelFont; /* Font of label. Overrides global font |
| 459 |
* specification. */ |
| 460 |
|
| 461 |
XColor *labelColor; /* Color of label. Overrides default text color |
| 462 |
* specification. */ |
| 463 |
|
| 464 |
GC labelGC; |
| 465 |
|
| 466 |
Shadow labelShadow; |
| 467 |
|
| 468 |
/* |
| 469 |
* Data (text or image) information: |
| 470 |
*/ |
| 471 |
Blt_Uid dataText; |
| 472 |
|
| 473 |
Tk_Font dataFont; |
| 474 |
|
| 475 |
XColor *dataColor; |
| 476 |
|
| 477 |
Shadow dataShadow; |
| 478 |
|
| 479 |
GC dataGC; |
| 480 |
|
| 481 |
CachedImage *images; |
| 482 |
|
| 483 |
}; |
| 484 |
|
| 485 |
|
| 486 |
static Tk_ConfigSpec entryConfigSpecs[] = |
| 487 |
{ |
| 488 |
{TK_CONFIG_CUSTOM, "-activeicons", "activeIcons", "Icons", |
| 489 |
DEF_ENTRY_ICONS, Tk_Offset(Entry, activeIcons), |
| 490 |
TK_CONFIG_NULL_OK, &imagesOption}, |
| 491 |
{TK_CONFIG_CUSTOM, "-bindtags", "bindTags", "BindTags", |
| 492 |
DEF_ENTRY_BIND_TAGS, Tk_Offset(Entry, tags), |
| 493 |
TK_CONFIG_NULL_OK, &bltUidOption}, |
| 494 |
{TK_CONFIG_CUSTOM, "-closecommand", "entryCloseCommand", |
| 495 |
"EntryCloseCommand", |
| 496 |
DEF_ENTRY_COMMAND, Tk_Offset(Entry, closeCmd), |
| 497 |
TK_CONFIG_NULL_OK, &bltUidOption}, |
| 498 |
{TK_CONFIG_CUSTOM, "-data", "data", "data", |
| 499 |
DEF_ENTRY_DATA, Tk_Offset(Entry, dataUid), |
| 500 |
TK_CONFIG_NULL_OK, &bltUidOption}, |
| 501 |
{TK_CONFIG_CUSTOM, "-button", "button", "Button", |
| 502 |
DEF_ENTRY_BUTTON, Tk_Offset(Entry, flags), |
| 503 |
TK_CONFIG_DONT_SET_DEFAULT, &buttonOption}, |
| 504 |
{TK_CONFIG_CUSTOM, "-icons", "icons", "Icons", |
| 505 |
DEF_ENTRY_ICONS, Tk_Offset(Entry, icons), |
| 506 |
TK_CONFIG_NULL_OK, &imagesOption}, |
| 507 |
{TK_CONFIG_CUSTOM, "-images", "images", "Images", |
| 508 |
DEF_ENTRY_IMAGES, Tk_Offset(Entry, images), |
| 509 |
TK_CONFIG_NULL_OK, &imagesOption}, |
| 510 |
{TK_CONFIG_STRING, "-label", "label", "Label", |
| 511 |
DEF_ENTRY_LABEL, Tk_Offset(Entry, labelText), 0}, |
| 512 |
{TK_CONFIG_COLOR, "-labelcolor", "labelColor", "LabelColor", |
| 513 |
DEF_ENTRY_FOREGROUND, Tk_Offset(Entry, labelColor), |
| 514 |
TK_CONFIG_NULL_OK | TK_CONFIG_COLOR_ONLY}, |
| 515 |
{TK_CONFIG_COLOR, "-labelcolor", "labelColor", "LabelColor", |
| 516 |
DEF_ENTRY_FG_MONO, Tk_Offset(Entry, labelColor), |
| 517 |
TK_CONFIG_NULL_OK | TK_CONFIG_MONO_ONLY}, |
| 518 |
{TK_CONFIG_FONT, "-labelfont", "labelFont", "LabelFont", |
| 519 |
DEF_ENTRY_FONT, Tk_Offset(Entry, labelFont), 0}, |
| 520 |
{TK_CONFIG_CUSTOM, "-labelshadow", "labelShadow", "LabelShadow", |
| 521 |
DEF_ENTRY_SHADOW_COLOR, Tk_Offset(Entry, labelShadow), |
| 522 |
TK_CONFIG_NULL_OK | TK_CONFIG_COLOR_ONLY, &bltShadowOption}, |
| 523 |
{TK_CONFIG_CUSTOM, "-labelshadow", "labelShadow", "LabelShadow", |
| 524 |
DEF_ENTRY_SHADOW_MONO, Tk_Offset(Entry, labelShadow), |
| 525 |
TK_CONFIG_NULL_OK | TK_CONFIG_MONO_ONLY, &bltShadowOption}, |
| 526 |
{TK_CONFIG_CUSTOM, "-opencommand", "entryOpenCommand", "EntryOpenCommand", |
| 527 |
DEF_ENTRY_COMMAND, Tk_Offset(Entry, openCmd), |
| 528 |
TK_CONFIG_NULL_OK, &bltUidOption}, |
| 529 |
{TK_CONFIG_CUSTOM, "-text", "text", "Text", |
| 530 |
DEF_ENTRY_LABEL, Tk_Offset(Entry, dataText), |
| 531 |
TK_CONFIG_NULL_OK, &bltUidOption}, |
| 532 |
{TK_CONFIG_COLOR, "-textcolor", "textColor", "TextColor", |
| 533 |
DEF_ENTRY_FOREGROUND, Tk_Offset(Entry, dataColor), |
| 534 |
TK_CONFIG_NULL_OK | TK_CONFIG_COLOR_ONLY}, |
| 535 |
{TK_CONFIG_FONT, "-textfont", "textFont", "TextFont", |
| 536 |
DEF_ENTRY_FONT, Tk_Offset(Entry, dataFont), 0}, |
| 537 |
{TK_CONFIG_CUSTOM, "-textshadow", "textShadow", "Shadow", |
| 538 |
DEF_ENTRY_SHADOW_COLOR, Tk_Offset(Entry, dataShadow), |
| 539 |
TK_CONFIG_NULL_OK | TK_CONFIG_COLOR_ONLY, &bltShadowOption}, |
| 540 |
{TK_CONFIG_CUSTOM, "-textShadow", "textShadow", "Shadow", |
| 541 |
DEF_ENTRY_SHADOW_MONO, Tk_Offset(Entry, dataShadow), |
| 542 |
TK_CONFIG_NULL_OK | TK_CONFIG_MONO_ONLY, &bltShadowOption}, |
| 543 |
{TK_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL, |
| 544 |
(char *)NULL, 0, 0} |
| 545 |
}; |
| 546 |
|
| 547 |
/* |
| 548 |
* ButtonAttributes -- |
| 549 |
* |
| 550 |
* A button is the open/close indicator at the far left of the |
| 551 |
* entry. It is displayed as a plus or minus in a solid |
| 552 |
* colored box with optionally an border. It has both "active" |
| 553 |
* and "normal" colors. |
| 554 |
*/ |
| 555 |
|
| 556 |
typedef struct { |
| 557 |
XColor *fgColor; /* Foreground color. */ |
| 558 |
Tk_3DBorder border; /* Background color. */ |
| 559 |
XColor *activeFgColor; /* Active foreground color. */ |
| 560 |
Tk_3DBorder activeBorder; /* Active background color. */ |
| 561 |
GC lineGC, normalGC, activeGC; |
| 562 |
int reqSize; |
| 563 |
int borderWidth; |
| 564 |
int openRelief, closeRelief; |
| 565 |
int width, height; |
| 566 |
CachedImage *images; |
| 567 |
|
| 568 |
} ButtonAttributes; |
| 569 |
|
| 570 |
/* |
| 571 |
* TextEdit -- |
| 572 |
* |
| 573 |
* This structure is shared by entries when their labels are |
| 574 |
* edited via the keyboard. It maintains the location of the |
| 575 |
* insertion cursor and the text selection for the editted entry. |
| 576 |
* The structure is shared since we need only one. The "focus" |
| 577 |
* entry should be the only entry receiving KeyPress/KeyRelease |
| 578 |
* events at any time. Information from the previously editted |
| 579 |
* entry is overwritten. |
| 580 |
* |
| 581 |
* Note that all the indices internally are in terms of bytes, |
| 582 |
* not characters. This is because UTF-8 strings may encode a |
| 583 |
* single character into a multi-byte sequence. To find the |
| 584 |
* respective character position |
| 585 |
* |
| 586 |
* n = Tcl_NumUtfChars(string, index); |
| 587 |
* |
| 588 |
* where n is the resulting character number. |
| 589 |
*/ |
| 590 |
typedef struct { |
| 591 |
int active; |
| 592 |
int insertPos; /* Position of the cursor within the |
| 593 |
* array of bytes of the entry's label. */ |
| 594 |
int x, y; /* Offsets of the insertion cursolsr from the |
| 595 |
* start of the label. Used to draw the |
| 596 |
* the cursor relative to the entry. */ |
| 597 |
int width, height; /* Size of the insertion cursor symbol. */ |
| 598 |
|
| 599 |
int selAnchor; /* Fixed end of selection. Used to extend |
| 600 |
* the selection while maintaining the |
| 601 |
* other end of the selection. */ |
| 602 |
int selFirst; /* Position of the first character in the |
| 603 |
* selection. */ |
| 604 |
int selLast; /* Position of the last character in the |
| 605 |
* selection. */ |
| 606 |
|
| 607 |
int cursorOn; /* Indicates if the cursor is displayed. */ |
| 608 |
int onTime, offTime; /* Time in milliseconds to wait before |
| 609 |
* changing the cursor from off-to-on |
| 610 |
* and on-to-off. Setting offTime to 0 makes |
| 611 |
* the cursor steady. */ |
| 612 |
Tcl_TimerToken timerToken; /* Handle for a timer event called periodically |
| 613 |
* to blink the cursor. */ |
| 614 |
|
| 615 |
} TextEdit; |
| 616 |
|
| 617 |
/* |
| 618 |
* LevelInfo -- |
| 619 |
* |
| 620 |
*/ |
| 621 |
|
| 622 |
typedef struct { |
| 623 |
int x; |
| 624 |
int width; |
| 625 |
} LevelInfo; |
| 626 |
|
| 627 |
/* |
| 628 |
* Hierbox -- |
| 629 |
* |
| 630 |
* Represents the hierarchy widget that contains one or more |
| 631 |
* entries. |
| 632 |
* |
| 633 |
* Entries are positioned in "world" coordinates, refering to |
| 634 |
* the virtual hierbox space. Coordinate 0,0 is the upper-left |
| 635 |
* of the hierarchy box and the bottom is the end of the last |
| 636 |
* entry. The widget's Tk window acts as view port into this |
| 637 |
* virtual space. The hierbox's xOffset and yOffset fields specify |
| 638 |
* the location of the view port in the virtual world. Scrolling |
| 639 |
* the viewport is therefore simply changing the xOffset and/or |
| 640 |
* yOffset fields and redrawing. |
| 641 |
* |
| 642 |
* Note that world coordinates are integers, not signed short |
| 643 |
* integers like X11 screen coordinates. It's very easy to |
| 644 |
* create a hierarchy that is more than 0x7FFF pixels high. |
| 645 |
* |
| 646 |
*/ |
| 647 |
struct HierboxStruct { |
| 648 |
Tk_Window tkwin; /* Window that embodies the widget. |
| 649 |
* NULL means that the window has been |
| 650 |
* destroyed but the data structures |
| 651 |
* haven't yet been cleaned up.*/ |
| 652 |
|
| 653 |
Display *display; /* Display containing widget; needed, |
| 654 |
* among other things, to release |
| 655 |
* resources after tkwin has already |
| 656 |
* gone away. */ |
| 657 |
|
| 658 |
Tcl_Interp *interp; /* Interpreter associated with widget. */ |
| 659 |
|
| 660 |
Tcl_Command cmdToken; /* Token for widget's command. */ |
| 661 |
|
| 662 |
int flags; /* For bitfield definitions, see below */ |
| 663 |
|
| 664 |
int allowDuplicates; /* Allow duplicate entries. */ |
| 665 |
|
| 666 |
int autoCreate; /* Automatically create path entries |
| 667 |
* as needed. */ |
| 668 |
int exportSelection; /* Export the selection to X. */ |
| 669 |
|
| 670 |
int hideRoot; /* Don't display the root entry. */ |
| 671 |
|
| 672 |
int scrollTile; /* Adjust the tile along with viewport |
| 673 |
* offsets as the widget is |
| 674 |
* scrolled. */ |
| 675 |
|
| 676 |
int inset; /* Total width of all borders, |
| 677 |
* including traversal highlight and |
| 678 |
* 3-D border. Indicates how much |
| 679 |
* interior stuff must be offset from |
| 680 |
* outside edges to leave room for |
| 681 |
* borders. */ |
| 682 |
|
| 683 |
Tk_3DBorder border; /* 3D border surrounding the window |
| 684 |
* (viewport). */ |
| 685 |
int borderWidth; /* Width of 3D border. */ |
| 686 |
int relief; /* 3D border relief. */ |
| 687 |
|
| 688 |
|
| 689 |
int highlightWidth; /* Width in pixels of highlight to draw |
| 690 |
* around widget when it has the focus. |
| 691 |
* <= 0 means don't draw a highlight. */ |
| 692 |
XColor *highlightBgColor; /* Color for drawing traversal highlight |
| 693 |
* area when highlight is off. */ |
| 694 |
XColor *highlightColor; /* Color for drawing traversal highlight. */ |
| 695 |
|
| 696 |
Blt_Tile tile; /* Tiled background */ |
| 697 |
|
| 698 |
char *separator; /* Pathname separators */ |
| 699 |
char *trimLeft; /* Leading characters to trim from |
| 700 |
* pathnames */ |
| 701 |
|
| 702 |
/* |
| 703 |
* Entries are connected by horizontal and vertical lines. They |
| 704 |
* may be drawn dashed or solid. |
| 705 |
*/ |
| 706 |
int lineWidth; /* Width of lines connecting entries */ |
| 707 |
int dashes; /* Dash on-off value. */ |
| 708 |
XColor *lineColor; /* Color of connecting lines. */ |
| 709 |
|
| 710 |
/* |
| 711 |
* Button Information: |
| 712 |
* |
| 713 |
* The button is the open/close indicator at the far left of the |
| 714 |
* entry. It is usually displayed as a plus or minus in a solid |
| 715 |
* colored box with optionally an border. It has both "active" |
| 716 |
* and "normal" colors. |
| 717 |
*/ |
| 718 |
ButtonAttributes button; |
| 719 |
|
| 720 |
|
| 721 |
/* |
| 722 |
* Selection Information: |
| 723 |
* |
| 724 |
* The selection is the rectangle that contains a selected entry. |
| 725 |
* There may be many selected entries. It is displayed as a |
| 726 |
* solid colored box with optionally a 3D border. |
| 727 |
*/ |
| 728 |
Tk_3DBorder selBorder; /* Background color of an highlighted entry.*/ |
| 729 |
|
| 730 |
int selRelief; /* Relief of selected items. Currently |
| 731 |
* is always raised. */ |
| 732 |
|
| 733 |
int selBorderWidth; /* Border width of a selected entry.*/ |
| 734 |
|
| 735 |
XColor *selFgColor; /* Text color of a selected entry. */ |
| 736 |
|
| 737 |
Tree *selAnchorPtr; /* Fixed end of selection (i.e. node |
| 738 |
* at which selection was started.) */ |
| 739 |
|
| 740 |
Blt_HashTable selectTable; |
| 741 |
Blt_Chain selectChain; |
| 742 |
|
| 743 |
int sortSelection; /* Indicates if the entries in the |
| 744 |
* selection should be sorted or |
| 745 |
* displayed in the order they were |
| 746 |
* selected. */ |
| 747 |
|
| 748 |
char *selectMode; /* Selection style. This value isn't |
| 749 |
* used in C code (it's just a place |
| 750 |
* holder), but for the widget's Tcl |
| 751 |
* bindings. */ |
| 752 |
|
| 753 |
char *selectCmd; /* Tcl script that's invoked whenever |
| 754 |
* the selection changes. */ |
| 755 |
|
| 756 |
int leader; /* Number of pixels padding between entries */ |
| 757 |
|
| 758 |
Tk_Cursor cursor; /* X Cursor */ |
| 759 |
|
| 760 |
int reqWidth, reqHeight; /* Requested dimensions of the widget's |
| 761 |
* window. */ |
| 762 |
|
| 763 |
GC lineGC; /* GC for drawing dotted line between |
| 764 |
* entries. */ |
| 765 |
|
| 766 |
XColor *activeFgColor; |
| 767 |
Tk_3DBorder activeBorder; |
| 768 |
|
| 769 |
XColor *focusColor; |
| 770 |
Blt_Dashes focusDashes; /* Dash on-off value. */ |
| 771 |
GC focusGC; /* Graphics context for the active label */ |
| 772 |
int focusEdit; /* Indicates if the label of the "focus" entry |
| 773 |
* can be editted. */ |
| 774 |
TextEdit labelEdit; |
| 775 |
|
| 776 |
Tree *activePtr; |
| 777 |
Tree *focusPtr; /* Pointer to node that's currently active. */ |
| 778 |
Tree *activeButtonPtr; /* Pointer to last active button */ |
| 779 |
|
| 780 |
/* Number of pixels to move for 1 scroll unit. */ |
| 781 |
int reqScrollX, reqScrollY; |
| 782 |
int xScrollUnits, yScrollUnits; |
| 783 |
|
| 784 |
/* Command strings to control horizontal and vertical scrollbars. */ |
| 785 |
char *xScrollCmdPrefix, *yScrollCmdPrefix; |
| 786 |
|
| 787 |
int scrollMode; /* Selects mode of scrolling: either |
| 788 |
* BLT_SCROLL_MODE_HIERBOX, |
| 789 |
* BLT_SCROLL_MODE_LISTBOX, or |
| 790 |
* BLT_SCROLL_MODE_CANVAS. */ |
| 791 |
|
| 792 |
/* |
| 793 |
* Total size of all "open" entries. This represents the range of |
| 794 |
* world coordinates. |
| 795 |
*/ |
| 796 |
int worldWidth, worldHeight; |
| 797 |
int xOffset, yOffset; /* Translation between view port and |
| 798 |
* world origin. */ |
| 799 |
int minHeight; /* Minimum entry height. Used to |
| 800 |
* to compute what the y-scroll unit |
| 801 |
* should be. */ |
| 802 |
LevelInfo *levelInfo; |
| 803 |
/* |
| 804 |
* Scanning information: |
| 805 |
*/ |
| 806 |
int scanAnchorX, scanAnchorY; |
| 807 |
/* Scan anchor in screen coordinates. */ |
| 808 |
int scanX, scanY; /* X-Y world coordinate where the scan |
| 809 |
* started. */ |
| 810 |
|
| 811 |
|
| 812 |
Blt_HashTable nodeTable; /* Table of node identifiers */ |
| 813 |
Blt_HashTable imageTable; /* Table of Tk images */ |
| 814 |
Tree *rootPtr; /* Root of hierarchy */ |
| 815 |
int depth; /* Maximum depth of the hierarchy. */ |
| 816 |
|
| 817 |
Tree **visibleArr; /* Array of visible entries */ |
| 818 |
int nVisible; /* Number of entries in the above array */ |
| 819 |
|
| 820 |
int nextSerial; |
| 821 |
|
| 822 |
char *openCmd, *closeCmd; /* Tcl commands to invoke when entries |
| 823 |
* are opened or closed. */ |
| 824 |
|
| 825 |
Tk_Font defFont; /* Specifies a default font for labels and |
| 826 |
* text data. It may be overridden for a |
| 827 |
* single entry by its -*font option. */ |
| 828 |
|
| 829 |
XColor *defColor; /* Global text color for labels. This |
| 830 |
* may be overridden by the -color |
| 831 |
* option for an individual entry. */ |
| 832 |
|
| 833 |
Pixmap iconBitmap, iconMask;/* Default icon bitmaps */ |
| 834 |
XColor *iconColor; |
| 835 |
|
| 836 |
char *takeFocus; |
| 837 |
char *sortCmd; /* Tcl command to invoke to sort entries */ |
| 838 |
|
| 839 |
ClientData clientData; |
| 840 |
Blt_BindTable bindTable; /* Binding information for entries. */ |
| 841 |
Blt_BindTable buttonBindTable; /* Binding information for buttons. */ |
| 842 |
}; |
| 843 |
|
| 844 |
static Tk_ConfigSpec buttonConfigSpecs[] = |
| 845 |
{ |
| 846 |
{TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Background", |
| 847 |
DEF_BUTTON_ACTIVE_BG_MONO, Tk_Offset(Hierbox, button.activeBorder), |
| 848 |
TK_CONFIG_MONO_ONLY}, |
| 849 |
{TK_CONFIG_BORDER, "-activebackground", "activeBackground", "Background", |
| 850 |
DEF_BUTTON_ACTIVE_BACKGROUND, Tk_Offset(Hierbox, button.activeBorder), |
| 851 |
TK_CONFIG_COLOR_ONLY}, |
| 852 |
{TK_CONFIG_COLOR, "-activeforeground", "activeForeground", "Foreground", |
| 853 |
DEF_BUTTON_ACTIVE_FOREGROUND, Tk_Offset(Hierbox, button.activeFgColor), |
| 854 |
TK_CONFIG_COLOR_ONLY}, |
| 855 |
{TK_CONFIG_COLOR, "-activeforeground", "activeForeground", "Foreground", |
| 856 |
DEF_BUTTON_ACTIVE_FG_MONO, Tk_Offset(Hierbox, button.activeFgColor), |
| 857 |
TK_CONFIG_MONO_ONLY}, |
| 858 |
{TK_CONFIG_BORDER, "-background", "background", "Background", |
| 859 |
DEF_BUTTON_NORMAL_BACKGROUND, Tk_Offset(Hierbox, button.border), |
| 860 |
TK_CONFIG_COLOR_ONLY}, |
| 861 |
{TK_CONFIG_BORDER, "-background", "background", "Background", |
| 862 |
DEF_BUTTON_NORMAL_BG_MONO, Tk_Offset(Hierbox, button.border), |
| 863 |
TK_CONFIG_MONO_ONLY}, |
| 864 |
{TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *)NULL, (char *)NULL, 0, 0}, |
| 865 |
{TK_CONFIG_SYNONYM, "-bg", "background", (char *)NULL, (char *)NULL, 0, 0}, |
| 866 |
{TK_CONFIG_CUSTOM, "-borderwidth", "borderWidth", "BorderWidth", |
| 867 |
DEF_BUTTON_BORDERWIDTH, Tk_Offset(Hierbox, button.borderWidth), |
| 868 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 869 |
{TK_CONFIG_RELIEF, "-closerelief", "closeRelief", "Relief", |
| 870 |
DEF_BUTTON_CLOSE_RELIEF, Tk_Offset(Hierbox, button.closeRelief), |
| 871 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 872 |
{TK_CONFIG_SYNONYM, "-fg", "foreground", (char *)NULL, (char *)NULL, 0, 0}, |
| 873 |
{TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground", |
| 874 |
DEF_BUTTON_NORMAL_FOREGROUND, Tk_Offset(Hierbox, button.fgColor), |
| 875 |
TK_CONFIG_COLOR_ONLY}, |
| 876 |
{TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground", |
| 877 |
DEF_BUTTON_NORMAL_FG_MONO, Tk_Offset(Hierbox, button.fgColor), |
| 878 |
TK_CONFIG_MONO_ONLY}, |
| 879 |
{TK_CONFIG_CUSTOM, "-images", "images", "Images", |
| 880 |
DEF_BUTTON_IMAGES, Tk_Offset(Hierbox, button.images), |
| 881 |
TK_CONFIG_NULL_OK, &imagesOption}, |
| 882 |
{TK_CONFIG_RELIEF, "-openrelief", "openRelief", "Relief", |
| 883 |
DEF_BUTTON_OPEN_RELIEF, Tk_Offset(Hierbox, button.openRelief), |
| 884 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 885 |
{TK_CONFIG_CUSTOM, "-size", "size", "Size", DEF_BUTTON_SIZE, |
| 886 |
Tk_Offset(Hierbox, button.reqSize), 0, &bltDistanceOption}, |
| 887 |
{TK_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL, |
| 888 |
(char *)NULL, 0, 0} |
| 889 |
}; |
| 890 |
|
| 891 |
static Tk_ConfigSpec configSpecs[] = |
| 892 |
{ |
| 893 |
{TK_CONFIG_BORDER, "-activebackground", "activeBackground", |
| 894 |
"ActiveBackground", |
| 895 |
DEF_HIERBOX_ACTIVE_BACKGROUND, Tk_Offset(Hierbox, activeBorder), |
| 896 |
TK_CONFIG_COLOR_ONLY | TK_CONFIG_NULL_OK}, |
| 897 |
{TK_CONFIG_BORDER, "-activebackground", "activeBackground", |
| 898 |
"ActiveBackground", |
| 899 |
DEF_HIERBOX_ACTIVE_BG_MONO, Tk_Offset(Hierbox, activeBorder), |
| 900 |
TK_CONFIG_MONO_ONLY | TK_CONFIG_NULL_OK}, |
| 901 |
{TK_CONFIG_COLOR, "-activeforeground", "activeForeground", "Foreground", |
| 902 |
DEF_HIERBOX_ACTIVE_FOREGROUND, Tk_Offset(Hierbox, activeFgColor), 0}, |
| 903 |
{TK_CONFIG_BOOLEAN, "-allowduplicates", "allowDuplicates", |
| 904 |
"AllowDuplicates", |
| 905 |
DEF_HIERBOX_ALLOW_DUPLICATES, Tk_Offset(Hierbox, allowDuplicates), |
| 906 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 907 |
{TK_CONFIG_BOOLEAN, "-autocreate", "autoCreate", "AutoCreate", |
| 908 |
DEF_HIERBOX_MAKE_PATH, Tk_Offset(Hierbox, autoCreate), |
| 909 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 910 |
{TK_CONFIG_BORDER, "-background", "background", "Background", |
| 911 |
DEF_HIERBOX_BACKGROUND, Tk_Offset(Hierbox, border), 0}, |
| 912 |
{TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *)NULL, (char *)NULL, 0, 0}, |
| 913 |
{TK_CONFIG_SYNONYM, "-bg", "background", (char *)NULL, (char *)NULL, 0, 0}, |
| 914 |
{TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor", |
| 915 |
DEF_HIERBOX_CURSOR, Tk_Offset(Hierbox, cursor), TK_CONFIG_NULL_OK}, |
| 916 |
{TK_CONFIG_CUSTOM, "-borderwidth", "borderWidth", "BorderWidth", |
| 917 |
DEF_HIERBOX_BORDERWIDTH, Tk_Offset(Hierbox, borderWidth), |
| 918 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 919 |
{TK_CONFIG_STRING, "-closecommand", "closeCommand", "CloseCommand", |
| 920 |
DEF_HIERBOX_COMMAND, Tk_Offset(Hierbox, closeCmd), TK_CONFIG_NULL_OK}, |
| 921 |
{TK_CONFIG_CUSTOM, "-dashes", "dashes", "Dashes", |
| 922 |
DEF_HIERBOX_DASHES, Tk_Offset(Hierbox, dashes), |
| 923 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 924 |
{TK_CONFIG_BOOLEAN, "-exportselection", "exportSelection", |
| 925 |
"ExportSelection", |
| 926 |
DEF_HIERBOX_EXPORT_SELECTION, Tk_Offset(Hierbox, exportSelection), |
| 927 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 928 |
{TK_CONFIG_SYNONYM, "-fg", "foreground", (char *)NULL, (char *)NULL, 0, 0}, |
| 929 |
{TK_CONFIG_CUSTOM, "-focusdashes", "focusDashes", "FocusDashes", |
| 930 |
DEF_HIERBOX_FOCUS_DASHES, Tk_Offset(Hierbox, focusDashes), |
| 931 |
TK_CONFIG_NULL_OK, &bltDashesOption}, |
| 932 |
{TK_CONFIG_BOOLEAN, "-focusedit", "focusEdit", "FocusEdit", |
| 933 |
DEF_HIERBOX_FOCUS_EDIT, Tk_Offset(Hierbox, focusEdit), 0}, |
| 934 |
{TK_CONFIG_COLOR, "-focusforeground", "focusForeground", |
| 935 |
"FocusForeground", |
| 936 |
DEF_HIERBOX_FOCUS_FOREGROUND, Tk_Offset(Hierbox, focusColor), |
| 937 |
TK_CONFIG_COLOR_ONLY}, |
| 938 |
{TK_CONFIG_COLOR, "-focusforeground", "focusForeground", |
| 939 |
"FocusForeground", |
| 940 |
DEF_HIERBOX_FOCUS_FG_MONO, Tk_Offset(Hierbox, focusColor), |
| 941 |
TK_CONFIG_MONO_ONLY}, |
| 942 |
{TK_CONFIG_FONT, "-font", "font", "Font", |
| 943 |
DEF_HIERBOX_FONT, Tk_Offset(Hierbox, defFont), 0}, |
| 944 |
{TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground", |
| 945 |
DEF_HIERBOX_TEXT_COLOR, Tk_Offset(Hierbox, defColor), |
| 946 |
TK_CONFIG_COLOR_ONLY}, |
| 947 |
{TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground", |
| 948 |
DEF_HIERBOX_TEXT_MONO, Tk_Offset(Hierbox, defColor), TK_CONFIG_MONO_ONLY}, |
| 949 |
{TK_CONFIG_CUSTOM, "-height", "height", "Height", |
| 950 |
DEF_HIERBOX_HEIGHT, Tk_Offset(Hierbox, reqHeight), |
| 951 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 952 |
{TK_CONFIG_BOOLEAN, "-hideroot", "hideRoot", "HideRoot", |
| 953 |
DEF_HIERBOX_HIDE_ROOT, Tk_Offset(Hierbox, hideRoot), |
| 954 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 955 |
{TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground", |
| 956 |
"HighlightBackground", |
| 957 |
DEF_HIERBOX_HIGHLIGHT_BACKGROUND, Tk_Offset(Hierbox, highlightBgColor), |
| 958 |
TK_CONFIG_COLOR_ONLY}, |
| 959 |
{TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground", |
| 960 |
"HighlightBackground", |
| 961 |
DEF_HIERBOX_HIGHLIGHT_BG_MONO, Tk_Offset(Hierbox, highlightBgColor), |
| 962 |
TK_CONFIG_MONO_ONLY}, |
| 963 |
{TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor", |
| 964 |
DEF_HIERBOX_HIGHLIGHT_COLOR, Tk_Offset(Hierbox, highlightColor), 0}, |
| 965 |
{TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness", |
| 966 |
"HighlightThickness", |
| 967 |
DEF_HIERBOX_HIGHLIGHT_WIDTH, Tk_Offset(Hierbox, highlightWidth), |
| 968 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 969 |
{TK_CONFIG_COLOR, "-linecolor", "lineColor", "LineColor", |
| 970 |
DEF_HIERBOX_LINE_COLOR, Tk_Offset(Hierbox, lineColor), |
| 971 |
TK_CONFIG_COLOR_ONLY}, |
| 972 |
{TK_CONFIG_COLOR, "-linecolor", "lineColor", "LineColor", |
| 973 |
DEF_HIERBOX_LINE_MONO, Tk_Offset(Hierbox, lineColor), |
| 974 |
TK_CONFIG_MONO_ONLY}, |
| 975 |
{TK_CONFIG_CUSTOM, "-linespacing", "lineSpacing", "LineSpacing", |
| 976 |
DEF_HIERBOX_LINE_SPACING, Tk_Offset(Hierbox, leader), |
| 977 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 978 |
{TK_CONFIG_CUSTOM, "-linewidth", "lineWidth", "LineWidth", |
| 979 |
DEF_HIERBOX_LINE_WIDTH, Tk_Offset(Hierbox, lineWidth), |
| 980 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 981 |
{TK_CONFIG_STRING, "-opencommand", "openCommand", "OpenCommand", |
| 982 |
DEF_HIERBOX_COMMAND, Tk_Offset(Hierbox, openCmd), TK_CONFIG_NULL_OK}, |
| 983 |
{TK_CONFIG_RELIEF, "-relief", "relief", "Relief", |
| 984 |
DEF_HIERBOX_RELIEF, Tk_Offset(Hierbox, relief), 0}, |
| 985 |
{TK_CONFIG_CUSTOM, "-scrollmode", "scrollMode", "ScrollMode", |
| 986 |
DEF_HIERBOX_SCROLL_MODE, Tk_Offset(Hierbox, scrollMode), |
| 987 |
TK_CONFIG_DONT_SET_DEFAULT, &scrollModeOption}, |
| 988 |
{TK_CONFIG_BOOLEAN, "-scrolltile", "scrollTile", "ScrollTile", |
| 989 |
DEF_HIERBOX_SCROLL_TILE, Tk_Offset(Hierbox, scrollTile), |
| 990 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 991 |
{TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground", |
| 992 |
DEF_HIERBOX_SELECT_BG_MONO, Tk_Offset(Hierbox, selBorder), |
| 993 |
TK_CONFIG_MONO_ONLY}, |
| 994 |
{TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground", |
| 995 |
DEF_HIERBOX_SELECT_BACKGROUND, Tk_Offset(Hierbox, selBorder), |
| 996 |
TK_CONFIG_COLOR_ONLY}, |
| 997 |
{TK_CONFIG_CUSTOM, "-selectborderwidth", "selectBorderWidth", "BorderWidth", |
| 998 |
DEF_HIERBOX_SELECT_BORDERWIDTH, Tk_Offset(Hierbox, selBorderWidth), |
| 999 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 1000 |
{TK_CONFIG_STRING, "-selectcommand", "selectCommand", "SelectCommand", |
| 1001 |
DEF_HIERBOX_SELECT_CMD, Tk_Offset(Hierbox, selectCmd), |
| 1002 |
TK_CONFIG_NULL_OK}, |
| 1003 |
{TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background", |
| 1004 |
DEF_HIERBOX_SELECT_FG_MONO, Tk_Offset(Hierbox, selFgColor), |
| 1005 |
TK_CONFIG_MONO_ONLY}, |
| 1006 |
{TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background", |
| 1007 |
DEF_HIERBOX_SELECT_FOREGROUND, Tk_Offset(Hierbox, selFgColor), |
| 1008 |
TK_CONFIG_COLOR_ONLY}, |
| 1009 |
{TK_CONFIG_STRING, "-selectmode", "selectMode", "SelectMode", |
| 1010 |
DEF_HIERBOX_SELECT_MODE, Tk_Offset(Hierbox, selectMode), |
| 1011 |
TK_CONFIG_NULL_OK}, |
| 1012 |
{TK_CONFIG_RELIEF, "-selectrelief", "selectRelief", "Relief", |
| 1013 |
DEF_HIERBOX_SELECT_RELIEF, Tk_Offset(Hierbox, selRelief), |
| 1014 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 1015 |
{TK_CONFIG_CUSTOM, "-separator", "separator", "Separator", |
| 1016 |
DEF_HIERBOX_SEPARATOR, Tk_Offset(Hierbox, separator), |
| 1017 |
TK_CONFIG_NULL_OK, &separatorOption}, |
| 1018 |
{TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus", |
| 1019 |
DEF_HIERBOX_TAKE_FOCUS, Tk_Offset(Hierbox, takeFocus), TK_CONFIG_NULL_OK}, |
| 1020 |
{TK_CONFIG_CUSTOM, "-tile", "tile", "Tile", |
| 1021 |
(char *)NULL, Tk_Offset(Hierbox, tile), TK_CONFIG_NULL_OK, |
| 1022 |
&bltTileOption}, |
| 1023 |
{TK_CONFIG_STRING, "-trimleft", "trimLeft", "Trim", |
| 1024 |
DEF_HIERBOX_TRIMLEFT, Tk_Offset(Hierbox, trimLeft), TK_CONFIG_NULL_OK}, |
| 1025 |
{TK_CONFIG_CUSTOM, "-width", "width", "Width", |
| 1026 |
DEF_HIERBOX_WIDTH, Tk_Offset(Hierbox, reqWidth), |
| 1027 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 1028 |
{TK_CONFIG_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand", |
| 1029 |
(char *)NULL, Tk_Offset(Hierbox, xScrollCmdPrefix), TK_CONFIG_NULL_OK}, |
| 1030 |
{TK_CONFIG_CUSTOM, "-xscrollincrement", "xScrollIncrement", |
| 1031 |
"ScrollIncrement", |
| 1032 |
DEF_HIERBOX_SCROLL_INCREMENT, Tk_Offset(Hierbox, reqScrollX), |
| 1033 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 1034 |
{TK_CONFIG_STRING, "-yscrollcommand", "yScrollCommand", "ScrollCommand", |
| 1035 |
(char *)NULL, Tk_Offset(Hierbox, yScrollCmdPrefix), TK_CONFIG_NULL_OK}, |
| 1036 |
{TK_CONFIG_CUSTOM, "-yscrollincrement", "yScrollIncrement", |
| 1037 |
"ScrollIncrement", |
| 1038 |
DEF_HIERBOX_SCROLL_INCREMENT, Tk_Offset(Hierbox, reqScrollY), |
| 1039 |
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption}, |
| 1040 |
{TK_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL, |
| 1041 |
(char *)NULL, 0, 0} |
| 1042 |
}; |
| 1043 |
|
| 1044 |
typedef struct { |
| 1045 |
int x, y; /* Tracks the current world |
| 1046 |
* coordinates as we traverse through |
| 1047 |
* the tree. After a full-tree |
| 1048 |
* traversal, the y-coordinate will be |
| 1049 |
* the height of the virtual |
| 1050 |
* hierarchy. */ |
| 1051 |
int maxWidth; /* Maximum entry width. This is the |
| 1052 |
* width of the virtual hierarchy. */ |
| 1053 |
int labelOffset; |
| 1054 |
int minHeight; /* Minimum entry height. Used to |
| 1055 |
* to compute what the y-scroll unit |
| 1056 |
* should be. */ |
| 1057 |
int maxIconWidth; |
| 1058 |
int level, depth; |
| 1059 |
} LayoutInfo; |
| 1060 |
|
| 1061 |
#define DEF_ICON_WIDTH 16 |
| 1062 |
#define DEF_ICON_HEIGHT 16 |
| 1063 |
static unsigned char folderBits[] = |
| 1064 |
{ |
| 1065 |
0x00, 0x00, 0x7c, 0x00, 0x82, 0x00, 0x81, 0x3f, 0x41, 0x40, 0x3f, 0xc0, |
| 1066 |
0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, |
| 1067 |
0x01, 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x00, 0x00}; |
| 1068 |
|
| 1069 |
static unsigned char folderMaskBits[] = |
| 1070 |
{ |
| 1071 |
0x00, 0x00, 0x7c, 0x00, 0xfe, 0x00, 0xff, 0x3f, 0xff, 0x7f, 0xff, 0xff, |
| 1072 |
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 1073 |
0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0x00, 0x00}; |
| 1074 |
|
| 1075 |
|
| 1076 |
/* Forward Declarations */ |
| 1077 |
static void DestroyHierbox _ANSI_ARGS_((DestroyData dataPtr)); |
| 1078 |
static void HierboxEventProc _ANSI_ARGS_((ClientData clientdata, |
| 1079 |
XEvent *eventPtr)); |
| 1080 |
static void DrawButton _ANSI_ARGS_((Hierbox *hboxPtr, Tree * treePtr, |
| 1081 |
Drawable drawable)); |
| 1082 |
static void DisplayHierbox _ANSI_ARGS_((ClientData clientData)); |
| 1083 |
static void HierboxInstCmdDeleteProc _ANSI_ARGS_((ClientData clientdata)); |
| 1084 |
static int HierboxInstCmd _ANSI_ARGS_((ClientData clientdata, |
| 1085 |
Tcl_Interp *interp, int argc, char **argv)); |
| 1086 |
static void EventuallyRedraw _ANSI_ARGS_((Hierbox *hboxPtr)); |
| 1087 |
static void SelectCmdProc _ANSI_ARGS_((ClientData clientData)); |
| 1088 |
static void EventuallyInvokeSelectCmd _ANSI_ARGS_((Hierbox *hboxPtr)); |
| 1089 |
static int ComputeVisibleEntries _ANSI_ARGS_((Hierbox *hboxPtr)); |
| 1090 |
static int ConfigureEntry _ANSI_ARGS_((Hierbox *hboxPtr, Entry * entryPtr, |
| 1091 |
int argc, CONST char **argv, int flags)); |
| 1092 |
static void ComputeLayout _ANSI_ARGS_((Hierbox *hboxPtr)); |
| 1093 |
|
| 1094 |
static CompareProc ExactCompare, GlobCompare, RegexpCompare; |
| 1095 |
static ApplyProc SelectNode, GetSelectedLabels, CloseNode, SizeOfNode, |
| 1096 |
IsSelectedNode, MapAncestors, FixUnmappedSelections, UnmapNode, |
| 1097 |
SortNode, OpenNode; |
| 1098 |
static IterProc NextNode, LastNode; |
| 1099 |
static Tk_ImageChangedProc ImageChangedProc; |
| 1100 |
static Blt_ChainCompareProc CompareNodesByTclCmd, CompareNodesByName; |
| 1101 |
static Blt_BindPickProc PickButton, PickEntry; |
| 1102 |
static Blt_BindTagProc GetTags; |
| 1103 |
static Tk_SelectionProc SelectionProc; |
| 1104 |
static Tk_LostSelProc LostSelection; |
| 1105 |
static Tcl_CmdProc HierboxCmd; |
| 1106 |
static Blt_TileChangedProc TileChangedProc; |
| 1107 |
static Tcl_TimerProc LabelBlinkProc; |
| 1108 |
static Tcl_FreeProc DestroyNode; |
| 1109 |
|
| 1110 |
|
| 1111 |
/* |
| 1112 |
*---------------------------------------------------------------------- |
| 1113 |
* |
| 1114 |
* StringToScrollMode -- |
| 1115 |
* |
| 1116 |
* Convert the string reprsenting a scroll mode, to its numeric |
| 1117 |
* form. |
| 1118 |
* |
| 1119 |
* Results: |
| 1120 |
* If the string is successfully converted, TCL_OK is returned. |
| 1121 |
* Otherwise, TCL_ERROR is returned and an error message is left |
| 1122 |
* in interpreter's result field. |
| 1123 |
* |
| 1124 |
*---------------------------------------------------------------------- |
| 1125 |
*/ |
| 1126 |
/*ARGSUSED*/ |
| 1127 |
static int |
| 1128 |
StringToScrollMode(clientData, interp, tkwin, string, widgRec, offset) |
| 1129 |
ClientData clientData; /* Not used. */ |
| 1130 |
Tcl_Interp *interp; /* Interpreter to send results back to */ |
| 1131 |
Tk_Window tkwin; /* Not used. */ |
| 1132 |
char *string; /* New legend position string */ |
| 1133 |
char *widgRec; /* Widget record */ |
| 1134 |
int offset; /* offset to XPoint structure */ |
| 1135 |
{ |
| 1136 |
int *modePtr = (int *)(widgRec + offset); |
| 1137 |
|
| 1138 |
if ((string[0] == 'l') && (strcmp(string, "listbox") == 0)) { |
| 1139 |
*modePtr = BLT_SCROLL_MODE_LISTBOX; |
| 1140 |
} else if ((string[0] == 'h') && (strcmp(string, "hierbox") == 0)) { |
| 1141 |
*modePtr = BLT_SCROLL_MODE_HIERBOX; |
| 1142 |
} else if ((string[0] == 'c') && (strcmp(string, "canvas") == 0)) { |
| 1143 |
*modePtr = BLT_SCROLL_MODE_CANVAS; |
| 1144 |
} else { |
| 1145 |
Tcl_AppendResult(interp, "bad scroll mode \"", string, |
| 1146 |
"\": should be \"hierbox\", \"listbox\", or \"canvas\"", (char *)NULL); |
| 1147 |
return TCL_ERROR; |
| 1148 |
} |
| 1149 |
return TCL_OK; |
| 1150 |
} |
| 1151 |
|
| 1152 |
/* |
| 1153 |
*---------------------------------------------------------------------- |
| 1154 |
* |
| 1155 |
* ScrollModeToString -- |
| 1156 |
* |
| 1157 |
* Results: |
| 1158 |
* The string representation of the button boolean is returned. |
| 1159 |
* |
| 1160 |
*---------------------------------------------------------------------- |
| 1161 |
*/ |
| 1162 |
/*ARGSUSED*/ |
| 1163 |
static char * |
| 1164 |
ScrollModeToString(clientData, tkwin, widgRec, offset, freeProcPtr) |
| 1165 |
ClientData clientData; /* Not used. */ |
| 1166 |
Tk_Window tkwin; /* Not used. */ |
| 1167 |
char *widgRec; /* Widget record */ |
| 1168 |
int offset; /* offset of flags field in record */ |
| 1169 |
Tcl_FreeProc **freeProcPtr; /* Memory deallocation scheme to use */ |
| 1170 |
{ |
| 1171 |
int mode = *(int *)(widgRec + offset); |
| 1172 |
|
| 1173 |
switch (mode) { |
| 1174 |
case BLT_SCROLL_MODE_LISTBOX: |
| 1175 |
return "listbox"; |
| 1176 |
case BLT_SCROLL_MODE_HIERBOX: |
| 1177 |
return "hierbox"; |
| 1178 |
case BLT_SCROLL_MODE_CANVAS: |
| 1179 |
return "canvas"; |
| 1180 |
default: |
| 1181 |
return "unknown scroll mode"; |
| 1182 |
} |
| 1183 |
} |
| 1184 |
|
| 1185 |
/* |
| 1186 |
*---------------------------------------------------------------------- |
| 1187 |
* |
| 1188 |
* StringToButton -- |
| 1189 |
* |
| 1190 |
* Convert a string to one of three values. |
| 1191 |
* 0 - false, no, off |
| 1192 |
* 1 - true, yes, on |
| 1193 |
* 2 - auto |
| 1194 |
* Results: |
| 1195 |
* If the string is successfully converted, TCL_OK is returned. |
| 1196 |
* Otherwise, TCL_ERROR is returned and an error message is left in |
| 1197 |
* interpreter's result field. |
| 1198 |
* |
| 1199 |
*---------------------------------------------------------------------- |
| 1200 |
*/ |
| 1201 |
/*ARGSUSED*/ |
| 1202 |
static int |
| 1203 |
StringToButton(clientData, interp, tkwin, string, widgRec, offset) |
| 1204 |
ClientData clientData; /* Not used. */ |
| 1205 |
Tcl_Interp *interp; /* Interpreter to send results back to */ |
| 1206 |
Tk_Window tkwin; /* Not used. */ |
| 1207 |
char *string; /* New legend position string */ |
| 1208 |
char *widgRec; /* Widget record */ |
| 1209 |
int offset; /* offset to XPoint structure */ |
| 1210 |
{ |
| 1211 |
int *flags = (int *)(widgRec + offset); |
| 1212 |
|
| 1213 |
*flags &= ~BUTTON_MASK; |
| 1214 |
if ((string[0] == 'a') && (strcmp(string, "auto") == 0)) { |
| 1215 |
*flags |= BUTTON_AUTO; |
| 1216 |
} else { |
| 1217 |
int value; |
| 1218 |
|
| 1219 |
if (Tcl_GetBoolean(interp, string, &value) != TCL_OK) { |
| 1220 |
return TCL_ERROR; |
| 1221 |
} |
| 1222 |
if (value) { |
| 1223 |
*flags |= BUTTON_SHOW; |
| 1224 |
} |
| 1225 |
} |
| 1226 |
return TCL_OK; |
| 1227 |
} |
| 1228 |
|
| 1229 |
/* |
| 1230 |
*---------------------------------------------------------------------- |
| 1231 |
* |
| 1232 |
* ButtonToString -- |
| 1233 |
* |
| 1234 |
* Results: |
| 1235 |
* The string representation of the button boolean is returned. |
| 1236 |
* |
| 1237 |
*---------------------------------------------------------------------- |
| 1238 |
*/ |
| 1239 |
/*ARGSUSED*/ |
| 1240 |
static char * |
| 1241 |
ButtonToString(clientData, tkwin, widgRec, offset, freeProcPtr) |
| 1242 |
ClientData clientData; /* Not used. */ |
| 1243 |
Tk_Window tkwin; /* Not used. */ |
| 1244 |
char *widgRec; /* Widget record */ |
| 1245 |
int offset; /* offset of flags field in record */ |
| 1246 |
Tcl_FreeProc **freeProcPtr; /* Memory deallocation scheme to use */ |
| 1247 |
{ |
| 1248 |
unsigned int flags = *(int *)(widgRec + offset); |
| 1249 |
|
| 1250 |
switch (flags & BUTTON_MASK) { |
| 1251 |
case 0: |
| 1252 |
return "0"; |
| 1253 |
case BUTTON_SHOW: |
| 1254 |
return "1"; |
| 1255 |
case BUTTON_AUTO: |
| 1256 |
return "auto"; |
| 1257 |
default: |
| 1258 |
return "unknown button value"; |
| 1259 |
} |
| 1260 |
} |
| 1261 |
|
| 1262 |
/* |
| 1263 |
*---------------------------------------------------------------------- |
| 1264 |
* |
| 1265 |
* ImageChangedProc |
| 1266 |
* |
| 1267 |
* |
| 1268 |
* Results: |
| 1269 |
* None. |
| 1270 |
* |
| 1271 |
*---------------------------------------------------------------------- |
| 1272 |
*/ |
| 1273 |
/* ARGSUSED */ |
| 1274 |
static void |
| 1275 |
ImageChangedProc(clientData, x, y, width, height, imageWidth, imageHeight) |
| 1276 |
ClientData clientData; |
| 1277 |
int x, y, width, height; /* Not used. */ |
| 1278 |
int imageWidth, imageHeight;/* Not used. */ |
| 1279 |
{ |
| 1280 |
Hierbox *hboxPtr = clientData; |
| 1281 |
|
| 1282 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 1283 |
EventuallyRedraw(hboxPtr); |
| 1284 |
} |
| 1285 |
|
| 1286 |
static CachedImage |
| 1287 |
GetCachedImage(hboxPtr, interp, tkwin, name) |
| 1288 |
Hierbox *hboxPtr; |
| 1289 |
Tcl_Interp *interp; |
| 1290 |
Tk_Window tkwin; |
| 1291 |
char *name; |
| 1292 |
{ |
| 1293 |
struct CachedImageStruct *imagePtr; |
| 1294 |
int isNew; |
| 1295 |
Blt_HashEntry *hPtr; |
| 1296 |
|
| 1297 |
hPtr = Blt_CreateHashEntry(&(hboxPtr->imageTable), (char *)name, &isNew); |
| 1298 |
if (isNew) { |
| 1299 |
Tk_Image tkImage; |
| 1300 |
int width, height; |
| 1301 |
|
| 1302 |
tkImage = Tk_GetImage(interp, tkwin, name, ImageChangedProc, hboxPtr); |
| 1303 |
if (tkImage == NULL) { |
| 1304 |
Blt_DeleteHashEntry(&(hboxPtr->imageTable), hPtr); |
| 1305 |
return NULL; |
| 1306 |
} |
| 1307 |
Tk_SizeOfImage(tkImage, &width, &height); |
| 1308 |
imagePtr = Blt_Malloc(sizeof(struct CachedImageStruct)); |
| 1309 |
imagePtr->tkImage = tkImage; |
| 1310 |
imagePtr->hashPtr = hPtr; |
| 1311 |
imagePtr->refCount = 1; |
| 1312 |
imagePtr->width = width, imagePtr->height = height; |
| 1313 |
Blt_SetHashValue(hPtr, imagePtr); |
| 1314 |
} else { |
| 1315 |
imagePtr = (struct CachedImageStruct *)Blt_GetHashValue(hPtr); |
| 1316 |
imagePtr->refCount++; |
| 1317 |
} |
| 1318 |
return imagePtr; |
| 1319 |
} |
| 1320 |
|
| 1321 |
static void |
| 1322 |
FreeCachedImage(hboxPtr, imagePtr) |
| 1323 |
Hierbox *hboxPtr; |
| 1324 |
struct CachedImageStruct *imagePtr; |
| 1325 |
{ |
| 1326 |
imagePtr->refCount--; |
| 1327 |
if (imagePtr->refCount == 0) { |
| 1328 |
Blt_DeleteHashEntry(&(hboxPtr->imageTable), imagePtr->hashPtr); |
| 1329 |
Tk_FreeImage(imagePtr->tkImage); |
| 1330 |
Blt_Free(imagePtr); |
| 1331 |
} |
| 1332 |
} |
| 1333 |
|
| 1334 |
/* |
| 1335 |
*---------------------------------------------------------------------- |
| 1336 |
* |
| 1337 |
* StringToImages -- |
| 1338 |
* |
| 1339 |
* Convert a list of image names into Tk images. |
| 1340 |
* |
| 1341 |
* Results: |
| 1342 |
* If the string is successfully converted, TCL_OK is returned. |
| 1343 |
* Otherwise, TCL_ERROR is returned and an error message is left in |
| 1344 |
* interpreter's result field. |
| 1345 |
* |
| 1346 |
*---------------------------------------------------------------------- |
| 1347 |
*/ |
| 1348 |
static int |
| 1349 |
StringToImages(clientData, interp, tkwin, string, widgRec, offset) |
| 1350 |
ClientData clientData; /* Not used. */ |
| 1351 |
Tcl_Interp *interp; /* Interpreter to send results back to */ |
| 1352 |
Tk_Window tkwin; /* Not used. */ |
| 1353 |
char *string; /* New legend position string */ |
| 1354 |
char *widgRec; /* Widget record */ |
| 1355 |
int offset; /* offset to field in structure */ |
| 1356 |
{ |
| 1357 |
Hierbox *hboxPtr = *(Hierbox **)clientData; |
| 1358 |
CachedImage **imagePtrPtr = (CachedImage **) (widgRec + offset); |
| 1359 |
CachedImage *imageArr; |
| 1360 |
int result; |
| 1361 |
|
| 1362 |
result = TCL_OK; |
| 1363 |
imageArr = NULL; |
| 1364 |
if ((string != NULL) && (*string != '\0')) { |
| 1365 |
int nNames; |
| 1366 |
char **nameArr; |
| 1367 |
|
| 1368 |
if (Tcl_SplitList(interp, string, &nNames, &nameArr) != TCL_OK) { |
| 1369 |
return TCL_ERROR; |
| 1370 |
} |
| 1371 |
if (nNames > 0) { |
| 1372 |
register int i; |
| 1373 |
|
| 1374 |
imageArr = Blt_Malloc(sizeof(CachedImage *) * (nNames + 1)); |
| 1375 |
assert(imageArr); |
| 1376 |
for (i = 0; i < nNames; i++) { |
| 1377 |
imageArr[i] = GetCachedImage(hboxPtr, interp, tkwin, nameArr[i]); |
| 1378 |
if (imageArr[i] == NULL) { |
| 1379 |
result = TCL_ERROR; |
| 1380 |
break; |
| 1381 |
} |
| 1382 |
} |
| 1383 |
Blt_Free(nameArr); |
| 1384 |
imageArr[nNames] = NULL; |
| 1385 |
} |
| 1386 |
} |
| 1387 |
if (*imagePtrPtr != NULL) { |
| 1388 |
register CachedImage *imagePtr; |
| 1389 |
|
| 1390 |
for (imagePtr = *imagePtrPtr; *imagePtr != NULL; imagePtr++) { |
| 1391 |
FreeCachedImage(hboxPtr, *imagePtr); |
| 1392 |
} |
| 1393 |
Blt_Free(*imagePtrPtr); |
| 1394 |
} |
| 1395 |
*imagePtrPtr = imageArr; |
| 1396 |
return result; |
| 1397 |
} |
| 1398 |
|
| 1399 |
/* |
| 1400 |
*---------------------------------------------------------------------- |
| 1401 |
* |
| 1402 |
* ImagesToString -- |
| 1403 |
* |
| 1404 |
* Converts the image into its string representation (its name). |
| 1405 |
* |
| 1406 |
* Results: |
| 1407 |
* The name of the image is returned. |
| 1408 |
* |
| 1409 |
*---------------------------------------------------------------------- |
| 1410 |
*/ |
| 1411 |
/*ARGSUSED*/ |
| 1412 |
static char * |
| 1413 |
ImagesToString(clientData, tkwin, widgRec, offset, freeProcPtr) |
| 1414 |
ClientData clientData; /* Not used. */ |
| 1415 |
Tk_Window tkwin; /* Not used. */ |
| 1416 |
char *widgRec; /* Widget record */ |
| 1417 |
int offset; /* offset of images array in record */ |
| 1418 |
Tcl_FreeProc **freeProcPtr; /* Memory deallocation scheme to use */ |
| 1419 |
{ |
| 1420 |
CachedImage **imagePtrPtr = (CachedImage **) (widgRec + offset); |
| 1421 |
Tcl_DString dString; |
| 1422 |
char *result; |
| 1423 |
|
| 1424 |
Tcl_DStringInit(&dString); |
| 1425 |
if (*imagePtrPtr != NULL) { |
| 1426 |
register CachedImage *imagePtr; |
| 1427 |
|
| 1428 |
for (imagePtr = *imagePtrPtr; *imagePtr != NULL; imagePtr++) { |
| 1429 |
Tcl_DStringAppendElement(&dString, |
| 1430 |
Blt_NameOfImage((*imagePtr)->tkImage)); |
| 1431 |
} |
| 1432 |
} |
| 1433 |
result = Blt_Strdup(Tcl_DStringValue(&dString)); |
| 1434 |
Tcl_DStringFree(&dString); |
| 1435 |
*freeProcPtr = (Tcl_FreeProc *)Blt_Free; |
| 1436 |
return result; |
| 1437 |
} |
| 1438 |
|
| 1439 |
|
| 1440 |
/* |
| 1441 |
*---------------------------------------------------------------------- |
| 1442 |
* |
| 1443 |
* StringToScrollmode -- |
| 1444 |
* |
| 1445 |
* Convert the string reprsenting a scroll mode, to its numeric |
| 1446 |
* form. |
| 1447 |
* |
| 1448 |
* Results: |
| 1449 |
* If the string is successfully converted, TCL_OK is returned. |
| 1450 |
* Otherwise, TCL_ERROR is returned and an error message is left |
| 1451 |
* in interpreter's result field. |
| 1452 |
* |
| 1453 |
*---------------------------------------------------------------------- |
| 1454 |
*/ |
| 1455 |
/*ARGSUSED*/ |
| 1456 |
static int |
| 1457 |
StringToSeparator(clientData, interp, tkwin, string, widgRec, offset) |
| 1458 |
ClientData clientData; /* Not used. */ |
| 1459 |
Tcl_Interp *interp; /* Interpreter to send results back to */ |
| 1460 |
Tk_Window tkwin; /* Not used. */ |
| 1461 |
char *string; /* String representing new value */ |
| 1462 |
char *widgRec; /* Widget record */ |
| 1463 |
int offset; /* offset in structure */ |
| 1464 |
{ |
| 1465 |
char **sepPtr = (char **)(widgRec + offset); |
| 1466 |
|
| 1467 |
if ((*sepPtr != SEPARATOR_LIST) && (*sepPtr != SEPARATOR_NONE)) { |
| 1468 |
Blt_Free(*sepPtr); |
| 1469 |
} |
| 1470 |
if ((string == NULL) || (*string == '\0')) { |
| 1471 |
*sepPtr = SEPARATOR_LIST; |
| 1472 |
} else if (strcmp(string, "none") == 0) { |
| 1473 |
*sepPtr = SEPARATOR_NONE; |
| 1474 |
} else { |
| 1475 |
*sepPtr = Blt_Strdup(string); |
| 1476 |
} |
| 1477 |
return TCL_OK; |
| 1478 |
} |
| 1479 |
|
| 1480 |
/* |
| 1481 |
*---------------------------------------------------------------------- |
| 1482 |
* |
| 1483 |
* SeparatorToString -- |
| 1484 |
* |
| 1485 |
* Results: |
| 1486 |
* The string representation of the separator is returned. |
| 1487 |
* |
| 1488 |
*---------------------------------------------------------------------- |
| 1489 |
*/ |
| 1490 |
/*ARGSUSED*/ |
| 1491 |
static char * |
| 1492 |
SeparatorToString(clientData, tkwin, widgRec, offset, freeProcPtr) |
| 1493 |
ClientData clientData; /* Not used. */ |
| 1494 |
Tk_Window tkwin; /* Not used. */ |
| 1495 |
char *widgRec; /* Widget record */ |
| 1496 |
int offset; /* offset of flags field in record */ |
| 1497 |
Tcl_FreeProc **freeProcPtr; /* Memory deallocation scheme to use */ |
| 1498 |
{ |
| 1499 |
char *separator = *(char **)(widgRec + offset); |
| 1500 |
|
| 1501 |
if (separator == SEPARATOR_NONE) { |
| 1502 |
return ""; |
| 1503 |
} else if (separator == SEPARATOR_LIST) { |
| 1504 |
return "list"; |
| 1505 |
} |
| 1506 |
return separator; |
| 1507 |
} |
| 1508 |
|
| 1509 |
static int |
| 1510 |
ApplyToTree(hboxPtr, rootPtr, proc, flags) |
| 1511 |
Hierbox *hboxPtr; |
| 1512 |
Tree *rootPtr; |
| 1513 |
ApplyProc *proc; |
| 1514 |
unsigned int flags; |
| 1515 |
{ |
| 1516 |
if (flags & APPLY_BEFORE) { |
| 1517 |
if ((*proc) (hboxPtr, rootPtr) != TCL_OK) { |
| 1518 |
return TCL_ERROR; |
| 1519 |
} |
| 1520 |
} |
| 1521 |
if (flags & APPLY_RECURSE) { |
| 1522 |
if (!(flags & APPLY_OPEN_ONLY) || |
| 1523 |
(rootPtr->entryPtr->flags & ENTRY_OPEN)) { |
| 1524 |
Blt_ChainLink *linkPtr, *nextPtr; |
| 1525 |
Tree *treePtr; |
| 1526 |
|
| 1527 |
for (linkPtr = Blt_ChainFirstLink(rootPtr->chainPtr); |
| 1528 |
linkPtr != NULL; linkPtr = nextPtr) { |
| 1529 |
/* Get the next link in the chain before calling |
| 1530 |
* ApplyToTree. This is because ApplyToTree may |
| 1531 |
* delete the node and its link. */ |
| 1532 |
nextPtr = Blt_ChainNextLink(linkPtr); |
| 1533 |
treePtr = Blt_ChainGetValue(linkPtr); |
| 1534 |
if (ApplyToTree(hboxPtr, treePtr, proc, flags) != TCL_OK) { |
| 1535 |
return TCL_ERROR; |
| 1536 |
} |
| 1537 |
} |
| 1538 |
} |
| 1539 |
} |
| 1540 |
if ((flags & APPLY_BEFORE) == 0) { |
| 1541 |
if ((*proc) (hboxPtr, rootPtr) != TCL_OK) { |
| 1542 |
return TCL_ERROR; |
| 1543 |
} |
| 1544 |
} |
| 1545 |
return TCL_OK; |
| 1546 |
} |
| 1547 |
|
| 1548 |
static void |
| 1549 |
ConfigureButtons(hboxPtr) |
| 1550 |
Hierbox *hboxPtr; |
| 1551 |
{ |
| 1552 |
ButtonAttributes *buttonPtr = &(hboxPtr->button); |
| 1553 |
unsigned long gcMask; |
| 1554 |
XGCValues gcValues; |
| 1555 |
GC newGC; |
| 1556 |
|
| 1557 |
gcMask = GCForeground; |
| 1558 |
gcValues.foreground = buttonPtr->fgColor->pixel; |
| 1559 |
newGC = Tk_GetGC(hboxPtr->tkwin, gcMask, &gcValues); |
| 1560 |
if (buttonPtr->normalGC != NULL) { |
| 1561 |
Tk_FreeGC(hboxPtr->display, buttonPtr->normalGC); |
| 1562 |
} |
| 1563 |
buttonPtr->normalGC = newGC; |
| 1564 |
|
| 1565 |
gcMask = (GCForeground | GCLineWidth); |
| 1566 |
gcValues.foreground = hboxPtr->lineColor->pixel; |
| 1567 |
gcValues.line_width = hboxPtr->lineWidth; |
| 1568 |
newGC = Tk_GetGC(hboxPtr->tkwin, gcMask, &gcValues); |
| 1569 |
if (buttonPtr->lineGC != NULL) { |
| 1570 |
Tk_FreeGC(hboxPtr->display, buttonPtr->lineGC); |
| 1571 |
} |
| 1572 |
buttonPtr->lineGC = newGC; |
| 1573 |
|
| 1574 |
gcMask = GCForeground; |
| 1575 |
gcValues.foreground = buttonPtr->activeFgColor->pixel; |
| 1576 |
newGC = Tk_GetGC(hboxPtr->tkwin, gcMask, &gcValues); |
| 1577 |
if (buttonPtr->activeGC != NULL) { |
| 1578 |
Tk_FreeGC(hboxPtr->display, buttonPtr->activeGC); |
| 1579 |
} |
| 1580 |
buttonPtr->activeGC = newGC; |
| 1581 |
|
| 1582 |
buttonPtr->width = buttonPtr->height = ODD(buttonPtr->reqSize); |
| 1583 |
if (buttonPtr->images != NULL) { |
| 1584 |
register int i; |
| 1585 |
|
| 1586 |
for (i = 0; i < 2; i++) { |
| 1587 |
if (buttonPtr->images[i] == NULL) { |
| 1588 |
break; |
| 1589 |
} |
| 1590 |
if (buttonPtr->width < ImageWidth(buttonPtr->images[i])) { |
| 1591 |
buttonPtr->width = ImageWidth(buttonPtr->images[i]); |
| 1592 |
} |
| 1593 |
if (buttonPtr->height < ImageHeight(buttonPtr->images[i])) { |
| 1594 |
buttonPtr->height = ImageHeight(buttonPtr->images[i]); |
| 1595 |
} |
| 1596 |
} |
| 1597 |
} |
| 1598 |
buttonPtr->width += 2 * buttonPtr->borderWidth; |
| 1599 |
buttonPtr->height += 2 * buttonPtr->borderWidth; |
| 1600 |
} |
| 1601 |
|
| 1602 |
static void |
| 1603 |
DestroyEntry(entryPtr) |
| 1604 |
Entry *entryPtr; |
| 1605 |
{ |
| 1606 |
Hierbox *hboxPtr = entryPtr->hboxPtr; |
| 1607 |
register CachedImage *imagePtr; |
| 1608 |
|
| 1609 |
Tk_FreeOptions(entryConfigSpecs, (char *)entryPtr, hboxPtr->display, 0); |
| 1610 |
if (entryPtr->labelGC != NULL) { |
| 1611 |
Tk_FreeGC(hboxPtr->display, entryPtr->labelGC); |
| 1612 |
} |
| 1613 |
if (entryPtr->dataGC != NULL) { |
| 1614 |
Tk_FreeGC(hboxPtr->display, entryPtr->dataGC); |
| 1615 |
} |
| 1616 |
if (entryPtr->hashPtr != NULL) { |
| 1617 |
Blt_DeleteHashEntry(&(hboxPtr->nodeTable), entryPtr->hashPtr); |
| 1618 |
} |
| 1619 |
if (entryPtr->dataShadow.color != NULL) { |
| 1620 |
Tk_FreeColor(entryPtr->dataShadow.color); |
| 1621 |
} |
| 1622 |
if (entryPtr->labelShadow.color != NULL) { |
| 1623 |
Tk_FreeColor(entryPtr->labelShadow.color); |
| 1624 |
} |
| 1625 |
if (entryPtr->iconGC != NULL) { |
| 1626 |
Tk_FreeGC(hboxPtr->display, entryPtr->iconGC); |
| 1627 |
} |
| 1628 |
if (entryPtr->openCmd != NULL) { |
| 1629 |
Blt_FreeUid(entryPtr->openCmd); |
| 1630 |
} |
| 1631 |
if (entryPtr->closeCmd != NULL) { |
| 1632 |
Blt_FreeUid(entryPtr->closeCmd); |
| 1633 |
} |
| 1634 |
if (entryPtr->dataUid != NULL) { |
| 1635 |
Blt_FreeUid(entryPtr->dataUid); |
| 1636 |
} |
| 1637 |
if (entryPtr->dataText != NULL) { |
| 1638 |
Blt_FreeUid(entryPtr->dataText); |
| 1639 |
} |
| 1640 |
if (entryPtr->tags != NULL) { |
| 1641 |
Blt_FreeUid(entryPtr->tags); |
| 1642 |
} |
| 1643 |
if (entryPtr->icons != NULL) { |
| 1644 |
for (imagePtr = entryPtr->icons; *imagePtr != NULL; imagePtr++) { |
| 1645 |
FreeCachedImage(hboxPtr, *imagePtr); |
| 1646 |
} |
| 1647 |
Blt_Free(entryPtr->icons); |
| 1648 |
} |
| 1649 |
if (entryPtr->activeIcons != NULL) { |
| 1650 |
for (imagePtr = entryPtr->activeIcons; *imagePtr != NULL; imagePtr++) { |
| 1651 |
FreeCachedImage(hboxPtr, *imagePtr); |
| 1652 |
} |
| 1653 |
Blt_Free(entryPtr->activeIcons); |
| 1654 |
} |
| 1655 |
if (entryPtr->images != NULL) { |
| 1656 |
for (imagePtr = entryPtr->images; *imagePtr != NULL; imagePtr++) { |
| 1657 |
FreeCachedImage(hboxPtr, *imagePtr); |
| 1658 |
} |
| 1659 |
Blt_Free(entryPtr->images); |
| 1660 |
} |
| 1661 |
Blt_Free(entryPtr); |
| 1662 |
} |
| 1663 |
|
| 1664 |
/*ARGSUSED*/ |
| 1665 |
static Tree * |
| 1666 |
LastNode(treePtr, mask) |
| 1667 |
register Tree *treePtr; |
| 1668 |
unsigned int mask; |
| 1669 |
{ |
| 1670 |
Blt_ChainLink *linkPtr; |
| 1671 |
|
| 1672 |
if (treePtr->parentPtr == NULL) { |
| 1673 |
return NULL; /* The root is the first node. */ |
| 1674 |
} |
| 1675 |
linkPtr = Blt_ChainPrevLink(treePtr->linkPtr); |
| 1676 |
if (linkPtr == NULL) { |
| 1677 |
/* There are no siblings previous to this one, so pick the parent. */ |
| 1678 |
return treePtr->parentPtr; |
| 1679 |
} |
| 1680 |
/* |
| 1681 |
* Traverse down the right-most thread, in order to select the |
| 1682 |
* next entry. Stop if we find a "closed" entry or reach a leaf. |
| 1683 |
*/ |
| 1684 |
treePtr = Blt_ChainGetValue(linkPtr); |
| 1685 |
while ((treePtr->entryPtr->flags & mask) == mask) { |
| 1686 |
linkPtr = Blt_ChainLastLink(treePtr->chainPtr); |
| 1687 |
if (linkPtr == NULL) { |
| 1688 |
break; /* Found a leaf. */ |
| 1689 |
} |
| 1690 |
treePtr = Blt_ChainGetValue(linkPtr); |
| 1691 |
} |
| 1692 |
return treePtr; |
| 1693 |
} |
| 1694 |
|
| 1695 |
|
| 1696 |
static Tree * |
| 1697 |
NextNode(treePtr, mask) |
| 1698 |
Tree *treePtr; |
| 1699 |
unsigned int mask; |
| 1700 |
{ |
| 1701 |
Blt_ChainLink *linkPtr; |
| 1702 |
|
| 1703 |
if ((treePtr->entryPtr->flags & mask) == mask) { |
| 1704 |
/* Pick the first sub-node. */ |
| 1705 |
linkPtr = Blt_ChainFirstLink(treePtr->chainPtr); |
| 1706 |
if (linkPtr != NULL) { |
| 1707 |
return Blt_ChainGetValue(linkPtr); |
| 1708 |
} |
| 1709 |
} |
| 1710 |
/* |
| 1711 |
* Back up until we can find a level where we can pick a "next" entry. |
| 1712 |
* For the last entry we'll thread our way back to the root. |
| 1713 |
*/ |
| 1714 |
while (treePtr->parentPtr != NULL) { |
| 1715 |
linkPtr = Blt_ChainNextLink(treePtr->linkPtr); |
| 1716 |
if (linkPtr != NULL) { |
| 1717 |
return Blt_ChainGetValue(linkPtr); |
| 1718 |
} |
| 1719 |
treePtr = treePtr->parentPtr; |
| 1720 |
} |
| 1721 |
return NULL; /* At root, no next node. */ |
| 1722 |
} |
| 1723 |
|
| 1724 |
/*ARGSUSED*/ |
| 1725 |
static Tree * |
| 1726 |
EndNode(treePtr, mask) |
| 1727 |
Tree *treePtr; |
| 1728 |
unsigned int mask; |
| 1729 |
{ |
| 1730 |
Blt_ChainLink *linkPtr; |
| 1731 |
|
| 1732 |
linkPtr = Blt_ChainLastLink(treePtr->chainPtr); |
| 1733 |
while (linkPtr != NULL) { |
| 1734 |
treePtr = Blt_ChainGetValue(linkPtr); |
| 1735 |
if ((treePtr->entryPtr->flags & mask) != mask) { |
| 1736 |
break; |
| 1737 |
} |
| 1738 |
linkPtr = Blt_ChainLastLink(treePtr->chainPtr); |
| 1739 |
} |
| 1740 |
return treePtr; |
| 1741 |
} |
| 1742 |
|
| 1743 |
static void |
| 1744 |
ExposeAncestors(treePtr) |
| 1745 |
register Tree *treePtr; |
| 1746 |
{ |
| 1747 |
treePtr = treePtr->parentPtr; |
| 1748 |
while (treePtr != NULL) { |
| 1749 |
treePtr->entryPtr->flags |= (ENTRY_OPEN | ENTRY_MAPPED); |
| 1750 |
treePtr = treePtr->parentPtr; |
| 1751 |
} |
| 1752 |
} |
| 1753 |
|
| 1754 |
static int |
| 1755 |
IsBefore(t1Ptr, t2Ptr) |
| 1756 |
register Tree *t1Ptr, *t2Ptr; |
| 1757 |
{ |
| 1758 |
int depth; |
| 1759 |
register int i; |
| 1760 |
Blt_ChainLink *linkPtr; |
| 1761 |
Tree *treePtr; |
| 1762 |
|
| 1763 |
depth = MIN(t1Ptr->level, t2Ptr->level); |
| 1764 |
|
| 1765 |
if (depth == 0) { /* One of the nodes is root. */ |
| 1766 |
if (t1Ptr->parentPtr == NULL) { |
| 1767 |
return 1; |
| 1768 |
} |
| 1769 |
return 0; |
| 1770 |
} |
| 1771 |
/* |
| 1772 |
* Traverse back from the deepest node, until the both nodes are at the |
| 1773 |
* same depth. Check if the ancestor node found is the other node. |
| 1774 |
*/ |
| 1775 |
for (i = t1Ptr->level; i > depth; i--) { |
| 1776 |
t1Ptr = t1Ptr->parentPtr; |
| 1777 |
} |
| 1778 |
if (t1Ptr == t2Ptr) { |
| 1779 |
return 0; |
| 1780 |
} |
| 1781 |
for (i = t2Ptr->level; i > depth; i--) { |
| 1782 |
t2Ptr = t2Ptr->parentPtr; |
| 1783 |
} |
| 1784 |
if (t2Ptr == t1Ptr) { |
| 1785 |
return 1; |
| 1786 |
} |
| 1787 |
/* |
| 1788 |
* First find the mutual ancestor of both nodes. Look at each |
| 1789 |
* preceding ancestor level-by-level for both nodes. Eventually |
| 1790 |
* we'll find a node that's the parent of both ancestors. Then |
| 1791 |
* find the first ancestor in the parent's list of subnodes. |
| 1792 |
*/ |
| 1793 |
for (i = depth; i > 0; i--) { |
| 1794 |
if (t1Ptr->parentPtr == t2Ptr->parentPtr) { |
| 1795 |
break; |
| 1796 |
} |
| 1797 |
t1Ptr = t1Ptr->parentPtr; |
| 1798 |
t2Ptr = t2Ptr->parentPtr; |
| 1799 |
} |
| 1800 |
for (linkPtr = Blt_ChainFirstLink(t1Ptr->parentPtr->chainPtr); linkPtr != NULL; |
| 1801 |
linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 1802 |
treePtr = Blt_ChainGetValue(linkPtr); |
| 1803 |
if (treePtr == t1Ptr) { |
| 1804 |
return 1; |
| 1805 |
} else if (treePtr == t2Ptr) { |
| 1806 |
return 0; |
| 1807 |
} |
| 1808 |
} |
| 1809 |
assert(linkPtr != NULL); |
| 1810 |
return 0; |
| 1811 |
} |
| 1812 |
|
| 1813 |
static int |
| 1814 |
IsAncestor(rootPtr, treePtr) |
| 1815 |
Tree *rootPtr, *treePtr; |
| 1816 |
{ |
| 1817 |
if (treePtr != NULL) { |
| 1818 |
treePtr = treePtr->parentPtr; |
| 1819 |
while (treePtr != NULL) { |
| 1820 |
if (treePtr == rootPtr) { |
| 1821 |
return 1; |
| 1822 |
} |
| 1823 |
treePtr = treePtr->parentPtr; |
| 1824 |
} |
| 1825 |
} |
| 1826 |
return 0; |
| 1827 |
} |
| 1828 |
|
| 1829 |
static int |
| 1830 |
IsHidden(treePtr) |
| 1831 |
register Tree *treePtr; |
| 1832 |
{ |
| 1833 |
if (treePtr != NULL) { |
| 1834 |
unsigned int mask; |
| 1835 |
|
| 1836 |
if (!(treePtr->entryPtr->flags & ENTRY_MAPPED)) { |
| 1837 |
return TRUE; |
| 1838 |
} |
| 1839 |
treePtr = treePtr->parentPtr; |
| 1840 |
mask = (ENTRY_OPEN | ENTRY_MAPPED); |
| 1841 |
while (treePtr != NULL) { |
| 1842 |
if ((treePtr->entryPtr->flags & mask) != mask) { |
| 1843 |
return TRUE; |
| 1844 |
} |
| 1845 |
treePtr = treePtr->parentPtr; |
| 1846 |
} |
| 1847 |
} |
| 1848 |
return FALSE; |
| 1849 |
} |
| 1850 |
|
| 1851 |
static void |
| 1852 |
SelectEntry(hboxPtr, treePtr) |
| 1853 |
Hierbox *hboxPtr; |
| 1854 |
Tree *treePtr; |
| 1855 |
{ |
| 1856 |
int isNew; |
| 1857 |
Blt_HashEntry *hPtr; |
| 1858 |
|
| 1859 |
hPtr = Blt_CreateHashEntry(&(hboxPtr->selectTable), (char *)treePtr, |
| 1860 |
&isNew); |
| 1861 |
if (isNew) { |
| 1862 |
Blt_ChainLink *linkPtr; |
| 1863 |
|
| 1864 |
linkPtr = Blt_ChainAppend(&(hboxPtr->selectChain), treePtr); |
| 1865 |
Blt_SetHashValue(hPtr, linkPtr); |
| 1866 |
} |
| 1867 |
} |
| 1868 |
|
| 1869 |
static void |
| 1870 |
DeselectEntry(hboxPtr, treePtr) |
| 1871 |
Hierbox *hboxPtr; |
| 1872 |
Tree *treePtr; |
| 1873 |
{ |
| 1874 |
Blt_HashEntry *hPtr; |
| 1875 |
|
| 1876 |
hPtr = Blt_FindHashEntry(&(hboxPtr->selectTable), (char *)treePtr); |
| 1877 |
if (hPtr != NULL) { |
| 1878 |
Blt_ChainLink *linkPtr; |
| 1879 |
|
| 1880 |
linkPtr = (Blt_ChainLink *)Blt_GetHashValue(hPtr); |
| 1881 |
Blt_ChainDeleteLink(&(hboxPtr->selectChain), linkPtr); |
| 1882 |
Blt_DeleteHashEntry(&(hboxPtr->selectTable), hPtr); |
| 1883 |
} |
| 1884 |
} |
| 1885 |
|
| 1886 |
static void |
| 1887 |
ClearSelection(hboxPtr) |
| 1888 |
Hierbox *hboxPtr; |
| 1889 |
{ |
| 1890 |
Blt_DeleteHashTable(&(hboxPtr->selectTable)); |
| 1891 |
Blt_InitHashTable(&(hboxPtr->selectTable), BLT_ONE_WORD_KEYS); |
| 1892 |
Blt_ChainReset(&(hboxPtr->selectChain)); |
| 1893 |
EventuallyRedraw(hboxPtr); |
| 1894 |
if (hboxPtr->selectCmd != NULL) { |
| 1895 |
EventuallyInvokeSelectCmd(hboxPtr); |
| 1896 |
} |
| 1897 |
} |
| 1898 |
|
| 1899 |
static void |
| 1900 |
PruneSelection(hboxPtr, rootPtr) |
| 1901 |
Hierbox *hboxPtr; |
| 1902 |
Tree *rootPtr; |
| 1903 |
{ |
| 1904 |
Blt_ChainLink *linkPtr, *nextPtr; |
| 1905 |
Tree *treePtr; |
| 1906 |
int selectionChanged; |
| 1907 |
|
| 1908 |
selectionChanged = FALSE; |
| 1909 |
for (linkPtr = Blt_ChainFirstLink(&(hboxPtr->selectChain)); |
| 1910 |
linkPtr != NULL; linkPtr = nextPtr) { |
| 1911 |
nextPtr = Blt_ChainNextLink(linkPtr); |
| 1912 |
treePtr = Blt_ChainGetValue(linkPtr); |
| 1913 |
if (IsAncestor(rootPtr, treePtr)) { |
| 1914 |
DeselectEntry(hboxPtr, treePtr); |
| 1915 |
selectionChanged = TRUE; |
| 1916 |
} |
| 1917 |
} |
| 1918 |
if (selectionChanged) { |
| 1919 |
EventuallyRedraw(hboxPtr); |
| 1920 |
if (hboxPtr->selectCmd != NULL) { |
| 1921 |
EventuallyInvokeSelectCmd(hboxPtr); |
| 1922 |
} |
| 1923 |
} |
| 1924 |
} |
| 1925 |
|
| 1926 |
static int |
| 1927 |
IsSelected(hboxPtr, treePtr) |
| 1928 |
Hierbox *hboxPtr; |
| 1929 |
Tree *treePtr; |
| 1930 |
{ |
| 1931 |
Blt_HashEntry *hPtr; |
| 1932 |
|
| 1933 |
hPtr = Blt_FindHashEntry(&(hboxPtr->selectTable), (char *)treePtr); |
| 1934 |
return (hPtr != NULL); |
| 1935 |
} |
| 1936 |
|
| 1937 |
|
| 1938 |
static void |
| 1939 |
GetFullPath(treePtr, separator, resultPtr) |
| 1940 |
Tree *treePtr; |
| 1941 |
char *separator; |
| 1942 |
Tcl_DString *resultPtr; |
| 1943 |
{ |
| 1944 |
char **nameArr; /* Used the stack the component names. */ |
| 1945 |
register int i; |
| 1946 |
int level; |
| 1947 |
|
| 1948 |
level = treePtr->level; |
| 1949 |
nameArr = Blt_Malloc((level + 1) * sizeof(char *)); |
| 1950 |
assert(nameArr); |
| 1951 |
for (i = level; i >= 0; i--) { |
| 1952 |
/* Save the name of each ancestor in the name array. */ |
| 1953 |
nameArr[i] = treePtr->nameId; |
| 1954 |
treePtr = treePtr->parentPtr; |
| 1955 |
} |
| 1956 |
Tcl_DStringInit(resultPtr); |
| 1957 |
if ((separator == SEPARATOR_LIST) || (separator == SEPARATOR_NONE)) { |
| 1958 |
for (i = 0; i <= level; i++) { |
| 1959 |
Tcl_DStringAppendElement(resultPtr, nameArr[i]); |
| 1960 |
} |
| 1961 |
} else { |
| 1962 |
Tcl_DStringAppend(resultPtr, nameArr[0], -1); |
| 1963 |
if (strcmp(nameArr[0], separator) != 0) { |
| 1964 |
Tcl_DStringAppend(resultPtr, separator, -1); |
| 1965 |
} |
| 1966 |
if (level > 0) { |
| 1967 |
for (i = 1; i < level; i++) { |
| 1968 |
Tcl_DStringAppend(resultPtr, nameArr[i], -1); |
| 1969 |
Tcl_DStringAppend(resultPtr, separator, -1); |
| 1970 |
} |
| 1971 |
Tcl_DStringAppend(resultPtr, nameArr[i], -1); |
| 1972 |
} |
| 1973 |
} |
| 1974 |
Blt_Free(nameArr); |
| 1975 |
} |
| 1976 |
|
| 1977 |
static void |
| 1978 |
InsertNode(parentPtr, position, nodePtr) |
| 1979 |
Tree *parentPtr; /* Parent node where the new node will |
| 1980 |
* be added. */ |
| 1981 |
int position; /* Position in the parent of the new node. */ |
| 1982 |
Tree *nodePtr; /* The node to be inserted. */ |
| 1983 |
{ |
| 1984 |
Blt_ChainLink *linkPtr; |
| 1985 |
|
| 1986 |
/* |
| 1987 |
* Create lists to contain subnodes as needed. We don't want to |
| 1988 |
* unnecessarily allocate storage for leaves (of which there may |
| 1989 |
* be many). |
| 1990 |
*/ |
| 1991 |
if (parentPtr->chainPtr == NULL) { |
| 1992 |
parentPtr->chainPtr = Blt_ChainCreate(); |
| 1993 |
} |
| 1994 |
linkPtr = Blt_ChainNewLink(); |
| 1995 |
if (position == APPEND) { |
| 1996 |
Blt_ChainAppendLink(parentPtr->chainPtr, linkPtr); |
| 1997 |
} else { |
| 1998 |
Blt_ChainLink *beforePtr; |
| 1999 |
|
| 2000 |
beforePtr = Blt_ChainGetNthLink(parentPtr->chainPtr, position); |
| 2001 |
Blt_ChainLinkBefore(parentPtr->chainPtr, linkPtr, beforePtr); |
| 2002 |
} |
| 2003 |
nodePtr->level = parentPtr->level + 1; |
| 2004 |
nodePtr->parentPtr = parentPtr; |
| 2005 |
nodePtr->linkPtr = linkPtr; |
| 2006 |
Blt_ChainSetValue(linkPtr, nodePtr); |
| 2007 |
} |
| 2008 |
|
| 2009 |
static void |
| 2010 |
DestroyNode(data) |
| 2011 |
DestroyData data; |
| 2012 |
{ |
| 2013 |
Tree *treePtr = (Tree *)data; |
| 2014 |
|
| 2015 |
if (treePtr->nameId != NULL) { |
| 2016 |
Blt_FreeUid(treePtr->nameId); |
| 2017 |
} |
| 2018 |
if (treePtr->chainPtr != NULL) { |
| 2019 |
Blt_ChainDestroy(treePtr->chainPtr); |
| 2020 |
} |
| 2021 |
if (treePtr->entryPtr != NULL) { |
| 2022 |
DestroyEntry(treePtr->entryPtr); |
| 2023 |
} |
| 2024 |
treePtr->entryPtr = NULL; |
| 2025 |
Blt_Free(treePtr); |
| 2026 |
} |
| 2027 |
|
| 2028 |
/* |
| 2029 |
*---------------------------------------------------------------------- |
| 2030 |
* |
| 2031 |
* CreateNode -- |
| 2032 |
* |
| 2033 |
* Creates and inserts a new node into the given tree at the |
| 2034 |
* specified position. |
| 2035 |
* |
| 2036 |
* Results: |
| 2037 |
* Returns a pointer to the newly created node. If an error |
| 2038 |
* occurred, such as the entry could not be configured, NULL |
| 2039 |
* is returned. |
| 2040 |
* |
| 2041 |
*---------------------------------------------------------------------- |
| 2042 |
*/ |
| 2043 |
static Tree * |
| 2044 |
CreateNode(hboxPtr, parentPtr, position, name) |
| 2045 |
Hierbox *hboxPtr; /* Hierarchy widget record */ |
| 2046 |
Tree *parentPtr; /* Pointer to parent node. */ |
| 2047 |
int position; /* Position in node list to insert node. */ |
| 2048 |
char *name; /* Name identifier for the new node. */ |
| 2049 |
{ |
| 2050 |
Entry *entryPtr; |
| 2051 |
Tree *treePtr; |
| 2052 |
Blt_HashEntry *hPtr; |
| 2053 |
int isNew; |
| 2054 |
int serial; |
| 2055 |
|
| 2056 |
/* Create the entry structure */ |
| 2057 |
entryPtr = Blt_Calloc(1, sizeof(Entry)); |
| 2058 |
assert(entryPtr); |
| 2059 |
entryPtr->flags |= (BUTTON_AUTO | ENTRY_MAPPED); |
| 2060 |
entryPtr->hboxPtr = hboxPtr; |
| 2061 |
|
| 2062 |
if (name == NULL) { |
| 2063 |
name = ""; |
| 2064 |
} |
| 2065 |
entryPtr->labelText = Blt_Strdup(name); |
| 2066 |
|
| 2067 |
if (ConfigureEntry(hboxPtr, entryPtr, 0, (CONST char **)NULL, 0) != TCL_OK) { |
| 2068 |
DestroyEntry(entryPtr); |
| 2069 |
return NULL; |
| 2070 |
} |
| 2071 |
/* Create the container structure too */ |
| 2072 |
treePtr = Blt_Calloc(1, sizeof(Tree)); |
| 2073 |
assert(treePtr); |
| 2074 |
treePtr->nameId = Blt_GetUid(name); |
| 2075 |
treePtr->entryPtr = entryPtr; |
| 2076 |
|
| 2077 |
/* Generate a unique node serial number. */ |
| 2078 |
do { |
| 2079 |
serial = hboxPtr->nextSerial++; |
| 2080 |
hPtr = Blt_CreateHashEntry(&(hboxPtr->nodeTable), (char *)serial, |
| 2081 |
&isNew); |
| 2082 |
} while (!isNew); |
| 2083 |
Blt_SetHashValue(hPtr, treePtr); |
| 2084 |
entryPtr->hashPtr = hPtr; |
| 2085 |
|
| 2086 |
if (parentPtr != NULL) { |
| 2087 |
InsertNode(parentPtr, position, treePtr); |
| 2088 |
} |
| 2089 |
return treePtr; |
| 2090 |
} |
| 2091 |
|
| 2092 |
/* |
| 2093 |
*---------------------------------------------------------------------- |
| 2094 |
* |
| 2095 |
* FindComponent -- |
| 2096 |
* |
| 2097 |
* Searches for the given child node. The node is designated |
| 2098 |
* by its node identifier string. |
| 2099 |
* |
| 2100 |
* Results: |
| 2101 |
* If found, returns a node pointer. Otherwise NULL. |
| 2102 |
* |
| 2103 |
*---------------------------------------------------------------------- |
| 2104 |
*/ |
| 2105 |
static Tree * |
| 2106 |
FindComponent(parentPtr, name) |
| 2107 |
Tree *parentPtr; |
| 2108 |
char *name; |
| 2109 |
{ |
| 2110 |
Blt_Uid nameId; |
| 2111 |
|
| 2112 |
nameId = Blt_FindUid(name); |
| 2113 |
if (nameId != NULL) { |
| 2114 |
register Tree *treePtr; |
| 2115 |
Blt_ChainLink *linkPtr; |
| 2116 |
|
| 2117 |
/* The component identifier must already exist if the node exists. */ |
| 2118 |
for (linkPtr = Blt_ChainFirstLink(parentPtr->chainPtr); linkPtr != NULL; |
| 2119 |
linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 2120 |
treePtr = Blt_ChainGetValue(linkPtr); |
| 2121 |
if (nameId == treePtr->nameId) { |
| 2122 |
return treePtr; |
| 2123 |
} |
| 2124 |
} |
| 2125 |
} |
| 2126 |
return NULL; |
| 2127 |
} |
| 2128 |
|
| 2129 |
/* |
| 2130 |
*---------------------------------------------------------------------- |
| 2131 |
* |
| 2132 |
* SkipSeparators -- |
| 2133 |
* |
| 2134 |
* Moves the character pointer past one of more separators. |
| 2135 |
* |
| 2136 |
* Results: |
| 2137 |
* Returns the updates character pointer. |
| 2138 |
* |
| 2139 |
*---------------------------------------------------------------------- |
| 2140 |
*/ |
| 2141 |
static char * |
| 2142 |
SkipSeparators(path, separator, length) |
| 2143 |
char *path, *separator; |
| 2144 |
int length; |
| 2145 |
{ |
| 2146 |
while ((*path == separator[0]) && (strncmp(path, separator, length) == 0)) { |
| 2147 |
path += length; |
| 2148 |
} |
| 2149 |
return path; |
| 2150 |
} |
| 2151 |
|
| 2152 |
/* |
| 2153 |
*---------------------------------------------------------------------- |
| 2154 |
* |
| 2155 |
* SplitPath -- |
| 2156 |
* |
| 2157 |
* Returns the trailing component of the given path. Trailing |
| 2158 |
* separators are ignored. |
| 2159 |
* |
| 2160 |
* Results: |
| 2161 |
* Returns the string of the tail component. |
| 2162 |
* |
| 2163 |
*---------------------------------------------------------------------- |
| 2164 |
*/ |
| 2165 |
static int |
| 2166 |
SplitPath(hboxPtr, path, levelPtr, compPtrPtr) |
| 2167 |
Hierbox *hboxPtr; |
| 2168 |
char *path; |
| 2169 |
int *levelPtr; |
| 2170 |
char ***compPtrPtr; |
| 2171 |
{ |
| 2172 |
int skipLen, pathLen; |
| 2173 |
char *sep; |
| 2174 |
int level, listSize; |
| 2175 |
char **components; |
| 2176 |
register char *p; |
| 2177 |
|
| 2178 |
skipLen = strlen(hboxPtr->separator); |
| 2179 |
path = SkipSeparators(path, hboxPtr->separator, skipLen); |
| 2180 |
pathLen = strlen(path); |
| 2181 |
|
| 2182 |
level = pathLen / skipLen; |
| 2183 |
listSize = (level + 1) * sizeof(char *); |
| 2184 |
components = Blt_Malloc(listSize + (pathLen + 1)); |
| 2185 |
assert(components); |
| 2186 |
p = (char *)components + listSize; |
| 2187 |
strcpy(p, path); |
| 2188 |
|
| 2189 |
sep = strstr(p, hboxPtr->separator); |
| 2190 |
level = 0; |
| 2191 |
while ((*p != '\0') && (sep != NULL)) { |
| 2192 |
*sep = '\0'; |
| 2193 |
components[level++] = p; |
| 2194 |
p = SkipSeparators(sep + skipLen, hboxPtr->separator, skipLen); |
| 2195 |
sep = strstr(p, hboxPtr->separator); |
| 2196 |
} |
| 2197 |
if (*p != '\0') { |
| 2198 |
components[level++] = p; |
| 2199 |
} |
| 2200 |
components[level] = NULL; |
| 2201 |
*levelPtr = level; |
| 2202 |
*compPtrPtr = components; |
| 2203 |
return TCL_OK; |
| 2204 |
} |
| 2205 |
|
| 2206 |
/* |
| 2207 |
*---------------------------------------------------------------------- |
| 2208 |
* |
| 2209 |
* FindPath -- |
| 2210 |
* |
| 2211 |
* Finds the node designated by the given path. Each path |
| 2212 |
* component is searched for as the tree is traversed. |
| 2213 |
* |
| 2214 |
* A leading character string is trimmed off the path if it |
| 2215 |
* matches the one designated (see the -trimleft option). |
| 2216 |
* |
| 2217 |
* If no separator is designated (see the -separator |
| 2218 |
* configuration option), the path is considered a Tcl list. |
| 2219 |
* Otherwise the each component of the path is separated by a |
| 2220 |
* character string. Leading and trailing separators are |
| 2221 |
* ignored. Multiple separators are treated as one. |
| 2222 |
* |
| 2223 |
* Results: |
| 2224 |
* Returns the pointer to the designated node. If any component |
| 2225 |
* can't be found, NULL is returned. |
| 2226 |
* |
| 2227 |
*---------------------------------------------------------------------- |
| 2228 |
*/ |
| 2229 |
static Tree * |
| 2230 |
FindPath(hboxPtr, rootPtr, path) |
| 2231 |
Hierbox *hboxPtr; |
| 2232 |
Tree *rootPtr; |
| 2233 |
char *path; |
| 2234 |
{ |
| 2235 |
register char *p; |
| 2236 |
int skip; |
| 2237 |
char *sep; |
| 2238 |
Tree *treePtr; |
| 2239 |
char save; |
| 2240 |
|
| 2241 |
/* Trim off characters that we don't want */ |
| 2242 |
if (hboxPtr->trimLeft != NULL) { |
| 2243 |
register char *s; |
| 2244 |
|
| 2245 |
/* Trim off leading character string if one exists. */ |
| 2246 |
for (p = path, s = hboxPtr->trimLeft; *s != '\0'; s++, p++) { |
| 2247 |
if (*p != *s) { |
| 2248 |
break; |
| 2249 |
} |
| 2250 |
} |
| 2251 |
if (*s == '\0') { |
| 2252 |
path = p; |
| 2253 |
} |
| 2254 |
} |
| 2255 |
if (*path == '\0') { |
| 2256 |
return rootPtr; |
| 2257 |
} |
| 2258 |
if (hboxPtr->separator == SEPARATOR_NONE) { |
| 2259 |
return FindComponent(rootPtr, path); |
| 2260 |
} |
| 2261 |
if (hboxPtr->separator == SEPARATOR_LIST) { |
| 2262 |
char **nameArr; |
| 2263 |
int nComp; |
| 2264 |
register int i; |
| 2265 |
|
| 2266 |
/* |
| 2267 |
* No separator, so this must be a Tcl list of components. |
| 2268 |
*/ |
| 2269 |
if (Tcl_SplitList(hboxPtr->interp, path, &nComp, &nameArr) |
| 2270 |
!= TCL_OK) { |
| 2271 |
return NULL; |
| 2272 |
} |
| 2273 |
for (i = 0; i < nComp; i++) { |
| 2274 |
treePtr = FindComponent(rootPtr, nameArr[i]); |
| 2275 |
if (treePtr == NULL) { |
| 2276 |
Blt_Free(nameArr); |
| 2277 |
return NULL; |
| 2278 |
} |
| 2279 |
rootPtr = treePtr; |
| 2280 |
} |
| 2281 |
Blt_Free(nameArr); |
| 2282 |
return rootPtr; |
| 2283 |
} |
| 2284 |
skip = strlen(hboxPtr->separator); |
| 2285 |
path = SkipSeparators(path, hboxPtr->separator, skip); |
| 2286 |
sep = strstr(path, hboxPtr->separator); |
| 2287 |
p = path; |
| 2288 |
treePtr = rootPtr; |
| 2289 |
while ((*p != '\0') && (sep != NULL)) { |
| 2290 |
save = *sep, *sep = '\0'; |
| 2291 |
treePtr = FindComponent(treePtr, p); |
| 2292 |
*sep = save; |
| 2293 |
if (treePtr == NULL) { |
| 2294 |
return NULL; /* Bad component name. */ |
| 2295 |
} |
| 2296 |
p = SkipSeparators(sep + skip, hboxPtr->separator, skip); |
| 2297 |
sep = strstr(p, hboxPtr->separator); |
| 2298 |
} |
| 2299 |
if (*p != '\0') { |
| 2300 |
treePtr = FindComponent(treePtr, p); |
| 2301 |
if (treePtr == NULL) { |
| 2302 |
return NULL; |
| 2303 |
} |
| 2304 |
} |
| 2305 |
return treePtr; |
| 2306 |
} |
| 2307 |
|
| 2308 |
/* |
| 2309 |
*---------------------------------------------------------------------- |
| 2310 |
* |
| 2311 |
* NearestNode -- |
| 2312 |
* |
| 2313 |
* Finds the entry closest to the given screen X-Y coordinates |
| 2314 |
* in the viewport. |
| 2315 |
* |
| 2316 |
* Results: |
| 2317 |
* Returns the pointer to the closest node. If no node is |
| 2318 |
* visible (nodes may be hidden), NULL is returned. |
| 2319 |
* |
| 2320 |
*---------------------------------------------------------------------- |
| 2321 |
*/ |
| 2322 |
/*ARGSUSED*/ |
| 2323 |
static Tree * |
| 2324 |
NearestNode(hboxPtr, x, y, selectOne) |
| 2325 |
Hierbox *hboxPtr; |
| 2326 |
int x, y; |
| 2327 |
int selectOne; |
| 2328 |
{ |
| 2329 |
register Tree *lastPtr, **treePtrPtr; |
| 2330 |
register Entry *entryPtr; |
| 2331 |
|
| 2332 |
/* |
| 2333 |
* We implicitly can pick only visible entries. So make sure that |
| 2334 |
* the tree exists. |
| 2335 |
*/ |
| 2336 |
if (hboxPtr->nVisible == 0) { |
| 2337 |
return NULL; |
| 2338 |
} |
| 2339 |
/* |
| 2340 |
* Since the entry positions were previously computed in world |
| 2341 |
* coordinates, convert Y-coordinate from screen to world |
| 2342 |
* coordinates too. |
| 2343 |
*/ |
| 2344 |
y = WORLDY(hboxPtr, y); |
| 2345 |
treePtrPtr = hboxPtr->visibleArr; |
| 2346 |
lastPtr = *treePtrPtr; |
| 2347 |
for ( /* empty */ ; *treePtrPtr != NULL; treePtrPtr++) { |
| 2348 |
entryPtr = (*treePtrPtr)->entryPtr; |
| 2349 |
/* |
| 2350 |
* If the start of the next entry starts beyond the point, |
| 2351 |
* use the last entry. |
| 2352 |
*/ |
| 2353 |
if (entryPtr->worldY > y) { |
| 2354 |
return (selectOne) ? lastPtr : NULL; |
| 2355 |
} |
| 2356 |
if (y < (entryPtr->worldY + entryPtr->height)) { |
| 2357 |
return *treePtrPtr; /* Found it. */ |
| 2358 |
} |
| 2359 |
lastPtr = *treePtrPtr; |
| 2360 |
} |
| 2361 |
return (selectOne) ? lastPtr : NULL; |
| 2362 |
} |
| 2363 |
|
| 2364 |
static Tree * |
| 2365 |
GetNodeByIndex(hboxPtr, string) |
| 2366 |
Hierbox *hboxPtr; |
| 2367 |
char *string; |
| 2368 |
{ |
| 2369 |
if (isdigit(UCHAR(string[0]))) { |
| 2370 |
int serial; |
| 2371 |
|
| 2372 |
if (Tcl_GetInt(NULL, string, &serial) == TCL_OK) { |
| 2373 |
Blt_HashEntry *hPtr; |
| 2374 |
|
| 2375 |
hPtr = Blt_FindHashEntry(&(hboxPtr->nodeTable), (char *)serial); |
| 2376 |
if (hPtr != NULL) { |
| 2377 |
return (Tree *) Blt_GetHashValue(hPtr); |
| 2378 |
} |
| 2379 |
} |
| 2380 |
} |
| 2381 |
return NULL; |
| 2382 |
} |
| 2383 |
|
| 2384 |
/* |
| 2385 |
*---------------------------------------------------------------------- |
| 2386 |
* |
| 2387 |
* NodeToString -- |
| 2388 |
* |
| 2389 |
* Converts a node pointer in its string representation. The |
| 2390 |
* string is the node's identifier number. |
| 2391 |
* |
| 2392 |
* Results: |
| 2393 |
* The string representation of the node is returned. Note that |
| 2394 |
* the string is stored statically, so that callers must save the |
| 2395 |
* string before the next call to this routine overwrites the |
| 2396 |
* static array again. |
| 2397 |
* |
| 2398 |
*---------------------------------------------------------------------- |
| 2399 |
*/ |
| 2400 |
static char * |
| 2401 |
NodeToString(hboxPtr, nodePtr) |
| 2402 |
Hierbox *hboxPtr; |
| 2403 |
Tree *nodePtr; |
| 2404 |
{ |
| 2405 |
static char string[200]; |
| 2406 |
int serial; |
| 2407 |
|
| 2408 |
/* Node table keys are integers. Convert them to strings. */ |
| 2409 |
serial = (int)Blt_GetHashKey(&(hboxPtr->nodeTable), |
| 2410 |
nodePtr->entryPtr->hashPtr); |
| 2411 |
sprintf(string, "%d", serial); |
| 2412 |
|
| 2413 |
return string; |
| 2414 |
} |
| 2415 |
|
| 2416 |
/* |
| 2417 |
*---------------------------------------------------------------------- |
| 2418 |
* |
| 2419 |
* GetNode -- |
| 2420 |
* |
| 2421 |
* Converts a string into node pointer. The string may be in one |
| 2422 |
* of the following forms: |
| 2423 |
* |
| 2424 |
* @x,y - Closest node to the specified X-Y position. |
| 2425 |
* NNN - inode. |
| 2426 |
* "active" - Currently active node. |
| 2427 |
* "anchor" - anchor of selected region. |
| 2428 |
* "mark" - mark of selected region. |
| 2429 |
* "current" - Currently picked node in bindtable. |
| 2430 |
* "focus" - The node currently with focus. |
| 2431 |
* "root" - Root node. |
| 2432 |
* "end" - Last open node in the entire hierarchy. |
| 2433 |
* "next" - Next open node from the currently active |
| 2434 |
* node. Wraps around back to top. |
| 2435 |
* "last" - Previous open node from the currently active |
| 2436 |
* node. Wraps around back to bottom. |
| 2437 |
* "up" - Next open node from the currently active |
| 2438 |
* node. Does not wrap around. |
| 2439 |
* "down" - Previous open node from the currently active |
| 2440 |
* node. Does not wrap around. |
| 2441 |
* "nextsibling" - Next sibling of the current node. |
| 2442 |
* "prevsibling" - Previous sibling of the current node. |
| 2443 |
* "parent" - Parent of the current node. |
| 2444 |
* "view.top" - Top of viewport. |
| 2445 |
* "view.bottom" - Bottom of viewport. |
| 2446 |
* @path - Absolute path to a node. |
| 2447 |
* |
| 2448 |
* Results: |
| 2449 |
* If the string is successfully converted, TCL_OK is returned. |
| 2450 |
* The pointer to the node is returned via treePtrPtr. |
| 2451 |
* Otherwise, TCL_ERROR is returned and an error message is left |
| 2452 |
* in interpreter's result field. |
| 2453 |
* |
| 2454 |
*---------------------------------------------------------------------- |
| 2455 |
*/ |
| 2456 |
|
| 2457 |
static int |
| 2458 |
GetNode(hboxPtr, string, treePtrPtr) |
| 2459 |
Hierbox *hboxPtr; |
| 2460 |
char *string; |
| 2461 |
Tree **treePtrPtr; |
| 2462 |
{ |
| 2463 |
Tree *nodePtr; |
| 2464 |
char c; |
| 2465 |
Tree *fromPtr; |
| 2466 |
|
| 2467 |
c = string[0]; |
| 2468 |
fromPtr = *treePtrPtr; |
| 2469 |
nodePtr = NULL; |
| 2470 |
if (isdigit(UCHAR(string[0]))) { |
| 2471 |
nodePtr = GetNodeByIndex(hboxPtr, string); |
| 2472 |
} else if ((c == 'e') && (strcmp(string, "end") == 0)) { |
| 2473 |
nodePtr = EndNode(hboxPtr->rootPtr, ENTRY_OPEN | ENTRY_MAPPED); |
| 2474 |
} else if ((c == 'a') && (strcmp(string, "anchor") == 0)) { |
| 2475 |
nodePtr = hboxPtr->selAnchorPtr; |
| 2476 |
} else if ((c == 'f') && (strcmp(string, "focus") == 0)) { |
| 2477 |
nodePtr = hboxPtr->focusPtr; |
| 2478 |
} else if ((c == 'r') && (strcmp(string, "root") == 0)) { |
| 2479 |
nodePtr = hboxPtr->rootPtr; |
| 2480 |
} else if ((c == 'p') && (strcmp(string, "parent") == 0)) { |
| 2481 |
nodePtr = fromPtr; |
| 2482 |
if (nodePtr->parentPtr != NULL) { |
| 2483 |
nodePtr = nodePtr->parentPtr; |
| 2484 |
} |
| 2485 |
} else if ((c == 'c') && (strcmp(string, "current") == 0)) { |
| 2486 |
/* Can't trust picked item, if entries have been added or deleted. */ |
| 2487 |
if (!(hboxPtr->flags & HIERBOX_DIRTY)) { |
| 2488 |
nodePtr = (Tree *) Blt_GetCurrentItem(hboxPtr->bindTable); |
| 2489 |
if (nodePtr == NULL) { |
| 2490 |
nodePtr = (Tree *)Blt_GetCurrentItem(hboxPtr->buttonBindTable); |
| 2491 |
} |
| 2492 |
} |
| 2493 |
} else if ((c == 'u') && (strcmp(string, "up") == 0)) { |
| 2494 |
nodePtr = LastNode(fromPtr, ENTRY_OPEN | ENTRY_MAPPED); |
| 2495 |
if (nodePtr == NULL) { |
| 2496 |
nodePtr = fromPtr; |
| 2497 |
} |
| 2498 |
if ((nodePtr == hboxPtr->rootPtr) && (hboxPtr->hideRoot)) { |
| 2499 |
nodePtr = NextNode(hboxPtr->rootPtr, ENTRY_OPEN | ENTRY_MAPPED); |
| 2500 |
} |
| 2501 |
} else if ((c == 'd') && (strcmp(string, "down") == 0)) { |
| 2502 |
nodePtr = NextNode(fromPtr, ENTRY_OPEN | ENTRY_MAPPED); |
| 2503 |
if (nodePtr == NULL) { |
| 2504 |
nodePtr = fromPtr; |
| 2505 |
} |
| 2506 |
if ((nodePtr == hboxPtr->rootPtr) && (hboxPtr->hideRoot)) { |
| 2507 |
nodePtr = NextNode(hboxPtr->rootPtr, ENTRY_OPEN | ENTRY_MAPPED); |
| 2508 |
} |
| 2509 |
} else if (((c == 'l') && (strcmp(string, "last") == 0)) || |
| 2510 |
((c == 'p') && (strcmp(string, "prev") == 0))) { |
| 2511 |
nodePtr = LastNode(fromPtr, ENTRY_OPEN | ENTRY_MAPPED); |
| 2512 |
if (nodePtr == NULL) { |
| 2513 |
nodePtr = EndNode(hboxPtr->rootPtr, ENTRY_OPEN | ENTRY_MAPPED); |
| 2514 |
} |
| 2515 |
if ((nodePtr == hboxPtr->rootPtr) && (hboxPtr->hideRoot)) { |
| 2516 |
nodePtr = NextNode(hboxPtr->rootPtr, ENTRY_OPEN | ENTRY_MAPPED); |
| 2517 |
} |
| 2518 |
} else if ((c == 'n') && (strcmp(string, "next") == 0)) { |
| 2519 |
nodePtr = NextNode(fromPtr, ENTRY_OPEN | ENTRY_MAPPED); |
| 2520 |
if (nodePtr == NULL) { |
| 2521 |
if (hboxPtr->hideRoot) { |
| 2522 |
nodePtr = NextNode(hboxPtr->rootPtr, ENTRY_OPEN | ENTRY_MAPPED); |
| 2523 |
} else { |
| 2524 |
nodePtr = hboxPtr->rootPtr; |
| 2525 |
} |
| 2526 |
} |
| 2527 |
} else if ((c == 'n') && (strcmp(string, "nextsibling") == 0)) { |
| 2528 |
if (fromPtr->linkPtr != NULL) { |
| 2529 |
Blt_ChainLink *linkPtr; |
| 2530 |
|
| 2531 |
linkPtr = Blt_ChainNextLink(fromPtr->linkPtr); |
| 2532 |
if (linkPtr != NULL) { |
| 2533 |
nodePtr = Blt_ChainGetValue(linkPtr); |
| 2534 |
} |
| 2535 |
} |
| 2536 |
} else if ((c == 'p') && (strcmp(string, "prevsibling") == 0)) { |
| 2537 |
if (fromPtr->linkPtr != NULL) { |
| 2538 |
Blt_ChainLink *linkPtr; |
| 2539 |
|
| 2540 |
linkPtr = Blt_ChainPrevLink(fromPtr->linkPtr); |
| 2541 |
if (linkPtr != NULL) { |
| 2542 |
nodePtr = Blt_ChainGetValue(linkPtr); |
| 2543 |
} |
| 2544 |
} |
| 2545 |
} else if ((c == 'v') && (strcmp(string, "view.top") == 0)) { |
| 2546 |
if (hboxPtr->nVisible > 0) { |
| 2547 |
nodePtr = hboxPtr->visibleArr[0]; |
| 2548 |
} |
| 2549 |
} else if ((c == 'v') && (strcmp(string, "view.bottom") == 0)) { |
| 2550 |
if (hboxPtr->nVisible > 0) { |
| 2551 |
nodePtr = hboxPtr->visibleArr[hboxPtr->nVisible - 1]; |
| 2552 |
} |
| 2553 |
} else if (c == '@') { |
| 2554 |
int x, y; |
| 2555 |
|
| 2556 |
if (Blt_GetXY(hboxPtr->interp, hboxPtr->tkwin, string, &x, &y) |
| 2557 |
== TCL_OK) { |
| 2558 |
nodePtr = NearestNode(hboxPtr, x, y, TRUE); |
| 2559 |
} else { |
| 2560 |
nodePtr = FindPath(hboxPtr, hboxPtr->rootPtr, string + 1); |
| 2561 |
} |
| 2562 |
if (nodePtr == NULL) { |
| 2563 |
Tcl_ResetResult(hboxPtr->interp); |
| 2564 |
Tcl_AppendResult(hboxPtr->interp, "can't find node entry \"", string, |
| 2565 |
"\" in \"", Tk_PathName(hboxPtr->tkwin), "\"", (char *)NULL); |
| 2566 |
return TCL_ERROR; |
| 2567 |
} |
| 2568 |
} else { |
| 2569 |
nodePtr = FindPath(hboxPtr, hboxPtr->rootPtr, string); |
| 2570 |
if (nodePtr == NULL) { |
| 2571 |
Tcl_ResetResult(hboxPtr->interp); |
| 2572 |
Tcl_AppendResult(hboxPtr->interp, "can't find node entry \"", |
| 2573 |
string, "\" in \"", Tk_PathName(hboxPtr->tkwin), "\"", |
| 2574 |
(char *)NULL); |
| 2575 |
return TCL_ERROR; |
| 2576 |
} |
| 2577 |
} |
| 2578 |
*treePtrPtr = nodePtr; |
| 2579 |
return TCL_OK; |
| 2580 |
} |
| 2581 |
|
| 2582 |
/* |
| 2583 |
*---------------------------------------------------------------------- |
| 2584 |
* |
| 2585 |
* StringToNode -- |
| 2586 |
* |
| 2587 |
* Like GetNode but also finds nodes by serial number. |
| 2588 |
* If the string starts with a digit, it's converted into a |
| 2589 |
* number and then looked-up in a hash table. This means that |
| 2590 |
* serial identifiers take precedence over node names with |
| 2591 |
* the contain only numbers. |
| 2592 |
* |
| 2593 |
* Results: |
| 2594 |
* If the string is successfully converted, TCL_OK is returned. |
| 2595 |
* The pointer to the node is returned via treePtrPtr. |
| 2596 |
* Otherwise, TCL_ERROR is returned and an error message is left |
| 2597 |
* in interpreter's result field. |
| 2598 |
* |
| 2599 |
*---------------------------------------------------------------------- |
| 2600 |
*/ |
| 2601 |
|
| 2602 |
static int |
| 2603 |
StringToNode(hboxPtr, string, treePtrPtr) |
| 2604 |
Hierbox *hboxPtr; |
| 2605 |
char *string; |
| 2606 |
Tree **treePtrPtr; |
| 2607 |
{ |
| 2608 |
*treePtrPtr = hboxPtr->focusPtr; |
| 2609 |
if (GetNode(hboxPtr, string, treePtrPtr) != TCL_OK) { |
| 2610 |
return TCL_ERROR; |
| 2611 |
} |
| 2612 |
if (*treePtrPtr == NULL) { |
| 2613 |
Tcl_ResetResult(hboxPtr->interp); |
| 2614 |
Tcl_AppendResult(hboxPtr->interp, "can't find node entry \"", string, |
| 2615 |
"\" in \"", Tk_PathName(hboxPtr->tkwin), "\"", (char *)NULL); |
| 2616 |
return TCL_ERROR; |
| 2617 |
} |
| 2618 |
return TCL_OK; |
| 2619 |
} |
| 2620 |
|
| 2621 |
/* |
| 2622 |
* Preprocess the command string for percent substitution. |
| 2623 |
*/ |
| 2624 |
static void |
| 2625 |
PercentSubst(hboxPtr, treePtr, command, resultPtr) |
| 2626 |
Hierbox *hboxPtr; |
| 2627 |
Tree *treePtr; |
| 2628 |
char *command; |
| 2629 |
Tcl_DString *resultPtr; |
| 2630 |
{ |
| 2631 |
Tcl_DString dString; |
| 2632 |
register char *last, *p; |
| 2633 |
|
| 2634 |
/* |
| 2635 |
* Get the full path name of the node, in case we need to |
| 2636 |
* substitute for it. |
| 2637 |
*/ |
| 2638 |
GetFullPath(treePtr, hboxPtr->separator, &dString); |
| 2639 |
Tcl_DStringInit(resultPtr); |
| 2640 |
for (last = p = command; *p != '\0'; p++) { |
| 2641 |
if (*p == '%') { |
| 2642 |
char *string; |
| 2643 |
char buf[3]; |
| 2644 |
|
| 2645 |
if (p > last) { |
| 2646 |
*p = '\0'; |
| 2647 |
Tcl_DStringAppend(resultPtr, last, -1); |
| 2648 |
*p = '%'; |
| 2649 |
} |
| 2650 |
switch (*(p + 1)) { |
| 2651 |
case '%': /* Percent sign */ |
| 2652 |
string = "%"; |
| 2653 |
break; |
| 2654 |
case 'W': /* Widget name */ |
| 2655 |
string = Tk_PathName(hboxPtr->tkwin); |
| 2656 |
break; |
| 2657 |
case 'P': /* Full pathname */ |
| 2658 |
string = Tcl_DStringValue(&dString); |
| 2659 |
break; |
| 2660 |
case 'p': /* Name of the node */ |
| 2661 |
string = treePtr->nameId; |
| 2662 |
break; |
| 2663 |
case 'n': /* Node identifier */ |
| 2664 |
string = NodeToString(hboxPtr, treePtr); |
| 2665 |
break; |
| 2666 |
default: |
| 2667 |
if (*(p + 1) == '\0') { |
| 2668 |
p--; |
| 2669 |
} |
| 2670 |
buf[0] = *p, buf[1] = *(p + 1), buf[2] = '\0'; |
| 2671 |
string = buf; |
| 2672 |
break; |
| 2673 |
} |
| 2674 |
Tcl_DStringAppend(resultPtr, string, -1); |
| 2675 |
p++; |
| 2676 |
last = p + 1; |
| 2677 |
} |
| 2678 |
} |
| 2679 |
if (p > last) { |
| 2680 |
*p = '\0'; |
| 2681 |
Tcl_DStringAppend(resultPtr, last, -1); |
| 2682 |
} |
| 2683 |
Tcl_DStringFree(&dString); |
| 2684 |
} |
| 2685 |
|
| 2686 |
/* |
| 2687 |
*---------------------------------------------------------------------- |
| 2688 |
* |
| 2689 |
* CloseNode -- |
| 2690 |
* |
| 2691 |
* Closes the node. If a close Tcl command is specified (see the |
| 2692 |
* "-close" option), it's invoked after the node is closed. |
| 2693 |
* |
| 2694 |
* Results: |
| 2695 |
* If an error occurred when executing the Tcl proc, TCL_ERROR is |
| 2696 |
* returned. Otherwise TCL_OK is returned. |
| 2697 |
* |
| 2698 |
*---------------------------------------------------------------------- |
| 2699 |
*/ |
| 2700 |
static int |
| 2701 |
CloseNode(hboxPtr, treePtr) |
| 2702 |
Hierbox *hboxPtr; |
| 2703 |
Tree *treePtr; |
| 2704 |
{ |
| 2705 |
Entry *entryPtr = treePtr->entryPtr; |
| 2706 |
char *command; |
| 2707 |
int result; |
| 2708 |
|
| 2709 |
/* |
| 2710 |
* The tricky part here is that the "close" command can delete |
| 2711 |
* this node. So we'll preserve it until after we mark it closed. |
| 2712 |
*/ |
| 2713 |
Tcl_Preserve(treePtr); |
| 2714 |
|
| 2715 |
/* |
| 2716 |
* Invoke the entry's "close" command, if there is one. Otherwise |
| 2717 |
* try the hierbox's global "close" command. |
| 2718 |
*/ |
| 2719 |
command = (entryPtr->closeCmd != NULL) ? entryPtr->closeCmd : |
| 2720 |
hboxPtr->closeCmd; |
| 2721 |
result = TCL_OK; |
| 2722 |
if ((entryPtr->flags & ENTRY_OPEN) && (command != NULL)) { |
| 2723 |
Tcl_DString cmdString; |
| 2724 |
|
| 2725 |
PercentSubst(hboxPtr, treePtr, command, &cmdString); |
| 2726 |
result = Tcl_GlobalEval(hboxPtr->interp, Tcl_DStringValue(&cmdString)); |
| 2727 |
Tcl_DStringFree(&cmdString); |
| 2728 |
} |
| 2729 |
/* |
| 2730 |
* Mark the entry closed, only after the Tcl proc callback. |
| 2731 |
*/ |
| 2732 |
entryPtr->flags &= ~ENTRY_OPEN; |
| 2733 |
|
| 2734 |
Tcl_Release(treePtr); |
| 2735 |
return result; |
| 2736 |
} |
| 2737 |
|
| 2738 |
/* |
| 2739 |
*---------------------------------------------------------------------- |
| 2740 |
* |
| 2741 |
* OpenNode -- |
| 2742 |
* |
| 2743 |
* Opens the node. If an open Tcl command is specified (see the |
| 2744 |
* "-open" option), it's invoked after the node is opened. |
| 2745 |
* |
| 2746 |
* Results: |
| 2747 |
* If an error occurred when executing the Tcl proc, TCL_ERROR is |
| 2748 |
* returned. Otherwise TCL_OK is returned. |
| 2749 |
* |
| 2750 |
*---------------------------------------------------------------------- |
| 2751 |
*/ |
| 2752 |
static int |
| 2753 |
OpenNode(hboxPtr, treePtr) |
| 2754 |
Hierbox *hboxPtr; |
| 2755 |
Tree *treePtr; |
| 2756 |
{ |
| 2757 |
Entry *entryPtr = treePtr->entryPtr; |
| 2758 |
char *string; |
| 2759 |
int result; |
| 2760 |
|
| 2761 |
/* |
| 2762 |
* The tricky part here is that the "open" command can delete |
| 2763 |
* this node. So we'll preserve it until after we mark it closed. |
| 2764 |
*/ |
| 2765 |
Tcl_Preserve(treePtr); |
| 2766 |
|
| 2767 |
/* |
| 2768 |
* Invoke the entry's "open" command, if there is one. Otherwise |
| 2769 |
* try the hierbox's global "open" command. |
| 2770 |
*/ |
| 2771 |
result = TCL_OK; |
| 2772 |
string = (entryPtr->openCmd != NULL) ? entryPtr->openCmd : hboxPtr->openCmd; |
| 2773 |
if (!(entryPtr->flags & ENTRY_OPEN) && (string != NULL)) { |
| 2774 |
Tcl_DString dString; |
| 2775 |
|
| 2776 |
PercentSubst(hboxPtr, treePtr, string, &dString); |
| 2777 |
result = Tcl_GlobalEval(hboxPtr->interp, Tcl_DStringValue(&dString)); |
| 2778 |
Tcl_DStringFree(&dString); |
| 2779 |
} |
| 2780 |
/* |
| 2781 |
* Mark the entry open, only after the Tcl proc callback has run. |
| 2782 |
*/ |
| 2783 |
entryPtr->flags |= ENTRY_OPEN; |
| 2784 |
|
| 2785 |
Tcl_Release(treePtr); |
| 2786 |
return result; |
| 2787 |
} |
| 2788 |
|
| 2789 |
/* |
| 2790 |
*---------------------------------------------------------------------- |
| 2791 |
* |
| 2792 |
* SelectNode -- |
| 2793 |
* |
| 2794 |
* Sets the selection flag for a node. The selection flag is |
| 2795 |
* set/cleared/toggled based upon the flag set in the hierarchy |
| 2796 |
* widget. |
| 2797 |
* |
| 2798 |
* Results: |
| 2799 |
* Always returns TCL_OK. |
| 2800 |
* |
| 2801 |
*---------------------------------------------------------------------- |
| 2802 |
*/ |
| 2803 |
static int |
| 2804 |
SelectNode(hboxPtr, treePtr) |
| 2805 |
Hierbox *hboxPtr; |
| 2806 |
Tree *treePtr; |
| 2807 |
{ |
| 2808 |
switch (hboxPtr->flags & SELECTION_MASK) { |
| 2809 |
case SELECTION_CLEAR: |
| 2810 |
DeselectEntry(hboxPtr, treePtr); |
| 2811 |
break; |
| 2812 |
|
| 2813 |
case SELECTION_SET: |
| 2814 |
SelectEntry(hboxPtr, treePtr); |
| 2815 |
break; |
| 2816 |
|
| 2817 |
case SELECTION_TOGGLE: |
| 2818 |
if (IsSelected(hboxPtr, treePtr)) { |
| 2819 |
DeselectEntry(hboxPtr, treePtr); |
| 2820 |
} else { |
| 2821 |
SelectEntry(hboxPtr, treePtr); |
| 2822 |
} |
| 2823 |
break; |
| 2824 |
} |
| 2825 |
return TCL_OK; |
| 2826 |
} |
| 2827 |
|
| 2828 |
/* |
| 2829 |
*---------------------------------------------------------------------- |
| 2830 |
* |
| 2831 |
* SelectRange -- |
| 2832 |
* |
| 2833 |
* Sets the selection flag for a range of nodes. The range is |
| 2834 |
* determined by two pointers which designate the first/last |
| 2835 |
* nodes of the range. |
| 2836 |
* |
| 2837 |
* Results: |
| 2838 |
* Always returns TCL_OK. |
| 2839 |
* |
| 2840 |
*---------------------------------------------------------------------- |
| 2841 |
*/ |
| 2842 |
static int |
| 2843 |
SelectRange(hboxPtr, fromPtr, toPtr) |
| 2844 |
Hierbox *hboxPtr; |
| 2845 |
Tree *fromPtr, *toPtr; |
| 2846 |
{ |
| 2847 |
register Tree *treePtr; |
| 2848 |
IterProc *proc; |
| 2849 |
|
| 2850 |
/* From the range determine the direction to select entries. */ |
| 2851 |
proc = (IsBefore(toPtr, fromPtr)) ? LastNode : NextNode; |
| 2852 |
for (treePtr = fromPtr; treePtr != NULL; |
| 2853 |
treePtr = (*proc)(treePtr, ENTRY_OPEN | ENTRY_MAPPED)) { |
| 2854 |
SelectNode(hboxPtr, treePtr); |
| 2855 |
if (treePtr == toPtr) { |
| 2856 |
break; |
| 2857 |
} |
| 2858 |
} |
| 2859 |
return TCL_OK; |
| 2860 |
} |
| 2861 |
|
| 2862 |
/* |
| 2863 |
*---------------------------------------------------------------------- |
| 2864 |
* |
| 2865 |
* IsSelectedNode -- |
| 2866 |
* |
| 2867 |
* Adds the name of the node the interpreter result if it is |
| 2868 |
* currently selected. |
| 2869 |
* |
| 2870 |
* Results: |
| 2871 |
* Always returns TCL_OK. |
| 2872 |
* |
| 2873 |
*---------------------------------------------------------------------- |
| 2874 |
*/ |
| 2875 |
static int |
| 2876 |
IsSelectedNode(hboxPtr, treePtr) |
| 2877 |
Hierbox *hboxPtr; |
| 2878 |
Tree *treePtr; |
| 2879 |
{ |
| 2880 |
if (IsSelected(hboxPtr, treePtr)) { |
| 2881 |
Tcl_AppendElement(hboxPtr->interp, NodeToString(hboxPtr, treePtr)); |
| 2882 |
} |
| 2883 |
return TCL_OK; |
| 2884 |
} |
| 2885 |
|
| 2886 |
/* |
| 2887 |
*---------------------------------------------------------------------- |
| 2888 |
* |
| 2889 |
* GetSelectedLabels -- |
| 2890 |
* |
| 2891 |
* This routine is invoked when the selection is exported. Each |
| 2892 |
* selected entry is appended line-by-line to a dynamic string |
| 2893 |
* passed via the clientData field of the hierarchy widget. |
| 2894 |
* |
| 2895 |
* Results: |
| 2896 |
* Always returns TCL_OK. |
| 2897 |
* |
| 2898 |
*---------------------------------------------------------------------- |
| 2899 |
*/ |
| 2900 |
static int |
| 2901 |
GetSelectedLabels(hboxPtr, treePtr) |
| 2902 |
Hierbox *hboxPtr; |
| 2903 |
Tree *treePtr; |
| 2904 |
{ |
| 2905 |
if (IsSelected(hboxPtr, treePtr)) { |
| 2906 |
Tcl_DString *resultPtr = (Tcl_DString *) hboxPtr->clientData; |
| 2907 |
Entry *entryPtr = treePtr->entryPtr; |
| 2908 |
|
| 2909 |
Tcl_DStringAppend(resultPtr, entryPtr->labelText, -1); |
| 2910 |
Tcl_DStringAppend(resultPtr, "\n", -1); |
| 2911 |
} |
| 2912 |
return TCL_OK; |
| 2913 |
} |
| 2914 |
|
| 2915 |
/* |
| 2916 |
*---------------------------------------------------------------------- |
| 2917 |
* |
| 2918 |
* SizeOfNode -- |
| 2919 |
* |
| 2920 |
* Returns the number of children at the given node. The sum |
| 2921 |
* is passed via the clientData field of the hierarchy widget. |
| 2922 |
* |
| 2923 |
* Results: |
| 2924 |
* Always TCL_OK. |
| 2925 |
* |
| 2926 |
*---------------------------------------------------------------------- |
| 2927 |
*/ |
| 2928 |
static int |
| 2929 |
SizeOfNode(hboxPtr, treePtr) |
| 2930 |
Hierbox *hboxPtr; |
| 2931 |
Tree *treePtr; |
| 2932 |
{ |
| 2933 |
int *sumPtr = (int *)&(hboxPtr->clientData); |
| 2934 |
|
| 2935 |
*sumPtr += Blt_ChainGetLength(treePtr->chainPtr); |
| 2936 |
return TCL_OK; |
| 2937 |
} |
| 2938 |
|
| 2939 |
/* |
| 2940 |
*---------------------------------------------------------------------- |
| 2941 |
* |
| 2942 |
* CompareNodesByName -- |
| 2943 |
* |
| 2944 |
* Comparison routine (used by qsort) to sort a chain of subnodes. |
| 2945 |
* A simple string comparison is performed on each node name. |
| 2946 |
* |
| 2947 |
* Results: |
| 2948 |
* 1 is the first is greater, -1 is the second is greater, 0 |
| 2949 |
* if equal. |
| 2950 |
* |
| 2951 |
*---------------------------------------------------------------------- |
| 2952 |
*/ |
| 2953 |
static int |
| 2954 |
CompareNodesByName(link1PtrPtr, link2PtrPtr) |
| 2955 |
Blt_ChainLink **link1PtrPtr, **link2PtrPtr; |
| 2956 |
{ |
| 2957 |
Tree *t1Ptr, *t2Ptr; |
| 2958 |
|
| 2959 |
t1Ptr = Blt_ChainGetValue(*link1PtrPtr); |
| 2960 |
t2Ptr = Blt_ChainGetValue(*link2PtrPtr); |
| 2961 |
return strcmp(t1Ptr->nameId, t2Ptr->nameId); |
| 2962 |
} |
| 2963 |
|
| 2964 |
/* |
| 2965 |
*---------------------------------------------------------------------- |
| 2966 |
* |
| 2967 |
* CompareNodesByTclCmd -- |
| 2968 |
* |
| 2969 |
* Comparison routine (used by qsort) to sort a list of subnodes. |
| 2970 |
* A specified Tcl proc is invoked to compare the nodes. |
| 2971 |
* |
| 2972 |
* Results: |
| 2973 |
* 1 is the first is greater, -1 is the second is greater, 0 |
| 2974 |
* if equal. |
| 2975 |
* |
| 2976 |
*---------------------------------------------------------------------- |
| 2977 |
*/ |
| 2978 |
static int |
| 2979 |
CompareNodesByTclCmd(link1PtrPtr, link2PtrPtr) |
| 2980 |
Blt_ChainLink **link1PtrPtr, **link2PtrPtr; |
| 2981 |
{ |
| 2982 |
int result; |
| 2983 |
Tree *t1Ptr, *t2Ptr; |
| 2984 |
Hierbox *hboxPtr = hierBox; |
| 2985 |
Tcl_Interp *interp = hboxPtr->interp; |
| 2986 |
|
| 2987 |
t1Ptr = Blt_ChainGetValue(*link1PtrPtr); |
| 2988 |
t2Ptr = Blt_ChainGetValue(*link2PtrPtr); |
| 2989 |
result = 0; /* Hopefully this will be Ok even if the |
| 2990 |
* Tcl command fails to return the correct |
| 2991 |
* result. */ |
| 2992 |
if ((Tcl_VarEval(interp, hboxPtr->sortCmd, " ", |
| 2993 |
Tk_PathName(hboxPtr->tkwin), " ", NodeToString(hboxPtr, t1Ptr), " ", |
| 2994 |
NodeToString(hboxPtr, t2Ptr)) != TCL_OK) || |
| 2995 |
(Tcl_GetInt(interp, Tcl_GetStringResult(interp), &result) != TCL_OK)) { |
| 2996 |
Tcl_BackgroundError(interp); |
| 2997 |
} |
| 2998 |
Tcl_ResetResult(interp); |
| 2999 |
return result; |
| 3000 |
} |
| 3001 |
|
| 3002 |
/* |
| 3003 |
*---------------------------------------------------------------------- |
| 3004 |
* |
| 3005 |
* SortNode -- |
| 3006 |
* |
| 3007 |
* Sorts the subnodes at a given node. |
| 3008 |
* |
| 3009 |
* Results: |
| 3010 |
* Always returns TCL_OK. |
| 3011 |
* |
| 3012 |
*---------------------------------------------------------------------- |
| 3013 |
*/ |
| 3014 |
static int |
| 3015 |
SortNode(hboxPtr, treePtr) |
| 3016 |
Hierbox *hboxPtr; |
| 3017 |
Tree *treePtr; |
| 3018 |
{ |
| 3019 |
if (treePtr->chainPtr != NULL) { |
| 3020 |
if (hboxPtr->sortCmd != NULL) { |
| 3021 |
hierBox = hboxPtr; |
| 3022 |
Blt_ChainSort(treePtr->chainPtr, CompareNodesByTclCmd); |
| 3023 |
} else { |
| 3024 |
Blt_ChainSort(treePtr->chainPtr, CompareNodesByName); |
| 3025 |
} |
| 3026 |
} |
| 3027 |
return TCL_OK; |
| 3028 |
} |
| 3029 |
|
| 3030 |
/* |
| 3031 |
*---------------------------------------------------------------------- |
| 3032 |
* |
| 3033 |
* UnmapNode -- |
| 3034 |
* |
| 3035 |
* Unmaps the given node. The node will not be drawn. Ignore |
| 3036 |
* unmapping of the root node (it makes no sense). |
| 3037 |
* |
| 3038 |
* Results: |
| 3039 |
* Always returns TCL_OK. |
| 3040 |
* |
| 3041 |
*---------------------------------------------------------------------- |
| 3042 |
*/ |
| 3043 |
static int |
| 3044 |
UnmapNode(hboxPtr, treePtr) |
| 3045 |
Hierbox *hboxPtr; |
| 3046 |
Tree *treePtr; |
| 3047 |
{ |
| 3048 |
if (treePtr != hboxPtr->rootPtr) { |
| 3049 |
treePtr->entryPtr->flags &= ~ENTRY_MAPPED; |
| 3050 |
} |
| 3051 |
return TCL_OK; |
| 3052 |
} |
| 3053 |
|
| 3054 |
/* |
| 3055 |
*---------------------------------------------------------------------- |
| 3056 |
* |
| 3057 |
* MapAncestors -- |
| 3058 |
* |
| 3059 |
* If a node in mapped, then all its ancestors must be mapped also. |
| 3060 |
* This routine traverses upwards and maps each unmapped ancestor. |
| 3061 |
* It's assumed that for any mapped ancestor, all it's ancestors |
| 3062 |
* will already be mapped too. |
| 3063 |
* |
| 3064 |
* Results: |
| 3065 |
* Always returns TCL_OK. |
| 3066 |
* |
| 3067 |
*---------------------------------------------------------------------- |
| 3068 |
*/ |
| 3069 |
/*ARGSUSED*/ |
| 3070 |
static int |
| 3071 |
MapAncestors(hboxPtr, treePtr) |
| 3072 |
Hierbox *hboxPtr; /* Not used. */ |
| 3073 |
Tree *treePtr; |
| 3074 |
{ |
| 3075 |
/* |
| 3076 |
* Make sure that all the ancestors of this node are mapped too. |
| 3077 |
*/ |
| 3078 |
treePtr = treePtr->parentPtr; |
| 3079 |
while (treePtr != NULL) { |
| 3080 |
if (treePtr->entryPtr->flags & ENTRY_MAPPED) { |
| 3081 |
break; /* Assume ancestors are also mapped. */ |
| 3082 |
} |
| 3083 |
treePtr->entryPtr->flags |= ENTRY_MAPPED; |
| 3084 |
treePtr = treePtr->parentPtr; |
| 3085 |
} |
| 3086 |
return TCL_OK; |
| 3087 |
} |
| 3088 |
|
| 3089 |
/* |
| 3090 |
*---------------------------------------------------------------------- |
| 3091 |
* |
| 3092 |
* MapNode -- |
| 3093 |
* |
| 3094 |
* Maps the given node. Only mapped nodes are drawn. |
| 3095 |
* |
| 3096 |
* Results: |
| 3097 |
* Always returns TCL_OK. |
| 3098 |
* |
| 3099 |
*---------------------------------------------------------------------- |
| 3100 |
*/ |
| 3101 |
static int |
| 3102 |
MapNode(hboxPtr, treePtr) |
| 3103 |
Hierbox *hboxPtr; |
| 3104 |
Tree *treePtr; |
| 3105 |
{ |
| 3106 |
treePtr->entryPtr->flags |= ENTRY_MAPPED; |
| 3107 |
MapAncestors(hboxPtr, treePtr); |
| 3108 |
return TCL_OK; |
| 3109 |
} |
| 3110 |
|
| 3111 |
static int |
| 3112 |
FixUnmappedSelections(hboxPtr, treePtr) |
| 3113 |
Hierbox *hboxPtr; |
| 3114 |
Tree *treePtr; |
| 3115 |
{ |
| 3116 |
if (!(treePtr->entryPtr->flags & ENTRY_MAPPED)) { |
| 3117 |
DeselectEntry(hboxPtr, treePtr); |
| 3118 |
PruneSelection(hboxPtr, treePtr); |
| 3119 |
if (IsAncestor(treePtr, hboxPtr->focusPtr)) { |
| 3120 |
hboxPtr->focusPtr = treePtr->parentPtr; |
| 3121 |
if (hboxPtr->focusPtr == NULL) { |
| 3122 |
hboxPtr->focusPtr = hboxPtr->rootPtr; |
| 3123 |
} |
| 3124 |
Blt_SetFocusItem(hboxPtr->bindTable, hboxPtr->focusPtr, NULL); |
| 3125 |
} |
| 3126 |
} |
| 3127 |
return TCL_OK; |
| 3128 |
} |
| 3129 |
|
| 3130 |
static int |
| 3131 |
DeleteNode(hboxPtr, treePtr) |
| 3132 |
Hierbox *hboxPtr; |
| 3133 |
Tree *treePtr; |
| 3134 |
{ |
| 3135 |
/* |
| 3136 |
* Indicate that the screen layout of the hierarchy may have changed |
| 3137 |
* because the node was deleted. We don't want to access the |
| 3138 |
* hboxPtr->visibleArr array if one of the nodes is bogus. |
| 3139 |
*/ |
| 3140 |
hboxPtr->flags |= HIERBOX_DIRTY; |
| 3141 |
if (treePtr == hboxPtr->activePtr) { |
| 3142 |
hboxPtr->activePtr = treePtr->parentPtr; |
| 3143 |
} |
| 3144 |
if (treePtr == hboxPtr->activeButtonPtr) { |
| 3145 |
hboxPtr->activeButtonPtr = NULL; |
| 3146 |
} |
| 3147 |
if (treePtr == hboxPtr->focusPtr) { |
| 3148 |
hboxPtr->focusPtr = treePtr->parentPtr; |
| 3149 |
Blt_SetFocusItem(hboxPtr->bindTable, hboxPtr->focusPtr, NULL); |
| 3150 |
} |
| 3151 |
if (treePtr == hboxPtr->selAnchorPtr) { |
| 3152 |
hboxPtr->selAnchorPtr = NULL; |
| 3153 |
} |
| 3154 |
DeselectEntry(hboxPtr, treePtr); |
| 3155 |
PruneSelection(hboxPtr, treePtr); |
| 3156 |
if (treePtr->linkPtr != NULL) { /* Remove from parent's list */ |
| 3157 |
Blt_ChainDeleteLink(treePtr->parentPtr->chainPtr, treePtr->linkPtr); |
| 3158 |
treePtr->linkPtr = NULL; |
| 3159 |
} |
| 3160 |
/* |
| 3161 |
* Node may still be in use, so we can't free it right now. We'll |
| 3162 |
* mark the parent as NULL and remove it from the parent's list of |
| 3163 |
* children. |
| 3164 |
*/ |
| 3165 |
treePtr->parentPtr = NULL; |
| 3166 |
Blt_DeleteBindings(hboxPtr->bindTable, treePtr); |
| 3167 |
Blt_DeleteBindings(hboxPtr->buttonBindTable, treePtr); |
| 3168 |
Tcl_EventuallyFree(treePtr, DestroyNode); |
| 3169 |
return TCL_OK; |
| 3170 |
} |
| 3171 |
|
| 3172 |
|
| 3173 |
/* |
| 3174 |
*---------------------------------------------------------------------- |
| 3175 |
* |
| 3176 |
* DestroyTree -- |
| 3177 |
* |
| 3178 |
* Recursively deletes the given node and all its subnodes. |
| 3179 |
* |
| 3180 |
* Results: |
| 3181 |
* If successful, returns TCL_OK. Otherwise TCL_ERROR is |
| 3182 |
* returned. |
| 3183 |
* |
| 3184 |
*---------------------------------------------------------------------- |
| 3185 |
*/ |
| 3186 |
static int |
| 3187 |
DestroyTree(hboxPtr, treePtr) |
| 3188 |
Hierbox *hboxPtr; |
| 3189 |
Tree *treePtr; |
| 3190 |
{ |
| 3191 |
return ApplyToTree(hboxPtr, treePtr, DeleteNode, APPLY_RECURSE); |
| 3192 |
} |
| 3193 |
|
| 3194 |
/*ARGSUSED*/ |
| 3195 |
static void |
| 3196 |
GetTags(table, object, context, list) |
| 3197 |
Blt_BindTable table; /* Not used. */ |
| 3198 |
ClientData object; |
| 3199 |
ClientData context; /* Not used. */ |
| 3200 |
Blt_List list; |
| 3201 |
{ |
| 3202 |
Tree *treePtr; |
| 3203 |
|
| 3204 |
Blt_ListAppend(list, (char *)object, 0); |
| 3205 |
treePtr = (Tree *) object; |
| 3206 |
if (treePtr->entryPtr->tags != NULL) { |
| 3207 |
int nNames; |
| 3208 |
char **names; |
| 3209 |
register char **p; |
| 3210 |
|
| 3211 |
if (Tcl_SplitList((Tcl_Interp *)NULL, treePtr->entryPtr->tags, &nNames, |
| 3212 |
&names) == TCL_OK) { |
| 3213 |
for (p = names; *p != NULL; p++) { |
| 3214 |
Blt_ListAppend(list, Tk_GetUid(*p), 0); |
| 3215 |
} |
| 3216 |
Blt_Free(names); |
| 3217 |
} |
| 3218 |
} |
| 3219 |
} |
| 3220 |
|
| 3221 |
/*ARGSUSED*/ |
| 3222 |
static ClientData |
| 3223 |
PickButton(clientData, x, y, contextPtr) |
| 3224 |
ClientData clientData; |
| 3225 |
int x, y; /* Screen coordinates of the test point. */ |
| 3226 |
ClientData *contextPtr; /* Not used. */ |
| 3227 |
{ |
| 3228 |
Hierbox *hboxPtr = clientData; |
| 3229 |
Entry *entryPtr; |
| 3230 |
Tree *treePtr; |
| 3231 |
|
| 3232 |
if (hboxPtr->flags & HIERBOX_DIRTY) { |
| 3233 |
/* Can't trust selected entry, if entries have been added or deleted. */ |
| 3234 |
if (hboxPtr->flags & HIERBOX_LAYOUT) { |
| 3235 |
ComputeLayout(hboxPtr); |
| 3236 |
} |
| 3237 |
ComputeVisibleEntries(hboxPtr); |
| 3238 |
} |
| 3239 |
if (hboxPtr->nVisible == 0) { |
| 3240 |
return (ClientData) 0; |
| 3241 |
} |
| 3242 |
treePtr = NearestNode(hboxPtr, x, y, FALSE); |
| 3243 |
if (treePtr == NULL) { |
| 3244 |
return (ClientData) 0; |
| 3245 |
} |
| 3246 |
entryPtr = treePtr->entryPtr; |
| 3247 |
if (entryPtr->flags & ENTRY_BUTTON) { |
| 3248 |
ButtonAttributes *buttonPtr = &(hboxPtr->button); |
| 3249 |
int left, right, top, bottom; |
| 3250 |
#define BUTTON_PAD 2 |
| 3251 |
left = entryPtr->worldX + entryPtr->buttonX - BUTTON_PAD; |
| 3252 |
right = left + buttonPtr->width + 2 * BUTTON_PAD; |
| 3253 |
top = entryPtr->worldY + entryPtr->buttonY - BUTTON_PAD; |
| 3254 |
bottom = top + buttonPtr->height + 2 * BUTTON_PAD; |
| 3255 |
x = WORLDX(hboxPtr, x); |
| 3256 |
y = WORLDY(hboxPtr, y); |
| 3257 |
if ((x >= left) && (x < right) && (y >= top) && (y < bottom)) { |
| 3258 |
return treePtr; |
| 3259 |
} |
| 3260 |
} |
| 3261 |
return (ClientData) 0; |
| 3262 |
} |
| 3263 |
|
| 3264 |
/*ARGSUSED*/ |
| 3265 |
static ClientData |
| 3266 |
PickEntry(clientData, x, y, contextPtr) |
| 3267 |
ClientData clientData; |
| 3268 |
int x, y; /* Screen coordinates of the test point. */ |
| 3269 |
ClientData *contextPtr; /* Not used. */ |
| 3270 |
{ |
| 3271 |
Hierbox *hboxPtr = clientData; |
| 3272 |
Entry *entryPtr; |
| 3273 |
Tree *treePtr; |
| 3274 |
|
| 3275 |
if (hboxPtr->flags & HIERBOX_DIRTY) { |
| 3276 |
/* Can't trust selected entry, if entries have been added or deleted. */ |
| 3277 |
if (hboxPtr->flags & HIERBOX_LAYOUT) { |
| 3278 |
ComputeLayout(hboxPtr); |
| 3279 |
} |
| 3280 |
ComputeVisibleEntries(hboxPtr); |
| 3281 |
} |
| 3282 |
if (hboxPtr->nVisible == 0) { |
| 3283 |
return (ClientData) 0; |
| 3284 |
} |
| 3285 |
treePtr = NearestNode(hboxPtr, x, y, FALSE); |
| 3286 |
if (treePtr == NULL) { |
| 3287 |
return (ClientData) 0; |
| 3288 |
} |
| 3289 |
entryPtr = treePtr->entryPtr; |
| 3290 |
if (entryPtr->flags & ENTRY_BUTTON) { |
| 3291 |
ButtonAttributes *buttonPtr = &(hboxPtr->button); |
| 3292 |
int left, right, top, bottom; |
| 3293 |
#define BUTTON_PAD 2 |
| 3294 |
left = entryPtr->worldX + entryPtr->buttonX - BUTTON_PAD; |
| 3295 |
right = left + buttonPtr->width + 2 * BUTTON_PAD; |
| 3296 |
top = entryPtr->worldY + entryPtr->buttonY - BUTTON_PAD; |
| 3297 |
bottom = top + buttonPtr->height + 2 * BUTTON_PAD; |
| 3298 |
x = WORLDX(hboxPtr, x); |
| 3299 |
y = WORLDY(hboxPtr, y); |
| 3300 |
if ((x >= left) && (x < right) && (y >= top) && (y < bottom)) { |
| 3301 |
return NULL; |
| 3302 |
} |
| 3303 |
} |
| 3304 |
return treePtr; |
| 3305 |
} |
| 3306 |
|
| 3307 |
static int |
| 3308 |
ConfigureEntry(hboxPtr, entryPtr, argc, argv, flags) |
| 3309 |
Hierbox *hboxPtr; |
| 3310 |
Entry *entryPtr; |
| 3311 |
int argc; |
| 3312 |
CONST char **argv; |
| 3313 |
int flags; |
| 3314 |
{ |
| 3315 |
GC newGC; |
| 3316 |
XGCValues gcValues; |
| 3317 |
unsigned long gcMask; |
| 3318 |
int entryWidth, entryHeight; |
| 3319 |
int width, height; |
| 3320 |
Tk_Font font; |
| 3321 |
XColor *colorPtr; |
| 3322 |
|
| 3323 |
hierBox = hboxPtr; |
| 3324 |
if (Blt_ConfigureWidget(hboxPtr->interp, hboxPtr->tkwin, entryConfigSpecs, |
| 3325 |
argc, argv, (char *)entryPtr, flags) != TCL_OK) { |
| 3326 |
return TCL_ERROR; |
| 3327 |
} |
| 3328 |
entryPtr->iconWidth = entryPtr->iconHeight = 0; |
| 3329 |
if (entryPtr->icons != NULL) { |
| 3330 |
register int i; |
| 3331 |
|
| 3332 |
for (i = 0; i < 2; i++) { |
| 3333 |
if (entryPtr->icons[i] == NULL) { |
| 3334 |
break; |
| 3335 |
} |
| 3336 |
if (entryPtr->iconWidth < ImageWidth(entryPtr->icons[i])) { |
| 3337 |
entryPtr->iconWidth = ImageWidth(entryPtr->icons[i]); |
| 3338 |
} |
| 3339 |
if (entryPtr->iconHeight < ImageHeight(entryPtr->icons[i])) { |
| 3340 |
entryPtr->iconHeight = ImageHeight(entryPtr->icons[i]); |
| 3341 |
} |
| 3342 |
} |
| 3343 |
} |
| 3344 |
newGC = NULL; |
| 3345 |
if ((entryPtr->icons == NULL) || (entryPtr->icons[0] == NULL)) { |
| 3346 |
gcMask = GCClipMask | GCBackground; |
| 3347 |
gcValues.clip_mask = hboxPtr->iconMask; |
| 3348 |
gcValues.background = hboxPtr->iconColor->pixel; |
| 3349 |
newGC = Tk_GetGC(hboxPtr->tkwin, gcMask, &gcValues); |
| 3350 |
entryPtr->iconWidth = DEF_ICON_WIDTH; |
| 3351 |
entryPtr->iconHeight = DEF_ICON_HEIGHT; |
| 3352 |
} |
| 3353 |
entryPtr->iconWidth += 2 * ICON_PADX; |
| 3354 |
entryPtr->iconHeight += 2 * ICON_PADY; |
| 3355 |
if (entryPtr->iconGC != NULL) { |
| 3356 |
Tk_FreeGC(hboxPtr->display, entryPtr->iconGC); |
| 3357 |
} |
| 3358 |
entryPtr->iconGC = newGC; |
| 3359 |
|
| 3360 |
entryHeight = MAX(entryPtr->iconHeight, hboxPtr->button.height); |
| 3361 |
entryWidth = 0; |
| 3362 |
|
| 3363 |
gcMask = GCForeground | GCFont; |
| 3364 |
colorPtr = GETCOLOR(hboxPtr, entryPtr->labelColor); |
| 3365 |
gcValues.foreground = colorPtr->pixel; |
| 3366 |
font = GETFONT(hboxPtr, entryPtr->labelFont); |
| 3367 |
gcValues.font = Tk_FontId(font); |
| 3368 |
newGC = Tk_GetGC(hboxPtr->tkwin, gcMask, &gcValues); |
| 3369 |
if (entryPtr->labelGC != NULL) { |
| 3370 |
Tk_FreeGC(hboxPtr->display, entryPtr->labelGC); |
| 3371 |
} |
| 3372 |
entryPtr->labelGC = newGC; |
| 3373 |
|
| 3374 |
if (*entryPtr->labelText == '\0') { |
| 3375 |
Tk_FontMetrics fontMetrics; |
| 3376 |
|
| 3377 |
Tk_GetFontMetrics(font, &fontMetrics); |
| 3378 |
width = height = fontMetrics.linespace; |
| 3379 |
} else { |
| 3380 |
TextStyle ts; |
| 3381 |
|
| 3382 |
Blt_InitTextStyle(&ts); |
| 3383 |
ts.shadow.offset = entryPtr->labelShadow.offset; |
| 3384 |
ts.font = font; |
| 3385 |
Blt_GetTextExtents(&ts, entryPtr->labelText, &width, &height); |
| 3386 |
} |
| 3387 |
width += 2 * (FOCUS_WIDTH + LABEL_PADX + hboxPtr->selBorderWidth); |
| 3388 |
height += 2 * (FOCUS_WIDTH + LABEL_PADY + hboxPtr->selBorderWidth); |
| 3389 |
width = ODD(width); |
| 3390 |
height = ODD(height); |
| 3391 |
entryWidth += width; |
| 3392 |
if (entryHeight < height) { |
| 3393 |
entryHeight = height; |
| 3394 |
} |
| 3395 |
entryPtr->labelWidth = width; |
| 3396 |
entryPtr->labelHeight = height; |
| 3397 |
width = height = 0; |
| 3398 |
if (entryPtr->images != NULL) { |
| 3399 |
register CachedImage *imagePtr; |
| 3400 |
|
| 3401 |
for (imagePtr = entryPtr->images; *imagePtr != NULL; imagePtr++) { |
| 3402 |
width += ImageWidth(*imagePtr); |
| 3403 |
if (height < ImageHeight(*imagePtr)) { |
| 3404 |
height = ImageHeight(*imagePtr); |
| 3405 |
} |
| 3406 |
} |
| 3407 |
} else if (entryPtr->dataText != NULL) { |
| 3408 |
TextStyle ts; |
| 3409 |
|
| 3410 |
gcMask = GCForeground | GCFont; |
| 3411 |
colorPtr = GETCOLOR(hboxPtr, entryPtr->dataColor); |
| 3412 |
gcValues.foreground = colorPtr->pixel; |
| 3413 |
font = GETFONT(hboxPtr, entryPtr->dataFont); |
| 3414 |
gcValues.font = Tk_FontId(font); |
| 3415 |
newGC = Tk_GetGC(hboxPtr->tkwin, gcMask, &gcValues); |
| 3416 |
if (entryPtr->dataGC != NULL) { |
| 3417 |
Tk_FreeGC(hboxPtr->display, entryPtr->dataGC); |
| 3418 |
} |
| 3419 |
entryPtr->dataGC = newGC; |
| 3420 |
|
| 3421 |
Blt_InitTextStyle(&ts); |
| 3422 |
ts.font = font; |
| 3423 |
ts.shadow.offset = entryPtr->dataShadow.offset; |
| 3424 |
Blt_GetTextExtents(&ts, entryPtr->dataText, &width, &height); |
| 3425 |
width += 2 * LABEL_PADX; |
| 3426 |
height += 2 * LABEL_PADY; |
| 3427 |
} |
| 3428 |
entryWidth += width; |
| 3429 |
if (entryHeight < height) { |
| 3430 |
entryHeight = height; |
| 3431 |
} |
| 3432 |
entryPtr->width = entryWidth + 4; |
| 3433 |
entryPtr->height = entryHeight + hboxPtr->leader; |
| 3434 |
|
| 3435 |
/* |
| 3436 |
* Force the height of the entry to an even number. This is to |
| 3437 |
* make the dots or the vertical line segments coincide with the |
| 3438 |
* start of the horizontal lines. |
| 3439 |
*/ |
| 3440 |
if (entryPtr->height & 0x01) { |
| 3441 |
entryPtr->height++; |
| 3442 |
} |
| 3443 |
hboxPtr->flags |= HIERBOX_LAYOUT; |
| 3444 |
EventuallyRedraw(hboxPtr); |
| 3445 |
return TCL_OK; |
| 3446 |
} |
| 3447 |
|
| 3448 |
/* |
| 3449 |
* Hierbox Procedures |
| 3450 |
*/ |
| 3451 |
/* |
| 3452 |
*---------------------------------------------------------------------- |
| 3453 |
* |
| 3454 |
* EventuallyRedraw -- |
| 3455 |
* |
| 3456 |
* Queues a request to redraw the widget at the next idle point. |
| 3457 |
* |
| 3458 |
* Results: |
| 3459 |
* None. |
| 3460 |
* |
| 3461 |
* Side effects: |
| 3462 |
* Information gets redisplayed. Right now we don't do selective |
| 3463 |
* redisplays: the whole window will be redrawn. |
| 3464 |
* |
| 3465 |
*---------------------------------------------------------------------- |
| 3466 |
*/ |
| 3467 |
static void |
| 3468 |
EventuallyRedraw(hboxPtr) |
| 3469 |
Hierbox *hboxPtr; |
| 3470 |
{ |
| 3471 |
if ((hboxPtr->tkwin != NULL) && !(hboxPtr->flags & HIERBOX_REDRAW)) { |
| 3472 |
hboxPtr->flags |= HIERBOX_REDRAW; |
| 3473 |
Tcl_DoWhenIdle(DisplayHierbox, hboxPtr); |
| 3474 |
} |
| 3475 |
} |
| 3476 |
|
| 3477 |
/* |
| 3478 |
*---------------------------------------------------------------------- |
| 3479 |
* |
| 3480 |
* LabelBlinkProc -- |
| 3481 |
* |
| 3482 |
* This procedure is called as a timer handler to blink the |
| 3483 |
* insertion cursor off and on. |
| 3484 |
* |
| 3485 |
* Results: |
| 3486 |
* None. |
| 3487 |
* |
| 3488 |
* Side effects: |
| 3489 |
* The cursor gets turned on or off, redisplay gets invoked, |
| 3490 |
* and this procedure reschedules itself. |
| 3491 |
* |
| 3492 |
*---------------------------------------------------------------------- |
| 3493 |
*/ |
| 3494 |
|
| 3495 |
static void |
| 3496 |
LabelBlinkProc(clientData) |
| 3497 |
ClientData clientData; /* Pointer to record describing entry. */ |
| 3498 |
{ |
| 3499 |
Hierbox *hboxPtr = clientData; |
| 3500 |
TextEdit *editPtr = &(hboxPtr->labelEdit); |
| 3501 |
int interval; |
| 3502 |
|
| 3503 |
if (!(hboxPtr->flags & HIERBOX_FOCUS) || (editPtr->offTime == 0)) { |
| 3504 |
return; |
| 3505 |
} |
| 3506 |
if (editPtr->active) { |
| 3507 |
editPtr->cursorOn ^= 1; |
| 3508 |
interval = (editPtr->cursorOn) ? editPtr->onTime : editPtr->offTime; |
| 3509 |
editPtr->timerToken = Tcl_CreateTimerHandler(interval, LabelBlinkProc, |
| 3510 |
hboxPtr); |
| 3511 |
EventuallyRedraw(hboxPtr); |
| 3512 |
} |
| 3513 |
} |
| 3514 |
|
| 3515 |
/* |
| 3516 |
*---------------------------------------------------------------------- |
| 3517 |
* |
| 3518 |
* EventuallyInvokeSelectCmd -- |
| 3519 |
* |
| 3520 |
* Queues a request to execute the -selectcommand code associated |
| 3521 |
* with the widget at the next idle point. Invoked whenever the |
| 3522 |
* selection changes. |
| 3523 |
* |
| 3524 |
* Results: |
| 3525 |
* None. |
| 3526 |
* |
| 3527 |
* Side effects: |
| 3528 |
* Tcl code gets executed for some application-specific task. |
| 3529 |
* |
| 3530 |
*---------------------------------------------------------------------- |
| 3531 |
*/ |
| 3532 |
static void |
| 3533 |
EventuallyInvokeSelectCmd(hboxPtr) |
| 3534 |
Hierbox *hboxPtr; |
| 3535 |
{ |
| 3536 |
if (!(hboxPtr->flags & SELECTION_PENDING)) { |
| 3537 |
hboxPtr->flags |= SELECTION_PENDING; |
| 3538 |
Tcl_DoWhenIdle(SelectCmdProc, hboxPtr); |
| 3539 |
} |
| 3540 |
} |
| 3541 |
|
| 3542 |
/* |
| 3543 |
* ---------------------------------------------------------------------- |
| 3544 |
* |
| 3545 |
* CreateHierbox -- |
| 3546 |
* |
| 3547 |
* ---------------------------------------------------------------------- |
| 3548 |
*/ |
| 3549 |
static Hierbox * |
| 3550 |
CreateHierbox(interp, tkwin) |
| 3551 |
Tcl_Interp *interp; |
| 3552 |
Tk_Window tkwin; |
| 3553 |
{ |
| 3554 |
Hierbox *hboxPtr; |
| 3555 |
|
| 3556 |
hboxPtr = Blt_Calloc(1, sizeof(Hierbox)); |
| 3557 |
assert(hboxPtr); |
| 3558 |
|
| 3559 |
Tk_SetClass(tkwin, "Hierbox"); |
| 3560 |
hboxPtr->tkwin = tkwin; |
| 3561 |
hboxPtr->display = Tk_Display(tkwin); |
| 3562 |
hboxPtr->interp = interp; |
| 3563 |
|
| 3564 |
hboxPtr->leader = 0; |
| 3565 |
hboxPtr->dashes = 1; |
| 3566 |
hboxPtr->highlightWidth = 2; |
| 3567 |
hboxPtr->selBorderWidth = 1; |
| 3568 |
hboxPtr->borderWidth = 2; |
| 3569 |
hboxPtr->relief = TK_RELIEF_SUNKEN; |
| 3570 |
hboxPtr->selRelief = TK_RELIEF_FLAT; |
| 3571 |
hboxPtr->scrollMode = BLT_SCROLL_MODE_HIERBOX; |
| 3572 |
hboxPtr->button.closeRelief = hboxPtr->button.openRelief = TK_RELIEF_SOLID; |
| 3573 |
hboxPtr->reqWidth = 200; |
| 3574 |
hboxPtr->reqHeight = 400; |
| 3575 |
hboxPtr->lineWidth = 1; |
| 3576 |
hboxPtr->button.borderWidth = 1; |
| 3577 |
hboxPtr->labelEdit.selAnchor = -1; |
| 3578 |
hboxPtr->labelEdit.selFirst = hboxPtr->labelEdit.selLast = -1; |
| 3579 |
hboxPtr->labelEdit.onTime = 600, hboxPtr->labelEdit.offTime = 300; |
| 3580 |
Blt_ChainInit(&(hboxPtr->selectChain)); |
| 3581 |
Blt_InitHashTable(&(hboxPtr->selectTable), BLT_ONE_WORD_KEYS); |
| 3582 |
Blt_InitHashTable(&(hboxPtr->nodeTable), BLT_ONE_WORD_KEYS); |
| 3583 |
Blt_InitHashTable(&(hboxPtr->imageTable), BLT_STRING_KEYS); |
| 3584 |
hboxPtr->bindTable = Blt_CreateBindingTable(interp, tkwin, hboxPtr, |
| 3585 |
PickEntry, GetTags); |
| 3586 |
hboxPtr->buttonBindTable = Blt_CreateBindingTable(interp, tkwin, hboxPtr, |
| 3587 |
PickButton, GetTags); |
| 3588 |
#if (TK_MAJOR_VERSION > 4) |
| 3589 |
Blt_SetWindowInstanceData(tkwin, hboxPtr); |
| 3590 |
#endif |
| 3591 |
return hboxPtr; |
| 3592 |
} |
| 3593 |
|
| 3594 |
/* |
| 3595 |
* ---------------------------------------------------------------------- |
| 3596 |
* |
| 3597 |
* DestroyHierbox -- |
| 3598 |
* |
| 3599 |
* This procedure is invoked by Tcl_EventuallyFree or Tcl_Release |
| 3600 |
* to clean up the internal structure of a Hierbox at a safe time |
| 3601 |
* (when no-one is using it anymore). |
| 3602 |
* |
| 3603 |
* Results: |
| 3604 |
* None. |
| 3605 |
* |
| 3606 |
* Side effects: |
| 3607 |
* Everything associated with the widget is freed up. |
| 3608 |
* |
| 3609 |
* ---------------------------------------------------------------------- |
| 3610 |
*/ |
| 3611 |
static void |
| 3612 |
DestroyHierbox(dataPtr) |
| 3613 |
DestroyData dataPtr; /* Pointer to the widget record. */ |
| 3614 |
{ |
| 3615 |
Hierbox *hboxPtr = (Hierbox *)dataPtr; |
| 3616 |
ButtonAttributes *buttonPtr = &(hboxPtr->button); |
| 3617 |
|
| 3618 |
Tk_FreeOptions(configSpecs, (char *)hboxPtr, hboxPtr->display, 0); |
| 3619 |
if (hboxPtr->tkwin != NULL) { |
| 3620 |
Tk_DeleteSelHandler(hboxPtr->tkwin, XA_PRIMARY, XA_STRING); |
| 3621 |
} |
| 3622 |
if (hboxPtr->lineGC != NULL) { |
| 3623 |
Tk_FreeGC(hboxPtr->display, hboxPtr->lineGC); |
| 3624 |
} |
| 3625 |
if (hboxPtr->focusGC != NULL) { |
| 3626 |
Blt_FreePrivateGC(hboxPtr->display, hboxPtr->focusGC); |
| 3627 |
} |
| 3628 |
if (hboxPtr->tile != NULL) { |
| 3629 |
Blt_FreeTile(hboxPtr->tile); |
| 3630 |
} |
| 3631 |
if (hboxPtr->visibleArr != NULL) { |
| 3632 |
Blt_Free(hboxPtr->visibleArr); |
| 3633 |
} |
| 3634 |
if (hboxPtr->levelInfo != NULL) { |
| 3635 |
Blt_Free(hboxPtr->levelInfo); |
| 3636 |
} |
| 3637 |
if (hboxPtr->iconBitmap != None) { |
| 3638 |
Tk_FreeBitmap(hboxPtr->display, hboxPtr->iconBitmap); |
| 3639 |
} |
| 3640 |
if (hboxPtr->iconMask != None) { |
| 3641 |
Tk_FreeBitmap(hboxPtr->display, hboxPtr->iconMask); |
| 3642 |
} |
| 3643 |
if (hboxPtr->iconColor != NULL) { |
| 3644 |
Tk_FreeColor(hboxPtr->iconColor); |
| 3645 |
} |
| 3646 |
if (buttonPtr->images != NULL) { |
| 3647 |
register CachedImage *imagePtr; |
| 3648 |
|
| 3649 |
for (imagePtr = buttonPtr->images; *imagePtr != NULL; imagePtr++) { |
| 3650 |
FreeCachedImage(hboxPtr, *imagePtr); |
| 3651 |
} |
| 3652 |
Blt_Free(buttonPtr->images); |
| 3653 |
} |
| 3654 |
if (buttonPtr->activeGC != NULL) { |
| 3655 |
Tk_FreeGC(hboxPtr->display, buttonPtr->activeGC); |
| 3656 |
} |
| 3657 |
if (buttonPtr->normalGC != NULL) { |
| 3658 |
Tk_FreeGC(hboxPtr->display, buttonPtr->normalGC); |
| 3659 |
} |
| 3660 |
if (buttonPtr->lineGC != NULL) { |
| 3661 |
Tk_FreeGC(hboxPtr->display, buttonPtr->lineGC); |
| 3662 |
} |
| 3663 |
DestroyTree(hboxPtr, hboxPtr->rootPtr); |
| 3664 |
Blt_DeleteHashTable(&(hboxPtr->nodeTable)); |
| 3665 |
Blt_ChainReset(&(hboxPtr->selectChain)); |
| 3666 |
Blt_DeleteHashTable(&(hboxPtr->selectTable)); |
| 3667 |
Blt_DestroyBindingTable(hboxPtr->bindTable); |
| 3668 |
Blt_DestroyBindingTable(hboxPtr->buttonBindTable); |
| 3669 |
Blt_Free(hboxPtr); |
| 3670 |
} |
| 3671 |
|
| 3672 |
/* |
| 3673 |
* -------------------------------------------------------------- |
| 3674 |
* |
| 3675 |
* HierboxEventProc -- |
| 3676 |
* |
| 3677 |
* This procedure is invoked by the Tk dispatcher for various |
| 3678 |
* events on hierarchy widgets. |
| 3679 |
* |
| 3680 |
* Results: |
| 3681 |
* None. |
| 3682 |
* |
| 3683 |
* Side effects: |
| 3684 |
* When the window gets deleted, internal structures get |
| 3685 |
* cleaned up. When it gets exposed, it is redisplayed. |
| 3686 |
* |
| 3687 |
* -------------------------------------------------------------- |
| 3688 |
*/ |
| 3689 |
static void |
| 3690 |
HierboxEventProc(clientData, eventPtr) |
| 3691 |
ClientData clientData; /* Information about window. */ |
| 3692 |
XEvent *eventPtr; /* Information about event. */ |
| 3693 |
{ |
| 3694 |
Hierbox *hboxPtr = clientData; |
| 3695 |
|
| 3696 |
if (eventPtr->type == Expose) { |
| 3697 |
if (eventPtr->xexpose.count == 0) { |
| 3698 |
EventuallyRedraw(hboxPtr); |
| 3699 |
} |
| 3700 |
} else if (eventPtr->type == ConfigureNotify) { |
| 3701 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 3702 |
EventuallyRedraw(hboxPtr); |
| 3703 |
} else if ((eventPtr->type == FocusIn) || (eventPtr->type == FocusOut)) { |
| 3704 |
if (eventPtr->xfocus.detail != NotifyInferior) { |
| 3705 |
TextEdit *editPtr = &(hboxPtr->labelEdit); |
| 3706 |
|
| 3707 |
if (eventPtr->type == FocusIn) { |
| 3708 |
hboxPtr->flags |= HIERBOX_FOCUS; |
| 3709 |
} else { |
| 3710 |
hboxPtr->flags &= ~HIERBOX_FOCUS; |
| 3711 |
} |
| 3712 |
Tcl_DeleteTimerHandler(editPtr->timerToken); |
| 3713 |
if ((editPtr->active) && (hboxPtr->flags & HIERBOX_FOCUS)) { |
| 3714 |
editPtr->cursorOn = TRUE; |
| 3715 |
if (editPtr->offTime != 0) { |
| 3716 |
editPtr->timerToken = |
| 3717 |
Tcl_CreateTimerHandler(editPtr->onTime, |
| 3718 |
LabelBlinkProc, clientData); |
| 3719 |
} |
| 3720 |
} else { |
| 3721 |
editPtr->cursorOn = FALSE; |
| 3722 |
editPtr->timerToken = (Tcl_TimerToken) NULL; |
| 3723 |
} |
| 3724 |
EventuallyRedraw(hboxPtr); |
| 3725 |
} |
| 3726 |
} else if (eventPtr->type == DestroyNotify) { |
| 3727 |
if (hboxPtr->tkwin != NULL) { |
| 3728 |
hboxPtr->tkwin = NULL; |
| 3729 |
Tcl_DeleteCommandFromToken(hboxPtr->interp, hboxPtr->cmdToken); |
| 3730 |
} |
| 3731 |
if (hboxPtr->flags & HIERBOX_REDRAW) { |
| 3732 |
Tcl_CancelIdleCall(DisplayHierbox, hboxPtr); |
| 3733 |
} |
| 3734 |
if (hboxPtr->flags & SELECTION_PENDING) { |
| 3735 |
Tcl_CancelIdleCall(SelectCmdProc, hboxPtr); |
| 3736 |
} |
| 3737 |
Tcl_EventuallyFree(hboxPtr, DestroyHierbox); |
| 3738 |
} |
| 3739 |
} |
| 3740 |
|
| 3741 |
/* Selection Procedures */ |
| 3742 |
/* |
| 3743 |
*---------------------------------------------------------------------- |
| 3744 |
* |
| 3745 |
* SelectionProc -- |
| 3746 |
* |
| 3747 |
* This procedure is called back by Tk when the selection is |
| 3748 |
* requested by someone. It returns part or all of the selection |
| 3749 |
* in a buffer provided by the caller. |
| 3750 |
* |
| 3751 |
* Results: |
| 3752 |
* The return value is the number of non-NULL bytes stored at |
| 3753 |
* buffer. Buffer is filled (or partially filled) with a |
| 3754 |
* NUL-terminated string containing part or all of the |
| 3755 |
* selection, as given by offset and maxBytes. |
| 3756 |
* |
| 3757 |
* Side effects: |
| 3758 |
* None. |
| 3759 |
* |
| 3760 |
*---------------------------------------------------------------------- |
| 3761 |
*/ |
| 3762 |
static int |
| 3763 |
SelectionProc(clientData, offset, buffer, maxBytes) |
| 3764 |
ClientData clientData; /* Information about the widget. */ |
| 3765 |
int offset; /* Offset within selection of first |
| 3766 |
* character to be returned. */ |
| 3767 |
char *buffer; /* Location in which to place |
| 3768 |
* selection. */ |
| 3769 |
int maxBytes; /* Maximum number of bytes to place |
| 3770 |
* at buffer, not including terminating |
| 3771 |
* NULL character. */ |
| 3772 |
{ |
| 3773 |
Hierbox *hboxPtr = clientData; |
| 3774 |
int size; |
| 3775 |
Tcl_DString dString; |
| 3776 |
|
| 3777 |
if (!hboxPtr->exportSelection) { |
| 3778 |
return -1; |
| 3779 |
} |
| 3780 |
/* |
| 3781 |
* Retrieve the names of the selected entries. |
| 3782 |
*/ |
| 3783 |
Tcl_DStringInit(&dString); |
| 3784 |
if (hboxPtr->sortSelection) { |
| 3785 |
hboxPtr->clientData = &dString; |
| 3786 |
ApplyToTree(hboxPtr, hboxPtr->rootPtr, GetSelectedLabels, |
| 3787 |
APPLY_RECURSE | APPLY_BEFORE | APPLY_OPEN_ONLY); |
| 3788 |
} else { |
| 3789 |
Blt_ChainLink *linkPtr; |
| 3790 |
Tree *treePtr; |
| 3791 |
|
| 3792 |
for (linkPtr = Blt_ChainFirstLink(&(hboxPtr->selectChain)); |
| 3793 |
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 3794 |
treePtr = Blt_ChainGetValue(linkPtr); |
| 3795 |
Tcl_DStringAppend(&dString, treePtr->entryPtr->labelText, -1); |
| 3796 |
Tcl_DStringAppend(&dString, "\n", -1); |
| 3797 |
} |
| 3798 |
} |
| 3799 |
size = Tcl_DStringLength(&dString) - offset; |
| 3800 |
strncpy(buffer, Tcl_DStringValue(&dString) + offset, maxBytes); |
| 3801 |
Tcl_DStringFree(&dString); |
| 3802 |
buffer[maxBytes] = '\0'; |
| 3803 |
return (size > maxBytes) ? maxBytes : size; |
| 3804 |
} |
| 3805 |
|
| 3806 |
/* |
| 3807 |
*---------------------------------------------------------------------- |
| 3808 |
* |
| 3809 |
* LostSelection -- |
| 3810 |
* |
| 3811 |
* This procedure is called back by Tk when the selection is grabbed |
| 3812 |
* away. |
| 3813 |
* |
| 3814 |
* Results: |
| 3815 |
* None. |
| 3816 |
* |
| 3817 |
* Side effects: |
| 3818 |
* The existing selection is unhighlighted, and the window is |
| 3819 |
* marked as not containing a selection. |
| 3820 |
* |
| 3821 |
*---------------------------------------------------------------------- |
| 3822 |
*/ |
| 3823 |
static void |
| 3824 |
LostSelection(clientData) |
| 3825 |
ClientData clientData; /* Information about the widget. */ |
| 3826 |
{ |
| 3827 |
Hierbox *hboxPtr = clientData; |
| 3828 |
|
| 3829 |
if ((hboxPtr->selAnchorPtr != NULL) && (hboxPtr->exportSelection)) { |
| 3830 |
ClearSelection(hboxPtr); |
| 3831 |
} |
| 3832 |
} |
| 3833 |
|
| 3834 |
/* |
| 3835 |
*---------------------------------------------------------------------- |
| 3836 |
* |
| 3837 |
* HierboxInstCmdDeleteProc -- |
| 3838 |
* |
| 3839 |
* This procedure is invoked when a widget command is deleted. If |
| 3840 |
* the widget isn't already in the process of being destroyed, |
| 3841 |
* this command destroys it. |
| 3842 |
* |
| 3843 |
* Results: |
| 3844 |
* None. |
| 3845 |
* |
| 3846 |
* Side effects: |
| 3847 |
* The widget is destroyed. |
| 3848 |
* |
| 3849 |
*---------------------------------------------------------------------- |
| 3850 |
*/ |
| 3851 |
static void |
| 3852 |
HierboxInstCmdDeleteProc(clientData) |
| 3853 |
ClientData clientData; /* Pointer to widget record for widget. */ |
| 3854 |
{ |
| 3855 |
Hierbox *hboxPtr = clientData; |
| 3856 |
|
| 3857 |
/* |
| 3858 |
* This procedure could be invoked either because the window was |
| 3859 |
* destroyed and the command was then deleted (in which case tkwin |
| 3860 |
* is NULL) or because the command was deleted, and then this |
| 3861 |
* procedure destroys the widget. |
| 3862 |
*/ |
| 3863 |
if (hboxPtr->tkwin != NULL) { |
| 3864 |
Tk_Window tkwin; |
| 3865 |
|
| 3866 |
tkwin = hboxPtr->tkwin; |
| 3867 |
hboxPtr->tkwin = NULL; |
| 3868 |
Tk_DestroyWindow(tkwin); |
| 3869 |
#ifdef ITCL_NAMESPACES |
| 3870 |
Itk_SetWidgetCommand(tkwin, (Tcl_Command) NULL); |
| 3871 |
#endif /* ITCL_NAMESPACES */ |
| 3872 |
} |
| 3873 |
} |
| 3874 |
|
| 3875 |
/* |
| 3876 |
*---------------------------------------------------------------------- |
| 3877 |
* |
| 3878 |
* TileChangedProc |
| 3879 |
* |
| 3880 |
* Stub for image change notifications. Since we immediately draw |
| 3881 |
* the image into a pixmap, we don't care about image changes. |
| 3882 |
* |
| 3883 |
* It would be better if Tk checked for NULL proc pointers. |
| 3884 |
* |
| 3885 |
* Results: |
| 3886 |
* None. |
| 3887 |
* |
| 3888 |
*---------------------------------------------------------------------- |
| 3889 |
*/ |
| 3890 |
/*ARGSUSED*/ |
| 3891 |
static void |
| 3892 |
TileChangedProc(clientData, tile) |
| 3893 |
ClientData clientData; |
| 3894 |
Blt_Tile tile; /* Not used. */ |
| 3895 |
{ |
| 3896 |
Hierbox *hboxPtr = clientData; |
| 3897 |
|
| 3898 |
if (hboxPtr->tkwin != NULL) { |
| 3899 |
EventuallyRedraw(hboxPtr); |
| 3900 |
} |
| 3901 |
} |
| 3902 |
|
| 3903 |
/* |
| 3904 |
* ---------------------------------------------------------------------- |
| 3905 |
* |
| 3906 |
* ConfigureHierbox -- |
| 3907 |
* |
| 3908 |
* This procedure is called to process an argv/argc list, plus |
| 3909 |
* the Tk option database, in order to configure (or reconfigure) |
| 3910 |
* the widget. |
| 3911 |
* |
| 3912 |
* Results: |
| 3913 |
* The return value is a standard Tcl result. If TCL_ERROR is |
| 3914 |
* returned, then interp->result contains an error message. |
| 3915 |
* |
| 3916 |
* Side effects: |
| 3917 |
* Configuration information, such as text string, colors, font, |
| 3918 |
* etc. get set for hboxPtr; old resources get freed, if there |
| 3919 |
* were any. The widget is redisplayed. |
| 3920 |
* |
| 3921 |
* ---------------------------------------------------------------------- |
| 3922 |
*/ |
| 3923 |
static int |
| 3924 |
ConfigureHierbox(interp, hboxPtr, argc, argv, flags) |
| 3925 |
Tcl_Interp *interp; /* Interpreter to report errors back to. */ |
| 3926 |
Hierbox *hboxPtr; /* Information about widget; may or may not |
| 3927 |
* already have values for some fields. */ |
| 3928 |
int argc; |
| 3929 |
CONST char **argv; |
| 3930 |
int flags; |
| 3931 |
{ |
| 3932 |
XGCValues gcValues; |
| 3933 |
unsigned long gcMask; |
| 3934 |
GC newGC; |
| 3935 |
Tk_Uid nameId; |
| 3936 |
Pixmap bitmap; |
| 3937 |
hierBox = hboxPtr; |
| 3938 |
if (Blt_ConfigureWidget(interp, hboxPtr->tkwin, configSpecs, argc, argv, |
| 3939 |
(char *)hboxPtr, flags) != TCL_OK) { |
| 3940 |
return TCL_ERROR; |
| 3941 |
} |
| 3942 |
if (Blt_ConfigModified(configSpecs, interp, "-font", "-linespacing", "-width", |
| 3943 |
"-height", "-hideroot", (char *)NULL)) { |
| 3944 |
/* |
| 3945 |
* These options change the layout of the box. Mark for |
| 3946 |
* update. |
| 3947 |
*/ |
| 3948 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 3949 |
} |
| 3950 |
if ((hboxPtr->reqHeight != Tk_ReqHeight(hboxPtr->tkwin)) || |
| 3951 |
(hboxPtr->reqWidth != Tk_ReqWidth(hboxPtr->tkwin))) { |
| 3952 |
Tk_GeometryRequest(hboxPtr->tkwin, hboxPtr->reqWidth, |
| 3953 |
hboxPtr->reqHeight); |
| 3954 |
} |
| 3955 |
gcMask = (GCForeground | GCLineWidth); |
| 3956 |
gcValues.foreground = hboxPtr->lineColor->pixel; |
| 3957 |
gcValues.line_width = hboxPtr->lineWidth; |
| 3958 |
if (hboxPtr->dashes > 0) { |
| 3959 |
gcMask |= (GCLineStyle | GCDashList); |
| 3960 |
gcValues.line_style = LineOnOffDash; |
| 3961 |
gcValues.dashes = hboxPtr->dashes; |
| 3962 |
} |
| 3963 |
newGC = Tk_GetGC(hboxPtr->tkwin, gcMask, &gcValues); |
| 3964 |
if (hboxPtr->lineGC != NULL) { |
| 3965 |
Tk_FreeGC(hboxPtr->display, hboxPtr->lineGC); |
| 3966 |
} |
| 3967 |
hboxPtr->lineGC = newGC; |
| 3968 |
|
| 3969 |
/* |
| 3970 |
* GC for active label. Dashed outline. |
| 3971 |
*/ |
| 3972 |
gcMask = GCForeground | GCLineStyle; |
| 3973 |
gcValues.foreground = hboxPtr->focusColor->pixel; |
| 3974 |
gcValues.line_style = (LineIsDashed(hboxPtr->focusDashes)) |
| 3975 |
? LineOnOffDash : LineSolid; |
| 3976 |
newGC = Blt_GetPrivateGC(hboxPtr->tkwin, gcMask, &gcValues); |
| 3977 |
if (LineIsDashed(hboxPtr->focusDashes)) { |
| 3978 |
hboxPtr->focusDashes.offset = 2; |
| 3979 |
Blt_SetDashes(hboxPtr->display, newGC, &(hboxPtr->focusDashes)); |
| 3980 |
} |
| 3981 |
if (hboxPtr->focusGC != NULL) { |
| 3982 |
Blt_FreePrivateGC(hboxPtr->display, hboxPtr->focusGC); |
| 3983 |
} |
| 3984 |
hboxPtr->focusGC = newGC; |
| 3985 |
|
| 3986 |
if (hboxPtr->iconBitmap == None) { |
| 3987 |
nameId = Tk_GetUid("HierboxFolder"); |
| 3988 |
bitmap = Tk_GetBitmap(interp, hboxPtr->tkwin, nameId); |
| 3989 |
if (bitmap == None) { |
| 3990 |
if (Tk_DefineBitmap(interp, nameId, (char *)folderBits, |
| 3991 |
DEF_ICON_WIDTH, DEF_ICON_HEIGHT) != TCL_OK) { |
| 3992 |
return TCL_ERROR; |
| 3993 |
} |
| 3994 |
bitmap = Tk_GetBitmap(interp, hboxPtr->tkwin, nameId); |
| 3995 |
if (bitmap == None) { |
| 3996 |
return TCL_ERROR; |
| 3997 |
} |
| 3998 |
} |
| 3999 |
hboxPtr->iconBitmap = bitmap; |
| 4000 |
Tcl_ResetResult(interp); |
| 4001 |
} |
| 4002 |
if (hboxPtr->iconMask == None) { |
| 4003 |
nameId = Tk_GetUid("HierboxFolderMask"); |
| 4004 |
bitmap = Tk_GetBitmap(interp, hboxPtr->tkwin, nameId); |
| 4005 |
if (bitmap == None) { |
| 4006 |
if (Tk_DefineBitmap(interp, nameId, (char *)folderMaskBits, |
| 4007 |
DEF_ICON_WIDTH, DEF_ICON_HEIGHT) != TCL_OK) { |
| 4008 |
return TCL_ERROR; |
| 4009 |
} |
| 4010 |
bitmap = Tk_GetBitmap(interp, hboxPtr->tkwin, nameId); |
| 4011 |
if (bitmap == None) { |
| 4012 |
return TCL_ERROR; |
| 4013 |
} |
| 4014 |
} |
| 4015 |
hboxPtr->iconMask = bitmap; |
| 4016 |
Tcl_ResetResult(interp); |
| 4017 |
} |
| 4018 |
if (hboxPtr->iconColor == NULL) { |
| 4019 |
hboxPtr->iconColor = Tk_GetColor(interp, hboxPtr->tkwin, |
| 4020 |
Tk_GetUid("yellow")); |
| 4021 |
if (hboxPtr->iconColor == NULL) { |
| 4022 |
return TCL_ERROR; |
| 4023 |
} |
| 4024 |
} |
| 4025 |
if (hboxPtr->tile != NULL) { |
| 4026 |
Blt_SetTileChangedProc(hboxPtr->tile, TileChangedProc, hboxPtr); |
| 4027 |
} |
| 4028 |
ConfigureButtons(hboxPtr); |
| 4029 |
|
| 4030 |
hboxPtr->inset = hboxPtr->highlightWidth + hboxPtr->borderWidth + INSET_PAD; |
| 4031 |
EventuallyRedraw(hboxPtr); |
| 4032 |
return TCL_OK; |
| 4033 |
} |
| 4034 |
|
| 4035 |
/* |
| 4036 |
* ---------------------------------------------------------------------- |
| 4037 |
* |
| 4038 |
* ResetCoordinates -- |
| 4039 |
* |
| 4040 |
* Determines the maximum height of all visible entries. |
| 4041 |
* |
| 4042 |
* Results: |
| 4043 |
* Returns 1 if beyond the last visible entry, 0 otherwise. |
| 4044 |
* |
| 4045 |
* Side effects: |
| 4046 |
* The array of visible nodes is filled. |
| 4047 |
* |
| 4048 |
* ---------------------------------------------------------------------- |
| 4049 |
*/ |
| 4050 |
static void |
| 4051 |
ResetCoordinates(hboxPtr, treePtr, infoPtr) |
| 4052 |
Hierbox *hboxPtr; |
| 4053 |
Tree *treePtr; |
| 4054 |
LayoutInfo *infoPtr; |
| 4055 |
{ |
| 4056 |
Entry *entryPtr = treePtr->entryPtr; |
| 4057 |
int width; |
| 4058 |
|
| 4059 |
/* |
| 4060 |
* If the entry is hidden, then do nothing. |
| 4061 |
* Otherwise, include it in the layout. |
| 4062 |
*/ |
| 4063 |
entryPtr->worldY = infoPtr->y; |
| 4064 |
if (!(entryPtr->flags & ENTRY_MAPPED)) { |
| 4065 |
return; |
| 4066 |
} |
| 4067 |
treePtr->level = infoPtr->level; |
| 4068 |
if (infoPtr->depth < infoPtr->level) { |
| 4069 |
infoPtr->depth = infoPtr->level; |
| 4070 |
} |
| 4071 |
if ((entryPtr->flags & BUTTON_SHOW) || ((entryPtr->flags & BUTTON_AUTO) && |
| 4072 |
(Blt_ChainGetLength(treePtr->chainPtr) > 0))) { |
| 4073 |
entryPtr->flags |= ENTRY_BUTTON; |
| 4074 |
} else { |
| 4075 |
entryPtr->flags &= ~ENTRY_BUTTON; |
| 4076 |
} |
| 4077 |
if (entryPtr->height < infoPtr->minHeight) { |
| 4078 |
infoPtr->minHeight = entryPtr->height; |
| 4079 |
} |
| 4080 |
/* |
| 4081 |
* Note: The maximum entry width below does not take into account |
| 4082 |
* the space for the icon (level offset). This has to be |
| 4083 |
* deferred because it's dependent upon the maximum icon |
| 4084 |
* size. |
| 4085 |
*/ |
| 4086 |
width = infoPtr->x + entryPtr->width; |
| 4087 |
if (width > infoPtr->maxWidth) { |
| 4088 |
infoPtr->maxWidth = width; |
| 4089 |
} |
| 4090 |
if (infoPtr->maxIconWidth < entryPtr->iconWidth) { |
| 4091 |
infoPtr->maxIconWidth = entryPtr->iconWidth; |
| 4092 |
} |
| 4093 |
entryPtr->lineHeight = -(infoPtr->y); |
| 4094 |
infoPtr->y += entryPtr->height; |
| 4095 |
if (entryPtr->flags & ENTRY_OPEN) { |
| 4096 |
Blt_ChainLink *linkPtr; |
| 4097 |
int labelOffset; |
| 4098 |
Tree *bottomPtr; |
| 4099 |
|
| 4100 |
infoPtr->level++; |
| 4101 |
labelOffset = infoPtr->labelOffset; |
| 4102 |
infoPtr->labelOffset = 0; |
| 4103 |
bottomPtr = treePtr; |
| 4104 |
for (linkPtr = Blt_ChainFirstLink(treePtr->chainPtr); linkPtr != NULL; |
| 4105 |
linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 4106 |
treePtr = Blt_ChainGetValue(linkPtr); |
| 4107 |
if (treePtr->entryPtr->flags & ENTRY_MAPPED) { |
| 4108 |
ResetCoordinates(hboxPtr, treePtr, infoPtr); |
| 4109 |
bottomPtr = treePtr; |
| 4110 |
} |
| 4111 |
} |
| 4112 |
infoPtr->level--; |
| 4113 |
entryPtr->lineHeight += bottomPtr->entryPtr->worldY; |
| 4114 |
entryPtr->levelX = infoPtr->labelOffset; |
| 4115 |
infoPtr->labelOffset = labelOffset; |
| 4116 |
} |
| 4117 |
if (infoPtr->labelOffset < entryPtr->labelWidth) { |
| 4118 |
infoPtr->labelOffset = entryPtr->labelWidth; |
| 4119 |
} |
| 4120 |
} |
| 4121 |
|
| 4122 |
/* |
| 4123 |
* ---------------------------------------------------------------------- |
| 4124 |
* |
| 4125 |
* ComputeWidths -- |
| 4126 |
* |
| 4127 |
* Determines the maximum height of all visible entries. |
| 4128 |
* |
| 4129 |
* Results: |
| 4130 |
* Returns 1 if beyond the last visible entry, 0 otherwise. |
| 4131 |
* |
| 4132 |
* Side effects: |
| 4133 |
* The array of visible nodes is filled. |
| 4134 |
* |
| 4135 |
* ---------------------------------------------------------------------- |
| 4136 |
*/ |
| 4137 |
static void |
| 4138 |
ComputeWidths(hboxPtr, treePtr) |
| 4139 |
Hierbox *hboxPtr; |
| 4140 |
Tree *treePtr; |
| 4141 |
{ |
| 4142 |
Entry *entryPtr = treePtr->entryPtr; |
| 4143 |
|
| 4144 |
if (!(entryPtr->flags & ENTRY_MAPPED)) { |
| 4145 |
return; |
| 4146 |
} |
| 4147 |
if (entryPtr->iconWidth > LEVELWIDTH(treePtr->level + 1)) { |
| 4148 |
LEVELWIDTH(treePtr->level + 1) = entryPtr->iconWidth; |
| 4149 |
} |
| 4150 |
if (entryPtr->flags & ENTRY_OPEN) { |
| 4151 |
Blt_ChainLink *linkPtr; |
| 4152 |
|
| 4153 |
for (linkPtr = Blt_ChainFirstLink(treePtr->chainPtr); linkPtr != NULL; |
| 4154 |
linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 4155 |
treePtr = Blt_ChainGetValue(linkPtr); |
| 4156 |
if (treePtr->entryPtr->flags & ENTRY_MAPPED) { |
| 4157 |
ComputeWidths(hboxPtr, treePtr); |
| 4158 |
} |
| 4159 |
} |
| 4160 |
} |
| 4161 |
} |
| 4162 |
|
| 4163 |
/* |
| 4164 |
* ---------------------------------------------------------------------- |
| 4165 |
* |
| 4166 |
* ComputeLayout -- |
| 4167 |
* |
| 4168 |
* Recompute the layout when entries are opened/closed, |
| 4169 |
* inserted/deleted, or when text attributes change (such as |
| 4170 |
* font, linespacing). |
| 4171 |
* |
| 4172 |
* Results: |
| 4173 |
* None. |
| 4174 |
* |
| 4175 |
* Side effects: |
| 4176 |
* The world coordinates are set for all the opened entries. |
| 4177 |
* |
| 4178 |
* ---------------------------------------------------------------------- |
| 4179 |
*/ |
| 4180 |
static void |
| 4181 |
ComputeLayout(hboxPtr) |
| 4182 |
Hierbox *hboxPtr; |
| 4183 |
{ |
| 4184 |
LayoutInfo info; |
| 4185 |
|
| 4186 |
info.level = info.depth = 0; |
| 4187 |
info.x = info.y = 0; |
| 4188 |
info.maxWidth = hboxPtr->button.width; |
| 4189 |
info.maxIconWidth = hboxPtr->button.width; |
| 4190 |
info.minHeight = INT_MAX; |
| 4191 |
info.labelOffset = 0; |
| 4192 |
|
| 4193 |
if (hboxPtr->hideRoot) { |
| 4194 |
info.y = -(hboxPtr->rootPtr->entryPtr->height); |
| 4195 |
} |
| 4196 |
ResetCoordinates(hboxPtr, hboxPtr->rootPtr, &info); |
| 4197 |
|
| 4198 |
hboxPtr->xScrollUnits = info.maxIconWidth; |
| 4199 |
hboxPtr->minHeight = hboxPtr->yScrollUnits = info.minHeight; |
| 4200 |
if (hboxPtr->reqScrollX > 0) { |
| 4201 |
hboxPtr->xScrollUnits = hboxPtr->reqScrollX; |
| 4202 |
} |
| 4203 |
if (hboxPtr->reqScrollY > 0) { |
| 4204 |
hboxPtr->yScrollUnits = hboxPtr->reqScrollY; |
| 4205 |
} |
| 4206 |
hboxPtr->depth = info.depth + 1; |
| 4207 |
hboxPtr->worldWidth = info.maxWidth + (hboxPtr->depth * info.maxIconWidth); |
| 4208 |
if (hboxPtr->worldWidth < 1) { |
| 4209 |
hboxPtr->worldWidth = 1; |
| 4210 |
} |
| 4211 |
hboxPtr->worldHeight = info.y; |
| 4212 |
if (hboxPtr->worldHeight < 1) { |
| 4213 |
hboxPtr->worldHeight = 1; |
| 4214 |
} |
| 4215 |
if (hboxPtr->yScrollUnits < 1) { |
| 4216 |
hboxPtr->yScrollUnits = 1; |
| 4217 |
} |
| 4218 |
if (hboxPtr->xScrollUnits < 1) { |
| 4219 |
hboxPtr->xScrollUnits = 1; |
| 4220 |
} |
| 4221 |
if (hboxPtr->levelInfo != NULL) { |
| 4222 |
Blt_Free(hboxPtr->levelInfo); |
| 4223 |
} |
| 4224 |
hboxPtr->levelInfo = Blt_Calloc(hboxPtr->depth + 2, sizeof(LevelInfo)); |
| 4225 |
assert(hboxPtr->levelInfo); |
| 4226 |
ComputeWidths(hboxPtr, hboxPtr->rootPtr); |
| 4227 |
{ |
| 4228 |
int sum, width; |
| 4229 |
register int i; |
| 4230 |
|
| 4231 |
sum = 0; |
| 4232 |
for (i = 0; i <= hboxPtr->depth; i++) { |
| 4233 |
width = hboxPtr->levelInfo[i].width; |
| 4234 |
width |= 0x01; |
| 4235 |
hboxPtr->levelInfo[i].width = width; |
| 4236 |
sum += width; |
| 4237 |
hboxPtr->levelInfo[i + 1].x = sum; |
| 4238 |
} |
| 4239 |
} |
| 4240 |
hboxPtr->flags &= ~HIERBOX_LAYOUT; |
| 4241 |
} |
| 4242 |
|
| 4243 |
/* |
| 4244 |
* ---------------------------------------------------------------------- |
| 4245 |
* |
| 4246 |
* ComputeVisibleEntries -- |
| 4247 |
* |
| 4248 |
* The entries visible in the viewport (the widget's window) are |
| 4249 |
* inserted into the array of visible nodes. |
| 4250 |
* |
| 4251 |
* Results: |
| 4252 |
* Returns 1 if beyond the last visible entry, 0 otherwise. |
| 4253 |
* |
| 4254 |
* Side effects: |
| 4255 |
* The array of visible nodes is filled. |
| 4256 |
* |
| 4257 |
* ---------------------------------------------------------------------- |
| 4258 |
*/ |
| 4259 |
static int |
| 4260 |
ComputeVisibleEntries(hboxPtr) |
| 4261 |
Hierbox *hboxPtr; |
| 4262 |
{ |
| 4263 |
Entry *entryPtr; |
| 4264 |
int height; |
| 4265 |
Blt_ChainLink *linkPtr; |
| 4266 |
register Tree *treePtr; |
| 4267 |
int x, maxX; |
| 4268 |
int nSlots; |
| 4269 |
|
| 4270 |
hboxPtr->xOffset = Blt_AdjustViewport(hboxPtr->xOffset, hboxPtr->worldWidth, |
| 4271 |
VPORTWIDTH(hboxPtr), hboxPtr->xScrollUnits, hboxPtr->scrollMode); |
| 4272 |
hboxPtr->yOffset = Blt_AdjustViewport(hboxPtr->yOffset, |
| 4273 |
hboxPtr->worldHeight, VPORTHEIGHT(hboxPtr), hboxPtr->yScrollUnits, |
| 4274 |
hboxPtr->scrollMode); |
| 4275 |
|
| 4276 |
height = VPORTHEIGHT(hboxPtr); |
| 4277 |
|
| 4278 |
/* Allocate worst case number of slots for entry array. */ |
| 4279 |
nSlots = (height / hboxPtr->minHeight) + 3; |
| 4280 |
if (/*(nSlots != hboxPtr->nVisible) && */(hboxPtr->visibleArr != NULL)) { |
| 4281 |
Blt_Free(hboxPtr->visibleArr); |
| 4282 |
} |
| 4283 |
hboxPtr->visibleArr = Blt_Calloc(nSlots, sizeof(Tree *)); |
| 4284 |
assert(hboxPtr->visibleArr); |
| 4285 |
hboxPtr->nVisible = 0; |
| 4286 |
|
| 4287 |
/* Find the node where the view port starts. */ |
| 4288 |
treePtr = hboxPtr->rootPtr; |
| 4289 |
entryPtr = treePtr->entryPtr; |
| 4290 |
while ((entryPtr->worldY + entryPtr->height) <= hboxPtr->yOffset) { |
| 4291 |
for (linkPtr = Blt_ChainLastLink(treePtr->chainPtr); linkPtr != NULL; |
| 4292 |
linkPtr = Blt_ChainPrevLink(linkPtr)) { |
| 4293 |
treePtr = Blt_ChainGetValue(linkPtr); |
| 4294 |
if (IsHidden(treePtr)) { |
| 4295 |
continue; /* Ignore hidden entries. */ |
| 4296 |
} |
| 4297 |
entryPtr = treePtr->entryPtr; |
| 4298 |
if (entryPtr->worldY <= hboxPtr->yOffset) { |
| 4299 |
break; |
| 4300 |
} |
| 4301 |
} |
| 4302 |
|
| 4303 |
/* |
| 4304 |
* If we can't find the starting node, then the view must be |
| 4305 |
* scrolled down, but some nodes were deleted. Reset the view |
| 4306 |
* back to the top and try again. |
| 4307 |
*/ |
| 4308 |
if (linkPtr == NULL) { |
| 4309 |
if (hboxPtr->yOffset == 0) { |
| 4310 |
return TCL_OK; /* All entries are hidden. */ |
| 4311 |
} |
| 4312 |
hboxPtr->yOffset = 0; |
| 4313 |
continue; |
| 4314 |
} |
| 4315 |
} |
| 4316 |
|
| 4317 |
height += hboxPtr->yOffset; |
| 4318 |
maxX = 0; |
| 4319 |
while (treePtr != NULL) { |
| 4320 |
if (!IsHidden(treePtr)) { |
| 4321 |
entryPtr = treePtr->entryPtr; |
| 4322 |
/* |
| 4323 |
* Compute and save the entry's X-coordinate now that we know |
| 4324 |
* what the maximum level offset for the entire Hierbox is. |
| 4325 |
*/ |
| 4326 |
entryPtr->worldX = LEVELX(treePtr->level); |
| 4327 |
x = entryPtr->worldX + LEVELWIDTH(treePtr->level) + |
| 4328 |
LEVELWIDTH(treePtr->level + 1) + entryPtr->width; |
| 4329 |
if (x > maxX) { |
| 4330 |
maxX = x; |
| 4331 |
} |
| 4332 |
if (entryPtr->worldY >= height) { |
| 4333 |
break; |
| 4334 |
} |
| 4335 |
hboxPtr->visibleArr[hboxPtr->nVisible] = treePtr; |
| 4336 |
hboxPtr->nVisible++; |
| 4337 |
} |
| 4338 |
treePtr = NextNode(treePtr, ENTRY_OPEN | ENTRY_MAPPED); |
| 4339 |
} |
| 4340 |
hboxPtr->worldWidth = maxX; |
| 4341 |
|
| 4342 |
/* |
| 4343 |
* ------------------------------------------------------------------- |
| 4344 |
* |
| 4345 |
* Note: It's assumed that the view port always starts at or |
| 4346 |
* over an entry. Check that a change in the hierarchy |
| 4347 |
* (e.g. closing a node) hasn't left the viewport beyond |
| 4348 |
* the last entry. If so, adjust the viewport to start |
| 4349 |
* on the last entry. |
| 4350 |
* |
| 4351 |
* ------------------------------------------------------------------- |
| 4352 |
*/ |
| 4353 |
if (hboxPtr->xOffset > (hboxPtr->worldWidth - hboxPtr->xScrollUnits)) { |
| 4354 |
hboxPtr->xOffset = hboxPtr->worldWidth - hboxPtr->xScrollUnits; |
| 4355 |
} |
| 4356 |
if (hboxPtr->yOffset > (hboxPtr->worldHeight - hboxPtr->yScrollUnits)) { |
| 4357 |
hboxPtr->yOffset = hboxPtr->worldHeight - hboxPtr->yScrollUnits; |
| 4358 |
} |
| 4359 |
hboxPtr->xOffset = Blt_AdjustViewport(hboxPtr->xOffset, hboxPtr->worldWidth, |
| 4360 |
VPORTWIDTH(hboxPtr), hboxPtr->xScrollUnits, hboxPtr->scrollMode); |
| 4361 |
hboxPtr->yOffset = Blt_AdjustViewport(hboxPtr->yOffset, |
| 4362 |
hboxPtr->worldHeight, VPORTHEIGHT(hboxPtr), hboxPtr->yScrollUnits, |
| 4363 |
hboxPtr->scrollMode); |
| 4364 |
hboxPtr->flags &= ~HIERBOX_DIRTY; |
| 4365 |
return TCL_OK; |
| 4366 |
} |
| 4367 |
|
| 4368 |
static int |
| 4369 |
GetCursorLocation(hboxPtr, treePtr) |
| 4370 |
Hierbox *hboxPtr; |
| 4371 |
Tree *treePtr; |
| 4372 |
{ |
| 4373 |
TextEdit *editPtr = &(hboxPtr->labelEdit); |
| 4374 |
int x, y; |
| 4375 |
int maxLines; |
| 4376 |
Tk_Font font; |
| 4377 |
TextStyle ts; |
| 4378 |
TextLayout *textPtr; |
| 4379 |
Tk_FontMetrics fontMetrics; |
| 4380 |
int nBytes; |
| 4381 |
int sum; |
| 4382 |
Entry *entryPtr; |
| 4383 |
TextFragment *fragPtr; |
| 4384 |
register int i; |
| 4385 |
|
| 4386 |
entryPtr = treePtr->entryPtr; |
| 4387 |
font = GETFONT(hboxPtr, entryPtr->labelFont); |
| 4388 |
memset(&ts, 0, sizeof(TextStyle)); |
| 4389 |
ts.font = font; |
| 4390 |
ts.justify = TK_JUSTIFY_LEFT; |
| 4391 |
ts.shadow.offset = entryPtr->labelShadow.offset; |
| 4392 |
textPtr = Blt_GetTextLayout(entryPtr->labelText, &ts); |
| 4393 |
|
| 4394 |
Tk_GetFontMetrics(font, &fontMetrics); |
| 4395 |
maxLines = (textPtr->height / fontMetrics.linespace) - 1; |
| 4396 |
|
| 4397 |
sum = 0; |
| 4398 |
x = y = 0; |
| 4399 |
|
| 4400 |
fragPtr = textPtr->fragArr; |
| 4401 |
for (i = 0; i <= maxLines; i++) { |
| 4402 |
/* Total the number of bytes on each line. Include newlines. */ |
| 4403 |
nBytes = fragPtr->count + 1; |
| 4404 |
if ((sum + nBytes) > editPtr->insertPos) { |
| 4405 |
x += Tk_TextWidth(font, fragPtr->text, editPtr->insertPos - sum); |
| 4406 |
break; |
| 4407 |
} |
| 4408 |
y += fontMetrics.linespace; |
| 4409 |
sum += nBytes; |
| 4410 |
fragPtr++; |
| 4411 |
} |
| 4412 |
editPtr->x = x; |
| 4413 |
editPtr->y = y; |
| 4414 |
editPtr->height = fontMetrics.linespace; |
| 4415 |
editPtr->width = 3; |
| 4416 |
Blt_Free(textPtr); |
| 4417 |
return TCL_OK; |
| 4418 |
} |
| 4419 |
|
| 4420 |
/* |
| 4421 |
* --------------------------------------------------------------------------- |
| 4422 |
* |
| 4423 |
* DrawVerticals -- |
| 4424 |
* |
| 4425 |
* Draws vertical lines for the ancestor nodes. While the entry |
| 4426 |
* of the ancestor may not be visible, its vertical line segment |
| 4427 |
* does extent into the viewport. So walk back up the hierarchy |
| 4428 |
* drawing lines until we get to the root. |
| 4429 |
* |
| 4430 |
* Results: |
| 4431 |
* None. |
| 4432 |
* |
| 4433 |
* Side Effects: |
| 4434 |
* Vertical lines are drawn for the ancestor nodes. |
| 4435 |
* |
| 4436 |
* --------------------------------------------------------------------------- |
| 4437 |
*/ |
| 4438 |
static void |
| 4439 |
DrawVerticals(hboxPtr, treePtr, drawable) |
| 4440 |
Hierbox *hboxPtr; /* Widget record containing the attribute |
| 4441 |
* information for buttons. */ |
| 4442 |
Tree *treePtr; /* Entry to be drawn. */ |
| 4443 |
Drawable drawable; /* Pixmap or window to draw into. */ |
| 4444 |
{ |
| 4445 |
Entry *entryPtr; /* Entry to be drawn. */ |
| 4446 |
int x1, y1i, x2, y2; |
| 4447 |
int height; |
| 4448 |
int x, y; |
| 4449 |
|
| 4450 |
while (treePtr->parentPtr != NULL) { |
| 4451 |
treePtr = treePtr->parentPtr; |
| 4452 |
entryPtr = treePtr->entryPtr; |
| 4453 |
|
| 4454 |
/* |
| 4455 |
* World X-coordinates are computed only for entries that are in |
| 4456 |
* the current view port. So for each of the off-screen ancestor |
| 4457 |
* nodes we must compute it here too. |
| 4458 |
*/ |
| 4459 |
entryPtr->worldX = LEVELX(treePtr->level); |
| 4460 |
x = SCREENX(hboxPtr, entryPtr->worldX); |
| 4461 |
y = SCREENY(hboxPtr, entryPtr->worldY); |
| 4462 |
height = MAX(entryPtr->iconHeight, hboxPtr->button.height); |
| 4463 |
y += (height - hboxPtr->button.height) / 2; |
| 4464 |
x1 = x2 = x + LEVELWIDTH(treePtr->level) + |
| 4465 |
LEVELWIDTH(treePtr->level + 1) / 2; |
| 4466 |
y1i = y + hboxPtr->button.height / 2; |
| 4467 |
y2 = y1i + entryPtr->lineHeight; |
| 4468 |
if ((treePtr == hboxPtr->rootPtr) && (hboxPtr->hideRoot)) { |
| 4469 |
y1i += entryPtr->height; |
| 4470 |
} |
| 4471 |
/* |
| 4472 |
* Clip the line's Y-coordinates at the window border. |
| 4473 |
*/ |
| 4474 |
if (y1i < 0) { |
| 4475 |
y1i = 0; |
| 4476 |
} |
| 4477 |
if (y2 > Tk_Height(hboxPtr->tkwin)) { |
| 4478 |
y2 = Tk_Height(hboxPtr->tkwin); |
| 4479 |
} |
| 4480 |
if ((y1i < Tk_Height(hboxPtr->tkwin)) && (y2 > 0)) { |
| 4481 |
XDrawLine(hboxPtr->display, drawable, hboxPtr->lineGC, x1, y1i, |
| 4482 |
x2, y2); |
| 4483 |
} |
| 4484 |
} |
| 4485 |
} |
| 4486 |
|
| 4487 |
/* |
| 4488 |
* --------------------------------------------------------------------------- |
| 4489 |
* |
| 4490 |
* DrawButton -- |
| 4491 |
* |
| 4492 |
* Draws a button for the given entry. The button is drawn |
| 4493 |
* centered in the region immediately to the left of the origin |
| 4494 |
* of the entry (computed in the layout routines). The height |
| 4495 |
* and width of the button were previously calculated from the |
| 4496 |
* average row height. |
| 4497 |
* |
| 4498 |
* button height = entry height - (2 * some arbitrary padding). |
| 4499 |
* button width = button height. |
| 4500 |
* |
| 4501 |
* The button may have a border. The symbol (either a plus or |
| 4502 |
* minus) is slight smaller than the width or height minus the |
| 4503 |
* border. |
| 4504 |
* |
| 4505 |
* x,y origin of entry |
| 4506 |
* |
| 4507 |
* +---+ |
| 4508 |
* | + | icon label |
| 4509 |
* +---+ |
| 4510 |
* closed |
| 4511 |
* |
| 4512 |
* |----|----| horizontal offset |
| 4513 |
* |
| 4514 |
* +---+ |
| 4515 |
* | - | icon label |
| 4516 |
* +---+ |
| 4517 |
* open |
| 4518 |
* |
| 4519 |
* Results: |
| 4520 |
* None. |
| 4521 |
* |
| 4522 |
* Side Effects: |
| 4523 |
* A button is drawn for the entry. |
| 4524 |
* |
| 4525 |
* --------------------------------------------------------------------------- |
| 4526 |
*/ |
| 4527 |
static void |
| 4528 |
DrawButton(hboxPtr, treePtr, drawable) |
| 4529 |
Hierbox *hboxPtr; /* Widget record containing the attribute |
| 4530 |
* information for buttons. */ |
| 4531 |
Tree *treePtr; /* Node of entry. */ |
| 4532 |
Drawable drawable; /* Pixmap or window to draw into. */ |
| 4533 |
{ |
| 4534 |
ButtonAttributes *buttonPtr = &(hboxPtr->button); |
| 4535 |
Entry *entryPtr; |
| 4536 |
int relief; |
| 4537 |
Tk_3DBorder border; |
| 4538 |
GC gc, lineGC; |
| 4539 |
int x, y; |
| 4540 |
CachedImage image; |
| 4541 |
int width, height; |
| 4542 |
|
| 4543 |
entryPtr = treePtr->entryPtr; |
| 4544 |
|
| 4545 |
width = LEVELWIDTH(treePtr->level); |
| 4546 |
height = MAX(entryPtr->iconHeight, buttonPtr->height); |
| 4547 |
entryPtr->buttonX = (width - buttonPtr->width) / 2; |
| 4548 |
entryPtr->buttonY = (height - buttonPtr->height) / 2; |
| 4549 |
|
| 4550 |
x = SCREENX(hboxPtr, entryPtr->worldX) + entryPtr->buttonX; |
| 4551 |
y = SCREENY(hboxPtr, entryPtr->worldY) + entryPtr->buttonY; |
| 4552 |
|
| 4553 |
if (treePtr == hboxPtr->activeButtonPtr) { |
| 4554 |
border = buttonPtr->activeBorder; |
| 4555 |
lineGC = buttonPtr->activeGC; |
| 4556 |
} else { |
| 4557 |
border = buttonPtr->border; |
| 4558 |
lineGC = buttonPtr->lineGC; |
| 4559 |
} |
| 4560 |
relief = (entryPtr->flags & ENTRY_OPEN) |
| 4561 |
? buttonPtr->openRelief : buttonPtr->closeRelief; |
| 4562 |
/* |
| 4563 |
* FIXME: Reliefs "flat" and "solid" the same, since there's no |
| 4564 |
* "solid" in pre-8.0 releases. Should change this when we go to a |
| 4565 |
* pure 8.x release. |
| 4566 |
*/ |
| 4567 |
if (relief == TK_RELIEF_SOLID) { |
| 4568 |
relief = TK_RELIEF_FLAT; |
| 4569 |
} |
| 4570 |
Blt_Fill3DRectangle(hboxPtr->tkwin, drawable, border, x, y, |
| 4571 |
buttonPtr->width, buttonPtr->height, buttonPtr->borderWidth, relief); |
| 4572 |
if (relief == TK_RELIEF_FLAT) { |
| 4573 |
XDrawRectangle(hboxPtr->display, drawable, lineGC, x, y, |
| 4574 |
buttonPtr->width - 1, buttonPtr->height - 1); |
| 4575 |
} |
| 4576 |
x += buttonPtr->borderWidth; |
| 4577 |
y += buttonPtr->borderWidth; |
| 4578 |
width = buttonPtr->width - (2 * buttonPtr->borderWidth); |
| 4579 |
height = buttonPtr->height - (2 * buttonPtr->borderWidth); |
| 4580 |
|
| 4581 |
image = NULL; |
| 4582 |
if (buttonPtr->images != NULL) { |
| 4583 |
/* Open or close button image? */ |
| 4584 |
image = buttonPtr->images[0]; |
| 4585 |
if ((entryPtr->flags & ENTRY_OPEN) && (buttonPtr->images[1] != NULL)) { |
| 4586 |
image = buttonPtr->images[1]; |
| 4587 |
} |
| 4588 |
} |
| 4589 |
/* Image or rectangle? */ |
| 4590 |
if (image != NULL) { |
| 4591 |
Tk_RedrawImage(ImageBits(image), 0, 0, width, height, drawable, x, y); |
| 4592 |
} else { |
| 4593 |
XSegment segArr[2]; |
| 4594 |
int count; |
| 4595 |
|
| 4596 |
gc = (treePtr == hboxPtr->activeButtonPtr) |
| 4597 |
? buttonPtr->activeGC : buttonPtr->normalGC; |
| 4598 |
count = 1; |
| 4599 |
segArr[0].y1 = segArr[0].y2 = y + height / 2; |
| 4600 |
segArr[0].x1 = x + BUTTON_IPAD; |
| 4601 |
#ifdef WIN32 |
| 4602 |
segArr[0].x2 = x + width - BUTTON_IPAD; |
| 4603 |
#else |
| 4604 |
segArr[0].x2 = x + width - BUTTON_IPAD - 1; |
| 4605 |
#endif |
| 4606 |
if (!(entryPtr->flags & ENTRY_OPEN)) { |
| 4607 |
segArr[1].x1 = segArr[1].x2 = x + width / 2; |
| 4608 |
segArr[1].y1 = y + BUTTON_IPAD; |
| 4609 |
#ifdef WIN32 |
| 4610 |
segArr[1].y2 = y + height - BUTTON_IPAD; |
| 4611 |
#else |
| 4612 |
segArr[1].y2 = y + height - BUTTON_IPAD - 1; |
| 4613 |
#endif |
| 4614 |
count++; |
| 4615 |
} |
| 4616 |
XDrawSegments(hboxPtr->display, drawable, gc, segArr, count); |
| 4617 |
} |
| 4618 |
} |
| 4619 |
|
| 4620 |
|
| 4621 |
static void |
| 4622 |
DisplayIcon(hboxPtr, treePtr, x, y, drawable) |
| 4623 |
Hierbox *hboxPtr; /* Widget record containing the attribute |
| 4624 |
* information for buttons. */ |
| 4625 |
Tree *treePtr; /* Node of entry. */ |
| 4626 |
int x, y; |
| 4627 |
Drawable drawable; /* Pixmap or window to draw into. */ |
| 4628 |
{ |
| 4629 |
Entry *entryPtr = treePtr->entryPtr; |
| 4630 |
int entryHeight; |
| 4631 |
CachedImage image; |
| 4632 |
int isActive; |
| 4633 |
|
| 4634 |
entryHeight = MAX(entryPtr->iconHeight, hboxPtr->button.height); |
| 4635 |
isActive = (treePtr == hboxPtr->activePtr); |
| 4636 |
image = NULL; |
| 4637 |
if ((isActive) && (entryPtr->activeIcons != NULL)) { |
| 4638 |
image = entryPtr->activeIcons[0]; |
| 4639 |
if ((treePtr == hboxPtr->focusPtr) && |
| 4640 |
(entryPtr->activeIcons[1] != NULL)) { |
| 4641 |
image = entryPtr->activeIcons[1]; |
| 4642 |
} |
| 4643 |
} else if (entryPtr->icons != NULL) { /* Selected or normal icon? */ |
| 4644 |
image = entryPtr->icons[0]; |
| 4645 |
if (((treePtr == hboxPtr->focusPtr) || (entryPtr->flags & ENTRY_OPEN)) |
| 4646 |
&& (entryPtr->icons[1] != NULL)) { |
| 4647 |
image = entryPtr->icons[1]; |
| 4648 |
} |
| 4649 |
} |
| 4650 |
if (image != NULL) { /* Image or default icon bitmap? */ |
| 4651 |
int width, height; |
| 4652 |
int top, bottom; |
| 4653 |
int inset; |
| 4654 |
int maxY; |
| 4655 |
|
| 4656 |
height = ImageHeight(image); |
| 4657 |
width = ImageWidth(image); |
| 4658 |
x += (LEVELWIDTH(treePtr->level + 1) - width) / 2; |
| 4659 |
y += (entryHeight - height) / 2; |
| 4660 |
inset = hboxPtr->inset - INSET_PAD; |
| 4661 |
maxY = Tk_Height(hboxPtr->tkwin) - inset; |
| 4662 |
top = 0; |
| 4663 |
bottom = y + height; |
| 4664 |
if (y < inset) { |
| 4665 |
height += y - inset; |
| 4666 |
top = -y + inset; |
| 4667 |
y = inset; |
| 4668 |
} else if (bottom >= maxY) { |
| 4669 |
height = maxY - y; |
| 4670 |
} |
| 4671 |
Tk_RedrawImage(ImageBits(image), 0, top, width, height, drawable, x, y); |
| 4672 |
} else { |
| 4673 |
x += (LEVELWIDTH(treePtr->level + 1) - DEF_ICON_WIDTH) / 2; |
| 4674 |
y += (entryHeight - DEF_ICON_HEIGHT) / 2; |
| 4675 |
XSetClipOrigin(hboxPtr->display, entryPtr->iconGC, x, y); |
| 4676 |
XCopyPlane(hboxPtr->display, hboxPtr->iconBitmap, drawable, |
| 4677 |
entryPtr->iconGC, 0, 0, DEF_ICON_WIDTH, DEF_ICON_HEIGHT, x, y, 1); |
| 4678 |
} |
| 4679 |
} |
| 4680 |
|
| 4681 |
static void |
| 4682 |
DrawData(hboxPtr, treePtr, x, y, entryHeight, drawable) |
| 4683 |
Hierbox *hboxPtr; /* Widget record containing the attribute |
| 4684 |
* information for buttons. */ |
| 4685 |
Tree *treePtr; /* Node of entry. */ |
| 4686 |
int x, y; |
| 4687 |
int entryHeight; |
| 4688 |
Drawable drawable; /* Pixmap or window to draw into. */ |
| 4689 |
{ |
| 4690 |
Entry *entryPtr = treePtr->entryPtr; |
| 4691 |
/* |
| 4692 |
* Auxillary data: text string or images. |
| 4693 |
*/ |
| 4694 |
if (entryPtr->images != NULL) { |
| 4695 |
register CachedImage *imagePtr; |
| 4696 |
int imageY; |
| 4697 |
|
| 4698 |
for (imagePtr = entryPtr->images; *imagePtr != NULL; imagePtr++) { |
| 4699 |
imageY = y; |
| 4700 |
if (ImageHeight(*imagePtr) < entryHeight) { |
| 4701 |
imageY += (entryHeight - ImageHeight(*imagePtr)) / 2; |
| 4702 |
} |
| 4703 |
Tk_RedrawImage(ImageBits(*imagePtr), 0, 0, ImageWidth(*imagePtr), |
| 4704 |
ImageHeight(*imagePtr), drawable, x, imageY); |
| 4705 |
x += ImageWidth(*imagePtr); |
| 4706 |
} |
| 4707 |
} else if (entryPtr->dataText != NULL) { |
| 4708 |
TextStyle ts; |
| 4709 |
Tk_Font font; |
| 4710 |
XColor *colorPtr; |
| 4711 |
int width, height; |
| 4712 |
|
| 4713 |
font = GETFONT(hboxPtr, entryPtr->dataFont); |
| 4714 |
colorPtr = GETCOLOR(hboxPtr, entryPtr->dataColor); |
| 4715 |
y += hboxPtr->selBorderWidth + LABEL_PADY; |
| 4716 |
|
| 4717 |
Blt_SetDrawTextStyle(&ts, font, entryPtr->dataGC, colorPtr, |
| 4718 |
hboxPtr->selFgColor, entryPtr->dataShadow.color, 0.0, |
| 4719 |
TK_ANCHOR_NW, TK_JUSTIFY_LEFT, 0, entryPtr->dataShadow.offset); |
| 4720 |
Blt_GetTextExtents(&ts, entryPtr->dataText, &width, &height); |
| 4721 |
if (height < entryHeight) { |
| 4722 |
y += (entryHeight - height) / 2; |
| 4723 |
} |
| 4724 |
Blt_DrawText(hboxPtr->tkwin, drawable, entryPtr->dataText, &ts, x, y); |
| 4725 |
} |
| 4726 |
} |
| 4727 |
|
| 4728 |
|
| 4729 |
static int |
| 4730 |
DrawLabel(hboxPtr, treePtr, x, y, drawable) |
| 4731 |
Hierbox *hboxPtr; /* Widget record containing the attribute |
| 4732 |
* information for buttons. */ |
| 4733 |
Tree *treePtr; /* Node of entry. */ |
| 4734 |
int x, y; |
| 4735 |
Drawable drawable; /* Pixmap or window to draw into. */ |
| 4736 |
{ |
| 4737 |
Entry *entryPtr = treePtr->entryPtr; |
| 4738 |
TextEdit *editPtr = &(hboxPtr->labelEdit); |
| 4739 |
TextStyle ts; |
| 4740 |
int width, height; /* Width and height of label. */ |
| 4741 |
Tk_Font font; |
| 4742 |
int isSelected, isFocused; |
| 4743 |
int entryHeight; |
| 4744 |
|
| 4745 |
entryHeight = MAX(entryPtr->iconHeight, hboxPtr->button.height); |
| 4746 |
font = GETFONT(hboxPtr, entryPtr->labelFont); |
| 4747 |
isFocused = ((treePtr == hboxPtr->focusPtr) && |
| 4748 |
(hboxPtr->flags & HIERBOX_FOCUS)); |
| 4749 |
isSelected = IsSelected(hboxPtr, treePtr); |
| 4750 |
|
| 4751 |
/* Includes padding, selection 3-D border, and focus outline. */ |
| 4752 |
width = entryPtr->labelWidth; |
| 4753 |
height = entryPtr->labelHeight; |
| 4754 |
|
| 4755 |
/* Center the label, if necessary, vertically along the entry row. */ |
| 4756 |
if (height < entryHeight) { |
| 4757 |
y += (entryHeight - height) / 2; |
| 4758 |
} |
| 4759 |
|
| 4760 |
#ifdef notdef |
| 4761 |
/* Normal background color */ |
| 4762 |
Blt_Fill3DRectangle(hboxPtr->tkwin, drawable, hboxPtr->border, x, y, width, |
| 4763 |
height, 0, TK_RELIEF_FLAT); |
| 4764 |
#endif |
| 4765 |
if (isFocused) { /* Focus outline */ |
| 4766 |
XDrawRectangle(hboxPtr->display, drawable, hboxPtr->focusGC, |
| 4767 |
x, y, width - 1, height - 1); |
| 4768 |
} |
| 4769 |
x += FOCUS_WIDTH; |
| 4770 |
y += FOCUS_WIDTH; |
| 4771 |
if (isSelected) { |
| 4772 |
Blt_Fill3DRectangle(hboxPtr->tkwin, drawable, hboxPtr->selBorder, |
| 4773 |
x, y, width - 2 * FOCUS_WIDTH, height - 2 * FOCUS_WIDTH, |
| 4774 |
hboxPtr->selBorderWidth, hboxPtr->selRelief); |
| 4775 |
} |
| 4776 |
x += LABEL_PADX + hboxPtr->selBorderWidth; |
| 4777 |
y += LABEL_PADY + hboxPtr->selBorderWidth; |
| 4778 |
|
| 4779 |
if (*entryPtr->labelText != '\0') { |
| 4780 |
XColor *normalColor; |
| 4781 |
|
| 4782 |
normalColor = GETCOLOR(hboxPtr, entryPtr->labelColor); |
| 4783 |
Blt_SetDrawTextStyle(&ts, font, entryPtr->labelGC, normalColor, |
| 4784 |
hboxPtr->selFgColor, entryPtr->labelShadow.color, 0.0, TK_ANCHOR_NW, |
| 4785 |
TK_JUSTIFY_LEFT, 0, entryPtr->labelShadow.offset); |
| 4786 |
ts.state = (isSelected) ? STATE_ACTIVE : 0; |
| 4787 |
Blt_DrawText(hboxPtr->tkwin, drawable, entryPtr->labelText, &ts, |
| 4788 |
x, y); |
| 4789 |
} |
| 4790 |
if ((isFocused) && (hboxPtr->focusEdit) && (editPtr->cursorOn)) { |
| 4791 |
int x1, y1i, x2, y2; |
| 4792 |
|
| 4793 |
GetCursorLocation(hboxPtr, treePtr); |
| 4794 |
x1 = x + editPtr->x; |
| 4795 |
x2 = x1 + 3; |
| 4796 |
y1i = y + editPtr->y - 1; |
| 4797 |
y2 = y1i + editPtr->height - 1; |
| 4798 |
XDrawLine(hboxPtr->display, drawable, entryPtr->labelGC, |
| 4799 |
x1, y1i, x1, y2); |
| 4800 |
XDrawLine(hboxPtr->display, drawable, entryPtr->labelGC, |
| 4801 |
x1 - 2, y1i, x2, y1i); |
| 4802 |
XDrawLine(hboxPtr->display, drawable, entryPtr->labelGC, |
| 4803 |
x1 - 2, y2, x2, y2); |
| 4804 |
} |
| 4805 |
return entryHeight; |
| 4806 |
} |
| 4807 |
|
| 4808 |
/* |
| 4809 |
* --------------------------------------------------------------------------- |
| 4810 |
* |
| 4811 |
* DrawEntry -- |
| 4812 |
* |
| 4813 |
* Draws a button for the given entry. Note that buttons should only |
| 4814 |
* be drawn if the entry has sub-entries to be opened or closed. It's |
| 4815 |
* the responsibility of the calling routine to ensure this. |
| 4816 |
* |
| 4817 |
* The button is drawn centered in the region immediately to the left |
| 4818 |
* of the origin of the entry (computed in the layout routines). The |
| 4819 |
* height and width of the button were previously calculated from the |
| 4820 |
* average row height. |
| 4821 |
* |
| 4822 |
* button height = entry height - (2 * some arbitrary padding). |
| 4823 |
* button width = button height. |
| 4824 |
* |
| 4825 |
* The button has a border. The symbol (either a plus or minus) is |
| 4826 |
* slight smaller than the width or height minus the border. |
| 4827 |
* |
| 4828 |
* x,y origin of entry |
| 4829 |
* |
| 4830 |
* +---+ |
| 4831 |
* | + | icon label |
| 4832 |
* +---+ |
| 4833 |
* closed |
| 4834 |
* |
| 4835 |
* |----|----| horizontal offset |
| 4836 |
* |
| 4837 |
* +---+ |
| 4838 |
* | - | icon label |
| 4839 |
* +---+ |
| 4840 |
* open |
| 4841 |
* |
| 4842 |
* Results: |
| 4843 |
* None. |
| 4844 |
* |
| 4845 |
* Side Effects: |
| 4846 |
* A button is drawn for the entry. |
| 4847 |
* |
| 4848 |
* --------------------------------------------------------------------------- |
| 4849 |
*/ |
| 4850 |
static void |
| 4851 |
DrawEntry(hboxPtr, treePtr, drawable) |
| 4852 |
Hierbox *hboxPtr; /* Widget record containing the attribute |
| 4853 |
* information for buttons. */ |
| 4854 |
Tree *treePtr; /* Node of entry to be drawn. */ |
| 4855 |
Drawable drawable; /* Pixmap or window to draw into. */ |
| 4856 |
{ |
| 4857 |
ButtonAttributes *buttonPtr = &(hboxPtr->button); |
| 4858 |
int x, y; |
| 4859 |
int width, height; |
| 4860 |
int entryHeight; |
| 4861 |
int buttonY; |
| 4862 |
int x1, y1i, x2, y2; |
| 4863 |
Entry *entryPtr; |
| 4864 |
|
| 4865 |
entryPtr = treePtr->entryPtr; |
| 4866 |
x = SCREENX(hboxPtr, entryPtr->worldX); |
| 4867 |
y = SCREENY(hboxPtr, entryPtr->worldY); |
| 4868 |
|
| 4869 |
width = LEVELWIDTH(treePtr->level); |
| 4870 |
height = MAX(entryPtr->iconHeight, buttonPtr->height); |
| 4871 |
|
| 4872 |
entryPtr->buttonX = (width - buttonPtr->width) / 2; |
| 4873 |
entryPtr->buttonY = (height - buttonPtr->height) / 2; |
| 4874 |
|
| 4875 |
buttonY = y + entryPtr->buttonY; |
| 4876 |
|
| 4877 |
x1 = x + (width / 2); |
| 4878 |
y1i = y2 = buttonY + (buttonPtr->height / 2); |
| 4879 |
x2 = x1 + (LEVELWIDTH(treePtr->level) + LEVELWIDTH(treePtr->level + 1)) / 2; |
| 4880 |
|
| 4881 |
if ((treePtr->parentPtr != NULL) && (hboxPtr->lineWidth > 0)) { |
| 4882 |
/* |
| 4883 |
* For every node except root, draw a horizontal line from |
| 4884 |
* the vertical bar to the middle of the icon. |
| 4885 |
*/ |
| 4886 |
XDrawLine(hboxPtr->display, drawable, hboxPtr->lineGC, x1, y1i, x2, y2); |
| 4887 |
} |
| 4888 |
if ((entryPtr->flags & ENTRY_OPEN) && (hboxPtr->lineWidth > 0)) { |
| 4889 |
/* |
| 4890 |
* Entry is open, draw vertical line. |
| 4891 |
*/ |
| 4892 |
y2 = y1i + entryPtr->lineHeight; |
| 4893 |
if (y2 > Tk_Height(hboxPtr->tkwin)) { |
| 4894 |
y2 = Tk_Height(hboxPtr->tkwin); /* Clip line at window border. */ |
| 4895 |
} |
| 4896 |
XDrawLine(hboxPtr->display, drawable, hboxPtr->lineGC, x2, y1i, x2, y2); |
| 4897 |
} |
| 4898 |
if ((entryPtr->flags & ENTRY_BUTTON) && (treePtr->parentPtr != NULL)) { |
| 4899 |
/* |
| 4900 |
* Except for root, draw a button for every entry that needs |
| 4901 |
* one. The displayed button can be either a Tk image or a |
| 4902 |
* rectangle with plus or minus sign. |
| 4903 |
*/ |
| 4904 |
DrawButton(hboxPtr, treePtr, drawable); |
| 4905 |
} |
| 4906 |
x += LEVELWIDTH(treePtr->level); |
| 4907 |
DisplayIcon(hboxPtr, treePtr, x, y, drawable); |
| 4908 |
|
| 4909 |
x += LEVELWIDTH(treePtr->level + 1) + 4; |
| 4910 |
|
| 4911 |
/* Entry label. */ |
| 4912 |
entryHeight = DrawLabel(hboxPtr, treePtr, x, y, drawable); |
| 4913 |
if (treePtr->parentPtr != NULL) { |
| 4914 |
x += treePtr->parentPtr->entryPtr->levelX + LABEL_PADX; |
| 4915 |
} else { |
| 4916 |
x += width + entryPtr->labelWidth + LABEL_PADX; |
| 4917 |
} |
| 4918 |
/* Auxilary data */ |
| 4919 |
DrawData(hboxPtr, treePtr, x, y, entryHeight, drawable); |
| 4920 |
|
| 4921 |
} |
| 4922 |
|
| 4923 |
static void |
| 4924 |
DrawOuterBorders(hboxPtr, drawable) |
| 4925 |
Hierbox *hboxPtr; |
| 4926 |
Drawable drawable; |
| 4927 |
{ |
| 4928 |
/* Draw 3D border just inside of the focus highlight ring. */ |
| 4929 |
if ((hboxPtr->borderWidth > 0) && (hboxPtr->relief != TK_RELIEF_FLAT)) { |
| 4930 |
Blt_Draw3DRectangle(hboxPtr->tkwin, drawable, hboxPtr->border, |
| 4931 |
hboxPtr->highlightWidth, hboxPtr->highlightWidth, |
| 4932 |
Tk_Width(hboxPtr->tkwin) - 2 * hboxPtr->highlightWidth, |
| 4933 |
Tk_Height(hboxPtr->tkwin) - 2 * hboxPtr->highlightWidth, |
| 4934 |
hboxPtr->borderWidth, hboxPtr->relief); |
| 4935 |
} |
| 4936 |
/* Draw focus highlight ring. */ |
| 4937 |
if (hboxPtr->highlightWidth > 0) { |
| 4938 |
XColor *color; |
| 4939 |
GC gc; |
| 4940 |
|
| 4941 |
color = (hboxPtr->flags & HIERBOX_FOCUS) |
| 4942 |
? hboxPtr->highlightColor : hboxPtr->highlightBgColor; |
| 4943 |
gc = Tk_GCForColor(color, drawable); |
| 4944 |
Tk_DrawFocusHighlight(hboxPtr->tkwin, gc, hboxPtr->highlightWidth, |
| 4945 |
drawable); |
| 4946 |
} |
| 4947 |
hboxPtr->flags &= ~HIERBOX_BORDERS; |
| 4948 |
} |
| 4949 |
|
| 4950 |
/* |
| 4951 |
* ---------------------------------------------------------------------- |
| 4952 |
* |
| 4953 |
* DisplayHierbox -- |
| 4954 |
* |
| 4955 |
* This procedure is invoked to display the widget. |
| 4956 |
* |
| 4957 |
* Recompute the layout of the text if necessary. This is |
| 4958 |
* necessary if the world coordinate system has changed. |
| 4959 |
* Specifically, the following may have occurred: |
| 4960 |
* |
| 4961 |
* 1. a text attribute has changed (font, linespacing, etc.). |
| 4962 |
* 2. an entry's option changed, possibly resizing the entry. |
| 4963 |
* |
| 4964 |
* This is deferred to the display routine since potentially |
| 4965 |
* many of these may occur. |
| 4966 |
* |
| 4967 |
* Set the vertical and horizontal scrollbars. This is done |
| 4968 |
* here since the window width and height are needed for the |
| 4969 |
* scrollbar calculations. |
| 4970 |
* |
| 4971 |
* Results: |
| 4972 |
* None. |
| 4973 |
* |
| 4974 |
* Side effects: |
| 4975 |
* The widget is redisplayed. |
| 4976 |
* |
| 4977 |
* ---------------------------------------------------------------------- |
| 4978 |
*/ |
| 4979 |
static void |
| 4980 |
DisplayHierbox(clientData) |
| 4981 |
ClientData clientData; /* Information about widget. */ |
| 4982 |
{ |
| 4983 |
Hierbox *hboxPtr = clientData; |
| 4984 |
Pixmap drawable; |
| 4985 |
|
| 4986 |
hboxPtr->flags &= ~HIERBOX_REDRAW; |
| 4987 |
if (hboxPtr->tkwin == NULL) { |
| 4988 |
return; /* Window has been destroyed. */ |
| 4989 |
} |
| 4990 |
if (hboxPtr->flags & HIERBOX_LAYOUT) { |
| 4991 |
/* |
| 4992 |
* Recompute the layout when entries are opened/closed, |
| 4993 |
* inserted/deleted, or when text attributes change |
| 4994 |
* (such as font, linespacing). |
| 4995 |
*/ |
| 4996 |
ComputeLayout(hboxPtr); |
| 4997 |
} |
| 4998 |
if (hboxPtr->flags & HIERBOX_SCROLL) { |
| 4999 |
int width, height; |
| 5000 |
|
| 5001 |
/* Scrolling means that the view port has changed and that the |
| 5002 |
* visible entries need to be recomputed. */ |
| 5003 |
ComputeVisibleEntries(hboxPtr); |
| 5004 |
Blt_PickCurrentItem(hboxPtr->bindTable); |
| 5005 |
Blt_PickCurrentItem(hboxPtr->buttonBindTable); |
| 5006 |
|
| 5007 |
width = VPORTWIDTH(hboxPtr); |
| 5008 |
height = VPORTHEIGHT(hboxPtr); |
| 5009 |
if (hboxPtr->flags & HIERBOX_XSCROLL) { |
| 5010 |
if (hboxPtr->xScrollCmdPrefix != NULL) { |
| 5011 |
Blt_UpdateScrollbar(hboxPtr->interp, hboxPtr->xScrollCmdPrefix, |
| 5012 |
(double)hboxPtr->xOffset / hboxPtr->worldWidth, |
| 5013 |
(double)(hboxPtr->xOffset + width) / hboxPtr->worldWidth); |
| 5014 |
} |
| 5015 |
} |
| 5016 |
if (hboxPtr->flags & HIERBOX_YSCROLL) { |
| 5017 |
if (hboxPtr->yScrollCmdPrefix != NULL) { |
| 5018 |
Blt_UpdateScrollbar(hboxPtr->interp, hboxPtr->yScrollCmdPrefix, |
| 5019 |
(double)hboxPtr->yOffset / hboxPtr->worldHeight, |
| 5020 |
(double)(hboxPtr->yOffset + height) / hboxPtr->worldHeight); |
| 5021 |
} |
| 5022 |
} |
| 5023 |
hboxPtr->flags &= ~HIERBOX_SCROLL; |
| 5024 |
} |
| 5025 |
if (!Tk_IsMapped(hboxPtr->tkwin)) { |
| 5026 |
return; |
| 5027 |
} |
| 5028 |
drawable = Tk_GetPixmap(hboxPtr->display, Tk_WindowId(hboxPtr->tkwin), |
| 5029 |
Tk_Width(hboxPtr->tkwin), Tk_Height(hboxPtr->tkwin), |
| 5030 |
Tk_Depth(hboxPtr->tkwin)); |
| 5031 |
|
| 5032 |
/* |
| 5033 |
* Clear the background either by tiling a pixmap or filling with |
| 5034 |
* a solid color. Tiling takes precedence. |
| 5035 |
*/ |
| 5036 |
if (hboxPtr->tile != NULL) { |
| 5037 |
if (hboxPtr->scrollTile) { |
| 5038 |
Blt_SetTSOrigin(hboxPtr->tkwin, hboxPtr->tile, -hboxPtr->xOffset, |
| 5039 |
-hboxPtr->yOffset); |
| 5040 |
} else { |
| 5041 |
Blt_SetTileOrigin(hboxPtr->tkwin, hboxPtr->tile, 0, 0); |
| 5042 |
} |
| 5043 |
Blt_TileRectangle(hboxPtr->tkwin, drawable, hboxPtr->tile, 0, 0, |
| 5044 |
Tk_Width(hboxPtr->tkwin), Tk_Height(hboxPtr->tkwin)); |
| 5045 |
} else { |
| 5046 |
Blt_Fill3DRectangle(hboxPtr->tkwin, drawable, hboxPtr->border, 0, 0, |
| 5047 |
Tk_Width(hboxPtr->tkwin), Tk_Height(hboxPtr->tkwin), 0, |
| 5048 |
TK_RELIEF_FLAT); |
| 5049 |
} |
| 5050 |
|
| 5051 |
if (hboxPtr->nVisible > 0) { |
| 5052 |
register Tree **treePtrPtr; |
| 5053 |
|
| 5054 |
if (hboxPtr->activePtr != NULL) { |
| 5055 |
int y, height; |
| 5056 |
|
| 5057 |
y = SCREENY(hboxPtr, hboxPtr->activePtr->entryPtr->worldY); |
| 5058 |
height = MAX(hboxPtr->activePtr->entryPtr->iconHeight, |
| 5059 |
hboxPtr->activePtr->entryPtr->labelHeight); |
| 5060 |
Blt_Fill3DRectangle(hboxPtr->tkwin, drawable, hboxPtr->activeBorder, |
| 5061 |
0, y, Tk_Width(hboxPtr->tkwin), height, 0, TK_RELIEF_FLAT); |
| 5062 |
} |
| 5063 |
if (hboxPtr->lineWidth > 0) { |
| 5064 |
DrawVerticals(hboxPtr, hboxPtr->visibleArr[0], drawable); |
| 5065 |
} |
| 5066 |
for (treePtrPtr = hboxPtr->visibleArr; *treePtrPtr != NULL; |
| 5067 |
treePtrPtr++) { |
| 5068 |
DrawEntry(hboxPtr, *treePtrPtr, drawable); |
| 5069 |
} |
| 5070 |
} |
| 5071 |
DrawOuterBorders(hboxPtr, drawable); |
| 5072 |
/* Now copy the new view to the window. */ |
| 5073 |
XCopyArea(hboxPtr->display, drawable, Tk_WindowId(hboxPtr->tkwin), |
| 5074 |
hboxPtr->lineGC, 0, 0, Tk_Width(hboxPtr->tkwin), |
| 5075 |
Tk_Height(hboxPtr->tkwin), 0, 0); |
| 5076 |
Tk_FreePixmap(hboxPtr->display, drawable); |
| 5077 |
} |
| 5078 |
|
| 5079 |
/* |
| 5080 |
*---------------------------------------------------------------------- |
| 5081 |
* |
| 5082 |
* SelectCmdProc -- |
| 5083 |
* |
| 5084 |
* Invoked at the next idle point whenever the current |
| 5085 |
* selection changes. Executes some application-specific code |
| 5086 |
* in the -selectcommand option. This provides a way for |
| 5087 |
* applications to handle selection changes. |
| 5088 |
* |
| 5089 |
* Results: |
| 5090 |
* None. |
| 5091 |
* |
| 5092 |
* Side effects: |
| 5093 |
* Tcl code gets executed for some application-specific task. |
| 5094 |
* |
| 5095 |
*---------------------------------------------------------------------- |
| 5096 |
*/ |
| 5097 |
static void |
| 5098 |
SelectCmdProc(clientData) |
| 5099 |
ClientData clientData; /* Information about widget. */ |
| 5100 |
{ |
| 5101 |
Hierbox *hboxPtr = clientData; |
| 5102 |
|
| 5103 |
/* |
| 5104 |
* Preserve the widget structure in case the "select" callback |
| 5105 |
* destroys it. |
| 5106 |
*/ |
| 5107 |
Tcl_Preserve(hboxPtr); |
| 5108 |
if (hboxPtr->selectCmd != NULL) { |
| 5109 |
hboxPtr->flags &= ~SELECTION_PENDING; |
| 5110 |
if (Tcl_GlobalEval(hboxPtr->interp, hboxPtr->selectCmd) != TCL_OK) { |
| 5111 |
Tcl_BackgroundError(hboxPtr->interp); |
| 5112 |
} |
| 5113 |
} |
| 5114 |
Tcl_Release(hboxPtr); |
| 5115 |
} |
| 5116 |
|
| 5117 |
/* |
| 5118 |
* -------------------------------------------------------------- |
| 5119 |
* |
| 5120 |
* HierboxCmd -- |
| 5121 |
* |
| 5122 |
* This procedure is invoked to process the Tcl command that |
| 5123 |
* corresponds to a widget managed by this module. See the user |
| 5124 |
* documentation for details on what it does. |
| 5125 |
* |
| 5126 |
* Results: |
| 5127 |
* A standard Tcl result. |
| 5128 |
* |
| 5129 |
* Side effects: |
| 5130 |
* See the user documentation. |
| 5131 |
* |
| 5132 |
* -------------------------------------------------------------- |
| 5133 |
*/ |
| 5134 |
/* ARGSUSED */ |
| 5135 |
static int |
| 5136 |
HierboxCmd(clientData, interp, argc, argv) |
| 5137 |
ClientData clientData; /* Main window associated with interpreter. */ |
| 5138 |
Tcl_Interp *interp; /* Current interpreter. */ |
| 5139 |
int argc; /* Number of arguments. */ |
| 5140 |
char **argv; /* Argument strings. */ |
| 5141 |
{ |
| 5142 |
Hierbox *hboxPtr; |
| 5143 |
Tk_Window tkwin; |
| 5144 |
Tree *treePtr; |
| 5145 |
Tcl_CmdInfo cmdInfo; |
| 5146 |
|
| 5147 |
if (argc < 2) { |
| 5148 |
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 5149 |
" pathName ?option value?...\"", (char *)NULL); |
| 5150 |
return TCL_ERROR; |
| 5151 |
} |
| 5152 |
tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), argv[1], |
| 5153 |
(char *)NULL); |
| 5154 |
if (tkwin == NULL) { |
| 5155 |
return TCL_ERROR; |
| 5156 |
} |
| 5157 |
hboxPtr = CreateHierbox(interp, tkwin); |
| 5158 |
|
| 5159 |
if (Blt_ConfigureWidgetComponent(interp, tkwin, "button", "Button", |
| 5160 |
buttonConfigSpecs, 0, (char **)NULL, (char *)hboxPtr, 0) != TCL_OK) { |
| 5161 |
goto error; |
| 5162 |
} |
| 5163 |
if (ConfigureHierbox(interp, hboxPtr, argc - 2, argv + 2, 0) != TCL_OK) { |
| 5164 |
goto error; |
| 5165 |
} |
| 5166 |
treePtr = CreateNode(hboxPtr, (Tree *) NULL, APPEND, hboxPtr->separator); |
| 5167 |
if (treePtr == NULL) { |
| 5168 |
goto error; |
| 5169 |
} |
| 5170 |
hboxPtr->rootPtr = hboxPtr->focusPtr = treePtr; |
| 5171 |
hboxPtr->selAnchorPtr = NULL; |
| 5172 |
Blt_SetFocusItem(hboxPtr->bindTable, hboxPtr->focusPtr, NULL); |
| 5173 |
|
| 5174 |
Tk_CreateSelHandler(tkwin, XA_PRIMARY, XA_STRING, SelectionProc, hboxPtr, |
| 5175 |
XA_STRING); |
| 5176 |
Tk_CreateEventHandler(tkwin, ExposureMask | StructureNotifyMask | |
| 5177 |
FocusChangeMask, HierboxEventProc, hboxPtr); |
| 5178 |
|
| 5179 |
hboxPtr->cmdToken = Tcl_CreateCommand(interp, argv[1], HierboxInstCmd, |
| 5180 |
hboxPtr, HierboxInstCmdDeleteProc); |
| 5181 |
#ifdef ITCL_NAMESPACES |
| 5182 |
Itk_SetWidgetCommand(hboxPtr->tkwin, hboxPtr->cmdToken); |
| 5183 |
#endif |
| 5184 |
|
| 5185 |
/* |
| 5186 |
* Invoke a procedure to initialize various bindings on hierbox |
| 5187 |
* entries. If the procedure doesn't already exist, source it |
| 5188 |
* from "$blt_library/bltHierbox.tcl". We deferred sourcing the file |
| 5189 |
* until now so that the variable $blt_library could be set within a |
| 5190 |
* script. |
| 5191 |
*/ |
| 5192 |
if (!Tcl_GetCommandInfo(interp, "blt::Hierbox::Init", &cmdInfo)) { |
| 5193 |
static char initCmd[] = |
| 5194 |
{ |
| 5195 |
"source [file join $blt_library hierbox.tcl]" |
| 5196 |
}; |
| 5197 |
if (Tcl_GlobalEval(interp, initCmd) != TCL_OK) { |
| 5198 |
char info[200]; |
| 5199 |
|
| 5200 |
sprintf(info, "\n (while loading bindings for %s)", argv[0]); |
| 5201 |
Tcl_AddErrorInfo(interp, info); |
| 5202 |
goto error; |
| 5203 |
} |
| 5204 |
} |
| 5205 |
if (Tcl_VarEval(interp, "blt::Hierbox::Init ", argv[1], (char *)NULL) |
| 5206 |
!= TCL_OK) { |
| 5207 |
goto error; |
| 5208 |
} |
| 5209 |
treePtr->entryPtr->flags = (ENTRY_MAPPED); |
| 5210 |
if (OpenNode(hboxPtr, treePtr) != TCL_OK) { |
| 5211 |
goto error; |
| 5212 |
} |
| 5213 |
Tcl_SetResult(interp, Tk_PathName(hboxPtr->tkwin), TCL_VOLATILE); |
| 5214 |
return TCL_OK; |
| 5215 |
error: |
| 5216 |
Tk_DestroyWindow(tkwin); |
| 5217 |
return TCL_ERROR; |
| 5218 |
} |
| 5219 |
|
| 5220 |
/* |
| 5221 |
* -------------------------------------------------------------- |
| 5222 |
* |
| 5223 |
* Hierbox operations |
| 5224 |
* |
| 5225 |
* -------------------------------------------------------------- |
| 5226 |
*/ |
| 5227 |
|
| 5228 |
/*ARGSUSED*/ |
| 5229 |
static int |
| 5230 |
FocusOp(hboxPtr, interp, argc, argv) |
| 5231 |
Hierbox *hboxPtr; |
| 5232 |
Tcl_Interp *interp; |
| 5233 |
int argc; |
| 5234 |
char **argv; |
| 5235 |
{ |
| 5236 |
if (argc == 3) { |
| 5237 |
Tree *treePtr; |
| 5238 |
|
| 5239 |
treePtr = hboxPtr->focusPtr; |
| 5240 |
if (GetNode(hboxPtr, argv[2], &treePtr) != TCL_OK) { |
| 5241 |
return TCL_ERROR; |
| 5242 |
} |
| 5243 |
if ((treePtr != NULL) && (treePtr != hboxPtr->focusPtr)) { |
| 5244 |
if (IsHidden(treePtr)) { |
| 5245 |
/* Doesn't make sense to set focus to a node you can't see. */ |
| 5246 |
ExposeAncestors(treePtr); |
| 5247 |
} |
| 5248 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 5249 |
hboxPtr->focusPtr = treePtr; |
| 5250 |
hboxPtr->labelEdit.insertPos = strlen(treePtr->entryPtr->labelText); |
| 5251 |
} |
| 5252 |
EventuallyRedraw(hboxPtr); |
| 5253 |
} |
| 5254 |
Blt_SetFocusItem(hboxPtr->bindTable, hboxPtr->focusPtr, NULL); |
| 5255 |
if (hboxPtr->focusPtr != NULL) { |
| 5256 |
Tcl_SetResult(interp, NodeToString(hboxPtr, hboxPtr->focusPtr), |
| 5257 |
TCL_VOLATILE); |
| 5258 |
} |
| 5259 |
return TCL_OK; |
| 5260 |
} |
| 5261 |
|
| 5262 |
/* |
| 5263 |
*---------------------------------------------------------------------- |
| 5264 |
* |
| 5265 |
* BboxOp -- |
| 5266 |
* |
| 5267 |
*---------------------------------------------------------------------- |
| 5268 |
*/ |
| 5269 |
/*ARGSUSED*/ |
| 5270 |
static int |
| 5271 |
BboxOp(hboxPtr, interp, argc, argv) |
| 5272 |
Hierbox *hboxPtr; |
| 5273 |
Tcl_Interp *interp; |
| 5274 |
int argc; /* Not used. */ |
| 5275 |
char **argv; |
| 5276 |
{ |
| 5277 |
Tree *treePtr; |
| 5278 |
register int i; |
| 5279 |
Entry *entryPtr; |
| 5280 |
char string[200]; |
| 5281 |
int width, height, yBot; |
| 5282 |
int left, top, right, bottom; |
| 5283 |
int screen; |
| 5284 |
|
| 5285 |
if (hboxPtr->flags & HIERBOX_LAYOUT) { |
| 5286 |
/* |
| 5287 |
* The layout is dirty. Recompute it now, before we use the |
| 5288 |
* world dimensions. But remember, the "bbox" operation isn't |
| 5289 |
* valid for hidden entries (since they're not visible, they |
| 5290 |
* don't have world coordinates). |
| 5291 |
*/ |
| 5292 |
ComputeLayout(hboxPtr); |
| 5293 |
} |
| 5294 |
left = hboxPtr->worldWidth; |
| 5295 |
top = hboxPtr->worldHeight; |
| 5296 |
right = bottom = 0; |
| 5297 |
|
| 5298 |
screen = FALSE; |
| 5299 |
if ((argc > 2) && (argv[2][0] == '-') && |
| 5300 |
(strcmp(argv[2], "-screen") == 0)) { |
| 5301 |
screen = TRUE; |
| 5302 |
argc--, argv++; |
| 5303 |
} |
| 5304 |
for (i = 2; i < argc; i++) { |
| 5305 |
if ((argv[i][0] == 'a') && (strcmp(argv[i], "all") == 0)) { |
| 5306 |
left = top = 0; |
| 5307 |
right = hboxPtr->worldWidth; |
| 5308 |
bottom = hboxPtr->worldHeight; |
| 5309 |
break; |
| 5310 |
} |
| 5311 |
treePtr = hboxPtr->focusPtr; |
| 5312 |
if (GetNode(hboxPtr, argv[i], &treePtr) != TCL_OK) { |
| 5313 |
return TCL_ERROR; |
| 5314 |
} |
| 5315 |
if ((treePtr == NULL) || (IsHidden(treePtr))) { |
| 5316 |
continue; |
| 5317 |
} |
| 5318 |
entryPtr = treePtr->entryPtr; |
| 5319 |
yBot = entryPtr->worldY + entryPtr->height; |
| 5320 |
height = VPORTHEIGHT(hboxPtr); |
| 5321 |
if ((yBot <= hboxPtr->yOffset) && |
| 5322 |
(entryPtr->worldY >= (hboxPtr->yOffset + height))) { |
| 5323 |
continue; |
| 5324 |
} |
| 5325 |
if (bottom < yBot) { |
| 5326 |
bottom = yBot; |
| 5327 |
} |
| 5328 |
if (top > entryPtr->worldY) { |
| 5329 |
top = entryPtr->worldY; |
| 5330 |
} |
| 5331 |
if (right < |
| 5332 |
(entryPtr->worldX + entryPtr->width + LEVELWIDTH(treePtr->level))) { |
| 5333 |
right = (entryPtr->worldX + entryPtr->width + |
| 5334 |
LEVELWIDTH(treePtr->level)); |
| 5335 |
} |
| 5336 |
if (left > entryPtr->worldX) { |
| 5337 |
left = entryPtr->worldX; |
| 5338 |
} |
| 5339 |
} |
| 5340 |
|
| 5341 |
if (screen) { |
| 5342 |
width = VPORTWIDTH(hboxPtr); |
| 5343 |
height = VPORTHEIGHT(hboxPtr); |
| 5344 |
|
| 5345 |
/* |
| 5346 |
* Do a min-max text for the intersection of the viewport and |
| 5347 |
* the computed bounding box. If there is no intersection, return |
| 5348 |
* the empty string. |
| 5349 |
*/ |
| 5350 |
if ((right < hboxPtr->xOffset) || (bottom < hboxPtr->yOffset) || |
| 5351 |
(left >= (hboxPtr->xOffset + width)) || |
| 5352 |
(top >= (hboxPtr->yOffset + height))) { |
| 5353 |
return TCL_OK; |
| 5354 |
} |
| 5355 |
/* Otherwise clip the coordinates at the view port boundaries. */ |
| 5356 |
if (left < hboxPtr->xOffset) { |
| 5357 |
left = hboxPtr->xOffset; |
| 5358 |
} else if (right > (hboxPtr->xOffset + width)) { |
| 5359 |
right = hboxPtr->xOffset + width; |
| 5360 |
} |
| 5361 |
if (top < hboxPtr->yOffset) { |
| 5362 |
top = hboxPtr->yOffset; |
| 5363 |
} else if (bottom > (hboxPtr->yOffset + height)) { |
| 5364 |
bottom = hboxPtr->yOffset + height; |
| 5365 |
} |
| 5366 |
left = SCREENX(hboxPtr, left), top = SCREENY(hboxPtr, top); |
| 5367 |
right = SCREENX(hboxPtr, right), bottom = SCREENY(hboxPtr, bottom); |
| 5368 |
} |
| 5369 |
if ((left < right) && (top < bottom)) { |
| 5370 |
sprintf(string, "%d %d %d %d", left, top, right - left, bottom - top); |
| 5371 |
Tcl_SetResult(interp, string, TCL_VOLATILE); |
| 5372 |
} |
| 5373 |
return TCL_OK; |
| 5374 |
} |
| 5375 |
|
| 5376 |
/* |
| 5377 |
*---------------------------------------------------------------------- |
| 5378 |
* |
| 5379 |
* ButtonActivateOp -- |
| 5380 |
* |
| 5381 |
* Selects the button to appear active. |
| 5382 |
* |
| 5383 |
*---------------------------------------------------------------------- |
| 5384 |
*/ |
| 5385 |
/*ARGSUSED*/ |
| 5386 |
static int |
| 5387 |
ButtonActivateOp(hboxPtr, interp, argc, argv) |
| 5388 |
Hierbox *hboxPtr; |
| 5389 |
Tcl_Interp *interp; |
| 5390 |
int argc; /* Not used. */ |
| 5391 |
char **argv; |
| 5392 |
{ |
| 5393 |
Tree *treePtr, *oldPtr; |
| 5394 |
|
| 5395 |
treePtr = hboxPtr->focusPtr; |
| 5396 |
if (argv[3][0] == '\0') { |
| 5397 |
treePtr = NULL; |
| 5398 |
} else if (GetNode(hboxPtr, argv[3], &treePtr) != TCL_OK) { |
| 5399 |
return TCL_ERROR; |
| 5400 |
} |
| 5401 |
oldPtr = hboxPtr->activeButtonPtr; |
| 5402 |
hboxPtr->activeButtonPtr = treePtr; |
| 5403 |
if (treePtr != oldPtr) { |
| 5404 |
Drawable drawable; |
| 5405 |
|
| 5406 |
drawable = Tk_WindowId(hboxPtr->tkwin); |
| 5407 |
if (oldPtr != NULL) { |
| 5408 |
DrawButton(hboxPtr, oldPtr, drawable); |
| 5409 |
} |
| 5410 |
if (treePtr != NULL) { |
| 5411 |
DrawButton(hboxPtr, treePtr, drawable); |
| 5412 |
} |
| 5413 |
DrawOuterBorders(hboxPtr, drawable); |
| 5414 |
} |
| 5415 |
return TCL_OK; |
| 5416 |
} |
| 5417 |
|
| 5418 |
/* |
| 5419 |
*---------------------------------------------------------------------- |
| 5420 |
* |
| 5421 |
* ButtonBindOp -- |
| 5422 |
* |
| 5423 |
* .t bind tag sequence command |
| 5424 |
* |
| 5425 |
*---------------------------------------------------------------------- |
| 5426 |
*/ |
| 5427 |
/*ARGSUSED*/ |
| 5428 |
static int |
| 5429 |
ButtonBindOp(hboxPtr, interp, argc, argv) |
| 5430 |
Hierbox *hboxPtr; |
| 5431 |
Tcl_Interp *interp; |
| 5432 |
int argc; /* Not used. */ |
| 5433 |
char **argv; |
| 5434 |
{ |
| 5435 |
ClientData object; |
| 5436 |
/* |
| 5437 |
* Individual entries are selected by inode only. All other |
| 5438 |
* strings are interpreted as a binding tag. For example, if one |
| 5439 |
* binds to "focus", it is assumed that this refers to a bind tag, |
| 5440 |
* not the entry with focus. |
| 5441 |
*/ |
| 5442 |
object = GetNodeByIndex(hboxPtr, argv[3]); |
| 5443 |
if (object == 0) { |
| 5444 |
object = (ClientData)Tk_GetUid(argv[3]); |
| 5445 |
} |
| 5446 |
return Blt_ConfigureBindings(interp, hboxPtr->buttonBindTable, object, |
| 5447 |
argc - 4, argv + 4); |
| 5448 |
} |
| 5449 |
|
| 5450 |
/* |
| 5451 |
*---------------------------------------------------------------------- |
| 5452 |
* |
| 5453 |
* ButCgetOpOp -- |
| 5454 |
* |
| 5455 |
*---------------------------------------------------------------------- |
| 5456 |
*/ |
| 5457 |
/*ARGSUSED*/ |
| 5458 |
static int |
| 5459 |
ButtonCgetOp(hboxPtr, interp, argc, argv) |
| 5460 |
Hierbox *hboxPtr; |
| 5461 |
Tcl_Interp *interp; |
| 5462 |
int argc; /* Not used. */ |
| 5463 |
char **argv; |
| 5464 |
{ |
| 5465 |
return Tk_ConfigureValue(interp, hboxPtr->tkwin, buttonConfigSpecs, |
| 5466 |
(char *)hboxPtr, argv[3], 0); |
| 5467 |
} |
| 5468 |
|
| 5469 |
/* |
| 5470 |
*---------------------------------------------------------------------- |
| 5471 |
* |
| 5472 |
* ButtonConfigureOp -- |
| 5473 |
* |
| 5474 |
* This procedure is called to process a list of configuration |
| 5475 |
* options database, in order to reconfigure the one of more |
| 5476 |
* entries in the widget. |
| 5477 |
* |
| 5478 |
* .h entryconfigure node node node node option value |
| 5479 |
* |
| 5480 |
* Results: |
| 5481 |
* A standard Tcl result. If TCL_ERROR is returned, then |
| 5482 |
* interp->result contains an error message. |
| 5483 |
* |
| 5484 |
* Side effects: |
| 5485 |
* Configuration information, such as text string, colors, font, |
| 5486 |
* etc. get set for hboxPtr; old resources get freed, if there |
| 5487 |
* were any. The hypertext is redisplayed. |
| 5488 |
* |
| 5489 |
*---------------------------------------------------------------------- |
| 5490 |
*/ |
| 5491 |
static int |
| 5492 |
ButtonConfigureOp(hboxPtr, interp, argc, argv) |
| 5493 |
Hierbox *hboxPtr; |
| 5494 |
Tcl_Interp *interp; |
| 5495 |
int argc; |
| 5496 |
CONST char **argv; |
| 5497 |
{ |
| 5498 |
/* Figure out where the option value pairs begin */ |
| 5499 |
argc -= 3; |
| 5500 |
argv += 3; |
| 5501 |
|
| 5502 |
if (argc == 0) { |
| 5503 |
return Tk_ConfigureInfo(interp, hboxPtr->tkwin, buttonConfigSpecs, |
| 5504 |
(char *)hboxPtr, (char *)NULL, 0); |
| 5505 |
} else if (argc == 1) { |
| 5506 |
return Tk_ConfigureInfo(interp, hboxPtr->tkwin, buttonConfigSpecs, |
| 5507 |
(char *)hboxPtr, argv[0], 0); |
| 5508 |
} |
| 5509 |
if (Blt_ConfigureWidget(hboxPtr->interp, hboxPtr->tkwin, buttonConfigSpecs, |
| 5510 |
argc, argv, (char *)hboxPtr, TK_CONFIG_ARGV_ONLY) != TCL_OK) { |
| 5511 |
return TCL_ERROR; |
| 5512 |
} |
| 5513 |
ConfigureButtons(hboxPtr); |
| 5514 |
EventuallyRedraw(hboxPtr); |
| 5515 |
return TCL_OK; |
| 5516 |
} |
| 5517 |
|
| 5518 |
/* |
| 5519 |
*---------------------------------------------------------------------- |
| 5520 |
* |
| 5521 |
* ButtonOp -- |
| 5522 |
* |
| 5523 |
* This procedure handles button operations. |
| 5524 |
* |
| 5525 |
* Results: |
| 5526 |
* A standard Tcl result. |
| 5527 |
* |
| 5528 |
*---------------------------------------------------------------------- |
| 5529 |
*/ |
| 5530 |
static Blt_OpSpec buttonOperSpecs[] = |
| 5531 |
{ |
| 5532 |
{"activate", 1, (Blt_Op)ButtonActivateOp, 4, 4, "node",}, |
| 5533 |
{"bind", 1, (Blt_Op)ButtonBindOp, 4, 6, |
| 5534 |
"tagName ?sequence command?",}, |
| 5535 |
{"cget", 2, (Blt_Op)ButtonCgetOp, 4, 4, "option",}, |
| 5536 |
{"configure", 2, (Blt_Op)ButtonConfigureOp, 3, 0, |
| 5537 |
"?option value?...",}, |
| 5538 |
{"highlight", 1, (Blt_Op)ButtonActivateOp, 4, 4, "node",}, |
| 5539 |
}; |
| 5540 |
|
| 5541 |
static int nButtonSpecs = sizeof(buttonOperSpecs) / sizeof(Blt_OpSpec); |
| 5542 |
|
| 5543 |
static int |
| 5544 |
ButtonOp(hboxPtr, interp, argc, argv) |
| 5545 |
Hierbox *hboxPtr; |
| 5546 |
Tcl_Interp *interp; |
| 5547 |
int argc; |
| 5548 |
char **argv; |
| 5549 |
{ |
| 5550 |
Blt_Op proc; |
| 5551 |
int result; |
| 5552 |
|
| 5553 |
proc = Blt_GetOp(interp, nButtonSpecs, buttonOperSpecs, BLT_OP_ARG2, argc, |
| 5554 |
argv, 0); |
| 5555 |
if (proc == NULL) { |
| 5556 |
return TCL_ERROR; |
| 5557 |
} |
| 5558 |
result = (*proc) (hboxPtr, interp, argc, argv); |
| 5559 |
return result; |
| 5560 |
} |
| 5561 |
|
| 5562 |
/* |
| 5563 |
*---------------------------------------------------------------------- |
| 5564 |
* |
| 5565 |
* CgetOp -- |
| 5566 |
* |
| 5567 |
*---------------------------------------------------------------------- |
| 5568 |
*/ |
| 5569 |
/*ARGSUSED*/ |
| 5570 |
static int |
| 5571 |
CgetOp(hboxPtr, interp, argc, argv) |
| 5572 |
Hierbox *hboxPtr; |
| 5573 |
Tcl_Interp *interp; |
| 5574 |
int argc; /* Not used. */ |
| 5575 |
char **argv; |
| 5576 |
{ |
| 5577 |
return Tk_ConfigureValue(interp, hboxPtr->tkwin, configSpecs, |
| 5578 |
(char *)hboxPtr, argv[2], 0); |
| 5579 |
} |
| 5580 |
|
| 5581 |
/*ARGSUSED*/ |
| 5582 |
static int |
| 5583 |
CloseOp(hboxPtr, interp, argc, argv) |
| 5584 |
Hierbox *hboxPtr; |
| 5585 |
Tcl_Interp *interp; /* Not used. */ |
| 5586 |
int argc; |
| 5587 |
char **argv; |
| 5588 |
{ |
| 5589 |
Tree *rootPtr; |
| 5590 |
unsigned int flags; |
| 5591 |
register int i; |
| 5592 |
|
| 5593 |
flags = 0; |
| 5594 |
if (argc > 2) { |
| 5595 |
int length; |
| 5596 |
|
| 5597 |
length = strlen(argv[2]); |
| 5598 |
if ((argv[2][0] == '-') && (length > 1) && |
| 5599 |
(strncmp(argv[2], "-recurse", length) == 0)) { |
| 5600 |
argv++, argc--; |
| 5601 |
flags |= APPLY_RECURSE; |
| 5602 |
} |
| 5603 |
} |
| 5604 |
for (i = 2; i < argc; i++) { |
| 5605 |
rootPtr = hboxPtr->focusPtr; |
| 5606 |
if (GetNode(hboxPtr, argv[i], &rootPtr) != TCL_OK) { |
| 5607 |
return TCL_ERROR; |
| 5608 |
} |
| 5609 |
if (rootPtr == NULL) { |
| 5610 |
continue; |
| 5611 |
} |
| 5612 |
/* |
| 5613 |
* Clear any selected entries that may become hidden by |
| 5614 |
* closing the node. |
| 5615 |
*/ |
| 5616 |
PruneSelection(hboxPtr, rootPtr); |
| 5617 |
|
| 5618 |
/* |
| 5619 |
* ----------------------------------------------------------- |
| 5620 |
* |
| 5621 |
* Check if either the "focus" entry or selection anchor |
| 5622 |
* is in this hierarchy. Must move it or disable it before |
| 5623 |
* we close the node. Otherwise it may be deleted by a Tcl |
| 5624 |
* "close" script, and we'll be left pointing to a bogus |
| 5625 |
* memory location. |
| 5626 |
* |
| 5627 |
* ----------------------------------------------------------- |
| 5628 |
*/ |
| 5629 |
if (IsAncestor(rootPtr, hboxPtr->focusPtr)) { |
| 5630 |
hboxPtr->focusPtr = rootPtr; |
| 5631 |
Blt_SetFocusItem(hboxPtr->bindTable, hboxPtr->focusPtr, NULL); |
| 5632 |
} |
| 5633 |
if (IsAncestor(rootPtr, hboxPtr->selAnchorPtr)) { |
| 5634 |
hboxPtr->selAnchorPtr = NULL; |
| 5635 |
} |
| 5636 |
if (IsAncestor(rootPtr, hboxPtr->activePtr)) { |
| 5637 |
hboxPtr->activePtr = rootPtr; |
| 5638 |
} |
| 5639 |
if (ApplyToTree(hboxPtr, rootPtr, CloseNode, flags) != TCL_OK) { |
| 5640 |
return TCL_ERROR; |
| 5641 |
} |
| 5642 |
} |
| 5643 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 5644 |
EventuallyRedraw(hboxPtr); |
| 5645 |
return TCL_OK; |
| 5646 |
} |
| 5647 |
|
| 5648 |
/* |
| 5649 |
*---------------------------------------------------------------------- |
| 5650 |
* |
| 5651 |
* ConfigureOp -- |
| 5652 |
* |
| 5653 |
* This procedure is called to process an argv/argc list, plus |
| 5654 |
* the Tk option database, in order to configure (or reconfigure) |
| 5655 |
* the widget. |
| 5656 |
* |
| 5657 |
* Results: |
| 5658 |
* A standard Tcl result. If TCL_ERROR is returned, then |
| 5659 |
* interp->result contains an error message. |
| 5660 |
* |
| 5661 |
* Side effects: |
| 5662 |
* Configuration information, such as text string, colors, font, |
| 5663 |
* etc. get set for hboxPtr; old resources get freed, if there |
| 5664 |
* were any. The widget is redisplayed. |
| 5665 |
* |
| 5666 |
*---------------------------------------------------------------------- |
| 5667 |
*/ |
| 5668 |
static int |
| 5669 |
ConfigureOp(hboxPtr, interp, argc, argv) |
| 5670 |
Hierbox *hboxPtr; |
| 5671 |
Tcl_Interp *interp; |
| 5672 |
int argc; |
| 5673 |
char **argv; |
| 5674 |
{ |
| 5675 |
if (argc == 2) { |
| 5676 |
return Tk_ConfigureInfo(interp, hboxPtr->tkwin, configSpecs, |
| 5677 |
(char *)hboxPtr, (char *)NULL, 0); |
| 5678 |
} else if (argc == 3) { |
| 5679 |
return Tk_ConfigureInfo(interp, hboxPtr->tkwin, configSpecs, |
| 5680 |
(char *)hboxPtr, argv[2], 0); |
| 5681 |
} |
| 5682 |
if (ConfigureHierbox(interp, hboxPtr, argc - 2, argv + 2, |
| 5683 |
TK_CONFIG_ARGV_ONLY) != TCL_OK) { |
| 5684 |
return TCL_ERROR; |
| 5685 |
} |
| 5686 |
EventuallyRedraw(hboxPtr); |
| 5687 |
return TCL_OK; |
| 5688 |
} |
| 5689 |
|
| 5690 |
/*ARGSUSED*/ |
| 5691 |
static int |
| 5692 |
CurselectionOp(hboxPtr, interp, argc, argv) |
| 5693 |
Hierbox *hboxPtr; |
| 5694 |
Tcl_Interp *interp; /* Not used. */ |
| 5695 |
int argc; /* Not used. */ |
| 5696 |
char **argv; /* Not used. */ |
| 5697 |
{ |
| 5698 |
if (hboxPtr->sortSelection) { |
| 5699 |
ApplyToTree(hboxPtr, hboxPtr->rootPtr, IsSelectedNode, |
| 5700 |
APPLY_RECURSE | APPLY_OPEN_ONLY | APPLY_BEFORE); |
| 5701 |
} else { |
| 5702 |
Blt_ChainLink *linkPtr; |
| 5703 |
Tree *treePtr; |
| 5704 |
|
| 5705 |
for (linkPtr = Blt_ChainFirstLink(&(hboxPtr->selectChain)); |
| 5706 |
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 5707 |
treePtr = Blt_ChainGetValue(linkPtr); |
| 5708 |
Tcl_AppendElement(interp, NodeToString(hboxPtr, treePtr)); |
| 5709 |
} |
| 5710 |
} |
| 5711 |
return TCL_OK; |
| 5712 |
} |
| 5713 |
|
| 5714 |
/* |
| 5715 |
*---------------------------------------------------------------------- |
| 5716 |
* |
| 5717 |
* ActivateOpOp -- |
| 5718 |
* |
| 5719 |
* Selects the tab to appear active. |
| 5720 |
* |
| 5721 |
*---------------------------------------------------------------------- |
| 5722 |
*/ |
| 5723 |
/*ARGSUSED*/ |
| 5724 |
static int |
| 5725 |
ActivateOpOp(hboxPtr, interp, argc, argv) |
| 5726 |
Hierbox *hboxPtr; |
| 5727 |
Tcl_Interp *interp; |
| 5728 |
int argc; /* Not used. */ |
| 5729 |
char **argv; |
| 5730 |
{ |
| 5731 |
Tree *treePtr, *oldPtr; |
| 5732 |
|
| 5733 |
treePtr = hboxPtr->focusPtr; |
| 5734 |
if (argv[3][0] == '\0') { |
| 5735 |
treePtr = NULL; |
| 5736 |
} else if (GetNode(hboxPtr, argv[3], &treePtr) != TCL_OK) { |
| 5737 |
return TCL_ERROR; |
| 5738 |
} |
| 5739 |
oldPtr = hboxPtr->activePtr; |
| 5740 |
hboxPtr->activePtr = treePtr; |
| 5741 |
if (treePtr != oldPtr) { |
| 5742 |
EventuallyRedraw(hboxPtr); |
| 5743 |
} |
| 5744 |
return TCL_OK; |
| 5745 |
} |
| 5746 |
|
| 5747 |
/* |
| 5748 |
*---------------------------------------------------------------------- |
| 5749 |
* |
| 5750 |
* BindOp -- |
| 5751 |
* |
| 5752 |
* .t bind index sequence command |
| 5753 |
* |
| 5754 |
*---------------------------------------------------------------------- |
| 5755 |
*/ |
| 5756 |
/*ARGSUSED*/ |
| 5757 |
static int |
| 5758 |
BindOp(hboxPtr, interp, argc, argv) |
| 5759 |
Hierbox *hboxPtr; |
| 5760 |
Tcl_Interp *interp; |
| 5761 |
int argc; /* Not used. */ |
| 5762 |
char **argv; |
| 5763 |
{ |
| 5764 |
ClientData item; |
| 5765 |
|
| 5766 |
/* |
| 5767 |
* Individual entries are selected by inode only. All other strings |
| 5768 |
* are interpreted as a binding tag. |
| 5769 |
*/ |
| 5770 |
item = GetNodeByIndex(hboxPtr, argv[2]); |
| 5771 |
if (item == 0) { |
| 5772 |
item = (ClientData)Tk_GetUid(argv[2]); |
| 5773 |
} |
| 5774 |
return Blt_ConfigureBindings(interp, hboxPtr->bindTable, item, argc - 3, |
| 5775 |
argv + 3); |
| 5776 |
} |
| 5777 |
|
| 5778 |
/* |
| 5779 |
*---------------------------------------------------------------------- |
| 5780 |
* |
| 5781 |
* CgetOpOp -- |
| 5782 |
* |
| 5783 |
*---------------------------------------------------------------------- |
| 5784 |
*/ |
| 5785 |
/*ARGSUSED*/ |
| 5786 |
static int |
| 5787 |
CgetOpOp(hboxPtr, interp, argc, argv) |
| 5788 |
Hierbox *hboxPtr; |
| 5789 |
Tcl_Interp *interp; |
| 5790 |
int argc; /* Not used. */ |
| 5791 |
char **argv; |
| 5792 |
{ |
| 5793 |
Tree *treePtr; |
| 5794 |
|
| 5795 |
if (StringToNode(hboxPtr, argv[3], &treePtr) != TCL_OK) { |
| 5796 |
return TCL_ERROR; |
| 5797 |
} |
| 5798 |
return Tk_ConfigureValue(interp, hboxPtr->tkwin, entryConfigSpecs, |
| 5799 |
(char *)treePtr->entryPtr, argv[4], 0); |
| 5800 |
} |
| 5801 |
|
| 5802 |
/* |
| 5803 |
*---------------------------------------------------------------------- |
| 5804 |
* |
| 5805 |
* ConfigureOpOp -- |
| 5806 |
* |
| 5807 |
* This procedure is called to process a list of configuration |
| 5808 |
* options database, in order to reconfigure the one of more |
| 5809 |
* entries in the widget. |
| 5810 |
* |
| 5811 |
* .h entryconfigure node node node node option value |
| 5812 |
* |
| 5813 |
* Results: |
| 5814 |
* A standard Tcl result. If TCL_ERROR is returned, then |
| 5815 |
* interp->result contains an error message. |
| 5816 |
* |
| 5817 |
* Side effects: |
| 5818 |
* Configuration information, such as text string, colors, font, |
| 5819 |
* etc. get set for hboxPtr; old resources get freed, if there |
| 5820 |
* were any. The hypertext is redisplayed. |
| 5821 |
* |
| 5822 |
*---------------------------------------------------------------------- |
| 5823 |
*/ |
| 5824 |
static int |
| 5825 |
ConfigureOpOp(hboxPtr, interp, argc, argv) |
| 5826 |
Hierbox *hboxPtr; |
| 5827 |
Tcl_Interp *interp; |
| 5828 |
int argc; |
| 5829 |
char **argv; |
| 5830 |
{ |
| 5831 |
int nIds, nOpts; |
| 5832 |
CONST char **options; |
| 5833 |
register int i; |
| 5834 |
Tree *treePtr; |
| 5835 |
|
| 5836 |
|
| 5837 |
/* Figure out where the option value pairs begin */ |
| 5838 |
argc -= 3; |
| 5839 |
argv += 3; |
| 5840 |
for (i = 0; i < argc; i++) { |
| 5841 |
if (argv[i][0] == '-') { |
| 5842 |
break; |
| 5843 |
} |
| 5844 |
if (StringToNode(hboxPtr, argv[i], &treePtr) != TCL_OK) { |
| 5845 |
return TCL_ERROR; /* Can't find node. */ |
| 5846 |
} |
| 5847 |
} |
| 5848 |
nIds = i; /* Number of element names specified */ |
| 5849 |
nOpts = argc - i; /* Number of options specified */ |
| 5850 |
options = (CONST char **)argv + i; /* Start of options in argv */ |
| 5851 |
|
| 5852 |
for (i = 0; i < nIds; i++) { |
| 5853 |
StringToNode(hboxPtr, argv[i], &treePtr); |
| 5854 |
if (argc == 1) { |
| 5855 |
return Tk_ConfigureInfo(interp, hboxPtr->tkwin, entryConfigSpecs, |
| 5856 |
(char *)treePtr->entryPtr, (char *)NULL, 0); |
| 5857 |
} else if (argc == 2) { |
| 5858 |
return Tk_ConfigureInfo(interp, hboxPtr->tkwin, entryConfigSpecs, |
| 5859 |
(char *)treePtr->entryPtr, argv[2], 0); |
| 5860 |
} |
| 5861 |
if (ConfigureEntry(hboxPtr, treePtr->entryPtr, nOpts, options, |
| 5862 |
TK_CONFIG_ARGV_ONLY) != TCL_OK) { |
| 5863 |
return TCL_ERROR; |
| 5864 |
} |
| 5865 |
} |
| 5866 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 5867 |
EventuallyRedraw(hboxPtr); |
| 5868 |
return TCL_OK; |
| 5869 |
} |
| 5870 |
|
| 5871 |
/* |
| 5872 |
*---------------------------------------------------------------------- |
| 5873 |
* |
| 5874 |
* IsHiddenOpOp -- |
| 5875 |
* |
| 5876 |
*---------------------------------------------------------------------- |
| 5877 |
*/ |
| 5878 |
/*ARGSUSED*/ |
| 5879 |
static int |
| 5880 |
IsHiddenOpOp(hboxPtr, interp, argc, argv) |
| 5881 |
Hierbox *hboxPtr; |
| 5882 |
Tcl_Interp *interp; |
| 5883 |
int argc; /* Not used. */ |
| 5884 |
char **argv; |
| 5885 |
{ |
| 5886 |
Tree *treePtr; |
| 5887 |
|
| 5888 |
if (StringToNode(hboxPtr, argv[3], &treePtr) != TCL_OK) { |
| 5889 |
return TCL_ERROR; |
| 5890 |
} |
| 5891 |
Blt_SetBooleanResult(interp, IsHidden(treePtr)); |
| 5892 |
return TCL_OK; |
| 5893 |
} |
| 5894 |
|
| 5895 |
/*ARGSUSED*/ |
| 5896 |
static int |
| 5897 |
IsBeforeOpOp(hboxPtr, interp, argc, argv) |
| 5898 |
Hierbox *hboxPtr; |
| 5899 |
Tcl_Interp *interp; |
| 5900 |
int argc; /* Not used. */ |
| 5901 |
char **argv; |
| 5902 |
{ |
| 5903 |
Tree *n1Ptr, *n2Ptr; |
| 5904 |
|
| 5905 |
if ((StringToNode(hboxPtr, argv[3], &n1Ptr) != TCL_OK) || |
| 5906 |
(StringToNode(hboxPtr, argv[4], &n2Ptr) != TCL_OK)) { |
| 5907 |
return TCL_ERROR; |
| 5908 |
} |
| 5909 |
Blt_SetBooleanResult(interp, IsBefore(n1Ptr, n2Ptr)); |
| 5910 |
return TCL_OK; |
| 5911 |
} |
| 5912 |
|
| 5913 |
|
| 5914 |
static int |
| 5915 |
ScreenToIndex(hboxPtr, x, y) |
| 5916 |
Hierbox *hboxPtr; |
| 5917 |
int x, y; |
| 5918 |
{ |
| 5919 |
Tk_Font font; |
| 5920 |
TextStyle ts; |
| 5921 |
TextLayout *textPtr; |
| 5922 |
Tk_FontMetrics fontMetrics; |
| 5923 |
TextFragment *fragPtr; |
| 5924 |
int nBytes; |
| 5925 |
Entry *entryPtr; |
| 5926 |
Tree *treePtr; |
| 5927 |
int lineNum; |
| 5928 |
register int i; |
| 5929 |
|
| 5930 |
treePtr = hboxPtr->focusPtr; |
| 5931 |
entryPtr = treePtr->entryPtr; |
| 5932 |
|
| 5933 |
if (*entryPtr->labelText == '\0') { |
| 5934 |
return 0; |
| 5935 |
} |
| 5936 |
/* |
| 5937 |
* Compute the X-Y offsets of the screen point from the start of |
| 5938 |
* label. Force the offsets to point within the label. |
| 5939 |
*/ |
| 5940 |
x -= SCREENX(hboxPtr, entryPtr->worldX) + LABEL_PADX + |
| 5941 |
hboxPtr->selBorderWidth; |
| 5942 |
y -= SCREENY(hboxPtr, entryPtr->worldY) + LABEL_PADY + |
| 5943 |
hboxPtr->selBorderWidth; |
| 5944 |
x -= LEVELWIDTH(treePtr->level) + LEVELWIDTH(treePtr->level + 1) + 4; |
| 5945 |
|
| 5946 |
font = GETFONT(hboxPtr, entryPtr->labelFont); |
| 5947 |
memset(&ts, 0, sizeof(TextStyle)); |
| 5948 |
ts.font = font; |
| 5949 |
ts.justify = TK_JUSTIFY_LEFT; |
| 5950 |
ts.shadow.offset = entryPtr->labelShadow.offset; |
| 5951 |
textPtr = Blt_GetTextLayout(entryPtr->labelText, &ts); |
| 5952 |
|
| 5953 |
if (y < 0) { |
| 5954 |
y = 0; |
| 5955 |
} else if (y >= textPtr->height) { |
| 5956 |
y = textPtr->height - 1; |
| 5957 |
} |
| 5958 |
Tk_GetFontMetrics(font, &fontMetrics); |
| 5959 |
lineNum = y / fontMetrics.linespace; |
| 5960 |
fragPtr = textPtr->fragArr + lineNum; |
| 5961 |
|
| 5962 |
if (x < 0) { |
| 5963 |
nBytes = 0; |
| 5964 |
} else if (x >= textPtr->width) { |
| 5965 |
nBytes = fragPtr->count; |
| 5966 |
} else { |
| 5967 |
int newX; |
| 5968 |
/* Find the character underneath the pointer. */ |
| 5969 |
nBytes = Tk_MeasureChars(font, fragPtr->text, fragPtr->count, x, 0, |
| 5970 |
&newX); |
| 5971 |
if ((newX < x) && (nBytes < fragPtr->count)) { |
| 5972 |
double fract; |
| 5973 |
int length, charSize; |
| 5974 |
char *next; |
| 5975 |
|
| 5976 |
next = fragPtr->text + nBytes; |
| 5977 |
#if HAVE_UTF |
| 5978 |
{ |
| 5979 |
Tcl_UniChar dummy; |
| 5980 |
|
| 5981 |
length = Tcl_UtfToUniChar(next, &dummy); |
| 5982 |
} |
| 5983 |
#else |
| 5984 |
length = 1; |
| 5985 |
#endif |
| 5986 |
charSize = Tk_TextWidth(font, next, length); |
| 5987 |
fract = ((double)(x - newX) / (double)charSize); |
| 5988 |
if (ROUND(fract)) { |
| 5989 |
nBytes += length; |
| 5990 |
} |
| 5991 |
} |
| 5992 |
} |
| 5993 |
for (i = lineNum - 1; i >= 0; i--) { |
| 5994 |
fragPtr--; |
| 5995 |
nBytes += fragPtr->count + 1; |
| 5996 |
} |
| 5997 |
Blt_Free(textPtr); |
| 5998 |
return nBytes; |
| 5999 |
} |
| 6000 |
|
| 6001 |
/* |
| 6002 |
*--------------------------------------------------------------------------- |
| 6003 |
* |
| 6004 |
* GetLabelIndex -- |
| 6005 |
* |
| 6006 |
* Parse an index into an entry and return either its value |
| 6007 |
* or an error. |
| 6008 |
* |
| 6009 |
* Results: |
| 6010 |
* A standard Tcl result. If all went well, then *indexPtr is |
| 6011 |
* filled in with the character index (into entryPtr) corresponding to |
| 6012 |
* string. The index value is guaranteed to lie between 0 and |
| 6013 |
* the number of characters in the string, inclusive. If an |
| 6014 |
* error occurs then an error message is left in the interp's result. |
| 6015 |
* |
| 6016 |
* Side effects: |
| 6017 |
* None. |
| 6018 |
* |
| 6019 |
*--------------------------------------------------------------------------- |
| 6020 |
*/ |
| 6021 |
static int |
| 6022 |
GetLabelIndex(hboxPtr, entryPtr, string, indexPtr) |
| 6023 |
Hierbox *hboxPtr; |
| 6024 |
Entry *entryPtr; |
| 6025 |
char *string; |
| 6026 |
int *indexPtr; |
| 6027 |
{ |
| 6028 |
Tcl_Interp *interp = hboxPtr->interp; |
| 6029 |
TextEdit *editPtr = &(hboxPtr->labelEdit); |
| 6030 |
char c; |
| 6031 |
|
| 6032 |
c = string[0]; |
| 6033 |
if ((c == 'a') && (strcmp(string, "anchor") == 0)) { |
| 6034 |
*indexPtr = editPtr->selAnchor; |
| 6035 |
} else if ((c == 'e') && (strcmp(string, "end") == 0)) { |
| 6036 |
*indexPtr = strlen(entryPtr->labelText); |
| 6037 |
} else if ((c == 'i') && (strcmp(string, "insert") == 0)) { |
| 6038 |
*indexPtr = editPtr->insertPos; |
| 6039 |
} else if ((c == 's') && (strcmp(string, "sel.first") == 0)) { |
| 6040 |
if (editPtr->selFirst < 0) { |
| 6041 |
Tcl_AppendResult(interp, "nothing is selected", (char *)NULL); |
| 6042 |
return TCL_ERROR; |
| 6043 |
} |
| 6044 |
*indexPtr = editPtr->selFirst; |
| 6045 |
} else if ((c == 's') && (strcmp(string, "sel.last") == 0)) { |
| 6046 |
if (editPtr->selLast < 0) { |
| 6047 |
Tcl_AppendResult(interp, "nothing is selected", (char *)NULL); |
| 6048 |
return TCL_ERROR; |
| 6049 |
} |
| 6050 |
*indexPtr = editPtr->selLast; |
| 6051 |
} else if (c == '@') { |
| 6052 |
int x, y; |
| 6053 |
|
| 6054 |
if (Blt_GetXY(interp, hboxPtr->tkwin, string, &x, &y) != TCL_OK) { |
| 6055 |
return TCL_ERROR; |
| 6056 |
} |
| 6057 |
*indexPtr = ScreenToIndex(hboxPtr, x, y); |
| 6058 |
} else if (isdigit((int)c)) { |
| 6059 |
int number; |
| 6060 |
int maxChars; |
| 6061 |
|
| 6062 |
if (Tcl_GetInt(interp, string, &number) != TCL_OK) { |
| 6063 |
return TCL_ERROR; |
| 6064 |
} |
| 6065 |
/* Don't allow the index to point outside the label. */ |
| 6066 |
maxChars = Tcl_NumUtfChars(entryPtr->labelText, -1); |
| 6067 |
if (number < 0) { |
| 6068 |
*indexPtr = 0; |
| 6069 |
} else if (number > maxChars) { |
| 6070 |
*indexPtr = strlen(entryPtr->labelText); |
| 6071 |
} else { |
| 6072 |
*indexPtr = Tcl_UtfAtIndex(entryPtr->labelText, number) - |
| 6073 |
entryPtr->labelText; |
| 6074 |
} |
| 6075 |
} else { |
| 6076 |
Tcl_AppendResult(interp, "bad label index \"", string, "\"", |
| 6077 |
(char *)NULL); |
| 6078 |
return TCL_ERROR; |
| 6079 |
} |
| 6080 |
return TCL_OK; |
| 6081 |
} |
| 6082 |
|
| 6083 |
/* |
| 6084 |
*---------------------------------------------------------------------- |
| 6085 |
* |
| 6086 |
* IndexOpOp -- |
| 6087 |
* |
| 6088 |
* Returns the numeric index of the given string. Indices can be |
| 6089 |
* one of the following: |
| 6090 |
* |
| 6091 |
* "anchor" Selection anchor. |
| 6092 |
* "end" End of the label. |
| 6093 |
* "insert" Insertion cursor. |
| 6094 |
* "sel.first" First character selected. |
| 6095 |
* "sel.last" Last character selected. |
| 6096 |
* @x,y Index at X-Y screen coordinate. |
| 6097 |
* number Returns the same number. |
| 6098 |
* |
| 6099 |
* Results: |
| 6100 |
* A standard Tcl result. If the argument does not represent a |
| 6101 |
* valid label index, then TCL_ERROR is returned and the interpreter |
| 6102 |
* result will contain an error message. |
| 6103 |
* |
| 6104 |
*---------------------------------------------------------------------- |
| 6105 |
*/ |
| 6106 |
/*ARGSUSED*/ |
| 6107 |
static int |
| 6108 |
IndexOpOp(hboxPtr, interp, argc, argv) |
| 6109 |
Hierbox *hboxPtr; |
| 6110 |
Tcl_Interp *interp; |
| 6111 |
int argc; /* Not used. */ |
| 6112 |
char **argv; |
| 6113 |
{ |
| 6114 |
Entry *entryPtr; |
| 6115 |
int nBytes, nChars; |
| 6116 |
|
| 6117 |
entryPtr = hboxPtr->focusPtr->entryPtr; |
| 6118 |
if (GetLabelIndex(hboxPtr, entryPtr, argv[3], &nBytes) != TCL_OK) { |
| 6119 |
return TCL_ERROR; |
| 6120 |
} |
| 6121 |
nChars = Tcl_NumUtfChars(entryPtr->labelText, nBytes); |
| 6122 |
Tcl_SetResult(interp, Blt_Itoa(nChars), TCL_VOLATILE); |
| 6123 |
return TCL_OK; |
| 6124 |
} |
| 6125 |
|
| 6126 |
/* |
| 6127 |
*---------------------------------------------------------------------- |
| 6128 |
* |
| 6129 |
* InsertOpOp -- |
| 6130 |
* |
| 6131 |
* Add new characters to the label of an entry. |
| 6132 |
* |
| 6133 |
* Results: |
| 6134 |
* None. |
| 6135 |
* |
| 6136 |
* Side effects: |
| 6137 |
* New information gets added to editPtr; it will be redisplayed |
| 6138 |
* soon, but not necessarily immediately. |
| 6139 |
* |
| 6140 |
*---------------------------------------------------------------------- |
| 6141 |
*/ |
| 6142 |
/*ARGSUSED*/ |
| 6143 |
static int |
| 6144 |
InsertOpOp(hboxPtr, interp, argc, argv) |
| 6145 |
Hierbox *hboxPtr; |
| 6146 |
Tcl_Interp *interp; /* Not used. */ |
| 6147 |
int argc; |
| 6148 |
char **argv; |
| 6149 |
{ |
| 6150 |
Tree *treePtr; |
| 6151 |
Entry *entryPtr; |
| 6152 |
TextEdit *editPtr = &(hboxPtr->labelEdit); |
| 6153 |
int oldSize, newSize; |
| 6154 |
char *string; |
| 6155 |
int extra; |
| 6156 |
int insertPos; |
| 6157 |
|
| 6158 |
if (!hboxPtr->focusEdit) { |
| 6159 |
return TCL_OK; /* Not in edit mode. */ |
| 6160 |
} |
| 6161 |
if (StringToNode(hboxPtr, argv[3], &treePtr) != TCL_OK) { |
| 6162 |
return TCL_ERROR; |
| 6163 |
} |
| 6164 |
if (treePtr == NULL) { |
| 6165 |
return TCL_OK; /* Not in edit mode. */ |
| 6166 |
} |
| 6167 |
entryPtr = treePtr->entryPtr; |
| 6168 |
if (hboxPtr->focusPtr != treePtr) { |
| 6169 |
hboxPtr->focusPtr = treePtr; |
| 6170 |
editPtr->insertPos = strlen(entryPtr->labelText); |
| 6171 |
editPtr->selAnchor = editPtr->selFirst = editPtr->selLast = -1; |
| 6172 |
} |
| 6173 |
if (GetLabelIndex(hboxPtr, entryPtr, argv[4], &insertPos) != TCL_OK) { |
| 6174 |
return TCL_ERROR; |
| 6175 |
} |
| 6176 |
extra = strlen(argv[5]); |
| 6177 |
if (extra == 0) { |
| 6178 |
/* Nothing to insert. Move the cursor anyways. */ |
| 6179 |
editPtr->insertPos = insertPos; |
| 6180 |
EventuallyRedraw(hboxPtr); |
| 6181 |
return TCL_OK; |
| 6182 |
} |
| 6183 |
oldSize = strlen(entryPtr->labelText); |
| 6184 |
newSize = oldSize + extra; |
| 6185 |
string = Blt_Malloc(sizeof(char) * (newSize + 1)); |
| 6186 |
|
| 6187 |
if (insertPos == oldSize) { /* Append */ |
| 6188 |
strcpy(string, entryPtr->labelText); |
| 6189 |
strcat(string, argv[5]); |
| 6190 |
} else if (insertPos == 0) {/* Prepend */ |
| 6191 |
strcpy(string, argv[5]); |
| 6192 |
strcat(string, entryPtr->labelText); |
| 6193 |
} else { /* Insert into existing. */ |
| 6194 |
char *left, *right; |
| 6195 |
char *p; |
| 6196 |
|
| 6197 |
left = entryPtr->labelText; |
| 6198 |
right = left + insertPos; |
| 6199 |
p = string; |
| 6200 |
strncpy(p, left, insertPos); |
| 6201 |
p += insertPos; |
| 6202 |
strcpy(p, argv[5]); |
| 6203 |
p += extra; |
| 6204 |
strcpy(p, right); |
| 6205 |
} |
| 6206 |
/* |
| 6207 |
* All indices from the start of the insertion to the end of the |
| 6208 |
* string need to be updated. Simply move the indices down by the |
| 6209 |
* number of characters added. |
| 6210 |
*/ |
| 6211 |
if (editPtr->selFirst >= insertPos) { |
| 6212 |
editPtr->selFirst += extra; |
| 6213 |
} |
| 6214 |
if (editPtr->selLast > insertPos) { |
| 6215 |
editPtr->selLast += extra; |
| 6216 |
} |
| 6217 |
if ((editPtr->selAnchor > insertPos) || (editPtr->selFirst >= insertPos)) { |
| 6218 |
editPtr->selAnchor += extra; |
| 6219 |
} |
| 6220 |
Blt_Free(entryPtr->labelText); |
| 6221 |
entryPtr->labelText = string; |
| 6222 |
|
| 6223 |
editPtr->insertPos = insertPos + extra; |
| 6224 |
GetCursorLocation(hboxPtr, treePtr); |
| 6225 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 6226 |
EventuallyRedraw(hboxPtr); |
| 6227 |
return TCL_OK; |
| 6228 |
} |
| 6229 |
|
| 6230 |
/* |
| 6231 |
*---------------------------------------------------------------------- |
| 6232 |
* |
| 6233 |
* DeleteOpOp -- |
| 6234 |
* |
| 6235 |
* Remove one or more characters from the label of an entry. |
| 6236 |
* |
| 6237 |
* Results: |
| 6238 |
* None. |
| 6239 |
* |
| 6240 |
* Side effects: |
| 6241 |
* Memory gets freed, the entry gets modified and (eventually) |
| 6242 |
* redisplayed. |
| 6243 |
* |
| 6244 |
*---------------------------------------------------------------------- |
| 6245 |
*/ |
| 6246 |
/*ARGSUSED*/ |
| 6247 |
static int |
| 6248 |
DeleteOpOp(hboxPtr, interp, argc, argv) |
| 6249 |
Hierbox *hboxPtr; |
| 6250 |
Tcl_Interp *interp; /* Not used. */ |
| 6251 |
int argc; |
| 6252 |
char **argv; |
| 6253 |
{ |
| 6254 |
TextEdit *editPtr = &(hboxPtr->labelEdit); |
| 6255 |
Tree *treePtr; |
| 6256 |
Entry *entryPtr; |
| 6257 |
int oldSize, newSize; |
| 6258 |
int nDeleted; |
| 6259 |
int first, last; |
| 6260 |
char *string; |
| 6261 |
char *p; |
| 6262 |
|
| 6263 |
if (!hboxPtr->focusEdit) { |
| 6264 |
return TCL_OK; /* Not in edit mode. */ |
| 6265 |
} |
| 6266 |
if (StringToNode(hboxPtr, argv[3], &treePtr) != TCL_OK) { |
| 6267 |
return TCL_ERROR; |
| 6268 |
} |
| 6269 |
if (treePtr == NULL) { |
| 6270 |
return TCL_OK; /* Not in edit mode. */ |
| 6271 |
} |
| 6272 |
entryPtr = treePtr->entryPtr; |
| 6273 |
if (hboxPtr->focusPtr != treePtr) { |
| 6274 |
hboxPtr->focusPtr = treePtr; |
| 6275 |
editPtr->insertPos = strlen(entryPtr->labelText); |
| 6276 |
editPtr->selAnchor = editPtr->selFirst = editPtr->selLast = -1; |
| 6277 |
} |
| 6278 |
if ((GetLabelIndex(hboxPtr, entryPtr, argv[4], &first) != TCL_OK) || |
| 6279 |
(GetLabelIndex(hboxPtr, entryPtr, argv[5], &last) != TCL_OK)) { |
| 6280 |
return TCL_ERROR; |
| 6281 |
} |
| 6282 |
if (first >= last) { |
| 6283 |
return TCL_OK; |
| 6284 |
} |
| 6285 |
if ((!hboxPtr->focusEdit) || (entryPtr == NULL)) { |
| 6286 |
return TCL_OK; /* Not in edit mode. */ |
| 6287 |
} |
| 6288 |
oldSize = strlen(entryPtr->labelText); |
| 6289 |
newSize = oldSize - (last - first); |
| 6290 |
p = string = Blt_Malloc(sizeof(char) * (newSize + 1)); |
| 6291 |
strncpy(p, entryPtr->labelText, first); |
| 6292 |
p += first; |
| 6293 |
strcpy(p, entryPtr->labelText + last); |
| 6294 |
|
| 6295 |
Blt_Free(entryPtr->labelText); |
| 6296 |
entryPtr->labelText = string; |
| 6297 |
nDeleted = last - first + 1; |
| 6298 |
|
| 6299 |
/* |
| 6300 |
* Since deleting characters compacts the character array, we need to |
| 6301 |
* update the various character indices according. It depends where |
| 6302 |
* the index occurs in relation to range of deleted characters: |
| 6303 |
* |
| 6304 |
* before Ignore. |
| 6305 |
* within Move the index back to the start of the deletion. |
| 6306 |
* after Subtract off the deleted number of characters, |
| 6307 |
* since the array has been compressed by that |
| 6308 |
* many characters. |
| 6309 |
* |
| 6310 |
*/ |
| 6311 |
if (editPtr->selFirst >= first) { |
| 6312 |
if (editPtr->selFirst >= last) { |
| 6313 |
editPtr->selFirst -= nDeleted; |
| 6314 |
} else { |
| 6315 |
editPtr->selFirst = first; |
| 6316 |
} |
| 6317 |
} |
| 6318 |
if (editPtr->selLast >= first) { |
| 6319 |
if (editPtr->selLast >= last) { |
| 6320 |
editPtr->selLast -= nDeleted; |
| 6321 |
} else { |
| 6322 |
editPtr->selLast = first; |
| 6323 |
} |
| 6324 |
} |
| 6325 |
if (editPtr->selLast <= editPtr->selFirst) { |
| 6326 |
editPtr->selFirst = editPtr->selLast = -1; /* Cut away the entire |
| 6327 |
* selection. */ |
| 6328 |
} |
| 6329 |
if (editPtr->selAnchor >= first) { |
| 6330 |
if (editPtr->selAnchor >= last) { |
| 6331 |
editPtr->selAnchor -= nDeleted; |
| 6332 |
} else { |
| 6333 |
editPtr->selAnchor = first; |
| 6334 |
} |
| 6335 |
} |
| 6336 |
if (editPtr->insertPos >= first) { |
| 6337 |
if (editPtr->insertPos >= last) { |
| 6338 |
editPtr->insertPos -= nDeleted; |
| 6339 |
} else { |
| 6340 |
editPtr->insertPos = first; |
| 6341 |
} |
| 6342 |
} |
| 6343 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 6344 |
EventuallyRedraw(hboxPtr); |
| 6345 |
return TCL_OK; |
| 6346 |
} |
| 6347 |
|
| 6348 |
/* |
| 6349 |
*---------------------------------------------------------------------- |
| 6350 |
* |
| 6351 |
* IsOpenOpOp -- |
| 6352 |
* |
| 6353 |
*---------------------------------------------------------------------- |
| 6354 |
*/ |
| 6355 |
/*ARGSUSED*/ |
| 6356 |
static int |
| 6357 |
IsOpenOpOp(hboxPtr, interp, argc, argv) |
| 6358 |
Hierbox *hboxPtr; |
| 6359 |
Tcl_Interp *interp; |
| 6360 |
int argc; /* Not used. */ |
| 6361 |
char **argv; |
| 6362 |
{ |
| 6363 |
Tree *treePtr; |
| 6364 |
|
| 6365 |
if (StringToNode(hboxPtr, argv[3], &treePtr) != TCL_OK) { |
| 6366 |
return TCL_ERROR; |
| 6367 |
} |
| 6368 |
Blt_SetBooleanResult(interp, (treePtr->entryPtr->flags & ENTRY_OPEN)); |
| 6369 |
return TCL_OK; |
| 6370 |
} |
| 6371 |
|
| 6372 |
/*ARGSUSED*/ |
| 6373 |
static int |
| 6374 |
ChildrenOpOp(hboxPtr, interp, argc, argv) |
| 6375 |
Hierbox *hboxPtr; |
| 6376 |
Tcl_Interp *interp; |
| 6377 |
int argc; |
| 6378 |
char **argv; |
| 6379 |
{ |
| 6380 |
Tree *parentPtr, *nodePtr; |
| 6381 |
|
| 6382 |
if (StringToNode(hboxPtr, argv[3], &parentPtr) != TCL_OK) { |
| 6383 |
return TCL_ERROR; |
| 6384 |
} |
| 6385 |
if (argc == 4) { |
| 6386 |
Blt_ChainLink *linkPtr; |
| 6387 |
|
| 6388 |
for (linkPtr = Blt_ChainFirstLink(parentPtr->chainPtr); linkPtr != NULL; |
| 6389 |
linkPtr = Blt_ChainNextLink(linkPtr)) { |
| 6390 |
nodePtr = Blt_ChainGetValue(linkPtr); |
| 6391 |
Tcl_AppendElement(interp, NodeToString(hboxPtr, nodePtr)); |
| 6392 |
} |
| 6393 |
} else if (argc == 6) { |
| 6394 |
Blt_ChainLink *firstPtr, *lastPtr; |
| 6395 |
int first, last; |
| 6396 |
int nNodes; |
| 6397 |
|
| 6398 |
if ((Blt_GetPosition(interp, argv[4], &first) != TCL_OK) || |
| 6399 |
(Blt_GetPosition(interp, argv[5], &last) != TCL_OK)) { |
| 6400 |
return TCL_ERROR; |
| 6401 |
} |
| 6402 |
nNodes = Blt_ChainGetLength(parentPtr->chainPtr); |
| 6403 |
if (nNodes == 0) { |
| 6404 |
return TCL_OK; |
| 6405 |
} |
| 6406 |
if ((last == -1) || (last >= nNodes)) { |
| 6407 |
last = nNodes - 1; |
| 6408 |
} |
| 6409 |
if ((first == -1) || (first >= nNodes)) { |
| 6410 |
first = nNodes - 1; |
| 6411 |
} |
| 6412 |
firstPtr = Blt_ChainGetNthLink(parentPtr->chainPtr, first); |
| 6413 |
lastPtr = Blt_ChainGetNthLink(parentPtr->chainPtr, last); |
| 6414 |
if (first > last) { |
| 6415 |
for ( /*empty*/ ; lastPtr != NULL; |
| 6416 |
lastPtr = Blt_ChainPrevLink(lastPtr)) { |
| 6417 |
nodePtr = Blt_ChainGetValue(lastPtr); |
| 6418 |
Tcl_AppendElement(interp, NodeToString(hboxPtr, nodePtr)); |
| 6419 |
if (lastPtr == firstPtr) { |
| 6420 |
break; |
| 6421 |
} |
| 6422 |
} |
| 6423 |
} else { |
| 6424 |
for ( /*empty*/ ; firstPtr != NULL; |
| 6425 |
firstPtr = Blt_ChainNextLink(firstPtr)) { |
| 6426 |
nodePtr = Blt_ChainGetValue(firstPtr); |
| 6427 |
Tcl_AppendElement(interp, NodeToString(hboxPtr, nodePtr)); |
| 6428 |
if (firstPtr == lastPtr) { |
| 6429 |
break; |
| 6430 |
} |
| 6431 |
} |
| 6432 |
} |
| 6433 |
} else { |
| 6434 |
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ", |
| 6435 |
argv[1], " ", argv[2], " index ?first last?", (char *)NULL); |
| 6436 |
return TCL_ERROR; |
| 6437 |
} |
| 6438 |
return TCL_OK; |
| 6439 |
} |
| 6440 |
|
| 6441 |
/* |
| 6442 |
*---------------------------------------------------------------------- |
| 6443 |
* |
| 6444 |
* SizeOpOp -- |
| 6445 |
* |
| 6446 |
* Counts the number of entries at this node. |
| 6447 |
* |
| 6448 |
* Results: |
| 6449 |
* A standard Tcl result. If an error occurred TCL_ERROR is |
| 6450 |
* returned and interp->result will contain an error message. |
| 6451 |
* Otherwise, TCL_OK is returned and interp->result contains |
| 6452 |
* the number of entries. |
| 6453 |
* |
| 6454 |
*---------------------------------------------------------------------- |
| 6455 |
*/ |
| 6456 |
static int |
| 6457 |
SizeOpOp(hboxPtr, interp, argc, argv) |
| 6458 |
Hierbox *hboxPtr; |
| 6459 |
Tcl_Interp *interp; |
| 6460 |
int argc; |
| 6461 |
char **argv; |
| 6462 |
{ |
| 6463 |
int length; |
| 6464 |
Tree *rootPtr; |
| 6465 |
int *sumPtr = (int *)&(hboxPtr->clientData); |
| 6466 |
|
| 6467 |
length = strlen(argv[3]); |
| 6468 |
if ((argv[3][0] == '-') && (length > 1) && |
| 6469 |
(strncmp(argv[3], "-recurse", length) == 0)) { |
| 6470 |
argv++, argc--; |
| 6471 |
} |
| 6472 |
if (argc == 3) { |
| 6473 |
Tcl_AppendResult(interp, "missing node argument: should be \"", |
| 6474 |
argv[0], " entry open node\"", (char *)NULL); |
| 6475 |
return TCL_ERROR; |
| 6476 |
} |
| 6477 |
if (StringToNode(hboxPtr, argv[3], &rootPtr) != TCL_OK) { |
| 6478 |
return TCL_ERROR; |
| 6479 |
} |
| 6480 |
*sumPtr = 0; |
| 6481 |
if (ApplyToTree(hboxPtr, rootPtr, SizeOfNode, 0) != TCL_OK) { |
| 6482 |
return TCL_ERROR; |
| 6483 |
} |
| 6484 |
Tcl_SetResult(interp, Blt_Itoa(*sumPtr), TCL_VOLATILE); |
| 6485 |
return TCL_OK; |
| 6486 |
} |
| 6487 |
|
| 6488 |
/* |
| 6489 |
*---------------------------------------------------------------------- |
| 6490 |
* |
| 6491 |
* EntryOp -- |
| 6492 |
* |
| 6493 |
* This procedure handles entry operations. |
| 6494 |
* |
| 6495 |
* Results: |
| 6496 |
* A standard Tcl result. |
| 6497 |
* |
| 6498 |
*---------------------------------------------------------------------- |
| 6499 |
*/ |
| 6500 |
|
| 6501 |
static Blt_OpSpec entryOperSpecs[] = |
| 6502 |
{ |
| 6503 |
{"activate", 1, (Blt_Op)ActivateOpOp, 4, 4, "node",}, |
| 6504 |
{"cget", 2, (Blt_Op)CgetOpOp, 5, 5, "node option",}, |
| 6505 |
{"children", 2, (Blt_Op)ChildrenOpOp, 4, 6, "node first last",}, |
| 6506 |
{"configure", 2, (Blt_Op)ConfigureOpOp, 4, 0, |
| 6507 |
"node ?node...? ?option value?...",}, |
| 6508 |
{"delete", 1, (Blt_Op)DeleteOpOp, 6, 6, "node first last"}, |
| 6509 |
{"highlight", 1, (Blt_Op)ActivateOpOp, 4, 4, "node",}, |
| 6510 |
{"index", 3, (Blt_Op)IndexOpOp, 6, 6, "index"}, |
| 6511 |
{"insert", 3, (Blt_Op)InsertOpOp, 6, 6, "node index string"}, |
| 6512 |
{"isbefore", 3, (Blt_Op)IsBeforeOpOp, 5, 5, "node node",}, |
| 6513 |
{"ishidden", 3, (Blt_Op)IsHiddenOpOp, 4, 4, "node",}, |
| 6514 |
{"isopen", 3, (Blt_Op)IsOpenOpOp, 4, 4, "node",}, |
| 6515 |
{"size", 1, (Blt_Op)SizeOpOp, 4, 5, "?-recurse? node",}, |
| 6516 |
}; |
| 6517 |
static int nEntrySpecs = sizeof(entryOperSpecs) / sizeof(Blt_OpSpec); |
| 6518 |
|
| 6519 |
static int |
| 6520 |
EntryOp(hboxPtr, interp, argc, argv) |
| 6521 |
Hierbox *hboxPtr; |
| 6522 |
Tcl_Interp *interp; |
| 6523 |
int argc; |
| 6524 |
char **argv; |
| 6525 |
{ |
| 6526 |
Blt_Op proc; |
| 6527 |
int result; |
| 6528 |
|
| 6529 |
proc = Blt_GetOp(interp, nEntrySpecs, entryOperSpecs, BLT_OP_ARG2, argc, |
| 6530 |
argv, 0); |
| 6531 |
if (proc == NULL) { |
| 6532 |
return TCL_ERROR; |
| 6533 |
} |
| 6534 |
result = (*proc) (hboxPtr, interp, argc, argv); |
| 6535 |
return result; |
| 6536 |
} |
| 6537 |
|
| 6538 |
/*ARGSUSED*/ |
| 6539 |
static int |
| 6540 |
ExactCompare(interp, name, pattern) |
| 6541 |
Tcl_Interp *interp; /* Not used. */ |
| 6542 |
char *name; |
| 6543 |
char *pattern; |
| 6544 |
{ |
| 6545 |
return (strcmp(name, pattern) == 0); |
| 6546 |
} |
| 6547 |
|
| 6548 |
/*ARGSUSED*/ |
| 6549 |
static int |
| 6550 |
GlobCompare(interp, name, pattern) |
| 6551 |
Tcl_Interp *interp; /* Not used. */ |
| 6552 |
char *name; |
| 6553 |
char *pattern; |
| 6554 |
{ |
| 6555 |
return Tcl_StringMatch(name, pattern); |
| 6556 |
} |
| 6557 |
|
| 6558 |
static int |
| 6559 |
RegexpCompare(interp, name, pattern) |
| 6560 |
Tcl_Interp *interp; |
| 6561 |
char *name; |
| 6562 |
char *pattern; |
| 6563 |
{ |
| 6564 |
return Tcl_RegExpMatch(interp, name, pattern); |
| 6565 |
} |
| 6566 |
|
| 6567 |
/* |
| 6568 |
*---------------------------------------------------------------------- |
| 6569 |
* |
| 6570 |
* FindOp -- |
| 6571 |
* |
| 6572 |
* Find one or more nodes based upon the pattern provided. |
| 6573 |
* |
| 6574 |
* Results: |
| 6575 |
* A standard Tcl result. The interpreter result will contain a |
| 6576 |
* list of the node serial identifiers. |
| 6577 |
* |
| 6578 |
*---------------------------------------------------------------------- |
| 6579 |
*/ |
| 6580 |
static int |
| 6581 |
FindOp(hboxPtr, interp, argc, argv) |
| 6582 |
Hierbox *hboxPtr; |
| 6583 |
Tcl_Interp *interp; |
| 6584 |
int argc; |
| 6585 |
char **argv; |
| 6586 |
{ |
| 6587 |
register Tree *treePtr; |
| 6588 |
Tree *firstPtr, *lastPtr; |
| 6589 |
int nMatches, maxMatches; |
| 6590 |
char c; |
| 6591 |
int length; |
| 6592 |
CompareProc *compareProc; |
| 6593 |
IterProc *nextProc; |
| 6594 |
int invertMatch; /* normal search mode (matching entries) */ |
| 6595 |
char *namePattern, *fullPattern; |
| 6596 |
char *execCmd; |
| 6597 |
register int i; |
| 6598 |
int result; |
| 6599 |
char *pattern; |
| 6600 |
char *option; |
| 6601 |
char *value; |
| 6602 |
Tcl_DString dString, pathString; |
| 6603 |
Blt_List optionList; |
| 6604 |
register Blt_ListNode node; |
| 6605 |
|
| 6606 |
invertMatch = FALSE; |
| 6607 |
maxMatches = 0; |
| 6608 |
execCmd = namePattern = fullPattern = NULL; |
| 6609 |
compareProc = ExactCompare; |
| 6610 |
nextProc = NextNode; |
| 6611 |
optionList = Blt_ListCreate(BLT_STRING_KEYS); |
| 6612 |
|
| 6613 |
/* |
| 6614 |
* Step 1: Process flags for find operation. |
| 6615 |
*/ |
| 6616 |
for (i = 2; i < argc; i++) { |
| 6617 |
if (argv[i][0] != '-') { |
| 6618 |
break; |
| 6619 |
} |
| 6620 |
option = argv[i] + 1; |
| 6621 |
length = strlen(option); |
| 6622 |
c = option[0]; |
| 6623 |
if ((c == 'e') && (length > 2) && |
| 6624 |
(strncmp(option, "exact", length) == 0)) { |
| 6625 |
compareProc = ExactCompare; |
| 6626 |
} else if ((c == 'g') && (strncmp(option, "glob", length) == 0)) { |
| 6627 |
compareProc = GlobCompare; |
| 6628 |
} else if ((c == 'r') && (strncmp(option, "regexp", length) == 0)) { |
| 6629 |
compareProc = RegexpCompare; |
| 6630 |
} else if ((c == 'n') && (length > 1) && |
| 6631 |
(strncmp(option, "nonmatching", length) == 0)) { |
| 6632 |
invertMatch = TRUE; |
| 6633 |
} else if ((c == 'n') && (length > 1) && |
| 6634 |
(strncmp(option, "name", length) == 0)) { |
| 6635 |
if ((i + 1) == argc) { |
| 6636 |
goto missingArg; |
| 6637 |
} |
| 6638 |
i++; |
| 6639 |
namePattern = argv[i]; |
| 6640 |
} else if ((c == 'f') && (strncmp(option, "full", length) == 0)) { |
| 6641 |
if ((i + 1) == argc) { |
| 6642 |
goto missingArg; |
| 6643 |
} |
| 6644 |
i++; |
| 6645 |
fullPattern = argv[i]; |
| 6646 |
} else if ((c == 'e') && (length > 2) && |
| 6647 |
(strncmp(option, "exec", length) == 0)) { |
| 6648 |
if ((i + 1) == argc) { |
| 6649 |
goto missingArg; |
| 6650 |
} |
| 6651 |
i++; |
| 6652 |
execCmd = argv[i]; |
| 6653 |
} else if ((c == 'c') && (strncmp(option, "count", length) == 0)) { |
| 6654 |
if ((i + 1) == argc) { |
| 6655 |
goto missingArg; |
| 6656 |
} |
| 6657 |
i++; |
| 6658 |
if (Tcl_GetInt(interp, argv[i], &maxMatches) != TCL_OK) { |
| 6659 |
return TCL_ERROR; |
| 6660 |
} |
| 6661 |
if (maxMatches < 0) { |
| 6662 |
Tcl_AppendResult(interp, "bad match count \"", argv[i], |
| 6663 |
"\": should be a positive number", (char *)NULL); |
| 6664 |
Blt_ListDestroy(optionList); |
| 6665 |
return TCL_ERROR; |
| 6666 |
} |
| 6667 |
} else if ((option[0] == '-') && (option[1] == '\0')) { |
| 6668 |
break; |
| 6669 |
} else { |
| 6670 |
/* |
| 6671 |
* Verify that the switch is actually an node configuration |
| 6672 |
* option. |
| 6673 |
*/ |
| 6674 |
if (Tk_ConfigureValue(interp, hboxPtr->tkwin, entryConfigSpecs, |
| 6675 |
(char *)hboxPtr->rootPtr->entryPtr, argv[i], 0) != TCL_OK) { |
| 6676 |
Tcl_ResetResult(interp); |
| 6677 |
Tcl_AppendResult(interp, "bad find switch \"", argv[i], "\"", |
| 6678 |
(char *)NULL); |
| 6679 |
Blt_ListDestroy(optionList); |
| 6680 |
return TCL_ERROR; |
| 6681 |
} |
| 6682 |
if ((i + 1) == argc) { |
| 6683 |
goto missingArg; |
| 6684 |
} |
| 6685 |
/* Save the option in the list of configuration options */ |
| 6686 |
node = Blt_ListGetNode(optionList, argv[i]); |
| 6687 |
if (node == NULL) { |
| 6688 |
node = Blt_ListCreateNode(optionList, argv[i]); |
| 6689 |
Blt_ListAppendNode(optionList, node); |
| 6690 |
} |
| 6691 |
Blt_ListSetValue(node, argv[i + 1]); |
| 6692 |
i++; |
| 6693 |
} |
| 6694 |
} |
| 6695 |
|
| 6696 |
if ((argc - i) > 2) { |
| 6697 |
Blt_ListDestroy(optionList); |
| 6698 |
Tcl_AppendResult(interp, "too many args", (char *)NULL); |
| 6699 |
return TCL_ERROR; |
| 6700 |
} |
| 6701 |
/* |
| 6702 |
* Step 2: Find the range of the search. Check the order of two |
| 6703 |
* nodes and arrange the search accordingly. |
| 6704 |
* |
| 6705 |
* Note: Be careful to treat "end" as the end of all nodes, instead |
| 6706 |
* of the end of visible nodes. That way, we can search the |
| 6707 |
* entire tree, even if the last folder is closed. |
| 6708 |
*/ |
| 6709 |
firstPtr = hboxPtr->rootPtr;/* Default to root node */ |
| 6710 |
lastPtr = EndNode(firstPtr, 0); |
| 6711 |
|
| 6712 |
if (i < argc) { |
| 6713 |
if ((argv[i][0] == 'e') && (strcmp(argv[i], "end") == 0)) { |
| 6714 |
firstPtr = EndNode(hboxPtr->rootPtr, 0); |
| 6715 |
} else if (StringToNode(hboxPtr, argv[i], &firstPtr) != TCL_OK) { |
| 6716 |
return TCL_ERROR; |
| 6717 |
} |
| 6718 |
i++; |
| 6719 |
} |
| 6720 |
if (i < argc) { |
| 6721 |
if ((argv[i][0] == 'e') && (strcmp(argv[i], "end") == 0)) { |
| 6722 |
lastPtr = EndNode(hboxPtr->rootPtr, 0); |
| 6723 |
} else if (StringToNode(hboxPtr, argv[i], &lastPtr) != TCL_OK) { |
| 6724 |
return TCL_ERROR; |
| 6725 |
} |
| 6726 |
} |
| 6727 |
if (IsBefore(lastPtr, firstPtr)) { |
| 6728 |
nextProc = LastNode; |
| 6729 |
} |
| 6730 |
nMatches = 0; |
| 6731 |
|
| 6732 |
/* |
| 6733 |
* Step 3: Search through the tree and look for nodes that match the |
| 6734 |
* current pattern specifications. Save the name of each of |
| 6735 |
* the matching nodes. |
| 6736 |
*/ |
| 6737 |
Tcl_DStringInit(&dString); |
| 6738 |
for (treePtr = firstPtr; treePtr != NULL; |
| 6739 |
treePtr = (*nextProc) (treePtr, 0)) { |
| 6740 |
if (namePattern != NULL) { |
| 6741 |
result = (*compareProc) (interp, treePtr->nameId, namePattern); |
| 6742 |
if (result == invertMatch) { |
| 6743 |
goto nextNode; /* Failed to match */ |
| 6744 |
} |
| 6745 |
} |
| 6746 |
if (fullPattern != NULL) { |
| 6747 |
GetFullPath(treePtr, hboxPtr->separator, &pathString); |
| 6748 |
result = (*compareProc) (interp, Tcl_DStringValue(&pathString), |
| 6749 |
fullPattern); |
| 6750 |
Tcl_DStringFree(&pathString); |
| 6751 |
if (result == invertMatch) { |
| 6752 |
goto nextNode; /* Failed to match */ |
| 6753 |
} |
| 6754 |
} |
| 6755 |
for (node = Blt_ListFirstNode(optionList); node != NULL; |
| 6756 |
node = Blt_ListNextNode(node)) { |
| 6757 |
option = (char *)Blt_ListGetKey(node); |
| 6758 |
Tcl_ResetResult(interp); |
| 6759 |
if (Tk_ConfigureValue(interp, hboxPtr->tkwin, entryConfigSpecs, |
| 6760 |
(char *)treePtr->entryPtr, option, 0) != TCL_OK) { |
| 6761 |
goto error; /* This shouldn't happen. */ |
| 6762 |
} |
| 6763 |
pattern = (char *)Blt_ListGetValue(node); |
| 6764 |
value = (char *)Tcl_GetStringResult(interp); |
| 6765 |
result = (*compareProc) (interp, value, pattern); |
| 6766 |
if (result == invertMatch) { |
| 6767 |
goto nextNode; /* Failed to match */ |
| 6768 |
} |
| 6769 |
} |
| 6770 |
/* |
| 6771 |
* As unlikely as it sounds, the "exec" callback may delete this |
| 6772 |
* node. We need to preverse it until we're not using it anymore |
| 6773 |
* (i.e. no longer accessing its fields). |
| 6774 |
*/ |
| 6775 |
Tcl_Preserve(treePtr); |
| 6776 |
if (execCmd != NULL) { |
| 6777 |
Tcl_DString cmdString; |
| 6778 |
|
| 6779 |
PercentSubst(hboxPtr, treePtr, execCmd, &cmdString); |
| 6780 |
result = Tcl_GlobalEval(interp, Tcl_DStringValue(&cmdString)); |
| 6781 |
Tcl_DStringFree(&cmdString); |
| 6782 |
if (result != TCL_OK) { |
| 6783 |
Tcl_Release(treePtr); |
| 6784 |
goto error; |
| 6785 |
} |
| 6786 |
} |
| 6787 |
/* Finally, save the matching node name. */ |
| 6788 |
Tcl_DStringAppendElement(&dString, NodeToString(hboxPtr, treePtr)); |
| 6789 |
Tcl_Release(treePtr); |
| 6790 |
nMatches++; |
| 6791 |
if ((nMatches == maxMatches) && (maxMatches > 0)) { |
| 6792 |
break; |
| 6793 |
} |
| 6794 |
nextNode: |
| 6795 |
if (treePtr == lastPtr) { |
| 6796 |
break; |
| 6797 |
} |
| 6798 |
} |
| 6799 |
Tcl_ResetResult(interp); |
| 6800 |
Blt_ListDestroy(optionList); |
| 6801 |
Tcl_DStringResult(interp, &dString); |
| 6802 |
return TCL_OK; |
| 6803 |
|
| 6804 |
missingArg: |
| 6805 |
Tcl_AppendResult(interp, "missing argument for find option \"", argv[i], |
| 6806 |
"\"", (char *)NULL); |
| 6807 |
error: |
| 6808 |
Tcl_DStringFree(&dString); |
| 6809 |
Blt_ListDestroy(optionList); |
| 6810 |
return TCL_ERROR; |
| 6811 |
} |
| 6812 |
|
| 6813 |
/* |
| 6814 |
*---------------------------------------------------------------------- |
| 6815 |
* |
| 6816 |
* GetOp -- |
| 6817 |
* |
| 6818 |
* Converts one or more node identifiers to its path component. |
| 6819 |
* The path may be either the single entry name or the full path |
| 6820 |
* of the entry. |
| 6821 |
* |
| 6822 |
* Results: |
| 6823 |
* A standard Tcl result. The interpreter result will contain a |
| 6824 |
* list of the convert names. |
| 6825 |
* |
| 6826 |
*---------------------------------------------------------------------- |
| 6827 |
*/ |
| 6828 |
static int |
| 6829 |
GetOp(hboxPtr, interp, argc, argv) |
| 6830 |
Hierbox *hboxPtr; |
| 6831 |
Tcl_Interp *interp; |
| 6832 |
int argc; |
| 6833 |
char **argv; |
| 6834 |
{ |
| 6835 |
int fullName; |
| 6836 |
Tree *treePtr; |
| 6837 |
Tcl_DString dString; |
| 6838 |
Tcl_DString pathString; |
| 6839 |
register int i; |
| 6840 |
|
| 6841 |
fullName = FALSE; |
| 6842 |
if ((argc > 2) && (argv[2][0] == '-') && (strcmp(argv[2], "-full") == 0)) { |
| 6843 |
fullName = TRUE; |
| 6844 |
argv++, argc--; |
| 6845 |
} |
| 6846 |
Tcl_DStringInit(&dString); |
| 6847 |
Tcl_DStringInit(&pathString); |
| 6848 |
for (i = 2; i < argc; i++) { |
| 6849 |
treePtr = hboxPtr->focusPtr; |
| 6850 |
if (GetNode(hboxPtr, argv[i], &treePtr) != TCL_OK) { |
| 6851 |
return TCL_ERROR; |
| 6852 |
} |
| 6853 |
if (treePtr == NULL) { |
| 6854 |
Tcl_DStringAppendElement(&dString, ""); |
| 6855 |
continue; |
| 6856 |
} |
| 6857 |
if (fullName) { |
| 6858 |
GetFullPath(treePtr, hboxPtr->separator, &pathString); |
| 6859 |
Tcl_DStringAppendElement(&dString, Tcl_DStringValue(&pathString)); |
| 6860 |
} else { |
| 6861 |
Tcl_DStringAppendElement(&dString, treePtr->nameId); |
| 6862 |
} |
| 6863 |
} |
| 6864 |
Tcl_DStringFree(&pathString); |
| 6865 |
Tcl_DStringResult(interp, &dString); |
| 6866 |
return TCL_OK; |
| 6867 |
} |
| 6868 |
|
| 6869 |
/* |
| 6870 |
*---------------------------------------------------------------------- |
| 6871 |
* |
| 6872 |
* SearchAndApplyToTree -- |
| 6873 |
* |
| 6874 |
* Searches through the current tree and applies a procedure |
| 6875 |
* to matching nodes. The search specification is taken from |
| 6876 |
* the following command-line arguments: |
| 6877 |
* |
| 6878 |
* ?-exact? ?-glob? ?-regexp? ?-nonmatching? |
| 6879 |
* ?-data string? |
| 6880 |
* ?-name string? |
| 6881 |
* ?-full string? |
| 6882 |
* ?--? |
| 6883 |
* ?inode...? |
| 6884 |
* |
| 6885 |
* Results: |
| 6886 |
* A standard Tcl result. If the result is valid, and if the |
| 6887 |
* nonmatchPtr is specified, it returns a boolean value |
| 6888 |
* indicating whether or not the search was inverted. This |
| 6889 |
* is needed to fix things properly for the "hide nonmatching" |
| 6890 |
* case. |
| 6891 |
* |
| 6892 |
*---------------------------------------------------------------------- |
| 6893 |
*/ |
| 6894 |
static int |
| 6895 |
SearchAndApplyToTree(hboxPtr, interp, argc, argv, proc, nonMatchPtr) |
| 6896 |
Hierbox *hboxPtr; |
| 6897 |
Tcl_Interp *interp; |
| 6898 |
int argc; |
| 6899 |
char **argv; |
| 6900 |
ApplyProc *proc; |
| 6901 |
int *nonMatchPtr; /* returns: inverted search indicator */ |
| 6902 |
{ |
| 6903 |
CompareProc *compareProc; |
| 6904 |
int invertMatch; /* normal search mode (matching entries) */ |
| 6905 |
char *namePattern, *fullPattern; |
| 6906 |
register int i; |
| 6907 |
int length; |
| 6908 |
int result; |
| 6909 |
char *option, *pattern; |
| 6910 |
char *value; |
| 6911 |
Tree *treePtr; |
| 6912 |
char c; |
| 6913 |
Blt_List optionList; |
| 6914 |
register Blt_ListNode node; |
| 6915 |
|
| 6916 |
optionList = Blt_ListCreate(BLT_STRING_KEYS); |
| 6917 |
invertMatch = FALSE; |
| 6918 |
namePattern = fullPattern = NULL; |
| 6919 |
compareProc = ExactCompare; |
| 6920 |
for (i = 2; i < argc; i++) { |
| 6921 |
if (argv[i][0] != '-') { |
| 6922 |
break; |
| 6923 |
} |
| 6924 |
option = argv[i] + 1; |
| 6925 |
length = strlen(option); |
| 6926 |
c = option[0]; |
| 6927 |
if ((c == 'e') && (strncmp(option, "exact", length) == 0)) { |
| 6928 |
compareProc = ExactCompare; |
| 6929 |
} else if ((c == 'g') && (strncmp(option, "glob", length) == 0)) { |
| 6930 |
compareProc = GlobCompare; |
| 6931 |
} else if ((c == 'r') && (strncmp(option, "regexp", length) == 0)) { |
| 6932 |
compareProc = RegexpCompare; |
| 6933 |
} else if ((c == 'n') && (length > 1) && |
| 6934 |
(strncmp(option, "nonmatching", length) == 0)) { |
| 6935 |
invertMatch = TRUE; |
| 6936 |
} else if ((c == 'f') && (strncmp(option, "full", length) == 0)) { |
| 6937 |
if ((i + 1) == argc) { |
| 6938 |
goto missingArg; |
| 6939 |
} |
| 6940 |
i++; |
| 6941 |
fullPattern = argv[i]; |
| 6942 |
} else if ((c == 'n') && (length > 1) && |
| 6943 |
(strncmp(option, "name", length) == 0)) { |
| 6944 |
if ((i + 1) == argc) { |
| 6945 |
goto missingArg; |
| 6946 |
} |
| 6947 |
i++; |
| 6948 |
namePattern = argv[i]; |
| 6949 |
} else if ((option[0] == '-') && (option[1] == '\0')) { |
| 6950 |
break; |
| 6951 |
} else { |
| 6952 |
/* |
| 6953 |
* Verify that the switch is actually an entry configuration option. |
| 6954 |
*/ |
| 6955 |
if (Tk_ConfigureValue(interp, hboxPtr->tkwin, entryConfigSpecs, |
| 6956 |
(char *)hboxPtr->rootPtr->entryPtr, argv[i], 0) != TCL_OK) { |
| 6957 |
Tcl_ResetResult(interp); |
| 6958 |
Tcl_AppendResult(interp, "bad switch \"", argv[i], |
| 6959 |
"\": must be -exact, -glob, -regexp, -name, -full, or -nonmatching", |
| 6960 |
(char *)NULL); |
| 6961 |
return TCL_ERROR; |
| 6962 |
} |
| 6963 |
if ((i + 1) == argc) { |
| 6964 |
goto missingArg; |
| 6965 |
} |
| 6966 |
/* Save the option in the list of configuration options */ |
| 6967 |
node = Blt_ListGetNode(optionList, argv[i]); |
| 6968 |
if (node == NULL) { |
| 6969 |
node = Blt_ListCreateNode(optionList, argv[i]); |
| 6970 |
Blt_ListAppendNode(optionList, node); |
| 6971 |
} |
| 6972 |
Blt_ListSetValue(node, argv[i + 1]); |
| 6973 |
} |
| 6974 |
} |
| 6975 |
|
| 6976 |
if ((namePattern != NULL) || (fullPattern != NULL) || |
| 6977 |
(Blt_ListGetLength(optionList) > 0)) { |
| 6978 |
/* |
| 6979 |
* Search through the tree and look for nodes that match the |
| 6980 |
* current spec. Apply the input procedure to each of the |
| 6981 |
* matching nodes. |
| 6982 |
*/ |
| 6983 |
for (treePtr = hboxPtr->rootPtr; treePtr != NULL; |
| 6984 |
treePtr = NextNode(treePtr, 0)) { |
| 6985 |
|
| 6986 |
if (namePattern != NULL) { |
| 6987 |
result = (*compareProc) (interp, treePtr->nameId, namePattern); |
| 6988 |
if (result == invertMatch) { |
| 6989 |
continue; /* Failed to match */ |
| 6990 |
} |
| 6991 |
} |
| 6992 |
if (fullPattern != NULL) { |
| 6993 |
Tcl_DString dString; |
| 6994 |
|
| 6995 |
GetFullPath(treePtr, hboxPtr->separator, &dString); |
| 6996 |
result = (*compareProc) (interp, Tcl_DStringValue(&dString), |
| 6997 |
fullPattern); |
| 6998 |
Tcl_DStringFree(&dString); |
| 6999 |
if (result == invertMatch) { |
| 7000 |
continue; /* Failed to match */ |
| 7001 |
} |
| 7002 |
} |
| 7003 |
for (node = Blt_ListFirstNode(optionList); node != NULL; |
| 7004 |
node = Blt_ListNextNode(node)) { |
| 7005 |
option = (char *)Blt_ListGetKey(node); |
| 7006 |
Tcl_ResetResult(interp); |
| 7007 |
if (Tk_ConfigureValue(interp, hboxPtr->tkwin, entryConfigSpecs, |
| 7008 |
(char *)treePtr->entryPtr, option, 0) != TCL_OK) { |
| 7009 |
return TCL_ERROR; /* This shouldn't happen. */ |
| 7010 |
} |
| 7011 |
pattern = (char *)Blt_ListGetValue(node); |
| 7012 |
value = (char *)Tcl_GetStringResult(interp); |
| 7013 |
result = (*compareProc) (interp, value, pattern); |
| 7014 |
if (result == invertMatch) { |
| 7015 |
continue; /* Failed to match */ |
| 7016 |
} |
| 7017 |
} |
| 7018 |
/* Finally, apply the procedure to the node */ |
| 7019 |
(*proc) (hboxPtr, treePtr); |
| 7020 |
} |
| 7021 |
Tcl_ResetResult(interp); |
| 7022 |
Blt_ListDestroy(optionList); |
| 7023 |
} |
| 7024 |
/* |
| 7025 |
* Apply the procedure to nodes that have been specified |
| 7026 |
* individually. |
| 7027 |
*/ |
| 7028 |
for ( /*empty*/ ; i < argc; i++) { |
| 7029 |
if ((argv[i][0] == 'a') && (strcmp(argv[i], "all") == 0)) { |
| 7030 |
return ApplyToTree(hboxPtr, hboxPtr->rootPtr, proc, APPLY_RECURSE); |
| 7031 |
} |
| 7032 |
if (StringToNode(hboxPtr, argv[i], &treePtr) != TCL_OK) { |
| 7033 |
return TCL_ERROR; |
| 7034 |
} |
| 7035 |
if ((*proc) (hboxPtr, treePtr) != TCL_OK) { |
| 7036 |
return TCL_ERROR; |
| 7037 |
} |
| 7038 |
} |
| 7039 |
|
| 7040 |
if (nonMatchPtr != NULL) { |
| 7041 |
*nonMatchPtr = invertMatch; /* return "inverted search" status */ |
| 7042 |
} |
| 7043 |
return TCL_OK; |
| 7044 |
|
| 7045 |
missingArg: |
| 7046 |
Blt_ListDestroy(optionList); |
| 7047 |
Tcl_AppendResult(interp, "missing pattern for search option \"", argv[i], |
| 7048 |
"\"", (char *)NULL); |
| 7049 |
return TCL_ERROR; |
| 7050 |
|
| 7051 |
} |
| 7052 |
|
| 7053 |
/* |
| 7054 |
*---------------------------------------------------------------------- |
| 7055 |
* |
| 7056 |
* HideOp -- |
| 7057 |
* |
| 7058 |
* Hides one or more nodes. Nodes can be specified by their |
| 7059 |
* inode, or by matching a name or data value pattern. By |
| 7060 |
* default, the patterns are matched exactly. They can also |
| 7061 |
* be matched using glob-style and regular expression rules. |
| 7062 |
* |
| 7063 |
* Results: |
| 7064 |
* A standard Tcl result. |
| 7065 |
* |
| 7066 |
*---------------------------------------------------------------------- |
| 7067 |
*/ |
| 7068 |
static int |
| 7069 |
HideOp(hboxPtr, interp, argc, argv) |
| 7070 |
Hierbox *hboxPtr; |
| 7071 |
Tcl_Interp *interp; |
| 7072 |
int argc; |
| 7073 |
char **argv; |
| 7074 |
{ |
| 7075 |
int status, nonmatching; |
| 7076 |
|
| 7077 |
status = SearchAndApplyToTree(hboxPtr, interp, argc, argv, UnmapNode, |
| 7078 |
&nonmatching); |
| 7079 |
|
| 7080 |
if (status != TCL_OK) { |
| 7081 |
return TCL_ERROR; |
| 7082 |
} |
| 7083 |
/* |
| 7084 |
* If this was an inverted search, scan back through the |
| 7085 |
* tree and make sure that the parents for all visible |
| 7086 |
* nodes are also visible. After all, if a node is supposed |
| 7087 |
* to be visible, its parent can't be hidden. |
| 7088 |
*/ |
| 7089 |
if (nonmatching) { |
| 7090 |
ApplyToTree(hboxPtr, hboxPtr->rootPtr, MapAncestors, APPLY_RECURSE); |
| 7091 |
} |
| 7092 |
/* |
| 7093 |
* Make sure that selections arme cleared from any hidden |
| 7094 |
* nodes. This wasn't done earlier--we had to delay it until |
| 7095 |
* we fixed the visibility status for the parents. |
| 7096 |
*/ |
| 7097 |
ApplyToTree(hboxPtr, hboxPtr->rootPtr, FixUnmappedSelections, |
| 7098 |
APPLY_RECURSE); |
| 7099 |
|
| 7100 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 7101 |
EventuallyRedraw(hboxPtr); |
| 7102 |
return TCL_OK; |
| 7103 |
} |
| 7104 |
|
| 7105 |
/* |
| 7106 |
*---------------------------------------------------------------------- |
| 7107 |
* |
| 7108 |
* ShowOp -- |
| 7109 |
* |
| 7110 |
* Mark one or more nodes to be exposed. Nodes can be specified |
| 7111 |
* by their inode, or by matching a name or data value pattern. By |
| 7112 |
* default, the patterns are matched exactly. They can also |
| 7113 |
* be matched using glob-style and regular expression rules. |
| 7114 |
* |
| 7115 |
* Results: |
| 7116 |
* A standard Tcl result. |
| 7117 |
* |
| 7118 |
*---------------------------------------------------------------------- |
| 7119 |
*/ |
| 7120 |
static int |
| 7121 |
ShowOp(hboxPtr, interp, argc, argv) |
| 7122 |
Hierbox *hboxPtr; |
| 7123 |
Tcl_Interp *interp; |
| 7124 |
int argc; |
| 7125 |
char **argv; |
| 7126 |
{ |
| 7127 |
if (SearchAndApplyToTree(hboxPtr, interp, argc, argv, MapNode, |
| 7128 |
(int *)NULL) != TCL_OK) { |
| 7129 |
return TCL_ERROR; |
| 7130 |
} |
| 7131 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 7132 |
EventuallyRedraw(hboxPtr); |
| 7133 |
return TCL_OK; |
| 7134 |
} |
| 7135 |
|
| 7136 |
/* |
| 7137 |
*---------------------------------------------------------------------- |
| 7138 |
* |
| 7139 |
* IndexOp -- |
| 7140 |
* |
| 7141 |
* Converts one of more words representing indices of the entries |
| 7142 |
* in the hierarchy widget to their respective serial identifiers. |
| 7143 |
* |
| 7144 |
* Results: |
| 7145 |
* A standard Tcl result. Interp->result will contain the |
| 7146 |
* identifier of each inode found. If an inode could not be found, |
| 7147 |
* then the serial identifier will be the empty string. |
| 7148 |
* |
| 7149 |
*---------------------------------------------------------------------- |
| 7150 |
*/ |
| 7151 |
/*ARGSUSED*/ |
| 7152 |
static int |
| 7153 |
IndexOp(hboxPtr, interp, argc, argv) |
| 7154 |
Hierbox *hboxPtr; |
| 7155 |
Tcl_Interp *interp; |
| 7156 |
int argc; /* Not used. */ |
| 7157 |
char **argv; |
| 7158 |
{ |
| 7159 |
Tree *nodePtr, *rootPtr; |
| 7160 |
|
| 7161 |
rootPtr = hboxPtr->focusPtr; |
| 7162 |
if ((argv[2][0] == '-') && (strcmp(argv[2], "-at") == 0)) { |
| 7163 |
if (StringToNode(hboxPtr, argv[3], &rootPtr) != TCL_OK) { |
| 7164 |
return TCL_ERROR; |
| 7165 |
} |
| 7166 |
argv += 2, argc -= 2; |
| 7167 |
} |
| 7168 |
if (argc > 3) { |
| 7169 |
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 7170 |
" index ?-at index? index\"", (char *)NULL); |
| 7171 |
return TCL_ERROR; |
| 7172 |
} |
| 7173 |
nodePtr = rootPtr; |
| 7174 |
if ((GetNode(hboxPtr, argv[2], &nodePtr) == TCL_OK) && (nodePtr != NULL)) { |
| 7175 |
Tcl_SetResult(interp, NodeToString(hboxPtr, nodePtr), TCL_VOLATILE); |
| 7176 |
} else { |
| 7177 |
Tcl_SetResult(interp, "", TCL_STATIC); |
| 7178 |
} |
| 7179 |
return TCL_OK; |
| 7180 |
} |
| 7181 |
|
| 7182 |
/* |
| 7183 |
*---------------------------------------------------------------------- |
| 7184 |
* |
| 7185 |
* InsertOp -- |
| 7186 |
* |
| 7187 |
* Add new entries into a hierarchy. If no node is specified, |
| 7188 |
* new entries will be added to the root of the hierarchy. |
| 7189 |
* |
| 7190 |
*---------------------------------------------------------------------- |
| 7191 |
*/ |
| 7192 |
/*ARGSUSED*/ |
| 7193 |
static int |
| 7194 |
InsertOp(hboxPtr, interp, argc, argv) |
| 7195 |
Hierbox *hboxPtr; |
| 7196 |
Tcl_Interp *interp; |
| 7197 |
int argc; /* Not used. */ |
| 7198 |
char **argv; |
| 7199 |
{ |
| 7200 |
Tree *rootPtr, *nodePtr, *parentPtr; |
| 7201 |
int position; |
| 7202 |
int level, count; |
| 7203 |
char *path; |
| 7204 |
Tcl_DString dString; |
| 7205 |
register int i, l; |
| 7206 |
int nOpts; |
| 7207 |
CONST char **options; |
| 7208 |
char **nameArr; |
| 7209 |
|
| 7210 |
rootPtr = hboxPtr->rootPtr; |
| 7211 |
if ((argv[2][0] == '-') && (strcmp(argv[2], "-at") == 0)) { |
| 7212 |
if (StringToNode(hboxPtr, argv[3], &rootPtr) != TCL_OK) { |
| 7213 |
return TCL_ERROR; |
| 7214 |
} |
| 7215 |
argv += 2, argc -= 2; |
| 7216 |
} |
| 7217 |
if (Blt_GetPosition(hboxPtr->interp, argv[2], &position) != TCL_OK) { |
| 7218 |
return TCL_ERROR; |
| 7219 |
} |
| 7220 |
argc -= 3, argv += 3; |
| 7221 |
|
| 7222 |
/* |
| 7223 |
* Count the pathnames that follow. Count the arguments until we |
| 7224 |
* spot one that looks like a configuration option (i.e. starts |
| 7225 |
* with a minus ("-")). |
| 7226 |
*/ |
| 7227 |
for (count = 0; count < argc; count++) { |
| 7228 |
if (argv[count][0] == '-') { |
| 7229 |
break; |
| 7230 |
} |
| 7231 |
} |
| 7232 |
nOpts = argc - count; |
| 7233 |
options = (CONST char **)argv + count; |
| 7234 |
|
| 7235 |
Tcl_DStringInit(&dString); |
| 7236 |
for (i = 0; i < count; i++) { |
| 7237 |
path = argv[i]; |
| 7238 |
if (hboxPtr->trimLeft != NULL) { |
| 7239 |
register char *p, *s; |
| 7240 |
|
| 7241 |
/* Trim off leading character string if one exists. */ |
| 7242 |
for (p = path, s = hboxPtr->trimLeft; *s != '\0'; s++, p++) { |
| 7243 |
if (*p != *s) { |
| 7244 |
break; |
| 7245 |
} |
| 7246 |
} |
| 7247 |
if (*s == '\0') { |
| 7248 |
path = p; |
| 7249 |
} |
| 7250 |
} |
| 7251 |
/* |
| 7252 |
* Split the path and find the parent node of the path. |
| 7253 |
*/ |
| 7254 |
nameArr = &path; |
| 7255 |
level = 1; |
| 7256 |
if (hboxPtr->separator == SEPARATOR_LIST) { |
| 7257 |
if (Tcl_SplitList(interp, path, &level, &nameArr) != TCL_OK) { |
| 7258 |
goto error; |
| 7259 |
} |
| 7260 |
} else if (hboxPtr->separator != SEPARATOR_NONE) { |
| 7261 |
if (SplitPath(hboxPtr, path, &level, &nameArr) != TCL_OK) { |
| 7262 |
goto error; |
| 7263 |
} |
| 7264 |
} |
| 7265 |
if (level == 0) { |
| 7266 |
continue; /* Root already exists. */ |
| 7267 |
} |
| 7268 |
parentPtr = rootPtr; |
| 7269 |
level--; |
| 7270 |
for (l = 0; l < level; l++) { |
| 7271 |
nodePtr = FindComponent(parentPtr, nameArr[l]); |
| 7272 |
if (nodePtr == NULL) { |
| 7273 |
if (!hboxPtr->autoCreate) { |
| 7274 |
Tcl_AppendResult(interp, "can't find path component \"", |
| 7275 |
nameArr[l], "\" in \"", path, "\"", (char *)NULL); |
| 7276 |
goto error; |
| 7277 |
} |
| 7278 |
nodePtr = CreateNode(hboxPtr, parentPtr, APPEND, nameArr[l]); |
| 7279 |
} |
| 7280 |
parentPtr = nodePtr; |
| 7281 |
} |
| 7282 |
nodePtr = NULL; |
| 7283 |
if (!hboxPtr->allowDuplicates) { |
| 7284 |
nodePtr = FindComponent(parentPtr, nameArr[level]); |
| 7285 |
} |
| 7286 |
if (nodePtr == NULL) { |
| 7287 |
nodePtr = CreateNode(hboxPtr, parentPtr, position, nameArr[level]); |
| 7288 |
if (nodePtr == NULL) { |
| 7289 |
goto error; |
| 7290 |
} |
| 7291 |
if (ConfigureEntry(hboxPtr, nodePtr->entryPtr, nOpts, options, |
| 7292 |
TK_CONFIG_ARGV_ONLY) != TCL_OK) { |
| 7293 |
DeleteNode(hboxPtr, nodePtr); |
| 7294 |
goto error; |
| 7295 |
} |
| 7296 |
Tcl_DStringAppendElement(&dString, NodeToString(hboxPtr, nodePtr)); |
| 7297 |
} else { |
| 7298 |
if (ConfigureEntry(hboxPtr, nodePtr->entryPtr, nOpts, options, |
| 7299 |
0) != TCL_OK) { |
| 7300 |
goto error; |
| 7301 |
} |
| 7302 |
} |
| 7303 |
if (nameArr != &path) { |
| 7304 |
Blt_Free(nameArr); |
| 7305 |
} |
| 7306 |
} |
| 7307 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL | HIERBOX_DIRTY); |
| 7308 |
EventuallyRedraw(hboxPtr); |
| 7309 |
Tcl_DStringResult(hboxPtr->interp, &dString); |
| 7310 |
return TCL_OK; |
| 7311 |
error: |
| 7312 |
if (nameArr != &path) { |
| 7313 |
Blt_Free(nameArr); |
| 7314 |
} |
| 7315 |
Tcl_DStringFree(&dString); |
| 7316 |
return TCL_ERROR; |
| 7317 |
} |
| 7318 |
|
| 7319 |
/* |
| 7320 |
*---------------------------------------------------------------------- |
| 7321 |
* |
| 7322 |
* DeleteOp -- |
| 7323 |
* |
| 7324 |
* Deletes nodes from the hierarchy. Deletes either a range of |
| 7325 |
* entries from a hierarchy or a single node (except root). |
| 7326 |
* In all cases, nodes are removed recursively. |
| 7327 |
* |
| 7328 |
*---------------------------------------------------------------------- |
| 7329 |
*/ |
| 7330 |
/*ARGSUSED*/ |
| 7331 |
static int |
| 7332 |
DeleteOp(hboxPtr, interp, argc, argv) |
| 7333 |
Hierbox *hboxPtr; |
| 7334 |
Tcl_Interp *interp; |
| 7335 |
int argc; /* Not used. */ |
| 7336 |
char **argv; |
| 7337 |
{ |
| 7338 |
Tree *treePtr; |
| 7339 |
Blt_ChainLink *linkPtr; |
| 7340 |
Blt_ChainLink *firstPtr, *lastPtr, *nextPtr; |
| 7341 |
|
| 7342 |
if (argc == 2) { |
| 7343 |
return TCL_OK; |
| 7344 |
} |
| 7345 |
if (StringToNode(hboxPtr, argv[2], &treePtr) != TCL_OK) { |
| 7346 |
return TCL_ERROR; /* Node or path doesn't already exist */ |
| 7347 |
} |
| 7348 |
firstPtr = lastPtr = NULL; |
| 7349 |
switch (argc) { |
| 7350 |
case 3: |
| 7351 |
/* |
| 7352 |
* Delete a single hierarchy. If the node specified is root, |
| 7353 |
* delete only the children. |
| 7354 |
*/ |
| 7355 |
if (treePtr != hboxPtr->rootPtr) { |
| 7356 |
DestroyTree(hboxPtr, treePtr); /* Don't delete root */ |
| 7357 |
goto done; |
| 7358 |
} |
| 7359 |
firstPtr = Blt_ChainFirstLink(treePtr->chainPtr); |
| 7360 |
lastPtr = Blt_ChainLastLink(treePtr->chainPtr); |
| 7361 |
break; |
| 7362 |
|
| 7363 |
case 4: |
| 7364 |
/* |
| 7365 |
* Delete a single node from hierarchy specified by its |
| 7366 |
* numeric position. |
| 7367 |
*/ |
| 7368 |
{ |
| 7369 |
int position; |
| 7370 |
|
| 7371 |
if (Blt_GetPosition(interp, argv[3], &position) != TCL_OK) { |
| 7372 |
return TCL_ERROR; |
| 7373 |
} |
| 7374 |
if (position >= Blt_ChainGetLength(treePtr->chainPtr)) { |
| 7375 |
return TCL_OK; /* Bad first index */ |
| 7376 |
} |
| 7377 |
if (position == APPEND) { |
| 7378 |
linkPtr = Blt_ChainLastLink(treePtr->chainPtr); |
| 7379 |
} else { |
| 7380 |
linkPtr = Blt_ChainGetNthLink(treePtr->chainPtr, position); |
| 7381 |
} |
| 7382 |
firstPtr = lastPtr = linkPtr; |
| 7383 |
} |
| 7384 |
break; |
| 7385 |
|
| 7386 |
case 5: |
| 7387 |
/* |
| 7388 |
* Delete range of nodes in hierarchy specified by first/last |
| 7389 |
* positions. |
| 7390 |
*/ |
| 7391 |
{ |
| 7392 |
int first, last; |
| 7393 |
int nEntries; |
| 7394 |
|
| 7395 |
if ((Blt_GetPosition(interp, argv[3], &first) != TCL_OK) || |
| 7396 |
(Blt_GetPosition(interp, argv[4], &last) != TCL_OK)) { |
| 7397 |
return TCL_ERROR; |
| 7398 |
} |
| 7399 |
nEntries = Blt_ChainGetLength(treePtr->chainPtr); |
| 7400 |
if (nEntries == 0) { |
| 7401 |
return TCL_OK; |
| 7402 |
} |
| 7403 |
if (first == APPEND) { |
| 7404 |
first = nEntries - 1; |
| 7405 |
} |
| 7406 |
if (first >= nEntries) { |
| 7407 |
Tcl_AppendResult(interp, "first position \"", argv[3], |
| 7408 |
" is out of range", (char *)NULL); |
| 7409 |
return TCL_ERROR; |
| 7410 |
} |
| 7411 |
if ((last == APPEND) || (last >= nEntries)) { |
| 7412 |
last = nEntries - 1; |
| 7413 |
} |
| 7414 |
if (first > last) { |
| 7415 |
Tcl_AppendResult(interp, "bad range: \"", argv[3], |
| 7416 |
" > ", argv[4], "\"", (char *)NULL); |
| 7417 |
return TCL_ERROR; |
| 7418 |
} |
| 7419 |
firstPtr = Blt_ChainGetNthLink(treePtr->chainPtr, first); |
| 7420 |
lastPtr = Blt_ChainGetNthLink(treePtr->chainPtr, last); |
| 7421 |
} |
| 7422 |
break; |
| 7423 |
} |
| 7424 |
for (linkPtr = firstPtr; linkPtr != NULL; linkPtr = nextPtr) { |
| 7425 |
nextPtr = Blt_ChainNextLink(linkPtr); |
| 7426 |
treePtr = Blt_ChainGetValue(linkPtr); |
| 7427 |
DestroyTree(hboxPtr, treePtr); |
| 7428 |
if (linkPtr == lastPtr) { |
| 7429 |
break; |
| 7430 |
} |
| 7431 |
} |
| 7432 |
done: |
| 7433 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 7434 |
EventuallyRedraw(hboxPtr); |
| 7435 |
return TCL_OK; |
| 7436 |
} |
| 7437 |
|
| 7438 |
/* |
| 7439 |
*---------------------------------------------------------------------- |
| 7440 |
* |
| 7441 |
* MoveOp -- |
| 7442 |
* |
| 7443 |
* Move an entry into a new location in the hierarchy. |
| 7444 |
* |
| 7445 |
* |
| 7446 |
*---------------------------------------------------------------------- |
| 7447 |
*/ |
| 7448 |
/*ARGSUSED*/ |
| 7449 |
static int |
| 7450 |
MoveOp(hboxPtr, interp, argc, argv) |
| 7451 |
Hierbox *hboxPtr; |
| 7452 |
Tcl_Interp *interp; |
| 7453 |
int argc; /* Not used. */ |
| 7454 |
char **argv; |
| 7455 |
{ |
| 7456 |
Tree *srcPtr, *destPtr, *parentPtr; |
| 7457 |
char c; |
| 7458 |
int action; |
| 7459 |
|
| 7460 |
#define MOVE_INTO (1<<0) |
| 7461 |
#define MOVE_BEFORE (1<<1) |
| 7462 |
#define MOVE_AFTER (1<<2) |
| 7463 |
if (StringToNode(hboxPtr, argv[2], &srcPtr) != TCL_OK) { |
| 7464 |
return TCL_ERROR; |
| 7465 |
} |
| 7466 |
c = argv[3][0]; |
| 7467 |
if ((c == 'i') && (strcmp(argv[3], "into") == 0)) { |
| 7468 |
action = MOVE_INTO; |
| 7469 |
} else if ((c == 'b') && (strcmp(argv[3], "before") == 0)) { |
| 7470 |
action = MOVE_BEFORE; |
| 7471 |
} else if ((c == 'a') && (strcmp(argv[3], "after") == 0)) { |
| 7472 |
action = MOVE_AFTER; |
| 7473 |
} else { |
| 7474 |
Tcl_AppendResult(interp, "bad position \"", argv[3], |
| 7475 |
"\": should be into, before, or after", (char *)NULL); |
| 7476 |
return TCL_ERROR; |
| 7477 |
} |
| 7478 |
if (StringToNode(hboxPtr, argv[4], &destPtr) != TCL_OK) { |
| 7479 |
return TCL_ERROR; |
| 7480 |
} |
| 7481 |
/* Verify they aren't ancestors. */ |
| 7482 |
if (IsAncestor(srcPtr, destPtr)) { |
| 7483 |
Tcl_AppendResult(interp, "can't move node: \"", argv[2], |
| 7484 |
"\" is an ancestor of \"", argv[4], "\"", (char *)NULL); |
| 7485 |
return TCL_ERROR; |
| 7486 |
} |
| 7487 |
parentPtr = destPtr->parentPtr; |
| 7488 |
if (parentPtr == NULL) { |
| 7489 |
action = MOVE_INTO; |
| 7490 |
} |
| 7491 |
Blt_ChainUnlinkLink(srcPtr->parentPtr->chainPtr, srcPtr->linkPtr); |
| 7492 |
switch (action) { |
| 7493 |
case MOVE_INTO: |
| 7494 |
Blt_ChainLinkBefore(destPtr->chainPtr, srcPtr->linkPtr, |
| 7495 |
(Blt_ChainLink *) NULL); |
| 7496 |
parentPtr = destPtr; |
| 7497 |
break; |
| 7498 |
|
| 7499 |
case MOVE_BEFORE: |
| 7500 |
Blt_ChainLinkBefore(parentPtr->chainPtr, srcPtr->linkPtr, |
| 7501 |
destPtr->linkPtr); |
| 7502 |
break; |
| 7503 |
|
| 7504 |
case MOVE_AFTER: |
| 7505 |
Blt_ChainLinkAfter(parentPtr->chainPtr, srcPtr->linkPtr, |
| 7506 |
destPtr->linkPtr); |
| 7507 |
break; |
| 7508 |
} |
| 7509 |
srcPtr->parentPtr = parentPtr; |
| 7510 |
srcPtr->level = parentPtr->level + 1; |
| 7511 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL | HIERBOX_DIRTY); |
| 7512 |
EventuallyRedraw(hboxPtr); |
| 7513 |
return TCL_OK; |
| 7514 |
} |
| 7515 |
|
| 7516 |
/*ARGSUSED*/ |
| 7517 |
static int |
| 7518 |
NearestOp(hboxPtr, interp, argc, argv) |
| 7519 |
Hierbox *hboxPtr; |
| 7520 |
Tcl_Interp *interp; |
| 7521 |
int argc; /* Not used. */ |
| 7522 |
char **argv; |
| 7523 |
{ |
| 7524 |
ButtonAttributes *buttonPtr = &(hboxPtr->button); |
| 7525 |
int x, y; /* Screen coordinates of the test point. */ |
| 7526 |
register Entry *entryPtr; |
| 7527 |
register Tree *treePtr; |
| 7528 |
|
| 7529 |
if ((Tk_GetPixels(interp, hboxPtr->tkwin, argv[2], &x) != TCL_OK) || |
| 7530 |
(Tk_GetPixels(interp, hboxPtr->tkwin, argv[3], &y) != TCL_OK)) { |
| 7531 |
return TCL_ERROR; |
| 7532 |
} |
| 7533 |
if (hboxPtr->nVisible == 0) { |
| 7534 |
return TCL_OK; |
| 7535 |
} |
| 7536 |
treePtr = NearestNode(hboxPtr, x, y, TRUE); |
| 7537 |
if (treePtr == NULL) { |
| 7538 |
return TCL_OK; |
| 7539 |
} |
| 7540 |
x = WORLDX(hboxPtr, x); |
| 7541 |
y = WORLDY(hboxPtr, y); |
| 7542 |
entryPtr = treePtr->entryPtr; |
| 7543 |
if (argc > 4) { |
| 7544 |
char *where; |
| 7545 |
int labelX; |
| 7546 |
|
| 7547 |
where = ""; |
| 7548 |
if (entryPtr->flags & ENTRY_BUTTON) { |
| 7549 |
int buttonX, buttonY; |
| 7550 |
|
| 7551 |
buttonX = entryPtr->worldX + entryPtr->buttonX; |
| 7552 |
buttonY = entryPtr->worldY + entryPtr->buttonY; |
| 7553 |
if ((x >= buttonX) && (x < (buttonX + buttonPtr->width)) && |
| 7554 |
(y >= buttonY) && (y < (buttonY + buttonPtr->height))) { |
| 7555 |
where = "gadget"; |
| 7556 |
} |
| 7557 |
} |
| 7558 |
labelX = entryPtr->worldX + LEVELWIDTH(treePtr->level); |
| 7559 |
if ((x >= labelX) && |
| 7560 |
(x < (labelX + LEVELWIDTH(treePtr->level + 1) + entryPtr->width))) { |
| 7561 |
where = "select"; |
| 7562 |
} |
| 7563 |
if (Tcl_SetVar(interp, argv[4], where, TCL_LEAVE_ERR_MSG) == NULL) { |
| 7564 |
return TCL_ERROR; |
| 7565 |
} |
| 7566 |
} |
| 7567 |
Tcl_SetResult(interp, NodeToString(hboxPtr, treePtr), TCL_VOLATILE); |
| 7568 |
return TCL_OK; |
| 7569 |
} |
| 7570 |
|
| 7571 |
/*ARGSUSED*/ |
| 7572 |
static int |
| 7573 |
OpenOp(hboxPtr, interp, argc, argv) |
| 7574 |
Hierbox *hboxPtr; |
| 7575 |
Tcl_Interp *interp; /* Not used. */ |
| 7576 |
int argc; |
| 7577 |
char **argv; |
| 7578 |
{ |
| 7579 |
Tree *rootPtr; |
| 7580 |
unsigned int flags; |
| 7581 |
register int i; |
| 7582 |
|
| 7583 |
flags = 0; |
| 7584 |
if (argc > 2) { |
| 7585 |
int length; |
| 7586 |
|
| 7587 |
length = strlen(argv[2]); |
| 7588 |
if ((argv[2][0] == '-') && (length > 1) && |
| 7589 |
(strncmp(argv[2], "-recurse", length) == 0)) { |
| 7590 |
argv++, argc--; |
| 7591 |
flags |= APPLY_RECURSE; |
| 7592 |
} |
| 7593 |
} |
| 7594 |
for (i = 2; i < argc; i++) { |
| 7595 |
rootPtr = hboxPtr->focusPtr; |
| 7596 |
if (GetNode(hboxPtr, argv[i], &rootPtr) != TCL_OK) { |
| 7597 |
return TCL_ERROR; |
| 7598 |
} |
| 7599 |
if (rootPtr == NULL) { |
| 7600 |
continue; |
| 7601 |
} |
| 7602 |
ExposeAncestors(rootPtr); /* Also make sure that all the ancestors |
| 7603 |
* of this node are also not hidden. */ |
| 7604 |
if (ApplyToTree(hboxPtr, rootPtr, OpenNode, flags) != TCL_OK) { |
| 7605 |
return TCL_ERROR; |
| 7606 |
} |
| 7607 |
} |
| 7608 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 7609 |
EventuallyRedraw(hboxPtr); |
| 7610 |
return TCL_OK; |
| 7611 |
} |
| 7612 |
|
| 7613 |
/* |
| 7614 |
*---------------------------------------------------------------------- |
| 7615 |
* |
| 7616 |
* RangeOp -- |
| 7617 |
* |
| 7618 |
* Returns the node identifiers in a given range. |
| 7619 |
* |
| 7620 |
*---------------------------------------------------------------------- |
| 7621 |
*/ |
| 7622 |
static int |
| 7623 |
RangeOp(hboxPtr, interp, argc, argv) |
| 7624 |
Hierbox *hboxPtr; |
| 7625 |
Tcl_Interp *interp; |
| 7626 |
int argc; |
| 7627 |
char **argv; |
| 7628 |
{ |
| 7629 |
Tree *firstPtr, *lastPtr; |
| 7630 |
register Tree *treePtr; |
| 7631 |
unsigned int flags; |
| 7632 |
int length; |
| 7633 |
|
| 7634 |
flags = 0; |
| 7635 |
length = strlen(argv[2]); |
| 7636 |
if ((argv[2][0] == '-') && (length > 1) && |
| 7637 |
(strncmp(argv[2], "-open", length) == 0)) { |
| 7638 |
argv++, argc--; |
| 7639 |
flags |= ENTRY_OPEN; |
| 7640 |
} |
| 7641 |
if (StringToNode(hboxPtr, argv[2], &firstPtr) != TCL_OK) { |
| 7642 |
return TCL_ERROR; |
| 7643 |
} |
| 7644 |
lastPtr = EndNode(firstPtr, flags); |
| 7645 |
if (argc > 3) { |
| 7646 |
if (StringToNode(hboxPtr, argv[3], &lastPtr) != TCL_OK) { |
| 7647 |
return TCL_ERROR; |
| 7648 |
} |
| 7649 |
} |
| 7650 |
if (flags & ENTRY_OPEN) { |
| 7651 |
if (IsHidden(firstPtr)) { |
| 7652 |
Tcl_AppendResult(interp, "first node \"", argv[2], "\" is hidden.", |
| 7653 |
(char *)NULL); |
| 7654 |
return TCL_ERROR; |
| 7655 |
} |
| 7656 |
if (IsHidden(lastPtr)) { |
| 7657 |
Tcl_AppendResult(interp, "last node \"", argv[3], "\" is hidden.", |
| 7658 |
(char *)NULL); |
| 7659 |
return TCL_ERROR; |
| 7660 |
} |
| 7661 |
} |
| 7662 |
/* |
| 7663 |
* The relative order of the first/last markers determines the |
| 7664 |
* direction. |
| 7665 |
*/ |
| 7666 |
if (IsBefore(lastPtr, firstPtr)) { |
| 7667 |
for (treePtr = lastPtr; treePtr != NULL; |
| 7668 |
treePtr = LastNode(treePtr, flags)) { |
| 7669 |
Tcl_AppendElement(interp, NodeToString(hboxPtr, treePtr)); |
| 7670 |
if (treePtr == firstPtr) { |
| 7671 |
break; |
| 7672 |
} |
| 7673 |
} |
| 7674 |
} else { |
| 7675 |
for (treePtr = firstPtr; treePtr != NULL; |
| 7676 |
treePtr = NextNode(treePtr, flags)) { |
| 7677 |
Tcl_AppendElement(interp, NodeToString(hboxPtr, treePtr)); |
| 7678 |
if (treePtr == lastPtr) { |
| 7679 |
break; |
| 7680 |
} |
| 7681 |
} |
| 7682 |
} |
| 7683 |
return TCL_OK; |
| 7684 |
} |
| 7685 |
|
| 7686 |
/* |
| 7687 |
*---------------------------------------------------------------------- |
| 7688 |
* |
| 7689 |
* ScanOp -- |
| 7690 |
* |
| 7691 |
* Implements the quick scan. |
| 7692 |
* |
| 7693 |
*---------------------------------------------------------------------- |
| 7694 |
*/ |
| 7695 |
/*ARGSUSED*/ |
| 7696 |
static int |
| 7697 |
ScanOp(hboxPtr, interp, argc, argv) |
| 7698 |
Hierbox *hboxPtr; |
| 7699 |
Tcl_Interp *interp; |
| 7700 |
int argc; /* Not used. */ |
| 7701 |
char **argv; |
| 7702 |
{ |
| 7703 |
int x, y; |
| 7704 |
char c; |
| 7705 |
unsigned int length; |
| 7706 |
int oper; |
| 7707 |
|
| 7708 |
#define SCAN_MARK 1 |
| 7709 |
#define SCAN_DRAGTO 2 |
| 7710 |
c = argv[2][0]; |
| 7711 |
length = strlen(argv[2]); |
| 7712 |
if ((c == 'm') && (strncmp(argv[2], "mark", length) == 0)) { |
| 7713 |
oper = SCAN_MARK; |
| 7714 |
} else if ((c == 'd') && (strncmp(argv[2], "dragto", length) == 0)) { |
| 7715 |
oper = SCAN_DRAGTO; |
| 7716 |
} else { |
| 7717 |
Tcl_AppendResult(interp, "bad scan operation \"", argv[2], |
| 7718 |
"\": should be either \"mark\" or \"dragto\"", (char *)NULL); |
| 7719 |
return TCL_ERROR; |
| 7720 |
} |
| 7721 |
if ((Tk_GetPixels(interp, hboxPtr->tkwin, argv[3], &x) != TCL_OK) || |
| 7722 |
(Tk_GetPixels(interp, hboxPtr->tkwin, argv[4], &y) != TCL_OK)) { |
| 7723 |
return TCL_ERROR; |
| 7724 |
} |
| 7725 |
if (oper == SCAN_MARK) { |
| 7726 |
hboxPtr->scanAnchorX = x; |
| 7727 |
hboxPtr->scanAnchorY = y; |
| 7728 |
hboxPtr->scanX = hboxPtr->xOffset; |
| 7729 |
hboxPtr->scanY = hboxPtr->yOffset; |
| 7730 |
} else { |
| 7731 |
int worldX, worldY; |
| 7732 |
int dx, dy; |
| 7733 |
|
| 7734 |
dx = hboxPtr->scanAnchorX - x; |
| 7735 |
dy = hboxPtr->scanAnchorY - y; |
| 7736 |
worldX = hboxPtr->scanX + (10 * dx); |
| 7737 |
worldY = hboxPtr->scanY + (10 * dy); |
| 7738 |
|
| 7739 |
if (worldX < 0) { |
| 7740 |
worldX = 0; |
| 7741 |
} else if (worldX >= hboxPtr->worldWidth) { |
| 7742 |
worldX = hboxPtr->worldWidth - hboxPtr->xScrollUnits; |
| 7743 |
} |
| 7744 |
if (worldY < 0) { |
| 7745 |
worldY = 0; |
| 7746 |
} else if (worldY >= hboxPtr->worldHeight) { |
| 7747 |
worldY = hboxPtr->worldHeight - hboxPtr->yScrollUnits; |
| 7748 |
} |
| 7749 |
hboxPtr->xOffset = worldX; |
| 7750 |
hboxPtr->yOffset = worldY; |
| 7751 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 7752 |
EventuallyRedraw(hboxPtr); |
| 7753 |
} |
| 7754 |
return TCL_OK; |
| 7755 |
} |
| 7756 |
|
| 7757 |
/*ARGSUSED*/ |
| 7758 |
static int |
| 7759 |
SeeOp(hboxPtr, interp, argc, argv) |
| 7760 |
Hierbox *hboxPtr; |
| 7761 |
Tcl_Interp *interp; /* Not used. */ |
| 7762 |
int argc; |
| 7763 |
char **argv; |
| 7764 |
{ |
| 7765 |
Entry *entryPtr; |
| 7766 |
int width, height; |
| 7767 |
int x, y; |
| 7768 |
Tree *treePtr; |
| 7769 |
Tk_Anchor anchor; |
| 7770 |
int left, right, top, bottom; |
| 7771 |
|
| 7772 |
anchor = TK_ANCHOR_W; /* Default anchor is West */ |
| 7773 |
if ((argv[2][0] == '-') && (strcmp(argv[2], "-anchor") == 0)) { |
| 7774 |
if (argc == 3) { |
| 7775 |
Tcl_AppendResult(interp, "missing \"-anchor\" argument", |
| 7776 |
(char *)NULL); |
| 7777 |
return TCL_ERROR; |
| 7778 |
} |
| 7779 |
if (Tk_GetAnchor(interp, argv[3], &anchor) != TCL_OK) { |
| 7780 |
return TCL_ERROR; |
| 7781 |
} |
| 7782 |
argc -= 2, argv += 2; |
| 7783 |
} |
| 7784 |
if (argc == 2) { |
| 7785 |
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], |
| 7786 |
"see ?-anchor anchor? index\"", (char *)NULL); |
| 7787 |
return TCL_ERROR; |
| 7788 |
} |
| 7789 |
treePtr = hboxPtr->focusPtr; |
| 7790 |
if (GetNode(hboxPtr, argv[2], &treePtr) != TCL_OK) { |
| 7791 |
return TCL_ERROR; |
| 7792 |
} |
| 7793 |
if (treePtr == NULL) { |
| 7794 |
return TCL_OK; |
| 7795 |
} |
| 7796 |
if (IsHidden(treePtr)) { |
| 7797 |
ExposeAncestors(treePtr); |
| 7798 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 7799 |
/* |
| 7800 |
* If the entry wasn't previously exposed, its world coordinates |
| 7801 |
* aren't likely to be valid. So re-compute the layout before |
| 7802 |
* we try to see the viewport to the entry's location. |
| 7803 |
*/ |
| 7804 |
ComputeLayout(hboxPtr); |
| 7805 |
} |
| 7806 |
entryPtr = treePtr->entryPtr; |
| 7807 |
width = VPORTWIDTH(hboxPtr); |
| 7808 |
height = VPORTHEIGHT(hboxPtr); |
| 7809 |
|
| 7810 |
/* |
| 7811 |
* XVIEW: If the entry is left or right of the current view, adjust |
| 7812 |
* the offset. If the entry is nearby, adjust the view just |
| 7813 |
* a bit. Otherwise, center the entry. |
| 7814 |
*/ |
| 7815 |
left = hboxPtr->xOffset; |
| 7816 |
right = hboxPtr->xOffset + width; |
| 7817 |
|
| 7818 |
switch (anchor) { |
| 7819 |
case TK_ANCHOR_W: |
| 7820 |
case TK_ANCHOR_NW: |
| 7821 |
case TK_ANCHOR_SW: |
| 7822 |
x = 0; |
| 7823 |
break; |
| 7824 |
case TK_ANCHOR_E: |
| 7825 |
case TK_ANCHOR_NE: |
| 7826 |
case TK_ANCHOR_SE: |
| 7827 |
x = entryPtr->worldX + entryPtr->width + LEVELWIDTH(treePtr->level) - |
| 7828 |
width; |
| 7829 |
break; |
| 7830 |
default: |
| 7831 |
if (entryPtr->worldX < left) { |
| 7832 |
x = entryPtr->worldX; |
| 7833 |
} else if ((entryPtr->worldX + entryPtr->width) > right) { |
| 7834 |
x = entryPtr->worldX + entryPtr->width - width; |
| 7835 |
} else { |
| 7836 |
x = hboxPtr->xOffset; |
| 7837 |
} |
| 7838 |
break; |
| 7839 |
} |
| 7840 |
/* |
| 7841 |
* YVIEW: If the entry is above or below the current view, adjust |
| 7842 |
* the offset. If the entry is nearby, adjust the view just |
| 7843 |
* a bit. Otherwise, center the entry. |
| 7844 |
*/ |
| 7845 |
top = hboxPtr->yOffset; |
| 7846 |
bottom = hboxPtr->yOffset + height; |
| 7847 |
|
| 7848 |
switch (anchor) { |
| 7849 |
case TK_ANCHOR_N: |
| 7850 |
case TK_ANCHOR_NE: |
| 7851 |
case TK_ANCHOR_NW: |
| 7852 |
y = entryPtr->worldY; |
| 7853 |
break; |
| 7854 |
case TK_ANCHOR_CENTER: |
| 7855 |
y = entryPtr->worldY - (height / 2); |
| 7856 |
break; |
| 7857 |
case TK_ANCHOR_S: |
| 7858 |
case TK_ANCHOR_SE: |
| 7859 |
case TK_ANCHOR_SW: |
| 7860 |
y = entryPtr->worldY + entryPtr->height - height; |
| 7861 |
break; |
| 7862 |
default: |
| 7863 |
if (entryPtr->worldY < top) { |
| 7864 |
y = entryPtr->worldY; |
| 7865 |
} else if ((entryPtr->worldY + entryPtr->height) > bottom) { |
| 7866 |
y = entryPtr->worldY + entryPtr->height - height; |
| 7867 |
} else { |
| 7868 |
y = hboxPtr->yOffset; |
| 7869 |
} |
| 7870 |
break; |
| 7871 |
} |
| 7872 |
if ((y != hboxPtr->yOffset) || (x != hboxPtr->xOffset)) { |
| 7873 |
hboxPtr->xOffset = x; |
| 7874 |
hboxPtr->yOffset = y; |
| 7875 |
hboxPtr->flags |= (HIERBOX_SCROLL | HIERBOX_LAYOUT); |
| 7876 |
} |
| 7877 |
EventuallyRedraw(hboxPtr); |
| 7878 |
return TCL_OK; |
| 7879 |
} |
| 7880 |
|
| 7881 |
/* |
| 7882 |
*---------------------------------------------------------------------- |
| 7883 |
* |
| 7884 |
* AnchorOpOp -- |
| 7885 |
* |
| 7886 |
* Sets the selection anchor to the element given by a index. |
| 7887 |
* The selection anchor is the end of the selection that is fixed |
| 7888 |
* while dragging out a selection with the mouse. The index |
| 7889 |
* "anchor" may be used to refer to the anchor element. |
| 7890 |
* |
| 7891 |
* Results: |
| 7892 |
* None. |
| 7893 |
* |
| 7894 |
* Side effects: |
| 7895 |
* The selection changes. |
| 7896 |
* |
| 7897 |
*---------------------------------------------------------------------- |
| 7898 |
*/ |
| 7899 |
/*ARGSUSED*/ |
| 7900 |
static int |
| 7901 |
AnchorOpOp(hboxPtr, interp, argc, argv) |
| 7902 |
Hierbox *hboxPtr; |
| 7903 |
Tcl_Interp *interp; /* Not used. */ |
| 7904 |
int argc; /* Not used. */ |
| 7905 |
char **argv; |
| 7906 |
{ |
| 7907 |
Tree *nodePtr; |
| 7908 |
|
| 7909 |
nodePtr = hboxPtr->focusPtr; |
| 7910 |
if (GetNode(hboxPtr, argv[3], &nodePtr) != TCL_OK) { |
| 7911 |
return TCL_ERROR; |
| 7912 |
} |
| 7913 |
hboxPtr->selAnchorPtr = nodePtr; |
| 7914 |
if (nodePtr != NULL) { |
| 7915 |
Tcl_SetResult(interp, NodeToString(hboxPtr, nodePtr), TCL_VOLATILE); |
| 7916 |
} |
| 7917 |
EventuallyRedraw(hboxPtr); |
| 7918 |
return TCL_OK; |
| 7919 |
} |
| 7920 |
|
| 7921 |
|
| 7922 |
|
| 7923 |
/* |
| 7924 |
*---------------------------------------------------------------------- |
| 7925 |
* |
| 7926 |
* ClearallOpOp |
| 7927 |
* |
| 7928 |
* Clears the entire selection. |
| 7929 |
* |
| 7930 |
* Results: |
| 7931 |
* None. |
| 7932 |
* |
| 7933 |
* Side effects: |
| 7934 |
* The selection changes. |
| 7935 |
* |
| 7936 |
*---------------------------------------------------------------------- |
| 7937 |
*/ |
| 7938 |
/*ARGSUSED*/ |
| 7939 |
static int |
| 7940 |
ClearallOpOp(hboxPtr, interp, argc, argv) |
| 7941 |
Hierbox *hboxPtr; |
| 7942 |
Tcl_Interp *interp; |
| 7943 |
int argc; /* Not used. */ |
| 7944 |
char **argv; |
| 7945 |
{ |
| 7946 |
ClearSelection(hboxPtr); |
| 7947 |
return TCL_OK; |
| 7948 |
} |
| 7949 |
|
| 7950 |
/* |
| 7951 |
*---------------------------------------------------------------------- |
| 7952 |
* |
| 7953 |
* IncludesOpOp |
| 7954 |
* |
| 7955 |
* Returns 1 if the element indicated by index is currently |
| 7956 |
* selected, 0 if it isn't. |
| 7957 |
* |
| 7958 |
* Results: |
| 7959 |
* None. |
| 7960 |
* |
| 7961 |
* Side effects: |
| 7962 |
* The selection changes. |
| 7963 |
* |
| 7964 |
*---------------------------------------------------------------------- |
| 7965 |
*/ |
| 7966 |
/*ARGSUSED*/ |
| 7967 |
static int |
| 7968 |
IncludesOpOp(hboxPtr, interp, argc, argv) |
| 7969 |
Hierbox *hboxPtr; |
| 7970 |
Tcl_Interp *interp; |
| 7971 |
int argc; /* Not used. */ |
| 7972 |
char **argv; |
| 7973 |
{ |
| 7974 |
Tree *treePtr; |
| 7975 |
|
| 7976 |
treePtr = hboxPtr->focusPtr; |
| 7977 |
if (GetNode(hboxPtr, argv[3], &treePtr) != TCL_OK) { |
| 7978 |
return TCL_ERROR; |
| 7979 |
} |
| 7980 |
if (treePtr != NULL) { |
| 7981 |
int bool; |
| 7982 |
|
| 7983 |
bool = IsSelected(hboxPtr, treePtr); |
| 7984 |
Blt_SetBooleanResult(interp, bool); |
| 7985 |
} |
| 7986 |
return TCL_OK; |
| 7987 |
} |
| 7988 |
|
| 7989 |
/*---------------------------------------------------------------------- |
| 7990 |
* |
| 7991 |
* MarkOpOp -- |
| 7992 |
* |
| 7993 |
* Sets the selection mark to the element given by a index. The |
| 7994 |
* selection mark is the end of the selection that is not fixed |
| 7995 |
* while dragging out a selection with the mouse. The index |
| 7996 |
* "mark" may be used to refer to the anchor element. |
| 7997 |
* |
| 7998 |
* Results: |
| 7999 |
* None. |
| 8000 |
* |
| 8001 |
* Side effects: |
| 8002 |
* The selection changes. |
| 8003 |
* |
| 8004 |
*---------------------------------------------------------------------- |
| 8005 |
*/ |
| 8006 |
/*ARGSUSED*/ |
| 8007 |
static int |
| 8008 |
MarkOpOp(hboxPtr, interp, argc, argv) |
| 8009 |
Hierbox *hboxPtr; |
| 8010 |
Tcl_Interp *interp; /* Not used. */ |
| 8011 |
int argc; /* Not used. */ |
| 8012 |
char **argv; |
| 8013 |
{ |
| 8014 |
Tree *nodePtr; |
| 8015 |
Blt_ChainLink *linkPtr, *nextPtr; |
| 8016 |
Tree *selectPtr; |
| 8017 |
|
| 8018 |
nodePtr = hboxPtr->focusPtr; |
| 8019 |
if (GetNode(hboxPtr, argv[3], &nodePtr) != TCL_OK) { |
| 8020 |
return TCL_ERROR; |
| 8021 |
} |
| 8022 |
if (hboxPtr->selAnchorPtr == NULL) { |
| 8023 |
Tcl_AppendResult(interp, "selection anchor must be set first", |
| 8024 |
(char *)NULL); |
| 8025 |
return TCL_ERROR; |
| 8026 |
} |
| 8027 |
|
| 8028 |
/* Deselect entry from the list all the way back to the anchor. */ |
| 8029 |
for (linkPtr = Blt_ChainLastLink(&(hboxPtr->selectChain)); |
| 8030 |
linkPtr != NULL; linkPtr = nextPtr) { |
| 8031 |
nextPtr = Blt_ChainPrevLink(linkPtr); |
| 8032 |
selectPtr = Blt_ChainGetValue(linkPtr); |
| 8033 |
if (selectPtr == hboxPtr->selAnchorPtr) { |
| 8034 |
break; |
| 8035 |
} |
| 8036 |
DeselectEntry(hboxPtr, selectPtr); |
| 8037 |
} |
| 8038 |
if (nodePtr != NULL) { |
| 8039 |
hboxPtr->flags &= ~SELECTION_MASK; |
| 8040 |
hboxPtr->flags |= SELECTION_SET; |
| 8041 |
SelectRange(hboxPtr, hboxPtr->selAnchorPtr, nodePtr); |
| 8042 |
hboxPtr->flags &= ~SELECTION_MASK; |
| 8043 |
Tcl_SetResult(interp, NodeToString(hboxPtr, nodePtr), TCL_VOLATILE); |
| 8044 |
} |
| 8045 |
EventuallyRedraw(hboxPtr); |
| 8046 |
if (hboxPtr->selectCmd != NULL) { |
| 8047 |
EventuallyInvokeSelectCmd(hboxPtr); |
| 8048 |
} |
| 8049 |
return TCL_OK; |
| 8050 |
} |
| 8051 |
|
| 8052 |
/* |
| 8053 |
*---------------------------------------------------------------------- |
| 8054 |
* |
| 8055 |
* PresentOpOp |
| 8056 |
* |
| 8057 |
* Indicates if there is a selection present. |
| 8058 |
* |
| 8059 |
* Results: |
| 8060 |
* A standard Tcl result. |
| 8061 |
* |
| 8062 |
*---------------------------------------------------------------------- |
| 8063 |
*/ |
| 8064 |
/*ARGSUSED*/ |
| 8065 |
static int |
| 8066 |
PresentOpOp(hboxPtr, interp, argc, argv) |
| 8067 |
Hierbox *hboxPtr; |
| 8068 |
Tcl_Interp *interp; |
| 8069 |
int argc; /* Not used. */ |
| 8070 |
char **argv; |
| 8071 |
{ |
| 8072 |
int bool; |
| 8073 |
|
| 8074 |
bool = (Blt_ChainGetLength(&(hboxPtr->selectChain)) > 0); |
| 8075 |
Blt_SetBooleanResult(interp, bool); |
| 8076 |
return TCL_OK; |
| 8077 |
} |
| 8078 |
|
| 8079 |
/* |
| 8080 |
*---------------------------------------------------------------------- |
| 8081 |
* |
| 8082 |
* SelectOpOp |
| 8083 |
* |
| 8084 |
* Selects, deselects, or toggles all of the elements in the |
| 8085 |
* range between first and last, inclusive, without affecting the |
| 8086 |
* selection state of elements outside that range. |
| 8087 |
* |
| 8088 |
* Results: |
| 8089 |
* None. |
| 8090 |
* |
| 8091 |
* Side effects: |
| 8092 |
* The selection changes. |
| 8093 |
* |
| 8094 |
*---------------------------------------------------------------------- |
| 8095 |
*/ |
| 8096 |
/*ARGSUSED*/ |
| 8097 |
static int |
| 8098 |
SelectOpOp(hboxPtr, interp, argc, argv) |
| 8099 |
Hierbox *hboxPtr; |
| 8100 |
Tcl_Interp *interp; |
| 8101 |
int argc; /* Not used. */ |
| 8102 |
char **argv; |
| 8103 |
{ |
| 8104 |
Tree *firstPtr, *lastPtr; |
| 8105 |
|
| 8106 |
hboxPtr->flags &= ~SELECTION_MASK; |
| 8107 |
switch (argv[2][0]) { |
| 8108 |
case 's': |
| 8109 |
hboxPtr->flags |= SELECTION_SET; |
| 8110 |
break; |
| 8111 |
case 'c': |
| 8112 |
hboxPtr->flags |= SELECTION_CLEAR; |
| 8113 |
break; |
| 8114 |
case 't': |
| 8115 |
hboxPtr->flags |= SELECTION_TOGGLE; |
| 8116 |
break; |
| 8117 |
} |
| 8118 |
|
| 8119 |
if (StringToNode(hboxPtr, argv[3], &firstPtr) != TCL_OK) { |
| 8120 |
return TCL_ERROR; |
| 8121 |
} |
| 8122 |
if ((IsHidden(firstPtr)) && !(hboxPtr->flags & SELECTION_CLEAR)) { |
| 8123 |
Tcl_AppendResult(interp, "can't select hidden node \"", argv[3], "\"", |
| 8124 |
(char *)NULL); |
| 8125 |
return TCL_ERROR; |
| 8126 |
} |
| 8127 |
lastPtr = firstPtr; |
| 8128 |
if (argc > 4) { |
| 8129 |
if (StringToNode(hboxPtr, argv[4], &lastPtr) != TCL_OK) { |
| 8130 |
return TCL_ERROR; |
| 8131 |
} |
| 8132 |
if ((IsHidden(lastPtr)) && !(hboxPtr->flags & SELECTION_CLEAR)) { |
| 8133 |
Tcl_AppendResult(interp, "can't select hidden node \"", argv[4], |
| 8134 |
"\"", (char *)NULL); |
| 8135 |
return TCL_ERROR; |
| 8136 |
} |
| 8137 |
} |
| 8138 |
if (firstPtr == lastPtr) { |
| 8139 |
SelectNode(hboxPtr, firstPtr); |
| 8140 |
} else { |
| 8141 |
SelectRange(hboxPtr, firstPtr, lastPtr); |
| 8142 |
} |
| 8143 |
hboxPtr->flags &= ~SELECTION_MASK; |
| 8144 |
if (hboxPtr->flags & SELECTION_EXPORT) { |
| 8145 |
Tk_OwnSelection(hboxPtr->tkwin, XA_PRIMARY, LostSelection, hboxPtr); |
| 8146 |
} |
| 8147 |
EventuallyRedraw(hboxPtr); |
| 8148 |
if (hboxPtr->selectCmd != NULL) { |
| 8149 |
EventuallyInvokeSelectCmd(hboxPtr); |
| 8150 |
} |
| 8151 |
return TCL_OK; |
| 8152 |
} |
| 8153 |
|
| 8154 |
/* |
| 8155 |
*---------------------------------------------------------------------- |
| 8156 |
* |
| 8157 |
* SelectionOp -- |
| 8158 |
* |
| 8159 |
* This procedure handles the individual options for text |
| 8160 |
* selections. The selected text is designated by start and end |
| 8161 |
* indices into the text pool. The selected segment has both a |
| 8162 |
* anchored and unanchored ends. |
| 8163 |
* |
| 8164 |
* Results: |
| 8165 |
* None. |
| 8166 |
* |
| 8167 |
* Side effects: |
| 8168 |
* The selection changes. |
| 8169 |
* |
| 8170 |
*---------------------------------------------------------------------- |
| 8171 |
*/ |
| 8172 |
static Blt_OpSpec selectionOperSpecs[] = |
| 8173 |
{ |
| 8174 |
{"anchor", 1, (Blt_Op)AnchorOpOp, 4, 4, "index",}, |
| 8175 |
{"clear", 5, (Blt_Op)SelectOpOp, 4, 5, "firstIndex ?lastIndex?",}, |
| 8176 |
{"clearall", 6, (Blt_Op)ClearallOpOp, 3, 3, "",}, |
| 8177 |
{"includes", 2, (Blt_Op)IncludesOpOp, 4, 4, "index",}, |
| 8178 |
{"mark", 1, (Blt_Op)MarkOpOp, 4, 4, "index",}, |
| 8179 |
{"present", 1, (Blt_Op)PresentOpOp, 3, 3, "",}, |
| 8180 |
{"set", 1, (Blt_Op)SelectOpOp, 4, 5, "firstIndex ?lastIndex?",}, |
| 8181 |
{"toggle", 1, (Blt_Op)SelectOpOp, 4, 5, "firstIndex ?lastIndex?",}, |
| 8182 |
}; |
| 8183 |
static int nSelectionSpecs = sizeof(selectionOperSpecs) / sizeof(Blt_OpSpec); |
| 8184 |
|
| 8185 |
static int |
| 8186 |
SelectionOp(hboxPtr, interp, argc, argv) |
| 8187 |
Hierbox *hboxPtr; |
| 8188 |
Tcl_Interp *interp; |
| 8189 |
int argc; |
| 8190 |
char **argv; |
| 8191 |
{ |
| 8192 |
Blt_Op proc; |
| 8193 |
int result; |
| 8194 |
|
| 8195 |
proc = Blt_GetOp(interp, nSelectionSpecs, selectionOperSpecs, BLT_OP_ARG2, |
| 8196 |
argc, argv, 0); |
| 8197 |
if (proc == NULL) { |
| 8198 |
return TCL_ERROR; |
| 8199 |
} |
| 8200 |
result = (*proc) (hboxPtr, interp, argc, argv); |
| 8201 |
return result; |
| 8202 |
} |
| 8203 |
|
| 8204 |
/*ARGSUSED*/ |
| 8205 |
static int |
| 8206 |
SortOp(hboxPtr, interp, argc, argv) |
| 8207 |
Hierbox *hboxPtr; |
| 8208 |
Tcl_Interp *interp; /* Not used. */ |
| 8209 |
int argc; |
| 8210 |
char **argv; |
| 8211 |
{ |
| 8212 |
int length; |
| 8213 |
Tree *rootPtr; |
| 8214 |
register int i; |
| 8215 |
unsigned int flags; |
| 8216 |
|
| 8217 |
flags = 0; |
| 8218 |
hboxPtr->sortCmd = NULL; |
| 8219 |
for (i = 2; i < argc; i++) { |
| 8220 |
if (argv[i][0] != '-') { |
| 8221 |
break; /* Found start of indices */ |
| 8222 |
} |
| 8223 |
length = strlen(argv[i]); |
| 8224 |
if ((length > 1) && (strncmp(argv[i], "-recurse", length) == 0)) { |
| 8225 |
flags |= APPLY_RECURSE; |
| 8226 |
} else if ((length > 1) && (strncmp(argv[i], "-command", length) ==0)) { |
| 8227 |
if ((i + 1) == argc) { |
| 8228 |
Tcl_AppendResult(interp, "\"-command\" must be", |
| 8229 |
" followed by comparison command", (char *)NULL); |
| 8230 |
return TCL_ERROR; |
| 8231 |
} |
| 8232 |
i++; |
| 8233 |
hboxPtr->sortCmd = argv[i]; |
| 8234 |
} else if ((argv[i][1] == '-') && (argv[i][2] == '\0')) { |
| 8235 |
break; /* Allow first index to start with a '-' */ |
| 8236 |
} else { |
| 8237 |
Tcl_AppendResult(interp, "bad switch \"", argv[i], |
| 8238 |
"\": must be -command or -recurse", (char *)NULL); |
| 8239 |
return TCL_ERROR; |
| 8240 |
} |
| 8241 |
} |
| 8242 |
for ( /*empty*/ ; i < argc; i++) { |
| 8243 |
if (StringToNode(hboxPtr, argv[i], &rootPtr) != TCL_OK) { |
| 8244 |
return TCL_ERROR; |
| 8245 |
} |
| 8246 |
if (ApplyToTree(hboxPtr, rootPtr, SortNode, flags) != TCL_OK) { |
| 8247 |
return TCL_ERROR; |
| 8248 |
} |
| 8249 |
} |
| 8250 |
hboxPtr->flags |= HIERBOX_LAYOUT; |
| 8251 |
EventuallyRedraw(hboxPtr); |
| 8252 |
return TCL_OK; |
| 8253 |
} |
| 8254 |
|
| 8255 |
/*ARGSUSED*/ |
| 8256 |
static int |
| 8257 |
ToggleOp(hboxPtr, interp, argc, argv) |
| 8258 |
Hierbox *hboxPtr; |
| 8259 |
Tcl_Interp *interp; /* Not used. */ |
| 8260 |
int argc; |
| 8261 |
char **argv; |
| 8262 |
{ |
| 8263 |
Tree *rootPtr; |
| 8264 |
int result; |
| 8265 |
|
| 8266 |
rootPtr = hboxPtr->focusPtr; |
| 8267 |
if (GetNode(hboxPtr, argv[2], &rootPtr) != TCL_OK) { |
| 8268 |
return TCL_ERROR; |
| 8269 |
} |
| 8270 |
if (rootPtr == NULL) { |
| 8271 |
return TCL_OK; |
| 8272 |
} |
| 8273 |
if (rootPtr->entryPtr->flags & ENTRY_OPEN) { |
| 8274 |
PruneSelection(hboxPtr, rootPtr); |
| 8275 |
if (IsAncestor(rootPtr, hboxPtr->focusPtr)) { |
| 8276 |
hboxPtr->focusPtr = rootPtr; |
| 8277 |
Blt_SetFocusItem(hboxPtr->bindTable, hboxPtr->focusPtr, NULL); |
| 8278 |
} |
| 8279 |
if (IsAncestor(rootPtr, hboxPtr->selAnchorPtr)) { |
| 8280 |
hboxPtr->selAnchorPtr = NULL; |
| 8281 |
} |
| 8282 |
result = CloseNode(hboxPtr, rootPtr); |
| 8283 |
} else { |
| 8284 |
result = OpenNode(hboxPtr, rootPtr); |
| 8285 |
} |
| 8286 |
if (result != TCL_OK) { |
| 8287 |
return TCL_ERROR; |
| 8288 |
} |
| 8289 |
hboxPtr->flags |= (HIERBOX_LAYOUT | HIERBOX_SCROLL); |
| 8290 |
EventuallyRedraw(hboxPtr); |
| 8291 |
return TCL_OK; |
| 8292 |
} |
| 8293 |
|
| 8294 |
static int |
| 8295 |
XViewOp(hboxPtr, interp, argc, argv) |
| 8296 |
Hierbox *hboxPtr; |
| 8297 |
Tcl_Interp *interp; |
| 8298 |
int argc; |
| 8299 |
char **argv; |
| 8300 |
{ |
| 8301 |
int width, worldWidth; |
| 8302 |
|
| 8303 |
width = VPORTWIDTH(hboxPtr); |
| 8304 |
worldWidth = hboxPtr->worldWidth; |
| 8305 |
if (argc == 2) { |
| 8306 |
double fract; |
| 8307 |
|
| 8308 |
/* |
| 8309 |
* Note that we are bounding the fractions between 0.0 and 1.0 |
| 8310 |
* to support the "canvas"-style of scrolling. |
| 8311 |
*/ |
| 8312 |
fract = (double)hboxPtr->xOffset / worldWidth; |
| 8313 |
Tcl_AppendElement(interp, Blt_Dtoa(interp, CLAMP(fract, 0.0, 1.0))); |
| 8314 |
fract = (double)(hboxPtr->xOffset + width) / worldWidth; |
| 8315 |
Tcl_AppendElement(interp, Blt_Dtoa(interp, CLAMP(fract, 0.0, 1.0))); |
| 8316 |
return TCL_OK; |
| 8317 |
} |
| 8318 |
if (Blt_GetScrollInfo(interp, argc - 2, argv + 2, &(hboxPtr->xOffset), |
| 8319 |
worldWidth, width, hboxPtr->xScrollUnits, hboxPtr->scrollMode) |
| 8320 |
!= TCL_OK) { |
| 8321 |
return TCL_ERROR; |
| 8322 |
} |
| 8323 |
hboxPtr->flags |= HIERBOX_XSCROLL; |
| 8324 |
EventuallyRedraw(hboxPtr); |
| 8325 |
return TCL_OK; |
| 8326 |
} |
| 8327 |
|
| 8328 |
static int |
| 8329 |
YViewOp(hboxPtr, interp, argc, argv) |
| 8330 |
Hierbox *hboxPtr; |
| 8331 |
Tcl_Interp *interp; |
| 8332 |
int argc; |
| 8333 |
char **argv; |
| 8334 |
{ |
| 8335 |
int height, worldHeight; |
| 8336 |
|
| 8337 |
height = VPORTHEIGHT(hboxPtr); |
| 8338 |
worldHeight = hboxPtr->worldHeight; |
| 8339 |
if (argc == 2) { |
| 8340 |
double fract; |
| 8341 |
|
| 8342 |
/* Report first and last fractions */ |
| 8343 |
fract = (double)hboxPtr->yOffset / worldHeight; |
| 8344 |
Tcl_AppendElement(interp, Blt_Dtoa(interp, CLAMP(fract, 0.0, 1.0))); |
| 8345 |
fract = (double)(hboxPtr->yOffset + height) / worldHeight; |
| 8346 |
Tcl_AppendElement(interp, Blt_Dtoa(interp, CLAMP(fract, 0.0, 1.0))); |
| 8347 |
return TCL_OK; |
| 8348 |
} |
| 8349 |
if (Blt_GetScrollInfo(interp, argc - 2, argv + 2, &(hboxPtr->yOffset), |
| 8350 |
worldHeight, height, hboxPtr->yScrollUnits, hboxPtr->scrollMode) |
| 8351 |
!= TCL_OK) { |
| 8352 |
return TCL_ERROR; |
| 8353 |
} |
| 8354 |
hboxPtr->flags |= HIERBOX_SCROLL; |
| 8355 |
EventuallyRedraw(hboxPtr); |
| 8356 |
return TCL_OK; |
| 8357 |
} |
| 8358 |
|
| 8359 |
/* |
| 8360 |
* -------------------------------------------------------------- |
| 8361 |
* |
| 8362 |
* HierboxInstCmd -- |
| 8363 |
* |
| 8364 |
* This procedure is invoked to process the "hierbox" command. |
| 8365 |
* See the user documentation for details on what it does. |
| 8366 |
* |
| 8367 |
* Results: |
| 8368 |
* A standard Tcl result. |
| 8369 |
* |
| 8370 |
* Side effects: |
| 8371 |
* See the user documentation. |
| 8372 |
* |
| 8373 |
* -------------------------------------------------------------- |
| 8374 |
*/ |
| 8375 |
static Blt_OpSpec operSpecs[] = |
| 8376 |
{ |
| 8377 |
{"bbox", 2, (Blt_Op)BboxOp, 2, 0, "index...",}, |
| 8378 |
{"bind", 2, (Blt_Op)BindOp, 3, 5, "tagName ?sequence command?",}, |
| 8379 |
{"button", 2, (Blt_Op)ButtonOp, 2, 0, "args",}, |
| 8380 |
{"cget", 2, (Blt_Op)CgetOp, 3, 3, "option",}, |
| 8381 |
{"close", 2, (Blt_Op)CloseOp, 2, 0, "?-recurse? index...",}, |
| 8382 |
{"configure", 2, (Blt_Op)ConfigureOp, 2, 0, "?option value?...",}, |
| 8383 |
{"curselection", 2, (Blt_Op)CurselectionOp, 2, 2, "",}, |
| 8384 |
{"delete", 1, (Blt_Op)DeleteOp, 2, 0, "?-recurse? index ?index...?",}, |
| 8385 |
{"entry", 1, (Blt_Op)EntryOp, 2, 0, "oper args",}, |
| 8386 |
{"find", 2, (Blt_Op)FindOp, 2, 0, "?flags...? ?firstIndex lastIndex?",}, |
| 8387 |
{"focus", 2, (Blt_Op)FocusOp, 3, 3, "index",}, |
| 8388 |
{"get", 1, (Blt_Op)GetOp, 2, 0, "?-full? index ?index...?",}, |
| 8389 |
{"hide", 1, (Blt_Op)HideOp, 2, 0, "?-exact? ?-glob? ?-regexp? ?-nonmatching? ?-name string? ?-full string? ?-data string? ?--? ?index...?",}, |
| 8390 |
{"index", 3, (Blt_Op)IndexOp, 3, 5, "?-at index? string",}, |
| 8391 |
{"insert", 3, (Blt_Op)InsertOp, 3, 0, "?-at index? position label ?label...? ?option value?",}, |
| 8392 |
{"move", 1, (Blt_Op)MoveOp, 5, 5, "index into|before|after index",}, |
| 8393 |
{"nearest", 1, (Blt_Op)NearestOp, 4, 5, "x y ?varName?",}, |
| 8394 |
{"open", 1, (Blt_Op)OpenOp, 2, 0, "?-recurse? index...",}, |
| 8395 |
{"range", 1, (Blt_Op)RangeOp, 4, 5, "?-open? firstIndex lastIndex",}, |
| 8396 |
{"scan", 2, (Blt_Op)ScanOp, 5, 5, "dragto|mark x y",}, |
| 8397 |
{"see", 3, (Blt_Op)SeeOp, 3, 0, "?-anchor anchor? index",}, |
| 8398 |
{"selection", 3, (Blt_Op)SelectionOp, 2, 0, "oper args",}, |
| 8399 |
{"show", 2, (Blt_Op)ShowOp, 2, 0, "?-exact? ?-glob? ?-regexp? ?-nonmatching? ?-name string? ?-full string? ?-data string? ?--? ?index...?",}, |
| 8400 |
{"sort", 2, (Blt_Op)SortOp, 2, 0, "?-recurse? ?-command string? index...",}, |
| 8401 |
{"toggle", 1, (Blt_Op)ToggleOp, 3, 3, "index",}, |
| 8402 |
{"xview", 1, (Blt_Op)XViewOp, 2, 5, "?moveto fract? ?scroll number what?",}, |
| 8403 |
{"yview", 1, (Blt_Op)YViewOp, 2, 5, "?moveto fract? ?scroll number what?",}, |
| 8404 |
}; |
| 8405 |
|
| 8406 |
static int nSpecs = sizeof(operSpecs) / sizeof(Blt_OpSpec); |
| 8407 |
|
| 8408 |
static int |
| 8409 |
HierboxInstCmd(clientData, interp, argc, argv) |
| 8410 |
ClientData clientData; /* Information about the widget. */ |
| 8411 |
Tcl_Interp *interp; /* Interpreter to report errors back to. */ |
| 8412 |
int argc; /* Number of arguments. */ |
| 8413 |
char **argv; /* Vector of argument strings. */ |
| 8414 |
{ |
| 8415 |
Blt_Op proc; |
| 8416 |
Hierbox *hboxPtr = clientData; |
| 8417 |
int result; |
| 8418 |
|
| 8419 |
proc = Blt_GetOp(interp, nSpecs, operSpecs, BLT_OP_ARG1, argc, argv, 0); |
| 8420 |
if (proc == NULL) { |
| 8421 |
return TCL_ERROR; |
| 8422 |
} |
| 8423 |
Tcl_Preserve(hboxPtr); |
| 8424 |
result = (*proc) (hboxPtr, interp, argc, argv); |
| 8425 |
Tcl_Release(hboxPtr); |
| 8426 |
return result; |
| 8427 |
} |
| 8428 |
|
| 8429 |
int |
| 8430 |
Blt_HierboxInit(interp) |
| 8431 |
Tcl_Interp *interp; |
| 8432 |
{ |
| 8433 |
static Blt_CmdSpec cmdSpec = |
| 8434 |
{ |
| 8435 |
"hierbox", HierboxCmd, |
| 8436 |
}; |
| 8437 |
|
| 8438 |
if (Blt_InitCmd(interp, "blt", &cmdSpec) == NULL) { |
| 8439 |
return TCL_ERROR; |
| 8440 |
} |
| 8441 |
return TCL_OK; |
| 8442 |
} |
| 8443 |
|
| 8444 |
#ifdef notdef |
| 8445 |
|
| 8446 |
/* Selection Procedures */ |
| 8447 |
/* |
| 8448 |
*---------------------------------------------------------------------- |
| 8449 |
* |
| 8450 |
* SelectTextBlock -- |
| 8451 |
* |
| 8452 |
* Modify the selection by moving its un-anchored end. This |
| 8453 |
* could make the selection either larger or smaller. |
| 8454 |
* |
| 8455 |
* Results: |
| 8456 |
* None. |
| 8457 |
* |
| 8458 |
* Side effects: |
| 8459 |
* The selection changes. |
| 8460 |
* |
| 8461 |
*---------------------------------------------------------------------- |
| 8462 |
*/ |
| 8463 |
static int |
| 8464 |
SelectTextBlock(hboxPtr, to) |
| 8465 |
Hierbox *hboxPtr; /* Information about widget. */ |
| 8466 |
int to; /* Index of element that is to |
| 8467 |
* become the "other" end of the |
| 8468 |
* selection. */ |
| 8469 |
{ |
| 8470 |
TextEdit *editPtr = &(hboxPtr->labelEdit); |
| 8471 |
int first, last; |
| 8472 |
|
| 8473 |
/* If the anchor hasn't been set yet, assume the beginning of the label. */ |
| 8474 |
if (editPtr->selAnchor < 0) { |
| 8475 |
editPtr->selAnchor = 0; |
| 8476 |
} |
| 8477 |
if (editPtr->selAnchor <= to) { |
| 8478 |
first = editPtr->selAnchor; |
| 8479 |
last = to; |
| 8480 |
} else { |
| 8481 |
first = to; |
| 8482 |
last = editPtr->selAnchor; |
| 8483 |
} |
| 8484 |
if ((editPtr->selFirst != first) || (editPtr->selLast != last)) { |
| 8485 |
editPtr->selFirst = first, editPtr->selLast = last; |
| 8486 |
EventuallyRedraw(hboxPtr); |
| 8487 |
} |
| 8488 |
return TCL_OK; |
| 8489 |
} |
| 8490 |
|
| 8491 |
/* |
| 8492 |
*---------------------------------------------------------------------- |
| 8493 |
* |
| 8494 |
* ClearOpOp -- |
| 8495 |
* |
| 8496 |
* Clears the selection from the label. |
| 8497 |
* |
| 8498 |
* Results: |
| 8499 |
* None. |
| 8500 |
* |
| 8501 |
* Side effects: |
| 8502 |
* The selection changes. |
| 8503 |
* |
| 8504 |
*---------------------------------------------------------------------- |
| 8505 |
*/ |
| 8506 |
static int |
| 8507 |
ClearOpOp(hboxPtr, interp, argc, argv) |
| 8508 |
Hierbox *hboxPtr; |
| 8509 |
Tcl_Interp *interp; |
| 8510 |
int argc; |
| 8511 |
char **argv; |
| 8512 |
{ |
| 8513 |
TextEdit *editPtr = &(hboxPtr->labelEdit); |
| 8514 |
|
| 8515 |
if (editPtr->selFirst != -1) { |
| 8516 |
editPtr->selFirst = editPtr->selLast = -1; |
| 8517 |
EventuallyRedraw(hboxPtr); |
| 8518 |
} |
| 8519 |
return TCL_OK; |
| 8520 |
} |
| 8521 |
|
| 8522 |
static int |
| 8523 |
FromOpOp(hboxPtr, interp, argc, argv) |
| 8524 |
Hierbox *hboxPtr; |
| 8525 |
Tcl_Interp *interp; |
| 8526 |
int argc; |
| 8527 |
char **argv; |
| 8528 |
{ |
| 8529 |
TextEdit *editPtr = &(hboxPtr->labelEdit); |
| 8530 |
int from; |
| 8531 |
|
| 8532 |
if (GetLabelIndex(hboxPtr, argv[3], &from) != TCL_OK) { |
| 8533 |
return TCL_ERROR; |
| 8534 |
} |
| 8535 |
editPtr->selAnchor = from; |
| 8536 |
return TCL_OK; |
| 8537 |
} |
| 8538 |
|
| 8539 |
static int |
| 8540 |
PresentOpOp(hboxPtr, interp, argc, argv) |
| 8541 |
Hierbox *hboxPtr; |
| 8542 |
Tcl_Interp *interp; |
| 8543 |
int argc; |
| 8544 |
char **argv; |
| 8545 |
{ |
| 8546 |
TextEdit *editPtr = &(hboxPtr->labelEdit); |
| 8547 |
Tcl_AppendResult(interp, (editPtr->selFirst != -1) ? "0" : "1", (char *)NULL); |
| 8548 |
return TCL_OK; |
| 8549 |
} |
| 8550 |
|
| 8551 |
static int |
| 8552 |
AdjustOpOp(hboxPtr, interp, argc, argv) |
| 8553 |
Hierbox *hboxPtr; |
| 8554 |
Tcl_Interp *interp; |
| 8555 |
int argc; |
| 8556 |
char **argv; |
| 8557 |
{ |
| 8558 |
TextEdit *editPtr = &(hboxPtr->labelEdit); |
| 8559 |
int adjust; |
| 8560 |
|
| 8561 |
if (GetLabelIndex(hboxPtr, argv[3], &adjust) != TCL_OK) { |
| 8562 |
return TCL_ERROR; |
| 8563 |
} |
| 8564 |
half1 = (editPtr->selFirst + editPtr->selLast) / 2; |
| 8565 |
half2 = (editPtr->selFirst + editPtr->selLast + 1) / 2; |
| 8566 |
if (adjust < half1) { |
| 8567 |
editPtr->selAnchor = editPtr->selLast; |
| 8568 |
} else if (adjust > half2) { |
| 8569 |
editPtr->selAnchor = editPtr->selFirst; |
| 8570 |
} |
| 8571 |
result = SelectTextBlock(hboxPtr, adjust); |
| 8572 |
return TCL_OK; |
| 8573 |
} |
| 8574 |
|
| 8575 |
static int |
| 8576 |
ToOpOp(hboxPtr, interp, argc, argv) |
| 8577 |
Hierbox *hboxPtr; |
| 8578 |
Tcl_Interp *interp; |
| 8579 |
int argc; |
| 8580 |
char **argv; |
| 8581 |
{ |
| 8582 |
int to; |
| 8583 |
|
| 8584 |
if (GetLabelIndex(hboxPtr, argv[3], &to) != TCL_OK) { |
| 8585 |
return TCL_ERROR; |
| 8586 |
} |
| 8587 |
SelectTextBlock(hboxPtr, to); |
| 8588 |
return TCL_OK; |
| 8589 |
} |
| 8590 |
|
| 8591 |
static int |
| 8592 |
RangeOpOp(hboxPtr, interp, argc, argv) |
| 8593 |
Hierbox *hboxPtr; |
| 8594 |
Tcl_Interp *interp; |
| 8595 |
int argc; |
| 8596 |
char **argv; |
| 8597 |
{ |
| 8598 |
TextEdit *editPtr = &(hboxPtr->labelEdit); |
| 8599 |
int first, last; |
| 8600 |
|
| 8601 |
if (GetLabelIndex(hboxPtr, argv[4], &first) != TCL_OK) { |
| 8602 |
return TCL_ERROR; |
| 8603 |
} |
| 8604 |
if (GetLabelIndex(hboxPtr, argv[5], &last) != TCL_OK) { |
| 8605 |
return TCL_ERROR; |
| 8606 |
} |
| 8607 |
editPtr->selAnchor = first; |
| 8608 |
return SelectTextBlock(hboxPtr, last); |
| 8609 |
} |
| 8610 |
|
| 8611 |
/* |
| 8612 |
*---------------------------------------------------------------------- |
| 8613 |
* |
| 8614 |
* SelectionOp -- |
| 8615 |
* |
| 8616 |
* This procedure handles the individual options for text |
| 8617 |
* selections. The selected text is designated by a starting |
| 8618 |
* and terminating index that points into the text. The selected |
| 8619 |
* segment has both a anchored and unanchored ends. The following |
| 8620 |
* selection operations are implemented: |
| 8621 |
* |
| 8622 |
* adjust index Resets either the first or last index |
| 8623 |
* of the selection. |
| 8624 |
* clear Clears the selection. Sets first/last |
| 8625 |
* indices to -1. |
| 8626 |
* from index Sets the index of the selection anchor. |
| 8627 |
* present Return "1" if a selection is available, |
| 8628 |
* "0" otherwise. |
| 8629 |
* range first last Sets the selection. |
| 8630 |
* to index Sets the index of the un-anchored end. |
| 8631 |
|
| 8632 |
* Results: |
| 8633 |
* None. |
| 8634 |
* |
| 8635 |
* Side effects: |
| 8636 |
* The selection changes. |
| 8637 |
* |
| 8638 |
*---------------------------------------------------------------------- |
| 8639 |
*/ |
| 8640 |
static Blt_OpSpec entrySelectionOperSpecs[] = |
| 8641 |
{ |
| 8642 |
{"adjust", 2, (Blt_Op)AdjustOpOp, 5, 5, "index",}, |
| 8643 |
{"clear", 2, (Blt_Op)ClearOpOp, 4, 4, "",}, |
| 8644 |
{"from", 1, (Blt_Op)FromOpOp, 5, 5, "index",}, |
| 8645 |
{"present", 1, (Blt_Op)PresentOpOp, 4, 4, "",}, |
| 8646 |
{"range", 1, (Blt_Op)RangeOpOp, 4, 5, "firstIndex lastIndex",}, |
| 8647 |
{"to", 1, (Blt_Op)ToOpOp, 5, 5, "index",}, |
| 8648 |
}; |
| 8649 |
static int nEntrySelectionSpecs = |
| 8650 |
sizeof(entrySelectionOperSpecs) / sizeof(Blt_OpSpec); |
| 8651 |
|
| 8652 |
static int |
| 8653 |
EntrySelectionOp(hboxPtr, interp, argc, argv) |
| 8654 |
Hierbox *hboxPtr; |
| 8655 |
Tcl_Interp *interp; |
| 8656 |
int argc; |
| 8657 |
char **argv; |
| 8658 |
{ |
| 8659 |
Blt_Op proc; |
| 8660 |
int result; |
| 8661 |
|
| 8662 |
proc = Blt_GetOp(interp, nSelectionSpecs, selectionOperSpecs, BLT_OP_ARG2, |
| 8663 |
argc, argv, 0); |
| 8664 |
if (proc == NULL) { |
| 8665 |
return TCL_ERROR; |
| 8666 |
} |
| 8667 |
result = (*proc) (hboxPtr, interp, argc, argv); |
| 8668 |
return result; |
| 8669 |
} |
| 8670 |
|
| 8671 |
#endif |
| 8672 |
|
| 8673 |
#endif /* NO_HIERBOX */ |