| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include "default.h" |
| 16 |
#include "tkInt.h" |
| 17 |
#include "tkMenubutton.h" |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
Tk_ClassProcs tkpMenubuttonClass = { |
| 25 |
sizeof(Tk_ClassProcs), |
| 26 |
TkMenuButtonWorldChanged, |
| 27 |
}; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
TkMenuButton * |
| 46 |
TkpCreateMenuButton(tkwin) |
| 47 |
Tk_Window tkwin; |
| 48 |
{ |
| 49 |
return (TkMenuButton *)ckalloc(sizeof(TkMenuButton)); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
void |
| 70 |
TkpDisplayMenuButton(clientData) |
| 71 |
ClientData clientData; |
| 72 |
{ |
| 73 |
register TkMenuButton *mbPtr = (TkMenuButton *) clientData; |
| 74 |
GC gc; |
| 75 |
Tk_3DBorder border; |
| 76 |
Pixmap pixmap; |
| 77 |
int x = 0; |
| 78 |
|
| 79 |
int y = 0; |
| 80 |
register Tk_Window tkwin = mbPtr->tkwin; |
| 81 |
int width, height, fullWidth, fullHeight; |
| 82 |
int textXOffset, textYOffset; |
| 83 |
int imageWidth, imageHeight; |
| 84 |
int imageXOffset, imageYOffset; |
| 85 |
|
| 86 |
int haveImage = 0, haveText = 0; |
| 87 |
|
| 88 |
mbPtr->flags &= ~REDRAW_PENDING; |
| 89 |
if ((mbPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { |
| 90 |
return; |
| 91 |
} |
| 92 |
|
| 93 |
if ((mbPtr->state == STATE_DISABLED) && (mbPtr->disabledFg != NULL)) { |
| 94 |
gc = mbPtr->disabledGC; |
| 95 |
border = mbPtr->normalBorder; |
| 96 |
} else if ((mbPtr->state == STATE_ACTIVE) |
| 97 |
&& !Tk_StrictMotif(mbPtr->tkwin)) { |
| 98 |
gc = mbPtr->activeTextGC; |
| 99 |
border = mbPtr->activeBorder; |
| 100 |
} else { |
| 101 |
gc = mbPtr->normalTextGC; |
| 102 |
border = mbPtr->normalBorder; |
| 103 |
} |
| 104 |
|
| 105 |
if (mbPtr->image != None) { |
| 106 |
Tk_SizeOfImage(mbPtr->image, &width, &height); |
| 107 |
haveImage = 1; |
| 108 |
} else if (mbPtr->bitmap != None) { |
| 109 |
Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height); |
| 110 |
haveImage = 1; |
| 111 |
} |
| 112 |
imageWidth = width; |
| 113 |
imageHeight = height; |
| 114 |
|
| 115 |
haveText = (mbPtr->textWidth != 0 && mbPtr->textHeight != 0); |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
pixmap = Tk_GetPixmap(mbPtr->display, Tk_WindowId(tkwin), |
| 125 |
Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); |
| 126 |
Tk_Fill3DRectangle(tkwin, pixmap, border, 0, 0, Tk_Width(tkwin), |
| 127 |
Tk_Height(tkwin), 0, TK_RELIEF_FLAT); |
| 128 |
|
| 129 |
imageXOffset = 0; |
| 130 |
imageYOffset = 0; |
| 131 |
textXOffset = 0; |
| 132 |
textYOffset = 0; |
| 133 |
fullWidth = 0; |
| 134 |
fullHeight = 0; |
| 135 |
|
| 136 |
if (mbPtr->compound != COMPOUND_NONE && haveImage && haveText) { |
| 137 |
switch ((enum compound) mbPtr->compound) { |
| 138 |
case COMPOUND_TOP: |
| 139 |
case COMPOUND_BOTTOM: { |
| 140 |
|
| 141 |
if (mbPtr->compound == COMPOUND_TOP) { |
| 142 |
textYOffset = height + mbPtr->padY; |
| 143 |
} else { |
| 144 |
imageYOffset = mbPtr->textHeight + mbPtr->padY; |
| 145 |
} |
| 146 |
fullHeight = height + mbPtr->textHeight + mbPtr->padY; |
| 147 |
fullWidth = (width > mbPtr->textWidth ? width : |
| 148 |
mbPtr->textWidth); |
| 149 |
textXOffset = (fullWidth - mbPtr->textWidth)/2; |
| 150 |
imageXOffset = (fullWidth - width)/2; |
| 151 |
break; |
| 152 |
} |
| 153 |
case COMPOUND_LEFT: |
| 154 |
case COMPOUND_RIGHT: { |
| 155 |
|
| 156 |
if (mbPtr->compound == COMPOUND_LEFT) { |
| 157 |
textXOffset = width + mbPtr->padX; |
| 158 |
} else { |
| 159 |
imageXOffset = mbPtr->textWidth + mbPtr->padX; |
| 160 |
} |
| 161 |
fullWidth = mbPtr->textWidth + mbPtr->padX + width; |
| 162 |
fullHeight = (height > mbPtr->textHeight ? height : |
| 163 |
mbPtr->textHeight); |
| 164 |
textYOffset = (fullHeight - mbPtr->textHeight)/2; |
| 165 |
imageYOffset = (fullHeight - height)/2; |
| 166 |
break; |
| 167 |
} |
| 168 |
case COMPOUND_CENTER: { |
| 169 |
|
| 170 |
fullWidth = (width > mbPtr->textWidth ? width : |
| 171 |
mbPtr->textWidth); |
| 172 |
fullHeight = (height > mbPtr->textHeight ? height : |
| 173 |
mbPtr->textHeight); |
| 174 |
textXOffset = (fullWidth - mbPtr->textWidth)/2; |
| 175 |
imageXOffset = (fullWidth - width)/2; |
| 176 |
textYOffset = (fullHeight - mbPtr->textHeight)/2; |
| 177 |
imageYOffset = (fullHeight - height)/2; |
| 178 |
break; |
| 179 |
} |
| 180 |
case COMPOUND_NONE: {break;} |
| 181 |
} |
| 182 |
|
| 183 |
TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0, |
| 184 |
mbPtr->indicatorWidth + fullWidth, fullHeight, &x, &y); |
| 185 |
|
| 186 |
imageXOffset += x; |
| 187 |
imageYOffset += y; |
| 188 |
if (mbPtr->image != NULL) { |
| 189 |
Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap, |
| 190 |
imageXOffset, imageYOffset); |
| 191 |
} else if (mbPtr->bitmap != None) { |
| 192 |
XSetClipOrigin(mbPtr->display, gc, imageXOffset, imageYOffset); |
| 193 |
XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap, |
| 194 |
gc, 0, 0, (unsigned) width, (unsigned) height, |
| 195 |
imageXOffset, imageYOffset, 1); |
| 196 |
XSetClipOrigin(mbPtr->display, gc, 0, 0); |
| 197 |
} |
| 198 |
|
| 199 |
Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, |
| 200 |
x + textXOffset, y + textYOffset, 0, -1); |
| 201 |
Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, |
| 202 |
x + textXOffset, y + textYOffset, mbPtr->underline); |
| 203 |
} else if (haveImage) { |
| 204 |
TkComputeAnchor(mbPtr->anchor, tkwin, 0, 0, |
| 205 |
width + mbPtr->indicatorWidth, height, &x, &y); |
| 206 |
imageXOffset += x; |
| 207 |
imageYOffset += y; |
| 208 |
if (mbPtr->image != NULL) { |
| 209 |
Tk_RedrawImage(mbPtr->image, 0, 0, width, height, pixmap, |
| 210 |
imageXOffset, imageYOffset); |
| 211 |
} else if (mbPtr->bitmap != None) { |
| 212 |
XSetClipOrigin(mbPtr->display, gc, x, y); |
| 213 |
XCopyPlane(mbPtr->display, mbPtr->bitmap, pixmap, |
| 214 |
gc, 0, 0, (unsigned) width, (unsigned) height, |
| 215 |
x, y, 1); |
| 216 |
XSetClipOrigin(mbPtr->display, gc, 0, 0); |
| 217 |
} |
| 218 |
} else { |
| 219 |
TkComputeAnchor(mbPtr->anchor, tkwin, mbPtr->padX, mbPtr->padY, |
| 220 |
mbPtr->textWidth + mbPtr->indicatorWidth, |
| 221 |
mbPtr->textHeight, &x, &y); |
| 222 |
Tk_DrawTextLayout(mbPtr->display, pixmap, gc, mbPtr->textLayout, |
| 223 |
x + textXOffset, y + textYOffset, 0, -1); |
| 224 |
Tk_UnderlineTextLayout(mbPtr->display, pixmap, gc, |
| 225 |
mbPtr->textLayout, x + textXOffset, y + textYOffset, |
| 226 |
mbPtr->underline); |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
if ((mbPtr->state == STATE_DISABLED) |
| 235 |
&& ((mbPtr->disabledFg == NULL) || (mbPtr->image != NULL))) { |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
if (mbPtr->disabledFg == NULL) { |
| 241 |
XFillRectangle(mbPtr->display, pixmap, mbPtr->stippleGC, |
| 242 |
mbPtr->inset, mbPtr->inset, |
| 243 |
(unsigned) (Tk_Width(tkwin) - 2*mbPtr->inset), |
| 244 |
(unsigned) (Tk_Height(tkwin) - 2*mbPtr->inset)); |
| 245 |
} else { |
| 246 |
XFillRectangle(mbPtr->display, pixmap, mbPtr->stippleGC, |
| 247 |
imageXOffset, imageYOffset, |
| 248 |
(unsigned) imageWidth, (unsigned) imageHeight); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
if (mbPtr->indicatorOn) { |
| 258 |
int borderWidth; |
| 259 |
|
| 260 |
borderWidth = (mbPtr->indicatorHeight+1)/3; |
| 261 |
if (borderWidth < 1) { |
| 262 |
borderWidth = 1; |
| 263 |
} |
| 264 |
|
| 265 |
Tk_Fill3DRectangle(tkwin, pixmap, border, |
| 266 |
Tk_Width(tkwin) - mbPtr->inset - mbPtr->indicatorWidth |
| 267 |
+ mbPtr->indicatorHeight, |
| 268 |
((int) (Tk_Height(tkwin) - mbPtr->indicatorHeight))/2, |
| 269 |
mbPtr->indicatorWidth - 2*mbPtr->indicatorHeight, |
| 270 |
mbPtr->indicatorHeight, borderWidth, TK_RELIEF_RAISED); |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
if (mbPtr->relief != TK_RELIEF_FLAT) { |
| 280 |
Tk_Draw3DRectangle(tkwin, pixmap, border, |
| 281 |
mbPtr->highlightWidth, mbPtr->highlightWidth, |
| 282 |
Tk_Width(tkwin) - 2*mbPtr->highlightWidth, |
| 283 |
Tk_Height(tkwin) - 2*mbPtr->highlightWidth, |
| 284 |
mbPtr->borderWidth, mbPtr->relief); |
| 285 |
} |
| 286 |
if (mbPtr->highlightWidth != 0) { |
| 287 |
GC gc; |
| 288 |
|
| 289 |
if (mbPtr->flags & GOT_FOCUS) { |
| 290 |
gc = Tk_GCForColor(mbPtr->highlightColorPtr, pixmap); |
| 291 |
} else { |
| 292 |
gc = Tk_GCForColor(mbPtr->highlightBgColorPtr, pixmap); |
| 293 |
} |
| 294 |
Tk_DrawFocusHighlight(tkwin, gc, mbPtr->highlightWidth, pixmap); |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
XCopyArea(mbPtr->display, pixmap, Tk_WindowId(tkwin), |
| 303 |
mbPtr->normalTextGC, 0, 0, (unsigned) Tk_Width(tkwin), |
| 304 |
(unsigned) Tk_Height(tkwin), 0, 0); |
| 305 |
Tk_FreePixmap(mbPtr->display, pixmap); |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
void |
| 325 |
TkpDestroyMenuButton(mbPtr) |
| 326 |
TkMenuButton *mbPtr; |
| 327 |
{ |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
void |
| 349 |
TkpComputeMenuButtonGeometry(mbPtr) |
| 350 |
TkMenuButton *mbPtr; |
| 351 |
{ |
| 352 |
int width, height, mm, pixels; |
| 353 |
int avgWidth, txtWidth, txtHeight; |
| 354 |
int haveImage = 0, haveText = 0; |
| 355 |
Tk_FontMetrics fm; |
| 356 |
|
| 357 |
mbPtr->inset = mbPtr->highlightWidth + mbPtr->borderWidth; |
| 358 |
|
| 359 |
width = 0; |
| 360 |
height = 0; |
| 361 |
txtWidth = 0; |
| 362 |
txtHeight = 0; |
| 363 |
avgWidth = 0; |
| 364 |
|
| 365 |
if (mbPtr->image != None) { |
| 366 |
Tk_SizeOfImage(mbPtr->image, &width, &height); |
| 367 |
haveImage = 1; |
| 368 |
} else if (mbPtr->bitmap != None) { |
| 369 |
Tk_SizeOfBitmap(mbPtr->display, mbPtr->bitmap, &width, &height); |
| 370 |
haveImage = 1; |
| 371 |
} |
| 372 |
|
| 373 |
if (haveImage == 0 || mbPtr->compound != COMPOUND_NONE) { |
| 374 |
Tk_FreeTextLayout(mbPtr->textLayout); |
| 375 |
|
| 376 |
mbPtr->textLayout = Tk_ComputeTextLayout(mbPtr->tkfont, mbPtr->text, |
| 377 |
-1, mbPtr->wrapLength, mbPtr->justify, 0, &mbPtr->textWidth, |
| 378 |
&mbPtr->textHeight); |
| 379 |
txtWidth = mbPtr->textWidth; |
| 380 |
txtHeight = mbPtr->textHeight; |
| 381 |
avgWidth = Tk_TextWidth(mbPtr->tkfont, "0", 1); |
| 382 |
Tk_GetFontMetrics(mbPtr->tkfont, &fm); |
| 383 |
haveText = (txtWidth != 0 && txtHeight != 0); |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
if (mbPtr->compound != COMPOUND_NONE && haveImage && haveText) { |
| 394 |
switch ((enum compound) mbPtr->compound) { |
| 395 |
case COMPOUND_TOP: |
| 396 |
case COMPOUND_BOTTOM: { |
| 397 |
|
| 398 |
height += txtHeight + mbPtr->padY; |
| 399 |
width = (width > txtWidth ? width : txtWidth); |
| 400 |
break; |
| 401 |
} |
| 402 |
case COMPOUND_LEFT: |
| 403 |
case COMPOUND_RIGHT: { |
| 404 |
|
| 405 |
width += txtWidth + mbPtr->padX; |
| 406 |
height = (height > txtHeight ? height : txtHeight); |
| 407 |
break; |
| 408 |
} |
| 409 |
case COMPOUND_CENTER: { |
| 410 |
|
| 411 |
width = (width > txtWidth ? width : txtWidth); |
| 412 |
height = (height > txtHeight ? height : txtHeight); |
| 413 |
break; |
| 414 |
} |
| 415 |
case COMPOUND_NONE: {break;} |
| 416 |
} |
| 417 |
if (mbPtr->width > 0) { |
| 418 |
width = mbPtr->width; |
| 419 |
} |
| 420 |
if (mbPtr->height > 0) { |
| 421 |
height = mbPtr->height; |
| 422 |
} |
| 423 |
width += 2*mbPtr->padX; |
| 424 |
height += 2*mbPtr->padY; |
| 425 |
} else { |
| 426 |
if (haveImage) { |
| 427 |
if (mbPtr->width > 0) { |
| 428 |
width = mbPtr->width; |
| 429 |
} |
| 430 |
if (mbPtr->height > 0) { |
| 431 |
height = mbPtr->height; |
| 432 |
} |
| 433 |
} else { |
| 434 |
width = txtWidth; |
| 435 |
height = txtHeight; |
| 436 |
if (mbPtr->width > 0) { |
| 437 |
width = mbPtr->width * avgWidth; |
| 438 |
} |
| 439 |
if (mbPtr->height > 0) { |
| 440 |
height = mbPtr->height * fm.linespace; |
| 441 |
} |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
if (! haveImage) { |
| 446 |
width += 2*mbPtr->padX; |
| 447 |
height += 2*mbPtr->padY; |
| 448 |
} |
| 449 |
|
| 450 |
if (mbPtr->indicatorOn) { |
| 451 |
mm = WidthMMOfScreen(Tk_Screen(mbPtr->tkwin)); |
| 452 |
pixels = WidthOfScreen(Tk_Screen(mbPtr->tkwin)); |
| 453 |
mbPtr->indicatorHeight= (INDICATOR_HEIGHT * pixels)/(10*mm); |
| 454 |
mbPtr->indicatorWidth = (INDICATOR_WIDTH * pixels)/(10*mm) |
| 455 |
+ 2*mbPtr->indicatorHeight; |
| 456 |
width += mbPtr->indicatorWidth; |
| 457 |
} else { |
| 458 |
mbPtr->indicatorHeight = 0; |
| 459 |
mbPtr->indicatorWidth = 0; |
| 460 |
} |
| 461 |
|
| 462 |
Tk_GeometryRequest(mbPtr->tkwin, (int) (width + 2*mbPtr->inset), |
| 463 |
(int) (height + 2*mbPtr->inset)); |
| 464 |
Tk_SetInternalBorder(mbPtr->tkwin, mbPtr->inset); |
| 465 |
} |