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
)
70 WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow
)
73 WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow
, wxWindow
)
75 static bool IsLive(wxSplitterWindow
* wnd
)
77 // with wxSP_LIVE_UPDATE style the splitter windows are always resized
78 // following the mouse movement while it drags the sash, without it we only
79 // draw the sash at the new position but only resize the windows when the
80 // dragging is finished
81 #if defined( __WXMAC__ ) && defined(TARGET_API_MAC_OSX) && TARGET_API_MAC_OSX == 1
82 return true; // Mac can't paint outside paint event - always need live mode
84 return wnd
->HasFlag(wxSP_LIVE_UPDATE
);
88 bool wxSplitterWindow::Create(wxWindow
*parent
, wxWindowID id
,
94 // allow TABbing from one window to the other
95 style
|= wxTAB_TRAVERSAL
;
97 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
101 m_lastSize
.x
= size
.x
;
103 m_lastSize
.y
= size
.y
;
105 m_permitUnsplitAlways
= (style
& wxSP_PERMIT_UNSPLIT
) != 0;
107 // FIXME: with this line the background is not erased at all under GTK1,
108 // so temporary avoid it there
109 #if !defined(__WXGTK__) || defined(__WXGTK20__)
110 // don't erase the splitter background, it's pointless as we overwrite it
112 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
118 void wxSplitterWindow::Init()
120 WX_INIT_CONTROL_CONTAINER();
122 m_splitMode
= wxSPLIT_VERTICAL
;
123 m_permitUnsplitAlways
= true;
126 m_dragMode
= wxSPLIT_DRAG_NONE
;
130 m_sashPosition
= m_requestedSashPosition
= 0;
132 m_lastSize
= wxSize(0,0);
133 m_checkRequestedSashPosition
= false;
134 m_minimumPaneSize
= 0;
135 m_sashCursorWE
= wxCursor(wxCURSOR_SIZEWE
);
136 m_sashCursorNS
= wxCursor(wxCURSOR_SIZENS
);
137 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxPENSTYLE_SOLID
);
139 m_needUpdating
= false;
143 wxSplitterWindow::~wxSplitterWindow()
145 delete m_sashTrackerPen
;
148 // ----------------------------------------------------------------------------
149 // entering/leaving sash
150 // ----------------------------------------------------------------------------
152 void wxSplitterWindow::RedrawIfHotSensitive(bool isHot
)
154 if ( wxRendererNative::Get().GetSplitterParams(this).isHotSensitive
)
161 //else: we don't change our appearance, don't redraw to avoid flicker
164 void wxSplitterWindow::OnEnterSash()
168 RedrawIfHotSensitive(true);
171 void wxSplitterWindow::OnLeaveSash()
173 SetCursor(*wxSTANDARD_CURSOR
);
175 RedrawIfHotSensitive(false);
178 void wxSplitterWindow::SetResizeCursor()
180 SetCursor(m_splitMode
== wxSPLIT_VERTICAL
? m_sashCursorWE
184 // ----------------------------------------------------------------------------
185 // other event handlers
186 // ----------------------------------------------------------------------------
188 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
192 // as subpanels might have a transparent background we must erase the background
193 // at least on OSX, otherwise traces of the sash will remain
194 // test with: splitter sample->replace right window
201 void wxSplitterWindow::OnInternalIdle()
203 wxWindow::OnInternalIdle();
205 // if this is the first idle time after a sash position has potentially
206 // been set, allow SizeWindows to check for a requested size.
207 if (!m_checkRequestedSashPosition
)
209 m_checkRequestedSashPosition
= true;
211 return; // it won't needUpdating in this case
218 void wxSplitterWindow::OnMouseEvent(wxMouseEvent
& event
)
220 int x
= (int)event
.GetX(),
221 y
= (int)event
.GetY();
223 if ( GetWindowStyle() & wxSP_NOSASH
)
229 bool isLive
= IsLive(this);
231 if (event
.LeftDown())
233 if ( SashHitTest(x
, y
) )
235 // Start the drag now
236 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
238 // Capture mouse and set the cursor
244 // remember the initial sash position and draw the initial
246 m_sashPositionCurrent
= m_sashPosition
;
248 m_oldX
= (m_splitMode
== wxSPLIT_VERTICAL
? m_sashPositionCurrent
: x
);
249 m_oldY
= (m_splitMode
!= wxSPLIT_VERTICAL
? m_sashPositionCurrent
: y
);
250 DrawSashTracker(m_oldX
, m_oldY
);
253 m_ptStart
= wxPoint(x
,y
);
254 m_sashStart
= m_sashPosition
;
258 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
260 // We can stop dragging now and see what we've got.
261 m_dragMode
= wxSPLIT_DRAG_NONE
;
263 // Release mouse and unset the cursor
265 SetCursor(* wxSTANDARD_CURSOR
);
267 // exit if unsplit after doubleclick
276 DrawSashTracker(m_oldX
, m_oldY
);
279 // the position of the click doesn't exactly correspond to
280 // m_sashPosition, rather it changes it by the distance by which the
282 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_ptStart
.x
: y
- m_ptStart
.y
;
284 int posSashNew
= OnSashPositionChanging(m_sashStart
+ diff
);
285 if ( posSashNew
== -1 )
287 // change not allowed
291 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
293 // Deal with possible unsplit scenarios
294 if ( posSashNew
== 0 )
296 // We remove the first window from the view
297 wxWindow
*removedWindow
= m_windowOne
;
298 m_windowOne
= m_windowTwo
;
300 OnUnsplit(removedWindow
);
301 wxSplitterEvent
eventUnsplit(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
302 eventUnsplit
.m_data
.win
= removedWindow
;
303 (void)DoSendEvent(eventUnsplit
);
304 SetSashPositionAndNotify(0);
306 else if ( posSashNew
== GetWindowSize() )
308 // We remove the second window from the view
309 wxWindow
*removedWindow
= m_windowTwo
;
311 OnUnsplit(removedWindow
);
312 wxSplitterEvent
eventUnsplit(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
313 eventUnsplit
.m_data
.win
= removedWindow
;
314 (void)DoSendEvent(eventUnsplit
);
315 SetSashPositionAndNotify(0);
319 SetSashPositionAndNotify(posSashNew
);
324 SetSashPositionAndNotify(posSashNew
);
328 } // left up && dragging
329 else if ((event
.Moving() || event
.Leaving() || event
.Entering()) && (m_dragMode
== wxSPLIT_DRAG_NONE
))
331 if ( event
.Leaving() || !SashHitTest(x
, y
) )
336 else if (event
.Dragging() && (m_dragMode
== wxSPLIT_DRAG_DRAGGING
))
338 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_ptStart
.x
: y
- m_ptStart
.y
;
340 int posSashNew
= OnSashPositionChanging(m_sashStart
+ diff
);
341 if ( posSashNew
== -1 )
343 // change not allowed
349 if ( posSashNew
== m_sashPositionCurrent
)
352 m_sashPositionCurrent
= posSashNew
;
355 DrawSashTracker(m_oldX
, m_oldY
);
357 m_oldX
= (m_splitMode
== wxSPLIT_VERTICAL
? m_sashPositionCurrent
: x
);
358 m_oldY
= (m_splitMode
!= wxSPLIT_VERTICAL
? m_sashPositionCurrent
: y
);
361 // As we captured the mouse, we may get the mouse events from outside
362 // our window - for example, negative values in x, y. This has a weird
363 // consequence under MSW where we use unsigned values sometimes and
364 // signed ones other times: the coordinates turn as big positive
365 // numbers and so the sash is drawn on the *right* side of the window
366 // instead of the left (or bottom instead of top). Correct this.
367 if ( (short)m_oldX
< 0 )
369 if ( (short)m_oldY
< 0 )
374 DrawSashTracker(m_oldX
, m_oldY
);
378 if ( posSashNew
== m_sashPosition
)
381 DoSetSashPosition(posSashNew
);
383 // in live mode, the new position is the actual sash position, clear requested position!
384 m_requestedSashPosition
= INT_MAX
;
385 m_needUpdating
= true;
388 else if ( event
.LeftDClick() && m_windowTwo
)
390 OnDoubleClickSash(x
, y
);
398 void wxSplitterWindow::OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
400 if (m_dragMode
!= wxSPLIT_DRAG_DRAGGING
)
403 m_dragMode
= wxSPLIT_DRAG_NONE
;
405 SetCursor(* wxSTANDARD_CURSOR
);
410 DrawSashTracker(m_oldX
, m_oldY
);
414 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
416 // only process this message if we're not iconized - otherwise iconizing
417 // and restoring a window containing the splitter has a funny side effect
418 // of changing the splitter position!
419 wxWindow
*parent
= wxGetTopLevelParent(this);
422 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
425 iconized
= winTop
->IsIconized();
429 wxFAIL_MSG(wxT("should have a top level parent!"));
436 m_lastSize
= wxSize(0,0);
446 GetClientSize(&w
, &h
);
448 int size
= m_splitMode
== wxSPLIT_VERTICAL
? w
: h
;
450 int old_size
= m_splitMode
== wxSPLIT_VERTICAL
? m_lastSize
.x
: m_lastSize
.y
;
453 int delta
= (int) ( (size
- old_size
)*m_sashGravity
);
456 int newPosition
= m_sashPosition
+ delta
;
457 if( newPosition
< m_minimumPaneSize
)
458 newPosition
= m_minimumPaneSize
;
459 SetSashPositionAndNotify(newPosition
);
463 if ( m_sashPosition
>= size
- 5 )
464 SetSashPositionAndNotify(wxMax(10, size
- 40));
465 m_lastSize
= wxSize(w
,h
);
471 void wxSplitterWindow::SetSashGravity(double gravity
)
473 wxCHECK_RET( gravity
>= 0. && gravity
<= 1.,
474 wxT("invalid gravity value") );
476 m_sashGravity
= gravity
;
479 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
481 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
482 return false; // No sash
484 int z
= m_splitMode
== wxSPLIT_VERTICAL
? x
: y
;
485 int hitMin
= m_sashPosition
- tolerance
;
486 int hitMax
= m_sashPosition
+ GetSashSize() + tolerance
;
488 return z
>= hitMin
&& z
<= hitMax
;
491 int wxSplitterWindow::GetSashSize() const
493 return wxRendererNative::Get().GetSplitterParams(this).widthSash
;
496 int wxSplitterWindow::GetBorderSize() const
498 return wxRendererNative::Get().GetSplitterParams(this).border
;
502 void wxSplitterWindow::DrawSash(wxDC
& dc
)
504 if (HasFlag(wxSP_3DBORDER
))
505 wxRendererNative::Get().DrawSplitterBorder
512 // don't draw sash if we're not split
513 if ( m_sashPosition
== 0 || !m_windowTwo
)
516 // nor if we're configured to not show it
517 if ( HasFlag(wxSP_NOSASH
) )
520 wxRendererNative::Get().DrawSplitterSash
526 m_splitMode
== wxSPLIT_VERTICAL
? wxVERTICAL
528 m_isHot
? (int)wxCONTROL_CURRENT
: 0
532 // Draw the sash tracker (for whilst moving the sash)
533 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
536 GetClientSize(&w
, &h
);
542 if ( m_splitMode
== wxSPLIT_VERTICAL
)
544 x1
= x2
= wxClip(x
, 0, w
) + m_sashTrackerPen
->GetWidth()/2;
550 y1
= y2
= wxClip(y
, 0, h
) + m_sashTrackerPen
->GetWidth()/2;
555 ClientToScreen(&x1
, &y1
);
556 ClientToScreen(&x2
, &y2
);
558 screenDC
.SetLogicalFunction(wxINVERT
);
559 screenDC
.SetPen(*m_sashTrackerPen
);
560 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
562 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
564 screenDC
.SetLogicalFunction(wxCOPY
);
567 int wxSplitterWindow::GetWindowSize() const
569 wxSize size
= GetClientSize();
571 return m_splitMode
== wxSPLIT_VERTICAL
? size
.x
: size
.y
;
574 int wxSplitterWindow::AdjustSashPosition(int sashPos
) const
581 // the window shouldn't be smaller than its own minimal size nor
582 // smaller than the minimual pane size specified for this splitter
583 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
584 : win
->GetMinHeight();
586 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
587 minSize
= m_minimumPaneSize
;
589 minSize
+= GetBorderSize();
591 if ( sashPos
< minSize
)
598 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
599 : win
->GetMinHeight();
601 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
602 minSize
= m_minimumPaneSize
;
604 int maxSize
= GetWindowSize() - minSize
- GetBorderSize() - GetSashSize();
605 if ( maxSize
> 0 && sashPos
> maxSize
&& maxSize
>= m_minimumPaneSize
)
612 bool wxSplitterWindow::DoSetSashPosition(int sashPos
)
614 int newSashPosition
= AdjustSashPosition(sashPos
);
616 if ( newSashPosition
== m_sashPosition
)
619 m_sashPosition
= newSashPosition
;
624 void wxSplitterWindow::SetSashPositionAndNotify(int sashPos
)
626 // we must reset the request here, otherwise the sash would be stuck at
627 // old position if the user attempted to move the sash after invalid
628 // (e.g. smaller than minsize) sash position was requested using
629 // SetSashPosition():
630 m_requestedSashPosition
= INT_MAX
;
632 // note that we must send the event in any case, i.e. even if the sash
633 // position hasn't changed and DoSetSashPosition() returns false because we
634 // must generate a CHANGED event at the end of resizing
635 DoSetSashPosition(sashPos
);
637 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
, this);
638 event
.m_data
.pos
= m_sashPosition
;
640 (void)DoSendEvent(event
);
643 // Position and size subwindows.
644 // Note that the border size applies to each subwindow, not
645 // including the edges next to the sash.
646 void wxSplitterWindow::SizeWindows()
648 // check if we have delayed setting the real sash position
649 if ( m_checkRequestedSashPosition
&& m_requestedSashPosition
!= INT_MAX
)
651 int newSashPosition
= ConvertSashPosition(m_requestedSashPosition
);
652 if ( newSashPosition
!= m_sashPosition
)
654 DoSetSashPosition(newSashPosition
);
657 if ( newSashPosition
<= m_sashPosition
658 && newSashPosition
>= m_sashPosition
- GetBorderSize() )
660 // don't update it any more
661 m_requestedSashPosition
= INT_MAX
;
666 GetClientSize(&w
, &h
);
668 if ( GetWindow1() && !GetWindow2() )
670 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
671 w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
673 else if ( GetWindow1() && GetWindow2() )
675 const int border
= GetBorderSize(),
676 sash
= GetSashSize();
678 int size1
= GetSashPosition() - border
,
679 size2
= GetSashPosition() + sash
;
681 int x2
, y2
, w1
, h1
, w2
, h2
;
682 if ( GetSplitMode() == wxSPLIT_VERTICAL
)
685 w2
= w
- 2*border
- sash
- w1
;
695 else // horz splitter
702 h2
= h
- 2*border
- sash
- h1
;
709 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
710 GetWindow1()->SetSize(border
, border
, w1
, h1
);
716 SetNeedUpdating(false);
719 // Set pane for unsplit window
720 void wxSplitterWindow::Initialize(wxWindow
*window
)
722 wxASSERT_MSG( (!window
|| window
->GetParent() == this),
723 wxT("windows in the splitter should have it as parent!") );
725 if (window
&& !window
->IsShown())
728 m_windowOne
= window
;
730 DoSetSashPosition(0);
733 // Associates the given window with window 2, drawing the appropriate sash
734 // and changing the split mode.
735 // Does nothing and returns false if the window is already split.
736 bool wxSplitterWindow::DoSplit(wxSplitMode mode
,
737 wxWindow
*window1
, wxWindow
*window2
,
743 wxCHECK_MSG( window1
&& window2
, false,
744 wxT("can not split with NULL window(s)") );
746 wxCHECK_MSG( window1
->GetParent() == this && window2
->GetParent() == this, false,
747 wxT("windows in the splitter should have it as parent!") );
749 if (! window1
->IsShown())
751 if (! window2
->IsShown())
755 m_windowOne
= window1
;
756 m_windowTwo
= window2
;
759 SetSashPosition(sashPosition
, true);
763 int wxSplitterWindow::ConvertSashPosition(int sashPosition
) const
765 if ( sashPosition
> 0 )
769 else if ( sashPosition
< 0 )
771 // It's negative so adding is subtracting
772 return GetWindowSize() + sashPosition
;
774 else // sashPosition == 0
776 // default, put it in the centre
777 return GetWindowSize() / 2;
781 // Remove the specified (or second) window from the view
782 // Doesn't actually delete the window.
783 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
789 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
794 else if ( toRemove
== m_windowOne
)
797 m_windowOne
= m_windowTwo
;
802 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
808 DoSetSashPosition(0);
814 // Replace a window with another one
815 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
817 wxCHECK_MSG( winOld
, false, wxT("use one of Split() functions instead") );
818 wxCHECK_MSG( winNew
, false, wxT("use Unsplit() functions instead") );
820 if ( winOld
== m_windowTwo
)
822 m_windowTwo
= winNew
;
824 else if ( winOld
== m_windowOne
)
826 m_windowOne
= winNew
;
830 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
840 void wxSplitterWindow::SetMinimumPaneSize(int min
)
842 m_minimumPaneSize
= min
;
843 int pos
= m_requestedSashPosition
!= INT_MAX
? m_requestedSashPosition
: m_sashPosition
;
844 SetSashPosition(pos
); // re-check limits
847 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
849 // remember the sash position we want to set for later if we can't set it
850 // right now (e.g. because the window is too small)
851 m_requestedSashPosition
= position
;
852 m_checkRequestedSashPosition
= false;
854 DoSetSashPosition(ConvertSashPosition(position
));
862 // Make sure the child window sizes are updated. This is useful
863 // for reducing flicker by updating the sizes before a
864 // window is shown, if you know the overall size is correct.
865 void wxSplitterWindow::UpdateSize()
867 m_checkRequestedSashPosition
= true;
869 m_checkRequestedSashPosition
= false;
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