| 1 | ######################################## SOH ########################################### | ||
| 2 | ## Function : Alternate version for Tk:HList with sorting and filtering of columns | ||
| 3 | ## | ||
| 4 | ## Copyright (c) 2013 Michael Krause. All rights reserved. | ||
| 5 | ## This program is free software; you can redistribute it and/or modify it | ||
| 6 | ## under the same terms as Perl itself. | ||
| 7 | ## | ||
| 8 | ## History : V0.1 06-Feb-2013 Class created. MK | ||
| 9 | ## V0.2 10-Feb-2013 Added code for feature 'column resizing' (w/o headerresizebutton!). MK | ||
| 10 | ## V0.3 13-Feb-2013 Added configure/cget access. Updated Pod documentation. MK | ||
| 11 | ## V0.4 26-Feb-2013 Added wrapper/easier func 'advheaderCreate(). Updated Pod documentation. MK | ||
| 12 | ### | ||
| 13 | ######################################## EOH ########################################### | ||
| 14 | package Tk::Treeplus; | ||
| 15 | |||
| 16 | ############################################## | ||
| 17 | ### Use | ||
| 18 | ############################################## | ||
| 19 | use strict; | ||
| 20 | use vars qw($VERSION); | ||
| 21 | $VERSION = '0.4'; | ||
| 22 | |||
| 23 | # standards | ||
| 24 | use Carp; | ||
| 25 | use Time::HiRes qw(usleep); | ||
| 26 | |||
| 27 | # Tk related | ||
| 28 | use Tk; | ||
| 29 | use Tk qw(Ev); | ||
| 30 | use Tk::Derived; | ||
| 31 | use Tk::ItemStyle; | ||
| 32 | use Tk::Compound; | ||
| 33 | use Tk::DialogBox; | ||
| 34 | use Tk::LabEntry; | ||
| 35 | |||
| 36 | |||
| 37 | #-------------------------------------------------------------------------------------------------- | ||
| 38 | #use base qw(Tk::Derived Tk::Tree); | ||
| 39 | use base qw(Tk::Derived Tk::Tree); | ||
| 40 | Tk::Widget->Construct ('Treeplus'); | ||
| 41 | |||
| 42 | #-------------------------------------------------------------------------------------------------- | ||
| 43 | my (%IconData, %Icons); | ||
| 44 | # Several internal constants | ||
| 45 | use constant MAX_HISTORY_SIZE => '10'; | ||
| 46 | # | ||
| 47 | use constant DEFAULT_CLIPBOARD_SEPARATOR => '|'; | ||
| 48 | # | ||
| 49 | use constant _HL_INDICATOR_NONE => '0'; | ||
| 50 | use constant _HL_INDICATOR_OPEN => '1'; | ||
| 51 | use constant _HL_INDICATOR_CLOSED => '2'; | ||
| 52 | |||
| 53 | #-------------------------------------------------------------------------------------------------- | ||
| 54 | # Setup Bitmaps | ||
| 55 | $IconData{Up} = <<'up_EOP'; | ||
| 56 | /* XPM */ | ||
| 57 | static char *Up[] = { | ||
| 58 | "6 3 2 1", | ||
| 59 | ". c none", | ||
| 60 | "X c black", | ||
| 61 | "..XX..", | ||
| 62 | ".XXXX.", | ||
| 63 | "XXXXXX", | ||
| 64 | }; | ||
| 65 | up_EOP | ||
| 66 | |||
| 67 | $IconData{Down} = <<'down_EOP'; | ||
| 68 | /* XPM */ | ||
| 69 | static char *Down[] = { | ||
| 70 | "6 3 2 1", | ||
| 71 | ". c none", | ||
| 72 | "X c black", | ||
| 73 | "XXXXXX", | ||
| 74 | ".XXXX.", | ||
| 75 | "..XX..", | ||
| 76 | }; | ||
| 77 | down_EOP | ||
| 78 | |||
| 79 | $IconData{Filter} = <<'filter_EOP'; | ||
| 80 | /* XPM */ | ||
| 81 | static char *Filter[] = { | ||
| 82 | "12 7 3 1", | ||
| 83 | ". c none", | ||
| 84 | "X c black", | ||
| 85 | "X c grey", | ||
| 86 | "..XXXXXXXX..", | ||
| 87 | "...XXXXXX...", | ||
| 88 | "....XXXX....", | ||
| 89 | ".....XX.....", | ||
| 90 | ".....XX.....", | ||
| 91 | ".....XX.....", | ||
| 92 | ".....XX.....", | ||
| 93 | }; | ||
| 94 | filter_EOP | ||
| 95 | |||
| 96 | #-------------------------------------------------------------------------------------------------- | ||
| 97 | |||
| 98 | #-------------------------------------------------------------------------------------------------- | ||
| 99 | sub ClassInit | ||
| 100 | { | ||
| 101 | my ($class, $window) = (@_); | ||
| 102 | $class->SUPER::ClassInit($window); | ||
| 103 | } | ||
| 104 | |||
| 105 | #-------------------------------------------------------------------------------------------------- | ||
| 106 | sub Populate | ||
| 107 | { | ||
| 108 | my ($this, $args) = @_; | ||
| 109 | |||
| 110 | # Setup a default Headerstyle | ||
| 111 | $this->{__TP_HeaderInfo}{Style} = delete $args->{-headerstyle} || | ||
| 112 | $this->ItemStyle('window', -padx => '0', -pady => '0', -anchor => 'nw'); | ||
| 113 | |||
| 114 | # Create the movable ColumnBar | ||
| 115 | $this->{__TP_ResizeInfo}{ColumnBar} = $this->Frame( | ||
| 116 | -background => delete $args->{-trimbackground} || 'white', | ||
| 117 | -relief => 'raised', | ||
| 118 | -borderwidth => 2, | ||
| 119 | -width => 2, | ||
| 120 | ); | ||
| 121 | |||
| 122 | $this->SUPER::Populate($args); | ||
| 123 | |||
| 124 | $this->ConfigSpecs( | ||
| 125 | # | ||
| 126 | -wrapsearch => ['PASSIVE', 'wrapsearch', 'Wrapsearch', 0 ], | ||
| 127 | # | ||
| 128 | -maxselhistory => ['PASSIVE', 'maxselhistory', 'Maxselhistory', MAX_HISTORY_SIZE ], | ||
| 129 | # | ||
| 130 | -clipboardseparator => ['PASSIVE', 'clipboardseparator', 'Clipboardseparator', DEFAULT_CLIPBOARD_SEPARATOR ], | ||
| 131 | # | ||
| 132 | -headerminwidth => ['PASSIVE', 'minwidth', 'MinWidth', 20 ], | ||
| 133 | -headerclosedwidth => ['PASSIVE', 'closedwidth', 'ClosedMinWidth', 5 ], | ||
| 134 | # | ||
| 135 | -headerforeground => ['PASSIVE', 'headerForeground', 'HeaderForeground', 'black'], | ||
| 136 | -headerbackground => ['PASSIVE', 'headerBackground', 'HeaderBackground', '#d9d9d9'], | ||
| 137 | -headeractiveforeground => ['PASSIVE', 'headerActiveforeground', 'HeaderActiveforeground', 'black'], | ||
| 138 | -headeractivebackground => ['PASSIVE', 'headerActivebackground', 'HeaderActivebackground', 'gray'], | ||
| 139 | # | ||
| 140 | # Internal, activates the headers for convenience | ||
| 141 | -header => ['SELF', 'header', 'Header', 1 ], | ||
| 142 | |||
| 143 | ); | ||
| 144 | # Initialize the 'Auto-add-HeaderColumn' counter | ||
| 145 | $this->{__TP_LastColumn} = 0; | ||
| 146 | } | ||
| 147 | |||
| 148 | #---------------------------------------------------------------------- | ||
| 149 | # Add-ons for misc functions | ||
| 150 | #---------------------------------------------------------------------- | ||
| 151 | |||
| 152 | sub activateEntry | ||
| 153 | { | ||
| 154 | # Parameter | ||
| 155 | my ($this, $path) = @_; | ||
| 156 | |||
| 157 | # Locals | ||
| 158 | my ($sep_char, $parent, $browsecmd); | ||
| 159 | |||
| 160 | # Delete any previous selection | ||
| 161 | $this->selectionClear; | ||
| 162 | |||
| 163 | if ($this->infoExists($path)) { | ||
| 164 | # Take care of hidden parents | ||
| 165 | $sep_char = quotemeta($this->cget('-separator')); | ||
| 166 | if ($path =~ /$sep_char/o) { | ||
| 167 | $parent = $path; | ||
| 168 | while (($parent = $this->infoParent($parent))) { | ||
| 169 | $this->open($parent); | ||
| 170 | } | ||
| 171 | } | ||
| 172 | $this->see($path); | ||
| 173 | $this->selectionSet($path); | ||
| 174 | # avoid any secondary selection | ||
| 175 | $this->anchorClear; | ||
| 176 | |||
| 177 | # Finally continue with the official callback | ||
| 178 | $browsecmd = $this->cget('-browsecmd'); | ||
| 179 | $browsecmd->Call($path) if $browsecmd; | ||
| 180 | } | ||
| 181 | # else { | ||
| 182 | # print "DBG: activateEntry() Called with >@_< by >", caller, "< , path [$path] is NOT a valid entry in this list.\n"; | ||
| 183 | # } | ||
| 184 | } | ||
| 185 | |||
| 186 | |||
| 187 | |||
| 188 | #---------------------------------------------------------------------- | ||
| 189 | # Add-ons for the new '_Sort & _Filter' Header function | ||
| 190 | #---------------------------------------------------------------------- | ||
| 191 | |||
| 192 | #-------------------------------------------------------------------------------------------------- | ||
| 193 | # Add-on: new function for refreshing the primary sorting after the | ||
| 194 | # list has been completely filled | ||
| 195 | #-------------------------------------------------------------------------------------------------- | ||
| 196 | sub initSort | ||
| 197 | { | ||
| 198 | # Parameters | ||
| 199 | my ($this, $column) = @_; | ||
| 200 | |||
| 201 | if (defined $column) { | ||
| 202 | $this->ChangeSortColumn($column) | ||
| 203 | } | ||
| 204 | else { | ||
| 205 | $this->ReorderContent('sort') | ||
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 209 | #-------------------------------------------------------------------------------------------------- | ||
| 210 | # OVERRIDE: std ADD function | ||
| 211 | #-------------------------------------------------------------------------------------------------- | ||
| 212 | sub add | ||
| 213 | { | ||
| 214 | # Parameters | ||
| 215 | my ($this, $path, %args) = @_; | ||
| 216 | |||
| 217 | croak __PACKAGE__ . '::add(PATH, %args) ***Error: Invalid empty PATH detected!' unless $path; | ||
| 218 | |||
| 219 | # Start storing 'create-time' infos | ||
| 220 | $this->{__TP_EntryInfo}{$path}{CreateParms} = \%args; | ||
| 221 | |||
| 222 | # Create a new entry | ||
| 223 | $this->SUPER::add($path, %args); | ||
| 224 | } | ||
| 225 | |||
| 226 | #-------------------------------------------------------------------------------------------------- | ||
| 227 | # OVERRIDE: std ADDCHILD function | ||
| 228 | #-------------------------------------------------------------------------------------------------- | ||
| 229 | sub addchild | ||
| 230 | { | ||
| 231 | # Parameters | ||
| 232 | my ($this, $parentpath, %args) = @_; | ||
| 233 | |||
| 234 | # Locals | ||
| 235 | my ($path); | ||
| 236 | |||
| 237 | # Create a new entry | ||
| 238 | $path = $this->SUPER::addchild($parentpath, %args); | ||
| 239 | |||
| 240 | # Start storing 'create-time' infos | ||
| 241 | $this->{__TP_EntryInfo}{$path}{CreateParms} = \%args if $path; | ||
| 242 | |||
| 243 | return $path | ||
| 244 | } | ||
| 245 | #-------------------------------------------------------------------------------------------------- | ||
| 246 | # OVERRIDE: std item-create function | ||
| 247 | #-------------------------------------------------------------------------------------------------- | ||
| 248 | sub itemCreate { shift->item('create', @_) } | ||
| 249 | sub itemConfigure { shift->item('configure', @_) } | ||
| 250 | sub item | ||
| 251 | { | ||
| 252 | # Parameters | ||
| 253 | my ($this, $cmd, $path, $column, %args) = @_; | ||
| 254 | |||
| 255 | # Add/update the colum related settings | ||
| 256 | if ($path and $cmd =~ /create|configure/io) { | ||
| 257 | # Check for special sorting feature | ||
| 258 | # SFXSort stores a String or Array/Hash/Ref that is given | ||
| 259 | # to the sort-func instead of the -text value during colum-based sorting | ||
| 260 | my $sfx_sort = delete $args{-sortitem}; | ||
| 261 | $this->{__TP_EntryInfo}{$path}{SortItem}{$column} = $sfx_sort if $sfx_sort; | ||
| 262 | map { $this->{__TP_EntryInfo}{$path}{Columns}{$column}{$_} = $args{$_} } keys %args; | ||
| 263 | } | ||
| 264 | if ($path and $cmd =~ /delete/io) { | ||
| 265 | delete $this->{__TP_EntryInfo}{$path}{Columns}{$column}; | ||
| 266 | } | ||
| 267 | $this->SUPER::item($cmd, $path, $column, %args); | ||
| 268 | } | ||
| 269 | |||
| 270 | |||
| 271 | #-------------------------------------------------------------------------------------------------- | ||
| 272 | # OVERRIDE: std DELETE function | ||
| 273 | #-------------------------------------------------------------------------------------------------- | ||
| 274 | sub delete | ||
| 275 | { | ||
| 276 | # Parameters | ||
| 277 | my ($this, $what, $path) = @_; | ||
| 278 | |||
| 279 | if ($what eq 'all') { | ||
| 280 | # Clear the internal storage | ||
| 281 | $this->{__TP_EntryInfo} = {}; | ||
| 282 | # Delete it | ||
| 283 | $this->SUPER::delete($what); | ||
| 284 | } | ||
| 285 | else { | ||
| 286 | # Delete it from internal storage list | ||
| 287 | delete $this->{__TP_EntryInfo}{$path}; | ||
| 288 | # Delete it | ||
| 289 | $this->SUPER::delete($what, $path); | ||
| 290 | } | ||
| 291 | } | ||
| 292 | |||
| 293 | |||
| 294 | |||
| 295 | #-------------------------------------------------------------------------------------------------- | ||
| 296 | # OVERRIDE: new header function | ||
| 297 | #-------------------------------------------------------------------------------------------------- | ||
| 298 | sub headerCreate { shift->header('create', @_) } | ||
| 299 | sub headerCget { shift->header('cget', @_) } | ||
| 300 | sub headerDelete { shift->header('delete', @_) } | ||
| 301 | sub header | ||
| 302 | { | ||
| 303 | # print "DBG: reached function [".((caller(0))[3])."] with >@_<, called by >", caller, "<\n"; | ||
| 304 | # Parameters | ||
| 305 | my ($this, $cmd, $column, @args) = @_; | ||
| 306 | |||
| 307 | # Note that we process here only the create command | ||
| 308 | if ($cmd eq 'create') { | ||
| 309 | my (%args, %hlist_args, $key, $headerbttn); | ||
| 310 | %args = @args; | ||
| 311 | if (($args{-itemtype}||'') eq 'advancedheader') { | ||
| 312 | # Failsafe activate the headers, if not yet done | ||
| 313 | $this->configure('-header', 1) unless $this->cget('-header'); | ||
| 314 | $args{-background} = delete $args{-headerbackground} if $args{-headerbackground}; | ||
| 315 | # Rip off all irrelevant options | ||
| 316 | foreach $key (qw(-itemtype -widget -style)) { | ||
| 317 | $hlist_args{$key} = delete $args{$key} if $args{$key}; | ||
| 318 | } | ||
| 319 | # Create a new Header Button | ||
| 320 | $headerbttn = $this->AddHeaderColumn($column, %args); | ||
| 321 | |||
| 322 | # Add options for parent class setup | ||
| 323 | $hlist_args{-itemtype} = 'window'; | ||
| 324 | $hlist_args{-widget} = $headerbttn; | ||
| 325 | $hlist_args{-style} = $this->{__TP_HeaderInfo}{Style} unless $hlist_args{-style}; | ||
| 326 | $hlist_args{-relief} = 'groove' unless $hlist_args{-relief}; | ||
| 327 | $hlist_args{-headerbackground} = $headerbttn->cget('-background'); | ||
| 328 | |||
| 329 | # pass on as new args for parental class | ||
| 330 | @args = %hlist_args; | ||
| 331 | } | ||
| 332 | } | ||
| 333 | elsif ($cmd eq 'configure') { | ||
| 334 | if ($args[0] eq '-command') { | ||
| 335 | $this->{__TP_HeaderInfo}{$column}{Command} = $args[1]; | ||
| 336 | } | ||
| 337 | elsif ($args[0] eq '-is_primary_column') { | ||
| 338 | $this->ChangeSortColumn($column) if $args[1] # Change only, if really set | ||
| 339 | } | ||
| 340 | elsif ($args[0] eq '-sort_numeric') { | ||
| 341 | $this->{__TP_HeaderInfo}{$column}{SortNumeric} = $args[1] ? 1 : 0; | ||
| 342 | $this->{__TP_HeaderInfo}{$column}{SortDirection} = 0; | ||
| 343 | unless ($this->{__TP_HeaderInfo}{$column}{CustomSort}) { | ||
| 344 | $this->{__TP_HeaderInfo}{$column}{SortFuncCB} = ($args[1] ? | ||
| 345 | # (sub { $a->[1] <=> $b->[1] }) : (sub { ($a->[1]||'') cmp ($b->[1]||'') })) | ||
| 346 | (sub { ($a->[1]||0) <=> ($b->[1]||0) }) : (sub { ($a->[1]||'') cmp ($b->[1]||'') })) | ||
| 347 | } | ||
| 348 | } | ||
| 349 | elsif ($args[0] eq '-sort_func_cb') { | ||
| 350 | if ($args[1]) { | ||
| 351 | croak "Not a Code Reference!" unless ref($args[1]) eq 'CODE'; | ||
| 352 | $this->{__TP_HeaderInfo}{$column}{CustomSort} = 1; | ||
| 353 | $this->{__TP_HeaderInfo}{$column}{SortFuncCB} = $args[1]; | ||
| 354 | } | ||
| 355 | else { | ||
| 356 | $this->{__TP_HeaderInfo}{$column}{CustomSort} = 0; | ||
| 357 | $this->{__TP_HeaderInfo}{$column}{SortFuncCB} = ( | ||
| 358 | $this->{__TP_HeaderInfo}{$column}{SortNumeric} ? | ||
| 359 | (sub { ($a->[1]||0) <=> ($b->[1]||0) }) : (sub { ($a->[1]||'') cmp ($b->[1]||'') })) | ||
| 360 | |||
| 361 | } | ||
| 362 | $this->{__TP_HeaderInfo}{$column}{SortDirection} = 0; | ||
| 363 | } | ||
| 364 | elsif ($args[0] eq '-resize_column') { | ||
| 365 | $this->{__TP_ResizeInfo}{$column}{TrimActive} = $args[1] ? 1 : 0; | ||
| 366 | } | ||
| 367 | elsif ($args[0] eq '-filter_column') { | ||
| 368 | $this->{__TP_PatternFilterInfo} = {} unless $this->{__TP_PatternFilterInfo}; | ||
| 369 | my $fpinfo = $this->{__TP_PatternFilterInfo}; | ||
| 370 | if ($args[1]) { | ||
| 371 | $fpinfo->{Active}{$column} = 1; | ||
| 372 | $fpinfo->{Pattern}{$column} = $args[1]; | ||
| 373 | $fpinfo->{PatternRE}{$column} = qr/$args[1]/; | ||
| 374 | $this->RefreshColumnHeader($column); | ||
| 375 | $this->ExecutePatternFilter($column, 'FILTER') | ||
| 376 | } | ||
| 377 | else { | ||
| 378 | $fpinfo->{Active}{$column} = 0; | ||
| 379 | } | ||
| 380 | } | ||
| 381 | else { | ||
| 382 | # all other requests are processed as 'button args' | ||
| 383 | return $this->{__TP_HeaderInfo}{$column}{Widget}->configure(@args); | ||
| 384 | } | ||
| 385 | return | ||
| 386 | } | ||
| 387 | elsif ($cmd eq 'cget') { | ||
| 388 | if ($args[0] eq '-widget') { | ||
| 389 | return $this->{__TP_HeaderInfo}{$column}{Widget}; | ||
| 390 | } | ||
| 391 | elsif ($args[0] eq '-command') { | ||
| 392 | return $this->{__TP_HeaderInfo}{$column}{Command}; | ||
| 393 | } | ||
| 394 | elsif ($args[0] eq '-sort_numeric') { | ||
| 395 | return $this->{__TP_HeaderInfo}{$column}{SortNumeric}; | ||
| 396 | } | ||
| 397 | elsif ($args[0] eq '-resize_column') { | ||
| 398 | return $this->{__TP_ResizeInfo}{$column}{TrimActive}; | ||
| 399 | } | ||
| 400 | elsif ($args[0] eq '-filter_column') { | ||
| 401 | return $this->{__TP_PatternFilterInfo}{Pattern}{$column}||''; | ||
| 402 | } | ||
| 403 | else { | ||
| 404 | # all other requests are processed as 'button args' | ||
| 405 | return $this->{__TP_HeaderInfo}{$column}{Widget}->cget(@args); | ||
| 406 | } | ||
| 407 | } | ||
| 408 | elsif ($cmd eq 'delete') { | ||
| 409 | croak "Header-Delete() is currently not supported. Try to find a w/a!" | ||
| 410 | } | ||
| 411 | # Install the 'normal view after we have something on the screen.. | ||
| 412 | if (defined $column) { | ||
| 413 | return $this->SUPER::header($cmd, $column, @args); | ||
| 414 | } | ||
| 415 | else { | ||
| 416 | return $this->SUPER::header($cmd); | ||
| 417 | } | ||
| 418 | } | ||
| 419 | |||
| 420 | #-------------------------------------------------------------------------------------------------- | ||
| 421 | # | ||
| 422 | # advancedHeaderCreate() | ||
| 423 | # | ||
| 424 | # Function: Easy header-column creation (traces the last free col automatically) | ||
| 425 | # Parms: Same as headerCreate(), w/o column, w/o '-itemtype' | ||
| 426 | # | ||
| 427 | #-------------------------------------------------------------------------------------------------- | ||
| 428 | sub advancedHeaderCreate | ||
| 429 | { | ||
| 430 | my $this = shift; | ||
| 431 | $this->header('create', $this->{__TP_LastColumn}++, | ||
| 432 | qw(-autocol 1 -itemtype advancedheader), @_) | ||
| 433 | } | ||
| 434 | |||
| 435 | #-------------------------------------------------------------------------------------------------- | ||
| 436 | # | ||
| 437 | # AddHeaderColumn() | ||
| 438 | # | ||
| 439 | # Create a header element based on the given parms | ||
| 440 | # | ||
| 441 | # Parms: | ||
| 442 | # mandatory: | ||
| 443 | # column Column Number, where to insert | ||
| 444 | # -text Visible Text for Column Header. | ||
| 445 | # | ||
| 446 | # optional: | ||
| 447 | # -is_primary_column Mark this column as the one that is usedfor sorting this list | ||
| 448 | # -foreground forground color for the header | ||
| 449 | # -background background color for the header | ||
| 450 | # -activeforeground active forground color for the active header | ||
| 451 | # -activebackground active background color for the active header | ||
| 452 | # -headerminwidth minimum size of the current column during custom column resizing operation | ||
| 453 | # -headerclosedwidth the size of the current column in case it is rendered 'CLOSED' | ||
| 454 | # -sort_numeric Mark this column to use a NUMERIC sort (default is to use | ||
| 455 | # ALPHANUMERIC sort) | ||
| 456 | # -sort_func_cb Custom sort: Callbackfunction to be executed in case the list | ||
| 457 | # should be sorted according this column (internal default: | ||
| 458 | # { my ($a, $b) = @_; $a->[1] cmp $b->[1] } ) | ||
| 459 | # -command Custom Callbackfunction to be executed, if a columnheader | ||
| 460 | # is clicked (AND 'released' on the header!) | ||
| 461 | # -resize_column boolean decides whether this column is resizable | ||
| 462 | #-------------------------------------------------------------------------------------------------- | ||
| 463 | sub AddHeaderColumn | ||
| 464 | { | ||
| 465 | #print "reached CreateListSelectHeader with >@_<\n"; | ||
| 466 | # Parameters | ||
| 467 | my ($this, $column, %args) = @_; | ||
| 468 | |||
| 469 | # Locals | ||
| 470 | my ($text, $is_primary_column, $sort_numeric, $resize_column, $headerparent, | ||
| 471 | $headerbttn, $headbttn, $trim_widget); | ||
| 472 | |||
| 473 | croak "No column defined!" unless defined $column; | ||
| 474 | croak "No label with '-text' defined!" unless $args{-text}; | ||
| 475 | $text = $args{-text}; | ||
| 476 | |||
| 477 | # Fill Args with defaults if necessary | ||
| 478 | $args{-foreground} = $args{-foreground} || $this->cget('-headerforeground'); | ||
| 479 | $args{-background} = $args{-background} || $this->cget('-headerbackground'); | ||
| 480 | $args{-activeforeground} = $args{-activeforeground} || $this->cget('-headeractiveforeground'); | ||
| 481 | $args{-activebackground} = $args{-activebackground} || $this->cget('-headeractivebackground'); | ||
| 482 | # Special check for 'not highlighting' 'empty' headers | ||
| 483 | if ($text =~ /--/io) { | ||
| 484 | delete $args{-activeforeground}; | ||
| 485 | delete $args{-activebackground} | ||
| 486 | } | ||
| 487 | |||
| 488 | # Trace the last column number (keep up-to-date for alternate use of 'advancedHeaderCreate()') | ||
| 489 | $this->{__TP_LastColumn}++ unless delete $args{-autocol}; | ||
| 490 | |||
| 491 | # Set some locals | ||
| 492 | $this = $this->Subwidget('scrolled') if (ref $this) =~ /Frame/io; | ||
| 493 | $is_primary_column = delete $args{-is_primary_column}; | ||
| 494 | $sort_numeric = delete $args{-sort_numeric}; | ||
| 495 | $resize_column = delete $args{-resize_column}; | ||
| 496 | # Create a 'collection' frame | ||
| 497 | $headerparent = $this->Frame(-background => $args{-background}); | ||
| 498 | |||
| 499 | #------------------------------------------------------------------- | ||
| 500 | # Store misc Header-Infos | ||
| 501 | $this->{__TP_HeaderInfo}{$column}{CustomSort} = 1 if $args{-sort_func_cb}; | ||
| 502 | $this->{__TP_HeaderInfo}{$column}{SortFuncCB} = delete $args{-sort_func_cb} || | ||
| 503 | # ($sort_numeric ? (sub { print "INT_NUM: a=>$a<>" . join(',',@$a) . "<\n"; $a->[1] <=> $b->[1] }) : | ||
| 504 | # (sub { print "INT_ALP: a=>$a<>" . join(',',@$a) . "<\n"; $a->[1] cmp $b->[1] })); | ||
| 505 | ($sort_numeric ? (sub { ($a->[1]||0) <=> ($b->[1]||0) }) : (sub { ($a->[1]||'') cmp ($b->[1]||'') })); | ||
| 506 | $this->{__TP_HeaderInfo}{$column}{SortNumeric} = $sort_numeric; | ||
| 507 | $this->{__TP_HeaderInfo}{$column}{SortDirection} = 0; | ||
| 508 | $this->{__TP_HeaderInfo}{$column}{ForegroundColor} = $args{-foreground}; | ||
| 509 | $this->{__TP_HeaderInfo}{$column}{ActiveForegroundColor} = $args{-activeforeground}; | ||
| 510 | $this->{__TP_HeaderInfo}{$column}{Command} = delete $args{-command}; | ||
| 511 | # Store Reszing related infos | ||
| 512 | $this->{__TP_ResizeInfo}{$column}{ColumnMinWidth} = delete $args{-headerminwidth} || $this->cget('-headerminwidth'); | ||
| 513 | $this->{__TP_ResizeInfo}{$column}{ColumnClosedWidth} = delete $args{-headerclosedwidth} || $this->cget('-headerclosedwidth'); | ||
| 514 | |||
| 515 | #------------------------------------------------------------------- | ||
| 516 | #Initialize the select-history storage | ||
| 517 | if ($column == 0) { | ||
| 518 | $this->InitializeSelectHistory(); | ||
| 519 | $is_primary_column = 1; # Set the first column to be the 'primary' by default | ||
| 520 | #------------------------------------------------------------------- | ||
| 521 | my $legacy_menu = delete $args{-legacy_menu}; | ||
| 522 | if ($legacy_menu) { | ||
| 523 | # Add special Meny Symbol fora anchoring the special capability menu at column 0 | ||
| 524 | my ($image, $help_balloon); | ||
| 525 | ($image, $help_balloon) = @$legacy_menu if ref($legacy_menu) =~ /ARRAY/io; | ||
| 526 | $headerbttn = $headerparent->Button( | ||
| 527 | -class => 'HListHeader', | ||
| 528 | -relief => 'flat', -borderwidth => '0', | ||
| 529 | -background => $args{-background}, | ||
| 530 | -foreground => $args{-foreground}, | ||
| 531 | -text => '+', | ||
| 532 | ($image ? (-image => $image) : ()), | ||
| 533 | -command => sub { $this->RMBPopUpMenu() }, | ||
| 534 | -padx => -1, -pady => -1, | ||
| 535 | )->pack(qw(-side left -fill both -anchor w)); # Place the bttn in the frame | ||
| 536 | $help_balloon->attach($headerbttn, -balloonmsg => 'List Operations ...') if $help_balloon; | ||
| 537 | } | ||
| 538 | } | ||
| 539 | $this->{__TP_HeaderInfo}{PrimaryColumn} = $column if $is_primary_column; | ||
| 540 | |||
| 541 | #------------------------------------------------------------------- | ||
| 542 | # Create a Action-Button | ||
| 543 | $headerbttn = $headerparent->Button( | ||
| 544 | -class => 'HListHeader', | ||
| 545 | -relief => 'flat', -borderwidth => '0', | ||
| 546 | -padx => '-1', -pady => '-1', | ||
| 547 | -highlightthickness => '0', | ||
| 548 | -command => sub { $this->ChangeSortColumn($column); | ||
| 549 | # Invoke custom hook, if any | ||
| 550 | my $cb = $this->{__TP_HeaderInfo}{$column}{Command}; | ||
| 551 | &$cb($this, $column) if $cb }, | ||
| 552 | |||
| 553 | # Apply promoted 'button-style(!)' args | ||
| 554 | %args, | ||
| 555 | )->pack(qw(-side left -expand 1 -fill both -anchor w)); # Place the bttn in the frame;; | ||
| 556 | # Store Headerbutton-Info | ||
| 557 | $this->{__TP_HeaderInfo}{$column}{Widget} = $headerbttn; | ||
| 558 | |||
| 559 | #------------------------------------------------------------------- | ||
| 560 | # Initialize the RMB Menu | ||
| 561 | $headerbttn->bind('<ButtonRelease-3>', sub { $this->RMBPopUpMenu($column) } ); | ||
| 562 | # Make the 'ALL Column" menu available everywhere | ||
| 563 | $headerbttn->bind('<ButtonRelease-2>', sub { $this->RMBPopUpMenu() } ); | ||
| 564 | #------------------------------------------------------------------- | ||
| 565 | |||
| 566 | #------------------------------------------------------------------- | ||
| 567 | # Add header separator for dynamic column resizing | ||
| 568 | $trim_widget = $headerparent->Frame( | ||
| 569 | -class => 'HListHeader', | ||
| 570 | -relief => 'flat', -borderwidth => '0', | ||
| 571 | -background => $headerbttn->cget('-background'), | ||
| 572 | #-borderwidth => 1, | ||
| 573 | -width => 1, | ||
| 574 | )->place( | ||
| 575 | -bordermode => 'outside', | ||
| 576 | -relheight => '1.0', | ||
| 577 | -anchor => 'ne', | ||
| 578 | -relx => '1.0', | ||
| 579 | ); | ||
| 580 | $this->{__TP_ResizeInfo}{$column}{TrimWidget} = $trim_widget; | ||
| 581 | $trim_widget->bind('<ButtonRelease-3>', sub { $this->RMBPopUpMenu($column) } ); | ||
| 582 | # Although we create the trim sensors for all new columns we activate it only on-demand (or via pop-up menu) | ||
| 583 | $this->{__TP_ResizeInfo}{$column}{TrimActive} = $resize_column ? 1 : 0; | ||
| 584 | $this->TrimEnable($column, 1) if $resize_column; | ||
| 585 | |||
| 586 | #------------------------------------------------------------------- | ||
| 587 | # Store this column (name) for the 'find-by' search | ||
| 588 | $this->{__TP_SearchInfo}{Columns}{$column} = $text; | ||
| 589 | |||
| 590 | #------------------------------------------------------------------- | ||
| 591 | # Mark-up this column, if it is the primary-search-column | ||
| 592 | $this->RefreshColumnHeader($column) if $is_primary_column; | ||
| 593 | |||
| 594 | return $headerparent | ||
| 595 | } | ||
| 596 | |||
| 597 | |||
| 598 | #-------------------------------------------------------------------------------------------------- | ||
| 599 | # | ||
| 600 | # ChangeSortColumn() | ||
| 601 | # | ||
| 602 | # Change the given filter to a new value | ||
| 603 | # | ||
| 604 | #-------------------------------------------------------------------------------------------------- | ||
| 605 | sub ChangeSortColumn | ||
| 606 | { | ||
| 607 | # Parameters | ||
| 608 | my ($this, $column) = @_; | ||
| 609 | |||
| 610 | # Locals | ||
| 611 | my ($last_primary_column); | ||
| 612 | |||
| 613 | $last_primary_column = $this->{__TP_HeaderInfo}{PrimaryColumn}; | ||
| 614 | $last_primary_column = -1 unless defined $last_primary_column; | ||
| 615 | if ($last_primary_column == $column) { | ||
| 616 | # We stay in the same column, We just reverse the ordering | ||
| 617 | $this->{__TP_HeaderInfo}{$column}{SortDirection} = | ||
| 618 | not $this->{__TP_HeaderInfo}{$column}{SortDirection}; | ||
| 619 | # Reverse the list | ||
| 620 | $this->ReorderContent('reverse'); | ||
| 621 | } | ||
| 622 | else { | ||
| 623 | $this->{__TP_HeaderInfo}{PrimaryColumn} = $column; | ||
| 624 | # Sort the list | ||
| 625 | $this->ReorderContent('sort'); | ||
| 626 | } | ||
| 627 | # Mark-up this column, eventually remove assignment from previous primary-column | ||
| 628 | $this->RefreshColumnHeader($last_primary_column) if $last_primary_column != -1; | ||
| 629 | $this->RefreshColumnHeader($column); | ||
| 630 | } | ||
| 631 | |||
| 632 | #-------------------------------------------------------------------------------------------------- | ||
| 633 | # | ||
| 634 | # ReorderContent() | ||
| 635 | # | ||
| 636 | # Changes the content to a new sort-order | ||
| 637 | # | ||
| 638 | #-------------------------------------------------------------------------------------------------- | ||
| 639 | sub ReorderContent | ||
| 640 | { | ||
| 641 | # Parameters | ||
| 642 | my ($this, $mode) = @_; | ||
| 643 | |||
| 644 | # Locals | ||
| 645 | my ($entry_info, %hidden, %indicator, @all_children, $sep_char, $qsep_char, | ||
| 646 | $path, $indicator, $ptr, $level, $column, $parent, %stack); | ||
| 647 | |||
| 648 | # Some Helper variables | ||
| 649 | $entry_info = $this->{__TP_EntryInfo}; | ||
| 650 | |||
| 651 | # failsafe-check - stop on lists with '' as path | ||
| 652 | #my @tmp = $this->infoChildren(''); | ||
| 653 | #return if (not @tmp or not $tmp[0]); | ||
| 654 | |||
| 655 | #------------------------------------------------------------------- | ||
| 656 | # Snapshot the existing layout | ||
| 657 | $this->__collect_children(\@all_children); | ||
| 658 | # print 'DBG: variable [\@all_children] = '; ETC::Universal::print_var(\@all_children, 1); | ||
| 659 | |||
| 660 | %hidden = map { ($_->[0], $_->[1]) } @all_children; | ||
| 661 | %indicator = map { ($_->[0], $_->[2]) } @all_children; | ||
| 662 | @all_children = map { $_->[0] } @all_children; | ||
| 663 | $sep_char = $this->cget('-separator'); | ||
| 664 | |||
| 665 | #------------------------------------------------------------------- | ||
| 666 | # sort / reorder | ||
| 667 | if ($mode =~ /reverse/io) { | ||
| 668 | @all_children = reverse @all_children; | ||
| 669 | } | ||
| 670 | elsif ($mode =~ /sort/io) { | ||
| 671 | my ($column, $sortfunction, $custom_sort, @sort_map); | ||
| 672 | $column = $this->{__TP_HeaderInfo}{PrimaryColumn}; | ||
| 673 | $sortfunction = $this->{__TP_HeaderInfo}{$column}{SortFuncCB}; | ||
| 674 | $custom_sort = $this->{__TP_HeaderInfo}{$column}{CustomSort}; | ||
| 675 | # Here we use the Schwartz-Transformation to sort mapped items | ||
| 676 | # s. "Programmieren in Perl" S. 815, 2. Aufl. | ||
| 677 | @all_children = map { $_->[0] } | ||
| 678 | sort $sortfunction | ||
| 679 | map { [ $_, $entry_info->{$_}{Columns}{$column}{-text}, | ||
| 680 | (($custom_sort) ? ($entry_info->{$_}{CreateParms}{-data}) : ()) | ||
| 681 | ] } @all_children; | ||
| 682 | # Optionally we have to reverse the sorting result, if user set this | ||
| 683 | @all_children = reverse @all_children if $this->{__TP_HeaderInfo}{$column}{SortDirection}; | ||
| 684 | } | ||
| 685 | else { | ||
| 686 | croak "SortChildren(): Unknown 'Sort-mode [$mode], skipping!\n" | ||
| 687 | } | ||
| 688 | |||
| 689 | #------------------------------------------------------------------- | ||
| 690 | # rebuild the list/tree according new calculated order based on cached content | ||
| 691 | $this->delete('all'); | ||
| 692 | $qsep_char = quotemeta($sep_char); | ||
| 693 | local (@_) = @all_children; | ||
| 694 | while (@_) { | ||
| 695 | $path = shift; | ||
| 696 | # print 'DBG: variable [$path] = >' . $path . "<\n"; | ||
| 697 | ($parent = $path) =~ s/^(.*)$qsep_char.*/$1/; | ||
| 698 | if ($this->infoExists($parent) or $parent eq $path) { | ||
| 699 | $ptr = $entry_info->{$path}; | ||
| 700 | $this->add($path, %{$ptr->{CreateParms}}); | ||
| 701 | foreach $column (keys %{$ptr->{Columns}}) { | ||
| 702 | $this->itemCreate($path, $column, %{$ptr->{Columns}{$column}}); | ||
| 703 | } | ||
| 704 | $indicator = $indicator{$path}; | ||
| 705 | if ($indicator) { | ||
| 706 | if ($indicator == _HL_INDICATOR_OPEN) { | ||
| 707 | $this->_indicator_image($path, 'minus'); | ||
| 708 | } | ||
| 709 | else { ### _HL_INDICATOR_CLOSED | ||
| 710 | $this->_indicator_image($path, 'plus'); | ||
| 711 | } | ||
| 712 | } | ||
| 713 | else { # _HL_INDICATOR_NONE -> '0' | ||
| 714 | $this->_indicator_image($path, undef); | ||
| 715 | } | ||
| 716 | $this->hide('entry', $path) if $hidden{$path}; | ||
| 717 | # Process those items that have been queued | ||
| 718 | if ($stack{$path}) { | ||
| 719 | # print "DBG: Insert again [".join(', ', @{$stack{$path}})."] at parent [$path]\n"; | ||
| 720 | unshift @_, @{delete $stack{$path}}; | ||
| 721 | } | ||
| 722 | } | ||
| 723 | else { | ||
| 724 | # print "DBG: Stacked >$path<, since parent n/a\n"; | ||
| 725 | push @{$stack{$parent}}, $path | ||
| 726 | } | ||
| 727 | } | ||
| 728 | # my @tmp; | ||
| 729 | # $this->__collect_children(\@tmp); | ||
| 730 | # print 'DBG: variable [\@tmp] = '; ETC::Universal::print_var(\@tmp, 1); | ||
| 731 | } | ||
| 732 | |||
| 733 | #-------------------------------------------------------------------------------------------------- | ||
| 734 | # | ||
| 735 | # __collect_children() | ||
| 736 | # | ||
| 737 | # Collects information about all entries of the current list or tree | ||
| 738 | # | ||
| 739 | #-------------------------------------------------------------------------------------------------- | ||
| 740 | sub __collect_children | ||
| 741 | { | ||
| 742 | # Locals | ||
| 743 | my ($this, $all_children, $path) = @_; | ||
| 744 | # Locals | ||
| 745 | my ($child, $indicator_images, $indicator); | ||
| 746 | |||
| 747 | foreach $child ($this->infoChildren($path)) { | ||
| 748 | #-------------------------------------- | ||
| 749 | # Note: In diference to 'getmode()' we need to store | ||
| 750 | # the CURRENT mode, not the 'NEXT ONE TO BE' ! | ||
| 751 | if ($this->indicatorExists($child)) { | ||
| 752 | $indicator_images = $this->privateData(); # for speed | ||
| 753 | if ($indicator_images->{$child} =~ /^(?:plus|plusarm)$/io) { | ||
| 754 | $indicator = _HL_INDICATOR_CLOSED | ||
| 755 | } | ||
| 756 | else { | ||
| 757 | $indicator = _HL_INDICATOR_OPEN | ||
| 758 | } | ||
| 759 | } | ||
| 760 | else { | ||
| 761 | $indicator = _HL_INDICATOR_NONE # --> 0 | ||
| 762 | } | ||
| 763 | #-------------------------------------- | ||
| 764 | push @$all_children, [$child, $this->infoHidden($child), $indicator]; | ||
| 765 | $this->__collect_children($all_children, $child) if $this->infoChildren($child); | ||
| 766 | } | ||
| 767 | } | ||
| 768 | |||
| 769 | #-------------------------------------------------------------------------------------------------- | ||
| 770 | # | ||
| 771 | # RefreshColumnHeader() | ||
| 772 | # | ||
| 773 | # Provides special assigment marker for the | ||
| 774 | # primary column | ||
| 775 | # | ||
| 776 | #-------------------------------------------------------------------------------------------------- | ||
| 777 | use constant STD => '0'; | ||
| 778 | use constant ACT => '1'; | ||
| 779 | sub RefreshColumnHeader | ||
| 780 | { # print "DBG: reached function [".((caller(0))[3])."] with >@_<, called by >", caller, "<\n"; | ||
| 781 | |||
| 782 | # Parameters | ||
| 783 | my ($this, $column) = @_; | ||
| 784 | |||
| 785 | # Locals | ||
| 786 | my ($hcolptr, $headerbttn, $sort_direction, $fg_color, $afg_color, $primary_images, | ||
| 787 | $filter_images, $image); | ||
| 788 | |||
| 789 | # Some Helper variables | ||
| 790 | $hcolptr = $this->{__TP_HeaderInfo}{$column}; | ||
| 791 | $headerbttn = $hcolptr->{Widget}; | ||
| 792 | $sort_direction = $hcolptr->{SortDirection} || 0; | ||
| 793 | $fg_color = $hcolptr->{ForegroundColor} || $headerbttn->cget('-foreground'); | ||
| 794 | $afg_color = $hcolptr->{ActiveForegroundColor} || $headerbttn->cget('-activeforeground'); | ||
| 795 | |||
| 796 | #------------------------------------------------------------------- | ||
| 797 | # Step 1: Check if this is the PRIMARY column | ||
| 798 | if ($column == $this->{__TP_HeaderInfo}{PrimaryColumn}) { | ||
| 799 | # sort_direction == 0 -> Up, != 0 -> Down | ||
| 800 | $primary_images = $hcolptr->{Image}{Primary}{$sort_direction}; | ||
| 801 | unless ($primary_images) { | ||
| 802 | my ($arrow_data, $image_data); | ||
| 803 | $arrow_data = $sort_direction ? $IconData{Down} : $IconData{Up}; | ||
| 804 | #------------------------------------- | ||
| 805 | # Create a 'Standard' Arrow | ||
| 806 | ($image_data = $arrow_data) =~ s/black/$fg_color/io; | ||
| 807 | $primary_images->[STD] = $headerbttn->Pixmap(-data => $image_data); | ||
| 808 | #------------------------------------- | ||
| 809 | # Create an 'Active' Arrow | ||
| 810 | ($image_data = $arrow_data) =~ s/black/$afg_color/io; | ||
| 811 | $primary_images->[ACT] = $headerbttn->Pixmap(-data => $image_data); | ||
| 812 | #------------------------------------- | ||
| 813 | # Store the new images | ||
| 814 | $hcolptr->{Image}{Primary}{$sort_direction} = $primary_images | ||
| 815 | } | ||
| 816 | } | ||
| 817 | #------------------------------------------------------------------- | ||
| 818 | # Step 2: Check if this is the FILTERED column | ||
| 819 | if ($this->{__TP_PatternFilterInfo}{Active}{$column}) { | ||
| 820 | $filter_images = $hcolptr->{Image}{Filter}; | ||
| 821 | unless ($filter_images) { | ||
| 822 | my ($image_data); | ||
| 823 | #------------------------------------- | ||
| 824 | # Create a 'Standard' Filter | ||
| 825 | ($image_data = $IconData{Filter}) =~ s/black/$fg_color/io; | ||
| 826 | $filter_images->[STD] = $headerbttn->Pixmap(-data => $image_data); | ||
| 827 | #------------------------------------- | ||
| 828 | # Create an 'Active' Filter | ||
| 829 | ($image_data = $IconData{Filter}) =~ s/black/$afg_color/io; | ||
| 830 | $filter_images->[ACT] = $headerbttn->Pixmap(-data => $image_data); | ||
| 831 | #------------------------------------- | ||
| 832 | # Store the new images | ||
| 833 | $hcolptr->{Image}{Filter} = $filter_images | ||
| 834 | } | ||
| 835 | } | ||
| 836 | |||
| 837 | #------------------------------------------------------------------- | ||
| 838 | # Step 3: Build together | ||
| 839 | if ($primary_images or $filter_images) { | ||
| 840 | my ($compound_images, $i, $color, $image, $old_bind); | ||
| 841 | $compound_images = $hcolptr->{Image}{Compound}; | ||
| 842 | if ($compound_images) { # Remove existing images | ||
| 843 | $compound_images->[STD]->delete; | ||
| 844 | $compound_images->[ACT]->delete | ||
| 845 | } | ||
| 846 | #------------------------------------- | ||
| 847 | # Create a new 'Standard' + 'Active' Compound Image | ||
| 848 | $i = STD; | ||
| 849 | foreach $color ($fg_color, $afg_color) { | ||
| 850 | $image = $headerbttn->Compound(-padx => 1, -pady => 1, -foreground => $color, | ||
| 851 | -background => $headerbttn->cget('-background')); | ||
| 852 | # Line 1 | ||
| 853 | if ($primary_images) { | ||
| 854 | $image->Image(-image => $primary_images->[$i], -anchor => 'n'); | ||
| 855 | $image->Space(-height => 1) | ||
| 856 | } | ||
| 857 | # Line 2 | ||
| 858 | $image->Line; | ||
| 859 | $image->Text(-text => $headerbttn->cget('-text'), | ||
| 860 | -wraplength => ($this->{__TP_ResizeInfo}{$column}{WrapLength}||0)); | ||
| 861 | if ($filter_images) { | ||
| 862 | $image->Space(-width => 3); | ||
| 863 | $image->Image(-image => $filter_images->[$i], -anchor => 'e'); | ||
| 864 | } | ||
| 865 | #------------------------------------- | ||
| 866 | # Store the new images | ||
| 867 | $hcolptr->{Image}{Compound}[$i++] = $image | ||
| 868 | } | ||
| 869 | #------------------------------------- | ||
| 870 | # Supply to the Headerbutton | ||
| 871 | $headerbttn->configure(-image => $hcolptr->{Image}{Compound}[STD]); | ||
| 872 | # Setup IMG change for 'active' state | ||
| 873 | $old_bind = $headerbttn->bind('<Enter>', sub { my $this = $_[0]; | ||
| 874 | $this->configure(-image => $hcolptr->{Image}{Compound}[ACT]) | ||
| 875 | if $this->cget('-state') ne 'disabled' } ); | ||
| 876 | $hcolptr->{EnterCB} = $old_bind unless $hcolptr->{EnterCB}; | ||
| 877 | # | ||
| 878 | $old_bind = $headerbttn->bind('<Leave>', sub { my $this = $_[0]; | ||
| 879 | $this->configure(-image => $hcolptr->{Image}{Compound}[STD]) | ||
| 880 | if $this->cget('-state') ne 'disabled' } ); | ||
| 881 | $hcolptr->{LeaveCB} = $old_bind unless $hcolptr->{LeaveCB}; | ||
| 882 | } | ||
| 883 | else { | ||
| 884 | # We shall remove all special markers | ||
| 885 | $headerbttn->configure(-image => undef); | ||
| 886 | $headerbttn->bind ('<Enter>', $hcolptr->{EnterCB} ); | ||
| 887 | $headerbttn->bind ('<Leave>', $hcolptr->{LeaveCB} ); | ||
| 888 | } | ||
| 889 | } | ||
| 890 | |||
| 891 | |||
| 892 | #-------------------------------------------------------------------------------------------------- | ||
| 893 | # | ||
| 894 | # Trim/Resize related functions | ||
| 895 | # | ||
| 896 | #-------------------------------------------------------------------------------------------------- | ||
| 897 | |||
| 898 | #-------------------------------------- | ||
| 899 | # CALLED IF WE ENTER THE TRIM AREA | ||
| 900 | #-------------------------------------- | ||
| 901 | sub TrimEnable | ||
| 902 | { | ||
| 903 | # Parameters | ||
| 904 | my ($this, $column, $enable) = @_; | ||
| 905 | # Locals | ||
| 906 | my ($rszinfo, $trim_widget); | ||
| 907 | |||
| 908 | # Shortcuts | ||
| 909 | $rszinfo = $this->{__TP_ResizeInfo}{$column}; | ||
| 910 | $trim_widget = $rszinfo->{TrimWidget}; | ||
| 911 | |||
| 912 | if ($enable) { | ||
| 913 | $rszinfo->{Bind_ButtonRelease_1} = | ||
| 914 | $trim_widget->bind( '<ButtonRelease-1>' => | ||
| 915 | sub { $this->TrimButtonRelease($column, 1) } ) unless $rszinfo->{Bind_ButtonRelease_1}; | ||
| 916 | $rszinfo->{Bind_ButtonPress_1} = | ||
| 917 | $trim_widget->bind( '<ButtonPress-1>' => | ||
| 918 | sub { $this->TrimButtonPress($column, 1) } ) unless $rszinfo->{Bind_ButtonPress_1}; | ||
| 919 | $rszinfo->{Bind_Motion} = | ||
| 920 | $trim_widget->bind( '<Motion>' => | ||
| 921 | sub { $this->MoveColumnBar($column) } ) unless $rszinfo->{Bind_Motion}; | ||
| 922 | $rszinfo->{Bind_Enter} = | ||
| 923 | $trim_widget->bind( '<Enter>' => | ||
| 924 | sub { $this->TrimEnter($column) } ) unless $rszinfo->{Bind_Enter}; | ||
| 925 | $rszinfo->{Bind_Leave} = | ||
| 926 | $trim_widget->bind( '<Leave>' => | ||
| 927 | sub { $this->TrimLeave() } ) unless $rszinfo->{Bind_Leave}; | ||
| 928 | $trim_widget->configure(-cursor => 'sb_h_double_arrow'); | ||
| 929 | } | ||
| 930 | else { | ||
| 931 | $trim_widget->bind( '<ButtonRelease-1>' => $rszinfo->{Bind_ButtonRelease_1} ); | ||
| 932 | $trim_widget->bind( '<ButtonPress-1>' => $rszinfo->{Bind_ButtonPress_1} ); | ||
| 933 | $trim_widget->bind( '<Motion>' => $rszinfo->{Bind_Motion} ); | ||
| 934 | $trim_widget->bind( '<Enter>' => $rszinfo->{Bind_Enter} ); | ||
| 935 | $trim_widget->bind( '<Leave>' => $rszinfo->{Bind_Leave} ); | ||
| 936 | $trim_widget->configure(-cursor => undef); | ||
| 937 | # safely disable | ||
| 938 | $this->HideTrimColumnBar(); | ||
| 939 | # deactivate any non-std columnwidth | ||
| 940 | $this->SetColumnWidth($column, 'Auto'); | ||
| 941 | } | ||
| 942 | } | ||
| 943 | |||
| 944 | #-------------------------------------- | ||
| 945 | # CALLED IF WE ENTER THE TRIM AREA | ||
| 946 | #-------------------------------------- | ||
| 947 | sub TrimEnter | ||
| 948 | { | ||
| 949 | # Parameters | ||
| 950 | my ($this, $column) = @_; | ||
| 951 | # Locals | ||
| 952 | my ($trim_widget); | ||
| 953 | |||
| 954 | $trim_widget = $this->{__TP_ResizeInfo}{$column}{TrimWidget}; | ||
| 955 | if ($column == $this->cget('-columns') - 1) { | ||
| 956 | $trim_widget->configure(-cursor => undef); | ||
| 957 | } | ||
| 958 | else { | ||
| 959 | $trim_widget->configure(-cursor => 'sb_h_double_arrow'); | ||
| 960 | # $this->TrimUpdate($column, 1); | ||
| 961 | $this->MoveColumnBar($column, 1); | ||
| 962 | } | ||
| 963 | } | ||
| 964 | |||
| 965 | #-------------------------------------- | ||
| 966 | # CALLED IF WE LEAVE THE TRIM AREA | ||
| 967 | #-------------------------------------- | ||
| 968 | sub TrimLeave | ||
| 969 | { | ||
| 970 | $_[0]->HideTrimColumnBar() | ||
| 971 | } | ||
| 972 | |||
| 973 | #-------------------------------------- | ||
| 974 | # Move a column bar which displays on top of the HList widget | ||
| 975 | # to indicate the eventual size of the column. | ||
| 976 | #-------------------------------------- | ||
| 977 | sub MoveColumnBar | ||
| 978 | { | ||
| 979 | # Parameters | ||
| 980 | my ($this, $column) = @_; | ||
| 981 | # Lcoals | ||
| 982 | my ($trim_widget, $height, $x); | ||
| 983 | |||
| 984 | if ($this->IsValidEdge($column)) { | ||
| 985 | $trim_widget = $this->{__TP_ResizeInfo}{$column}{TrimWidget}; | ||
| 986 | $height = $this->height() - $trim_widget->height(); | ||
| 987 | $x = $this->pointerx() - $this->rootx() + 1; # +1 for move right into gap | ||
| 988 | |||
| 989 | $this->{__TP_ResizeInfo}{ColumnBar}->place( | ||
| 990 | '-x' => $x, | ||
| 991 | '-height' => $height - 5, | ||
| 992 | '-y' => $trim_widget->height() + 5, | ||
| 993 | ) if $column != $this->cget('-columns') - 1; | ||
| 994 | $this->{__TP_ResizeInfo}{ColumnBarVisible} = 1; | ||
| 995 | } | ||
| 996 | } | ||
| 997 | |||
| 998 | #-------------------------------------- | ||
| 999 | # REMOVES IT FROM DISPLAY without destroying it | ||
| 1000 | #-------------------------------------- | ||
| 1001 | sub HideTrimColumnBar | ||
| 1002 | { | ||
| 1003 | # Parameters | ||
| 1004 | my $this = $_[0]; | ||
| 1005 | if ($this->{__TP_ResizeInfo}{ColumnBarVisible}) { | ||
| 1006 | $this->{__TP_ResizeInfo}{ColumnBarVisible} = 0; | ||
| 1007 | $this->{__TP_ResizeInfo}{ColumnBar}->placeForget(); | ||
| 1008 | } | ||
| 1009 | } | ||
| 1010 | |||
| 1011 | #-------------------------------------- | ||
| 1012 | # RESIZE ACTIONS | ||
| 1013 | #-------------------------------------- | ||
| 1014 | sub TrimButtonPress | ||
| 1015 | { | ||
| 1016 | # Parameters | ||
| 1017 | my ($this, $column, $activate_trim_flag) = @_; | ||
| 1018 | # Locals | ||
| 1019 | my ($trim_widget); | ||
| 1020 | |||
| 1021 | $trim_widget = $this->{__TP_ResizeInfo}{$column}{TrimWidget}; | ||
| 1022 | if ($this->IsValidEdge($column) or $activate_trim_flag) { | ||
| 1023 | $this->{__TP_ResizeInfo}{XStart} = $trim_widget->pointerx() - $trim_widget->rootx(); | ||
| 1024 | } | ||
| 1025 | else { | ||
| 1026 | $this->{__TP_ResizeInfo}{XStart} = -1 | ||
| 1027 | } | ||
| 1028 | } | ||
| 1029 | sub TrimButtonRelease | ||
| 1030 | { | ||
| 1031 | # Parameters | ||
| 1032 | my ($this, $column, $activate_trim_flag) = @_; | ||
| 1033 | |||
| 1034 | # Immediately hiode it | ||
| 1035 | $this->HideTrimColumnBar(); | ||
| 1036 | |||
| 1037 | if ($this->{__TP_ResizeInfo}{XStart} >= 0) { | ||
| 1038 | my ($trim_widget, $min_width, $old_width, $new_width, $headerbttn); | ||
| 1039 | |||
| 1040 | $trim_widget = $this->{__TP_ResizeInfo}{$column}{TrimWidget}; | ||
| 1041 | $min_width = $this->{__TP_ResizeInfo}{$column}{ColumnMinWidth} || 5; | ||
| 1042 | $old_width = $this->columnWidth($column); | ||
| 1043 | # Calculate new width | ||
| 1044 | $new_width = $old_width + ( $trim_widget->pointerx() - $trim_widget->rootx() ); | ||
| 1045 | $new_width = $min_width if $new_width < $min_width; | ||
| 1046 | |||
| 1047 | $this->SetColumnWidth($column, 'Custom', $new_width) | ||
| 1048 | } | ||
| 1049 | $this->{__TP_ResizeInfo}{XStart} = -1; | ||
| 1050 | } | ||
| 1051 | |||
| 1052 | #-------------------------------------- | ||
| 1053 | # CHECK IF THE RESIZE CONTROL IS SELECTED | ||
| 1054 | #-------------------------------------- | ||
| 1055 | sub IsValidEdge | ||
| 1056 | { | ||
| 1057 | my ($this, $column) = @_; | ||
| 1058 | return (($column == ($this->cget('-columns') - 1)) ? 0 : 1); | ||
| 1059 | } | ||
| 1060 | |||
| 1061 | #-------------------------------------- | ||
| 1062 | # Supply a new ColumnWidth | ||
| 1063 | #-------------------------------------- | ||
| 1064 | sub SetColumnWidth | ||
| 1065 | { | ||
| 1066 | # Parameters | ||
| 1067 | my ($this, $column, $cmd, $value) = @_; | ||
| 1068 | # Locals | ||
| 1069 | my ($rszinfo, $old_width, $old_anchor, $old_wraplength, $new_width, $headerbttn, $anchor, $wrap_length); | ||
| 1070 | |||
| 1071 | # Shortcuts | ||
| 1072 | $rszinfo = $this->{__TP_ResizeInfo}{$column}; | ||
| 1073 | $headerbttn = $this->{__TP_HeaderInfo}{$column}{Widget}; | ||
| 1074 | |||
| 1075 | # Store the last value | ||
| 1076 | $old_width = $this->columnWidth($column); | ||
| 1077 | $old_anchor = $headerbttn->cget('-anchor'); | ||
| 1078 | $old_wraplength = $headerbttn->cget('-wraplength')||0; | ||
| 1079 | # Store the 'Auto' / Default settings | ||
| 1080 | $rszinfo->{AnchorOrg} = $old_anchor unless defined $rszinfo->{AnchorOrg}; | ||
| 1081 | $rszinfo->{WrapLengthOrg} = $old_wraplength unless defined $rszinfo->{WrapLengthOrg}; | ||
| 1082 | |||
| 1083 | # Configure the behavior for 'user controlled sizes' | ||
| 1084 | if ($cmd =~ /auto|default/io) { | ||
| 1085 | $anchor = $rszinfo->{AnchorOrg}; | ||
| 1086 | $wrap_length = $rszinfo->{WrapLengthOrg}; | ||
| 1087 | $new_width = '' | ||
| 1088 | } | ||
| 1089 | elsif ($cmd =~ /min/io) { | ||
| 1090 | $anchor = 'w'; | ||
| 1091 | $wrap_length = 0; | ||
| 1092 | $new_width = $rszinfo->{ColumnMinWidth} | ||
| 1093 | } | ||
| 1094 | elsif ($cmd =~ /close/io) { | ||
| 1095 | $anchor = $rszinfo->{AnchorOrg}; | ||
| 1096 | $wrap_length = 0; | ||
| 1097 | $new_width = $rszinfo->{ColumnClosedWidth} | ||
| 1098 | } | ||
| 1099 | elsif ($cmd =~ /last/io) { | ||
| 1100 | $anchor = $rszinfo->{ColumLastAnchor}; | ||
| 1101 | $wrap_length = $rszinfo->{ColumLastWrapLength}; | ||
| 1102 | $new_width = $rszinfo->{ColumLastWidth} || $old_width; | ||
| 1103 | } | ||
| 1104 | elsif ($cmd =~ /custom/io) { | ||
| 1105 | $anchor = 'w'; | ||
| 1106 | $wrap_length = $value; | ||
| 1107 | $new_width = $value | ||
| 1108 | } | ||
| 1109 | else { | ||
| 1110 | croak "Unknown cmd [$cmd] for SetColumnWidth()! [called by >", caller, "<]\n" | ||
| 1111 | } | ||
| 1112 | # Apply it | ||
| 1113 | $this->columnWidth($column, $new_width); | ||
| 1114 | |||
| 1115 | # Store infos for next cycle | ||
| 1116 | $rszinfo->{ColumnWidth} = $new_width; | ||
| 1117 | $rszinfo->{WrapLength} = $wrap_length; | ||
| 1118 | $rszinfo->{ColumLastWidth} = $old_width; | ||
| 1119 | $rszinfo->{ColumLastAnchor} = $old_anchor; | ||
| 1120 | $rszinfo->{ColumLastWrapLength} = $old_wraplength; | ||
| 1121 | $rszinfo->{Mode} = $cmd; | ||
| 1122 | #print "DBG: variable [\$new_width, \$anchor, \$wrap_length] = >$new_width< >$anchor< >$wrap_length<\n"; | ||
| 1123 | #------------------------------------------------------------------- | ||
| 1124 | # Some Postprocessing | ||
| 1125 | # Modify the Header ResizeBttn attr to be better visable | ||
| 1126 | $headerbttn->configure(-anchor => $anchor, -wraplength => $wrap_length); | ||
| 1127 | $this->RefreshColumnHeader($column); # Necessary to rebuild Compound images | ||
| 1128 | } | ||
| 1129 | |||
| 1130 | |||
| 1131 | #-------------------------------------------------------------------------------------------------- | ||
| 1132 | # | ||
| 1133 | # RMBPopUpMenu() | ||
| 1134 | # | ||
| 1135 | # IN : I<-listwidget, I<current_column> | ||
| 1136 | # | ||
| 1137 | # OUT: I<---> | ||
| 1138 | # | ||
| 1139 | # B<Description>: | ||
| 1140 | # Creates a Pop-up Menu for the given list | ||
| 1141 | # for single column OR multiple list operations | ||
| 1142 | # | ||
| 1143 | #-------------------------------------------------------------------------------------------------- | ||
| 1144 | sub RMBPopUpMenu | ||
| 1145 | { | ||
| 1146 | # Parameters | ||
| 1147 | my ($this, $current_column) = @_; | ||
| 1148 | |||
| 1149 | # Locals | ||
| 1150 | my ($search_info, $col_search, @all_columns, $single_column, @used_columns, $menu, $find_submenu, | ||
| 1151 | $accelerator1, $accelerator2, $column, $filter_submenu, $submenu, | ||
| 1152 | $resize_submenu, $submenu2, $submenu3, $xclip_submenu); | ||
| 1153 | |||
| 1154 | #------------------------------------------------------------------------ | ||
| 1155 | # Shortcuts | ||
| 1156 | $search_info = $this->{__TP_SearchInfo}; | ||
| 1157 | $col_search = $search_info->{Columns}; | ||
| 1158 | @all_columns = sort { $a <=>$b } keys %$col_search; | ||
| 1159 | $single_column = (defined $current_column) ? 1 : 0; # make the following checks easier | ||
| 1160 | @used_columns = $single_column ? ($current_column) : (@all_columns); | ||
| 1161 | |||
| 1162 | #------------------------------------------------------------------------ | ||
| 1163 | $menu = $this->{__TP_PopUpListOperationsMenu}; | ||
| 1164 | if ($menu) { | ||
| 1165 | $menu->delete(0, 'end'); | ||
| 1166 | } | ||
| 1167 | else { | ||
| 1168 | $menu = $this->{__TP_PopUpListOperationsMenu} = $this->Menu( | ||
| 1169 | -tearoff => '0', | ||
| 1170 | #-disabledforeground => $this->cget('-foreground') | ||
| 1171 | ); | ||
| 1172 | } | ||
| 1173 | #------------------------------------------------------------------------ | ||
| 1174 | if ($single_column) { | ||
| 1175 | $find_submenu = $menu | ||
| 1176 | } | ||
| 1177 | else { | ||
| 1178 | $find_submenu = $menu->cascade( | ||
| 1179 | -label => 'Find', | ||
| 1180 | -tearoff => '0', | ||
| 1181 | ) | ||
| 1182 | } | ||
| 1183 | # Some Shortcuts | ||
| 1184 | $accelerator1 = 'Ctrl-f'; | ||
| 1185 | $accelerator2 = 'Ctrl-h'; | ||
| 1186 | foreach $column (@used_columns) { | ||
| 1187 | my ($column_name, $last_pattern, $is_numeric_col, $column_curr); | ||
| 1188 | $column_name = $col_search->{$column}; | ||
| 1189 | $last_pattern = $search_info->{SearchPattern}{$column}; | ||
| 1190 | $is_numeric_col = $this->{__TP_HeaderInfo}{$column}{SortNumeric}; | ||
| 1191 | $column_curr = $column; # Closure ! | ||
| 1192 | |||
| 1193 | if ($last_pattern and not $is_numeric_col) { | ||
| 1194 | $submenu = $find_submenu->cascade( | ||
| 1195 | -label => ($single_column ? 'Find' : ucfirst($column_name)), | ||
| 1196 | -tearoff => '0', | ||
| 1197 | ); | ||
| 1198 | $submenu->command( | ||
| 1199 | -label => 'Find ...', | ||
| 1200 | -command => sub { $this->__find_hlentry($column_curr) }, | ||
| 1201 | -accelerator => $accelerator1 | ||
| 1202 | ); | ||
| 1203 | $submenu->command( | ||
| 1204 | -label => 'Find NEXT [' . $last_pattern . ']', | ||
| 1205 | -command => sub { $this->__find_hlentry($column_curr, 'NEXT'); | ||
| 1206 | $this->bind('<Control-h>' => | ||
| 1207 | sub { $this->__find_hlentry($column_curr, 'NEXT') } ) | ||
| 1208 | }, | ||
| 1209 | -accelerator => $accelerator2 | ||
| 1210 | ); | ||
| 1211 | $accelerator2 = undef; | ||
| 1212 | } | ||
| 1213 | else { | ||
| 1214 | # if ($find_submenu->index('end') !~ /none/io) { | ||
| 1215 | if ($is_numeric_col) { | ||
| 1216 | $find_submenu->separator unless $accelerator1; # Already at least one column before ID-col | ||
| 1217 | $accelerator1 = 'Ctrl-F'; | ||
| 1218 | } | ||
| 1219 | $find_submenu->command( | ||
| 1220 | -label => ($single_column ? 'Find ...' : ucfirst($column_name)), | ||
| 1221 | -command => sub { $this->__find_hlentry($column_curr) }, | ||
| 1222 | -accelerator => $accelerator1 | ||
| 1223 | ); | ||
| 1224 | } | ||
| 1225 | $accelerator1 = undef; | ||
| 1226 | } | ||
| 1227 | #------------------------------------------------------------------------ | ||
| 1228 | $menu->separator; | ||
| 1229 | if ($single_column and not $this->{__TP_PatternFilterInfo}{Active}{$current_column}) { | ||
| 1230 | $menu->command( | ||
| 1231 | -label => 'Filter ...', | ||
| 1232 | -command => sub { $this->ExecutePatternFilter($current_column, 'ASK') }, | ||
| 1233 | ); | ||
| 1234 | } | ||
| 1235 | else { | ||
| 1236 | $filter_submenu = $menu->cascade( | ||
| 1237 | -label => 'Filter', | ||
| 1238 | -tearoff => '0', | ||
| 1239 | ); | ||
| 1240 | #------------------------------------- | ||
| 1241 | foreach $column (@used_columns) { | ||
| 1242 | my $column_name = $col_search->{$column}; | ||
| 1243 | my $column_curr = $column; # Closure ! | ||
| 1244 | if ($single_column) { | ||
| 1245 | $submenu = $filter_submenu | ||
| 1246 | } | ||
| 1247 | else { | ||
| 1248 | $submenu = $filter_submenu->cascade( | ||
| 1249 | -label => ucfirst($column_name), | ||
| 1250 | -tearoff => '0', | ||
| 1251 | ); | ||
| 1252 | } | ||
| 1253 | $submenu->command( | ||
| 1254 | -label => 'Set ...', | ||
| 1255 | -command => sub { $this->ExecutePatternFilter($column_curr, 'ASK') }, | ||
| 1256 | ); | ||
| 1257 | $submenu->command( | ||
| 1258 | -label => 'Remove', | ||
| 1259 | -command => sub { $this->ExecutePatternFilter($column_curr, 'REMOVE') }, | ||
| 1260 | ) | ||
| 1261 | } | ||
| 1262 | } | ||
| 1263 | unless ($single_column) { | ||
| 1264 | $filter_submenu->separator; | ||
| 1265 | $filter_submenu->command( | ||
| 1266 | -label => 'Remove ALL', | ||
| 1267 | -command => sub { $this->ExecutePatternFilter(0, 'REMOVE_ALL') }, | ||
| 1268 | ); | ||
| 1269 | } | ||
| 1270 | #------------------------------------------------------------------------ | ||
| 1271 | if ($this->{__TP_SelectHistory} and (@used_columns > 1 or $current_column == 0)) { | ||
| 1272 | # Step 1: Refresh the selection list (might have changed/invalid due to delete/refresh/insert list entries) | ||
| 1273 | my ($sel_hist, $path, @valid_sel_histories); | ||
| 1274 | foreach $sel_hist (@{$this->{__TP_SelectHistory}}) { | ||
| 1275 | $path = $sel_hist->[2]; | ||
| 1276 | if ($this->infoExists($path)) { | ||
| 1277 | push @valid_sel_histories, $sel_hist; | ||
| 1278 | } | ||
| 1279 | } | ||
| 1280 | $this->{__TP_SelectHistory} = \@valid_sel_histories; | ||
| 1281 | # Step 2: Show valid selections | ||
| 1282 | if (@valid_sel_histories) { | ||
| 1283 | $menu->separator; | ||
| 1284 | my $select_submenu = $menu->cascade( | ||
| 1285 | -label => 'Selection History', | ||
| 1286 | -tearoff => '0', | ||
| 1287 | -state => 'normal', | ||
| 1288 | ); | ||
| 1289 | foreach my $sel_hist (@valid_sel_histories) { # NOTE the 'my' CLOSURE!!! MKr | ||
| 1290 | #print "DBG: set menu [\$sel_hist] = "; ETC::Universal::print_var($sel_hist, 1); | ||
| 1291 | $select_submenu->command( | ||
| 1292 | -label => "<Re>Select '" . $sel_hist->[0] ."'", | ||
| 1293 | -command => sub { my $path = $sel_hist->[2]; | ||
| 1294 | $this->selectionClear; | ||
| 1295 | $this->selectionSet($path); | ||
| 1296 | $this->see($path); | ||
| 1297 | $this->anchorClear; | ||
| 1298 | $sel_hist->[1]->Call($path) }, | ||
| 1299 | ); | ||
| 1300 | } | ||
| 1301 | $select_submenu->separator; | ||
| 1302 | $select_submenu->command( | ||
| 1303 | -label => 'Clear History', | ||
| 1304 | -command => sub { $this->{__TP_SelectHistory} = [] }, | ||
| 1305 | ); | ||
| 1306 | } | ||
| 1307 | } | ||
| 1308 | |||
| 1309 | |||
| 1310 | #------------------------------------------------------------------------ | ||
| 1311 | $menu->separator; | ||
| 1312 | $resize_submenu = $menu->cascade( | ||
| 1313 | -label => 'Column Size', | ||
| 1314 | -tearoff => '0', | ||
| 1315 | ); | ||
| 1316 | #------------------------------------- | ||
| 1317 | foreach $column (@used_columns) { | ||
| 1318 | my $column_name = $col_search->{$column}; | ||
| 1319 | my $var = $this->{__TP_ResizeInfo}{$column}{TrimActive}; # Closure ! | ||
| 1320 | my $column_curr = $column; # Closure ! | ||
| 1321 | |||
| 1322 | if ($single_column) { | ||
| 1323 | $submenu = $resize_submenu | ||
| 1324 | } | ||
| 1325 | else { | ||
| 1326 | $submenu = $resize_submenu->cascade( | ||
| 1327 | -label => ucfirst($column_name), | ||
| 1328 | -tearoff => '0', | ||
| 1329 | ); | ||
| 1330 | } | ||
| 1331 | $submenu->checkbutton( | ||
| 1332 | # -label => ($single_column ? 'Dynamic Column-Resizing' : ucfirst($column_name)), | ||
| 1333 | -label => 'Dynamic Column-Resizing', | ||
| 1334 | -command => sub { $this->{__TP_ResizeInfo}{$column_curr}{TrimActive} = $var; | ||
| 1335 | $this->TrimEnable($column_curr, $var); | ||
| 1336 | }, | ||
| 1337 | -variable => \$var, | ||
| 1338 | ); | ||
| 1339 | $submenu2 = $submenu->cascade( | ||
| 1340 | -label => 'Column Width', | ||
| 1341 | -tearoff => '0', | ||
| 1342 | -state => $this->{__TP_ResizeInfo}{$column}{TrimActive} ? 'normal' : 'disabled', | ||
| 1343 | ); | ||
| 1344 | $submenu2->command( | ||
| 1345 | -label => 'Auto', | ||
| 1346 | -command => sub { $this->SetColumnWidth($column_curr, 'Auto') }, | ||
| 1347 | -accelerator => $accelerator1 | ||
| 1348 | ); | ||
| 1349 | $submenu2->command( | ||
| 1350 | -label => 'Last', | ||
| 1351 | -command => sub { $this->SetColumnWidth($column_curr, 'Last') }, | ||
| 1352 | ); | ||
| 1353 | $submenu2->command( | ||
| 1354 | -label => 'Min', | ||
| 1355 | -command => sub { $this->SetColumnWidth($column_curr, 'Min') }, | ||
| 1356 | ); | ||
| 1357 | $submenu2->command( | ||
| 1358 | -label => 'Closed', | ||
| 1359 | -command => sub { $this->SetColumnWidth($column_curr, 'Close') }, | ||
| 1360 | ) | ||
| 1361 | } | ||
| 1362 | #------------------------------------- | ||
| 1363 | unless ($single_column) { | ||
| 1364 | $resize_submenu->separator; | ||
| 1365 | $resize_submenu->command( | ||
| 1366 | -label => 'Restore DEFAULT', | ||
| 1367 | -command => sub { map { $this->SetColumnWidth($_, 'Auto') } @all_columns }, | ||
| 1368 | ) | ||
| 1369 | } | ||
| 1370 | #------------------------------------------------------------------------ | ||
| 1371 | $menu->separator; | ||
| 1372 | $xclip_submenu = $menu->cascade( | ||
| 1373 | -label => 'X-ClipBoard', | ||
| 1374 | -tearoff => '0', | ||
| 1375 | ); | ||
| 1376 | $xclip_submenu->command( | ||
| 1377 | -label => 'Export Selected Entry(ies)', | ||
| 1378 | -command => sub { $this->__copy_selection_to_clipboard() }, | ||
| 1379 | -accelerator => 'Ctrl-c' | ||
| 1380 | ); | ||
| 1381 | $xclip_submenu->command( | ||
| 1382 | -label => 'Export Selection + Column Headers', | ||
| 1383 | -command => sub { $this->__copy_selection_to_clipboard('use_header_info') }, | ||
| 1384 | -accelerator => 'Ctrl-C' | ||
| 1385 | ); | ||
| 1386 | |||
| 1387 | # Set some default bindings | ||
| 1388 | $this->bind('<Control-c>' => sub { $this->__copy_selection_to_clipboard() } ); | ||
| 1389 | $this->bind('<Control-C>' => sub { $this->__copy_selection_to_clipboard('use_header_info') } ); | ||
| 1390 | $this->bind('<Control-f>' => sub { $this->__find_hlentry(0) } ); | ||
| 1391 | |||
| 1392 | |||
| 1393 | #------------------------------------------------------------------------ | ||
| 1394 | $menu->Popup(-popover => 'cursor', -popanchor => 'nw'); | ||
| 1395 | } | ||
| 1396 | |||
| 1397 | #-------------------------------------------------------------------------------------------------- | ||
| 1398 | # | ||
| 1399 | # InitializeSelectHistory() | ||
| 1400 | # | ||
| 1401 | # IN : I<-listwidget => list-widget>, I<-event_binding => alternate pop-up-event> | ||
| 1402 | # | ||
| 1403 | # OUT: I<---> | ||
| 1404 | # | ||
| 1405 | # B<Description>: | ||
| 1406 | # Add an interceptor for the browsecommand callback to store the last 10 selections | ||
| 1407 | # | ||
| 1408 | #-------------------------------------------------------------------------------------------------- | ||
| 1409 | sub InitializeSelectHistory | ||
| 1410 | { | ||
| 1411 | #print "called AddPopUpListOperations with >@_< from ", caller, "<\n"; | ||
| 1412 | # Parameter | ||
| 1413 | my $this = $_[0]; | ||
| 1414 | # Locals | ||
| 1415 | my ($browsecmd); | ||
| 1416 | |||
| 1417 | #------------------------------------------------------------------------ | ||
| 1418 | # Rough Check | ||
| 1419 | return if $this->{__TP_SelectHistoryEngaged}; | ||
| 1420 | |||
| 1421 | #------------------------------------------------------------------------ | ||
| 1422 | $browsecmd = $this->cget('-browsecmd'); #print "DBG: variable [\$browsecmd] = >$browsecmd<\n"; | ||
| 1423 | if ($browsecmd) { | ||
| 1424 | $this->{__TP_SelectHistoryEngaged} = 1; | ||
| 1425 | $this->configure(-browsecmd => | ||
| 1426 | sub { #print "DBG: reached function [browsecmd-interceptor] with >@_<, called by >", caller, "<\n"; | ||
| 1427 | #Parameters | ||
| 1428 | my ($path, @args) = @_; | ||
| 1429 | # Locals | ||
| 1430 | my ($this_id, $select_history, $parent, @path, $entry_txt); | ||
| 1431 | |||
| 1432 | # FailSafe: Avoid circular invocations | ||
| 1433 | return if $this->{BrowseCmdOngoing}; | ||
| 1434 | local $this->{BrowseCmdOngoing} = 1; | ||
| 1435 | |||
| 1436 | unless (@args) { | ||
| 1437 | $this_id = $this->id; | ||
| 1438 | $this->{__TP_SelectHistory} = [] unless $this->{__TP_SelectHistory}; | ||
| 1439 | $select_history = $this->{__TP_SelectHistory}; | ||
| 1440 | |||
| 1441 | # Latch only different calls | ||
| 1442 | unless (grep m/^$path$/, map {$_->[2]} @$select_history) { | ||
| 1443 | $parent = $this->infoParent($path); | ||
| 1444 | if ($parent) { | ||
| 1445 | @path = $this->itemCget($path, 0, '-text'); | ||
| 1446 | while ($parent) { | ||
| 1447 | push @path, $this->itemCget($parent, 0, '-text'); | ||
| 1448 | $parent = $this->infoParent($parent); | ||
| 1449 | } | ||
| 1450 | $entry_txt = join('/', reverse @path); | ||
| 1451 | } | ||
| 1452 | else { | ||
| 1453 | $entry_txt = $this->itemCget($path, 0, '-text') | ||
| 1454 | } | ||
| 1455 | #print "DBG: variable [\$entry_txt, \$path] = >$entry_txt, $path<\n"; | ||
| 1456 | push @$select_history, [$entry_txt, $browsecmd, $path ]; | ||
| 1457 | shift @$select_history if @$select_history > $this->cget('-maxselhistory'); | ||
| 1458 | } | ||
| 1459 | } | ||
| 1460 | # Finally continue with the official callback | ||
| 1461 | $browsecmd->Call(@_) | ||
| 1462 | } | ||
| 1463 | ); | ||
| 1464 | } | ||
| 1465 | } | ||
| 1466 | |||
| 1467 | #-------------------------------------------------------------------------------------------------- | ||
| 1468 | # | ||
| 1469 | # ExecutePatternFilter() | ||
| 1470 | # | ||
| 1471 | # IN : I<dialog_class>, I<list-widget>, I<SEarchColumn-Num>, I<$mode>, I<$filter_pattern> | ||
| 1472 | # | ||
| 1473 | # OUT: I<$filter-hash> | ||
| 1474 | # | ||
| 1475 | # B<Description>: | ||
| 1476 | # Maintains the Pattern Filter for Columns. | ||
| 1477 | # CMDs: Set/Remove/Pattern/Filter | ||
| 1478 | # | ||
| 1479 | #-------------------------------------------------------------------------------------------------- | ||
| 1480 | sub ExecutePatternFilter | ||
| 1481 | { | ||
| 1482 | # Parameters | ||
| 1483 | my ($this, $column, $cmd) = @_; | ||
| 1484 | # Locals | ||
| 1485 | my ($fpinfo); | ||
| 1486 | |||
| 1487 | return unless defined $column; | ||
| 1488 | |||
| 1489 | # Define some shortcuts | ||
| 1490 | $this->{__TP_PatternFilterInfo} = {} unless $this->{__TP_PatternFilterInfo}; | ||
| 1491 | $fpinfo = $this->{__TP_PatternFilterInfo}; | ||
| 1492 | |||
| 1493 | if ($cmd =~ /ASK/io) { | ||
| 1494 | my ($column_name, $headerbttn, $old_pattern, $new_pattern); | ||
| 1495 | $column_name = $this->headerCget($column, '-text'); | ||
| 1496 | $old_pattern = $fpinfo->{Pattern}{$column}; $old_pattern = '' unless defined $old_pattern; | ||
| 1497 | ($new_pattern, $cmd) = $this->EnterStringDlg( | ||
| 1498 | -default_button => 'Set', | ||
| 1499 | -value => $old_pattern, | ||
| 1500 | -buttons => ['Set', ($fpinfo->{Active}{$column} ? ('Clear') : ()), 'Cancel'], | ||
| 1501 | -title => 'Column Filter for [' . $column_name . ']', | ||
| 1502 | -label => 'FilterPattern: ', | ||
| 1503 | -validatecommand => sub { return $_[1] =~ /[\w\:?\*\.\-\+\^\$\[\]\(\)\{\}\\\|\s]/o }, | ||
| 1504 | ); | ||
| 1505 | # Filter out invalid keys that would be undeletable otherwise | ||
| 1506 | $new_pattern =~ s/\'|\"//go; | ||
| 1507 | |||
| 1508 | if ($cmd =~ /Set/io) { | ||
| 1509 | $fpinfo->{Active}{$column} = 1; | ||
| 1510 | $fpinfo->{Pattern}{$column} = $new_pattern; | ||
| 1511 | $fpinfo->{PatternRE}{$column} = qr/$new_pattern/; | ||
| 1512 | #------------------------------------------------- | ||
| 1513 | # Adopt the Column Headers | ||
| 1514 | $this->RefreshColumnHeader($column); | ||
| 1515 | #------------------------------------------------- | ||
| 1516 | # Filter the displayed-List | ||
| 1517 | $cmd = 'FILTER'; | ||
| 1518 | } | ||
| 1519 | } | ||
| 1520 | if ($cmd =~ /REMOVE|CLEAR/io) { | ||
| 1521 | my ($del_column, @columns); | ||
| 1522 | if ($cmd =~ /ALL/io) { | ||
| 1523 | @columns = keys %{$fpinfo->{Active}} | ||
| 1524 | } | ||
| 1525 | else { | ||
| 1526 | @columns = $column | ||
| 1527 | } | ||
| 1528 | foreach $del_column (@columns) { | ||
| 1529 | # Clear the active -flag but keep the pattern for convenience | ||
| 1530 | delete $fpinfo->{Active}{$del_column}; | ||
| 1531 | #------------------------------------------------- | ||
| 1532 | # Adopt the Column Headers | ||
| 1533 | $this->RefreshColumnHeader($del_column) | ||
| 1534 | } | ||
| 1535 | #------------------------------------------------- | ||
| 1536 | # Filter the displayed-List | ||
| 1537 | $cmd = 'FILTER'; | ||
| 1538 | } | ||
| 1539 | |||
| 1540 | # Second Cycle: Take care of the cmd-changes of ASK-/Remove-mode | ||
| 1541 | if ($cmd =~ /FILTER|REFRESH/io) { | ||
| 1542 | # Clear it to avoid accumulation of enabled filters | ||
| 1543 | my $filter_info = $fpinfo->{Filter} = {}; | ||
| 1544 | # Rebuild the current pattern matrix | ||
| 1545 | foreach $column (sort {$a<=>$b} keys %{$fpinfo->{Active}}) { | ||
| 1546 | $filter_info->{$column} = $fpinfo->{PatternRE}{$column} if $fpinfo->{Active}{$column} | ||
| 1547 | } | ||
| 1548 | # Execute the filter | ||
| 1549 | $this->__filter_hlentry_r($filter_info, '') | ||
| 1550 | } | ||
| 1551 | } | ||
| 1552 | |||
| 1553 | |||
| 1554 | #----------------------------------------------------------------- | ||
| 1555 | # Very internal related function, NOT to be invoked by user apps | ||
| 1556 | #----------------------------------------------------------------- | ||
| 1557 | # Transfers the current selected entries of the given | ||
| 1558 | # widget into the common X11-Clipboard. | ||
| 1559 | sub __copy_selection_to_clipboard | ||
| 1560 | { | ||
| 1561 | #print "DBG: reached function [__copy_selection_to_clipboard] with >@_<, called by >", caller, "<\n"; | ||
| 1562 | # Parameter | ||
| 1563 | my ($this, $use_header_info) = @_; | ||
| 1564 | |||
| 1565 | # Locals | ||
| 1566 | my (@selitems, $selectforeground, $selectbackground, $text, $clip_txt, | ||
| 1567 | $wclass, $col_cnt, $clipboard_column_separator, $column, $entry); | ||
| 1568 | |||
| 1569 | return unless $this; | ||
| 1570 | @selitems = $this->infoSelection(); | ||
| 1571 | if (@selitems) { | ||
| 1572 | $selectforeground = $this->cget('-selectforeground'); | ||
| 1573 | $selectbackground = $this->cget('-selectbackground'); | ||
| 1574 | |||
| 1575 | $wclass = ref $this; $clip_txt = ''; | ||
| 1576 | $col_cnt = $this->cget('-columns'); | ||
| 1577 | $clipboard_column_separator = $this->cget('-clipboardseparator'); | ||
| 1578 | if ($wclass =~ /HList|Tree/io and $use_header_info and $this->cget('-header')) { | ||
| 1579 | for ($column = 0; $column < $col_cnt; $column++) { | ||
| 1580 | $clip_txt .= $clipboard_column_separator if $clip_txt; | ||
| 1581 | $clip_txt .= $this->headerCget($column, '-text'); | ||
| 1582 | } | ||
| 1583 | #print "DBG: header: [\$clip_txt] = >$clip_txt<\n"; | ||
| 1584 | } | ||
| 1585 | # REtrieve all selected items | ||
| 1586 | foreach (@selitems) { | ||
| 1587 | if ($wclass =~ /TList/io) { | ||
| 1588 | $text = $this->entrycget($_, '-text'); | ||
| 1589 | } | ||
| 1590 | elsif ($wclass =~ /HList|Tree/io) { | ||
| 1591 | $text = ''; | ||
| 1592 | for ($column = 0; $column < $col_cnt; $column++) { | ||
| 1593 | $text .= $clipboard_column_separator if length $text; | ||
| 1594 | $entry = $this->itemCget($_, $column, '-text'); $entry = '' unless defined $entry; | ||
| 1595 | $text .= $entry; | ||
| 1596 | } | ||
| 1597 | } | ||
| 1598 | else { | ||
| 1599 | last; # don't do anything on unspecific widget types | ||
| 1600 | } | ||
| 1601 | $clip_txt .= "\n" if $clip_txt; | ||
| 1602 | $clip_txt .= $text; | ||
| 1603 | } | ||
| 1604 | if ($clip_txt) { | ||
| 1605 | # Update the global (unix) Clipboard | ||
| 1606 | $this->clipboardClear(); | ||
| 1607 | $this->clipboardAppend($clip_txt); | ||
| 1608 | $this->configure( -selectforeground => 'black', | ||
| 1609 | -selectbackground => ($use_header_info ? 'lawngreen' : 'darkgreen'), | ||
| 1610 | ); | ||
| 1611 | #print "DBG: Copied Entries [$clip_txt] from Widget [$wclass] to global X-clipboard.\n" | ||
| 1612 | } | ||
| 1613 | else { | ||
| 1614 | $this->clipboardClear(); | ||
| 1615 | $this->clipboardAppend($clip_txt); | ||
| 1616 | $this->configure( -selectforeground => 'white', | ||
| 1617 | -selectbackground => 'darkred', | ||
| 1618 | ); | ||
| 1619 | carp "Internal Warning: Failed to copy Entries from Widget [$wclass] to global X-clipboard!\n" | ||
| 1620 | } | ||
| 1621 | $this->update; | ||
| 1622 | usleep(900000); | ||
| 1623 | $this->configure( -selectforeground => $this->cget('-foreground'), | ||
| 1624 | -selectbackground => $this->cget('-background'), | ||
| 1625 | ); | ||
| 1626 | $this->update; | ||
| 1627 | usleep(300000); | ||
| 1628 | |||
| 1629 | # Restore original settings | ||
| 1630 | $this->configure( | ||
| 1631 | -selectforeground => $selectforeground, | ||
| 1632 | -selectbackground => $selectbackground, | ||
| 1633 | ); | ||
| 1634 | $this->update; | ||
| 1635 | } | ||
| 1636 | } | ||
| 1637 | |||
| 1638 | #----------------------------------------------------------------- | ||
| 1639 | # Very internal related function, NOT to be invoked by user apps | ||
| 1640 | #----------------------------------------------------------------- | ||
| 1641 | sub __find_hlentry | ||
| 1642 | { | ||
| 1643 | # Parameter | ||
| 1644 | my ($this, $column, $find_next_flag) = @_; | ||
| 1645 | |||
| 1646 | # Locals | ||
| 1647 | my ($search_info, $is_numeric_col, $search_item, $path, $parent, $answer); | ||
| 1648 | |||
| 1649 | # Some shortcuts | ||
| 1650 | $is_numeric_col = $this->{__TP_HeaderInfo}{$column}{SortNumeric}; | ||
| 1651 | $search_info = $this->{__TP_SearchInfo}; | ||
| 1652 | $search_item = $search_info->{SearchPattern}{$column}; | ||
| 1653 | |||
| 1654 | #---------------------------------------------------------------------------------------------- | ||
| 1655 | if ($find_next_flag and $search_item) { | ||
| 1656 | $answer = 'Find Next'; | ||
| 1657 | } | ||
| 1658 | else { | ||
| 1659 | my $column_name = $search_info->{Columns}{$column}; | ||
| 1660 | |||
| 1661 | ($search_item, $answer) = $this->EnterStringDlg( | ||
| 1662 | -default_button => 'Find', | ||
| 1663 | -value => $search_item, | ||
| 1664 | -buttons => ['Find', | ||
| 1665 | (($column_name and $search_item and not $is_numeric_col) | ||
| 1666 | ? ('Find Next') : ()), 'Cancel'], | ||
| 1667 | -title => 'Enter Search Item [' . $column_name . ']', | ||
| 1668 | -label => "Find '$column_name': ", | ||
| 1669 | -validatecommand => sub { my $value = $_[1]||''; | ||
| 1670 | if ($column_name eq 'ID') { | ||
| 1671 | return $value =~ /[\d\-]/o | ||
| 1672 | } | ||
| 1673 | else { | ||
| 1674 | return $value =~ /[\w\?\*\.\-\+\^\$\[\]\(\)\\\|\s]/o | ||
| 1675 | } | ||
| 1676 | }, | ||
| 1677 | ); | ||
| 1678 | return if $answer eq 'Cancel'; | ||
| 1679 | } | ||
| 1680 | #print "DBG: variable [\$search_item] = >$search_item< [\$answer] = >$answer< [\$column_name] = >$column_name< \n"; | ||
| 1681 | if ($search_item) { | ||
| 1682 | $this->update; | ||
| 1683 | $this->Busy(-recurse => 1); | ||
| 1684 | |||
| 1685 | #---------------------------------------------------------------------------------------------- | ||
| 1686 | # Store pattern for potential 'NEXT' Search | ||
| 1687 | $search_info->{SearchPattern}{$column} = $search_item; | ||
| 1688 | |||
| 1689 | #---------------------------------------------------------------------------------------------- | ||
| 1690 | # Support perl's regexes | ||
| 1691 | $search_item = '\b' . $search_item . '\b' if $is_numeric_col; | ||
| 1692 | $search_item = qr($search_item); | ||
| 1693 | |||
| 1694 | # Clear the Search StartPoint for Starting the Search at the very Beginning | ||
| 1695 | $search_info->{LastHLEntry} = '' if $answer !~ /Next/io or $is_numeric_col; | ||
| 1696 | |||
| 1697 | # NOTE: We have to pass a reference to the startposition-path to be able to reset it GLOBALLY, if we detect the last stop | ||
| 1698 | $path = __find_hlentry_r($this, $search_item, $column, '', \$search_info->{LastHLEntry}); | ||
| 1699 | $this->Unbusy(); | ||
| 1700 | if ($path) { | ||
| 1701 | # Prepare for the next match | ||
| 1702 | $this->bind('<Control-f>' => sub { $this->__find_hlentry($column) } ); | ||
| 1703 | $this->bind('<Control-h>' => sub { $this->__find_hlentry($column, 'NEXT') } ); | ||
| 1704 | #print "Found path [$path]\n"; | ||
| 1705 | # Store for potential 'NEXT' | ||
| 1706 | $search_info->{LastHLEntry} = $path; | ||
| 1707 | $this->show('entry', $path) if $this->infoHidden($path); | ||
| 1708 | if ($path =~ m/\./o) { | ||
| 1709 | $parent = $path; | ||
| 1710 | while (($parent = $this->infoParent($parent))) { | ||
| 1711 | $this->open($parent); | ||
| 1712 | } | ||
| 1713 | } | ||
| 1714 | $this->focus; | ||
| 1715 | $this->selectionClear; | ||
| 1716 | $this->see($path); | ||
| 1717 | $this->selectionSet($path); | ||
| 1718 | $this->anchorClear; | ||
| 1719 | $this->Callback(-browsecmd => $path); | ||
| 1720 | } | ||
| 1721 | else { | ||
| 1722 | if ($this->cget('-wrapsearch')) { | ||
| 1723 | $answer = $this->messageBox( | ||
| 1724 | -title => '(List) Search Operation', | ||
| 1725 | -message => "No Matching Entry found!\nContinue search from begin of list ?", | ||
| 1726 | -icon => 'question', | ||
| 1727 | -popover => 'cursor', | ||
| 1728 | -type => 'YesNo', | ||
| 1729 | -default => 'No' | ||
| 1730 | ); | ||
| 1731 | if ($answer =~ /YES/io) { | ||
| 1732 | $this->afterIdle(sub { $this->__find_hlentry($column, 'NEXT') }); | ||
| 1733 | } | ||
| 1734 | } | ||
| 1735 | else { | ||
| 1736 | $this->messageBox( -title => '(List) Search Operation', | ||
| 1737 | -message => "No Matching Entry found!", | ||
| 1738 | -icon => 'info', | ||
| 1739 | -popover => 'cursor', | ||
| 1740 | -type => 'OK', | ||
| 1741 | ) | ||
| 1742 | } | ||
| 1743 | # Assume we want Start another find from scratch next time means wrap-around back to start | ||
| 1744 | delete $search_info->{LastHLEntry}; | ||
| 1745 | } | ||
| 1746 | } | ||
| 1747 | } | ||
| 1748 | #----------------------------------------------------------------- | ||
| 1749 | # Very internal related function, NOT to be invoked by user apps | ||
| 1750 | #----------------------------------------------------------------- | ||
| 1751 | sub __find_hlentry_r | ||
| 1752 | { | ||
| 1753 | #print "DBG: reached function [__find_hlentry_r] with >@_<, called by >", caller, "<\n"; | ||
| 1754 | # Parameters | ||
| 1755 | my ($this, $search_item, $column_number, $path, $startpath) = @_; | ||
| 1756 | |||
| 1757 | # Locals | ||
| 1758 | my ($result, $child, $data, $id); | ||
| 1759 | |||
| 1760 | #$result = __test_entry($this, $search_item, $column_number, $path) if $path; | ||
| 1761 | $result = $path if $path and $this->itemCget($path, $column_number, '-text') =~ /$search_item/; | ||
| 1762 | |||
| 1763 | #print "DBG: FOUND a MATCH [\$result] = >$result< on >$_< (1)\n" if $result; | ||
| 1764 | # Skip Search Results until were at the ('NEXT') StartPoint after the last match | ||
| 1765 | if ($$startpath and $path) { | ||
| 1766 | $result = undef; | ||
| 1767 | $$startpath = undef if $$startpath eq $path; # LAST Round : Ignore 1st match, since it WAS the last match | ||
| 1768 | } | ||
| 1769 | unless ($result) { | ||
| 1770 | foreach ($this->infoChildren($path)) { | ||
| 1771 | #$result = __test_entry($this, $search_item, $column_number, $_); | ||
| 1772 | $result = $_ if ($this->itemCget($_, $column_number, '-text') =~ /$search_item/); | ||
| 1773 | #print "DBG: FOUND a MATCH [\$result] = >$result< on >$_< (2)\n" if $result; | ||
| 1774 | # Skip Search Results until were at the ('NEXT') StartPoint after the last match | ||
| 1775 | if ($$startpath and $result) { | ||
| 1776 | $$startpath = undef if $$startpath eq $result; # LAST Round : Ignore 1st match, since it WAS the last match | ||
| 1777 | $result = undef; | ||
| 1778 | } | ||
| 1779 | #print "DBG: --------> [\$result] = >$result< on >$_<\n"; | ||
| 1780 | unless ($result) { | ||
| 1781 | foreach $child ($this->infoChildren($_)) { | ||
| 1782 | $result = __find_hlentry_r($this, $search_item, $column_number, $child, $startpath); | ||
| 1783 | last if $result; | ||
| 1784 | } | ||
| 1785 | } | ||
| 1786 | last if $result; | ||
| 1787 | } | ||
| 1788 | } | ||
| 1789 | return $result; | ||
| 1790 | } | ||
| 1791 | |||
| 1792 | #----------------------------------------------------------------- | ||
| 1793 | # Very internal related function, NOT to be invoked by user apps | ||
| 1794 | #----------------------------------------------------------------- | ||
| 1795 | sub __filter_hlentry_r | ||
| 1796 | { | ||
| 1797 | #print "DBG: reached function [__filter_hlentry_r] with >@_<, called by >", caller, "<\n"; | ||
| 1798 | # Parameters | ||
| 1799 | my ($this, $filter_info, $path) = @_; | ||
| 1800 | |||
| 1801 | # Locals | ||
| 1802 | my ($needed, @children, $filter_pattern, $column_number, $show_entry, | ||
| 1803 | $child, $grand_child, @grand_children, $tree_look); | ||
| 1804 | #print 'DBG: variable [$filter_info] = '; ETC::Universal::print_var($filter_info, 1); | ||
| 1805 | |||
| 1806 | $needed = 0; | ||
| 1807 | # Check for Level -1 below (this is because Top-Start $path == "") | ||
| 1808 | @children = $this->infoChildren($path); | ||
| 1809 | $this->open($path) if $path and @children and $this->getmode($path) ne 'none'; | ||
| 1810 | |||
| 1811 | foreach $child (@children) { | ||
| 1812 | $tree_look = $this->getmode($child) ne 'none' ? 1 : 0; | ||
| 1813 | @grand_children = $this->infoChildren($child); | ||
| 1814 | if (@grand_children) { | ||
| 1815 | $this->Activate($child, 'open') if $tree_look; | ||
| 1816 | foreach $grand_child ($this->infoChildren($child)) { | ||
| 1817 | $needed |= $this->__filter_hlentry_r($filter_info, $grand_child); | ||
| 1818 | } | ||
| 1819 | # $this->Activate($child, 'close') unless $needed; | ||
| 1820 | $this->Activate($child, 'close') if $tree_look and not $needed; | ||
| 1821 | } | ||
| 1822 | else { | ||
| 1823 | $show_entry = 1; | ||
| 1824 | foreach $column_number (keys %$filter_info) { | ||
| 1825 | $filter_pattern = $filter_info->{$column_number}; | ||
| 1826 | if (($this->itemCget($child, $column_number, '-text')||'') !~ /$filter_pattern/) { | ||
| 1827 | $show_entry = 0; last | ||
| 1828 | } | ||
| 1829 | } | ||
| 1830 | if ($show_entry) { | ||
| 1831 | $needed = 1; | ||
| 1832 | $this->show('entry', $child) | ||
| 1833 | } | ||
| 1834 | else { | ||
| 1835 | $this->hide('entry', $child) | ||
| 1836 | } | ||
| 1837 | } | ||
| 1838 | } | ||
| 1839 | #print 'DBG: Sub-result [$needed] = >' . $needed . "<\n"; | ||
| 1840 | #------------------------------------------------------------------------------- | ||
| 1841 | # Check for Level -1 immediate (this is for level 2++ $path == "") | ||
| 1842 | if ($path) { | ||
| 1843 | if (@children) { | ||
| 1844 | $this->Activate($path, 'close') unless $needed; | ||
| 1845 | } | ||
| 1846 | else { | ||
| 1847 | $show_entry = 1; | ||
| 1848 | foreach $column_number (keys %$filter_info) { | ||
| 1849 | $filter_pattern = $filter_info->{$column_number}; | ||
| 1850 | if (($this->itemCget($path, $column_number, '-text')||'') !~ /$filter_pattern/) { | ||
| 1851 | $show_entry = 0; last | ||
| 1852 | } | ||
| 1853 | } | ||
| 1854 | if ($show_entry) { | ||
| 1855 | $needed = 1; | ||
| 1856 | $this->show('entry', $path) | ||
| 1857 | } | ||
| 1858 | else { | ||
| 1859 | $this->hide('entry', $path) | ||
| 1860 | } | ||
| 1861 | } | ||
| 1862 | } | ||
| 1863 | #print 'DBG: Final-result [$needed] = >' . $needed . "<\n"; | ||
| 1864 | return $needed | ||
| 1865 | } | ||
| 1866 | |||
| 1867 | #-------------------------------------------------------------------------------------------------- | ||
| 1868 | # | ||
| 1869 | # =for html <hr> | ||
| 1870 | # | ||
| 1871 | # EnterStringDlg() | ||
| 1872 | # | ||
| 1873 | # IN : I<DialogArgs> | ||
| 1874 | # | ||
| 1875 | # OUT: I<---> | ||
| 1876 | # | ||
| 1877 | # B<Description>: | ||
| 1878 | # Creates & diplays an 'enter-a-string' dialog. | ||
| 1879 | # The entered scalar value is returned. if the | ||
| 1880 | # user presses I<CANCEL> an empty string is returned. | ||
| 1881 | # | ||
| 1882 | #-------------------------------------------------------------------------------------------------- | ||
| 1883 | sub EnterStringDlg | ||
| 1884 | { | ||
| 1885 | # Parameters | ||
| 1886 | my ($this, %args) = @_; | ||
| 1887 | |||
| 1888 | # Locals | ||
| 1889 | my ($label_text, $new_entry, $buttons, $dbox, $db_frame, $db_entry, $answer, $okstr); | ||
| 1890 | |||
| 1891 | # Retrieve them and / or assign defaults | ||
| 1892 | $new_entry = $args{-value}|| ''; | ||
| 1893 | $buttons = $args{-buttons} || ['Ok', 'Cancel']; | ||
| 1894 | |||
| 1895 | # Create the GUI | ||
| 1896 | $dbox = $this->DialogBox( | ||
| 1897 | -title => ($args{-title} || 'String Request'), | ||
| 1898 | -buttons => $buttons, | ||
| 1899 | -default_button => ($args{-default_button} || 'Ok'), | ||
| 1900 | -popover => 'cursor', | ||
| 1901 | ); | ||
| 1902 | $dbox->protocol('WM_DELETE_WINDOW' => sub { $dbox->Exit } ); | ||
| 1903 | $db_frame = $dbox->add('Frame')->pack(qw(-side top -expand 1 -fill x -anchor center)); | ||
| 1904 | $db_frame->Label(-text => "")->pack(-side => 'right'); | ||
| 1905 | $db_frame->Button( | ||
| 1906 | -text => 'Clear', | ||
| 1907 | -command => sub { $new_entry = '' }, | ||
| 1908 | -padx => -1, -pady => -1, | ||
| 1909 | )->pack(qw(-side right -padx 2)); | ||
| 1910 | $db_frame->Label(-text => ($args{-label} || 'Please Enter'))->pack(qw(-side left -anchor w)); | ||
| 1911 | $db_entry = $db_frame->Entry( | ||
| 1912 | -textvariable => \$new_entry, | ||
| 1913 | -width => 25, | ||
| 1914 | -validate => 'key', | ||
| 1915 | -validatecommand => ($args{-validatecommand} || sub { 1 }), | ||
| 1916 | )->pack(qw(-side right -expand 1 -fill x -anchor w )); | ||
| 1917 | |||
| 1918 | if ($new_entry) { | ||
| 1919 | # SELECT the complete old content and position the cursor to the begin of chars 'anchor' | ||
| 1920 | $db_entry->selectionClear(); | ||
| 1921 | $db_entry->selectionFrom(0); #<- set 'anchor' | ||
| 1922 | $db_entry->selectionTo('end'); | ||
| 1923 | $db_entry->selectionRange(0, 'end'); # <- make it look selected | ||
| 1924 | } | ||
| 1925 | $db_entry->focus; | ||
| 1926 | |||
| 1927 | # Present it | ||
| 1928 | $answer = $dbox->Show(); | ||
| 1929 | $okstr = $buttons->[0]; | ||
| 1930 | $dbox->destroy; | ||
| 1931 | $this->idletasks; | ||
| 1932 | |||
| 1933 | # Must be invoked here(!) after destroy() | ||
| 1934 | # to avoid calling 'validate' again | ||
| 1935 | $new_entry = '' if @$buttons == 2 and $answer !~ /$okstr/i; | ||
| 1936 | |||
| 1937 | # In case of special buttons, return also which Button was pressed | ||
| 1938 | return wantarray ? ($new_entry, $answer) : [$new_entry, $answer] | ||
| 1939 | } | ||
| 1940 | |||
| 1941 | ######################################################################## | ||
| 1942 | 1; | ||
| 1943 | __END__ |