MCPcopy Create free account
hub / github.com/SimHacker/micropolis / ComputeMessageGeometry

Function ComputeMessageGeometry

micropolis-activity/src/tk/tkmsg.c:479–567  ·  view source on GitHub ↗
(msgPtr)

Source from the content-addressed store, hash-verified

477 * Side effects:
478 * Tk_GeometryRequest is called to inform the geometry
479 * manager of the desired geometry for this window.
480 *
481 *--------------------------------------------------------------
482 */
483
484static void
485ComputeMessageGeometry(msgPtr)
486 register Message *msgPtr; /* Information about window. */
487{
488 char *p;
489 int width, inc, height, numLines;
490 int thisWidth, maxWidth;
491 int aspect, lowerBound, upperBound;
492
493 /*
494 * Compute acceptable bounds for the final aspect ratio.
495 */
496 aspect = msgPtr->aspect/10;
497 if (aspect < 5) {
498 aspect = 5;
499 }
500 lowerBound = msgPtr->aspect - aspect;
501 upperBound = msgPtr->aspect + aspect;
502
503 /*
504 * Do the computation in multiple passes: start off with
505 * a very wide window, and compute its height. Then change
506 * the width and try again. Reduce the size of the change
507 * and iterate until dimensions are found that approximate
508 * the desired aspect ratio. Or, if the user gave an explicit
509 * width then just use that.
510 */
511
512 if (msgPtr->width > 0) {
513 width = msgPtr->width;
514 inc = 0;
515 } else {
516 width = WidthOfScreen(Tk_Screen(msgPtr->tkwin))/2;
517 inc = width/2;
518 }
519 for ( ; ; inc /= 2) {
520 maxWidth = 0;
521 for (numLines = 1, p = msgPtr->string; ; numLines++) {
522 if (*p == '\n') {
523 p++;
524 continue;
525 }
526 p += TkMeasureChars(msgPtr->fontPtr, p,
527 msgPtr->numChars - (p - msgPtr->string), 0, width,
528 TK_WHOLE_WORDS|TK_AT_LEAST_ONE, &thisWidth);
529 if (thisWidth > maxWidth) {
530 maxWidth = thisWidth;
531 }
532 if (*p == 0) {
533 break;
534 }
535
536 /*

Callers 2

ConfigureMessageFunction · 0.85
tkmsg.cFile · 0.85

Calls 3

TkMeasureCharsFunction · 0.85
Tk_GeometryRequestFunction · 0.85
Tk_SetInternalBorderFunction · 0.85

Tested by

no test coverage detected