| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
#include "bltInt.h" |
| 44 |
|
| 45 |
#ifndef NO_TREEVIEW |
| 46 |
|
| 47 |
#include "bltTreeView.h" |
| 48 |
#include <X11/Xutil.h> |
| 49 |
#include <X11/Xatom.h> |
| 50 |
|
| 51 |
#define TEXTBOX_FOCUS (1<<0) |
| 52 |
#define TEXTBOX_REDRAW (1<<1) |
| 53 |
|
| 54 |
static Tcl_IdleProc DisplayTextbox; |
| 55 |
static Tcl_FreeProc DestroyTextbox; |
| 56 |
static Tcl_TimerProc BlinkCursorProc; |
| 57 |
static Tcl_ObjCmdProc TextboxCmd; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
typedef struct { |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
Tk_Window tkwin; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
Display *display; |
| 97 |
|
| 98 |
|
| 99 |
Tcl_Interp *interp; |
| 100 |
|
| 101 |
Tcl_Command widgetCmd; |
| 102 |
char *className; |
| 103 |
|
| 104 |
int mask; |
| 105 |
|
| 106 |
|
| 107 |
char *screenName; |
| 108 |
|
| 109 |
|
| 110 |
char *visualName; |
| 111 |
|
| 112 |
|
| 113 |
char *colormapName; |
| 114 |
|
| 115 |
|
| 116 |
char *menuName; |
| 117 |
|
| 118 |
Colormap colormap; |
| 119 |
|
| 120 |
|
| 121 |
Tk_3DBorder border; |
| 122 |
|
| 123 |
|
| 124 |
int borderWidth; |
| 125 |
int relief; |
| 126 |
int highlightWidth; |
| 127 |
|
| 128 |
|
| 129 |
XColor *highlightBgColorPtr; |
| 130 |
|
| 131 |
|
| 132 |
XColor *highlightColorPtr; |
| 133 |
int width; |
| 134 |
|
| 135 |
int height; |
| 136 |
|
| 137 |
Tk_Cursor cursor; |
| 138 |
char *takeFocus; |
| 139 |
|
| 140 |
|
| 141 |
int isContainer; |
| 142 |
|
| 143 |
char *useThis; |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
int flags; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
TreeView *tvPtr; |
| 152 |
int x, y; |
| 153 |
|
| 154 |
int active; |
| 155 |
int exportSelection; |
| 156 |
|
| 157 |
int insertPos; |
| 158 |
|
| 159 |
|
| 160 |
int cursorX, cursorY; |
| 161 |
|
| 162 |
short int cursorWidth; |
| 163 |
short int cursorHeight; |
| 164 |
|
| 165 |
int selAnchor; |
| 166 |
|
| 167 |
|
| 168 |
int selFirst; |
| 169 |
|
| 170 |
int selLast; |
| 171 |
|
| 172 |
|
| 173 |
int cursorOn; |
| 174 |
int onTime, offTime; |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
Tcl_TimerToken timerToken; |
| 179 |
|
| 180 |
|
| 181 |
TreeViewEntry *entryPtr; |
| 182 |
TreeViewColumn *columnPtr; |
| 183 |
TreeViewStyle *stylePtr; |
| 184 |
TreeViewIcon icon; |
| 185 |
int gap; |
| 186 |
char *string; |
| 187 |
TextLayout *textPtr; |
| 188 |
Tk_Font font; |
| 189 |
GC gc; |
| 190 |
|
| 191 |
Tk_3DBorder selBorder; |
| 192 |
int selRelief; |
| 193 |
int selBorderWidth; |
| 194 |
XColor *selFgColor; |
| 195 |
int buttonBorderWidth; |
| 196 |
Tk_3DBorder buttonBorder; |
| 197 |
int buttonRelief; |
| 198 |
} Textbox; |
| 199 |
|
| 200 |
#define DEF_TEXTBOX_BACKGROUND RGB_WHITE |
| 201 |
#define DEF_TEXTBOX_BORDERWIDTH STD_BORDERWIDTH |
| 202 |
#ifdef WIN32 |
| 203 |
#define DEF_TEXTBOX_BUTTON_BACKGROUND RGB_GREY85 |
| 204 |
#else |
| 205 |
#define DEF_TEXTBOX_BUTTON_BACKGROUND RGB_GREY90 |
| 206 |
#endif |
| 207 |
#define DEF_TEXTBOX_BUTTON_BORDERWIDTH "2" |
| 208 |
#define DEF_TEXTBOX_BUTTON_RELIEF "raised" |
| 209 |
#define DEF_TEXTBOX_CURSOR (char *)NULL |
| 210 |
#define DEF_TEXTBOX_EXPORT_SELECTION "no" |
| 211 |
#define DEF_TEXTBOX_NORMAL_BACKGROUND STD_NORMAL_BACKGROUND |
| 212 |
#define DEF_TEXTBOX_NORMAL_FG_MONO STD_ACTIVE_FG_MONO |
| 213 |
#define DEF_TEXTBOX_RELIEF "sunken" |
| 214 |
#define DEF_TEXTBOX_SELECT_BACKGROUND RGB_LIGHTBLUE0 |
| 215 |
#define DEF_TEXTBOX_SELECT_BG_MONO STD_SELECT_BG_MONO |
| 216 |
#define DEF_TEXTBOX_SELECT_BORDERWIDTH "1" |
| 217 |
#define DEF_TEXTBOX_SELECT_FOREGROUND STD_SELECT_FOREGROUND |
| 218 |
#define DEF_TEXTBOX_SELECT_FG_MONO STD_SELECT_FG_MONO |
| 219 |
#define DEF_TEXTBOX_SELECT_RELIEF "flat" |
| 220 |
|
| 221 |
|
| 222 |
static Blt_ConfigSpec textboxConfigSpecs[] = |
| 223 |
{ |
| 224 |
{BLT_CONFIG_BORDER, "-background", "background", "Background", |
| 225 |
DEF_TEXTBOX_BACKGROUND, Blt_Offset(Textbox, border), 0}, |
| 226 |
{BLT_CONFIG_SYNONYM, "-bd", (char *)NULL, (char *)NULL, (char *)NULL, 0,0, (ClientData)"-borderwidth"}, |
| 227 |
{BLT_CONFIG_SYNONYM, "-bg", (char *)NULL, (char *)NULL, (char *)NULL, 0,0, (ClientData)"-background"}, |
| 228 |
{BLT_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor", |
| 229 |
DEF_TEXTBOX_CURSOR, Blt_Offset(Textbox, cursor), |
| 230 |
BLT_CONFIG_NULL_OK}, |
| 231 |
{BLT_CONFIG_DISTANCE, "-borderwidth", "borderWidth", "BorderWidth", |
| 232 |
DEF_TEXTBOX_BORDERWIDTH, Blt_Offset(Textbox, borderWidth), |
| 233 |
BLT_CONFIG_DONT_SET_DEFAULT}, |
| 234 |
{BLT_CONFIG_BORDER, "-buttonbackground", "buttonBackground", |
| 235 |
"ButtonBackground", DEF_TEXTBOX_BUTTON_BACKGROUND, |
| 236 |
Blt_Offset(Textbox, buttonBorder), 0}, |
| 237 |
{BLT_CONFIG_RELIEF, "-buttonrelief", "buttonRelief", "ButtonRelief", |
| 238 |
DEF_TEXTBOX_BUTTON_RELIEF, Blt_Offset(Textbox, buttonRelief), |
| 239 |
BLT_CONFIG_DONT_SET_DEFAULT}, |
| 240 |
{BLT_CONFIG_DISTANCE, "-buttonborderwidth", "buttonBorderWidth", |
| 241 |
"ButtonBorderWidth", DEF_TEXTBOX_BUTTON_BORDERWIDTH, |
| 242 |
Blt_Offset(Textbox, buttonBorderWidth), |
| 243 |
BLT_CONFIG_DONT_SET_DEFAULT}, |
| 244 |
{BLT_CONFIG_BOOLEAN, "-exportselection", "exportSelection", |
| 245 |
"ExportSelection", DEF_TEXTBOX_EXPORT_SELECTION, |
| 246 |
Blt_Offset(Textbox, exportSelection), |
| 247 |
BLT_CONFIG_DONT_SET_DEFAULT}, |
| 248 |
{BLT_CONFIG_RELIEF, "-relief", "relief", "Relief", |
| 249 |
DEF_TEXTBOX_RELIEF, Blt_Offset(Textbox, relief), 0}, |
| 250 |
{BLT_CONFIG_BORDER, "-selectbackground", "selectBackground", "Background", |
| 251 |
DEF_TEXTBOX_SELECT_BG_MONO, Blt_Offset(Textbox, selBorder), |
| 252 |
BLT_CONFIG_MONO_ONLY}, |
| 253 |
{BLT_CONFIG_BORDER, "-selectbackground", "selectBackground", "Background", |
| 254 |
DEF_TEXTBOX_SELECT_BACKGROUND, Blt_Offset(Textbox, selBorder), |
| 255 |
BLT_CONFIG_COLOR_ONLY}, |
| 256 |
{BLT_CONFIG_DISTANCE, "-selectborderwidth", "selectBorderWidth", |
| 257 |
"BorderWidth", DEF_TEXTBOX_SELECT_BORDERWIDTH, |
| 258 |
Blt_Offset(Textbox, selBorderWidth), |
| 259 |
BLT_CONFIG_DONT_SET_DEFAULT}, |
| 260 |
{BLT_CONFIG_COLOR, "-selectforeground", "selectForeground", "Foreground", |
| 261 |
|
| 262 |
DEF_TEXTBOX_SELECT_FG_MONO, Blt_Offset(Textbox, selFgColor), |
| 263 |
BLT_CONFIG_MONO_ONLY}, |
| 264 |
{BLT_CONFIG_COLOR, "-selectforeground", "selectForeground", "Foreground", |
| 265 |
DEF_TEXTBOX_SELECT_FOREGROUND, Blt_Offset(Textbox, selFgColor), |
| 266 |
BLT_CONFIG_COLOR_ONLY}, |
| 267 |
{BLT_CONFIG_RELIEF, "-selectrelief", "selectRelief", "Relief", |
| 268 |
DEF_TEXTBOX_SELECT_RELIEF, Blt_Offset(Textbox, selRelief), |
| 269 |
BLT_CONFIG_DONT_SET_DEFAULT}, |
| 270 |
{BLT_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL, (char *)NULL, |
| 271 |
0, 0} |
| 272 |
}; |
| 273 |
|
| 274 |
static Tk_LostSelProc TextboxLostSelectionProc; |
| 275 |
static Tk_SelectionProc TextboxSelectionProc; |
| 276 |
static Tk_EventProc TextboxEventProc; |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
static void |
| 295 |
EventuallyRedraw(tbPtr) |
| 296 |
Textbox *tbPtr; |
| 297 |
{ |
| 298 |
if ((tbPtr->tkwin != NULL) && |
| 299 |
((tbPtr->flags & TEXTBOX_REDRAW) == 0)) { |
| 300 |
tbPtr->flags |= TEXTBOX_REDRAW; |
| 301 |
Tcl_DoWhenIdle(DisplayTextbox, tbPtr); |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
static void |
| 323 |
BlinkCursorProc(clientData) |
| 324 |
ClientData clientData; |
| 325 |
{ |
| 326 |
Textbox *tbPtr = clientData; |
| 327 |
int interval; |
| 328 |
|
| 329 |
if (!(tbPtr->flags & TEXTBOX_FOCUS) || (tbPtr->offTime == 0)) { |
| 330 |
return; |
| 331 |
} |
| 332 |
if (tbPtr->active) { |
| 333 |
tbPtr->cursorOn ^= 1; |
| 334 |
interval = (tbPtr->cursorOn) ? tbPtr->onTime : tbPtr->offTime; |
| 335 |
tbPtr->timerToken = |
| 336 |
Tcl_CreateTimerHandler(interval, BlinkCursorProc, tbPtr); |
| 337 |
EventuallyRedraw(tbPtr); |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
static void |
| 359 |
TextboxEventProc(clientData, eventPtr) |
| 360 |
ClientData clientData; |
| 361 |
XEvent *eventPtr; |
| 362 |
{ |
| 363 |
Textbox *tbPtr = clientData; |
| 364 |
|
| 365 |
if (eventPtr->type == Expose) { |
| 366 |
if (eventPtr->xexpose.count == 0) { |
| 367 |
EventuallyRedraw(tbPtr); |
| 368 |
} |
| 369 |
} else if (eventPtr->type == ConfigureNotify) { |
| 370 |
EventuallyRedraw(tbPtr); |
| 371 |
} else if ((eventPtr->type == FocusIn) || (eventPtr->type == FocusOut)) { |
| 372 |
if (eventPtr->xfocus.detail == NotifyInferior) { |
| 373 |
return; |
| 374 |
} |
| 375 |
if (eventPtr->type == FocusIn) { |
| 376 |
tbPtr->flags |= TEXTBOX_FOCUS; |
| 377 |
} else { |
| 378 |
tbPtr->flags &= ~TEXTBOX_FOCUS; |
| 379 |
} |
| 380 |
Tcl_DeleteTimerHandler(tbPtr->timerToken); |
| 381 |
if ((tbPtr->active) && (tbPtr->flags & TEXTBOX_FOCUS)) { |
| 382 |
tbPtr->cursorOn = TRUE; |
| 383 |
if (tbPtr->offTime != 0) { |
| 384 |
tbPtr->timerToken = Tcl_CreateTimerHandler(tbPtr->onTime, |
| 385 |
BlinkCursorProc, tbPtr); |
| 386 |
} |
| 387 |
} else { |
| 388 |
tbPtr->cursorOn = FALSE; |
| 389 |
tbPtr->timerToken = (Tcl_TimerToken) NULL; |
| 390 |
} |
| 391 |
EventuallyRedraw(tbPtr); |
| 392 |
} else if (eventPtr->type == DestroyNotify) { |
| 393 |
if (tbPtr->tkwin != NULL) { |
| 394 |
tbPtr->tkwin = NULL; |
| 395 |
} |
| 396 |
if (tbPtr->flags & TEXTBOX_REDRAW) { |
| 397 |
Tcl_CancelIdleCall(DisplayTextbox, tbPtr); |
| 398 |
} |
| 399 |
if (tbPtr->timerToken != NULL) { |
| 400 |
Tcl_DeleteTimerHandler(tbPtr->timerToken); |
| 401 |
} |
| 402 |
tbPtr->tvPtr->comboWin = NULL; |
| 403 |
Tcl_EventuallyFree(tbPtr, DestroyTextbox); |
| 404 |
} |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
static void |
| 425 |
TextboxLostSelectionProc(clientData) |
| 426 |
ClientData clientData; |
| 427 |
{ |
| 428 |
Textbox *tbPtr = clientData; |
| 429 |
|
| 430 |
if ((tbPtr->selFirst >= 0) && (tbPtr->exportSelection)) { |
| 431 |
tbPtr->selFirst = tbPtr->selLast = -1; |
| 432 |
EventuallyRedraw(tbPtr); |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
static int |
| 437 |
PointerToIndex(tbPtr, x, y) |
| 438 |
Textbox *tbPtr; |
| 439 |
int x, y; |
| 440 |
{ |
| 441 |
TextLayout *textPtr; |
| 442 |
Tk_FontMetrics fontMetrics; |
| 443 |
TextFragment *fragPtr; |
| 444 |
int nBytes; |
| 445 |
register int i; |
| 446 |
int total; |
| 447 |
|
| 448 |
if ((tbPtr->string == NULL) || (tbPtr->string[0] == '\0')) { |
| 449 |
return 0; |
| 450 |
} |
| 451 |
x -= tbPtr->selBorderWidth; |
| 452 |
y -= tbPtr->selBorderWidth; |
| 453 |
|
| 454 |
textPtr = tbPtr->textPtr; |
| 455 |
|
| 456 |
|
| 457 |
if (y < 0) { |
| 458 |
y = 0; |
| 459 |
} else if (y >= textPtr->height) { |
| 460 |
y = textPtr->height - 1; |
| 461 |
} |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
Tk_GetFontMetrics(tbPtr->font, &fontMetrics); |
| 469 |
fragPtr = textPtr->fragArr; |
| 470 |
total = 0; |
| 471 |
for (i = (y / fontMetrics.linespace); i > 0; i--) { |
| 472 |
total += fragPtr->count; |
| 473 |
fragPtr++; |
| 474 |
} |
| 475 |
if (x < 0) { |
| 476 |
nBytes = 0; |
| 477 |
} else if (x >= textPtr->width) { |
| 478 |
nBytes = fragPtr->count; |
| 479 |
} else { |
| 480 |
int newX; |
| 481 |
|
| 482 |
|
| 483 |
nBytes = Tk_MeasureChars(tbPtr->font, fragPtr->text, fragPtr->count, |
| 484 |
x, 0, &newX); |
| 485 |
if ((newX < x) && (nBytes < fragPtr->count)) { |
| 486 |
double fract; |
| 487 |
int length, charSize; |
| 488 |
char *next; |
| 489 |
|
| 490 |
next = fragPtr->text + nBytes; |
| 491 |
#if HAVE_UTF |
| 492 |
{ |
| 493 |
Tcl_UniChar dummy; |
| 494 |
|
| 495 |
length = Tcl_UtfToUniChar(next, &dummy); |
| 496 |
} |
| 497 |
#else |
| 498 |
length = 1; |
| 499 |
#endif |
| 500 |
charSize = Tk_TextWidth(tbPtr->font, next, length); |
| 501 |
fract = ((double)(x - newX) / (double)charSize); |
| 502 |
if (ROUND(fract)) { |
| 503 |
nBytes += length; |
| 504 |
} |
| 505 |
} |
| 506 |
} |
| 507 |
return nBytes + total; |
| 508 |
} |
| 509 |
|
| 510 |
static int |
| 511 |
IndexToPointer(tbPtr) |
| 512 |
Textbox *tbPtr; |
| 513 |
{ |
| 514 |
int x, y; |
| 515 |
int maxLines; |
| 516 |
TextLayout *textPtr; |
| 517 |
Tk_FontMetrics fontMetrics; |
| 518 |
int nBytes; |
| 519 |
int sum; |
| 520 |
TextFragment *fragPtr; |
| 521 |
register int i; |
| 522 |
|
| 523 |
textPtr = tbPtr->textPtr; |
| 524 |
Tk_GetFontMetrics(tbPtr->font, &fontMetrics); |
| 525 |
maxLines = (textPtr->height / fontMetrics.linespace) - 1; |
| 526 |
|
| 527 |
sum = 0; |
| 528 |
x = y = tbPtr->borderWidth; |
| 529 |
if (tbPtr->icon != NULL) { |
| 530 |
x += TreeViewIconWidth(tbPtr->icon) + 2 * tbPtr->gap; |
| 531 |
} |
| 532 |
fragPtr = textPtr->fragArr; |
| 533 |
for (i = 0; i <= maxLines; i++) { |
| 534 |
|
| 535 |
nBytes = fragPtr->count + 1; |
| 536 |
if ((sum + nBytes) > tbPtr->insertPos) { |
| 537 |
x += Tk_TextWidth(tbPtr->font, fragPtr->text, |
| 538 |
tbPtr->insertPos - sum); |
| 539 |
break; |
| 540 |
} |
| 541 |
y += fontMetrics.linespace; |
| 542 |
sum += nBytes; |
| 543 |
fragPtr++; |
| 544 |
} |
| 545 |
tbPtr->cursorX = x; |
| 546 |
tbPtr->cursorY = y; |
| 547 |
tbPtr->cursorHeight = fontMetrics.linespace; |
| 548 |
tbPtr->cursorWidth = 3; |
| 549 |
return TCL_OK; |
| 550 |
} |
| 551 |
|
| 552 |
static void |
| 553 |
UpdateLayout(tbPtr) |
| 554 |
Textbox *tbPtr; |
| 555 |
{ |
| 556 |
TextStyle ts; |
| 557 |
int width, height; |
| 558 |
TextLayout *textPtr; |
| 559 |
int gap; |
| 560 |
int iconWidth, iconHeight; |
| 561 |
|
| 562 |
gap = iconWidth = iconHeight = 0; |
| 563 |
if (tbPtr->icon != NULL) { |
| 564 |
iconWidth = TreeViewIconWidth(tbPtr->icon) + 4; |
| 565 |
iconHeight = TreeViewIconHeight(tbPtr->icon); |
| 566 |
gap = tbPtr->gap; |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
Blt_InitTextStyle(&ts); |
| 571 |
ts.anchor = TK_ANCHOR_NW; |
| 572 |
ts.justify = TK_JUSTIFY_LEFT; |
| 573 |
ts.font = tbPtr->font; |
| 574 |
textPtr = Blt_GetTextLayout(tbPtr->string, &ts); |
| 575 |
if (tbPtr->textPtr != NULL) { |
| 576 |
Blt_Free(tbPtr->textPtr); |
| 577 |
} |
| 578 |
tbPtr->textPtr = textPtr; |
| 579 |
|
| 580 |
width = iconWidth + textPtr->width + gap * 2; |
| 581 |
height = MAX(iconHeight, textPtr->height); |
| 582 |
|
| 583 |
if (width <= tbPtr->columnPtr->width) { |
| 584 |
width = tbPtr->columnPtr->width; |
| 585 |
} |
| 586 |
if (height < tbPtr->entryPtr->height) { |
| 587 |
height = tbPtr->entryPtr->height; |
| 588 |
} |
| 589 |
tbPtr->width = width + (2 * tbPtr->borderWidth); |
| 590 |
tbPtr->height = height + (2 * tbPtr->borderWidth); |
| 591 |
IndexToPointer(tbPtr); |
| 592 |
Tk_MoveResizeWindow(tbPtr->tkwin, tbPtr->x, tbPtr->y, |
| 593 |
tbPtr->width, tbPtr->height); |
| 594 |
Tk_MapWindow(tbPtr->tkwin); |
| 595 |
XRaiseWindow(tbPtr->display, Tk_WindowId(tbPtr->tkwin)); |
| 596 |
} |
| 597 |
|
| 598 |
static void |
| 599 |
InsertText(tbPtr, insertText, insertPos, nBytes) |
| 600 |
Textbox *tbPtr; |
| 601 |
char *insertText; |
| 602 |
int insertPos; |
| 603 |
int nBytes; |
| 604 |
{ |
| 605 |
int oldSize, newSize; |
| 606 |
char *oldText, *newText; |
| 607 |
|
| 608 |
oldText = tbPtr->string; |
| 609 |
oldSize = strlen(oldText); |
| 610 |
newSize = oldSize + nBytes; |
| 611 |
newText = Blt_Malloc(sizeof(char) * (newSize + 1)); |
| 612 |
if (insertPos == oldSize) { |
| 613 |
strcpy(newText, oldText); |
| 614 |
strcat(newText, insertText); |
| 615 |
} else if (insertPos == 0) { |
| 616 |
strcpy(newText, insertText); |
| 617 |
strcat(newText, oldText); |
| 618 |
} else { |
| 619 |
char *p; |
| 620 |
|
| 621 |
p = newText; |
| 622 |
strncpy(p, oldText, insertPos); |
| 623 |
p += insertPos; |
| 624 |
strcpy(p, insertText); |
| 625 |
p += nBytes; |
| 626 |
strcpy(p, oldText + insertPos); |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
if (tbPtr->selFirst >= insertPos) { |
| 635 |
tbPtr->selFirst += nBytes; |
| 636 |
} |
| 637 |
if (tbPtr->selLast > insertPos) { |
| 638 |
tbPtr->selLast += nBytes; |
| 639 |
} |
| 640 |
if ((tbPtr->selAnchor > insertPos) || (tbPtr->selFirst >= insertPos)) { |
| 641 |
tbPtr->selAnchor += nBytes; |
| 642 |
} |
| 643 |
if (tbPtr->string != NULL) { |
| 644 |
Blt_Free(tbPtr->string); |
| 645 |
} |
| 646 |
tbPtr->string = newText; |
| 647 |
tbPtr->insertPos = insertPos + nBytes; |
| 648 |
UpdateLayout(tbPtr); |
| 649 |
} |
| 650 |
|
| 651 |
static int |
| 652 |
DeleteText(tbPtr, firstPos, lastPos) |
| 653 |
Textbox *tbPtr; |
| 654 |
int firstPos, lastPos; |
| 655 |
{ |
| 656 |
char *oldText, *newText; |
| 657 |
int oldSize, newSize; |
| 658 |
int nBytes; |
| 659 |
char *p; |
| 660 |
|
| 661 |
oldText = tbPtr->string; |
| 662 |
if (firstPos > lastPos) { |
| 663 |
return TCL_OK; |
| 664 |
} |
| 665 |
lastPos++; |
| 666 |
|
| 667 |
|
| 668 |
nBytes = lastPos - firstPos; |
| 669 |
|
| 670 |
oldSize = strlen(oldText) + 1; |
| 671 |
newSize = oldSize - nBytes + 1; |
| 672 |
newText = Blt_Malloc(sizeof(char) * newSize); |
| 673 |
p = newText; |
| 674 |
if (firstPos > 0) { |
| 675 |
strncpy(p, oldText, firstPos); |
| 676 |
p += firstPos; |
| 677 |
} |
| 678 |
*p = '\0'; |
| 679 |
if (lastPos < oldSize) { |
| 680 |
strcpy(p, oldText + lastPos); |
| 681 |
} |
| 682 |
Blt_Free(oldText); |
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
if (tbPtr->selFirst >= firstPos) { |
| 697 |
if (tbPtr->selFirst >= lastPos) { |
| 698 |
tbPtr->selFirst -= nBytes; |
| 699 |
} else { |
| 700 |
tbPtr->selFirst = firstPos; |
| 701 |
} |
| 702 |
} |
| 703 |
if (tbPtr->selLast >= firstPos) { |
| 704 |
if (tbPtr->selLast >= lastPos) { |
| 705 |
tbPtr->selLast -= nBytes; |
| 706 |
} else { |
| 707 |
tbPtr->selLast = firstPos; |
| 708 |
} |
| 709 |
} |
| 710 |
if (tbPtr->selLast <= tbPtr->selFirst) { |
| 711 |
tbPtr->selFirst = tbPtr->selLast = -1; |
| 712 |
|
| 713 |
} |
| 714 |
if (tbPtr->selAnchor >= firstPos) { |
| 715 |
if (tbPtr->selAnchor >= lastPos) { |
| 716 |
tbPtr->selAnchor -= nBytes; |
| 717 |
} else { |
| 718 |
tbPtr->selAnchor = firstPos; |
| 719 |
} |
| 720 |
} |
| 721 |
if (tbPtr->insertPos >= firstPos) { |
| 722 |
if (tbPtr->insertPos >= lastPos) { |
| 723 |
tbPtr->insertPos -= nBytes; |
| 724 |
} else { |
| 725 |
tbPtr->insertPos = firstPos; |
| 726 |
} |
| 727 |
} |
| 728 |
tbPtr->string = newText; |
| 729 |
UpdateLayout(tbPtr); |
| 730 |
EventuallyRedraw(tbPtr); |
| 731 |
return TCL_OK; |
| 732 |
} |
| 733 |
|
| 734 |
static int |
| 735 |
AcquireText(tvPtr, tbPtr, entryPtr, columnPtr) |
| 736 |
TreeView *tvPtr; |
| 737 |
Textbox *tbPtr; |
| 738 |
TreeViewEntry *entryPtr; |
| 739 |
TreeViewColumn *columnPtr; |
| 740 |
{ |
| 741 |
TreeViewStyle *stylePtr; |
| 742 |
int x, y; |
| 743 |
char *string; |
| 744 |
TreeViewIcon icon; |
| 745 |
|
| 746 |
if (columnPtr == &tvPtr->treeColumn) { |
| 747 |
int level; |
| 748 |
|
| 749 |
level = DEPTH(tvPtr, entryPtr->node); |
| 750 |
x = SCREENX(tvPtr, entryPtr->worldX); |
| 751 |
y = SCREENY(tvPtr, entryPtr->worldY); |
| 752 |
x += ICONWIDTH(level) + ICONWIDTH(level + 1) + 4; |
| 753 |
string = GETLABEL(entryPtr); |
| 754 |
stylePtr = columnPtr->stylePtr; |
| 755 |
icon = Blt_TreeViewGetEntryIcon(tvPtr, entryPtr); |
| 756 |
} else { |
| 757 |
TreeViewValue *valuePtr; |
| 758 |
|
| 759 |
x = SCREENX(tvPtr, columnPtr->worldX); |
| 760 |
y = SCREENY(tvPtr, entryPtr->worldY); |
| 761 |
stylePtr = columnPtr->stylePtr; |
| 762 |
valuePtr = Blt_TreeViewFindValue(entryPtr, columnPtr); |
| 763 |
string = valuePtr->string; |
| 764 |
if (valuePtr->stylePtr != NULL) { |
| 765 |
stylePtr = valuePtr->stylePtr; |
| 766 |
} |
| 767 |
icon = stylePtr->icon; |
| 768 |
} |
| 769 |
if (tbPtr->textPtr != NULL) { |
| 770 |
Blt_Free(tbPtr->textPtr); |
| 771 |
tbPtr->textPtr = NULL; |
| 772 |
} |
| 773 |
if (tbPtr->string != NULL) { |
| 774 |
Blt_Free(tbPtr->string); |
| 775 |
} |
| 776 |
if (string == NULL) { |
| 777 |
string = ""; |
| 778 |
} |
| 779 |
tbPtr->icon = icon; |
| 780 |
tbPtr->entryPtr = entryPtr; |
| 781 |
tbPtr->columnPtr = columnPtr; |
| 782 |
tbPtr->x = x - tbPtr->borderWidth; |
| 783 |
tbPtr->y = y - tbPtr->borderWidth; |
| 784 |
|
| 785 |
tbPtr->gap = stylePtr->gap; |
| 786 |
tbPtr->string = Blt_Strdup(string); |
| 787 |
tbPtr->gc = Blt_TreeViewGetStyleGC(tvPtr, stylePtr); |
| 788 |
tbPtr->font = Blt_TreeViewGetStyleFont(tvPtr, columnPtr, stylePtr); |
| 789 |
tbPtr->selFirst = tbPtr->selLast = -1; |
| 790 |
UpdateLayout(tbPtr); |
| 791 |
Tk_MapWindow(tbPtr->tkwin); |
| 792 |
EventuallyRedraw(tbPtr); |
| 793 |
return TCL_OK; |
| 794 |
} |
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
static int |
| 818 |
GetIndexFromObj(interp, tbPtr, objPtr, indexPtr) |
| 819 |
Tcl_Interp *interp; |
| 820 |
Textbox *tbPtr; |
| 821 |
Tcl_Obj *objPtr; |
| 822 |
int *indexPtr; |
| 823 |
{ |
| 824 |
int textPos; |
| 825 |
char c; |
| 826 |
char *string; |
| 827 |
|
| 828 |
string = Tcl_GetString(objPtr); |
| 829 |
if ((tbPtr->string == NULL) || (tbPtr->string[0] == '\0')) { |
| 830 |
*indexPtr = 0; |
| 831 |
return TCL_OK; |
| 832 |
} |
| 833 |
c = string[0]; |
| 834 |
if ((c == 'a') && (strcmp(string, "anchor") == 0)) { |
| 835 |
textPos = tbPtr->selAnchor; |
| 836 |
} else if ((c == 'e') && (strcmp(string, "end") == 0)) { |
| 837 |
textPos = strlen(tbPtr->string); |
| 838 |
} else if ((c == 'i') && (strcmp(string, "insert") == 0)) { |
| 839 |
textPos = tbPtr->insertPos; |
| 840 |
} else if ((c == 'n') && (strcmp(string, "next") == 0)) { |
| 841 |
textPos = tbPtr->insertPos; |
| 842 |
if (textPos < (int)strlen(tbPtr->string)) { |
| 843 |
textPos++; |
| 844 |
} |
| 845 |
} else if ((c == 'l') && (strcmp(string, "last") == 0)) { |
| 846 |
textPos = tbPtr->insertPos; |
| 847 |
if (textPos > 0) { |
| 848 |
textPos--; |
| 849 |
} |
| 850 |
} else if ((c == 's') && (strcmp(string, "sel.first") == 0)) { |
| 851 |
if (tbPtr->selFirst < 0) { |
| 852 |
textPos = -1; |
| 853 |
} else { |
| 854 |
textPos = tbPtr->selFirst; |
| 855 |
} |
| 856 |
} else if ((c == 's') && (strcmp(string, "sel.last") == 0)) { |
| 857 |
if (tbPtr->selLast < 0) { |
| 858 |
textPos = -1; |
| 859 |
} else { |
| 860 |
textPos = tbPtr->selLast; |
| 861 |
} |
| 862 |
} else if (c == '@') { |
| 863 |
int x, y; |
| 864 |
|
| 865 |
if (Blt_GetXY(interp, tbPtr->tkwin, string, &x, &y) != TCL_OK) { |
| 866 |
return TCL_ERROR; |
| 867 |
} |
| 868 |
textPos = PointerToIndex(tbPtr, x, y); |
| 869 |
} else if (isdigit((int)c)) { |
| 870 |
int number; |
| 871 |
int maxChars; |
| 872 |
|
| 873 |
if (Tcl_GetIntFromObj(interp, objPtr, &number) != TCL_OK) { |
| 874 |
return TCL_ERROR; |
| 875 |
} |
| 876 |
|
| 877 |
maxChars = Tcl_NumUtfChars(tbPtr->string, -1); |
| 878 |
if (number < 0) { |
| 879 |
textPos = 0; |
| 880 |
} else if (number > maxChars) { |
| 881 |
textPos = strlen(tbPtr->string); |
| 882 |
} else { |
| 883 |
textPos = Tcl_UtfAtIndex(tbPtr->string, number) - |
| 884 |
tbPtr->string; |
| 885 |
} |
| 886 |
} else { |
| 887 |
if (interp != NULL) { |
| 888 |
Tcl_AppendResult(interp, "bad label index \"", string, "\"", |
| 889 |
(char *)NULL); |
| 890 |
} |
| 891 |
return TCL_ERROR; |
| 892 |
} |
| 893 |
*indexPtr = textPos; |
| 894 |
return TCL_OK; |
| 895 |
} |
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
static int |
| 914 |
SelectText(tbPtr, textPos) |
| 915 |
Textbox *tbPtr; |
| 916 |
int textPos; |
| 917 |
|
| 918 |
|
| 919 |
{ |
| 920 |
int selFirst, selLast; |
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
if ((tbPtr->exportSelection) && (tbPtr->selFirst == -1)) { |
| 926 |
Tk_OwnSelection(tbPtr->tkwin, XA_PRIMARY, |
| 927 |
TextboxLostSelectionProc, tbPtr); |
| 928 |
} |
| 929 |
|
| 930 |
if (tbPtr->selAnchor < 0) { |
| 931 |
tbPtr->selAnchor = 0; |
| 932 |
} |
| 933 |
if (tbPtr->selAnchor <= textPos) { |
| 934 |
selFirst = tbPtr->selAnchor; |
| 935 |
selLast = textPos; |
| 936 |
} else { |
| 937 |
selFirst = textPos; |
| 938 |
selLast = tbPtr->selAnchor; |
| 939 |
} |
| 940 |
if ((tbPtr->selFirst != selFirst) || (tbPtr->selLast != selLast)) { |
| 941 |
tbPtr->selFirst = selFirst; |
| 942 |
tbPtr->selLast = selLast; |
| 943 |
EventuallyRedraw(tbPtr); |
| 944 |
} |
| 945 |
return TCL_OK; |
| 946 |
} |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
static int |
| 969 |
TextboxSelectionProc(clientData, offset, buffer, maxBytes) |
| 970 |
ClientData clientData; |
| 971 |
int offset; |
| 972 |
|
| 973 |
char *buffer; |
| 974 |
|
| 975 |
int maxBytes; |
| 976 |
|
| 977 |
|
| 978 |
{ |
| 979 |
Textbox *tbPtr = clientData; |
| 980 |
int size; |
| 981 |
|
| 982 |
size = strlen(tbPtr->string + offset); |
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
strncpy(buffer, tbPtr->string + offset, maxBytes); |
| 987 |
buffer[maxBytes] = '\0'; |
| 988 |
return (size > maxBytes) ? maxBytes : size; |
| 989 |
} |
| 990 |
|
| 991 |
|
| 992 |
static void |
| 993 |
DestroyTextbox(data) |
| 994 |
DestroyData data; |
| 995 |
{ |
| 996 |
Textbox *tbPtr = (Textbox *)data; |
| 997 |
|
| 998 |
Blt_FreeObjOptions(tbPtr->interp, textboxConfigSpecs, (char *)tbPtr, |
| 999 |
tbPtr->display, 0); |
| 1000 |
|
| 1001 |
if (tbPtr->string != NULL) { |
| 1002 |
Blt_Free(tbPtr->string); |
| 1003 |
} |
| 1004 |
if (tbPtr->textPtr != NULL) { |
| 1005 |
Blt_Free(tbPtr->textPtr); |
| 1006 |
} |
| 1007 |
if (tbPtr->timerToken != NULL) { |
| 1008 |
Tcl_DeleteTimerHandler(tbPtr->timerToken); |
| 1009 |
} |
| 1010 |
if (tbPtr->tkwin != NULL) { |
| 1011 |
Tk_DeleteSelHandler(tbPtr->tkwin, XA_PRIMARY, XA_STRING); |
| 1012 |
} |
| 1013 |
Blt_Free(tbPtr); |
| 1014 |
} |
| 1015 |
|
| 1016 |
static void |
| 1017 |
ConfigureTextbox(tbPtr) |
| 1018 |
Textbox *tbPtr; |
| 1019 |
{ |
| 1020 |
#ifdef notdef |
| 1021 |
GC newGC; |
| 1022 |
Textbox *tbPtr = tvPtr->tbPtr; |
| 1023 |
XGCValues gcValues; |
| 1024 |
unsigned long gcMask; |
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
gcMask = 0; |
| 1030 |
newGC = Tk_GetGC(tbPtr->tkwin, gcMask, &gcValues); |
| 1031 |
if (tbPtr->gc != NULL) { |
| 1032 |
Tk_FreeGC(tbPtr->display, tbPtr->gc); |
| 1033 |
} |
| 1034 |
tbPtr->gc = newGC; |
| 1035 |
tbPtr->width = tbPtr->textPtr->width + |
| 1036 |
2 * (tbPtr->borderWidth + tbPtr->highlightWidth); |
| 1037 |
tbPtr->height = tbPtr->textPtr->height + |
| 1038 |
2 * (tbPtr->borderWidth + tbPtr->highlightWidth); |
| 1039 |
|
| 1040 |
if (Tk_IsMapped(tbPtr->tkwin)) { |
| 1041 |
if ((tbPtr->height != Tk_Height(tbPtr->tkwin)) || |
| 1042 |
(tbPtr->width != Tk_Width(tbPtr->tkwin))) { |
| 1043 |
Tk_ResizeWindow(tbPtr->tkwin, tbPtr->width, tbPtr->height); |
| 1044 |
} |
| 1045 |
} |
| 1046 |
#endif |
| 1047 |
} |
| 1048 |
|
| 1049 |
int |
| 1050 |
Blt_TreeViewTextbox(tvPtr, entryPtr, columnPtr) |
| 1051 |
TreeView *tvPtr; |
| 1052 |
TreeViewEntry *entryPtr; |
| 1053 |
TreeViewColumn *columnPtr; |
| 1054 |
{ |
| 1055 |
Tk_Window tkwin; |
| 1056 |
Textbox *tbPtr; |
| 1057 |
char editClass[20]; |
| 1058 |
|
| 1059 |
if (tvPtr->comboWin != NULL) { |
| 1060 |
Tk_DestroyWindow(tvPtr->comboWin); |
| 1061 |
} |
| 1062 |
tkwin = Tk_CreateWindow(tvPtr->interp, tvPtr->tkwin, "edit", (char *)NULL); |
| 1063 |
if (tkwin == NULL) { |
| 1064 |
return TCL_ERROR; |
| 1065 |
} |
| 1066 |
|
| 1067 |
Tk_MakeWindowExist(tkwin); |
| 1068 |
|
| 1069 |
sprintf(editClass, "%sEditor", Tk_Class(tvPtr->tkwin)); |
| 1070 |
Tk_SetClass(tkwin, editClass); |
| 1071 |
|
| 1072 |
tbPtr = Blt_Calloc(1, sizeof(Textbox)); |
| 1073 |
assert(tbPtr); |
| 1074 |
|
| 1075 |
tbPtr->interp = tvPtr->interp; |
| 1076 |
tbPtr->display = Tk_Display(tkwin); |
| 1077 |
tbPtr->tkwin = tkwin; |
| 1078 |
tbPtr->borderWidth = 1; |
| 1079 |
tbPtr->relief = TK_RELIEF_SOLID; |
| 1080 |
tbPtr->selRelief = TK_RELIEF_FLAT; |
| 1081 |
tbPtr->selBorderWidth = 1; |
| 1082 |
tbPtr->selAnchor = -1; |
| 1083 |
tbPtr->selFirst = tbPtr->selLast = -1; |
| 1084 |
tbPtr->onTime = 600; |
| 1085 |
tbPtr->active = TRUE; |
| 1086 |
tbPtr->offTime = 300; |
| 1087 |
tbPtr->tvPtr = tvPtr; |
| 1088 |
tbPtr->buttonRelief = TK_RELIEF_SUNKEN; |
| 1089 |
tbPtr->buttonBorderWidth = 1; |
| 1090 |
tvPtr->comboWin = tkwin; |
| 1091 |
#if (TK_MAJOR_VERSION > 4) |
| 1092 |
Blt_SetWindowInstanceData(tkwin, tbPtr); |
| 1093 |
#endif |
| 1094 |
Tk_CreateSelHandler(tkwin, XA_PRIMARY, XA_STRING, |
| 1095 |
TextboxSelectionProc, tbPtr, XA_STRING); |
| 1096 |
Tk_CreateEventHandler(tkwin, ExposureMask | StructureNotifyMask | |
| 1097 |
FocusChangeMask, TextboxEventProc, tbPtr); |
| 1098 |
Tcl_CreateObjCommand(tvPtr->interp, Tk_PathName(tkwin), |
| 1099 |
TextboxCmd, tbPtr, NULL); |
| 1100 |
if (Blt_ConfigureWidgetFromObj(tvPtr->interp, tkwin, textboxConfigSpecs, 0, |
| 1101 |
(Tcl_Obj **)NULL, (char *)tbPtr, 0, NULL) != TCL_OK) { |
| 1102 |
Tk_DestroyWindow(tkwin); |
| 1103 |
return TCL_ERROR; |
| 1104 |
} |
| 1105 |
AcquireText(tvPtr, tbPtr, entryPtr, columnPtr); |
| 1106 |
tbPtr->insertPos = strlen(tbPtr->string); |
| 1107 |
|
| 1108 |
Tk_MoveResizeWindow(tkwin, tbPtr->x, tbPtr->y, tbPtr->width, |
| 1109 |
tbPtr->height); |
| 1110 |
Tk_MapWindow(tkwin); |
| 1111 |
Tk_MakeWindowExist(tkwin); |
| 1112 |
XRaiseWindow(tbPtr->display, Tk_WindowId(tkwin)); |
| 1113 |
EventuallyRedraw(tbPtr); |
| 1114 |
return TCL_OK; |
| 1115 |
} |
| 1116 |
|
| 1117 |
static void |
| 1118 |
DisplayTextbox(clientData) |
| 1119 |
ClientData clientData; |
| 1120 |
{ |
| 1121 |
Textbox *tbPtr = clientData; |
| 1122 |
Pixmap drawable; |
| 1123 |
register int i; |
| 1124 |
int x1, x2; |
| 1125 |
int count, nChars; |
| 1126 |
int leftPos, rightPos; |
| 1127 |
int selStart, selEnd, selLength; |
| 1128 |
int x, y; |
| 1129 |
TextFragment *fragPtr; |
| 1130 |
Tk_FontMetrics fontMetrics; |
| 1131 |
#ifdef notdef |
| 1132 |
int buttonX, buttonY, buttonWidth, buttonHeight; |
| 1133 |
#endif |
| 1134 |
tbPtr->flags &= ~TEXTBOX_REDRAW; |
| 1135 |
if (!Tk_IsMapped(tbPtr->tkwin)) { |
| 1136 |
return; |
| 1137 |
} |
| 1138 |
if (tbPtr->columnPtr == NULL) { |
| 1139 |
return; |
| 1140 |
} |
| 1141 |
drawable = Tk_GetPixmap(tbPtr->display, Tk_WindowId(tbPtr->tkwin), |
| 1142 |
Tk_Width(tbPtr->tkwin), Tk_Height(tbPtr->tkwin), |
| 1143 |
Tk_Depth(tbPtr->tkwin)); |
| 1144 |
|
| 1145 |
Blt_Fill3DRectangle(tbPtr->tkwin, drawable, tbPtr->border, 0, 0, |
| 1146 |
Tk_Width(tbPtr->tkwin), Tk_Height(tbPtr->tkwin), |
| 1147 |
tbPtr->borderWidth, tbPtr->relief); |
| 1148 |
|
| 1149 |
x = tbPtr->borderWidth + tbPtr->gap; |
| 1150 |
y = tbPtr->borderWidth; |
| 1151 |
|
| 1152 |
#ifdef notdef |
| 1153 |
buttonX = Tk_Width(tbPtr->tkwin) - |
| 1154 |
(tbPtr->borderWidth + tbPtr->gap + 1); |
| 1155 |
buttonY = tbPtr->borderWidth + 1; |
| 1156 |
#endif |
| 1157 |
|
| 1158 |
if (tbPtr->icon != NULL) { |
| 1159 |
y += (tbPtr->height - TreeViewIconHeight(tbPtr->icon)) / 2; |
| 1160 |
Tk_RedrawImage(TreeViewIconBits(tbPtr->icon), 0, 0, |
| 1161 |
TreeViewIconWidth(tbPtr->icon), |
| 1162 |
TreeViewIconHeight(tbPtr->icon), |
| 1163 |
drawable, x, y); |
| 1164 |
x += TreeViewIconWidth(tbPtr->icon) + tbPtr->gap; |
| 1165 |
} |
| 1166 |
|
| 1167 |
Tk_GetFontMetrics(tbPtr->font, &fontMetrics); |
| 1168 |
fragPtr = tbPtr->textPtr->fragArr; |
| 1169 |
count = 0; |
| 1170 |
y = tbPtr->borderWidth; |
| 1171 |
if (tbPtr->height > fontMetrics.linespace) { |
| 1172 |
y += (tbPtr->height - fontMetrics.linespace) / 2; |
| 1173 |
} |
| 1174 |
for (i = 0; i < tbPtr->textPtr->nFrags; i++, fragPtr++) { |
| 1175 |
leftPos = count; |
| 1176 |
count += fragPtr->count; |
| 1177 |
rightPos = count; |
| 1178 |
if ((rightPos < tbPtr->selFirst) || (leftPos > tbPtr->selLast)) { |
| 1179 |
|
| •1180 |
#ifdef TK_DRAWCHARS_ANGLE |
| 1181 |
Tk_DrawChars(tbPtr->display, drawable, tbPtr->gc, |
| 1182 |
tbPtr->font, fragPtr->text, fragPtr->count, |
| 1183 |
x + fragPtr->x, y + fragPtr->y, 0.); |
| 1184 |
#else |
| 1185 |
Tk_DrawChars(tbPtr->display, drawable, tbPtr->gc, |
| 1186 |
tbPtr->font, fragPtr->text, fragPtr->count, |
| 1187 |
x + fragPtr->x, y + fragPtr->y); |
| •1188 |
#endif |
| 1189 |
continue; |
| 1190 |
} |
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
selStart = leftPos; |
| 1201 |
selEnd = rightPos; |
| 1202 |
|
| 1203 |
if (tbPtr->selFirst > leftPos) { |
| 1204 |
selStart = tbPtr->selFirst; |
| 1205 |
} |
| 1206 |
if (tbPtr->selLast < rightPos) { |
| 1207 |
selEnd = tbPtr->selLast; |
| 1208 |
} |
| 1209 |
selLength = (selEnd - selStart); |
| 1210 |
x1 = x; |
| 1211 |
|
| 1212 |
if (selStart > leftPos) { |
| 1213 |
nChars = (selStart - leftPos); |
| 1214 |
Tk_MeasureChars(tbPtr->font, tbPtr->string + leftPos, |
| 1215 |
nChars, 10000, DEF_TEXT_FLAGS, &x1); |
| 1216 |
x1 += x; |
| 1217 |
} |
| 1218 |
if (selLength > 0) { |
| 1219 |
int width; |
| 1220 |
|
| 1221 |
Tk_MeasureChars(tbPtr->font, fragPtr->text + selStart, selLength, |
| 1222 |
10000, DEF_TEXT_FLAGS, &x2); |
| 1223 |
x2 += x; |
| 1224 |
width = (x2 - x1) + 1; |
| 1225 |
Blt_Fill3DRectangle(tbPtr->tkwin, drawable, tbPtr->selBorder, |
| 1226 |
x1, y + fragPtr->y - fontMetrics.ascent, |
| 1227 |
width, fontMetrics.linespace, |
| 1228 |
tbPtr->selBorderWidth, tbPtr->selRelief); |
| 1229 |
} |
| •1230 |
#ifdef TK_DRAWCHARS_ANGLE |
| 1231 |
Tk_DrawChars(Tk_Display(tbPtr->tkwin), drawable, tbPtr->gc, |
| 1232 |
tbPtr->font, fragPtr->text, fragPtr->count, |
| 1233 |
fragPtr->x + x, fragPtr->y + y, 0.); |
| 1234 |
#else |
| 1235 |
Tk_DrawChars(Tk_Display(tbPtr->tkwin), drawable, tbPtr->gc, |
| 1236 |
tbPtr->font, fragPtr->text, fragPtr->count, |
| 1237 |
fragPtr->x + x, fragPtr->y + y); |
| •1238 |
#endif |
| 1239 |
} |
| 1240 |
if ((tbPtr->flags & TEXTBOX_FOCUS) && (tbPtr->cursorOn)) { |
| 1241 |
int left, top, right, bottom; |
| 1242 |
|
| 1243 |
IndexToPointer(tbPtr); |
| 1244 |
left = tbPtr->cursorX + 1; |
| 1245 |
right = left + 1; |
| 1246 |
top = tbPtr->cursorY; |
| 1247 |
if (tbPtr->height > fontMetrics.linespace) { |
| 1248 |
top += (tbPtr->height - fontMetrics.linespace) / 2; |
| 1249 |
} |
| 1250 |
bottom = top + tbPtr->cursorHeight - 1; |
| 1251 |
XDrawLine(tbPtr->display, drawable, tbPtr->gc, left, top, left, |
| 1252 |
bottom); |
| 1253 |
XDrawLine(tbPtr->display, drawable, tbPtr->gc, left - 1, top, right, |
| 1254 |
top); |
| 1255 |
XDrawLine(tbPtr->display, drawable, tbPtr->gc, left - 1, bottom, |
| 1256 |
right, bottom); |
| 1257 |
} |
| 1258 |
#ifdef notdef |
| 1259 |
buttonWidth = STD_ARROW_WIDTH + 6 + 2 * tbPtr->buttonBorderWidth; |
| 1260 |
buttonX -= buttonWidth; |
| 1261 |
buttonHeight = Tk_Height(tbPtr->tkwin) - 4; |
| 1262 |
Blt_Fill3DRectangle(tbPtr->tkwin, drawable, tbPtr->buttonBorder, |
| 1263 |
buttonX, buttonY, buttonWidth, buttonHeight, |
| 1264 |
tbPtr->buttonBorderWidth, tbPtr->buttonRelief); |
| 1265 |
|
| 1266 |
buttonX += buttonWidth / 2; |
| 1267 |
buttonY = tbPtr->height / 2; |
| 1268 |
Blt_DrawArrow(tbPtr->display, drawable, tbPtr->gc, buttonX, |
| 1269 |
buttonY, STD_ARROW_HEIGHT, ARROW_DOWN); |
| 1270 |
#endif |
| 1271 |
Blt_Draw3DRectangle(tbPtr->tkwin, drawable, tbPtr->border, 0, 0, |
| 1272 |
Tk_Width(tbPtr->tkwin), Tk_Height(tbPtr->tkwin), |
| 1273 |
tbPtr->borderWidth, tbPtr->relief); |
| 1274 |
XCopyArea(tbPtr->display, drawable, Tk_WindowId(tbPtr->tkwin), |
| 1275 |
tbPtr->gc, 0, 0, Tk_Width(tbPtr->tkwin), |
| 1276 |
Tk_Height(tbPtr->tkwin), 0, 0); |
| 1277 |
Tk_FreePixmap(tbPtr->display, drawable); |
| 1278 |
} |
| 1279 |
|
| 1280 |
|
| 1281 |
static int |
| 1282 |
ApplyOp(tbPtr, interp, objc, objv) |
| 1283 |
Textbox *tbPtr; |
| 1284 |
Tcl_Interp *interp; |
| 1285 |
int objc; |
| 1286 |
Tcl_Obj *CONST *objv; |
| 1287 |
{ |
| 1288 |
TreeViewEntry *entryPtr; |
| 1289 |
TreeView *tvPtr = tbPtr->tvPtr; |
| 1290 |
|
| 1291 |
entryPtr = tbPtr->entryPtr; |
| 1292 |
if (tbPtr->columnPtr == &tvPtr->treeColumn) { |
| 1293 |
if (entryPtr->labelUid != NULL) { |
| 1294 |
Blt_TreeViewFreeUid(tvPtr, entryPtr->labelUid); |
| 1295 |
} |
| 1296 |
if (tbPtr->string == NULL) { |
| 1297 |
entryPtr->labelUid = Blt_TreeViewGetUid(tvPtr, ""); |
| 1298 |
} else { |
| 1299 |
entryPtr->labelUid = Blt_TreeViewGetUid(tvPtr, tbPtr->string); |
| 1300 |
} |
| 1301 |
} else { |
| 1302 |
TreeViewColumn *columnPtr; |
| 1303 |
Tcl_Obj *objPtr; |
| 1304 |
|
| 1305 |
columnPtr = tbPtr->columnPtr; |
| 1306 |
objPtr = Tcl_NewStringObj(tbPtr->string, -1); |
| 1307 |
if (Blt_TreeSetValueByKey(interp, tvPtr->tree, entryPtr->node, |
| 1308 |
columnPtr->key, objPtr) != TCL_OK) { |
| 1309 |
Tcl_DecrRefCount(objPtr); |
| 1310 |
return TCL_ERROR; |
| 1311 |
} |
| 1312 |
entryPtr->flags |= ENTRY_DIRTY; |
| 1313 |
} |
| 1314 |
if (tvPtr != NULL) { |
| 1315 |
Blt_TreeViewConfigureEntry(tvPtr, entryPtr, 0, NULL, |
| 1316 |
BLT_CONFIG_OBJV_ONLY); |
| 1317 |
tvPtr->flags |= (TV_LAYOUT | TV_DIRTY | TV_RESORT); |
| 1318 |
Blt_TreeViewEventuallyRedraw(tvPtr); |
| 1319 |
} |
| 1320 |
Tk_DestroyWindow(tbPtr->tkwin); |
| 1321 |
return TCL_OK; |
| 1322 |
} |
| 1323 |
|
| 1324 |
|
| 1325 |
static int |
| 1326 |
CancelOp(tbPtr, interp, objc, objv) |
| 1327 |
Textbox *tbPtr; |
| 1328 |
Tcl_Interp *interp; |
| 1329 |
int objc; |
| 1330 |
Tcl_Obj *CONST *objv; |
| 1331 |
{ |
| 1332 |
Tk_DestroyWindow(tbPtr->tkwin); |
| 1333 |
return TCL_OK; |
| 1334 |
} |
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
static int |
| 1345 |
CgetOp(tbPtr, interp, objc, objv) |
| 1346 |
Textbox *tbPtr; |
| 1347 |
Tcl_Interp *interp; |
| 1348 |
int objc; |
| 1349 |
Tcl_Obj *CONST *objv; |
| 1350 |
{ |
| 1351 |
return Blt_ConfigureValueFromObj(interp, tbPtr->tkwin, |
| 1352 |
textboxConfigSpecs, (char *)tbPtr, objv[2], 0); |
| 1353 |
} |
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
static int |
| 1378 |
ConfigureOp(tbPtr, interp, objc, objv) |
| 1379 |
Textbox *tbPtr; |
| 1380 |
Tcl_Interp *interp; |
| 1381 |
int objc; |
| 1382 |
Tcl_Obj *CONST *objv; |
| 1383 |
{ |
| 1384 |
if (objc == 2) { |
| 1385 |
return Blt_ConfigureInfoFromObj(interp, tbPtr->tkwin, |
| 1386 |
textboxConfigSpecs, (char *)tbPtr, (Tcl_Obj *)NULL, 0); |
| 1387 |
} else if (objc == 3) { |
| 1388 |
return Blt_ConfigureInfoFromObj(interp, tbPtr->tkwin, |
| 1389 |
textboxConfigSpecs, (char *)tbPtr, objv[2], 0); |
| 1390 |
} |
| 1391 |
if (Blt_ConfigureWidgetFromObj(interp, tbPtr->tkwin, |
| 1392 |
textboxConfigSpecs, objc - 2, objv + 2, (char *)tbPtr, |
| 1393 |
BLT_CONFIG_OBJV_ONLY, NULL) != TCL_OK) { |
| 1394 |
return TCL_ERROR; |
| 1395 |
} |
| 1396 |
ConfigureTextbox(tbPtr); |
| 1397 |
EventuallyRedraw(tbPtr); |
| 1398 |
return TCL_OK; |
| 1399 |
} |
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
static int |
| 1419 |
DeleteOp(tbPtr, interp, objc, objv) |
| 1420 |
Textbox *tbPtr; |
| 1421 |
Tcl_Interp *interp; |
| 1422 |
int objc; |
| 1423 |
Tcl_Obj *CONST *objv; |
| 1424 |
{ |
| 1425 |
int firstPos, lastPos; |
| 1426 |
|
| 1427 |
if (tbPtr->entryPtr == NULL) { |
| 1428 |
return TCL_OK; |
| 1429 |
} |
| 1430 |
if (GetIndexFromObj(interp, tbPtr, objv[2], &firstPos) != TCL_OK) { |
| 1431 |
return TCL_ERROR; |
| 1432 |
} |
| 1433 |
lastPos = firstPos; |
| 1434 |
if ((objc == 4) && |
| 1435 |
(GetIndexFromObj(interp, tbPtr, objv[3], &lastPos) != TCL_OK)) { |
| 1436 |
return TCL_ERROR; |
| 1437 |
} |
| 1438 |
if (firstPos > lastPos) { |
| 1439 |
return TCL_OK; |
| 1440 |
} |
| 1441 |
return DeleteText(tbPtr, firstPos, lastPos); |
| 1442 |
} |
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
static int |
| 1470 |
IcursorOp(tbPtr, interp, objc, objv) |
| 1471 |
Textbox *tbPtr; |
| 1472 |
Tcl_Interp *interp; |
| 1473 |
int objc; |
| 1474 |
Tcl_Obj *CONST *objv; |
| 1475 |
{ |
| 1476 |
int textPos; |
| 1477 |
|
| 1478 |
if (GetIndexFromObj(interp, tbPtr, objv[2], &textPos) != TCL_OK) { |
| 1479 |
return TCL_ERROR; |
| 1480 |
} |
| 1481 |
if (tbPtr->columnPtr != NULL) { |
| 1482 |
tbPtr->insertPos = textPos; |
| 1483 |
IndexToPointer(tbPtr); |
| 1484 |
EventuallyRedraw(tbPtr); |
| 1485 |
} |
| 1486 |
return TCL_OK; |
| 1487 |
} |
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
static int |
| 1515 |
IndexOp(tbPtr, interp, objc, objv) |
| 1516 |
Textbox *tbPtr; |
| 1517 |
Tcl_Interp *interp; |
| 1518 |
int objc; |
| 1519 |
Tcl_Obj *CONST *objv; |
| 1520 |
{ |
| 1521 |
int textPos; |
| 1522 |
|
| 1523 |
if (GetIndexFromObj(interp, tbPtr, objv[2], &textPos) != TCL_OK) { |
| 1524 |
return TCL_ERROR; |
| 1525 |
} |
| 1526 |
if ((tbPtr->columnPtr != NULL) && (tbPtr->string != NULL)) { |
| 1527 |
int nChars; |
| 1528 |
|
| 1529 |
nChars = Tcl_NumUtfChars(tbPtr->string, textPos); |
| 1530 |
Tcl_SetObjResult(interp, Tcl_NewIntObj(nChars)); |
| 1531 |
} |
| 1532 |
return TCL_OK; |
| 1533 |
} |
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
static int |
| 1553 |
InsertOp(tbPtr, interp, objc, objv) |
| 1554 |
Textbox *tbPtr; |
| 1555 |
Tcl_Interp *interp; |
| 1556 |
int objc; |
| 1557 |
Tcl_Obj *CONST *objv; |
| 1558 |
{ |
| 1559 |
int extra; |
| 1560 |
int insertPos; |
| 1561 |
char *string; |
| 1562 |
|
| 1563 |
if (tbPtr->entryPtr == NULL) { |
| 1564 |
return TCL_ERROR; |
| 1565 |
} |
| 1566 |
if (GetIndexFromObj(interp, tbPtr, objv[2], &insertPos) != TCL_OK) { |
| 1567 |
return TCL_ERROR; |
| 1568 |
} |
| 1569 |
string = Tcl_GetStringFromObj(objv[3], &extra); |
| 1570 |
if (extra == 0) { |
| 1571 |
tbPtr->insertPos = insertPos; |
| 1572 |
} else { |
| 1573 |
InsertText(tbPtr, string, insertPos, extra); |
| 1574 |
} |
| 1575 |
return TCL_OK; |
| 1576 |
} |
| 1577 |
|
| 1578 |
|
| 1579 |
static int |
| 1580 |
SelectionAdjustOp(tbPtr, interp, objc, objv) |
| 1581 |
Textbox *tbPtr; |
| 1582 |
Tcl_Interp *interp; |
| 1583 |
int objc; |
| 1584 |
Tcl_Obj *CONST *objv; |
| 1585 |
{ |
| 1586 |
int textPos; |
| 1587 |
int half1, half2; |
| 1588 |
|
| 1589 |
if (GetIndexFromObj(interp, tbPtr, objv[3], &textPos) != TCL_OK) { |
| 1590 |
return TCL_ERROR; |
| 1591 |
} |
| 1592 |
half1 = (tbPtr->selFirst + tbPtr->selLast) / 2; |
| 1593 |
half2 = (tbPtr->selFirst + tbPtr->selLast + 1) / 2; |
| 1594 |
if (textPos < half1) { |
| 1595 |
tbPtr->selAnchor = tbPtr->selLast; |
| 1596 |
} else if (textPos > half2) { |
| 1597 |
tbPtr->selAnchor = tbPtr->selFirst; |
| 1598 |
} |
| 1599 |
return SelectText(tbPtr, textPos); |
| 1600 |
} |
| 1601 |
|
| 1602 |
|
| 1603 |
static int |
| 1604 |
SelectionClearOp(tbPtr, interp, objc, objv) |
| 1605 |
Textbox *tbPtr; |
| 1606 |
Tcl_Interp *interp; |
| 1607 |
int objc; |
| 1608 |
Tcl_Obj *CONST *objv; |
| 1609 |
{ |
| 1610 |
if (tbPtr->selFirst != -1) { |
| 1611 |
tbPtr->selFirst = tbPtr->selLast = -1; |
| 1612 |
EventuallyRedraw(tbPtr); |
| 1613 |
} |
| 1614 |
return TCL_OK; |
| 1615 |
} |
| 1616 |
|
| 1617 |
|
| 1618 |
static int |
| 1619 |
SelectionFromOp(tbPtr, interp, objc, objv) |
| 1620 |
Textbox *tbPtr; |
| 1621 |
Tcl_Interp *interp; |
| 1622 |
int objc; |
| 1623 |
Tcl_Obj *CONST *objv; |
| 1624 |
{ |
| 1625 |
int textPos; |
| 1626 |
|
| 1627 |
if (GetIndexFromObj(interp, tbPtr, objv[3], &textPos) != TCL_OK) { |
| 1628 |
return TCL_ERROR; |
| 1629 |
} |
| 1630 |
tbPtr->selAnchor = textPos; |
| 1631 |
return TCL_OK; |
| 1632 |
} |
| 1633 |
|
| 1634 |
|
| 1635 |
static int |
| 1636 |
SelectionPresentOp(tbPtr, interp, objc, objv) |
| 1637 |
Textbox *tbPtr; |
| 1638 |
Tcl_Interp *interp; |
| 1639 |
int objc; |
| 1640 |
Tcl_Obj *CONST *objv; |
| 1641 |
{ |
| 1642 |
int bool; |
| 1643 |
|
| 1644 |
bool = (tbPtr->selFirst != -1); |
| 1645 |
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(bool)); |
| 1646 |
return TCL_OK; |
| 1647 |
} |
| 1648 |
|
| 1649 |
|
| 1650 |
static int |
| 1651 |
SelectionRangeOp(tbPtr, interp, objc, objv) |
| 1652 |
Textbox *tbPtr; |
| 1653 |
Tcl_Interp *interp; |
| 1654 |
int objc; |
| 1655 |
Tcl_Obj *CONST *objv; |
| 1656 |
{ |
| 1657 |
int selFirst, selLast; |
| 1658 |
|
| 1659 |
if (GetIndexFromObj(interp, tbPtr, objv[3], &selFirst) != TCL_OK) { |
| 1660 |
return TCL_ERROR; |
| 1661 |
} |
| 1662 |
if (GetIndexFromObj(interp, tbPtr, objv[4], &selLast) != TCL_OK) { |
| 1663 |
return TCL_ERROR; |
| 1664 |
} |
| 1665 |
tbPtr->selAnchor = selFirst; |
| 1666 |
return SelectText(tbPtr, selLast); |
| 1667 |
} |
| 1668 |
|
| 1669 |
|
| 1670 |
static int |
| 1671 |
SelectionToOp(tbPtr, interp, objc, objv) |
| 1672 |
Textbox *tbPtr; |
| 1673 |
Tcl_Interp *interp; |
| 1674 |
int objc; |
| 1675 |
Tcl_Obj *CONST *objv; |
| 1676 |
{ |
| 1677 |
int textPos; |
| 1678 |
|
| 1679 |
if (GetIndexFromObj(interp, tbPtr, objv[3], &textPos) != TCL_OK) { |
| 1680 |
return TCL_ERROR; |
| 1681 |
} |
| 1682 |
return SelectText(tbPtr, textPos); |
| 1683 |
} |
| 1684 |
|
| 1685 |
|
| 1686 |
static Blt_OpSpec selectionOps[] = |
| 1687 |
{ |
| 1688 |
{"adjust", 1, (Blt_Op)SelectionAdjustOp, 4, 4, "index",}, |
| 1689 |
{"clear", 1, (Blt_Op)SelectionClearOp, 3, 3, "",}, |
| 1690 |
{"from", 1, (Blt_Op)SelectionFromOp, 4, 4, "index"}, |
| 1691 |
{"present", 1, (Blt_Op)SelectionPresentOp, 3, 3, ""}, |
| 1692 |
{"range", 1, (Blt_Op)SelectionRangeOp, 5, 5, "start end",}, |
| 1693 |
{"to", 1, (Blt_Op)SelectionToOp, 4, 4, "index"}, |
| 1694 |
}; |
| 1695 |
|
| 1696 |
static int nSelectionOps = sizeof(selectionOps) / sizeof(Blt_OpSpec); |
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
static int |
| 1716 |
SelectionOp(tbPtr, interp, objc, objv) |
| 1717 |
Textbox *tbPtr; |
| 1718 |
Tcl_Interp *interp; |
| 1719 |
int objc; |
| 1720 |
Tcl_Obj *CONST *objv; |
| 1721 |
{ |
| 1722 |
Blt_Op proc; |
| 1723 |
int result; |
| 1724 |
|
| 1725 |
proc = Blt_GetOpFromObj(interp, nSelectionOps, selectionOps, BLT_OP_ARG2, |
| 1726 |
objc, objv, 0); |
| 1727 |
if (proc == NULL) { |
| 1728 |
return TCL_ERROR; |
| 1729 |
} |
| 1730 |
result = (*proc) (tbPtr, interp, objc, objv); |
| 1731 |
return result; |
| 1732 |
} |
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
static Blt_OpSpec comboOps[] = |
| 1747 |
{ |
| 1748 |
{"apply", 1, (Blt_Op)ApplyOp, 2, 2, "",}, |
| 1749 |
{"cancel", 2, (Blt_Op)CancelOp, 2, 2, "",}, |
| 1750 |
{"cget", 2, (Blt_Op)CgetOp, 3, 3, "value",}, |
| 1751 |
{"configure", 2, (Blt_Op)ConfigureOp, 2, 0, "?option value...?",}, |
| 1752 |
{"delete", 1, (Blt_Op)DeleteOp, 3, 4, "first ?last?"}, |
| 1753 |
{"icursor", 2, (Blt_Op)IcursorOp, 3, 3, "index"}, |
| 1754 |
{"index", 3, (Blt_Op)IndexOp, 3, 3, "index"}, |
| 1755 |
{"insert", 3, (Blt_Op)InsertOp, 4, 4, "index string"}, |
| 1756 |
{"selection", 1, (Blt_Op)SelectionOp, 2, 0, "args"}, |
| 1757 |
}; |
| 1758 |
static int nComboOps = sizeof(comboOps) / sizeof(Blt_OpSpec); |
| 1759 |
|
| 1760 |
static int |
| 1761 |
TextboxCmd(clientData, interp, objc, objv) |
| 1762 |
ClientData clientData; |
| 1763 |
Tcl_Interp *interp; |
| 1764 |
int objc; |
| 1765 |
Tcl_Obj *CONST *objv; |
| 1766 |
{ |
| 1767 |
Textbox *tbPtr = clientData; |
| 1768 |
Blt_Op proc; |
| 1769 |
int result; |
| 1770 |
|
| 1771 |
proc = Blt_GetOpFromObj(interp, nComboOps, comboOps, BLT_OP_ARG1, objc, |
| 1772 |
objv, 0); |
| 1773 |
if (proc == NULL) { |
| 1774 |
return TCL_ERROR; |
| 1775 |
} |
| 1776 |
result = (*proc) (tbPtr, interp, objc, objv); |
| 1777 |
return result; |
| 1778 |
} |
| 1779 |
|
| 1780 |
#endif |
| 1781 |
|