Chapter 4. Interface strategy

Classes, static methods and global functions

In wxPerl all classes are named Wx::Something, so wxFrame is really Wx::Frame. Static methods are called Wx::ClassName::Method(). Global function named wxFunction() are accessible as Wx::Function().


In wxWindows some methods (like FindWindow) return a pointer to a base class, and the programmer is obliged to explicitly cast the object to the right type. wxPerl does this for you, so you do not need to worry for that.

Overloaded methods

Where is applicable, wxPerl uses overloaded method names just like wxWindows, when this is not feasible, the difference is documented in the following pages (and will be documented in wxWindows manual, in the future).

Functions modifying their parameters

Some wxWindows functions modify their parameters; though in Perl this is possible, wxPerl avoids this practice, and such methods are always modified to take less parameters and return a Perl array.

Object destruction

In Perl memory management is a matter for the perl interpreter; however, since we are interacting with an external C++ library, there are some problems.

In wxPerl there are three kinds of objects

  1. objects destroyed 'by hand' by the program (using the Destroy method)
  2. objects destroyed automatically by wxWindows in some situations, sometimes they too need to be destroyed by hand
  3. objects destroyed when no more referenced (as Perl does usually)
  4. other objects you do not need to worry about

First category

  • Wx::Log and derived classes
  • Wx::Mask

Second category

  • all Wx::Window/Wx::Sizer/Wx::LayoutConstraints/Wx::Menu* and derived objects: when they are childs of some other window/sizer, are destroyed automatically when the paent itself is destroyed. When they have no parent they need to be destroyed explicitily.
  • all Wx::ImageHandler/Wx::BitmapHandler-derived objects: if you have added them to the handlers (using AddHandler, they are automatically destroyed, otherwise you need to destroy them explicitly

Third category

Wx::*Event, Wx::App, Wx::Bitmap, Wx::Brush, Wx::*DC, Wx::Colour, Wx::Cursor, Wx::EvtHandler (user objects derived directly from Wx::EvtHandler), Wx::Font, Wx::Icon, Wx::Image, Wx::ImageList, Wx::Locale, Wx::Pen, Wx::Point, Wx::Rect, Wx::Region, Wx::Size, Wx::ToolTip

Fourth category

Wx::ClassInfo, Wx::IndividualLayoutConstraints