1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/splitter.cpp
3 // Purpose: wxSplitterWindow implementation
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/splitter.h"
23 #include "wx/string.h"
27 #include "wx/dcclient.h"
28 #include "wx/dcscreen.h"
30 #include "wx/window.h"
31 #include "wx/dialog.h"
34 #include "wx/settings.h"
37 #include "wx/renderer.h"
41 wxDEFINE_EVENT( wxEVT_SPLITTER_SASH_POS_CHANGED
, wxSplitterEvent
);
42 wxDEFINE_EVENT( wxEVT_SPLITTER_SASH_POS_CHANGING
, wxSplitterEvent
);
43 wxDEFINE_EVENT( wxEVT_SPLITTER_DOUBLECLICKED
, wxSplitterEvent
);
44 wxDEFINE_EVENT( wxEVT_SPLITTER_UNSPLIT
, wxSplitterEvent
);
46 IMPLEMENT_DYNAMIC_CLASS(wxSplitterWindow
, wxWindow
)
57 IMPLEMENT_DYNAMIC_CLASS(wxSplitterEvent
, wxNotifyEvent
)
59 BEGIN_EVENT_TABLE(wxSplitterWindow
, wxWindow
)
60 EVT_PAINT(wxSplitterWindow::OnPaint
)
61 EVT_SIZE(wxSplitterWindow::OnSize
)
62 EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent
)
63 EVT_MOUSE_CAPTURE_LOST(wxSplitterWindow::OnMouseCaptureLost
)
65 #if defined( __WXMSW__ ) || defined( __WXMAC__)
66 EVT_SET_CURSOR(wxSplitterWindow::OnSetCursor
)
70 static bool IsLive(wxSplitterWindow
* wnd
)
72 // with wxSP_LIVE_UPDATE style the splitter windows are always resized
73 // following the mouse movement while it drags the sash, without it we only
74 // draw the sash at the new position but only resize the windows when the
75 // dragging is finished
76 #if defined( __WXMAC__ ) && defined(TARGET_API_MAC_OSX) && TARGET_API_MAC_OSX == 1
77 return true; // Mac can't paint outside paint event - always need live mode
79 return wnd
->HasFlag(wxSP_LIVE_UPDATE
);
83 bool wxSplitterWindow::Create(wxWindow
*parent
, wxWindowID id
,
89 // allow TABbing from one window to the other
90 style
|= wxTAB_TRAVERSAL
;
92 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
95 m_lastSize
= GetClientSize();
97 m_permitUnsplitAlways
= (style
& wxSP_PERMIT_UNSPLIT
) != 0;
99 // FIXME: with this line the background is not erased at all under GTK1,
100 // so temporary avoid it there
101 #if !defined(__WXGTK__) || defined(__WXGTK20__)
102 // don't erase the splitter background, it's pointless as we overwrite it
104 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
110 void wxSplitterWindow::Init()
112 m_splitMode
= wxSPLIT_VERTICAL
;
113 m_permitUnsplitAlways
= true;
116 m_dragMode
= wxSPLIT_DRAG_NONE
;
121 m_requestedSashPosition
= INT_MAX
;
123 m_lastSize
= wxSize(0,0);
124 m_minimumPaneSize
= 0;
125 m_sashCursorWE
= wxCursor(wxCURSOR_SIZEWE
);
126 m_sashCursorNS
= wxCursor(wxCURSOR_SIZENS
);
127 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxPENSTYLE_SOLID
);
129 m_needUpdating
= false;
133 wxSplitterWindow::~wxSplitterWindow()
135 delete m_sashTrackerPen
;
138 // ----------------------------------------------------------------------------
139 // entering/leaving sash
140 // ----------------------------------------------------------------------------
142 void wxSplitterWindow::RedrawIfHotSensitive(bool isHot
)
144 if ( wxRendererNative::Get().GetSplitterParams(this).isHotSensitive
)
151 //else: we don't change our appearance, don't redraw to avoid flicker
154 void wxSplitterWindow::OnEnterSash()
158 RedrawIfHotSensitive(true);
161 void wxSplitterWindow::OnLeaveSash()
163 SetCursor(*wxSTANDARD_CURSOR
);
165 RedrawIfHotSensitive(false);
168 void wxSplitterWindow::SetResizeCursor()
170 SetCursor(m_splitMode
== wxSPLIT_VERTICAL
? m_sashCursorWE
174 // ----------------------------------------------------------------------------
175 // other event handlers
176 // ----------------------------------------------------------------------------
178 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
182 // as subpanels might have a transparent background we must erase the background
183 // at least on OSX, otherwise traces of the sash will remain
184 // test with: splitter sample->replace right window
191 void wxSplitterWindow::OnInternalIdle()
193 wxWindow::OnInternalIdle();
195 // We may need to update the children sizes in two cases: either because
196 // we're in the middle of a live update as indicated by m_needUpdating or
197 // because we have a requested but not yet set sash position as indicated
198 // by m_requestedSashPosition having a valid value.
199 if ( m_needUpdating
)
201 m_needUpdating
= false;
203 else if ( m_requestedSashPosition
== INT_MAX
)
205 // We don't need to resize the children.
212 void wxSplitterWindow::OnMouseEvent(wxMouseEvent
& event
)
214 int x
= (int)event
.GetX(),
215 y
= (int)event
.GetY();
217 if ( GetWindowStyle() & wxSP_NOSASH
)
223 bool isLive
= IsLive(this);
225 if (event
.LeftDown())
227 if ( SashHitTest(x
, y
) )
229 // Start the drag now
230 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
232 // Capture mouse and set the cursor
238 // remember the initial sash position and draw the initial
240 m_sashPositionCurrent
= m_sashPosition
;
242 m_oldX
= (m_splitMode
== wxSPLIT_VERTICAL
? m_sashPositionCurrent
: x
);
243 m_oldY
= (m_splitMode
!= wxSPLIT_VERTICAL
? m_sashPositionCurrent
: y
);
244 DrawSashTracker(m_oldX
, m_oldY
);
247 m_ptStart
= wxPoint(x
,y
);
248 m_sashStart
= m_sashPosition
;
252 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
254 // We can stop dragging now and see what we've got.
255 m_dragMode
= wxSPLIT_DRAG_NONE
;
257 // Release mouse and unset the cursor
259 SetCursor(* wxSTANDARD_CURSOR
);
261 // exit if unsplit after doubleclick
270 DrawSashTracker(m_oldX
, m_oldY
);
273 // the position of the click doesn't exactly correspond to
274 // m_sashPosition, rather it changes it by the distance by which the
276 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_ptStart
.x
: y
- m_ptStart
.y
;
278 int posSashNew
= OnSashPositionChanging(m_sashStart
+ diff
);
279 if ( posSashNew
== -1 )
281 // change not allowed
285 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
287 // Deal with possible unsplit scenarios
288 if ( posSashNew
== 0 )
290 // We remove the first window from the view
291 wxWindow
*removedWindow
= m_windowOne
;
292 m_windowOne
= m_windowTwo
;
294 OnUnsplit(removedWindow
);
295 wxSplitterEvent
eventUnsplit(wxEVT_SPLITTER_UNSPLIT
, this);
296 eventUnsplit
.m_data
.win
= removedWindow
;
297 (void)DoSendEvent(eventUnsplit
);
298 SetSashPositionAndNotify(0);
300 else if ( posSashNew
== GetWindowSize() )
302 // We remove the second window from the view
303 wxWindow
*removedWindow
= m_windowTwo
;
305 OnUnsplit(removedWindow
);
306 wxSplitterEvent
eventUnsplit(wxEVT_SPLITTER_UNSPLIT
, this);
307 eventUnsplit
.m_data
.win
= removedWindow
;
308 (void)DoSendEvent(eventUnsplit
);
309 SetSashPositionAndNotify(0);
313 SetSashPositionAndNotify(posSashNew
);
318 SetSashPositionAndNotify(posSashNew
);
322 } // left up && dragging
323 else if ((event
.Moving() || event
.Leaving() || event
.Entering()) && (m_dragMode
== wxSPLIT_DRAG_NONE
))
325 if ( event
.Leaving() || !SashHitTest(x
, y
) )
330 else if (event
.Dragging() && (m_dragMode
== wxSPLIT_DRAG_DRAGGING
))
332 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_ptStart
.x
: y
- m_ptStart
.y
;
334 int posSashNew
= OnSashPositionChanging(m_sashStart
+ diff
);
335 if ( posSashNew
== -1 )
337 // change not allowed
343 if ( posSashNew
== m_sashPositionCurrent
)
346 m_sashPositionCurrent
= posSashNew
;
349 DrawSashTracker(m_oldX
, m_oldY
);
351 m_oldX
= (m_splitMode
== wxSPLIT_VERTICAL
? m_sashPositionCurrent
: x
);
352 m_oldY
= (m_splitMode
!= wxSPLIT_VERTICAL
? m_sashPositionCurrent
: y
);
355 // As we captured the mouse, we may get the mouse events from outside
356 // our window - for example, negative values in x, y. This has a weird
357 // consequence under MSW where we use unsigned values sometimes and
358 // signed ones other times: the coordinates turn as big positive
359 // numbers and so the sash is drawn on the *right* side of the window
360 // instead of the left (or bottom instead of top). Correct this.
361 if ( (short)m_oldX
< 0 )
363 if ( (short)m_oldY
< 0 )
368 DrawSashTracker(m_oldX
, m_oldY
);
372 if ( posSashNew
== m_sashPosition
)
375 DoSetSashPosition(posSashNew
);
377 // in live mode, the new position is the actual sash position, clear requested position!
378 m_requestedSashPosition
= INT_MAX
;
379 m_needUpdating
= true;
382 else if ( event
.LeftDClick() && m_windowTwo
)
384 OnDoubleClickSash(x
, y
);
392 void wxSplitterWindow::OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
394 if (m_dragMode
!= wxSPLIT_DRAG_DRAGGING
)
397 m_dragMode
= wxSPLIT_DRAG_NONE
;
399 SetCursor(* wxSTANDARD_CURSOR
);
404 DrawSashTracker(m_oldX
, m_oldY
);
408 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
410 // only process this message if we're not iconized - otherwise iconizing
411 // and restoring a window containing the splitter has a funny side effect
412 // of changing the splitter position!
413 wxWindow
*parent
= wxGetTopLevelParent(this);
416 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
419 iconized
= winTop
->IsIconized();
423 wxFAIL_MSG(wxT("should have a top level parent!"));
430 m_lastSize
= wxSize(0,0);
437 const wxSize curSize
= event
.GetSize();
439 // Update the sash position if needed.
441 // Notice that we shouldn't do this if the sash position requested by user
442 // couldn't be set yet as it would never be taken into account at all if we
443 // modified it before this happens.
444 if ( m_windowTwo
&& m_requestedSashPosition
== INT_MAX
)
446 int size
= m_splitMode
== wxSPLIT_VERTICAL
? curSize
.x
: curSize
.y
;
448 int old_size
= m_splitMode
== wxSPLIT_VERTICAL
? m_lastSize
.x
: m_lastSize
.y
;
450 // Don't do anything if the size didn't really change.
451 if ( size
!= old_size
)
453 int newPosition
= -1;
455 // Apply gravity if we use it.
456 int delta
= (int) ( (size
- old_size
)*m_sashGravity
);
459 newPosition
= m_sashPosition
+ delta
;
460 if( newPosition
< m_minimumPaneSize
)
461 newPosition
= m_minimumPaneSize
;
464 // Also check if the second window became too small.
465 newPosition
= AdjustSashPosition(newPosition
== -1
468 if ( newPosition
!= m_sashPosition
)
469 SetSashPositionAndNotify(newPosition
);
473 m_lastSize
= curSize
;
478 void wxSplitterWindow::SetSashGravity(double gravity
)
480 wxCHECK_RET( gravity
>= 0. && gravity
<= 1.,
481 wxT("invalid gravity value") );
483 m_sashGravity
= gravity
;
486 bool wxSplitterWindow::SashHitTest(int x
, int y
)
488 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
489 return false; // No sash
491 int z
= m_splitMode
== wxSPLIT_VERTICAL
? x
: y
;
492 int hitMax
= m_sashPosition
+ GetSashSize() - 1;
494 return z
>= m_sashPosition
&& z
<= hitMax
;
497 void wxSplitterWindow::SetSashInvisible(bool invisible
)
499 if ( IsSashInvisible() != invisible
)
500 ToggleWindowStyle(wxSP_NOSASH
);
503 int wxSplitterWindow::GetSashSize() const
505 return IsSashInvisible() ? 0 : GetDefaultSashSize();
508 int wxSplitterWindow::GetDefaultSashSize() const
510 return wxRendererNative::Get().GetSplitterParams(this).widthSash
;
513 int wxSplitterWindow::GetBorderSize() const
515 return wxRendererNative::Get().GetSplitterParams(this).border
;
519 void wxSplitterWindow::DrawSash(wxDC
& dc
)
521 if (HasFlag(wxSP_3DBORDER
))
522 wxRendererNative::Get().DrawSplitterBorder
529 // don't draw sash if we're not split
530 if ( m_sashPosition
== 0 || !m_windowTwo
)
533 // nor if we're configured to not show it
534 if ( IsSashInvisible() )
537 wxRendererNative::Get().DrawSplitterSash
543 m_splitMode
== wxSPLIT_VERTICAL
? wxVERTICAL
545 m_isHot
? (int)wxCONTROL_CURRENT
: 0
549 // Draw the sash tracker (for whilst moving the sash)
550 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
553 GetClientSize(&w
, &h
);
559 if ( m_splitMode
== wxSPLIT_VERTICAL
)
561 x1
= x2
= wxClip(x
, 0, w
) + m_sashTrackerPen
->GetWidth()/2;
567 y1
= y2
= wxClip(y
, 0, h
) + m_sashTrackerPen
->GetWidth()/2;
572 ClientToScreen(&x1
, &y1
);
573 ClientToScreen(&x2
, &y2
);
575 screenDC
.SetLogicalFunction(wxINVERT
);
576 screenDC
.SetPen(*m_sashTrackerPen
);
577 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
579 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
581 screenDC
.SetLogicalFunction(wxCOPY
);
584 int wxSplitterWindow::GetWindowSize() const
586 wxSize size
= GetClientSize();
588 return m_splitMode
== wxSPLIT_VERTICAL
? size
.x
: size
.y
;
591 int wxSplitterWindow::AdjustSashPosition(int sashPos
) const
598 // the window shouldn't be smaller than its own minimal size nor
599 // smaller than the minimual pane size specified for this splitter
600 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
601 : win
->GetMinHeight();
603 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
604 minSize
= m_minimumPaneSize
;
606 minSize
+= GetBorderSize();
608 if ( sashPos
< minSize
)
615 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
616 : win
->GetMinHeight();
618 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
619 minSize
= m_minimumPaneSize
;
621 int maxSize
= GetWindowSize() - minSize
- GetBorderSize() - GetSashSize();
622 if ( maxSize
> 0 && sashPos
> maxSize
&& maxSize
>= m_minimumPaneSize
)
629 bool wxSplitterWindow::DoSetSashPosition(int sashPos
)
631 int newSashPosition
= AdjustSashPosition(sashPos
);
633 if ( newSashPosition
== m_sashPosition
)
636 m_sashPosition
= newSashPosition
;
641 void wxSplitterWindow::SetSashPositionAndNotify(int sashPos
)
643 // we must reset the request here, otherwise the sash would be stuck at
644 // old position if the user attempted to move the sash after invalid
645 // (e.g. smaller than minsize) sash position was requested using
646 // SetSashPosition():
647 m_requestedSashPosition
= INT_MAX
;
649 // note that we must send the event in any case, i.e. even if the sash
650 // position hasn't changed and DoSetSashPosition() returns false because we
651 // must generate a CHANGED event at the end of resizing
652 DoSetSashPosition(sashPos
);
654 wxSplitterEvent
event(wxEVT_SPLITTER_SASH_POS_CHANGED
, this);
655 event
.m_data
.pos
= m_sashPosition
;
657 (void)DoSendEvent(event
);
660 // Position and size subwindows.
661 // Note that the border size applies to each subwindow, not
662 // including the edges next to the sash.
663 void wxSplitterWindow::SizeWindows()
665 // check if we have delayed setting the real sash position
666 if ( m_requestedSashPosition
!= INT_MAX
)
668 int newSashPosition
= ConvertSashPosition(m_requestedSashPosition
);
669 if ( newSashPosition
!= m_sashPosition
)
671 DoSetSashPosition(newSashPosition
);
674 if ( newSashPosition
<= m_sashPosition
675 && newSashPosition
>= m_sashPosition
- GetBorderSize() )
677 // don't update it any more
678 m_requestedSashPosition
= INT_MAX
;
683 GetClientSize(&w
, &h
);
685 if ( GetWindow1() && !GetWindow2() )
687 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
688 w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
690 else if ( GetWindow1() && GetWindow2() )
692 const int border
= GetBorderSize(),
693 sash
= GetSashSize();
695 int size1
= GetSashPosition() - border
,
696 size2
= GetSashPosition() + sash
;
698 int x2
, y2
, w1
, h1
, w2
, h2
;
699 if ( GetSplitMode() == wxSPLIT_VERTICAL
)
702 w2
= w
- 2*border
- sash
- w1
;
712 else // horz splitter
719 h2
= h
- 2*border
- sash
- h1
;
726 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
727 GetWindow1()->SetSize(border
, border
, w1
, h1
);
734 // Set pane for unsplit window
735 void wxSplitterWindow::Initialize(wxWindow
*window
)
737 wxASSERT_MSG( (!window
|| window
->GetParent() == this),
738 wxT("windows in the splitter should have it as parent!") );
740 if (window
&& !window
->IsShown())
743 m_windowOne
= window
;
745 DoSetSashPosition(0);
748 // Associates the given window with window 2, drawing the appropriate sash
749 // and changing the split mode.
750 // Does nothing and returns false if the window is already split.
751 bool wxSplitterWindow::DoSplit(wxSplitMode mode
,
752 wxWindow
*window1
, wxWindow
*window2
,
758 wxCHECK_MSG( window1
&& window2
, false,
759 wxT("cannot split with NULL window(s)") );
761 wxCHECK_MSG( window1
->GetParent() == this && window2
->GetParent() == this, false,
762 wxT("windows in the splitter should have it as parent!") );
764 if (! window1
->IsShown())
766 if (! window2
->IsShown())
770 m_windowOne
= window1
;
771 m_windowTwo
= window2
;
774 SetSashPosition(sashPosition
, true);
778 int wxSplitterWindow::ConvertSashPosition(int sashPosition
) const
780 if ( sashPosition
> 0 )
784 else if ( sashPosition
< 0 )
786 // It's negative so adding is subtracting
787 return GetWindowSize() + sashPosition
;
789 else // sashPosition == 0
791 // default, put it in the centre
792 return GetWindowSize() / 2;
796 // Remove the specified (or second) window from the view
797 // Doesn't actually delete the window.
798 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
804 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
809 else if ( toRemove
== m_windowOne
)
812 m_windowOne
= m_windowTwo
;
817 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
823 DoSetSashPosition(0);
829 // Replace a window with another one
830 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
832 wxCHECK_MSG( winOld
, false, wxT("use one of Split() functions instead") );
833 wxCHECK_MSG( winNew
, false, wxT("use Unsplit() functions instead") );
835 if ( winOld
== m_windowTwo
)
837 m_windowTwo
= winNew
;
839 else if ( winOld
== m_windowOne
)
841 m_windowOne
= winNew
;
845 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
855 void wxSplitterWindow::SetMinimumPaneSize(int min
)
857 m_minimumPaneSize
= min
;
858 int pos
= m_requestedSashPosition
!= INT_MAX
? m_requestedSashPosition
: m_sashPosition
;
859 SetSashPosition(pos
); // re-check limits
862 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
864 // remember the sash position we want to set for later if we can't set it
865 // right now (e.g. because the window is too small)
866 m_requestedSashPosition
= position
;
868 DoSetSashPosition(ConvertSashPosition(position
));
876 // Make sure the child window sizes are updated. This is useful
877 // for reducing flicker by updating the sizes before a
878 // window is shown, if you know the overall size is correct.
879 void wxSplitterWindow::UpdateSize()
884 bool wxSplitterWindow::DoSendEvent(wxSplitterEvent
& event
)
886 return !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed();
889 wxSize
wxSplitterWindow::DoGetBestSize() const
891 // get best sizes of subwindows
894 size1
= m_windowOne
->GetEffectiveMinSize();
896 size2
= m_windowTwo
->GetEffectiveMinSize();
900 // pSash points to the size component to which sash size must be added
903 if ( m_splitMode
== wxSPLIT_VERTICAL
)
905 sizeBest
.y
= wxMax(size1
.y
, size2
.y
);
906 sizeBest
.x
= wxMax(size1
.x
, m_minimumPaneSize
) +
907 wxMax(size2
.x
, m_minimumPaneSize
);
911 else // wxSPLIT_HORIZONTAL
913 sizeBest
.x
= wxMax(size1
.x
, size2
.x
);
914 sizeBest
.y
= wxMax(size1
.y
, m_minimumPaneSize
) +
915 wxMax(size2
.y
, m_minimumPaneSize
);
920 // account for the sash if the window is actually split
921 if ( m_windowOne
&& m_windowTwo
)
922 *pSash
+= GetSashSize();
924 // account for the border too
925 int border
= 2*GetBorderSize();
926 sizeBest
.x
+= border
;
927 sizeBest
.y
+= border
;
932 // ---------------------------------------------------------------------------
933 // wxSplitterWindow virtual functions: they now just generate the events
934 // ---------------------------------------------------------------------------
936 bool wxSplitterWindow::OnSashPositionChange(int WXUNUSED(newSashPosition
))
938 // always allow by default
942 int wxSplitterWindow::OnSashPositionChanging(int newSashPosition
)
944 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
945 const int UNSPLIT_THRESHOLD
= 4;
947 // first of all, check if OnSashPositionChange() doesn't forbid this change
948 if ( !OnSashPositionChange(newSashPosition
) )
954 // Obtain relevant window dimension for bottom / right threshold check
955 int window_size
= GetWindowSize();
957 bool unsplit_scenario
= false;
958 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
960 // Do edge detection if unsplit premitted
961 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
963 // threshold top / left check
965 unsplit_scenario
= true;
967 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
969 // threshold bottom/right check
970 newSashPosition
= window_size
;
971 unsplit_scenario
= true;
975 if ( !unsplit_scenario
)
977 // If resultant pane would be too small, enlarge it
978 newSashPosition
= AdjustSashPosition(newSashPosition
);
980 // If the result is out of bounds it means minimum size is too big,
981 // so split window in half as best compromise.
982 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
983 newSashPosition
= window_size
/ 2;
986 // now let the event handler have it
988 // FIXME: shouldn't we do it before the adjustments above so as to ensure
989 // that the sash position is always reasonable?
990 wxSplitterEvent
event(wxEVT_SPLITTER_SASH_POS_CHANGING
, this);
991 event
.m_data
.pos
= newSashPosition
;
993 if ( !DoSendEvent(event
) )
995 // the event handler vetoed the change
996 newSashPosition
= -1;
1000 // it could have been changed by it
1001 newSashPosition
= event
.GetSashPosition();
1004 return newSashPosition
;
1007 // Called when the sash is double-clicked. The default behaviour is to remove
1008 // the sash if the minimum pane size is zero.
1009 void wxSplitterWindow::OnDoubleClickSash(int x
, int y
)
1011 wxCHECK_RET(m_windowTwo
, wxT("splitter: no window to remove"));
1013 // new code should handle events instead of using the virtual functions
1014 wxSplitterEvent
event(wxEVT_SPLITTER_DOUBLECLICKED
, this);
1015 event
.m_data
.pt
.x
= x
;
1016 event
.m_data
.pt
.y
= y
;
1017 if ( DoSendEvent(event
) )
1019 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
1021 wxWindow
* win
= m_windowTwo
;
1024 wxSplitterEvent
unsplitEvent(wxEVT_SPLITTER_UNSPLIT
, this);
1025 unsplitEvent
.m_data
.win
= win
;
1026 (void)DoSendEvent(unsplitEvent
);
1030 //else: blocked by user
1033 void wxSplitterWindow::OnUnsplit(wxWindow
*winRemoved
)
1035 // call this before calling the event handler which may delete the window
1036 winRemoved
->Show(false);
1039 #if defined( __WXMSW__ ) || defined( __WXMAC__)
1041 // this is currently called (and needed) under MSW only...
1042 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& event
)
1044 // if we don't do it, the resizing cursor might be set for child window:
1045 // and like this we explicitly say that our cursor should not be used for
1046 // children windows which overlap us
1048 if ( SashHitTest(event
.GetX(), event
.GetY()) )
1050 // default processing is ok
1053 //else: do nothing, in particular, don't call Skip()
1056 #endif // wxMSW || wxMac
1058 #endif // wxUSE_SPLITTER