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 int newSashPosition
= AdjustSashPosition(sashPos
);
723 if ( newSashPosition
!= m_sashPosition
)
725 m_sashPosition
= newSashPosition
;
727 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
, this);
728 event
.m_data
.pos
= m_sashPosition
;
730 (void)DoSendEvent(event
);
734 // Position and size subwindows.
735 // Note that the border size applies to each subwindow, not
736 // including the edges next to the sash.
737 void wxSplitterWindow::SizeWindows()
739 // check if we have delayed setting the real sash position
740 if ( m_requestedSashPosition
!= INT_MAX
)
742 int newSashPosition
= ConvertSashPosition(m_requestedSashPosition
);
743 if ( newSashPosition
!= m_sashPosition
)
745 DoSetSashPosition(newSashPosition
);
748 if ( newSashPosition
== m_sashPosition
)
750 // don't update it any more
751 m_requestedSashPosition
= INT_MAX
;
756 GetClientSize(&w
, &h
);
758 if ( GetWindow1() && !GetWindow2() )
760 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
761 w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
763 else if ( GetWindow1() && GetWindow2() )
765 if (GetSplitMode() == wxSPLIT_VERTICAL
)
767 int x1
= GetBorderSize();
768 int y1
= GetBorderSize();
769 int w1
= GetSashPosition() - GetBorderSize();
770 int h1
= h
- 2*GetBorderSize();
772 int x2
= GetSashPosition() + GetSashSize();
773 int y2
= GetBorderSize();
774 int w2
= w
- 2*GetBorderSize() - GetSashSize() - w1
;
775 int h2
= h
- 2*GetBorderSize();
777 GetWindow1()->SetSize(x1
, y1
, w1
, h1
);
778 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
782 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
783 w
- 2*GetBorderSize(), GetSashPosition() - GetBorderSize());
784 GetWindow2()->SetSize(GetBorderSize(), GetSashPosition() + GetSashSize(),
785 w
- 2*GetBorderSize(), h
- 2*GetBorderSize() - GetSashSize() - (GetSashPosition() - GetBorderSize()));
789 if ( GetBorderSize() > 0 )
793 SetNeedUpdating(FALSE
);
796 // Set pane for unsplit window
797 void wxSplitterWindow::Initialize(wxWindow
*window
)
799 m_windowOne
= window
;
800 m_windowTwo
= (wxWindow
*) NULL
;
801 DoSetSashPosition(0);
804 // Associates the given window with window 2, drawing the appropriate sash
805 // and changing the split mode.
806 // Does nothing and returns FALSE if the window is already split.
807 bool wxSplitterWindow::DoSplit(wxSplitMode mode
,
808 wxWindow
*window1
, wxWindow
*window2
,
815 m_windowOne
= window1
;
816 m_windowTwo
= window2
;
818 // remember the sash position we want to set for later if we can't set it
819 // right now (e.g. because the window is too small)
820 m_requestedSashPosition
= sashPosition
;
822 DoSetSashPosition(ConvertSashPosition(sashPosition
));
829 int wxSplitterWindow::ConvertSashPosition(int sashPosition
) const
831 if ( sashPosition
> 0 )
835 else if ( sashPosition
< 0 )
837 // It's negative so adding is subtracting
838 return GetWindowSize() + sashPosition
;
840 else // sashPosition == 0
842 // default, put it in the centre
843 return GetWindowSize() / 2;
847 // Remove the specified (or second) window from the view
848 // Doesn't actually delete the window.
849 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
854 wxWindow
*win
= NULL
;
855 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
858 m_windowTwo
= (wxWindow
*) NULL
;
860 else if ( toRemove
== m_windowOne
)
863 m_windowOne
= m_windowTwo
;
864 m_windowTwo
= (wxWindow
*) NULL
;
868 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
874 DoSetSashPosition(0);
880 // Replace a window with another one
881 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
883 wxCHECK_MSG( winOld
, FALSE
, wxT("use one of Split() functions instead") );
884 wxCHECK_MSG( winNew
, FALSE
, wxT("use Unsplit() functions instead") );
886 if ( winOld
== m_windowTwo
)
888 m_windowTwo
= winNew
;
890 else if ( winOld
== m_windowOne
)
892 m_windowOne
= winNew
;
896 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
906 void wxSplitterWindow::SetMinimumPaneSize(int min
)
908 m_minimumPaneSize
= min
;
909 SetSashPosition(m_sashPosition
); // re-check limits
912 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
914 DoSetSashPosition(position
);
922 // Initialize colours
923 void wxSplitterWindow::InitColours()
925 wxDELETE( m_facePen
);
926 wxDELETE( m_faceBrush
);
927 wxDELETE( m_mediumShadowPen
);
928 wxDELETE( m_darkShadowPen
);
929 wxDELETE( m_lightShadowPen
);
930 wxDELETE( m_hilightPen
);
934 wxColour
faceColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
935 m_facePen
= new wxPen(faceColour
, 1, wxSOLID
);
936 m_faceBrush
= new wxBrush(faceColour
, wxSOLID
);
938 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
939 m_mediumShadowPen
= new wxPen(mediumShadowColour
, 1, wxSOLID
);
941 wxColour
darkShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
));
942 m_darkShadowPen
= new wxPen(darkShadowColour
, 1, wxSOLID
);
944 wxColour
lightShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
));
945 m_lightShadowPen
= new wxPen(lightShadowColour
, 1, wxSOLID
);
947 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
948 m_hilightPen
= new wxPen(hilightColour
, 1, wxSOLID
);
950 m_facePen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
951 m_faceBrush
= new wxBrush("LIGHT GREY", wxSOLID
);
952 m_mediumShadowPen
= new wxPen("GREY", 1, wxSOLID
);
953 m_darkShadowPen
= new wxPen("BLACK", 1, wxSOLID
);
954 m_lightShadowPen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
955 m_hilightPen
= new wxPen("WHITE", 1, wxSOLID
);
959 bool wxSplitterWindow::DoSendEvent(wxSplitterEvent
& event
)
961 return !GetEventHandler()->ProcessEvent(event
) || event
.IsAllowed();
964 // ---------------------------------------------------------------------------
965 // wxSplitterWindow virtual functions: they now just generate the events
966 // ---------------------------------------------------------------------------
968 bool wxSplitterWindow::OnSashPositionChange(int WXUNUSED(newSashPosition
))
970 // always allow by default
974 int wxSplitterWindow::OnSashPositionChanging(int newSashPosition
)
976 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
977 const int UNSPLIT_THRESHOLD
= 4;
979 // first of all, check if OnSashPositionChange() doesn't forbid this change
980 if ( !OnSashPositionChange(newSashPosition
) )
986 // Obtain relevant window dimension for bottom / right threshold check
987 int window_size
= GetWindowSize();
989 bool unsplit_scenario
= FALSE
;
990 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
992 // Do edge detection if unsplit premitted
993 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
995 // threshold top / left check
997 unsplit_scenario
= TRUE
;
999 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
1001 // threshold bottom/right check
1002 newSashPosition
= window_size
;
1003 unsplit_scenario
= TRUE
;
1007 if ( !unsplit_scenario
)
1009 // If resultant pane would be too small, enlarge it
1010 newSashPosition
= AdjustSashPosition(newSashPosition
);
1013 // If the result is out of bounds it means minimum size is too big,
1014 // so split window in half as best compromise.
1015 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
1016 newSashPosition
= window_size
/ 2;
1018 // now let the event handler have it
1020 // FIXME: shouldn't we do it before the adjustments above so as to ensure
1021 // that the sash position is always reasonable?
1022 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
, this);
1023 event
.m_data
.pos
= newSashPosition
;
1025 if ( !DoSendEvent(event
) )
1027 // the event handler vetoed the change
1028 newSashPosition
= -1;
1032 // it could have been changed by it
1033 newSashPosition
= event
.GetSashPosition();
1036 return newSashPosition
;
1039 // Called when the sash is double-clicked. The default behaviour is to remove
1040 // the sash if the minimum pane size is zero.
1041 void wxSplitterWindow::OnDoubleClickSash(int x
, int y
)
1043 // new code should handle events instead of using the virtual functions
1044 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
, this);
1045 event
.m_data
.pt
.x
= x
;
1046 event
.m_data
.pt
.y
= y
;
1047 if ( DoSendEvent(event
) )
1049 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
1054 //else: blocked by user
1057 void wxSplitterWindow::OnUnsplit(wxWindow
*winRemoved
)
1059 // do it before calling the event handler which may delete the window
1060 winRemoved
->Show(FALSE
);
1062 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
1063 event
.m_data
.win
= winRemoved
;
1065 (void)DoSendEvent(event
);
1070 // this is currently called (and needed) under MSW only...
1071 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& event
)
1073 // if we don't do it, the resizing cursor might be set for child window:
1074 // and like this we explicitly say that our cursor should not be used for
1075 // children windows which overlap us
1077 if ( SashHitTest(event
.GetX(), event
.GetY()) )
1079 // default processing is ok
1082 //else: do nothing, in particular, don't call Skip()