| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "tk.h" |
| 17 |
#include "tkText.h" |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
static void EmbWinRequestProc _ANSI_ARGS_((ClientData clientData, |
| 25 |
Tk_Window tkwin)); |
| 26 |
static void EmbWinLostSlaveProc _ANSI_ARGS_((ClientData clientData, |
| 27 |
Tk_Window tkwin)); |
| 28 |
|
| 29 |
static Tk_GeomMgr textGeomType = { |
| 30 |
"text", |
| 31 |
EmbWinRequestProc, |
| 32 |
EmbWinLostSlaveProc, |
| 33 |
}; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
#define ALIGN_BOTTOM 0 |
| 40 |
#define ALIGN_CENTER 1 |
| 41 |
#define ALIGN_TOP 2 |
| 42 |
#define ALIGN_BASELINE 3 |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
#define EW_SEG_SIZE ((unsigned) (Tk_Offset(TkTextSegment, body) \ |
| 49 |
+ sizeof(TkTextEmbWindow))) |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
static int AlignParseProc _ANSI_ARGS_((ClientData clientData, |
| 56 |
Tcl_Interp *interp, Tk_Window tkwin, |
| 57 |
Tcl_Obj *value, char *widgRec, int offset)); |
| 58 |
static Tcl_Obj * AlignPrintProc _ANSI_ARGS_((ClientData clientData, |
| 59 |
Tk_Window tkwin, char *widgRec, int offset, |
| 60 |
Tcl_FreeProc **freeProcPtr)); |
| 61 |
static TkTextSegment * EmbWinCleanupProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 62 |
TkTextLine *linePtr)); |
| 63 |
static void EmbWinCheckProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 64 |
TkTextLine *linePtr)); |
| 65 |
static void EmbWinBboxProc _ANSI_ARGS_((TkTextDispChunk *chunkPtr, |
| 66 |
int index, int y, int lineHeight, int baseline, |
| 67 |
int *xPtr, int *yPtr, int *widthPtr, |
| 68 |
int *heightPtr)); |
| 69 |
static int EmbWinConfigure _ANSI_ARGS_((TkText *textPtr, |
| 70 |
TkTextSegment *ewPtr, int argc, CONST char **argv)); |
| 71 |
static void EmbWinDelayedUnmap _ANSI_ARGS_(( |
| 72 |
ClientData clientData)); |
| 73 |
static int EmbWinDeleteProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 74 |
TkTextLine *linePtr, int treeGone)); |
| 75 |
static void EmbWinDisplayProc _ANSI_ARGS_(( |
| 76 |
TkTextDispChunk *chunkPtr, int x, int y, |
| 77 |
int lineHeight, int baseline, Display *display, |
| 78 |
Drawable dst, int screenY)); |
| 79 |
static int EmbWinLayoutProc _ANSI_ARGS_((TkText *textPtr, |
| 80 |
TkTextIndex *indexPtr, TkTextSegment *segPtr, |
| 81 |
int offset, int maxX, int maxChars, |
| 82 |
int noCharsYet, TkWrapMode wrapMode, |
| 83 |
TkTextDispChunk *chunkPtr)); |
| 84 |
static void EmbWinStructureProc _ANSI_ARGS_((ClientData clientData, |
| 85 |
XEvent *eventPtr)); |
| 86 |
static void EmbWinUndisplayProc _ANSI_ARGS_((TkText *textPtr, |
| 87 |
TkTextDispChunk *chunkPtr)); |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
static Tk_SegType tkTextEmbWindowType = { |
| 94 |
"window", |
| 95 |
0, |
| 96 |
(Tk_SegSplitProc *) NULL, |
| 97 |
EmbWinDeleteProc, |
| 98 |
EmbWinCleanupProc, |
| 99 |
(Tk_SegLineChangeProc *) NULL, |
| 100 |
EmbWinLayoutProc, |
| 101 |
EmbWinCheckProc |
| 102 |
}; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
static Tk_CustomOption alignOption = {AlignParseProc, AlignPrintProc, |
| 109 |
(ClientData) NULL}; |
| 110 |
|
| 111 |
static Tk_ConfigSpec configSpecs[] = { |
| 112 |
{TK_CONFIG_CUSTOM, "-align", (char *) NULL, (char *) NULL, |
| 113 |
"center", 0, TK_CONFIG_DONT_SET_DEFAULT, &alignOption}, |
| 114 |
{TK_CONFIG_CALLBACK, "-create", (char *) NULL, (char *) NULL, |
| 115 |
(char *) NULL, Tk_Offset(TkTextEmbWindow, create), |
| 116 |
TK_CONFIG_DONT_SET_DEFAULT|TK_CONFIG_NULL_OK}, |
| 117 |
{TK_CONFIG_INT, "-padx", (char *) NULL, (char *) NULL, |
| 118 |
"0", Tk_Offset(TkTextEmbWindow, padX), |
| 119 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 120 |
{TK_CONFIG_INT, "-pady", (char *) NULL, (char *) NULL, |
| 121 |
"0", Tk_Offset(TkTextEmbWindow, padY), |
| 122 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 123 |
{TK_CONFIG_BOOLEAN, "-stretch", (char *) NULL, (char *) NULL, |
| 124 |
"0", Tk_Offset(TkTextEmbWindow, stretch), |
| 125 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 126 |
{TK_CONFIG_WINDOW, "-window", (char *) NULL, (char *) NULL, |
| 127 |
(char *) NULL, Tk_Offset(TkTextEmbWindow, tkwin), |
| 128 |
TK_CONFIG_DONT_SET_DEFAULT|TK_CONFIG_NULL_OK}, |
| 129 |
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, |
| 130 |
(char *) NULL, 0, 0} |
| 131 |
}; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
int |
| 152 |
TkTextWindowCmd(textPtr, interp, argc, argv) |
| 153 |
register TkText *textPtr; |
| 154 |
Tcl_Interp *interp; |
| 155 |
int argc; |
| 156 |
CONST char **argv; |
| 157 |
|
| 158 |
|
| 159 |
{ |
| 160 |
size_t length; |
| 161 |
register TkTextSegment *ewPtr; |
| 162 |
|
| 163 |
if (argc < 3) { |
| 164 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 165 |
argv[0], " window option ?arg arg ...?\"", (char *) NULL); |
| 166 |
return TCL_ERROR; |
| 167 |
} |
| 168 |
length = strlen(argv[2]); |
| 169 |
if ((strncmp(argv[2], "cget", length) == 0) && (length >= 2)) { |
| 170 |
TkTextIndex index; |
| 171 |
TkTextSegment *ewPtr; |
| 172 |
|
| 173 |
if (argc != 5) { |
| 174 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 175 |
argv[0], " window cget index option\"", |
| 176 |
(char *) NULL); |
| 177 |
return TCL_ERROR; |
| 178 |
} |
| 179 |
if (TkTextGetIndex(interp, textPtr, argv[3], &index) != TCL_OK) { |
| 180 |
return TCL_ERROR; |
| 181 |
} |
| 182 |
ewPtr = TkTextIndexToSeg(&index, (int *) NULL); |
| 183 |
if (ewPtr->typePtr != &tkTextEmbWindowType) { |
| 184 |
Tcl_AppendResult(interp, "no embedded window at index \"", |
| 185 |
argv[3], "\"", (char *) NULL); |
| 186 |
return TCL_ERROR; |
| 187 |
} |
| 188 |
return Tk_ConfigureValue(interp, textPtr->tkwin, configSpecs, |
| 189 |
(char *) &ewPtr->body.ew, argv[4], 0); |
| 190 |
} else if ((strncmp(argv[2], "configure", length) == 0) && (length >= 2)) { |
| 191 |
TkTextIndex index; |
| 192 |
TkTextSegment *ewPtr; |
| 193 |
|
| 194 |
if (argc < 4) { |
| 195 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 196 |
argv[0], " window configure index ?option value ...?\"", |
| 197 |
(char *) NULL); |
| 198 |
return TCL_ERROR; |
| 199 |
} |
| 200 |
if (TkTextGetIndex(interp, textPtr, argv[3], &index) != TCL_OK) { |
| 201 |
return TCL_ERROR; |
| 202 |
} |
| 203 |
ewPtr = TkTextIndexToSeg(&index, (int *) NULL); |
| 204 |
if (ewPtr->typePtr != &tkTextEmbWindowType) { |
| 205 |
Tcl_AppendResult(interp, "no embedded window at index \"", |
| 206 |
argv[3], "\"", (char *) NULL); |
| 207 |
return TCL_ERROR; |
| 208 |
} |
| 209 |
if (argc == 4) { |
| 210 |
return Tk_ConfigureInfo(interp, textPtr->tkwin, configSpecs, |
| 211 |
(char *) &ewPtr->body.ew, (char *) NULL, 0); |
| 212 |
} else if (argc == 5) { |
| 213 |
return Tk_ConfigureInfo(interp, textPtr->tkwin, configSpecs, |
| 214 |
(char *) &ewPtr->body.ew, argv[4], 0); |
| 215 |
} else { |
| 216 |
TkTextChanged(textPtr, &index, &index); |
| 217 |
return EmbWinConfigure(textPtr, ewPtr, argc-4, argv+4); |
| 218 |
} |
| 219 |
} else if ((strncmp(argv[2], "create", length) == 0) && (length >= 2)) { |
| 220 |
TkTextIndex index; |
| 221 |
int lineIndex; |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
if (argc < 4) { |
| 229 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 230 |
argv[0], " window create index ?option value ...?\"", |
| 231 |
(char *) NULL); |
| 232 |
return TCL_ERROR; |
| 233 |
} |
| 234 |
if (TkTextGetIndex(interp, textPtr, argv[3], &index) != TCL_OK) { |
| 235 |
return TCL_ERROR; |
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
lineIndex = TkBTreeLineIndex(index.linePtr); |
| 243 |
if (lineIndex == TkBTreeNumLines(textPtr->tree)) { |
| 244 |
lineIndex--; |
| 245 |
TkTextMakeByteIndex(textPtr->tree, lineIndex, 1000000, &index); |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
ewPtr = (TkTextSegment *) ckalloc(EW_SEG_SIZE); |
| 253 |
ewPtr->typePtr = &tkTextEmbWindowType; |
| 254 |
ewPtr->size = 1; |
| 255 |
ewPtr->body.ew.textPtr = textPtr; |
| 256 |
ewPtr->body.ew.linePtr = NULL; |
| 257 |
ewPtr->body.ew.tkwin = NULL; |
| 258 |
ewPtr->body.ew.create = NULL; |
| 259 |
ewPtr->body.ew.align = ALIGN_CENTER; |
| 260 |
ewPtr->body.ew.padX = ewPtr->body.ew.padY = 0; |
| 261 |
ewPtr->body.ew.stretch = 0; |
| 262 |
ewPtr->body.ew.chunkCount = 0; |
| 263 |
ewPtr->body.ew.displayed = 0; |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
TkTextChanged(textPtr, &index, &index); |
| 271 |
TkBTreeLinkSegment(ewPtr, &index); |
| 272 |
if (EmbWinConfigure(textPtr, ewPtr, argc-4, argv+4) != TCL_OK) { |
| 273 |
TkTextIndex index2; |
| 274 |
|
| 275 |
TkTextIndexForwChars(&index, 1, &index2); |
| 276 |
TkBTreeDeleteChars(&index, &index2); |
| 277 |
return TCL_ERROR; |
| 278 |
} |
| 279 |
} else if (strncmp(argv[2], "names", length) == 0) { |
| 280 |
Tcl_HashSearch search; |
| 281 |
Tcl_HashEntry *hPtr; |
| 282 |
|
| 283 |
if (argc != 3) { |
| 284 |
Tcl_AppendResult(interp, "wrong # args: should be \"", |
| 285 |
argv[0], " window names\"", (char *) NULL); |
| 286 |
return TCL_ERROR; |
| 287 |
} |
| 288 |
for (hPtr = Tcl_FirstHashEntry(&textPtr->windowTable, &search); |
| 289 |
hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { |
| 290 |
Tcl_AppendElement(interp, |
| 291 |
Tcl_GetHashKey(&textPtr->markTable, hPtr)); |
| 292 |
} |
| 293 |
} else { |
| 294 |
Tcl_AppendResult(interp, "bad window option \"", argv[2], |
| 295 |
"\": must be cget, configure, create, or names", |
| 296 |
(char *) NULL); |
| 297 |
return TCL_ERROR; |
| 298 |
} |
| 299 |
return TCL_OK; |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
static int |
| 323 |
EmbWinConfigure(textPtr, ewPtr, argc, argv) |
| 324 |
TkText *textPtr; |
| 325 |
|
| 326 |
TkTextSegment *ewPtr; |
| 327 |
int argc; |
| 328 |
CONST char **argv; |
| 329 |
|
| 330 |
{ |
| 331 |
Tk_Window oldWindow; |
| 332 |
Tcl_HashEntry *hPtr; |
| 333 |
int new; |
| 334 |
|
| 335 |
oldWindow = ewPtr->body.ew.tkwin; |
| 336 |
if (Tk_ConfigureWidget(textPtr->interp, textPtr->tkwin, configSpecs, |
| 337 |
argc, argv, (char *) &ewPtr->body.ew, TK_CONFIG_ARGV_ONLY) |
| 338 |
!= TCL_OK) { |
| 339 |
return TCL_ERROR; |
| 340 |
} |
| 341 |
if (oldWindow != ewPtr->body.ew.tkwin) { |
| 342 |
if (oldWindow != NULL) { |
| 343 |
Tcl_DeleteHashEntry(Tcl_FindHashEntry(&textPtr->windowTable, |
| 344 |
Tk_PathName(oldWindow))); |
| 345 |
Tk_DeleteEventHandler(oldWindow, StructureNotifyMask, |
| 346 |
EmbWinStructureProc, (ClientData) ewPtr); |
| 347 |
Tk_ManageGeometry(oldWindow, (Tk_GeomMgr *) NULL, |
| 348 |
(ClientData) NULL); |
| 349 |
if (textPtr->tkwin != Tk_Parent(oldWindow)) { |
| 350 |
Tk_UnmaintainGeometry(oldWindow, textPtr->tkwin); |
| 351 |
} else { |
| 352 |
Tk_UnmapWindow(oldWindow); |
| 353 |
} |
| 354 |
} |
| 355 |
if (ewPtr->body.ew.tkwin != NULL) { |
| 356 |
Tk_Window ancestor, parent; |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
parent = Tk_Parent(ewPtr->body.ew.tkwin); |
| 366 |
for (ancestor = textPtr->tkwin; ; |
| 367 |
ancestor = Tk_Parent(ancestor)) { |
| 368 |
if (ancestor == parent) { |
| 369 |
break; |
| 370 |
} |
| 371 |
if (Tk_TopWinHierarchy(ancestor)) { |
| 372 |
badMaster: |
| 373 |
Tcl_AppendResult(textPtr->interp, "can't embed ", |
| 374 |
Tk_PathName(ewPtr->body.ew.tkwin), " in ", |
| 375 |
Tk_PathName(textPtr->tkwin), (char *) NULL); |
| 376 |
ewPtr->body.ew.tkwin = NULL; |
| 377 |
return TCL_ERROR; |
| 378 |
} |
| 379 |
} |
| 380 |
if (Tk_TopWinHierarchy(ewPtr->body.ew.tkwin) |
| 381 |
|| (ewPtr->body.ew.tkwin == textPtr->tkwin)) { |
| 382 |
goto badMaster; |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
Tk_ManageGeometry(ewPtr->body.ew.tkwin, &textGeomType, |
| 391 |
(ClientData) ewPtr); |
| 392 |
Tk_CreateEventHandler(ewPtr->body.ew.tkwin, StructureNotifyMask, |
| 393 |
EmbWinStructureProc, (ClientData) ewPtr); |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
hPtr = Tcl_CreateHashEntry(&textPtr->windowTable, |
| 404 |
Tk_PathName(ewPtr->body.ew.tkwin), &new); |
| 405 |
Tcl_SetHashValue(hPtr, ewPtr); |
| 406 |
|
| 407 |
} |
| 408 |
} |
| 409 |
return TCL_OK; |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
static int |
| 432 |
AlignParseProc(clientData, interp, tkwin, arg, widgRec, offset) |
| 433 |
ClientData clientData; |
| 434 |
Tcl_Interp *interp; |
| 435 |
Tk_Window tkwin; |
| 436 |
Tcl_Obj *arg; |
| 437 |
char *widgRec; |
| 438 |
|
| 439 |
int offset; |
| 440 |
{ |
| 441 |
char *value = Tcl_GetString(arg); |
| 442 |
register TkTextEmbWindow *embPtr = (TkTextEmbWindow *) widgRec; |
| 443 |
|
| 444 |
if (strcmp(value, "baseline") == 0) { |
| 445 |
embPtr->align = ALIGN_BASELINE; |
| 446 |
} else if (strcmp(value, "bottom") == 0) { |
| 447 |
embPtr->align = ALIGN_BOTTOM; |
| 448 |
} else if (strcmp(value, "center") == 0) { |
| 449 |
embPtr->align = ALIGN_CENTER; |
| 450 |
} else if (strcmp(value, "top") == 0) { |
| 451 |
embPtr->align = ALIGN_TOP; |
| 452 |
} else { |
| 453 |
Tcl_AppendResult(interp, "bad alignment \"", value, |
| 454 |
"\": must be baseline, bottom, center, or top", |
| 455 |
(char *) NULL); |
| 456 |
return TCL_ERROR; |
| 457 |
} |
| 458 |
return TCL_OK; |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
static Tcl_Obj * |
| 482 |
AlignPrintProc(clientData, tkwin, widgRec, offset, freeProcPtr) |
| 483 |
ClientData clientData; |
| 484 |
Tk_Window tkwin; |
| 485 |
char *widgRec; |
| 486 |
|
| 487 |
int offset; |
| 488 |
Tcl_FreeProc **freeProcPtr; |
| 489 |
|
| 490 |
|
| 491 |
{ |
| 492 |
Tcl_Obj * result = NULL; |
| 493 |
LangSetDefault(&result, ""); |
| 494 |
|
| 495 |
*freeProcPtr = TCL_STATIC; |
| 496 |
|
| 497 |
switch (((TkTextEmbWindow *) widgRec)->align) { |
| 498 |
case ALIGN_BASELINE: |
| 499 |
LangSetString(&result, "baseline"); |
| 500 |
break; |
| 501 |
case ALIGN_BOTTOM: |
| 502 |
LangSetString(&result, "bottom"); |
| 503 |
break; |
| 504 |
case ALIGN_CENTER: |
| 505 |
LangSetString(&result, "centre"); |
| 506 |
break; |
| 507 |
case ALIGN_TOP: |
| 508 |
LangSetString(&result, "top"); |
| 509 |
break; |
| 510 |
default: |
| 511 |
break; |
| 512 |
} |
| 513 |
return result; |
| 514 |
} |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
static void |
| 537 |
EmbWinStructureProc(clientData, eventPtr) |
| 538 |
ClientData clientData; |
| 539 |
XEvent *eventPtr; |
| 540 |
{ |
| 541 |
register TkTextSegment *ewPtr = (TkTextSegment *) clientData; |
| 542 |
TkTextIndex index; |
| 543 |
|
| 544 |
if (eventPtr->type != DestroyNotify) { |
| 545 |
return; |
| 546 |
} |
| 547 |
|
| 548 |
Tcl_DeleteHashEntry(Tcl_FindHashEntry(&ewPtr->body.ew.textPtr->windowTable, |
| 549 |
Tk_PathName(ewPtr->body.ew.tkwin))); |
| 550 |
ewPtr->body.ew.tkwin = NULL; |
| 551 |
index.tree = ewPtr->body.ew.textPtr->tree; |
| 552 |
index.linePtr = ewPtr->body.ew.linePtr; |
| 553 |
index.byteIndex = TkTextSegToOffset(ewPtr, ewPtr->body.ew.linePtr); |
| 554 |
TkTextChanged(ewPtr->body.ew.textPtr, &index, &index); |
| 555 |
} |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
static void |
| 577 |
EmbWinRequestProc(clientData, tkwin) |
| 578 |
ClientData clientData; |
| 579 |
Tk_Window tkwin; |
| 580 |
|
| 581 |
{ |
| 582 |
TkTextSegment *ewPtr = (TkTextSegment *) clientData; |
| 583 |
TkTextIndex index; |
| 584 |
|
| 585 |
index.tree = ewPtr->body.ew.textPtr->tree; |
| 586 |
index.linePtr = ewPtr->body.ew.linePtr; |
| 587 |
index.byteIndex = TkTextSegToOffset(ewPtr, ewPtr->body.ew.linePtr); |
| 588 |
TkTextChanged(ewPtr->body.ew.textPtr, &index, &index); |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
static void |
| 611 |
EmbWinLostSlaveProc(clientData, tkwin) |
| 612 |
ClientData clientData; |
| 613 |
Tk_Window tkwin; |
| 614 |
|
| 615 |
{ |
| 616 |
register TkTextSegment *ewPtr = (TkTextSegment *) clientData; |
| 617 |
TkTextIndex index; |
| 618 |
|
| 619 |
Tk_DeleteEventHandler(ewPtr->body.ew.tkwin, StructureNotifyMask, |
| 620 |
EmbWinStructureProc, (ClientData) ewPtr); |
| 621 |
Tcl_CancelIdleCall(EmbWinDelayedUnmap, (ClientData) ewPtr); |
| 622 |
if (ewPtr->body.ew.textPtr->tkwin != Tk_Parent(tkwin)) { |
| 623 |
Tk_UnmaintainGeometry(tkwin, ewPtr->body.ew.textPtr->tkwin); |
| 624 |
} else { |
| 625 |
Tk_UnmapWindow(tkwin); |
| 626 |
} |
| 627 |
Tcl_DeleteHashEntry(Tcl_FindHashEntry(&ewPtr->body.ew.textPtr->windowTable, |
| 628 |
Tk_PathName(ewPtr->body.ew.tkwin))); |
| 629 |
ewPtr->body.ew.tkwin = NULL; |
| 630 |
index.tree = ewPtr->body.ew.textPtr->tree; |
| 631 |
index.linePtr = ewPtr->body.ew.linePtr; |
| 632 |
index.byteIndex = TkTextSegToOffset(ewPtr, ewPtr->body.ew.linePtr); |
| 633 |
TkTextChanged(ewPtr->body.ew.textPtr, &index, &index); |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
static int |
| 656 |
EmbWinDeleteProc(ewPtr, linePtr, treeGone) |
| 657 |
TkTextSegment *ewPtr; |
| 658 |
TkTextLine *linePtr; |
| 659 |
int treeGone; |
| 660 |
|
| 661 |
|
| 662 |
{ |
| 663 |
Tcl_HashEntry *hPtr; |
| 664 |
|
| 665 |
if (ewPtr->body.ew.tkwin != NULL) { |
| 666 |
hPtr = Tcl_FindHashEntry(&ewPtr->body.ew.textPtr->windowTable, |
| 667 |
Tk_PathName(ewPtr->body.ew.tkwin)); |
| 668 |
if (hPtr != NULL) { |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
Tcl_DeleteHashEntry(hPtr); |
| 676 |
} |
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
Tk_DeleteEventHandler(ewPtr->body.ew.tkwin, StructureNotifyMask, |
| 686 |
EmbWinStructureProc, (ClientData) ewPtr); |
| 687 |
Tk_DestroyWindow(ewPtr->body.ew.tkwin); |
| 688 |
} |
| 689 |
Tcl_CancelIdleCall(EmbWinDelayedUnmap, (ClientData) ewPtr); |
| 690 |
Tk_FreeOptions(configSpecs, (char *) &ewPtr->body.ew, |
| 691 |
ewPtr->body.ew.textPtr->display, 0); |
| 692 |
ckfree((char *) ewPtr); |
| 693 |
return 0; |
| 694 |
} |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
static TkTextSegment * |
| 715 |
EmbWinCleanupProc(ewPtr, linePtr) |
| 716 |
TkTextSegment *ewPtr; |
| 717 |
TkTextLine *linePtr; |
| 718 |
{ |
| 719 |
ewPtr->body.ew.linePtr = linePtr; |
| 720 |
return ewPtr; |
| 721 |
} |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
static int |
| 743 |
EmbWinLayoutProc(textPtr, indexPtr, ewPtr, offset, maxX, maxChars, |
| 744 |
noCharsYet, wrapMode, chunkPtr) |
| 745 |
TkText *textPtr; |
| 746 |
TkTextIndex *indexPtr; |
| 747 |
TkTextSegment *ewPtr; |
| 748 |
int offset; |
| 749 |
|
| 750 |
int maxX; |
| 751 |
|
| 752 |
int maxChars; |
| 753 |
|
| 754 |
int noCharsYet; |
| 755 |
|
| 756 |
TkWrapMode wrapMode; |
| 757 |
|
| 758 |
register TkTextDispChunk *chunkPtr; |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
{ |
| 763 |
int width, height; |
| 764 |
|
| 765 |
if (offset != 0) { |
| 766 |
panic("Non-zero offset in EmbWinLayoutProc"); |
| 767 |
} |
| 768 |
|
| 769 |
if ((ewPtr->body.ew.tkwin == NULL) && (ewPtr->body.ew.create != NULL)) { |
| 770 |
int code, new; |
| 771 |
Tcl_Obj *name; |
| 772 |
Tk_Window ancestor; |
| 773 |
Tcl_HashEntry *hPtr; |
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
code = LangDoCallback(textPtr->interp, ewPtr->body.ew.create, 1, 0); |
| 784 |
if (code != TCL_OK) { |
| 785 |
createError: |
| 786 |
Tcl_BackgroundError(textPtr->interp); |
| 787 |
goto gotWindow; |
| 788 |
} |
| 789 |
name = Tcl_GetObjResult(textPtr->interp); |
| 790 |
Tcl_IncrRefCount(name); |
| 791 |
Tcl_ResetResult(textPtr->interp); |
| 792 |
ewPtr->body.ew.tkwin = Tk_NameToWindow(textPtr->interp, |
| 793 |
Tcl_GetString(name), textPtr->tkwin); |
| 794 |
Tcl_DecrRefCount(name); |
| 795 |
if (ewPtr->body.ew.tkwin == NULL) { |
| 796 |
goto createError; |
| 797 |
} |
| 798 |
for (ancestor = textPtr->tkwin; ; |
| 799 |
ancestor = Tk_Parent(ancestor)) { |
| 800 |
if (ancestor == Tk_Parent(ewPtr->body.ew.tkwin)) { |
| 801 |
break; |
| 802 |
} |
| 803 |
if (Tk_TopWinHierarchy(ancestor)) { |
| 804 |
badMaster: |
| 805 |
Tcl_AppendResult(textPtr->interp, "can't embed ", |
| 806 |
Tk_PathName(ewPtr->body.ew.tkwin), " relative to ", |
| 807 |
Tk_PathName(textPtr->tkwin), (char *) NULL); |
| 808 |
Tcl_BackgroundError(textPtr->interp); |
| 809 |
ewPtr->body.ew.tkwin = NULL; |
| 810 |
goto gotWindow; |
| 811 |
} |
| 812 |
} |
| 813 |
if (Tk_TopWinHierarchy(ewPtr->body.ew.tkwin) |
| 814 |
|| (textPtr->tkwin == ewPtr->body.ew.tkwin)) { |
| 815 |
goto badMaster; |
| 816 |
} |
| 817 |
Tk_ManageGeometry(ewPtr->body.ew.tkwin, &textGeomType, |
| 818 |
(ClientData) ewPtr); |
| 819 |
Tk_CreateEventHandler(ewPtr->body.ew.tkwin, StructureNotifyMask, |
| 820 |
EmbWinStructureProc, (ClientData) ewPtr); |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
hPtr = Tcl_CreateHashEntry(&textPtr->windowTable, |
| 831 |
Tk_PathName(ewPtr->body.ew.tkwin), &new); |
| 832 |
Tcl_SetHashValue(hPtr, ewPtr); |
| 833 |
} |
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
gotWindow: |
| 840 |
if (ewPtr->body.ew.tkwin == NULL) { |
| 841 |
width = 0; |
| 842 |
height = 0; |
| 843 |
} else { |
| 844 |
width = Tk_ReqWidth(ewPtr->body.ew.tkwin) + 2*ewPtr->body.ew.padX; |
| 845 |
height = Tk_ReqHeight(ewPtr->body.ew.tkwin) + 2*ewPtr->body.ew.padY; |
| 846 |
} |
| 847 |
if ((width > (maxX - chunkPtr->x)) |
| 848 |
&& !noCharsYet && (textPtr->wrapMode != TEXT_WRAPMODE_NONE)) { |
| 849 |
return 0; |
| 850 |
} |
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
chunkPtr->displayProc = EmbWinDisplayProc; |
| 857 |
chunkPtr->undisplayProc = EmbWinUndisplayProc; |
| 858 |
chunkPtr->measureProc = (Tk_ChunkMeasureProc *) NULL; |
| 859 |
chunkPtr->bboxProc = EmbWinBboxProc; |
| 860 |
chunkPtr->numBytes = 1; |
| 861 |
if (ewPtr->body.ew.align == ALIGN_BASELINE) { |
| 862 |
chunkPtr->minAscent = height - ewPtr->body.ew.padY; |
| 863 |
chunkPtr->minDescent = ewPtr->body.ew.padY; |
| 864 |
chunkPtr->minHeight = 0; |
| 865 |
} else { |
| 866 |
chunkPtr->minAscent = 0; |
| 867 |
chunkPtr->minDescent = 0; |
| 868 |
chunkPtr->minHeight = height; |
| 869 |
} |
| 870 |
chunkPtr->width = width; |
| 871 |
chunkPtr->breakIndex = -1; |
| 872 |
chunkPtr->breakIndex = 1; |
| 873 |
chunkPtr->clientData = (ClientData) ewPtr; |
| 874 |
ewPtr->body.ew.chunkCount += 1; |
| 875 |
return 1; |
| 876 |
} |
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
static void |
| 897 |
EmbWinCheckProc(ewPtr, linePtr) |
| 898 |
TkTextSegment *ewPtr; |
| 899 |
TkTextLine *linePtr; |
| 900 |
{ |
| 901 |
if (ewPtr->nextPtr == NULL) { |
| 902 |
panic("EmbWinCheckProc: embedded window is last segment in line"); |
| 903 |
} |
| 904 |
if (ewPtr->size != 1) { |
| 905 |
panic("EmbWinCheckProc: embedded window has size %d", ewPtr->size); |
| 906 |
} |
| 907 |
} |
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
static void |
| 929 |
EmbWinDisplayProc(chunkPtr, x, y, lineHeight, baseline, display, dst, screenY) |
| 930 |
TkTextDispChunk *chunkPtr; |
| 931 |
int x; |
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
int y; |
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
int lineHeight; |
| 940 |
int baseline; |
| 941 |
Display *display; |
| 942 |
Drawable dst; |
| 943 |
int screenY; |
| 944 |
|
| 945 |
{ |
| 946 |
TkTextSegment *ewPtr = (TkTextSegment *) chunkPtr->clientData; |
| 947 |
int lineX, windowX, windowY, width, height; |
| 948 |
Tk_Window tkwin; |
| 949 |
|
| 950 |
tkwin = ewPtr->body.ew.tkwin; |
| 951 |
if (tkwin == NULL) { |
| 952 |
return; |
| 953 |
} |
| 954 |
if ((x + chunkPtr->width) <= 0) { |
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
if (ewPtr->body.ew.textPtr->tkwin != Tk_Parent(tkwin)) { |
| 960 |
Tk_UnmaintainGeometry(tkwin, ewPtr->body.ew.textPtr->tkwin); |
| 961 |
} else { |
| 962 |
Tk_UnmapWindow(tkwin); |
| 963 |
} |
| 964 |
return; |
| 965 |
} |
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
EmbWinBboxProc(chunkPtr, 0, screenY, lineHeight, baseline, &lineX, |
| 973 |
&windowY, &width, &height); |
| 974 |
windowX = lineX - chunkPtr->x + x; |
| 975 |
|
| 976 |
if (ewPtr->body.ew.textPtr->tkwin == Tk_Parent(tkwin)) { |
| 977 |
if ((windowX != Tk_X(tkwin)) || (windowY != Tk_Y(tkwin)) |
| 978 |
|| (Tk_ReqWidth(tkwin) != Tk_Width(tkwin)) |
| 979 |
|| (height != Tk_Height(tkwin))) { |
| 980 |
Tk_MoveResizeWindow(tkwin, windowX, windowY, width, height); |
| 981 |
} |
| 982 |
Tk_MapWindow(tkwin); |
| 983 |
} else { |
| 984 |
Tk_MaintainGeometry(tkwin, ewPtr->body.ew.textPtr->tkwin, |
| 985 |
windowX, windowY, width, height); |
| 986 |
} |
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
ewPtr->body.ew.displayed = 1; |
| 993 |
} |
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
static void |
| 1014 |
EmbWinUndisplayProc(textPtr, chunkPtr) |
| 1015 |
TkText *textPtr; |
| 1016 |
|
| 1017 |
TkTextDispChunk *chunkPtr; |
| 1018 |
{ |
| 1019 |
TkTextSegment *ewPtr = (TkTextSegment *) chunkPtr->clientData; |
| 1020 |
|
| 1021 |
ewPtr->body.ew.chunkCount--; |
| 1022 |
if (ewPtr->body.ew.chunkCount == 0) { |
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
ewPtr->body.ew.displayed = 0; |
| 1032 |
Tcl_DoWhenIdle(EmbWinDelayedUnmap, (ClientData) ewPtr); |
| 1033 |
} |
| 1034 |
} |
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
static void |
| 1060 |
EmbWinBboxProc(chunkPtr, index, y, lineHeight, baseline, xPtr, yPtr, |
| 1061 |
widthPtr, heightPtr) |
| 1062 |
TkTextDispChunk *chunkPtr; |
| 1063 |
int index; |
| 1064 |
|
| 1065 |
int y; |
| 1066 |
|
| 1067 |
int lineHeight; |
| 1068 |
int baseline; |
| 1069 |
|
| 1070 |
int *xPtr, *yPtr; |
| 1071 |
|
| 1072 |
int *widthPtr; |
| 1073 |
|
| 1074 |
int *heightPtr; |
| 1075 |
|
| 1076 |
{ |
| 1077 |
TkTextSegment *ewPtr = (TkTextSegment *) chunkPtr->clientData; |
| 1078 |
Tk_Window tkwin; |
| 1079 |
|
| 1080 |
tkwin = ewPtr->body.ew.tkwin; |
| 1081 |
if (tkwin != NULL) { |
| 1082 |
*widthPtr = Tk_ReqWidth(tkwin); |
| 1083 |
*heightPtr = Tk_ReqHeight(tkwin); |
| 1084 |
} else { |
| 1085 |
*widthPtr = 0; |
| 1086 |
*heightPtr = 0; |
| 1087 |
} |
| 1088 |
*xPtr = chunkPtr->x + ewPtr->body.ew.padX; |
| 1089 |
if (ewPtr->body.ew.stretch) { |
| 1090 |
if (ewPtr->body.ew.align == ALIGN_BASELINE) { |
| 1091 |
*heightPtr = baseline - ewPtr->body.ew.padY; |
| 1092 |
} else { |
| 1093 |
*heightPtr = lineHeight - 2*ewPtr->body.ew.padY; |
| 1094 |
} |
| 1095 |
} |
| 1096 |
switch (ewPtr->body.ew.align) { |
| 1097 |
case ALIGN_BOTTOM: |
| 1098 |
*yPtr = y + (lineHeight - *heightPtr - ewPtr->body.ew.padY); |
| 1099 |
break; |
| 1100 |
case ALIGN_CENTER: |
| 1101 |
*yPtr = y + (lineHeight - *heightPtr)/2; |
| 1102 |
break; |
| 1103 |
case ALIGN_TOP: |
| 1104 |
*yPtr = y + ewPtr->body.ew.padY; |
| 1105 |
break; |
| 1106 |
case ALIGN_BASELINE: |
| 1107 |
*yPtr = y + (baseline - *heightPtr); |
| 1108 |
break; |
| 1109 |
} |
| 1110 |
} |
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
static void |
| 1132 |
EmbWinDelayedUnmap(clientData) |
| 1133 |
ClientData clientData; |
| 1134 |
|
| 1135 |
{ |
| 1136 |
TkTextSegment *ewPtr = (TkTextSegment *) clientData; |
| 1137 |
|
| 1138 |
if (!ewPtr->body.ew.displayed && (ewPtr->body.ew.tkwin != NULL)) { |
| 1139 |
if (ewPtr->body.ew.textPtr->tkwin != Tk_Parent(ewPtr->body.ew.tkwin)) { |
| 1140 |
Tk_UnmaintainGeometry(ewPtr->body.ew.tkwin, |
| 1141 |
ewPtr->body.ew.textPtr->tkwin); |
| 1142 |
} else { |
| 1143 |
Tk_UnmapWindow(ewPtr->body.ew.tkwin); |
| 1144 |
} |
| 1145 |
} |
| 1146 |
} |
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
int |
| 1169 |
TkTextWindowIndex(textPtr, name, indexPtr) |
| 1170 |
TkText *textPtr; |
| 1171 |
CONST char *name; |
| 1172 |
TkTextIndex *indexPtr; |
| 1173 |
{ |
| 1174 |
Tcl_HashEntry *hPtr; |
| 1175 |
TkTextSegment *ewPtr; |
| 1176 |
|
| 1177 |
hPtr = Tcl_FindHashEntry(&textPtr->windowTable, name); |
| 1178 |
if (hPtr == NULL) { |
| 1179 |
return 0; |
| 1180 |
} |
| 1181 |
ewPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); |
| 1182 |
indexPtr->tree = textPtr->tree; |
| 1183 |
indexPtr->linePtr = ewPtr->body.ew.linePtr; |
| 1184 |
indexPtr->byteIndex = TkTextSegToOffset(ewPtr, indexPtr->linePtr); |
| 1185 |
return 1; |
| 1186 |
} |
| 1187 |
|