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 wxDEFINE_EVENT( wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
, wxSplitterEvent
);
43 wxDEFINE_EVENT( wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
, wxSplitterEvent
);
44 wxDEFINE_EVENT( wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
, wxSplitterEvent
);
45 wxDEFINE_EVENT( wxEVT_COMMAND_SPLITTER_UNSPLIT
, wxSplitterEvent
);
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
)
64 EVT_MOUSE_CAPTURE_LOST(wxSplitterWindow::OnMouseCaptureLost
)
66 #if defined( __WXMSW__ ) || defined( __WXMAC__)
67 EVT_SET_CURSOR(wxSplitterWindow::OnSetCursor
)
71 static bool IsLive(wxSplitterWindow
* wnd
)
73 // with wxSP_LIVE_UPDATE style the splitter windows are always resized
74 // following the mouse movement while it drags the sash, without it we only
75 // draw the sash at the new position but only resize the windows when the
76 // dragging is finished
77 #if defined( __WXMAC__ ) && defined(TARGET_API_MAC_OSX) && TARGET_API_MAC_OSX == 1
78 return true; // Mac can't paint outside paint event - always need live mode
80 return wnd
->HasFlag(wxSP_LIVE_UPDATE
);
84 bool wxSplitterWindow::Create(wxWindow
*parent
, wxWindowID id
,
90 // allow TABbing from one window to the other
91 style
|= wxTAB_TRAVERSAL
;
93 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
96 m_lastSize
= GetClientSize();
98 m_permitUnsplitAlways
= (style
& wxSP_PERMIT_UNSPLIT
) != 0;
100 // FIXME: with this line the background is not erased at all under GTK1,
101 // so temporary avoid it there
102 #if !defined(__WXGTK__) || defined(__WXGTK20__)
103 // don't erase the splitter background, it's pointless as we overwrite it
105 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
111 void wxSplitterWindow::Init()
113 m_splitMode
= wxSPLIT_VERTICAL
;
114 m_permitUnsplitAlways
= true;
117 m_dragMode
= wxSPLIT_DRAG_NONE
;
122 m_requestedSashPosition
= INT_MAX
;
124 m_lastSize
= wxSize(0,0);
125 m_minimumPaneSize
= 0;
126 m_sashCursorWE
= wxCursor(wxCURSOR_SIZEWE
);
127 m_sashCursorNS
= wxCursor(wxCURSOR_SIZENS
);
128 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxPENSTYLE_SOLID
);
130 m_needUpdating
= false;
134 wxSplitterWindow::~wxSplitterWindow()
136 delete m_sashTrackerPen
;
139 // ----------------------------------------------------------------------------
140 // entering/leaving sash
141 // ----------------------------------------------------------------------------
143 void wxSplitterWindow::RedrawIfHotSensitive(bool isHot
)
145 if ( wxRendererNative::Get().GetSplitterParams(this).isHotSensitive
)
152 //else: we don't change our appearance, don't redraw to avoid flicker
155 void wxSplitterWindow::OnEnterSash()
159 RedrawIfHotSensitive(true);
162 void wxSplitterWindow::OnLeaveSash()
164 SetCursor(*wxSTANDARD_CURSOR
);
166 RedrawIfHotSensitive(false);
169 void wxSplitterWindow::SetResizeCursor()
171 SetCursor(m_splitMode
== wxSPLIT_VERTICAL
? m_sashCursorWE
175 // ----------------------------------------------------------------------------
176 // other event handlers
177 // ----------------------------------------------------------------------------
179 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
183 // as subpanels might have a transparent background we must erase the background
184 // at least on OSX, otherwise traces of the sash will remain
185 // test with: splitter sample->replace right window
192 void wxSplitterWindow::OnInternalIdle()
194 wxWindow::OnInternalIdle();
196 // We may need to update the children sizes in two cases: either because
197 // we're in the middle of a live update as indicated by m_needUpdating or
198 // because we have a requested but not yet set sash position as indicated
199 // by m_requestedSashPosition having a valid value.
200 if ( m_needUpdating
)
202 m_needUpdating
= false;
204 else if ( m_requestedSashPosition
== INT_MAX
)
206 // We don't need to resize the children.
213 void wxSplitterWindow::OnMouseEvent(wxMouseEvent
& event
)
215 int x
= (int)event
.GetX(),
216 y
= (int)event
.GetY();
218 if ( GetWindowStyle() & wxSP_NOSASH
)
224 bool isLive
= IsLive(this);
226 if (event
.LeftDown())
228 if ( SashHitTest(x
, y
) )
230 // Start the drag now
231 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
233 // Capture mouse and set the cursor
239 // remember the initial sash position and draw the initial
241 m_sashPositionCurrent
= m_sashPosition
;
243 m_oldX
= (m_splitMode
== wxSPLIT_VERTICAL
? m_sashPositionCurrent
: x
);
244 m_oldY
= (m_splitMode
!= wxSPLIT_VERTICAL
? m_sashPositionCurrent
: y
);
245 DrawSashTracker(m_oldX
, m_oldY
);
248 m_ptStart
= wxPoint(x
,y
);
249 m_sashStart
= m_sashPosition
;
253 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
255 // We can stop dragging now and see what we've got.
256 m_dragMode
= wxSPLIT_DRAG_NONE
;
258 // Release mouse and unset the cursor
260 SetCursor(* wxSTANDARD_CURSOR
);
262 // exit if unsplit after doubleclick
271 DrawSashTracker(m_oldX
, m_oldY
);
274 // the position of the click doesn't exactly correspond to
275 // m_sashPosition, rather it changes it by the distance by which the
277 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_ptStart
.x
: y
- m_ptStart
.y
;
279 int posSashNew
= OnSashPositionChanging(m_sashStart
+ diff
);
280 if ( posSashNew
== -1 )
282 // change not allowed
286 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
288 // Deal with possible unsplit scenarios
289 if ( posSashNew
== 0 )
291 // We remove the first window from the view
292 wxWindow
*removedWindow
= m_windowOne
;
293 m_windowOne
= m_windowTwo
;
295 OnUnsplit(removedWindow
);
296 wxSplitterEvent
eventUnsplit(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
297 eventUnsplit
.m_data
.win
= removedWindow
;
298 (void)DoSendEvent(eventUnsplit
);
299 SetSashPositionAndNotify(0);
301 else if ( posSashNew
== GetWindowSize() )
303 // We remove the second window from the view
304 wxWindow
*removedWindow
= m_windowTwo
;
306 OnUnsplit(removedWindow
);
307 wxSplitterEvent
eventUnsplit(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
308 eventUnsplit
.m_data
.win
= removedWindow
;
309 (void)DoSendEvent(eventUnsplit
);
310 SetSashPositionAndNotify(0);
314 SetSashPositionAndNotify(posSashNew
);
319 SetSashPositionAndNotify(posSashNew
);
323 } // left up && dragging
324 else if ((event
.Moving() || event
.Leaving() || event
.Entering()) && (m_dragMode
== wxSPLIT_DRAG_NONE
))
326 if ( event
.Leaving() || !SashHitTest(x
, y
) )
331 else if (event
.Dragging() && (m_dragMode
== wxSPLIT_DRAG_DRAGGING
))
333 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_ptStart
.x
: y
- m_ptStart
.y
;
335 int posSashNew
= OnSashPositionChanging(m_sashStart
+ diff
);
336 if ( posSashNew
== -1 )
338 // change not allowed
344 if ( posSashNew
== m_sashPositionCurrent
)
347 m_sashPositionCurrent
= posSashNew
;
350 DrawSashTracker(m_oldX
, m_oldY
);
352 m_oldX
= (m_splitMode
== wxSPLIT_VERTICAL
? m_sashPositionCurrent
: x
);
353 m_oldY
= (m_splitMode
!= wxSPLIT_VERTICAL
? m_sashPositionCurrent
: y
);
356 // As we captured the mouse, we may get the mouse events from outside
357 // our window - for example, negative values in x, y. This has a weird
358 // consequence under MSW where we use unsigned values sometimes and
359 // signed ones other times: the coordinates turn as big positive
360 // numbers and so the sash is drawn on the *right* side of the window
361 // instead of the left (or bottom instead of top). Correct this.
362 if ( (short)m_oldX
< 0 )
364 if ( (short)m_oldY
< 0 )
369 DrawSashTracker(m_oldX
, m_oldY
);
373 if ( posSashNew
== m_sashPosition
)
376 DoSetSashPosition(posSashNew
);
378 // in live mode, the new position is the actual sash position, clear requested position!
379 m_requestedSashPosition
= INT_MAX
;
380 m_needUpdating
= true;
383 else if ( event
.LeftDClick() && m_windowTwo
)
385 OnDoubleClickSash(x
, y
);
393 void wxSplitterWindow::OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
395 if (m_dragMode
!= wxSPLIT_DRAG_DRAGGING
)
398 m_dragMode
= wxSPLIT_DRAG_NONE
;
400 SetCursor(* wxSTANDARD_CURSOR
);
405 DrawSashTracker(m_oldX
, m_oldY
);
409 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
411 // only process this message if we're not iconized - otherwise iconizing
412 // and restoring a window containing the splitter has a funny side effect
413 // of changing the splitter position!
414 wxWindow
*parent
= wxGetTopLevelParent(this);
417 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
420 iconized
= winTop
->IsIconized();
424 wxFAIL_MSG(wxT("should have a top level parent!"));
431 m_lastSize
= wxSize(0,0);
438 const wxSize curSize
= event
.GetSize();
440 // Update the sash position if needed.
442 // Notice that we shouldn't do this if the sash position requested by user
443 // couldn't be set yet as it would never be taken into account at all if we
444 // modified it before this happens.
445 if ( m_windowTwo
&& m_requestedSashPosition
== INT_MAX
)
447 int size
= m_splitMode
== wxSPLIT_VERTICAL
? curSize
.x
: curSize
.y
;
449 int old_size
= m_splitMode
== wxSPLIT_VERTICAL
? m_lastSize
.x
: m_lastSize
.y
;
451 // Don't do anything if the size didn't really change.
452 if ( size
!= old_size
)
454 // Apply gravity if we use it.
455 int delta
= (int) ( (size
- old_size
)*m_sashGravity
);
458 int newPosition
= m_sashPosition
+ delta
;
459 if( newPosition
< m_minimumPaneSize
)
460 newPosition
= m_minimumPaneSize
;
461 SetSashPositionAndNotify(newPosition
);
464 // Also check if the second window became too small.
465 int adjustedPosition
= AdjustSashPosition(m_sashPosition
);
466 if ( adjustedPosition
!= m_sashPosition
)
467 SetSashPositionAndNotify(adjustedPosition
);
471 m_lastSize
= curSize
;
476 void wxSplitterWindow::SetSashGravity(double gravity
)
478 wxCHECK_RET( gravity
>= 0. && gravity
<= 1.,
479 wxT("invalid gravity value") );
481 m_sashGravity
= gravity
;
484 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
486 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
487 return false; // No sash
489 int z
= m_splitMode
== wxSPLIT_VERTICAL
? x
: y
;
490 int hitMin
= m_sashPosition
- tolerance
;
491 int hitMax
= m_sashPosition
+ GetSashSize() + tolerance
;
493 return z
>= hitMin
&& z
<= hitMax
;
496 int wxSplitterWindow::GetSashSize() const
498 return wxRendererNative::Get().GetSplitterParams(this).widthSash
;
501 int wxSplitterWindow::GetBorderSize() const
503 return wxRendererNative::Get().GetSplitterParams(this).border
;
507 void wxSplitterWindow::DrawSash(wxDC
& dc
)
509 if (HasFlag(wxSP_3DBORDER
))
510 wxRendererNative::Get().DrawSplitterBorder
517 // don't draw sash if we're not split
518 if ( m_sashPosition
== 0 || !m_windowTwo
)
521 // nor if we're configured to not show it
522 if ( HasFlag(wxSP_NOSASH
) )
525 wxRendererNative::Get().DrawSplitterSash
531 m_splitMode
== wxSPLIT_VERTICAL
? wxVERTICAL
533 m_isHot
? (int)wxCONTROL_CURRENT
: 0
537 // Draw the sash tracker (for whilst moving the sash)
538 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
541 GetClientSize(&w
, &h
);
547 if ( m_splitMode
== wxSPLIT_VERTICAL
)
549 x1
= x2
= wxClip(x
, 0, w
) + m_sashTrackerPen
->GetWidth()/2;
555 y1
= y2
= wxClip(y
, 0, h
) + m_sashTrackerPen
->GetWidth()/2;
560 ClientToScreen(&x1
, &y1
);
561 ClientToScreen(&x2
, &y2
);
563 screenDC
.SetLogicalFunction(wxINVERT
);
564 screenDC
.SetPen(*m_sashTrackerPen
);
565 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
567 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
569 screenDC
.SetLogicalFunction(wxCOPY
);
572 int wxSplitterWindow::GetWindowSize() const
574 wxSize size
= GetClientSize();
576 return m_splitMode
== wxSPLIT_VERTICAL
? size
.x
: size
.y
;
579 int wxSplitterWindow::AdjustSashPosition(int sashPos
) const
586 // the window shouldn't be smaller than its own minimal size nor
587 // smaller than the minimual pane size specified for this splitter
588 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
589 : win
->GetMinHeight();
591 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
592 minSize
= m_minimumPaneSize
;
594 minSize
+= GetBorderSize();
596 if ( sashPos
< minSize
)
603 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
604 : win
->GetMinHeight();
606 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
607 minSize
= m_minimumPaneSize
;
609 int maxSize
= GetWindowSize() - minSize
- GetBorderSize() - GetSashSize();
610 if ( maxSize
> 0 && sashPos
> maxSize
&& maxSize
>= m_minimumPaneSize
)
617 bool wxSplitterWindow::DoSetSashPosition(int sashPos
)
619 int newSashPosition
= AdjustSashPosition(sashPos
);
621 if ( newSashPosition
== m_sashPosition
)
624 m_sashPosition
= newSashPosition
;
629 void wxSplitterWindow::SetSashPositionAndNotify(int sashPos
)
631 // we must reset the request here, otherwise the sash would be stuck at
632 // old position if the user attempted to move the sash after invalid
633 // (e.g. smaller than minsize) sash position was requested using
634 // SetSashPosition():
635 m_requestedSashPosition
= INT_MAX
;
637 // note that we must send the event in any case, i.e. even if the sash
638 // position hasn't changed and DoSetSashPosition() returns false because we
639 // must generate a CHANGED event at the end of resizing
640 DoSetSashPosition(sashPos
);
642 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
, this);
643 event
.m_data
.pos
= m_sashPosition
;
645 (void)DoSendEvent(event
);
648 // Position and size subwindows.
649 // Note that the border size applies to each subwindow, not
650 // including the edges next to the sash.
651 void wxSplitterWindow::SizeWindows()
653 // check if we have delayed setting the real sash position
654 if ( m_requestedSashPosition
!= INT_MAX
)
656 int newSashPosition
= ConvertSashPosition(m_requestedSashPosition
);
657 if ( newSashPosition
!= m_sashPosition
)
659 DoSetSashPosition(newSashPosition
);
662 if ( newSashPosition
<= m_sashPosition
663 && newSashPosition
>= m_sashPosition
- GetBorderSize() )
665 // don't update it any more
666 m_requestedSashPosition
= INT_MAX
;
671 GetClientSize(&w
, &h
);
673 if ( GetWindow1() && !GetWindow2() )
675 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
676 w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
678 else if ( GetWindow1() && GetWindow2() )
680 const int border
= GetBorderSize(),
681 sash
= GetSashSize();
683 int size1
= GetSashPosition() - border
,
684 size2
= GetSashPosition() + sash
;
686 int x2
, y2
, w1
, h1
, w2
, h2
;
687 if ( GetSplitMode() == wxSPLIT_VERTICAL
)
690 w2
= w
- 2*border
- sash
- w1
;
700 else // horz splitter
707 h2
= h
- 2*border
- sash
- h1
;
714 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
715 GetWindow1()->SetSize(border
, border
, w1
, h1
);
722 // Set pane for unsplit window
723 void wxSplitterWindow::Initialize(wxWindow
*window
)
725 wxASSERT_MSG( (!window
|| window
->GetParent() == this),
726 wxT("windows in the splitter should have it as parent!") );
728 if (window
&& !window
->IsShown())
731 m_windowOne
= window
;
733 DoSetSashPosition(0);
736 // Associates the given window with window 2, drawing the appropriate sash
737 // and changing the split mode.
738 // Does nothing and returns false if the window is already split.
739 bool wxSplitterWindow::DoSplit(wxSplitMode mode
,
740 wxWindow
*window1
, wxWindow
*window2
,
746 wxCHECK_MSG( window1
&& window2
, false,
747 wxT("cannot split with NULL window(s)") );
749 wxCHECK_MSG( window1
->GetParent() == this && window2
->GetParent() == this, false,
750 wxT("windows in the splitter should have it as parent!") );
752 if (! window1
->IsShown())
754 if (! window2
->IsShown())
758 m_windowOne
= window1
;
759 m_windowTwo
= window2
;
762 SetSashPosition(sashPosition
, true);
766 int wxSplitterWindow::ConvertSashPosition(int sashPosition
) const
768 if ( sashPosition
> 0 )
772 else if ( sashPosition
< 0 )
774 // It's negative so adding is subtracting
775 return GetWindowSize() + sashPosition
;
777 else // sashPosition == 0
779 // default, put it in the centre
780 return GetWindowSize() / 2;
784 // Remove the specified (or second) window from the view
785 // Doesn't actually delete the window.
786 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
792 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
797 else if ( toRemove
== m_windowOne
)
800 m_windowOne
= m_windowTwo
;
805 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
811 DoSetSashPosition(0);
817 // Replace a window with another one
818 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
820 wxCHECK_MSG( winOld
, false, wxT("use one of Split() functions instead") );
821 wxCHECK_MSG( winNew
, false, wxT("use Unsplit() functions instead") );
823 if ( winOld
== m_windowTwo
)
825 m_windowTwo
= winNew
;
827 else if ( winOld
== m_windowOne
)
829 m_windowOne
= winNew
;
833 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
843 void wxSplitterWindow::SetMinimumPaneSize(int min
)
845 m_minimumPaneSize
= min
;
846 int pos
= m_requestedSashPosition
!= INT_MAX
? m_requestedSashPosition
: m_sashPosition
;
847 SetSashPosition(pos
); // re-check limits
850 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
852 // remember the sash position we want to set for later if we can't set it
853 // right now (e.g. because the window is too small)
854 m_requestedSashPosition
= position
;
856 DoSetSashPosition(ConvertSashPosition(position
));
864 // Make sure the child window sizes are updated. This is useful
865 // for reducing flicker by updating the sizes before a
866 // window is shown, if you know the overall size is correct.
867 void wxSplitterWindow::UpdateSize()
872 bool wxSplitterWindow::DoSendEvent(wxSplitterEvent
& event
)
874 return !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed();
877 wxSize
wxSplitterWindow::DoGetBestSize() const
879 // get best sizes of subwindows
882 size1
= m_windowOne
->GetEffectiveMinSize();
884 size2
= m_windowTwo
->GetEffectiveMinSize();
888 // pSash points to the size component to which sash size must be added
891 if ( m_splitMode
== wxSPLIT_VERTICAL
)
893 sizeBest
.y
= wxMax(size1
.y
, size2
.y
);
894 sizeBest
.x
= wxMax(size1
.x
, m_minimumPaneSize
) +
895 wxMax(size2
.x
, m_minimumPaneSize
);
899 else // wxSPLIT_HORIZONTAL
901 sizeBest
.x
= wxMax(size1
.x
, size2
.x
);
902 sizeBest
.y
= wxMax(size1
.y
, m_minimumPaneSize
) +
903 wxMax(size2
.y
, m_minimumPaneSize
);
908 // account for the sash if the window is actually split
909 if ( m_windowOne
&& m_windowTwo
)
910 *pSash
+= GetSashSize();
912 // account for the border too
913 int border
= 2*GetBorderSize();
914 sizeBest
.x
+= border
;
915 sizeBest
.y
+= border
;
920 // ---------------------------------------------------------------------------
921 // wxSplitterWindow virtual functions: they now just generate the events
922 // ---------------------------------------------------------------------------
924 bool wxSplitterWindow::OnSashPositionChange(int WXUNUSED(newSashPosition
))
926 // always allow by default
930 int wxSplitterWindow::OnSashPositionChanging(int newSashPosition
)
932 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
933 const int UNSPLIT_THRESHOLD
= 4;
935 // first of all, check if OnSashPositionChange() doesn't forbid this change
936 if ( !OnSashPositionChange(newSashPosition
) )
942 // Obtain relevant window dimension for bottom / right threshold check
943 int window_size
= GetWindowSize();
945 bool unsplit_scenario
= false;
946 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
948 // Do edge detection if unsplit premitted
949 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
951 // threshold top / left check
953 unsplit_scenario
= true;
955 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
957 // threshold bottom/right check
958 newSashPosition
= window_size
;
959 unsplit_scenario
= true;
963 if ( !unsplit_scenario
)
965 // If resultant pane would be too small, enlarge it
966 newSashPosition
= AdjustSashPosition(newSashPosition
);
968 // If the result is out of bounds it means minimum size is too big,
969 // so split window in half as best compromise.
970 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
971 newSashPosition
= window_size
/ 2;
974 // now let the event handler have it
976 // FIXME: shouldn't we do it before the adjustments above so as to ensure
977 // that the sash position is always reasonable?
978 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
, this);
979 event
.m_data
.pos
= newSashPosition
;
981 if ( !DoSendEvent(event
) )
983 // the event handler vetoed the change
984 newSashPosition
= -1;
988 // it could have been changed by it
989 newSashPosition
= event
.GetSashPosition();
992 return newSashPosition
;
995 // Called when the sash is double-clicked. The default behaviour is to remove
996 // the sash if the minimum pane size is zero.
997 void wxSplitterWindow::OnDoubleClickSash(int x
, int y
)
999 wxCHECK_RET(m_windowTwo
, wxT("splitter: no window to remove"));
1001 // new code should handle events instead of using the virtual functions
1002 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
, this);
1003 event
.m_data
.pt
.x
= x
;
1004 event
.m_data
.pt
.y
= y
;
1005 if ( DoSendEvent(event
) )
1007 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
1009 wxWindow
* win
= m_windowTwo
;
1012 wxSplitterEvent
unsplitEvent(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
1013 unsplitEvent
.m_data
.win
= win
;
1014 (void)DoSendEvent(unsplitEvent
);
1018 //else: blocked by user
1021 void wxSplitterWindow::OnUnsplit(wxWindow
*winRemoved
)
1023 // call this before calling the event handler which may delete the window
1024 winRemoved
->Show(false);
1027 #if defined( __WXMSW__ ) || defined( __WXMAC__)
1029 // this is currently called (and needed) under MSW only...
1030 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& event
)
1032 // if we don't do it, the resizing cursor might be set for child window:
1033 // and like this we explicitly say that our cursor should not be used for
1034 // children windows which overlap us
1036 if ( SashHitTest(event
.GetX(), event
.GetY(), 0) )
1038 // default processing is ok
1041 //else: do nothing, in particular, don't call Skip()
1044 #endif // wxMSW || wxMac
1046 #endif // wxUSE_SPLITTER