| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include "tkPort.h" |
| 16 |
#include "tkInt.h" |
| 17 |
#include "tkCanvases.h" |
| 18 |
#include "default.h" |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
typedef struct TextItem { |
| 25 |
Tk_Item header; |
| 26 |
|
| 27 |
Tk_CanvasTextInfo *textInfoPtr; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
double x, y; |
| 38 |
int insertPos; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
Tk_Anchor anchor; |
| 46 |
Tk_TSOffset tsoffset; |
| 47 |
XColor *color; |
| 48 |
XColor *activeColor; |
| 49 |
XColor *disabledColor; |
| 50 |
Tk_Font tkfont; |
| 51 |
Tk_Justify justify; |
| 52 |
Pixmap stipple; |
| 53 |
Pixmap activeStipple; |
| 54 |
Pixmap disabledStipple; |
| 55 |
char *text; |
| 56 |
int width; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
int numChars; |
| 65 |
int numBytes; |
| 66 |
Tk_TextLayout textLayout; |
| 67 |
int leftEdge; |
| 68 |
|
| 69 |
|
| 70 |
int rightEdge; |
| 71 |
|
| 72 |
|
| 73 |
GC gc; |
| 74 |
GC selTextGC; |
| 75 |
GC cursorOffGC; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
Tk_Tile tile; |
| 80 |
} TextItem; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
static Tk_CustomOption stateOption = { |
| 87 |
TkStateParseProc, |
| 88 |
TkStatePrintProc, (ClientData) 2 |
| 89 |
}; |
| 90 |
static Tk_CustomOption tagsOption = { |
| 91 |
Tk_CanvasTagsParseProc, |
| 92 |
Tk_CanvasTagsPrintProc, (ClientData) NULL |
| 93 |
}; |
| 94 |
static Tk_CustomOption tileOption = { |
| 95 |
Tk_TileParseProc, |
| 96 |
Tk_TilePrintProc, (ClientData) NULL |
| 97 |
}; |
| 98 |
static Tk_CustomOption offsetOption = { |
| 99 |
Tk_OffsetParseProc, |
| 100 |
Tk_OffsetPrintProc, (ClientData) (TK_OFFSET_RELATIVE) |
| 101 |
}; |
| 102 |
|
| 103 |
static Tk_ConfigSpec configSpecs[] = { |
| 104 |
{TK_CONFIG_COLOR, "-activefill", (char *) NULL, (char *) NULL, |
| 105 |
(char *) NULL, Tk_Offset(TextItem, activeColor), TK_CONFIG_NULL_OK}, |
| 106 |
{TK_CONFIG_BITMAP, "-activestipple", (char *) NULL, (char *) NULL, |
| 107 |
(char *) NULL, Tk_Offset(TextItem, activeStipple), TK_CONFIG_NULL_OK}, |
| 108 |
{TK_CONFIG_ANCHOR, "-anchor", (char *) NULL, (char *) NULL, |
| 109 |
"center", Tk_Offset(TextItem, anchor), |
| 110 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 111 |
{TK_CONFIG_COLOR, "-disabledfill", (char *) NULL, (char *) NULL, |
| 112 |
(char *) NULL, Tk_Offset(TextItem, disabledColor), TK_CONFIG_NULL_OK}, |
| 113 |
{TK_CONFIG_BITMAP, "-disabledstipple", (char *) NULL, (char *) NULL, |
| 114 |
(char *) NULL, Tk_Offset(TextItem, disabledStipple), TK_CONFIG_NULL_OK}, |
| 115 |
{TK_CONFIG_COLOR, "-fill", (char *) NULL, (char *) NULL, |
| 116 |
"black", Tk_Offset(TextItem, color), TK_CONFIG_NULL_OK}, |
| 117 |
{TK_CONFIG_FONT, "-font", (char *) NULL, (char *) NULL, |
| 118 |
DEF_CANVTEXT_FONT, Tk_Offset(TextItem, tkfont), 0}, |
| 119 |
{TK_CONFIG_JUSTIFY, "-justify", (char *) NULL, (char *) NULL, |
| 120 |
"left", Tk_Offset(TextItem, justify), |
| 121 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 122 |
{TK_CONFIG_CUSTOM, "-offset", (char *) NULL, (char *) NULL, |
| 123 |
"0 0", Tk_Offset(TextItem, tsoffset), |
| 124 |
TK_CONFIG_DONT_SET_DEFAULT, &offsetOption}, |
| 125 |
{TK_CONFIG_CUSTOM, "-state", (char *) NULL, (char *) NULL, |
| 126 |
(char *) NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, |
| 127 |
&stateOption}, |
| 128 |
{TK_CONFIG_BITMAP, "-stipple", (char *) NULL, (char *) NULL, |
| 129 |
(char *) NULL, Tk_Offset(TextItem, stipple), TK_CONFIG_NULL_OK}, |
| 130 |
{TK_CONFIG_CUSTOM, "-tags", (char *) NULL, (char *) NULL, |
| 131 |
(char *) NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, |
| 132 |
{TK_CONFIG_STRING, "-text", (char *) NULL, (char *) NULL, |
| 133 |
"", Tk_Offset(TextItem, text), 0}, |
| 134 |
{TK_CONFIG_CALLBACK, "-updatecommand", (char *) NULL, (char *) NULL, |
| 135 |
(char *) NULL, Tk_Offset(Tk_Item, updateCmd), TK_CONFIG_NULL_OK}, |
| 136 |
{TK_CONFIG_PIXELS, "-width", (char *) NULL, (char *) NULL, |
| 137 |
"0", Tk_Offset(TextItem, width), TK_CONFIG_DONT_SET_DEFAULT}, |
| 138 |
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, |
| 139 |
(char *) NULL, 0, 0} |
| 140 |
}; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
static void ComputeTextBbox _ANSI_ARGS_((Tk_Canvas canvas, |
| 147 |
TextItem *textPtr)); |
| 148 |
static int ConfigureText _ANSI_ARGS_((Tcl_Interp *interp, |
| 149 |
Tk_Canvas canvas, Tk_Item *itemPtr, int argc, |
| 150 |
Tcl_Obj *CONST objv[], int flags)); |
| 151 |
static int CreateText _ANSI_ARGS_((Tcl_Interp *interp, |
| 152 |
Tk_Canvas canvas, struct Tk_Item *itemPtr, |
| 153 |
int argc, Tcl_Obj *CONST objv[])); |
| 154 |
static void DeleteText _ANSI_ARGS_((Tk_Canvas canvas, |
| 155 |
Tk_Item *itemPtr, Display *display)); |
| 156 |
static void DisplayCanvText _ANSI_ARGS_((Tk_Canvas canvas, |
| 157 |
Tk_Item *itemPtr, Display *display, Drawable dst, |
| 158 |
int x, int y, int width, int height)); |
| 159 |
static int GetSelText _ANSI_ARGS_((Tk_Canvas canvas, |
| 160 |
Tk_Item *itemPtr, int offset, char *buffer, |
| 161 |
int maxBytes)); |
| 162 |
static int GetTextIndex _ANSI_ARGS_((Tcl_Interp *interp, |
| 163 |
Tk_Canvas canvas, Tk_Item *itemPtr, |
| 164 |
Tcl_Obj *obj, int *indexPtr)); |
| 165 |
static void ScaleText _ANSI_ARGS_((Tk_Canvas canvas, |
| 166 |
Tk_Item *itemPtr, double originX, double originY, |
| 167 |
double scaleX, double scaleY)); |
| 168 |
static void SetTextCursor _ANSI_ARGS_((Tk_Canvas canvas, |
| 169 |
Tk_Item *itemPtr, int index)); |
| 170 |
static int TextCoords _ANSI_ARGS_((Tcl_Interp *interp, |
| 171 |
Tk_Canvas canvas, Tk_Item *itemPtr, |
| 172 |
int argc, Tcl_Obj *CONST objv[])); |
| 173 |
static void TextDeleteChars _ANSI_ARGS_((Tk_Canvas canvas, |
| 174 |
Tk_Item *itemPtr, int first, int last)); |
| 175 |
static void TextInsert _ANSI_ARGS_((Tk_Canvas canvas, |
| 176 |
Tk_Item *itemPtr, int beforeThis, Tcl_Obj *string)); |
| 177 |
static int TextToArea _ANSI_ARGS_((Tk_Canvas canvas, |
| 178 |
Tk_Item *itemPtr, double *rectPtr)); |
| 179 |
static double TextToPoint _ANSI_ARGS_((Tk_Canvas canvas, |
| 180 |
Tk_Item *itemPtr, double *pointPtr)); |
| 181 |
static int TextToPostscript _ANSI_ARGS_((Tcl_Interp *interp, |
| 182 |
Tk_Canvas canvas, Tk_Item *itemPtr, int prepass)); |
| 183 |
static void TranslateText _ANSI_ARGS_((Tk_Canvas canvas, |
| 184 |
Tk_Item *itemPtr, double deltaX, double deltaY)); |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
Tk_ItemType tkTextType = { |
| 192 |
"text", |
| 193 |
sizeof(TextItem), |
| 194 |
CreateText, |
| 195 |
configSpecs, |
| 196 |
ConfigureText, |
| 197 |
TextCoords, |
| 198 |
DeleteText, |
| 199 |
DisplayCanvText, |
| 200 |
TK_ITEM_VISITOR_SUPPORT|TK_CONFIG_OBJS, |
| 201 |
TextToPoint, |
| 202 |
TextToArea, |
| 203 |
TextToPostscript, |
| 204 |
ScaleText, |
| 205 |
TranslateText, |
| 206 |
GetTextIndex, |
| 207 |
SetTextCursor, |
| 208 |
GetSelText, |
| 209 |
TextInsert, |
| 210 |
TextDeleteChars, |
| 211 |
(Tk_ItemType *) NULL, |
| 212 |
(Tk_ItemBboxProc *) ComputeTextBbox, |
| 213 |
Tk_Offset(Tk_VisitorType, visitText), |
| 214 |
NULL, |
| 215 |
NULL |
| 216 |
}; |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
static int |
| 239 |
CreateText(interp, canvas, itemPtr, objc, objv) |
| 240 |
Tcl_Interp *interp; |
| 241 |
Tk_Canvas canvas; |
| 242 |
Tk_Item *itemPtr; |
| 243 |
|
| 244 |
int objc; |
| 245 |
Tcl_Obj *CONST objv[]; |
| 246 |
{ |
| 247 |
TextItem *textPtr = (TextItem *) itemPtr; |
| 248 |
int i; |
| 249 |
|
| 250 |
if (objc == 0) { |
| 251 |
panic("canvas did not pass any coords\n"); |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
textPtr->textInfoPtr = Tk_CanvasGetTextInfo(canvas); |
| 260 |
|
| 261 |
textPtr->insertPos = 0; |
| 262 |
|
| 263 |
textPtr->anchor = TK_ANCHOR_CENTER; |
| 264 |
textPtr->tsoffset.flags = 0; |
| 265 |
textPtr->tsoffset.xoffset = 0; |
| 266 |
textPtr->tsoffset.yoffset = 0; |
| 267 |
textPtr->color = NULL; |
| 268 |
textPtr->activeColor = NULL; |
| 269 |
textPtr->disabledColor = NULL; |
| 270 |
textPtr->tkfont = NULL; |
| 271 |
textPtr->justify = TK_JUSTIFY_LEFT; |
| 272 |
textPtr->stipple = None; |
| 273 |
textPtr->activeStipple = None; |
| 274 |
textPtr->disabledStipple = None; |
| 275 |
textPtr->text = NULL; |
| 276 |
textPtr->width = 0; |
| 277 |
|
| 278 |
textPtr->numChars = 0; |
| 279 |
textPtr->numBytes = 0; |
| 280 |
textPtr->textLayout = NULL; |
| 281 |
textPtr->leftEdge = 0; |
| 282 |
textPtr->rightEdge = 0; |
| 283 |
textPtr->gc = None; |
| 284 |
textPtr->selTextGC = None; |
| 285 |
textPtr->cursorOffGC = None; |
| 286 |
textPtr->tile = NULL; |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
if (objc == 1) { |
| 294 |
i = 1; |
| 295 |
} else { |
| 296 |
char *arg = Tcl_GetString(objv[1]); |
| 297 |
i = 2; |
| 298 |
if ((arg[0] == '-') && (arg[1] >= 'a') && (arg[1] <= 'z')) { |
| 299 |
i = 1; |
| 300 |
} |
| 301 |
} |
| 302 |
if ((TextCoords(interp, canvas, itemPtr, i, objv) != TCL_OK)) { |
| 303 |
goto error; |
| 304 |
} |
| 305 |
if (ConfigureText(interp, canvas, itemPtr, objc-i, objv+i, 0) == TCL_OK) { |
| 306 |
return TCL_OK; |
| 307 |
} |
| 308 |
|
| 309 |
error: |
| 310 |
DeleteText(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas))); |
| 311 |
return TCL_ERROR; |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
static int |
| 333 |
TextCoords(interp, canvas, itemPtr, objc, objv) |
| 334 |
Tcl_Interp *interp; |
| 335 |
Tk_Canvas canvas; |
| 336 |
Tk_Item *itemPtr; |
| 337 |
|
| 338 |
int objc; |
| 339 |
Tcl_Obj *CONST objv[]; |
| 340 |
{ |
| 341 |
TextItem *textPtr = (TextItem *) itemPtr; |
| 342 |
|
| 343 |
if (objc == 0) { |
| 344 |
Tcl_Obj *obj = Tcl_NewObj(); |
| 345 |
Tcl_Obj *subobj = Tcl_NewDoubleObj(textPtr->x); |
| 346 |
Tcl_ListObjAppendElement(interp, obj, subobj); |
| 347 |
subobj = Tcl_NewDoubleObj(textPtr->y); |
| 348 |
Tcl_ListObjAppendElement(interp, obj, subobj); |
| 349 |
Tcl_SetObjResult(interp, obj); |
| 350 |
} else if (objc < 3) { |
| 351 |
if (objc==1) { |
| 352 |
if (Tcl_ListObjGetElements(interp, objv[0], &objc, |
| 353 |
(Tcl_Obj ***) &objv) != TCL_OK) { |
| 354 |
return TCL_ERROR; |
| 355 |
} else if (objc != 2) { |
| 356 |
char buf[64 + TCL_INTEGER_SPACE]; |
| 357 |
|
| 358 |
sprintf(buf, "wrong # coordinates: expected 2, got %d", objc); |
| 359 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 360 |
return TCL_ERROR; |
| 361 |
} |
| 362 |
} |
| 363 |
if ((Tk_CanvasGetCoordFromObj(interp, canvas, objv[0], &textPtr->x) != TCL_OK) |
| 364 |
|| (Tk_CanvasGetCoordFromObj(interp, canvas, objv[1], |
| 365 |
&textPtr->y) != TCL_OK)) { |
| 366 |
return TCL_ERROR; |
| 367 |
} |
| 368 |
ComputeTextBbox(canvas, textPtr); |
| 369 |
} else { |
| 370 |
char buf[64 + TCL_INTEGER_SPACE]; |
| 371 |
|
| 372 |
sprintf(buf, "wrong # coordinates: expected 0 or 2, got %d", objc); |
| 373 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 374 |
return TCL_ERROR; |
| 375 |
} |
| 376 |
return TCL_OK; |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
static int |
| 399 |
ConfigureText(interp, canvas, itemPtr, objc, objv, flags) |
| 400 |
Tcl_Interp *interp; |
| 401 |
Tk_Canvas canvas; |
| 402 |
Tk_Item *itemPtr; |
| 403 |
int objc; |
| 404 |
Tcl_Obj *CONST objv[]; |
| 405 |
int flags; |
| 406 |
{ |
| 407 |
TextItem *textPtr = (TextItem *) itemPtr; |
| 408 |
XGCValues gcValues; |
| 409 |
GC newGC, newSelGC; |
| 410 |
unsigned long mask; |
| 411 |
Tk_Window tkwin; |
| 412 |
Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr; |
| 413 |
XColor *selBgColorPtr; |
| 414 |
XColor *color; |
| 415 |
Pixmap stipple; |
| 416 |
Tk_State state; |
| 417 |
Tk_Tile tile; |
| 418 |
|
| 419 |
tkwin = Tk_CanvasTkwin(canvas); |
| 420 |
if (TCL_OK != Tk_ConfigureWidget(interp, tkwin, configSpecs, objc, |
| 421 |
(CONST84 Tcl_Obj *CONST*) objv, (char *) textPtr, flags|TK_CONFIG_OBJS)) { |
| 422 |
return TCL_ERROR; |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
state = Tk_GetItemState(canvas, itemPtr); |
| 431 |
|
| 432 |
if (textPtr->activeColor != NULL || |
| 433 |
textPtr->activeStipple != None) { |
| 434 |
itemPtr->redraw_flags |= TK_ITEM_STATE_DEPENDANT; |
| 435 |
} else { |
| 436 |
itemPtr->redraw_flags &= ~TK_ITEM_STATE_DEPENDANT; |
| 437 |
} |
| 438 |
|
| 439 |
tile = textPtr->tile; |
| 440 |
color = textPtr->color; |
| 441 |
stipple = textPtr->stipple; |
| 442 |
if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { |
| 443 |
if (textPtr->activeColor!=NULL) { |
| 444 |
color = textPtr->activeColor; |
| 445 |
} |
| 446 |
if (textPtr->activeStipple!=None) { |
| 447 |
stipple = textPtr->activeStipple; |
| 448 |
} |
| 449 |
} else if (state==TK_STATE_DISABLED) { |
| 450 |
if (textPtr->disabledColor!=NULL) { |
| 451 |
color = textPtr->disabledColor; |
| 452 |
} |
| 453 |
if (textPtr->disabledStipple!=None) { |
| 454 |
stipple = textPtr->disabledStipple; |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
newGC = newSelGC = None; |
| 459 |
if (textPtr->tkfont != NULL) { |
| 460 |
gcValues.font = Tk_FontId(textPtr->tkfont); |
| 461 |
mask = GCFont; |
| 462 |
if (color != NULL) { |
| 463 |
gcValues.foreground = color->pixel; |
| 464 |
mask |= GCForeground; |
| 465 |
if (stipple != None) { |
| 466 |
gcValues.stipple = stipple; |
| 467 |
gcValues.fill_style = FillStippled; |
| 468 |
mask |= GCStipple|GCFillStyle; |
| 469 |
} |
| 470 |
newGC = Tk_GetGC(tkwin, mask, &gcValues); |
| 471 |
} |
| 472 |
mask &= ~(GCTile|GCFillStyle|GCStipple); |
| 473 |
if (stipple != None) { |
| 474 |
gcValues.stipple = stipple; |
| 475 |
gcValues.fill_style = FillStippled; |
| 476 |
mask |= GCStipple|GCFillStyle; |
| 477 |
} |
| 478 |
gcValues.foreground = textInfoPtr->selFgColorPtr->pixel; |
| 479 |
newSelGC = Tk_GetGC(tkwin, mask|GCForeground, &gcValues); |
| 480 |
} |
| 481 |
if (textPtr->gc != None) { |
| 482 |
Tk_FreeGC(Tk_Display(tkwin), textPtr->gc); |
| 483 |
} |
| 484 |
textPtr->gc = newGC; |
| 485 |
if (textPtr->selTextGC != None) { |
| 486 |
Tk_FreeGC(Tk_Display(tkwin), textPtr->selTextGC); |
| 487 |
} |
| 488 |
textPtr->selTextGC = newSelGC; |
| 489 |
|
| 490 |
selBgColorPtr = Tk_3DBorderColor(textInfoPtr->selBorder); |
| 491 |
if (Tk_3DBorderColor(textInfoPtr->insertBorder)->pixel |
| 492 |
== selBgColorPtr->pixel) { |
| 493 |
if (selBgColorPtr->pixel == BlackPixelOfScreen(Tk_Screen(tkwin))) { |
| 494 |
gcValues.foreground = WhitePixelOfScreen(Tk_Screen(tkwin)); |
| 495 |
} else { |
| 496 |
gcValues.foreground = BlackPixelOfScreen(Tk_Screen(tkwin)); |
| 497 |
} |
| 498 |
newGC = Tk_GetGC(tkwin, GCForeground, &gcValues); |
| 499 |
} else { |
| 500 |
newGC = None; |
| 501 |
} |
| 502 |
if (textPtr->cursorOffGC != None) { |
| 503 |
Tk_FreeGC(Tk_Display(tkwin), textPtr->cursorOffGC); |
| 504 |
} |
| 505 |
textPtr->cursorOffGC = newGC; |
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
textPtr->numBytes = strlen(textPtr->text); |
| 514 |
textPtr->numChars = Tcl_NumUtfChars(textPtr->text, textPtr->numBytes); |
| 515 |
if (textInfoPtr->selItemPtr == itemPtr) { |
| 516 |
|
| 517 |
if (textInfoPtr->selectFirst >= textPtr->numChars) { |
| 518 |
textInfoPtr->selItemPtr = NULL; |
| 519 |
} else { |
| 520 |
if (textInfoPtr->selectLast >= textPtr->numChars) { |
| 521 |
textInfoPtr->selectLast = textPtr->numChars - 1; |
| 522 |
} |
| 523 |
if ((textInfoPtr->anchorItemPtr == itemPtr) |
| 524 |
&& (textInfoPtr->selectAnchor >= textPtr->numChars)) { |
| 525 |
textInfoPtr->selectAnchor = textPtr->numChars - 1; |
| 526 |
} |
| 527 |
} |
| 528 |
} |
| 529 |
if (textPtr->insertPos >= textPtr->numChars) { |
| 530 |
textPtr->insertPos = textPtr->numChars; |
| 531 |
} |
| 532 |
|
| 533 |
ComputeTextBbox(canvas, textPtr); |
| 534 |
return TCL_OK; |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
static void |
| 555 |
DeleteText(canvas, itemPtr, display) |
| 556 |
Tk_Canvas canvas; |
| 557 |
Tk_Item *itemPtr; |
| 558 |
Display *display; |
| 559 |
{ |
| 560 |
TextItem *textPtr = (TextItem *) itemPtr; |
| 561 |
|
| 562 |
if (textPtr->color != NULL) { |
| 563 |
Tk_FreeColor(textPtr->color); |
| 564 |
} |
| 565 |
if (textPtr->activeColor != NULL) { |
| 566 |
Tk_FreeColor(textPtr->activeColor); |
| 567 |
} |
| 568 |
if (textPtr->disabledColor != NULL) { |
| 569 |
Tk_FreeColor(textPtr->disabledColor); |
| 570 |
} |
| 571 |
Tk_FreeFont(textPtr->tkfont); |
| 572 |
if (textPtr->stipple != None) { |
| 573 |
Tk_FreeBitmap(display, textPtr->stipple); |
| 574 |
} |
| 575 |
if (textPtr->activeStipple != None) { |
| 576 |
Tk_FreeBitmap(display, textPtr->activeStipple); |
| 577 |
} |
| 578 |
if (textPtr->disabledStipple != None) { |
| 579 |
Tk_FreeBitmap(display, textPtr->disabledStipple); |
| 580 |
} |
| 581 |
if (textPtr->text != NULL) { |
| 582 |
ckfree(textPtr->text); |
| 583 |
} |
| 584 |
|
| 585 |
Tk_FreeTextLayout(textPtr->textLayout); |
| 586 |
if (textPtr->gc != None) { |
| 587 |
Tk_FreeGC(display, textPtr->gc); |
| 588 |
} |
| 589 |
if (textPtr->selTextGC != None) { |
| 590 |
Tk_FreeGC(display, textPtr->selTextGC); |
| 591 |
} |
| 592 |
if (textPtr->cursorOffGC != None) { |
| 593 |
Tk_FreeGC(display, textPtr->cursorOffGC); |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
static void |
| 619 |
ComputeTextBbox(canvas, textPtr) |
| 620 |
Tk_Canvas canvas; |
| 621 |
TextItem *textPtr; |
| 622 |
{ |
| 623 |
Tk_CanvasTextInfo *textInfoPtr; |
| 624 |
int leftX, topY, width, height, fudge; |
| 625 |
Tk_State state = Tk_GetItemState(canvas, &textPtr->header); |
| 626 |
|
| 627 |
Tk_FreeTextLayout(textPtr->textLayout); |
| 628 |
textPtr->textLayout = Tk_ComputeTextLayout(textPtr->tkfont, |
| 629 |
textPtr->text, textPtr->numChars, textPtr->width, |
| 630 |
textPtr->justify, 0, &width, &height); |
| 631 |
|
| 632 |
if (state == TK_STATE_HIDDEN || textPtr->color == NULL) { |
| 633 |
width = height = 0; |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
leftX = (int) floor(textPtr->x + 0.5); |
| 642 |
topY = (int) floor(textPtr->y + 0.5); |
| 643 |
switch (textPtr->anchor) { |
| 644 |
case TK_ANCHOR_NW: |
| 645 |
case TK_ANCHOR_N: |
| 646 |
case TK_ANCHOR_NE: |
| 647 |
break; |
| 648 |
|
| 649 |
case TK_ANCHOR_W: |
| 650 |
case TK_ANCHOR_CENTER: |
| 651 |
case TK_ANCHOR_E: |
| 652 |
topY -= height / 2; |
| 653 |
break; |
| 654 |
|
| 655 |
case TK_ANCHOR_SW: |
| 656 |
case TK_ANCHOR_S: |
| 657 |
case TK_ANCHOR_SE: |
| 658 |
topY -= height; |
| 659 |
break; |
| 660 |
} |
| 661 |
switch (textPtr->anchor) { |
| 662 |
case TK_ANCHOR_NW: |
| 663 |
case TK_ANCHOR_W: |
| 664 |
case TK_ANCHOR_SW: |
| 665 |
break; |
| 666 |
|
| 667 |
case TK_ANCHOR_N: |
| 668 |
case TK_ANCHOR_CENTER: |
| 669 |
case TK_ANCHOR_S: |
| 670 |
leftX -= width / 2; |
| 671 |
break; |
| 672 |
|
| 673 |
case TK_ANCHOR_NE: |
| 674 |
case TK_ANCHOR_E: |
| 675 |
case TK_ANCHOR_SE: |
| 676 |
leftX -= width; |
| 677 |
break; |
| 678 |
} |
| 679 |
|
| 680 |
textPtr->leftEdge = leftX; |
| 681 |
textPtr->rightEdge = leftX + width; |
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
textInfoPtr = textPtr->textInfoPtr; |
| 691 |
fudge = (textInfoPtr->insertWidth + 1) / 2; |
| 692 |
if (textInfoPtr->selBorderWidth > fudge) { |
| 693 |
fudge = textInfoPtr->selBorderWidth; |
| 694 |
} |
| 695 |
textPtr->header.x1 = leftX - fudge; |
| 696 |
textPtr->header.y1 = topY; |
| 697 |
textPtr->header.x2 = leftX + width + fudge; |
| 698 |
textPtr->header.y2 = topY + height; |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
static void |
| 720 |
DisplayCanvText(canvas, itemPtr, display, drawable, x, y, width, height) |
| 721 |
Tk_Canvas canvas; |
| 722 |
Tk_Item *itemPtr; |
| 723 |
Display *display; |
| 724 |
Drawable drawable; |
| 725 |
int x, y, width, height; |
| 726 |
|
| 727 |
{ |
| 728 |
TextItem *textPtr; |
| 729 |
Tk_CanvasTextInfo *textInfoPtr; |
| 730 |
int selFirstChar, selLastChar; |
| 731 |
short drawableX, drawableY; |
| 732 |
Pixmap stipple; |
| 733 |
Tk_Tile tile; |
| 734 |
Tk_State state = Tk_GetItemState(canvas, itemPtr); |
| 735 |
|
| 736 |
textPtr = (TextItem *) itemPtr; |
| 737 |
textInfoPtr = textPtr->textInfoPtr; |
| 738 |
|
| 739 |
stipple = textPtr->stipple; |
| 740 |
if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { |
| 741 |
if (textPtr->activeStipple!=None) { |
| 742 |
stipple = textPtr->activeStipple; |
| 743 |
} |
| 744 |
} else if (state==TK_STATE_DISABLED) { |
| 745 |
if (textPtr->disabledStipple!=None) { |
| 746 |
stipple = textPtr->disabledStipple; |
| 747 |
} |
| 748 |
} |
| 749 |
|
| 750 |
if (textPtr->gc == None) { |
| 751 |
return; |
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
if (stipple != None) { |
| 761 |
Tk_CanvasSetOffset(canvas, textPtr->gc, &textPtr->tsoffset); |
| 762 |
} |
| 763 |
|
| 764 |
selFirstChar = -1; |
| 765 |
selLastChar = 0; |
| 766 |
|
| 767 |
if (textInfoPtr->selItemPtr == itemPtr) { |
| 768 |
selFirstChar = textInfoPtr->selectFirst; |
| 769 |
selLastChar = textInfoPtr->selectLast; |
| 770 |
if (selLastChar > textPtr->numChars) { |
| 771 |
selLastChar = textPtr->numChars - 1; |
| 772 |
} |
| 773 |
if ((selFirstChar >= 0) && (selFirstChar <= selLastChar)) { |
| 774 |
int xFirst, yFirst, hFirst; |
| 775 |
int xLast, yLast, wLast; |
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
Tk_CharBbox(textPtr->textLayout, selFirstChar, &xFirst, &yFirst, |
| 782 |
NULL, &hFirst); |
| 783 |
Tk_CharBbox(textPtr->textLayout, selLastChar, &xLast, &yLast, |
| 784 |
&wLast, NULL); |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
x = xFirst; |
| 794 |
height = hFirst; |
| 795 |
for (y = yFirst ; y <= yLast; y += height) { |
| 796 |
if (y == yLast) { |
| 797 |
width = xLast + wLast - x; |
| 798 |
} else { |
| 799 |
width = textPtr->rightEdge - textPtr->leftEdge - x; |
| 800 |
} |
| 801 |
Tk_CanvasDrawableCoords(canvas, |
| 802 |
(double) (textPtr->leftEdge + x |
| 803 |
- textInfoPtr->selBorderWidth), |
| 804 |
(double) (textPtr->header.y1 + y), |
| 805 |
&drawableX, &drawableY); |
| 806 |
Tk_Fill3DRectangle(Tk_CanvasTkwin(canvas), drawable, |
| 807 |
textInfoPtr->selBorder, drawableX, drawableY, |
| 808 |
width + 2 * textInfoPtr->selBorderWidth, |
| 809 |
height, textInfoPtr->selBorderWidth, TK_RELIEF_RAISED); |
| 810 |
x = 0; |
| 811 |
} |
| 812 |
} |
| 813 |
} |
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
if ((textInfoPtr->focusItemPtr == itemPtr) && (textInfoPtr->gotFocus)) { |
| 825 |
if (Tk_CharBbox(textPtr->textLayout, textPtr->insertPos, |
| 826 |
&x, &y, NULL, &height)) { |
| 827 |
Tk_CanvasDrawableCoords(canvas, |
| 828 |
(double) (textPtr->leftEdge + x |
| 829 |
- (textInfoPtr->insertWidth / 2)), |
| 830 |
(double) (textPtr->header.y1 + y), |
| 831 |
&drawableX, &drawableY); |
| 832 |
Tk_SetCaretPos(Tk_CanvasTkwin(canvas), drawableX, drawableY, |
| 833 |
height); |
| 834 |
if (textInfoPtr->cursorOn) { |
| 835 |
Tk_Fill3DRectangle(Tk_CanvasTkwin(canvas), drawable, |
| 836 |
textInfoPtr->insertBorder, |
| 837 |
drawableX, drawableY, |
| 838 |
textInfoPtr->insertWidth, height, |
| 839 |
textInfoPtr->insertBorderWidth, TK_RELIEF_RAISED); |
| 840 |
} else if (textPtr->cursorOffGC != None) { |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
XFillRectangle(display, drawable, textPtr->cursorOffGC, |
| 850 |
drawableX, drawableY, |
| 851 |
(unsigned) textInfoPtr->insertWidth, |
| 852 |
(unsigned) height); |
| 853 |
} |
| 854 |
} |
| 855 |
} |
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
Tk_CanvasDrawableCoords(canvas, (double) textPtr->leftEdge, |
| 866 |
(double) textPtr->header.y1, &drawableX, &drawableY); |
| 867 |
Tk_DrawTextLayout(display, drawable, textPtr->gc, textPtr->textLayout, |
| 868 |
drawableX, drawableY, 0, -1); |
| 869 |
|
| 870 |
if ((selFirstChar >= 0) && (textPtr->selTextGC != textPtr->gc)) { |
| 871 |
Tk_DrawTextLayout(display, drawable, textPtr->selTextGC, |
| 872 |
textPtr->textLayout, drawableX, drawableY, selFirstChar, |
| 873 |
selLastChar + 1); |
| 874 |
} |
| 875 |
|
| 876 |
if (stipple != None) { |
| 877 |
XSetTSOrigin(display, textPtr->gc, 0, 0); |
| 878 |
} |
| 879 |
} |
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
static void |
| 900 |
TextInsert(canvas, itemPtr, index, ostring) |
| 901 |
Tk_Canvas canvas; |
| 902 |
Tk_Item *itemPtr; |
| 903 |
int index; |
| 904 |
|
| 905 |
Tcl_Obj *ostring; |
| 906 |
{ |
| 907 |
TextItem *textPtr = (TextItem *) itemPtr; |
| 908 |
int byteIndex, byteCount, charsAdded; |
| 909 |
char *new, *text; |
| 910 |
Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr; |
| 911 |
|
| 912 |
char * string = Tcl_GetString(ostring); |
| 913 |
|
| 914 |
text = textPtr->text; |
| 915 |
|
| 916 |
if (index < 0) { |
| 917 |
index = 0; |
| 918 |
} |
| 919 |
if (index > textPtr->numChars) { |
| 920 |
index = textPtr->numChars; |
| 921 |
} |
| 922 |
byteIndex = Tcl_UtfAtIndex(text, index) - text; |
| 923 |
byteCount = strlen(string); |
| 924 |
if (byteCount == 0) { |
| 925 |
return; |
| 926 |
} |
| 927 |
|
| 928 |
new = (char *) ckalloc((unsigned) textPtr->numBytes + byteCount + 1); |
| 929 |
memcpy(new, text, (size_t) byteIndex); |
| 930 |
strcpy(new + byteIndex, string); |
| 931 |
strcpy(new + byteIndex + byteCount, text + byteIndex); |
| 932 |
|
| 933 |
ckfree(text); |
| 934 |
textPtr->text = new; |
| 935 |
charsAdded = Tcl_NumUtfChars(string, byteCount); |
| 936 |
textPtr->numChars += charsAdded; |
| 937 |
textPtr->numBytes += byteCount; |
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
if (textInfoPtr->selItemPtr == itemPtr) { |
| 945 |
if (textInfoPtr->selectFirst >= index) { |
| 946 |
textInfoPtr->selectFirst += charsAdded; |
| 947 |
} |
| 948 |
if (textInfoPtr->selectLast >= index) { |
| 949 |
textInfoPtr->selectLast += charsAdded; |
| 950 |
} |
| 951 |
if ((textInfoPtr->anchorItemPtr == itemPtr) |
| 952 |
&& (textInfoPtr->selectAnchor >= index)) { |
| 953 |
textInfoPtr->selectAnchor += charsAdded; |
| 954 |
} |
| 955 |
} |
| 956 |
if (textPtr->insertPos >= index) { |
| 957 |
textPtr->insertPos += charsAdded; |
| 958 |
} |
| 959 |
ComputeTextBbox(canvas, textPtr); |
| 960 |
} |
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
static void |
| 981 |
TextDeleteChars(canvas, itemPtr, first, last) |
| 982 |
Tk_Canvas canvas; |
| 983 |
Tk_Item *itemPtr; |
| 984 |
int first; |
| 985 |
|
| 986 |
int last; |
| 987 |
|
| 988 |
{ |
| 989 |
TextItem *textPtr = (TextItem *) itemPtr; |
| 990 |
int byteIndex, byteCount, charsRemoved; |
| 991 |
char *new, *text; |
| 992 |
Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr; |
| 993 |
|
| 994 |
text = textPtr->text; |
| 995 |
if (first < 0) { |
| 996 |
first = 0; |
| 997 |
} |
| 998 |
if (last >= textPtr->numChars) { |
| 999 |
last = textPtr->numChars - 1; |
| 1000 |
} |
| 1001 |
if (first > last) { |
| 1002 |
return; |
| 1003 |
} |
| 1004 |
charsRemoved = last + 1 - first; |
| 1005 |
|
| 1006 |
byteIndex = Tcl_UtfAtIndex(text, first) - text; |
| 1007 |
byteCount = Tcl_UtfAtIndex(text + byteIndex, charsRemoved) |
| 1008 |
- (text + byteIndex); |
| 1009 |
|
| 1010 |
new = (char *) ckalloc((unsigned) (textPtr->numBytes + 1 - byteCount)); |
| 1011 |
memcpy(new, text, (size_t) byteIndex); |
| 1012 |
strcpy(new + byteIndex, text + byteIndex + byteCount); |
| 1013 |
|
| 1014 |
ckfree(text); |
| 1015 |
textPtr->text = new; |
| 1016 |
textPtr->numChars -= charsRemoved; |
| 1017 |
textPtr->numBytes -= byteCount; |
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
if (textInfoPtr->selItemPtr == itemPtr) { |
| 1025 |
if (textInfoPtr->selectFirst > first) { |
| 1026 |
textInfoPtr->selectFirst -= charsRemoved; |
| 1027 |
if (textInfoPtr->selectFirst < first) { |
| 1028 |
textInfoPtr->selectFirst = first; |
| 1029 |
} |
| 1030 |
} |
| 1031 |
if (textInfoPtr->selectLast >= first) { |
| 1032 |
textInfoPtr->selectLast -= charsRemoved; |
| 1033 |
if (textInfoPtr->selectLast < first - 1) { |
| 1034 |
textInfoPtr->selectLast = first - 1; |
| 1035 |
} |
| 1036 |
} |
| 1037 |
if (textInfoPtr->selectFirst > textInfoPtr->selectLast) { |
| 1038 |
textInfoPtr->selItemPtr = NULL; |
| 1039 |
} |
| 1040 |
if ((textInfoPtr->anchorItemPtr == itemPtr) |
| 1041 |
&& (textInfoPtr->selectAnchor > first)) { |
| 1042 |
textInfoPtr->selectAnchor -= charsRemoved; |
| 1043 |
if (textInfoPtr->selectAnchor < first) { |
| 1044 |
textInfoPtr->selectAnchor = first; |
| 1045 |
} |
| 1046 |
} |
| 1047 |
} |
| 1048 |
if (textPtr->insertPos > first) { |
| 1049 |
textPtr->insertPos -= charsRemoved; |
| 1050 |
if (textPtr->insertPos < first) { |
| 1051 |
textPtr->insertPos = first; |
| 1052 |
} |
| 1053 |
} |
| 1054 |
ComputeTextBbox(canvas, textPtr); |
| 1055 |
return; |
| 1056 |
} |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
static double |
| 1079 |
TextToPoint(canvas, itemPtr, pointPtr) |
| 1080 |
Tk_Canvas canvas; |
| 1081 |
Tk_Item *itemPtr; |
| 1082 |
double *pointPtr; |
| 1083 |
{ |
| 1084 |
TextItem *textPtr; |
| 1085 |
Tk_State state = Tk_GetItemState(canvas, itemPtr); |
| 1086 |
double value; |
| 1087 |
|
| 1088 |
textPtr = (TextItem *) itemPtr; |
| 1089 |
value = (double) Tk_DistanceToTextLayout(textPtr->textLayout, |
| 1090 |
(int) pointPtr[0] - textPtr->leftEdge, |
| 1091 |
(int) pointPtr[1] - textPtr->header.y1); |
| 1092 |
|
| 1093 |
if ((state == TK_STATE_HIDDEN) || (textPtr->color == NULL) || |
| 1094 |
(textPtr->text == NULL) || (*textPtr->text == 0)) { |
| 1095 |
value = 1.0e36; |
| 1096 |
} |
| 1097 |
return value; |
| 1098 |
} |
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
static int |
| 1121 |
TextToArea(canvas, itemPtr, rectPtr) |
| 1122 |
Tk_Canvas canvas; |
| 1123 |
Tk_Item *itemPtr; |
| 1124 |
double *rectPtr; |
| 1125 |
|
| 1126 |
|
| 1127 |
{ |
| 1128 |
TextItem *textPtr; |
| 1129 |
Tk_State state = Tk_GetItemState(canvas, itemPtr); |
| 1130 |
|
| 1131 |
textPtr = (TextItem *) itemPtr; |
| 1132 |
return Tk_IntersectTextLayout(textPtr->textLayout, |
| 1133 |
(int) (rectPtr[0] + 0.5) - textPtr->leftEdge, |
| 1134 |
(int) (rectPtr[1] + 0.5) - textPtr->header.y1, |
| 1135 |
(int) (rectPtr[2] - rectPtr[0] + 0.5), |
| 1136 |
(int) (rectPtr[3] - rectPtr[1] + 0.5)); |
| 1137 |
} |
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
static void |
| 1158 |
ScaleText(canvas, itemPtr, originX, originY, scaleX, scaleY) |
| 1159 |
Tk_Canvas canvas; |
| 1160 |
Tk_Item *itemPtr; |
| 1161 |
double originX, originY; |
| 1162 |
double scaleX; |
| 1163 |
double scaleY; |
| 1164 |
{ |
| 1165 |
TextItem *textPtr = (TextItem *) itemPtr; |
| 1166 |
|
| 1167 |
textPtr->x = originX + scaleX*(textPtr->x - originX); |
| 1168 |
textPtr->y = originY + scaleY*(textPtr->y - originY); |
| 1169 |
ComputeTextBbox(canvas, textPtr); |
| 1170 |
return; |
| 1171 |
} |
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
static void |
| 1193 |
TranslateText(canvas, itemPtr, deltaX, deltaY) |
| 1194 |
Tk_Canvas canvas; |
| 1195 |
Tk_Item *itemPtr; |
| 1196 |
double deltaX, deltaY; |
| 1197 |
{ |
| 1198 |
TextItem *textPtr = (TextItem *) itemPtr; |
| 1199 |
|
| 1200 |
textPtr->x += deltaX; |
| 1201 |
textPtr->y += deltaY; |
| 1202 |
ComputeTextBbox(canvas, textPtr); |
| 1203 |
} |
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
static int |
| 1226 |
GetTextIndex(interp, canvas, itemPtr, obj, indexPtr) |
| 1227 |
Tcl_Interp *interp; |
| 1228 |
Tk_Canvas canvas; |
| 1229 |
Tk_Item *itemPtr; |
| 1230 |
|
| 1231 |
Tcl_Obj *obj; |
| 1232 |
|
| 1233 |
int *indexPtr; |
| 1234 |
|
| 1235 |
{ |
| 1236 |
TextItem *textPtr = (TextItem *) itemPtr; |
| •1237 |
int length; |
| 1238 |
int c; |
| 1239 |
TkCanvas *canvasPtr = (TkCanvas *) canvas; |
| 1240 |
Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr; |
| 1241 |
char *string; |
| 1242 |
int x, y; |
| 1243 |
double dx,dy; |
| 1244 |
char *end, *p; |
| 1245 |
Tcl_Obj **objv; |
| 1246 |
|
| 1247 |
if (Tcl_ListObjGetElements(interp, obj, &c, &objv) == TCL_OK && c == 2 |
| 1248 |
&& Tcl_GetDoubleFromObj(interp, objv[0], &dx) == TCL_OK |
| 1249 |
&& Tcl_GetDoubleFromObj(interp, objv[1], &dy) == TCL_OK) { |
| 1250 |
goto doxy; |
| 1251 |
} |
| 1252 |
|
| 1253 |
string = Tcl_GetStringFromObj(obj, &length); |
| 1254 |
c = string[0]; |
| 1255 |
length = strlen(string); |
| 1256 |
|
| 1257 |
if ((c == 'e') && (strncmp(string, "end", length) == 0)) { |
| 1258 |
*indexPtr = textPtr->numChars; |
| 1259 |
} else if ((c == 'i') && (strncmp(string, "insert", length) == 0)) { |
| 1260 |
*indexPtr = textPtr->insertPos; |
| 1261 |
} else if ((c == 's') && (strncmp(string, "sel.first", length) == 0) |
| 1262 |
&& (length >= 5)) { |
| 1263 |
if (textInfoPtr->selItemPtr != itemPtr) { |
| 1264 |
Tcl_SetResult(interp, "selection isn't in item", TCL_STATIC); |
| 1265 |
return TCL_ERROR; |
| 1266 |
} |
| 1267 |
*indexPtr = textInfoPtr->selectFirst; |
| 1268 |
} else if ((c == 's') && (strncmp(string, "sel.last", length) == 0) |
| 1269 |
&& (length >= 5)) { |
| 1270 |
if (textInfoPtr->selItemPtr != itemPtr) { |
| 1271 |
Tcl_SetResult(interp, "selection isn't in item", TCL_STATIC); |
| 1272 |
return TCL_ERROR; |
| 1273 |
} |
| 1274 |
*indexPtr = textInfoPtr->selectLast; |
| 1275 |
} else if (c == '@') { |
| 1276 |
p = string+1; |
| 1277 |
dx = strtod(p, &end); |
| 1278 |
if ((end == p) || (*end != ',')) { |
| 1279 |
goto badIndex; |
| 1280 |
} |
| 1281 |
p = end+1; |
| 1282 |
dy = strtod(p, &end); |
| 1283 |
if ((end == p) || (*end != 0)) { |
| 1284 |
goto badIndex; |
| 1285 |
} |
| 1286 |
doxy: |
| 1287 |
x = (int) ((dx < 0) ? dx - 0.5 : dx + 0.5); |
| 1288 |
y = (int) ((dy < 0) ? dy - 0.5 : dy + 0.5); |
| 1289 |
*indexPtr = Tk_PointToChar(textPtr->textLayout, |
| 1290 |
x + canvasPtr->scrollX1 - textPtr->leftEdge, |
| 1291 |
y + canvasPtr->scrollY1 - textPtr->header.y1); |
| 1292 |
} else if (Tcl_GetIntFromObj((Tcl_Interp *)NULL, obj, indexPtr) == TCL_OK) { |
| 1293 |
if (*indexPtr < 0){ |
| 1294 |
*indexPtr = 0; |
| 1295 |
} else if (*indexPtr > textPtr->numChars) { |
| 1296 |
*indexPtr = textPtr->numChars; |
| 1297 |
} |
| 1298 |
} else { |
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
badIndex: |
| 1305 |
Tcl_SetResult(interp, (char *) NULL, TCL_STATIC); |
| 1306 |
Tcl_AppendResult(interp, "bad index \"", string, "\"", |
| 1307 |
(char *) NULL); |
| 1308 |
return TCL_ERROR; |
| 1309 |
} |
| 1310 |
return TCL_OK; |
| 1311 |
} |
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
static void |
| 1331 |
SetTextCursor(canvas, itemPtr, index) |
| 1332 |
Tk_Canvas canvas; |
| 1333 |
Tk_Item *itemPtr; |
| 1334 |
|
| 1335 |
int index; |
| 1336 |
|
| 1337 |
{ |
| 1338 |
TextItem *textPtr = (TextItem *) itemPtr; |
| 1339 |
|
| 1340 |
if (index < 0) { |
| 1341 |
textPtr->insertPos = 0; |
| 1342 |
} else if (index > textPtr->numChars) { |
| 1343 |
textPtr->insertPos = textPtr->numChars; |
| 1344 |
} else { |
| 1345 |
textPtr->insertPos = index; |
| 1346 |
} |
| 1347 |
} |
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
static int |
| 1371 |
GetSelText(canvas, itemPtr, offset, buffer, maxBytes) |
| 1372 |
Tk_Canvas canvas; |
| 1373 |
Tk_Item *itemPtr; |
| 1374 |
int offset; |
| 1375 |
|
| 1376 |
char *buffer; |
| 1377 |
int maxBytes; |
| 1378 |
|
| 1379 |
|
| 1380 |
{ |
| 1381 |
TextItem *textPtr = (TextItem *) itemPtr; |
| 1382 |
int byteCount; |
| 1383 |
char *text; |
| 1384 |
CONST char *selStart, *selEnd; |
| 1385 |
Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr; |
| 1386 |
|
| 1387 |
if ((textInfoPtr->selectFirst < 0) || |
| 1388 |
(textInfoPtr->selectFirst > textInfoPtr->selectLast)) { |
| 1389 |
return 0; |
| 1390 |
} |
| 1391 |
text = textPtr->text; |
| 1392 |
selStart = Tcl_UtfAtIndex(text, textInfoPtr->selectFirst); |
| 1393 |
selEnd = Tcl_UtfAtIndex(selStart, |
| 1394 |
textInfoPtr->selectLast + 1 - textInfoPtr->selectFirst); |
| 1395 |
byteCount = selEnd - selStart - offset; |
| 1396 |
if (byteCount > maxBytes) { |
| 1397 |
byteCount = maxBytes; |
| 1398 |
} |
| 1399 |
if (byteCount <= 0) { |
| 1400 |
return 0; |
| 1401 |
} |
| 1402 |
memcpy(buffer, selStart + offset, (size_t) byteCount); |
| 1403 |
buffer[byteCount] = '\0'; |
| 1404 |
return byteCount; |
| 1405 |
} |
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
static int |
| 1429 |
TextToPostscript(interp, canvas, itemPtr, prepass) |
| 1430 |
Tcl_Interp *interp; |
| 1431 |
Tk_Canvas canvas; |
| 1432 |
Tk_Item *itemPtr; |
| 1433 |
int prepass; |
| 1434 |
|
| 1435 |
|
| 1436 |
{ |
| 1437 |
TextItem *textPtr = (TextItem *) itemPtr; |
| 1438 |
int x, y; |
| 1439 |
Tk_FontMetrics fm; |
| 1440 |
char *justify; |
| 1441 |
char buffer[500]; |
| 1442 |
XColor *color; |
| 1443 |
Pixmap stipple; |
| 1444 |
Tk_State state = Tk_GetItemState(canvas, itemPtr); |
| 1445 |
|
| 1446 |
color = textPtr->color; |
| 1447 |
stipple = textPtr->stipple; |
| 1448 |
if (state == TK_STATE_HIDDEN || textPtr->color == NULL || |
| 1449 |
textPtr->text == NULL || *textPtr->text == 0) { |
| 1450 |
return TCL_OK; |
| 1451 |
} else if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { |
| 1452 |
if (textPtr->activeColor!=NULL) { |
| 1453 |
color = textPtr->activeColor; |
| 1454 |
} |
| 1455 |
if (textPtr->activeStipple!=None) { |
| 1456 |
stipple = textPtr->activeStipple; |
| 1457 |
} |
| 1458 |
} else if (state==TK_STATE_DISABLED) { |
| 1459 |
if (textPtr->disabledColor!=NULL) { |
| 1460 |
color = textPtr->disabledColor; |
| 1461 |
} |
| 1462 |
if (textPtr->disabledStipple!=None) { |
| 1463 |
stipple = textPtr->disabledStipple; |
| 1464 |
} |
| 1465 |
} |
| 1466 |
|
| 1467 |
if (Tk_CanvasPsFont(interp, canvas, textPtr->tkfont) != TCL_OK) { |
| 1468 |
return TCL_ERROR; |
| 1469 |
} |
| 1470 |
if (prepass != 0) { |
| 1471 |
return TCL_OK; |
| 1472 |
} |
| 1473 |
if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) { |
| 1474 |
return TCL_ERROR; |
| 1475 |
} |
| 1476 |
if (stipple != None) { |
| 1477 |
Tcl_AppendResult(interp, "/StippleText {\n ", |
| 1478 |
(char *) NULL); |
| 1479 |
Tk_CanvasPsStipple(interp, canvas, stipple); |
| 1480 |
Tcl_AppendResult(interp, "} bind def\n", (char *) NULL); |
| 1481 |
} |
| 1482 |
|
| 1483 |
sprintf(buffer, "%.15g %.15g [\n", textPtr->x, |
| 1484 |
Tk_CanvasPsY(canvas, textPtr->y)); |
| 1485 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1486 |
|
| 1487 |
Tk_TextLayoutToPostscript(interp, textPtr->textLayout); |
| 1488 |
|
| 1489 |
x = 0; y = 0; justify = NULL; |
| 1490 |
switch (textPtr->anchor) { |
| 1491 |
case TK_ANCHOR_NW: x = 0; y = 0; break; |
| 1492 |
case TK_ANCHOR_N: x = 1; y = 0; break; |
| 1493 |
case TK_ANCHOR_NE: x = 2; y = 0; break; |
| 1494 |
case TK_ANCHOR_E: x = 2; y = 1; break; |
| 1495 |
case TK_ANCHOR_SE: x = 2; y = 2; break; |
| 1496 |
case TK_ANCHOR_S: x = 1; y = 2; break; |
| 1497 |
case TK_ANCHOR_SW: x = 0; y = 2; break; |
| 1498 |
case TK_ANCHOR_W: x = 0; y = 1; break; |
| 1499 |
case TK_ANCHOR_CENTER: x = 1; y = 1; break; |
| 1500 |
} |
| 1501 |
switch (textPtr->justify) { |
| 1502 |
case TK_JUSTIFY_LEFT: justify = "0"; break; |
| 1503 |
case TK_JUSTIFY_CENTER: justify = "0.5";break; |
| 1504 |
case TK_JUSTIFY_RIGHT: justify = "1"; break; |
| 1505 |
} |
| 1506 |
|
| 1507 |
Tk_GetFontMetrics(textPtr->tkfont, &fm); |
| 1508 |
sprintf(buffer, "] %d %g %g %s %s DrawText\n", |
| 1509 |
fm.linespace, x / -2.0, y / 2.0, justify, |
| 1510 |
((stipple == None) ? "false" : "true")); |
| 1511 |
Tcl_AppendResult(interp, buffer, (char *) NULL); |
| 1512 |
|
| 1513 |
return TCL_OK; |
| 1514 |
} |
| 1515 |
|
| 1516 |
|