| 1 | =head1 NAME | ||
| 2 | |||
| 3 | Tk::SMListbox - Sortable Multicolumn Listbox with arrows in headers indicating sort order. | ||
| 4 | |||
| 5 | =head1 AUTHOR | ||
| 6 | |||
| 7 | Jim Turner | ||
| 8 | |||
| 9 | (c) 2015-2022, Jim Turner under the same license that Perl 5 itself is. All rights reserved. | ||
| 10 | |||
| 11 | Tk::MListbox authors: Hans Jorgen Helgesen, hans_helgesen@hotmail.com (from March 2000: hans.helgesen@novit.no) | ||
| 12 | |||
| 13 | =head1 SYNOPSIS | ||
| 14 | |||
| 15 | use Tk::SMListbox; | ||
| 16 | |||
| 17 | $ml = $parent->SMListbox (<options>); | ||
| 18 | |||
| 19 | =head1 DESCRIPTION | ||
| 20 | |||
| 21 | Tk::SMListbox is a derivitive of Tk::MListbox that adds optional tiny up and | ||
| 22 | down arrow graphics to columns in the SMListbox that the data is | ||
| 23 | currently sorted on indicating ascending and/or descending order. | ||
| 24 | |||
| 25 | It also now supports "-state => 'disabled'", but note that the state must not | ||
| 26 | be disabled when inserting rows (inserts silently fail)! L<Tk::HMListbox> is | ||
| 27 | not subject to this restriction. | ||
| 28 | |||
| 29 | Sorting is done by clicking on one of the column headings in the | ||
| 30 | widget. The first click will sort the data with the selected column as | ||
| 31 | key, a new click will reverse the sort order. | ||
| 32 | |||
| 33 | =head1 EXAMPLES | ||
| 34 | |||
| 35 | my $table = $w->Scrolled('SMListbox' | ||
| 36 | |||
| 37 | -scrollbars => 'se', | ||
| 38 | |||
| 39 | -height => 12, | ||
| 40 | |||
| 41 | -relief => 'sunken', | ||
| 42 | |||
| 43 | -sortable => 1, #USER CAN SORT BY COLUMN BY CLICKING ON THE COLUMN HEADER BUTTON. | ||
| 44 | |||
| 45 | -selectmode => 'extended', | ||
| 46 | |||
| 47 | -showallsortcolumns => 1, #SHOW SORT DIRECTION ARROW ON ALL SORTED COLUMNS. | ||
| 48 | |||
| 49 | -takefocus => 1, | ||
| 50 | |||
| 51 | -borderwidth => 1, | ||
| 52 | |||
| 53 | -fillcolumn => 1, #IF WINDOW RESIZED, EXPAND COLUMN 1 ("Name") TO FILL THE EXTRA SPACE. | ||
| 54 | |||
| 55 | -columns => [ #COLUMN WIDTH, SORT FUNCTIONS, HEADER BUTTON INFORMATION, ETC.: | ||
| 56 | |||
| 57 | [-text => '~D', -width => 3, -comparecommand => sub { $_[1] cmp $_[0] } ], | ||
| 58 | |||
| 59 | [-text => '~Name', -width => 25 ], | ||
| 60 | |||
| 61 | [-text => '~Perm.', -width => 10 ], | ||
| 62 | |||
| 63 | [-text => '~Owner:Group', -width => 14 ], | ||
| 64 | |||
| 65 | [-text => '~Size', -width => 8, -comparecommand => sub { $_[1] <=> $_[0] } ], | ||
| 66 | |||
| 67 | [-text => 'Date/~Time', -width => 15, -reversearrow => 1, -comparecommand => sub { $_[1] cmp $_[0] }], | ||
| 68 | |||
| 69 | ] | ||
| 70 | |||
| 71 | )->pack( | ||
| 72 | |||
| 73 | -expand => 'yes', | ||
| 74 | |||
| 75 | ); | ||
| 76 | |||
| 77 | =head1 STANDARD OPTIONS | ||
| 78 | |||
| 79 | B<-background> B<-borderwidth> B<-cursor> B<-disabledforeground> | ||
| 80 | B<-exportselection> B<-font> B<-foreground> B<-height> B<-highlightbackground> | ||
| 81 | B<-highlightcolor> B<-highlightthickness> B<-relief> B<-selectbackground> | ||
| 82 | B<-selectborderwidth> B<-selectforeground> B<-setgrid> B<-state> B<-takefocus> | ||
| 83 | B<-width> B<-xscrollcommand> B<-yscrollcommand> | ||
| 84 | |||
| 85 | =head1 WIDGET SPECIFIC OPTIONS | ||
| 86 | |||
| 87 | =over 4 | ||
| 88 | |||
| 89 | =item B<-columns> => I<list> | ||
| 90 | |||
| 91 | Defines the columns in the widget. Each element in the list | ||
| 92 | describes a column. See the B<COLUMNS> section below. | ||
| 93 | |||
| 94 | =item B<-configurecommand> => I<callback> | ||
| 95 | |||
| 96 | The -configurecommand callback will be called whenever the layout of the | ||
| 97 | widget has changed due to user interaction. That is, the user changes the | ||
| 98 | width of a column by dragging the separator, or moves a column by dragging | ||
| 99 | the column header. | ||
| 100 | |||
| 101 | This option is useful if the application wants to store the widget layout | ||
| 102 | for later retrieval. The widget layout can be obtained by the callback | ||
| 103 | by calling the method columnPackInfo(). | ||
| 104 | |||
| 105 | =item B<-fillcolumn> => I<index> | ||
| 106 | |||
| 107 | Specify the index number of a column that will expand to fill any new | ||
| 108 | space opened up by dragging the window to a larger size. All other | ||
| 109 | columns maintain their current widths unless changed by the user | ||
| 110 | dragging a column separator. Otherwise all columns maintain their | ||
| 111 | sizes and the extra space is unused (if no column specified here). | ||
| 112 | Default: -1 (no column expands horizontally). All columns always | ||
| 113 | expand vertically though. The same column keeps it's expansion | ||
| 114 | privilege even if user rearranges their positions. | ||
| 115 | |||
| 116 | =item B<-focuscolumn> => I<index> | ||
| 117 | |||
| 118 | Specify the column to receive the input focus when the SMListbox | ||
| 119 | receives focus. This is useful if the first column is not the one | ||
| 120 | of primary interest to the user, since only one column will | ||
| 121 | show the active row cursor because the underlying Tk::Listbox | ||
| 122 | widgets only show the active row cursor when they have the focus. | ||
| 123 | |||
| 124 | NOTE: none of this applies if B<-nocolumnfocus> is set, which | ||
| 125 | also has the side effect of disabling most keyboard bindings on | ||
| 126 | the SMListbox. Default: I<0> (The first column will get the | ||
| 127 | focus and show the active row cursor (usually an I<underline>). | ||
| 128 | |||
| 129 | =item B<-headerbackground> => I<color> | ||
| 130 | |||
| 131 | Specify a different background color for the top ("header") row. | ||
| 132 | Default: B<-background> or parent window's background. | ||
| 133 | |||
| 134 | =item B<-headerforeground> => I<color> | ||
| 135 | |||
| 136 | Specify a different foreground color for the top ("header") row. | ||
| 137 | Default: B<-foreground> or parent window's foreground. | ||
| 138 | |||
| 139 | =item B<-moveable> => I<boolean> | ||
| 140 | |||
| 141 | A value of B<1> indicates that it is okay for the user to move | ||
| 142 | the columns by dragging the column headers. B<0> disables this | ||
| 143 | function. Default: B<1>. | ||
| 144 | |||
| 145 | =item B<-nocolumnfocus> => I<boolean> | ||
| 146 | |||
| 147 | Prevents the SMListbox widget from giving the keyboard focus to | ||
| 148 | a specific column. The net effect of this option being set is | ||
| 149 | that the widget itself takes focus, but many keyboard bindings | ||
| 150 | will not work, namely selecting rows with the spacebar. | ||
| 151 | Default: I<0> (Take focus normally and give the | ||
| 152 | focus to one of the column listboxes under the hood so that | ||
| 153 | row-based keyboard bindings will all work properly). To have | ||
| 154 | the SMListbox widget itself be skipped in the focus order, set | ||
| 155 | B<-takefocus> to I<0>. | ||
| 156 | |||
| 157 | =item B<-resizeable> => I<boolean> | ||
| 158 | |||
| 159 | A value of B<1> indicates that it is okay for the user to resize | ||
| 160 | the columns by dragging the column separators. B<0> disables | ||
| 161 | this function. Default: B<1>. | ||
| 162 | |||
| 163 | Note that you can also specify -resizeable on a column | ||
| 164 | by column basis. See the B<COLUMNS> section below. | ||
| 165 | |||
| 166 | =item B<-selectmode> => I<string> | ||
| 167 | |||
| 168 | Should be "single", "browse", "multiple", or "extended". | ||
| 169 | Default: B<"browse">. See L<Tk::Listbox>. | ||
| 170 | |||
| 171 | =item B<-separatorcolor> => I<string> | ||
| 172 | |||
| 173 | Specifies the color of the separator lines | ||
| 174 | (the vertical lines that separates the columns). | ||
| 175 | Default: B<black>. | ||
| 176 | |||
| 177 | Note that you can also specify -separatorcolor on a column | ||
| 178 | by column basis. See the B<COLUMNS> section below. | ||
| 179 | |||
| 180 | =item B<-scrollbarfocus> => I<value> | ||
| 181 | |||
| 182 | Specifies which scrollbars (if any) are allowed to take keyboard | ||
| 183 | focus via the tab-circulate order: Valid values are: | ||
| 184 | B<0> (no scrollbars take focus), B<1> or B<"xy"> (all scrollbars take focus, | ||
| 185 | B<"x"> (only horizontal scrollbar takes focus), or B<"y"> (only vertical | ||
| 186 | scrollbar takes focus). Default is B<""> (Allow all to take focus based | ||
| 187 | on Tk's default focusing model). | ||
| 188 | |||
| 189 | =item B<-separatorwidth> => I<integer> | ||
| 190 | |||
| 191 | Specifies the width in pixels of the separator lines | ||
| 192 | (the vertical lines that separates the columns). | ||
| 193 | Default: B<1>. | ||
| 194 | |||
| 195 | Note that you can also specify -separatorwidth on a column | ||
| 196 | by column basis. See the B<COLUMNS> section below. | ||
| 197 | |||
| 198 | =item B<-sortable> => I<boolean> | ||
| 199 | |||
| 200 | A value of B<1> indicates that it is okay for the user to sort | ||
| 201 | the data by clicking column headings. B<0> disables this function. | ||
| 202 | Default: B<1>. | ||
| 203 | |||
| 204 | Note that you can also specify B<-sortable> on a column | ||
| 205 | by column basis. See I<COLUMNS> below. | ||
| 206 | |||
| 207 | =item B<-state> | ||
| 208 | |||
| 209 | Specifies one of two states for the widget: B<"normal"> or B<"disabled">. | ||
| 210 | If the widget is disabled then user can interact with the widget in a very | ||
| 211 | limited (read-only) way. Items may not be selected, but currently, the | ||
| 212 | list can be resorted or the columns potentially expanded for easier viewing. | ||
| 213 | Items are drawn in the B<-disabledforeground> color, and selection | ||
| 214 | cannot be modified and is not shown (though selection information is | ||
| 215 | retained). | ||
| 216 | |||
| 217 | =item B<-takefocus> | ||
| 218 | |||
| 219 | There are actually three different focusing options: Specify B<1> to both | ||
| 220 | allow the widget to take keyboard focus itself and to enable grabbing the | ||
| 221 | keyboard focus when a user clicks on a row in the listbox. Specify B<''> | ||
| 222 | to allow the widget to take focus (via the <TAB> circulate order) but do | ||
| 223 | not grab the focus when a user clicks on (selects) a row. This is the | ||
| 224 | default focusing model. Specify B<0> to not allow the widget to receive | ||
| 225 | the keyboard focus. | ||
| 226 | Default: B<''>. | ||
| 227 | |||
| 228 | =back | ||
| 229 | |||
| 230 | =head1 WIDGET SPECIFIC, COLUMN-SPECIFIC OPTIONS | ||
| 231 | |||
| 232 | =over 4 | ||
| 233 | |||
| 234 | =item B<-comparecmd> => I<callback> | ||
| 235 | |||
| 236 | Specifies a callback to use when sorting the SMListbox with this | ||
| 237 | column as key. The callback will be called with two scalar arguments, | ||
| 238 | each a value from this particular column. The callback should | ||
| 239 | return an integer less than, equal to, or greater than 0, depending | ||
| 240 | on how the tow arguments are ordered. If for example the column | ||
| 241 | should be sorted by numerical value: | ||
| 242 | |||
| 243 | -comparecommand => sub { $_[0] <=> $_[1]} | ||
| 244 | |||
| 245 | Default: B<sub { $_[0] cmp $_[1] }> #(Ascending by string) | ||
| 246 | |||
| 247 | =item B<-reversearrow> => 0 | 1 | ||
| 248 | |||
| 249 | New option (not included with the old Tk::MListbox) that | ||
| 250 | causes the up / down direction of the sort arrow in the | ||
| 251 | column header that shows the direction the sorted-by | ||
| 252 | column is currently sorted. Default: B<0> (zero): (Up-arrow) | ||
| 253 | if sorted in ascending order, Down-arrow if in | ||
| 254 | descending order. Setting to 1 reverses this. This is | ||
| 255 | often necessary to show desired results, ie. if the sort | ||
| 256 | function is reversed, such as: sub { $_[1] cmp $_[0] } | ||
| 257 | |||
| 258 | =back | ||
| 259 | |||
| 260 | =head1 SMListbox COLUMN CONFIGURATION | ||
| 261 | |||
| 262 | NOTE: See also the additional options described in the previous | ||
| 263 | section "WIDGET SPECIFIC COLUMN-SPECIFIC OPTIONS". | ||
| 264 | |||
| 265 | The SMListbox widget is a collection of I<SMLColumn> widgets. | ||
| 266 | Each SMLColumn contains a Listbox, a heading and the separator bar. | ||
| 267 | The columns are created and maintained through the -columns | ||
| 268 | option or the column methods of the widget. The columns are indexed | ||
| 269 | from 0 and up. Initially, column 0 is the leftmost column of the | ||
| 270 | widget. The column indices B<are not changed> when the columns | ||
| 271 | are moved or hidden. The only ways to change the column indices | ||
| 272 | are to call columnInsert(), columnDelete() or configure(-column). | ||
| 273 | |||
| 274 | Each column has its own set of options which might be passed to | ||
| 275 | SMListbox::configure(-columns), SMListbox::insert(), | ||
| 276 | SMListbox::columnConfigure() or SMLColumn::configure(). | ||
| 277 | |||
| 278 | NOTE: Unlike HListbox widgets, Listbox widgets will IGNORE data-insertions | ||
| 279 | if the current state is B<'disabled'>! | ||
| 280 | |||
| 281 | The following code snippets are all equal: | ||
| 282 | |||
| 283 | 1. $ml=$mw->SMListbox(-columns=>[[-text=>'Heading1', | ||
| 284 | -sortable=>0], | ||
| 285 | [-text=>'Heading2']]); | ||
| 286 | |||
| 287 | 2. $ml=$mw->SMListbox; | ||
| 288 | $sml->columnInsert(0,-text=>'Heading1', -sortable=>0); | ||
| 289 | $sml->columnInsert(0,-text=>'Heading2'); | ||
| 290 | |||
| 291 | 3. $ml=$mw->SMListbox; | ||
| 292 | $c=$sml->columnInsert(0,-text=>'Heading1'); | ||
| 293 | $sml->columnInsert(0,-text=>'Heading2'); | ||
| 294 | $c->configure(-sortable=>0); | ||
| 295 | |||
| 296 | 4. $ml=$mw->SMListbox; | ||
| 297 | $sml->columnInsert(0,-text=>'Heading1'); | ||
| 298 | $sml->columnInsert(0,-text=>'Heading2'); | ||
| 299 | $sml->columnConfigure(0,-sortable=>0); | ||
| 300 | |||
| 301 | (See the columnConfigure() method below for details on column options). | ||
| 302 | |||
| 303 | All column methods expects one or two column indices as arguments. | ||
| 304 | The column indices might be an integer (between 0 and the number | ||
| 305 | of columns minus one), 'end' for the last column, or a reference | ||
| 306 | to the SMLColumn widget (obtained by calling SMListbox->columnGet() | ||
| 307 | or by storing the return value from SMListbox->columnInsert()). | ||
| 308 | |||
| 309 | =head1 WIDGET METHODS | ||
| 310 | |||
| 311 | =over 4 | ||
| 312 | |||
| 313 | =item $sml->B<compound>(I<[left|right|top|bottom]>) | ||
| 314 | |||
| 315 | Gets / sets the side of the column header that the | ||
| 316 | ascending / descending arrow is to appear (left, right, top, | ||
| 317 | bottom). Default: I<"right">. | ||
| 318 | |||
| 319 | =item $sml->B<focusColumn>([index]) | ||
| 320 | |||
| 321 | Gets or sets the index of the column whose listbox is to receive | ||
| 322 | the keyboard focus when the SMListbox widget receives keyboard | ||
| 323 | focus. This is useful so that the I<"underline"> will show on the | ||
| 324 | element the keyboard cursor is on when navigating the widget using | ||
| 325 | the Up and Down arrow keys to make multiple selections in "Extended" | ||
| 326 | mode using the keyboard. The first (leftmost) column listbox | ||
| 327 | gets the focus by default, but this option allows a different | ||
| 328 | column to get the keyboard focus, if a different column has | ||
| 329 | better, ie. wider and easier to see text values. This is | ||
| 330 | because the underline only appears under non-blank text, rather | ||
| 331 | than the width of the column, and only when the underlying | ||
| 332 | Tk::Listbox itself has the focus. Requires version 2 or higher. | ||
| 333 | |||
| 334 | NOTE: none of this applies if B<-nocolumnfocus> is set, which | ||
| 335 | also has the side effect of disabling most keyboard bindings on | ||
| 336 | the SMListbox. | ||
| 337 | |||
| 338 | =item $sml->B<getSortOrder>() | ||
| 339 | |||
| 340 | returns an array that is in the same format accepted by the | ||
| 341 | $smListBox->sort method. The 1st element is | ||
| 342 | either true for descending sort, false for assending. | ||
| 343 | Subsequent elements represent the column indices of one or | ||
| 344 | more columns by which the data is sorted. | ||
| 345 | Default (if nothing previously set): B<(0, 0)>. | ||
| 346 | |||
| 347 | =item $hml->B<setSortOrder>(I<descending>, I<columnindex>...) | ||
| 348 | |||
| 349 | Sets the default sort order and columns to sort without actually | ||
| 350 | sorting. The arguments are the same as the sort() function. | ||
| 351 | |||
| 352 | =item $sml->B<setButtonHeight>([I<pady>]) | ||
| 353 | |||
| 354 | Sets (alters) the "-pady" value for the header buttons. | ||
| 355 | Should be called AFTER all columns have been created. | ||
| 356 | Requires version 2 or higher. | ||
| 357 | |||
| 358 | =item $sml->B<showallsortcolumns>([I<1|0>]) | ||
| 359 | |||
| 360 | Gets or sets whether a sort direction arrow is to be displayed | ||
| 361 | on each column involved in the sorting or just the 1st | ||
| 362 | (primary sort). Default: B<0> (false) - show arrow only on the | ||
| 363 | primary sort column. | ||
| 364 | |||
| 365 | =item $sml->B<bindColumns>(I<sequence>,I<callback>) | ||
| 366 | |||
| 367 | Adds the binding to all column headers in the widget. See the section | ||
| 368 | BINDING EVENTS TO SMListbox below. | ||
| 369 | |||
| 370 | =item $sml->B<bindRows>(I<sequence>,I<callback>) | ||
| 371 | |||
| 372 | Adds the binding to all listboxes in the widget. See the section | ||
| 373 | BINDING EVENTS TO SMListbox below. | ||
| 374 | |||
| 375 | =item $sml->B<bindSeparators>(I<sequence>,I<callback>) | ||
| 376 | |||
| 377 | Adds the binding to all separators in the widget. See the section | ||
| 378 | BINDING EVENTS TO SMListbox below. | ||
| 379 | |||
| 380 | =back | ||
| 381 | |||
| 382 | =head2 COLUMN METHODS | ||
| 383 | |||
| 384 | (Methods for accessing and manipulating individual columns | ||
| 385 | in the SMListbox widget) | ||
| 386 | |||
| 387 | =over 4 | ||
| 388 | |||
| 389 | =item $sml->B<columnConfigure>(I<index>,I<option>=>I<value>...) | ||
| 390 | |||
| 391 | Set option values for a specific column. | ||
| 392 | Equal to $sml->columnGet(I<index>)->configure(...). | ||
| 393 | |||
| 394 | The following column options are supported: | ||
| 395 | |||
| 396 | =over 4 | ||
| 397 | |||
| 398 | =item B<-comparecommand> => I<callback> | ||
| 399 | |||
| 400 | Specifies a callback to use when sorting the SMListbox with this | ||
| 401 | column as key. The callback will be called with two scalar arguments, | ||
| 402 | each a value from this particular column. The callback should | ||
| 403 | return an integer less than, equal to, or greater than 0, depending | ||
| 404 | on how the tow arguments are ordered. If for example the column | ||
| 405 | should be sorted by numerical value: | ||
| 406 | |||
| 407 | -comparecommand => sub { $_[0] <=> $_[1]} | ||
| 408 | |||
| 409 | The default is to sort the columns alphabetically. | ||
| 410 | |||
| 411 | =item B<-text> => I<string> | ||
| 412 | |||
| 413 | Specifies the text to be used in the heading button of the column. | ||
| 414 | |||
| 415 | =item B<-resizeable> => I<boolean> | ||
| 416 | |||
| 417 | A value of B<1> indicates that it is okay for the user to resize | ||
| 418 | this column by dragging the separator. B<0> disables this function. | ||
| 419 | Default: B<1>. | ||
| 420 | |||
| 421 | =item B<-separatorcolor> => I<string> | ||
| 422 | |||
| 423 | Specifies the color of the separator line. Default: B<black>. | ||
| 424 | |||
| 425 | =item B<-separatorwidth> => I<integer> | ||
| 426 | |||
| 427 | Specifies the width of the separator line in pixels. Default: B<1>. | ||
| 428 | |||
| 429 | =item B<-sortable> => I<boolean> | ||
| 430 | |||
| 431 | A value of B<1> indicates that it is okay for the user to sort | ||
| 432 | the data by clicking this column's heading. B<0> disables this | ||
| 433 | function. Default: B<1>. | ||
| 434 | |||
| 435 | =item B<-reversearrow> => 0 | 1 | ||
| 436 | |||
| 437 | New option (not included with the old Tk::MListbox) that | ||
| 438 | causes the up / down direction of the sort arrow in the | ||
| 439 | column header that shows the direction the sorted-by | ||
| 440 | column is currently sorted. Default: B<0> (zero) - (Up-arrow | ||
| 441 | if sorted in ascending order, Down-arrow if in | ||
| 442 | descending order. Setting to 1 reverses this. This is | ||
| 443 | often necessary to show desired results, ie. if the sort | ||
| 444 | function is reversed, such as: sub { $_[1] cmp $_[0] } | ||
| 445 | |||
| 446 | =back | ||
| 447 | |||
| 448 | =item $sml->B<columnDelete>(I<first>,I<last>) | ||
| 449 | |||
| 450 | If I<last> is omitted, deletes column I<first>. If I<last> is | ||
| 451 | specified, deletes all columns from I<first> to I<last>, inclusive. | ||
| 452 | |||
| 453 | All previous column indices greater than I<last> (or I<first> if | ||
| 454 | I<last> is omitted) are decremented by the number of columns | ||
| 455 | deleted. | ||
| 456 | |||
| 457 | =item $sml->B<columnGet>(I<first>,I<last>) | ||
| 458 | |||
| 459 | If I<last> is not specified, returns the SMLColumn widget specified by I<first>. | ||
| 460 | If both I<first> and I<last> are specified, returns an array containing all | ||
| 461 | columns from I<first> to I<last>. | ||
| 462 | |||
| 463 | =item $sml->B<columnHide>(I<first>,I<last>) | ||
| 464 | |||
| 465 | If I<last> is omitted, hides column I<first>. If I<last> is | ||
| 466 | specified, hides all columns from I<first> to I<last>, inclusive. | ||
| 467 | |||
| 468 | Hiding a column is equal to calling $sml->columnGet(I<index>)->packForget. | ||
| 469 | The column is B<not> deleted, all data are still available, | ||
| 470 | and the column indices remain the same. | ||
| 471 | |||
| 472 | See also the columnShow() method below. | ||
| 473 | |||
| 474 | =item $sml->B<columnIndex>(I<index>) | ||
| 475 | |||
| 476 | Returns an integer index for the column specifed by I<index>. | ||
| 477 | |||
| 478 | =item $sml->B<columnInsert>(I<index>,I<option>=>I<value>...) | ||
| 479 | |||
| 480 | Creates a new column in the SMListbox widget. The column will | ||
| 481 | get the index specified by I<index>. If I<index> is 'end', the | ||
| 482 | new column's index will be one more than the previous highest | ||
| 483 | column index. | ||
| 484 | |||
| 485 | If column I<index> exists, the new column will be placed | ||
| 486 | to the B<left> of this column. All previous column indices | ||
| 487 | equal to or greater than I<index> will be incremented by one. | ||
| 488 | |||
| 489 | Returns the newly created SMLColumn widget. | ||
| 490 | |||
| 491 | (See the columnConfigure() method above for details on column options). | ||
| 492 | |||
| 493 | =item $sml->B<columnPack>(I<array>) | ||
| 494 | |||
| 495 | Repacks all columns in the SMListbox widget according to the | ||
| 496 | specification in I<array>. Each element in I<array> is a string | ||
| 497 | on the format B<index:width>. I<index> is a column index, I<width> | ||
| 498 | defines the columns width in pixels (may be omitted). The columns | ||
| 499 | are packed left to right in the order specified by by I<array>. | ||
| 500 | Columns not specified in I<array> will be hidden. | ||
| 501 | |||
| 502 | This method is most useful if used together with the | ||
| 503 | columnPackInfo() method. | ||
| 504 | |||
| 505 | =item $sml->B<columnPackInfo>() | ||
| 506 | |||
| 507 | Returns an array describing the current layout of the SMListbox | ||
| 508 | widget. Each element of the array is a string on the format | ||
| 509 | B<index:width> (see columnPack() above). Only indices of columns that | ||
| 510 | are currently shown (not hidden) will be returned. The first element | ||
| 511 | in the returned array represents the leftmost column. | ||
| 512 | |||
| 513 | This method may be used in conjunction with columnPack() to save | ||
| 514 | and restore the column configuration. | ||
| 515 | |||
| 516 | =item $sml->B<columnShow>(I<index>,I<option>=>I<value>) | ||
| 517 | |||
| 518 | Shows a hidden column (see the columnHide() method above). | ||
| 519 | The column to show is specified by I<index>. | ||
| 520 | |||
| 521 | By default, the column is pack'ed at the rigthmost end of the | ||
| 522 | SMListbox widget. This might be overridden by specifying one of | ||
| 523 | the following options: | ||
| 524 | |||
| 525 | =item B<-after> => I<index> | ||
| 526 | |||
| 527 | Place the column B<after> (to the right of) the column specified | ||
| 528 | by I<index>. | ||
| 529 | |||
| 530 | =item B<-before> => I<index> | ||
| 531 | |||
| 532 | Place the column B<before> (to the left of) the column specified | ||
| 533 | by I<index>. | ||
| 534 | |||
| 535 | =back | ||
| 536 | |||
| 537 | =head2 ROW METHODS | ||
| 538 | |||
| 539 | (Methods for accessing and manipulating rows of data) | ||
| 540 | |||
| 541 | Many of the methods for SMListbox take one or more indices as | ||
| 542 | arguments. See L<Tk::Listbox> for a description of row indices. | ||
| 543 | |||
| 544 | =over 4 | ||
| 545 | |||
| 546 | =item $sml->B<delete>(I<first>,I<last>) | ||
| 547 | |||
| 548 | Deletes one or more row elements of the SMListbox. I<First> and I<last> | ||
| 549 | are indices specifying the first and last elements in the range to | ||
| 550 | delete. If I<last> isn't specified it defaults to I<first>, | ||
| 551 | i.e. a single element is deleted. | ||
| 552 | |||
| 553 | =item $sml->B<get>(I<first>,I<last>) | ||
| 554 | |||
| 555 | If I<last> is omitted, returns the content of the SMListbox row | ||
| 556 | indicated by I<first>. If I<last> is specified, the command returns | ||
| 557 | a list whose elements are all of the listbox rows between | ||
| 558 | I<first> and I<last>. | ||
| 559 | |||
| 560 | The returned elements are all array references. The referenced | ||
| 561 | arrays contains one element for each column of the SMListbox. | ||
| 562 | |||
| 563 | =item $sml->B<getRow>(I<index>) | ||
| 564 | |||
| 565 | In scalar context, returns the value of column 0 in the SMListbox | ||
| 566 | row specified by I<index>. In list context, returns the content | ||
| 567 | of all columns in the row as an array. | ||
| 568 | |||
| 569 | This method is provided for convenience, since retrieving a single | ||
| 570 | row with the get() method might produce some ugly code. | ||
| 571 | |||
| 572 | The following two code snippets are equal: | ||
| 573 | |||
| 574 | 1. @row=$sml->getRow(0); | ||
| 575 | |||
| 576 | 2. @row=@{($sml->get(0))[0]}; | ||
| 577 | |||
| 578 | |||
| 579 | =item $sml->B<sort>(I<descending>, I<columnindex>...) | ||
| 580 | |||
| 581 | Sorts the content of the SMListbox. If I<descending> is a B<true> | ||
| 582 | value, the sort order will be descending. Default is B<0> - ascending | ||
| 583 | sort on B<first> column (0). | ||
| 584 | |||
| 585 | If I<columnindex> is specified, the sort will be done with the | ||
| 586 | specified column as key. You can specify as many I<columnindex> | ||
| 587 | arguments as you wish. Sorting is done on the first column, then | ||
| 588 | on the second, etc... | ||
| 589 | |||
| 590 | The default is to sort the data on all columns of the listbox, | ||
| 591 | with column 0 as the first sort key, column 1 as the second, etc. | ||
| 592 | |||
| 593 | =back | ||
| 594 | |||
| 595 | =head1 OTHER LISTBOX METHODS | ||
| 596 | |||
| 597 | Most other Tk::Listbox methods works for the SMListbox widget. This | ||
| 598 | includes the methods activate, cget, curselection, index, nearest, see, | ||
| 599 | selectionXXX, size, xview, yview. | ||
| 600 | |||
| 601 | See L<Tk::Listbox> | ||
| 602 | |||
| 603 | =head1 BINDING EVENTS TO SMLISTBOX | ||
| 604 | |||
| 605 | Calling $sml->bind(...) probably makes little sense, since the call does not | ||
| 606 | specify whether the binding should apply to the listbox, the header button | ||
| 607 | or the separator line between each column. | ||
| 608 | |||
| 609 | In stead of the ordinary bind, the following methods should be used: | ||
| 610 | |||
| 611 | =over 4 | ||
| 612 | |||
| 613 | =item $sml->B<bind>(I<sequence>,I<callback>) | ||
| 614 | |||
| 615 | Synonym for $sml->B<bindRows>(I<sequence>,I<callback>). | ||
| 616 | |||
| 617 | =item $sml->B<bindRows>(I<sequence>,I<callback>) | ||
| 618 | |||
| 619 | Synonym for $sml->B<bindSubwidgets>('listbox',I<sequence>,I<callback>) | ||
| 620 | |||
| 621 | =item $sml->B<bindColumns>(I<sequence>,I<callback>) | ||
| 622 | |||
| 623 | Synonym for $sml->B<bindSubwidgets>('heading',I<sequence>,I<callback>) | ||
| 624 | |||
| 625 | =item $sml->B<bindSeparators>(I<sequence>,I<callback>) | ||
| 626 | |||
| 627 | Synonym for $sml->B<bindSubwidgets>('separator',I<sequence>,I<callback>) | ||
| 628 | |||
| 629 | =item $sml->B<bindSubwidgets>(I<subwidget>,I<sequence>,I<callback>) | ||
| 630 | |||
| 631 | Adds the binding specified by I<sequence> and I<callback> to all subwidgets | ||
| 632 | of the given type (should be 'listbox', 'heading' or 'separator'). | ||
| 633 | |||
| 634 | The binding is stored in the widget, and if you create a new column | ||
| 635 | by calling $sml->columnInsert(), all bindings created by $sml->bindSubwidgets() | ||
| 636 | are automatically copied to the new column. | ||
| 637 | |||
| 638 | The callback is called with the SMListbox widget as first argument, and | ||
| 639 | the index of the column where the event occured as the second argument. | ||
| 640 | |||
| 641 | NOTE that $sml->bindSubwidgets() does not support all of Tk's callback formats. | ||
| 642 | The following are supported: | ||
| 643 | |||
| 644 | \&subname | ||
| 645 | sub { code } | ||
| 646 | [ \&subname, arguments...] | ||
| 647 | [ sub { code }, arguments...] | ||
| 648 | |||
| 649 | If I<sequence> is undefined, then the return value is a list whose elements | ||
| 650 | are all the sequences for which there exist bindings for I<subwidget>. | ||
| 651 | |||
| 652 | If I<sequence> is specified without I<callback>, then the callback currently | ||
| 653 | bound to sequence is returned, or an empty string is returned if there is no | ||
| 654 | binding for sequence. | ||
| 655 | |||
| 656 | If I<sequence> is specified, and I<callback> is an empty string, then the | ||
| 657 | current binding for sequence is destroyed, leaving sequence unbound. | ||
| 658 | An empty string is returned. | ||
| 659 | |||
| 660 | An empty string is returned in all other cases. | ||
| 661 | |||
| 662 | =back | ||
| 663 | |||
| 664 | =head1 KEYWORDS | ||
| 665 | |||
| 666 | smlistbox, mlistbox, listbox, widget | ||
| 667 | |||
| 668 | =head1 SEE ALSO | ||
| 669 | |||
| 670 | L<Tk::MListbox> L<Tk::Listbox> | ||
| 671 | |||
| 672 | =cut | ||
| 673 | |||
| 674 | ## Tk::SMListbox | ||
| 675 | ## | ||
| 676 | ## Tk::SMListbox is a derivitive of Tk::MListbox that adds optional tiny | ||
| 677 | ## up and down arrow graphics to columns in the SMListbox that the data is | ||
| 678 | ## currently sorted on indicating ascending and/or descending order. | ||
| 679 | ## | ||
| 680 | ## Tk::SMListbox adds 3 new methods: "compound", "getSortOrder" and | ||
| 681 | ## "showallsortcolumns": | ||
| 682 | ## | ||
| 683 | ## Version 2.x addes 2 additional methods: "setButtonHeight" and | ||
| 684 | ## "focusColumn". | ||
| 685 | ## | ||
| 686 | ## $smListBox->compound gets / sets the side of the column header that the | ||
| 687 | ## ascending / descending arrow is to appear (left, right, top, bottom), | ||
| 688 | ## default is "right". | ||
| 689 | ## | ||
| 690 | ## $smListBox->getSortOrder returns an array that is in the same format | ||
| 691 | ## accepted by the $smListBox->sort method. The 1st element is either | ||
| 692 | ## true for descending sort, false for assending. Subsequent elements | ||
| 693 | ## represent the column indices of one or more columns by which the data | ||
| 694 | ## is sorted. | ||
| 695 | ## | ||
| 696 | ## $smListBox->showallsortcolumns gets or sets whether a sort direction | ||
| 697 | ## arrow is to be displayed on each column involved in the sorting or just | ||
| 698 | ## the 1st (primary sort). Default is 0 (false) - show arrow only on the | ||
| 699 | ## primary sort column. | ||
| 700 | ## | ||
| 701 | ## $smListBox->setButtonHeight Sets (alters) the "-pady" value for the | ||
| 702 | ## header buttons. Should be called AFTER all columns have been created. | ||
| 703 | ## | ||
| 704 | ## $smListBox->focusColumn Gets or sets the index of the column whose | ||
| 705 | ## listbox is to receive the keyboard focus when the SMListbox widget | ||
| 706 | ## receives keyboard focus (See the pod / manpage for more details). | ||
| 707 | ## | ||
| 708 | ############################################################################## | ||
| 709 | ## MListbox Version 1.11 (26 Dec 2001) | ||
| 710 | ## | ||
| 711 | ## Original Author: Hans J. Helgesen, Dec 1999 | ||
| 712 | ## Maintainer: Rob Seegel (versions 1.10+) | ||
| 713 | ## | ||
| 714 | ## This version is a maintenance release of Hans' MListbox widget. | ||
| 715 | ## I have tried to avoid adding too many new features and just ensure | ||
| 716 | ## that the existing ones work properly. | ||
| 717 | ## | ||
| 718 | ## Please post feedback to comp.lang.perl.tk or email to RobSeegel@aol.com | ||
| 719 | ## | ||
| 720 | ## This module contains four classes. Of the four MListbox is | ||
| 721 | ## is the only one intended for standalone use, the other three: | ||
| 722 | ## SMCListbox, SMLColumn, SMHButton are accessible as Subwidgets, but | ||
| 723 | ## not intended to be used in any other way other than as | ||
| 724 | ## components of MListbox | ||
| 725 | ## | ||
| 726 | ############################################################################## | ||
| 727 | ## SMCListbox is similar to an ordinary listbox, but with the following | ||
| 728 | ## differences: | ||
| 729 | ## - Calls an -updatecommand whenever something happens to it. | ||
| 730 | ## - Horizontal scanning is disabled, calls -xscancommand to let parent widget | ||
| 731 | ## handle this. | ||
| 732 | |||
| 733 | { | ||
| 734 | package Tk::SMListbox::SMCListbox; | ||
| 735 | use base qw(Tk::Derived Tk::Listbox); | ||
| 736 | |||
| 737 | Tk::Widget->Construct('SMCListbox'); | ||
| 738 | |||
| 739 | sub Populate { | ||
| 740 | my ($w, $args) = @_; | ||
| 741 | $w->SUPER::Populate($args); | ||
| 742 | $w->ConfigSpecs( | ||
| 743 | -updatecommand => ['CALLBACK'], | ||
| 744 | -xscancommand => ['CALLBACK'], | ||
| 745 | ); | ||
| 746 | } | ||
| 747 | |||
| 748 | sub selectionSet { #JWT:NOTE:Callback->can() EATS 1ST ARGUMENT, SO WE MUST *NOT* SHIFT @_!!! | ||
| 749 | my ($w) = @_; | ||
| 750 | $w->Callback(-updatecommand=>$w->can('Tk::Listbox::selectionSet'),@_); | ||
| 751 | } | ||
| 752 | |||
| 753 | sub selectionClear { | ||
| 754 | my ($w) = @_; | ||
| 755 | $w->Callback(-updatecommand=>$w->can('Tk::Listbox::selectionClear'),@_); | ||
| 756 | } | ||
| 757 | |||
| 758 | sub selectionAnchor { | ||
| 759 | my ($w) = @_; | ||
| 760 | $w->Callback(-updatecommand=>$w->can('Tk::Listbox::selectionAnchor'),@_); | ||
| 761 | } | ||
| 762 | |||
| 763 | sub activate { | ||
| 764 | my ($w) = @_; | ||
| 765 | $w->Callback(-updatecommand=>$w->can('Tk::Listbox::activate'),@_); | ||
| 766 | } | ||
| 767 | |||
| 768 | sub see { | ||
| 769 | my ($w) = @_; | ||
| 770 | $w->Callback(-updatecommand=>$w->can('Tk::Listbox::see'),@_); | ||
| 771 | } | ||
| 772 | |||
| 773 | sub yview { | ||
| 774 | my ($w) = @_; #JWT:NOTE:Callback->can() EATS 1ST ARGUMENT, SO WE MUST *NOT* SHIFT @_!!! | ||
| 775 | @args = @_; | ||
| 776 | shift @args; #JWT:NOTE:WE DO SHIFT THE MODULE OFF BEFORE CALLING yview, ETC. DIRECTLY! | ||
| 777 | $w->Callback(-updatecommand=>$w->can('Tk::Listbox::yview'),@_); | ||
| 778 | $w->Tk::Listbox::yview unless (@args); #JWT:REQUIRED BY _yscrollCallback! | ||
| 779 | } | ||
| 780 | |||
| 781 | sub scan { | ||
| 782 | my ($w,$type,$x,$y) = @_; | ||
| 783 | # Disable horizontal scanning. | ||
| 784 | if ($type eq 'mark') { | ||
| 785 | $w->{'_scanmark_x'} = $x; | ||
| 786 | } | ||
| 787 | $w->Callback(-updatecommand=>$w->can('Tk::Listbox::scan'), | ||
| 788 | $w, $type, $w->{'_scanmark_x'}, $y | ||
| 789 | ); | ||
| 790 | $w->Callback(-xscancommand=>$type,$x); | ||
| 791 | } | ||
| 792 | |||
| 793 | sub SpaceSelect | ||
| 794 | { | ||
| 795 | my ($w) = @_; | ||
| 796 | eval { shift; $w->Tk::Listbox::SpaceSelect(@_); }; | ||
| 797 | } | ||
| 798 | |||
| 799 | sub CtrlPriorNext | ||
| 800 | { | ||
| 801 | my ($w) = @_; | ||
| 802 | $w->Callback(-updatecommand=>$w->can('Tk::Listbox::CtrlPriorNext'),@_); | ||
| 803 | } | ||
| 804 | } | ||
| 805 | |||
| 806 | ############################################################################## | ||
| 807 | ## SMHButton is like an ordinary Button, but with an addition option: | ||
| 808 | ## -pixelwidth | ||
| 809 | ## The new configure method makes sure the pixelwidth is always retained. | ||
| 810 | { | ||
| 811 | package Tk::SMListbox::SMHButton; | ||
| 812 | use base qw(Tk::Derived Tk::Button); | ||
| 813 | Tk::Widget->Construct('SMHButton'); | ||
| 814 | |||
| 815 | sub Populate { | ||
| 816 | my ($w, $args) = @_; | ||
| 817 | $w->SUPER::Populate($args); | ||
| 818 | $w->ConfigSpecs( | ||
| 819 | -pixelwidth => ['PASSIVE'], | ||
| 820 | -bitmap => [qw/SELF bitmap bitmap/, 'noarrow'], | ||
| 821 | -compound => [qw/SELF compound compound/, 'right'], | ||
| 822 | -background => [qw/SELF background Background/, undef], | ||
| 823 | -foreground => [qw/SELF foreground Foreground/, undef] | ||
| 824 | ); | ||
| 825 | } | ||
| 826 | |||
| 827 | sub configure { | ||
| 828 | my $w = shift; | ||
| 829 | my (@ret) = $w->SUPER::configure(@_); | ||
| 830 | unless (@ret) { | ||
| 831 | if (defined(my $pixels = $w->cget('-pixelwidth'))) { | ||
| 832 | $w->GeometryRequest($pixels,$w->reqheight); | ||
| 833 | } | ||
| 834 | } | ||
| 835 | return @ret; | ||
| 836 | } | ||
| 837 | } | ||
| 838 | |||
| 839 | ############################################################################### | ||
| 840 | ## SMLColumn implements a single column in the SMListbox. SMLColumn is a composite | ||
| 841 | ## containing a heading (an SMHButton), a listbox (SMCListbox) and a frame which | ||
| 842 | ## frame which serves as a draggable separator | ||
| 843 | { | ||
| 844 | package Tk::SMListbox::SMLColumn; | ||
| 845 | use base qw(Tk::Frame); | ||
| 846 | Tk::Widget->Construct('SMLColumn'); | ||
| 847 | |||
| 848 | sub Populate { | ||
| 849 | my ($w, $args) = @_; | ||
| 850 | my $undln = delete($args->{'-underline'}); | ||
| 851 | $w->SUPER::Populate($args); | ||
| 852 | my $hdrBG = $args->{'-headerbackground'} || $args->{'-background'} || undef; | ||
| 853 | my $hdrFG = $args->{'-headerforeground'} || $args->{'-foreground'} || undef; | ||
| 854 | my $disableFG = $args->{'-disabledforeground'} || undef; | ||
| 855 | |||
| 856 | ## SMLColumn Components | ||
| 857 | ## $sep - separator - Frame | ||
| 858 | ## $hdr - heading - SMHButton | ||
| 859 | ## $f - frame - Frame | ||
| 860 | ## $lb - listbox - SMCListbox | ||
| 861 | |||
| 862 | my $sep = $w->Component( | ||
| 863 | Frame => 'separator', | ||
| 864 | -height => 1, | ||
| 865 | -takefocus => 0, | ||
| 866 | )->pack(qw/-side right -fill y -anchor w/); | ||
| 867 | |||
| 868 | $sep->bind( "<B1-Motion>", | ||
| 869 | [$w=>'adjustMotion']); | ||
| 870 | $sep->bind("<ButtonRelease-1>", | ||
| 871 | [$w=>'Callback','-configurecommand']); | ||
| 872 | |||
| 873 | my $f = $w->Component( | ||
| 874 | Frame => "frame", | ||
| 875 | -takefocus => 0, | ||
| 876 | )->pack(qw/-side left -anchor n -fill both -expand 1/); | ||
| 877 | |||
| 878 | my $hdr; | ||
| 879 | if (defined $undln) { | ||
| 880 | |||
| 881 | $hdr = $f->SMHButton( | ||
| 882 | -takefocus=>0, | ||
| 883 | -padx=>0, | ||
| 884 | -width=>1, | ||
| 885 | -borderwidth=>2, | ||
| 886 | -underline=>$undln, | ||
| 887 | -highlightthickness=>0 | ||
| 888 | )->pack(qw/-side top -anchor n -fill x -expand 0/); | ||
| 889 | } else { | ||
| 890 | $hdr = $f->SMHButton( | ||
| 891 | -takefocus=>0, | ||
| 892 | -padx=>0, | ||
| 893 | -width=>1, | ||
| 894 | -borderwidth=>2, | ||
| 895 | -highlightthickness=>0 | ||
| 896 | )->pack(qw/-side top -anchor n -fill x -expand 0/); | ||
| 897 | } | ||
| 898 | $w->Advertise("heading" => $hdr); | ||
| 899 | |||
| 900 | my $lb = $f->SMCListbox( | ||
| 901 | -highlightthickness=>0, | ||
| 902 | -relief=>'flat', | ||
| 903 | -bd=>0, | ||
| 904 | -exportselection=>0, | ||
| 905 | -takefocus=>0, | ||
| 906 | #DECIDED TO LEAVE UNDERLINED: -activestyle => 'dotbox', | ||
| 907 | )->pack(qw/-side top -anchor n -expand 1 -fill both/); | ||
| 908 | $w->Advertise("listbox" => $lb); | ||
| 909 | $w->Delegates (DEFAULT => $lb); | ||
| 910 | |||
| 911 | my $bgWidgets = defined($hdrBG) ? [$f, $lb] : [$f, $hdr, $lb]; | ||
| 912 | my $fgWidgets = defined($hdrFG) ? [$f, $lb] : [$f, $hdr, $lb]; | ||
| 913 | my $dfgWidgets = defined($disableFG) ? [$f, $lb] : [$f, $hdr, $lb]; | ||
| 914 | $w->ConfigSpecs( | ||
| 915 | # -background => [[$f, $hdr, $lb], | ||
| 916 | -background => [$bgWidgets, | ||
| 917 | qw/background Background/, undef], | ||
| 918 | -comparecommand => ['CALLBACK', undef, undef, | ||
| 919 | sub{$_[0] cmp $_[1]}], | ||
| 920 | -configurecommand => ['CALLBACK'], | ||
| 921 | |||
| 922 | -font => [[$hdr, $lb], qw/font Font/, undef], | ||
| 923 | # -foreground => [[$hdr, $lb], | ||
| 924 | -foreground => [$fgWidgets, | ||
| 925 | qw/foreground Foreground/, undef], | ||
| 926 | -headerbackground => [qw/PASSIVE headerBackground HeaderBackground/, $hdrBG], | ||
| 927 | -headerforeground => [qw/PASSIVE headerForeground HeaderForeground/, $hdrFG], | ||
| 928 | -disabledforeground => [$dfgWidgets, qw/disabledForeground DisabledForeground/, $disableFG], | ||
| 929 | -separatorwidth => [{-width => $sep}, | ||
| 930 | qw/separatorWidth Separator 1/], | ||
| 931 | -separatorcolor => [{-background => $sep}, | ||
| 932 | qw/separatorColor Separator black/], | ||
| 933 | -resizeable => [qw/METHOD resizeable Resizeable 1/], | ||
| 934 | -sortable => [qw/PASSIVE sortable Sortable 1/], | ||
| 935 | -text => [$hdr], | ||
| 936 | -compound => [[$hdr], 'compound', 'compound', 'right'], | ||
| 937 | -updatecommand => [$lb], | ||
| 938 | -textwidth => [{-width => [$lb, $hdr]}], | ||
| 939 | -reversearrow => [qw/PASSIVE reversearrow reversearrow 0/], | ||
| 940 | -state => ['METHOD', 'state', 'State', 'normal'], | ||
| 941 | DEFAULT => [$lb] | ||
| 942 | ); | ||
| 943 | $w->ConfigAlias( | ||
| 944 | -comparecmd => '-comparecommand', | ||
| 945 | -width => '-textwidth' | ||
| 946 | ); | ||
| 947 | |||
| 948 | $hdr->configure('-background' => $hdrBG) if (defined $hdrBG); | ||
| 949 | $hdr->configure('-foreground' => $hdrFG) if (defined $hdrFG); | ||
| 950 | $hdr->configure('-disabledforeground' => $disableFG) if (defined $disableFG); | ||
| 951 | } | ||
| 952 | |||
| 953 | ###################################################################### | ||
| 954 | ## SMLColumn Configuration methods (call via configure/cget). | ||
| 955 | ###################################################################### | ||
| 956 | |||
| 957 | sub resizeable { | ||
| 958 | my ($w, $value) = @_; | ||
| 959 | return $w->{Configure}{-resizeable} unless (defined $value); | ||
| 960 | |||
| 961 | $w->Subwidget("separator")->configure( | ||
| 962 | -cursor => ($value ? 'sb_h_double_arrow' : 'xterm') | ||
| 963 | ); | ||
| 964 | } | ||
| 965 | |||
| 966 | sub compare { | ||
| 967 | shift->Callback(-comparecommand => $_[0], $_[1]); | ||
| 968 | } | ||
| 969 | |||
| 970 | sub setWidth { | ||
| 971 | my ($w, $pixels) = @_; | ||
| 972 | $pixels -= $w->Subwidget("separator")->width; | ||
| 973 | return unless ($pixels >= 0); | ||
| 974 | |||
| 975 | $w->Subwidget("listbox")->GeometryRequest( | ||
| 976 | $pixels,$w->Subwidget("listbox")->height); | ||
| 977 | $w->Subwidget("heading")->configure(-pixelwidth=>$pixels); | ||
| 978 | } | ||
| 979 | |||
| 980 | ###################################################################### | ||
| 981 | ## SMLColumn Private methods (Do not depend on these methods being present) | ||
| 982 | ###################################################################### | ||
| 983 | |||
| 984 | sub _setButtonHeight { | ||
| 985 | my $w = shift; | ||
| 986 | my $pady = shift; | ||
| 987 | $w->Subwidget("heading")->configure(-pady => $pady) if (defined $pady); | ||
| 988 | } | ||
| 989 | |||
| 990 | ## Adjust size of column. | ||
| 991 | sub adjustMotion { | ||
| 992 | my ($w) = @_; | ||
| 993 | return if ($w->getState() =~ /d/o); | ||
| 994 | |||
| 995 | $w->setWidth($w->pointerx - $w->rootx) if ($w->resizeable); | ||
| 996 | } | ||
| 997 | |||
| 998 | sub state { | ||
| 999 | my $w = shift; | ||
| 1000 | my $state = shift; | ||
| 1001 | #FOOBARS FOCUS?! return $w->{Configure}{'-state'} || undef unless (defined($state) && $state); | ||
| 1002 | |||
| 1003 | $w->Subwidget("listbox")->configure('-state' => $state, -takefocus => 0); | ||
| 1004 | $w->Subwidget("heading")->configure('-state' => $state, -takefocus => 0); | ||
| 1005 | $w->{'_hlistboxstate'} = $state; | ||
| 1006 | } | ||
| 1007 | |||
| 1008 | sub getState { | ||
| 1009 | return shift->{'_hlistboxstate'}; | ||
| 1010 | } | ||
| 1011 | |||
| 1012 | } ## END PRELOADING OF SMLColumn | ||
| 1013 | |||
| 1014 | ###################################################################### | ||
| 1015 | ## Package: Tk::SMListbox | ||
| 1016 | ## Purpose: Multicolumn widget used to display tabular data | ||
| 1017 | ## with optional sorted-column indicator arrows and keyboard- | ||
| 1018 | ## bound column-sorting capability. | ||
| 1019 | ## This widget has the ability to sort data by column, | ||
| 1020 | ## hide/show columns, and the ability to change the order | ||
| 1021 | ## of columns on the fly | ||
| 1022 | |||
| 1023 | package Tk::SMListbox; | ||
| 1024 | use strict; | ||
| 1025 | use Carp; | ||
| 1026 | use vars qw($VERSION); | ||
| 1027 | $VERSION = '2.21'; | ||
| 1028 | |||
| 1029 | use Tk; | ||
| 1030 | |||
| 1031 | ## Overidden Scrolled method to suit the purposes of SMListbox | ||
| 1032 | ## I want -columns to be configured LAST no matter what. | ||
| 1033 | ## I know full well that I'm overriding the Scrolled method | ||
| 1034 | ## and I don't need a warning broadcasting the fact. | ||
| 1035 | |||
| 1036 | no warnings; | ||
| 1037 | |||
| 1038 | sub Tk::Widget::Scrolled { | ||
| 1039 | my ($parent, $kind, %args) = @_; | ||
| 1040 | |||
| 1041 | my $colAR; | ||
| 1042 | $colAR = delete $args{'-columns'} if $kind eq 'SMListbox'; | ||
| 1043 | |||
| 1044 | ## Find args that are Frame create time args | ||
| 1045 | my @args = Tk::Frame->CreateArgs($parent,\%args); | ||
| 1046 | my $name = delete $args{'Name'}; | ||
| 1047 | push(@args,'Name' => $name) if (defined $name); | ||
| 1048 | my $cw = $parent->Frame(@args); | ||
| 1049 | # $cw->bind('<FocusIn>', sub { $cw->focusNext; Tk->break;}); | ||
| 1050 | @args = (); | ||
| 1051 | my $scrollbarfocus = (defined $args{'-scrollbarfocus'}) ? delete($args{'-scrollbarfocus'}) : undef; | ||
| 1052 | |||
| 1053 | ## Now remove any args that Frame can handle | ||
| 1054 | foreach my $k ('-scrollbars',map($_->[0],$cw->configure)) { | ||
| 1055 | push(@args,$k,delete($args{$k})) if (exists $args{$k}) | ||
| 1056 | } | ||
| 1057 | ## Anything else must be for target widget - pass at widget create time | ||
| 1058 | my $w = $cw->$kind(%args); | ||
| 1059 | $cw->{'__SMListbox__'} = $w if ($w =~ /SMListbox/o); #JWT:SAVE ME FOR FUTURE USE! | ||
| 1060 | ## Now re-set %args to be ones Frame can handle | ||
| 1061 | ## RCS NOTE: I've also slightly modified the ConfigSpecs | ||
| 1062 | %args = @args; | ||
| 1063 | $args{'-scrollbarfocus'} = $scrollbarfocus if (defined($scrollbarfocus) && $scrollbarfocus =~ /[xy01]/); | ||
| 1064 | $cw->ConfigSpecs( | ||
| 1065 | '-scrollbars' => [qw/METHOD scrollbars Scrollbars se/], | ||
| 1066 | '-background' => [$w, qw/background Background/, undef], | ||
| 1067 | '-foreground' => [$w, qw/foreground Foreground/, undef], | ||
| 1068 | '-scrollbarfocus' => ['METHOD', 'scrollbarfocus', 'Focus', ''], | ||
| 1069 | ); | ||
| 1070 | $cw->AddScrollbars($w); | ||
| 1071 | $cw->Default("\L$kind" => $w); | ||
| 1072 | $cw->Delegates('bind' => $w, 'bindtags' => $w, 'menu' => $w); | ||
| 1073 | $cw->ConfigDefault(\%args); | ||
| 1074 | delete($args{'-scrollbarfocus'}) if (defined $args{'-scrollbarfocus'}); #DELETE IT AGAIN SO THIS ONE WON'T BITCH! | ||
| 1075 | $cw->configure(%args); | ||
| 1076 | $args{'-scrollbarfocus'} = $scrollbarfocus if (defined($scrollbarfocus) && $scrollbarfocus =~ /[xy01]/); | ||
| 1077 | $cw->configure(-columns => $colAR) if $colAR; | ||
| 1078 | $w->scrollbarfocus($scrollbarfocus) if ($scrollbarfocus =~ /[xy01]/); | ||
| 1079 | #MAKE HORIZ. SCROLLBAR SCROLL WINDOW HORIZONTALLY (SCROLLING IN COLUMNS SCROLLS JUST THAT COLUMN): | ||
| 1080 | $w->parent->Subwidget('xscrollbar')->bind('<Button-6>', sub { | ||
| 1081 | $cw->{'__SMListbox__'}->_chgView('xview','scroll',-1,'units') if (defined $cw->{'__SMListbox__'}); | ||
| 1082 | }); | ||
| 1083 | $w->parent->Subwidget('xscrollbar')->bind('<Button-7>', sub { | ||
| 1084 | $cw->{'__SMListbox__'}->_chgView('xview','scroll',1,'units') if (defined $cw->{'__SMListbox__'}); | ||
| 1085 | }); | ||
| 1086 | return $cw; | ||
| 1087 | } | ||
| 1088 | |||
| 1089 | use warnings; | ||
| 1090 | |||
| 1091 | require Tk::Pane; | ||
| 1092 | use base qw(Tk::Frame); | ||
| 1093 | Tk::Widget->Construct('SMListbox'); | ||
| 1094 | |||
| 1095 | sub ClassInit { | ||
| 1096 | my ($class,$mw) = @_; | ||
| 1097 | $mw->bind($class,'<Configure>',['_yscrollCallback']); | ||
| 1098 | $mw->bind($class,'<Down>',['_upDown',1]); | ||
| 1099 | $mw->bind($class,'<Up>', ['_upDown',-1]); | ||
| 1100 | $mw->bind($class,'<Control-Down>',['_ctrlupDown',1]); | ||
| 1101 | $mw->bind($class,'<Control-Up>', ['_ctrlupDown',-1]); | ||
| 1102 | $mw->bind($class,'<Shift-Up>', ['_extendUpDown',-1]); | ||
| 1103 | $mw->bind($class,'<Shift-Down>',['_extendUpDown',1]); | ||
| 1104 | $mw->bind($class,'<Control-Home>','_cntrlHome'); | ||
| 1105 | $mw->bind($class,'<Control-End>','_cntrlEnd'); | ||
| 1106 | $mw->bind($class,'<Shift-Control-Home>',['_dataExtend',0]); | ||
| 1107 | $mw->bind($class,'<Shift-Control-End>',['_dataExtend',Ev('index', 'end')]); | ||
| 1108 | $mw->bind($class,'<Control-slash>','_selectAll'); | ||
| 1109 | $mw->bind($class,'<Control-backslash>','_deselectAll'); | ||
| 1110 | $mw->bind($class,'<FocusIn>','focus'); | ||
| 1111 | $mw->bind($class,'<FocusOut>','unfocus'); | ||
| 1112 | $mw->bind($class,'<Escape>', '_Cancel'); | ||
| 1113 | $mw->bind($class, '<Home>', ['_chgView','xview','moveto',0.001]); | ||
| 1114 | $mw->bind($class, '<End>', ['_chgView','xview','moveto',1]); | ||
| 1115 | $mw->bind($class, '<Prior>', ['_chgView','yview','scroll',-1,'pages']); | ||
| 1116 | $mw->bind($class, '<Next>', ['_chgView','yview','scroll',1,'pages']); | ||
| 1117 | $mw->bind($class, '<Control-Prior>', ['CtrlPriorNext',-1]); | ||
| 1118 | $mw->bind($class, '<Control-Next>', ['CtrlPriorNext',1]); | ||
| 1119 | $mw->bind($class,'<space>',['SpaceSelect',Ev('index','active')]); | ||
| 1120 | $mw->bind($class,'<Select>',['SpaceSelect',Ev('index','active')]); | ||
| 1121 | $mw->bind($class,'<Tab>', sub { my $w = shift; $w->focusNext; }); | ||
| 1122 | |||
| 1123 | my $downArrowBits = pack("b10"x10, | ||
| 1124 | "..........", | ||
| 1125 | "..........", | ||
| 1126 | "..........", | ||
| 1127 | ".#########", | ||
| 1128 | "..#######.", | ||
| 1129 | "...#####..", | ||
| 1130 | "....###...", | ||
| 1131 | ".....#....", | ||
| 1132 | "..........", | ||
| 1133 | ".........." | ||
| 1134 | ); | ||
| 1135 | $mw->DefineBitmap('downarrow' => 10,10, $downArrowBits); | ||
| 1136 | my $upArrowBits = pack("b10"x10, | ||
| 1137 | "..........", | ||
| 1138 | "..........", | ||
| 1139 | "..........", | ||
| 1140 | ".....#....", | ||
| 1141 | "....###...", | ||
| 1142 | "...#####..", | ||
| 1143 | "..#######.", | ||
| 1144 | ".#########", | ||
| 1145 | "..........", | ||
| 1146 | ".........." | ||
| 1147 | ); | ||
| 1148 | $mw->DefineBitmap('uparrow' => 10,10, $upArrowBits); | ||
| 1149 | my $noArrowBits = pack("b10"x10, | ||
| 1150 | "..........", | ||
| 1151 | "..........", | ||
| 1152 | "..........", | ||
| 1153 | "..........", | ||
| 1154 | "..........", | ||
| 1155 | "..........", | ||
| 1156 | "..........", | ||
| 1157 | "..........", | ||
| 1158 | "..........", | ||
| 1159 | ".........." | ||
| 1160 | ); | ||
| 1161 | $mw->DefineBitmap('noarrow' => 10,10, $noArrowBits); | ||
| 1162 | } | ||
| 1163 | |||
| 1164 | ## Do some slightly tricky stuff: The -columns option, if called is | ||
| 1165 | ## guaranteed to be confiugred last of all the options submitted. | ||
| 1166 | ## NOTE: The args hash is cleared out if a columns option is sent | ||
| 1167 | ## so that all the options won't be reconfigured again immediately | ||
| 1168 | ## after this method finishes. ALso, if Scrolled is called, then | ||
| 1169 | ## the -columns option will never make it down to this level so | ||
| 1170 | |||
| 1171 | sub InitObject { | ||
| 1172 | my ($w, $args) = @_; | ||
| 1173 | |||
| 1174 | my $colAR = delete $args->{'-columns'}; | ||
| 1175 | $w->Populate($args); | ||
| 1176 | $w->ConfigDefault($args); | ||
| 1177 | if ($colAR) { | ||
| 1178 | $w->configure(%$args); | ||
| 1179 | $w->configure(-columns => $colAR); | ||
| 1180 | %$args = (); | ||
| 1181 | } | ||
| 1182 | } | ||
| 1183 | |||
| 1184 | sub Populate { | ||
| 1185 | my ($w, $args) = @_; | ||
| 1186 | |||
| 1187 | # $w->SUPER::Populate($args); | ||
| 1188 | |||
| 1189 | $w->{'_columns'} = []; ## Array of SMLColumn objects | ||
| 1190 | $w->{'_sortcol'} = -1; ## Column used for sorting | ||
| 1191 | $w->{'_sortcolumns'} = []; | ||
| 1192 | $w->{'_sort_descending'} = 0; ## Flag for ascending/desc. sort order | ||
| 1193 | $w->{'_top'} = 0; | ||
| 1194 | $w->{'_bottom'} = 0; | ||
| 1195 | $w->{'_hasfocus'} = 0; | ||
| 1196 | |||
| 1197 | my $pane = $w->Component( | ||
| 1198 | Pane => "pane", | ||
| 1199 | -sticky => 'nsew', | ||
| 1200 | -takefocus => 0, | ||
| 1201 | )->pack(-expand=>1,-fill=>'both'); | ||
| 1202 | |||
| 1203 | my $font; | ||
| 1204 | if ($Tk::platform eq 'MSWin32') { | ||
| 1205 | $font = "{MS Sans Serif} 8"; | ||
| 1206 | } else { | ||
| 1207 | $font = "Helvetica -12 bold"; | ||
| 1208 | } | ||
| 1209 | |||
| 1210 | my $hdr = $w->Subwidget('heading'); | ||
| 1211 | |||
| 1212 | $w->ConfigSpecs( | ||
| 1213 | -background => [qw/METHOD background Background/, undef], | ||
| 1214 | -columns => [qw/METHOD/], | ||
| 1215 | -configurecommand => [qw/CALLBACK/], | ||
| 1216 | -font => [qw/METHOD font Font/, $font], | ||
| 1217 | -foreground => [qw/METHOD foreground Foreground/, undef], | ||
| 1218 | -headerbackground => [qw/METHOD headerbackground headerBackground/, undef], | ||
| 1219 | -headerforeground => [qw/METHOD headerforeground headerForeground/, undef], | ||
| 1220 | -height => [qw/METHOD height Height 10/], | ||
| 1221 | -moveable => [qw/PASSIVE moveable Moveable 1/], | ||
| 1222 | -resizeable => [qw/METHOD resizeable Resizeable 1/], | ||
| 1223 | -selectbackground => [qw/METHOD selectBackground Background/, undef], | ||
| 1224 | -selectborderwidth => [qw/METHOD selectBorderwidth Borderwidth 1/], | ||
| 1225 | -selectforeground => [qw/METHOD selectForeground Foreground/, undef], | ||
| 1226 | -disabledforeground => [qw/PASSIVE disabledForeground DisabledForeground/, undef], | ||
| 1227 | -selectmode => [qw/METHOD selectMode Mode browse/], | ||
| 1228 | -compound => [qw/METHOD compound compound right/], | ||
| 1229 | -showallsortcolumns => [qw/METHOD showallsortcolumns showallsortcolumns 0/], | ||
| 1230 | -jwtlistboxhack => [qw/PASSIVE jwtlistboxhack jwtlistboxhack 0/], | ||
| 1231 | -fillcolumn => [qw/PASSIVE fillcolumn fillColumn -1/], | ||
| 1232 | -focuscolumn => [qw/PASSIVE focuscolumn focusColumn -1/], | ||
| 1233 | -nocolumnfocus => [qw/PASSIVE nocolumnfocus nocolumnfocus 0/], | ||
| 1234 | -separatorcolor => [qw/METHOD separatorColor Foreground black/], | ||
| 1235 | -separatorwidth => [qw/METHOD separatorWidth SeparatorWidth 1/], | ||
| 1236 | -sortable => [qw/METHOD sortable Sortable 1/], | ||
| 1237 | -takefocus => ['METHOD', 'takeFocus', 'TakeFocus', ''], #JWT:MUST BE METHOD SINCE SCROLLED EATS IT OTHERWISE! | ||
| 1238 | -textwidth => [qw/METHOD textWidth Width 10/], | ||
| 1239 | -width => [qw/METHOD width Width/, undef], | ||
| 1240 | -xscrollcommand => [$pane], | ||
| 1241 | -yscrollcommand => ['CALLBACK'], | ||
| 1242 | -state => ['METHOD', 'state', 'State', 'normal'], | ||
| 1243 | ); | ||
| 1244 | $w->{'_ourtakefocus'} = (defined $args->{'-takefocus'}) ? $args->{'-takefocus'} : ''; #NOTE: Scrolled EATS THIS! | ||
| 1245 | |||
| 1246 | $w->ConfigAlias( | ||
| 1247 | -selectbg => "-selectbackground", | ||
| 1248 | -selectbd => "-selectborderwidth", | ||
| 1249 | -selectfg => "-selectforeground", | ||
| 1250 | -sepcolor => "-separatorcolor", | ||
| 1251 | -sepwidth => "-separatorwidth", | ||
| 1252 | ); | ||
| 1253 | #THESE NEEDED TO GET TAB-FOCUS CYCLING RIGHT: | ||
| 1254 | $w->parent->bind('<Tab>', sub { my $w = shift; $w->focusNext; }); | ||
| 1255 | $w->parent->bind('<FocusIn>', sub { my $w = shift; $w->focusNext; }); | ||
| 1256 | #JWT:HAD TO DO THESE THIS WAY INSTEAD OF IN THE CLASS, ELSE THEY DON'T WORK!: | ||
| 1257 | $w->bindRows('<Home>', ['_chgView', 'xview','moveto',0.001]); | ||
| 1258 | $w->bindRows('<End>', ['_chgView', 'xview','moveto',1]); | ||
| 1259 | |||
| 1260 | $w->bindRows('<ButtonPress-1>', [sub { #ONLY NEED THIS BINDING TO TAKE FOCUS IF -takefocus == 1 (CLICK-TO-FOCUS): | ||
| 1261 | my $w = shift; | ||
| 1262 | |||
| 1263 | #WARNING: WE DON'T REALLY HAVE ACCESS TO WHERE THE MOUSE WAS CLICKED, AS "Ev(*)" DATA IS | ||
| 1264 | #NOT PROPERLY PASSED TO THESE BINDINGS IF THE COLUMNS DON'T ALREADY EXIST WHEN THEY'RE SET UP!: | ||
| 1265 | if (Tk::Exists($w)) { | ||
| 1266 | return if ($w->{Configure}{'-state'} =~ /d/o); | ||
| 1267 | |||
| 1268 | $w->focus if (!$w->{'_hasfocus'} && $w->{'_ourtakefocus'}); | ||
| 1269 | } | ||
| 1270 | }]); | ||
| 1271 | } | ||
| 1272 | |||
| 1273 | sub scrollbarfocus { #JWT: ALLOW THEM TO SPECIFY WHICH, IF ANY SCROLLBARS TAKE FOCUS: | ||
| 1274 | my $w = shift; | ||
| 1275 | my $focusopt = shift; | ||
| 1276 | return $w->{Configure}{'-scrollbarfocus'} || undef unless (defined($focusopt)); | ||
| 1277 | |||
| 1278 | if ($focusopt eq '0') { | ||
| 1279 | $w->parent->Subwidget('xscrollbar')->configure(-takefocus => 0); | ||
| 1280 | $w->parent->Subwidget('yscrollbar')->configure(-takefocus => 0); | ||
| 1281 | } elsif (! $focusopt) { | ||
| 1282 | return; | ||
| 1283 | } elsif ($focusopt eq '1' || ($focusopt =~ /x/o && $focusopt =~ /y/o)) { | ||
| 1284 | $w->parent->Subwidget('xscrollbar')->configure(-takefocus => 1); | ||
| 1285 | $w->parent->Subwidget('yscrollbar')->configure(-takefocus => 1); | ||
| 1286 | } elsif ($focusopt =~ /x/o) { | ||
| 1287 | $w->parent->Subwidget('xscrollbar')->configure(-takefocus => 1); | ||
| 1288 | $w->parent->Subwidget('yscrollbar')->configure(-takefocus => 0); | ||
| 1289 | } elsif ($focusopt =~ /y/o || $focusopt !~ /x/o) { | ||
| 1290 | $w->parent->Subwidget('yscrollbar')->configure(-takefocus => 1); | ||
| 1291 | $w->parent->Subwidget('xscrollbar')->configure(-takefocus => 0); | ||
| 1292 | } | ||
| 1293 | } | ||
| 1294 | |||
| 1295 | sub getSortOrder { #JWT: ADDED THIS METHOD TO FETCH HOW THE LIST IS SORTED! | ||
| 1296 | my $w = shift; | ||
| 1297 | |||
| 1298 | my @l = scalar(@{$w->{'_sortcolumns'}}) ? @{$w->{'_sortcolumns'}} : (0); | ||
| 1299 | return ($w->{'_sort_descending'}||0, @l); | ||
| 1300 | } | ||
| 1301 | |||
| 1302 | sub setSortOrder { #JWT: ADDED THIS METHOD TO FETCH HOW THE LIST IS SORTED! | ||
| 1303 | my $w = shift; | ||
| 1304 | my ($sOrder, @sColumns) = @_; | ||
| 1305 | |||
| 1306 | $w->{'_sort_descending'} = $sOrder; | ||
| 1307 | $w->{'_sortcolumns'} = [@sColumns] if (defined $sColumns[0]); | ||
| 1308 | } | ||
| 1309 | |||
| 1310 | ###################################################################### | ||
| 1311 | ## Configuration methods (call via configure). | ||
| 1312 | ###################################################################### | ||
| 1313 | |||
| 1314 | ## Background is a slightly tricky option, this option would be a | ||
| 1315 | ## great candidate for "DESCENDANTS", except for the separator subwidget in | ||
| 1316 | ## each column set by separatorcolor which I'd prefer not to set in such | ||
| 1317 | ## a clumsy way. All other background colors are fair game, but I'd like | ||
| 1318 | ## to leave open the possibility for other exceptions such as separator. | ||
| 1319 | ## Besides I prefer that composite subwidgets manage their own component parts | ||
| 1320 | ## as much as possible. | ||
| 1321 | |||
| 1322 | sub background { | ||
| 1323 | my ($w, $val) = @_; | ||
| 1324 | return $w->{Configure}{'-background'} | ||
| 1325 | unless $val; | ||
| 1326 | |||
| 1327 | ## Ensure that the base Frame, pane and columns (if any) get set | ||
| 1328 | Tk::configure($w, "-background", $val); | ||
| 1329 | $w->Subwidget("pane")->configure("-background", $val); | ||
| 1330 | $w->_configureColumns("-background", $val); | ||
| 1331 | } | ||
| 1332 | |||
| 1333 | ## columns needs to be called last during creation time if set and I | ||
| 1334 | ## went to a great deal of trouble to guarantee this. The reason | ||
| 1335 | ## being is that it needs to use many of the other configurations to | ||
| 1336 | ## use as defaults for columns, and the ability to override any of them | ||
| 1337 | ## for individual columns. If these options (that the columns override) | ||
| 1338 | ## were called afterwards, then the reverse would happen. All the default | ||
| 1339 | ## would override the individually specified options. | ||
| 1340 | |||
| 1341 | sub columns { | ||
| 1342 | my ($w, $vAR) = @_; | ||
| 1343 | return $w->{Configure}{'-columns'} unless (defined $vAR); | ||
| 1344 | |||
| 1345 | $w->columnDelete(0, 'end'); | ||
| 1346 | map {$w->columnInsert('end', @$_)} @$vAR; | ||
| 1347 | } | ||
| 1348 | |||
| 1349 | sub font { shift->_configureColumns('-font', @_) } | ||
| 1350 | sub foreground { shift->_configureColumns('-foreground', @_) } | ||
| 1351 | sub headerbackground { shift->_configureColumns('-headerbackground', @_); } | ||
| 1352 | sub headerforeground { shift->_configureColumns('-headerforeground', @_); } | ||
| 1353 | sub disabledforeground { shift->_configureColumns('-disabledforeground', @_); } | ||
| 1354 | sub height { shift->_configureColumns('-height', @_) } | ||
| 1355 | sub resizeable { shift->_configureColumns('-resizeable', @_) } | ||
| 1356 | sub selectbackground { shift->_configureColumns('-selectbackground', @_) } | ||
| 1357 | sub selectborderwidth { shift->_configureColumns('-selectborderwidth', @_) } | ||
| 1358 | sub selectforeground { shift->_configureColumns('-selectforeground', @_) } | ||
| 1359 | sub selectmode { shift->_configureColumns('-selectmode', @_) } | ||
| 1360 | sub compound { #JWT: ADDED THIS METHOD TO ALLOW USER TO DYNAMICALLY OVERWRITE WHERE THE SORT ARROW IMAGE DISPLAYS. | ||
| 1361 | my $w = shift; | ||
| 1362 | if (scalar(@_) > 0) { | ||
| 1363 | |||
| 1364 | $w->_configureColumns('-compound', @_); | ||
| 1365 | $w->{'-compound'} = $_[0]; | ||
| 1366 | } else { | ||
| 1367 | return $w->{'-compound'}; | ||
| 1368 | } | ||
| 1369 | } | ||
| 1370 | sub showallsortcolumns { #JWT: ADDED THIS METHOD TO ALLOW USER TO DYNAMICALLY OVERWRITE WHERE THE SORT ARROW IMAGE DISPLAYS. | ||
| 1371 | my $w = shift; if (scalar(@_) > 0) { | ||
| 1372 | |||
| 1373 | $w->{'-showallsortcolumns'} = $_[0]; | ||
| 1374 | } else | ||
| 1375 | |||
| 1376 | { | ||
| 1377 | return $w->{'-showallsortcolumns'}; | ||
| 1378 | } | ||
| 1379 | } | ||
| 1380 | sub columnFocus { #JWT:ALLOW A SPECIFIED COLUMN'S LISTBOX GET FOCUS SO THAT KEYBOARD CURSOR "UNDERSCORE" MAY BECOME (MORE) VISIBLE: | ||
| 1381 | my $w = shift; | ||
| 1382 | |||
| 1383 | if ($w->cget('-nocolumnfocus') != 1 && scalar(@_) > 0) { | ||
| 1384 | $w->{Configure}{'-focuscolumn'} = $_[0] if ($_[0] =~ /\d/o); | ||
| 1385 | } else { | ||
| 1386 | return $w->{Configure}{'-focuscolumn'}; | ||
| 1387 | } | ||
| 1388 | } | ||
| 1389 | sub focusColumn { #JWT:DEPRECIATED:USE columnFocus! | ||
| 1390 | return shift->columnFocus(@_) | ||
| 1391 | } | ||
| 1392 | sub setButtonHeight { #JWT:ALLOW USER TO SET HEIGHT OF BUTTONS (-pady): | ||
| 1393 | my $w = shift; | ||
| 1394 | foreach my $c (@{$w->{'_columns'}}) { | ||
| 1395 | $c->_setButtonHeight(@_); | ||
| 1396 | } | ||
| 1397 | } | ||
| 1398 | sub separatorcolor { shift->_configureColumns('-separatorcolor', @_ ) } | ||
| 1399 | sub separatorwidth { shift->_configureColumns('-separatorwidth', @_ ) } | ||
| 1400 | sub sortable { shift->_configureColumns('-sortable', @_) } | ||
| 1401 | sub textwidth { shift->_configureColumns('-textwidth', @_) } | ||
| 1402 | |||
| 1403 | sub takefocus { | ||
| 1404 | my ($w, $val, $byus) = @_; | ||
| 1405 | return $w->{Configure}{'-takefocus'} unless (defined $val); | ||
| 1406 | |||
| 1407 | #JWT:NEEDS TO BE '' INSTEAD OF 1 FOR Tk (SO WE KEEP IT IN OUR OWN VARIABLE FOR OUR USE)!: | ||
| 1408 | $w->{'_ourtakefocus'} = $val unless (defined $byus); | ||
| 1409 | $w->{Configure}{'-takefocus'} = ($val =~ /0/o) ? 0 : ''; | ||
| 1410 | } | ||
| 1411 | |||
| 1412 | sub width { | ||
| 1413 | my ($w, $v) = @_; | ||
| 1414 | |||
| 1415 | return $w->{Configure}{'-width'} unless defined $v; | ||
| 1416 | if ($v == 0) { | ||
| 1417 | $w->afterIdle(['_setWidth', $w]); | ||
| 1418 | } else { | ||
| 1419 | $w->Subwidget('pane')->configure(-width => $v); | ||
| 1420 | } | ||
| 1421 | } | ||
| 1422 | |||
| 1423 | ###################################################################### | ||
| 1424 | ## Private methods (Do not depend on these methods being present) | ||
| 1425 | ## | ||
| 1426 | ## For all methods which have _firstVisible, the method is delegated | ||
| 1427 | ## to the first visible (packed) Listbox | ||
| 1428 | ###################################################################### | ||
| 1429 | |||
| 1430 | ## This is the main callback that is bound to the subwidgets | ||
| 1431 | ## when using any of the public bind methods, The defined | ||
| 1432 | ## defined callback ($cb) is called from within it | ||
| 1433 | |||
| 1434 | sub _bindCallback { | ||
| 1435 | my ($w, $cb, $sw, $ci, $yCoord) = @_; | ||
| 1436 | |||
| 1437 | my $iHR = { '-subwidget' => $sw, '-column' => $ci }; | ||
| 1438 | if (defined($yCoord)) { | ||
| 1439 | $iHR->{'-row'} = $w->_getEntryFromY($sw, $yCoord); | ||
| 1440 | } | ||
| 1441 | if (ref $cb eq 'ARRAY') { | ||
| 1442 | my ($code,@args) = @$cb; | ||
| 1443 | return $w->$code($iHR, @args); | ||
| 1444 | } else { | ||
| 1445 | return $w->$cb($iHR); | ||
| 1446 | } | ||
| 1447 | } | ||
| 1448 | |||
| 1449 | ## bind subwidgets is used by other public bind methods to | ||
| 1450 | ## apply a callback to an event sequence of a particular subwidget | ||
| 1451 | ## within each of the columns. Any defined callbacks are passed | ||
| 1452 | ## to the _bindCallback which is actually the callback that gets | ||
| 1453 | ## bound. | ||
| 1454 | |||
| 1455 | sub _bindSubwidgets { | ||
| 1456 | my ($w,$subwidget,$sequence,$callback) = @_; | ||
| 1457 | my $col = 0; | ||
| 1458 | |||
| 1459 | return (keys %{$w->{'_bindings'}->{$subwidget}}) | ||
| 1460 | unless (defined $sequence); | ||
| 1461 | |||
| 1462 | unless (defined $callback) { | ||
| 1463 | $callback = $w->{'_bindings'}->{$subwidget}->{$sequence}; | ||
| 1464 | $callback = '' unless defined $callback; | ||
| 1465 | return $callback; | ||
| 1466 | } | ||
| 1467 | |||
| 1468 | if ($callback eq '') { | ||
| 1469 | foreach (@{$w->{'_columns'}}) { | ||
| 1470 | $_->Subwidget($subwidget)->Tk::bind($sequence,''); | ||
| 1471 | } | ||
| 1472 | delete $w->{'_bindings'}->{$subwidget}->{$sequence}; | ||
| 1473 | return ''; | ||
| 1474 | } | ||
| 1475 | my @args = ('_bindCallback', $callback); | ||
| 1476 | #WARNING: IF THESE ARE BOUND BEFORE THE COLUMNS ARE CREATED, THEN "Ev(*)" DATA IS NOT | ||
| 1477 | #PROPERLY PASSED TO THE CALLBACKS WHEN THE BINDINGS ARE BOUND LATER WHEN THE COLUMNS ARE CREATED!: | ||
| 1478 | foreach (@{$w->{'_columns'}}) { | ||
| 1479 | my $sw = $_->Subwidget($subwidget); | ||
| 1480 | if ($sw->class ne 'SMCListbox') { | ||
| 1481 | $sw->Tk::bind($sequence, [$w => @args, $sw, $col++]); | ||
| 1482 | } else { | ||
| 1483 | $sw->Tk::bind($sequence, [$w => @args, $sw, $col++, Ev('y')]); | ||
| 1484 | } | ||
| 1485 | } | ||
| 1486 | $w->{'_bindings'}->{$subwidget}->{$sequence} = $callback; | ||
| 1487 | return ''; | ||
| 1488 | } | ||
| 1489 | |||
| 1490 | ## handles config options that should be propagated to all SMLColumn | ||
| 1491 | ## subwidgets. Using the DEFAULT setting in ConfigSpecs would be one | ||
| 1492 | ## idea, but the pane subwidget is also a child, and Pane will not | ||
| 1493 | ## be able to handle many of the options being passed to this method. | ||
| 1494 | |||
| 1495 | sub _configureColumns { | ||
| 1496 | my ($w, $option, $value) = @_; | ||
| 1497 | return $w->{Configure}{$option} unless (defined $value); | ||
| 1498 | |||
| 1499 | foreach (@{$w->{'_columns'}}) { | ||
| 1500 | $_->configure("$option" => $value); | ||
| 1501 | } | ||
| 1502 | } | ||
| 1503 | |||
| 1504 | sub _cntrlEnd { shift->_firstVisible->Cntrl_End; } | ||
| 1505 | |||
| 1506 | sub _cntrlHome { shift->_firstVisible->Cntrl_Home; } | ||
| 1507 | |||
| 1508 | sub _chgView { | ||
| 1509 | my ($w, $fn, @args) = @_; | ||
| 1510 | |||
| 1511 | $fn = shift(@args) if ($fn =~ /HASH/o); | ||
| 1512 | my $code = "\$w->$fn('".join("','",@args)."')"; | ||
| 1513 | eval $code; | ||
| 1514 | } | ||
| 1515 | |||
| 1516 | sub _dataExtend { | ||
| 1517 | my ($w, $el) = @_; | ||
| 1518 | my $mode = $w->cget('-selectmode'); | ||
| 1519 | if ($mode eq 'extended') { | ||
| 1520 | $w->activate($el); | ||
| 1521 | $w->see($el); | ||
| 1522 | $w->_firstVisible->Motion($el) if (defined($w->_firstVisible) && $w->selectionIncludes('anchor')); | ||
| 1523 | } elsif ($mode eq 'multiple') { | ||
| 1524 | $w->activate($el); | ||
| 1525 | $w->see($el) | ||
| 1526 | } | ||
| 1527 | } | ||
| 1528 | |||
| 1529 | sub _deselectAll { | ||
| 1530 | my $w = shift; | ||
| 1531 | $w->selectionClear(0, 'end') if ($w->cget('-selectmode') ne 'browse'); | ||
| 1532 | } | ||
| 1533 | |||
| 1534 | ## implements sorting and dragging & drop of a column | ||
| 1535 | sub _dragOrSort { | ||
| 1536 | my ($w, $c, $sortAnyway) = @_; | ||
| 1537 | |||
| 1538 | return if ($w->state() =~ /disable/o); #DON'T ALLOW SORTING OR DRAGGING IF DISABLED! | ||
| 1539 | |||
| 1540 | if (!$w->cget('-moveable') || (defined($sortAnyway) && $sortAnyway)) { | ||
| 1541 | $w->sort(undef, $c) if ($c->cget('-sortable')); | ||
| 1542 | return; | ||
| 1543 | } | ||
| 1544 | |||
| 1545 | my $h=$c->Subwidget("heading"); # The heading button of the column. | ||
| 1546 | |||
| 1547 | my $start_mouse_x = $h->pointerx; | ||
| 1548 | my $y_pos = $h->rooty; # This is constant through the whole operation. | ||
| 1549 | my $width = $h->width; | ||
| 1550 | my $left_limit = $w->rootx - 1; | ||
| 1551 | |||
| 1552 | # Find the rightmost, visible column | ||
| 1553 | my $right_end = 0; | ||
| 1554 | foreach (@{$w->{'_columns'}}) { | ||
| 1555 | if ($_->rootx + $_->width > $right_end) { | ||
| 1556 | $right_end = $_->rootx + $_->width; | ||
| 1557 | } | ||
| 1558 | } | ||
| 1559 | my $right_limit = $right_end + 1; | ||
| 1560 | |||
| 1561 | # Create a "copy" of the heading button, put it in a toplevel that matches | ||
| 1562 | # the size of the button, put the toplevel on top of the button. | ||
| 1563 | my $tl=$w->Toplevel; | ||
| 1564 | $tl->overrideredirect(1); | ||
| 1565 | $tl->geometry(sprintf("%dx%d+%d+%d", | ||
| 1566 | $h->width, $h->height, $h->rootx, $y_pos)); | ||
| 1567 | |||
| 1568 | my $b=$tl->SMHButton | ||
| 1569 | (map{defined($_->[4]) ? ($_->[0]=>$_->[4]) : ()} $h->configure) | ||
| 1570 | ->pack(-expand=>1,-fill=>'both'); | ||
| 1571 | |||
| 1572 | # Move the toplevel with the mouse (as long as Button-1 is down). | ||
| 1573 | $h->bind("<Motion>", sub { | ||
| 1574 | my $new_x = $h->rootx - ($start_mouse_x - $h->pointerx); | ||
| 1575 | unless ($new_x + $width/2 < $left_limit || | ||
| 1576 | $new_x + $width/2 > $right_limit) | ||
| 1577 | { | ||
| 1578 | $tl->geometry(sprintf("+%d+%d",$new_x,$y_pos)); | ||
| 1579 | } | ||
| 1580 | }); | ||
| 1581 | |||
| 1582 | $h->bind("<ButtonRelease-1>", sub { | ||
| 1583 | my $rootx; | ||
| 1584 | eval {$rootx = $tl->rootx;}; | ||
| 1585 | return unless (defined $rootx); #ASSUME WE'RE DISABLED. | ||
| 1586 | |||
| 1587 | my $x = $rootx + ($tl->width/2); | ||
| 1588 | $tl->destroy; # Don't need this anymore... | ||
| 1589 | $h->bind("<Motion>",''); # Cancel binding | ||
| 1590 | |||
| 1591 | if ($h->rootx == $rootx) { | ||
| 1592 | # Button NOT moved, sort the column.... | ||
| 1593 | if ($c->cget('-sortable')) { | ||
| 1594 | $w->sort(undef, $c); | ||
| 1595 | } | ||
| 1596 | return; | ||
| 1597 | } | ||
| 1598 | |||
| 1599 | # Button moved..... | ||
| 1600 | # Decide where to put the column. If the center of the dragged | ||
| 1601 | # button is on the left half of another heading, insert it -before | ||
| 1602 | # the column, otherwise insert it -after the column. | ||
| 1603 | foreach (@{$w->{'_columns'}}) { | ||
| 1604 | if ($_->ismapped) { | ||
| 1605 | my $left = $_->rootx; | ||
| 1606 | my $right = $left + $_->width; | ||
| 1607 | if ($left <= $x && $x <= $right) { | ||
| 1608 | if ($x - $left < $right - $x) { | ||
| 1609 | $w->columnShow($c,-before=>$_); | ||
| 1610 | } else { | ||
| 1611 | $w->columnShow($c,'-after'=>$_); | ||
| 1612 | } | ||
| 1613 | $w->update; | ||
| 1614 | $w->Callback(-configurecommand => $w); | ||
| 1615 | } | ||
| 1616 | } | ||
| 1617 | } | ||
| 1618 | }); | ||
| 1619 | } | ||
| 1620 | |||
| 1621 | sub _extendUpDown { | ||
| 1622 | my ($w, $amount) = @_; | ||
| 1623 | return if ($w->cget('-selectmode') ne 'extended'); | ||
| 1624 | $w->activate($w->index('active')+$amount); | ||
| 1625 | $w->see('active'); | ||
| 1626 | $w->_motion($w->index('active')) | ||
| 1627 | } | ||
| 1628 | |||
| 1629 | ## Many of the methods in this package are very similar in that they | ||
| 1630 | ## delagate calls to the SMLColumn widgets. Because widgets can be | ||
| 1631 | ## be moved around (repacked) and hidden (packForget), any | ||
| 1632 | ## one widget may not be the "best" to be delegating calls to. The | ||
| 1633 | ## _columns variable holds an array of the columns but the order of | ||
| 1634 | ## this array does not correspond to the order in which they might | ||
| 1635 | ## by displayed, therefore this method is used to return the first | ||
| 1636 | ## "visible" or packed SMLColumn. RCS Note: It might be reasonable to | ||
| 1637 | ## make this a public method as it could conceivably useful to someone | ||
| 1638 | ## who might want to subclass this widget or use their own bindings. | ||
| 1639 | sub _firstVisible { | ||
| 1640 | my $w = shift; | ||
| 1641 | foreach my $c (@{$w->{'_columns'}}) { | ||
| 1642 | return $c if $c->ismapped; | ||
| 1643 | } | ||
| 1644 | return $w->{'_columns'}->[0]; | ||
| 1645 | } | ||
| 1646 | |||
| 1647 | sub _getEntryFromY { | ||
| 1648 | my ($cw, $sw, $yCoord) = @_; | ||
| 1649 | my $nearest = $sw->nearest($yCoord); | ||
| 1650 | |||
| 1651 | return $nearest if (defined($nearest) && $nearest < ($sw->size() - 1)); | ||
| 1652 | |||
| 1653 | my ($x, $y, $w, $h) = $sw->bbox($nearest); | ||
| 1654 | my $lastY = $y + $h; | ||
| 1655 | return -1 if ($yCoord > $lastY); | ||
| 1656 | return $nearest; | ||
| 1657 | } | ||
| 1658 | |||
| 1659 | ## Used to distribute method calls which would otherwise be called for | ||
| 1660 | ## for one SMCListbox (Within a column), Each SMCListbox is a modified | ||
| 1661 | ## Listbox whose methods end up passing the code and arguments that need | ||
| 1662 | ## to be called to this method where they are invoked for each column | ||
| 1663 | ## It's an interesting, although complex, interaction and it's worth | ||
| 1664 | ## tracing to follow the program flow. | ||
| 1665 | |||
| 1666 | sub _motion { shift->_firstVisible->Motion(@_) } | ||
| 1667 | sub _selectAll { shift->_firstVisible->SelectAll; } | ||
| 1668 | sub _Cancel { shift->_firstVisible->Cancel; } | ||
| 1669 | |||
| 1670 | sub _selectionUpdate { | ||
| 1671 | my ($w, $code, $l, @args) = @_; | ||
| 1672 | |||
| 1673 | if (@args) { | ||
| 1674 | foreach (@{$w->{'_columns'}}) { | ||
| 1675 | &$code($_->Subwidget("listbox"), @args); | ||
| 1676 | } | ||
| 1677 | } else { | ||
| 1678 | # &$code($w->{'_columns'}->[0]->Subwidget("listbox")); | ||
| 1679 | foreach (@{$w->{'_columns'}}) { | ||
| 1680 | &$code($_->Subwidget("listbox")); | ||
| 1681 | } | ||
| 1682 | } | ||
| 1683 | } | ||
| 1684 | |||
| 1685 | ## dynamically sets the width of the widget by calculating | ||
| 1686 | ## the width of each of the currently visible columns. | ||
| 1687 | ## This is generally called during creation time when -width | ||
| 1688 | ## is set to 0. | ||
| 1689 | |||
| 1690 | sub _setWidth { | ||
| 1691 | my ($w) = shift; | ||
| 1692 | my $width = 0; | ||
| 1693 | foreach my $c (@{$w->{'_columns'}}) { | ||
| 1694 | my $lw = $c->Subwidget('heading')->reqwidth; | ||
| 1695 | my $sw = $c->Subwidget('separator')->reqwidth; | ||
| 1696 | $width += ($lw + $sw); | ||
| 1697 | } | ||
| 1698 | $w->Subwidget('pane')->configure(-width => $width); | ||
| 1699 | } | ||
| 1700 | |||
| 1701 | |||
| 1702 | |||
| 1703 | sub _upDown { shift->_firstVisible->UpDown(@_) } | ||
| 1704 | |||
| 1705 | sub _ctrlupDown #JWT:TAKE ADVANTAGE OF PERSONAL LISTBOX HACK TO ALLOW MULTIPLE SELECTIONS IN "BROWSE" MODE VIA KEYBOARD (Ctrl-Up, Ctrl-Down, and Spacebar): | ||
| 1706 | { | ||
| 1707 | my $w = shift; | ||
| 1708 | if (defined($w->{Configure}{'-jwtlistboxhack'}) && $w->{Configure}{'-jwtlistboxhack'} == 1) { | ||
| 1709 | no warnings; | ||
| 1710 | eval { $w->_firstVisible->Tk::Listbox::CtrlUpDown(@_); }; | ||
| 1711 | use warnings; | ||
| 1712 | } else { | ||
| 1713 | $w->_firstVisible->UpDown(@_); | ||
| 1714 | } | ||
| 1715 | } | ||
| 1716 | |||
| 1717 | sub _yscrollCallback { | ||
| 1718 | my ($w, $top, $bottom) = @_; | ||
| 1719 | |||
| 1720 | return unless ($w->cget(-yscrollcommand)); | ||
| 1721 | |||
| 1722 | unless (defined($top)) { | ||
| 1723 | # Called internally | ||
| 1724 | my $c = $w->_firstVisible; | ||
| 1725 | if (Tk::Exists($c) && $c->ismapped) { | ||
| 1726 | ($top,$bottom) = $c->yview; | ||
| 1727 | } else { | ||
| 1728 | ($top,$bottom) = (0,1); | ||
| 1729 | } | ||
| 1730 | } | ||
| 1731 | |||
| 1732 | if ($top != $w->{'_top'} || $bottom != $w->{'_bottom'}) { | ||
| 1733 | $w->Callback(-yscrollcommand=>$top,$bottom); | ||
| 1734 | $w->{'_top'} = $top; | ||
| 1735 | $w->{'_bottom'} = $bottom; | ||
| 1736 | } | ||
| 1737 | } | ||
| 1738 | |||
| 1739 | ###################################################################### | ||
| 1740 | ## Exported (Public) methods (listed alphabetically) | ||
| 1741 | ###################################################################### | ||
| 1742 | |||
| 1743 | ## Activate a row | ||
| 1744 | sub activate { shift->_firstVisible->activate(@_)} | ||
| 1745 | |||
| 1746 | sub focus | ||
| 1747 | { | ||
| 1748 | my $w = shift; | ||
| 1749 | |||
| 1750 | $w->Tk::focus; | ||
| 1751 | $w->{'_hasfocus'} = 1; | ||
| 1752 | my $c = (defined($w->{Configure}{'-focuscolumn'}) && $w->{Configure}{'-focuscolumn'} >= 0) | ||
| 1753 | ? $w->columnGet($w->{Configure}{'-focuscolumn'}) #User specified which one to get focus. | ||
| 1754 | : $w->_firstVisible; | ||
| 1755 | #Default to 1st one visible if user did not pick one. | ||
| 1756 | if (defined($c) && $w->cget('-nocolumnfocus') != 1) { | ||
| 1757 | $c->Subwidget("listbox")->focus(@_); | ||
| 1758 | $c->Subwidget("listbox")->bind('<<LeftTab>>', sub { | ||
| 1759 | $w->focusPrev; | ||
| 1760 | $w->focusCurrent->focusPrev; | ||
| 1761 | Tk->break; | ||
| 1762 | }); | ||
| 1763 | } | ||
| 1764 | } | ||
| 1765 | |||
| 1766 | sub unfocus | ||
| 1767 | { | ||
| 1768 | shift->{'_hasfocus'} = 0; | ||
| 1769 | } | ||
| 1770 | |||
| 1771 | sub bindColumns { shift->_bindSubwidgets('heading',@_) } | ||
| 1772 | sub bindRows { shift->_bindSubwidgets('listbox',@_) } | ||
| 1773 | sub bindSeparators { shift->_bindSubwidgets('separator',@_) } | ||
| 1774 | |||
| 1775 | sub columnConfigure { | ||
| 1776 | my ($w, $index, %args) = @_; | ||
| 1777 | $w->columnGet($index)->configure(%args); | ||
| 1778 | } | ||
| 1779 | |||
| 1780 | ## Delete a column. | ||
| 1781 | sub columnDelete { | ||
| 1782 | my ($w, $first, $last) = @_; | ||
| 1783 | |||
| 1784 | $last ||= $first; #JWT:ADDED 20150429 | ||
| 1785 | for (my $i=$w->columnIndex($first); $i<=$w->columnIndex($last); $i++) { | ||
| 1786 | eval { $w->columnGet($i)->destroy; }; | ||
| 1787 | } | ||
| 1788 | @{$w->{'_columns'}} = map{Exists($_) ? $_ : ()} @{$w->{'_columns'}}; | ||
| 1789 | } | ||
| 1790 | |||
| 1791 | sub columnGet { | ||
| 1792 | my ($w, $from, $to) = @_; | ||
| 1793 | if (defined($to)) { | ||
| 1794 | $from= $w->columnIndex($from); | ||
| 1795 | $to = $w->columnIndex($to); | ||
| 1796 | return @{$w->{'_columns'}}[$from..$to]; | ||
| 1797 | } else { | ||
| 1798 | return $w->{'_columns'}->[$w->columnIndex($from)]; | ||
| 1799 | } | ||
| 1800 | } | ||
| 1801 | |||
| 1802 | sub columnHide { | ||
| 1803 | my ($w, $first, $last) = @_; | ||
| 1804 | $last = $first unless defined $last; | ||
| 1805 | |||
| 1806 | for (my $i=$w->columnIndex($first); $i<=$w->columnIndex($last); $i++) { | ||
| 1807 | eval { $w->columnGet($i)->packForget; }; | ||
| 1808 | } | ||
| 1809 | } | ||
| 1810 | |||
| 1811 | ## Converts a column index to a numeric index. $index might be a number, | ||
| 1812 | ## 'end' or a reference to a SMLColumn widget (see columnGet). Note that | ||
| 1813 | ## the index return by this method may not match up with it's current | ||
| 1814 | ## visual location due to columns being moved around | ||
| 1815 | |||
| 1816 | sub columnIndex { | ||
| 1817 | my ($w, $index, $after_end) = @_; | ||
| 1818 | |||
| 1819 | if ($index eq 'end') { | ||
| 1820 | if (defined $after_end) { | ||
| 1821 | return $#{$w->{'_columns'}} + 1; | ||
| 1822 | } else { | ||
| 1823 | return $#{$w->{'_columns'}}; | ||
| 1824 | } | ||
| 1825 | } | ||
| 1826 | |||
| 1827 | if (ref($index) eq "Tk::SMListbox::SMLColumn") { | ||
| 1828 | foreach (0..$#{$w->{'_columns'}}) { | ||
| 1829 | if ($index eq $w->{'_columns'}->[$_]) { | ||
| 1830 | return $_; | ||
| 1831 | } | ||
| 1832 | } | ||
| 1833 | } | ||
| 1834 | |||
| 1835 | if ($index =~ m/^\s*(\d+)\s*$/o) { | ||
| 1836 | return $1; | ||
| 1837 | } | ||
| 1838 | croak "Invalid column index: $index\n"; | ||
| 1839 | } | ||
| 1840 | |||
| 1841 | ## JWT:Bind "underlined" Alt-<letter> keys in column headers to sort function (as if header button pressed) to SMListbox widget (when it has focus) | ||
| 1842 | |||
| 1843 | sub _headerAltBindit { | ||
| 1844 | my ($x, $w, $c, $idx) = @_; | ||
| 1845 | |||
| 1846 | $w->_dragOrSort($c, 1); | ||
| 1847 | $x->break; | ||
| 1848 | } | ||
| 1849 | |||
| 1850 | ## JWT:Bind "underlined" Alt-<letter> keys in column headers to sort function (as if header button pressed) to all column Listbox widgets (when it has focus using JWT's hack) | ||
| 1851 | |||
| 1852 | sub _headerAltBinditAll { | ||
| 1853 | my ($x, $w) = @_; | ||
| 1854 | my $mykey = $x->XEvent->A; | ||
| 1855 | foreach my $c (@{$w->{'_columns'}}) { | ||
| 1856 | if (defined($c->{'sorthotkey'}) && $c->{'sorthotkey'} eq $mykey) { | ||
| 1857 | $w->_dragOrSort($c, 1); | ||
| 1858 | } | ||
| 1859 | } | ||
| 1860 | $x->break; | ||
| 1861 | } | ||
| 1862 | |||
| 1863 | ## Insert a column. $index should be a number or 'end'. | ||
| 1864 | |||
| 1865 | sub columnInsert { | ||
| 1866 | my ($w, $index, %args) = @_; | ||
| 1867 | |||
| 1868 | $index = $w->columnIndex($index,1); | ||
| 1869 | my %opts = (); | ||
| 1870 | |||
| 1871 | ## Copy these options from the megawidget. | ||
| 1872 | foreach (qw/-background -foreground -headerbackground -headerforeground -font -height | ||
| 1873 | -resizeable -selectbackground -selectforeground -disabledforeground | ||
| 1874 | -selectborderwidth -selectmode -separatorcolor | ||
| 1875 | -separatorwidth -sortable -textwidth -reversearrow -state/) | ||
| 1876 | { | ||
| 1877 | $opts{$_} = $w->cget($_) if defined $w->cget($_); | ||
| 1878 | } | ||
| 1879 | ## All options (and more) might be overridden by %args. | ||
| 1880 | map {$opts{$_} = $args{$_}} keys %args; | ||
| 1881 | |||
| 1882 | ## JWT:See if column header contains "~" indicating a "hot-character (next letter) to use as a keyboard binding for sorting the column using the keyboard!: | ||
| 1883 | my $hotchar; if (defined($opts{'-text'}) && $opts{'-text'} =~ s/^([^\~]*)\~(\w)/$1$2/o) { | ||
| 1884 | |||
| 1885 | $hotchar = $2; | ||
| 1886 | $opts{'-underline'} = length($1); #Cause the hotkey to be underlined in the column header button. | ||
| 1887 | } | ||
| 1888 | my $c = $w->Subwidget("pane")->SMLColumn(%opts, #Create the new column: | ||
| 1889 | -yscrollcommand => [ $w => '_yscrollCallback'], | ||
| 1890 | -configurecommand => [ $w => 'Callback', '-configurecommand', $w], | ||
| 1891 | -xscancommand => [ $w => 'xscan' ], | ||
| 1892 | -updatecommand => [ $w => '_selectionUpdate'] | ||
| 1893 | ); | ||
| 1894 | unless ($index || defined $w->{Configure}{'-jwtlistboxhack'} || $w->cget('-nocolumnfocus') == 1) { #JWT:If 1st column (now that we've created a listbox), see if we're using JWT's HACKED listbox: | ||
| 1895 | no warnings; | ||
| 1896 | eval { $c->Subwidget("listbox")->Tk::Listbox::CtrlUpDown(0); }; | ||
| 1897 | use warnings; | ||
| 1898 | $w->{Configure}{'-jwtlistboxhack'} = $@ ? 0 : 1; #eval succeeds if using JWT's hacked listbox! | ||
| 1899 | } | ||
| 1900 | $c->{'__SMListbox__'} = $w; #JWT:SAVE ME FOR FUTURE REFERENCES. | ||
| 1901 | ## RCS: Review this later - questionable implementation | ||
| 1902 | ## Fill the new column with empty values, making sure all columns have | ||
| 1903 | ## the same number of rows. | ||
| 1904 | unless (scalar(@{$w->{'_columns'}}) == 0) { | ||
| 1905 | foreach (1..$w->size) { | ||
| 1906 | $c->insert('end',''); | ||
| 1907 | } | ||
| 1908 | } | ||
| 1909 | $c->Subwidget("heading")->bind("<ButtonPress-1>", [ $w => '_dragOrSort', $c]); | ||
| 1910 | $c->Subwidget("heading")->configure(-compound => $w->{'-compound'}) if ($w->{'-compound'}); | ||
| 1911 | my @bindTags = $w->bindtags; | ||
| 1912 | if (defined($hotchar) && $hotchar =~ /\S/o) { #JWT:Set up Alt-<hotkey> bindings if we have a hotkey character defined: | ||
| 1913 | |||
| 1914 | $hotchar =~ tr/A-Z/a-z/; | ||
| 1915 | $c->{'sorthotkey'} = $hotchar; | ||
| 1916 | $w->bind($bindTags[1], "<Alt-$hotchar>", [\&_headerAltBindit, $w, $c, $index]); | ||
| 1917 | $c->Subwidget("listbox")->Tk::Listbox::bind("<Alt-Key>", [\&_headerAltBinditAll, $w, $c, $index]); | ||
| 1918 | } | ||
| 1919 | |||
| 1920 | my $carr = $w->{'_columns'}; | ||
| 1921 | splice(@$carr,$index,0,$c); | ||
| 1922 | |||
| 1923 | ## Update the selection to also include the new column. | ||
| 1924 | map {$w->selectionSet($_, $_)} $w->curselection | ||
| 1925 | if $w->curselection; | ||
| 1926 | |||
| 1927 | ## Copy all bindings that are created by calls to | ||
| 1928 | ## bindRows, bindColumns and/or bindSeparators. | ||
| 1929 | ## RCS: check this out, on the next pass | ||
| 1930 | foreach my $subwidget (qw/listbox heading separator/) { | ||
| 1931 | foreach (keys %{$w->{'_bindings'}->{$subwidget}}) { | ||
| 1932 | $c->Subwidget($subwidget)->Tk::bind($_, | ||
| 1933 | [ | ||
| 1934 | $w => '_bindCallback', | ||
| 1935 | $w->{'_bindings'}->{$subwidget}->{$_}, | ||
| 1936 | $index | ||
| 1937 | ] | ||
| 1938 | ); | ||
| 1939 | } | ||
| 1940 | } | ||
| 1941 | |||
| 1942 | if (Tk::Exists($w->{'_columns'}->[$index+1])) { | ||
| 1943 | $w->columnShow($index, -before=>$index+1); | ||
| 1944 | } else { | ||
| 1945 | $w->columnShow($index); | ||
| 1946 | } | ||
| 1947 | return $c; | ||
| 1948 | } | ||
| 1949 | |||
| 1950 | sub columnPack { | ||
| 1951 | my ($w, @packinfo) = @_; | ||
| 1952 | $w->columnHide(0,'end'); | ||
| 1953 | foreach (@packinfo) { | ||
| 1954 | my ($index, $width) = split /:/o; | ||
| 1955 | $w->columnShow ($index); | ||
| 1956 | if (defined($width) && $width =~ /^\d+$/o) { | ||
| 1957 | $w->columnGet($index)->setWidth($width) | ||
| 1958 | } | ||
| 1959 | } | ||
| 1960 | } | ||
| 1961 | |||
| 1962 | sub columnPackInfo { | ||
| 1963 | my ($w) = @_; | ||
| 1964 | |||
| 1965 | ## Widget needs to have an update call first, otherwise | ||
| 1966 | ## the method will not return anything if called prior to | ||
| 1967 | ## MainLoop - RCS | ||
| 1968 | |||
| 1969 | $w->update; | ||
| 1970 | map {$w->columnIndex($_) . ':' . $_->width} | ||
| 1971 | sort {$a->rootx <=> $b->rootx} | ||
| 1972 | map {$_->ismapped ? $_ : ()} @{$w->{'_columns'}}; | ||
| 1973 | } | ||
| 1974 | |||
| 1975 | sub columnShow { | ||
| 1976 | my ($w, $index, %args) = @_; | ||
| 1977 | |||
| 1978 | my $numericIndex = $w->columnIndex($index); | ||
| 1979 | my $c = $w->columnGet($index); | ||
| 1980 | my @packopts = ($numericIndex == $w->{Configure}{'-fillcolumn'}) | ||
| 1981 | ? (-anchor=>'w',-side=>'left',-fill=>'both',-expand=>1) | ||
| 1982 | : (-anchor=>'w',-side=>'left',-fill=>'both'); | ||
| 1983 | if (defined($args{'-before'})) { | ||
| 1984 | push (@packopts, '-before'=>$w->columnGet($args{'-before'})); | ||
| 1985 | } elsif (defined($args{'-after'})) { | ||
| 1986 | push (@packopts, '-after'=>$w->columnGet($args{'-after'})); | ||
| 1987 | } | ||
| 1988 | eval { $c->pack(@packopts); }; | ||
| 1989 | } | ||
| 1990 | |||
| 1991 | sub curselection { shift->_firstVisible->curselection(@_)} | ||
| 1992 | |||
| 1993 | sub delete { | ||
| 1994 | my $w = shift; | ||
| 1995 | foreach (@{$w->{'_columns'}}) { | ||
| 1996 | my $saved_width = $_->width; | ||
| 1997 | $_->delete(@_); | ||
| 1998 | if ($_->ismapped) { | ||
| 1999 | $_->setWidth($saved_width); | ||
| 2000 | } | ||
| 2001 | } | ||
| 2002 | $w->_yscrollCallback; | ||
| 2003 | } | ||
| 2004 | |||
| 2005 | sub get { | ||
| 2006 | my @result = (); | ||
| 2007 | my ($colnum,$rownum) = (0,0); | ||
| 2008 | |||
| 2009 | foreach (@{shift->{'_columns'}}) { | ||
| 2010 | my @coldata = $_->get(@_); | ||
| 2011 | $rownum = 0; | ||
| 2012 | map {$result[$rownum++][$colnum] = $_} @coldata; | ||
| 2013 | $colnum++; | ||
| 2014 | } | ||
| 2015 | @result; | ||
| 2016 | } | ||
| 2017 | |||
| 2018 | sub getRow { | ||
| 2019 | my @result = map {$_->get(@_)} @{shift->{'_columns'}}; | ||
| 2020 | if (wantarray) { | ||
| 2021 | @result; | ||
| 2022 | } else { | ||
| 2023 | $result[0]; | ||
| 2024 | } | ||
| 2025 | } | ||
| 2026 | |||
| 2027 | sub index { | ||
| 2028 | my $w = shift; | ||
| 2029 | |||
| 2030 | return undef unless (defined($_[0]) && defined($w->_firstVisible)); | ||
| 2031 | return $w->_firstVisible->index(@_) | ||
| 2032 | } | ||
| 2033 | |||
| 2034 | sub insert { #NOTE: UNDERLYING LISTBOXES (UNLIKE HLISTBOXES) WILL *NOT* ACCEPT DATA INSERSIONS IF DISABLED!!! | ||
| 2035 | my ($w, $index, @data) = @_; | ||
| 2036 | my ($rownum, $colnum); | ||
| 2037 | my $rowcnt = $#data; | ||
| 2038 | |||
| 2039 | # Insert data into one column at a time, calling $listbox->insert | ||
| 2040 | # ONCE for each column. (The first version of this widget call insert | ||
| 2041 | # once for each row in each column). | ||
| 2042 | # | ||
| 2043 | foreach $colnum (0..$#{$w->{'_columns'}}) { | ||
| 2044 | my $c = $w->{'_columns'}->[$colnum]; | ||
| 2045 | |||
| 2046 | # The listbox might get resized after insert/delete, which is a | ||
| 2047 | # behaviour we don't like.... | ||
| 2048 | my $saved_width = $c->width; | ||
| 2049 | |||
| 2050 | my @coldata = (); | ||
| 2051 | |||
| 2052 | foreach (0..$#data) { | ||
| 2053 | if (defined($data[$_][$colnum])) { | ||
| 2054 | push @coldata, $data[$_][$colnum]; | ||
| 2055 | } else { | ||
| 2056 | push @coldata, ''; | ||
| 2057 | } | ||
| 2058 | } | ||
| 2059 | $c->insert($index,@coldata); | ||
| 2060 | |||
| 2061 | if ($c->ismapped) { | ||
| 2062 | # Restore saved width. | ||
| 2063 | $c->setWidth($saved_width); | ||
| 2064 | } | ||
| 2065 | } | ||
| 2066 | $w->_yscrollCallback; | ||
| 2067 | } | ||
| 2068 | |||
| 2069 | ## These methods all delegate to the first visible column's | ||
| 2070 | ## Listbox. Refer to Listbox docs and description for _firstVisible | ||
| 2071 | |||
| 2072 | sub nearest { shift->_firstVisible->nearest(@_)} | ||
| 2073 | sub see { shift->_firstVisible->see(@_)} | ||
| 2074 | sub selectionAnchor { shift->_firstVisible->selectionAnchor(@_)} | ||
| 2075 | sub selectionClear { shift->_firstVisible->selectionClear(@_)} | ||
| 2076 | sub selectionIncludes { shift->_firstVisible->selectionIncludes(@_)} | ||
| 2077 | sub selectionSet { shift->_firstVisible->selectionSet(@_)} | ||
| 2078 | sub SpaceSelect { shift->_firstVisible->SpaceSelect(@_)} | ||
| 2079 | sub CtrlPriorNext { shift->_firstVisible->CtrlPriorNext(@_)} | ||
| 2080 | sub size { shift->_firstVisible->size(@_)} | ||
| 2081 | |||
| 2082 | sub sort { | ||
| 2083 | my ($w, $descending, @indexes) = @_; | ||
| 2084 | |||
| 2085 | #my @l = @{$w->{'_sortcolumns'}}; #JWT:CHGD. TO NEXT 20150429 TO PREVENT STRAY ARROWS: | ||
| 2086 | my @l = (0..$#{$w->{'_columns'}}); | ||
| 2087 | foreach my $i (@l) { | ||
| 2088 | $w->{'_columns'}->[$i]->Subwidget("heading")->configure(-bitmap => 'noarrow'); | ||
| 2089 | } | ||
| 2090 | |||
| 2091 | # Hack to avoid problem with older Tk versions which do not support | ||
| 2092 | # the -recurse=>1 option. | ||
| 2093 | $w->Busy; # This works always (but not very good...) | ||
| 2094 | Tk::catch {$w->Busy(-recurse=>1)};# This works on newer Tk versions, | ||
| 2095 | # harmless on old versions. | ||
| 2096 | |||
| 2097 | @indexes = (0..$#{$w->{'_columns'}}) unless @indexes; | ||
| 2098 | |||
| 2099 | # Convert all indexes to integers. | ||
| 2100 | map {$_=$w->columnIndex($_)} @indexes; | ||
| 2101 | # This works on Solaris, but not on Linux??? | ||
| 2102 | # Store the -comparecommand for each row in a local array. In the sort, | ||
| 2103 | # the store command is called directly in stead of via the SMLColumn | ||
| 2104 | # subwidget. This saves a lot of callbacks and function calls. | ||
| 2105 | # | ||
| 2106 | # my @cmp_subs = map {$_->cget(-comparecommand)} @{$w->{'_columns'}}; | ||
| 2107 | |||
| 2108 | # If sort order is not defined | ||
| 2109 | unless (defined $descending) { | ||
| 2110 | if ($#indexes == 0 && | ||
| 2111 | $w->{'_sortcol'} == $indexes[0] && | ||
| 2112 | $w->{'_sort_descending'} == 0) | ||
| 2113 | { | ||
| 2114 | # Already sorted on this column, reverse sort order. | ||
| 2115 | $descending = 1; | ||
| 2116 | } else { | ||
| 2117 | $descending = 0; | ||
| 2118 | } | ||
| 2119 | } | ||
| 2120 | |||
| 2121 | # To retain the selection after the sort we have to save information | ||
| 2122 | # about the current selection before the sort. Adds a dummy column | ||
| 2123 | # to the two dimensional data array, this last column will be true | ||
| 2124 | # for all rows that are currently selected. | ||
| 2125 | my $dummy_column = scalar(@{$w->{'_columns'}}); | ||
| 2126 | |||
| 2127 | my $wasActive = $w->index('active'); | ||
| 2128 | my @data = $w->get(0,'end'); | ||
| 2129 | foreach ($w->curselection) { | ||
| 2130 | $data[$_]->[$dummy_column] = 1; # Selected... | ||
| 2131 | } | ||
| 2132 | $data[$wasActive]->[$dummy_column] += 2 if (defined($wasActive) && $wasActive >= 0); | ||
| 2133 | |||
| 2134 | @data = sort { | ||
| 2135 | local $^W = 0; | ||
| 2136 | foreach (@indexes) { | ||
| 2137 | my $res = do { | ||
| 2138 | if ($descending) { | ||
| 2139 | # Call via cmp_subs works fine on Solaris, but no | ||
| 2140 | # on Linux. The column->compare method is much slower... | ||
| 2141 | # | ||
| 2142 | # &{$cmp_subs[$_]} ($b->[$_],$a->[$_]); | ||
| 2143 | $w->{'_columns'}->[$_]->compare($b->[$_],$a->[$_]); | ||
| 2144 | } else { | ||
| 2145 | # &{$cmp_subs[$_]} ($a->[$_],$b->[$_]); | ||
| 2146 | $w->{'_columns'}->[$_]->compare($a->[$_],$b->[$_]); | ||
| 2147 | } | ||
| 2148 | }; | ||
| 2149 | return $res if $res; | ||
| 2150 | } | ||
| 2151 | return 0; | ||
| 2152 | } @data; | ||
| 2153 | |||
| 2154 | # Replace data with the new, sorted list. | ||
| 2155 | $w->delete(0,'end'); | ||
| 2156 | $w->insert('end',@data); | ||
| 2157 | |||
| 2158 | my @new_selection = (); | ||
| 2159 | foreach (0..$#data) { | ||
| 2160 | if (defined $data[$_]->[$dummy_column]) { | ||
| 2161 | $w->selectionSet($_,$_) if ($data[$_]->[$dummy_column] % 2); | ||
| 2162 | $w->activate($_) if ($data[$_]->[$dummy_column] > 1); | ||
| 2163 | } | ||
| 2164 | } | ||
| 2165 | |||
| 2166 | $w->{'_sortcol'} = $indexes[0]; | ||
| 2167 | @{$w->{'_sortcolumns'}} = @indexes; | ||
| 2168 | $w->{'_sort_descending'} = $descending; | ||
| 2169 | |||
| 2170 | $w->Unbusy; #(-recurse=>1); | ||
| 2171 | if ($w->{'-showallsortcolumns'}) { | ||
| 2172 | for (my $i=0;$i<=$#indexes;$i++) { #UNCOMMENT TO SHOW ALL SORTED COLUMNS: | ||
| 2173 | # $w->{'_columns'}->[$indexes[$i]]->Subwidget("heading")->configure(-bitmap => ($w->{'_sort_descending'} ? 'downarrow' : 'uparrow')); | ||
| 2174 | if ($w->{'_columns'}->[$indexes[$i]]->cget('-reversearrow') == 1) { | ||
| 2175 | $w->{'_columns'}->[$indexes[$i]]->Subwidget("heading")->configure(-bitmap => ($w->{'_sort_descending'} ? 'uparrow' : 'downarrow')); | ||
| 2176 | } else { | ||
| 2177 | $w->{'_columns'}->[$indexes[$i]]->Subwidget("heading")->configure(-bitmap => ($w->{'_sort_descending'} ? 'downarrow' : 'uparrow')); | ||
| 2178 | } | ||
| 2179 | } | ||
| 2180 | } else { | ||
| 2181 | # $w->{'_columns'}->[$indexes[0]]->Subwidget("heading")->configure(-bitmap => ($w->{'_sort_descending'} ? 'downarrow' : 'uparrow')); | ||
| 2182 | if ($w->{'_columns'}->[$indexes[0]]->cget('-reversearrow') == 1) { | ||
| 2183 | $w->{'_columns'}->[$indexes[0]]->Subwidget("heading")->configure(-bitmap => ($w->{'_sort_descending'} ? 'uparrow' : 'downarrow')); | ||
| 2184 | } else { | ||
| 2185 | $w->{'_columns'}->[$indexes[0]]->Subwidget("heading")->configure(-bitmap => ($w->{'_sort_descending'} ? 'downarrow' : 'uparrow')); | ||
| 2186 | } | ||
| 2187 | } | ||
| 2188 | } | ||
| 2189 | |||
| 2190 | sub state { | ||
| 2191 | my ($w, $val) = @_; | ||
| 2192 | |||
| 2193 | return $w->{Configure}{'-state'} || undef unless (defined($val) && $val); | ||
| 2194 | return if (defined($w->{'_prevstate'}) && $val eq $w->{'_prevstate'}); #DON'T DO TWICE IN A ROW! | ||
| 2195 | |||
| 2196 | $w->{'_statechg'} = 1; | ||
| 2197 | if ($val =~ /d/o) { #WE'RE DISABLING (SAVE CURRENT ENABLED STATUS STUFF, THEN DISABLE USER-INTERACTION): | ||
| 2198 | #? $w->{Configure}{'-state'} = 'normal'; | ||
| 2199 | $w->{'_saveactive'} = $w->index('active') || 0; | ||
| 2200 | $w->{'_foreground'} = $w->cget('-foreground'); #SAVE CURRENT (ENABLED) FG COLOR! | ||
| 2201 | $w->{Configure}{'-state'} = $val; | ||
| 2202 | foreach my $i (0..$#{$w->{'_columns'}}) { | ||
| 2203 | $w->{'_columns'}->[$i]->state($val); | ||
| 2204 | } | ||
| 2205 | #? $w->activate($w->{'_saveactive'}) unless ($w->{'_hasfocus'}); | ||
| 2206 | $w->takefocus(0, 1); | ||
| 2207 | $w->focusNext if ($w->{'_hasfocus'}); #MOVE FOCUS OFF WIDGET IF IT HAS IT. | ||
| 2208 | #NOTE: THIS DIFFERS FROM Tk::Listbox BEHAVIOUR, AS Tk::Listbox WILL STILL TAKE FOCUS IN THE | ||
| 2209 | #TAB-CIRCULATE ORDER EVEN IF DISABLED, IF -takefocus IS SET TO 1!: | ||
| 2210 | } elsif ($w->{'_prevstate'}) { #WE'RE ENABLING (RESTORE PREV. ENABLED STUFF AND REALLOW USER-INTERACTION): | ||
| 2211 | my $fg = $w->{'_foreground'}; | ||
| 2212 | $w->{Configure}{'-state'} = $val; | ||
| 2213 | foreach my $i (0..$#{$w->{'_columns'}}) { | ||
| 2214 | $w->{'_columns'}->[$i]->state($val); | ||
| 2215 | } | ||
| 2216 | if (defined $w->_firstVisible) { #RESTORE SELECTED LIST AND ACTIVE CURSOR: | ||
| 2217 | my @selected = $w->_firstVisible->curselection; | ||
| 2218 | $w->selectionSet(shift @selected) while (@selected); | ||
| 2219 | $w->activate($w->{'_saveactive'}); | ||
| 2220 | } | ||
| 2221 | $w->takefocus($w->{'_ourtakefocus'}, 1); | ||
| 2222 | } | ||
| 2223 | $w->{'_prevstate'} = $w->{Configure}{'-state'}; | ||
| 2224 | $w->{'_statechg'} = 0; | ||
| 2225 | } | ||
| 2226 | |||
| 2227 | # Implements horizontal scanning. | ||
| 2228 | sub xscan { | ||
| 2229 | my ($w, $type, $x) = @_; | ||
| 2230 | |||
| 2231 | if ($type eq 'dragto') { | ||
| 2232 | my $dist = $w->{'_scanmark_x'} - $w->pointerx; | ||
| 2233 | |||
| 2234 | # Looks like there is a bug in Pane: If no -xscrollcommand | ||
| 2235 | # is defined, xview() fails. This is fixed by this hack: | ||
| 2236 | # | ||
| 2237 | my $p = $w->Subwidget("pane"); | ||
| 2238 | unless (defined ($p->cget(-xscrollcommand))) { | ||
| 2239 | $p->configure(-xscrollcommand => sub {}); | ||
| 2240 | } | ||
| 2241 | $p->xview('scroll',$dist,'units'); | ||
| 2242 | } | ||
| 2243 | $w->{'_scanmark_x'} = $w->pointerx; | ||
| 2244 | } | ||
| 2245 | |||
| 2246 | sub xview { shift->Subwidget("pane")->xview(@_) } | ||
| 2247 | sub yview { shift->_firstVisible->yview(@_)} | ||
| 2248 | |||
| 2249 | 1 | ||
| 2250 | |||
| 2251 | __END__ |