| 1 | # | ||
| 2 | # Tk::JBrowseEntry is an enhanced version of the Tk::BrowseEntry widget. | ||
| 3 | |||
| 4 | =head1 NAME | ||
| 5 | |||
| 6 | Tk::JBrowseEntry - Full-featured "Combo-box" (Text-entry combined with | ||
| 7 | drop-down listbox) derived from Tk::BrowseEntry with many additional features | ||
| 8 | and options. | ||
| 9 | |||
| 10 | =head1 SYNOPSIS | ||
| 11 | |||
| 12 | use Tk; | ||
| 13 | use Tk::JBrowseEntry; | ||
| 14 | |||
| 15 | my $mw = MainWindow->new; | ||
| 16 | my $var; | ||
| 17 | |||
| 18 | my $widget = $mw->JBrowseEntry( | ||
| 19 | -label => 'Normal:', | ||
| 20 | -variable => \$var, | ||
| 21 | -state => 'normal', | ||
| 22 | -choices => [qw(pigs cows foxes goats)], | ||
| 23 | -width => 12 | ||
| 24 | )->pack( | ||
| 25 | -side => 'top', | ||
| 26 | -pady => '10', | ||
| 27 | -anchor => 'w'); | ||
| 28 | |||
| 29 | MainLoop; | ||
| 30 | |||
| 31 | =head1 DESCRIPTION | ||
| 32 | |||
| 33 | Tk::JBrowseEntry is a derived widget from Tk::BrowseEntry, but adds numerous | ||
| 34 | features and options. Among them are hash lists (one set of values is | ||
| 35 | displayed for the user, but another is used as data), ability to disable | ||
| 36 | either the text entry widget or the listbox, ability to allow user to delete | ||
| 37 | items from the list, additional keyboard bindings, ability to have the | ||
| 38 | drop-down list "fixed" (always displayed, ability to use Tk::HListbox, ie. to | ||
| 39 | include thumbnail icons in the list), customized key bindings and behaviour, | ||
| 40 | and much more! | ||
| 41 | |||
| 42 | JBrowseEntry widgets allow one to specify a full combo-box, a "readonly" | ||
| 43 | box (text field allows user to type the 1st letter of an item to search for, | ||
| 44 | but user may only ultimately select one of the items in the list); a "textonly" | ||
| 45 | version (drop-down list and list pattern-matching disabled); a "text" version | ||
| 46 | (drop-down list disabled), but the up, down, and right arrows will still do | ||
| 47 | text-completion by matching against the choices in the list; or a completely | ||
| 48 | disabled widget. | ||
| 49 | |||
| 50 | This widget is similar to other combo-boxes, ie. JComboBox, but has better | ||
| 51 | keyboard bindings and allows for quick lookup/search within the listbox. | ||
| 52 | pressing <RETURN> in entry field displays the drop-down box with the | ||
| 53 | first entry most closly matching whatever's in the entry field highlighted. | ||
| 54 | Pressing <RETURN> or <SPACE> in the listbox | ||
| 55 | selects the highlighted entry and copies it to the text field and removes the | ||
| 56 | listbox. <ESC> removes the listbox from view. | ||
| 57 | <UP> and <DOWN> arrows work the listbox as well as pressing a key, which will | ||
| 58 | move the highlight to the next item starting with that letter/number, etc. | ||
| 59 | <UP> and <DOWN> arrows pressed within the entry field circle through the | ||
| 60 | various list options as well (unless "-state" is set to 'textonly'). | ||
| 61 | Set "-state" to "text" to disable the drop-down list, but allow <UP> and | ||
| 62 | <DOWN> to cycle among the choices. Setting "-state" to 'textonly' completely | ||
| 63 | hides the choices list from the user - he must type in his choice just like | ||
| 64 | a normal entry widget. | ||
| 65 | |||
| 66 | One may also specify whether or not the button which activates the | ||
| 67 | drop-down list via the mouse can take focus or not (-btntakesfocus) or | ||
| 68 | whether the widget itself can take focus or is skipped in the focusing | ||
| 69 | order. The developer can also specify alternate bitmap images for the | ||
| 70 | button (-arrowimage and / or -farrowimage). The developer can also specify the | ||
| 71 | maximum length of the drop-down list such that if more than that number of | ||
| 72 | items is added, a vertical scrollbar is automatically added (-height). | ||
| 73 | A fixed width in characters (-width) can be specified, or the widget can be | ||
| 74 | allowed to resize itself to the width of the longest string in the list. The | ||
| 75 | listbox and text entry field are automatically kept to the same width. | ||
| 76 | |||
| 77 | One can optionally specify a label (-label), similar to the "LabEntry" widget. | ||
| 78 | By default, the label appears packed to the left of the widget. The | ||
| 79 | positioning can be specified via the "-labelPack" option. For example, to | ||
| 80 | position the label above the widget, use "-labelPack => [-side => 'top']". | ||
| 81 | |||
| 82 | =head1 EXAMPLES | ||
| 83 | |||
| 84 | It is easiest to illustrate this widget's capabilities via examples: | ||
| 85 | |||
| 86 | use Tk; | ||
| 87 | use Tk::JBrowseEntry; | ||
| 88 | |||
| 89 | $MainWin = MainWindow->new; | ||
| 90 | |||
| 91 | #SET UP SOME DEFAULT VALUES. | ||
| 92 | |||
| 93 | $dbname1 = 'cows'; | ||
| 94 | $dbname2 = 'foxes'; | ||
| 95 | $dbname3 = 'goats'; | ||
| 96 | $dbname5 = 'default'; | ||
| 97 | |||
| 98 | #HERE'S A NORMAL COMBO-BOX. | ||
| 99 | |||
| 100 | $jb1 = $MainWin->JBrowseEntry( | ||
| 101 | -label => 'Normal:', | ||
| 102 | -variable => \$dbname1, | ||
| 103 | -state => 'normal', | ||
| 104 | -choices => [qw(pigs cows foxes goats)], | ||
| 105 | -width => 12); | ||
| 106 | $jb1->pack( | ||
| 107 | -side => 'top', -pady => '10', -anchor => 'w'); | ||
| 108 | |||
| 109 | #THIS ONE HAS THE DROP-DOWN LIST DISABLED. | ||
| 110 | |||
| 111 | $jb2 = $MainWin->JBrowseEntry( | ||
| 112 | -label => 'TextOnly:', | ||
| 113 | -variable => \$dbname2, | ||
| 114 | -state => 'text', | ||
| 115 | -choices => [qw(pigs cows foxes goats)], | ||
| 116 | -width => 12); | ||
| 117 | $jb2->pack( | ||
| 118 | -side => 'top', -pady => '10', -anchor => 'w'); | ||
| 119 | |||
| 120 | #THIS ONE'S "READONLY" (USER MUST PICK FROM THE LIST, TEXT BOX ALLOWS QUICK | ||
| 121 | #SEARCH. | ||
| 122 | |||
| 123 | $jb3 = $MainWin->JBrowseEntry( | ||
| 124 | -label => 'ReadOnly:', | ||
| 125 | -variable => \$dbname3, | ||
| 126 | -choices => [qw(pigs cows foxes goats)], | ||
| 127 | -state => 'readonly', | ||
| 128 | -width => 12); | ||
| 129 | $jb3->pack( | ||
| 130 | -side => 'top', -pady => '10', -anchor => 'w'); | ||
| 131 | |||
| 132 | #THIS ONE'S COMPLETELY DISABLED! | ||
| 133 | |||
| 134 | $jb4 = $MainWin->JBrowseEntry( | ||
| 135 | -label => 'Disabled:', | ||
| 136 | -variable => \$dbname3, | ||
| 137 | -state => 'disabled', | ||
| 138 | -choices => [qw(pigs cows foxes goats)], | ||
| 139 | -width => 12); | ||
| 140 | $jb4->pack( | ||
| 141 | -side => 'top', -pady => '10', -anchor => 'w'); | ||
| 142 | |||
| 143 | #HERE'S ONE WITH A SCROLLBAR (NOTE THE "-height" ATTRIBUTE). | ||
| 144 | |||
| 145 | $jb5 = $MainWin->JBrowseEntry( | ||
| 146 | -label => 'Scrolled List:', | ||
| 147 | -width => 12, | ||
| 148 | -default => $dbname5, | ||
| 149 | -height => 4, | ||
| 150 | -variable => \$dbname5, | ||
| 151 | -browsecmd => sub {print "-browsecmd!\n";}, | ||
| 152 | -listcmd => sub {print "-listcmd!\n";}, | ||
| 153 | -state => 'normal', | ||
| 154 | -choices => [qw(pigs cows foxes goats horses sheep dogs cats ardvarks default)]); | ||
| 155 | $jb5->pack( | ||
| 156 | -side => 'top', -pady => '10', -anchor => 'w'); | ||
| 157 | |||
| 158 | #HERE'S ONE THAT THE BUTTON TAKES KEYBOARD FOCUS. | ||
| 159 | |||
| 160 | $jb6 = $MainWin->JBrowseEntry( | ||
| 161 | -label => 'Button Focus:', | ||
| 162 | -btntakesfocus => 1, | ||
| 163 | -arrowimage => $MainWin->Getimage('balArrow'), #SPECIFY A DIFFERENT BUTTON IMAGE. | ||
| 164 | -farrowimage => $MainWin->Getimage('cbxarrow'), #OPTIONAL 2ND IMAGE FOR BUTTON WHEN FOCUSED. | ||
| 165 | -width => 12, | ||
| 166 | -height => 4, | ||
| 167 | -variable => \$dbname6, | ||
| 168 | -browsecmd => sub {print "-browsecmd!\n";}, | ||
| 169 | -listcmd => sub {print "-listcmd!\n";}, | ||
| 170 | -state => 'normal', | ||
| 171 | -choices => [qw(pigs cows foxes goats horses sheep dogs cats ardvarks default)]); | ||
| 172 | $jb6->pack( | ||
| 173 | -side => 'top', -pady => '10', -anchor => 'w'); | ||
| 174 | |||
| 175 | #HERE'S ONE THAT DOWS NOT TAKE KEYBOARD FOCUS. | ||
| 176 | |||
| 177 | $jb7 = $MainWin->JBrowseEntry( | ||
| 178 | -label => 'Skip Focus:', | ||
| 179 | -takefocus => 0, | ||
| 180 | -width => 12, | ||
| 181 | -height => 4, | ||
| 182 | -variable => \$dbname7, | ||
| 183 | -browsecmd => sub {print "-browsecmd!\n";}, | ||
| 184 | -listcmd => sub {print "-listcmd!\n";}, | ||
| 185 | -state => 'normal', | ||
| 186 | -choices => [qw(pigs cows foxes goats horses sheep dogs cats ardvarks default)]); | ||
| 187 | $jb7->pack( | ||
| 188 | -side => 'top', -pady => '10', -anchor => 'w'); | ||
| 189 | |||
| 190 | $jb7->choices([qw(First Second Fifth Sixth)]); #REPLACE LIST CHOICES! | ||
| 191 | $jb7->insert(2, 'Third', 'Fourth'); #ADD MORE AFTER 1ST 2. | ||
| 192 | $jb7->insert('end', [qw(Seventh Oops Eighth)]); #ADD STILL MORE AT END. | ||
| 193 | $jb7->delete(7); #REMOVE ONE. | ||
| 194 | |||
| 195 | $b = $MainWin->Button(-text => 'Quit', -command => sub {exit(); }); | ||
| 196 | $b->pack(-side => 'top'); | ||
| 197 | $jb1->focus; #PICK ONE TO START WITH KEYBOARD FOCUS. | ||
| 198 | |||
| 199 | MainLoop; | ||
| 200 | |||
| 201 | =head1 SEE ALSO | ||
| 202 | |||
| 203 | L<Tk::BrowseEntry> L<Tk::HListbox> L<Tk::Listbox> L<Tk::JComboBox> L<Tk::Entry> | ||
| 204 | |||
| 205 | =head1 WIDGET-SPECIFIC OPTIONS | ||
| 206 | |||
| 207 | =over 4 | ||
| 208 | |||
| 209 | =item B<-state> => I<'normal' | 'readonly' | 'text' | 'textonly' | 'disabled'> | ||
| 210 | |||
| 211 | Default: B<'normal'> | ||
| 212 | |||
| 213 | JBrowseEntry supports 5 different states: | ||
| 214 | |||
| 215 | =over 4 | ||
| 216 | |||
| 217 | I<normal>: Default operation -- Both text entry field and drop-down list | ||
| 218 | button function normally. | ||
| 219 | |||
| 220 | I<readonly>: Drop-down list functions normally. When text entry field has | ||
| 221 | focus, user may type in a letter, and the drop-down list immediately drops | ||
| 222 | down and the first/ next matching item becomes highlighted. The user must | ||
| 223 | ultimately select from the list of valid entries and may not enter | ||
| 224 | anything else. | ||
| 225 | |||
| 226 | I<text>: Text entry functions normally, but drop-down list button is disabled. | ||
| 227 | User must type in an entry or use the up and down arrows to choose from among | ||
| 228 | the list items. | ||
| 229 | |||
| 230 | I<textonly>: Similar to "text": Text entry functions normally, but drop-down | ||
| 231 | list button is disabled. User must type in an entry. The list choices are | ||
| 232 | completely hidden from the user. | ||
| 233 | |||
| 234 | I<disabled>: Widget is completely disabled and greyed out. It will not | ||
| 235 | activate or take focus. | ||
| 236 | |||
| 237 | =back | ||
| 238 | |||
| 239 | =item B<-altbinding> | ||
| 240 | |||
| 241 | Allows one to specify alternate binding schema for certain keys. Each binding | ||
| 242 | pair may be separated by a comma, semicolon, colon, space, or virtical bar. | ||
| 243 | Case is insensitive. Currently valid values are: | ||
| 244 | |||
| 245 | "Return=Go" - causes [Return] key to roll up the drop-down list and invoke the | ||
| 246 | I<-browsecmd> callback, if any. | ||
| 247 | |||
| 248 | "Return=NonEmptyGo" - same as "Return=Go" if the text field is non-empty, | ||
| 249 | otherwises pops up the drop-down list. | ||
| 250 | |||
| 251 | "Return=SingleGo" - same as "Return=Go" if there are no choices in the | ||
| 252 | drop-down list (instead of popping up the drop-down list). | ||
| 253 | |||
| 254 | "Return=Next" - causes pressing the [Return] key to advance the focus to the | ||
| 255 | next widget in the main window. | ||
| 256 | |||
| 257 | "Right=NoSearch" - Do not complete the text in the text field with the next | ||
| 258 | matching value found in the | ||
| 259 | choices list when the [Right-arrow] key is pressed in the entry field, rather | ||
| 260 | leave it unchanged. | ||
| 261 | |||
| 262 | "Down=Popup" - causes the [Down-arrow] key pressed in the entry field to pop | ||
| 263 | up the selection listbox. | ||
| 264 | Useful particularly if the [arrow-button] isn't displayed, | ||
| 265 | ie. (I<-nobutton> => 1) and/or the [Return] key is bound with an | ||
| 266 | I<-altbinding>, etc. to do something other than pop up the drop-down list. | ||
| 267 | |||
| 268 | "List=Bouncy" - causes the drop-down list to behave more like a popup menu | ||
| 269 | and immediately roll back up (after matching text with nearest entry) if the | ||
| 270 | mouse button is pressed and released on the drop-down list button. | ||
| 271 | (Normally, the drop-down list state is simply toggled when mouse is pressed | ||
| 272 | and released on the button.) | ||
| 273 | |||
| 274 | "Nolistbox=actions" - causes certain I<actions> to NOT invoke the | ||
| 275 | I<-browsecmd> callback when activated within the listbox widget, | ||
| 276 | ie. "Nolistbox=listbox.space" means don't invoke I<-browsecmd> callback if | ||
| 277 | <spacebar> pressed in the listbox. Valid values are | ||
| 278 | ([listbox.]{space|return|button1|*button1|mod[.{shift|Control|alt|*}-]button1}: | ||
| 279 | "space,button1,return,mod.Shift-button1,mod.Control-button1,mod.Alt-button1,mod,*button1", | ||
| 280 | etc. Multiple values can be separated by commas. "mod" means any modifier | ||
| 281 | (Shift|Control|Alt), "*button1" means button1 regardless of modifier. | ||
| 282 | |||
| 283 | "Tab=KeepList" - Normally, if the [Tab] key is pressed while the drop-down | ||
| 284 | list is displayed and focused, the drop-down list is removed from view | ||
| 285 | (rolled up) and the focus simply returns to the text entry field. | ||
| 286 | |||
| 287 | Specifying "Tab=KeepList" (on Unixish systems) makes Tk::JBrowseEntry keep the | ||
| 288 | drop-down list displayed while returning the focus back to the text field | ||
| 289 | when either tabbing off of the listbox or selecting an entry via the | ||
| 290 | I<spacebar> key. To roll the listbox back up (unless I<-fixedlist> is | ||
| 291 | specified), simply press the Enter or Tab key, or click on the entry-field. | ||
| 292 | |||
| 293 | "Tab=Popup" - Normally, if the [Tab] key is pressed while the text-entry field | ||
| 294 | is displayed and focused, the focus advances to the next widget. | ||
| 295 | |||
| 296 | Specifying "Tab=Popup" will cause the listbox to be popped up and receive the | ||
| 297 | focus. Either way, the listbox is undisplayed anyway when the JBrowseEntry | ||
| 298 | widget itself goes out of focus, or either the [Enter] or [Esc] key is pressed. | ||
| 299 | If the drop-down list is a "fixed" list (I<-fixedlist> is specified), then the | ||
| 300 | list always remains in view and only the focus changes and this setting | ||
| 301 | is ignored. This setting is also ignored on M$-Windows platforms, which is | ||
| 302 | beyond our control. | ||
| 303 | |||
| 304 | "Down=None", "Up=None", "Right=None", "Esc=None", "Return=None", "Space=None" | ||
| 305 | - causes pressing that respective key to NOT perform it's default | ||
| 306 | binding action. User can still add their own bindings within their calling | ||
| 307 | program though. | ||
| 308 | |||
| 309 | =item B<-arrowimage> | ||
| 310 | |||
| 311 | Allows one to specify an alternate image for the the button which activates | ||
| 312 | the drop-down list when the button has the keyboard focus. The default is: | ||
| 313 | $MainWin->Getimage('cbxarrow') on Linux and a custom bitmap on M$-Windows. | ||
| 314 | Also see the "-farrowimage" option below, as well as the "-arrowimage" | ||
| 315 | option under Standard BrowseEntry options for more details. On Linux, this | ||
| 316 | is used regardless of the focus status of the button, which is indicated by | ||
| 317 | the border, unless a "-farrowimage" image is specified. On M$-Windows, a | ||
| 318 | separate custom bitmap is provided for the focused version, since Windows does | ||
| 319 | not change the border color when the button takes focus. | ||
| 320 | |||
| 321 | =item B<-browse> | ||
| 322 | |||
| 323 | Adds several additional triggering events which invoke the B<-browsecmd> | ||
| 324 | callback: entry.tab, frame.tab, and key.<character-typed>, if set to 1. | ||
| 325 | Default is 0. This likely is rarely needed in practice, but allows the | ||
| 326 | calling program to know whenever a key is typed into the entry field or if the | ||
| 327 | field is tabbed away from. The one case the author uses this option on is the | ||
| 328 | "drive-letter" field in the M$-Windows version of his Tk::JFileDialog widget. | ||
| 329 | |||
| 330 | =item B<-browsecmd> | ||
| 331 | |||
| 332 | Specifies a callback function to call when a selection is made in the popped | ||
| 333 | up listbox. This function is called after the entry variable has been | ||
| 334 | assigned the value, (so the programmer can validate and override the user's | ||
| 335 | entry if desired). | ||
| 336 | |||
| 337 | The function is passed the widget reference itself (self), the content of the | ||
| 338 | entry field (not necessarily equal to the B<-variable> reference value), and | ||
| 339 | the triggering "event" as described below. | ||
| 340 | |||
| 341 | Specific cases (events) where it is invoked: | ||
| 342 | entry.[-mod.{Shift|Control|Alt}]return[.{go|browse}], listbox.return, | ||
| 343 | listbox.space, or listbox.[-mod.{Shift|Control|Alt}]button1. | ||
| 344 | If B<-browse> is set to 1, then additional triggering events are: | ||
| 345 | entry.tab, frame.tab, and key.<character-typed>. | ||
| 346 | |||
| 347 | =item B<-btntakesfocus> | ||
| 348 | |||
| 349 | The drop-down list button is normally activated with the mouse and is skipped | ||
| 350 | in the focusing circuit. If this option is set, then the button will take | ||
| 351 | keyboard focus. Pressing <Return>, <Spacebar>, or <Downarrow> will cause the | ||
| 352 | list to be dropped down, repeating causes the list to be removed again. | ||
| 353 | Normally, the text entry widget receives the keyboard focus. This option can | ||
| 354 | be used in combination with "-takefocus" so that either the text entry widget, | ||
| 355 | the button, or both or neither receive keyboard focus. If both options are set, | ||
| 356 | the entry field first receives focus, then pressing <Tab> causes the button | ||
| 357 | to be focused. | ||
| 358 | |||
| 359 | =item B<-buttonbackground> | ||
| 360 | |||
| 361 | Specify alternate background for the drop-down list button. | ||
| 362 | |||
| 363 | =item B<-buttonforeground> | ||
| 364 | |||
| 365 | Specify alternate foreground for the drop-down list button. | ||
| 366 | |||
| 367 | =item B<-colorstate> | ||
| 368 | |||
| 369 | Archaic carryover from Tk::BrowseEntry -- Appears to force the background of | ||
| 370 | the text-entry widget to I<"lightgray"> if set to I<"1"> and state is | ||
| 371 | I<readonly> or I<disabled>, and no B<-background> color has been set; and a | ||
| 372 | slightly darker shade of gray (I<"gray95 ">) otherwise. We also set the | ||
| 373 | foreground color to I<gray30> for I<readonly> or I<disabled> states and | ||
| 374 | I<black> otherwise to ensure that the text remains readable regardless of what | ||
| 375 | foreground color is otherwise set. I've also added special value of I<"2"> | ||
| 376 | (or I<"dark">) to set a darker version of the readonly and disabled colors. | ||
| 377 | To only make one or the other use the "darker" shades, one can instead | ||
| 378 | specify I<"readonlydark"> or I<"disableddark">. NOTE: Once the widget has | ||
| 379 | been set to a "readonly" state, the I<"-textreadonlybackground"> color remains | ||
| 380 | fixed thru future calls to setPalette! This seems to be a limitation of Tk | ||
| 381 | and setPalette. Also note that in general, changing the widget's | ||
| 382 | I<-foreground> and / or I<-background> options later via "$widget->configure() | ||
| 383 | may not completely change all the colors of every part of every subwidget, | ||
| 384 | and setPalette may not completely correct everything until the widget's | ||
| 385 | I<-state> is changed, therefore, it's a good idea to also call | ||
| 386 | $w->state($w->state()); after dynamically changing foreground or background | ||
| 387 | colors for the widget. | ||
| 388 | |||
| 389 | =item B<-default> | ||
| 390 | |||
| 391 | (string) - If set, it becomes the default value, ie. if the user presses | ||
| 392 | the Esc (escape) key inside the text box (pressing Esc a second time blanks | ||
| 393 | out the field unless I<-state == 'readonly'>). It's recommended to set this | ||
| 394 | to either the I<-variable> variable (the variable itself, not it's reference) | ||
| 395 | or to a string representing one of the values in the dropdown listbox, to | ||
| 396 | avoid possibly confusing users. | ||
| 397 | |||
| 398 | NOTE: The initial value set in the text field will be whatever's in the | ||
| 399 | I<-variable>, NOT the I<-default> value unless I<-variable> is not defined! | ||
| 400 | If neither option is defined, the initial value will be empty string (''). | ||
| 401 | |||
| 402 | =item B<-deleteitemsok> | ||
| 403 | |||
| 404 | If set, allows user to delete individual items in the drop-down list by | ||
| 405 | pressing the <Delete> key to delete the current (active) item. No effect if | ||
| 406 | the state is "text" or "textonly". | ||
| 407 | |||
| 408 | =item B<-deletecmd> | ||
| 409 | |||
| 410 | (ADDED v4.9): Specifies a callback function to call when the user deletes an | ||
| 411 | entry (if B<-deleteitemsok> is set to true) in the popped up listbox. It is | ||
| 412 | passed the widget and either the index of the entry being deleted OR -1. This | ||
| 413 | function is called BOTH before AND after the entry is deleted. The entry | ||
| 414 | parameter is -1 on the second call, and the first call if $_[1] (the index to | ||
| 415 | be deleted) >= 0, the function should return false/undef to permit the delete | ||
| 416 | or true to SUPPRESS the delete (in which case, the callback will NOT be called | ||
| 417 | a second time)! No effect if the state is "text" or "textonly". | ||
| 418 | |||
| 419 | =item B<-farrowimage> | ||
| 420 | |||
| 421 | Allows one to specify a second, alternate bitmap for the image on the button | ||
| 422 | which activates the drop-down list when the button has the keyboard focus. | ||
| 423 | The default is to use the "-arrowimage" image, EXCEPT in M$-Windows, in which | ||
| 424 | case, the default remains the default "focused" bitmap, since Windows does not | ||
| 425 | use a focus border, but rather, the image itself must change to indicate | ||
| 426 | focus status. See the "-arrowimage" option under Standard BrowseEntry options | ||
| 427 | for more details. The default image for Linux is: | ||
| 428 | $MainWin->Getimage('cbxarrow') and a custom bitmap for M$-Windows. | ||
| 429 | |||
| 430 | =item B<-fixedlist> | ||
| 431 | |||
| 432 | Normally the drop-down list pops up and down when requested, rolling up | ||
| 433 | (hiding) when not. Setting this option to a true value will cause the | ||
| 434 | drop-down list to be a fixed listbox widget packed below the rest of the | ||
| 435 | widget. Specifying B<-fixedlist> => I<"top"> will instead display the | ||
| 436 | listbox I<above> the rest of the widget. | ||
| 437 | |||
| 438 | Default: B<0> (false) - drop-down list is not fixed (pre-v5.10 behavior). | ||
| 439 | |||
| 440 | NOTE: A list can be set to both "fixed" (I<-fixedlist> => ...) and "bouncy" | ||
| 441 | (I<-altbinding> => <'list=bouncy'>) at the same time. This will ensure that | ||
| 442 | the focus always jumps right back to the text field whenever the user | ||
| 443 | selects an entry from the list. Otherwise, "fixed" lists alternate | ||
| 444 | focus between the list and the entry field when the user clicks on | ||
| 445 | the list to select a value, as if the list is alternating between | ||
| 446 | "popped down" and "popped up" - this is not considered a bug, but a feature. | ||
| 447 | |||
| 448 | =item B<-indicator> | ||
| 449 | |||
| 450 | Only used if B<-listboxtype> is set to HListbox, otherwise ignored. | ||
| 451 | Specifies whether an indicator image may be included with HListbox entries. | ||
| 452 | |||
| 453 | Default: B<0> (false - no indicator image). | ||
| 454 | |||
| 455 | =item B<-itemtype> | ||
| 456 | |||
| 457 | Only used if B<-listboxtype> is set to HListbox, otherwise ignored. | ||
| 458 | Specifies the type of data permitted for HListbox entries. | ||
| 459 | Valid values are: I<"text">, I<"image">, and I<"imagetext">. | ||
| 460 | |||
| 461 | Default: I<"text">. | ||
| 462 | |||
| 463 | =item B<-label> | ||
| 464 | |||
| 465 | Specify a label to be displayed next to the widget. | ||
| 466 | The default is I<undef> - do not display (or pack) a label next to the widget. | ||
| 467 | If you do not wish to specify a label initially, but plan to set a label | ||
| 468 | later, you should set B<-label> to ''. By default the label is displayed to | ||
| 469 | the left of the widget (as part of it). This can be changed using the | ||
| 470 | B<-labelPack> option. | ||
| 471 | |||
| 472 | =item B<-labelbackground> | ||
| 473 | |||
| 474 | Specify alternate background for the label. | ||
| 475 | |||
| 476 | =item B<-labelforeground> | ||
| 477 | |||
| 478 | Specify alternate foreground for the label. | ||
| 479 | |||
| 480 | =item B<-labelfont> | ||
| 481 | |||
| 482 | Specify alternate font for the label. | ||
| 483 | |||
| 484 | NOTE: To change the font for the text entry field, use B<-font>. See also | ||
| 485 | B<-listfont> below for changing the font of the items in the listbox. | ||
| 486 | |||
| 487 | =item B<-labelPack> | ||
| 488 | |||
| 489 | Specify alternate packing options for the label. The default is: | ||
| 490 | "[-side => 'left', -anchor => 'e']" ("[-side => 'left', -anchor => | ||
| 491 | 'n'|'s', -pady => 1, -ipady => 2] if B<-fixedlist> is set | ||
| 492 | ('s' if 'top', 'n' otherwise)). The argument is an arrayref. | ||
| 493 | Note: if no label is specified, none is packed or displayed, therefore, | ||
| 494 | if you do not wish to specify a label initially, but plan to set a label | ||
| 495 | later, you should set B<-label> to ''. | ||
| 496 | |||
| 497 | =item B<-labelrelief> | ||
| 498 | |||
| 499 | Default: B<"flat"> | ||
| 500 | |||
| 501 | Allow relief of the label portion of the widget to be specified. | ||
| 502 | |||
| 503 | =item B<-listboxtype> | ||
| 504 | |||
| 505 | Specifies tye type of listbox widget to use for the drop-down list. | ||
| 506 | Valid values are I<"Listbox"> and I<"HListbox">. | ||
| 507 | If I<"HListbox"> is specified, you must have Tk::HListbox (v2.1+) installed | ||
| 508 | or the application will fail with an error. | ||
| 509 | |||
| 510 | Default: I<"Listbox"> (Tk::Listbox). | ||
| 511 | |||
| 512 | =item B<-listcmd> | ||
| 513 | |||
| 514 | Specifies a callback function to call when the button next to the entry is | ||
| 515 | pressed to popup the choices in the listbox. This is called before popping up | ||
| 516 | the listbox, so can be used to populate the entries in the listbox. It passes | ||
| 517 | the widget itself, and now also passes in the current value string in the | ||
| 518 | text-entry field (when the list was popped up). | ||
| 519 | |||
| 520 | Default: none (no callback function) | ||
| 521 | |||
| 522 | =item B<-listfont> | ||
| 523 | |||
| 524 | Specify an alternate font for the text in the listbox. | ||
| 525 | |||
| 526 | NOTE: Use B<-font> to change the text of the text entry field. For best | ||
| 527 | results, I<-font> and I<-listfont> should usually specify fonts of | ||
| 528 | similar size. | ||
| 529 | |||
| 530 | =item B<-listrelief> | ||
| 531 | |||
| 532 | Specifies relief for the drop-down list (default is "sunken"). | ||
| 533 | |||
| 534 | =item B<-listwidth> | ||
| 535 | |||
| 536 | Specifies the width of the popup listbox. | ||
| 537 | |||
| 538 | Default: The same width (including any scrollbar) as the text entry | ||
| 539 | field's width. | ||
| 540 | |||
| 541 | =item B<-nobutton> | ||
| 542 | |||
| 543 | Whether or not to display the button that toggles the drop-down list. | ||
| 544 | Set to B<1> (true) to hide. | ||
| 545 | |||
| 546 | Default: B<0> (false - display the button). | ||
| 547 | |||
| 548 | Prevents drop-down list button from being displayed if set to 1 (true). | ||
| 549 | |||
| 550 | =item B<-noselecttext> | ||
| 551 | |||
| 552 | Normally, when the widget has the focus and is set by listbox selection, the | ||
| 553 | text will then be "selected" (highlighted and in the cut-buffer), and will not | ||
| 554 | "appear" to be selected in the drop-down listbox, if visible. Some consider | ||
| 555 | this annoying. Setting this option will cause the text to not be selected, | ||
| 556 | but will still appear selected in the drop-down listbox (if visible). | ||
| 557 | The user can still select the text themself, but either way, the selected | ||
| 558 | item is in the cut buffer. | ||
| 559 | |||
| 560 | =item B<-tabcomplete> | ||
| 561 | |||
| 562 | If set to "1", pressing the "<Tab>" key will cause the string in the entry | ||
| 563 | field to be "auto-completed" to the next matching item in the list. If there | ||
| 564 | is no match, the typed text is not changed. If it already matches a list item, | ||
| 565 | then the listbox is removed from view and keyboard focus transfers to the next | ||
| 566 | widget. If set to "2" and there is no match in the list, then entry is reset | ||
| 567 | to the default value or empty string. If set to "0", focus is simply advanced | ||
| 568 | to the next widget in the main window. In either case, if the text field is | ||
| 569 | changed, focus remains on the text field, otherwise focus advances to next | ||
| 570 | widget, so, after completing, pressing [Tab] again advances to next widget. | ||
| 571 | (NEW in v5.30): If set to 3, then tab-completion will only occur when tabbing | ||
| 572 | off of a focused and visible listbox. | ||
| 573 | |||
| 574 | =item B<-textbackground> | ||
| 575 | |||
| 576 | Specify alternate background for the entry field (when editable). | ||
| 577 | |||
| 578 | =item B<-textforeground> | ||
| 579 | |||
| 580 | Specify alternate foreground for the entry field (when editable). | ||
| 581 | |||
| 582 | =item B<-textdisabledbackground> | ||
| 583 | |||
| 584 | Specify alternate background for the entry field (when I<-state> is disabled). | ||
| 585 | |||
| 586 | =item B<-textdisabledforeground> | ||
| 587 | |||
| 588 | Specify alternate foreground for the entry field (when I<-state> is disabled). | ||
| 589 | |||
| 590 | Default: B<-disabledforeground> or a dark grey. | ||
| 591 | |||
| 592 | =item B<-textreadonlybackground> | ||
| 593 | |||
| 594 | Specify alternate background for the entry field (when I<-state> is readonly). | ||
| 595 | |||
| 596 | =item B<-textreadonlyforeground> | ||
| 597 | |||
| 598 | Specify alternate foreground for the entry field (when I<-state> is readonly). | ||
| 599 | |||
| 600 | Default: a light gray. | ||
| 601 | |||
| 602 | =back | ||
| 603 | |||
| 604 | =head1 INHERITED OPTIONS | ||
| 605 | |||
| 606 | =over 4 | ||
| 607 | |||
| 608 | =item B<-activestyle> | ||
| 609 | |||
| 610 | Specifies the style in which to draw the active element. This must be one of | ||
| 611 | dotbox (show a focus ring around the active element), none (no special | ||
| 612 | indication of active element) or underline (underline the active element). | ||
| 613 | The default is underline. Ignored (not supported) if B<-listboxtype> is set | ||
| 614 | to I<HListbox>, in which case, I<"dotbox"> is always used. | ||
| 615 | |||
| 616 | =item B<-background> | ||
| 617 | |||
| 618 | Specifies the background color for the widget and it's subwidgets. | ||
| 619 | NOTE: In general, changing the widget's | ||
| 620 | I<-foreground> and / or I<-background> options later via "$widget->configure() | ||
| 621 | may not completely change all the colors of every part of every subwidget, | ||
| 622 | and setPalette may not completely correct everything until the widget's | ||
| 623 | I<-state> is changed, therefore, it's a good idea to also call | ||
| 624 | $w->state($w->state()); after dynamically changing foreground or background | ||
| 625 | colors for the widget. | ||
| 626 | |||
| 627 | =item B<-choices> | ||
| 628 | |||
| 629 | Specifies the list of initial choices to pop up. This is a reference to an | ||
| 630 | array or hash of strings specifying the choices. If a I<hashref> is specified, | ||
| 631 | the keys represent the actual data values and the values represent the | ||
| 632 | corresponding values the user sees displayed in the listbox. | ||
| 633 | NOTE: If a I<hashref> is specified, the B<-variable> should be initialized | ||
| 634 | to one of the hash VALUES rather than it's corresponding key. | ||
| 635 | The individual items in the referenced array are normally simple text | ||
| 636 | strings unless B<-listboxtype> is set to I<"HListbox">, in which case, each | ||
| 637 | can be either a simple text string or a hashref to a hash of attributes and | ||
| 638 | values representing a valid Tk::HListbox entry, for example: | ||
| 639 | {-image => $thumbnailimage, -text => 'text string'}. | ||
| 640 | |||
| 641 | =item B<-foreground> | ||
| 642 | |||
| 643 | Specifies the foreground color for the widget and it's subwidgets. | ||
| 644 | |||
| 645 | =item B<-height> | ||
| 646 | |||
| 647 | Specify the maximum number of items (rows) to be displayed in the listbox | ||
| 648 | before a vertical scrollbar is automatically added. Default is infinity | ||
| 649 | (listbox will not be given a scrollbar regardless of the number of | ||
| 650 | items added). | ||
| 651 | |||
| 652 | NOTE: This can overflow below the user's screen, so it is recommended to set | ||
| 653 | this to a sane value to cause a scrollbar to be added automatically if needed, | ||
| 654 | if there are going to be potentially say a dozen or more items. | ||
| 655 | |||
| 656 | =item B<-maxwidth> | ||
| 657 | |||
| 658 | Specifies the maximum width the entry and listbox widgets can expand to in | ||
| 659 | characters. Default is I<0> (zero), meaning expand to the width to accomodate | ||
| 660 | the widest string in the list. (Ignored if B<-width> > 0 (a fixed width) | ||
| 661 | is specified). | ||
| 662 | |||
| 663 | =item B<-textvariable> | ||
| 664 | |||
| 665 | B<Depreciated> - use B<-variable> now. | ||
| 666 | |||
| 667 | =item B<-variable> | ||
| 668 | |||
| 669 | Specifies a scalar reference to the variable in which the entered value is to | ||
| 670 | be stored/retrieved (tied). | ||
| 671 | |||
| 672 | =item B<-width> | ||
| 673 | |||
| 674 | The number of characters (average if proportional font used) wide to make the | ||
| 675 | entry field. The drop-down list will be set the same width as the entry widget | ||
| 676 | plus the width of the button. If not specified, the default is to calculate | ||
| 677 | the width to the width of the longest item in the choices list and if items | ||
| 678 | are later added or removed the width will be recalculated. | ||
| 679 | |||
| 680 | =back | ||
| 681 | |||
| 682 | =head1 WIDGET METHODS | ||
| 683 | |||
| 684 | =over 4 | ||
| 685 | |||
| 686 | =item $widget->B<activate>(index) | ||
| 687 | |||
| 688 | activate() invokes the activate() option on the listbox to make the item with | ||
| 689 | the index specified by the first argument "active". Unless a second argument | ||
| 690 | is passed containing a false value, the value of the "-variable" variable is | ||
| 691 | also set to this now active value. | ||
| 692 | |||
| 693 | =item $widget->B<choices>([listref]) | ||
| 694 | |||
| 695 | Sets the drop-down list listbox to the list of values referenced by I<listref>, | ||
| 696 | if specified. Returns the current list of choices in the listbox if no | ||
| 697 | arguments provided. If a I<hashref> is specified, the keys represent the | ||
| 698 | actual data values and the values represent the corresponding values the user | ||
| 699 | sees displayed in the listbox. NOTE: If a I<hashref> is specified, the | ||
| 700 | B<-variable> should be initialized to one of the hash VALUES rather than it's | ||
| 701 | corresponding key. The individual items in the referenced array are normally | ||
| 702 | simple text strings unless B<-listboxtype> is set to I<"HListbox">, in which | ||
| 703 | case, each can be either a simple text string or a hashref to a hash of | ||
| 704 | attributes and values representing a valid Tk::HListbox entry, for example: | ||
| 705 | {-image => $thumbnailimage, -text => 'text string'}. | ||
| 706 | |||
| 707 | =item $widget->B<curselection>() | ||
| 708 | |||
| 709 | Returns the currently-selected element in the listbox, if any, otherwise, | ||
| 710 | B<undef>. | ||
| 711 | |||
| 712 | =item $widget->B<delete>(first [, last]) | ||
| 713 | |||
| 714 | Deletes one or more elements of the listbox. First and last are indices | ||
| 715 | specifying the first and last elements in the range to delete. If last isn't | ||
| 716 | specified it defaults to first, i.e. a single element is deleted. | ||
| 717 | |||
| 718 | =item $widget->B<delete_byvalue>(hashkey) | ||
| 719 | |||
| 720 | Deletes one or more elements of the listbox. "hashkey" specifies the element | ||
| 721 | to be deleted by the value visible to the user. | ||
| 722 | |||
| 723 | =item $widget->B<reference>(hashkey) | ||
| 724 | |||
| 725 | Returns the value (displayed in the listbox) that corresponds to the choice | ||
| 726 | key specified by "hashkey". If the key is not one of the valid choices or the | ||
| 727 | choices are a list instead of a hash, then the hashkey itself is returned. If | ||
| 728 | the choices are a list rather than a hash, then the value is returned as is. | ||
| 729 | Returns B<undef> on error. | ||
| 730 | |||
| 731 | =item $widget->B<dereference>(hashvalue) | ||
| 732 | |||
| 733 | Returns the actual option key value that corresponds to the choice value | ||
| 734 | displayed in the listbox. (undef if there is none). | ||
| 735 | (Opposite of reference(). Use this function on the -variable reference | ||
| 736 | variable to get the actual data (hash key), since the reference variable will | ||
| 737 | contain the VALUE displayed to the user! If the choices are a list rather | ||
| 738 | than a hash, then the value is returned as is. Returns B<undef> on error. | ||
| 739 | |||
| 740 | =item $widget->B<get_hashref_byname>() | ||
| 741 | |||
| 742 | Returns a reference to the current hash of choices (keyed by the option | ||
| 743 | visable tothe user) if the choice list is a hash (reversed from the hash | ||
| 744 | passed to choices()), otherwise, B<undef> is returned. | ||
| 745 | |||
| 746 | =item $widget->B<get_hashref_byvalue>() | ||
| 747 | |||
| 748 | Returns a reference to the current hash of choices (keyed by actual option | ||
| 749 | value) if the choice list is a hash (same as the hash passed to choices()), | ||
| 750 | otherwise, B<undef> is returned. | ||
| 751 | |||
| 752 | =item $widget->B<get>([first [, last]]) | ||
| 753 | |||
| 754 | get() with no arguments returns the current value of the "-variable" variable. | ||
| 755 | If any arguments are passed, they are passed directly to the listbox->get() | ||
| 756 | function, ie. "0", "end" to return all I<text> values of the listbox. For | ||
| 757 | choice hashes, the value returned is what is displayed to the user. | ||
| 758 | If Tk::HListbox is used, only the I<text> part of the entries are returned. | ||
| 759 | The arguments are indices. | ||
| 760 | |||
| 761 | =item $widget->B<get_icursor>([index]) | ||
| 762 | |||
| 763 | Return the location of I<index> in the I<text-entry> field. Values known to | ||
| 764 | be valid are: "insert" and "end", which return the character position of the | ||
| 765 | insertion cursor and the location of the "end" of the current input string | ||
| 766 | (ie. it's length). The cursor is set by the $widget->B<icursor> function. | ||
| 767 | If no argument (I<index>) is given, the index of the insertion cursor | ||
| 768 | (I<"insert">) is returned. | ||
| 769 | |||
| 770 | =item $widget->B<get_index>(value) | ||
| 771 | |||
| 772 | Returns the index number in the list (zero-based) that can be used by get() of | ||
| 773 | the value specified by "value", or undef if "value" is not in the list of | ||
| 774 | choices. If the choice list is a hash, then "value" should be the value | ||
| 775 | displayed (stored in the -variable reference variable), not the hash key. | ||
| 776 | This function is the reverse of the B<get>() function. | ||
| 777 | |||
| 778 | =item $widget->B<hasreference>(hashkey) | ||
| 779 | |||
| 780 | Returns the value (displayed in the listbox) that corresponds to the choice | ||
| 781 | key specified by "hashkey". If the key is not one of the valid choices or the | ||
| 782 | choices are a list instead of a hash, then B<undef> is returned. | ||
| 783 | |||
| 784 | =item $widget->B<icursor>(index) | ||
| 785 | |||
| 786 | Sets the location of the text-entry field's text cursor to I<index>. | ||
| 787 | Valid values are numeric (zero for beginning) and "end" for placing the cursor | ||
| 788 | at the end of the text. The index can be retrieved by using the | ||
| 789 | $widget->B<get_icursor>(index) function. | ||
| 790 | |||
| 791 | =item $widget->B<index>(index) | ||
| 792 | |||
| 793 | Invokes and returns the result of the listbox->index() function. | ||
| 794 | |||
| 795 | =item $widget->B<insert>(index, [item | list | listref | hashref]) | ||
| 796 | |||
| 797 | Inserts one or more elements in the list just before the element given by | ||
| 798 | index. If I<index> is specified as "end" then the new elements are added to | ||
| 799 | the end of the list. List can be a reference to a list (I<listref>). If a | ||
| 800 | hash reference is specified, then the values are displayed to the user in the | ||
| 801 | drop-down list, but the values returned by the "-variable" variable or the | ||
| 802 | get() function are the corresponding hash key(s). The individual items in the | ||
| 803 | referenced array are normally simple text strings unless B<-listboxtype> is set | ||
| 804 | to I<"HListbox">, in which case, each can be either a simple text string or a | ||
| 805 | hashref to a hash of attributes and values representing a valid Tk::HListbox | ||
| 806 | entry, for example: {-image => $thumbnailimage, -text => 'text string'}. | ||
| 807 | |||
| 808 | =item $widget->B<selectionRange>(index1, index2) | ||
| 809 | |||
| 810 | Select (highlight) the text in the text-entry field between I<index1> and | ||
| 811 | I<index2>. Valid values are numeric (zero for beginning), "insert" and "end". | ||
| 812 | |||
| 813 | =item $widget->B<size>() | ||
| 814 | |||
| 815 | Invokes and returns the result of the listbox size() function (the number of | ||
| 816 | items in the list). | ||
| 817 | |||
| 818 | =item $widget->B<state>([normal | readonly | text | textonly | disabled]) | ||
| 819 | |||
| 820 | Get or set the state of the widget. | ||
| 821 | |||
| 822 | =item $widget->B<Popdown>([nofocusrestore]) | ||
| 823 | |||
| 824 | Roll up (undisplay) the drop-down list. If I<nofocusrestore> is specified and | ||
| 825 | is true, no attempt will be made to refocus the previous widget focused when | ||
| 826 | the drop-down list was popped up. This is useful when the developer intends | ||
| 827 | to immediately focus somewhere else. | ||
| 828 | |||
| 829 | =item $widget->B<PressButton>([nofocussave]) | ||
| 830 | |||
| 831 | Activates drop-down list as if user pressed the button (unless state is "text" | ||
| 832 | or "textonly" or "disabled". Returns 1 if drop-down list activated, zero | ||
| 833 | otherwise. If the drop-down list is already visible, then removes it (pops it | ||
| 834 | back down) and returns zero.Available in versions 5.0 and later. The current | ||
| 835 | keyboard focus is saved for restoration when the drop-down list is rolled up | ||
| 836 | unless I<nofocussave> is specified and is true, in which case, focus will | ||
| 837 | remain with the JBrowseEntry widget whose button was "pressed". | ||
| 838 | |||
| 839 | =back | ||
| 840 | |||
| 841 | =head1 AUTHOR | ||
| 842 | |||
| 843 | Jim Turner, C<< <https://metacpan.org/author/TURNERJW> >>. | ||
| 844 | |||
| 845 | =head1 COPYRIGHT | ||
| 846 | |||
| 847 | Copyright (c) 2001-2018 Jim Turner C<< <mailto:turnerjw784@yahoo.com> >>. | ||
| 848 | All rights reserved. | ||
| 849 | |||
| 850 | This program is free software; you can redistribute | ||
| 851 | it and/or modify it under the same terms as Perl itself. | ||
| 852 | |||
| 853 | This is a derived work from Tk::Listbox and Tk::HList. | ||
| 854 | |||
| 855 | This code may be distributed under the same conditions as Perl itself. | ||
| 856 | |||
| 857 | This is a derived work from Tk::BrowseEntry. Tk::BrowseEntry is | ||
| 858 | copyrighted by Rajappa Iyer | ||
| 859 | |||
| 860 | =head1 LICENSE AND COPYRIGHT | ||
| 861 | |||
| 862 | Copyright 2001-2019 Jim Turner. | ||
| 863 | |||
| 864 | This program is free software; you can redistribute it and/or modify it | ||
| 865 | under the terms of the the Artistic License (2.0). You may obtain a | ||
| 866 | copy of the full license at: | ||
| 867 | |||
| 868 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||
| 869 | |||
| 870 | Any use, modification, and distribution of the Standard or Modified | ||
| 871 | Versions is governed by this Artistic License. By using, modifying or | ||
| 872 | distributing the Package, you accept this license. Do not use, modify, | ||
| 873 | or distribute the Package, if you do not accept this license. | ||
| 874 | |||
| 875 | If your Modified Version has been derived from a Modified Version made | ||
| 876 | by someone other than you, you are nevertheless required to ensure that | ||
| 877 | your Modified Version complies with the requirements of this license. | ||
| 878 | |||
| 879 | This license does not grant you the right to use any trademark, service | ||
| 880 | mark, tradename, or logo of the Copyright Holder. | ||
| 881 | |||
| 882 | This license includes the non-exclusive, worldwide, free-of-charge | ||
| 883 | patent license to make, have made, use, offer to sell, sell, import and | ||
| 884 | otherwise transfer the Package with respect to any patent claims | ||
| 885 | licensable by the Copyright Holder that are necessarily infringed by the | ||
| 886 | Package. If you institute patent litigation (including a cross-claim or | ||
| 887 | counterclaim) against any party alleging that the Package constitutes | ||
| 888 | direct or contributory patent infringement, then this Artistic License | ||
| 889 | to you shall terminate on the date that such litigation is filed. | ||
| 890 | |||
| 891 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||
| 892 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||
| 893 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| 894 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||
| 895 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||
| 896 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||
| 897 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||
| 898 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 899 | |||
| 900 | =cut | ||
| 901 | |||
| 902 | package Tk::JBrowseEntry; | ||
| 903 | |||
| 904 | #BEGIN | ||
| 905 | #{ | ||
| 906 | use vars qw($VERSION $haveHListbox); | ||
| 907 | $VERSION = '5.32'; | ||
| 908 | |||
| 909 | use strict; | ||
| 910 | use warnings; | ||
| 911 | use Carp; | ||
| 912 | use Tk; | ||
| 913 | use Tk::Frame; | ||
| 914 | eval 'use Tk::HListbox; $haveHListbox = ($Tk::HListbox::VERSION >= 2.1) ? 1 : 0; 1'; | ||
| 915 | use base qw(Tk::Frame); | ||
| 916 | #}; | ||
| 917 | |||
| 918 | Construct Tk::Widget 'JBrowseEntry'; | ||
| 919 | |||
| 920 | my ($BITMAP, $FOCUSEDBITMAP); | ||
| 921 | my $bummer = ($^O =~ /MSWin/) ? 1 : 0; | ||
| 922 | |||
| 923 | sub ClassInit | ||
| 924 | { | ||
| 925 | my ($class,$mw) = @_; | ||
| 926 | |||
| 927 | unless(defined($BITMAP)) #THIS TEST ACTUALLY SAVES TIME B/C IT ONLY DOES THIS ONCE IF MULTIPLE JBrowseEntry WIDGETS ARE DEFINED! | ||
| 928 | { | ||
| 929 | #DEFINE OUR VERY OWN DEFAULT BITMAP IMAGES FOR THE LITTLE BUTTON WIDGET (WINDOWS NEEDS DIFFERENT BUTTONS/SIZED!: | ||
| 930 | |||
| 931 | $BITMAP = __PACKAGE__ . "::downarrwow"; | ||
| 932 | |||
| 933 | if ($Tk::platform =~ /Win32/) #FIXME:NOT USING "bummer" HERE SINCE NOT SURE A/B cygwin PLATFORM SINCE THIS IS TK-DEPENDENT! | ||
| 934 | { | ||
| 935 | my $bits = pack("b10"x10, | ||
| 936 | "..........", | ||
| 937 | "..........", | ||
| 938 | "..........", | ||
| 939 | ".#########", | ||
| 940 | "..#######.", | ||
| 941 | "...#####..", | ||
| 942 | "....###...", | ||
| 943 | ".....#....", | ||
| 944 | "..........", | ||
| 945 | ".........." | ||
| 946 | ); | ||
| 947 | $mw->DefineBitmap($BITMAP => 10,10, $bits); | ||
| 948 | } | ||
| 949 | else | ||
| 950 | { | ||
| 951 | my $bits = pack("b11"x11, | ||
| 952 | "....###....", | ||
| 953 | "....###....", | ||
| 954 | "....###....", | ||
| 955 | ".#########.", | ||
| 956 | "..#######..", | ||
| 957 | "...#####...", | ||
| 958 | "....###....", | ||
| 959 | ".....#.....", | ||
| 960 | "...........", | ||
| 961 | ".#########.", | ||
| 962 | ".#########." | ||
| 963 | ); | ||
| 964 | $mw->DefineBitmap($BITMAP => 11,11, $bits); | ||
| 965 | } | ||
| 966 | $FOCUSEDBITMAP = __PACKAGE__ . "::fdownarrow"; | ||
| 967 | |||
| 968 | if ($Tk::platform =~ /Win32/) | ||
| 969 | { | ||
| 970 | my $bits = pack("b10"x10, | ||
| 971 | ".#.#.#.#.#", | ||
| 972 | ".#.......#", | ||
| 973 | "..........", | ||
| 974 | ".#########", | ||
| 975 | "..#######.", | ||
| 976 | ".#.#####.#", | ||
| 977 | "....###...", | ||
| 978 | ".#...#...#", | ||
| 979 | "..........", | ||
| 980 | ".##.#.#.##" | ||
| 981 | ); | ||
| 982 | $mw->DefineBitmap($FOCUSEDBITMAP => 10,10, $bits); | ||
| 983 | } | ||
| 984 | else | ||
| 985 | { | ||
| 986 | my $bits = pack("b11"x11, | ||
| 987 | "....###....", | ||
| 988 | "....###....", | ||
| 989 | "....###....", | ||
| 990 | ".#########.", | ||
| 991 | "..#######..", | ||
| 992 | "...#####...", | ||
| 993 | "....###....", | ||
| 994 | ".....#.....", | ||
| 995 | "...........", | ||
| 996 | ".#########.", | ||
| 997 | ".#########." | ||
| 998 | ); | ||
| 999 | $mw->DefineBitmap($FOCUSEDBITMAP => 11,11, $bits); | ||
| 1000 | } | ||
| 1001 | } | ||
| 1002 | return $class->SUPER::ClassInit($mw); | ||
| 1003 | } | ||
| 1004 | |||
| 1005 | sub SetBindtags { #function added by Jeff Stephens: | ||
| 1006 | my ($self) = @_; | ||
| 1007 | $self->SUPER::SetBindtags; | ||
| 1008 | } | ||
| 1009 | |||
| 1010 | sub Populate | ||
| 1011 | { | ||
| 1012 | my ($w, $args) = @_; | ||
| 1013 | |||
| 1014 | $w->{'btntakesfocus'} = 0; | ||
| 1015 | $w->{'btntakesfocus'} = delete ($args->{'-btntakesfocus'}) if (defined($args->{'-btntakesfocus'})); | ||
| 1016 | $w->{'arrowimage'} = $args->{'-arrowimage'} if (defined($args->{'-arrowimage'})); | ||
| 1017 | $w->{'farrowimage'} = delete ($args->{'-farrowimage'}) if (defined($args->{'-farrowimage'})); | ||
| 1018 | $w->{'farrowimage'} ||= $w->{'arrowimage'} if ($w->{'arrowimage'} && !$bummer); #IN WINDOWS, LEAVE FOCUSED DEFAULT ALONE, OTHERWISE, IF SAME, THERE'S NO FOCUS INDICATOR! | ||
| 1019 | $w->{'mylistcmd'} = $args->{'-listcmd'} if (defined($args->{'-listcmd'})); | ||
| 1020 | $w->{'takefocus'} = 1; | ||
| 1021 | $w->{'takefocus'} = delete ($args->{'-takefocus'}) if (defined($args->{'-takefocus'})); | ||
| 1022 | $w->{'-width'} = $args->{'-width'} if (defined($args->{'-width'})); | ||
| 1023 | $w->{'-height'} = $args->{'-height'} if (defined($args->{'-height'})); | ||
| 1024 | $w->{'-maxwidth'} = delete($args->{'-maxwidth'}) if (defined($args->{'-maxwidth'})); | ||
| 1025 | $w->{'-listwidth'} = $w->{'-width'}; | ||
| 1026 | # $w->{'-foreground'} = $args->{'-foreground'} if (defined($args->{'-foreground'})); | ||
| 1027 | # $w->{'-background'} = $args->{'-background'} if (defined($args->{'-background'})); | ||
| 1028 | # $w->{'-background'} ||= $w->parent->cget('-background'); | ||
| 1029 | my $initFG = defined($args->{'-foreground'}) ? $args->{'-foreground'} : $w->parent->cget('-foreground'); | ||
| 1030 | my $initBG = defined($args->{'-background'}) ? $args->{'-background'} : $w->parent->cget('-background'); | ||
| 1031 | foreach my $i (qw/-textreadonlyforeground/) | ||
| 1032 | { | ||
| 1033 | $w->{$i} = delete($args->{$i}) if (defined($args->{$i})); | ||
| 1034 | } | ||
| 1035 | foreach my $i (qw/-textbackground -textforeground -textdisabledbackground -textdisabledforeground | ||
| 1036 | -textreadonlybackground -labelbackground -labelforeground -buttonbackground -buttonforeground/) | ||
| 1037 | { | ||
| 1038 | $w->{$i} = $args->{$i} if (defined($args->{$i})); | ||
| 1039 | } | ||
| 1040 | # $w->{'-foreground'} = $w->parent->cget('-foreground'); | ||
| 1041 | # $w->{'-borderwidth'} = delete($args->{'-borderwidth'}) if (defined($args->{'-borderwidth'})); #CHGD. TO NEXT 20070904 FROM WOLFRAM HUMANN. | ||
| 1042 | $w->{'-borderwidth'} = defined($args->{'-borderwidth'}) ? delete($args->{'-borderwidth'}) : 2; | ||
| 1043 | $w->{'-relief'} = 'sunken'; | ||
| 1044 | $w->{'-relief'} = delete($args->{'-relief'}) if (defined($args->{'-relief'})); | ||
| 1045 | $w->{'-listrelief'} = 'sunken'; | ||
| 1046 | $w->{'-listrelief'} = delete($args->{'-listrelief'}) if (defined($args->{'-listrelief'})); | ||
| 1047 | $w->{'-listfont'} = delete($args->{'-listfont'}) if (defined($args->{'-listfont'})); | ||
| 1048 | $w->{'-labelfont'} = delete($args->{'-labelfont'}) if (defined($args->{'-labelfont'})); | ||
| 1049 | $w->{'-noselecttext'} = delete($args->{'-noselecttext'}) if (defined($args->{'-noselecttext'})); | ||
| 1050 | $w->{'-browse'} = 0; | ||
| 1051 | $w->{'-browse'} = delete($args->{'-browse'}) if (defined($args->{'-browse'})); | ||
| 1052 | $w->{'-tabcomplete'} = 0; | ||
| 1053 | $w->{'-tabcomplete'} = delete($args->{'-tabcomplete'}) if (defined($args->{'-tabcomplete'})); | ||
| 1054 | $w->{'-altbinding'} = ''; #NEXT 2 ADDED 20050112 TO SUPPORT ALTERNATE KEY-ACTION MODELS. | ||
| 1055 | $w->{'-altbinding'} = delete($args->{'-altbinding'}) if (defined($args->{'-altbinding'})); | ||
| 1056 | #NEXT LINE ADDED 20060429 TO SUPPORT OPTION FOR USER DELETION OF LISTBOX ITEMS. | ||
| 1057 | $w->{'-deleteitemsok'} = delete($args->{'-deleteitemsok'}) if (defined($args->{'-deleteitemsok'})); | ||
| 1058 | $w->{'-framehighlightthickness'} = defined($args->{'-framehighlightthickness'}) | ||
| 1059 | ? delete($args->{'-framehighlightthickness'}) : 1; | ||
| 1060 | #NEXT 2 OPTIONS ADDED 20070904 BY JWT: | ||
| 1061 | $w->{'-buttonborderwidth'} = defined($args->{'-buttonborderwidth'}) | ||
| 1062 | ? delete($args->{'-buttonborderwidth'}) : 1; | ||
| 1063 | $w->{'-default'} = defined($args->{'-default'}) | ||
| 1064 | ? delete($args->{'-default'}) : undef; | ||
| 1065 | $w->{'-entryborderwidth'} = defined($args->{'-entryborderwidth'}) | ||
| 1066 | ? $args->{'-entryborderwidth'} : 0; | ||
| 1067 | $w->{'-nobutton'} = defined($args->{'-nobutton'}) | ||
| 1068 | ? delete($args->{-nobutton}) : 0; | ||
| 1069 | $w->{'-labelrelief'} = defined($args->{'-labelrelief'}) | ||
| 1070 | ? delete($args->{'-labelrelief'}) : 'flat'; | ||
| 1071 | $w->{'-label'} = defined($args->{'-label'}) | ||
| 1072 | ? $args->{'-label'} : undef; | ||
| 1073 | #NEXT OPTIONS ADDED FOR v5.1 BY JWT: | ||
| 1074 | $w->{'-fixedlist'} = defined($args->{'-fixedlist'}) ? delete($args->{'-fixedlist'}) : 0; | ||
| 1075 | #HListbox-specific options (v5.1): | ||
| 1076 | $w->{'-listboxtype'} = defined($args->{'-listboxtype'}) | ||
| 1077 | ? delete($args->{'-listboxtype'}) : 'Listbox'; | ||
| 1078 | $w->{'-itemtype'} = defined($args->{'-itemtype'}) ? delete($args->{'-itemtype'}) : 'text'; | ||
| 1079 | $w->{'-indicator'} = defined($args->{'-indicator'}) ? delete($args->{'-indicator'}) : '0'; | ||
| 1080 | $w->{'-activestyle'} = defined($args->{'-activestyle'}) ? delete($args->{'-activestyle'}) : 'underline'; | ||
| 1081 | $w->{'-activestyle'} = defined($args->{'-activestyle'}) ? delete($args->{'-activestyle'}) : 'underline'; | ||
| 1082 | $w->{'-colorstate'} = defined($args->{'-colorstate'}) ? delete($args->{'-colorstate'}) : '0'; | ||
| 1083 | my $lpack = delete $args->{-labelPack}; #MOVED ABOVE SUPER:POPULATE 20050120. | ||
| 1084 | |||
| 1085 | $w->SUPER::Populate($args); | ||
| 1086 | |||
| 1087 | # ENTRY WIDGET AND ARROW BUTTON | ||
| 1088 | |||
| 1089 | unless (defined $lpack) | ||
| 1090 | { | ||
| 1091 | my $justify = ($w->{'-fixedlist'} =~ /top/) ? 's' : 'n'; | ||
| 1092 | $lpack = ($w->{'-fixedlist'}) ? [-side => 'left', -anchor => $justify, -pady => 1, -ipady => 2] | ||
| 1093 | : [-side => 'left', -anchor => 'e', -ipady => 2]; | ||
| 1094 | } | ||
| 1095 | |||
| 1096 | my $ll = $w->Label(); | ||
| 1097 | my $tf = $w->Frame(-borderwidth => ($w->{-borderwidth} || 2), | ||
| 1098 | -highlightcolor => $initFG, -highlightbackground => $initBG, | ||
| 1099 | -highlightthickness => ($w->{'-framehighlightthickness'} || 1), | ||
| 1100 | -relief => ($w->{'-relief'} || 'sunken')); | ||
| 1101 | |||
| 1102 | #DEPRECIATED(SOLVED): FOR SOME REASON, E HAS TO BE A LABENTRY, JUST PLAIN ENTRY WOULDN'T TAKE KEYBOARD EVENTS???? | ||
| 1103 | #AFTER MUCH T&E: POUNDING OUT THE "e->bindtags()" FUNCTION CALL RESOLVED THIS ISSUE! :D | ||
| 1104 | my %entryHash = (-borderwidth => $w->{'-entryborderwidth'}||0, -relief => 'flat', | ||
| 1105 | -highlightcolor => $initFG, -highlightbackground => $initBG); | ||
| 1106 | if (defined($args->{'-colorstate'}) && $args->{'-colorstate'} == 1) | ||
| 1107 | { | ||
| 1108 | $entryHash{'-background'} = 'gray95'; | ||
| 1109 | $entryHash{'-foreground'} = 'black'; | ||
| 1110 | } | ||
| 1111 | my $e = $tf->Entry(%entryHash); | ||
| 1112 | $w->ConfigSpecs(DEFAULT => [$e]); | ||
| 1113 | my $b = $tf->Button(-borderwidth => $w->{'-buttonborderwidth'}, -takefocus => $w->{'btntakesfocus'}, | ||
| 1114 | -bitmap => $BITMAP); | ||
| 1115 | if (defined $w->{'-label'}) | ||
| 1116 | { | ||
| 1117 | $ll->pack(@$lpack); | ||
| 1118 | } | ||
| 1119 | else | ||
| 1120 | { | ||
| 1121 | $ll->packForget(); # REMOVE LABEL, IF NO VALUE SPECIFIED. | ||
| 1122 | } | ||
| 1123 | $w->Advertise('entry' => $e); #TEXT PART. | ||
| 1124 | $w->Advertise('arrow' => $b); #ARROW BUTTON PART. | ||
| 1125 | $w->Advertise('frame' => $tf); #SURROUNDING FRAME PART. | ||
| 1126 | $w->Advertise('label' => $ll); #SURROUNDING FRAME PART. | ||
| 1127 | $b->pack(-side => 'right', -padx => 0, -pady => 0, -fill => 'y') unless ($w->{'-nobutton'}); | ||
| 1128 | $e->pack(-side => 'right', -fill => 'x', -padx => 0, -pady => 0, -expand => 1); | ||
| 1129 | |||
| 1130 | # POPUP SHELL FOR LISTBOX WITH VALUES. | ||
| 1131 | |||
| 1132 | my ($c, $sl); | ||
| 1133 | if ($w->{'-listboxtype'} =~ /HList/i) | ||
| 1134 | { | ||
| 1135 | die "Error: You requested Tk::HListbox, but it does not appear to be installed or is < v2.1." | ||
| 1136 | unless ($haveHListbox); | ||
| 1137 | $w->{'-listboxtype'} = 'HListbox'; | ||
| 1138 | } | ||
| 1139 | else | ||
| 1140 | { | ||
| 1141 | $w->{'-listboxtype'} = 'Listbox'; | ||
| 1142 | } | ||
| 1143 | if ($w->{'-fixedlist'}) | ||
| 1144 | { | ||
| 1145 | $tf->pack(-side => 'top', -padx => 0, -pady => 0, -fill => 'x', -expand => 1) | ||
| 1146 | unless ($w->{'-fixedlist'} =~ /top/); | ||
| 1147 | my $height = $w->{'-height'} ||= 3; | ||
| 1148 | $c = $w->Frame(-bd => 0, -relief => 'flat', -takefocus => 0); | ||
| 1149 | $sl = $c->Scrolled($w->{'-listboxtype'}, | ||
| 1150 | -takefocus => 0, | ||
| 1151 | -selectmode => 'browse', | ||
| 1152 | -height => $height, | ||
| 1153 | -scrollbars => 'oe', | ||
| 1154 | -activestyle => $w->{'-activestyle'}, | ||
| 1155 | -exportselection => ($w->{'-noselecttext'} ? 0 : 1), | ||
| 1156 | )->pack(-fill => 'x', -expand => 1); | ||
| 1157 | (my $lbtype = $w->{'-listboxtype'}) =~ tr/A-Z/a-z/; | ||
| 1158 | $sl->Subwidget($lbtype)->configure(-takefocus => 0); | ||
| 1159 | $w->update; | ||
| 1160 | $c->pack(-side => 'top', -padx => 0, -pady => 0, -fill => 'both', -expand => 1); | ||
| 1161 | $tf->pack(-side => 'top', -padx => 0, -pady => 0, -fill => 'x', -expand => 1) | ||
| 1162 | if ($w->{'-fixedlist'} =~ /top/); | ||
| 1163 | $c->bind('<FocusIn>' => sub { | ||
| 1164 | if (!defined($w->{'_lbignorefocus'}) || $w->{'_lbignorefocus'} == 1) #DON'T REFOCUS ON JUST POPPED-DOWN "BOUNCY" LISTBOX! | ||
| 1165 | { | ||
| 1166 | $w->{'_lbignorefocus'} = 0; | ||
| 1167 | } | ||
| 1168 | else | ||
| 1169 | { | ||
| 1170 | $sl->focus; | ||
| 1171 | } | ||
| 1172 | Tk->break; | ||
| 1173 | }); #AIN'T SUPPOSED TO TAKE FOCUS, BUT DOES, SO, MOVE ALONG! | ||
| 1174 | $e->bind('<FocusIn>' => sub { $w->Popdown(1); Tk->break }); | ||
| 1175 | } | ||
| 1176 | else | ||
| 1177 | { | ||
| 1178 | $tf->pack(-side => 'top', -padx => 0, -pady => 0, -fill => 'x', -expand => 1); | ||
| 1179 | $c = $w->Toplevel(-bd => 0, -relief => 'raised'); | ||
| 1180 | $c->overrideredirect(1); | ||
| 1181 | $c->withdraw; | ||
| 1182 | $sl = $c->Scrolled($w->{'-listboxtype'}, | ||
| 1183 | -selectmode => 'browse', | ||
| 1184 | -exportselection => ($w->{'-noselecttext'} ? 0 : 1), | ||
| 1185 | -scrollbars => 'oe'); | ||
| 1186 | } | ||
| 1187 | |||
| 1188 | $w->{'-listboxtype'} =~ tr/A-Z/a-z/; | ||
| 1189 | |||
| 1190 | #SPECIAL HLISTBOX CONFIGS: | ||
| 1191 | if ($w->{'-listboxtype'} =~ /h/) | ||
| 1192 | { | ||
| 1193 | foreach my $arg (qw/-indicator -itemtype/) | ||
| 1194 | { | ||
| 1195 | $sl->configure($arg => $w->{$arg}); | ||
| 1196 | } | ||
| 1197 | } | ||
| 1198 | |||
| 1199 | $w->Advertise('choices' => $c); #LISTBOX POPUP MAIN WINDOW PART. | ||
| 1200 | $w->Advertise('slistbox' => $sl); #ACTUAL LISTBOX ITSELF. | ||
| 1201 | $sl->pack(-expand => 1, -fill => 'both'); | ||
| 1202 | |||
| 1203 | # OTHER INITIALIZATIONS. | ||
| 1204 | |||
| 1205 | $w->SetBindings; | ||
| 1206 | $w->{"popped"} = 0; | ||
| 1207 | $w->Delegates('insert' => $sl, 'delete' => $sl, get => $sl, DEFAULT => $e); | ||
| 1208 | $w->ConfigSpecs( | ||
| 1209 | -listwidth => [qw/PASSIVE listWidth ListWidth/, undef], | ||
| 1210 | -maxwidth => [qw/PASSIVE maxWidth MaxWidth/, undef], | ||
| 1211 | -height => [qw/PASSIVE height Height/, undef], | ||
| 1212 | -listcmd => [qw/CALLBACK listCmd ListCmd/, undef], | ||
| 1213 | -browsecmd => [qw/CALLBACK browseCmd BrowseCmd/, undef], | ||
| 1214 | -deletecmd => [qw/CALLBACK deleteCmd DeleteCmd/, undef], | ||
| 1215 | -choices => [qw/METHOD choices Choices/, undef], | ||
| 1216 | -state => [qw/METHOD state State normal/], | ||
| 1217 | -colorstate => [qw/PASSIVE colorState ColorState 0/], | ||
| 1218 | #-colorstate => [qw/PASSIVE colorState ColorState/, undef], | ||
| 1219 | -arrowimage => [ {-image => $b}, qw/arrowImage ArrowImage/, undef], | ||
| 1220 | -variable => [ {-textvariable => $e}, qw/variable Variable/, undef], | ||
| 1221 | -label => [ {-text => $ll}, qw/label Label/, undef], | ||
| 1222 | -labelrelief => [ {-relief => $ll}, qw/relief Relief/, undef], | ||
| 1223 | -listrelief => [ {-relief => $sl}, qw/relief Relief/, 'sunken'], | ||
| 1224 | -labelbackground => [ {-background => $ll}, qw/background Background/, undef], | ||
| 1225 | -labelforeground => [ {-foreground => $ll}, qw/foreground Foreground/, undef], | ||
| 1226 | -labelfont => [ {-font => $ll}, qw/font Font/, undef], | ||
| 1227 | -textbackground => [ {-background => $e}, qw/background Background/, undef], | ||
| 1228 | -textforeground => [ {-foreground => $e}, qw/foreground Foreground/, undef], | ||
| 1229 | -textdisabledbackground => [ {-disabledbackground => $e}, qw/disabledBackground DisabledBackground/, undef], | ||
| 1230 | -textdisabledforeground => [ {-disabledforeground => $e}, qw/disabledForeground DisabledForeground/, undef], | ||
| 1231 | -textreadonlybackground => [ {-readonlybackground => $e}, qw/readonlyBackground ReadonlyBackground/, undef], | ||
| 1232 | #THIS ONE DOESN'T EXIST!: -textreadonlyforeground => [ {-readonlyforeground => $e}, qw/background Background/, undef], | ||
| 1233 | -entryborderwidth => [ {-borderwidth => $e}, qw/borderWidth BorderWidth/, 0], | ||
| 1234 | -buttonbackground => [ {-background => $b}, qw/background Background/, undef], | ||
| 1235 | -buttonforeground => [ {-foreground => $b}, qw/foreground Foreground/, undef], | ||
| 1236 | -background => [['SELF', 'DESCENDANTS'], qw/background Background/, undef], | ||
| 1237 | -foreground => [['SELF', 'DESCENDANTS'], qw/foreground Foreground/, undef], | ||
| 1238 | -default => ['PASSIVE', undef, undef, undef], | ||
| 1239 | DEFAULT => [$e] ); | ||
| 1240 | |||
| 1241 | $sl->configure(-relief => $w->{'-listrelief'}||'sunken'); | ||
| 1242 | $sl->configure(-font => $w->{'-listfont'}) if ($w->{'-listfont'}); | ||
| 1243 | $sl->Subwidget('yscrollbar')->configure(-takefocus => 0); | ||
| 1244 | my $state = (defined $args->{'-state'}) ? $args->{'-state'} : 'normal'; | ||
| 1245 | my %argHash = (); | ||
| 1246 | my $haveSomething = 0; | ||
| 1247 | foreach my $a (keys %{$w}) #THIS UGLY HACK NEEDED TO INITIALIZE -labelforground, -labelbackground, ETC.: | ||
| 1248 | { | ||
| 1249 | if ($a =~ /^\-label(\w+)$/o) { | ||
| 1250 | $argHash{$a} = $w->{$a}; | ||
| 1251 | ++$haveSomething; | ||
| 1252 | } | ||
| 1253 | } | ||
| 1254 | $w->configure(%argHash) if ($haveSomething); | ||
| 1255 | my $var_ref = $w->{'-variable'}; | ||
| 1256 | |||
| 1257 | $w->{'default'} = $w->{'-default'}; | ||
| 1258 | unless (defined $w->{'default'}) | ||
| 1259 | { | ||
| 1260 | $w->{'default'} = defined($w->{'-variable'}) ? ${$w->{'-variable'}} : undef; | ||
| 1261 | } | ||
| 1262 | #SET UP DUMMY SO IT DISPLAYSS IF NO VARIABLE SPECIFIED: | ||
| 1263 | unless (defined($var_ref) && ref($var_ref)) | ||
| 1264 | { | ||
| 1265 | $var_ref = defined($w->{'default'}) ? $w->{'default'} : ''; | ||
| 1266 | $w->configure(-variable => \$var_ref); | ||
| 1267 | } | ||
| 1268 | } | ||
| 1269 | |||
| 1270 | sub focus #CALLED WHENEVER MAIN WIDGET TAKES FOCUS: | ||
| 1271 | { | ||
| 1272 | my ($w) = shift; | ||
| 1273 | |||
| 1274 | if (defined($w->{'_ignorefocus'}) && $w->{'_ignorefocus'} == 1) #DON'T CHANGE (SUBWIDGET) FOCUS EVEN THOUGH MAIN WIDGET IS TAKING FOCUS (NEEDED BY CLICKING ON THE FIXED DD-LIST): | ||
| 1275 | { | ||
| 1276 | $w->{'_ignorefocus'} = 0; | ||
| 1277 | return; | ||
| 1278 | } | ||
| 1279 | my $state = $w->cget( "-state" ); | ||
| 1280 | my $fw = (defined($state) && $state eq 'readonly') ? 'frame' : 'entry'; | ||
| 1281 | my $e = $w->Subwidget('entry'); #FOR SOME REASON ON RARE OCCASIONS THESE SUBWIDGETS ERROR OUT AS NOT DEFINED?! | ||
| 1282 | my $f = $w->Subwidget('frame'); #IE. THE "Select To Mark" DDLIST IN e.pl IS KNOWN TO SILENTLY FAIL HERE! | ||
| 1283 | my $b = $w->Subwidget('arrow'); #PBLY B/C THE SURROUNDING DIALOG HAS ALREADY CLOSED, PERHAPS? | ||
| 1284 | my $eORf = $w->Subwidget($fw); | ||
| 1285 | #CHGD. TO NEXT: 202407 TO FIX ERROR: $w->Subwidget($fw)->configure(-highlightcolor => $w->Subwidget('frame')->cget('-background')) | ||
| 1286 | $w->Subwidget($fw)->configure(-highlightcolor => $f->cget('-background')) | ||
| 1287 | if (defined($f) && defined($e) && $fw eq 'entry'); #CLEAN UP ANY MESS MADE BY setPalette! | ||
| 1288 | $w->Subwidget($fw)->focus if (defined $eORf); | ||
| 1289 | |||
| 1290 | #BUTTON GETS FOCUS IF BUTTON TAKES FOCUS, BUT WIDGET ITSELF DOESN'T. | ||
| 1291 | $w->Subwidget('arrow')->focus if (defined($b) && !$w->{'takefocus'} && $w->{'btntakesfocus'}); | ||
| 1292 | if (defined $e) { | ||
| 1293 | $w->Subwidget('entry')->icursor('end'); | ||
| 1294 | $w->Subwidget('entry')->selectionRange(0,'end') | ||
| 1295 | unless ($w->{'-noselecttext'} || !$w->Subwidget('entry')->index('end')); | ||
| 1296 | } | ||
| 1297 | ########Tk->break #DON'T, IT WON'T RUN! | ||
| 1298 | } | ||
| 1299 | |||
| 1300 | sub SetBindings | ||
| 1301 | { | ||
| 1302 | my $w = shift; | ||
| 1303 | |||
| 1304 | my $e = $w->Subwidget('entry'); | ||
| 1305 | my $f = $w->Subwidget('frame'); | ||
| 1306 | my $b = $w->Subwidget('arrow'); | ||
| 1307 | my $sl = $w->Subwidget('slistbox'); | ||
| 1308 | my $l = $sl->Subwidget($w->{'-listboxtype'}); | ||
| 1309 | |||
| 1310 | local *returnFn = sub #HANDLES RETURN-KEY PRESSED IN ENTRY AREA. | ||
| 1311 | { | ||
| 1312 | my $self = shift; | ||
| 1313 | my $keyModifier = shift || ''; | ||
| 1314 | $keyModifier .= '-' if ($keyModifier =~ /\S/o); | ||
| 1315 | my ($state) = $w->cget( "-state" ); | ||
| 1316 | my $altbinding = $w->{'-altbinding'}; | ||
| 1317 | return if ($state eq 'disabled' || $altbinding =~ /Return\=None\b/io); | ||
| 1318 | |||
| 1319 | if ($altbinding =~ /Return\=SingleGo/io | ||
| 1320 | && $w->Subwidget('slistbox')->index('end') < 1) | ||
| 1321 | { | ||
| 1322 | #MAKE <RETURN> "GO" IF THE LISTBOX IS EMPTY: | ||
| 1323 | $w->Callback(-browsecmd => $w, $w->Subwidget('entry')->get, "entry.${keyModifier}return.go"); | ||
| 1324 | Tk->break; | ||
| 1325 | return if ($state =~ /text/o); | ||
| 1326 | } | ||
| 1327 | elsif ($altbinding =~ /Return\=Go/io) | ||
| 1328 | { | ||
| 1329 | $w->Popdown if ($w->{"popped"}); #ROLL UP (HIDE) LISTBOX. | ||
| 1330 | $w->Callback(-browsecmd => $w, $w->Subwidget('entry')->get, "entry.${keyModifier}return.go"); | ||
| 1331 | Tk->break; | ||
| 1332 | } | ||
| 1333 | elsif ($altbinding =~ /Return\=NonEmptyGo/io) | ||
| 1334 | { | ||
| 1335 | my $textval = $w->get(); | ||
| 1336 | if (defined($textval) && $textval ne '') | ||
| 1337 | { | ||
| 1338 | $w->Popdown if ($w->{"popped"}); #UNDISPLAYS LISTBOX. | ||
| 1339 | $w->Callback(-browsecmd => $w, $w->Subwidget('entry')->get, "entry.${keyModifier}return.go"); | ||
| 1340 | Tk->break; | ||
| 1341 | } | ||
| 1342 | } | ||
| 1343 | elsif ($altbinding =~ /Return\=Next/io) | ||
| 1344 | { | ||
| 1345 | $w->Popdown if ($w->{"popped"}); #UNDISPLAYS LISTBOX. | ||
| 1346 | $w->Callback(-browsecmd => $w, $w->Subwidget('entry')->get, "entry.${keyModifier}return.browse") | ||
| 1347 | if ($w->{'-browse'} == 1); | ||
| 1348 | $self->focusNext; | ||
| 1349 | Tk->break; | ||
| 1350 | } | ||
| 1351 | $w->LbFindSelection(0); | ||
| 1352 | if ($w->{'popped'}) #LISTBOX IS SHOWING: | ||
| 1353 | { | ||
| 1354 | $w->LbCopySelection(0,'entry.${keyModifier}return'); | ||
| 1355 | Tk->break; | ||
| 1356 | } | ||
| 1357 | else | ||
| 1358 | { | ||
| 1359 | $w->Callback(-browsecmd => $w, $w->Subwidget('entry')->get, "entry.${keyModifier}return.browse") | ||
| 1360 | if ($w->{'-browse'} == 1); | ||
| 1361 | $w->PopupChoices; | ||
| 1362 | } | ||
| 1363 | }; | ||
| 1364 | |||
| 1365 | local *rightFn = sub #RIGHT-ARROW PRESSED IN ENTRY: COMPLETE TEXT TO NEXT MATCHING SELECTION. | ||
| 1366 | { | ||
| 1367 | Tk->break if ($e->index('insert') < $e->index('end') | ||
| 1368 | || $w->{'-altbinding'} =~ /Right\=NoSearch/io); | ||
| 1369 | my ($state) = $w->cget( "-state" ); | ||
| 1370 | return if ($state eq 'textonly' || $state eq 'disabled' || $w->{'-altbinding'} =~ /Right\=None/io); | ||
| 1371 | |||
| 1372 | my $var_ref = $w->cget('-variable'); | ||
| 1373 | return unless (defined($var_ref) && defined($$var_ref) && $$var_ref =~ /\S/o); #TEXT FIELD EMPTY, PUNT! | ||
| 1374 | |||
| 1375 | my @listsels = $w->getText('0','end'); | ||
| 1376 | return if ($#listsels < 0); #NO LIST TO SEARCH, SO PUNT! | ||
| 1377 | |||
| 1378 | my $srchPattern = $$var_ref; | ||
| 1379 | my $found = $w->LbFindSelection(0); #SEARCH FOR CURRENT TEXT: RETURNS 1 IF FULL MATCH (IN LIST), -1 IF CONTAINS, 0 IF NO MATCH. | ||
| 1380 | return unless (defined($found) && $found); #NO MATCH, PUNT! | ||
| 1381 | |||
| 1382 | my $index; | ||
| 1383 | $index = $w->LbIndex(2) if ($found < 0 && $w->LbFindSelection(0,$srchPattern)); #IF MATCH ONLY CONTAINS TEXT, SEARCH AGAIN STARTING AT *NEXT* ENTRY. | ||
| 1384 | if (defined $index) { | ||
| 1385 | $$var_ref = $w->reference($listsels[$index]); | ||
| 1386 | $e->icursor('end'); | ||
| 1387 | $e->selectionRange(0,'end') unless ($w->{'-noselecttext'} || !$e->index('end')); | ||
| 1388 | } | ||
| 1389 | }; | ||
| 1390 | |||
| 1391 | local *downFn = sub #HANDLES DOWN-ARROW PRESSED IN ENTRY AREA. | ||
| 1392 | { | ||
| 1393 | my ($state) = $w->cget( '-state' ) || 'normal'; | ||
| 1394 | return if ($state eq 'textonly' || $state eq 'disabled' || $w->{'-altbinding'} =~ /Down\=None/io); | ||
| 1395 | |||
| 1396 | if ($w->{'-altbinding'} =~ /Down\=Popup/io && $state !~ /text/o) #MAKE DOWN-ARROW POP UP DD-LIST. | ||
| 1397 | { | ||
| 1398 | $w->LbFindSelection(0); | ||
| 1399 | if (!$w->{'-fixedlist'} && $w->{'popped'}) #LISTBOX IS SHOWING: | ||
| 1400 | { | ||
| 1401 | $w->LbCopySelection(1,'entry.down'); | ||
| 1402 | Tk->break; | ||
| 1403 | } | ||
| 1404 | else | ||
| 1405 | { | ||
| 1406 | $w->PopupChoices; | ||
| 1407 | } | ||
| 1408 | return; | ||
| 1409 | } | ||
| 1410 | if ($w->{'popped'}) #LISTBOX IS SHOWING: | ||
| 1411 | { | ||
| 1412 | return if ($state eq 'text'); | ||
| 1413 | |||
| 1414 | $w->LbFindSelection(0); | ||
| 1415 | $w->Subwidget("slistbox")->focus; | ||
| 1416 | } | ||
| 1417 | else | ||
| 1418 | { | ||
| 1419 | $w->LbFindSelection(0); | ||
| 1420 | my $l = $w->Subwidget('slistbox')->Subwidget($w->{'-listboxtype'}); | ||
| 1421 | my @listsels = $w->getText('0','end'); | ||
| 1422 | return unless ($#listsels >= 0); | ||
| 1423 | |||
| 1424 | my $index = $w->LbIndex(3); | ||
| 1425 | my $var_ref = $w->cget('-variable'); | ||
| 1426 | if ($$var_ref eq $listsels[$index]) | ||
| 1427 | { | ||
| 1428 | $l->selectionClear($index++); | ||
| 1429 | $index = $#listsels if ($index > $#listsels); | ||
| 1430 | #REPLACE PREV. WITH THIS FOR ROUND-ROBIN: $index = 0 if ($index > $#listsels); | ||
| 1431 | } | ||
| 1432 | $$var_ref = $w->reference($listsels[$index]); | ||
| 1433 | $l->activate($index); #ADDED 20070904 PER PATCH FROM WOLFRAM HUMANN. | ||
| 1434 | $l->selectionSet($index); | ||
| 1435 | $l->see($index) if ($w->{'-fixedlist'}); | ||
| 1436 | $e->icursor('end'); | ||
| 1437 | #LET'S NOT DO: $e->selectionRange(0,'end') unless ($w->{'-noselecttext'} || !$e->index('end')); | ||
| 1438 | } | ||
| 1439 | }; | ||
| 1440 | |||
| 1441 | local *upFn = sub #HANDLES UP-ARROW PRESSED IN ENTRY AREA. | ||
| 1442 | { | ||
| 1443 | my ($state) = $w->cget( '-state' ) || 'normal'; | ||
| 1444 | return if ($state eq 'textonly' || $state eq 'disabled' || $w->{'-altbinding'} =~ /Up\=None/io); | ||
| 1445 | |||
| 1446 | if ($w->{'-altbinding'} =~ /Up\=Popup/io && $state !~ /text/o) #MAKE DOWN-ARROW POP UP DD-LIST. | ||
| 1447 | { | ||
| 1448 | $w->LbFindSelection(1); | ||
| 1449 | if (!$w->{'-fixedlist'} && $w->{'popped'}) #LISTBOX IS SHOWING: | ||
| 1450 | { | ||
| 1451 | $w->LbCopySelection(1,'entry.down'); | ||
| 1452 | Tk->break; | ||
| 1453 | } | ||
| 1454 | else | ||
| 1455 | { | ||
| 1456 | $w->PopupChoices; | ||
| 1457 | } | ||
| 1458 | return; | ||
| 1459 | } | ||
| 1460 | if ($w->{'popped'}) #LISTBOX IS SHOWING: | ||
| 1461 | { | ||
| 1462 | return if ($state eq 'text'); | ||
| 1463 | |||
| 1464 | $w->LbFindSelection(1); | ||
| 1465 | $w->Subwidget("slistbox")->focus; | ||
| 1466 | } | ||
| 1467 | else | ||
| 1468 | { | ||
| 1469 | $w->LbFindSelection(1); | ||
| 1470 | my $l = $w->Subwidget('slistbox')->Subwidget($w->{'-listboxtype'}); | ||
| 1471 | my @listsels = $w->getText('0','end'); | ||
| 1472 | return unless ($#listsels >= 0); | ||
| 1473 | |||
| 1474 | my $index = $w->LbIndex(3); | ||
| 1475 | my $var_ref = $w->cget('-variable'); | ||
| 1476 | if ($$var_ref eq $listsels[$index]) | ||
| 1477 | { | ||
| 1478 | $l->selectionClear($index--); | ||
| 1479 | $index = 0 if ($index < 0); | ||
| 1480 | #REPLACE PREV. WITH THIS FOR ROUND-ROBIN: $index = $#listsels if ($index < 0); | ||
| 1481 | } | ||
| 1482 | $$var_ref = $w->reference($listsels[$index]); | ||
| 1483 | $l->activate($index); #ADDED 20070904 PER PATCH FROM WOLFRAM HUMANN. | ||
| 1484 | $l->selectionSet($index); | ||
| 1485 | $l->see($index) if ($w->{'-fixedlist'}); | ||
| 1486 | $e->icursor('end'); | ||
| 1487 | #LET'S NOT DO: $e->selectionRange(0,'end') unless ($w->{'-noselecttext'} || !$e->index('end')); | ||
| 1488 | } | ||
| 1489 | }; | ||
| 1490 | |||
| 1491 | local *escapeFn = sub #HANDLES ESCAPE-KEY PRESSED IN ENTRY AREA. | ||
| 1492 | { | ||
| 1493 | return if ($w->{'-altbinding'} =~ /Esc\=None/io); | ||
| 1494 | |||
| 1495 | if ($w->{'popped'}) #LISTBOX IS SHOWING, ROLL IT UP: | ||
| 1496 | { | ||
| 1497 | $w->Popdown; | ||
| 1498 | } | ||
| 1499 | else #JUST RESET TEXT FIELD TO DEFAULT OR EMPTY: | ||
| 1500 | { | ||
| 1501 | my $var_ref = $w->cget('-variable'); | ||
| 1502 | #if ($$var_ref eq $w->{'default'} && $w->cget( '-state' ) ne 'readonly') | ||
| 1503 | #CHGD. TO NEXT 20030531 PER PATCH BY FRANK HERRMANN. | ||
| 1504 | if ($w->cget('-state') eq 'readonly') | ||
| 1505 | { | ||
| 1506 | $$var_ref = $w->{'default'} if (defined $w->{'default'}); | ||
| 1507 | } | ||
| 1508 | else | ||
| 1509 | { | ||
| 1510 | $$var_ref = (defined($w->{'default'}) && $$var_ref eq $w->{'default'}) | ||
| 1511 | ? '' : $w->{'default'}; | ||
| 1512 | $$var_ref = '' unless (defined $$var_ref); #MAKE THE NANNY-STATERS HAPPY! | ||
| 1513 | } | ||
| 1514 | $e->icursor('end'); | ||
| 1515 | $w->{'searchindx'} = 0; | ||
| 1516 | } | ||
| 1517 | $e->selectionRange(0,'end') unless ($w->{'-noselecttext'} || !$e->index('end')); #ADDED 20020716 | ||
| 1518 | Tk->break; | ||
| 1519 | }; | ||
| 1520 | |||
| 1521 | local *spacebarFn = sub #HANDLES SPACEBAR PRESSED IN ENTRY AREA (ONLY MATTERS IN READONLY STATE): | ||
| 1522 | { | ||
| 1523 | return if ($w->{'-altbinding'} =~ /Space\=None/io); | ||
| 1524 | |||
| 1525 | my ($state) = $w->cget( '-state' ); | ||
| 1526 | if ($state eq 'readonly') | ||
| 1527 | { | ||
| 1528 | my $res = $w->LbFindSelection(0); | ||
| 1529 | if ($w->{'popped'}) #LISTBOX IS SHOWING: | ||
| 1530 | { | ||
| 1531 | $w->LbCopySelection(0,'entry.space'); | ||
| 1532 | Tk->break; | ||
| 1533 | } | ||
| 1534 | else | ||
| 1535 | { | ||
| 1536 | $w->PopupChoices; | ||
| 1537 | unless ($res) #ADDED 20090320 TO CAUSE DROP-DOWN LIST TO POP DOWN W/ACTIVE CURSOR IN RIGHT PLACE (INSTEAD OF BOTTOM) IF NO MATCH: | ||
| 1538 | { | ||
| 1539 | $l->selectionClear('0','end'); | ||
| 1540 | $l->activate(0); | ||
| 1541 | $l->selectionSet(0); | ||
| 1542 | $l->update(); | ||
| 1543 | $l->see(0); | ||
| 1544 | } | ||
| 1545 | } | ||
| 1546 | } | ||
| 1547 | }; | ||
| 1548 | |||
| 1549 | # SET BIND TAGS | ||
| 1550 | |||
| 1551 | $w->bindtags([$w, 'Tk::JBrowseEntry', $w->toplevel, 'all']); | ||
| 1552 | ########!!!!!!!!OK FOR LABENTRY, BUT *NOT* ENTRY (NOT SURE WHAT IT EVER DID)!!!: $e->bindtags([$e, $e->toplevel, 'all']); | ||
| 1553 | |||
| 1554 | # IF USER-SPECIFIED IMAGE(S), CHANGE BUTTON IMAGE WHEN GETTING/LOSING FOCUS. | ||
| 1555 | |||
| 1556 | $b->bind('<FocusIn>', sub | ||
| 1557 | { | ||
| 1558 | my $img = $w->{'farrowimage'}; | ||
| 1559 | if ($img) | ||
| 1560 | { | ||
| 1561 | $b->configure(-image => $img); | ||
| 1562 | } | ||
| 1563 | else #RESET TO FOCUSED DEFAULT BITMAP: | ||
| 1564 | { | ||
| 1565 | $b->configure(-image => undef); | ||
| 1566 | $b->configure(-bitmap => $FOCUSEDBITMAP); | ||
| 1567 | } | ||
| 1568 | $w->{'savehl'} = $f->cget('-highlightcolor'); | ||
| 1569 | my $framehlcolor = $f->cget('-background'); | ||
| 1570 | $f->configure(-highlightcolor => $framehlcolor); | ||
| 1571 | Tk->break; | ||
| 1572 | }); | ||
| 1573 | |||
| 1574 | $b->bind('<FocusOut>', sub | ||
| 1575 | { | ||
| 1576 | $f->configure(-highlightcolor => $w->{'savehl'}) if ($w->{'savehl'}); | ||
| 1577 | unless ($w->focusCurrent =~ /Listbox/o) { | ||
| 1578 | my $img = $w->{'arrowimage'}; # || $b->cget('-image'); | ||
| 1579 | if ($img) | ||
| 1580 | { | ||
| 1581 | $b->configure(-image => $img); | ||
| 1582 | } | ||
| 1583 | else #RESET TO UNFOCUSED DEFAULT BITMAP: | ||
| 1584 | { | ||
| 1585 | $b->configure(-image => undef); | ||
| 1586 | $b->configure(-bitmap => $BITMAP); | ||
| 1587 | } | ||
| 1588 | Tk->break; | ||
| 1589 | } | ||
| 1590 | }); | ||
| 1591 | |||
| 1592 | $b->bind('<ButtonPress-1>', sub #MOUSE CLICKED ON THE BUTTON: | ||
| 1593 | { | ||
| 1594 | unless ($b->cget( '-state' ) eq 'disabled') | ||
| 1595 | { | ||
| 1596 | #1 $w->LbFindSelection(0) if ($w->{'popped'}); #(IF LISTBOX IS SHOWING, FIND & HIGHLIGHT CLOSEST MATCH TO TEXT): | ||
| 1597 | #$w->LbFindSelection(0); | ||
| 1598 | $w->PopupChoices; #TOGGLES DISPLAY OF LISTBOX! | ||
| 1599 | if ($w->{'popped'}) | ||
| 1600 | { | ||
| 1601 | #my $index = $w->LbIndex(1); | ||
| 1602 | |||
| 1603 | $sl->focus; | ||
| 1604 | $sl->raise; | ||
| 1605 | $w->{'_ignorefocus'} = 1; | ||
| 1606 | } | ||
| 1607 | else | ||
| 1608 | { | ||
| 1609 | $w->{'_ignorefocus'} = 0; | ||
| 1610 | $w->focus; | ||
| 1611 | } | ||
| 1612 | #LET'S NOT DO: $w->LbCopySelection(1,'button.button1'); | ||
| 1613 | } | ||
| 1614 | Tk->break; | ||
| 1615 | }); | ||
| 1616 | |||
| 1617 | $b->bind('<Shift-ButtonRelease-1>', sub #SHIFT-MOUSE1: SO USER CAN AVOID BOUNCE ON BOUNCY MENUS! | ||
| 1618 | { | ||
| 1619 | Tk->break; | ||
| 1620 | }); | ||
| 1621 | |||
| 1622 | $b->bind('<ButtonRelease-1>', sub #MOUSE CLICKED ON THE BUTTON: | ||
| 1623 | { | ||
| 1624 | if ($w->{'popped'} && $w->{'-altbinding'} =~ /List\=Bouncy/io) | ||
| 1625 | { | ||
| 1626 | $w->{'_ignorefocus'} = 0; | ||
| 1627 | $w->{'_lbignorefocus'} = 1; | ||
| 1628 | $w->Popdown(1); # if ($w->{'popped'} && $w->{'-altbinding'} =~ /List\=Bouncy/io); | ||
| 1629 | $w->focus(); | ||
| 1630 | } | ||
| 1631 | $l->selectionSet($l->index('active')) if ($w->{'popped'}); | ||
| 1632 | Tk->break; | ||
| 1633 | }); | ||
| 1634 | |||
| 1635 | $b->bind('<space>', sub #USER HIT SPACEBAR WHILST BUTTON FOCUSED (TOGGLE DD-LIST): | ||
| 1636 | { | ||
| 1637 | my ($state) = $w->cget( '-state' ) || 'normal'; | ||
| 1638 | return if ($state =~ /text/o || $state eq 'disabled'); | ||
| 1639 | |||
| 1640 | $w->PopupChoices; | ||
| 1641 | }); | ||
| 1642 | |||
| 1643 | $b->bind('<Return>', sub #USER HIT [RETURN] KEY WHILST BUTTON FOCUSED (TOGGLE DD-LIST): | ||
| 1644 | { | ||
| 1645 | my ($state) = $w->cget( '-state' ) || 'normal'; | ||
| 1646 | return if ($state =~ /text/o || $state eq 'disabled'); | ||
| 1647 | |||
| 1648 | $w->PopupChoices; | ||
| 1649 | Tk->break; | ||
| 1650 | }); | ||
| 1651 | |||
| 1652 | $b->bind('<Down>', sub #USER HIT [DOWN-ARROW] KEY WHILST BUTTON FOCUSED (TOGGLE DD-LIST): | ||
| 1653 | { | ||
| 1654 | my ($state) = $w->cget( '-state' ) || 'normal'; | ||
| 1655 | return if ($state =~ /text/o || $state eq 'disabled'); | ||
| 1656 | |||
| 1657 | $w->PopupChoices; | ||
| 1658 | Tk->break; | ||
| 1659 | }); | ||
| 1660 | |||
| 1661 | $e->bind('<Shift-Return>', [\&returnFn, 'mod.Shift']); #REPORT ANY MODIFIERS PRESSED W/[RETURN] KEY: | ||
| 1662 | $f->bind('<Shift-Return>', [\&returnFn, 'mod.Shift']); | ||
| 1663 | $e->bind('<Control-Return>', [\&returnFn, 'mod.Control']); | ||
| 1664 | $f->bind('<Control-Return>', [\&returnFn, 'mod.Control']); | ||
| 1665 | $e->bind('<Alt-Return>', [\&returnFn, 'mod.Alt']); | ||
| 1666 | $f->bind('<Alt-Return>', [\&returnFn, 'mod.Alt']); | ||
| 1667 | $e->bind('<Return>', \&returnFn); | ||
| 1668 | $f->bind('<Return>', \&returnFn); | ||
| 1669 | |||
| 1670 | $e->bind('<Down>', \&downFn); | ||
| 1671 | $f->bind('<Down>', \&downFn); | ||
| 1672 | |||
| 1673 | $e->bind('<space>', \&spacebarFn); | ||
| 1674 | $f->bind('<space>', \&spacebarFn); | ||
| 1675 | |||
| 1676 | $e->bind('<Up>', \&upFn); | ||
| 1677 | $f->bind('<Up>', \&upFn); | ||
| 1678 | |||
| 1679 | $e->bind('<Escape>' => \&escapeFn); | ||
| 1680 | $f->bind('<Escape>' => \&escapeFn); | ||
| 1681 | |||
| 1682 | $e->bind('<Left>', sub {Tk->break;}); | ||
| 1683 | $e->bind('<Right>', \&rightFn); | ||
| 1684 | $f->bind('<Left>', sub {Tk->break;}); | ||
| 1685 | $f->bind('<Right>', \&rightFn); | ||
| 1686 | |||
| 1687 | $e->bind('<<LeftTab>>', sub #ADDED 20070904 PER PATCH FROM WOLFRAM HUMANN (HANDLES REVERSE-TABBING): | ||
| 1688 | { | ||
| 1689 | my ($state) = $w->cget( '-state' ) || 'normal'; | ||
| 1690 | $w->Popdown if ($w->{'popped'}); | ||
| 1691 | if ($state =~ /only/o || (!$w->{'takefocus'} && !$w->{'btntakesfocus'})) | ||
| 1692 | { | ||
| 1693 | $w->focusPrev; | ||
| 1694 | } | ||
| 1695 | else | ||
| 1696 | { | ||
| 1697 | $w->focusCurrent->focusPrev; | ||
| 1698 | $w->focusCurrent->focusPrev unless ($state =~ /only/o); | ||
| 1699 | } | ||
| 1700 | Tk->break; | ||
| 1701 | }); | ||
| 1702 | |||
| 1703 | $f->bind('<<LeftTab>>', sub #FRAME HAS FOCUS INSTEAD OF ENTRY WHEN READONLY!: | ||
| 1704 | { | ||
| 1705 | my ($state) = $w->cget( '-state' ) || 'normal'; | ||
| 1706 | $w->Popdown if ($w->{'popped'}); | ||
| 1707 | if ($state =~ /only/o || (!$w->{'takefocus'} && !$w->{'btntakesfocus'})) | ||
| 1708 | { | ||
| 1709 | $w->focusPrev; | ||
| 1710 | } | ||
| 1711 | else | ||
| 1712 | { | ||
| 1713 | $w->focusCurrent->focusPrev; | ||
| 1714 | $w->focusCurrent->focusPrev unless ($state =~ /only/o); | ||
| 1715 | } | ||
| 1716 | Tk->break; | ||
| 1717 | }); | ||
| 1718 | |||
| 1719 | $b->bind('<<LeftTab>>', sub #ADDED 20180621 TO PROPERLY REVERSE TABBING FROM ENTRY TO BUTTON (JFileDialog)! | ||
| 1720 | { | ||
| 1721 | $w->Popdown if ($w->{'popped'}); | ||
| 1722 | if ($w->{'takefocus'}) | ||
| 1723 | { | ||
| 1724 | $w->focus; | ||
| 1725 | } | ||
| 1726 | else | ||
| 1727 | { | ||
| 1728 | $w->focusPrev; | ||
| 1729 | } | ||
| 1730 | Tk->break; | ||
| 1731 | }); | ||
| 1732 | |||
| 1733 | $b->bind('<Tab>', sub | ||
| 1734 | { | ||
| 1735 | $w->Popdown(1) if (!$w->{'takefocus'}); | ||
| 1736 | #DON'T BREAK, JUST ALLOW TAB TO MOVE ON TO NEXT WIDGET. | ||
| 1737 | }); | ||
| 1738 | |||
| 1739 | $e->bind('<Tab>', sub | ||
| 1740 | { | ||
| 1741 | my $same = 1; #VALUE HASN'T CHANGED, MOVE TO NEXT WIDGET (TAB-COMPLETE STOPS THIS!) | ||
| 1742 | #NEXT LINE ADDED 20030531 PER PATCH BY FRANK HERRMANN. | ||
| 1743 | $w->Callback(-browsecmd => $w, $w->Subwidget('entry')->get, 'entry.tab') | ||
| 1744 | if ($w->{'-browse'} == 1); | ||
| 1745 | if (($w->{'-tabcomplete'} == 1 || $w->{'-tabcomplete'} == 2) | ||
| 1746 | && $w->cget('-state') !~ /(?:textonly|disabled)/o) | ||
| 1747 | { | ||
| 1748 | my $var_ref = $w->cget('-variable'); | ||
| 1749 | return unless ($$var_ref =~ /\S/o); #TEXT FIELD EMPTY, PUNT! | ||
| 1750 | |||
| 1751 | my @listsels = $w->getText('0','end'); | ||
| 1752 | my $srchPattern = $$var_ref; | ||
| 1753 | my $found = $w->LbFindSelection(0); #SEARCH FOR CURRENT TEXT: RETURNS 1 IF FULL MATCH (IN LIST), -1 IF CONTAINS, 0 IF NO MATCH. | ||
| 1754 | if ($found) | ||
| 1755 | { | ||
| 1756 | my $index; | ||
| 1757 | $index = $w->LbIndex(2) if ($found < 0 && $w->LbFindSelection(0,$srchPattern)); #IF MATCH ONLY CONTAINS TEXT, SEARCH AGAIN STARTING AT *NEXT* ENTRY. | ||
| 1758 | if (defined $index) { | ||
| 1759 | $$var_ref = $w->reference($listsels[$index]); | ||
| 1760 | $e->icursor('end'); | ||
| 1761 | $e->selectionRange(0,'end') unless ($w->{'-noselecttext'} || !$e->index('end')); | ||
| 1762 | $same = 0; | ||
| 1763 | } | ||
| 1764 | } | ||
| 1765 | elsif ($w->{'-tabcomplete'} == 2) | ||
| 1766 | { | ||
| 1767 | #THIS CODE FORCES TAB TO CHANGE TEXT ENTERED TO THE DEFAULT VALUE IF NOTHING MATCHED! | ||
| 1768 | #THIS SUCKS IF THERE IS NO LIST OR USER WISHES TO OVERRIDE THE VALUE AND THEN TAB ON! | ||
| 1769 | unless ($$var_ref eq ((defined $w->{'default'}) ? $w->{'default'} : '')) | ||
| 1770 | { | ||
| 1771 | $$var_ref = (defined $w->{'default'}) ? $w->{'default'} : ''; | ||
| 1772 | $e->icursor('end'); | ||
| 1773 | $same = 0; | ||
| 1774 | } | ||
| 1775 | } | ||
| 1776 | $e->selectionRange(0,'end') unless ($w->{'-noselecttext'} || !$e->index('end')); | ||
| 1777 | } | ||
| 1778 | else | ||
| 1779 | { | ||
| 1780 | $w->{'searchindx'} = 0; | ||
| 1781 | } | ||
| 1782 | |||
| 1783 | my $wasPoppedAlready = $w->{'popped'}; | ||
| 1784 | $w->Popdown(1) if ($wasPoppedAlready); #UNDISPLAYS LISTBOX. | ||
| 1785 | if ($same) #TEXT NOT CHANGED BY TAB-COMPLETION: | ||
| 1786 | { | ||
| 1787 | my $state = $w->cget('-state'); | ||
| 1788 | if (!$wasPoppedAlready && $w->{'-altbinding'} =~ /Tab\=Popup/io | ||
| 1789 | && $state !~ /(?:text|disabled)/o) | ||
| 1790 | { | ||
| 1791 | $w->PopupChoices; #TOGGLE STATE OF DD-LIST: | ||
| 1792 | } | ||
| 1793 | else #JUST TRY TO GO TO NEXT WIDGET IN MAIN WINDOW: | ||
| 1794 | { | ||
| 1795 | my $self = shift; | ||
| 1796 | $self->focusNext; | ||
| 1797 | } | ||
| 1798 | } | ||
| 1799 | Tk->break; | ||
| 1800 | }); | ||
| 1801 | |||
| 1802 | $f->bind('<Tab>', sub | ||
| 1803 | { | ||
| 1804 | #NEXT LINE ADDED 20030531 PER PATCH BY FRANK HERRMANN. | ||
| 1805 | $w->Callback(-browsecmd => $w, $w->Subwidget('entry')->get, 'frame.tab') | ||
| 1806 | if ($w->{'-browse'} == 1); | ||
| 1807 | $w->{'searchindx'} = 0; | ||
| 1808 | my $wasPoppedAlready = $w->{'popped'}; | ||
| 1809 | $w->Popdown(1) if ($wasPoppedAlready); #UNDISPLAYS LISTBOX. | ||
| 1810 | my $state = $w->cget('-state'); | ||
| 1811 | if (!$wasPoppedAlready && $w->{'-altbinding'} =~ /Tab\=Popup/io | ||
| 1812 | && $state !~ /(?:text|disabled)/o) | ||
| 1813 | { | ||
| 1814 | $w->PopupChoices; | ||
| 1815 | } | ||
| 1816 | else #TRY TO GO TO NEXT WIDGET IN MAIN WINDOW: | ||
| 1817 | { | ||
| 1818 | shift->focusNext; | ||
| 1819 | } | ||
| 1820 | Tk->break; | ||
| 1821 | }); | ||
| 1822 | |||
| 1823 | # KEYBOARD BINDINGS FOR LISTBOX | ||
| 1824 | |||
| 1825 | $l->configure(-selectmode => 'browse'); | ||
| 1826 | |||
| 1827 | local *ListboxMoused = sub { | ||
| 1828 | if ($w->cget('-state') =~ /^(?:normal|readonly)/) | ||
| 1829 | { | ||
| 1830 | my $self = shift; | ||
| 1831 | my $keyModifier = shift || ''; | ||
| 1832 | my $s = $w->Subwidget("slistbox"); | ||
| 1833 | my $e = $s->XEvent; | ||
| 1834 | |||
| 1835 | $s->focus; | ||
| 1836 | $w->LbClose unless (defined $e); #POPS DOWN (ROLLS UP LIST) | ||
| 1837 | $w->LbChoose($l->XEvent->x, $l->XEvent->y, $keyModifier); | ||
| 1838 | if (($w->{'-altbinding'} !~ /List\=Bouncy/io || $keyModifier =~ /mod/o) | ||
| 1839 | && $w->{'-fixedlist'} && !$w->{'popped'}) #"POP UP" DD-LIST W/O ACTUALLY POPPING IT UP (CALLING PopupChoices() PUTS FOCUS BACK ON ENTRY FIELD)! | ||
| 1840 | { | ||
| 1841 | $s->Subwidget($w->{'-listboxtype'})->configure('-takefocus' => 1); | ||
| 1842 | $w->{'popped'} = 1; | ||
| 1843 | #MUSN'T DO (& DON'T NEED!): $w->LbFindSelection(0); | ||
| 1844 | $s->see('active'); | ||
| 1845 | $w->Subwidget('choices')->configure(-cursor => 'arrow'); | ||
| 1846 | $w->{'_ignorefocus'} = 1; | ||
| 1847 | } | ||
| 1848 | else | ||
| 1849 | { | ||
| 1850 | $w->{'_lbignorefocus'} = 1 if ($w->{'-fixedlist'} && $w->{'-altbinding'} =~ /List\=Bouncy/io && $keyModifier !~ /mod/o); | ||
| 1851 | $w->{'_ignorefocus'} = 0; | ||
| 1852 | $w->focus; | ||
| 1853 | } | ||
| 1854 | } | ||
| 1855 | Tk->break; | ||
| 1856 | }; | ||
| 1857 | |||
| 1858 | $l->bind('<Shift-ButtonRelease-1>', [\&ListboxMoused,'mod.Shift']); | ||
| 1859 | $l->bind('<Control-ButtonRelease-1>', [\&ListboxMoused,'mod.Control']); | ||
| 1860 | $l->bind('<Alt-ButtonRelease-1>', [\&ListboxMoused,'mod.Alt']); | ||
| 1861 | $l->bind('<ButtonRelease-1>', [\&ListboxMoused]); | ||
| 1862 | $l->bind('<Escape>' => sub #[Escape] PRESSED IN DD-LIST (CLEAR ANY ENTRY SELECTED AND ROLL IT UP): | ||
| 1863 | { | ||
| 1864 | $w->{'_ignorefocus'} = 0; | ||
| 1865 | $w->LbClose; | ||
| 1866 | Tk->break; | ||
| 1867 | }); | ||
| 1868 | |||
| 1869 | $l->bind('<Return>' => sub #[Return] PRESSED IN DD-LIST (COPY SELECTED ENTRY TO TEXT FIELD): | ||
| 1870 | { | ||
| 1871 | $w->{'_ignorefocus'} = 0; | ||
| 1872 | $w->LbCopySelection(0,'listbox.return'); | ||
| 1873 | Tk->break; | ||
| 1874 | }); | ||
| 1875 | |||
| 1876 | $l->bind('<space>' => sub #[Spacebar] PRESSED IN DD-LIST (COPY SELECTED ENTRY TO TEXT FIELD): | ||
| 1877 | { | ||
| 1878 | $w->{'_ignorefocus'} = 0; | ||
| 1879 | my $dontrollup = ($w->{'-altbinding'} =~ /Tab\=KeepList/i) ? -1 : 0; | ||
| 1880 | $w->LbCopySelection($dontrollup,'listbox.space',1); | ||
| 1881 | Tk->break; | ||
| 1882 | }); | ||
| 1883 | |||
| 1884 | $l->bind('<Tab>' => sub #[Tab] PRESSED IN DD-LIST: | ||
| 1885 | { | ||
| 1886 | #THE TRICK HERE IS WE WANT TO UN-POP (ROLL-UP) THE DD-LIST WHEN TABBING OFF OF | ||
| 1887 | #IT UNLESS "Tab=KeepList" IS SET AND WE'RE NOT A "FIXED" LIST: | ||
| 1888 | $w->{'_ignorefocus'} = 0; | ||
| 1889 | if ($w->{'-tabcomplete'}) #IF TAB COMPLETES SELECTION, SET TEXT FIELD TO NEAREST MATCH IN LIST: | ||
| 1890 | { | ||
| 1891 | # #WE'RE DOING TAB-COMPLETE, SO FIND THE NEAREST MATCHING ITEM IN DD-LIST AND SET TEXT TO IT: | ||
| 1892 | my @listsels = $w->getText('0','end'); | ||
| 1893 | my $index = $w->LbIndex(2); | ||
| 1894 | if (defined $index) | ||
| 1895 | { | ||
| 1896 | my $var_ref = $w->cget('-variable'); | ||
| 1897 | my $index_value = $w->reference($listsels[$index]); | ||
| 1898 | $$var_ref = $index_value unless ($$var_ref eq $index_value); | ||
| 1899 | } | ||
| 1900 | } | ||
| 1901 | if ($w->{'-altbinding'} !~ /Tab\=KeepList/io | ||
| 1902 | && $w->{'-altbinding'} !~ /Tab\=Popup/io) #THIS LAST TEST JUST TO PREVENT TRAPPING USER IN A TABBING CIRCLEJERK BETWEEN DD-LIST AND ENTRY FIELD! | ||
| 1903 | { | ||
| 1904 | #BEHAVE LIKE MODERN COMBOS - SIMPLY HIDE THE LISTBOX AND FOCUS BACK ON THE TEXT FIELD | ||
| 1905 | #W/O CHANGING IT'S CONTENT: | ||
| 1906 | #NOTE: IF WE'RE A "FIXED" LIST, WE *MUST* CALL "Popdown" EVEN THOUGH THE | ||
| 1907 | #LIST *ALWAYS* REMAINS DISPLAYED, THE PGM IS TOLD THAT IT'S "POPPED DOWN"!! | ||
| 1908 | if ($w->{'-altbinding'} !~ /Tab\=Popup/io) #GO TO NEXT WIDGET: | ||
| 1909 | { | ||
| 1910 | $w->Popdown; #ROLLS UP DD-LIST (WHEN NOT FIXED), THEN MOVES FOCUS (BACK) TO THE ENTRY FIELD. | ||
| 1911 | Tk->break; #WE'VE SET FOCUS, SO DON'T LET TAB DO IT'S NORMAL THING AND MOVE FOCUS! | ||
| 1912 | } | ||
| 1913 | else #GO BACK TO CURRENT WIDGET'S ENTRY (OR BUTTON): | ||
| 1914 | { | ||
| 1915 | $w->Popdown(1); #ROLLS UP DD-LIST (WHEN NOT FIXED) & LETS TAB MOVE FOCUS TO *NEXT* WIDGET (DON'T WANT TO END UP IN A TABBING CIRCLEJERK)! | ||
| 1916 | } | ||
| 1917 | } | ||
| 1918 | else #BEHAVE OUR OLD WAY: LEAVE DD-LIST SHOWING (DON'T "Popdown"), BUT PUT FOCUS ON THE TEXT FIELD W/O CHANGING IT'S CONTENT (UNLESS "TAB-COMPLETE" CHANGES IT): | ||
| 1919 | { | ||
| 1920 | $w->Popdown(1) unless ($w->{'-altbinding'} =~ /Tab\=KeepList/io); | ||
| 1921 | #SET THE TEXT CURSOR TO END AND HIGHLIGHT (UNLESS -noselectext): | ||
| 1922 | $e->icursor('end'); | ||
| 1923 | $e->selectionRange(0,'end') unless ($w->{'-noselecttext'} || !$e->index('end')); | ||
| 1924 | $w->focus; #MANUALLY MOVE FOCUS BACK TO THE ENTRY FIELD (OR BUTTON). | ||
| 1925 | Tk->break; #WE'VE SET FOCUS, SO DON'T LET TAB DO IT'S NORMAL THING AND MOVE FOCUS! | ||
| 1926 | } | ||
| 1927 | }); | ||
| 1928 | |||
| 1929 | $l->bind('<<LeftTab>>' => sub #[Shift-Tab] (REVERSE-TAB) PRESSED IN DD-LIST: | ||
| 1930 | { | ||
| 1931 | $w->{'_ignorefocus'} = 0; #MAKE SURE THE WIDGET WILL TAKE THE FOCUS. | ||
| 1932 | $w->Popdown; #THIS ROLLS UP DD-LIST (WHEN NOT FIXED), THEN ALWAYS MOVES FOCUS (BACK) TO THE ENTRY FIELD. | ||
| 1933 | Tk->break; #WE'VE SET FOCUS, SO DON'T LET TAB DO IT'S NORMAL THING AND MOVE FOCUS! | ||
| 1934 | }); | ||
| 1935 | |||
| 1936 | if ($w->{'-deleteitemsok'}) #USER IS ALLOWED TO DELETE DD-LIST ENTRIES W/[Delete] KEY: | ||
| 1937 | { | ||
| 1938 | $l->bind('<Delete>' => sub #[Delete] KEY PRESSED IN DD-LIST (DELETE SELECTED ENTRY, IF USER ALLOWED TO): | ||
| 1939 | { | ||
| 1940 | my $index = $w->LbIndex; | ||
| 1941 | |||
| 1942 | $w->{'_ignorefocus'} = 0; | ||
| 1943 | if (defined($index) && $index >= 0) | ||
| 1944 | { | ||
| 1945 | my $x = $w->Callback('-deletecmd', $w, $w->LbIndex); #CALL 1ST (W/INDEX OF ITEM 2B DELETED) BEFORE DELETING (PROGRAMMER CAN BLOCK THE DELETE PENDING THE RESULT)! | ||
| 1946 | if (!defined($x) || !$x) #IF NO CALLBACK -OR- CALLBACK RETURNS FALSE, DELETE THE ITEM HIGHLIGHTED: | ||
| 1947 | { | ||
| 1948 | $w->delete($index); | ||
| 1949 | $w->Callback('-deletecmd', $w, -1); #CALL AGAIN W/-1 TO ALLOW PROGRAMMER TO DO SOMETHING WHEN DELETED, IE. UPDATE A CURRENT ITEM LIST VARABLE, ETC! | ||
| 1950 | #NEXT 2 ADDED 20190131 (v5.22) TO SELECT NOW-ACTIVE ITEM AFTER DELETE: | ||
| 1951 | $index = $w->LbIndex(1); | ||
| 1952 | $l->selectionSet($index); | ||
| 1953 | } | ||
| 1954 | } | ||
| 1955 | }); #ADDED 20060429 TO SUPPORT OPTION FOR USER DELETION OF LISTBOX ITEMS. | ||
| 1956 | } | ||
| 1957 | if ($ENV{'jwtlistboxhack'}) { #WE'RE USIN' OUR HACKED LISTBOX THAT CAN TELL US IF WE'RE AT TOP OR BOTTOM!: | ||
| 1958 | $l->bind('<<ListboxTop>>' => sub { | ||
| 1959 | if ($w->{'-altbinding'} =~ /Listbox\=Circular/io) { #WE'RE AT TOP OF CIRCULAR LIST, SO CIRCLE BACK TO BOTTOM!: | ||
| 1960 | $l->selectionClear('0','end'); | ||
| 1961 | $l->activate('end'); | ||
| 1962 | $l->selectionSet('end'); | ||
| 1963 | $l->update(); | ||
| 1964 | $l->see('end'); | ||
| 1965 | Tk->break; | ||
| 1966 | } elsif ($w->{'-altbinding'} =~ /(?:Down|Up)\=Popup/io) { #WE'RE AT TOP, UN-POP THE LISTBOX!: | ||
| 1967 | $w->Popdown; | ||
| 1968 | $e->icursor('end'); | ||
| 1969 | $e->selectionRange(0,'end') unless ($w->{'-noselecttext'} || !$e->index('end')); #ADDED 20020716 | ||
| 1970 | } | ||
| 1971 | }); | ||
| 1972 | $l->bind('<<ListboxBottom>>' => sub { | ||
| 1973 | if ($w->{'-altbinding'} =~ /Listbox\=Circular/io) { #WE'RE AT BOTTOM OF CIRCULAR LIST, SO CIRCLE BACK TO TOP!: | ||
| 1974 | $l->selectionClear('0','end'); | ||
| 1975 | $l->activate(0); | ||
| 1976 | $l->selectionSet(0); | ||
| 1977 | $l->update(); | ||
| 1978 | $l->see(0); | ||
| 1979 | Tk->break; | ||
| 1980 | } elsif ($w->{'-altbinding'} =~ /(?:Down|Up)\=Popup/io) { #WE'RE AT TOP, UN-POP THE LISTBOX!: | ||
| 1981 | $w->Popdown; | ||
| 1982 | $e->icursor('end'); | ||
| 1983 | $e->selectionRange(0,'end') unless ($w->{'-noselecttext'} || !$e->index('end')); #ADDED 20020716 | ||
| 1984 | } | ||
| 1985 | }); | ||
| 1986 | } | ||
| 1987 | $l->bind('<Key>' => [\&keyFn,$w,$e,$l,1]); | ||
| 1988 | $e->bind('<Key>' => [\&keyFn,$w,$e,$l]); | ||
| 1989 | $f->bind('<Key>' => [\&keyFn,$w,$e,$l]); | ||
| 1990 | $e->bind('<ButtonRelease-1>' => sub { #MOUSE CLICKED ON ENTRY FIELD: | ||
| 1991 | my ($state) = $w->cget( '-state' ); | ||
| 1992 | if ($state eq 'readonly' && !$w->{'-fixedlist'}) | ||
| 1993 | { | ||
| 1994 | my $res = $w->LbFindSelection(0); | ||
| 1995 | if ($w->{'popped'}) #LISTBOX IS SHOWING: | ||
| 1996 | { | ||
| 1997 | $w->Popdown(1); | ||
| 1998 | } | ||
| 1999 | else | ||
| 2000 | { | ||
| 2001 | unless ($res) #ADDED 20090320 TO CAUSE DROP-DOWN LIST TO POP DOWN W/ACTIVE CURSOR IN RIGHT PLACE (INSTEAD OF BOTTOM) IF ENTRY FIELD EMPTY. | ||
| 2002 | { | ||
| 2003 | $l->selectionClear('0','end'); | ||
| 2004 | $l->activate(0); | ||
| 2005 | $l->selectionSet(0); | ||
| 2006 | $l->update(); | ||
| 2007 | $l->see(0); | ||
| 2008 | } | ||
| 2009 | $w->PopupChoices; | ||
| 2010 | } | ||
| 2011 | Tk->break; | ||
| 2012 | } | ||
| 2013 | else | ||
| 2014 | { | ||
| 2015 | $w->Popdown if ($w->{'popped'}); | ||
| 2016 | Tk->break; | ||
| 2017 | } | ||
| 2018 | }); | ||
| 2019 | |||
| 2020 | #NEXT 3 LINES ADDED 20030531 PER PATCH BY FRANK HERRMANN. | ||
| 2021 | # ALLOW CLICK OUTSIDE THE POPPED UP LISTBOX TO POP IT DOWN. | ||
| 2022 | |||
| 2023 | $w->bind('<ButtonRelease-1>', sub | ||
| 2024 | { | ||
| 2025 | $w->Popdown(1) if ($w->{'popped'}); | ||
| 2026 | Tk->break; | ||
| 2027 | }); | ||
| 2028 | |||
| 2029 | $w->parent->bind('<ButtonRelease-1>', sub | ||
| 2030 | { | ||
| 2031 | $w->Popdown(1) if ($w->{'popped'}); | ||
| 2032 | Tk->break; | ||
| 2033 | }); | ||
| 2034 | |||
| 2035 | $w->bind('<FocusIn>', \&focus); | ||
| 2036 | } | ||
| 2037 | |||
| 2038 | sub keyFn #JWT: TRAP LETTERS PRESSED AND ADJUST SELECTION ACCORDINGLY. | ||
| 2039 | { | ||
| 2040 | my ($x,$w,$e,$l,$flag) = @_; #FLAG IS 1 IF CALLED FROM THE LISTBOX. | ||
| 2041 | my $mykey = $x->XEvent->A; #DOESN'T SEEM TO GET CALLED IF USER TYPES A SPACE?! | ||
| 2042 | |||
| 2043 | $flag = 0 unless (defined $flag); | ||
| 2044 | #NEXT LINE ADDED 20030531 PER PATCH BY FRANK HERRMANN. | ||
| 2045 | if (!$flag && $w->{'-browse'} == 1 && ($mykey =~ /\S/o || $mykey eq ' ')) { | ||
| 2046 | $w->Callback(-browsecmd => $w, $w->Subwidget('entry')->get, "key.$mykey"); | ||
| 2047 | } | ||
| 2048 | |||
| 2049 | if ($w->cget( '-state' ) eq 'readonly') #ADDED 20020711 TO ALLOW TYPING 1ST LETTER TO SELECT NEXT VALID ITEM! | ||
| 2050 | { | ||
| 2051 | if ($mykey) { | ||
| 2052 | $w->PopupChoices unless ($w->{'popped'}); #LISTBOX IS NOT SHOWING: SHOW IT!: | ||
| 2053 | $w->LbFindSelection(0,$mykey); #JUMP TO 1ST ITEM STARTING WITH THIS KEY | ||
| 2054 | } | ||
| 2055 | } | ||
| 2056 | elsif ($flag == 1) #LISTBOX HAS FOCUS: | ||
| 2057 | { | ||
| 2058 | $w->{'_ignorefocus'} = 0; | ||
| 2059 | $w->LbFindSelection(0,$mykey) if ($mykey =~ /\S/o); #JUMP TO NEXT ITEM STARTING WITH THIS KEY | ||
| 2060 | } | ||
| 2061 | else #TEXT FIELD HAS FOCUS: | ||
| 2062 | { | ||
| 2063 | $w->LbFindSelection(0) if ($mykey =~ /\S/o); #JUMP TO 1ST ITEM MATCHING TEXT FIELD. | ||
| 2064 | if (!$flag && $w->{'-browse'} == 1 && ($mykey =~ /\S/o || $mykey eq ' ')) { | ||
| 2065 | $w->Subwidget('entry')->selectionRange(0,'end') | ||
| 2066 | unless ($w->{'-noselecttext'} || !$w->Subwidget('entry')->index('end')); | ||
| 2067 | $e->icursor('end'); | ||
| 2068 | } | ||
| 2069 | } | ||
| 2070 | } | ||
| 2071 | |||
| 2072 | sub PressButton #NEW USER-CALLABLE FUNCTION (v5.0+) TO EFFECT A DROP-DOWN BUTTON PRESS (POPUP DD-LIST & GIVE IT FOCUS): | ||
| 2073 | { | ||
| 2074 | my $w = shift; | ||
| 2075 | my $nofocussave = shift||0; | ||
| 2076 | my $state = $w->cget( '-state' ); | ||
| 2077 | return 0 if ($state =~ /text/o || $state eq 'disabled'); | ||
| 2078 | |||
| 2079 | $w->{'savefocus'} = $w->focusCurrent unless ($nofocussave); | ||
| 2080 | $w->PopupChoices; | ||
| 2081 | return 1; | ||
| 2082 | } | ||
| 2083 | |||
| 2084 | sub PopupChoices #TOGGLE STATE OF DD-LIST (POP UP OR DOWN): | ||
| 2085 | { | ||
| 2086 | my $w = shift; | ||
| 2087 | my ($state) = $w->cget( '-state' ); | ||
| 2088 | |||
| 2089 | return if ($state =~ /text/o || $state eq 'disabled'); | ||
| 2090 | return unless ($w->getText('0','end')); | ||
| 2091 | |||
| 2092 | if ($w->{'popped'}) #DD-LIST DISPLAYED, ROLL IT UP: | ||
| 2093 | { | ||
| 2094 | $w->Popdown(1); | ||
| 2095 | } | ||
| 2096 | else #DD-LIST NOT DISPLAYED, POP IT UP: | ||
| 2097 | { | ||
| 2098 | my $x = $w->Callback(-listcmd, $w, $w->Subwidget('entry')->get); | ||
| 2099 | return undef if (defined($x) && $x =~ /nolist/io); #IF -listcmd CALLBACK RETURNS 'nolist', | ||
| 2100 | |||
| 2101 | my $c = $w->Subwidget('choices'); | ||
| 2102 | my $s = $w->Subwidget('slistbox'); | ||
| 2103 | if ($w->{'-fixedlist'}) #IF WE'RE A FIXED LIST (ALWAYS DISPLAYED), JUST MARK IT POPPED UP & GIVE IT FOCUS: | ||
| 2104 | { | ||
| 2105 | $s->Subwidget($w->{'-listboxtype'})->configure('-takefocus' => 1); | ||
| 2106 | $w->{'popped'} = 1; | ||
| 2107 | $w->LbFindSelection(0); | ||
| 2108 | $s->see('active'); | ||
| 2109 | $c->configure(-cursor => 'arrow'); | ||
| 2110 | $s->focus; | ||
| 2111 | $w->grab; | ||
| 2112 | return; | ||
| 2113 | } | ||
| 2114 | my $e = $w->Subwidget('entry'); | ||
| 2115 | my $a = $w->Subwidget('arrow'); | ||
| 2116 | my $wheight = $w->cget('-height'); | ||
| 2117 | my $sll = $s->Subwidget($w->{'-listboxtype'}); | ||
| 2118 | my $rw = $c->width; | ||
| 2119 | my ($itemcnt) = $sll->index('end'); | ||
| 2120 | $wheight = 10 unless ($wheight); | ||
| 2121 | $wheight = $itemcnt if ($itemcnt < $wheight); | ||
| 2122 | $wheight = $itemcnt unless ($wheight); | ||
| 2123 | $wheight = $itemcnt unless ($wheight || $itemcnt > 10); | ||
| 2124 | if ($wheight) | ||
| 2125 | { | ||
| 2126 | $sll->configure(-height => ($wheight * $w->height)); | ||
| 2127 | $w->update; | ||
| 2128 | } | ||
| 2129 | |||
| 2130 | my $y1 = $e->rooty + $e->height + 3; | ||
| 2131 | #my $bd = $c->cget(-bd) + $c->cget(-highlightthickness); #CHGD. TO NEXT 20050120. | ||
| 2132 | my $bd = $c->cget(-bd); | ||
| 2133 | my ($unitpixels, $ht, $x1, $ee, $width, $x2); | ||
| 2134 | if ($bummer) | ||
| 2135 | { | ||
| 2136 | $y1 -= 3 - ($w->{'-borderheight'} || 2); | ||
| 2137 | #$unitpixels = $e->height + 1; #CHGD. TO NEXT 20040827 - WINBLOWS XP SEEMS TO NOT BEVEL THE HIGHLIGHT CURSOR, | ||
| 2138 | $unitpixels = $e->height - 1; #SO THE WIDTH OF EACH ITEM IS NOW 2 PIXELS SMALLER! (USE OLD LINE, IF BEVELLED)! | ||
| 2139 | $ht = ($wheight * $unitpixels) + (2 * $bd) + 4; | ||
| 2140 | $ee = $w->Subwidget('frame'); | ||
| 2141 | $x1 = $ee->rootx; | ||
| 2142 | $x2 = $a->rootx + $a->width; | ||
| 2143 | $width = ($w->{'-nobutton'}) ? ($e->width + ($w->{'-borderwidth'} || 2)) : ($x2 - $x1); | ||
| 2144 | if ($w->{'-nobutton'}) | ||
| 2145 | { | ||
| 2146 | my $wheight = $w->cget('-height'); | ||
| 2147 | if (defined($wheight) && $wheight > 0) { | ||
| 2148 | my $itemcnt = $sll->index('end'); | ||
| 2149 | $width += $s->Subwidget('yscrollbar')->cget('-width') + 6; | ||
| 2150 | } | ||
| 2151 | } | ||
| 2152 | #$rw = $width + $w->{'-borderwidth'}; | ||
| 2153 | #CHGD. TO NEXT 20030531 PER PATCH BY FRANK HERRMANN. | ||
| 2154 | #$rw = ($width || 0) + ($w->{'-borderwidth'} || 0); | ||
| 2155 | $rw = $width; | ||
| 2156 | $x1 += 1; #FUDGE MORE FOR WINDOWS (THINNER BORDER) TO MAKE DROP-DOWN LINE UP VERTICALLY W/ENTRY&BUTTON. | ||
| 2157 | } | ||
| 2158 | else | ||
| 2159 | { | ||
| 2160 | $y1 -= 3 - ($w->{'-borderheight'} || 2); | ||
| 2161 | #$unitpixels = $e->height - 1; #CHGD. TO NEXT 2 20050120. | ||
| 2162 | $unitpixels = $e->height - (2 * $w->cget('-highlightthickness')); | ||
| 2163 | $unitpixels += 1; | ||
| 2164 | $ht = ($wheight * $unitpixels) + (2 * $bd) + 6; | ||
| 2165 | $ee = $w->Subwidget('frame'); | ||
| 2166 | $x1 = $ee->rootx; | ||
| 2167 | $x2 = $a->rootx + $a->width; | ||
| 2168 | $width = ($w->{'-nobutton'}) ? ($e->width + ($w->{'-borderwidth'} || 2)) : ($x2 - $x1); | ||
| 2169 | if ($w->{'-nobutton'}) | ||
| 2170 | { | ||
| 2171 | my $wheight = $w->cget('-height'); | ||
| 2172 | if (defined($wheight) && $wheight > 0) { | ||
| 2173 | my $itemcnt = $sll->index('end'); | ||
| 2174 | $width += $s->Subwidget('yscrollbar')->cget('-width') + 6; | ||
| 2175 | } | ||
| 2176 | } | ||
| 2177 | $rw = $width; #ADDED 20020815 TO CAUSE LISTBOX TO ADJUST WIDTH TO SAME AS VARYING ENTRY FIELD! | ||
| 2178 | # if ($first) -- REMOVED 20070904 PER PATCH BY WOLFRAM HUMANN | ||
| 2179 | # { | ||
| 2180 | #NEXT LINE ADDED 20030531 PER PATCH BY FRANK HERRMANN. | ||
| 2181 | $w->{'-borderwidth'} = 0 unless (defined $w->{'-borderwidth'}); | ||
| 2182 | # $rw += 1 + int($w->{'-borderwidth'} / 2); -- CHGD. TO NEXT 20070904 - SEEMS TO WORK BETTER! | ||
| 2183 | $rw += $w->{'-borderwidth'}; | ||
| 2184 | # $first = 0; -- REMOVED 20070904 PER PATCH BY WOLFRAM HUMANN | ||
| 2185 | #THANKS, WOLFRAM! | ||
| 2186 | # } | ||
| 2187 | |||
| 2188 | # IF LISTBOX IS TOO FAR RIGHT, PULL IT BACK TO THE LEFT | ||
| 2189 | |||
| 2190 | $x1 = $w->vrootwidth - $width if ($x2 > $w->vrootwidth); | ||
| 2191 | $x1 += 1; #FUDGE MORE FOR WINDOWS (THINNER BORDER) TO MAKE DROP-DOWN LINE UP VERTICALLY W/ENTRY&BUTTON. | ||
| 2192 | } | ||
| 2193 | |||
| 2194 | # IF LISTBOX IS TOO FAR LEFT, PULL IT BACK TO THE RIGHT | ||
| 2195 | |||
| 2196 | $x1 = 0 if ($x1 < 0); | ||
| 2197 | |||
| 2198 | # IF LISTBOX IS BELOW BOTTOM OF SCREEN, PULL IT UP. | ||
| 2199 | |||
| 2200 | my $y2 = $y1 + $ht; | ||
| 2201 | $y1 = $y1 - $ht - ($e->height - 5) if ($y2 > $w->vrootheight); | ||
| 2202 | $c->geometry(sprintf('%dx%d+%d+%d', $rw, $ht, $x1, $y1)); | ||
| 2203 | $c->deiconify; | ||
| 2204 | $c->raise; | ||
| 2205 | $s->focus; | ||
| 2206 | $w->{'popped'} = 1; | ||
| 2207 | |||
| 2208 | $w->LbFindSelection(0); | ||
| 2209 | $s->see('active'); | ||
| 2210 | $c->configure(-cursor => 'arrow'); | ||
| 2211 | $w->grabGlobal; | ||
| 2212 | $s->focus; | ||
| 2213 | } | ||
| 2214 | } | ||
| 2215 | |||
| 2216 | sub LbChoose # CHOOSE VALUE FROM LISTBOX WITH THE MOUSE IF APPROPRIATE. | ||
| 2217 | { | ||
| 2218 | my ($w, $x, $y, $keyModifier) = @_; | ||
| 2219 | my $l = $w->Subwidget('slistbox')->Subwidget($w->{'-listboxtype'}); | ||
| 2220 | |||
| 2221 | $keyModifier ||= '' unless (defined $keyModifier); | ||
| 2222 | $keyModifier .= '-' if ($keyModifier =~ /\S/o); | ||
| 2223 | if ((($x < 0) || ($x > $l->Width)) || (($y < 0) || ($y > $l->Height))) | ||
| 2224 | { | ||
| 2225 | # MOUSE WAS CLICKED OUTSIDE THE LISTBOX... CLOSE THE LISTBOX | ||
| 2226 | $w->LbClose; | ||
| 2227 | } | ||
| 2228 | else | ||
| 2229 | { | ||
| 2230 | #NEXT 5 ADDED @v5 FROM Tk::BrowseEntry DUE TO STUFF NOT ALWAYS BEING SELECTED W/MOUSE: | ||
| 2231 | my $inx = $l->nearest($y); | ||
| 2232 | if (defined $inx) { | ||
| 2233 | $l->selectionClear(0, "end"); | ||
| 2234 | $l->selectionSet($inx); | ||
| 2235 | } | ||
| 2236 | # SELECT APPROPRIATE ENTRY AND CLOSE THE LISTBOX | ||
| 2237 | my $popornotFlag = $w->{'-fixedlist'} ? -1 : 0; | ||
| 2238 | $w->LbCopySelection($popornotFlag,"listbox.${keyModifier}button1"); | ||
| 2239 | } | ||
| 2240 | } | ||
| 2241 | |||
| 2242 | sub LbClose # CLOSE THE LISTBOX AFTER CLEARING SELECTION. | ||
| 2243 | { | ||
| 2244 | my $w = shift; | ||
| 2245 | my $l = $w->Subwidget('slistbox')->Subwidget($w->{'-listboxtype'}); | ||
| 2246 | $l->selection('clear', 0, 'end'); | ||
| 2247 | $w->Popdown; | ||
| 2248 | } | ||
| 2249 | |||
| 2250 | # COPY THE LISTBOX-SELECTION TO THE ENTRY FIELD, AND CLOSE (ROLL UP) LISTBOX (UNLESS JUSTCOPY SET). | ||
| 2251 | |||
| 2252 | sub LbCopySelection | ||
| 2253 | { | ||
| 2254 | my ($w, $justcopy, $action, $forceSelect) = @_; | ||
| 2255 | my $index = $w->LbIndex($forceSelect); | ||
| 2256 | my $e = $w->Subwidget('entry'); | ||
| 2257 | |||
| 2258 | if (defined $index) | ||
| 2259 | { | ||
| 2260 | my $var_ref = $w->cget('-variable'); | ||
| 2261 | $$var_ref = $w->reference($w->getText($index)); | ||
| 2262 | $e->icursor('end'); | ||
| 2263 | $e->selectionRange(0,'end') unless ($w->{'-noselecttext'} || !$e->index('end')); | ||
| 2264 | } | ||
| 2265 | if ($justcopy <= 0) #1 MEANS JUST COPY, NO SEARCH & CALLBACK -1 MEANS LEAVE DD-LIST UP & FOCUSED (USER CLICKED ON IT!): | ||
| 2266 | { | ||
| 2267 | $w->Popdown unless ($justcopy < 0); # ROLL UP THE LISTBOX, SINCE IT'S VISIBLE: | ||
| 2268 | my $altbinding = $w->{'-altbinding'}; | ||
| 2269 | if ($altbinding =~ /NoListbox\=([^\;]+)/io) { | ||
| 2270 | my @noActions = split(/\,/o, $1); | ||
| 2271 | my $res; | ||
| 2272 | foreach my $i (@noActions) { | ||
| 2273 | $i = 'listbox.' . $i unless ($i =~ /listbox\./io); | ||
| 2274 | eval "\$res = (\$action =~ /^$i/i);"; | ||
| 2275 | return if ($res); | ||
| 2276 | } | ||
| 2277 | } | ||
| 2278 | my $gettext = $e->get; | ||
| 2279 | $w->Callback(-browsecmd => $w, $gettext, $action) if (defined $index); | ||
| 2280 | } | ||
| 2281 | } | ||
| 2282 | |||
| 2283 | # GRAB TEXT TYPED IN AND FIND NEAREST ENTRY IN LISTBOX AND SELECT IT. | ||
| 2284 | # LETTERSEARCH SET MEANS SEARCH FOR *NEXT* MATCH OF SPECIFIED LETTER, | ||
| 2285 | # CLEARED MEANS SEARCH FOR *1ST* ITEM STARTING WITH CURRENT TEXT ENTRY VALUE. | ||
| 2286 | # THE TRICK HERE IS THAT WHEN USER CLEARS AND THEN TYPES LETTERS INTO THE | ||
| 2287 | # TEXT BOX OR A LETTER INTO THE DROP-DOWN LIST, WE "REMEMBER" WHERE WE | ||
| 2288 | # WERE IN THE LIST SO THAT IF THEY RIGHTARROW-COMPLETE IT COMPLETES | ||
| 2289 | # THE TEXT FIELD WITH THAT ENTRY, THEN, IF THEY DO IT AGAIN, WE START | ||
| 2290 | # WITH THE NEXT INDEX SO THAT, IF THERE ARE MORE THAN ONE MATCHING | ||
| 2291 | # VALUES, THEY'LL ADVANCE TO THE *NEXT* MATCH RATHER THAN GETTING | ||
| 2292 | # IT COMPLETED WITH THE SAME ONE AGAIN!: (searchindx) | ||
| 2293 | |||
| 2294 | sub LbFindSelection | ||
| 2295 | { | ||
| 2296 | my ($w, $reverse, $srchval) = @_; | ||
| 2297 | |||
| 2298 | my $lettersearch = 0; | ||
| 2299 | if (defined($srchval) && $srchval =~ /\S/o) | ||
| 2300 | { | ||
| 2301 | $lettersearch = 1; | ||
| 2302 | } | ||
| 2303 | else | ||
| 2304 | { | ||
| 2305 | $srchval = $w->get(); | ||
| 2306 | unless (defined ($srchval) && $srchval =~ /\S/o) | ||
| 2307 | { | ||
| 2308 | $w->Subwidget('slistbox')->Subwidget($w->{'-listboxtype'})->activate(0); | ||
| 2309 | $w->{'searchindx'} = 0; | ||
| 2310 | |||
| 2311 | return 0; | ||
| 2312 | } | ||
| 2313 | } | ||
| 2314 | my $l = $w->Subwidget('slistbox')->Subwidget($w->{'-listboxtype'}); | ||
| 2315 | my @listsels = $w->getText('0','end'); | ||
| 2316 | |||
| 2317 | return 0 if ($#listsels < 0); | ||
| 2318 | |||
| 2319 | my $index = 0; | ||
| 2320 | if ($w->{'popped'} && $lettersearch) | ||
| 2321 | { | ||
| 2322 | $w->{'searchindx'} = $l->index('active'); | ||
| 2323 | $index = $reverse ? $w->{'searchindx'} : $w->{'searchindx'} + 1; | ||
| 2324 | $index = 0 if ($index > $#listsels); | ||
| 2325 | $index = $#listsels if ($index < 0); | ||
| 2326 | } | ||
| 2327 | elsif (defined $w->{'searchindx'}) | ||
| 2328 | { | ||
| 2329 | $index = $w->{'searchindx'}; | ||
| 2330 | } | ||
| 2331 | if ($reverse) { | ||
| 2332 | for (my $i=$#listsels;$i>=0;$i--) #SEARCH W/O REGARD TO CASE, START W/CURRENT SELECTION. | ||
| 2333 | { | ||
| 2334 | #if ($listsels[$index] =~ /^$srchval/i) | ||
| 2335 | #CHGD. TO NEXT 20030531 PER PATCH BY FRANK HERRMANN. | ||
| 2336 | # if (defined $srchval && $listsels[$index] =~ /^$srchval/i) #CHGD TO NEXT 20060429 TO PREVENT TK-ERROR ON "("! | ||
| 2337 | my $index_value = $w->reference($listsels[$index]); | ||
| 2338 | if ($index_value =~ /^\Q$srchval\E/i) | ||
| 2339 | { | ||
| 2340 | $l->selectionClear('0','end'); | ||
| 2341 | $l->activate($index); | ||
| 2342 | $l->selectionSet($index); | ||
| 2343 | $l->update(); | ||
| 2344 | $l->see($index); | ||
| 2345 | if ($lettersearch) { | ||
| 2346 | --$w->{'searchindx'}; | ||
| 2347 | $w->{'searchindx'} = $#listsels if ($w->{'searchindx'} < 0); | ||
| 2348 | } else { | ||
| 2349 | $w->{'searchindx'} = $index; | ||
| 2350 | } | ||
| 2351 | return ($index_value =~ /^\Q$srchval\E$/i) ? 1 : -1; #(1=EXACT MATCH, CASE INSENSITIVE, -1=MATCH CONTAINS SEARCH STRING. | ||
| 2352 | } | ||
| 2353 | --$index; | ||
| 2354 | $index = $#listsels if ($index < 0); #ROLL BACK AROUND IF AT BOTTOM. | ||
| 2355 | $w->{'searchindx'} = $index; | ||
| 2356 | } | ||
| 2357 | } else { | ||
| 2358 | foreach my $i (0..$#listsels) #SEARCH W/O REGARD TO CASE, START W/CURRENT SELECTION. | ||
| 2359 | { | ||
| 2360 | #if ($listsels[$index] =~ /^$srchval/i) | ||
| 2361 | #CHGD. TO NEXT 20030531 PER PATCH BY FRANK HERRMANN. | ||
| 2362 | # if (defined $srchval && $listsels[$index] =~ /^$srchval/i) #CHGD TO NEXT 20060429 TO PREVENT TK-ERROR ON "("! | ||
| 2363 | my $index_value = $w->reference($listsels[$index]); | ||
| 2364 | if ($index_value =~ /^\Q$srchval\E/i) | ||
| 2365 | { | ||
| 2366 | $l->selectionClear('0','end'); | ||
| 2367 | $l->activate($index); | ||
| 2368 | $l->selectionSet($index); | ||
| 2369 | $l->update(); | ||
| 2370 | $l->see($index); | ||
| 2371 | if ($lettersearch) { | ||
| 2372 | ++$w->{'searchindx'}; | ||
| 2373 | $w->{'searchindx'} = 0 if ($w->{'searchindx'} > $#listsels); | ||
| 2374 | } else { | ||
| 2375 | $w->{'searchindx'} = $index; | ||
| 2376 | } | ||
| 2377 | return ($index_value =~ /^\Q$srchval\E$/i) ? 1 : -1; #(1=EXACT MATCH, CASE INSENSITIVE, -1=MATCH CONTAINS SEARCH STRING. | ||
| 2378 | } | ||
| 2379 | ++$index; | ||
| 2380 | $index = 0 if ($index > $#listsels); #ROLL BACK AROUND IF AT BOTTOM. | ||
| 2381 | $w->{'searchindx'} = $index; | ||
| 2382 | } | ||
| 2383 | } | ||
| 2384 | $l->selectionClear('0','end'); | ||
| 2385 | $l->activate(0); | ||
| 2386 | $l->see(0); | ||
| 2387 | $w->{'searchindx'} = 0; | ||
| 2388 | return 0; #NO MATCH! | ||
| 2389 | } | ||
| 2390 | |||
| 2391 | sub LbIndex #FETCH THE INDEX OF THE SELECTED OR ACTIVE ENTRY FROM THE DD-LIST: | ||
| 2392 | { | ||
| 2393 | my ($w, $flag) = @_; | ||
| 2394 | |||
| 2395 | my $slistbox = $w->Subwidget('slistbox'); | ||
| 2396 | #CHANGED NEXT 5 TO FOLLOWING 2 (20180707) TO *NOT* TREAT ACTIVE ELEMENT AS SELECTED IF IT ISN'T. | ||
| 2397 | #SPACEBAR WILL SELECT IT, HITTING [Enter] WILL LEAVE ENTRY TEXT UNCHANGED SINCE NOTHING SELECTED - | ||
| 2398 | #I DECIDED THIS WAS PREFERRED, IN PARTICULAR IF ONE PRESSED A CHARACTER, HIT [Enter] AND NOTHING | ||
| 2399 | #MATCHES, DO NOT JUST SELECT THE CURRENTLY-ACTIVE ENTRY (THAT DOESN'T MATCH)! | ||
| 2400 | # my $sel = $w->Subwidget('slistbox')->Subwidget('listbox')->curselection | ||
| 2401 | # || $w->Subwidget('slistbox')->Subwidget('listbox')->index('active'); | ||
| 2402 | # $sel = $w->Subwidget('slistbox')->Subwidget('listbox')->index('active') | ||
| 2403 | # unless ($sel =~ /^\d+$/o); #JWT: ADDED 20040819 'CAUSE CURSELECTION SEEMS TO RETURN "ARRAY(XXXX)" NOW?!?!?! | ||
| 2404 | # return (defined $sel) ? int($sel) : 0; | ||
| 2405 | (my $sel) = $slistbox->Subwidget($w->{'-listboxtype'})->curselection; | ||
| 2406 | #REPLACE REMAINING LINES WITH COMMENTED CODE IF DESIRE IS TO SELECT ACTIVE IS NOTHING SELECTED (AS BEFORE). | ||
| 2407 | #IF NO SELECTION THEN: IF NO FLAG: undef, FLAG=0: zero(1st element), 1: active (underlined) element. | ||
| 2408 | #FLAG=2|3 && DD-LIST IS DISABLED(state==text): SAME AS 0|1 RESPECTIVELY, BUT SEARCH CHOICES FOR AN INDEX. | ||
| 2409 | #THIS IS NEEDED FOR THE TABCOMPLETE, RIGHTCOMPLETE, UP/DOWN FUNCTIONS TO STILL FIND THE NEAREST CHOICE! | ||
| 2410 | if (defined $sel) #SOMETHING'S ACTUALLY SELECTED: | ||
| 2411 | { | ||
| 2412 | return int($sel); | ||
| 2413 | } | ||
| 2414 | elsif (defined($flag) && $flag) #NOTHING SELECTED, DO WE WANT THE ACTIVE ENTRY INSTEAD? | ||
| 2415 | { | ||
| 2416 | if ($flag == 1) #WILL RETURN FIRST ENTRY(0) IF NOTHING'S ACTIVE: | ||
| 2417 | { | ||
| 2418 | return $slistbox->Subwidget($w->{'-listboxtype'})->index('active') || 0; | ||
| 2419 | } | ||
| 2420 | elsif ($flag > 1) #WE MUST FIND THE INDEX OF THE CHOICE EVEN THOUGH THE DD-LIST IS DISABLED: | ||
| 2421 | { | ||
| 2422 | if ($slistbox->cget('-state') eq 'disabled') | ||
| 2423 | { | ||
| 2424 | my @listsels = $w->getText('0','end'); | ||
| 2425 | my $index = $w->{'searchindx'} || 0; | ||
| 2426 | my $textval = $w->get(); | ||
| 2427 | if (defined($textval) && $textval =~ /\S/o) | ||
| 2428 | { | ||
| 2429 | for (my $i=0; $i<=$#listsels;$i++) | ||
| 2430 | { | ||
| 2431 | return $index if ($w->reference($listsels[$index]) =~ /^\Q$textval\E/i); | ||
| 2432 | ++$index; | ||
| 2433 | $index = 0 if ($index > $#listsels); #ROLL BACK AROUND IF AT BOTTOM. | ||
| 2434 | $w->{'searchindx'} = $index; | ||
| 2435 | } | ||
| 2436 | } | ||
| 2437 | } | ||
| 2438 | return ($flag == 3) ? 0 : undef; | ||
| 2439 | } | ||
| 2440 | } | ||
| 2441 | return undef; | ||
| 2442 | } | ||
| 2443 | |||
| 2444 | sub Popdown # POP DOWN (ROLL UP/HIDE) THE DD-LIST BOX! | ||
| 2445 | { | ||
| 2446 | my ($w, $flag) = @_; | ||
| 2447 | my ($state) = $w->cget( '-state' ); | ||
| 2448 | |||
| 2449 | if ($w->{'popped'}) #LISTBOX IS SHOWING: | ||
| 2450 | { | ||
| 2451 | if ($w->{'-fixedlist'}) { #DON'T LET FIXED DD-LIST TAKE FOCUS WHEN NOT "POPPED" (FOCUSED) W/O CALLING PopupChoices() FIRST (SO TABBING WILL WORK RIGHT)!: | ||
| 2452 | $w->Subwidget('slistbox')->Subwidget($w->{'-listboxtype'})->configure('-takefocus' => 0); | ||
| 2453 | } | ||
| 2454 | else #ROLL UP ("UN-POP") THE DD-LIST: | ||
| 2455 | { | ||
| 2456 | $w->Subwidget('choices')->withdraw; | ||
| 2457 | } | ||
| 2458 | $w->grabRelease; | ||
| 2459 | $w->{'popped'} = 0; | ||
| 2460 | $w->Subwidget('entry')->selectionRange(0,'end') | ||
| 2461 | unless ($w->{'-noselecttext'} || !$w->Subwidget('entry')->index('end')); | ||
| 2462 | } | ||
| 2463 | |||
| 2464 | if (defined($w->{'savefocus'}) && $w->{'savefocus'} && Tk::Exists($w->{'savefocus'})) #USED BY PressButton FUNCTION TO RESTORE FOCUS TO WIDGET THAT HAD IT WHEN DEVELOPER CALLED IT: | ||
| 2465 | { | ||
| 2466 | $w->{'savefocus'}->focus; | ||
| 2467 | delete $w->{'savefocus'}; | ||
| 2468 | } | ||
| 2469 | else | ||
| 2470 | { | ||
| 2471 | $w->focus unless ($flag); #WILL PUT FOCUS BACK ONTO ENTRY|FRAME|BUTTON! (flag SAYS LEAVE FOCUS WHERE IT IS!) | ||
| 2472 | } | ||
| 2473 | } | ||
| 2474 | |||
| 2475 | sub _adustLBsize #ADJUST THE DD-LIST WIDTH / HEIGHT, IF WE NEED TO: | ||
| 2476 | { | ||
| 2477 | my $w = shift; | ||
| 2478 | my @l = $w->getText(0, 'end'); | ||
| 2479 | $w->{'-width'} = $w->{'-maxwidth'} if (defined($w->{'-width'}) && defined($w->{'-maxwidth'}) && $w->{'-maxwidth'} > 0 && $w->{'-width'} > $w->{'-maxwidth'}); | ||
| 2480 | my $w_width = (defined $w->{'-width'}) ? $w->{'-width'} : 0; #NEEDED B/C PERL'S BECOME A NANNY-STATE W/WARNINGS! | ||
| 2481 | my $width = $w_width; | ||
| 2482 | unless ($width) | ||
| 2483 | { | ||
| 2484 | $width = 0; | ||
| 2485 | for (my $i=0;$i<=$#l;$i++) | ||
| 2486 | { | ||
| 2487 | $width = length($l[$i]) if ($width < length($l[$i])); | ||
| 2488 | } | ||
| 2489 | $width = $w->{'-maxwidth'} if (defined($w->{'-maxwidth'}) | ||
| 2490 | && $width > $w->{'-maxwidth'} && $w->{'-maxwidth'} > 0); | ||
| 2491 | } | ||
| 2492 | if ($w->{'-fixedlist'} || $width != $w_width) #ADJUST WIDTH IF CHANGED & ALLOWED TO CHANGE: | ||
| 2493 | { | ||
| 2494 | ++$width; | ||
| 2495 | $w->Subwidget('entry')->configure(-width => $width); | ||
| 2496 | $w->Subwidget('slistbox')->configure(-width => $width); | ||
| 2497 | } | ||
| 2498 | } | ||
| 2499 | |||
| 2500 | sub getText #GET THE ACTUAL TEXT OF ENTRIES (EVEN IF THEY'RE HList HASHES!) (WRAPS *Listbox->get & ALLOWS FOR NO ARGS TO == 0..'end'(ALL)): | ||
| 2501 | { | ||
| 2502 | my ($w, @indices) = @_; | ||
| 2503 | |||
| 2504 | @indices = (0, 'end') unless (defined $indices[0]); | ||
| 2505 | return $w->Subwidget('slistbox')->Subwidget($w->{'-listboxtype'})->get(@indices) unless ($w->{'-listboxtype'} =~ /h/o); | ||
| 2506 | |||
| 2507 | if (defined $indices[1]) #TWO INDEX ARGS GIVEN, RETURN LIST OF ITEMS BETWEEN firstArg & secondArg INCLUSIVE: | ||
| 2508 | { | ||
| 2509 | my @items = $w->Subwidget('slistbox')->Subwidget($w->{'-listboxtype'})->get(@indices); | ||
| 2510 | for (my $i=0;$i<=$#items;$i++) | ||
| 2511 | { | ||
| 2512 | $items[$i] = $w->dereference($items[$i]->{'-text'}) if (ref($items[$i]) && defined($items[$i]->{'-text'})); | ||
| 2513 | } | ||
| 2514 | return @items; #RETURNS ARRAY. | ||
| 2515 | } | ||
| 2516 | else #SINGLE INDEX ARG. GIVEN: | ||
| 2517 | { | ||
| 2518 | my $item = $w->Subwidget('slistbox')->Subwidget($w->{'-listboxtype'})->get($indices[0]); | ||
| 2519 | if (ref $item) | ||
| 2520 | { | ||
| 2521 | return (defined $item->{'-text'}) ? $w->dereference($item->{'-text'}) : ''; | ||
| 2522 | } | ||
| 2523 | return $w->dereference($item); #RETURNS SCALAR (THE SINGLE ITEM MATCHING THE INDEX: | ||
| 2524 | } | ||
| 2525 | } | ||
| 2526 | |||
| 2527 | sub choices #(RE)SET THE CHOICES IN THE DD-LIST: | ||
| 2528 | { | ||
| 2529 | my $w = shift; | ||
| 2530 | unless( @_ ) #NO ARGS, RETURN CURRENT CHOICES. | ||
| 2531 | { | ||
| 2532 | return ($w->getText( qw/0 end/ )); | ||
| 2533 | } | ||
| 2534 | else #POPULATE DROP-DOWN LIST WITH THESE CHOICES. | ||
| 2535 | { | ||
| 2536 | my $choices = shift; | ||
| 2537 | if ($choices) | ||
| 2538 | { | ||
| 2539 | $w->delete( qw/0 end/ ); | ||
| 2540 | $w->{'hashref'} = {} if (defined $w->{'hashref'}); #ADDED 20050125. | ||
| 2541 | $w->{'hashref_bydesc'} = {} if (defined $w->{'hashref_bydesc'}); #ADDED 20110226. | ||
| 2542 | $w->insert($choices); | ||
| 2543 | #NOOOOOOOOO! (INITIAL VARIABLE MAY NOT BE IN CHOICES)!: $w->activate(0); | ||
| 2544 | } | ||
| 2545 | |||
| 2546 | #NO WIDTH SPECIFIED, CALCULATE TEXT & LIST WIDTH BASED ON LONGEST CHOICE. | ||
| 2547 | |||
| 2548 | $w->_adustLBsize(); | ||
| 2549 | $w->state($w->state()); | ||
| 2550 | # return (''); | ||
| 2551 | return undef; | ||
| 2552 | } | ||
| 2553 | } | ||
| 2554 | |||
| 2555 | # INSERT NEW ITEMS INTO DROP-DOWN LIST. | ||
| 2556 | |||
| 2557 | sub insert #ADD CHOICES TO THE DD-LIST: | ||
| 2558 | { | ||
| 2559 | my $w = shift; | ||
| 2560 | my $pos = ($_[1]) ? shift : 'end'; | ||
| 2561 | my $item = shift; #POINTER TO OR LIST OF ITEMS TO INSERT. | ||
| 2562 | my $res; | ||
| 2563 | my $slistbox = $w->Subwidget('slistbox'); | ||
| 2564 | |||
| 2565 | #FORCE LISTBOX TO BE TEMP. ENABLED, IF DISABLED IN ORDER TO INSERT STUFF (WHICH IS ALLOWED, TO KEEP SYNC W/CHOICES): | ||
| 2566 | local *listboxInsert = sub { | ||
| 2567 | my $state = $slistbox->cget('-state'); | ||
| 2568 | $slistbox->configure(-state => 'normal') if ($state eq 'disabled'); | ||
| 2569 | my $res = $slistbox->insert(@_); | ||
| 2570 | $slistbox->configure(-state => $state) if ($state eq 'disabled'); | ||
| 2571 | return $res; | ||
| 2572 | }; | ||
| 2573 | |||
| 2574 | if (ref($item)) | ||
| 2575 | { | ||
| 2576 | if (ref($item) eq 'HASH') | ||
| 2577 | { | ||
| 2578 | my @choiceKeys = (); | ||
| 2579 | @choiceKeys = sort { $item->{$a} cmp $item->{$b} } keys(%$item); | ||
| 2580 | my @choiceVals = sort values(%$item); | ||
| 2581 | $res = &listboxInsert($pos, @choiceVals); | ||
| 2582 | my $choiceHashRef = (defined $w->{'hashref'}) ? $w->{'hashref'} | ||
| 2583 | : {}; #ADDED 20050125. | ||
| 2584 | my $choiceReverseHashRef = (defined $w->{'hashref_bydesc'}) ? $w->{'hashref_bydesc'} | ||
| 2585 | : {}; #ADDED 20110226. | ||
| 2586 | for (my $i=0;$i<=$#choiceKeys;$i++) #ADDED 20050125. | ||
| 2587 | { | ||
| 2588 | $choiceHashRef->{$choiceKeys[$i]} = $choiceVals[$i]; | ||
| 2589 | $choiceReverseHashRef->{$choiceVals[$i]} = $choiceKeys[$i]; | ||
| 2590 | } | ||
| 2591 | $w->{'hashref_bydesc'} = $choiceReverseHashRef; | ||
| 2592 | $w->{'hashref'} = $choiceHashRef; | ||
| 2593 | } | ||
| 2594 | else | ||
| 2595 | { | ||
| 2596 | $res = &listboxInsert($pos, @$item); | ||
| 2597 | } | ||
| 2598 | } | ||
| 2599 | else | ||
| 2600 | { | ||
| 2601 | $res = &listboxInsert($pos, $item, @_); | ||
| 2602 | } | ||
| 2603 | |||
| 2604 | #NO WIDTH SPECIFIED, (RE)CALCULATE TEXT & LIST WIDTH BASED ON LONGEST CHOICE. | ||
| 2605 | |||
| 2606 | $w->_adustLBsize(); | ||
| 2607 | $w->state($w->state()); #MAKE SURE THE BUTTON'S STATE GETS PROPERLY RESET IF LIST WAS EMPTY. | ||
| 2608 | return $res; | ||
| 2609 | } | ||
| 2610 | |||
| 2611 | sub delete #DELETE SELECTED ENTRY(S) FROM THE DD-LIST BY INDICES: | ||
| 2612 | { | ||
| 2613 | my $w = shift; | ||
| 2614 | if (defined $w->{'hashref'}) #ADDED 20050125. | ||
| 2615 | { | ||
| 2616 | my ($key, $val); | ||
| 2617 | foreach my $i (@_) | ||
| 2618 | { | ||
| 2619 | $val = $w->get($i) || ''; | ||
| 2620 | $key = $w->{'hashref_bydesc'}->{$val}; | ||
| 2621 | next unless ($val); | ||
| 2622 | delete $w->{'hashref_bydesc'}->{$val} if (defined $w->{'hashref_bydesc'}->{$val}); | ||
| 2623 | delete $w->{'hashref'}->{$key} if (defined $w->{'hashref'}->{$key}); | ||
| 2624 | } | ||
| 2625 | } | ||
| 2626 | my $res = $w->Subwidget('slistbox')->delete(@_); | ||
| 2627 | #CHGD. TO NEXT 2 @v5.0: unless ($w->Subwidget('slistbox')->size > 0 || $w->{'mylistcmd'}) | ||
| 2628 | # { | ||
| 2629 | # my $button = $w->Subwidget( 'arrow' ); | ||
| 2630 | # $button->configure( -state => 'disabled', -takefocus => 0); | ||
| 2631 | # } | ||
| 2632 | $w->_adustLBsize(); | ||
| 2633 | $w->state($w->state()) #MAKE SURE THE BUTTON'S STATE GETS DISABLED, IF NEEDED & EMPTY LIST. | ||
| 2634 | unless ($w->Subwidget('slistbox')->size > 0); | ||
| 2635 | return $res; | ||
| 2636 | } | ||
| 2637 | |||
| 2638 | sub delete_byvalue #DELETE SELECTED ENTRY(S) FROM THE DD-LIST BY TEXT VALUES: | ||
| 2639 | { | ||
| 2640 | my $w = shift; | ||
| 2641 | return undef unless (@_); | ||
| 2642 | |||
| 2643 | my @keys = $w->get(0, 'end'); | ||
| 2644 | my $v; | ||
| 2645 | my $delThisValue; | ||
| 2646 | my $delCnt = 0; | ||
| 2647 | while (@_) | ||
| 2648 | { | ||
| 2649 | $delThisValue = shift; | ||
| 2650 | if (defined $w->{'hashref'}) #ADDED 20050125. | ||
| 2651 | { | ||
| 2652 | for (my $k=0;$k<=$#keys;$k++) | ||
| 2653 | { | ||
| 2654 | if ($keys[$k] eq $delThisValue) | ||
| 2655 | { | ||
| 2656 | $v = $w->{'hashref_bydesc'}->{$keys[$k]}; | ||
| 2657 | delete $w->{'hashref_bydesc'}->{$keys[$k]} if (defined $w->{'hashref_bydesc'}->{$keys[$k]}); | ||
| 2658 | delete $w->{'hashref'}->{$v} if (defined $w->{'hashref'}->{$v}); | ||
| 2659 | $w->Subwidget('slistbox')->delete($k); | ||
| 2660 | $delCnt++; | ||
| 2661 | last; | ||
| 2662 | } | ||
| 2663 | } | ||
| 2664 | } | ||
| 2665 | } | ||
| 2666 | $w->state($w->state()) #MAKE SURE THE BUTTON'S STATE GETS TURNED OFF IF THE DD-LIST IS NOW EMPTY. | ||
| 2667 | unless ($w->Subwidget('slistbox')->size > 0); | ||
| 2668 | return $delCnt; | ||
| 2669 | } | ||
| 2670 | |||
| 2671 | sub curselection #RETURN CURRENT LISTBOX SELECTION. | ||
| 2672 | { | ||
| 2673 | return shift->Subwidget('slistbox')->curselection; | ||
| 2674 | } | ||
| 2675 | |||
| 2676 | sub _set_edit_state #CHANGE APPEARANCES BASED ON CHANGES IN "-STATE" OPTION: | ||
| 2677 | { | ||
| 2678 | my( $w, $state ) = @_; | ||
| 2679 | $state ||= 'normal'; #JWT: HAD TO ADD THIS IN TK804... | ||
| 2680 | my $entry = $w->Subwidget('entry'); | ||
| 2681 | my $frame = $w->Subwidget('frame'); | ||
| 2682 | my $label = $w->Subwidget('label'); | ||
| 2683 | my $button = $w->Subwidget('arrow'); | ||
| 2684 | my $slistbox = $w->Subwidget('slistbox'); | ||
| 2685 | my $txtfg = ($w->{'-colorstate'} eq '1') ? 'black' : $w->{'-textforeground'} || $frame->cget('-foreground'); | ||
| 2686 | my $txtbg = ($w->{'-colorstate'} eq '1') ? 'gray95' : $w->{'-textbackground'} || $frame->cget('-background'); | ||
| 2687 | my $texthlcolor = $frame->cget('-background'); | ||
| 2688 | my $framehlcolor = $frame->cget('-foreground'); | ||
| 2689 | my $framehlbg = $texthlcolor; | ||
| 2690 | if( $state eq 'readonly') | ||
| 2691 | { | ||
| 2692 | $framehlcolor = $frame->cget('-foreground') || $entry->cget( '-foreground' ); | ||
| 2693 | if ($w->{'-colorstate'} eq '1') | ||
| 2694 | { | ||
| 2695 | $txtbg = 'lightgray'; | ||
| 2696 | } | ||
| 2697 | elsif ($w->{'-colorstate'} =~ /^(?:2|dark|readonlydark)$/io) | ||
| 2698 | { | ||
| 2699 | $txtfg = ($txtbg eq $entry->cget('-readonlybackground')) ? 'gray30' : 'black'; | ||
| 2700 | } | ||
| 2701 | elsif ($bummer) #WINDOWS SETPALETTE DOESN'T "SHADE" THE READONLY TEXT FIELD BG, SO WE NEED TO MAKE FG LOOK DIFFERENT FROM NORMAL STATE!: | ||
| 2702 | { | ||
| 2703 | $txtfg = ($txtfg =~ /black/io) ? 'gray30' : 'lightgray'; | ||
| 2704 | } | ||
| 2705 | else #USE DISABLED FOREGROUND AS DEFAULT, ONLY IF THE READONLY BG IS NOT SET (IS THE DEFAULT): | ||
| 2706 | { | ||
| 2707 | my $txrobg = $w->cget('-textreadonlybackground'); | ||
| 2708 | if ($txrobg eq '#d9d9d9' && $w->cget('-textreadonlybackground') eq '#d9d9d9') | ||
| 2709 | { | ||
| 2710 | my $txtDisabledFg = $w->cget('-textdisabledforeground'); | ||
| 2711 | $txtfg = $txtDisabledFg unless ($txtDisabledFg eq '#d9d9d9'); | ||
| 2712 | } | ||
| 2713 | } | ||
| 2714 | $txtfg = $w->{'-textreadonlyforeground'} if ($w->{'-textreadonlyforeground'}); | ||
| 2715 | $txtbg = $w->{'-textreadonlybackground'} if ($w->{'-textreadonlybackground'}); | ||
| 2716 | my %entryHash = (-state => $state, -takefocus => 0, | ||
| 2717 | -foreground => $txtfg, -background => $txtbg, | ||
| 2718 | -highlightcolor => $texthlcolor, | ||
| 2719 | -highlightbackground => $texthlcolor); | ||
| 2720 | #PROGRAMMER NOTE: ONCE THIS PARAMETER IS "SET", SWITCHING PALETTES WILL *NOT* UPDATE IT!: | ||
| 2721 | $entryHash{'-readonlybackground'} = $w->{'-textreadonlybackground'} || 'lightgray' | ||
| 2722 | if ($w->{'-colorstate'} eq '1'); | ||
| 2723 | $entry->configure(%entryHash); | ||
| 2724 | |||
| 2725 | $button->configure(-state => 'normal', -takefocus => $w->{'btntakesfocus'}, -relief => 'raised', | ||
| 2726 | -highlightcolor => $framehlcolor, -highlightbackground => $framehlbg); | ||
| 2727 | $frame->configure(-relief => ($w->{'-relief'} || 'raised'), | ||
| 2728 | -takefocus => (1 & $w->{'takefocus'}), -highlightcolor => $framehlcolor, | ||
| 2729 | -highlightbackground => $framehlbg); | ||
| 2730 | $slistbox->configure(-state => 'normal') if ($w->{'-fixedlist'}); | ||
| 2731 | } | ||
| 2732 | elsif ($state =~ /text/o) | ||
| 2733 | { | ||
| 2734 | $button->configure( -state => 'disabled', -takefocus => 0, -relief => 'flat', | ||
| 2735 | -highlightbackground => $framehlbg); | ||
| 2736 | $frame->configure(-relief => ($w->{'-relief'} || 'sunken'), | ||
| 2737 | -takefocus => 0, -highlightcolor => $framehlcolor, | ||
| 2738 | -highlightbackground => $framehlbg); | ||
| 2739 | $entry->configure( -state => 'normal', | ||
| 2740 | -takefocus => (1 & ($w->{'takefocus'} || $w->{'btntakesfocus'})), | ||
| 2741 | -foreground => $txtfg, -background => $txtbg, -highlightcolor => $texthlcolor, | ||
| 2742 | -highlightbackground => $texthlcolor); | ||
| 2743 | if ($w->{'-fixedlist'}) | ||
| 2744 | { | ||
| 2745 | $w->Popdown(1) if ($w->{"popped"}); #UNFOCUS BEFORE DISABLING! | ||
| 2746 | $w->update; | ||
| 2747 | $slistbox->configure(-state => 'disabled', -takefocus => 0); | ||
| 2748 | } | ||
| 2749 | } | ||
| 2750 | elsif ($state eq 'disabled') | ||
| 2751 | { | ||
| 2752 | $frame->configure(-relief => ($w->{'-relief'} || 'groove'), | ||
| 2753 | -takefocus => 0, -highlightcolor => $framehlcolor, | ||
| 2754 | -highlightbackground => $framehlbg); | ||
| 2755 | |||
| 2756 | $txtfg = $w->{'-textdisabledforeground'} if ($w->{'-textdisabledforeground'}); | ||
| 2757 | $txtbg = $w->{'-textdisabledbackground'} if ($w->{'-textdisabledbackground'}); | ||
| 2758 | my %entryHash = (-state => $state, -takefocus => 0, | ||
| 2759 | -foreground => $txtfg, -background => $txtbg, | ||
| 2760 | -highlightcolor => $texthlcolor, | ||
| 2761 | -highlightbackground => $texthlcolor); | ||
| 2762 | $entryHash{'-disabledbackground'} = '' if ($w->{'-colorstate'} =~ /^(?:2|dark|disableddark)$/io); | ||
| 2763 | $entry->configure(%entryHash); | ||
| 2764 | |||
| 2765 | $button->configure(-state => $state, -takefocus => 0, -relief => 'flat', | ||
| 2766 | -highlightcolor => $framehlcolor, -highlightbackground => $framehlbg); | ||
| 2767 | if ($w->{'-fixedlist'}) | ||
| 2768 | { | ||
| 2769 | $w->Popdown(1) if ($w->{"popped"}); #UNFOCUS BEFORE DISABLING! | ||
| 2770 | $w->update; | ||
| 2771 | $slistbox->configure(-state => $state, -takefocus => 0); | ||
| 2772 | } | ||
| 2773 | } | ||
| 2774 | else #NORMAL. | ||
| 2775 | { | ||
| 2776 | $entry->configure( -state => $state, -takefocus => 0, | ||
| 2777 | -foreground => $txtfg, -background => $txtbg, | ||
| 2778 | -highlightcolor => $texthlcolor, | ||
| 2779 | -highlightbackground => $texthlcolor); | ||
| 2780 | $button->configure(-state => $state, -relief => 'raised', | ||
| 2781 | -takefocus => $w->{'btntakesfocus'}, | ||
| 2782 | -highlightcolor => $framehlcolor, -highlightbackground => $framehlbg); | ||
| 2783 | $frame->configure(-relief => ($w->{'-relief'} || 'sunken'), | ||
| 2784 | -takefocus => (1 & $w->{'takefocus'}), | ||
| 2785 | -highlightcolor => $framehlcolor, | ||
| 2786 | -highlightbackground => $framehlbg); | ||
| 2787 | $slistbox->configure(-state => $state) if ($w->{'-fixedlist'}); | ||
| 2788 | } | ||
| 2789 | |||
| 2790 | $label->configure( -background => $w->{'-labelbackground'}) if ($w->{'-labelbackground'}); | ||
| 2791 | $label->configure( -foreground => $w->{'-labelforeground'}) if ($w->{'-labelforeground'}); | ||
| 2792 | $button->configure( -state => 'disabled', -takefocus => 0) #DISABLE BUTTON IF EMPTY LIST. | ||
| 2793 | unless ($w->Subwidget('slistbox')->size > 0); | ||
| 2794 | } | ||
| 2795 | |||
| 2796 | sub state #DYNAMICALLY CHANGE THE -state OF THE WIDGET: | ||
| 2797 | { | ||
| 2798 | my $w = shift; | ||
| 2799 | |||
| 2800 | if (@_) | ||
| 2801 | { | ||
| 2802 | my $state = shift; | ||
| 2803 | $w->{'Configure'}{'-state'} = $state; | ||
| 2804 | $w->_set_edit_state($state); | ||
| 2805 | } | ||
| 2806 | else | ||
| 2807 | { | ||
| 2808 | return $w->{'Configure'}{'-state'}; | ||
| 2809 | } | ||
| 2810 | } | ||
| 2811 | |||
| 2812 | sub colorstate #DYNAMICALLY CHANGE THE -state OF THE WIDGET: | ||
| 2813 | { | ||
| 2814 | my $w = shift; | ||
| 2815 | |||
| 2816 | if (@_) | ||
| 2817 | { | ||
| 2818 | my $state = $w->cget('-state') || 'normal'; | ||
| 2819 | $w->{'Configure'}{'-colorstate'} = shift; | ||
| 2820 | $w->_set_edit_state($state); | ||
| 2821 | } | ||
| 2822 | else | ||
| 2823 | { | ||
| 2824 | return $w->{'Configure'}{'-colorstate'}; | ||
| 2825 | } | ||
| 2826 | } | ||
| 2827 | |||
| 2828 | sub dereference #USER-CALLABLE FUNCTION, ADDED 20050125. | ||
| 2829 | { | ||
| 2830 | my $w = shift; | ||
| 2831 | return undef unless (defined $_[0]); | ||
| 2832 | return (defined($w->{'hashref_bydesc'}) && defined($w->{'hashref_bydesc'}->{$_[0]})) | ||
| 2833 | ? $w->{'hashref_bydesc'}->{$_[0]} : $_[0]; | ||
| 2834 | } | ||
| 2835 | |||
| 2836 | sub reference #USER-CALLABLE FUNCTION, ADDED 20110227, v. 4.8: | ||
| 2837 | { | ||
| 2838 | my $w = shift; | ||
| 2839 | return undef unless (defined $_[0]); | ||
| 2840 | return (defined($w->{'hashref'}) && defined($w->{'hashref'}->{$_[0]})) | ||
| 2841 | ? $w->{'hashref'}->{$_[0]} : $_[0]; | ||
| 2842 | } | ||
| 2843 | |||
| 2844 | sub hasreference #USER-CALLABLE FUNCTION, ADDED 20050125. | ||
| 2845 | { | ||
| 2846 | my $w = shift; | ||
| 2847 | return undef unless (defined $_[0]); | ||
| 2848 | return (defined($w->{'hashref_bydesc'}) | ||
| 2849 | && defined($w->{'hashref_bydesc'}->{$_[0]})) ? 1 : 0; | ||
| 2850 | } | ||
| 2851 | |||
| 2852 | sub get_hashref_byname #USER-CALLABLE FUNCTION, ADDED 20110227, v. 4.8: | ||
| 2853 | { | ||
| 2854 | my $w = shift; | ||
| 2855 | return (defined $w->{'hashref_bydesc'}) ? $w->{'hashref_bydesc'} : undef; | ||
| 2856 | } | ||
| 2857 | |||
| 2858 | sub fetchhash #DEPRECIATED, RENAMED get_hashref_byname(): | ||
| 2859 | { | ||
| 2860 | my $w = shift; | ||
| 2861 | return $w->get_hashref_byname; | ||
| 2862 | } | ||
| 2863 | |||
| 2864 | sub get_hashref_byvalue #USER-CALLABLE FUNCTION, ADDED 20110227, v. 4.8: | ||
| 2865 | { | ||
| 2866 | my $w = shift; | ||
| 2867 | return (defined $w->{'hashref'}) ? $w->{'hashref'} : undef; | ||
| 2868 | } | ||
| 2869 | |||
| 2870 | sub get #USER-CALLABLE FUNCTION, ADDED 20090210 v4.72 (returns DISPLAYED VALUE for choice hashes)! | ||
| 2871 | { | ||
| 2872 | my $w = shift; | ||
| 2873 | if ($#{_} >= 0) #RETURN TEXT VALUES FOR GIVEN INDEX(ES). | ||
| 2874 | { | ||
| 2875 | my @items = $w->getText(@_); | ||
| 2876 | for (my $i=0;$i<=$#items;$i++) | ||
| 2877 | { | ||
| 2878 | $items[$i] = $w->reference($items[$i]); | ||
| 2879 | } | ||
| 2880 | return @items; #RETURNS ARRAY. | ||
| 2881 | } | ||
| 2882 | else #NO ARGS, RETURN CURRENT TEXT FIELD VALUE: | ||
| 2883 | { | ||
| 2884 | my $var_ref = $w->cget('-variable'); | ||
| 2885 | return $$var_ref; | ||
| 2886 | } | ||
| 2887 | } | ||
| 2888 | |||
| 2889 | sub get_index #USER-CALLABLE FUNCTION, ADDED 20110227, v. 4.8: | ||
| 2890 | { | ||
| 2891 | my $w = shift; | ||
| 2892 | return undef unless ($#{_} >= 0); | ||
| 2893 | |||
| 2894 | my $val = shift; | ||
| 2895 | my @keys = $w->get(0, 'end'); | ||
| 2896 | for (my $k=0;$k<=$#keys;$k++) | ||
| 2897 | { | ||
| 2898 | return $k if ($keys[$k] eq $val); | ||
| 2899 | } | ||
| 2900 | return undef; | ||
| 2901 | } | ||
| 2902 | |||
| 2903 | sub activate #USER-CALLABLE FUNCTION, ADDED 20090210 v4.72 | ||
| 2904 | { | ||
| 2905 | my $w = shift; | ||
| 2906 | my $indx = shift; | ||
| 2907 | my $res = $w->Subwidget('slistbox')->Subwidget($w->{'-listboxtype'})->activate($indx); | ||
| 2908 | my $var_ref = $w->cget('-variable'); | ||
| 2909 | $$var_ref = $w->reference($w->getText($indx)); | ||
| 2910 | return $res; | ||
| 2911 | } | ||
| 2912 | |||
| 2913 | sub index | ||
| 2914 | { | ||
| 2915 | my $w = shift; | ||
| 2916 | return $w->Subwidget('slistbox')->Subwidget($w->{'-listboxtype'})->index(@_); | ||
| 2917 | } | ||
| 2918 | |||
| 2919 | sub size | ||
| 2920 | { | ||
| 2921 | my $w = shift; | ||
| 2922 | return $w->Subwidget('slistbox')->Subwidget($w->{'-listboxtype'})->size(@_); | ||
| 2923 | } | ||
| 2924 | |||
| 2925 | sub get_icursor | ||
| 2926 | { | ||
| 2927 | my $w = shift; | ||
| 2928 | return $w->Subwidget('entry')->index(@_) if (@_); | ||
| 2929 | return $w->Subwidget('entry')->index('insert'); | ||
| 2930 | } | ||
| 2931 | |||
| 2932 | 1 | ||
| 2933 | |||
| 2934 | __END__ |