1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/splitter.cpp
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/string.h"
28 #include "wx/dcscreen.h"
30 #include "wx/window.h"
31 #include "wx/dialog.h"
34 #include "wx/settings.h"
37 #include "wx/splitter.h"
41 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
)
42 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
)
43 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
)
44 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_UNSPLIT
)
46 IMPLEMENT_DYNAMIC_CLASS(wxSplitterWindow
, wxWindow
)
47 IMPLEMENT_DYNAMIC_CLASS(wxSplitterEvent
, wxNotifyEvent
)
49 BEGIN_EVENT_TABLE(wxSplitterWindow
, wxWindow
)
50 EVT_PAINT(wxSplitterWindow::OnPaint
)
51 EVT_SIZE(wxSplitterWindow::OnSize
)
52 EVT_IDLE(wxSplitterWindow::OnIdle
)
53 EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent
)
56 EVT_SET_CURSOR(wxSplitterWindow::OnSetCursor
)
59 WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow
)
62 WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow
);
64 bool wxSplitterWindow::Create(wxWindow
*parent
, wxWindowID id
,
70 // allow TABbing from one window to the other
71 style
|= wxTAB_TRAVERSAL
;
73 if (!wxWindow::Create(parent
, id
, pos
, size
, style
, name
))
76 m_permitUnsplitAlways
= (style
& wxSP_PERMIT_UNSPLIT
) != 0;
78 if ( style
& wxSP_3DSASH
)
83 if ( style
& wxSP_3DBORDER
)
85 else if ( style
& wxSP_BORDER
)
92 wxGetOsVersion( &major
, &minor
);
94 m_windowStyle
|= wxSP_SASH_AQUA
;
100 void wxSplitterWindow::Init()
102 m_container
.SetContainerWindow(this);
104 m_splitMode
= wxSPLIT_VERTICAL
;
105 m_permitUnsplitAlways
= TRUE
;
106 m_windowOne
= (wxWindow
*) NULL
;
107 m_windowTwo
= (wxWindow
*) NULL
;
108 m_dragMode
= wxSPLIT_DRAG_NONE
;
115 m_sashPosition
= m_requestedSashPosition
= 0;
116 m_minimumPaneSize
= 0;
117 m_sashCursorWE
= wxCursor(wxCURSOR_SIZEWE
);
118 m_sashCursorNS
= wxCursor(wxCURSOR_SIZENS
);
119 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxSOLID
);
120 m_lightShadowPen
= (wxPen
*) NULL
;
121 m_mediumShadowPen
= (wxPen
*) NULL
;
122 m_darkShadowPen
= (wxPen
*) NULL
;
123 m_faceBrush
= (wxBrush
*) NULL
;
124 m_facePen
= (wxPen
*) NULL
;
125 m_hilightPen
= (wxPen
*) NULL
;
129 m_needUpdating
= FALSE
;
132 wxSplitterWindow::~wxSplitterWindow()
134 delete m_sashTrackerPen
;
135 delete m_lightShadowPen
;
136 delete m_darkShadowPen
;
137 delete m_mediumShadowPen
;
143 void wxSplitterWindow::SetResizeCursor()
145 SetCursor(m_splitMode
== wxSPLIT_VERTICAL
? m_sashCursorWE
149 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
153 if ( m_borderSize
> 0 )
158 void wxSplitterWindow::OnIdle(wxIdleEvent
& event
)
166 void wxSplitterWindow::OnMouseEvent(wxMouseEvent
& event
)
168 int x
= (int)event
.GetX(),
169 y
= (int)event
.GetY();
172 #if defined( __WXMOTIF__ ) || defined( __WXGTK__ ) || defined( __WXMAC__ )
173 SetCursor(* wxSTANDARD_CURSOR
);
174 #elif defined(__WXMSW__)
175 SetCursor(wxCursor());
178 if (GetWindowStyle() & wxSP_NOSASH
)
181 // with wxSP_LIVE_UPDATE style the splitter windows are always resized
182 // following the mouse movement while it drags the sash, without it we only
183 // draw the sash at the new position but only resize the windows when the
184 // dragging is finished
185 bool isLive
= (GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) != 0;
187 if (event
.LeftDown())
189 if ( SashHitTest(x
, y
) )
193 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
197 // remember the initial sash position and draw the initial
199 m_sashPositionCurrent
= m_sashPosition
;
201 DrawSashTracker(x
, y
);
211 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
213 // We can stop dragging now and see what we've got.
214 m_dragMode
= wxSPLIT_DRAG_NONE
;
217 // exit if unsplit after doubleclick
226 DrawSashTracker(m_oldX
, m_oldY
);
229 // the position of the click doesn't exactly correspond to
230 // m_sashPosition, rather it changes it by the distance by which the
232 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_oldX
: y
- m_oldY
;
234 int posSashOld
= isLive
? m_sashPosition
: m_sashPositionCurrent
;
235 int posSashNew
= OnSashPositionChanging(posSashOld
+ diff
);
236 if ( posSashNew
== -1 )
238 // change not allowed
242 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
244 // Deal with possible unsplit scenarios
245 if ( posSashNew
== 0 )
247 // We remove the first window from the view
248 wxWindow
*removedWindow
= m_windowOne
;
249 m_windowOne
= m_windowTwo
;
250 m_windowTwo
= (wxWindow
*) NULL
;
251 OnUnsplit(removedWindow
);
252 SetSashPositionAndNotify(0);
254 else if ( posSashNew
== GetWindowSize() )
256 // We remove the second window from the view
257 wxWindow
*removedWindow
= m_windowTwo
;
258 m_windowTwo
= (wxWindow
*) NULL
;
259 OnUnsplit(removedWindow
);
260 SetSashPositionAndNotify(0);
264 SetSashPositionAndNotify(posSashNew
);
269 SetSashPositionAndNotify(posSashNew
);
273 } // left up && dragging
274 else if (event
.Moving() && !event
.Dragging())
276 // Just change the cursor if required
277 if ( SashHitTest(x
, y
) )
281 #if defined(__WXGTK__) || defined(__WXMSW__) || defined(__WXMAC__)
284 // We must set the normal cursor in MSW, because
285 // if the child window doesn't have a cursor, the
286 // parent's (splitter window) will be used, and this
287 // must be the standard cursor.
289 // where else do we unset the cursor?
290 SetCursor(* wxSTANDARD_CURSOR
);
294 else if (event
.Dragging() && (m_dragMode
== wxSPLIT_DRAG_DRAGGING
))
296 #if defined( __WXMSW__ ) || defined( __WXMAC__ )
297 // Otherwise, the cursor sometimes reverts to the normal cursor
302 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_oldX
: y
- m_oldY
;
305 // nothing to do, mouse didn't really move far enough
309 int posSashOld
= isLive
? m_sashPosition
: m_sashPositionCurrent
;
310 int posSashNew
= OnSashPositionChanging(posSashOld
+ diff
);
311 if ( posSashNew
== -1 )
313 // change not allowed
317 if ( posSashNew
== m_sashPosition
)
323 DrawSashTracker(m_oldX
, m_oldY
);
326 if (m_splitMode
== wxSPLIT_VERTICAL
)
331 // Remember old positions
336 // As we captured the mouse, we may get the mouse events from outside
337 // our window - for example, negative values in x, y. This has a weird
338 // consequence under MSW where we use unsigned values sometimes and
339 // signed ones other times: the coordinates turn as big positive
340 // numbers and so the sash is drawn on the *right* side of the window
341 // instead of the left (or bottom instead of top). Correct this.
342 if ( (short)m_oldX
< 0 )
344 if ( (short)m_oldY
< 0 )
351 m_sashPositionCurrent
= posSashNew
;
353 DrawSashTracker(m_oldX
, m_oldY
);
357 SetSashPositionAndNotify(posSashNew
);
358 m_needUpdating
= TRUE
;
361 else if ( event
.LeftDClick() )
363 OnDoubleClickSash(x
, y
);
367 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
369 // only process this message if we're not iconized - otherwise iconizing
370 // and restoring a window containing the splitter has a funny side effect
371 // of changing the splitter position!
372 wxWindow
*parent
= GetParent();
373 while ( parent
&& !parent
->IsTopLevel() )
375 parent
= parent
->GetParent();
378 bool iconized
= FALSE
;
380 // wxMotif doesn't yet have a wxTopLevelWindow implementation
382 wxFrame
*winTop
= wxDynamicCast(parent
, wxFrame
);
384 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
388 iconized
= winTop
->IsIconized();
393 wxFAIL_MSG(wxT("should have a top level parent!"));
407 GetClientSize( &cw
, &ch
);
410 if ( m_splitMode
== wxSPLIT_VERTICAL
)
412 if ( m_sashPosition
>= (cw
- 5) )
413 SetSashPositionAndNotify(wxMax(10, cw
- 40));
415 else // m_splitMode == wxSPLIT_HORIZONTAL
417 if ( m_sashPosition
>= (ch
- 5) )
418 SetSashPositionAndNotify(wxMax(10, ch
- 40));
425 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
427 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
428 return FALSE
; // No sash
430 if ( m_splitMode
== wxSPLIT_VERTICAL
)
432 if ( (x
>= m_sashPosition
- tolerance
) && (x
<= m_sashPosition
+ m_sashSize
+ tolerance
) )
439 if ( (y
>= (m_sashPosition
- tolerance
)) && (y
<= (m_sashPosition
+ m_sashSize
+ tolerance
)) )
446 // Draw 3D effect borders
447 void wxSplitterWindow::DrawBorders(wxDC
& dc
)
450 GetClientSize(&w
, &h
);
452 if ( GetWindowStyleFlag() & wxSP_3DBORDER
)
455 dc
.SetPen(*m_facePen
);
456 dc
.SetBrush(*m_faceBrush
);
457 dc
.DrawRectangle(1, 1 , w
-1, m_borderSize
-2 ); //high
458 dc
.DrawRectangle(1, m_borderSize
-2 , m_borderSize
-2, h
-1 ); // left
459 dc
.DrawRectangle(w
-m_borderSize
+2, m_borderSize
-2 , w
-1, h
-1 ); // right
460 dc
.DrawRectangle(m_borderSize
-2, h
-m_borderSize
+2 , w
-m_borderSize
+2, h
-1 ); //bottom
462 dc
.SetPen(*m_mediumShadowPen
);
463 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, w
-m_borderSize
+1, m_borderSize
-2);
464 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, m_borderSize
-2, h
-m_borderSize
+1);
466 dc
.SetPen(*m_darkShadowPen
);
467 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, w
-m_borderSize
, m_borderSize
-1);
468 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, m_borderSize
-1, h
-m_borderSize
);
470 dc
.SetPen(*m_hilightPen
);
471 dc
.DrawLine(m_borderSize
- 2, h
-m_borderSize
+1, w
-m_borderSize
+1, h
-m_borderSize
+1);
472 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.
473 /// Anyway, h is required for MSW.
475 dc
.SetPen(*m_lightShadowPen
);
476 dc
.DrawLine(w
-m_borderSize
, m_borderSize
-1, w
-m_borderSize
, h
-m_borderSize
); // Right hand side
477 dc
.DrawLine(m_borderSize
-1, h
-m_borderSize
, w
-m_borderSize
+1, h
-m_borderSize
); // Bottom
479 else if ( GetWindowStyleFlag() & wxSP_BORDER
)
481 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
482 dc
.SetPen(*wxBLACK_PEN
);
483 dc
.DrawRectangle(0, 0, w
-1, h
-1);
486 dc
.SetPen(wxNullPen
);
487 dc
.SetBrush(wxNullBrush
);
491 void wxSplitterWindow::DrawSash(wxDC
& dc
)
493 if ( m_sashPosition
== 0 || !m_windowTwo
)
495 if (GetWindowStyle() & wxSP_NOSASH
)
499 GetClientSize(&w
, &h
);
501 if ( GetWindowStyleFlag() & wxSP_3DSASH
)
503 if ( m_splitMode
== wxSPLIT_VERTICAL
)
505 dc
.SetPen(*m_facePen
);
507 if (HasFlag( wxSP_SASH_AQUA
))
508 dc
.SetBrush(*wxWHITE_BRUSH
);
510 dc
.SetBrush(*m_faceBrush
);
511 dc
.DrawRectangle(m_sashPosition
+ 2, 0 , m_sashSize
- 4, h
);
513 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
515 dc
.SetPen(*m_lightShadowPen
);
516 int xShadow
= m_borderSize
? m_borderSize
- 1 : 0 ;
517 dc
.DrawLine(m_sashPosition
, xShadow
, m_sashPosition
, h
-m_borderSize
);
519 dc
.SetPen(*m_hilightPen
);
520 dc
.DrawLine(m_sashPosition
+1, m_borderSize
- 2, m_sashPosition
+1, h
- m_borderSize
+2);
522 if (!HasFlag( wxSP_SASH_AQUA
))
523 dc
.SetPen(*m_mediumShadowPen
);
525 int yMedium
= m_borderSize
? h
-m_borderSize
+1 : h
;
526 dc
.DrawLine(m_sashPosition
+m_sashSize
-2, xShadow
, m_sashPosition
+m_sashSize
-2, yMedium
);
528 if (HasFlag( wxSP_SASH_AQUA
))
529 dc
.SetPen(*m_lightShadowPen
);
531 dc
.SetPen(*m_darkShadowPen
);
532 dc
.DrawLine(m_sashPosition
+m_sashSize
-1, m_borderSize
, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
);
534 // Draw the top and bottom edges of the sash, if requested
535 if (GetWindowStyle() & wxSP_FULLSASH
)
538 dc
.SetPen(*m_hilightPen
);
539 dc
.DrawLine(m_sashPosition
+1, m_borderSize
, m_sashPosition
+m_sashSize
-1, m_borderSize
);
542 dc
.SetPen(*m_darkShadowPen
);
543 dc
.DrawLine(m_sashPosition
+1, h
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
-1);
546 else // wxSPLIT_HORIZONTAL
548 dc
.SetPen(*m_facePen
);
549 if (HasFlag( wxSP_SASH_AQUA
))
550 dc
.SetBrush(*wxWHITE_BRUSH
);
552 dc
.SetBrush(*m_faceBrush
);
553 dc
.DrawRectangle( m_borderSize
-2, m_sashPosition
+ 2, w
-m_borderSize
+2, m_sashSize
- 4);
555 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
557 dc
.SetPen(*m_lightShadowPen
);
558 dc
.DrawLine(m_borderSize
-1, m_sashPosition
, w
-m_borderSize
, m_sashPosition
);
560 dc
.SetPen(*m_hilightPen
);
561 dc
.DrawLine(m_borderSize
-2, m_sashPosition
+1, w
-m_borderSize
+1, m_sashPosition
+1);
563 if (!HasFlag( wxSP_SASH_AQUA
))
564 dc
.SetPen(*m_mediumShadowPen
);
565 dc
.DrawLine(m_borderSize
-1, m_sashPosition
+m_sashSize
-2, w
-m_borderSize
+1, m_sashPosition
+m_sashSize
-2);
567 if (HasFlag( wxSP_SASH_AQUA
))
568 dc
.SetPen(*m_lightShadowPen
);
570 dc
.SetPen(*m_darkShadowPen
);
571 dc
.DrawLine(m_borderSize
, m_sashPosition
+m_sashSize
-1, w
-m_borderSize
, m_sashPosition
+m_sashSize
-1);
573 // Draw the left and right edges of the sash, if requested
574 if (GetWindowStyle() & wxSP_FULLSASH
)
577 dc
.SetPen(*m_hilightPen
);
578 dc
.DrawLine(m_borderSize
, m_sashPosition
, m_borderSize
, m_sashPosition
+m_sashSize
);
581 dc
.SetPen(*m_darkShadowPen
);
582 dc
.DrawLine(w
-m_borderSize
-1, m_sashPosition
+1, w
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1);
588 dc
.SetPen(*wxTRANSPARENT_PEN
);
589 dc
.SetBrush(*m_faceBrush
);
590 if ( m_splitMode
== wxSPLIT_VERTICAL
)
594 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
595 h1
+= 1; // Not sure why this is necessary...
596 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
600 dc
.DrawRectangle(m_sashPosition
, y1
, m_sashSize
, h1
);
602 else // wxSPLIT_HORIZONTAL
606 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
608 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
612 dc
.DrawRectangle(x1
, m_sashPosition
, w1
, m_sashSize
);
616 dc
.SetPen(wxNullPen
);
617 dc
.SetBrush(wxNullBrush
);
620 // Draw the sash tracker (for whilst moving the sash)
621 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
624 GetClientSize(&w
, &h
);
630 if ( m_splitMode
== wxSPLIT_VERTICAL
)
661 ClientToScreen(&x1
, &y1
);
662 ClientToScreen(&x2
, &y2
);
664 screenDC
.SetLogicalFunction(wxINVERT
);
665 screenDC
.SetPen(*m_sashTrackerPen
);
666 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
668 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
670 screenDC
.SetLogicalFunction(wxCOPY
);
672 screenDC
.SetPen(wxNullPen
);
673 screenDC
.SetBrush(wxNullBrush
);
676 int wxSplitterWindow::GetWindowSize() const
678 wxSize size
= GetClientSize();
680 return m_splitMode
== wxSPLIT_VERTICAL
? size
.x
: size
.y
;
683 int wxSplitterWindow::AdjustSashPosition(int sashPos
) const
685 int window_size
= GetWindowSize();
692 // the window shouldn't be smaller than its own minimal size nor
693 // smaller than the minimual pane size specified for this splitter
694 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
695 : win
->GetMinHeight();
697 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
698 minSize
= m_minimumPaneSize
;
700 minSize
+= GetBorderSize();
702 if ( sashPos
< minSize
)
709 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
710 : win
->GetMinHeight();
712 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
713 minSize
= m_minimumPaneSize
;
715 int maxSize
= window_size
- minSize
- GetBorderSize();
716 if ( sashPos
> maxSize
)
723 bool wxSplitterWindow::DoSetSashPosition(int sashPos
)
725 int newSashPosition
= AdjustSashPosition(sashPos
);
727 if ( newSashPosition
== m_sashPosition
)
730 m_sashPosition
= newSashPosition
;
735 void wxSplitterWindow::SetSashPositionAndNotify(int sashPos
)
737 if ( DoSetSashPosition(sashPos
) )
739 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
, this);
740 event
.m_data
.pos
= m_sashPosition
;
742 (void)DoSendEvent(event
);
746 // Position and size subwindows.
747 // Note that the border size applies to each subwindow, not
748 // including the edges next to the sash.
749 void wxSplitterWindow::SizeWindows()
751 // check if we have delayed setting the real sash position
752 if ( m_requestedSashPosition
!= INT_MAX
)
754 int newSashPosition
= ConvertSashPosition(m_requestedSashPosition
);
755 if ( newSashPosition
!= m_sashPosition
)
757 DoSetSashPosition(newSashPosition
);
760 if ( newSashPosition
<= m_sashPosition
761 && newSashPosition
>= m_sashPosition
- GetBorderSize() )
763 // don't update it any more
764 m_requestedSashPosition
= INT_MAX
;
769 GetClientSize(&w
, &h
);
771 if ( GetWindow1() && !GetWindow2() )
773 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
774 w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
776 else if ( GetWindow1() && GetWindow2() )
778 if (GetSplitMode() == wxSPLIT_VERTICAL
)
780 int x1
= GetBorderSize();
781 int y1
= GetBorderSize();
782 int w1
= GetSashPosition() - GetBorderSize();
783 int h1
= h
- 2*GetBorderSize();
785 int x2
= GetSashPosition() + GetSashSize();
786 int y2
= GetBorderSize();
787 int w2
= w
- 2*GetBorderSize() - GetSashSize() - w1
;
788 int h2
= h
- 2*GetBorderSize();
790 GetWindow1()->SetSize(x1
, y1
, w1
, h1
);
791 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
795 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
796 w
- 2*GetBorderSize(), GetSashPosition() - GetBorderSize());
797 GetWindow2()->SetSize(GetBorderSize(), GetSashPosition() + GetSashSize(),
798 w
- 2*GetBorderSize(), h
- 2*GetBorderSize() - GetSashSize() - (GetSashPosition() - GetBorderSize()));
802 if ( GetBorderSize() > 0 )
806 SetNeedUpdating(FALSE
);
809 // Set pane for unsplit window
810 void wxSplitterWindow::Initialize(wxWindow
*window
)
812 wxASSERT_MSG( window
&& window
->GetParent() == this,
813 _T("windows in the splitter should have it as parent!") );
815 m_windowOne
= window
;
816 m_windowTwo
= (wxWindow
*) NULL
;
817 DoSetSashPosition(0);
820 // Associates the given window with window 2, drawing the appropriate sash
821 // and changing the split mode.
822 // Does nothing and returns FALSE if the window is already split.
823 bool wxSplitterWindow::DoSplit(wxSplitMode mode
,
824 wxWindow
*window1
, wxWindow
*window2
,
830 wxCHECK_MSG( window1
&& window2
, FALSE
,
831 _T("can not split with NULL window(s)") );
833 wxCHECK_MSG( window1
->GetParent() == this && window2
->GetParent() == this, FALSE
,
834 _T("windows in the splitter should have it as parent!") );
837 m_windowOne
= window1
;
838 m_windowTwo
= window2
;
840 // remember the sash position we want to set for later if we can't set it
841 // right now (e.g. because the window is too small)
842 m_requestedSashPosition
= sashPosition
;
844 DoSetSashPosition(ConvertSashPosition(sashPosition
));
851 int wxSplitterWindow::ConvertSashPosition(int sashPosition
) const
853 if ( sashPosition
> 0 )
857 else if ( sashPosition
< 0 )
859 // It's negative so adding is subtracting
860 return GetWindowSize() + sashPosition
;
862 else // sashPosition == 0
864 // default, put it in the centre
865 return GetWindowSize() / 2;
869 // Remove the specified (or second) window from the view
870 // Doesn't actually delete the window.
871 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
876 wxWindow
*win
= NULL
;
877 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
880 m_windowTwo
= (wxWindow
*) NULL
;
882 else if ( toRemove
== m_windowOne
)
885 m_windowOne
= m_windowTwo
;
886 m_windowTwo
= (wxWindow
*) NULL
;
890 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
896 DoSetSashPosition(0);
902 // Replace a window with another one
903 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
905 wxCHECK_MSG( winOld
, FALSE
, wxT("use one of Split() functions instead") );
906 wxCHECK_MSG( winNew
, FALSE
, wxT("use Unsplit() functions instead") );
908 if ( winOld
== m_windowTwo
)
910 m_windowTwo
= winNew
;
912 else if ( winOld
== m_windowOne
)
914 m_windowOne
= winNew
;
918 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
928 void wxSplitterWindow::SetMinimumPaneSize(int min
)
930 m_minimumPaneSize
= min
;
931 SetSashPosition(m_sashPosition
); // re-check limits
934 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
936 DoSetSashPosition(position
);
944 // Initialize colours
945 void wxSplitterWindow::InitColours()
947 wxDELETE( m_facePen
);
948 wxDELETE( m_faceBrush
);
949 wxDELETE( m_mediumShadowPen
);
950 wxDELETE( m_darkShadowPen
);
951 wxDELETE( m_lightShadowPen
);
952 wxDELETE( m_hilightPen
);
956 wxColour
faceColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
957 m_facePen
= new wxPen(faceColour
, 1, wxSOLID
);
958 m_faceBrush
= new wxBrush(faceColour
, wxSOLID
);
960 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
961 m_mediumShadowPen
= new wxPen(mediumShadowColour
, 1, wxSOLID
);
963 wxColour
darkShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
));
964 m_darkShadowPen
= new wxPen(darkShadowColour
, 1, wxSOLID
);
966 wxColour
lightShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
));
967 m_lightShadowPen
= new wxPen(lightShadowColour
, 1, wxSOLID
);
969 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
970 m_hilightPen
= new wxPen(hilightColour
, 1, wxSOLID
);
972 m_facePen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
973 m_faceBrush
= new wxBrush("LIGHT GREY", wxSOLID
);
974 m_mediumShadowPen
= new wxPen("GREY", 1, wxSOLID
);
975 m_darkShadowPen
= new wxPen("BLACK", 1, wxSOLID
);
976 m_lightShadowPen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
977 m_hilightPen
= new wxPen("WHITE", 1, wxSOLID
);
981 bool wxSplitterWindow::DoSendEvent(wxSplitterEvent
& event
)
983 return !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed();
986 // ---------------------------------------------------------------------------
987 // wxSplitterWindow virtual functions: they now just generate the events
988 // ---------------------------------------------------------------------------
990 bool wxSplitterWindow::OnSashPositionChange(int WXUNUSED(newSashPosition
))
992 // always allow by default
996 int wxSplitterWindow::OnSashPositionChanging(int newSashPosition
)
998 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
999 const int UNSPLIT_THRESHOLD
= 4;
1001 // first of all, check if OnSashPositionChange() doesn't forbid this change
1002 if ( !OnSashPositionChange(newSashPosition
) )
1008 // Obtain relevant window dimension for bottom / right threshold check
1009 int window_size
= GetWindowSize();
1011 bool unsplit_scenario
= FALSE
;
1012 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
1014 // Do edge detection if unsplit premitted
1015 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
1017 // threshold top / left check
1018 newSashPosition
= 0;
1019 unsplit_scenario
= TRUE
;
1021 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
1023 // threshold bottom/right check
1024 newSashPosition
= window_size
;
1025 unsplit_scenario
= TRUE
;
1029 if ( !unsplit_scenario
)
1031 // If resultant pane would be too small, enlarge it
1032 newSashPosition
= AdjustSashPosition(newSashPosition
);
1035 // If the result is out of bounds it means minimum size is too big,
1036 // so split window in half as best compromise.
1037 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
1038 newSashPosition
= window_size
/ 2;
1040 // now let the event handler have it
1042 // FIXME: shouldn't we do it before the adjustments above so as to ensure
1043 // that the sash position is always reasonable?
1044 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
, this);
1045 event
.m_data
.pos
= newSashPosition
;
1047 if ( !DoSendEvent(event
) )
1049 // the event handler vetoed the change
1050 newSashPosition
= -1;
1054 // it could have been changed by it
1055 newSashPosition
= event
.GetSashPosition();
1058 return newSashPosition
;
1061 // Called when the sash is double-clicked. The default behaviour is to remove
1062 // the sash if the minimum pane size is zero.
1063 void wxSplitterWindow::OnDoubleClickSash(int x
, int y
)
1065 // new code should handle events instead of using the virtual functions
1066 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
, this);
1067 event
.m_data
.pt
.x
= x
;
1068 event
.m_data
.pt
.y
= y
;
1069 if ( DoSendEvent(event
) )
1071 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
1076 //else: blocked by user
1079 void wxSplitterWindow::OnUnsplit(wxWindow
*winRemoved
)
1081 // do it before calling the event handler which may delete the window
1082 winRemoved
->Show(FALSE
);
1084 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
1085 event
.m_data
.win
= winRemoved
;
1087 (void)DoSendEvent(event
);
1092 // this is currently called (and needed) under MSW only...
1093 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& event
)
1095 // if we don't do it, the resizing cursor might be set for child window:
1096 // and like this we explicitly say that our cursor should not be used for
1097 // children windows which overlap us
1099 if ( SashHitTest(event
.GetX(), event
.GetY()) )
1101 // default processing is ok
1104 //else: do nothing, in particular, don't call Skip()