Octavian Rasnita wrote:

  Hi,

Is it possible to subclass some empty classes like Wx::TextAttr?

  Some classes are tricky to subclass, but not because they are empty.

I have also tried to use Wx:

package Style;
use Wx;
use base 'Wx::TextAttr';

In this case it doesn't tell that Wx::TextAttr is empty, but if I add a certain 
method in this package, that method can't be used because it gives the error 
telling that there is no such a method defined in Wx::TextAttr.

I'm not sure if this is easy to fix in wxPerl without requiring a change to all constructors. I'll think about it. In the meantime you can just rebless the object:

  package Style;
  use Wx;
  use base 'Wx::TextAttr';

  sub new {
      my $class = shift;
      my $self = $class->SUPER::new( @_ );
      bless $self, $class;

      return $self;
  }

  1;

Note: I haven't tested it, but it should work. One problem with this approach is that, since the text attr is used as a value in wxWidgets, there is no way to preserve identity, so if you do:

  $text->SetStyle( 0, 100, $myclass );
  my( $ok, $style ) = $text->GetStyle( 0, 100 );

the returned $style object will be a copy of your object, and there is no way to automatically bless it to the correct class.

HTH,
Mattia

Reply via email to