ChrisR has asked for the wisdom of the Perl Monks concerning the following question:

I have a problem with tabstops when using Win32::GUI::TabFrame. Tabbing does not work as expected and I'm sure it is my fault but I can't figure it out.
Problem #1 is that back-tabbing (shift+tab) sets the focus on the tab label itself.
Problem #2 is that I cannot tab off the tab label.
Here is a small test script that will reproduce the issues:
#!c:\perl\bin\wperl.exe use strict; use Win32::GUI; use Win32::GUI::TabFrame; my $mainform; $mainform = Win32::GUI::Window->new(-name=>'main',-text=>'tabframe tes +t',-width=>800,-height=>600,-dialogui=>1); $mainform->AddTabFrame(-name=>"tab",-panel=>"Page",-width=>770,-height +=>550,-left=>10,-top=>10,-addstyle=>WS_TABSTOP); $mainform->tab->InsertItem(-text=>" Tab1 ",-border=>0,top=>10,-addstyl +e=>WS_TABSTOP); $mainform->tab->Page0->AddTextfield(-name=>'tab0_text1', -text=>'tab0_ +text1', -left=>200, -top=>10, -height=>24, -width=>80,-tabstop=>1); $mainform->tab->Page0->AddTextfield(-name=>'tab0_text2', -text=>'tab0_ +text2', -left=>200, -top=>40, -height=>24, -width=>80,-tabstop=>1); $mainform->tab->Page0->AddTextfield(-name=>'tab0_text3', -text=>'tab0_ +text3', -left=>200, -top=>70, -height=>24, -width=>80,-tabstop=>1); $mainform->tab->InsertItem(-text=>" Tab2 ",-border=>0,top=>10,-addstyl +e=>WS_TABSTOP); $mainform->tab->Page1->AddTextfield(-name=>'tab1_text1', -text=>'tab1_ +text1', -left=>200, -top=>10, -height=>24, -width=>80,-tabstop=>1); $mainform->tab->Page1->AddTextfield(-name=>'tab1_text2', -text=>'tab1_ +text2', -left=>200, -top=>40, -height=>24, -width=>80,-tabstop=>1); $mainform->tab->Page1->AddTextfield(-name=>'tab1_text3', -text=>'tab1_ +text3', -left=>200, -top=>70, -height=>24, -width=>80,-tabstop=>1); $mainform->tab->InsertItem(-text=>" Tab3 ",-border=>0,top=>10,-addstyl +e=>WS_TABSTOP); $mainform->tab->Page2->AddTextfield(-name=>'tab2_text1', -text=>'tab2_ +text1', -left=>200, -top=>10, -height=>24, -width=>80,-tabstop=>1); $mainform->tab->Page2->AddTextfield(-name=>'tab2_text2', -text=>'tab2_ +text2', -left=>200, -top=>40, -height=>24, -width=>80,-tabstop=>1); $mainform->tab->Page2->AddTextfield(-name=>'tab2_text3', -text=>'tab2_ +text3', -left=>200, -top=>70, -height=>24, -width=>80,-tabstop=>1); $mainform->Show(); Win32::GUI::Dialog(); exit; main_Terminate { $mainform->Hide(); return -1; }
I have tried using $mainform = Win32::GUI::DialogBox->new(-name=>'main',-text=>'tabframe test',-width=>800,-height=>600,-dialogui=>1); to create the main window but it has no effect.

I have tried changing the way I set tabstops from -addstyle=>WS_TABSTOP to -tabstop=>1 again this has no effect

I have tried to remove the tabstop setting from the tabframe $mainform->AddTabFrame(-name=>"tab",-panel=>"Page",-width=>770,-height=>550,-left=>10,-top=>10); but this causes the program to lock up when I try to backtab.

I have tried removing the tabstop from the tabs themselves $mainform->tab->InsertItem(-text=>" Tab1 ",-border=>0,top=>10); but that has no effect either.

I also tried setting the tabstop on the tabs to 0 $mainform->tab->InsertItem(-text=>" Tab1 ",-border=>0,top=>10,-tabstop=>0); but that also has no effect.

It is entirely possible that I am way off base with the whole thing as I am still pretty new to perl GUI's in windows. I also know that the community is much more in tune with Tk than Win32::GUI however that is not an option for me. I also noticed that information on Win32::GUI::TabFrame is almost nonexistent so for those of you have not seen or heard of it, here it is (with one tiny mod by me to resolve a display issue I was having):
package Win32::GUI::TabFrame; my $VERSION = "0.02"; use Win32::GUI; use Win32::GUI::Frame; @ISA = qw(Win32::GUI::TabStrip); my %Instance = {}; # # new # sub new { my $class = shift; my $parent = shift; my %options = @_; my $panel = "Panel"; # Default Panel Name $panel = $options{-panel} if exists $options{-panel}; # New TabStrip my $self = new Win32::GUI::TabStrip ($parent, %options); # Init instance variable $self->{'#LastPanel'} = 0; $self->{'#Panel'} = $panel; # Keep object reference $Instance{$options{-name}} = $self; # Add Click Event eval qq( sub main::$options{-name}_Click { return Win32::GUI::TabFrame->ClickEvent($options{-name}); } ); return bless $self, $class; } # # AddSSTab # sub Win32::GUI::Window::AddTabFrame { return Win32::GUI::TabFrame->new(@_); } # # DisplayArea # sub DisplayArea { my $self = shift; my ($left,$top,$right,$botton) = $self->AdjustRect($self->GetClien +tRect()); return ($left, $top, $right - $left, $botton - $top); } # # Insert Element # sub InsertItem { my $self = shift; my %options = @_; # Add a panel my $count = $self->Count(); my $name = $self->{'#Panel'}.$count; my $border = 0; my $text = ""; if (exists $options{-border}) { $border = $options{-border} } if (exists $options{-paneltext}) { $text = $options{-paneltext} } my ($x,$y,$width,$height) = $self->DisplayArea(); #following line added by ChrisR to resolve display issue if($count == 0){$y=$y+18;$height=$height-18;} my $panel = $self->AddFrame ( -name => $name, -text => $text, -pos => [$x, $y], -size => [$width, $height], -border => $border, ); # Only show first page $panel->Hide() unless ($count == 0); # Add TabStrip $self->SUPER::InsertItem(%options); return $panel; } # # Resize # sub Resize { my $self = shift; my $width = shift; my $height = shift; $self->SUPER::Resize ($width, $height); my ($ax,$ay,$awidth,$aheight) = $self->DisplayArea(); my $count = $self->Count(); for ($i = 0; $i < $count; $i++) { my $page = $self->{'#Panel'}.$i; $self->{$page}->Move ($ax , $ay); $self->{$page}->Resize($awidth, $aheight); } } # # Reset : # sub Reset { my $self = shift; my $count = $self->Count(); for ($i = 0; $i < $count; $i++) { my $page = $self->{'#Panel'}.$i; $self->{$page}->DestroyWindow(); } $self->{'#LastPage'} = 0; return $self->SUPER::Reset(); } # # DeleteItem : # sub DeleteItem { die "Win32:GUI::TabFrame : Methode DeleteItem not working"; } # # ClickEvent # sub ClickEvent { my $class = shift; my $name = shift; my $element = $Instance{$name}; my $page = $element->{'#Panel'}.$element->{'#LastPanel'}; # Hide Last Page $element->{$page}->Hide(); # Show New Page $element->{'#LastPanel'} = $element->SelectedItem(); $page = $element->{'#Panel'}.$element->{'#LastPanel'}; $element->{$page}->Show(); } 1;

Does anybody have any ideas?

Replies are listed 'Best First'.
Re: Help with tabstops in Win32::GUI
by jplindstrom (Monsignor) on Apr 14, 2005 at 14:25 UTC
    I think that may be an inherent problem with that module.

    You could always try Win32::GUI::TabStripGroup instead. It's available if you install the PPMs from The GUI Loft.

    /J

      ok, I was just trying to become familiar with the tabstrip not using any kind of wrapper like tabframe or tabstripgroup. I thought it would be a good idea but things are getting worse. When I run the code below and hit tab, it takes me to currently selected tab label/button and does not tab between the textfields. What am I doing wrong here??
      #!c:\perl\bin\wperl.exe use strict; use Win32::GUI; my $mainform; $mainform = Win32::GUI::Window->new(-name=>'main',-text=>'tabstrip tes +t',-width=>800,-height=>600,-dialogui=>1); $mainform->AddTabStrip(-name=>"tab",-width=>770,-height=>550,-left=>10 +,-top=>10); $mainform->tab->InsertItem(-name=>'Tab1',-text=>" Tab1 ",-border=>0,to +p=>10,-addstyle=>WS_TABSTOP); $mainform->tab->AddTextfield(-name=>'text1',-top=>50,-left=>50,-text=> +"text #1",-addstyle=>WS_TABSTOP,-width=>150,-height=>20); $mainform->tab->AddTextfield(-name=>'text2',-top=>80,-left=>50,-text=> +"text #2",-addstyle=>WS_TABSTOP,-width=>150,-height=>20); $mainform->tab->AddTextfield(-name=>'text3',-top=>110,-left=>50,-text= +>"text #3",-addstyle=>WS_TABSTOP,-width=>150,-height=>20); $mainform->tab->AddTextfield(-name=>'text4',-top=>140,-left=>50,-text= +>"text #4",-addstyle=>WS_TABSTOP,-width=>150,-height=>20); $mainform->tab->InsertItem(-name=>'Tab2',-text=>" Tab2 ",-border=>0,to +p=>10,-addstyle=>WS_TABSTOP); $mainform->tab->InsertItem(-name=>'Tab3',-text=>" Tab3 ",-border=>0,to +p=>10,-addstyle=>WS_TABSTOP); $mainform->Show(); Win32::GUI::Dialog(); exit; main_Terminate { $mainform->Hide(); return -1; }
        You should not AddXXX to the TabStrip object, you should add them to the window $mainform. Then you use e.g. Win32::GUI::TabStripGroup to manage the controls for you.

        If you use The GUI Loft, all this is automagically taken care of for you.

        /J