summaryrefslogtreecommitdiffstats
path: root/generic/tkPlace.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2022-02-02 15:08:27 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2022-02-02 15:08:27 (GMT)
commitdb1813195a62a66315c34ba2b4a341f3efb331a9 (patch)
tree60d2477ada09b28f45c1e8594004153451f10785 /generic/tkPlace.c
parent309c748ad6d849d9cdb327bed24cff7e04f7ebd0 (diff)
downloadtk-db1813195a62a66315c34ba2b4a341f3efb331a9.zip
tk-db1813195a62a66315c34ba2b4a341f3efb331a9.tar.gz
tk-db1813195a62a66315c34ba2b4a341f3efb331a9.tar.bz2
TIP #613 demo: rewrite "place" and text tag handling (-elide, -overstrike, -underline) using the new functionality
Diffstat (limited to 'generic/tkPlace.c')
-rw-r--r--generic/tkPlace.c65
1 files changed, 16 insertions, 49 deletions
diff --git a/generic/tkPlace.c b/generic/tkPlace.c
index 7818976..195275e 100644
--- a/generic/tkPlace.c
+++ b/generic/tkPlace.c
@@ -70,8 +70,6 @@ typedef struct Content {
Tk_Anchor anchor; /* Which point on tkwin is placed at the given
* position. */
BorderMode borderMode; /* How to treat borders of container window. */
- int flags; /* Various flags; see below for bit
- * definitions. */
} Content;
/*
@@ -109,20 +107,6 @@ static const Tk_OptionSpec optionSpecs[] = {
};
/*
- * Flag definitions for Content structures:
- *
- * CHILD_WIDTH - 1 means -width was specified;
- * CHILD_REL_WIDTH - 1 means -relwidth was specified.
- * CHILD_HEIGHT - 1 means -height was specified;
- * CHILD_REL_HEIGHT - 1 means -relheight was specified.
- */
-
-#define CHILD_WIDTH 1
-#define CHILD_REL_WIDTH 2
-#define CHILD_HEIGHT 4
-#define CHILD_REL_HEIGHT 8
-
-/*
* For each container window that has a content managed by the placer there is a
* structure of the following form:
*/
@@ -410,6 +394,10 @@ CreateContent(
contentPtr->inTkwin = NULL;
contentPtr->anchor = TK_ANCHOR_NW;
contentPtr->borderMode = BM_INSIDE;
+ contentPtr->width = INT_MIN;
+ contentPtr->height = INT_MIN;
+ contentPtr->relWidth = NAN;
+ contentPtr->relHeight = NAN;
contentPtr->optionTable = table;
Tcl_SetHashValue(hPtr, contentPtr);
Tk_CreateEventHandler(tkwin, StructureNotifyMask, ContentStructureProc,
@@ -646,27 +634,6 @@ ConfigureContent(
goto error;
}
- /*
- * Set content flags. First clear the field, then add bits as needed.
- */
-
- contentPtr->flags = 0;
- if (contentPtr->heightPtr) {
- contentPtr->flags |= CHILD_HEIGHT;
- }
-
- if (contentPtr->relHeightPtr) {
- contentPtr->flags |= CHILD_REL_HEIGHT;
- }
-
- if (contentPtr->relWidthPtr) {
- contentPtr->flags |= CHILD_REL_WIDTH;
- }
-
- if (contentPtr->widthPtr) {
- contentPtr->flags |= CHILD_WIDTH;
- }
-
if (!(mask & IN_MASK) && (contentPtr->containerPtr != NULL)) {
/*
* If no -in option was passed and the content is already placed then
@@ -824,23 +791,23 @@ PlaceInfoCommand(
Tcl_AppendPrintfToObj(infoObj,
"-x %d -relx %.4g -y %d -rely %.4g",
contentPtr->x, contentPtr->relX, contentPtr->y, contentPtr->relY);
- if (contentPtr->flags & CHILD_WIDTH) {
+ if (contentPtr->width != INT_MIN) {
Tcl_AppendPrintfToObj(infoObj, " -width %d", contentPtr->width);
} else {
Tcl_AppendToObj(infoObj, " -width {}", -1);
}
- if (contentPtr->flags & CHILD_REL_WIDTH) {
+ if (!TkIsNaN(contentPtr->relWidth)) {
Tcl_AppendPrintfToObj(infoObj,
" -relwidth %.4g", contentPtr->relWidth);
} else {
Tcl_AppendToObj(infoObj, " -relwidth {}", -1);
}
- if (contentPtr->flags & CHILD_HEIGHT) {
+ if (contentPtr->height != INT_MIN) {
Tcl_AppendPrintfToObj(infoObj, " -height %d", contentPtr->height);
} else {
Tcl_AppendToObj(infoObj, " -height {}", -1);
}
- if (contentPtr->flags & CHILD_REL_HEIGHT) {
+ if (!TkIsNaN(contentPtr->relHeight)) {
Tcl_AppendPrintfToObj(infoObj,
" -relheight %.4g", contentPtr->relHeight);
} else {
@@ -936,12 +903,12 @@ RecomputePlacement(
x = (int) (x1 + ((x1 > 0) ? 0.5 : -0.5));
y1 = contentPtr->y + containerY + (contentPtr->relY*containerHeight);
y = (int) (y1 + ((y1 > 0) ? 0.5 : -0.5));
- if (contentPtr->flags & (CHILD_WIDTH|CHILD_REL_WIDTH)) {
+ if ((contentPtr->width != INT_MIN) || !TkIsNaN(contentPtr->relWidth)) {
width = 0;
- if (contentPtr->flags & CHILD_WIDTH) {
+ if (contentPtr->width != INT_MIN) {
width += contentPtr->width;
}
- if (contentPtr->flags & CHILD_REL_WIDTH) {
+ if (!TkIsNaN(contentPtr->relWidth)) {
/*
* The code below is a bit tricky. In order to round correctly
* when both relX and relWidth are specified, compute the
@@ -958,12 +925,12 @@ RecomputePlacement(
width = Tk_ReqWidth(contentPtr->tkwin)
+ 2*Tk_Changes(contentPtr->tkwin)->border_width;
}
- if (contentPtr->flags & (CHILD_HEIGHT|CHILD_REL_HEIGHT)) {
+ if (((contentPtr->height != INT_MIN)) || !TkIsNaN(contentPtr->relHeight)) {
height = 0;
- if (contentPtr->flags & CHILD_HEIGHT) {
+ if (contentPtr->height != INT_MIN) {
height += contentPtr->height;
}
- if (contentPtr->flags & CHILD_REL_HEIGHT) {
+ if (!TkIsNaN(contentPtr->relHeight)) {
/*
* See note above for rounding errors in width computation.
*/
@@ -1214,8 +1181,8 @@ PlaceRequestProc(
Content *contentPtr = (Content *)clientData;
Container *containerPtr;
- if ((contentPtr->flags & (CHILD_WIDTH|CHILD_REL_WIDTH))
- && (contentPtr->flags & (CHILD_HEIGHT|CHILD_REL_HEIGHT))) {
+ if (((contentPtr->width != INT_MIN) || !TkIsNaN(contentPtr->relWidth))
+ && ((contentPtr->height != INT_MIN) || !TkIsNaN(contentPtr->relHeight))) {
/*
* Send a ConfigureNotify to indicate that the size change
* request was rejected.