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
)
65 #if defined( __WXMSW__ ) || defined( __WXMAC__)
66 EVT_SET_CURSOR(wxSplitterWindow::OnSetCursor
)
69 WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow
)
72 WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow
, wxWindow
)
74 bool wxSplitterWindow::Create(wxWindow
*parent
, wxWindowID id
,
80 // allow TABbing from one window to the other
81 style
|= wxTAB_TRAVERSAL
;
83 // we draw our border ourselves to blend the sash with it
84 style
&= ~wxBORDER_MASK
;
85 style
|= wxBORDER_NONE
;
88 // CoreGraphics can't paint sash feedback
89 style
|= wxSP_LIVE_UPDATE
;
92 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
96 m_lastSize
.x
= size
.x
;
98 m_lastSize
.y
= size
.y
;
100 m_permitUnsplitAlways
= (style
& wxSP_PERMIT_UNSPLIT
) != 0;
102 // FIXME: with this line the background is not erased at all under GTK1,
103 // so temporary avoid it there
104 #if !defined(__WXGTK__) || defined(__WXGTK20__)
105 // don't erase the splitter background, it's pointless as we overwrite it
107 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
113 void wxSplitterWindow::Init()
115 WX_INIT_CONTROL_CONTAINER();
117 m_splitMode
= wxSPLIT_VERTICAL
;
118 m_permitUnsplitAlways
= true;
119 m_windowOne
= (wxWindow
*) NULL
;
120 m_windowTwo
= (wxWindow
*) NULL
;
121 m_dragMode
= wxSPLIT_DRAG_NONE
;
126 m_sashPosition
= m_requestedSashPosition
= 0;
128 m_sashSize
= -1; // -1 means use the native sash size
129 m_lastSize
= wxSize(0,0);
130 m_checkRequestedSashPosition
= false;
131 m_minimumPaneSize
= 0;
132 m_sashCursorWE
= wxCursor(wxCURSOR_SIZEWE
);
133 m_sashCursorNS
= wxCursor(wxCURSOR_SIZENS
);
134 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxPENSTYLE_SOLID
);
136 m_needUpdating
= false;
140 wxSplitterWindow::~wxSplitterWindow()
142 delete m_sashTrackerPen
;
145 // ----------------------------------------------------------------------------
146 // entering/leaving sash
147 // ----------------------------------------------------------------------------
149 void wxSplitterWindow::RedrawIfHotSensitive(bool isHot
)
151 if ( wxRendererNative::Get().GetSplitterParams(this).isHotSensitive
)
158 //else: we don't change our appearance, don't redraw to avoid flicker
161 void wxSplitterWindow::OnEnterSash()
165 RedrawIfHotSensitive(true);
168 void wxSplitterWindow::OnLeaveSash()
170 SetCursor(*wxSTANDARD_CURSOR
);
172 RedrawIfHotSensitive(false);
175 void wxSplitterWindow::SetResizeCursor()
177 SetCursor(m_splitMode
== wxSPLIT_VERTICAL
? m_sashCursorWE
181 // ----------------------------------------------------------------------------
182 // other event handlers
183 // ----------------------------------------------------------------------------
185 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
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
)
217 // with wxSP_LIVE_UPDATE style the splitter windows are always resized
218 // following the mouse movement while it drags the sash, without it we only
219 // draw the sash at the new position but only resize the windows when the
220 // dragging is finished
221 #if defined( __WXMAC__ )
222 // FIXME : this should be usable also with no live update, but then this
223 // currently is not visible
226 bool isLive
= HasFlag(wxSP_LIVE_UPDATE
);
228 if (event
.LeftDown())
230 if ( SashHitTest(x
, y
) )
232 // Start the drag now
233 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
235 // Capture mouse and set the cursor
241 // remember the initial sash position and draw the initial
243 m_sashPositionCurrent
= m_sashPosition
;
245 DrawSashTracker(x
, y
);
255 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
257 // We can stop dragging now and see what we've got.
258 m_dragMode
= wxSPLIT_DRAG_NONE
;
260 // Release mouse and unset the cursor
262 SetCursor(* wxSTANDARD_CURSOR
);
264 // exit if unsplit after doubleclick
273 DrawSashTracker(m_oldX
, m_oldY
);
276 // the position of the click doesn't exactly correspond to
277 // m_sashPosition, rather it changes it by the distance by which the
279 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_oldX
: y
- m_oldY
;
281 int posSashOld
= isLive
? m_sashPosition
: m_sashPositionCurrent
;
282 int posSashNew
= OnSashPositionChanging(posSashOld
+ diff
);
283 if ( posSashNew
== -1 )
285 // change not allowed
289 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
291 // Deal with possible unsplit scenarios
292 if ( posSashNew
== 0 )
294 // We remove the first window from the view
295 wxWindow
*removedWindow
= m_windowOne
;
296 m_windowOne
= m_windowTwo
;
297 m_windowTwo
= (wxWindow
*) NULL
;
298 OnUnsplit(removedWindow
);
299 wxSplitterEvent
eventUnsplit(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
300 eventUnsplit
.m_data
.win
= removedWindow
;
301 (void)DoSendEvent(eventUnsplit
);
302 SetSashPositionAndNotify(0);
304 else if ( posSashNew
== GetWindowSize() )
306 // We remove the second window from the view
307 wxWindow
*removedWindow
= m_windowTwo
;
308 m_windowTwo
= (wxWindow
*) NULL
;
309 OnUnsplit(removedWindow
);
310 wxSplitterEvent
eventUnsplit(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
311 eventUnsplit
.m_data
.win
= removedWindow
;
312 (void)DoSendEvent(eventUnsplit
);
313 SetSashPositionAndNotify(0);
317 SetSashPositionAndNotify(posSashNew
);
322 SetSashPositionAndNotify(posSashNew
);
326 } // left up && dragging
327 else if ((event
.Moving() || event
.Leaving() || event
.Entering()) && (m_dragMode
== wxSPLIT_DRAG_NONE
))
329 if ( event
.Leaving() || !SashHitTest(x
, y
) )
334 else if (event
.Dragging() && (m_dragMode
== wxSPLIT_DRAG_DRAGGING
))
336 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_oldX
: y
- m_oldY
;
339 // nothing to do, mouse didn't really move far enough
343 int posSashOld
= isLive
? m_sashPosition
: m_sashPositionCurrent
;
344 int posSashNew
= OnSashPositionChanging(posSashOld
+ diff
);
345 if ( posSashNew
== -1 )
347 // change not allowed
351 if ( posSashNew
== m_sashPosition
)
357 DrawSashTracker(m_oldX
, m_oldY
);
360 if (m_splitMode
== wxSPLIT_VERTICAL
)
365 // Remember old positions
370 // As we captured the mouse, we may get the mouse events from outside
371 // our window - for example, negative values in x, y. This has a weird
372 // consequence under MSW where we use unsigned values sometimes and
373 // signed ones other times: the coordinates turn as big positive
374 // numbers and so the sash is drawn on the *right* side of the window
375 // instead of the left (or bottom instead of top). Correct this.
376 if ( (short)m_oldX
< 0 )
378 if ( (short)m_oldY
< 0 )
385 m_sashPositionCurrent
= posSashNew
;
387 DrawSashTracker(m_oldX
, m_oldY
);
391 DoSetSashPosition(posSashNew
);
392 m_needUpdating
= true;
395 else if ( event
.LeftDClick() && m_windowTwo
)
397 OnDoubleClickSash(x
, y
);
401 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
403 // only process this message if we're not iconized - otherwise iconizing
404 // and restoring a window containing the splitter has a funny side effect
405 // of changing the splitter position!
406 wxWindow
*parent
= wxGetTopLevelParent(this);
409 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
412 iconized
= winTop
->IsIconized();
416 wxFAIL_MSG(wxT("should have a top level parent!"));
423 m_lastSize
= wxSize(0,0);
433 GetClientSize(&w
, &h
);
435 int size
= m_splitMode
== wxSPLIT_VERTICAL
? w
: h
;
437 int old_size
= m_splitMode
== wxSPLIT_VERTICAL
? m_lastSize
.x
: m_lastSize
.y
;
440 int delta
= (int) ( (size
- old_size
)*m_sashGravity
);
443 int newPosition
= m_sashPosition
+ delta
;
444 if( newPosition
< m_minimumPaneSize
)
445 newPosition
= m_minimumPaneSize
;
446 SetSashPositionAndNotify(newPosition
);
450 if ( m_sashPosition
>= size
- 5 )
451 SetSashPositionAndNotify(wxMax(10, size
- 40));
452 m_lastSize
= wxSize(w
,h
);
458 void wxSplitterWindow::SetSashGravity(double gravity
)
460 wxCHECK_RET( gravity
>= 0. && gravity
<= 1.,
461 _T("invalid gravity value") );
463 m_sashGravity
= gravity
;
466 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
468 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
469 return false; // No sash
471 int z
= m_splitMode
== wxSPLIT_VERTICAL
? x
: y
;
472 int hitMin
= m_sashPosition
- tolerance
;
473 int hitMax
= m_sashPosition
+ GetSashSize() + tolerance
;
475 return z
>= hitMin
&& z
<= hitMax
;
478 int wxSplitterWindow::GetSashSize() const
480 return m_sashSize
> -1 ? m_sashSize
: wxRendererNative::Get().GetSplitterParams(this).widthSash
;
483 int wxSplitterWindow::GetBorderSize() const
485 return wxRendererNative::Get().GetSplitterParams(this).border
;
489 void wxSplitterWindow::DrawSash(wxDC
& dc
)
491 if (HasFlag(wxSP_3DBORDER
))
492 wxRendererNative::Get().DrawSplitterBorder
499 // don't draw sash if we're not split
500 if ( m_sashPosition
== 0 || !m_windowTwo
)
503 // nor if we're configured to not show it
504 if ( HasFlag(wxSP_NOSASH
) )
507 wxRendererNative::Get().DrawSplitterSash
513 m_splitMode
== wxSPLIT_VERTICAL
? wxVERTICAL
515 m_isHot
? (int)wxCONTROL_CURRENT
: 0
519 // Draw the sash tracker (for whilst moving the sash)
520 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
523 GetClientSize(&w
, &h
);
529 if ( m_splitMode
== wxSPLIT_VERTICAL
)
560 ClientToScreen(&x1
, &y1
);
561 ClientToScreen(&x2
, &y2
);
563 screenDC
.SetLogicalFunction(wxINVERT
);
564 screenDC
.SetPen(*m_sashTrackerPen
);
565 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
567 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
569 screenDC
.SetLogicalFunction(wxCOPY
);
572 int wxSplitterWindow::GetWindowSize() const
574 wxSize size
= GetClientSize();
576 return m_splitMode
== wxSPLIT_VERTICAL
? size
.x
: size
.y
;
579 int wxSplitterWindow::AdjustSashPosition(int sashPos
) const
586 // the window shouldn't be smaller than its own minimal size nor
587 // smaller than the minimual pane size specified for this splitter
588 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
589 : win
->GetMinHeight();
591 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
592 minSize
= m_minimumPaneSize
;
594 minSize
+= GetBorderSize();
596 if ( sashPos
< minSize
)
603 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
604 : win
->GetMinHeight();
606 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
607 minSize
= m_minimumPaneSize
;
609 int maxSize
= GetWindowSize() - minSize
- GetBorderSize() - GetSashSize();
610 if ( maxSize
> 0 && sashPos
> maxSize
)
617 bool wxSplitterWindow::DoSetSashPosition(int sashPos
)
619 int newSashPosition
= AdjustSashPosition(sashPos
);
621 if ( newSashPosition
== m_sashPosition
)
624 m_sashPosition
= newSashPosition
;
629 void wxSplitterWindow::SetSashPositionAndNotify(int sashPos
)
631 // we must reset the request here, otherwise the sash would be stuck at
632 // old position if the user attempted to move the sash after invalid
633 // (e.g. smaller than minsize) sash position was requested using
634 // SetSashPosition():
635 m_requestedSashPosition
= INT_MAX
;
637 // note that we must send the event in any case, i.e. even if the sash
638 // position hasn't changed and DoSetSashPosition() returns false because we
639 // must generate a CHANGED event at the end of resizing
640 DoSetSashPosition(sashPos
);
642 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
, this);
643 event
.m_data
.pos
= m_sashPosition
;
645 (void)DoSendEvent(event
);
648 // Position and size subwindows.
649 // Note that the border size applies to each subwindow, not
650 // including the edges next to the sash.
651 void wxSplitterWindow::SizeWindows()
653 // check if we have delayed setting the real sash position
654 if ( m_checkRequestedSashPosition
&& m_requestedSashPosition
!= INT_MAX
)
656 int newSashPosition
= ConvertSashPosition(m_requestedSashPosition
);
657 if ( newSashPosition
!= m_sashPosition
)
659 DoSetSashPosition(newSashPosition
);
662 if ( newSashPosition
<= m_sashPosition
663 && newSashPosition
>= m_sashPosition
- GetBorderSize() )
665 // don't update it any more
666 m_requestedSashPosition
= INT_MAX
;
671 GetClientSize(&w
, &h
);
673 if ( GetWindow1() && !GetWindow2() )
675 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
676 w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
678 else if ( GetWindow1() && GetWindow2() )
680 const int border
= GetBorderSize(),
681 sash
= GetSashSize();
683 int size1
= GetSashPosition() - border
,
684 size2
= GetSashPosition() + sash
;
686 int x2
, y2
, w1
, h1
, w2
, h2
;
687 if ( GetSplitMode() == wxSPLIT_VERTICAL
)
690 w2
= w
- 2*border
- sash
- w1
;
700 else // horz splitter
707 h2
= h
- 2*border
- sash
- h1
;
714 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
715 GetWindow1()->SetSize(border
, border
, w1
, h1
);
721 SetNeedUpdating(false);
724 // Set pane for unsplit window
725 void wxSplitterWindow::Initialize(wxWindow
*window
)
727 wxASSERT_MSG( (!window
|| window
->GetParent() == this),
728 _T("windows in the splitter should have it as parent!") );
730 if (window
&& !window
->IsShown())
733 m_windowOne
= window
;
734 m_windowTwo
= (wxWindow
*) NULL
;
735 DoSetSashPosition(0);
738 // Associates the given window with window 2, drawing the appropriate sash
739 // and changing the split mode.
740 // Does nothing and returns false if the window is already split.
741 bool wxSplitterWindow::DoSplit(wxSplitMode mode
,
742 wxWindow
*window1
, wxWindow
*window2
,
748 wxCHECK_MSG( window1
&& window2
, false,
749 _T("can not split with NULL window(s)") );
751 wxCHECK_MSG( window1
->GetParent() == this && window2
->GetParent() == this, false,
752 _T("windows in the splitter should have it as parent!") );
754 if (! window1
->IsShown())
756 if (! window2
->IsShown())
760 m_windowOne
= window1
;
761 m_windowTwo
= window2
;
763 // remember the sash position we want to set for later if we can't set it
764 // right now (e.g. because the window is too small)
765 m_requestedSashPosition
= sashPosition
;
766 m_checkRequestedSashPosition
= false;
768 DoSetSashPosition(ConvertSashPosition(sashPosition
));
775 int wxSplitterWindow::ConvertSashPosition(int sashPosition
) const
777 if ( sashPosition
> 0 )
781 else if ( sashPosition
< 0 )
783 // It's negative so adding is subtracting
784 return GetWindowSize() + sashPosition
;
786 else // sashPosition == 0
788 // default, put it in the centre
789 return GetWindowSize() / 2;
793 // Remove the specified (or second) window from the view
794 // Doesn't actually delete the window.
795 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
801 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
804 m_windowTwo
= (wxWindow
*) NULL
;
806 else if ( toRemove
== m_windowOne
)
809 m_windowOne
= m_windowTwo
;
810 m_windowTwo
= (wxWindow
*) NULL
;
814 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
820 DoSetSashPosition(0);
826 // Replace a window with another one
827 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
829 wxCHECK_MSG( winOld
, false, wxT("use one of Split() functions instead") );
830 wxCHECK_MSG( winNew
, false, wxT("use Unsplit() functions instead") );
832 if ( winOld
== m_windowTwo
)
834 m_windowTwo
= winNew
;
836 else if ( winOld
== m_windowOne
)
838 m_windowOne
= winNew
;
842 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
852 void wxSplitterWindow::SetMinimumPaneSize(int min
)
854 m_minimumPaneSize
= min
;
855 int pos
= m_requestedSashPosition
!= INT_MAX
? m_requestedSashPosition
: m_sashPosition
;
856 SetSashPosition(pos
); // re-check limits
859 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
861 // remember the sash position we want to set for later if we can't set it
862 // right now (e.g. because the window is too small)
863 m_requestedSashPosition
= position
;
864 m_checkRequestedSashPosition
= false;
866 DoSetSashPosition(ConvertSashPosition(position
));
874 // Make sure the child window sizes are updated. This is useful
875 // for reducing flicker by updating the sizes before a
876 // window is shown, if you know the overall size is correct.
877 void wxSplitterWindow::UpdateSize()
879 m_checkRequestedSashPosition
= true;
881 m_checkRequestedSashPosition
= false;
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 border and the sash
921 int border
= 2*GetBorderSize();
922 *pSash
+= GetSashSize();
923 sizeBest
.x
+= border
;
924 sizeBest
.y
+= border
;
929 // ---------------------------------------------------------------------------
930 // wxSplitterWindow virtual functions: they now just generate the events
931 // ---------------------------------------------------------------------------
933 bool wxSplitterWindow::OnSashPositionChange(int WXUNUSED(newSashPosition
))
935 // always allow by default
939 int wxSplitterWindow::OnSashPositionChanging(int newSashPosition
)
941 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
942 const int UNSPLIT_THRESHOLD
= 4;
944 // first of all, check if OnSashPositionChange() doesn't forbid this change
945 if ( !OnSashPositionChange(newSashPosition
) )
951 // Obtain relevant window dimension for bottom / right threshold check
952 int window_size
= GetWindowSize();
954 bool unsplit_scenario
= false;
955 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
957 // Do edge detection if unsplit premitted
958 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
960 // threshold top / left check
962 unsplit_scenario
= true;
964 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
966 // threshold bottom/right check
967 newSashPosition
= window_size
;
968 unsplit_scenario
= true;
972 if ( !unsplit_scenario
)
974 // If resultant pane would be too small, enlarge it
975 newSashPosition
= AdjustSashPosition(newSashPosition
);
978 // If the result is out of bounds it means minimum size is too big,
979 // so split window in half as best compromise.
980 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
981 newSashPosition
= window_size
/ 2;
983 // now let the event handler have it
985 // FIXME: shouldn't we do it before the adjustments above so as to ensure
986 // that the sash position is always reasonable?
987 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
, this);
988 event
.m_data
.pos
= newSashPosition
;
990 if ( !DoSendEvent(event
) )
992 // the event handler vetoed the change
993 newSashPosition
= -1;
997 // it could have been changed by it
998 newSashPosition
= event
.GetSashPosition();
1001 return newSashPosition
;
1004 // Called when the sash is double-clicked. The default behaviour is to remove
1005 // the sash if the minimum pane size is zero.
1006 void wxSplitterWindow::OnDoubleClickSash(int x
, int y
)
1008 wxCHECK_RET(m_windowTwo
, wxT("splitter: no window to remove"));
1010 // new code should handle events instead of using the virtual functions
1011 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
, this);
1012 event
.m_data
.pt
.x
= x
;
1013 event
.m_data
.pt
.y
= y
;
1014 if ( DoSendEvent(event
) )
1016 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
1018 wxWindow
* win
= m_windowTwo
;
1021 wxSplitterEvent
unsplitEvent(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
1022 unsplitEvent
.m_data
.win
= win
;
1023 (void)DoSendEvent(unsplitEvent
);
1027 //else: blocked by user
1030 void wxSplitterWindow::OnUnsplit(wxWindow
*winRemoved
)
1032 // call this before calling the event handler which may delete the window
1033 winRemoved
->Show(false);
1036 #if defined( __WXMSW__ ) || defined( __WXMAC__)
1038 // this is currently called (and needed) under MSW only...
1039 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& event
)
1041 // if we don't do it, the resizing cursor might be set for child window:
1042 // and like this we explicitly say that our cursor should not be used for
1043 // children windows which overlap us
1045 if ( SashHitTest(event
.GetX(), event
.GetY(), 0) )
1047 // default processing is ok
1050 //else: do nothing, in particular, don't call Skip()
1053 #endif // wxMSW || wxMac
1055 #endif // wxUSE_SPLITTER