| 1 |
# Copyright (c) 1996 Sun Microsystems, Inc. |
| 2 |
# See the file "license.terms" for information on usage and redistribution |
| 3 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 4 |
# |
| 5 |
# |
| 6 |
|
| 7 |
=head1 NAME |
| 8 |
|
| 9 |
Tk::grid - Geometry manager that arranges widgets in a grid |
| 10 |
|
| 11 |
=for category Tk Geometry Management |
| 12 |
|
| 13 |
=head1 SYNOPSIS |
| 14 |
|
| 15 |
S< >I<$widget>-E<gt>B<grid>?(?I<widget> ...,? ?I<arg> ?...>?)? |
| 16 |
|
| 17 |
S< >I<$widget>-E<gt>B<grid>I<Option>?(I<arg> ?,I<arg> ...?)? |
| 18 |
|
| 19 |
=head1 DESCRIPTION |
| 20 |
|
| 21 |
The B<grid> method is used to communicate with the grid |
| 22 |
geometry manager that arranges widgets in rows and columns inside |
| 23 |
of another window, called the geometry master (or master window). |
| 24 |
The B<grid> method can have any of several forms, depending |
| 25 |
on the I<option> argument: |
| 26 |
|
| 27 |
=over 4 |
| 28 |
|
| 29 |
=item I<$slave>-E<gt>B<grid>(?I<$slave, ...>??, I<options>?) |
| 30 |
|
| 31 |
The arguments consist of the optional references to more slave windows |
| 32 |
followed by pairs of arguments that specify how to manage the slaves. |
| 33 |
The characters B<->, B<x> and B<^>, |
| 34 |
can be specified instead of a window reference to alter the default |
| 35 |
location of a I<$slave>, as described in L<"RELATIVE PLACEMENT">, below. |
| 36 |
|
| 37 |
If any of the slaves are already managed by the geometry manager |
| 38 |
then any unspecified options for them retain their previous values rather |
| 39 |
than receiving default values. |
| 40 |
|
| 41 |
The following options are supported: |
| 42 |
|
| 43 |
=over 8 |
| 44 |
|
| 45 |
=item B<-column> => I<n> |
| 46 |
|
| 47 |
Insert the I<$slave> so that it occupies the I<n>th column in the grid. |
| 48 |
Column numbers start with 0. If this option is not supplied, then the |
| 49 |
I<$slave> is arranged just to the right of previous slave specified on this |
| 50 |
call to B<grid>, or column "0" if it is the first slave. For each |
| 51 |
B<x> that immediately precedes the I<$slave>, the column position |
| 52 |
is incremented by one. Thus the B<x> represents a blank column |
| 53 |
for this row in the grid. |
| 54 |
|
| 55 |
=item B<-columnspan> => I<n> |
| 56 |
|
| 57 |
Insert the slave so that it occupies I<n> columns in the grid. |
| 58 |
The default is one column, unless the window name is followed by a |
| 59 |
B<->, in which case the columnspan is incremented once for each immediately |
| 60 |
following B<->. |
| 61 |
|
| 62 |
=item B<-in> => I<$other> |
| 63 |
|
| 64 |
Insert the slave(s) in the master |
| 65 |
window given by I<$other>. The default is the first slave's |
| 66 |
parent window. |
| 67 |
|
| 68 |
=item B<-ipadx> => I<amount> |
| 69 |
|
| 70 |
The I<amount> specifies how much horizontal internal padding to |
| 71 |
leave on each side of the slave(s). This is space is added |
| 72 |
inside the slave(s) border. |
| 73 |
The I<amount> must be a valid screen distance, such as B<2> or B<'.5c'>. |
| 74 |
It defaults to 0. |
| 75 |
|
| 76 |
=item B<-ipady> => I<amount> |
| 77 |
|
| 78 |
The I<amount> specifies how much vertical internal padding to |
| 79 |
leave on on the top and bottom of the slave(s). |
| 80 |
This space is added inside the slave(s) border. |
| 81 |
The I<amount> defaults to 0. |
| 82 |
|
| 83 |
=item B<-padx> => I<amount> |
| 84 |
|
| 85 |
The I<amount> specifies how much horizontal external padding to |
| 86 |
leave on each side of the slave(s), in screen units. |
| 87 |
The I<amount> defaults to 0. |
| 88 |
This space is added outside the slave(s) border. |
| 89 |
|
| 90 |
=item B<-pady> => I<amount> |
| 91 |
|
| 92 |
The I<amount> specifies how much vertical external padding to |
| 93 |
leave on the top and bottom of the slave(s), in screen units. |
| 94 |
The I<amount> defaults to 0. |
| 95 |
This space is added outside the slave(s) border. |
| 96 |
|
| 97 |
=item B<-row> => I<n> |
| 98 |
|
| 99 |
Insert the slave so that it occupies the I<n>th row in the grid. |
| 100 |
Row numbers start with 0. If this option is not supplied, then the |
| 101 |
slave is arranged on the same row as the previous slave specified on this |
| 102 |
call to B<grid>, or the first unoccupied row if this is the first slave. |
| 103 |
|
| 104 |
=item B<-rowspan> => I<n> |
| 105 |
|
| 106 |
Insert the slave so that it occupies I<n> rows in the grid. |
| 107 |
The default is one row. If the next B<grid> method contains |
| 108 |
B<^> characters instead of I<$slave>s that line up with the columns |
| 109 |
of this I<$slave>, then the B<rowspan> of this I<$slave> is |
| 110 |
extended by one. |
| 111 |
|
| 112 |
=item B<-sticky> => I<style> |
| 113 |
|
| 114 |
If a slave's cell is larger than its requested dimensions, this |
| 115 |
option may be used to position (or stretch) the slave within its cell. |
| 116 |
I<Style> is a string that contains zero or more of the characters |
| 117 |
B<n>, B<s>, B<e> or B<w>. |
| 118 |
The string can optionally contain spaces or |
| 119 |
commas, but they are ignored. Each letter refers to a side (north, south, |
| 120 |
east, or west) that the slave will "stick" to. If both B<n> and B<s> (or |
| 121 |
B<e> and B<w>) are specified, the slave will be stretched to fill the entire |
| 122 |
height (or width) of its cavity. The B<sticky> option subsumes the |
| 123 |
combination of B<-anchor> and B<-fill> that is used by L<pack|Tk::pack>. |
| 124 |
The default is B<''>, which causes the slave to be centered in its cavity, |
| 125 |
at its requested size. |
| 126 |
|
| 127 |
=back |
| 128 |
|
| 129 |
=item I<$master>-E<gt>B<gridBbox>(?I<column, row>,? ?I<column2, row2>?) |
| 130 |
|
| 131 |
With no arguments, |
| 132 |
the bounding box (in pixels) of the grid is returned. |
| 133 |
The return value consists of 4 integers. The first two are the pixel |
| 134 |
offset from the master window (x then y) of the top-left corner of the |
| 135 |
grid, and the second two integers are the width and height of the grid, |
| 136 |
also in pixels. If a single I<column> and I<row> is specified on |
| 137 |
the command line, then the bounding box for that cell is returned, where the |
| 138 |
top left cell is numbered from zero. If both I<column> and I<row> |
| 139 |
arguments are specified, then the bounding box spanning the rows and columns |
| 140 |
indicated is returned. |
| 141 |
|
| 142 |
=item I<$master>-E<gt>B<gridColumnconfigure>(I<index>?, I<-option>=>I<value, ...>?) |
| 143 |
|
| 144 |
Query or set the column properties of the I<index> column of the |
| 145 |
geometry master, I<$master>. |
| 146 |
The valid options are B<-minsize>, B<-weight> and B<-pad>. |
| 147 |
If one or more options are provided, then I<index> may be given as |
| 148 |
a list of column indices to which the configuration options will operate on. |
| 149 |
The B<-minsize> option sets the minimum size, in screen units, |
| 150 |
that will be permitted for this column. |
| 151 |
The B<-weight> option (an integer value) |
| 152 |
sets the relative weight for apportioning |
| 153 |
any extra spaces among |
| 154 |
columns. |
| 155 |
A weight of zero (0) indicates the column will not deviate from its requested |
| 156 |
size. A column whose weight is two will grow at twice the rate as a column |
| 157 |
of weight one when extra space is allocated to the layout. |
| 158 |
The B<-uniform> option, when a |
| 159 |
non-empty value is supplied, places the column in a I<uniform |
| 160 |
group> with other columns that have the same value for B<-uniform>. |
| 161 |
The space for columns belonging to a uniform group is allocated |
| 162 |
so that their sizes are always in strict proportion to their |
| 163 |
B<-weight> values. See I<THE GRID ALGORITHM> below for further |
| 164 |
details. |
| 165 |
The B<-pad> option specifies the number of screen units that will be |
| 166 |
added to the largest window contained completely in that column when the |
| 167 |
grid geometry manager requests a size from the containing window. |
| 168 |
If only an option is specified, with no value, |
| 169 |
the current value of that option is returned. |
| 170 |
If only the master window and index is specified, all the current settings |
| 171 |
are returned in an list of "-option value" pairs. |
| 172 |
|
| 173 |
=item I<$slave>-E<gt>B<gridConfigure>(?I<$slave, ...>?, I<options>?) |
| 174 |
|
| 175 |
The same as B<grid> method. |
| 176 |
|
| 177 |
=item I<$slave>-E<gt>B<gridForget>?(I<$slave, ...>)? |
| 178 |
|
| 179 |
Removes each of the I<$slave>s from grid for its |
| 180 |
master and unmaps their windows. |
| 181 |
The slaves will no longer be managed by the grid geometry manager. |
| 182 |
The configuration options for that window are forgotten, so that if the |
| 183 |
slave is managed once more by the grid geometry manager, the initial |
| 184 |
default settings are used. |
| 185 |
|
| 186 |
=item I<$slave>-E<gt>B<gridInfo> |
| 187 |
|
| 188 |
Returns a list whose elements are the current configuration state of |
| 189 |
the slave given by I<$slave> in the same option-value form that |
| 190 |
might be specified to B<gridConfigure>. |
| 191 |
The first two elements of the list are ``B<-in>=>I<$master>'' where |
| 192 |
I<$master> is the slave's master. |
| 193 |
|
| 194 |
=item I<$master>-E<gt>B<gridLocation>(I<x, y>) |
| 195 |
|
| 196 |
Given I<x> and I<y> values in screen units relative to the master window, |
| 197 |
the column and row number at that I<x> and I<y> location is returned. |
| 198 |
For locations that are above or to the left of the grid, B<-1> is returned. |
| 199 |
|
| 200 |
=item I<$master>-E<gt>B<gridPropagate>?(I<boolean>)? |
| 201 |
|
| 202 |
If I<boolean> has a true boolean value such as B<1> or B<on> |
| 203 |
then propagation is enabled for I<$master>, which must be a window |
| 204 |
name (see L<"GEOMETRY PROPAGATION"> below). |
| 205 |
If I<boolean> has a false boolean value then propagation is |
| 206 |
disabled for I<$master>. |
| 207 |
In either of these cases an empty string is returned. |
| 208 |
If I<boolean> is omitted then the method returns B<0> or |
| 209 |
B<1> to indicate whether propagation is currently enabled |
| 210 |
for I<$master>. |
| 211 |
Propagation is enabled by default. |
| 212 |
|
| 213 |
=item I<$master>-E<gt>B<gridRowconfigure>(I<index>?, I<-option>=>I<value, ...>?) |
| 214 |
|
| 215 |
Query or set the row properties of the I<index> row of the |
| 216 |
geometry master, I<$master>. |
| 217 |
The valid options are B<-minsize>, B<-weight> and B<-pad>. |
| 218 |
If one or more options are provided, then I<index> may be given as |
| 219 |
a list of row indeces to which the configuration options will operate on. |
| 220 |
The B<-minsize> option sets the minimum size, in screen units, |
| 221 |
that will be permitted for this row. |
| 222 |
The B<-weight> option (an integer value) |
| 223 |
sets the relative weight for apportioning |
| 224 |
any extra spaces among |
| 225 |
rows. |
| 226 |
A weight of zero (0) indicates the row will not deviate from its requested |
| 227 |
size. A row whose weight is two will grow at twice the rate as a row |
| 228 |
of weight one when extra space is allocated to the layout. |
| 229 |
The B<-uniform> option, when a non-empty value is supplied, places the |
| 230 |
row in a I<uniform group> with other rows that have the same value |
| 231 |
for B<-uniform>. The space for rows belonging to a uniform group |
| 232 |
is allocated so that their sizes are always in strict proportion |
| 233 |
to their B<-weight> values. See I<THE GRID ALGORITHM> below for |
| 234 |
further details. |
| 235 |
The B<-pad> option specifies the number of screen units that will be |
| 236 |
added to the largest window contained completely in that row when the |
| 237 |
grid geometry manager requests a size from the containing window. |
| 238 |
If only an option is specified, with no value, |
| 239 |
the current value of that option is returned. |
| 240 |
If only the master window and index is specified, all the current settings |
| 241 |
are returned in an list of "option-value" pairs. |
| 242 |
|
| 243 |
=item I<$slave>-E<gt>B<gridRemove>?(I<$slave, ...>)? |
| 244 |
|
| 245 |
Removes each of the I<$slave>s from grid for its |
| 246 |
master and unmaps their windows. |
| 247 |
The slaves will no longer be managed by the grid geometry manager. |
| 248 |
However, the configuration options for that window are remembered, |
| 249 |
so that if the |
| 250 |
slave is managed once more by the grid geometry manager, the previous |
| 251 |
values are retained. |
| 252 |
|
| 253 |
=item I<$master>-E<gt>B<gridSize> |
| 254 |
|
| 255 |
Returns the size of the grid (in columns then rows) for I<$master>. |
| 256 |
The size is determined either by the I<$slave> occupying the largest |
| 257 |
row or column, or the largest column or row with a B<-minsize>, |
| 258 |
B<-weight>, or B<-pad> that is non-zero. |
| 259 |
|
| 260 |
=item I<$master>-E<gt>B<gridSlaves>?(I<-option>=>I<value>)? |
| 261 |
|
| 262 |
If no options are supplied, a list of all of the slaves in I<$master> |
| 263 |
are returned, most recently manages first. |
| 264 |
I<-option> can be either B<-row> or B<-column> which |
| 265 |
causes only the slaves in the row (or column) specified by I<value> |
| 266 |
to be returned. |
| 267 |
|
| 268 |
=back |
| 269 |
|
| 270 |
=head1 RELATIVE PLACEMENT |
| 271 |
|
| 272 |
The B<grid> method contains a limited set of capabilities that |
| 273 |
permit layouts to be created without specifying the row and column |
| 274 |
information for each slave. This permits slaves to be rearranged, |
| 275 |
added, or removed without the need to explicitly specify row and |
| 276 |
column information. |
| 277 |
When no column or row information is specified for a I<$slave>, |
| 278 |
default values are chosen for |
| 279 |
B<-column>, B<-row>, B<-columnspan> and B<-rowspan> |
| 280 |
at the time the I<$slave> is managed. The values are chosen |
| 281 |
based upon the current layout of the grid, the position of the I<$slave> |
| 282 |
relative to other I<$slave>s in the same grid method, and the presence |
| 283 |
of the characters B<->, B<^>, and B<^> in B<grid> |
| 284 |
method where I<$slave> names are normally expected. |
| 285 |
|
| 286 |
=over 4 |
| 287 |
|
| 288 |
=item B<-> |
| 289 |
|
| 290 |
This increases the columnspan of the I<$slave> to the left. Several |
| 291 |
B<->'s in a row will successively increase the columnspan. A B<-> |
| 292 |
may not follow a B<^> or a B<x>. |
| 293 |
|
| 294 |
=item B<x> |
| 295 |
|
| 296 |
This leaves an empty column between the I<$slave> on the left and |
| 297 |
the I<$slave> on the right. |
| 298 |
|
| 299 |
=item B<^> |
| 300 |
|
| 301 |
This extends the B<-rowspan> of the I<$slave> above the B<^>'s |
| 302 |
in the grid. The number of B<^>'s in a row must match the number of |
| 303 |
columns spanned by the I<$slave> above it. |
| 304 |
|
| 305 |
=back |
| 306 |
|
| 307 |
=head1 THE GRID ALGORITHM |
| 308 |
|
| 309 |
The grid geometry manager lays out its slaves in three steps. |
| 310 |
In the first step, the minimum size needed to fit all of the slaves |
| 311 |
is computed, then (if propagation is turned on), a request is made |
| 312 |
of the master window to become that size. |
| 313 |
In the second step, the requested size is compared against the actual size |
| 314 |
of the master. If the sizes are different, then space is added to or taken |
| 315 |
away from the layout as needed. |
| 316 |
For the final step, each slave is positioned in its row(s) and column(s) |
| 317 |
based on the setting of its I<sticky> flag. |
| 318 |
|
| 319 |
To compute the minimum size of a layout, the grid geometry manager |
| 320 |
first looks at all slaves whose columnspan and rowspan values are one, |
| 321 |
and computes the nominal size of each row or column to be either the |
| 322 |
I<minsize> for that row or column, or the sum of the I<pad>ding |
| 323 |
plus the size of the largest slave, whichever is greater. Then the |
| 324 |
slaves whose rowspans or columnspans are greater than one are |
| 325 |
examined. If a group of rows or columns need to be increased in size |
| 326 |
in order to accommodate these slaves, then extra space is added to each |
| 327 |
row or column in the group according to its I<weight>. For each |
| 328 |
group whose weights are all zero, the additional space is apportioned |
| 329 |
equally. |
| 330 |
|
| 331 |
When multiple rows or columns belong to a uniform group, the space |
| 332 |
allocated to them is always in proportion to their weights. (A weight |
| 333 |
of zero is considered to be 1.) In other words, a row or column |
| 334 |
configured with B<-weight 1 -uniform> a will have exactly the same size |
| 335 |
as any other row or column configured with B<-weight 1 -uniform a>. A |
| 336 |
row or column configured with B<-weight 2 -uniform b> will be exactly |
| 337 |
twice as large as one that is configured with B<-weight 1 -uniform b>. |
| 338 |
|
| 339 |
More technically, each row or column in the group will have a size |
| 340 |
equal to I<k*weight> for some constant k. The constant k is chosen so |
| 341 |
that no row or column becomes smaller than its minimum size. For |
| 342 |
example, if all rows or columns in a group have the same weight, then |
| 343 |
each row or column will have the same size as the largest row or |
| 344 |
column in the group. |
| 345 |
|
| 346 |
|
| 347 |
For masters whose size is larger than the requested layout, the additional |
| 348 |
space is apportioned according to the row and column weights. If all of |
| 349 |
the weights are zero, the layout is centered within its master. |
| 350 |
For masters whose size is smaller than the requested layout, space is taken |
| 351 |
away from columns and rows according to their weights. However, once a |
| 352 |
column or row shrinks to its minsize, its weight is taken to be zero. |
| 353 |
If more space needs to be removed from a layout than would be permitted, as |
| 354 |
when all the rows or columns are at there minimum sizes, the layout is |
| 355 |
clipped on the bottom and right. |
| 356 |
|
| 357 |
=head1 GEOMETRY PROPAGATION |
| 358 |
|
| 359 |
The grid geometry manager normally computes how large a master must be to |
| 360 |
just exactly meet the needs of its slaves, and it sets the |
| 361 |
requested width and height of the master to these dimensions. |
| 362 |
This causes geometry information to propagate up through a |
| 363 |
window hierarchy to a top-level window so that the entire |
| 364 |
sub-tree sizes itself to fit the needs of the leaf windows. |
| 365 |
However, the B<gridPropagate> method may be used to |
| 366 |
turn off propagation for one or more masters. |
| 367 |
If propagation is disabled then grid will not set |
| 368 |
the requested width and height of the master window. |
| 369 |
This may be useful if, for example, you wish for a master |
| 370 |
window to have a fixed size that you specify. |
| 371 |
|
| 372 |
=head1 RESTRICTIONS ON MASTER WINDOWS |
| 373 |
|
| 374 |
The master for each slave must either be the slave's parent |
| 375 |
(the default) or a descendant of the slave's parent. |
| 376 |
This restriction is necessary to guarantee that the |
| 377 |
slave can be placed over any part of its master that is |
| 378 |
visible without danger of the slave being clipped by its parent. |
| 379 |
In addition, all slaves in one call to B<grid> must have the same master. |
| 380 |
|
| 381 |
=head1 STACKING ORDER |
| 382 |
|
| 383 |
If the master for a slave is not its parent then you must make sure |
| 384 |
that the slave is higher in the stacking order than the master. |
| 385 |
Otherwise the master will obscure the slave and it will appear as |
| 386 |
if the slave hasn't been managed correctly. |
| 387 |
The easiest way to make sure the slave is higher than the master is |
| 388 |
to create the master window first: the most recently created window |
| 389 |
will be highest in the stacking order. |
| 390 |
|
| 391 |
=head1 CREDITS |
| 392 |
|
| 393 |
The B<grid> method is based on ideas taken from the I<GridBag> |
| 394 |
geometry manager written by Doug. Stein, and the B<blt_table> geometry |
| 395 |
manager, written by George Howlett. |
| 396 |
|
| 397 |
=head1 SEE ALSO |
| 398 |
|
| 399 |
L<Tk::form|Tk::form> |
| 400 |
L<Tk::pack|Tk::pack> |
| 401 |
L<Tk::place|Tk::place> |
| 402 |
|
| 403 |
=head1 KEYWORDS |
| 404 |
|
| 405 |
geometry manager, location, grid, cell, propagation, size, pack, |
| 406 |
master, slave |
| 407 |
|
| 408 |
=cut |
| 409 |
|