On 02/14/13 13:28, steveco.1...@gmail.com wrote:
There is Wx::ComboCtrl
(http://docs.wxwidgets.org/2.8.12/wx_wxcomboctrl.html#wxcomboctrl)
with
Wx::ComboPopup
(http://docs.wxwidgets.org/2.8.12/wx_wxcombopopup.html#wxcombopopup)
Which gives you a custom pop-up window for what is essentially a ComboBox.
I'm pretty sure it's in the demo where it shows you how to have a three
column RadioButton instead of a ListCtrl for a Combo.
Thanks very much for this! This appears to be a better match for what I
want, and appears to avoid the focus issues I had before. :)
There's a couple of issues this decision has highlighted, and I'd like
some feedback on them if possible. :D
1) Apparently Wx::ComboCtrl does not respect or use wxTE_PROCESS_TAB. Why?
2) There's an infrequent practice in wxperl of returning blessed scalar
references for subclassable controls. I'm not sure I like those very
much, since I normally expect blessed references to be hashes (or less
commonly arrays) where I can store instance data. With events, this is
always leading me to closure issues. For example:
package MyDialog;
use base qw(Wx::Dialog);
use Wx::Event qw(EVT_CHAR);
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->{'mydata'} = 'foo';
EVT_CHAR($self, sub {
my ($self, $event) = @_;
my $data = $self->{'mydata'};
....
});
return $self;
}
I can access object data in the event in this case. However, I cannot do
(unless there is some perl mysticism I am unaware of):
package MyComboPopup;
use base qw(Wx::PlComboPopup);
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->{'mydata'} = 'foo';
EVT_CHAR($self, sub {
my ($self, $event) = @_;
my $data = $self->{'mydata'};
....
});
return $self;. This would normally be a pedantic issue except for
the practice of subclassing controls and events
}
This is because $self will be a blessed scalar reference. I feel I am
forced to do things like this (in the combo control object):
package MyComboCtrl;
use base qw(Wx::ComboCtrl);
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->{'mydata'} = 'foo';
my $popup = MyComboPopup->new;
EVT_CHAR($popup, sub {
my ($popup, $event) = @_;
my $data = $self->{'mydata'};
....
});
return $self;
}
If I understand correctly, this will produce a closure on $self which
means it will never be destroyed. I don't see a way to avoid this
easily, with the possible exception of Scalar::Util::weaken.
Am I missing something here?
--
Dave Hayes - Consultant - Altadena CA, USA - d...@jetcafe.org
>>>> *The opinions expressed above are entirely my own* <<<<
None should say "I can trust" or "I cannot trust" until they
are the master of the option of trusting or not trusting.