1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/splitter.cpp
3 // Purpose: wxSplitterWindow implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/splitter.h"
24 #include "wx/string.h"
28 #include "wx/dcclient.h"
29 #include "wx/dcscreen.h"
31 #include "wx/window.h"
32 #include "wx/dialog.h"
35 #include "wx/settings.h"
38 #include "wx/renderer.h"
42 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
)
43 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
)
44 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
)
45 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_UNSPLIT
)
47 IMPLEMENT_DYNAMIC_CLASS(wxSplitterWindow
, wxWindow
)
58 IMPLEMENT_DYNAMIC_CLASS(wxSplitterEvent
, wxNotifyEvent
)
60 BEGIN_EVENT_TABLE(wxSplitterWindow
, wxWindow
)
61 EVT_PAINT(wxSplitterWindow::OnPaint
)
62 EVT_SIZE(wxSplitterWindow::OnSize
)
63 EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent
)
65 #if defined( __WXMSW__ ) || defined( __WXMAC__)
66 EVT_SET_CURSOR(wxSplitterWindow::OnSetCursor
)
69 WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow
)
72 WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow
, wxWindow
)
74 bool wxSplitterWindow::Create(wxWindow
*parent
, wxWindowID id
,
80 // allow TABbing from one window to the other
81 style
|= wxTAB_TRAVERSAL
;
83 // we draw our border ourselves to blend the sash with it
84 style
&= ~wxBORDER_MASK
;
85 style
|= wxBORDER_NONE
;
87 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
91 m_lastSize
.x
= size
.x
;
93 m_lastSize
.y
= size
.y
;
95 m_permitUnsplitAlways
= (style
& wxSP_PERMIT_UNSPLIT
) != 0;
97 // FIXME: with this line the background is not erased at all under GTK1,
98 // so temporary avoid it there
99 #if !defined(__WXGTK__) || defined(__WXGTK20__)
100 // don't erase the splitter background, it's pointless as we overwrite it
102 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
108 void wxSplitterWindow::Init()
110 WX_INIT_CONTROL_CONTAINER();
112 m_splitMode
= wxSPLIT_VERTICAL
;
113 m_permitUnsplitAlways
= true;
114 m_windowOne
= (wxWindow
*) NULL
;
115 m_windowTwo
= (wxWindow
*) NULL
;
116 m_dragMode
= wxSPLIT_DRAG_NONE
;
121 m_sashPosition
= m_requestedSashPosition
= 0;
123 m_sashSize
= -1; // -1 means use the native sash size
124 m_lastSize
= wxSize(0,0);
125 m_checkRequestedSashPosition
= false;
126 m_minimumPaneSize
= 0;
127 m_sashCursorWE
= wxCursor(wxCURSOR_SIZEWE
);
128 m_sashCursorNS
= wxCursor(wxCURSOR_SIZENS
);
129 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxSOLID
);
131 m_needUpdating
= false;
135 wxSplitterWindow::~wxSplitterWindow()
137 delete m_sashTrackerPen
;
140 // ----------------------------------------------------------------------------
141 // entering/leaving sash
142 // ----------------------------------------------------------------------------
144 void wxSplitterWindow::RedrawIfHotSensitive(bool isHot
)
146 if ( wxRendererNative::Get().GetSplitterParams(this).isHotSensitive
)
153 //else: we don't change our appearance, don't redraw to avoid flicker
156 void wxSplitterWindow::OnEnterSash()
160 RedrawIfHotSensitive(true);
163 void wxSplitterWindow::OnLeaveSash()
165 SetCursor(*wxSTANDARD_CURSOR
);
167 RedrawIfHotSensitive(false);
170 void wxSplitterWindow::SetResizeCursor()
172 SetCursor(m_splitMode
== wxSPLIT_VERTICAL
? m_sashCursorWE
176 // ----------------------------------------------------------------------------
177 // other event handlers
178 // ----------------------------------------------------------------------------
180 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
187 void wxSplitterWindow::OnInternalIdle()
189 wxWindow::OnInternalIdle();
191 // if this is the first idle time after a sash position has potentially
192 // been set, allow SizeWindows to check for a requested size.
193 if (!m_checkRequestedSashPosition
)
195 m_checkRequestedSashPosition
= true;
197 return; // it won't needUpdating in this case
204 void wxSplitterWindow::OnMouseEvent(wxMouseEvent
& event
)
206 int x
= (int)event
.GetX(),
207 y
= (int)event
.GetY();
209 if (GetWindowStyle() & wxSP_NOSASH
)
212 // with wxSP_LIVE_UPDATE style the splitter windows are always resized
213 // following the mouse movement while it drags the sash, without it we only
214 // draw the sash at the new position but only resize the windows when the
215 // dragging is finished
216 #if defined( __WXMAC__ ) && defined(TARGET_API_MAC_OSX) && TARGET_API_MAC_OSX == 1
217 bool isLive
= true ; // FIXME: why?
219 bool isLive
= HasFlag(wxSP_LIVE_UPDATE
);
221 if (event
.LeftDown())
223 if ( SashHitTest(x
, y
) )
225 // Start the drag now
226 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
228 // Capture mouse and set the cursor
234 // remember the initial sash position and draw the initial
236 m_sashPositionCurrent
= m_sashPosition
;
238 DrawSashTracker(x
, y
);
248 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
250 // We can stop dragging now and see what we've got.
251 m_dragMode
= wxSPLIT_DRAG_NONE
;
253 // Release mouse and unset the cursor
255 SetCursor(* wxSTANDARD_CURSOR
);
257 // exit if unsplit after doubleclick
266 DrawSashTracker(m_oldX
, m_oldY
);
269 // the position of the click doesn't exactly correspond to
270 // m_sashPosition, rather it changes it by the distance by which the
272 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_oldX
: y
- m_oldY
;
274 int posSashOld
= isLive
? m_sashPosition
: m_sashPositionCurrent
;
275 int posSashNew
= OnSashPositionChanging(posSashOld
+ diff
);
276 if ( posSashNew
== -1 )
278 // change not allowed
282 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
284 // Deal with possible unsplit scenarios
285 if ( posSashNew
== 0 )
287 // We remove the first window from the view
288 wxWindow
*removedWindow
= m_windowOne
;
289 m_windowOne
= m_windowTwo
;
290 m_windowTwo
= (wxWindow
*) NULL
;
291 OnUnsplit(removedWindow
);
292 wxSplitterEvent
eventUnsplit(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
293 eventUnsplit
.m_data
.win
= removedWindow
;
294 (void)DoSendEvent(eventUnsplit
);
295 SetSashPositionAndNotify(0);
297 else if ( posSashNew
== GetWindowSize() )
299 // We remove the second window from the view
300 wxWindow
*removedWindow
= m_windowTwo
;
301 m_windowTwo
= (wxWindow
*) NULL
;
302 OnUnsplit(removedWindow
);
303 wxSplitterEvent
eventUnsplit(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
304 eventUnsplit
.m_data
.win
= removedWindow
;
305 (void)DoSendEvent(eventUnsplit
);
306 SetSashPositionAndNotify(0);
310 SetSashPositionAndNotify(posSashNew
);
315 SetSashPositionAndNotify(posSashNew
);
319 } // left up && dragging
320 else if ((event
.Moving() || event
.Leaving() || event
.Entering()) && (m_dragMode
== wxSPLIT_DRAG_NONE
))
322 if ( event
.Leaving() || !SashHitTest(x
, y
) )
327 else if (event
.Dragging() && (m_dragMode
== wxSPLIT_DRAG_DRAGGING
))
329 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_oldX
: y
- m_oldY
;
332 // nothing to do, mouse didn't really move far enough
336 int posSashOld
= isLive
? m_sashPosition
: m_sashPositionCurrent
;
337 int posSashNew
= OnSashPositionChanging(posSashOld
+ diff
);
338 if ( posSashNew
== -1 )
340 // change not allowed
344 if ( posSashNew
== m_sashPosition
)
350 DrawSashTracker(m_oldX
, m_oldY
);
353 if (m_splitMode
== wxSPLIT_VERTICAL
)
358 // Remember old positions
363 // As we captured the mouse, we may get the mouse events from outside
364 // our window - for example, negative values in x, y. This has a weird
365 // consequence under MSW where we use unsigned values sometimes and
366 // signed ones other times: the coordinates turn as big positive
367 // numbers and so the sash is drawn on the *right* side of the window
368 // instead of the left (or bottom instead of top). Correct this.
369 if ( (short)m_oldX
< 0 )
371 if ( (short)m_oldY
< 0 )
378 m_sashPositionCurrent
= posSashNew
;
380 DrawSashTracker(m_oldX
, m_oldY
);
384 DoSetSashPosition(posSashNew
);
385 m_needUpdating
= true;
388 else if ( event
.LeftDClick() && m_windowTwo
)
390 OnDoubleClickSash(x
, y
);
394 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
396 // only process this message if we're not iconized - otherwise iconizing
397 // and restoring a window containing the splitter has a funny side effect
398 // of changing the splitter position!
399 wxWindow
*parent
= wxGetTopLevelParent(this);
402 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
405 iconized
= winTop
->IsIconized();
409 wxFAIL_MSG(wxT("should have a top level parent!"));
416 m_lastSize
= wxSize(0,0);
426 GetClientSize(&w
, &h
);
428 int size
= m_splitMode
== wxSPLIT_VERTICAL
? w
: h
;
430 int old_size
= m_splitMode
== wxSPLIT_VERTICAL
? m_lastSize
.x
: m_lastSize
.y
;
433 int delta
= (int) ( (size
- old_size
)*m_sashGravity
);
436 int newPosition
= m_sashPosition
+ delta
;
437 if( newPosition
< m_minimumPaneSize
)
438 newPosition
= m_minimumPaneSize
;
439 SetSashPositionAndNotify(newPosition
);
443 if ( m_sashPosition
>= size
- 5 )
444 SetSashPositionAndNotify(wxMax(10, size
- 40));
445 m_lastSize
= wxSize(w
,h
);
451 void wxSplitterWindow::SetSashGravity(double gravity
)
453 wxCHECK_RET( gravity
>= 0. && gravity
<= 1.,
454 _T("invalid gravity value") );
456 m_sashGravity
= gravity
;
459 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
461 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
462 return false; // No sash
464 int z
= m_splitMode
== wxSPLIT_VERTICAL
? x
: y
;
465 int hitMin
= m_sashPosition
- tolerance
;
466 int hitMax
= m_sashPosition
+ GetSashSize() + tolerance
;
468 return z
>= hitMin
&& z
<= hitMax
;
471 int wxSplitterWindow::GetSashSize() const
473 return m_sashSize
> -1 ? m_sashSize
: wxRendererNative::Get().GetSplitterParams(this).widthSash
;
476 int wxSplitterWindow::GetBorderSize() const
478 return wxRendererNative::Get().GetSplitterParams(this).border
;
482 void wxSplitterWindow::DrawSash(wxDC
& dc
)
484 if (HasFlag(wxSP_3DBORDER
))
485 wxRendererNative::Get().DrawSplitterBorder
492 // don't draw sash if we're not split
493 if ( m_sashPosition
== 0 || !m_windowTwo
)
496 // nor if we're configured to not show it
497 if ( HasFlag(wxSP_NOSASH
) )
500 wxRendererNative::Get().DrawSplitterSash
506 m_splitMode
== wxSPLIT_VERTICAL
? wxVERTICAL
508 m_isHot
? (int)wxCONTROL_CURRENT
: 0
512 // Draw the sash tracker (for whilst moving the sash)
513 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
516 GetClientSize(&w
, &h
);
522 if ( m_splitMode
== wxSPLIT_VERTICAL
)
553 ClientToScreen(&x1
, &y1
);
554 ClientToScreen(&x2
, &y2
);
556 screenDC
.SetLogicalFunction(wxINVERT
);
557 screenDC
.SetPen(*m_sashTrackerPen
);
558 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
560 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
562 screenDC
.SetLogicalFunction(wxCOPY
);
565 int wxSplitterWindow::GetWindowSize() const
567 wxSize size
= GetClientSize();
569 return m_splitMode
== wxSPLIT_VERTICAL
? size
.x
: size
.y
;
572 int wxSplitterWindow::AdjustSashPosition(int sashPos
) const
579 // the window shouldn't be smaller than its own minimal size nor
580 // smaller than the minimual pane size specified for this splitter
581 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
582 : win
->GetMinHeight();
584 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
585 minSize
= m_minimumPaneSize
;
587 minSize
+= GetBorderSize();
589 if ( sashPos
< minSize
)
596 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
597 : win
->GetMinHeight();
599 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
600 minSize
= m_minimumPaneSize
;
602 int maxSize
= GetWindowSize() - minSize
- GetBorderSize() - GetSashSize();
603 if ( maxSize
> 0 && sashPos
> maxSize
)
610 bool wxSplitterWindow::DoSetSashPosition(int sashPos
)
612 int newSashPosition
= AdjustSashPosition(sashPos
);
614 if ( newSashPosition
== m_sashPosition
)
617 m_sashPosition
= newSashPosition
;
622 void wxSplitterWindow::SetSashPositionAndNotify(int sashPos
)
624 // we must reset the request here, otherwise the sash would be stuck at
625 // old position if the user attempted to move the sash after invalid
626 // (e.g. smaller than minsize) sash position was requested using
627 // SetSashPosition():
628 m_requestedSashPosition
= INT_MAX
;
630 // note that we must send the event in any case, i.e. even if the sash
631 // position hasn't changed and DoSetSashPosition() returns false because we
632 // must generate a CHANGED event at the end of resizing
633 DoSetSashPosition(sashPos
);
635 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
, this);
636 event
.m_data
.pos
= m_sashPosition
;
638 (void)DoSendEvent(event
);
641 // Position and size subwindows.
642 // Note that the border size applies to each subwindow, not
643 // including the edges next to the sash.
644 void wxSplitterWindow::SizeWindows()
646 // check if we have delayed setting the real sash position
647 if ( m_checkRequestedSashPosition
&& m_requestedSashPosition
!= INT_MAX
)
649 int newSashPosition
= ConvertSashPosition(m_requestedSashPosition
);
650 if ( newSashPosition
!= m_sashPosition
)
652 DoSetSashPosition(newSashPosition
);
655 if ( newSashPosition
<= m_sashPosition
656 && newSashPosition
>= m_sashPosition
- GetBorderSize() )
658 // don't update it any more
659 m_requestedSashPosition
= INT_MAX
;
664 GetClientSize(&w
, &h
);
666 if ( GetWindow1() && !GetWindow2() )
668 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
669 w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
671 else if ( GetWindow1() && GetWindow2() )
673 const int border
= GetBorderSize(),
674 sash
= GetSashSize();
676 int size1
= GetSashPosition() - border
,
677 size2
= GetSashPosition() + sash
;
679 int x2
, y2
, w1
, h1
, w2
, h2
;
680 if ( GetSplitMode() == wxSPLIT_VERTICAL
)
683 w2
= w
- 2*border
- sash
- w1
;
693 else // horz splitter
700 h2
= h
- 2*border
- sash
- h1
;
707 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
708 GetWindow1()->SetSize(border
, border
, w1
, h1
);
714 SetNeedUpdating(false);
717 // Set pane for unsplit window
718 void wxSplitterWindow::Initialize(wxWindow
*window
)
720 wxASSERT_MSG( (!window
|| (window
&& window
->GetParent() == this)),
721 _T("windows in the splitter should have it as parent!") );
723 if (window
&& !window
->IsShown())
726 m_windowOne
= window
;
727 m_windowTwo
= (wxWindow
*) NULL
;
728 DoSetSashPosition(0);
731 // Associates the given window with window 2, drawing the appropriate sash
732 // and changing the split mode.
733 // Does nothing and returns false if the window is already split.
734 bool wxSplitterWindow::DoSplit(wxSplitMode mode
,
735 wxWindow
*window1
, wxWindow
*window2
,
741 wxCHECK_MSG( window1
&& window2
, false,
742 _T("can not split with NULL window(s)") );
744 wxCHECK_MSG( window1
->GetParent() == this && window2
->GetParent() == this, false,
745 _T("windows in the splitter should have it as parent!") );
747 if (! window1
->IsShown())
749 if (! window2
->IsShown())
753 m_windowOne
= window1
;
754 m_windowTwo
= window2
;
756 // remember the sash position we want to set for later if we can't set it
757 // right now (e.g. because the window is too small)
758 m_requestedSashPosition
= sashPosition
;
759 m_checkRequestedSashPosition
= false;
761 DoSetSashPosition(ConvertSashPosition(sashPosition
));
768 int wxSplitterWindow::ConvertSashPosition(int sashPosition
) const
770 if ( sashPosition
> 0 )
774 else if ( sashPosition
< 0 )
776 // It's negative so adding is subtracting
777 return GetWindowSize() + sashPosition
;
779 else // sashPosition == 0
781 // default, put it in the centre
782 return GetWindowSize() / 2;
786 // Remove the specified (or second) window from the view
787 // Doesn't actually delete the window.
788 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
794 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
797 m_windowTwo
= (wxWindow
*) NULL
;
799 else if ( toRemove
== m_windowOne
)
802 m_windowOne
= m_windowTwo
;
803 m_windowTwo
= (wxWindow
*) NULL
;
807 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
813 DoSetSashPosition(0);
819 // Replace a window with another one
820 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
822 wxCHECK_MSG( winOld
, false, wxT("use one of Split() functions instead") );
823 wxCHECK_MSG( winNew
, false, wxT("use Unsplit() functions instead") );
825 if ( winOld
== m_windowTwo
)
827 m_windowTwo
= winNew
;
829 else if ( winOld
== m_windowOne
)
831 m_windowOne
= winNew
;
835 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
845 void wxSplitterWindow::SetMinimumPaneSize(int min
)
847 m_minimumPaneSize
= min
;
848 int pos
= m_requestedSashPosition
!= INT_MAX
? m_requestedSashPosition
: m_sashPosition
;
849 SetSashPosition(pos
); // re-check limits
852 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
854 // remember the sash position we want to set for later if we can't set it
855 // right now (e.g. because the window is too small)
856 m_requestedSashPosition
= position
;
857 m_checkRequestedSashPosition
= false;
859 DoSetSashPosition(ConvertSashPosition(position
));
867 // Make sure the child window sizes are updated. This is useful
868 // for reducing flicker by updating the sizes before a
869 // window is shown, if you know the overall size is correct.
870 void wxSplitterWindow::UpdateSize()
872 m_checkRequestedSashPosition
= true;
874 m_checkRequestedSashPosition
= false;
877 bool wxSplitterWindow::DoSendEvent(wxSplitterEvent
& event
)
879 return !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed();
882 wxSize
wxSplitterWindow::DoGetBestSize() const
884 // get best sizes of subwindows
887 size1
= m_windowOne
->GetEffectiveMinSize();
889 size2
= m_windowTwo
->GetEffectiveMinSize();
893 // pSash points to the size component to which sash size must be added
896 if ( m_splitMode
== wxSPLIT_VERTICAL
)
898 sizeBest
.y
= wxMax(size1
.y
, size2
.y
);
899 sizeBest
.x
= wxMax(size1
.x
, m_minimumPaneSize
) +
900 wxMax(size2
.x
, m_minimumPaneSize
);
904 else // wxSPLIT_HORIZONTAL
906 sizeBest
.x
= wxMax(size1
.x
, size2
.x
);
907 sizeBest
.y
= wxMax(size1
.y
, m_minimumPaneSize
) +
908 wxMax(size2
.y
, m_minimumPaneSize
);
913 // account for the border and the sash
914 int border
= 2*GetBorderSize();
915 *pSash
+= GetSashSize();
916 sizeBest
.x
+= border
;
917 sizeBest
.y
+= border
;
922 // ---------------------------------------------------------------------------
923 // wxSplitterWindow virtual functions: they now just generate the events
924 // ---------------------------------------------------------------------------
926 bool wxSplitterWindow::OnSashPositionChange(int WXUNUSED(newSashPosition
))
928 // always allow by default
932 int wxSplitterWindow::OnSashPositionChanging(int newSashPosition
)
934 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
935 const int UNSPLIT_THRESHOLD
= 4;
937 // first of all, check if OnSashPositionChange() doesn't forbid this change
938 if ( !OnSashPositionChange(newSashPosition
) )
944 // Obtain relevant window dimension for bottom / right threshold check
945 int window_size
= GetWindowSize();
947 bool unsplit_scenario
= false;
948 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
950 // Do edge detection if unsplit premitted
951 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
953 // threshold top / left check
955 unsplit_scenario
= true;
957 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
959 // threshold bottom/right check
960 newSashPosition
= window_size
;
961 unsplit_scenario
= true;
965 if ( !unsplit_scenario
)
967 // If resultant pane would be too small, enlarge it
968 newSashPosition
= AdjustSashPosition(newSashPosition
);
971 // If the result is out of bounds it means minimum size is too big,
972 // so split window in half as best compromise.
973 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
974 newSashPosition
= window_size
/ 2;
976 // now let the event handler have it
978 // FIXME: shouldn't we do it before the adjustments above so as to ensure
979 // that the sash position is always reasonable?
980 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
, this);
981 event
.m_data
.pos
= newSashPosition
;
983 if ( !DoSendEvent(event
) )
985 // the event handler vetoed the change
986 newSashPosition
= -1;
990 // it could have been changed by it
991 newSashPosition
= event
.GetSashPosition();
994 return newSashPosition
;
997 // Called when the sash is double-clicked. The default behaviour is to remove
998 // the sash if the minimum pane size is zero.
999 void wxSplitterWindow::OnDoubleClickSash(int x
, int y
)
1001 wxCHECK_RET(m_windowTwo
, wxT("splitter: no window to remove"));
1003 // new code should handle events instead of using the virtual functions
1004 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
, this);
1005 event
.m_data
.pt
.x
= x
;
1006 event
.m_data
.pt
.y
= y
;
1007 if ( DoSendEvent(event
) )
1009 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
1011 wxWindow
* win
= m_windowTwo
;
1014 wxSplitterEvent
unsplitEvent(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
1015 unsplitEvent
.m_data
.win
= win
;
1016 (void)DoSendEvent(unsplitEvent
);
1020 //else: blocked by user
1023 void wxSplitterWindow::OnUnsplit(wxWindow
*winRemoved
)
1025 // call this before calling the event handler which may delete the window
1026 winRemoved
->Show(false);
1029 #if defined( __WXMSW__ ) || defined( __WXMAC__)
1031 // this is currently called (and needed) under MSW only...
1032 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& event
)
1034 // if we don't do it, the resizing cursor might be set for child window:
1035 // and like this we explicitly say that our cursor should not be used for
1036 // children windows which overlap us
1038 if ( SashHitTest(event
.GetX(), event
.GetY(), 0) )
1040 // default processing is ok
1043 //else: do nothing, in particular, don't call Skip()
1046 #endif // wxMSW || wxMac
1048 #endif // wxUSE_SPLITTER