1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSplitterWindow implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "splitter.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
24 #include "wx/window.h"
25 #include "wx/dialog.h"
31 #include "wx/string.h"
32 #include "wx/splitter.h"
33 #include "wx/dcscreen.h"
34 #include "wx/settings.h"
38 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
)
39 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
)
40 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
)
41 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_UNSPLIT
)
43 IMPLEMENT_DYNAMIC_CLASS(wxSplitterWindow
, wxWindow
)
44 IMPLEMENT_DYNAMIC_CLASS(wxSplitterEvent
, wxNotifyEvent
)
46 BEGIN_EVENT_TABLE(wxSplitterWindow
, wxWindow
)
47 EVT_PAINT(wxSplitterWindow::OnPaint
)
48 EVT_SIZE(wxSplitterWindow::OnSize
)
49 EVT_IDLE(wxSplitterWindow::OnIdle
)
50 EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent
)
53 EVT_SET_CURSOR(wxSplitterWindow::OnSetCursor
)
56 WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow
)
59 WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow
);
61 bool wxSplitterWindow::Create(wxWindow
*parent
, wxWindowID id
,
67 // allow TABbing from one window to the other
68 style
|= wxTAB_TRAVERSAL
;
70 if (!wxWindow::Create(parent
, id
, pos
, size
, style
, name
))
73 m_permitUnsplitAlways
= (style
& wxSP_PERMIT_UNSPLIT
) != 0;
75 if ( style
& wxSP_3DSASH
)
80 if ( style
& wxSP_3DBORDER
)
82 else if ( style
& wxSP_BORDER
)
89 wxGetOsVersion( &major
, &minor
);
91 m_windowStyle
|= wxSP_SASH_AQUA
;
97 void wxSplitterWindow::Init()
99 m_container
.SetContainerWindow(this);
101 m_splitMode
= wxSPLIT_VERTICAL
;
102 m_permitUnsplitAlways
= TRUE
;
103 m_windowOne
= (wxWindow
*) NULL
;
104 m_windowTwo
= (wxWindow
*) NULL
;
105 m_dragMode
= wxSPLIT_DRAG_NONE
;
112 m_sashPosition
= m_requestedSashPosition
= 0;
113 m_minimumPaneSize
= 0;
114 m_sashCursorWE
= new wxCursor(wxCURSOR_SIZEWE
);
115 m_sashCursorNS
= new wxCursor(wxCURSOR_SIZENS
);
116 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxSOLID
);
117 m_lightShadowPen
= (wxPen
*) NULL
;
118 m_mediumShadowPen
= (wxPen
*) NULL
;
119 m_darkShadowPen
= (wxPen
*) NULL
;
120 m_faceBrush
= (wxBrush
*) NULL
;
121 m_facePen
= (wxPen
*) NULL
;
122 m_hilightPen
= (wxPen
*) NULL
;
129 m_needUpdating
= FALSE
;
132 wxSplitterWindow::~wxSplitterWindow()
134 delete m_sashCursorWE
;
135 delete m_sashCursorNS
;
136 delete m_sashTrackerPen
;
137 delete m_lightShadowPen
;
138 delete m_darkShadowPen
;
139 delete m_mediumShadowPen
;
145 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
149 if ( m_borderSize
> 0 )
154 void wxSplitterWindow::OnIdle(wxIdleEvent
& event
)
162 void wxSplitterWindow::OnMouseEvent(wxMouseEvent
& event
)
164 int x
= (int)event
.GetX(),
165 y
= (int)event
.GetY();
169 SetCursor(* wxSTANDARD_CURSOR
);
172 SetCursor(wxCursor());
175 if (GetWindowStyle() & wxSP_NOSASH
)
178 if (event
.LeftDown())
180 if ( SashHitTest(x
, y
) )
184 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
186 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
188 DrawSashTracker(x
, y
);
194 if ( m_splitMode
== wxSPLIT_VERTICAL
)
196 SetCursor(*m_sashCursorWE
);
200 SetCursor(*m_sashCursorNS
);
205 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
207 // We can stop dragging now and see what we've got.
208 m_dragMode
= wxSPLIT_DRAG_NONE
;
212 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
214 DrawSashTracker(m_oldX
, m_oldY
);
217 // the position of the click doesn't exactly correspond to
218 // m_sashPosition, rather it changes it by the distance by which the
220 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_oldX
: y
- m_oldY
;
222 int posSashNew
= OnSashPositionChanging(m_sashPosition
+ diff
);
223 if ( posSashNew
== -1 )
225 // change not allowed
229 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
231 // Deal with possible unsplit scenarios
232 if ( posSashNew
== 0 )
234 // We remove the first window from the view
235 wxWindow
*removedWindow
= m_windowOne
;
236 m_windowOne
= m_windowTwo
;
237 m_windowTwo
= (wxWindow
*) NULL
;
238 OnUnsplit(removedWindow
);
239 DoSetSashPosition(0);
241 else if ( posSashNew
== GetWindowSize() )
243 // We remove the second window from the view
244 wxWindow
*removedWindow
= m_windowTwo
;
245 m_windowTwo
= (wxWindow
*) NULL
;
246 OnUnsplit(removedWindow
);
247 DoSetSashPosition(0);
251 DoSetSashPosition(posSashNew
);
256 DoSetSashPosition(posSashNew
);
260 } // left up && dragging
261 else if (event
.Moving() && !event
.Dragging())
263 // Just change the cursor if required
264 if ( SashHitTest(x
, y
) )
266 if ( m_splitMode
== wxSPLIT_VERTICAL
)
268 SetCursor(*m_sashCursorWE
);
272 SetCursor(*m_sashCursorNS
);
275 #if defined(__WXGTK__) || defined(__WXMSW__)
278 // We must set the normal cursor in MSW, because
279 // if the child window doesn't have a cursor, the
280 // parent's (splitter window) will be used, and this
281 // must be the standard cursor.
283 // where else do we unset the cursor?
284 SetCursor(* wxSTANDARD_CURSOR
);
288 else if (event
.Dragging() && (m_dragMode
== wxSPLIT_DRAG_DRAGGING
))
291 // Otherwise, the cursor sometimes reverts to the normal cursor
293 if ( m_splitMode
== wxSPLIT_VERTICAL
)
295 SetCursor(*m_sashCursorWE
);
299 SetCursor(*m_sashCursorNS
);
303 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_oldX
: y
- m_oldY
;
305 int posSashNew
= OnSashPositionChanging(m_sashPosition
+ diff
);
306 if ( posSashNew
== -1 )
308 // change not allowed
312 if ( posSashNew
== m_sashPosition
)
316 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
318 DrawSashTracker(m_oldX
, m_oldY
);
321 if (m_splitMode
== wxSPLIT_VERTICAL
)
326 // Remember old positions
331 // As we captured the mouse, we may get the mouse events from outside
332 // our window - for example, negative values in x, y. This has a weird
333 // consequence under MSW where we use unsigned values sometimes and
334 // signed ones other times: the coordinates turn as big positive
335 // numbers and so the sash is drawn on the *right* side of the window
336 // instead of the left (or bottom instead of top). Correct this.
337 if ( (short)m_oldX
< 0 )
339 if ( (short)m_oldY
< 0 )
344 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
346 DrawSashTracker(m_oldX
, m_oldY
);
350 DoSetSashPosition(posSashNew
);
351 m_needUpdating
= TRUE
;
354 else if ( event
.LeftDClick() )
356 OnDoubleClickSash(x
, y
);
360 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
362 // only process this message if we're not iconized - otherwise iconizing
363 // and restoring a window containing the splitter has a funny side effect
364 // of changing the splitter position!
365 wxWindow
*parent
= GetParent();
366 while ( parent
&& !parent
->IsTopLevel() )
368 parent
= parent
->GetParent();
371 bool iconized
= FALSE
;
373 // wxMotif doesn't yet have a wxTopLevelWindow implementation
375 wxFrame
*winTop
= wxDynamicCast(parent
, wxFrame
);
377 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
381 iconized
= winTop
->IsIconized();
386 wxFAIL_MSG(wxT("should have a top level parent!"));
400 GetClientSize( &cw
, &ch
);
403 if ( m_splitMode
== wxSPLIT_VERTICAL
)
405 if ( m_sashPosition
>= (cw
- 5) )
406 DoSetSashPosition(wxMax(10, cw
- 40));
408 else // m_splitMode == wxSPLIT_HORIZONTAL
410 if ( m_sashPosition
>= (ch
- 5) )
411 DoSetSashPosition(wxMax(10, ch
- 40));
418 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
420 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
421 return FALSE
; // No sash
423 if ( m_splitMode
== wxSPLIT_VERTICAL
)
425 if ( (x
>= m_sashPosition
- tolerance
) && (x
<= m_sashPosition
+ m_sashSize
+ tolerance
) )
432 if ( (y
>= (m_sashPosition
- tolerance
)) && (y
<= (m_sashPosition
+ m_sashSize
+ tolerance
)) )
439 // Draw 3D effect borders
440 void wxSplitterWindow::DrawBorders(wxDC
& dc
)
443 GetClientSize(&w
, &h
);
445 if ( GetWindowStyleFlag() & wxSP_3DBORDER
)
448 dc
.SetPen(*m_facePen
);
449 dc
.SetBrush(*m_faceBrush
);
450 dc
.DrawRectangle(1, 1 , w
-1, m_borderSize
-2 ); //high
451 dc
.DrawRectangle(1, m_borderSize
-2 , m_borderSize
-2, h
-1 ); // left
452 dc
.DrawRectangle(w
-m_borderSize
+2, m_borderSize
-2 , w
-1, h
-1 ); // right
453 dc
.DrawRectangle(m_borderSize
-2, h
-m_borderSize
+2 , w
-m_borderSize
+2, h
-1 ); //bottom
455 dc
.SetPen(*m_mediumShadowPen
);
456 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, w
-m_borderSize
+1, m_borderSize
-2);
457 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, m_borderSize
-2, h
-m_borderSize
+1);
459 dc
.SetPen(*m_darkShadowPen
);
460 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, w
-m_borderSize
, m_borderSize
-1);
461 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, m_borderSize
-1, h
-m_borderSize
);
463 dc
.SetPen(*m_hilightPen
);
464 dc
.DrawLine(m_borderSize
- 2, h
-m_borderSize
+1, w
-m_borderSize
+1, h
-m_borderSize
+1);
465 dc
.DrawLine(w
-m_borderSize
+1, m_borderSize
- 2, w
-m_borderSize
+1, h
-m_borderSize
+2); // Surely the maximum y pos. should be h - 1.
466 /// Anyway, h is required for MSW.
468 dc
.SetPen(*m_lightShadowPen
);
469 dc
.DrawLine(w
-m_borderSize
, m_borderSize
-1, w
-m_borderSize
, h
-m_borderSize
); // Right hand side
470 dc
.DrawLine(m_borderSize
-1, h
-m_borderSize
, w
-m_borderSize
+1, h
-m_borderSize
); // Bottom
472 else if ( GetWindowStyleFlag() & wxSP_BORDER
)
474 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
475 dc
.SetPen(*wxBLACK_PEN
);
476 dc
.DrawRectangle(0, 0, w
-1, h
-1);
479 dc
.SetPen(wxNullPen
);
480 dc
.SetBrush(wxNullBrush
);
484 void wxSplitterWindow::DrawSash(wxDC
& dc
)
486 if ( m_sashPosition
== 0 || !m_windowTwo
)
488 if (GetWindowStyle() & wxSP_NOSASH
)
492 GetClientSize(&w
, &h
);
494 if ( GetWindowStyleFlag() & wxSP_3DSASH
)
496 if ( m_splitMode
== wxSPLIT_VERTICAL
)
498 dc
.SetPen(*m_facePen
);
500 if (HasFlag( wxSP_SASH_AQUA
))
501 dc
.SetBrush(*wxWHITE_BRUSH
);
503 dc
.SetBrush(*m_faceBrush
);
504 dc
.DrawRectangle(m_sashPosition
+ 2, 0 , m_sashSize
- 4, h
);
506 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
508 dc
.SetPen(*m_lightShadowPen
);
509 int xShadow
= m_borderSize
? m_borderSize
- 1 : 0 ;
510 dc
.DrawLine(m_sashPosition
, xShadow
, m_sashPosition
, h
-m_borderSize
);
512 dc
.SetPen(*m_hilightPen
);
513 dc
.DrawLine(m_sashPosition
+1, m_borderSize
- 2, m_sashPosition
+1, h
- m_borderSize
+2);
515 if (!HasFlag( wxSP_SASH_AQUA
))
516 dc
.SetPen(*m_mediumShadowPen
);
518 int yMedium
= m_borderSize
? h
-m_borderSize
+1 : h
;
519 dc
.DrawLine(m_sashPosition
+m_sashSize
-2, xShadow
, m_sashPosition
+m_sashSize
-2, yMedium
);
521 if (HasFlag( wxSP_SASH_AQUA
))
522 dc
.SetPen(*m_lightShadowPen
);
524 dc
.SetPen(*m_darkShadowPen
);
525 dc
.DrawLine(m_sashPosition
+m_sashSize
-1, m_borderSize
, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
);
527 // Draw the top and bottom edges of the sash, if requested
528 if (GetWindowStyle() & wxSP_FULLSASH
)
531 dc
.SetPen(*m_hilightPen
);
532 dc
.DrawLine(m_sashPosition
+1, m_borderSize
, m_sashPosition
+m_sashSize
-1, m_borderSize
);
535 dc
.SetPen(*m_darkShadowPen
);
536 dc
.DrawLine(m_sashPosition
+1, h
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
-1);
541 dc
.SetPen(*m_facePen
);
542 if (HasFlag( wxSP_SASH_AQUA
))
543 dc
.SetBrush(*wxWHITE_BRUSH
);
545 dc
.SetBrush(*m_faceBrush
);
546 dc
.DrawRectangle( m_borderSize
-2, m_sashPosition
+ 2, w
-m_borderSize
+2, m_sashSize
- 4);
548 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
550 dc
.SetPen(*m_lightShadowPen
);
551 dc
.DrawLine(m_borderSize
-1, m_sashPosition
, w
-m_borderSize
, m_sashPosition
);
553 dc
.SetPen(*m_hilightPen
);
554 dc
.DrawLine(m_borderSize
-2, m_sashPosition
+1, w
-m_borderSize
+1, m_sashPosition
+1);
556 if (!HasFlag( wxSP_SASH_AQUA
))
557 dc
.SetPen(*m_mediumShadowPen
);
558 dc
.DrawLine(m_borderSize
-1, m_sashPosition
+m_sashSize
-2, w
-m_borderSize
+1, m_sashPosition
+m_sashSize
-2);
560 if (HasFlag( wxSP_SASH_AQUA
))
561 dc
.SetPen(*m_lightShadowPen
);
563 dc
.SetPen(*m_darkShadowPen
);
564 dc
.DrawLine(m_borderSize
, m_sashPosition
+m_sashSize
-1, w
-m_borderSize
, m_sashPosition
+m_sashSize
-1);
566 // Draw the left and right edges of the sash, if requested
567 if (GetWindowStyle() & wxSP_FULLSASH
)
570 dc
.SetPen(*m_hilightPen
);
571 dc
.DrawLine(m_borderSize
, m_sashPosition
, m_borderSize
, m_sashPosition
+m_sashSize
);
574 dc
.SetPen(*m_darkShadowPen
);
575 dc
.DrawLine(w
-m_borderSize
-1, m_sashPosition
+1, w
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1);
581 if ( m_splitMode
== wxSPLIT_VERTICAL
)
583 dc
.SetPen(*wxBLACK_PEN
);
584 dc
.SetBrush(*wxBLACK_BRUSH
);
587 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
588 h1
+= 1; // Not sure why this is necessary...
589 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
593 dc
.DrawRectangle(m_sashPosition
, y1
, m_sashSize
, h1
);
597 dc
.SetPen(*wxBLACK_PEN
);
598 dc
.SetBrush(*wxBLACK_BRUSH
);
601 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
603 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
607 dc
.DrawRectangle(x1
, m_sashPosition
, w1
, m_sashSize
);
612 dc
.SetPen(wxNullPen
);
613 dc
.SetBrush(wxNullBrush
);
616 // Draw the sash tracker (for whilst moving the sash)
617 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
620 GetClientSize(&w
, &h
);
626 if ( m_splitMode
== wxSPLIT_VERTICAL
)
657 ClientToScreen(&x1
, &y1
);
658 ClientToScreen(&x2
, &y2
);
660 screenDC
.SetLogicalFunction(wxINVERT
);
661 screenDC
.SetPen(*m_sashTrackerPen
);
662 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
664 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
666 screenDC
.SetLogicalFunction(wxCOPY
);
668 screenDC
.SetPen(wxNullPen
);
669 screenDC
.SetBrush(wxNullBrush
);
672 int wxSplitterWindow::GetWindowSize() const
674 wxSize size
= GetClientSize();
676 return m_splitMode
== wxSPLIT_VERTICAL
? size
.x
: size
.y
;
679 int wxSplitterWindow::AdjustSashPosition(int sashPos
) const
681 int window_size
= GetWindowSize();
688 // the window shouldn't be smaller than its own minimal size nor
689 // smaller than the minimual pane size specified for this splitter
690 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
691 : win
->GetMinHeight();
693 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
694 minSize
= m_minimumPaneSize
;
696 minSize
+= GetBorderSize();
698 if ( sashPos
< minSize
)
705 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
706 : win
->GetMinHeight();
708 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
709 minSize
= m_minimumPaneSize
;
711 int maxSize
= window_size
- minSize
- GetBorderSize();
712 if ( sashPos
> maxSize
)
719 void wxSplitterWindow::DoSetSashPosition(int sashPos
)
721 m_requestedSashPosition
= sashPos
;
722 m_sashPosition
= sashPos
== 0 ? 0 : AdjustSashPosition(sashPos
);
724 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
, this);
725 event
.m_data
.pos
= m_sashPosition
;
727 (void)DoSendEvent(event
);
730 // Position and size subwindows.
731 // Note that the border size applies to each subwindow, not
732 // including the edges next to the sash.
733 void wxSplitterWindow::SizeWindows()
735 if ( m_requestedSashPosition
!= m_sashPosition
)
736 DoSetSashPosition(m_requestedSashPosition
);
739 GetClientSize(&w
, &h
);
741 if ( GetWindow1() && !GetWindow2() )
743 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
744 w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
746 else if ( GetWindow1() && GetWindow2() )
748 if (GetSplitMode() == wxSPLIT_VERTICAL
)
750 int x1
= GetBorderSize();
751 int y1
= GetBorderSize();
752 int w1
= GetSashPosition() - GetBorderSize();
753 int h1
= h
- 2*GetBorderSize();
755 int x2
= GetSashPosition() + GetSashSize();
756 int y2
= GetBorderSize();
757 int w2
= w
- 2*GetBorderSize() - GetSashSize() - w1
;
758 int h2
= h
- 2*GetBorderSize();
760 GetWindow1()->SetSize(x1
, y1
, w1
, h1
);
761 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
765 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
766 w
- 2*GetBorderSize(), GetSashPosition() - GetBorderSize());
767 GetWindow2()->SetSize(GetBorderSize(), GetSashPosition() + GetSashSize(),
768 w
- 2*GetBorderSize(), h
- 2*GetBorderSize() - GetSashSize() - (GetSashPosition() - GetBorderSize()));
772 if ( GetBorderSize() > 0 )
776 SetNeedUpdating(FALSE
);
779 // Set pane for unsplit window
780 void wxSplitterWindow::Initialize(wxWindow
*window
)
782 m_windowOne
= window
;
783 m_windowTwo
= (wxWindow
*) NULL
;
784 DoSetSashPosition(0);
787 // Associates the given window with window 2, drawing the appropriate sash
788 // and changing the split mode.
789 // Does nothing and returns FALSE if the window is already split.
790 bool wxSplitterWindow::DoSplit(wxSplitMode mode
,
791 wxWindow
*window1
, wxWindow
*window2
,
797 int window_size
= GetWindowSize();
800 m_windowOne
= window1
;
801 m_windowTwo
= window2
;
803 if ( sashPosition
> 0 )
805 DoSetSashPosition(sashPosition
);
807 else if ( sashPosition
< 0 )
809 // It's negative so adding is subtracting
810 DoSetSashPosition(window_size
+ sashPosition
);
815 DoSetSashPosition(window_size
/2);
823 // Remove the specified (or second) window from the view
824 // Doesn't actually delete the window.
825 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
830 wxWindow
*win
= NULL
;
831 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
834 m_windowTwo
= (wxWindow
*) NULL
;
836 else if ( toRemove
== m_windowOne
)
839 m_windowOne
= m_windowTwo
;
840 m_windowTwo
= (wxWindow
*) NULL
;
844 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
850 DoSetSashPosition(0);
856 // Replace a window with another one
857 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
859 wxCHECK_MSG( winOld
, FALSE
, wxT("use one of Split() functions instead") );
860 wxCHECK_MSG( winNew
, FALSE
, wxT("use Unsplit() functions instead") );
862 if ( winOld
== m_windowTwo
)
864 m_windowTwo
= winNew
;
866 else if ( winOld
== m_windowOne
)
868 m_windowOne
= winNew
;
872 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
882 void wxSplitterWindow::SetMinimumPaneSize(int min
)
884 m_minimumPaneSize
= min
;
885 SetSashPosition(m_sashPosition
); // re-check limits
888 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
890 DoSetSashPosition(position
);
898 // Initialize colours
899 void wxSplitterWindow::InitColours()
901 wxDELETE( m_facePen
);
902 wxDELETE( m_faceBrush
);
903 wxDELETE( m_mediumShadowPen
);
904 wxDELETE( m_darkShadowPen
);
905 wxDELETE( m_lightShadowPen
);
906 wxDELETE( m_hilightPen
);
910 wxColour
faceColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
911 m_facePen
= new wxPen(faceColour
, 1, wxSOLID
);
912 m_faceBrush
= new wxBrush(faceColour
, wxSOLID
);
914 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
915 m_mediumShadowPen
= new wxPen(mediumShadowColour
, 1, wxSOLID
);
917 wxColour
darkShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
));
918 m_darkShadowPen
= new wxPen(darkShadowColour
, 1, wxSOLID
);
920 wxColour
lightShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
));
921 m_lightShadowPen
= new wxPen(lightShadowColour
, 1, wxSOLID
);
923 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
924 m_hilightPen
= new wxPen(hilightColour
, 1, wxSOLID
);
926 m_facePen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
927 m_faceBrush
= new wxBrush("LIGHT GREY", wxSOLID
);
928 m_mediumShadowPen
= new wxPen("GREY", 1, wxSOLID
);
929 m_darkShadowPen
= new wxPen("BLACK", 1, wxSOLID
);
930 m_lightShadowPen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
931 m_hilightPen
= new wxPen("WHITE", 1, wxSOLID
);
935 bool wxSplitterWindow::DoSendEvent(wxSplitterEvent
& event
)
937 return !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed();
940 // ---------------------------------------------------------------------------
941 // wxSplitterWindow virtual functions: they now just generate the events
942 // ---------------------------------------------------------------------------
944 bool wxSplitterWindow::OnSashPositionChange(int WXUNUSED(newSashPosition
))
946 // always allow by default
950 int wxSplitterWindow::OnSashPositionChanging(int newSashPosition
)
952 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
953 const int UNSPLIT_THRESHOLD
= 4;
955 // first of all, check if OnSashPositionChange() doesn't forbid this change
956 if ( !OnSashPositionChange(newSashPosition
) )
962 // Obtain relevant window dimension for bottom / right threshold check
963 int window_size
= GetWindowSize();
965 bool unsplit_scenario
= FALSE
;
966 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
968 // Do edge detection if unsplit premitted
969 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
971 // threshold top / left check
973 unsplit_scenario
= TRUE
;
975 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
977 // threshold bottom/right check
978 newSashPosition
= window_size
;
979 unsplit_scenario
= TRUE
;
983 if ( !unsplit_scenario
)
985 // If resultant pane would be too small, enlarge it
986 newSashPosition
= AdjustSashPosition(newSashPosition
);
989 // If the result is out of bounds it means minimum size is too big,
990 // so split window in half as best compromise.
991 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
992 newSashPosition
= window_size
/ 2;
994 // now let the event handler have it
996 // FIXME: shouldn't we do it before the adjustments above so as to ensure
997 // that the sash position is always reasonable?
998 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
, this);
999 event
.m_data
.pos
= newSashPosition
;
1001 if ( !DoSendEvent(event
) )
1003 // the event handler vetoed the change
1004 newSashPosition
= -1;
1008 // it could have been changed by it
1009 newSashPosition
= event
.GetSashPosition();
1012 return newSashPosition
;
1015 // Called when the sash is double-clicked. The default behaviour is to remove
1016 // the sash if the minimum pane size is zero.
1017 void wxSplitterWindow::OnDoubleClickSash(int x
, int y
)
1019 // new code should handle events instead of using the virtual functions
1020 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
, this);
1021 event
.m_data
.pt
.x
= x
;
1022 event
.m_data
.pt
.y
= y
;
1023 if ( DoSendEvent(event
) )
1025 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
1030 //else: blocked by user
1033 void wxSplitterWindow::OnUnsplit(wxWindow
*winRemoved
)
1035 // do it before calling the event handler which may delete the window
1036 winRemoved
->Show(FALSE
);
1038 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
1039 event
.m_data
.win
= winRemoved
;
1041 (void)DoSendEvent(event
);
1046 // this is currently called (and needed) under MSW only...
1047 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& event
)
1049 // if we don't do it, the resizing cursor might be set for child window:
1050 // and like this we explicitly say that our cursor should not be used for
1051 // children windows which overlap us
1053 if ( SashHitTest(event
.GetX(), event
.GetY()) )
1055 // default processing is ok
1058 //else: do nothing, in particular, don't call Skip()