All (GUI):
+- wxSplitterWindow now supports gravity parameter (Zbigniew Zagórski)
- recursive wxSizer::GetItem returns item of given window, sizer or nth index
- wxLayoutConstraints now use best size, not current size, for AsIs() condition
- wxSizer::Add/Insert etc. now returns pointer to wxSizerItem just added and this
\helpref{wxSplitterWindow::SetMinimumPaneSize}{wxsplitterwindowsetminimumpanesize}
+\membersection{wxSplitterWindow::GetSashGravity}\label{wxsplitterwindowgetsashgravity}
+
+\func{double}{GetSashGravity}{\void}
+
+Returns the current sash gravity.
+
+\wxheading{See also}
+
+\helpref{wxSplitterWindow::SetSashGravity}{wxsplitterwindowsetsashgravity}
+
\membersection{wxSplitterWindow::GetSashPosition}\label{wxsplitterwindowgetsashposition}
\func{int}{GetSashPosition}{\void}
\helpref{wxSplitterWindow::SplitVertically}{wxsplitterwindowsplitvertically}\\
\helpref{wxSplitterWindow::SplitHorizontally}{wxsplitterwindowsplithorizontally}
+\membersection{wxSplitterWindow::SetSashGravity}\label{wxsplitterwindowsetsashgravity}
+
+\func{void}{SetSashGravity}{\param{double }{gravity}}
+
+Sets the sash gravity.
+
+\wxheading{Parameters}
+
+\docparam{gravity}{The sash gravity. Value between 0.0 and 1.0.}
+
+
+\wxheading{Remarks}
+Gravity is real factor which controls position of sash while resizing wxSplitterWindow.
+Gravity tells wxSplitterWindow how much will left/top window grow while resizing.
+
+Example values:
+\begin{itemize}\itemsep=0pt
+\item{ 0.0 - only the bottom/right window is automaticaly resized}
+\item{ 0.5 - both windows grow by equal size}
+\item{ 1.0 - only left/top window grows}
+\end{itemize}
+
+Gravity should be real value betwwen 0.0 and 1.0.
+
+Default value of sash gravity is 0.0. That value is compatible with previous
+(before gravity was introduced) behaviour of wxSplitterWindow.
+
+\wxheading{See also}
+
+\helpref{wxSplitterWindow::GetSashGravity}{wxsplitterwindowgetsashgravity}
+
\membersection{wxSplitterWindow::SetSashPosition}\label{wxsplitterwindowsetsashposition}
\func{void}{SetSashPosition}{\param{int }{position}, \param{const bool}{ redraw = true}}
// Gets the sash position
int GetSashPosition() const { return m_sashPosition; }
+ // Set the sash gravity
+ void SetSashGravity(double gravity);
+
+ // Gets the sash gravity
+ double GetSashGravity() const { return m_sashGravity; }
+
// If this is zero, we can remove panes by dragging the sash.
void SetMinimumPaneSize(int min);
int GetMinimumPaneSize() const { return m_minimumPaneSize; }
bool GetNeedUpdating() const { return m_needUpdating ; }
#ifdef __WXMAC__
- virtual bool MacClipGrandChildren() const { return true ; }
+ virtual bool MacClipGrandChildren() const { return true ; }
#endif
protected:
// event handlers
int m_oldX;
int m_oldY;
int m_sashPosition; // Number of pixels from left or top
+ double m_sashGravity;
+ wxSize m_lastSize;
int m_requestedSashPosition;
int m_sashPositionCurrent; // while dragging
int m_firstX;
SPLIT_UNSPLIT,
SPLIT_LIVE,
SPLIT_SETPOSITION,
- SPLIT_SETMINSIZE
+ SPLIT_SETMINSIZE,
+ SPLIT_SETGRAVITY
};
// ----------------------------------------------------------------------------
void ToggleLive(wxCommandEvent& event);
void SetPosition(wxCommandEvent& event);
void SetMinSize(wxCommandEvent& event);
+ void SetGravity(wxCommandEvent& event);
void Quit(wxCommandEvent& event);
EVT_MENU(SPLIT_LIVE, MyFrame::ToggleLive)
EVT_MENU(SPLIT_SETPOSITION, MyFrame::SetPosition)
EVT_MENU(SPLIT_SETMINSIZE, MyFrame::SetMinSize)
+ EVT_MENU(SPLIT_SETGRAVITY, MyFrame::SetGravity)
EVT_MENU(SPLIT_QUIT, MyFrame::Quit)
splitMenu->Append(SPLIT_SETMINSIZE,
_T("Set &min size\tCtrl-M"),
_T("Set minimum pane size"));
+ splitMenu->Append(SPLIT_SETGRAVITY,
+ _T("Set &gravity\tCtrl-G"),
+ _T("Set gravity of sash"));
splitMenu->AppendSeparator();
splitMenu->Append(SPLIT_QUIT, _T("E&xit\tAlt-X"), _T("Exit"));
menuBar->Check(SPLIT_LIVE, true);
m_splitter = new MySplitterWindow(this);
+
+ m_splitter->SetSashGravity(1.0);
#if 1
m_left = new MyCanvas(m_splitter, true);
SetStatusText(str, 1);
#endif // wxUSE_STATUSBAR
}
+void MyFrame::SetGravity(wxCommandEvent& WXUNUSED(event) )
+{
+ wxString str;
+ str.Printf( wxT("%g"), m_splitter->GetSashGravity());
+ str = wxGetTextFromUser(_T("Enter sash gravity (0,1):"), _T(""), str, this);
+ if ( str.empty() )
+ return;
+
+ double gravity = wxStrtod( str, (wxChar**)NULL);
+ m_splitter->SetSashGravity(gravity);
+#if wxUSE_STATUSBAR
+ str.Printf( wxT("Gravity = %g"), gravity);
+ SetStatusText(str, 1);
+#endif // wxUSE_STATUSBAR
+}
// Update UI handlers
m_firstX = 0;
m_firstY = 0;
m_sashPosition = m_requestedSashPosition = 0;
+ m_sashGravity = 0.0;
+ m_lastSize = wxSize(0,0);
m_checkRequestedSashPosition = false;
m_minimumPaneSize = 0;
m_sashCursorWE = wxCursor(wxCURSOR_SIZEWE);
if ( iconized )
{
+ m_lastSize = wxSize(0,0);
+
event.Skip();
return;
GetClientSize(&w, &h);
int size = m_splitMode == wxSPLIT_VERTICAL ? w : h;
+
+ int old_size = m_splitMode == wxSPLIT_VERTICAL ? m_lastSize.x : m_lastSize.y;
+ if ( old_size != 0 )
+ {
+ int delta = (int) ( (size - old_size)*m_sashGravity );
+ if ( delta != 0 )
+ {
+ int newPosition = m_sashPosition + delta;
+ if( newPosition < m_minimumPaneSize )
+ newPosition = m_minimumPaneSize;
+ SetSashPositionAndNotify(newPosition);
+ }
+ }
+
if ( m_sashPosition >= size - 5 )
SetSashPositionAndNotify(wxMax(10, size - 40));
+ m_lastSize = wxSize(w,h);
}
SizeWindows();
}
+void wxSplitterWindow::SetSashGravity(double gravity)
+{
+ wxCHECK_RET( gravity >= 0. && gravity <= 1.,
+ _T("invalid gravity value") );
+
+ m_sashGravity = gravity;
+}
+
bool wxSplitterWindow::SashHitTest(int x, int y, int tolerance)
{
if ( m_windowTwo == NULL || m_sashPosition == 0)
{
// we must reset the request here, otherwise the sash would be stuck at
// old position if the user attempted to move the sash after invalid
- // (e.g. smaller than minsize) sash position was requested using
+ // (e.g. smaller than minsize) sash position was requested using
// SetSashPosition():
m_requestedSashPosition = INT_MAX;