| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#include "tkPort.h" |
| 19 |
#include "default.h" |
| 20 |
#include "tkInt.h" |
| 21 |
#include "tkVMacro.h" |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
typedef struct { |
| 29 |
Tk_Window tkwin; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
Tk_OptionTable optionTable; |
| 34 |
|
| 35 |
Display *display; |
| 36 |
|
| 37 |
|
| 38 |
Tcl_Interp *interp; |
| 39 |
Tcl_Command widgetCmd; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
char *string; |
| 46 |
int numChars; |
| 47 |
|
| 48 |
Var textVarName; |
| 49 |
|
| 50 |
|
| 51 |
Tk_3DBorder border; |
| 52 |
|
| 53 |
|
| 54 |
int borderWidth; |
| 55 |
int relief; |
| 56 |
int highlightWidth; |
| 57 |
|
| 58 |
|
| 59 |
XColor *highlightBgColorPtr; |
| 60 |
|
| 61 |
|
| 62 |
XColor *highlightColorPtr; |
| 63 |
Tk_Font tkfont; |
| 64 |
XColor *fgColorPtr; |
| 65 |
Tcl_Obj *padXPtr, *padYPtr; |
| 66 |
int padX, padY; |
| 67 |
int width; |
| 68 |
|
| 69 |
int aspect; |
| 70 |
|
| 71 |
int msgWidth; |
| 72 |
|
| 73 |
int msgHeight; |
| 74 |
|
| 75 |
Tk_Anchor anchor; |
| 76 |
|
| 77 |
|
| 78 |
Tk_Justify justify; |
| 79 |
|
| 80 |
GC textGC; |
| 81 |
Tk_TextLayout textLayout; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
Tk_Cursor cursor; |
| 88 |
char *takeFocus; |
| 89 |
|
| 90 |
|
| 91 |
int flags; |
| 92 |
|
| 93 |
} Message; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
#define REDRAW_PENDING 1 |
| 107 |
#define GOT_FOCUS 4 |
| 108 |
#define MESSAGE_DELETED 8 |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
static Tk_CustomOption tileOption = { |
| 115 |
Tk_TileParseProc, |
| 116 |
Tk_TilePrintProc, |
| 117 |
(ClientData) NULL |
| 118 |
}; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
static Tk_OptionSpec optionSpecs[] = { |
| 125 |
{TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", DEF_MESSAGE_ANCHOR, |
| 126 |
-1, Tk_Offset(Message, anchor), 0, 0, 0}, |
| 127 |
{TK_OPTION_INT, "-aspect", "aspect", "Aspect", DEF_MESSAGE_ASPECT, |
| 128 |
-1, Tk_Offset(Message, aspect), 0, 0, 0}, |
| 129 |
{TK_OPTION_BORDER, "-background", "background", "Background", |
| 130 |
DEF_MESSAGE_BG_COLOR, -1, Tk_Offset(Message, border), 0, |
| 131 |
(ClientData) DEF_MESSAGE_BG_MONO, 0}, |
| 132 |
{TK_OPTION_SYNONYM, "-bd", (char *) NULL, (char *) NULL, (char *) NULL, |
| 133 |
0, -1, 0, (ClientData) "-borderwidth", 0}, |
| 134 |
{TK_OPTION_SYNONYM, "-bg", (char *) NULL, (char *) NULL, (char *) NULL, |
| 135 |
0, -1, 0, (ClientData) "-background", 0}, |
| 136 |
{TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth", |
| 137 |
DEF_MESSAGE_BORDER_WIDTH, -1, |
| 138 |
Tk_Offset(Message, borderWidth), 0, 0, 0}, |
| 139 |
{TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor", |
| 140 |
DEF_MESSAGE_CURSOR, -1, Tk_Offset(Message, cursor), |
| 141 |
TK_OPTION_NULL_OK, 0, 0}, |
| 142 |
{TK_OPTION_SYNONYM, "-fg", (char *) NULL, (char *) NULL, (char *) NULL, |
| 143 |
0, -1, 0, (ClientData) "-foreground", 0}, |
| 144 |
{TK_OPTION_FONT, "-font", "font", "Font", |
| 145 |
DEF_MESSAGE_FONT, -1, Tk_Offset(Message, tkfont), 0, 0, 0}, |
| 146 |
{TK_OPTION_COLOR, "-foreground", "foreground", "Foreground", |
| 147 |
DEF_MESSAGE_FG, -1, Tk_Offset(Message, fgColorPtr), 0, 0, 0}, |
| 148 |
{TK_OPTION_COLOR, "-highlightbackground", "highlightBackground", |
| 149 |
"HighlightBackground", DEF_MESSAGE_HIGHLIGHT_BG, -1, |
| 150 |
Tk_Offset(Message, highlightBgColorPtr), 0, 0}, |
| 151 |
{TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor", |
| 152 |
DEF_MESSAGE_HIGHLIGHT, -1, Tk_Offset(Message, highlightColorPtr), |
| 153 |
0, 0, 0}, |
| 154 |
{TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness", |
| 155 |
"HighlightThickness", DEF_MESSAGE_HIGHLIGHT_WIDTH, -1, |
| 156 |
Tk_Offset(Message, highlightWidth), 0, 0, 0}, |
| 157 |
{TK_OPTION_JUSTIFY, "-justify", "justify", "Justify", |
| 158 |
DEF_MESSAGE_JUSTIFY, -1, Tk_Offset(Message, justify), 0, 0, 0}, |
| 159 |
{TK_OPTION_PIXELS, "-padx", "padX", "Pad", |
| 160 |
DEF_MESSAGE_PADX, Tk_Offset(Message, padXPtr), |
| 161 |
Tk_Offset(Message, padX), 0, 0, 0}, |
| 162 |
{TK_OPTION_PIXELS, "-pady", "padY", "Pad", |
| 163 |
DEF_MESSAGE_PADY, Tk_Offset(Message, padYPtr), |
| 164 |
Tk_Offset(Message, padY), 0, 0, 0}, |
| 165 |
{TK_OPTION_RELIEF, "-relief", "relief", "Relief", |
| 166 |
DEF_MESSAGE_RELIEF, -1, Tk_Offset(Message, relief), 0, 0, 0}, |
| 167 |
{TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus", |
| 168 |
DEF_MESSAGE_TAKE_FOCUS, -1, Tk_Offset(Message, takeFocus), |
| 169 |
TK_OPTION_NULL_OK, 0, 0}, |
| 170 |
{TK_OPTION_STRING, "-text", "text", "Text", |
| 171 |
DEF_MESSAGE_TEXT, -1, Tk_Offset(Message, string), 0, 0, 0}, |
| 172 |
{TK_OPTION_OBJ, "-textvariable", "textVariable", "Variable", |
| 173 |
DEF_MESSAGE_TEXT_VARIABLE, -1, Tk_Offset(Message, textVarName), |
| 174 |
TK_OPTION_NULL_OK, 0, 0}, |
| 175 |
{TK_OPTION_PIXELS, "-width", "width", "Width", |
| 176 |
DEF_MESSAGE_WIDTH, -1, Tk_Offset(Message, width), 0, 0 ,0}, |
| 177 |
{TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL, |
| 178 |
(char *) NULL, 0, 0, 0, 0} |
| 179 |
}; |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
static void MessageCmdDeletedProc _ANSI_ARGS_(( |
| 186 |
ClientData clientData)); |
| 187 |
static void MessageEventProc _ANSI_ARGS_((ClientData clientData, |
| 188 |
XEvent *eventPtr)); |
| 189 |
static char * MessageTextVarProc _ANSI_ARGS_((ClientData clientData, |
| 190 |
Tcl_Interp *interp, Var name1, |
| 191 |
CONST char *name2, int flags)); |
| 192 |
static int MessageWidgetObjCmd _ANSI_ARGS_((ClientData clientData, |
| 193 |
Tcl_Interp *interp, int objc, |
| 194 |
Tcl_Obj *CONST objv[])); |
| 195 |
static void MessageWorldChanged _ANSI_ARGS_(( |
| 196 |
ClientData instanceData)); |
| 197 |
static void ComputeMessageGeometry _ANSI_ARGS_((Message *msgPtr)); |
| 198 |
static int ConfigureMessage _ANSI_ARGS_((Tcl_Interp *interp, |
| 199 |
Message *msgPtr, int objc, Tcl_Obj *CONST objv[], |
| 200 |
int flags)); |
| 201 |
static void DestroyMessage _ANSI_ARGS_((char *memPtr)); |
| 202 |
static void DisplayMessage _ANSI_ARGS_((ClientData clientData)); |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
static Tk_ClassProcs messageClass = { |
| 210 |
sizeof(Tk_ClassProcs), |
| 211 |
MessageWorldChanged, |
| 212 |
}; |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
int |
| 234 |
Tk_MessageObjCmd(clientData, interp, objc, objv) |
| 235 |
ClientData clientData; |
| 236 |
Tcl_Interp *interp; |
| 237 |
int objc; |
| 238 |
Tcl_Obj *CONST objv[]; |
| 239 |
{ |
| 240 |
register Message *msgPtr; |
| 241 |
Tk_OptionTable optionTable; |
| 242 |
Tk_Window tkwin; |
| 243 |
|
| 244 |
if (objc < 2) { |
| 245 |
Tcl_WrongNumArgs(interp, 1, objv, "pathName ?options?"); |
| 246 |
return TCL_ERROR; |
| 247 |
} |
| 248 |
|
| 249 |
tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), |
| 250 |
Tcl_GetString(objv[1]), (char *) NULL); |
| 251 |
if (tkwin == NULL) { |
| 252 |
return TCL_ERROR; |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
optionTable = Tk_CreateOptionTable(interp, optionSpecs); |
| 261 |
|
| 262 |
msgPtr = (Message *) ckalloc(sizeof(Message)); |
| 263 |
memset(msgPtr, 0, (size_t) sizeof(Message)); |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
msgPtr->tkwin = tkwin; |
| 269 |
msgPtr->display = Tk_Display(tkwin); |
| 270 |
msgPtr->interp = interp; |
| 271 |
msgPtr->widgetCmd = Tcl_CreateObjCommand(interp, |
| 272 |
Tk_PathName(msgPtr->tkwin), MessageWidgetObjCmd, |
| 273 |
(ClientData) msgPtr, MessageCmdDeletedProc); |
| 274 |
msgPtr->optionTable = optionTable; |
| 275 |
msgPtr->relief = TK_RELIEF_FLAT; |
| 276 |
msgPtr->textGC = None; |
| 277 |
msgPtr->anchor = TK_ANCHOR_CENTER; |
| 278 |
msgPtr->aspect = 150; |
| 279 |
msgPtr->justify = TK_JUSTIFY_LEFT; |
| 280 |
msgPtr->cursor = None; |
| 281 |
|
| 282 |
Tk_SetClass(msgPtr->tkwin, "Message"); |
| 283 |
Tk_SetClassProcs(msgPtr->tkwin, &messageClass, (ClientData) msgPtr); |
| 284 |
Tk_CreateEventHandler(msgPtr->tkwin, |
| 285 |
ExposureMask|StructureNotifyMask|FocusChangeMask, |
| 286 |
MessageEventProc, (ClientData) msgPtr); |
| 287 |
if (Tk_InitOptions(interp, (char *)msgPtr, optionTable, tkwin) != TCL_OK) { |
| 288 |
Tk_DestroyWindow(msgPtr->tkwin); |
| 289 |
return TCL_ERROR; |
| 290 |
} |
| 291 |
|
| 292 |
if (ConfigureMessage(interp, msgPtr, objc-2, objv+2, 0) != TCL_OK) { |
| 293 |
Tk_DestroyWindow(msgPtr->tkwin); |
| 294 |
return TCL_ERROR; |
| 295 |
} |
| 296 |
|
| 297 |
Tcl_SetResult(interp, Tk_PathName(msgPtr->tkwin), TCL_STATIC); |
| 298 |
return TCL_OK; |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
static int |
| 320 |
MessageWidgetObjCmd(clientData, interp, objc, objv) |
| 321 |
ClientData clientData; |
| 322 |
Tcl_Interp *interp; |
| 323 |
int objc; |
| 324 |
Tcl_Obj *CONST objv[]; |
| 325 |
{ |
| 326 |
register Message *msgPtr = (Message *) clientData; |
| 327 |
static CONST char *optionStrings[] = { "cget", "configure", (char *) NULL }; |
| 328 |
enum options { MESSAGE_CGET, MESSAGE_CONFIGURE }; |
| 329 |
int index; |
| 330 |
int result = TCL_OK; |
| 331 |
Tcl_Obj *objPtr; |
| 332 |
|
| 333 |
if (objc < 2) { |
| 334 |
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?"); |
| 335 |
return TCL_ERROR; |
| 336 |
} |
| 337 |
|
| 338 |
if (Tcl_GetIndexFromObj(interp, objv[1], optionStrings, "option", 0, |
| 339 |
&index) != TCL_OK) { |
| 340 |
return TCL_ERROR; |
| 341 |
} |
| 342 |
|
| 343 |
Tcl_Preserve((ClientData) msgPtr); |
| 344 |
|
| 345 |
switch ((enum options) index) { |
| 346 |
case MESSAGE_CGET: { |
| 347 |
if (objc != 3) { |
| 348 |
Tcl_WrongNumArgs(interp, 2, objv, "option"); |
| 349 |
return TCL_ERROR; |
| 350 |
} |
| 351 |
objPtr = Tk_GetOptionValue(interp, (char *) msgPtr, |
| 352 |
msgPtr->optionTable, objv[2], msgPtr->tkwin); |
| 353 |
if (objPtr == NULL) { |
| 354 |
result = TCL_ERROR; |
| 355 |
} else { |
| 356 |
Tcl_SetObjResult(interp, objPtr); |
| 357 |
result = TCL_OK; |
| 358 |
} |
| 359 |
break; |
| 360 |
} |
| 361 |
case MESSAGE_CONFIGURE: { |
| 362 |
if (objc <= 3) { |
| 363 |
objPtr = Tk_GetOptionInfo(interp, (char *) msgPtr, |
| 364 |
msgPtr->optionTable, |
| 365 |
(objc == 3) ? objv[2] : (Tcl_Obj *) NULL, |
| 366 |
msgPtr->tkwin); |
| 367 |
if (objPtr == NULL) { |
| 368 |
result = TCL_ERROR; |
| 369 |
} else { |
| 370 |
Tcl_SetObjResult(interp, objPtr); |
| 371 |
result = TCL_OK; |
| 372 |
} |
| 373 |
} else { |
| 374 |
result = ConfigureMessage(interp, msgPtr, objc-2, objv+2, 0); |
| 375 |
} |
| 376 |
break; |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
Tcl_Release((ClientData) msgPtr); |
| 381 |
return result; |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
static void |
| 403 |
DestroyMessage(memPtr) |
| 404 |
char *memPtr; |
| 405 |
{ |
| 406 |
register Message *msgPtr = (Message *) memPtr; |
| 407 |
|
| 408 |
msgPtr->flags |= MESSAGE_DELETED; |
| 409 |
|
| 410 |
Tcl_DeleteCommandFromToken(msgPtr->interp, msgPtr->widgetCmd); |
| 411 |
if (msgPtr->flags & REDRAW_PENDING) { |
| 412 |
Tcl_CancelIdleCall(DisplayMessage, (ClientData) msgPtr); |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
if (msgPtr->textGC != None) { |
| 422 |
Tk_FreeGC(msgPtr->display, msgPtr->textGC); |
| 423 |
} |
| 424 |
if (msgPtr->textLayout != NULL) { |
| 425 |
Tk_FreeTextLayout(msgPtr->textLayout); |
| 426 |
} |
| 427 |
if (msgPtr->textVarName != NULL) { |
| 428 |
Lang_UntraceVar(msgPtr->interp, msgPtr->textVarName, |
| 429 |
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, |
| 430 |
MessageTextVarProc, (ClientData) msgPtr); |
| 431 |
} |
| 432 |
Tk_FreeConfigOptions((char *) msgPtr, msgPtr->optionTable, msgPtr->tkwin); |
| 433 |
msgPtr->tkwin = NULL; |
| 434 |
ckfree((char *) msgPtr); |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
static int |
| 459 |
ConfigureMessage(interp, msgPtr, objc, objv, flags) |
| 460 |
Tcl_Interp *interp; |
| 461 |
register Message *msgPtr; |
| 462 |
|
| 463 |
int objc; |
| 464 |
Tcl_Obj *CONST objv[]; |
| 465 |
int flags; |
| 466 |
{ |
| 467 |
Tk_SavedOptions savedOptions; |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
if (msgPtr->textVarName != NULL) { |
| 474 |
Lang_UntraceVar(interp, msgPtr->textVarName, |
| 475 |
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, |
| 476 |
MessageTextVarProc, (ClientData) msgPtr); |
| 477 |
} |
| 478 |
|
| 479 |
if (Tk_SetOptions(interp, (char *) msgPtr, msgPtr->optionTable, objc, objv, |
| 480 |
msgPtr->tkwin, &savedOptions, (int *)NULL) != TCL_OK) { |
| 481 |
Tk_RestoreSavedOptions(&savedOptions); |
| 482 |
return TCL_ERROR; |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
if (msgPtr->textVarName != NULL) { |
| 493 |
CONST char *value; |
| 494 |
|
| 495 |
value = Tcl_GetString(Tcl_ObjGetVar2(interp, msgPtr->textVarName, NULL, TCL_GLOBAL_ONLY)); |
| 496 |
if (value == NULL) { |
| 497 |
Tcl_Obj *temp = Tcl_NewStringObj(msgPtr->string,-1); |
| 498 |
Tcl_ObjSetVar2(interp, msgPtr->textVarName, NULL, temp, |
| 499 |
TCL_GLOBAL_ONLY); |
| 500 |
Tcl_DecrRefCount(temp); |
| 501 |
} else { |
| 502 |
if (msgPtr->string != NULL) { |
| 503 |
ckfree(msgPtr->string); |
| 504 |
} |
| 505 |
msgPtr->string = strcpy(ckalloc(strlen(value) + 1), value); |
| 506 |
} |
| 507 |
Lang_TraceVar(interp, msgPtr->textVarName, |
| 508 |
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, |
| 509 |
MessageTextVarProc, (ClientData) msgPtr); |
| 510 |
} |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
msgPtr->numChars = Tcl_NumUtfChars(msgPtr->string, -1); |
| 519 |
|
| 520 |
if (msgPtr->highlightWidth < 0) { |
| 521 |
msgPtr->highlightWidth = 0; |
| 522 |
} |
| 523 |
|
| 524 |
Tk_FreeSavedOptions(&savedOptions); |
| 525 |
MessageWorldChanged((ClientData) msgPtr); |
| 526 |
return TCL_OK; |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
static void |
| 548 |
MessageWorldChanged(instanceData) |
| 549 |
ClientData instanceData; |
| 550 |
{ |
| 551 |
XGCValues gcValues; |
| 552 |
GC gc = None; |
| 553 |
Tk_FontMetrics fm; |
| 554 |
Message *msgPtr; |
| 555 |
|
| 556 |
msgPtr = (Message *) instanceData; |
| 557 |
|
| 558 |
if (msgPtr->border != NULL) { |
| 559 |
Tk_SetBackgroundFromBorder(msgPtr->tkwin, msgPtr->border); |
| 560 |
} |
| 561 |
|
| 562 |
gcValues.font = Tk_FontId(msgPtr->tkfont); |
| 563 |
gcValues.foreground = msgPtr->fgColorPtr->pixel; |
| 564 |
gc = Tk_GetGC(msgPtr->tkwin, GCForeground | GCFont, &gcValues); |
| 565 |
if (msgPtr->textGC != None) { |
| 566 |
Tk_FreeGC(msgPtr->display, msgPtr->textGC); |
| 567 |
} |
| 568 |
msgPtr->textGC = gc; |
| 569 |
|
| 570 |
Tk_GetFontMetrics(msgPtr->tkfont, &fm); |
| 571 |
if (msgPtr->padX < 0) { |
| 572 |
msgPtr->padX = fm.ascent / 2; |
| 573 |
} |
| 574 |
if (msgPtr->padY == -1) { |
| 575 |
msgPtr->padY = fm.ascent / 4; |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
ComputeMessageGeometry(msgPtr); |
| 584 |
if ((msgPtr->tkwin != NULL) && Tk_IsMapped(msgPtr->tkwin) |
| 585 |
&& !(msgPtr->flags & REDRAW_PENDING)) { |
| 586 |
Tcl_DoWhenIdle(DisplayMessage, (ClientData) msgPtr); |
| 587 |
msgPtr->flags |= REDRAW_PENDING; |
| 588 |
} |
| 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 |
ComputeMessageGeometry(msgPtr) |
| 612 |
register Message *msgPtr; |
| 613 |
{ |
| 614 |
int width, inc, height; |
| 615 |
int thisWidth, thisHeight, maxWidth; |
| 616 |
int aspect, lowerBound, upperBound, inset; |
| 617 |
|
| 618 |
Tk_FreeTextLayout(msgPtr->textLayout); |
| 619 |
|
| 620 |
inset = msgPtr->borderWidth + msgPtr->highlightWidth; |
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
aspect = msgPtr->aspect/10; |
| 627 |
if (aspect < 5) { |
| 628 |
aspect = 5; |
| 629 |
} |
| 630 |
lowerBound = msgPtr->aspect - aspect; |
| 631 |
upperBound = msgPtr->aspect + aspect; |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
if (msgPtr->width > 0) { |
| 643 |
width = msgPtr->width; |
| 644 |
inc = 0; |
| 645 |
} else { |
| 646 |
width = WidthOfScreen(Tk_Screen(msgPtr->tkwin))/2; |
| 647 |
inc = width/2; |
| 648 |
} |
| 649 |
|
| 650 |
for ( ; ; inc /= 2) { |
| 651 |
msgPtr->textLayout = Tk_ComputeTextLayout(msgPtr->tkfont, |
| 652 |
msgPtr->string, msgPtr->numChars, width, msgPtr->justify, |
| 653 |
0, &thisWidth, &thisHeight); |
| 654 |
maxWidth = thisWidth + 2 * (inset + msgPtr->padX); |
| 655 |
height = thisHeight + 2 * (inset + msgPtr->padY); |
| 656 |
|
| 657 |
if (inc <= 2) { |
| 658 |
break; |
| 659 |
} |
| 660 |
aspect = (100 * maxWidth) / height; |
| 661 |
|
| 662 |
if (aspect < lowerBound) { |
| 663 |
width += inc; |
| 664 |
} else if (aspect > upperBound) { |
| 665 |
width -= inc; |
| 666 |
} else { |
| 667 |
break; |
| 668 |
} |
| 669 |
Tk_FreeTextLayout(msgPtr->textLayout); |
| 670 |
} |
| 671 |
msgPtr->msgWidth = thisWidth; |
| 672 |
msgPtr->msgHeight = thisHeight; |
| 673 |
Tk_GeometryRequest(msgPtr->tkwin, maxWidth, height); |
| 674 |
Tk_SetInternalBorder(msgPtr->tkwin, inset); |
| 675 |
} |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
static void |
| 694 |
DisplayMessage(clientData) |
| 695 |
ClientData clientData; |
| 696 |
{ |
| 697 |
register Message *msgPtr = (Message *) clientData; |
| 698 |
register Tk_Window tkwin = msgPtr->tkwin; |
| 699 |
int x, y; |
| 700 |
int borderWidth = msgPtr->highlightWidth; |
| 701 |
|
| 702 |
msgPtr->flags &= ~REDRAW_PENDING; |
| 703 |
if ((msgPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { |
| 704 |
return; |
| 705 |
} |
| 706 |
if (msgPtr->border != NULL) { |
| 707 |
borderWidth += msgPtr->borderWidth; |
| 708 |
} |
| 709 |
if (msgPtr->relief == TK_RELIEF_FLAT) { |
| 710 |
borderWidth = msgPtr->highlightWidth; |
| 711 |
} |
| 712 |
Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), msgPtr->border, |
| 713 |
borderWidth, borderWidth, |
| 714 |
Tk_Width(tkwin) - 2 * borderWidth, |
| 715 |
Tk_Height(tkwin) - 2 * borderWidth, |
| 716 |
0, TK_RELIEF_FLAT); |
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
TkComputeAnchor(msgPtr->anchor, tkwin, msgPtr->padX, msgPtr->padY, |
| 724 |
msgPtr->msgWidth, msgPtr->msgHeight, &x, &y); |
| 725 |
Tk_DrawTextLayout(Tk_Display(tkwin), Tk_WindowId(tkwin), msgPtr->textGC, |
| 726 |
msgPtr->textLayout, x, y, 0, -1); |
| 727 |
|
| 728 |
if (borderWidth > msgPtr->highlightWidth) { |
| 729 |
Tk_Draw3DRectangle(tkwin, Tk_WindowId(tkwin), msgPtr->border, |
| 730 |
msgPtr->highlightWidth, msgPtr->highlightWidth, |
| 731 |
Tk_Width(tkwin) - 2*msgPtr->highlightWidth, |
| 732 |
Tk_Height(tkwin) - 2*msgPtr->highlightWidth, |
| 733 |
msgPtr->borderWidth, msgPtr->relief); |
| 734 |
} |
| 735 |
if (msgPtr->highlightWidth != 0) { |
| 736 |
GC fgGC, bgGC; |
| 737 |
|
| 738 |
bgGC = Tk_GCForColor(msgPtr->highlightBgColorPtr, Tk_WindowId(tkwin)); |
| 739 |
if (msgPtr->flags & GOT_FOCUS) { |
| 740 |
fgGC = Tk_GCForColor(msgPtr->highlightColorPtr, Tk_WindowId(tkwin)); |
| 741 |
TkpDrawHighlightBorder(tkwin, fgGC, bgGC, msgPtr->highlightWidth, |
| 742 |
Tk_WindowId(tkwin)); |
| 743 |
} else { |
| 744 |
TkpDrawHighlightBorder(tkwin, bgGC, bgGC, msgPtr->highlightWidth, |
| 745 |
Tk_WindowId(tkwin)); |
| 746 |
} |
| 747 |
} |
| 748 |
} |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
static void |
| 769 |
MessageEventProc(clientData, eventPtr) |
| 770 |
ClientData clientData; |
| 771 |
XEvent *eventPtr; |
| 772 |
{ |
| 773 |
Message *msgPtr = (Message *) clientData; |
| 774 |
|
| 775 |
if (((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) |
| 776 |
|| (eventPtr->type == ConfigureNotify)) { |
| 777 |
goto redraw; |
| 778 |
} else if (eventPtr->type == DestroyNotify) { |
| 779 |
DestroyMessage((char *) clientData); |
| 780 |
} else if (eventPtr->type == FocusIn) { |
| 781 |
if (eventPtr->xfocus.detail != NotifyInferior) { |
| 782 |
msgPtr->flags |= GOT_FOCUS; |
| 783 |
if (msgPtr->highlightWidth > 0) { |
| 784 |
goto redraw; |
| 785 |
} |
| 786 |
} |
| 787 |
} else if (eventPtr->type == FocusOut) { |
| 788 |
if (eventPtr->xfocus.detail != NotifyInferior) { |
| 789 |
msgPtr->flags &= ~GOT_FOCUS; |
| 790 |
if (msgPtr->highlightWidth > 0) { |
| 791 |
goto redraw; |
| 792 |
} |
| 793 |
} |
| 794 |
} |
| 795 |
return; |
| 796 |
|
| 797 |
redraw: |
| 798 |
if ((msgPtr->tkwin != NULL) && !(msgPtr->flags & REDRAW_PENDING)) { |
| 799 |
Tcl_DoWhenIdle(DisplayMessage, (ClientData) msgPtr); |
| 800 |
msgPtr->flags |= REDRAW_PENDING; |
| 801 |
} |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
static void |
| 823 |
MessageCmdDeletedProc(clientData) |
| 824 |
ClientData clientData; |
| 825 |
{ |
| 826 |
Message *msgPtr = (Message *) clientData; |
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
if (!(msgPtr->flags & MESSAGE_DELETED)) { |
| 836 |
Tk_DestroyWindow(msgPtr->tkwin); |
| 837 |
} |
| 838 |
} |
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
static char * |
| 860 |
MessageTextVarProc(clientData, interp, name1, name2, flags) |
| 861 |
ClientData clientData; |
| 862 |
Tcl_Interp *interp; |
| 863 |
Var name1; |
| 864 |
CONST char *name2; |
| 865 |
int flags; |
| 866 |
{ |
| 867 |
register Message *msgPtr = (Message *) clientData; |
| 868 |
CONST char *value; |
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
if (flags & TCL_TRACE_UNSETS) { |
| 876 |
if ((flags & TCL_TRACE_DESTROYED) && !(flags & TCL_INTERP_DESTROYED)) { |
| 877 |
Tcl_Obj *temp = Tcl_NewStringObj(msgPtr->string,-1); |
| 878 |
Tcl_ObjSetVar2(interp, msgPtr->textVarName, NULL, temp, |
| 879 |
TCL_GLOBAL_ONLY); |
| 880 |
Tcl_DecrRefCount(temp); |
| 881 |
Lang_TraceVar(interp, msgPtr->textVarName, |
| 882 |
TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, |
| 883 |
MessageTextVarProc, clientData); |
| 884 |
} |
| 885 |
return (char *) NULL; |
| 886 |
} |
| 887 |
|
| 888 |
value = Tcl_GetString(Tcl_ObjGetVar2(interp, msgPtr->textVarName, NULL, TCL_GLOBAL_ONLY)); |
| 889 |
if (value == NULL) { |
| 890 |
value = ""; |
| 891 |
} |
| 892 |
if (msgPtr->string != NULL) { |
| 893 |
ckfree(msgPtr->string); |
| 894 |
} |
| 895 |
msgPtr->numChars = Tcl_NumUtfChars(value, -1); |
| 896 |
msgPtr->string = (char *) ckalloc((unsigned) (strlen(value) + 1)); |
| 897 |
strcpy(msgPtr->string, value); |
| 898 |
ComputeMessageGeometry(msgPtr); |
| 899 |
|
| 900 |
if ((msgPtr->tkwin != NULL) && Tk_IsMapped(msgPtr->tkwin) |
| 901 |
&& !(msgPtr->flags & REDRAW_PENDING)) { |
| 902 |
Tcl_DoWhenIdle(DisplayMessage, (ClientData) msgPtr); |
| 903 |
msgPtr->flags |= REDRAW_PENDING; |
| 904 |
} |
| 905 |
return (char *) NULL; |
| 906 |
} |
| 907 |
|
| 908 |
|