## wxSplitterWindow

wxSplitterWindow overview

This class manages up to two subwindows. The current view can be split into two programmatically (perhaps from a menu command), and unsplit either programmatically or via the wxSplitterWindow user interface.

Appropriate 3D shading for the Windows 95 user interface is an option - this is also recommended for GTK. Optionally, the sash can be made to look more like the native control under MacOS X.

Window styles

wxSP_3D | Draws a 3D effect border and sash.
wxSP_3DSASH | Draws a 3D effect sash.
wxSP_3DBORDER | Draws a 3D effect border.
wxSP_FULLSASH | Draws the ends of the sash (so the window can be used without a border).
wxSP_BORDER | Draws a thin black border around the window.
wxSP_NOBORDER | No border, and a black sash.
wxSP_PERMIT_UNSPLIT | Always allow to unsplit, even with the minimum pane size other than zero.
wxSP_LIVE_UPDATE | Don't draw XOR line but resize the child windows immediately.

See also window styles overview.

Derived from

wxWindow
wxEvtHandler
wxObject

Include files

<wx/splitter.h>

Event handling

To process input from a splitter control, use the following event handler macros to direct input to member functions that take a wxSplitterEvent argument.

EVT_SPLITTER_SASH_POS_CHANGING(id, func) | The sash position is in the process of being changed. May be used to modify the position of the tracking bar to properly reflect the position that would be set if the drag were to be completed at this point. Processes a wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING event.
EVT_SPLITTER_SASH_POS_CHANGED(id, func) | The sash position was changed. May be used to modify the sash position before it is set, or to prevent the change from taking place. Processes a wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED event.
EVT_SPLITTER_UNSPLIT(id, func) | The splitter has been just unsplit. Processes a wxEVT_COMMAND_SPLITTER_UNSPLIT event.
EVT_SPLITTER_DCLICK(id, func) | The sash was double clicked. The default behaviour is to unsplit the window when this happens (unless the minimum pane size has been set to a value greater than zero). Processes a wxEVT_COMMAND_SPLITTER_DOUBLECLICKED event.

See also

wxSplitterEvent

Members

wxSplitterWindow::wxSplitterWindow
wxSplitterWindow::~wxSplitterWindow
wxSplitterWindow::Create
wxSplitterWindow::GetMinimumPaneSize
wxSplitterWindow::GetSashPosition
wxSplitterWindow::GetSplitMode
wxSplitterWindow::GetWindow1
wxSplitterWindow::GetWindow2
wxSplitterWindow::Initialize
wxSplitterWindow::IsSplit
wxSplitterWindow::OnDoubleClickSash
wxSplitterWindow::OnUnsplit
wxSplitterWindow::OnSashPositionChange
wxSplitterWindow::ReplaceWindow
wxSplitterWindow::SetSashPosition
wxSplitterWindow::SetMinimumPaneSize
wxSplitterWindow::SetSplitMode
wxSplitterWindow::SplitHorizontally
wxSplitterWindow::SplitVertically
wxSplitterWindow::Unsplit

### wxSplitterWindow::wxSplitterWindow

wxSplitterWindow()

Default constructor.

wxSplitterWindow(wxWindow* parent, wxWindowID id, const wxPoint& point = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style=wxSP_3D, const wxString& name = "splitterWindow")

Constructor for creating the window.

Parameters

parent

The parent of the splitter window.

id

The window identifier.

pos

The window position.

size

The window size.

style

The window style. See wxSplitterWindow.

name

The window name.

Remarks

After using this constructor, you must create either one or two subwindows with the splitter window as parent, and then call one of wxSplitterWindow::Initialize, wxSplitterWindow::SplitVertically and wxSplitterWindow::SplitHorizontally in order to set the pane(s).

You can create two windows, with one hidden when not being shown; or you can create and delete the second pane on demand.

See also

wxSplitterWindow::Initialize, wxSplitterWindow::SplitVertically, wxSplitterWindow::SplitHorizontally, wxSplitterWindow::Create

### wxSplitterWindow::~wxSplitterWindow

~wxSplitterWindow()

Destroys the wxSplitterWindow and its children.

### wxSplitterWindow::Create

bool Create(wxWindow* parent, wxWindowID id, int x, const wxPoint& point = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style=wxSP_3D, const wxString& name = "splitterWindow")

Creation function, for two-step construction. See wxSplitterWindow::wxSplitterWindow for details.

### wxSplitterWindow::GetMinimumPaneSize

int GetMinimumPaneSize() const

Returns the current minimum pane size (defaults to zero).

See also

wxSplitterWindow::SetMinimumPaneSize

### wxSplitterWindow::GetSashPosition

int GetSashPosition()

Returns the current sash position.

See also

wxSplitterWindow::SetSashPosition

### wxSplitterWindow::GetSplitMode

int GetSplitMode() const

Gets the split mode.

See also

wxSplitterWindow::SetSplitMode, wxSplitterWindow::SplitVertically, wxSplitterWindow::SplitHorizontally.

### wxSplitterWindow::GetWindow1

wxWindow* GetWindow1() const

Returns the left/top or only pane.

### wxSplitterWindow::GetWindow2

wxWindow* GetWindow2() const

Returns the right/bottom pane.

### wxSplitterWindow::Initialize

void Initialize(wxWindow* window)

Initializes the splitter window to have one pane.

Parameters

window

The pane for the unsplit window.

Remarks

This should be called if you wish to initially view only a single pane in the splitter window.

See also

wxSplitterWindow::SplitVertically, wxSplitterWindow::SplitHorizontally

### wxSplitterWindow::IsSplit

bool IsSplit() const

Returns TRUE if the window is split, FALSE otherwise.

### wxSplitterWindow::OnDoubleClickSash

virtual void OnDoubleClickSash(int x, int y)

Application-overridable function called when the sash is double-clicked with the left mouse button.

Parameters

x

The x position of the mouse cursor.

y

The y position of the mouse cursor.

Remarks

The default implementation of this function calls Unsplit if the minimum pane size is zero.

See also

wxSplitterWindow::Unsplit

### wxSplitterWindow::OnUnsplit

virtual void OnUnsplit(wxWindow* removed)

Application-overridable function called when the window is unsplit, either programmatically or using the wxSplitterWindow user interface.

Parameters

removed

The window being removed.

Remarks

The default implementation of this function simply hides removed. You may wish to delete the window.

### wxSplitterWindow::OnSashPositionChange

virtual bool OnSashPositionChange(int newSashPosition)

Application-overridable function called when the sash position is changed by user. It may return FALSE to prevent the change or TRUE to allow it.

Parameters

newSashPosition

The new sash position (always positive or zero)

Remarks

The default implementation of this function verifies that the sizes of both panes of the splitter are greater than minimum pane size.

### wxSplitterWindow::ReplaceWindow

bool ReplaceWindow(wxWindow * winOld, wxWindow * winNew)

This function replaces one of the windows managed by the wxSplitterWindow with another one. It is in general better to use it instead of calling Unsplit() and then resplitting the window back because it will provoke much less flicker (if any). It is valid to call this function whether the splitter has two windows or only one.

Both parameters should be non-NULL and winOld must specify one of the windows managed by the splitter. If the parameters are incorrect or the window couldn't be replaced, FALSE is returned. Otherwise the function will return TRUE, but please notice that it will not delete the replaced window and you may wish to do it yourself.

See also

wxSplitterWindow::GetMinimumPaneSize

See also

wxSplitterWindow::Unsplit
wxSplitterWindow::SplitVertically
wxSplitterWindow::SplitHorizontally

### wxSplitterWindow::SetSashPosition

void SetSashPosition(int position, const bool redraw = TRUE)

Sets the sash position.

Parameters

position

The sash position in pixels.

redraw

If TRUE, resizes the panes and redraws the sash and border.

Remarks

Does not currently check for an out-of-range value.

See also

wxSplitterWindow::GetSashPosition

### wxSplitterWindow::SetMinimumPaneSize

void SetMinimumPaneSize(int paneSize)

Sets the minimum pane size.

Parameters

paneSize

Minimum pane size in pixels.

Remarks

The default minimum pane size is zero, which means that either pane can be reduced to zero by dragging the sash, thus removing one of the panes. To prevent this behaviour (and veto out-of-range sash dragging), set a minimum size, for example 20 pixels. If the wxSP_PERMIT_UNSPLIT style is used when a splitter window is created, the window may be unsplit even if minimum size is non-zero.

See also

wxSplitterWindow::GetMinimumPaneSize

### wxSplitterWindow::SetSplitMode

void SetSplitMode(int mode)

Sets the split mode.

Parameters

mode

Can be wxSPLIT_VERTICAL or wxSPLIT_HORIZONTAL.

Remarks

Only sets the internal variable; does not update the display.

See also

wxSplitterWindow::GetSplitMode, wxSplitterWindow::SplitVertically, wxSplitterWindow::SplitHorizontally.

### wxSplitterWindow::SplitHorizontally

bool SplitHorizontally(wxWindow* window1, wxWindow* window2, int sashPosition = 0)

Initializes the top and bottom panes of the splitter window.

Parameters

window1

The top pane.

window2

The bottom pane.

sashPosition

The initial position of the sash. If this value is positive, it specifies the size of the upper pane. If it is negative, it is absolute value gives the size of the lower pane. Finally, specify 0 (default) to choose the default position (half of the total window height).

Return value

TRUE if successful, FALSE otherwise (the window was already split).

Remarks

This should be called if you wish to initially view two panes. It can also be called at any subsequent time, but the application should check that the window is not currently split using IsSplit.

See also

wxSplitterWindow::SplitVertically, wxSplitterWindow::IsSplit, wxSplitterWindow::Unsplit

### wxSplitterWindow::SplitVertically

bool SplitVertically(wxWindow* window1, wxWindow* window2, int sashPosition = 0)

Initializes the left and right panes of the splitter window.

Parameters

window1

The left pane.

window2

The right pane.

sashPosition

The initial position of the sash. If this value is positive, it specifies the size of the left pane. If it is negative, it is absolute value gives the size of the right pane. Finally, specify 0 (default) to choose the default position (half of the total window width).

Return value

TRUE if successful, FALSE otherwise (the window was already split).

Remarks

This should be called if you wish to initially view two panes. It can also be called at any subsequent time, but the application should check that the window is not currently split using IsSplit.

See also

wxSplitterWindow::SplitHorizontally, wxSplitterWindow::IsSplit, wxSplitterWindow::Unsplit.

### wxSplitterWindow::Unsplit

bool Unsplit(wxWindow* toRemove = NULL)

Unsplits the window.

Parameters

toRemove

The pane to remove, or NULL to remove the right or bottom pane.

Return value

TRUE if successful, FALSE otherwise (the window was not split).

Remarks

This call will not actually delete the pane being removed; it calls OnUnsplit which can be overridden for the desired behaviour. By default, the pane being removed is hidden.

See also

wxSplitterWindow::SplitHorizontally, wxSplitterWindow::SplitVertically, wxSplitterWindow::IsSplit, wxSplitterWindow::OnUnsplit