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
) )
97 m_lastSize
.x
= size
.x
;
99 m_lastSize
.y
= size
.y
;
101 m_permitUnsplitAlways
= (style
& wxSP_PERMIT_UNSPLIT
) != 0;
103 // FIXME: with this line the background is not erased at all under GTK1,
104 // so temporary avoid it there
105 #if !defined(__WXGTK__) || defined(__WXGTK20__)
106 // don't erase the splitter background, it's pointless as we overwrite it
108 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
114 void wxSplitterWindow::Init()
116 m_splitMode
= wxSPLIT_VERTICAL
;
117 m_permitUnsplitAlways
= true;
120 m_dragMode
= wxSPLIT_DRAG_NONE
;
124 m_sashPosition
= m_requestedSashPosition
= 0;
126 m_lastSize
= wxSize(0,0);
127 m_checkRequestedSashPosition
= false;
128 m_minimumPaneSize
= 0;
129 m_sashCursorWE
= wxCursor(wxCURSOR_SIZEWE
);
130 m_sashCursorNS
= wxCursor(wxCURSOR_SIZENS
);
131 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxPENSTYLE_SOLID
);
133 m_needUpdating
= false;
137 wxSplitterWindow::~wxSplitterWindow()
139 delete m_sashTrackerPen
;
142 // ----------------------------------------------------------------------------
143 // entering/leaving sash
144 // ----------------------------------------------------------------------------
146 void wxSplitterWindow::RedrawIfHotSensitive(bool isHot
)
148 if ( wxRendererNative::Get().GetSplitterParams(this).isHotSensitive
)
155 //else: we don't change our appearance, don't redraw to avoid flicker
158 void wxSplitterWindow::OnEnterSash()
162 RedrawIfHotSensitive(true);
165 void wxSplitterWindow::OnLeaveSash()
167 SetCursor(*wxSTANDARD_CURSOR
);
169 RedrawIfHotSensitive(false);
172 void wxSplitterWindow::SetResizeCursor()
174 SetCursor(m_splitMode
== wxSPLIT_VERTICAL
? m_sashCursorWE
178 // ----------------------------------------------------------------------------
179 // other event handlers
180 // ----------------------------------------------------------------------------
182 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
186 // as subpanels might have a transparent background we must erase the background
187 // at least on OSX, otherwise traces of the sash will remain
188 // test with: splitter sample->replace right window
195 void wxSplitterWindow::OnInternalIdle()
197 wxWindow::OnInternalIdle();
199 // if this is the first idle time after a sash position has potentially
200 // been set, allow SizeWindows to check for a requested size.
201 if (!m_checkRequestedSashPosition
)
203 m_checkRequestedSashPosition
= true;
205 return; // it won't needUpdating in this case
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_COMMAND_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_COMMAND_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);
440 GetClientSize(&w
, &h
);
442 int size
= m_splitMode
== wxSPLIT_VERTICAL
? w
: h
;
444 int old_size
= m_splitMode
== wxSPLIT_VERTICAL
? m_lastSize
.x
: m_lastSize
.y
;
447 int delta
= (int) ( (size
- old_size
)*m_sashGravity
);
450 int newPosition
= m_sashPosition
+ delta
;
451 if( newPosition
< m_minimumPaneSize
)
452 newPosition
= m_minimumPaneSize
;
453 SetSashPositionAndNotify(newPosition
);
457 if ( m_sashPosition
>= size
- 5 )
458 SetSashPositionAndNotify(wxMax(10, size
- 40));
459 m_lastSize
= wxSize(w
,h
);
465 void wxSplitterWindow::SetSashGravity(double gravity
)
467 wxCHECK_RET( gravity
>= 0. && gravity
<= 1.,
468 wxT("invalid gravity value") );
470 m_sashGravity
= gravity
;
473 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
475 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
476 return false; // No sash
478 int z
= m_splitMode
== wxSPLIT_VERTICAL
? x
: y
;
479 int hitMin
= m_sashPosition
- tolerance
;
480 int hitMax
= m_sashPosition
+ GetSashSize() + tolerance
;
482 return z
>= hitMin
&& z
<= hitMax
;
485 int wxSplitterWindow::GetSashSize() const
487 return wxRendererNative::Get().GetSplitterParams(this).widthSash
;
490 int wxSplitterWindow::GetBorderSize() const
492 return wxRendererNative::Get().GetSplitterParams(this).border
;
496 void wxSplitterWindow::DrawSash(wxDC
& dc
)
498 if (HasFlag(wxSP_3DBORDER
))
499 wxRendererNative::Get().DrawSplitterBorder
506 // don't draw sash if we're not split
507 if ( m_sashPosition
== 0 || !m_windowTwo
)
510 // nor if we're configured to not show it
511 if ( HasFlag(wxSP_NOSASH
) )
514 wxRendererNative::Get().DrawSplitterSash
520 m_splitMode
== wxSPLIT_VERTICAL
? wxVERTICAL
522 m_isHot
? (int)wxCONTROL_CURRENT
: 0
526 // Draw the sash tracker (for whilst moving the sash)
527 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
530 GetClientSize(&w
, &h
);
536 if ( m_splitMode
== wxSPLIT_VERTICAL
)
538 x1
= x2
= wxClip(x
, 0, w
) + m_sashTrackerPen
->GetWidth()/2;
544 y1
= y2
= wxClip(y
, 0, h
) + m_sashTrackerPen
->GetWidth()/2;
549 ClientToScreen(&x1
, &y1
);
550 ClientToScreen(&x2
, &y2
);
552 screenDC
.SetLogicalFunction(wxINVERT
);
553 screenDC
.SetPen(*m_sashTrackerPen
);
554 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
556 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
558 screenDC
.SetLogicalFunction(wxCOPY
);
561 int wxSplitterWindow::GetWindowSize() const
563 wxSize size
= GetClientSize();
565 return m_splitMode
== wxSPLIT_VERTICAL
? size
.x
: size
.y
;
568 int wxSplitterWindow::AdjustSashPosition(int sashPos
) const
575 // the window shouldn't be smaller than its own minimal size nor
576 // smaller than the minimual pane size specified for this splitter
577 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
578 : win
->GetMinHeight();
580 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
581 minSize
= m_minimumPaneSize
;
583 minSize
+= GetBorderSize();
585 if ( sashPos
< minSize
)
592 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
593 : win
->GetMinHeight();
595 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
596 minSize
= m_minimumPaneSize
;
598 int maxSize
= GetWindowSize() - minSize
- GetBorderSize() - GetSashSize();
599 if ( maxSize
> 0 && sashPos
> maxSize
&& maxSize
>= m_minimumPaneSize
)
606 bool wxSplitterWindow::DoSetSashPosition(int sashPos
)
608 int newSashPosition
= AdjustSashPosition(sashPos
);
610 if ( newSashPosition
== m_sashPosition
)
613 m_sashPosition
= newSashPosition
;
618 void wxSplitterWindow::SetSashPositionAndNotify(int sashPos
)
620 // we must reset the request here, otherwise the sash would be stuck at
621 // old position if the user attempted to move the sash after invalid
622 // (e.g. smaller than minsize) sash position was requested using
623 // SetSashPosition():
624 m_requestedSashPosition
= INT_MAX
;
626 // note that we must send the event in any case, i.e. even if the sash
627 // position hasn't changed and DoSetSashPosition() returns false because we
628 // must generate a CHANGED event at the end of resizing
629 DoSetSashPosition(sashPos
);
631 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
, this);
632 event
.m_data
.pos
= m_sashPosition
;
634 (void)DoSendEvent(event
);
637 // Position and size subwindows.
638 // Note that the border size applies to each subwindow, not
639 // including the edges next to the sash.
640 void wxSplitterWindow::SizeWindows()
642 // check if we have delayed setting the real sash position
643 if ( m_checkRequestedSashPosition
&& m_requestedSashPosition
!= INT_MAX
)
645 int newSashPosition
= ConvertSashPosition(m_requestedSashPosition
);
646 if ( newSashPosition
!= m_sashPosition
)
648 DoSetSashPosition(newSashPosition
);
651 if ( newSashPosition
<= m_sashPosition
652 && newSashPosition
>= m_sashPosition
- GetBorderSize() )
654 // don't update it any more
655 m_requestedSashPosition
= INT_MAX
;
660 GetClientSize(&w
, &h
);
662 if ( GetWindow1() && !GetWindow2() )
664 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
665 w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
667 else if ( GetWindow1() && GetWindow2() )
669 const int border
= GetBorderSize(),
670 sash
= GetSashSize();
672 int size1
= GetSashPosition() - border
,
673 size2
= GetSashPosition() + sash
;
675 int x2
, y2
, w1
, h1
, w2
, h2
;
676 if ( GetSplitMode() == wxSPLIT_VERTICAL
)
679 w2
= w
- 2*border
- sash
- w1
;
689 else // horz splitter
696 h2
= h
- 2*border
- sash
- h1
;
703 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
704 GetWindow1()->SetSize(border
, border
, w1
, h1
);
710 SetNeedUpdating(false);
713 // Set pane for unsplit window
714 void wxSplitterWindow::Initialize(wxWindow
*window
)
716 wxASSERT_MSG( (!window
|| window
->GetParent() == this),
717 wxT("windows in the splitter should have it as parent!") );
719 if (window
&& !window
->IsShown())
722 m_windowOne
= window
;
724 DoSetSashPosition(0);
727 // Associates the given window with window 2, drawing the appropriate sash
728 // and changing the split mode.
729 // Does nothing and returns false if the window is already split.
730 bool wxSplitterWindow::DoSplit(wxSplitMode mode
,
731 wxWindow
*window1
, wxWindow
*window2
,
737 wxCHECK_MSG( window1
&& window2
, false,
738 wxT("cannot split with NULL window(s)") );
740 wxCHECK_MSG( window1
->GetParent() == this && window2
->GetParent() == this, false,
741 wxT("windows in the splitter should have it as parent!") );
743 if (! window1
->IsShown())
745 if (! window2
->IsShown())
749 m_windowOne
= window1
;
750 m_windowTwo
= window2
;
753 SetSashPosition(sashPosition
, true);
757 int wxSplitterWindow::ConvertSashPosition(int sashPosition
) const
759 if ( sashPosition
> 0 )
763 else if ( sashPosition
< 0 )
765 // It's negative so adding is subtracting
766 return GetWindowSize() + sashPosition
;
768 else // sashPosition == 0
770 // default, put it in the centre
771 return GetWindowSize() / 2;
775 // Remove the specified (or second) window from the view
776 // Doesn't actually delete the window.
777 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
783 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
788 else if ( toRemove
== m_windowOne
)
791 m_windowOne
= m_windowTwo
;
796 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
802 DoSetSashPosition(0);
808 // Replace a window with another one
809 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
811 wxCHECK_MSG( winOld
, false, wxT("use one of Split() functions instead") );
812 wxCHECK_MSG( winNew
, false, wxT("use Unsplit() functions instead") );
814 if ( winOld
== m_windowTwo
)
816 m_windowTwo
= winNew
;
818 else if ( winOld
== m_windowOne
)
820 m_windowOne
= winNew
;
824 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
834 void wxSplitterWindow::SetMinimumPaneSize(int min
)
836 m_minimumPaneSize
= min
;
837 int pos
= m_requestedSashPosition
!= INT_MAX
? m_requestedSashPosition
: m_sashPosition
;
838 SetSashPosition(pos
); // re-check limits
841 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
843 // remember the sash position we want to set for later if we can't set it
844 // right now (e.g. because the window is too small)
845 m_requestedSashPosition
= position
;
846 m_checkRequestedSashPosition
= false;
848 DoSetSashPosition(ConvertSashPosition(position
));
856 // Make sure the child window sizes are updated. This is useful
857 // for reducing flicker by updating the sizes before a
858 // window is shown, if you know the overall size is correct.
859 void wxSplitterWindow::UpdateSize()
861 m_checkRequestedSashPosition
= true;
863 m_checkRequestedSashPosition
= false;
866 bool wxSplitterWindow::DoSendEvent(wxSplitterEvent
& event
)
868 return !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed();
871 wxSize
wxSplitterWindow::DoGetBestSize() const
873 // get best sizes of subwindows
876 size1
= m_windowOne
->GetEffectiveMinSize();
878 size2
= m_windowTwo
->GetEffectiveMinSize();
882 // pSash points to the size component to which sash size must be added
885 if ( m_splitMode
== wxSPLIT_VERTICAL
)
887 sizeBest
.y
= wxMax(size1
.y
, size2
.y
);
888 sizeBest
.x
= wxMax(size1
.x
, m_minimumPaneSize
) +
889 wxMax(size2
.x
, m_minimumPaneSize
);
893 else // wxSPLIT_HORIZONTAL
895 sizeBest
.x
= wxMax(size1
.x
, size2
.x
);
896 sizeBest
.y
= wxMax(size1
.y
, m_minimumPaneSize
) +
897 wxMax(size2
.y
, m_minimumPaneSize
);
902 // account for the sash if the window is actually split
903 if ( m_windowOne
&& m_windowTwo
)
904 *pSash
+= GetSashSize();
906 // account for the border too
907 int border
= 2*GetBorderSize();
908 sizeBest
.x
+= border
;
909 sizeBest
.y
+= border
;
914 // ---------------------------------------------------------------------------
915 // wxSplitterWindow virtual functions: they now just generate the events
916 // ---------------------------------------------------------------------------
918 bool wxSplitterWindow::OnSashPositionChange(int WXUNUSED(newSashPosition
))
920 // always allow by default
924 int wxSplitterWindow::OnSashPositionChanging(int newSashPosition
)
926 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
927 const int UNSPLIT_THRESHOLD
= 4;
929 // first of all, check if OnSashPositionChange() doesn't forbid this change
930 if ( !OnSashPositionChange(newSashPosition
) )
936 // Obtain relevant window dimension for bottom / right threshold check
937 int window_size
= GetWindowSize();
939 bool unsplit_scenario
= false;
940 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
942 // Do edge detection if unsplit premitted
943 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
945 // threshold top / left check
947 unsplit_scenario
= true;
949 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
951 // threshold bottom/right check
952 newSashPosition
= window_size
;
953 unsplit_scenario
= true;
957 if ( !unsplit_scenario
)
959 // If resultant pane would be too small, enlarge it
960 newSashPosition
= AdjustSashPosition(newSashPosition
);
962 // If the result is out of bounds it means minimum size is too big,
963 // so split window in half as best compromise.
964 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
965 newSashPosition
= window_size
/ 2;
968 // now let the event handler have it
970 // FIXME: shouldn't we do it before the adjustments above so as to ensure
971 // that the sash position is always reasonable?
972 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
, this);
973 event
.m_data
.pos
= newSashPosition
;
975 if ( !DoSendEvent(event
) )
977 // the event handler vetoed the change
978 newSashPosition
= -1;
982 // it could have been changed by it
983 newSashPosition
= event
.GetSashPosition();
986 return newSashPosition
;
989 // Called when the sash is double-clicked. The default behaviour is to remove
990 // the sash if the minimum pane size is zero.
991 void wxSplitterWindow::OnDoubleClickSash(int x
, int y
)
993 wxCHECK_RET(m_windowTwo
, wxT("splitter: no window to remove"));
995 // new code should handle events instead of using the virtual functions
996 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
, this);
997 event
.m_data
.pt
.x
= x
;
998 event
.m_data
.pt
.y
= y
;
999 if ( DoSendEvent(event
) )
1001 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
1003 wxWindow
* win
= m_windowTwo
;
1006 wxSplitterEvent
unsplitEvent(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
1007 unsplitEvent
.m_data
.win
= win
;
1008 (void)DoSendEvent(unsplitEvent
);
1012 //else: blocked by user
1015 void wxSplitterWindow::OnUnsplit(wxWindow
*winRemoved
)
1017 // call this before calling the event handler which may delete the window
1018 winRemoved
->Show(false);
1021 #if defined( __WXMSW__ ) || defined( __WXMAC__)
1023 // this is currently called (and needed) under MSW only...
1024 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& event
)
1026 // if we don't do it, the resizing cursor might be set for child window:
1027 // and like this we explicitly say that our cursor should not be used for
1028 // children windows which overlap us
1030 if ( SashHitTest(event
.GetX(), event
.GetY(), 0) )
1032 // default processing is ok
1035 //else: do nothing, in particular, don't call Skip()
1038 #endif // wxMSW || wxMac
1040 #endif // wxUSE_SPLITTER