contents up previous next

wxlayoutalgorithm

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 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 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 oncalculatelayout chooses to interpret a window's size and alignment. therefore you could implement a different window class with a new 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.

derived from

wxobject

include files

<wx/laywin.h>

event handling

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

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.

data types

enum wxlayoutorientation {
    wxlayout_horizontal,
    wxlayout_vertical
};

enum wxlayoutalignment {
    wxlayout_none,
    wxlayout_top,
    wxlayout_left,
    wxlayout_right,
    wxlayout_bottom,
};

see also

wxsashevent, wxsashlayoutwindow, event handling overview

wxcalculatelayoutevent, wxquerylayoutinfoevent, wxsashlayoutwindow, wxsashwindow

members

wxlayoutalgorithm::wxlayoutalgorithm
wxlayoutalgorithm::~wxlayoutalgorithm
wxlayoutalgorithm::layoutframe
wxlayoutalgorithm::layoutmdiframe
wxlayoutalgorithm::layoutwindow


wxlayoutalgorithm::wxlayoutalgorithm

wxlayoutalgorithm()

default constructor.


wxlayoutalgorithm::~wxlayoutalgorithm

~wxlayoutalgorithm()

destructor.


wxlayoutalgorithm::layoutframe

bool layoutframe(wxframe* frame, wxwindow* mainwindow = null) const

lays out the children of a normal frame. mainwindow is set to occupy the remaining space.

this function simply calls wxlayoutalgorithm::layoutwindow.


wxlayoutalgorithm::layoutmdiframe

bool layoutmdiframe(wxmdiparentframe* frame, wxrect* rect = null) const

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.


wxlayoutalgorithm::layoutwindow

bool layoutwindow(wxwindow* parent, wxwindow* mainwindow = null) const

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).