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/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
= wxCursor(wxCURSOR_SIZEWE
);
115 m_sashCursorNS
= 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_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();
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
;
220 DrawSashTracker(m_oldX
, m_oldY
);
223 // the position of the click doesn't exactly correspond to
224 // m_sashPosition, rather it changes it by the distance by which the
226 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_oldX
: y
- m_oldY
;
228 int posSashOld
= isLive
? m_sashPosition
: m_sashPositionCurrent
;
229 int posSashNew
= OnSashPositionChanging(posSashOld
+ diff
);
230 if ( posSashNew
== -1 )
232 // change not allowed
236 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
238 // Deal with possible unsplit scenarios
239 if ( posSashNew
== 0 )
241 // We remove the first window from the view
242 wxWindow
*removedWindow
= m_windowOne
;
243 m_windowOne
= m_windowTwo
;
244 m_windowTwo
= (wxWindow
*) NULL
;
245 OnUnsplit(removedWindow
);
246 SetSashPositionAndNotify(0);
248 else if ( posSashNew
== GetWindowSize() )
250 // We remove the second window from the view
251 wxWindow
*removedWindow
= m_windowTwo
;
252 m_windowTwo
= (wxWindow
*) NULL
;
253 OnUnsplit(removedWindow
);
254 SetSashPositionAndNotify(0);
258 SetSashPositionAndNotify(posSashNew
);
263 SetSashPositionAndNotify(posSashNew
);
267 } // left up && dragging
268 else if (event
.Moving() && !event
.Dragging())
270 // Just change the cursor if required
271 if ( SashHitTest(x
, y
) )
275 #if defined(__WXGTK__) || defined(__WXMSW__) || defined(__WXMAC__)
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
296 int diff
= m_splitMode
== wxSPLIT_VERTICAL
? x
- m_oldX
: y
- m_oldY
;
299 // nothing to do, mouse didn't really move far enough
303 int posSashOld
= isLive
? m_sashPosition
: m_sashPositionCurrent
;
304 int posSashNew
= OnSashPositionChanging(posSashOld
+ diff
);
305 if ( posSashNew
== -1 )
307 // change not allowed
311 if ( posSashNew
== m_sashPosition
)
317 DrawSashTracker(m_oldX
, m_oldY
);
320 if (m_splitMode
== wxSPLIT_VERTICAL
)
325 // Remember old positions
330 // As we captured the mouse, we may get the mouse events from outside
331 // our window - for example, negative values in x, y. This has a weird
332 // consequence under MSW where we use unsigned values sometimes and
333 // signed ones other times: the coordinates turn as big positive
334 // numbers and so the sash is drawn on the *right* side of the window
335 // instead of the left (or bottom instead of top). Correct this.
336 if ( (short)m_oldX
< 0 )
338 if ( (short)m_oldY
< 0 )
345 m_sashPositionCurrent
= posSashNew
;
347 DrawSashTracker(m_oldX
, m_oldY
);
351 SetSashPositionAndNotify(posSashNew
);
352 m_needUpdating
= TRUE
;
355 else if ( event
.LeftDClick() )
357 OnDoubleClickSash(x
, y
);
361 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
363 // only process this message if we're not iconized - otherwise iconizing
364 // and restoring a window containing the splitter has a funny side effect
365 // of changing the splitter position!
366 wxWindow
*parent
= GetParent();
367 while ( parent
&& !parent
->IsTopLevel() )
369 parent
= parent
->GetParent();
372 bool iconized
= FALSE
;
374 // wxMotif doesn't yet have a wxTopLevelWindow implementation
376 wxFrame
*winTop
= wxDynamicCast(parent
, wxFrame
);
378 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
382 iconized
= winTop
->IsIconized();
387 wxFAIL_MSG(wxT("should have a top level parent!"));
401 GetClientSize( &cw
, &ch
);
404 if ( m_splitMode
== wxSPLIT_VERTICAL
)
406 if ( m_sashPosition
>= (cw
- 5) )
407 SetSashPositionAndNotify(wxMax(10, cw
- 40));
409 else // m_splitMode == wxSPLIT_HORIZONTAL
411 if ( m_sashPosition
>= (ch
- 5) )
412 SetSashPositionAndNotify(wxMax(10, ch
- 40));
419 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
421 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
422 return FALSE
; // No sash
424 if ( m_splitMode
== wxSPLIT_VERTICAL
)
426 if ( (x
>= m_sashPosition
- tolerance
) && (x
<= m_sashPosition
+ m_sashSize
+ tolerance
) )
433 if ( (y
>= (m_sashPosition
- tolerance
)) && (y
<= (m_sashPosition
+ m_sashSize
+ tolerance
)) )
440 // Draw 3D effect borders
441 void wxSplitterWindow::DrawBorders(wxDC
& dc
)
444 GetClientSize(&w
, &h
);
446 if ( GetWindowStyleFlag() & wxSP_3DBORDER
)
449 dc
.SetPen(*m_facePen
);
450 dc
.SetBrush(*m_faceBrush
);
451 dc
.DrawRectangle(1, 1 , w
-1, m_borderSize
-2 ); //high
452 dc
.DrawRectangle(1, m_borderSize
-2 , m_borderSize
-2, h
-1 ); // left
453 dc
.DrawRectangle(w
-m_borderSize
+2, m_borderSize
-2 , w
-1, h
-1 ); // right
454 dc
.DrawRectangle(m_borderSize
-2, h
-m_borderSize
+2 , w
-m_borderSize
+2, h
-1 ); //bottom
456 dc
.SetPen(*m_mediumShadowPen
);
457 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, w
-m_borderSize
+1, m_borderSize
-2);
458 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, m_borderSize
-2, h
-m_borderSize
+1);
460 dc
.SetPen(*m_darkShadowPen
);
461 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, w
-m_borderSize
, m_borderSize
-1);
462 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, m_borderSize
-1, h
-m_borderSize
);
464 dc
.SetPen(*m_hilightPen
);
465 dc
.DrawLine(m_borderSize
- 2, h
-m_borderSize
+1, w
-m_borderSize
+1, h
-m_borderSize
+1);
466 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.
467 /// Anyway, h is required for MSW.
469 dc
.SetPen(*m_lightShadowPen
);
470 dc
.DrawLine(w
-m_borderSize
, m_borderSize
-1, w
-m_borderSize
, h
-m_borderSize
); // Right hand side
471 dc
.DrawLine(m_borderSize
-1, h
-m_borderSize
, w
-m_borderSize
+1, h
-m_borderSize
); // Bottom
473 else if ( GetWindowStyleFlag() & wxSP_BORDER
)
475 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
476 dc
.SetPen(*wxBLACK_PEN
);
477 dc
.DrawRectangle(0, 0, w
-1, h
-1);
480 dc
.SetPen(wxNullPen
);
481 dc
.SetBrush(wxNullBrush
);
485 void wxSplitterWindow::DrawSash(wxDC
& dc
)
487 if ( m_sashPosition
== 0 || !m_windowTwo
)
489 if (GetWindowStyle() & wxSP_NOSASH
)
493 GetClientSize(&w
, &h
);
495 if ( GetWindowStyleFlag() & wxSP_3DSASH
)
497 if ( m_splitMode
== wxSPLIT_VERTICAL
)
499 dc
.SetPen(*m_facePen
);
501 if (HasFlag( wxSP_SASH_AQUA
))
502 dc
.SetBrush(*wxWHITE_BRUSH
);
504 dc
.SetBrush(*m_faceBrush
);
505 dc
.DrawRectangle(m_sashPosition
+ 2, 0 , m_sashSize
- 4, h
);
507 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
509 dc
.SetPen(*m_lightShadowPen
);
510 int xShadow
= m_borderSize
? m_borderSize
- 1 : 0 ;
511 dc
.DrawLine(m_sashPosition
, xShadow
, m_sashPosition
, h
-m_borderSize
);
513 dc
.SetPen(*m_hilightPen
);
514 dc
.DrawLine(m_sashPosition
+1, m_borderSize
- 2, m_sashPosition
+1, h
- m_borderSize
+2);
516 if (!HasFlag( wxSP_SASH_AQUA
))
517 dc
.SetPen(*m_mediumShadowPen
);
519 int yMedium
= m_borderSize
? h
-m_borderSize
+1 : h
;
520 dc
.DrawLine(m_sashPosition
+m_sashSize
-2, xShadow
, m_sashPosition
+m_sashSize
-2, yMedium
);
522 if (HasFlag( wxSP_SASH_AQUA
))
523 dc
.SetPen(*m_lightShadowPen
);
525 dc
.SetPen(*m_darkShadowPen
);
526 dc
.DrawLine(m_sashPosition
+m_sashSize
-1, m_borderSize
, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
);
528 // Draw the top and bottom edges of the sash, if requested
529 if (GetWindowStyle() & wxSP_FULLSASH
)
532 dc
.SetPen(*m_hilightPen
);
533 dc
.DrawLine(m_sashPosition
+1, m_borderSize
, m_sashPosition
+m_sashSize
-1, m_borderSize
);
536 dc
.SetPen(*m_darkShadowPen
);
537 dc
.DrawLine(m_sashPosition
+1, h
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
-1);
542 dc
.SetPen(*m_facePen
);
543 if (HasFlag( wxSP_SASH_AQUA
))
544 dc
.SetBrush(*wxWHITE_BRUSH
);
546 dc
.SetBrush(*m_faceBrush
);
547 dc
.DrawRectangle( m_borderSize
-2, m_sashPosition
+ 2, w
-m_borderSize
+2, m_sashSize
- 4);
549 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
551 dc
.SetPen(*m_lightShadowPen
);
552 dc
.DrawLine(m_borderSize
-1, m_sashPosition
, w
-m_borderSize
, m_sashPosition
);
554 dc
.SetPen(*m_hilightPen
);
555 dc
.DrawLine(m_borderSize
-2, m_sashPosition
+1, w
-m_borderSize
+1, m_sashPosition
+1);
557 if (!HasFlag( wxSP_SASH_AQUA
))
558 dc
.SetPen(*m_mediumShadowPen
);
559 dc
.DrawLine(m_borderSize
-1, m_sashPosition
+m_sashSize
-2, w
-m_borderSize
+1, m_sashPosition
+m_sashSize
-2);
561 if (HasFlag( wxSP_SASH_AQUA
))
562 dc
.SetPen(*m_lightShadowPen
);
564 dc
.SetPen(*m_darkShadowPen
);
565 dc
.DrawLine(m_borderSize
, m_sashPosition
+m_sashSize
-1, w
-m_borderSize
, m_sashPosition
+m_sashSize
-1);
567 // Draw the left and right edges of the sash, if requested
568 if (GetWindowStyle() & wxSP_FULLSASH
)
571 dc
.SetPen(*m_hilightPen
);
572 dc
.DrawLine(m_borderSize
, m_sashPosition
, m_borderSize
, m_sashPosition
+m_sashSize
);
575 dc
.SetPen(*m_darkShadowPen
);
576 dc
.DrawLine(w
-m_borderSize
-1, m_sashPosition
+1, w
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1);
582 if ( m_splitMode
== wxSPLIT_VERTICAL
)
584 dc
.SetPen(*wxBLACK_PEN
);
585 dc
.SetBrush(*wxBLACK_BRUSH
);
588 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
589 h1
+= 1; // Not sure why this is necessary...
590 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
594 dc
.DrawRectangle(m_sashPosition
, y1
, m_sashSize
, h1
);
598 dc
.SetPen(*wxBLACK_PEN
);
599 dc
.SetBrush(*wxBLACK_BRUSH
);
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
);
613 dc
.SetPen(wxNullPen
);
614 dc
.SetBrush(wxNullBrush
);
617 // Draw the sash tracker (for whilst moving the sash)
618 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
621 GetClientSize(&w
, &h
);
627 if ( m_splitMode
== wxSPLIT_VERTICAL
)
658 ClientToScreen(&x1
, &y1
);
659 ClientToScreen(&x2
, &y2
);
661 screenDC
.SetLogicalFunction(wxINVERT
);
662 screenDC
.SetPen(*m_sashTrackerPen
);
663 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
665 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
667 screenDC
.SetLogicalFunction(wxCOPY
);
669 screenDC
.SetPen(wxNullPen
);
670 screenDC
.SetBrush(wxNullBrush
);
673 int wxSplitterWindow::GetWindowSize() const
675 wxSize size
= GetClientSize();
677 return m_splitMode
== wxSPLIT_VERTICAL
? size
.x
: size
.y
;
680 int wxSplitterWindow::AdjustSashPosition(int sashPos
) const
682 int window_size
= GetWindowSize();
689 // the window shouldn't be smaller than its own minimal size nor
690 // smaller than the minimual pane size specified for this splitter
691 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
692 : win
->GetMinHeight();
694 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
695 minSize
= m_minimumPaneSize
;
697 minSize
+= GetBorderSize();
699 if ( sashPos
< minSize
)
706 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
707 : win
->GetMinHeight();
709 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
710 minSize
= m_minimumPaneSize
;
712 int maxSize
= window_size
- minSize
- GetBorderSize();
713 if ( sashPos
> maxSize
)
720 bool wxSplitterWindow::DoSetSashPosition(int sashPos
)
722 int newSashPosition
= AdjustSashPosition(sashPos
);
724 if ( newSashPosition
== m_sashPosition
)
727 m_sashPosition
= newSashPosition
;
732 void wxSplitterWindow::SetSashPositionAndNotify(int sashPos
)
734 if ( DoSetSashPosition(sashPos
) )
736 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
, this);
737 event
.m_data
.pos
= m_sashPosition
;
739 (void)DoSendEvent(event
);
743 // Position and size subwindows.
744 // Note that the border size applies to each subwindow, not
745 // including the edges next to the sash.
746 void wxSplitterWindow::SizeWindows()
748 // check if we have delayed setting the real sash position
749 if ( m_requestedSashPosition
!= INT_MAX
)
751 int newSashPosition
= ConvertSashPosition(m_requestedSashPosition
);
752 if ( newSashPosition
!= m_sashPosition
)
754 DoSetSashPosition(newSashPosition
);
757 if ( newSashPosition
== m_sashPosition
)
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
->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 wxASSERT_MSG( window1
->GetParent() == this && window2
->GetParent() == this,
827 _T("windows in the splitter should have it as parent!") );
830 m_windowOne
= window1
;
831 m_windowTwo
= window2
;
833 // remember the sash position we want to set for later if we can't set it
834 // right now (e.g. because the window is too small)
835 m_requestedSashPosition
= sashPosition
;
837 DoSetSashPosition(ConvertSashPosition(sashPosition
));
844 int wxSplitterWindow::ConvertSashPosition(int sashPosition
) const
846 if ( sashPosition
> 0 )
850 else if ( sashPosition
< 0 )
852 // It's negative so adding is subtracting
853 return GetWindowSize() + sashPosition
;
855 else // sashPosition == 0
857 // default, put it in the centre
858 return GetWindowSize() / 2;
862 // Remove the specified (or second) window from the view
863 // Doesn't actually delete the window.
864 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
869 wxWindow
*win
= NULL
;
870 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
873 m_windowTwo
= (wxWindow
*) NULL
;
875 else if ( toRemove
== m_windowOne
)
878 m_windowOne
= m_windowTwo
;
879 m_windowTwo
= (wxWindow
*) NULL
;
883 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
889 DoSetSashPosition(0);
895 // Replace a window with another one
896 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
898 wxCHECK_MSG( winOld
, FALSE
, wxT("use one of Split() functions instead") );
899 wxCHECK_MSG( winNew
, FALSE
, wxT("use Unsplit() functions instead") );
901 if ( winOld
== m_windowTwo
)
903 m_windowTwo
= winNew
;
905 else if ( winOld
== m_windowOne
)
907 m_windowOne
= winNew
;
911 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
921 void wxSplitterWindow::SetMinimumPaneSize(int min
)
923 m_minimumPaneSize
= min
;
924 SetSashPosition(m_sashPosition
); // re-check limits
927 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
929 DoSetSashPosition(position
);
937 // Initialize colours
938 void wxSplitterWindow::InitColours()
940 wxDELETE( m_facePen
);
941 wxDELETE( m_faceBrush
);
942 wxDELETE( m_mediumShadowPen
);
943 wxDELETE( m_darkShadowPen
);
944 wxDELETE( m_lightShadowPen
);
945 wxDELETE( m_hilightPen
);
949 wxColour
faceColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
950 m_facePen
= new wxPen(faceColour
, 1, wxSOLID
);
951 m_faceBrush
= new wxBrush(faceColour
, wxSOLID
);
953 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
954 m_mediumShadowPen
= new wxPen(mediumShadowColour
, 1, wxSOLID
);
956 wxColour
darkShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
));
957 m_darkShadowPen
= new wxPen(darkShadowColour
, 1, wxSOLID
);
959 wxColour
lightShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
));
960 m_lightShadowPen
= new wxPen(lightShadowColour
, 1, wxSOLID
);
962 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
963 m_hilightPen
= new wxPen(hilightColour
, 1, wxSOLID
);
965 m_facePen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
966 m_faceBrush
= new wxBrush("LIGHT GREY", wxSOLID
);
967 m_mediumShadowPen
= new wxPen("GREY", 1, wxSOLID
);
968 m_darkShadowPen
= new wxPen("BLACK", 1, wxSOLID
);
969 m_lightShadowPen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
970 m_hilightPen
= new wxPen("WHITE", 1, wxSOLID
);
974 bool wxSplitterWindow::DoSendEvent(wxSplitterEvent
& event
)
976 return !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed();
979 // ---------------------------------------------------------------------------
980 // wxSplitterWindow virtual functions: they now just generate the events
981 // ---------------------------------------------------------------------------
983 bool wxSplitterWindow::OnSashPositionChange(int WXUNUSED(newSashPosition
))
985 // always allow by default
989 int wxSplitterWindow::OnSashPositionChanging(int newSashPosition
)
991 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
992 const int UNSPLIT_THRESHOLD
= 4;
994 // first of all, check if OnSashPositionChange() doesn't forbid this change
995 if ( !OnSashPositionChange(newSashPosition
) )
1001 // Obtain relevant window dimension for bottom / right threshold check
1002 int window_size
= GetWindowSize();
1004 bool unsplit_scenario
= FALSE
;
1005 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
1007 // Do edge detection if unsplit premitted
1008 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
1010 // threshold top / left check
1011 newSashPosition
= 0;
1012 unsplit_scenario
= TRUE
;
1014 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
1016 // threshold bottom/right check
1017 newSashPosition
= window_size
;
1018 unsplit_scenario
= TRUE
;
1022 if ( !unsplit_scenario
)
1024 // If resultant pane would be too small, enlarge it
1025 newSashPosition
= AdjustSashPosition(newSashPosition
);
1028 // If the result is out of bounds it means minimum size is too big,
1029 // so split window in half as best compromise.
1030 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
1031 newSashPosition
= window_size
/ 2;
1033 // now let the event handler have it
1035 // FIXME: shouldn't we do it before the adjustments above so as to ensure
1036 // that the sash position is always reasonable?
1037 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
, this);
1038 event
.m_data
.pos
= newSashPosition
;
1040 if ( !DoSendEvent(event
) )
1042 // the event handler vetoed the change
1043 newSashPosition
= -1;
1047 // it could have been changed by it
1048 newSashPosition
= event
.GetSashPosition();
1051 return newSashPosition
;
1054 // Called when the sash is double-clicked. The default behaviour is to remove
1055 // the sash if the minimum pane size is zero.
1056 void wxSplitterWindow::OnDoubleClickSash(int x
, int y
)
1058 // new code should handle events instead of using the virtual functions
1059 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
, this);
1060 event
.m_data
.pt
.x
= x
;
1061 event
.m_data
.pt
.y
= y
;
1062 if ( DoSendEvent(event
) )
1064 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
1069 //else: blocked by user
1072 void wxSplitterWindow::OnUnsplit(wxWindow
*winRemoved
)
1074 // do it before calling the event handler which may delete the window
1075 winRemoved
->Show(FALSE
);
1077 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
1078 event
.m_data
.win
= winRemoved
;
1080 (void)DoSendEvent(event
);
1085 // this is currently called (and needed) under MSW only...
1086 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& event
)
1088 // if we don't do it, the resizing cursor might be set for child window:
1089 // and like this we explicitly say that our cursor should not be used for
1090 // children windows which overlap us
1092 if ( SashHitTest(event
.GetX(), event
.GetY()) )
1094 // default processing is ok
1097 //else: do nothing, in particular, don't call Skip()