#include "wx/dcscreen.h"
#include "wx/settings.h"
#include "wx/log.h"
+#include "wx/utils.h"
+
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_UNSPLIT)
IMPLEMENT_DYNAMIC_CLASS(wxSplitterWindow, wxWindow)
IMPLEMENT_DYNAMIC_CLASS(wxSplitterEvent, wxCommandEvent)
EVT_SPLITTER_SASH_POS_CHANGING(-1, wxSplitterWindow::OnSashPosChanged)
EVT_SPLITTER_DCLICK(-1, wxSplitterWindow::OnDoubleClick)
EVT_SPLITTER_UNSPLIT(-1, wxSplitterWindow::OnUnsplitEvent)
+
+ WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow)
END_EVENT_TABLE()
+WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow);
+
bool wxSplitterWindow::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
+ // allow TABbing from one window to the other
+ style |= wxTAB_TRAVERSAL;
+
if (!wxWindow::Create(parent, id, pos, size, style, name))
return FALSE;
else
m_borderSize = 0;
+#ifdef __WXMAC__
+ int major,minor;
+ wxGetOsVersion( &major, &minor );
+ if (major >= 10)
+ m_windowStyle |= wxSP_SASH_AQUA;
+#endif
+
return TRUE;
}
void wxSplitterWindow::Init()
{
+ m_container.SetContainerWindow(this);
+
m_splitMode = wxSPLIT_VERTICAL;
m_permitUnsplitAlways = TRUE;
m_windowOne = (wxWindow *) NULL;
m_firstY = 0;
m_sashSize = 7;
m_borderSize = 2;
- m_sashPosition = 0;
+ m_sashPosition = m_requestedSashPosition = 0;
m_minimumPaneSize = 0;
m_sashCursorWE = new wxCursor(wxCURSOR_SIZEWE);
m_sashCursorNS = new wxCursor(wxCURSOR_SIZENS);
DrawSash(dc);
}
-void wxSplitterWindow::OnIdle(wxIdleEvent& WXUNUSED(event))
+void wxSplitterWindow::OnIdle(wxIdleEvent& event)
{
if (m_needUpdating)
SizeWindows();
+
+ event.Skip();
}
void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
{
- wxCoord x = (wxCoord)event.GetX(),
- y = (wxCoord)event.GetY();
+ int x = (int)event.GetX(),
+ y = (int)event.GetY();
// reset the cursor
#ifdef __WXMOTIF__
// Obtain window size. We are only interested in the dimension the sash
// splits up
- int w, h;
- GetClientSize(&w, &h);
- int window_size = (m_splitMode == wxSPLIT_VERTICAL ? w : h );
- int new_sash_position =
- (int) ( m_splitMode == wxSPLIT_VERTICAL ? x : y );
+ int window_size = GetWindowSize();
+ int new_sash_position = m_splitMode == wxSPLIT_VERTICAL ? x : y;
wxSplitterEvent eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED,
this);
m_windowOne = m_windowTwo;
m_windowTwo = (wxWindow *) NULL;
SendUnsplitEvent(removedWindow);
- m_sashPosition = 0;
+ DoSetSashPosition(0);
}
else if ( new_sash_position == window_size )
{
wxWindow *removedWindow = m_windowTwo;
m_windowTwo = (wxWindow *) NULL;
SendUnsplitEvent(removedWindow);
- m_sashPosition = 0;
+ DoSetSashPosition(0);
}
else
{
- m_sashPosition = new_sash_position;
+ DoSetSashPosition(new_sash_position);
}
}
else
{
- m_sashPosition = new_sash_position;
+ DoSetSashPosition(new_sash_position);
}
SizeWindows();
// Obtain window size. We are only interested in the dimension the sash
// splits up
- int new_sash_position =
- (int) ( m_splitMode == wxSPLIT_VERTICAL ? x : y );
+ int new_sash_position = m_splitMode == wxSPLIT_VERTICAL ? x : y;
wxSplitterEvent eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING,
this);
return;
}
}
-
+
if (new_sash_position == m_sashPosition)
return;
}
else
{
- m_sashPosition = new_sash_position;
+ DoSetSashPosition(new_sash_position);
m_needUpdating = TRUE;
}
}
}
bool iconized = FALSE;
- wxFrame *frame = wxDynamicCast(parent, wxFrame);
- if ( frame )
- iconized = frame->IsIconized();
- else
+
+ // wxMotif doesn't yet have a wxTopLevelWindow implementation
+#ifdef __WXMOTIF__
+ wxFrame *winTop = wxDynamicCast(parent, wxFrame);
+#else
+ wxTopLevelWindow *winTop = wxDynamicCast(parent, wxTopLevelWindow);
+#endif
+ if ( winTop )
{
- wxDialog *dialog = wxDynamicCast(parent, wxDialog);
- if ( dialog )
- iconized = dialog->IsIconized();
- else
- wxFAIL_MSG(wxT("should have a top level frame or dialog parent!"));
+ iconized = winTop->IsIconized();
}
+#ifndef __WXMOTIF__
+ else
+ {
+ wxFAIL_MSG(wxT("should have a top level parent!"));
+ iconized = FALSE;
+ }
+#endif
+
if ( iconized )
{
event.Skip();
+
+ return;
}
- else
+
+ int cw, ch;
+ GetClientSize( &cw, &ch );
+ if ( m_windowTwo )
{
- int cw, ch;
- GetClientSize( &cw, &ch );
- if ( m_windowTwo )
+ if ( m_splitMode == wxSPLIT_VERTICAL )
{
- if ( m_splitMode == wxSPLIT_VERTICAL )
- {
- if ( m_sashPosition >= (cw - 5) )
- m_sashPosition = wxMax(10, cw - 40);
- }
- if ( m_splitMode == wxSPLIT_HORIZONTAL )
- {
- if ( m_sashPosition >= (ch - 5) )
- m_sashPosition = wxMax(10, ch - 40);
- }
+ if ( m_sashPosition >= (cw - 5) )
+ DoSetSashPosition(wxMax(10, cw - 40));
+ }
+ else // m_splitMode == wxSPLIT_HORIZONTAL
+ {
+ if ( m_sashPosition >= (ch - 5) )
+ DoSetSashPosition(wxMax(10, ch - 40));
}
-
- SizeWindows();
}
+
+ SizeWindows();
}
bool wxSplitterWindow::SashHitTest(int x, int y, int tolerance)
if ( m_splitMode == wxSPLIT_VERTICAL )
{
dc.SetPen(*m_facePen);
- dc.SetBrush(*m_faceBrush);
+
+ if (HasFlag( wxSP_SASH_AQUA ))
+ dc.SetBrush(*wxWHITE_BRUSH);
+ else
+ dc.SetBrush(*m_faceBrush);
dc.DrawRectangle(m_sashPosition + 2, 0 , m_sashSize - 4, h );
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.SetPen(*m_hilightPen);
dc.DrawLine(m_sashPosition+1, m_borderSize - 2, m_sashPosition+1, h - m_borderSize+2);
- dc.SetPen(*m_mediumShadowPen);
- int yMedium = m_borderSize ? h-m_borderSize+1 : h ;
+ if (!HasFlag( wxSP_SASH_AQUA ))
+ dc.SetPen(*m_mediumShadowPen);
+
+ int yMedium = m_borderSize ? h-m_borderSize+1 : h ;
dc.DrawLine(m_sashPosition+m_sashSize-2, xShadow, m_sashPosition+m_sashSize-2, yMedium);
- dc.SetPen(*m_darkShadowPen);
+ if (HasFlag( wxSP_SASH_AQUA ))
+ dc.SetPen(*m_lightShadowPen);
+ else
+ dc.SetPen(*m_darkShadowPen);
dc.DrawLine(m_sashPosition+m_sashSize-1, m_borderSize, m_sashPosition+m_sashSize-1, h-m_borderSize );
// Draw the top and bottom edges of the sash, if requested
else
{
dc.SetPen(*m_facePen);
- dc.SetBrush(*m_faceBrush);
+ if (HasFlag( wxSP_SASH_AQUA ))
+ dc.SetBrush(*wxWHITE_BRUSH);
+ else
+ dc.SetBrush(*m_faceBrush);
dc.DrawRectangle( m_borderSize-2, m_sashPosition + 2, w-m_borderSize+2, m_sashSize - 4);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.SetPen(*m_hilightPen);
dc.DrawLine(m_borderSize-2, m_sashPosition+1, w-m_borderSize+1, m_sashPosition+1);
- dc.SetPen(*m_mediumShadowPen);
+ if (!HasFlag( wxSP_SASH_AQUA ))
+ dc.SetPen(*m_mediumShadowPen);
dc.DrawLine(m_borderSize-1, m_sashPosition+m_sashSize-2, w-m_borderSize+1, m_sashPosition+m_sashSize-2);
- dc.SetPen(*m_darkShadowPen);
+ if (HasFlag( wxSP_SASH_AQUA ))
+ dc.SetPen(*m_lightShadowPen);
+ else
+ dc.SetPen(*m_darkShadowPen);
dc.DrawLine(m_borderSize, m_sashPosition+m_sashSize-1, w-m_borderSize, m_sashPosition+m_sashSize-1);
// Draw the left and right edges of the sash, if requested
screenDC.SetBrush(wxNullBrush);
}
+int wxSplitterWindow::GetWindowSize() const
+{
+ wxSize size = GetClientSize();
+
+ return m_splitMode == wxSPLIT_VERTICAL ? size.x : size.y;
+}
+
+int wxSplitterWindow::AdjustSashPosition(int sashPos) const
+{
+ int window_size = GetWindowSize();
+
+ wxWindow *win;
+
+ win = GetWindow1();
+ if ( win )
+ {
+ // the window shouldn't be smaller than its own minimal size nor
+ // smaller than the minimual pane size specified for this splitter
+ int minSize = m_splitMode == wxSPLIT_VERTICAL ? win->GetMinWidth()
+ : win->GetMinHeight();
+
+ if ( minSize == -1 || m_minimumPaneSize > minSize )
+ minSize = m_minimumPaneSize;
+
+ minSize += GetBorderSize();
+
+ if ( sashPos < minSize )
+ sashPos = minSize;
+ }
+
+ win = GetWindow2();
+ if ( win )
+ {
+ int minSize = m_splitMode == wxSPLIT_VERTICAL ? win->GetMinWidth()
+ : win->GetMinHeight();
+
+ if ( minSize == -1 || m_minimumPaneSize > minSize )
+ minSize = m_minimumPaneSize;
+
+ int maxSize = window_size - minSize - GetBorderSize();
+ if ( sashPos > maxSize )
+ sashPos = maxSize;
+ }
+
+ return sashPos;
+}
+
+void wxSplitterWindow::DoSetSashPosition(int sashPos)
+{
+ m_requestedSashPosition = sashPos;
+ m_sashPosition = (sashPos == 0) ? 0 : AdjustSashPosition(sashPos);
+}
+
// Position and size subwindows.
// Note that the border size applies to each subwindow, not
// including the edges next to the sash.
void wxSplitterWindow::SizeWindows()
{
+ if ( m_requestedSashPosition != m_sashPosition )
+ DoSetSashPosition(m_requestedSashPosition);
+
int w, h;
GetClientSize(&w, &h);
if ( GetWindow1() && !GetWindow2() )
{
- GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(), w - 2*GetBorderSize(), h - 2*GetBorderSize());
-
+ GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
+ w - 2*GetBorderSize(), h - 2*GetBorderSize());
}
else if ( GetWindow1() && GetWindow2() )
{
if ( GetBorderSize() > 0 )
DrawBorders(dc);
DrawSash(dc);
-
+
SetNeedUpdating(FALSE);
}
{
m_windowOne = window;
m_windowTwo = (wxWindow *) NULL;
- m_sashPosition = 0;
+ DoSetSashPosition(0);
}
// Associates the given window with window 2, drawing the appropriate sash
// and changing the split mode.
// Does nothing and returns FALSE if the window is already split.
-bool wxSplitterWindow::SplitVertically(wxWindow *window1, wxWindow *window2, int sashPosition)
+bool wxSplitterWindow::DoSplit(wxSplitMode mode,
+ wxWindow *window1, wxWindow *window2,
+ int sashPosition)
{
if ( IsSplit() )
return FALSE;
- int w, h;
- GetClientSize(&w, &h);
+ int window_size = GetWindowSize();
- m_splitMode = wxSPLIT_VERTICAL;
+ m_splitMode = mode;
m_windowOne = window1;
m_windowTwo = window2;
- if ( sashPosition > 0 )
- m_sashPosition = sashPosition;
- else if ( sashPosition < 0 )
- m_sashPosition = w - sashPosition;
- else // default
- m_sashPosition = w/2;
-
- SizeWindows();
- return TRUE;
-}
-
-bool wxSplitterWindow::SplitHorizontally(wxWindow *window1, wxWindow *window2, int sashPosition)
-{
- if ( IsSplit() )
- return FALSE;
-
- int w, h;
- GetClientSize(&w, &h);
-
- m_splitMode = wxSPLIT_HORIZONTAL;
- m_windowOne = window1;
- m_windowTwo = window2;
if ( sashPosition > 0 )
- m_sashPosition = sashPosition;
+ {
+ DoSetSashPosition(sashPosition);
+ }
else if ( sashPosition < 0 )
- m_sashPosition = h - sashPosition;
- else // default
- m_sashPosition = h/2;
+ {
+ // It's negative so adding is subtracting
+ DoSetSashPosition(window_size + sashPosition);
+ }
+ else
+ {
+ // default
+ DoSetSashPosition(window_size/2);
+ }
SizeWindows();
return TRUE;
}
-
// Remove the specified (or second) window from the view
// Doesn't actually delete the window.
bool wxSplitterWindow::Unsplit(wxWindow *toRemove)
}
SendUnsplitEvent(win);
- m_sashPosition = 0;
+ DoSetSashPosition(0);
SizeWindows();
return TRUE;
return TRUE;
}
+void wxSplitterWindow::SetMinimumPaneSize(int min)
+{
+ m_minimumPaneSize = min;
+ SetSashPosition(m_sashPosition); // re-check limits
+}
+
void wxSplitterWindow::SetSashPosition(int position, bool redraw)
{
- m_sashPosition = position;
+ DoSetSashPosition(position);
if ( redraw )
{
// Shadow colours
#ifndef __WIN16__
- wxColour faceColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
+ wxColour faceColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
m_facePen = new wxPen(faceColour, 1, wxSOLID);
m_faceBrush = new wxBrush(faceColour, wxSOLID);
- wxColour mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW));
+ wxColour mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW));
m_mediumShadowPen = new wxPen(mediumShadowColour, 1, wxSOLID);
- wxColour darkShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DDKSHADOW));
+ wxColour darkShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW));
m_darkShadowPen = new wxPen(darkShadowColour, 1, wxSOLID);
- wxColour lightShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT));
+ wxColour lightShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT));
m_lightShadowPen = new wxPen(lightShadowColour, 1, wxSOLID);
- wxColour hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT));
+ wxColour hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT));
m_hilightPen = new wxPen(hilightColour, 1, wxSOLID);
#else
m_facePen = new wxPen("LIGHT GREY", 1, wxSOLID);
int newSashPosition = event.GetSashPosition();
// Obtain relevant window dimension for bottom / right threshold check
- int w, h;
- GetClientSize(&w, &h);
- int window_size = (m_splitMode == wxSPLIT_VERTICAL) ? w : h ;
+ int window_size = GetWindowSize();
bool unsplit_scenario = FALSE;
if ( m_permitUnsplitAlways
if ( !unsplit_scenario )
{
// If resultant pane would be too small, enlarge it
- if ( newSashPosition < m_minimumPaneSize )
- newSashPosition = m_minimumPaneSize;
- if ( newSashPosition > window_size - m_minimumPaneSize )
- newSashPosition = window_size - m_minimumPaneSize;
+ newSashPosition = AdjustSashPosition(newSashPosition);
}
// If the result is out of bounds it means minimum size is too big,