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
;
121 m_sashPosition
= m_requestedSashPosition
= 0;
123 m_lastSize
= wxSize(0,0);
124 m_checkRequestedSashPosition
= false;
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 // if this is the first idle time after a sash position has potentially
197 // been set, allow SizeWindows to check for a requested size.
198 if (!m_checkRequestedSashPosition
)
200 m_checkRequestedSashPosition
= true;
202 return; // it won't needUpdating in this case
209 void wxSplitterWindow::OnMouseEvent(wxMouseEvent
& event
)
211 int x
= (int)event
.GetX(),
212 y
= (int)event
.GetY();
214 if ( GetWindowStyle() & wxSP_NOSASH
)
220 bool isLive
= IsLive(this);
222 if (event
.LeftDown())
224 if ( SashHitTest(x
, y
) )
226 // Start the drag now
227 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
229 // Capture mouse and set the cursor
235 // remember the initial sash position and draw the initial
237 m_sashPositionCurrent
= m_sashPosition
;
239 m_oldX
= (m_splitMode
== wxSPLIT_VERTICAL
? m_sashPositionCurrent
: x
);
240 m_oldY
= (m_splitMode
!= wxSPLIT_VERTICAL
? m_sashPositionCurrent
: y
);
241 DrawSashTracker(m_oldX
, m_oldY
);
244 m_ptStart
= wxPoint(x
,y
);
245 m_sashStart
= m_sashPosition
;
249 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
251 // We can stop dragging now and see what we've got.
252 m_dragMode
= wxSPLIT_DRAG_NONE
;
254 // Release mouse and unset the cursor
256 SetCursor(* wxSTANDARD_CURSOR
);
258 // exit if unsplit after doubleclick
267 DrawSashTracker(m_oldX
, m_oldY
);
270 // the position of the click doesn't exactly correspond to
271 // m_sashPosition, rather it changes it by the distance by which the
273 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_ptStart
.x
: y
- m_ptStart
.y
;
275 int posSashNew
= OnSashPositionChanging(m_sashStart
+ 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
;
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
;
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_ptStart
.x
: y
- m_ptStart
.y
;
331 int posSashNew
= OnSashPositionChanging(m_sashStart
+ diff
);
332 if ( posSashNew
== -1 )
334 // change not allowed
340 if ( posSashNew
== m_sashPositionCurrent
)
343 m_sashPositionCurrent
= posSashNew
;
346 DrawSashTracker(m_oldX
, m_oldY
);
348 m_oldX
= (m_splitMode
== wxSPLIT_VERTICAL
? m_sashPositionCurrent
: x
);
349 m_oldY
= (m_splitMode
!= wxSPLIT_VERTICAL
? m_sashPositionCurrent
: y
);
352 // As we captured the mouse, we may get the mouse events from outside
353 // our window - for example, negative values in x, y. This has a weird
354 // consequence under MSW where we use unsigned values sometimes and
355 // signed ones other times: the coordinates turn as big positive
356 // numbers and so the sash is drawn on the *right* side of the window
357 // instead of the left (or bottom instead of top). Correct this.
358 if ( (short)m_oldX
< 0 )
360 if ( (short)m_oldY
< 0 )
365 DrawSashTracker(m_oldX
, m_oldY
);
369 if ( posSashNew
== m_sashPosition
)
372 DoSetSashPosition(posSashNew
);
374 // in live mode, the new position is the actual sash position, clear requested position!
375 m_requestedSashPosition
= INT_MAX
;
376 m_needUpdating
= true;
379 else if ( event
.LeftDClick() && m_windowTwo
)
381 OnDoubleClickSash(x
, y
);
389 void wxSplitterWindow::OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
391 if (m_dragMode
!= wxSPLIT_DRAG_DRAGGING
)
394 m_dragMode
= wxSPLIT_DRAG_NONE
;
396 SetCursor(* wxSTANDARD_CURSOR
);
401 DrawSashTracker(m_oldX
, m_oldY
);
405 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
407 // only process this message if we're not iconized - otherwise iconizing
408 // and restoring a window containing the splitter has a funny side effect
409 // of changing the splitter position!
410 wxWindow
*parent
= wxGetTopLevelParent(this);
413 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
416 iconized
= winTop
->IsIconized();
420 wxFAIL_MSG(wxT("should have a top level parent!"));
427 m_lastSize
= wxSize(0,0);
437 GetClientSize(&w
, &h
);
439 int size
= m_splitMode
== wxSPLIT_VERTICAL
? w
: h
;
441 int old_size
= m_splitMode
== wxSPLIT_VERTICAL
? m_lastSize
.x
: m_lastSize
.y
;
443 // Don't do anything if the size didn't really change. In particular,
444 // it is important that we don't reset our sash position because it's
445 // out of current range in this case as otherwise the really requested
446 // position would be lost and never set. Wait until we get a real size
447 // event with our non-initial size to do it.
448 if ( size
!= old_size
)
450 int delta
= (int) ( (size
- old_size
)*m_sashGravity
);
453 int newPosition
= m_sashPosition
+ delta
;
454 if( newPosition
< m_minimumPaneSize
)
455 newPosition
= m_minimumPaneSize
;
456 SetSashPositionAndNotify(newPosition
);
459 if ( m_sashPosition
>= size
- 5 )
460 SetSashPositionAndNotify(wxMax(10, size
- 40));
461 m_lastSize
= wxSize(w
,h
);
468 void wxSplitterWindow::SetSashGravity(double gravity
)
470 wxCHECK_RET( gravity
>= 0. && gravity
<= 1.,
471 wxT("invalid gravity value") );
473 m_sashGravity
= gravity
;
476 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
478 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
479 return false; // No sash
481 int z
= m_splitMode
== wxSPLIT_VERTICAL
? x
: y
;
482 int hitMin
= m_sashPosition
- tolerance
;
483 int hitMax
= m_sashPosition
+ GetSashSize() + tolerance
;
485 return z
>= hitMin
&& z
<= hitMax
;
488 int wxSplitterWindow::GetSashSize() const
490 return wxRendererNative::Get().GetSplitterParams(this).widthSash
;
493 int wxSplitterWindow::GetBorderSize() const
495 return wxRendererNative::Get().GetSplitterParams(this).border
;
499 void wxSplitterWindow::DrawSash(wxDC
& dc
)
501 if (HasFlag(wxSP_3DBORDER
))
502 wxRendererNative::Get().DrawSplitterBorder
509 // don't draw sash if we're not split
510 if ( m_sashPosition
== 0 || !m_windowTwo
)
513 // nor if we're configured to not show it
514 if ( HasFlag(wxSP_NOSASH
) )
517 wxRendererNative::Get().DrawSplitterSash
523 m_splitMode
== wxSPLIT_VERTICAL
? wxVERTICAL
525 m_isHot
? (int)wxCONTROL_CURRENT
: 0
529 // Draw the sash tracker (for whilst moving the sash)
530 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
533 GetClientSize(&w
, &h
);
539 if ( m_splitMode
== wxSPLIT_VERTICAL
)
541 x1
= x2
= wxClip(x
, 0, w
) + m_sashTrackerPen
->GetWidth()/2;
547 y1
= y2
= wxClip(y
, 0, h
) + m_sashTrackerPen
->GetWidth()/2;
552 ClientToScreen(&x1
, &y1
);
553 ClientToScreen(&x2
, &y2
);
555 screenDC
.SetLogicalFunction(wxINVERT
);
556 screenDC
.SetPen(*m_sashTrackerPen
);
557 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
559 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
561 screenDC
.SetLogicalFunction(wxCOPY
);
564 int wxSplitterWindow::GetWindowSize() const
566 wxSize size
= GetClientSize();
568 return m_splitMode
== wxSPLIT_VERTICAL
? size
.x
: size
.y
;
571 int wxSplitterWindow::AdjustSashPosition(int sashPos
) const
578 // the window shouldn't be smaller than its own minimal size nor
579 // smaller than the minimual pane size specified for this splitter
580 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
581 : win
->GetMinHeight();
583 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
584 minSize
= m_minimumPaneSize
;
586 minSize
+= GetBorderSize();
588 if ( sashPos
< minSize
)
595 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
596 : win
->GetMinHeight();
598 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
599 minSize
= m_minimumPaneSize
;
601 int maxSize
= GetWindowSize() - minSize
- GetBorderSize() - GetSashSize();
602 if ( maxSize
> 0 && sashPos
> maxSize
&& maxSize
>= m_minimumPaneSize
)
609 bool wxSplitterWindow::DoSetSashPosition(int sashPos
)
611 int newSashPosition
= AdjustSashPosition(sashPos
);
613 if ( newSashPosition
== m_sashPosition
)
616 m_sashPosition
= newSashPosition
;
621 void wxSplitterWindow::SetSashPositionAndNotify(int sashPos
)
623 // we must reset the request here, otherwise the sash would be stuck at
624 // old position if the user attempted to move the sash after invalid
625 // (e.g. smaller than minsize) sash position was requested using
626 // SetSashPosition():
627 m_requestedSashPosition
= INT_MAX
;
629 // note that we must send the event in any case, i.e. even if the sash
630 // position hasn't changed and DoSetSashPosition() returns false because we
631 // must generate a CHANGED event at the end of resizing
632 DoSetSashPosition(sashPos
);
634 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
, this);
635 event
.m_data
.pos
= m_sashPosition
;
637 (void)DoSendEvent(event
);
640 // Position and size subwindows.
641 // Note that the border size applies to each subwindow, not
642 // including the edges next to the sash.
643 void wxSplitterWindow::SizeWindows()
645 // check if we have delayed setting the real sash position
646 if ( m_checkRequestedSashPosition
&& m_requestedSashPosition
!= INT_MAX
)
648 int newSashPosition
= ConvertSashPosition(m_requestedSashPosition
);
649 if ( newSashPosition
!= m_sashPosition
)
651 DoSetSashPosition(newSashPosition
);
654 if ( newSashPosition
<= m_sashPosition
655 && newSashPosition
>= m_sashPosition
- GetBorderSize() )
657 // don't update it any more
658 m_requestedSashPosition
= INT_MAX
;
663 GetClientSize(&w
, &h
);
665 if ( GetWindow1() && !GetWindow2() )
667 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
668 w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
670 else if ( GetWindow1() && GetWindow2() )
672 const int border
= GetBorderSize(),
673 sash
= GetSashSize();
675 int size1
= GetSashPosition() - border
,
676 size2
= GetSashPosition() + sash
;
678 int x2
, y2
, w1
, h1
, w2
, h2
;
679 if ( GetSplitMode() == wxSPLIT_VERTICAL
)
682 w2
= w
- 2*border
- sash
- w1
;
692 else // horz splitter
699 h2
= h
- 2*border
- sash
- h1
;
706 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
707 GetWindow1()->SetSize(border
, border
, w1
, h1
);
713 SetNeedUpdating(false);
716 // Set pane for unsplit window
717 void wxSplitterWindow::Initialize(wxWindow
*window
)
719 wxASSERT_MSG( (!window
|| window
->GetParent() == this),
720 wxT("windows in the splitter should have it as parent!") );
722 if (window
&& !window
->IsShown())
725 m_windowOne
= window
;
727 DoSetSashPosition(0);
730 // Associates the given window with window 2, drawing the appropriate sash
731 // and changing the split mode.
732 // Does nothing and returns false if the window is already split.
733 bool wxSplitterWindow::DoSplit(wxSplitMode mode
,
734 wxWindow
*window1
, wxWindow
*window2
,
740 wxCHECK_MSG( window1
&& window2
, false,
741 wxT("cannot split with NULL window(s)") );
743 wxCHECK_MSG( window1
->GetParent() == this && window2
->GetParent() == this, false,
744 wxT("windows in the splitter should have it as parent!") );
746 if (! window1
->IsShown())
748 if (! window2
->IsShown())
752 m_windowOne
= window1
;
753 m_windowTwo
= window2
;
756 SetSashPosition(sashPosition
, true);
760 int wxSplitterWindow::ConvertSashPosition(int sashPosition
) const
762 if ( sashPosition
> 0 )
766 else if ( sashPosition
< 0 )
768 // It's negative so adding is subtracting
769 return GetWindowSize() + sashPosition
;
771 else // sashPosition == 0
773 // default, put it in the centre
774 return GetWindowSize() / 2;
778 // Remove the specified (or second) window from the view
779 // Doesn't actually delete the window.
780 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
786 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
791 else if ( toRemove
== m_windowOne
)
794 m_windowOne
= m_windowTwo
;
799 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
805 DoSetSashPosition(0);
811 // Replace a window with another one
812 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
814 wxCHECK_MSG( winOld
, false, wxT("use one of Split() functions instead") );
815 wxCHECK_MSG( winNew
, false, wxT("use Unsplit() functions instead") );
817 if ( winOld
== m_windowTwo
)
819 m_windowTwo
= winNew
;
821 else if ( winOld
== m_windowOne
)
823 m_windowOne
= winNew
;
827 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
837 void wxSplitterWindow::SetMinimumPaneSize(int min
)
839 m_minimumPaneSize
= min
;
840 int pos
= m_requestedSashPosition
!= INT_MAX
? m_requestedSashPosition
: m_sashPosition
;
841 SetSashPosition(pos
); // re-check limits
844 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
846 // remember the sash position we want to set for later if we can't set it
847 // right now (e.g. because the window is too small)
848 m_requestedSashPosition
= position
;
849 m_checkRequestedSashPosition
= false;
851 DoSetSashPosition(ConvertSashPosition(position
));
859 // Make sure the child window sizes are updated. This is useful
860 // for reducing flicker by updating the sizes before a
861 // window is shown, if you know the overall size is correct.
862 void wxSplitterWindow::UpdateSize()
864 m_checkRequestedSashPosition
= true;
866 m_checkRequestedSashPosition
= false;
869 bool wxSplitterWindow::DoSendEvent(wxSplitterEvent
& event
)
871 return !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed();
874 wxSize
wxSplitterWindow::DoGetBestSize() const
876 // get best sizes of subwindows
879 size1
= m_windowOne
->GetEffectiveMinSize();
881 size2
= m_windowTwo
->GetEffectiveMinSize();
885 // pSash points to the size component to which sash size must be added
888 if ( m_splitMode
== wxSPLIT_VERTICAL
)
890 sizeBest
.y
= wxMax(size1
.y
, size2
.y
);
891 sizeBest
.x
= wxMax(size1
.x
, m_minimumPaneSize
) +
892 wxMax(size2
.x
, m_minimumPaneSize
);
896 else // wxSPLIT_HORIZONTAL
898 sizeBest
.x
= wxMax(size1
.x
, size2
.x
);
899 sizeBest
.y
= wxMax(size1
.y
, m_minimumPaneSize
) +
900 wxMax(size2
.y
, m_minimumPaneSize
);
905 // account for the sash if the window is actually split
906 if ( m_windowOne
&& m_windowTwo
)
907 *pSash
+= GetSashSize();
909 // account for the border too
910 int border
= 2*GetBorderSize();
911 sizeBest
.x
+= border
;
912 sizeBest
.y
+= border
;
917 // ---------------------------------------------------------------------------
918 // wxSplitterWindow virtual functions: they now just generate the events
919 // ---------------------------------------------------------------------------
921 bool wxSplitterWindow::OnSashPositionChange(int WXUNUSED(newSashPosition
))
923 // always allow by default
927 int wxSplitterWindow::OnSashPositionChanging(int newSashPosition
)
929 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
930 const int UNSPLIT_THRESHOLD
= 4;
932 // first of all, check if OnSashPositionChange() doesn't forbid this change
933 if ( !OnSashPositionChange(newSashPosition
) )
939 // Obtain relevant window dimension for bottom / right threshold check
940 int window_size
= GetWindowSize();
942 bool unsplit_scenario
= false;
943 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
945 // Do edge detection if unsplit premitted
946 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
948 // threshold top / left check
950 unsplit_scenario
= true;
952 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
954 // threshold bottom/right check
955 newSashPosition
= window_size
;
956 unsplit_scenario
= true;
960 if ( !unsplit_scenario
)
962 // If resultant pane would be too small, enlarge it
963 newSashPosition
= AdjustSashPosition(newSashPosition
);
965 // If the result is out of bounds it means minimum size is too big,
966 // so split window in half as best compromise.
967 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
968 newSashPosition
= window_size
/ 2;
971 // now let the event handler have it
973 // FIXME: shouldn't we do it before the adjustments above so as to ensure
974 // that the sash position is always reasonable?
975 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
, this);
976 event
.m_data
.pos
= newSashPosition
;
978 if ( !DoSendEvent(event
) )
980 // the event handler vetoed the change
981 newSashPosition
= -1;
985 // it could have been changed by it
986 newSashPosition
= event
.GetSashPosition();
989 return newSashPosition
;
992 // Called when the sash is double-clicked. The default behaviour is to remove
993 // the sash if the minimum pane size is zero.
994 void wxSplitterWindow::OnDoubleClickSash(int x
, int y
)
996 wxCHECK_RET(m_windowTwo
, wxT("splitter: no window to remove"));
998 // new code should handle events instead of using the virtual functions
999 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
, this);
1000 event
.m_data
.pt
.x
= x
;
1001 event
.m_data
.pt
.y
= y
;
1002 if ( DoSendEvent(event
) )
1004 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
1006 wxWindow
* win
= m_windowTwo
;
1009 wxSplitterEvent
unsplitEvent(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
1010 unsplitEvent
.m_data
.win
= win
;
1011 (void)DoSendEvent(unsplitEvent
);
1015 //else: blocked by user
1018 void wxSplitterWindow::OnUnsplit(wxWindow
*winRemoved
)
1020 // call this before calling the event handler which may delete the window
1021 winRemoved
->Show(false);
1024 #if defined( __WXMSW__ ) || defined( __WXMAC__)
1026 // this is currently called (and needed) under MSW only...
1027 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& event
)
1029 // if we don't do it, the resizing cursor might be set for child window:
1030 // and like this we explicitly say that our cursor should not be used for
1031 // children windows which overlap us
1033 if ( SashHitTest(event
.GetX(), event
.GetY(), 0) )
1035 // default processing is ok
1038 //else: do nothing, in particular, don't call Skip()
1041 #endif // wxMSW || wxMac
1043 #endif // wxUSE_SPLITTER