Version: 3.2.7
wxLayoutAlgorithm Class Reference

#include <wx/laywin.h>

+ Inheritance diagram for wxLayoutAlgorithm:

Detailed Description

wxLayoutAlgorithm implements layout of subwindows in MDI or SDI frames.

It sends a wxCalculateLayoutEvent event to children of the frame, asking them for information about their size. For MDI parent frames, the algorithm allocates the remaining space to the MDI client window (which contains the MDI child frames).

For SDI (normal) frames, a 'main' window is specified as taking up the remaining space.

Because the event system is used, this technique can be applied to any windows, which are not necessarily 'aware' of the layout classes (no virtual functions in wxWindow refer to wxLayoutAlgorithm or its events). However, you may wish to use wxSashLayoutWindow for your subwindows since this class provides handlers for the required events, and accessors to specify the desired size of the window. The sash behaviour in the base class can be used, optionally, to make the windows user-resizable.

wxLayoutAlgorithm is typically used in IDE (integrated development environment) applications, where there are several resizable windows in addition to the MDI client window, or other primary editing window. Resizable windows might include toolbars, a project window, and a window for displaying error and warning messages.

When a window receives an OnCalculateLayout event, it should call SetRect in the given event object, to be the old supplied rectangle minus whatever space the window takes up. It should also set its own size accordingly. wxSashLayoutWindow::OnCalculateLayout generates an OnQueryLayoutInfo event which it sends to itself to determine the orientation, alignment and size of the window, which it gets from internal member variables set by the application.

The algorithm works by starting off with a rectangle equal to the whole frame client area. It iterates through the frame children, generating wxLayoutAlgorithm::OnCalculateLayout events which subtract the window size and return the remaining rectangle for the next window to process. It is assumed (by wxSashLayoutWindow::OnCalculateLayout) that a window stretches the full dimension of the frame client, according to the orientation it specifies. For example, a horizontal window will stretch the full width of the remaining portion of the frame client area. In the other orientation, the window will be fixed to whatever size was specified by wxLayoutAlgorithm::OnQueryLayoutInfo. An alignment setting will make the window 'stick' to the left, top, right or bottom of the remaining client area. This scheme implies that order of window creation is important. Say you wish to have an extra toolbar at the top of the frame, a project window to the left of the MDI client window, and an output window above the status bar. You should therefore create the windows in this order: toolbar, output window, project window. This ensures that the toolbar and output window take up space at the top and bottom, and then the remaining height in-between is used for the project window.

wxLayoutAlgorithm is quite independent of the way in which wxLayoutAlgorithm::OnCalculateLayout chooses to interpret a window's size and alignment. Therefore you could implement a different window class with a new wxLayoutAlgorithm::OnCalculateLayout event handler, that has a more sophisticated way of laying out the windows. It might allow specification of whether stretching occurs in the specified orientation, for example, rather than always assuming stretching. (This could, and probably should, be added to the existing implementation).

Note
wxLayoutAlgorithm has nothing to do with wxLayoutConstraints. It is an alternative way of specifying layouts for which the normal constraint system is unsuitable.

Events emitted by this class

The following event handler macros redirect the events to member function handlers 'func' with prototypes like:

void handlerFuncName(wxQueryLayoutInfoEvent& event) or void handlerFuncName(wxCalculateLayoutEvent& event)

Event macros for events emitted by this class:

  • EVT_QUERY_LAYOUT_INFO(func):
    Process a wxEVT_QUERY_LAYOUT_INFO event, to get size, orientation and alignment from a window. See wxQueryLayoutInfoEvent.
  • EVT_CALCULATE_LAYOUT(func):
    Process a wxEVT_CALCULATE_LAYOUT event, which asks the window to take a 'bite' out of a rectangle provided by the algorithm. See wxCalculateLayoutEvent.

Note that the algorithm object does not respond to events, but itself generates the previous events in order to calculate window sizes.

Library:  wxCore
Category:  Window Layout
See also
wxSashEvent, wxSashLayoutWindow, Events and Event Handling

Public Member Functions

 wxLayoutAlgorithm ()
 Default constructor. More...
 
virtual ~wxLayoutAlgorithm ()
 Destructor. More...
 
bool LayoutFrame (wxFrame *frame, wxWindow *mainWindow=NULL)
 Lays out the children of a normal frame. More...
 
bool LayoutMDIFrame (wxMDIParentFrame *frame, wxRect *rect=NULL)
 Lays out the children of an MDI parent frame. More...
 
bool LayoutWindow (wxWindow *parent, wxWindow *mainWindow=NULL)
 Lays out the children of a normal frame or other window. More...
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to NULL the internal reference data. More...
 
 wxObject (const wxObject &other)
 Copy ctor. More...
 
virtual ~wxObject ()
 Destructor. More...
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class. More...
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj. More...
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone. More...
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer. More...
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public. More...
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More...
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More...
 

Additional Inherited Members

- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object. More...
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
 
- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data. More...
 

Constructor & Destructor Documentation

◆ wxLayoutAlgorithm()

wxLayoutAlgorithm::wxLayoutAlgorithm ( )

Default constructor.

◆ ~wxLayoutAlgorithm()

virtual wxLayoutAlgorithm::~wxLayoutAlgorithm ( )
virtual

Destructor.

Member Function Documentation

◆ LayoutFrame()

bool wxLayoutAlgorithm::LayoutFrame ( wxFrame frame,
wxWindow mainWindow = NULL 
)

Lays out the children of a normal frame.

mainWindow is set to occupy the remaining space. This function simply calls LayoutWindow().

◆ LayoutMDIFrame()

bool wxLayoutAlgorithm::LayoutMDIFrame ( wxMDIParentFrame frame,
wxRect rect = NULL 
)

Lays out the children of an MDI parent frame.

If rect is non-NULL, the given rectangle will be used as a starting point instead of the frame's client area. The MDI client window is set to occupy the remaining space.

◆ LayoutWindow()

bool wxLayoutAlgorithm::LayoutWindow ( wxWindow parent,
wxWindow mainWindow = NULL 
)

Lays out the children of a normal frame or other window.

mainWindow is set to occupy the remaining space. If this is not specified, then the last window that responds to a calculate layout event in query mode will get the remaining space (that is, a non-query OnCalculateLayout event will not be sent to this window and the window will be set to the remaining size).