| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include "tkButton.h" |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
typedef struct UnixButton { |
| 22 |
TkButton info; |
| 23 |
} UnixButton; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
Tk_ClassProcs tkpButtonProcs = { |
| 30 |
sizeof(Tk_ClassProcs), |
| 31 |
TkButtonWorldChanged, |
| 32 |
}; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
TkButton * |
| 51 |
TkpCreateButton(tkwin) |
| 52 |
Tk_Window tkwin; |
| 53 |
{ |
| 54 |
UnixButton *butPtr = (UnixButton *)ckalloc(sizeof(UnixButton)); |
| 55 |
return (TkButton *) butPtr; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
void |
| 77 |
TkpDisplayButton(clientData) |
| 78 |
ClientData clientData; |
| 79 |
{ |
| 80 |
register TkButton *butPtr = (TkButton *) clientData; |
| 81 |
GC gc; |
| 82 |
Tk_3DBorder border; |
| 83 |
Pixmap pixmap; |
| 84 |
int x = 0; |
| 85 |
|
| 86 |
int y, relief; |
| 87 |
Tk_Window tkwin = butPtr->tkwin; |
| 88 |
int width, height, fullWidth, fullHeight; |
| 89 |
int textXOffset, textYOffset; |
| 90 |
int haveImage = 0, haveText = 0; |
| 91 |
int offset; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
int imageWidth, imageHeight; |
| 96 |
int imageXOffset = 0, imageYOffset = 0; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
butPtr->flags &= ~REDRAW_PENDING; |
| 101 |
if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { |
| 102 |
return; |
| 103 |
} |
| 104 |
|
| 105 |
border = butPtr->normalBorder; |
| 106 |
if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) { |
| 107 |
gc = butPtr->disabledGC; |
| 108 |
} else if ((butPtr->state == STATE_ACTIVE) |
| 109 |
&& !Tk_StrictMotif(butPtr->tkwin)) { |
| 110 |
gc = butPtr->activeTextGC; |
| 111 |
border = butPtr->activeBorder; |
| 112 |
} else { |
| 113 |
gc = butPtr->normalTextGC; |
| 114 |
} |
| 115 |
if ((butPtr->flags & SELECTED) && (butPtr->state != STATE_ACTIVE) |
| 116 |
&& (butPtr->selectBorder != NULL) && !butPtr->indicatorOn) { |
| 117 |
border = butPtr->selectBorder; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
relief = butPtr->relief; |
| 150 |
if ((butPtr->type >= TYPE_CHECK_BUTTON) && !butPtr->indicatorOn) { |
| 151 |
if (butPtr->flags & SELECTED) { |
| 152 |
relief = TK_RELIEF_SUNKEN; |
| 153 |
} else if (butPtr->overRelief != relief) { |
| 154 |
relief = butPtr->offRelief; |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
offset = (butPtr->type == TYPE_BUTTON) && !Tk_StrictMotif(butPtr->tkwin); |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
pixmap = Tk_GetPixmap(butPtr->display, Tk_WindowId(tkwin), |
| 168 |
Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); |
| 169 |
Tk_Fill3DRectangle(tkwin, pixmap, border, 0, 0, Tk_Width(tkwin), |
| 170 |
Tk_Height(tkwin), 0, TK_RELIEF_FLAT); |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
if (butPtr->image != NULL) { |
| 177 |
Tk_SizeOfImage(butPtr->image, &width, &height); |
| 178 |
haveImage = 1; |
| 179 |
} else if (butPtr->bitmap != None) { |
| 180 |
Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height); |
| 181 |
haveImage = 1; |
| 182 |
} |
| 183 |
imageWidth = width; |
| 184 |
imageHeight = height; |
| 185 |
|
| 186 |
haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0); |
| 187 |
|
| 188 |
if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) { |
| 189 |
textXOffset = 0; |
| 190 |
textYOffset = 0; |
| 191 |
fullWidth = 0; |
| 192 |
fullHeight = 0; |
| 193 |
|
| 194 |
switch ((enum compound) butPtr->compound) { |
| 195 |
case COMPOUND_TOP: |
| 196 |
case COMPOUND_BOTTOM: { |
| 197 |
|
| 198 |
if (butPtr->compound == COMPOUND_TOP) { |
| 199 |
textYOffset = height + butPtr->padY; |
| 200 |
} else { |
| 201 |
imageYOffset = butPtr->textHeight + butPtr->padY; |
| 202 |
} |
| 203 |
fullHeight = height + butPtr->textHeight + butPtr->padY; |
| 204 |
fullWidth = (width > butPtr->textWidth ? width : |
| 205 |
butPtr->textWidth); |
| 206 |
textXOffset = (fullWidth - butPtr->textWidth)/2; |
| 207 |
imageXOffset = (fullWidth - width)/2; |
| 208 |
break; |
| 209 |
} |
| 210 |
case COMPOUND_LEFT: |
| 211 |
case COMPOUND_RIGHT: { |
| 212 |
|
| 213 |
if (butPtr->compound == COMPOUND_LEFT) { |
| 214 |
textXOffset = width + butPtr->padX; |
| 215 |
} else { |
| 216 |
imageXOffset = butPtr->textWidth + butPtr->padX; |
| 217 |
} |
| 218 |
fullWidth = butPtr->textWidth + butPtr->padX + width; |
| 219 |
fullHeight = (height > butPtr->textHeight ? height : |
| 220 |
butPtr->textHeight); |
| 221 |
textYOffset = (fullHeight - butPtr->textHeight)/2; |
| 222 |
imageYOffset = (fullHeight - height)/2; |
| 223 |
break; |
| 224 |
} |
| 225 |
case COMPOUND_CENTER: { |
| 226 |
|
| 227 |
fullWidth = (width > butPtr->textWidth ? width : |
| 228 |
butPtr->textWidth); |
| 229 |
fullHeight = (height > butPtr->textHeight ? height : |
| 230 |
butPtr->textHeight); |
| 231 |
textXOffset = (fullWidth - butPtr->textWidth)/2; |
| 232 |
imageXOffset = (fullWidth - width)/2; |
| 233 |
textYOffset = (fullHeight - butPtr->textHeight)/2; |
| 234 |
imageYOffset = (fullHeight - height)/2; |
| 235 |
break; |
| 236 |
} |
| 237 |
case COMPOUND_NONE: {break;} |
| 238 |
} |
| 239 |
|
| 240 |
TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY, |
| 241 |
butPtr->indicatorSpace + fullWidth, fullHeight, &x, &y); |
| 242 |
|
| 243 |
x += butPtr->indicatorSpace; |
| 244 |
|
| 245 |
x += offset; |
| 246 |
y += offset; |
| 247 |
if (relief == TK_RELIEF_RAISED) { |
| 248 |
x -= offset; |
| 249 |
y -= offset; |
| 250 |
} else if (relief == TK_RELIEF_SUNKEN) { |
| 251 |
x += offset; |
| 252 |
y += offset; |
| 253 |
} |
| 254 |
|
| 255 |
imageXOffset += x; |
| 256 |
imageYOffset += y; |
| 257 |
|
| 258 |
if (butPtr->image != NULL) { |
| 259 |
if ((butPtr->selectImage != NULL) && (butPtr->flags & SELECTED)) { |
| 260 |
Tk_RedrawImage(butPtr->selectImage, 0, 0, |
| 261 |
width, height, pixmap, imageXOffset, imageYOffset); |
| 262 |
} else { |
| 263 |
Tk_RedrawImage(butPtr->image, 0, 0, width, |
| 264 |
height, pixmap, imageXOffset, imageYOffset); |
| 265 |
} |
| 266 |
} else { |
| 267 |
XSetClipOrigin(butPtr->display, gc, imageXOffset, imageYOffset); |
| 268 |
XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, |
| 269 |
0, 0, (unsigned int) width, (unsigned int) height, |
| 270 |
imageXOffset, imageYOffset, 1); |
| 271 |
XSetClipOrigin(butPtr->display, gc, 0, 0); |
| 272 |
} |
| 273 |
|
| 274 |
Tk_DrawTextLayout(butPtr->display, pixmap, gc, |
| 275 |
butPtr->textLayout, x + textXOffset, y + textYOffset, 0, -1); |
| 276 |
Tk_UnderlineTextLayout(butPtr->display, pixmap, gc, |
| 277 |
butPtr->textLayout, x + textXOffset, y + textYOffset, |
| 278 |
butPtr->underline); |
| 279 |
y += fullHeight/2; |
| 280 |
} else { |
| 281 |
if (haveImage) { |
| 282 |
TkComputeAnchor(butPtr->anchor, tkwin, 0, 0, |
| 283 |
butPtr->indicatorSpace + width, height, &x, &y); |
| 284 |
x += butPtr->indicatorSpace; |
| 285 |
|
| 286 |
x += offset; |
| 287 |
y += offset; |
| 288 |
if (relief == TK_RELIEF_RAISED) { |
| 289 |
x -= offset; |
| 290 |
y -= offset; |
| 291 |
} else if (relief == TK_RELIEF_SUNKEN) { |
| 292 |
x += offset; |
| 293 |
y += offset; |
| 294 |
} |
| 295 |
imageXOffset += x; |
| 296 |
imageYOffset += y; |
| 297 |
if (butPtr->image != NULL) { |
| 298 |
if ((butPtr->selectImage != NULL) && |
| 299 |
(butPtr->flags & SELECTED)) { |
| 300 |
Tk_RedrawImage(butPtr->selectImage, 0, 0, width, |
| 301 |
height, pixmap, imageXOffset, imageYOffset); |
| 302 |
} else { |
| 303 |
Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap, |
| 304 |
imageXOffset, imageYOffset); |
| 305 |
} |
| 306 |
} else { |
| 307 |
XSetClipOrigin(butPtr->display, gc, x, y); |
| 308 |
XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, 0, 0, |
| 309 |
(unsigned int) width, (unsigned int) height, x, y, 1); |
| 310 |
XSetClipOrigin(butPtr->display, gc, 0, 0); |
| 311 |
} |
| 312 |
y += height/2; |
| 313 |
} else { |
| 314 |
TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY, |
| 315 |
butPtr->indicatorSpace + butPtr->textWidth, |
| 316 |
butPtr->textHeight, &x, &y); |
| 317 |
|
| 318 |
x += butPtr->indicatorSpace; |
| 319 |
|
| 320 |
x += offset; |
| 321 |
y += offset; |
| 322 |
if (relief == TK_RELIEF_RAISED) { |
| 323 |
x -= offset; |
| 324 |
y -= offset; |
| 325 |
} else if (relief == TK_RELIEF_SUNKEN) { |
| 326 |
x += offset; |
| 327 |
y += offset; |
| 328 |
} |
| 329 |
Tk_DrawTextLayout(butPtr->display, pixmap, gc, butPtr->textLayout, |
| 330 |
x, y, 0, -1); |
| 331 |
Tk_UnderlineTextLayout(butPtr->display, pixmap, gc, |
| 332 |
butPtr->textLayout, x, y, butPtr->underline); |
| 333 |
y += butPtr->textHeight/2; |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
if ((butPtr->type == TYPE_CHECK_BUTTON) && butPtr->indicatorOn) { |
| 344 |
int dim; |
| 345 |
|
| 346 |
dim = butPtr->indicatorDiameter; |
| 347 |
x -= butPtr->indicatorSpace; |
| 348 |
y -= dim/2; |
| 349 |
if (dim > 2*butPtr->borderWidth) { |
| 350 |
Tk_Draw3DRectangle(tkwin, pixmap, border, x, y, dim, dim, |
| 351 |
butPtr->borderWidth, |
| 352 |
(butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN : |
| 353 |
TK_RELIEF_RAISED); |
| 354 |
x += butPtr->borderWidth; |
| 355 |
y += butPtr->borderWidth; |
| 356 |
dim -= 2*butPtr->borderWidth; |
| 357 |
if (butPtr->flags & SELECTED) { |
| 358 |
GC gc; |
| 359 |
if (butPtr->state != STATE_DISABLED) { |
| 360 |
if (butPtr->selectBorder != NULL) { |
| 361 |
gc = Tk_3DBorderGC(tkwin, butPtr->selectBorder, |
| 362 |
TK_3D_FLAT_GC); |
| 363 |
} else { |
| 364 |
gc = Tk_3DBorderGC(tkwin, butPtr->normalBorder, |
| 365 |
TK_3D_FLAT_GC); |
| 366 |
} |
| 367 |
} else { |
| 368 |
if (butPtr->disabledFg != NULL) { |
| 369 |
gc = butPtr->disabledGC; |
| 370 |
} else { |
| 371 |
gc = butPtr->normalTextGC; |
| 372 |
XSetForeground(butPtr->display, butPtr->disabledGC, |
| 373 |
Tk_3DBorderColor(butPtr->normalBorder)->pixel); |
| 374 |
} |
| 375 |
} |
| 376 |
|
| 377 |
XFillRectangle(butPtr->display, pixmap, gc, x, y, |
| 378 |
(unsigned int) dim, (unsigned int) dim); |
| 379 |
} else { |
| 380 |
Tk_Fill3DRectangle(tkwin, pixmap, butPtr->normalBorder, x, y, |
| 381 |
dim, dim, butPtr->borderWidth, TK_RELIEF_FLAT); |
| 382 |
} |
| 383 |
} |
| 384 |
} else if ((butPtr->type == TYPE_RADIO_BUTTON) && butPtr->indicatorOn) { |
| 385 |
XPoint points[4]; |
| 386 |
int radius; |
| 387 |
|
| 388 |
radius = butPtr->indicatorDiameter/2; |
| 389 |
points[0].x = x - butPtr->indicatorSpace; |
| 390 |
points[0].y = y; |
| 391 |
points[1].x = points[0].x + radius; |
| 392 |
points[1].y = points[0].y + radius; |
| 393 |
points[2].x = points[1].x + radius; |
| 394 |
points[2].y = points[0].y; |
| 395 |
points[3].x = points[1].x; |
| 396 |
points[3].y = points[0].y - radius; |
| 397 |
if (butPtr->flags & SELECTED) { |
| 398 |
GC gc; |
| 399 |
|
| 400 |
if (butPtr->state != STATE_DISABLED) { |
| 401 |
if (butPtr->selectBorder != NULL) { |
| 402 |
gc = Tk_3DBorderGC(tkwin, butPtr->selectBorder, |
| 403 |
TK_3D_FLAT_GC); |
| 404 |
} else { |
| 405 |
gc = Tk_3DBorderGC(tkwin, butPtr->normalBorder, |
| 406 |
TK_3D_FLAT_GC); |
| 407 |
} |
| 408 |
} else { |
| 409 |
if (butPtr->disabledFg != NULL) { |
| 410 |
gc = butPtr->disabledGC; |
| 411 |
} else { |
| 412 |
gc = butPtr->normalTextGC; |
| 413 |
XSetForeground(butPtr->display, butPtr->disabledGC, |
| 414 |
Tk_3DBorderColor(butPtr->normalBorder)->pixel); |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
XFillPolygon(butPtr->display, pixmap, gc, points, 4, Convex, |
| 419 |
CoordModeOrigin); |
| 420 |
} else { |
| 421 |
Tk_Fill3DPolygon(tkwin, pixmap, butPtr->normalBorder, points, |
| 422 |
4, butPtr->borderWidth, TK_RELIEF_FLAT); |
| 423 |
} |
| 424 |
Tk_Draw3DPolygon(tkwin, pixmap, border, points, 4, butPtr->borderWidth, |
| 425 |
(butPtr->flags & SELECTED) ? TK_RELIEF_SUNKEN : |
| 426 |
TK_RELIEF_RAISED); |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
if ((butPtr->state == STATE_DISABLED) |
| 437 |
&& ((butPtr->disabledFg == NULL) || (butPtr->image != NULL))) { |
| 438 |
if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn |
| 439 |
&& (butPtr->selectBorder != NULL)) { |
| 440 |
XSetForeground(butPtr->display, butPtr->stippleGC, |
| 441 |
Tk_3DBorderColor(butPtr->selectBorder)->pixel); |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
if (butPtr->disabledFg == NULL) { |
| 448 |
XFillRectangle(butPtr->display, pixmap, butPtr->stippleGC, 0, 0, |
| 449 |
(unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin)); |
| 450 |
} else { |
| 451 |
XFillRectangle(butPtr->display, pixmap, butPtr->stippleGC, |
| 452 |
imageXOffset, imageYOffset, |
| 453 |
(unsigned) imageWidth, (unsigned) imageHeight); |
| 454 |
} |
| 455 |
if ((butPtr->flags & SELECTED) && !butPtr->indicatorOn |
| 456 |
&& (butPtr->selectBorder != NULL)) { |
| 457 |
XSetForeground(butPtr->display, butPtr->stippleGC, |
| 458 |
Tk_3DBorderColor(butPtr->normalBorder)->pixel); |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
if (relief != TK_RELIEF_FLAT) { |
| 471 |
int inset = butPtr->highlightWidth; |
| 472 |
|
| 473 |
if (butPtr->defaultState == DEFAULT_ACTIVE) { |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, inset, |
| 483 |
inset, Tk_Width(tkwin) - 2*inset, |
| 484 |
Tk_Height(tkwin) - 2*inset, 2, TK_RELIEF_FLAT); |
| 485 |
inset += 2; |
| 486 |
Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, inset, |
| 487 |
inset, Tk_Width(tkwin) - 2*inset, |
| 488 |
Tk_Height(tkwin) - 2*inset, 1, TK_RELIEF_SUNKEN); |
| 489 |
inset++; |
| 490 |
Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, inset, |
| 491 |
inset, Tk_Width(tkwin) - 2*inset, |
| 492 |
Tk_Height(tkwin) - 2*inset, 2, TK_RELIEF_FLAT); |
| 493 |
|
| 494 |
inset += 2; |
| 495 |
} else if (butPtr->defaultState == DEFAULT_NORMAL) { |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
Tk_Draw3DRectangle(tkwin, pixmap, butPtr->highlightBorder, 0, |
| 502 |
0, Tk_Width(tkwin), Tk_Height(tkwin), 5, TK_RELIEF_FLAT); |
| 503 |
inset += 5; |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
Tk_Draw3DRectangle(tkwin, pixmap, border, inset, inset, |
| 511 |
Tk_Width(tkwin) - 2*inset, Tk_Height(tkwin) - 2*inset, |
| 512 |
butPtr->borderWidth, relief); |
| 513 |
} |
| 514 |
if (butPtr->highlightWidth > 0) { |
| 515 |
GC gc; |
| 516 |
|
| 517 |
if (butPtr->flags & GOT_FOCUS) { |
| 518 |
gc = Tk_GCForColor(butPtr->highlightColorPtr, pixmap); |
| 519 |
} else { |
| 520 |
gc = Tk_GCForColor(Tk_3DBorderColor(butPtr->highlightBorder), |
| 521 |
pixmap); |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
if (butPtr->defaultState == DEFAULT_NORMAL) { |
| 530 |
TkDrawInsetFocusHighlight(tkwin, gc, butPtr->highlightWidth, |
| 531 |
pixmap, 5); |
| 532 |
} else { |
| 533 |
Tk_DrawFocusHighlight(tkwin, gc, butPtr->highlightWidth, pixmap); |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
XCopyArea(butPtr->display, pixmap, Tk_WindowId(tkwin), |
| 543 |
butPtr->copyGC, 0, 0, (unsigned) Tk_Width(tkwin), |
| 544 |
(unsigned) Tk_Height(tkwin), 0, 0); |
| 545 |
Tk_FreePixmap(butPtr->display, pixmap); |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
void |
| 567 |
TkpComputeButtonGeometry(butPtr) |
| 568 |
register TkButton *butPtr; |
| 569 |
{ |
| 570 |
int width, height, avgWidth, txtWidth, txtHeight; |
| 571 |
int haveImage = 0, haveText = 0; |
| 572 |
Tk_FontMetrics fm; |
| 573 |
|
| 574 |
butPtr->inset = butPtr->highlightWidth + butPtr->borderWidth; |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
if (butPtr->defaultState != DEFAULT_DISABLED) { |
| 581 |
butPtr->inset += 5; |
| 582 |
} |
| 583 |
butPtr->indicatorSpace = 0; |
| 584 |
|
| 585 |
width = 0; |
| 586 |
height = 0; |
| 587 |
txtWidth = 0; |
| 588 |
txtHeight = 0; |
| 589 |
avgWidth = 0; |
| 590 |
|
| 591 |
if (butPtr->image != NULL) { |
| 592 |
Tk_SizeOfImage(butPtr->image, &width, &height); |
| 593 |
haveImage = 1; |
| 594 |
} else if (butPtr->bitmap != None) { |
| 595 |
Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height); |
| 596 |
haveImage = 1; |
| 597 |
} |
| 598 |
|
| 599 |
if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) { |
| 600 |
Tk_FreeTextLayout(butPtr->textLayout); |
| 601 |
|
| 602 |
butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont, |
| 603 |
Tcl_GetString(butPtr->textPtr), -1, butPtr->wrapLength, |
| 604 |
butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight); |
| 605 |
|
| 606 |
txtWidth = butPtr->textWidth; |
| 607 |
txtHeight = butPtr->textHeight; |
| 608 |
avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1); |
| 609 |
Tk_GetFontMetrics(butPtr->tkfont, &fm); |
| 610 |
haveText = (txtWidth != 0 && txtHeight != 0); |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) { |
| 621 |
switch ((enum compound) butPtr->compound) { |
| 622 |
case COMPOUND_TOP: |
| 623 |
case COMPOUND_BOTTOM: { |
| 624 |
|
| 625 |
height += txtHeight + butPtr->padY; |
| 626 |
width = (width > txtWidth ? width : txtWidth); |
| 627 |
break; |
| 628 |
} |
| 629 |
case COMPOUND_LEFT: |
| 630 |
case COMPOUND_RIGHT: { |
| 631 |
|
| 632 |
width += txtWidth + butPtr->padX; |
| 633 |
height = (height > txtHeight ? height : txtHeight); |
| 634 |
break; |
| 635 |
} |
| 636 |
case COMPOUND_CENTER: { |
| 637 |
|
| 638 |
width = (width > txtWidth ? width : txtWidth); |
| 639 |
height = (height > txtHeight ? height : txtHeight); |
| 640 |
break; |
| 641 |
} |
| 642 |
case COMPOUND_NONE: {break;} |
| 643 |
} |
| 644 |
if (butPtr->width > 0) { |
| 645 |
width = butPtr->width; |
| 646 |
} |
| 647 |
if (butPtr->height > 0) { |
| 648 |
height = butPtr->height; |
| 649 |
} |
| 650 |
|
| 651 |
if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) { |
| 652 |
butPtr->indicatorSpace = height; |
| 653 |
if (butPtr->type == TYPE_CHECK_BUTTON) { |
| 654 |
butPtr->indicatorDiameter = (65*height)/100; |
| 655 |
} else { |
| 656 |
butPtr->indicatorDiameter = (75*height)/100; |
| 657 |
} |
| 658 |
} |
| 659 |
|
| 660 |
width += 2*butPtr->padX; |
| 661 |
height += 2*butPtr->padY; |
| 662 |
|
| 663 |
} else { |
| 664 |
if (haveImage) { |
| 665 |
if (butPtr->width > 0) { |
| 666 |
width = butPtr->width; |
| 667 |
} |
| 668 |
if (butPtr->height > 0) { |
| 669 |
height = butPtr->height; |
| 670 |
} |
| 671 |
|
| 672 |
if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) { |
| 673 |
butPtr->indicatorSpace = height; |
| 674 |
if (butPtr->type == TYPE_CHECK_BUTTON) { |
| 675 |
butPtr->indicatorDiameter = (65*height)/100; |
| 676 |
} else { |
| 677 |
butPtr->indicatorDiameter = (75*height)/100; |
| 678 |
} |
| 679 |
} |
| 680 |
} else { |
| 681 |
width = txtWidth; |
| 682 |
height = txtHeight; |
| 683 |
|
| 684 |
if (butPtr->width > 0) { |
| 685 |
width = butPtr->width * avgWidth; |
| 686 |
} |
| 687 |
if (butPtr->height > 0) { |
| 688 |
height = butPtr->height * fm.linespace; |
| 689 |
} |
| 690 |
if ((butPtr->type >= TYPE_CHECK_BUTTON) && butPtr->indicatorOn) { |
| 691 |
butPtr->indicatorDiameter = fm.linespace; |
| 692 |
if (butPtr->type == TYPE_CHECK_BUTTON) { |
| 693 |
butPtr->indicatorDiameter = |
| 694 |
(80*butPtr->indicatorDiameter)/100; |
| 695 |
} |
| 696 |
butPtr->indicatorSpace = butPtr->indicatorDiameter + avgWidth; |
| 697 |
} |
| 698 |
} |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
if ((butPtr->image == NULL) && (butPtr->bitmap == None)) { |
| 709 |
width += 2*butPtr->padX; |
| 710 |
height += 2*butPtr->padY; |
| 711 |
} |
| 712 |
if ((butPtr->type == TYPE_BUTTON) && !Tk_StrictMotif(butPtr->tkwin)) { |
| 713 |
width += 2; |
| 714 |
height += 2; |
| 715 |
} |
| 716 |
Tk_GeometryRequest(butPtr->tkwin, (int) (width + butPtr->indicatorSpace |
| 717 |
+ 2*butPtr->inset), (int) (height + 2*butPtr->inset)); |
| 718 |
Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset); |
| 719 |
} |