summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorericm <ericm>2000-08-10 00:21:05 (GMT)
committerericm <ericm>2000-08-10 00:21:05 (GMT)
commitfcb8e69104714a2eb1b9acea70d39dd51331f5fd (patch)
tree3acd79b0de2739be7bffae01ae70436c029d98a9
parent21cbf6e8a1d65d4d6f9e5ba0426cc14d5649f0c3 (diff)
downloadtk-fcb8e69104714a2eb1b9acea70d39dd51331f5fd.zip
tk-fcb8e69104714a2eb1b9acea70d39dd51331f5fd.tar.gz
tk-fcb8e69104714a2eb1b9acea70d39dd51331f5fd.tar.bz2
* doc/SetOptions.3: Updated documentation to reflect support for
TK_OPTION_NULL_OK for TK_OPTION_DOUBLE and TK_OPTION_PIXELS. * generic/tkConfig.c: Added for TK_OPTION_NULL_OK support for TK_OPTION_DOUBLE and TK_OPTION_PIXELS. * doc/place.n: Updated, reformatted manual entry. * tests/place.test: Added many tests. * generic/tkPlace.c (Tk_PlaceObjCmd): Updated to use Tk widget-option management facilities to manage place options (-x, -y, etc.), which simplifies the placer code. Added support for [place configure pathName] and [place configure pathName -option], similar to the behavior of the configure subcommand supported by widgets.
-rw-r--r--ChangeLog19
-rw-r--r--doc/SetOptions.313
-rw-r--r--doc/place.n209
-rw-r--r--generic/tkConfig.c26
-rw-r--r--generic/tkMessage.c4
-rw-r--r--generic/tkPlace.c650
-rw-r--r--tests/place.test79
7 files changed, 552 insertions, 448 deletions
diff --git a/ChangeLog b/ChangeLog
index cf2376b..f35ea95 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2000-08-09 Eric Melski <ericm@ajubasolutions.com>
+
+ * doc/SetOptions.3: Updated documentation to reflect support for
+ TK_OPTION_NULL_OK for TK_OPTION_DOUBLE and TK_OPTION_PIXELS.
+
+ * generic/tkConfig.c: Added for TK_OPTION_NULL_OK support for
+ TK_OPTION_DOUBLE and TK_OPTION_PIXELS.
+
+ * doc/place.n: Updated, reformatted manual entry.
+
+ * tests/place.test: Added many tests.
+
+ * generic/tkPlace.c (Tk_PlaceObjCmd): Updated to use Tk
+ widget-option management facilities to manage place options (-x,
+ -y, etc.), which simplifies the placer code. Added support for
+ [place configure pathName] and [place configure pathName -option],
+ similar to the behavior of the configure subcommand supported by
+ widgets.
+
2000-08-08 Eric Melski <ericm@ajubasolutions.com>
* tests/place.test: Extended test suite to test error returns from
diff --git a/doc/SetOptions.3 b/doc/SetOptions.3
index 8393085..29f6e72 100644
--- a/doc/SetOptions.3
+++ b/doc/SetOptions.3
@@ -4,7 +4,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: SetOptions.3,v 1.3 2000/05/17 21:17:19 ericm Exp $
+'\" RCS: @(#) $Id: SetOptions.3,v 1.4 2000/08/10 00:21:06 ericm Exp $
'\"
.so man.macros
.TH Tk_SetOptions 3 8.1 Tk "Tk Library Procedures"
@@ -311,8 +311,8 @@ The \fIflags\fR field consists of one or more bits ORed together. At
present only a single flag is supported: TK_OPTION_NULL_OK. If
this bit is set for an option then an empty string will be accepted as
the value for the option and the resulting internal form will be a
-NULL pointer or \fBNone\fR, depending on the type of the option.
-If the flag is not set then empty strings will result
+NULL pointer, a zero value, or \fBNone\fR, depending on the type of
+the option. If the flag is not set then empty strings will result
in errors.
TK_OPTION_NULL_OK is typically used to allow a
feature to be turned off entirely, e.g. set a cursor value to
@@ -371,7 +371,8 @@ option type also supports the TK_OPTION_NULL_OK flag.
\fBTK_OPTION_DOUBLE\fR
The string value must be a floating-point number in
the format accepted by \fBstrtol\fR. The internal form is a C
-\fBdouble\fR value.
+\fBdouble\fR value. This option type supports the TK_OPTION_NULL_OK
+flag; if a NULL value is set, the internal representation is set to zero.
.TP
\fBTK_OPTION_END\fR
Marks the end of the template. There must be a Tk_OptionSpec structure
@@ -406,7 +407,9 @@ The internal form is an integer value giving a
distance in pixels, like the values returned by
\fBTk_GetPixelsFromObj\fR. Note: if the \fIobjOffset\fR field isn't
used then information about the original value of this option will be lost.
-See \fBOBJOFFSET VS. INTERNALOFFSET\fR below for details.
+See \fBOBJOFFSET VS. INTERNALOFFSET\fR below for details. This option
+type supports the TK_OPTION_NULL_OK flag; if a NULL value is set, the
+internal representation is set to zero.
.TP
\fBTK_OPTION_RELIEF\fR
The value must be standard relief such as \fBraised\fR.
diff --git a/doc/place.n b/doc/place.n
index b51e996..3a256e1 100644
--- a/doc/place.n
+++ b/doc/place.n
@@ -5,7 +5,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: place.n,v 1.2 1998/09/14 18:22:59 stanton Exp $
+'\" RCS: @(#) $Id: place.n,v 1.3 2000/08/10 00:21:06 ericm Exp $
'\"
.so man.macros
.TH place n "" Tk "Tk Built-In Commands"
@@ -16,7 +16,7 @@ place \- Geometry manager for fixed or rubber-sheet placement
.SH SYNOPSIS
\fBplace \fIwindow option value \fR?\fIoption value ...\fR?
.sp
-\fBplace configure \fIwindow option value \fR?\fIoption value ...\fR?
+\fBplace configure \fIwindow \fR?\fIoption\fR? ?\fIvalue option value ...\fR?
.sp
\fBplace forget \fIwindow\fR
.sp
@@ -39,16 +39,69 @@ Lastly, the placer allows you to mix these styles of placement so
that, for example, the slave has a fixed width and height but is
centered inside the master.
.PP
-If the first argument to the \fBplace\fR command is a window path
-name or \fBconfigure\fR then the command arranges for the placer
-to manage the geometry of a slave whose path name is \fIwindow\fR.
-The remaining arguments consist of one or more \fIoption\-value\fR
-pairs that specify the way in which \fIwindow\fR's
-geometry is managed.
-If the placer is already managing \fIwindow\fR, then the
-\fIoption\-value\fR pairs modify the configuration for \fIwindow\fR.
-In this form the \fBplace\fR command returns an empty string as result.
+.TP
+\fBplace \fIwindow option value \fR?\fIoption value ...\fR?
+Arrange for the placer to manage the geometry of a slave whose
+pathName is \fIwindow\fR. The remaining arguments consist of one or
+more \fIoption\-value\fR pairs that specify the way in which
+\fIwindow\fR's geometry is managed. \fIOption\fR may have any of the
+values accepted by the \fBplace configure\fR command.
+.TP
+\fBplace configure \fIwindow \fR?\fIoption\fR? ?\fIvalue option value ...\fR?
+Query or modify the geometry options of the slave given by
+\fIwindow\fR. If no \fIoption\fR is specified, this command returns a
+list describing the available options (see \fBTk_ConfigureInfo\fR for
+information on the format of this list). If \fIoption\fR is specified
+with no \fIvalue\fR, then the command returns a list describing the
+one named option (this list will be identical to the corresponding
+sublist of the value returned if no \fIoption\fR is specified). If
+one or more \fIoption\-value\fR pairs are specified, then the command
+modifies the given option(s) to have the given value(s); in this case
+the command returns an empty string.
+
The following \fIoption\-value\fR pairs are supported:
+.RS
+.TP
+\fB\-anchor \fIwhere\fR
+\fIWhere\fR specifies which point of \fIwindow\fR is to be positioned
+at the (x,y) location selected by the \fB\-x\fR, \fB\-y\fR,
+\fB\-relx\fR, and \fB\-rely\fR options.
+The anchor point is in terms of the outer area of \fIwindow\fR
+including its border, if any.
+Thus if \fIwhere\fR is \fBse\fR then the lower-right corner of
+\fIwindow\fR's border will appear at the given (x,y) location
+in the master.
+The anchor position defaults to \fBnw\fR.
+.TP
+\fB\-bordermode \fImode\fR
+\fIMode\fR determines the degree to which borders within the
+master are used in determining the placement of the slave.
+The default and most common value is \fBinside\fR.
+In this case the placer considers the area of the master to
+be the innermost area of the master, inside any border:
+an option of \fB\-x 0\fR corresponds to an x-coordinate just
+inside the border and an option of \fB\-relwidth 1.0\fR
+means \fIwindow\fR will fill the area inside the master's
+border.
+
+If \fImode\fR is \fBoutside\fR then the placer considers
+the area of the master to include its border;
+this mode is typically used when placing \fIwindow\fR
+outside its master, as with the options \fB\-x 0 \-y 0 \-anchor ne\fR.
+Lastly, \fImode\fR may be specified as \fBignore\fR, in which
+case borders are ignored: the area of the master is considered
+to be its official X area, which includes any internal border but
+no external border. A bordermode of \fBignore\fR is probably
+not very useful.
+.TP
+\fB\-height \fIsize\fR
+\fISize\fR specifies the height for \fIwindow\fR in screen units
+(i.e. any of the forms accepted by \fBTk_GetPixels\fR).
+The height will be the outer dimension of \fIwindow\fR including its
+border, if any.
+If \fIsize\fR is an empty string, or if no \fB\-height\fR or
+\fB\-relheight\fR option is specified, then the height requested
+internally by the window will be used.
.TP
\fB\-in \fImaster\fR
\fIMaster\fR specifes the path name of the window relative
@@ -62,12 +115,25 @@ that \fIwindow\fR is visible whenever \fImaster\fR is visible.
If this option isn't specified then the master defaults to
\fIwindow\fR's parent.
.TP
-\fB\-x \fIlocation\fR
-\fILocation\fR specifies the x-coordinate within the master window
-of the anchor point for \fIwindow\fR.
-The location is specified in screen units (i.e. any of the forms
-accepted by \fBTk_GetPixels\fR) and need not lie within the bounds
-of the master window.
+\fB\-relheight \fIsize\fR
+\fISize\fR specifies the height for \fIwindow\fR.
+In this case the height is specified as a floating-point number
+relative to the height of the master: 0.5 means \fIwindow\fR will
+be half as high as the master, 1.0 means \fIwindow\fR will have
+the same height as the master, and so on.
+If both \fB\-height\fR and \fB\-relheight\fR are specified for a slave,
+their values are summed. For example, \fB\-relheight 1.0 \-height \-2\fR
+makes the slave 2 pixels shorter than the master.
+.TP
+\fB\-relwidth \fIsize\fR
+\fISize\fR specifies the width for \fIwindow\fR.
+In this case the width is specified as a floating-point number
+relative to the width of the master: 0.5 means \fIwindow\fR will
+be half as wide as the master, 1.0 means \fIwindow\fR will have
+the same width as the master, and so on.
+If both \fB\-width\fR and \fB\-relwidth\fR are specified for a slave,
+their values are summed. For example, \fB\-relwidth 1.0 \-width 5\fR
+makes the slave 5 pixels wider than the master.
.TP
\fB\-relx \fIlocation\fR
\fILocation\fR specifies the x-coordinate within the master window
@@ -81,13 +147,6 @@ then their values are summed. For example, \fB\-relx 0.5 \-x \-2\fR
positions the left edge of the slave 2 pixels to the left of the
center of its master.
.TP
-\fB\-y \fIlocation\fR
-\fILocation\fR specifies the y-coordinate within the master window
-of the anchor point for \fIwindow\fR.
-The location is specified in screen units (i.e. any of the forms
-accepted by \fBTk_GetPixels\fR) and need not lie within the bounds
-of the master window.
-.TP
\fB\-rely \fIlocation\fR
\fILocation\fR specifies the y-coordinate within the master window
of the anchor point for \fIwindow\fR.
@@ -100,17 +159,6 @@ then their values are summed. For example, \fB\-rely 0.5 \-x 3\fR
positions the top edge of the slave 3 pixels below the
center of its master.
.TP
-\fB\-anchor \fIwhere\fR
-\fIWhere\fR specifies which point of \fIwindow\fR is to be positioned
-at the (x,y) location selected by the \fB\-x\fR, \fB\-y\fR,
-\fB\-relx\fR, and \fB\-rely\fR options.
-The anchor point is in terms of the outer area of \fIwindow\fR
-including its border, if any.
-Thus if \fIwhere\fR is \fBse\fR then the lower-right corner of
-\fIwindow\fR's border will appear at the given (x,y) location
-in the master.
-The anchor position defaults to \fBnw\fR.
-.TP
\fB\-width \fIsize\fR
\fISize\fR specifies the width for \fIwindow\fR in screen units
(i.e. any of the forms accepted by \fBTk_GetPixels\fR).
@@ -120,77 +168,42 @@ If \fIsize\fR is an empty string, or if no \fB\-width\fR
or \fB\-relwidth\fR option is specified, then the width requested
internally by the window will be used.
.TP
-\fB\-relwidth \fIsize\fR
-\fISize\fR specifies the width for \fIwindow\fR.
-In this case the width is specified as a floating-point number
-relative to the width of the master: 0.5 means \fIwindow\fR will
-be half as wide as the master, 1.0 means \fIwindow\fR will have
-the same width as the master, and so on.
-If both \fB\-width\fR and \fB\-relwidth\fR are specified for a slave,
-their values are summed. For example, \fB\-relwidth 1.0 \-width 5\fR
-makes the slave 5 pixels wider than the master.
-.TP
-\fB\-height \fIsize\fR
-\fISize\fR specifies the height for \fIwindow\fR in screen units
-(i.e. any of the forms accepted by \fBTk_GetPixels\fR).
-The height will be the outer dimension of \fIwindow\fR including its
-border, if any.
-If \fIsize\fR is an empty string, or if no \fB\-height\fR or
-\fB\-relheight\fR option is specified, then the height requested
-internally by the window will be used.
-.TP
-\fB\-relheight \fIsize\fR
-\fISize\fR specifies the height for \fIwindow\fR.
-In this case the height is specified as a floating-point number
-relative to the height of the master: 0.5 means \fIwindow\fR will
-be half as high as the master, 1.0 means \fIwindow\fR will have
-the same height as the master, and so on.
-If both \fB\-height\fR and \fB\-relheight\fR are specified for a slave,
-their values are summed. For example, \fB\-relheight 1.0 \-height \-2\fR
-makes the slave 2 pixels shorter than the master.
+\fB\-x \fIlocation\fR
+\fILocation\fR specifies the x-coordinate within the master window
+of the anchor point for \fIwindow\fR.
+The location is specified in screen units (i.e. any of the forms
+accepted by \fBTk_GetPixels\fR) and need not lie within the bounds
+of the master window.
.TP
-\fB\-bordermode \fImode\fR
-\fIMode\fR determines the degree to which borders within the
-master are used in determining the placement of the slave.
-The default and most common value is \fBinside\fR.
-In this case the placer considers the area of the master to
-be the innermost area of the master, inside any border:
-an option of \fB\-x 0\fR corresponds to an x-coordinate just
-inside the border and an option of \fB\-relwidth 1.0\fR
-means \fIwindow\fR will fill the area inside the master's
-border.
-If \fImode\fR is \fBoutside\fR then the placer considers
-the area of the master to include its border;
-this mode is typically used when placing \fIwindow\fR
-outside its master, as with the options \fB\-x 0 \-y 0 \-anchor ne\fR.
-Lastly, \fImode\fR may be specified as \fBignore\fR, in which
-case borders are ignored: the area of the master is considered
-to be its official X area, which includes any internal border but
-no external border. A bordermode of \fBignore\fR is probably
-not very useful.
+\fB\-y \fIlocation\fR
+\fILocation\fR specifies the y-coordinate within the master window
+of the anchor point for \fIwindow\fR.
+The location is specified in screen units (i.e. any of the forms
+accepted by \fBTk_GetPixels\fR) and need not lie within the bounds
+of the master window.
.PP
If the same value is specified separately with
two different options, such as \fB\-x\fR and \fB\-relx\fR, then
the most recent option is used and the older one is ignored.
-.PP
-The \fBplace slaves\fR command returns a list of all the slave
-windows for which \fIwindow\fR is the master.
-If there are no slaves for \fIwindow\fR then an empty string is
-returned.
-.PP
-The \fBplace forget\fR command causes the placer to stop managing
-the geometry of \fIwindow\fR. As a side effect of this command
-\fIwindow\fR will be unmapped so that it doesn't appear on the
-screen.
-If \fIwindow\fR isn't currently managed by the placer then the
-command has no effect.
-\fBPlace forget\fR returns an empty string as result.
-.PP
-The \fBplace info\fR command returns a list giving the current
-configuration of \fIwindow\fR.
+.RE
+.TP
+\fBplace forget \fIwindow\fR
+Causes the placer to stop managing the geometry of \fIwindow\fR. As a
+side effect of this command \fIwindow\fR will be unmapped so that it
+doesn't appear on the screen. If \fIwindow\fR isn't currently managed
+by the placer then the command has no effect. This command returns an
+empty string.
+.TP
+\fBplace info \fIwindow\fR
+Returns a list giving the current configuration of \fIwindow\fR.
The list consists of \fIoption\-value\fR pairs in exactly the
same form as might be specified to the \fBplace configure\fR
command.
+.TP
+\fBplace slaves \fIwindow\fR
+Returns a list of all the slave windows for which \fIwindow\fR is the master.
+If there are no slaves for \fIwindow\fR then an empty string is returned.
+
If the configuration of a window has been retrieved with
\fBplace info\fR, that configuration can be restored later by
first using \fBplace forget\fR to erase any existing information
diff --git a/generic/tkConfig.c b/generic/tkConfig.c
index 0f2bea5..28ebf98 100644
--- a/generic/tkConfig.c
+++ b/generic/tkConfig.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkConfig.c,v 1.9 2000/05/17 21:17:20 ericm Exp $
+ * RCS: @(#) $Id: tkConfig.c,v 1.10 2000/08/10 00:21:07 ericm Exp $
*/
/*
@@ -685,10 +685,15 @@ DoObjConfig(interp, recordPtr, optionPtr, valuePtr, tkwin, savedOptionPtr)
case TK_OPTION_DOUBLE: {
double new;
- if (Tcl_GetDoubleFromObj(interp, valuePtr, &new)
- != TCL_OK) {
- return TCL_ERROR;
+ if (nullOK && ObjectIsEmpty(valuePtr)) {
+ valuePtr = NULL;
+ new = 0;
+ } else {
+ if (Tcl_GetDoubleFromObj(interp, valuePtr, &new) != TCL_OK) {
+ return TCL_ERROR;
+ }
}
+
if (internalPtr != NULL) {
*((double *) oldInternalPtr) = *((double *) internalPtr);
*((double *) internalPtr) = new;
@@ -866,10 +871,15 @@ DoObjConfig(interp, recordPtr, optionPtr, valuePtr, tkwin, savedOptionPtr)
}
case TK_OPTION_PIXELS: {
int new;
-
- if (Tk_GetPixelsFromObj(interp, tkwin, valuePtr,
- &new) != TCL_OK) {
- return TCL_ERROR;
+
+ if (nullOK && ObjectIsEmpty(valuePtr)) {
+ valuePtr = NULL;
+ new = 0;
+ } else {
+ if (Tk_GetPixelsFromObj(interp, tkwin, valuePtr,
+ &new) != TCL_OK) {
+ return TCL_ERROR;
+ }
}
if (internalPtr != NULL) {
*((int *) oldInternalPtr) = *((int *) internalPtr);
diff --git a/generic/tkMessage.c b/generic/tkMessage.c
index 2f85885..69233b2 100644
--- a/generic/tkMessage.c
+++ b/generic/tkMessage.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMessage.c,v 1.6 2000/08/02 01:33:33 ericm Exp $
+ * RCS: @(#) $Id: tkMessage.c,v 1.7 2000/08/10 00:21:07 ericm Exp $
*/
#include "tkPort.h"
@@ -230,7 +230,7 @@ Tk_MessageObjCmd(clientData, interp, objc, objv)
{
register Message *msgPtr;
Tk_OptionTable optionTable;
- Tk_Window tkwin = (Tk_Window) clientData;
+ Tk_Window tkwin;
optionTable = (Tk_OptionTable) clientData;
if (optionTable == NULL) {
diff --git a/generic/tkPlace.c b/generic/tkPlace.c
index 9525bc5..2214926 100644
--- a/generic/tkPlace.c
+++ b/generic/tkPlace.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkPlace.c,v 1.7 2000/08/08 19:21:19 ericm Exp $
+ * RCS: @(#) $Id: tkPlace.c,v 1.8 2000/08/10 00:21:07 ericm Exp $
*/
#include "tkPort.h"
@@ -28,11 +28,9 @@
* master's actual window size.
*/
-#ifdef USE_WIDGET_CONFIG
static char *borderModeStrings[] = {
"inside", "outside", "ignore", (char *) NULL
};
-#endif /* USE_WIDGET_CONFIG */
typedef enum {BM_INSIDE, BM_OUTSIDE, BM_IGNORE} BorderMode;
@@ -43,6 +41,7 @@ typedef enum {BM_INSIDE, BM_OUTSIDE, BM_IGNORE} BorderMode;
typedef struct Slave {
Tk_Window tkwin; /* Tk's token for window. */
+ Tk_Window inTkwin; /* Token for the -in window. */
struct Master *masterPtr; /* Pointer to information for window
* relative to which tkwin is placed.
* This isn't necessarily the logical
@@ -50,7 +49,6 @@ typedef struct Slave {
* master was deleted or never assigned. */
struct Slave *nextPtr; /* Next in list of windows placed relative
* to same master (NULL for end of list). */
-
/*
* Geometry information for window; where there are both relative
* and absolute values for the same attribute (e.g. x and relX) only
@@ -58,19 +56,17 @@ typedef struct Slave {
*/
int x, y; /* X and Y pixel coordinates for tkwin. */
-#ifdef USE_WIDGET_CONFIGURE
Tcl_Obj *xPtr, *yPtr; /* Tcl_Obj rep's of x, y coords, to keep
* pixel spec. information */
-#endif /* USE_WIDGET_CONFIGURE */
double relX, relY; /* X and Y coordinates relative to size of
* master. */
int width, height; /* Absolute dimensions for tkwin. */
-#ifdef USE_WIDGET_CONFIGURE
Tcl_Obj *widthPtr; /* Tcl_Obj rep of width, to keep pixel spec */
Tcl_Obj *heightPtr; /* Tcl_Obj rep of height, to keep pixel spec */
-#endif /* USE_WIDGET_CONFIGURE */
double relWidth, relHeight; /* Dimensions for tkwin relative to size of
* master. */
+ Tcl_Obj *relWidthPtr;
+ Tcl_Obj *relHeightPtr;
Tk_Anchor anchor; /* Which point on tkwin is placed at the
* given position. */
BorderMode borderMode; /* How to treat borders of master window. */
@@ -78,7 +74,11 @@ typedef struct Slave {
* definitions. */
} Slave;
-#ifdef USE_WIDGET_CONFIG
+/*
+ * Type masks for options:
+ */
+#define IN_MASK 1
+
static Tk_OptionSpec optionSpecs[] = {
{TK_OPTION_ANCHOR, "-anchor", NULL, NULL, "nw", -1,
Tk_Offset(Slave, anchor), 0, 0, 0},
@@ -86,26 +86,27 @@ static Tk_OptionSpec optionSpecs[] = {
Tk_Offset(Slave, borderMode), 0, (ClientData) borderModeStrings, 0},
{TK_OPTION_PIXELS, "-height", NULL, NULL, "", Tk_Offset(Slave, heightPtr),
Tk_Offset(Slave, height), TK_OPTION_NULL_OK, 0, 0},
- {TK_OPTION_WINDOW, "-in", NULL, NULL, "", -1, Tk_Offset(Slave, tkwin),
- 0, 0, 0},
- {TK_OPTION_DOUBLE, "-relheight", NULL, NULL, "0", -1,
- Tk_Offset(Slave, relHeight), 0, 0, 0},
- {TK_OPTION_DOUBLE, "-relwidth", NULL, NULL, "0", -1,
- Tk_Offset(Slave, relWidth), 0, 0, 0},
+ {TK_OPTION_WINDOW, "-in", NULL, NULL, "", -1, Tk_Offset(Slave, inTkwin),
+ 0, 0, IN_MASK},
+ {TK_OPTION_DOUBLE, "-relheight", NULL, NULL, "",
+ Tk_Offset(Slave, relHeightPtr), Tk_Offset(Slave, relHeight),
+ TK_OPTION_NULL_OK, 0, 0},
+ {TK_OPTION_DOUBLE, "-relwidth", NULL, NULL, "",
+ Tk_Offset(Slave, relWidthPtr), Tk_Offset(Slave, relWidth),
+ TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_DOUBLE, "-relx", NULL, NULL, "0", -1,
Tk_Offset(Slave, relX), 0, 0, 0},
{TK_OPTION_DOUBLE, "-rely", NULL, NULL, "0", -1,
Tk_Offset(Slave, relY), 0, 0, 0},
{TK_OPTION_PIXELS, "-width", NULL, NULL, "", Tk_Offset(Slave, widthPtr),
Tk_Offset(Slave, width), TK_OPTION_NULL_OK, 0, 0},
- {TK_OPTION_PIXELS, "-x", NULL, NULL, "", Tk_Offset(Slave, xPtr),
+ {TK_OPTION_PIXELS, "-x", NULL, NULL, "0", Tk_Offset(Slave, xPtr),
Tk_Offset(Slave, x), TK_OPTION_NULL_OK, 0, 0},
- {TK_OPTION_PIXELS, "-y", NULL, NULL, "", Tk_Offset(Slave, yPtr),
+ {TK_OPTION_PIXELS, "-y", NULL, NULL, "0", Tk_Offset(Slave, yPtr),
Tk_Offset(Slave, y), TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL,
(char *) NULL, 0, -1, 0, 0, 0}
};
-#endif /* USE_WIDGET_CONFIG */
/*
* Flag definitions for Slave structures:
@@ -165,8 +166,13 @@ static Tk_GeomMgr placerType = {
static void SlaveStructureProc _ANSI_ARGS_((ClientData clientData,
XEvent *eventPtr));
static int ConfigureSlave _ANSI_ARGS_((Tcl_Interp *interp,
- Slave *slavePtr, int objc, Tcl_Obj *CONST objv[]));
+ Tk_Window tkwin, Tk_OptionTable table,
+ int objc, Tcl_Obj *CONST objv[]));
+static int PlaceInfoCommand _ANSI_ARGS_((Tcl_Interp *interp,
+ Tk_Window tkwin));
+static Slave * CreateSlave _ANSI_ARGS_((Tk_Window tkwin));
static Slave * FindSlave _ANSI_ARGS_((Tk_Window tkwin));
+static Master * CreateMaster _ANSI_ARGS_((Tk_Window tkwin));
static Master * FindMaster _ANSI_ARGS_((Tk_Window tkwin));
static void MasterStructureProc _ANSI_ARGS_((ClientData clientData,
XEvent *eventPtr));
@@ -200,9 +206,9 @@ Tk_PlaceObjCmd(clientData, interp, objc, objv)
{
Tk_Window tkwin;
Slave *slavePtr;
- Tcl_HashEntry *hPtr;
char *string;
TkDisplay *dispPtr;
+ Tk_OptionTable optionTable = (Tk_OptionTable)clientData;
static char *optionStrings[] = { "configure", "forget", "info", "slaves",
(char *) NULL };
enum options { PLACE_CONFIGURE, PLACE_FORGET, PLACE_INFO, PLACE_SLAVES };
@@ -214,12 +220,29 @@ Tk_PlaceObjCmd(clientData, interp, objc, objv)
return TCL_ERROR;
}
- string = Tcl_GetString(objv[1]);
-
+ if (optionTable == NULL) {
+ Tcl_CmdInfo info;
+ char *name;
+
+ /*
+ * We haven't created the option table for this widget class
+ * yet. Do it now and save the table as the clientData for
+ * the command, so we'll have access to it in future
+ * invocations of the command.
+ */
+
+ optionTable = Tk_CreateOptionTable(interp, optionSpecs);
+ name = Tcl_GetString(objv[0]);
+ Tcl_GetCommandInfo(interp, name, &info);
+ info.objClientData = (ClientData) optionTable;
+ Tcl_SetCommandInfo(interp, name, &info);
+ }
+
/*
* Handle special shortcut where window name is first argument.
*/
+ string = Tcl_GetString(objv[1]);
if (string[0] == '.') {
tkwin = Tk_NameToWindow(interp, string, Tk_MainWindow(interp));
if (tkwin == NULL) {
@@ -237,8 +260,7 @@ Tk_PlaceObjCmd(clientData, interp, objc, objv)
dispPtr->placeInit = 1;
}
- slavePtr = FindSlave(tkwin);
- return ConfigureSlave(interp, slavePtr, objc-2, objv+2);
+ return ConfigureSlave(interp, tkwin, optionTable, objc-2, objv+2);
}
/*
@@ -270,13 +292,25 @@ Tk_PlaceObjCmd(clientData, interp, objc, objv)
switch ((enum options) index) {
case PLACE_CONFIGURE: {
- if (objc < 5) {
- Tcl_WrongNumArgs(interp, 2, objv,
- "pathName option value ?option value ...?");
- return TCL_ERROR;
+ Tcl_Obj *objPtr;
+ if (objc == 3 || objc == 4) {
+ slavePtr = FindSlave(tkwin);
+ if (slavePtr == NULL) {
+ return TCL_OK;
+ }
+ objPtr = Tk_GetOptionInfo(interp, (char *) slavePtr,
+ optionTable,
+ (objc == 4) ? objv[3] : (Tcl_Obj *) NULL, tkwin);
+ if (objPtr == NULL) {
+ return TCL_ERROR;
+ } else {
+ Tcl_SetObjResult(interp, objPtr);
+ return TCL_OK;
+ }
+ } else {
+ return ConfigureSlave(interp, tkwin, optionTable, objc-3,
+ objv+3);
}
- slavePtr = FindSlave(tkwin);
- return ConfigureSlave(interp, slavePtr, objc-3, objv+3);
}
case PLACE_FORGET: {
@@ -284,11 +318,10 @@ Tk_PlaceObjCmd(clientData, interp, objc, objv)
Tcl_WrongNumArgs(interp, 2, objv, "pathName");
return TCL_ERROR;
}
- hPtr = Tcl_FindHashEntry(&dispPtr->slaveTable, (char *) tkwin);
- if (hPtr == NULL) {
+ slavePtr = FindSlave(tkwin);
+ if (slavePtr == NULL) {
return TCL_OK;
}
- slavePtr = (Slave *) Tcl_GetHashValue(hPtr);
if ((slavePtr->masterPtr != NULL) &&
(slavePtr->masterPtr->tkwin !=
Tk_Parent(slavePtr->tkwin))) {
@@ -296,7 +329,8 @@ Tk_PlaceObjCmd(clientData, interp, objc, objv)
slavePtr->masterPtr->tkwin);
}
UnlinkSlave(slavePtr);
- Tcl_DeleteHashEntry(hPtr);
+ Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->slaveTable,
+ (char *) tkwin));
Tk_DeleteEventHandler(tkwin, StructureNotifyMask,
SlaveStructureProc, (ClientData) slavePtr);
Tk_ManageGeometry(tkwin, (Tk_GeomMgr *) NULL, (ClientData) NULL);
@@ -306,82 +340,29 @@ Tk_PlaceObjCmd(clientData, interp, objc, objv)
}
case PLACE_INFO: {
- char buffer[32 + TCL_INTEGER_SPACE];
-
if (objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "pathName");
return TCL_ERROR;
}
- hPtr = Tcl_FindHashEntry(&dispPtr->slaveTable, (char *) tkwin);
- if (hPtr == NULL) {
- return TCL_OK;
- }
- slavePtr = (Slave *) Tcl_GetHashValue(hPtr);
- sprintf(buffer, "-x %d", slavePtr->x);
- Tcl_AppendResult(interp, buffer, (char *) NULL);
- sprintf(buffer, " -relx %.4g", slavePtr->relX);
- Tcl_AppendResult(interp, buffer, (char *) NULL);
- sprintf(buffer, " -y %d", slavePtr->y);
- Tcl_AppendResult(interp, buffer, (char *) NULL);
- sprintf(buffer, " -rely %.4g", slavePtr->relY);
- Tcl_AppendResult(interp, buffer, (char *) NULL);
- if (slavePtr->flags & CHILD_WIDTH) {
- sprintf(buffer, " -width %d", slavePtr->width);
- Tcl_AppendResult(interp, buffer, (char *) NULL);
- } else {
- Tcl_AppendResult(interp, " -width {}", (char *) NULL);
- }
- if (slavePtr->flags & CHILD_REL_WIDTH) {
- sprintf(buffer, " -relwidth %.4g", slavePtr->relWidth);
- Tcl_AppendResult(interp, buffer, (char *) NULL);
- } else {
- Tcl_AppendResult(interp, " -relwidth {}", (char *) NULL);
- }
- if (slavePtr->flags & CHILD_HEIGHT) {
- sprintf(buffer, " -height %d", slavePtr->height);
- Tcl_AppendResult(interp, buffer, (char *) NULL);
- } else {
- Tcl_AppendResult(interp, " -height {}", (char *) NULL);
- }
- if (slavePtr->flags & CHILD_REL_HEIGHT) {
- sprintf(buffer, " -relheight %.4g", slavePtr->relHeight);
- Tcl_AppendResult(interp, buffer, (char *) NULL);
- } else {
- Tcl_AppendResult(interp, " -relheight {}", (char *) NULL);
- }
-
- Tcl_AppendResult(interp, " -anchor ",
- Tk_NameOfAnchor(slavePtr->anchor),
- (char *) NULL);
- if (slavePtr->borderMode == BM_OUTSIDE) {
- Tcl_AppendResult(interp, " -bordermode outside",
- (char *) NULL);
- } else if (slavePtr->borderMode == BM_IGNORE) {
- Tcl_AppendResult(interp, " -bordermode ignore", (char *) NULL);
- }
- if ((slavePtr->masterPtr != NULL)
- && (slavePtr->masterPtr->tkwin !=
- Tk_Parent(slavePtr->tkwin))) {
- Tcl_AppendResult(interp, " -in ",
- Tk_PathName(slavePtr->masterPtr->tkwin),
- (char *) NULL);
- }
- break;
+ return PlaceInfoCommand(interp, tkwin);
}
case PLACE_SLAVES: {
+ Master *masterPtr;
+ Tcl_Obj *listPtr;
if (objc != 3) {
Tcl_WrongNumArgs(interp, 2, objv, "pathName");
return TCL_ERROR;
}
- hPtr = Tcl_FindHashEntry(&dispPtr->masterTable, (char *) tkwin);
- if (hPtr != NULL) {
- Master *masterPtr;
- masterPtr = (Master *) Tcl_GetHashValue(hPtr);
+ masterPtr = FindMaster(tkwin);
+ if (masterPtr != NULL) {
+ listPtr = Tcl_NewObj();
for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
slavePtr = slavePtr->nextPtr) {
- Tcl_AppendElement(interp, Tk_PathName(slavePtr->tkwin));
+ Tcl_ListObjAppendElement(interp, listPtr,
+ Tcl_NewStringObj(Tk_PathName(slavePtr->tkwin),-1));
}
+ Tcl_SetObjResult(interp, listPtr);
}
break;
}
@@ -393,13 +374,13 @@ Tk_PlaceObjCmd(clientData, interp, objc, objv)
/*
*----------------------------------------------------------------------
*
- * FindSlave --
+ * CreateSlave --
*
* Given a Tk_Window token, find the Slave structure corresponding
- * to that token (making a new one if necessary).
+ * to that token, creating a new one if necessary.
*
* Results:
- * None.
+ * Pointer to the Slave structure.
*
* Side effects:
* A new Slave structure may be created.
@@ -408,7 +389,7 @@ Tk_PlaceObjCmd(clientData, interp, objc, objv)
*/
static Slave *
-FindSlave(tkwin)
+CreateSlave(tkwin)
Tk_Window tkwin; /* Token for desired slave. */
{
Tcl_HashEntry *hPtr;
@@ -419,16 +400,11 @@ FindSlave(tkwin)
hPtr = Tcl_CreateHashEntry(&dispPtr->slaveTable, (char *) tkwin, &new);
if (new) {
slavePtr = (Slave *) ckalloc(sizeof(Slave));
- slavePtr->tkwin = tkwin;
- slavePtr->masterPtr = NULL;
- slavePtr->nextPtr = NULL;
- slavePtr->x = slavePtr->y = 0;
- slavePtr->relX = slavePtr->relY = (float) 0.0;
- slavePtr->width = slavePtr->height = 0;
- slavePtr->relWidth = slavePtr->relHeight = (float) 0.0;
- slavePtr->anchor = TK_ANCHOR_NW;
- slavePtr->borderMode = BM_INSIDE;
- slavePtr->flags = 0;
+ memset(slavePtr, 0, sizeof(Slave));
+ slavePtr->tkwin = tkwin;
+ slavePtr->inTkwin = None;
+ slavePtr->anchor = TK_ANCHOR_NW;
+ slavePtr->borderMode = BM_INSIDE;
Tcl_SetHashValue(hPtr, slavePtr);
Tk_CreateEventHandler(tkwin, StructureNotifyMask, SlaveStructureProc,
(ClientData) slavePtr);
@@ -442,6 +418,40 @@ FindSlave(tkwin)
/*
*----------------------------------------------------------------------
*
+ * FindSlave --
+ *
+ * Given a Tk_Window token, find the Slave structure corresponding
+ * to that token. This is purely a lookup function; it will not
+ * create a record if one does not yet exist.
+ *
+ * Results:
+ * Pointer to Slave structure; NULL if none exists.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static Slave *
+FindSlave(tkwin)
+ Tk_Window tkwin; /* Token for desired slave. */
+{
+ Tcl_HashEntry *hPtr;
+ register Slave *slavePtr;
+ TkDisplay * dispPtr = ((TkWindow *) tkwin)->dispPtr;
+
+ hPtr = Tcl_FindHashEntry(&dispPtr->slaveTable, (char *) tkwin);
+ if (hPtr == NULL) {
+ return NULL;
+ }
+ slavePtr = (Slave *) Tcl_GetHashValue(hPtr);
+ return slavePtr;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* UnlinkSlave --
*
* This procedure removes a slave window from the chain of slaves
@@ -487,13 +497,13 @@ UnlinkSlave(slavePtr)
/*
*----------------------------------------------------------------------
*
- * FindMaster --
+ * CreateMaster --
*
* Given a Tk_Window token, find the Master structure corresponding
- * to that token (making a new one if necessary).
+ * to that token, creating a new one if necessary.
*
* Results:
- * None.
+ * Pointer to the Master structure.
*
* Side effects:
* A new Master structure may be created.
@@ -502,7 +512,7 @@ UnlinkSlave(slavePtr)
*/
static Master *
-FindMaster(tkwin)
+CreateMaster(tkwin)
Tk_Window tkwin; /* Token for desired master. */
{
Tcl_HashEntry *hPtr;
@@ -513,9 +523,9 @@ FindMaster(tkwin)
hPtr = Tcl_CreateHashEntry(&dispPtr->masterTable, (char *) tkwin, &new);
if (new) {
masterPtr = (Master *) ckalloc(sizeof(Master));
- masterPtr->tkwin = tkwin;
- masterPtr->slavePtr = NULL;
- masterPtr->flags = 0;
+ masterPtr->tkwin = tkwin;
+ masterPtr->slavePtr = NULL;
+ masterPtr->flags = 0;
Tcl_SetHashValue(hPtr, masterPtr);
Tk_CreateEventHandler(masterPtr->tkwin, StructureNotifyMask,
MasterStructureProc, (ClientData) masterPtr);
@@ -528,6 +538,41 @@ FindMaster(tkwin)
/*
*----------------------------------------------------------------------
*
+ * FindMaster --
+ *
+ * Given a Tk_Window token, find the Master structure corresponding
+ * to that token. This is simply a lookup procedure; a new record
+ * will not be created if one does not already exist.
+ *
+ * Results:
+ * Pointer to the Master structure; NULL if one does not exist for
+ * the given Tk_Window token.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static Master *
+FindMaster(tkwin)
+ Tk_Window tkwin; /* Token for desired master. */
+{
+ Tcl_HashEntry *hPtr;
+ register Master *masterPtr;
+ TkDisplay * dispPtr = ((TkWindow *) tkwin)->dispPtr;
+
+ hPtr = Tcl_FindHashEntry(&dispPtr->masterTable, (char *) tkwin);
+ if (hPtr == NULL) {
+ return NULL;
+ }
+ masterPtr = (Master *) Tcl_GetHashValue(hPtr);
+ return masterPtr;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* ConfigureSlave --
*
* This procedure is called to process an argv/argc list to
@@ -545,234 +590,107 @@ FindMaster(tkwin)
*/
static int
-ConfigureSlave(interp, slavePtr, objc, objv)
+ConfigureSlave(interp, tkwin, table, objc, objv)
Tcl_Interp *interp; /* Used for error reporting. */
- Slave *slavePtr; /* Pointer to current information
- * about slave. */
+ Tk_Window tkwin; /* Token for the window to manipulate. */
+ Tk_OptionTable table; /* Token for option table. */
int objc; /* Number of config arguments. */
Tcl_Obj *CONST objv[]; /* Object values for arguments. */
{
register Master *masterPtr;
- int result;
- Tcl_Obj **objs;
- static char *optionStrings[] = { "-anchor", "-bordermode", "-height",
- "-in", "-relheight", "-relwidth",
- "-relx", "-rely", "-width", "-x",
- "-y", (char *) NULL };
- enum options { PLACE_ANCHOR, PLACE_BORDERMODE, PLACE_HEIGHT, PLACE_IN,
- PLACE_RELHEIGHT, PLACE_RELWIDTH, PLACE_RELX, PLACE_RELY,
- PLACE_WIDTH, PLACE_X, PLACE_Y };
- int index;
-
- result = TCL_OK;
- if (Tk_IsTopLevel(slavePtr->tkwin)) {
+ Tk_SavedOptions savedOptions;
+ int mask;
+ int result = TCL_OK;
+ Slave *slavePtr;
+
+ if (Tk_IsTopLevel(tkwin)) {
Tcl_AppendResult(interp, "can't use placer on top-level window \"",
- Tk_PathName(slavePtr->tkwin), "\"; use wm command instead",
+ Tk_PathName(tkwin), "\"; use wm command instead",
(char *) NULL);
return TCL_ERROR;
}
- for (objs = (Tcl_Obj **)objv; objc > 0; objc -= 2, objs += 2) {
-
- /*
- * Verify that the option given is a legitimate one.
- */
- if (Tcl_GetIndexFromObj(interp, objs[0], optionStrings, "option",
- 0, &index) != TCL_OK) {
- return TCL_ERROR;
- }
+ slavePtr = CreateSlave(tkwin);
+
+ if (Tk_SetOptions(interp, (char *)slavePtr, table, objc, objv,
+ slavePtr->tkwin, &savedOptions, &mask) != TCL_OK) {
+ Tk_RestoreSavedOptions(&savedOptions);
+ result = TCL_ERROR;
+ goto done;
+ }
+ if (mask & IN_MASK) {
+ /* -in changed */
+ Tk_Window tkwin;
+ Tk_Window ancestor;
+
+ tkwin = slavePtr->inTkwin;
+
/*
- * Verify that there is a value for the option.
+ * Make sure that the new master is either the logical parent
+ * of the slave or a descendant of that window, and that the
+ * master and slave aren't the same.
*/
-
- if (objc < 2) {
- Tcl_AppendResult(interp, "value missing for option \"",
- Tcl_GetString(objs[0]), "\"", (char *) NULL);
- result = TCL_ERROR;
- goto done;
- }
-
- switch ((enum options) index) {
- case PLACE_ANCHOR: {
- if (Tk_GetAnchor(interp, Tcl_GetString(objs[1]),
- &slavePtr->anchor) != TCL_OK) {
- result = TCL_ERROR;
- }
- break;
- }
-
- case PLACE_BORDERMODE: {
- static char *bordermodeStrings[] = { "ignore", "inside",
- "outside",
- (char *) NULL };
- enum bordermodes { BORDERMODE_IGNORE, BORDERMODE_INSIDE,
- BORDERMODE_OUTSIDE };
- int borderIndex;
- if (Tcl_GetIndexFromObj(interp, objs[1], bordermodeStrings,
- "border mode", 0, &borderIndex) != TCL_OK) {
- result = TCL_ERROR;
- break;
- }
- switch ((enum bordermodes) borderIndex) {
- case BORDERMODE_IGNORE:
- slavePtr->borderMode = BM_IGNORE;
- break;
- case BORDERMODE_INSIDE:
- slavePtr->borderMode = BM_INSIDE;
- break;
- case BORDERMODE_OUTSIDE:
- slavePtr->borderMode = BM_OUTSIDE;
- break;
- }
+
+ for (ancestor = tkwin; ; ancestor = Tk_Parent(ancestor)) {
+ if (ancestor == Tk_Parent(slavePtr->tkwin)) {
break;
}
-
- case PLACE_HEIGHT: {
- if (*(Tcl_GetString(objs[1])) == 0) {
- slavePtr->flags &= ~CHILD_HEIGHT;
- } else {
- if (Tk_GetPixelsFromObj(interp, slavePtr->tkwin, objs[1],
- &slavePtr->height) != TCL_OK) {
- result = TCL_ERROR;
- break;
- }
- slavePtr->flags |= CHILD_HEIGHT;
- }
- break;
+ if (Tk_IsTopLevel(ancestor)) {
+ Tcl_AppendResult(interp, "can't place ",
+ Tk_PathName(slavePtr->tkwin), " relative to ",
+ Tk_PathName(tkwin), (char *) NULL);
+ result = TCL_ERROR;
+ Tk_RestoreSavedOptions(&savedOptions);
+ goto done;
}
-
- case PLACE_IN: {
- Tk_Window tkwin;
- Tk_Window ancestor;
-
- tkwin = Tk_NameToWindow(interp, Tcl_GetString(objs[1]),
- slavePtr->tkwin);
- if (tkwin == NULL) {
- result = TCL_ERROR;
- break;
- }
-
- /*
- * Make sure that the new master is either the logical parent
- * of the slave or a descendant of that window, and that the
- * master and slave aren't the same.
- */
-
- for (ancestor = tkwin; ; ancestor = Tk_Parent(ancestor)) {
- if (ancestor == Tk_Parent(slavePtr->tkwin)) {
- break;
- }
- if (Tk_IsTopLevel(ancestor)) {
- Tcl_AppendResult(interp, "can't place ",
- Tk_PathName(slavePtr->tkwin), " relative to ",
- Tk_PathName(tkwin), (char *) NULL);
- result = TCL_ERROR;
- goto done;
- }
- }
- if (slavePtr->tkwin == tkwin) {
- Tcl_AppendResult(interp, "can't place ",
- Tk_PathName(slavePtr->tkwin),
- " relative to itself",
- (char *) NULL);
- result = TCL_ERROR;
- goto done;
- }
- if ((slavePtr->masterPtr != NULL)
- && (slavePtr->masterPtr->tkwin == tkwin)) {
- /*
- * Re-using same old master. Nothing to do.
- */
- } else {
- if ((slavePtr->masterPtr != NULL)
- && (slavePtr->masterPtr->tkwin
- != Tk_Parent(slavePtr->tkwin))) {
- Tk_UnmaintainGeometry(slavePtr->tkwin,
- slavePtr->masterPtr->tkwin);
- }
- UnlinkSlave(slavePtr);
- slavePtr->masterPtr = FindMaster(tkwin);
- slavePtr->nextPtr = slavePtr->masterPtr->slavePtr;
- slavePtr->masterPtr->slavePtr = slavePtr;
- }
- break;
+ }
+ if (slavePtr->tkwin == tkwin) {
+ Tcl_AppendResult(interp, "can't place ",
+ Tk_PathName(slavePtr->tkwin), " relative to itself",
+ (char *) NULL);
+ result = TCL_ERROR;
+ Tk_RestoreSavedOptions(&savedOptions);
+ goto done;
+ }
+ if ((slavePtr->masterPtr != NULL)
+ && (slavePtr->masterPtr->tkwin == tkwin)) {
+ /*
+ * Re-using same old master. Nothing to do.
+ */
+ } else {
+ if ((slavePtr->masterPtr != NULL)
+ && (slavePtr->masterPtr->tkwin
+ != Tk_Parent(slavePtr->tkwin))) {
+ Tk_UnmaintainGeometry(slavePtr->tkwin,
+ slavePtr->masterPtr->tkwin);
}
+ UnlinkSlave(slavePtr);
+ slavePtr->masterPtr = CreateMaster(tkwin);
+ slavePtr->nextPtr = slavePtr->masterPtr->slavePtr;
+ slavePtr->masterPtr->slavePtr = slavePtr;
+ }
+ }
- case PLACE_RELHEIGHT: {
- if (*(Tcl_GetString(objs[1])) == 0) {
- slavePtr->flags &= ~CHILD_REL_HEIGHT;
- } else {
- if (Tcl_GetDoubleFromObj(interp, objs[1],
- &slavePtr->relHeight) != TCL_OK) {
- result = TCL_ERROR;
- break;
- }
- slavePtr->flags |= CHILD_REL_HEIGHT;
- }
- break;
- }
-
- case PLACE_RELWIDTH: {
- if (*(Tcl_GetString(objs[1])) == 0) {
- slavePtr->flags &= ~CHILD_REL_WIDTH;
- } else {
- if (Tcl_GetDoubleFromObj(interp, objs[1],
- &slavePtr->relWidth) != TCL_OK) {
- result = TCL_ERROR;
- break;
- }
- slavePtr->flags |= CHILD_REL_WIDTH;
- }
- break;
- }
+ /*
+ * Set slave flags. First clear the field, then add bits as needed.
+ */
- case PLACE_RELX: {
- if (Tcl_GetDoubleFromObj(interp, objs[1],
- &slavePtr->relX) != TCL_OK) {
- result = TCL_ERROR;
- }
- break;
- }
-
- case PLACE_RELY: {
- if (Tcl_GetDoubleFromObj(interp, objs[1],
- &slavePtr->relY) != TCL_OK) {
- result = TCL_ERROR;
- }
- break;
- }
+ slavePtr->flags = 0;
+ if (slavePtr->heightPtr) {
+ slavePtr->flags |= CHILD_HEIGHT;
+ }
- case PLACE_WIDTH: {
- if (*(Tcl_GetString(objs[1])) == 0) {
- slavePtr->flags &= ~CHILD_WIDTH;
- } else {
- if (Tk_GetPixelsFromObj(interp, slavePtr->tkwin, objs[1],
- &slavePtr->width) != TCL_OK) {
- result = TCL_ERROR;
- break;
- }
- slavePtr->flags |= CHILD_WIDTH;
- }
- break;
- }
+ if (slavePtr->relHeightPtr) {
+ slavePtr->flags |= CHILD_REL_HEIGHT;
+ }
- case PLACE_X: {
- if (Tk_GetPixelsFromObj(interp, slavePtr->tkwin, objs[1],
- &slavePtr->x) != TCL_OK) {
- result = TCL_ERROR;
- }
- break;
- }
+ if (slavePtr->relWidthPtr) {
+ slavePtr->flags |= CHILD_REL_WIDTH;
+ }
- case PLACE_Y: {
- if (Tk_GetPixelsFromObj(interp, slavePtr->tkwin, objs[1],
- &slavePtr->y) != TCL_OK) {
- result = TCL_ERROR;
- }
- break;
- }
- }
+ if (slavePtr->widthPtr) {
+ slavePtr->flags |= CHILD_WIDTH;
}
/*
@@ -780,14 +698,16 @@ ConfigureSlave(interp, slavePtr, objc, objv)
* Then arrange for a placement recalculation in the master.
*/
+ Tk_FreeSavedOptions(&savedOptions);
done:
masterPtr = slavePtr->masterPtr;
if (masterPtr == NULL) {
- masterPtr = FindMaster(Tk_Parent(slavePtr->tkwin));
+ masterPtr = CreateMaster(Tk_Parent(slavePtr->tkwin));
slavePtr->masterPtr = masterPtr;
slavePtr->nextPtr = masterPtr->slavePtr;
masterPtr->slavePtr = slavePtr;
}
+ slavePtr->inTkwin = masterPtr->tkwin;
if (!(masterPtr->flags & PARENT_RECONFIG_PENDING)) {
masterPtr->flags |= PARENT_RECONFIG_PENDING;
Tcl_DoWhenIdle(RecomputePlacement, (ClientData) masterPtr);
@@ -798,6 +718,88 @@ ConfigureSlave(interp, slavePtr, objc, objv)
/*
*----------------------------------------------------------------------
*
+ * PlaceInfoCommand --
+ *
+ * Implementation of the [place info] subcommand. See the user
+ * documentation for information on what it does.
+ *
+ * Results:
+ * Standard Tcl result.
+ *
+ * Side effects:
+ * If the given tkwin is managed by the placer, this function will
+ * put information about that placement in the interp's result.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static int
+PlaceInfoCommand(interp, tkwin)
+ Tcl_Interp *interp; /* Interp into which to place result. */
+ Tk_Window tkwin; /* Token for the window to get info on. */
+{
+ char buffer[32 + TCL_INTEGER_SPACE];
+ Slave *slavePtr;
+
+ slavePtr = FindSlave(tkwin);
+ if (slavePtr == NULL) {
+ return TCL_OK;
+ }
+ sprintf(buffer, "-x %d", slavePtr->x);
+ Tcl_AppendResult(interp, buffer, (char *) NULL);
+ sprintf(buffer, " -relx %.4g", slavePtr->relX);
+ Tcl_AppendResult(interp, buffer, (char *) NULL);
+ sprintf(buffer, " -y %d", slavePtr->y);
+ Tcl_AppendResult(interp, buffer, (char *) NULL);
+ sprintf(buffer, " -rely %.4g", slavePtr->relY);
+ Tcl_AppendResult(interp, buffer, (char *) NULL);
+ if (slavePtr->flags & CHILD_WIDTH) {
+ sprintf(buffer, " -width %d", slavePtr->width);
+ Tcl_AppendResult(interp, buffer, (char *) NULL);
+ } else {
+ Tcl_AppendResult(interp, " -width {}", (char *) NULL);
+ }
+ if (slavePtr->flags & CHILD_REL_WIDTH) {
+ sprintf(buffer, " -relwidth %.4g", slavePtr->relWidth);
+ Tcl_AppendResult(interp, buffer, (char *) NULL);
+ } else {
+ Tcl_AppendResult(interp, " -relwidth {}", (char *) NULL);
+ }
+ if (slavePtr->flags & CHILD_HEIGHT) {
+ sprintf(buffer, " -height %d", slavePtr->height);
+ Tcl_AppendResult(interp, buffer, (char *) NULL);
+ } else {
+ Tcl_AppendResult(interp, " -height {}", (char *) NULL);
+ }
+ if (slavePtr->flags & CHILD_REL_HEIGHT) {
+ sprintf(buffer, " -relheight %.4g", slavePtr->relHeight);
+ Tcl_AppendResult(interp, buffer, (char *) NULL);
+ } else {
+ Tcl_AppendResult(interp, " -relheight {}", (char *) NULL);
+ }
+
+ Tcl_AppendResult(interp, " -anchor ",
+ Tk_NameOfAnchor(slavePtr->anchor),
+ (char *) NULL);
+ if (slavePtr->borderMode == BM_OUTSIDE) {
+ Tcl_AppendResult(interp, " -bordermode outside",
+ (char *) NULL);
+ } else if (slavePtr->borderMode == BM_IGNORE) {
+ Tcl_AppendResult(interp, " -bordermode ignore", (char *) NULL);
+ }
+ if ((slavePtr->masterPtr != NULL)
+ && (slavePtr->masterPtr->tkwin !=
+ Tk_Parent(slavePtr->tkwin))) {
+ Tcl_AppendResult(interp, " -in ",
+ Tk_PathName(slavePtr->masterPtr->tkwin),
+ (char *) NULL);
+ }
+ return TCL_OK;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* RecomputePlacement --
*
* This procedure is called as a when-idle handler. It recomputes
diff --git a/tests/place.test b/tests/place.test
index 86f663d..1dc2dfa 100644
--- a/tests/place.test
+++ b/tests/place.test
@@ -5,7 +5,7 @@
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
-# RCS: @(#) $Id: place.test,v 1.4 2000/08/08 19:21:20 ericm Exp $
+# RCS: @(#) $Id: place.test,v 1.5 2000/08/10 00:21:08 ericm Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
source [file join [pwd] [file dirname [info script]] defs.tcl]
@@ -77,7 +77,11 @@ test place-3.3 {ConfigureSlave procedure, -relheight option} {
test place-4.1 {ConfigureSlave procedure, bad -in options} {
place forget .t.f2
list [catch {place .t.f2 -in .t.f2} msg] $msg
-} {1 {can't place .t.f2 relative to itself}}
+} [list 1 "can't place .t.f2 relative to itself"]
+test place-4.2 {ConfigureSlave procedure, bad -in option} {
+ place forget .t.f2
+ list [catch {place .t.f2 -in .} msg] $msg
+} [list 1 "can't place .t.f2 relative to ."]
test place-5.1 {ConfigureSlave procedure, -relwidth option} {
list [catch {place .t.f2 -relwidth abcd} msg] $msg
@@ -243,58 +247,111 @@ test place-9.6 {PlaceObjCmd, configure errors} {
set res [list [catch {place configure .foo} msg] $msg]
destroy .foo
set res
-} [list 1 "wrong # args: should be \"place configure pathName option value ?option value ...?\""]
+} [list 0 ""]
test place-9.7 {PlaceObjCmd, configure errors} {
catch {destroy .foo}
frame .foo
set res [list [catch {place configure .foo bar} msg] $msg]
destroy .foo
set res
-} [list 1 "wrong # args: should be \"place configure pathName option value ?option value ...?\""]
-test place-9.8 {PlaceObjCmd, forget errors} {
+} [list 0 ""]
+test place-9.8 {PlaceObjCmd, configure} {
+ catch {destroy .foo}
+ frame .foo
+ place .foo -x 0 -y 0
+ set res [place configure .foo]
+ destroy .foo
+ set res
+} [list {-anchor {} {} nw nw} {-bordermode {} {} inside inside} {-height {} {} {} {}} {-in {} {} {} .} {-relheight {} {} {} {}} {-relwidth {} {} {} {}} {-relx {} {} 0 0.0} {-rely {} {} 0 0.0} {-width {} {} {} {}} {-x {} {} 0 0} {-y {} {} 0 0}]
+test place-9.9 {PlaceObjCmd, configure} {
+ catch {destroy .foo}
+ frame .foo
+ place .foo -x 0 -y 0
+ set res [place configure .foo -x]
+ destroy .foo
+ set res
+} [list -x {} {} 0 0]
+test place-9.10 {PlaceObjCmd, forget errors} {
catch {destroy .foo}
frame .foo
set res [list [catch {place forget .foo bar} msg] $msg]
destroy .foo
set res
} [list 1 "wrong # args: should be \"place forget pathName\""]
-test place-9.9 {PlaceObjCmd, info errors} {
+test place-9.11 {PlaceObjCmd, info errors} {
catch {destroy .foo}
frame .foo
set res [list [catch {place info .foo bar} msg] $msg]
destroy .foo
set res
} [list 1 "wrong # args: should be \"place info pathName\""]
-test place-9.10 {PlaceObjCmd, slaves errors} {
+test place-9.12 {PlaceObjCmd, slaves errors} {
catch {destroy .foo}
frame .foo
set res [list [catch {place slaves .foo bar} msg] $msg]
destroy .foo
set res
} [list 1 "wrong # args: should be \"place slaves pathName\""]
-
+
test place-10.1 {ConfigureSlave} {
catch {destroy .foo}
frame .foo
set res [list [catch {place .foo -badopt} msg] $msg]
destroy .foo
set res
-} [list 1 "bad option \"-badopt\": must be -anchor, -bordermode, -height, -in, -relheight, -relwidth, -relx, -rely, -width, -x, or -y"]
+} [list 1 "unknown option \"-badopt\""]
test place-10.2 {ConfigureSlave} {
catch {destroy .foo}
frame .foo
set res [list [catch {place .foo -anchor} msg] $msg]
destroy .foo
set res
-} [list 1 "value missing for option \"-anchor\""]
+} [list 1 "value for \"-anchor\" missing"]
test place-10.3 {ConfigureSlave} {
catch {destroy .foo}
frame .foo
set res [list [catch {place .foo -bordermode j} msg] $msg]
destroy .foo
set res
-} [list 1 "bad border mode \"j\": must be ignore, inside, or outside"]
+} [list 1 "bad bordermode \"j\": must be inside, outside, or ignore"]
+test place-10.4 {ConfigureSlave} {
+ catch {destroy .foo}
+ frame .foo
+ set res [list [catch {place configure .foo -x 0 -y} msg] $msg]
+ destroy .foo
+ set res
+} [list 1 "value for \"-y\" missing"]
+test place-11.1 {PlaceObjCmd, slaves command} {
+ catch {destroy .foo}
+ frame .foo
+ set res [place slaves .foo]
+ destroy .foo
+ set res
+} {}
+test place-11.2 {PlaceObjCmd, slaves command} {
+ catch {destroy .foo .bar}
+ frame .foo
+ frame .bar
+ place .bar -in .foo
+ set res [place slaves .foo]
+ destroy .foo
+ destroy .bar
+ set res
+} [list .bar]
+
+test place-12.1 {PlaceObjCmd, forget command} {
+ catch {destroy .foo}
+ frame .foo
+ place .foo -width 50 -height 50
+ update
+ set res [winfo ismapped .foo]
+ place forget .foo
+ update
+ lappend res [winfo ismapped .foo]
+ destroy .foo
+ set res
+} [list 1 0]
catch {destroy .t}