From: Mattia B. <mb...@ds...> - 2002-08-27 20:27:19
|
> Hi, > > I am working on implimenting wxWindows' doc/view framework in wxPerl. I've > got about 95% of the XS done and it compiles ok, but I'm having a problem WOW! This is really impressive! > with wxDocTemplate/wxClassInfo. > The wxDocTemplate constructor looks like this: > > Wx_DocTemplate * > Wx_DocTemplate::new(manager, descr, filter, dir, ext, docTypeName, > viewTypeName, docClassInfo, viewClassInfo, flags) > Wx_DocManager* manager > wxString descr > wxString filter > wxString dir > wxString ext > wxString docTypeName > wxString viewTypeName > Wx_ClassInfo* docClassInfo > Wx_ClassInfo* viewClassInfo > long flags > > The wxDocTemplate needs wxClassInfo objects for the document and view > classes, so it can create the documents/views automatically when they are > needed. I think this probably works ok if I use c++ classes it already knows Yes, it should > about such as wxDocument and wxView. Obviously wxClassInfo doesn't know > anything about perl classes, so I can't create a classinfo object for > "MyDocument" and "MyView". Yes; the alternative (as explained in wxDT::wxDT docs) is to override CreateDocument; to be able to do this you need a wxPlDocTemplate class (see below). > At the moment, I've got this in my test script: > > my $ci_doc = Wx::ClassInfo::FindClass("wxDocument"); > my $ci_view = Wx::ClassInfo::FindClass("wxView"); > my $docmanager = Wx::DocManager->new( 1, 1 ); > my $doctemplate = Wx::DocTemplate->new($docmanager, "XML", "*.xml", "", > "xml", "MyDoc", "MyView", $ci_doc, > $ci_view, 1 ); > my $frame = new Wx::DocParentFrame($docmanager, undef, -1, "DocView > Demo", > wxDefaultPosition, wxDefaultSize, > wxDEFAULT_FRAME_STYLE); > > > So far I'm getting encouraging results for Wx::DocManager. When I click on > File -> Open, it automatically pops up a file selector for *.xml files. But > when I try and open one it crashes. I think this is because > wxView::OnCreate() isn't doing anything. Possibly > What I'd like to be able to do is something like this: > > my $ci_doc = Wx::ClassInfo::FindClass("My::Document"); > my $ci_view = Wx::ClassInfo::FindClass("My::View"); > > Although we might need a different method name so we can still handle c++ > classes in the same way. My problem is that I don't know how to impliment > this. We'd need to override Wx::ClassInfo->CreateObject() or > wxClassInfo::m_objectConstructor. It is sufficient to override ->CreateObject. > I don't think I'm experienced enough to do this, but even if I were, I'd > want to make sure that I did it in a way that was compatible with wxPerl > development. > > If I can get this working I'll submit a patch to add the document/view > framework. If not, I'll give you what I've done so far so you don't need to > repeat what I've already done. > > By the way Mattia, I'm interested to know what the wxPl...... classes are > for? Do we need something like that here? It looks like there are some > useful functions in cpp/helpers.cpp The wxPlFoo classes are used when: 1 - you need to have a C++ virtual function overridable from Perl (for example wxSizer::RecalcSizes) 2 - you want the C++ object to store a reference to the Perl object; for example Wx::Icon does not use a wxPlIcon (just a wxIcon) hence $frame->SetIcon( $icon1 ); $icon2 = $frame->GetIcon(); $icon1 and $icon2 will be different Perl-level objects OTOH when you do $button1 = Wx::Button->new( $parent, ... ); $button2 = ($parent->GetChildren())[0]; $button1 and $button2 should be the same Perl-level object, and this is possible because a wxPlButton is used 3 - some other utility classes are named wxPlFoo or wxPliFoo We need these classes here, because wxDoc/View uses virtual functions a lot. I will post a more detailed explanation in another mail. Regards Mattia |