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 // we draw our border ourselves to blend the sash with it
98 style
&= ~wxBORDER_MASK
;
99 style
|= wxBORDER_NONE
;
102 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
106 m_lastSize
.x
= size
.x
;
108 m_lastSize
.y
= size
.y
;
110 m_permitUnsplitAlways
= (style
& wxSP_PERMIT_UNSPLIT
) != 0;
112 // FIXME: with this line the background is not erased at all under GTK1,
113 // so temporary avoid it there
114 #if !defined(__WXGTK__) || defined(__WXGTK20__)
115 // don't erase the splitter background, it's pointless as we overwrite it
117 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
123 void wxSplitterWindow::Init()
125 WX_INIT_CONTROL_CONTAINER();
127 m_splitMode
= wxSPLIT_VERTICAL
;
128 m_permitUnsplitAlways
= true;
131 m_dragMode
= wxSPLIT_DRAG_NONE
;
135 m_sashPosition
= m_requestedSashPosition
= 0;
137 m_sashSize
= -1; // -1 means use the native sash size
138 m_lastSize
= wxSize(0,0);
139 m_checkRequestedSashPosition
= false;
140 m_minimumPaneSize
= 0;
141 m_sashCursorWE
= wxCursor(wxCURSOR_SIZEWE
);
142 m_sashCursorNS
= wxCursor(wxCURSOR_SIZENS
);
143 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxPENSTYLE_SOLID
);
145 m_needUpdating
= false;
149 wxSplitterWindow::~wxSplitterWindow()
151 delete m_sashTrackerPen
;
154 // ----------------------------------------------------------------------------
155 // entering/leaving sash
156 // ----------------------------------------------------------------------------
158 void wxSplitterWindow::RedrawIfHotSensitive(bool isHot
)
160 if ( wxRendererNative::Get().GetSplitterParams(this).isHotSensitive
)
167 //else: we don't change our appearance, don't redraw to avoid flicker
170 void wxSplitterWindow::OnEnterSash()
174 RedrawIfHotSensitive(true);
177 void wxSplitterWindow::OnLeaveSash()
179 SetCursor(*wxSTANDARD_CURSOR
);
181 RedrawIfHotSensitive(false);
184 void wxSplitterWindow::SetResizeCursor()
186 SetCursor(m_splitMode
== wxSPLIT_VERTICAL
? m_sashCursorWE
190 // ----------------------------------------------------------------------------
191 // other event handlers
192 // ----------------------------------------------------------------------------
194 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
198 // as subpanels might have a transparent background we must erase the background
199 // at least on OSX, otherwise traces of the sash will remain
200 // test with: splitter sample->replace right window
207 void wxSplitterWindow::OnInternalIdle()
209 wxWindow::OnInternalIdle();
211 // if this is the first idle time after a sash position has potentially
212 // been set, allow SizeWindows to check for a requested size.
213 if (!m_checkRequestedSashPosition
)
215 m_checkRequestedSashPosition
= true;
217 return; // it won't needUpdating in this case
224 void wxSplitterWindow::OnMouseEvent(wxMouseEvent
& event
)
226 int x
= (int)event
.GetX(),
227 y
= (int)event
.GetY();
229 if ( GetWindowStyle() & wxSP_NOSASH
)
235 bool isLive
= IsLive(this);
237 if (event
.LeftDown())
239 if ( SashHitTest(x
, y
) )
241 // Start the drag now
242 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
244 // Capture mouse and set the cursor
250 // remember the initial sash position and draw the initial
252 m_sashPositionCurrent
= m_sashPosition
;
254 m_oldX
= (m_splitMode
== wxSPLIT_VERTICAL
? m_sashPositionCurrent
: x
);
255 m_oldY
= (m_splitMode
!= wxSPLIT_VERTICAL
? m_sashPositionCurrent
: y
);
256 DrawSashTracker(m_oldX
, m_oldY
);
259 m_ptStart
= wxPoint(x
,y
);
260 m_sashStart
= m_sashPosition
;
264 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
266 // We can stop dragging now and see what we've got.
267 m_dragMode
= wxSPLIT_DRAG_NONE
;
269 // Release mouse and unset the cursor
271 SetCursor(* wxSTANDARD_CURSOR
);
273 // exit if unsplit after doubleclick
282 DrawSashTracker(m_oldX
, m_oldY
);
285 // the position of the click doesn't exactly correspond to
286 // m_sashPosition, rather it changes it by the distance by which the
288 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_ptStart
.x
: y
- m_ptStart
.y
;
290 int posSashNew
= OnSashPositionChanging(m_sashStart
+ diff
);
291 if ( posSashNew
== -1 )
293 // change not allowed
297 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
299 // Deal with possible unsplit scenarios
300 if ( posSashNew
== 0 )
302 // We remove the first window from the view
303 wxWindow
*removedWindow
= m_windowOne
;
304 m_windowOne
= 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);
312 else if ( posSashNew
== GetWindowSize() )
314 // We remove the second window from the view
315 wxWindow
*removedWindow
= m_windowTwo
;
317 OnUnsplit(removedWindow
);
318 wxSplitterEvent
eventUnsplit(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
319 eventUnsplit
.m_data
.win
= removedWindow
;
320 (void)DoSendEvent(eventUnsplit
);
321 SetSashPositionAndNotify(0);
325 SetSashPositionAndNotify(posSashNew
);
330 SetSashPositionAndNotify(posSashNew
);
334 } // left up && dragging
335 else if ((event
.Moving() || event
.Leaving() || event
.Entering()) && (m_dragMode
== wxSPLIT_DRAG_NONE
))
337 if ( event
.Leaving() || !SashHitTest(x
, y
) )
342 else if (event
.Dragging() && (m_dragMode
== wxSPLIT_DRAG_DRAGGING
))
344 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_ptStart
.x
: y
- m_ptStart
.y
;
346 int posSashNew
= OnSashPositionChanging(m_sashStart
+ diff
);
347 if ( posSashNew
== -1 )
349 // change not allowed
355 if ( posSashNew
== m_sashPositionCurrent
)
358 m_sashPositionCurrent
= posSashNew
;
361 DrawSashTracker(m_oldX
, m_oldY
);
363 m_oldX
= (m_splitMode
== wxSPLIT_VERTICAL
? m_sashPositionCurrent
: x
);
364 m_oldY
= (m_splitMode
!= wxSPLIT_VERTICAL
? m_sashPositionCurrent
: y
);
367 // As we captured the mouse, we may get the mouse events from outside
368 // our window - for example, negative values in x, y. This has a weird
369 // consequence under MSW where we use unsigned values sometimes and
370 // signed ones other times: the coordinates turn as big positive
371 // numbers and so the sash is drawn on the *right* side of the window
372 // instead of the left (or bottom instead of top). Correct this.
373 if ( (short)m_oldX
< 0 )
375 if ( (short)m_oldY
< 0 )
380 DrawSashTracker(m_oldX
, m_oldY
);
384 if ( posSashNew
== m_sashPosition
)
387 DoSetSashPosition(posSashNew
);
389 // in live mode, the new position is the actual sash position, clear requested position!
390 m_requestedSashPosition
= INT_MAX
;
391 m_needUpdating
= true;
394 else if ( event
.LeftDClick() && m_windowTwo
)
396 OnDoubleClickSash(x
, y
);
404 void wxSplitterWindow::OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
406 if (m_dragMode
!= wxSPLIT_DRAG_DRAGGING
)
409 m_dragMode
= wxSPLIT_DRAG_NONE
;
411 SetCursor(* wxSTANDARD_CURSOR
);
416 DrawSashTracker(m_oldX
, m_oldY
);
420 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
422 // only process this message if we're not iconized - otherwise iconizing
423 // and restoring a window containing the splitter has a funny side effect
424 // of changing the splitter position!
425 wxWindow
*parent
= wxGetTopLevelParent(this);
428 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
431 iconized
= winTop
->IsIconized();
435 wxFAIL_MSG(wxT("should have a top level parent!"));
442 m_lastSize
= wxSize(0,0);
452 GetClientSize(&w
, &h
);
454 int size
= m_splitMode
== wxSPLIT_VERTICAL
? w
: h
;
456 int old_size
= m_splitMode
== wxSPLIT_VERTICAL
? m_lastSize
.x
: m_lastSize
.y
;
459 int delta
= (int) ( (size
- old_size
)*m_sashGravity
);
462 int newPosition
= m_sashPosition
+ delta
;
463 if( newPosition
< m_minimumPaneSize
)
464 newPosition
= m_minimumPaneSize
;
465 SetSashPositionAndNotify(newPosition
);
469 if ( m_sashPosition
>= size
- 5 )
470 SetSashPositionAndNotify(wxMax(10, size
- 40));
471 m_lastSize
= wxSize(w
,h
);
477 void wxSplitterWindow::SetSashGravity(double gravity
)
479 wxCHECK_RET( gravity
>= 0. && gravity
<= 1.,
480 wxT("invalid gravity value") );
482 m_sashGravity
= gravity
;
485 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
487 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
488 return false; // No sash
490 int z
= m_splitMode
== wxSPLIT_VERTICAL
? x
: y
;
491 int hitMin
= m_sashPosition
- tolerance
;
492 int hitMax
= m_sashPosition
+ GetSashSize() + tolerance
;
494 return z
>= hitMin
&& z
<= hitMax
;
497 int wxSplitterWindow::GetSashSize() const
499 return m_sashSize
> -1 ? m_sashSize
: wxRendererNative::Get().GetSplitterParams(this).widthSash
;
502 int wxSplitterWindow::GetBorderSize() const
504 return wxRendererNative::Get().GetSplitterParams(this).border
;
508 void wxSplitterWindow::DrawSash(wxDC
& dc
)
510 if (HasFlag(wxSP_3DBORDER
))
511 wxRendererNative::Get().DrawSplitterBorder
518 // don't draw sash if we're not split
519 if ( m_sashPosition
== 0 || !m_windowTwo
)
522 // nor if we're configured to not show it
523 if ( HasFlag(wxSP_NOSASH
) )
526 wxRendererNative::Get().DrawSplitterSash
532 m_splitMode
== wxSPLIT_VERTICAL
? wxVERTICAL
534 m_isHot
? (int)wxCONTROL_CURRENT
: 0
538 // Draw the sash tracker (for whilst moving the sash)
539 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
542 GetClientSize(&w
, &h
);
548 if ( m_splitMode
== wxSPLIT_VERTICAL
)
550 x1
= x2
= wxClip(x
, 0, w
) + m_sashTrackerPen
->GetWidth()/2;
556 y1
= y2
= wxClip(y
, 0, h
) + m_sashTrackerPen
->GetWidth()/2;
561 ClientToScreen(&x1
, &y1
);
562 ClientToScreen(&x2
, &y2
);
564 screenDC
.SetLogicalFunction(wxINVERT
);
565 screenDC
.SetPen(*m_sashTrackerPen
);
566 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
568 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
570 screenDC
.SetLogicalFunction(wxCOPY
);
573 int wxSplitterWindow::GetWindowSize() const
575 wxSize size
= GetClientSize();
577 return m_splitMode
== wxSPLIT_VERTICAL
? size
.x
: size
.y
;
580 int wxSplitterWindow::AdjustSashPosition(int sashPos
) const
587 // the window shouldn't be smaller than its own minimal size nor
588 // smaller than the minimual pane size specified for this splitter
589 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
590 : win
->GetMinHeight();
592 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
593 minSize
= m_minimumPaneSize
;
595 minSize
+= GetBorderSize();
597 if ( sashPos
< minSize
)
604 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
605 : win
->GetMinHeight();
607 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
608 minSize
= m_minimumPaneSize
;
610 int maxSize
= GetWindowSize() - minSize
- GetBorderSize() - GetSashSize();
611 if ( maxSize
> 0 && sashPos
> maxSize
&& maxSize
>= m_minimumPaneSize
)
618 bool wxSplitterWindow::DoSetSashPosition(int sashPos
)
620 int newSashPosition
= AdjustSashPosition(sashPos
);
622 if ( newSashPosition
== m_sashPosition
)
625 m_sashPosition
= newSashPosition
;
630 void wxSplitterWindow::SetSashPositionAndNotify(int sashPos
)
632 // we must reset the request here, otherwise the sash would be stuck at
633 // old position if the user attempted to move the sash after invalid
634 // (e.g. smaller than minsize) sash position was requested using
635 // SetSashPosition():
636 m_requestedSashPosition
= INT_MAX
;
638 // note that we must send the event in any case, i.e. even if the sash
639 // position hasn't changed and DoSetSashPosition() returns false because we
640 // must generate a CHANGED event at the end of resizing
641 DoSetSashPosition(sashPos
);
643 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
, this);
644 event
.m_data
.pos
= m_sashPosition
;
646 (void)DoSendEvent(event
);
649 // Position and size subwindows.
650 // Note that the border size applies to each subwindow, not
651 // including the edges next to the sash.
652 void wxSplitterWindow::SizeWindows()
654 // check if we have delayed setting the real sash position
655 if ( m_checkRequestedSashPosition
&& m_requestedSashPosition
!= INT_MAX
)
657 int newSashPosition
= ConvertSashPosition(m_requestedSashPosition
);
658 if ( newSashPosition
!= m_sashPosition
)
660 DoSetSashPosition(newSashPosition
);
663 if ( newSashPosition
<= m_sashPosition
664 && newSashPosition
>= m_sashPosition
- GetBorderSize() )
666 // don't update it any more
667 m_requestedSashPosition
= INT_MAX
;
672 GetClientSize(&w
, &h
);
674 if ( GetWindow1() && !GetWindow2() )
676 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
677 w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
679 else if ( GetWindow1() && GetWindow2() )
681 const int border
= GetBorderSize(),
682 sash
= GetSashSize();
684 int size1
= GetSashPosition() - border
,
685 size2
= GetSashPosition() + sash
;
687 int x2
, y2
, w1
, h1
, w2
, h2
;
688 if ( GetSplitMode() == wxSPLIT_VERTICAL
)
691 w2
= w
- 2*border
- sash
- w1
;
701 else // horz splitter
708 h2
= h
- 2*border
- sash
- h1
;
715 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
716 GetWindow1()->SetSize(border
, border
, w1
, h1
);
722 SetNeedUpdating(false);
725 // Set pane for unsplit window
726 void wxSplitterWindow::Initialize(wxWindow
*window
)
728 wxASSERT_MSG( (!window
|| window
->GetParent() == this),
729 wxT("windows in the splitter should have it as parent!") );
731 if (window
&& !window
->IsShown())
734 m_windowOne
= window
;
736 DoSetSashPosition(0);
739 // Associates the given window with window 2, drawing the appropriate sash
740 // and changing the split mode.
741 // Does nothing and returns false if the window is already split.
742 bool wxSplitterWindow::DoSplit(wxSplitMode mode
,
743 wxWindow
*window1
, wxWindow
*window2
,
749 wxCHECK_MSG( window1
&& window2
, false,
750 wxT("can not split with NULL window(s)") );
752 wxCHECK_MSG( window1
->GetParent() == this && window2
->GetParent() == this, false,
753 wxT("windows in the splitter should have it as parent!") );
755 if (! window1
->IsShown())
757 if (! window2
->IsShown())
761 m_windowOne
= window1
;
762 m_windowTwo
= window2
;
765 SetSashPosition(sashPosition
, true);
769 int wxSplitterWindow::ConvertSashPosition(int sashPosition
) const
771 if ( sashPosition
> 0 )
775 else if ( sashPosition
< 0 )
777 // It's negative so adding is subtracting
778 return GetWindowSize() + sashPosition
;
780 else // sashPosition == 0
782 // default, put it in the centre
783 return GetWindowSize() / 2;
787 // Remove the specified (or second) window from the view
788 // Doesn't actually delete the window.
789 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
795 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
800 else if ( toRemove
== m_windowOne
)
803 m_windowOne
= m_windowTwo
;
808 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
814 DoSetSashPosition(0);
820 // Replace a window with another one
821 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
823 wxCHECK_MSG( winOld
, false, wxT("use one of Split() functions instead") );
824 wxCHECK_MSG( winNew
, false, wxT("use Unsplit() functions instead") );
826 if ( winOld
== m_windowTwo
)
828 m_windowTwo
= winNew
;
830 else if ( winOld
== m_windowOne
)
832 m_windowOne
= winNew
;
836 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
846 void wxSplitterWindow::SetMinimumPaneSize(int min
)
848 m_minimumPaneSize
= min
;
849 int pos
= m_requestedSashPosition
!= INT_MAX
? m_requestedSashPosition
: m_sashPosition
;
850 SetSashPosition(pos
); // re-check limits
853 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
855 // remember the sash position we want to set for later if we can't set it
856 // right now (e.g. because the window is too small)
857 m_requestedSashPosition
= position
;
858 m_checkRequestedSashPosition
= false;
860 DoSetSashPosition(ConvertSashPosition(position
));
868 // Make sure the child window sizes are updated. This is useful
869 // for reducing flicker by updating the sizes before a
870 // window is shown, if you know the overall size is correct.
871 void wxSplitterWindow::UpdateSize()
873 m_checkRequestedSashPosition
= true;
875 m_checkRequestedSashPosition
= false;
878 bool wxSplitterWindow::DoSendEvent(wxSplitterEvent
& event
)
880 return !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed();
883 wxSize
wxSplitterWindow::DoGetBestSize() const
885 // get best sizes of subwindows
888 size1
= m_windowOne
->GetEffectiveMinSize();
890 size2
= m_windowTwo
->GetEffectiveMinSize();
894 // pSash points to the size component to which sash size must be added
897 if ( m_splitMode
== wxSPLIT_VERTICAL
)
899 sizeBest
.y
= wxMax(size1
.y
, size2
.y
);
900 sizeBest
.x
= wxMax(size1
.x
, m_minimumPaneSize
) +
901 wxMax(size2
.x
, m_minimumPaneSize
);
905 else // wxSPLIT_HORIZONTAL
907 sizeBest
.x
= wxMax(size1
.x
, size2
.x
);
908 sizeBest
.y
= wxMax(size1
.y
, m_minimumPaneSize
) +
909 wxMax(size2
.y
, m_minimumPaneSize
);
914 // account for the sash if the window is actually split
915 if ( m_windowOne
&& m_windowTwo
)
916 *pSash
+= GetSashSize();
918 // account for the border too
919 int border
= 2*GetBorderSize();
920 sizeBest
.x
+= border
;
921 sizeBest
.y
+= border
;
926 // ---------------------------------------------------------------------------
927 // wxSplitterWindow virtual functions: they now just generate the events
928 // ---------------------------------------------------------------------------
930 bool wxSplitterWindow::OnSashPositionChange(int WXUNUSED(newSashPosition
))
932 // always allow by default
936 int wxSplitterWindow::OnSashPositionChanging(int newSashPosition
)
938 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
939 const int UNSPLIT_THRESHOLD
= 4;
941 // first of all, check if OnSashPositionChange() doesn't forbid this change
942 if ( !OnSashPositionChange(newSashPosition
) )
948 // Obtain relevant window dimension for bottom / right threshold check
949 int window_size
= GetWindowSize();
951 bool unsplit_scenario
= false;
952 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
954 // Do edge detection if unsplit premitted
955 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
957 // threshold top / left check
959 unsplit_scenario
= true;
961 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
963 // threshold bottom/right check
964 newSashPosition
= window_size
;
965 unsplit_scenario
= true;
969 if ( !unsplit_scenario
)
971 // If resultant pane would be too small, enlarge it
972 newSashPosition
= AdjustSashPosition(newSashPosition
);
974 // If the result is out of bounds it means minimum size is too big,
975 // so split window in half as best compromise.
976 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
977 newSashPosition
= window_size
/ 2;
980 // now let the event handler have it
982 // FIXME: shouldn't we do it before the adjustments above so as to ensure
983 // that the sash position is always reasonable?
984 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
, this);
985 event
.m_data
.pos
= newSashPosition
;
987 if ( !DoSendEvent(event
) )
989 // the event handler vetoed the change
990 newSashPosition
= -1;
994 // it could have been changed by it
995 newSashPosition
= event
.GetSashPosition();
998 return newSashPosition
;
1001 // Called when the sash is double-clicked. The default behaviour is to remove
1002 // the sash if the minimum pane size is zero.
1003 void wxSplitterWindow::OnDoubleClickSash(int x
, int y
)
1005 wxCHECK_RET(m_windowTwo
, wxT("splitter: no window to remove"));
1007 // new code should handle events instead of using the virtual functions
1008 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
, this);
1009 event
.m_data
.pt
.x
= x
;
1010 event
.m_data
.pt
.y
= y
;
1011 if ( DoSendEvent(event
) )
1013 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
1015 wxWindow
* win
= m_windowTwo
;
1018 wxSplitterEvent
unsplitEvent(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
1019 unsplitEvent
.m_data
.win
= win
;
1020 (void)DoSendEvent(unsplitEvent
);
1024 //else: blocked by user
1027 void wxSplitterWindow::OnUnsplit(wxWindow
*winRemoved
)
1029 // call this before calling the event handler which may delete the window
1030 winRemoved
->Show(false);
1033 #if defined( __WXMSW__ ) || defined( __WXMAC__)
1035 // this is currently called (and needed) under MSW only...
1036 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& event
)
1038 // if we don't do it, the resizing cursor might be set for child window:
1039 // and like this we explicitly say that our cursor should not be used for
1040 // children windows which overlap us
1042 if ( SashHitTest(event
.GetX(), event
.GetY(), 0) )
1044 // default processing is ok
1047 //else: do nothing, in particular, don't call Skip()
1050 #endif // wxMSW || wxMac
1052 #endif // wxUSE_SPLITTER