#!/usr/bin/perl
use strict;
use warnings;
use utf8;

{
package MyMostLeastChoices;

use Wx qw(:listbox :sizer wxDefaultPosition wxDefaultSize
          wxDEFAULT_DIALOG_STYLE wxRESIZE_BORDER);
use Wx::Event qw(EVT_CLOSE EVT_BUTTON);
use base 'Wx::Frame';

sub new {
    my ($ref) = @_;

    my $self = $ref->SUPER::new(undef,
                                 -1,
                                 'maintitle',
                                 wxDefaultPosition,
                                 wxDefaultSize,
                                 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER
                                 );

    my $tsz = Wx::BoxSizer->new( wxVERTICAL );

    my $sw = Wx::ScrolledWindow->new($self, -1);

    my $itsz = Wx::BoxSizer->new( wxVERTICAL );

    for (1..10){
        my $choice = MyMostLeastChoices::Choice->new($sw, "sometest");

        $itsz->Add($choice, 0, wxALL, 30);
    }
    $sw->SetSizer($itsz);
    $sw->SetScrollRate( 0, 10 );

    $tsz->Add($sw, 0, wxALIGN_CENTER | wxALL, 10);


    my $button = Wx::Button->new( $self,         # parent window
                                  -1,             # ID
                                  'OK',    # label
                                  wxDefaultPosition,       # position
                                  wxDefaultSize       # default size
                                  );

    $tsz->Add($button, 0, wxALIGN_CENTER | wxALL, 10);

    $self->SetAutoLayout( 1 );
    $self->SetSizer($tsz);
    $tsz->Fit( $self );
    $tsz->SetSizeHints( $self );

    return $self;
}

}

{
package MyMostLeastChoices::Choice;

use Wx qw(:sizer  wxDefaultPosition wxDefaultSize
          wxDEFAULT_DIALOG_STYLE wxRESIZE_BORDER);
use base 'Wx::BoxSizer';

sub new {
    my ($ref, $parent, $message) = @_;

    my $self = $ref->SUPER::new(wxHORIZONTAL);

    my $button = Wx::ToggleButton->new( $parent,         # parent window
                                  -1,             # ID
                                  '+',    # label
                                  wxDefaultPosition,       # position
                                  wxDefaultSize       # default size
                                  );
    $self->Add($button, 0, wxALIGN_CENTER | wxALL, 10);

    $button = Wx::ToggleButton->new( $parent,         # parent window
                                  -1,             # ID
                                  '-',    # label
                                  wxDefaultPosition,       # position
                                  wxDefaultSize       # default size
                                  );
    $self->Add($button, 0, wxALIGN_CENTER | wxALL, 10);

    my $text = Wx::StaticText->new($parent, -1, $message,
                                   wxDefaultPosition,
                                   wxDefaultSize,
                                   wxALIGN_CENTER);
    $self->Add($text, 0, wxALL, 30);

    return $self;
}

}

{
package MyApp;

use base 'Wx::App';

sub OnInit {
    my $self = shift;
    my $frame = MyMostLeastChoices->new();
    #warn ref $frame;
    $frame->Show(1);
}

}

my $app = MyApp->new;
$app->MainLoop;



