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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "splitter.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/string.h"
29 #include "wx/dcscreen.h"
31 #include "wx/window.h"
32 #include "wx/dialog.h"
35 #include "wx/settings.h"
38 #include "wx/splitter.h"
42 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
)
43 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
)
44 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
)
45 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_UNSPLIT
)
47 IMPLEMENT_DYNAMIC_CLASS(wxSplitterWindow
, wxWindow
)
48 IMPLEMENT_DYNAMIC_CLASS(wxSplitterEvent
, wxNotifyEvent
)
50 BEGIN_EVENT_TABLE(wxSplitterWindow
, wxWindow
)
51 EVT_PAINT(wxSplitterWindow::OnPaint
)
52 EVT_SIZE(wxSplitterWindow::OnSize
)
53 EVT_IDLE(wxSplitterWindow::OnIdle
)
54 EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent
)
56 #if defined( __WXMSW__ ) || defined( __WXMAC__)
57 EVT_SET_CURSOR(wxSplitterWindow::OnSetCursor
)
60 WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow
)
63 WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow
);
65 bool wxSplitterWindow::Create(wxWindow
*parent
, wxWindowID id
,
71 // allow TABbing from one window to the other
72 style
|= wxTAB_TRAVERSAL
;
74 if (!wxWindow::Create(parent
, id
, pos
, size
, style
, name
))
77 m_permitUnsplitAlways
= (style
& wxSP_PERMIT_UNSPLIT
) != 0;
79 if ( style
& wxSP_3DSASH
)
84 if ( style
& wxSP_3DBORDER
)
86 else if ( style
& wxSP_BORDER
)
93 wxGetOsVersion( &major
, &minor
);
95 m_windowStyle
|= wxSP_SASH_AQUA
;
101 void wxSplitterWindow::Init()
103 m_container
.SetContainerWindow(this);
105 m_splitMode
= wxSPLIT_VERTICAL
;
106 m_permitUnsplitAlways
= TRUE
;
107 m_windowOne
= (wxWindow
*) NULL
;
108 m_windowTwo
= (wxWindow
*) NULL
;
109 m_dragMode
= wxSPLIT_DRAG_NONE
;
116 m_sashPosition
= m_requestedSashPosition
= 0;
117 m_minimumPaneSize
= 0;
118 m_sashCursorWE
= wxCursor(wxCURSOR_SIZEWE
);
119 m_sashCursorNS
= wxCursor(wxCURSOR_SIZENS
);
120 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxSOLID
);
121 m_lightShadowPen
= (wxPen
*) NULL
;
122 m_mediumShadowPen
= (wxPen
*) NULL
;
123 m_darkShadowPen
= (wxPen
*) NULL
;
124 m_faceBrush
= (wxBrush
*) NULL
;
125 m_facePen
= (wxPen
*) NULL
;
126 m_hilightPen
= (wxPen
*) NULL
;
130 m_needUpdating
= FALSE
;
133 wxSplitterWindow::~wxSplitterWindow()
135 delete m_sashTrackerPen
;
136 delete m_lightShadowPen
;
137 delete m_darkShadowPen
;
138 delete m_mediumShadowPen
;
144 void wxSplitterWindow::SetResizeCursor()
146 SetCursor(m_splitMode
== wxSPLIT_VERTICAL
? m_sashCursorWE
150 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
154 if ( m_borderSize
> 0 )
159 void wxSplitterWindow::OnIdle(wxIdleEvent
& event
)
167 void wxSplitterWindow::OnMouseEvent(wxMouseEvent
& event
)
169 int x
= (int)event
.GetX(),
170 y
= (int)event
.GetY();
172 #if defined(__WXMSW__)
173 // SetCursor(wxCursor()); // Is this required?
176 if (GetWindowStyle() & wxSP_NOSASH
)
179 // with wxSP_LIVE_UPDATE style the splitter windows are always resized
180 // following the mouse movement while it drags the sash, without it we only
181 // draw the sash at the new position but only resize the windows when the
182 // dragging is finished
183 bool isLive
= (GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) != 0;
185 if (event
.LeftDown())
187 if ( SashHitTest(x
, y
) )
189 // Start the drag now
190 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
192 // Capture mouse and set the cursor
198 // remember the initial sash position and draw the initial
200 m_sashPositionCurrent
= m_sashPosition
;
202 DrawSashTracker(x
, y
);
212 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
214 // We can stop dragging now and see what we've got.
215 m_dragMode
= wxSPLIT_DRAG_NONE
;
217 // Release mouse and unset the cursor
219 SetCursor(* wxSTANDARD_CURSOR
);
221 // exit if unsplit after doubleclick
230 DrawSashTracker(m_oldX
, m_oldY
);
233 // the position of the click doesn't exactly correspond to
234 // m_sashPosition, rather it changes it by the distance by which the
236 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_oldX
: y
- m_oldY
;
238 int posSashOld
= isLive
? m_sashPosition
: m_sashPositionCurrent
;
239 int posSashNew
= OnSashPositionChanging(posSashOld
+ diff
);
240 if ( posSashNew
== -1 )
242 // change not allowed
246 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
248 // Deal with possible unsplit scenarios
249 if ( posSashNew
== 0 )
251 // We remove the first window from the view
252 wxWindow
*removedWindow
= m_windowOne
;
253 m_windowOne
= m_windowTwo
;
254 m_windowTwo
= (wxWindow
*) NULL
;
255 OnUnsplit(removedWindow
);
256 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
257 event
.m_data
.win
= removedWindow
;
258 (void)DoSendEvent(event
);
259 SetSashPositionAndNotify(0);
261 else if ( posSashNew
== GetWindowSize() )
263 // We remove the second window from the view
264 wxWindow
*removedWindow
= m_windowTwo
;
265 m_windowTwo
= (wxWindow
*) NULL
;
266 OnUnsplit(removedWindow
);
267 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
268 event
.m_data
.win
= removedWindow
;
269 (void)DoSendEvent(event
);
270 SetSashPositionAndNotify(0);
274 SetSashPositionAndNotify(posSashNew
);
279 SetSashPositionAndNotify(posSashNew
);
283 } // left up && dragging
284 else if ((event
.Moving() || event
.Leaving() || event
.Entering()) && (m_dragMode
== wxSPLIT_DRAG_NONE
))
286 // Just change the cursor as required
287 if ( !event
.Leaving() && SashHitTest(x
, y
) )
293 SetCursor(* wxSTANDARD_CURSOR
);
296 else if (event
.Dragging() && (m_dragMode
== wxSPLIT_DRAG_DRAGGING
))
298 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_oldX
: y
- m_oldY
;
301 // nothing to do, mouse didn't really move far enough
305 int posSashOld
= isLive
? m_sashPosition
: m_sashPositionCurrent
;
306 int posSashNew
= OnSashPositionChanging(posSashOld
+ diff
);
307 if ( posSashNew
== -1 )
309 // change not allowed
313 if ( posSashNew
== m_sashPosition
)
319 DrawSashTracker(m_oldX
, m_oldY
);
322 if (m_splitMode
== wxSPLIT_VERTICAL
)
327 // Remember old positions
332 // As we captured the mouse, we may get the mouse events from outside
333 // our window - for example, negative values in x, y. This has a weird
334 // consequence under MSW where we use unsigned values sometimes and
335 // signed ones other times: the coordinates turn as big positive
336 // numbers and so the sash is drawn on the *right* side of the window
337 // instead of the left (or bottom instead of top). Correct this.
338 if ( (short)m_oldX
< 0 )
340 if ( (short)m_oldY
< 0 )
347 m_sashPositionCurrent
= posSashNew
;
349 DrawSashTracker(m_oldX
, m_oldY
);
353 SetSashPositionAndNotify(posSashNew
);
354 m_needUpdating
= TRUE
;
357 else if ( event
.LeftDClick() && m_windowTwo
)
359 OnDoubleClickSash(x
, y
);
363 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
365 // only process this message if we're not iconized - otherwise iconizing
366 // and restoring a window containing the splitter has a funny side effect
367 // of changing the splitter position!
368 wxWindow
*parent
= GetParent();
369 while ( parent
&& !parent
->IsTopLevel() )
371 parent
= parent
->GetParent();
374 bool iconized
= FALSE
;
376 // wxMotif doesn't yet have a wxTopLevelWindow implementation
378 wxFrame
*winTop
= wxDynamicCast(parent
, wxFrame
);
380 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
384 iconized
= winTop
->IsIconized();
389 wxFAIL_MSG(wxT("should have a top level parent!"));
403 GetClientSize( &cw
, &ch
);
406 if ( m_splitMode
== wxSPLIT_VERTICAL
)
408 if ( m_sashPosition
>= (cw
- 5) )
409 SetSashPositionAndNotify(wxMax(10, cw
- 40));
411 else // m_splitMode == wxSPLIT_HORIZONTAL
413 if ( m_sashPosition
>= (ch
- 5) )
414 SetSashPositionAndNotify(wxMax(10, ch
- 40));
421 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
423 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
424 return FALSE
; // No sash
426 if ( m_splitMode
== wxSPLIT_VERTICAL
)
428 if ( (x
>= m_sashPosition
- tolerance
) && (x
<= m_sashPosition
+ m_sashSize
+ tolerance
) )
435 if ( (y
>= (m_sashPosition
- tolerance
)) && (y
<= (m_sashPosition
+ m_sashSize
+ tolerance
)) )
442 // Draw 3D effect borders
443 void wxSplitterWindow::DrawBorders(wxDC
& dc
)
446 GetClientSize(&w
, &h
);
448 if ( GetWindowStyleFlag() & wxSP_3DBORDER
)
451 dc
.SetPen(*m_facePen
);
452 dc
.SetBrush(*m_faceBrush
);
453 dc
.DrawRectangle(1, 1 , w
-1, m_borderSize
-2 ); //high
454 dc
.DrawRectangle(1, m_borderSize
-2 , m_borderSize
-2, h
-1 ); // left
455 dc
.DrawRectangle(w
-m_borderSize
+2, m_borderSize
-2 , w
-1, h
-1 ); // right
456 dc
.DrawRectangle(m_borderSize
-2, h
-m_borderSize
+2 , w
-m_borderSize
+2, h
-1 ); //bottom
458 dc
.SetPen(*m_mediumShadowPen
);
459 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, w
-m_borderSize
+1, m_borderSize
-2);
460 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, m_borderSize
-2, h
-m_borderSize
+1);
462 dc
.SetPen(*m_darkShadowPen
);
463 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, w
-m_borderSize
, m_borderSize
-1);
464 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, m_borderSize
-1, h
-m_borderSize
);
466 dc
.SetPen(*m_hilightPen
);
467 dc
.DrawLine(m_borderSize
- 2, h
-m_borderSize
+1, w
-m_borderSize
+1, h
-m_borderSize
+1);
468 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.
469 /// Anyway, h is required for MSW.
471 dc
.SetPen(*m_lightShadowPen
);
472 dc
.DrawLine(w
-m_borderSize
, m_borderSize
-1, w
-m_borderSize
, h
-m_borderSize
); // Right hand side
473 dc
.DrawLine(m_borderSize
-1, h
-m_borderSize
, w
-m_borderSize
+1, h
-m_borderSize
); // Bottom
475 else if ( GetWindowStyleFlag() & wxSP_BORDER
)
477 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
478 dc
.SetPen(*wxBLACK_PEN
);
479 dc
.DrawRectangle(0, 0, w
-1, h
-1);
482 dc
.SetPen(wxNullPen
);
483 dc
.SetBrush(wxNullBrush
);
487 void wxSplitterWindow::DrawSash(wxDC
& dc
)
489 if ( m_sashPosition
== 0 || !m_windowTwo
)
491 if (GetWindowStyle() & wxSP_NOSASH
)
495 GetClientSize(&w
, &h
);
497 if ( GetWindowStyleFlag() & wxSP_3DSASH
)
499 if ( m_splitMode
== wxSPLIT_VERTICAL
)
501 dc
.SetPen(*m_facePen
);
503 if (HasFlag( wxSP_SASH_AQUA
))
504 dc
.SetBrush(*wxWHITE_BRUSH
);
506 dc
.SetBrush(*m_faceBrush
);
507 dc
.DrawRectangle(m_sashPosition
+ 2, 0 , m_sashSize
- 4, h
);
509 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
511 dc
.SetPen(*m_lightShadowPen
);
512 int xShadow
= m_borderSize
? m_borderSize
- 1 : 0 ;
513 dc
.DrawLine(m_sashPosition
, xShadow
, m_sashPosition
, h
-m_borderSize
);
515 dc
.SetPen(*m_hilightPen
);
516 dc
.DrawLine(m_sashPosition
+1, m_borderSize
- 2, m_sashPosition
+1, h
- m_borderSize
+2);
518 if (!HasFlag( wxSP_SASH_AQUA
))
519 dc
.SetPen(*m_mediumShadowPen
);
521 int yMedium
= m_borderSize
? h
-m_borderSize
+1 : h
;
522 dc
.DrawLine(m_sashPosition
+m_sashSize
-2, xShadow
, m_sashPosition
+m_sashSize
-2, yMedium
);
524 if (HasFlag( wxSP_SASH_AQUA
))
525 dc
.SetPen(*m_lightShadowPen
);
527 dc
.SetPen(*m_darkShadowPen
);
528 dc
.DrawLine(m_sashPosition
+m_sashSize
-1, m_borderSize
, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
);
530 // Draw the top and bottom edges of the sash, if requested
531 if (GetWindowStyle() & wxSP_FULLSASH
)
534 dc
.SetPen(*m_hilightPen
);
535 dc
.DrawLine(m_sashPosition
+1, m_borderSize
, m_sashPosition
+m_sashSize
-1, m_borderSize
);
538 dc
.SetPen(*m_darkShadowPen
);
539 dc
.DrawLine(m_sashPosition
+1, h
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
-1);
542 else // wxSPLIT_HORIZONTAL
544 dc
.SetPen(*m_facePen
);
545 if (HasFlag( wxSP_SASH_AQUA
))
546 dc
.SetBrush(*wxWHITE_BRUSH
);
548 dc
.SetBrush(*m_faceBrush
);
549 dc
.DrawRectangle( m_borderSize
-2, m_sashPosition
+ 2, w
-m_borderSize
+2, m_sashSize
- 4);
551 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
553 dc
.SetPen(*m_lightShadowPen
);
554 dc
.DrawLine(m_borderSize
-1, m_sashPosition
, w
-m_borderSize
, m_sashPosition
);
556 dc
.SetPen(*m_hilightPen
);
557 dc
.DrawLine(m_borderSize
-2, m_sashPosition
+1, w
-m_borderSize
+1, m_sashPosition
+1);
559 if (!HasFlag( wxSP_SASH_AQUA
))
560 dc
.SetPen(*m_mediumShadowPen
);
561 dc
.DrawLine(m_borderSize
-1, m_sashPosition
+m_sashSize
-2, w
-m_borderSize
+1, m_sashPosition
+m_sashSize
-2);
563 if (HasFlag( wxSP_SASH_AQUA
))
564 dc
.SetPen(*m_lightShadowPen
);
566 dc
.SetPen(*m_darkShadowPen
);
567 dc
.DrawLine(m_borderSize
, m_sashPosition
+m_sashSize
-1, w
-m_borderSize
, m_sashPosition
+m_sashSize
-1);
569 // Draw the left and right edges of the sash, if requested
570 if (GetWindowStyle() & wxSP_FULLSASH
)
573 dc
.SetPen(*m_hilightPen
);
574 dc
.DrawLine(m_borderSize
, m_sashPosition
, m_borderSize
, m_sashPosition
+m_sashSize
);
577 dc
.SetPen(*m_darkShadowPen
);
578 dc
.DrawLine(w
-m_borderSize
-1, m_sashPosition
+1, w
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1);
584 dc
.SetPen(*wxTRANSPARENT_PEN
);
585 dc
.SetBrush(*m_faceBrush
);
586 if ( m_splitMode
== wxSPLIT_VERTICAL
)
590 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
591 h1
+= 1; // Not sure why this is necessary...
592 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
596 dc
.DrawRectangle(m_sashPosition
, y1
, m_sashSize
, h1
);
598 else // wxSPLIT_HORIZONTAL
602 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
604 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
608 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 bool wxSplitterWindow::DoSetSashPosition(int sashPos
)
721 int newSashPosition
= AdjustSashPosition(sashPos
);
723 if ( newSashPosition
== m_sashPosition
)
726 m_sashPosition
= newSashPosition
;
731 void wxSplitterWindow::SetSashPositionAndNotify(int sashPos
)
733 if ( DoSetSashPosition(sashPos
) )
735 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
, this);
736 event
.m_data
.pos
= m_sashPosition
;
738 (void)DoSendEvent(event
);
742 // Position and size subwindows.
743 // Note that the border size applies to each subwindow, not
744 // including the edges next to the sash.
745 void wxSplitterWindow::SizeWindows()
747 // check if we have delayed setting the real sash position
748 if ( m_requestedSashPosition
!= INT_MAX
)
750 int newSashPosition
= ConvertSashPosition(m_requestedSashPosition
);
751 if ( newSashPosition
!= m_sashPosition
)
753 DoSetSashPosition(newSashPosition
);
756 if ( newSashPosition
<= m_sashPosition
757 && newSashPosition
>= m_sashPosition
- GetBorderSize() )
759 // don't update it any more
760 m_requestedSashPosition
= INT_MAX
;
765 GetClientSize(&w
, &h
);
767 if ( GetWindow1() && !GetWindow2() )
769 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
770 w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
772 else if ( GetWindow1() && GetWindow2() )
774 if (GetSplitMode() == wxSPLIT_VERTICAL
)
776 int x1
= GetBorderSize();
777 int y1
= GetBorderSize();
778 int w1
= GetSashPosition() - GetBorderSize();
779 int h1
= h
- 2*GetBorderSize();
781 int x2
= GetSashPosition() + GetSashSize();
782 int y2
= GetBorderSize();
783 int w2
= w
- 2*GetBorderSize() - GetSashSize() - w1
;
784 int h2
= h
- 2*GetBorderSize();
786 GetWindow1()->SetSize(x1
, y1
, w1
, h1
);
787 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
791 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
792 w
- 2*GetBorderSize(), GetSashPosition() - GetBorderSize());
793 GetWindow2()->SetSize(GetBorderSize(), GetSashPosition() + GetSashSize(),
794 w
- 2*GetBorderSize(), h
- 2*GetBorderSize() - GetSashSize() - (GetSashPosition() - GetBorderSize()));
798 if ( GetBorderSize() > 0 )
802 SetNeedUpdating(FALSE
);
805 // Set pane for unsplit window
806 void wxSplitterWindow::Initialize(wxWindow
*window
)
808 wxASSERT_MSG( window
&& window
->GetParent() == this,
809 _T("windows in the splitter should have it as parent!") );
811 m_windowOne
= window
;
812 m_windowTwo
= (wxWindow
*) NULL
;
813 DoSetSashPosition(0);
816 // Associates the given window with window 2, drawing the appropriate sash
817 // and changing the split mode.
818 // Does nothing and returns FALSE if the window is already split.
819 bool wxSplitterWindow::DoSplit(wxSplitMode mode
,
820 wxWindow
*window1
, wxWindow
*window2
,
826 wxCHECK_MSG( window1
&& window2
, FALSE
,
827 _T("can not split with NULL window(s)") );
829 wxCHECK_MSG( window1
->GetParent() == this && window2
->GetParent() == this, FALSE
,
830 _T("windows in the splitter should have it as parent!") );
833 m_windowOne
= window1
;
834 m_windowTwo
= window2
;
836 // remember the sash position we want to set for later if we can't set it
837 // right now (e.g. because the window is too small)
838 m_requestedSashPosition
= sashPosition
;
840 DoSetSashPosition(ConvertSashPosition(sashPosition
));
847 int wxSplitterWindow::ConvertSashPosition(int sashPosition
) const
849 if ( sashPosition
> 0 )
853 else if ( sashPosition
< 0 )
855 // It's negative so adding is subtracting
856 return GetWindowSize() + sashPosition
;
858 else // sashPosition == 0
860 // default, put it in the centre
861 return GetWindowSize() / 2;
865 // Remove the specified (or second) window from the view
866 // Doesn't actually delete the window.
867 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
872 wxWindow
*win
= NULL
;
873 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
876 m_windowTwo
= (wxWindow
*) NULL
;
878 else if ( toRemove
== m_windowOne
)
881 m_windowOne
= m_windowTwo
;
882 m_windowTwo
= (wxWindow
*) NULL
;
886 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
892 DoSetSashPosition(0);
898 // Replace a window with another one
899 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
901 wxCHECK_MSG( winOld
, FALSE
, wxT("use one of Split() functions instead") );
902 wxCHECK_MSG( winNew
, FALSE
, wxT("use Unsplit() functions instead") );
904 if ( winOld
== m_windowTwo
)
906 m_windowTwo
= winNew
;
908 else if ( winOld
== m_windowOne
)
910 m_windowOne
= winNew
;
914 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
924 void wxSplitterWindow::SetMinimumPaneSize(int min
)
926 m_minimumPaneSize
= min
;
927 SetSashPosition(m_sashPosition
); // re-check limits
930 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
932 DoSetSashPosition(position
);
940 // Initialize colours
941 void wxSplitterWindow::InitColours()
943 wxDELETE( m_facePen
);
944 wxDELETE( m_faceBrush
);
945 wxDELETE( m_mediumShadowPen
);
946 wxDELETE( m_darkShadowPen
);
947 wxDELETE( m_lightShadowPen
);
948 wxDELETE( m_hilightPen
);
952 wxColour
faceColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
953 m_facePen
= new wxPen(faceColour
, 1, wxSOLID
);
954 m_faceBrush
= new wxBrush(faceColour
, wxSOLID
);
956 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
957 m_mediumShadowPen
= new wxPen(mediumShadowColour
, 1, wxSOLID
);
959 wxColour
darkShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
));
960 m_darkShadowPen
= new wxPen(darkShadowColour
, 1, wxSOLID
);
962 wxColour
lightShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
));
963 m_lightShadowPen
= new wxPen(lightShadowColour
, 1, wxSOLID
);
965 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
966 m_hilightPen
= new wxPen(hilightColour
, 1, wxSOLID
);
968 m_facePen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
969 m_faceBrush
= new wxBrush("LIGHT GREY", wxSOLID
);
970 m_mediumShadowPen
= new wxPen("GREY", 1, wxSOLID
);
971 m_darkShadowPen
= new wxPen("BLACK", 1, wxSOLID
);
972 m_lightShadowPen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
973 m_hilightPen
= new wxPen("WHITE", 1, wxSOLID
);
977 bool wxSplitterWindow::DoSendEvent(wxSplitterEvent
& event
)
979 return !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed();
982 // ---------------------------------------------------------------------------
983 // wxSplitterWindow virtual functions: they now just generate the events
984 // ---------------------------------------------------------------------------
986 bool wxSplitterWindow::OnSashPositionChange(int WXUNUSED(newSashPosition
))
988 // always allow by default
992 int wxSplitterWindow::OnSashPositionChanging(int newSashPosition
)
994 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
995 const int UNSPLIT_THRESHOLD
= 4;
997 // first of all, check if OnSashPositionChange() doesn't forbid this change
998 if ( !OnSashPositionChange(newSashPosition
) )
1004 // Obtain relevant window dimension for bottom / right threshold check
1005 int window_size
= GetWindowSize();
1007 bool unsplit_scenario
= FALSE
;
1008 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
1010 // Do edge detection if unsplit premitted
1011 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
1013 // threshold top / left check
1014 newSashPosition
= 0;
1015 unsplit_scenario
= TRUE
;
1017 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
1019 // threshold bottom/right check
1020 newSashPosition
= window_size
;
1021 unsplit_scenario
= TRUE
;
1025 if ( !unsplit_scenario
)
1027 // If resultant pane would be too small, enlarge it
1028 newSashPosition
= AdjustSashPosition(newSashPosition
);
1031 // If the result is out of bounds it means minimum size is too big,
1032 // so split window in half as best compromise.
1033 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
1034 newSashPosition
= window_size
/ 2;
1036 // now let the event handler have it
1038 // FIXME: shouldn't we do it before the adjustments above so as to ensure
1039 // that the sash position is always reasonable?
1040 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
, this);
1041 event
.m_data
.pos
= newSashPosition
;
1043 if ( !DoSendEvent(event
) )
1045 // the event handler vetoed the change
1046 newSashPosition
= -1;
1050 // it could have been changed by it
1051 newSashPosition
= event
.GetSashPosition();
1054 return newSashPosition
;
1057 // Called when the sash is double-clicked. The default behaviour is to remove
1058 // the sash if the minimum pane size is zero.
1059 void wxSplitterWindow::OnDoubleClickSash(int x
, int y
)
1061 wxCHECK_RET(m_windowTwo
, wxT("splitter: no window to remove"));
1063 // new code should handle events instead of using the virtual functions
1064 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
, this);
1065 event
.m_data
.pt
.x
= x
;
1066 event
.m_data
.pt
.y
= y
;
1067 if ( DoSendEvent(event
) )
1069 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
1071 wxWindow
* win
= m_windowTwo
;
1074 wxSplitterEvent
unsplitEvent(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
1075 unsplitEvent
.m_data
.win
= win
;
1076 (void)DoSendEvent(unsplitEvent
);
1080 //else: blocked by user
1083 void wxSplitterWindow::OnUnsplit(wxWindow
*winRemoved
)
1085 // call this before calling the event handler which may delete the window
1086 winRemoved
->Show(FALSE
);
1089 #if defined( __WXMSW__ ) || defined( __WXMAC__)
1091 // this is currently called (and needed) under MSW only...
1092 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& event
)
1094 // if we don't do it, the resizing cursor might be set for child window:
1095 // and like this we explicitly say that our cursor should not be used for
1096 // children windows which overlap us
1098 if ( SashHitTest(event
.GetX(), event
.GetY()) )
1100 // default processing is ok
1103 //else: do nothing, in particular, don't call Skip()
1106 #endif // wxUSE_SPLITTER