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"
37 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
)
38 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
)
39 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
)
40 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_UNSPLIT
)
42 IMPLEMENT_DYNAMIC_CLASS(wxSplitterWindow
, wxWindow
)
43 IMPLEMENT_DYNAMIC_CLASS(wxSplitterEvent
, wxCommandEvent
)
45 BEGIN_EVENT_TABLE(wxSplitterWindow
, wxWindow
)
46 EVT_PAINT(wxSplitterWindow::OnPaint
)
47 EVT_SIZE(wxSplitterWindow::OnSize
)
48 EVT_IDLE(wxSplitterWindow::OnIdle
)
49 EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent
)
51 EVT_SET_CURSOR(wxSplitterWindow::OnSetCursor
)
53 EVT_SPLITTER_SASH_POS_CHANGED(-1, wxSplitterWindow::OnSashPosChanged
)
54 // NB: we borrow OnSashPosChanged for purposes of
55 // EVT_SPLITTER_SASH_POS_CHANGING since default implementation is identical
56 EVT_SPLITTER_SASH_POS_CHANGING(-1, wxSplitterWindow::OnSashPosChanged
)
57 EVT_SPLITTER_DCLICK(-1, wxSplitterWindow::OnDoubleClick
)
58 EVT_SPLITTER_UNSPLIT(-1, wxSplitterWindow::OnUnsplitEvent
)
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
)
94 void wxSplitterWindow::Init()
96 m_container
.SetContainerWindow(this);
98 m_splitMode
= wxSPLIT_VERTICAL
;
99 m_permitUnsplitAlways
= TRUE
;
100 m_windowOne
= (wxWindow
*) NULL
;
101 m_windowTwo
= (wxWindow
*) NULL
;
102 m_dragMode
= wxSPLIT_DRAG_NONE
;
110 m_minimumPaneSize
= 0;
111 m_sashCursorWE
= new wxCursor(wxCURSOR_SIZEWE
);
112 m_sashCursorNS
= new wxCursor(wxCURSOR_SIZENS
);
113 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxSOLID
);
114 m_lightShadowPen
= (wxPen
*) NULL
;
115 m_mediumShadowPen
= (wxPen
*) NULL
;
116 m_darkShadowPen
= (wxPen
*) NULL
;
117 m_faceBrush
= (wxBrush
*) NULL
;
118 m_facePen
= (wxPen
*) NULL
;
119 m_hilightPen
= (wxPen
*) NULL
;
126 m_needUpdating
= FALSE
;
129 wxSplitterWindow::~wxSplitterWindow()
131 delete m_sashCursorWE
;
132 delete m_sashCursorNS
;
133 delete m_sashTrackerPen
;
134 delete m_lightShadowPen
;
135 delete m_darkShadowPen
;
136 delete m_mediumShadowPen
;
142 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
146 if ( m_borderSize
> 0 )
151 void wxSplitterWindow::OnIdle(wxIdleEvent
& event
)
159 void wxSplitterWindow::OnMouseEvent(wxMouseEvent
& event
)
161 wxCoord x
= (wxCoord
)event
.GetX(),
162 y
= (wxCoord
)event
.GetY();
166 SetCursor(* wxSTANDARD_CURSOR
);
169 SetCursor(wxCursor());
172 if (GetWindowStyle() & wxSP_NOSASH
)
175 if (event
.LeftDown())
177 if ( SashHitTest(x
, y
) )
181 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
183 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
185 DrawSashTracker(x
, y
);
191 if ( m_splitMode
== wxSPLIT_VERTICAL
)
193 SetCursor(*m_sashCursorWE
);
197 SetCursor(*m_sashCursorNS
);
202 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
204 // We can stop dragging now and see what we've got.
205 m_dragMode
= wxSPLIT_DRAG_NONE
;
209 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
211 DrawSashTracker(m_oldX
, m_oldY
);
214 // Obtain window size. We are only interested in the dimension the sash
217 GetClientSize(&w
, &h
);
218 int window_size
= (m_splitMode
== wxSPLIT_VERTICAL
? w
: h
);
219 int new_sash_position
=
220 (int) ( m_splitMode
== wxSPLIT_VERTICAL
? x
: y
);
222 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
,
224 eventSplitter
.m_data
.pos
= new_sash_position
;
225 if ( GetEventHandler()->ProcessEvent(eventSplitter
) )
227 new_sash_position
= eventSplitter
.GetSashPosition();
228 if ( new_sash_position
== -1 )
230 // change not allowed
235 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
237 // Deal with possible unsplit scenarios
238 if ( new_sash_position
== 0 )
240 // We remove the first window from the view
241 wxWindow
*removedWindow
= m_windowOne
;
242 m_windowOne
= m_windowTwo
;
243 m_windowTwo
= (wxWindow
*) NULL
;
244 SendUnsplitEvent(removedWindow
);
247 else if ( new_sash_position
== window_size
)
249 // We remove the second window from the view
250 wxWindow
*removedWindow
= m_windowTwo
;
251 m_windowTwo
= (wxWindow
*) NULL
;
252 SendUnsplitEvent(removedWindow
);
257 m_sashPosition
= new_sash_position
;
262 m_sashPosition
= new_sash_position
;
266 } // left up && dragging
267 else if (event
.Moving() && !event
.Dragging())
269 // Just change the cursor if required
270 if ( SashHitTest(x
, y
) )
272 if ( m_splitMode
== wxSPLIT_VERTICAL
)
274 SetCursor(*m_sashCursorWE
);
278 SetCursor(*m_sashCursorNS
);
281 #if defined(__WXGTK__) || defined(__WXMSW__)
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
))
297 // Otherwise, the cursor sometimes reverts to the normal cursor
299 if ( m_splitMode
== wxSPLIT_VERTICAL
)
301 SetCursor(*m_sashCursorWE
);
305 SetCursor(*m_sashCursorNS
);
309 // Obtain window size. We are only interested in the dimension the sash
311 int new_sash_position
=
312 (int) ( m_splitMode
== wxSPLIT_VERTICAL
? x
: y
);
314 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
,
316 eventSplitter
.m_data
.pos
= new_sash_position
;
317 if ( GetEventHandler()->ProcessEvent(eventSplitter
) )
319 new_sash_position
= eventSplitter
.GetSashPosition();
320 if ( new_sash_position
== -1 )
322 // change not allowed
327 if (new_sash_position
== m_sashPosition
)
331 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
333 DrawSashTracker(m_oldX
, m_oldY
);
336 if (m_splitMode
== wxSPLIT_VERTICAL
)
337 x
= new_sash_position
;
339 y
= new_sash_position
;
341 // Remember old positions
346 // As we captured the mouse, we may get the mouse events from outside
347 // our window - for example, negative values in x, y. This has a weird
348 // consequence under MSW where we use unsigned values sometimes and
349 // signed ones other times: the coordinates turn as big positive
350 // numbers and so the sash is drawn on the *right* side of the window
351 // instead of the left (or bottom instead of top). Correct this.
352 if ( (short)m_oldX
< 0 )
354 if ( (short)m_oldY
< 0 )
359 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
361 DrawSashTracker(m_oldX
, m_oldY
);
365 m_sashPosition
= new_sash_position
;
366 m_needUpdating
= TRUE
;
369 else if ( event
.LeftDClick() )
371 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
,
373 eventSplitter
.m_data
.pt
.x
= x
;
374 eventSplitter
.m_data
.pt
.y
= y
;
376 (void)GetEventHandler()->ProcessEvent(eventSplitter
);
380 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
382 // only process this message if we're not iconized - otherwise iconizing
383 // and restoring a window containing the splitter has a funny side effect
384 // of changing the splitter position!
385 wxWindow
*parent
= GetParent();
386 while ( parent
&& !parent
->IsTopLevel() )
388 parent
= parent
->GetParent();
391 bool iconized
= FALSE
;
392 wxFrame
*frame
= wxDynamicCast(parent
, wxFrame
);
394 iconized
= frame
->IsIconized();
397 wxDialog
*dialog
= wxDynamicCast(parent
, wxDialog
);
399 iconized
= dialog
->IsIconized();
401 wxFAIL_MSG(wxT("should have a top level frame or dialog parent!"));
411 GetClientSize( &cw
, &ch
);
414 if ( m_splitMode
== wxSPLIT_VERTICAL
)
416 if ( m_sashPosition
>= (cw
- 5) )
417 m_sashPosition
= wxMax(10, cw
- 40);
419 if ( m_splitMode
== wxSPLIT_HORIZONTAL
)
421 if ( m_sashPosition
>= (ch
- 5) )
422 m_sashPosition
= wxMax(10, ch
- 40);
430 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
432 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
433 return FALSE
; // No sash
435 if ( m_splitMode
== wxSPLIT_VERTICAL
)
437 if ( (x
>= m_sashPosition
- tolerance
) && (x
<= m_sashPosition
+ m_sashSize
+ tolerance
) )
444 if ( (y
>= (m_sashPosition
- tolerance
)) && (y
<= (m_sashPosition
+ m_sashSize
+ tolerance
)) )
451 // Draw 3D effect borders
452 void wxSplitterWindow::DrawBorders(wxDC
& dc
)
455 GetClientSize(&w
, &h
);
457 if ( GetWindowStyleFlag() & wxSP_3DBORDER
)
460 dc
.SetPen(*m_facePen
);
461 dc
.SetBrush(*m_faceBrush
);
462 dc
.DrawRectangle(1, 1 , w
-1, m_borderSize
-2 ); //high
463 dc
.DrawRectangle(1, m_borderSize
-2 , m_borderSize
-2, h
-1 ); // left
464 dc
.DrawRectangle(w
-m_borderSize
+2, m_borderSize
-2 , w
-1, h
-1 ); // right
465 dc
.DrawRectangle(m_borderSize
-2, h
-m_borderSize
+2 , w
-m_borderSize
+2, h
-1 ); //bottom
467 dc
.SetPen(*m_mediumShadowPen
);
468 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, w
-m_borderSize
+1, m_borderSize
-2);
469 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, m_borderSize
-2, h
-m_borderSize
+1);
471 dc
.SetPen(*m_darkShadowPen
);
472 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, w
-m_borderSize
, m_borderSize
-1);
473 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, m_borderSize
-1, h
-m_borderSize
);
475 dc
.SetPen(*m_hilightPen
);
476 dc
.DrawLine(m_borderSize
- 2, h
-m_borderSize
+1, w
-m_borderSize
+1, h
-m_borderSize
+1);
477 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.
478 /// Anyway, h is required for MSW.
480 dc
.SetPen(*m_lightShadowPen
);
481 dc
.DrawLine(w
-m_borderSize
, m_borderSize
-1, w
-m_borderSize
, h
-m_borderSize
); // Right hand side
482 dc
.DrawLine(m_borderSize
-1, h
-m_borderSize
, w
-m_borderSize
+1, h
-m_borderSize
); // Bottom
484 else if ( GetWindowStyleFlag() & wxSP_BORDER
)
486 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
487 dc
.SetPen(*wxBLACK_PEN
);
488 dc
.DrawRectangle(0, 0, w
-1, h
-1);
491 dc
.SetPen(wxNullPen
);
492 dc
.SetBrush(wxNullBrush
);
496 void wxSplitterWindow::DrawSash(wxDC
& dc
)
498 if ( m_sashPosition
== 0 || !m_windowTwo
)
500 if (GetWindowStyle() & wxSP_NOSASH
)
504 GetClientSize(&w
, &h
);
506 if ( GetWindowStyleFlag() & wxSP_3DSASH
)
508 if ( m_splitMode
== wxSPLIT_VERTICAL
)
510 dc
.SetPen(*m_facePen
);
511 dc
.SetBrush(*m_faceBrush
);
512 dc
.DrawRectangle(m_sashPosition
+ 2, 0 , m_sashSize
- 4, h
);
514 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
516 dc
.SetPen(*m_lightShadowPen
);
517 int xShadow
= m_borderSize
? m_borderSize
- 1 : 0 ;
518 dc
.DrawLine(m_sashPosition
, xShadow
, m_sashPosition
, h
-m_borderSize
);
520 dc
.SetPen(*m_hilightPen
);
521 dc
.DrawLine(m_sashPosition
+1, m_borderSize
- 2, m_sashPosition
+1, h
- m_borderSize
+2);
523 dc
.SetPen(*m_mediumShadowPen
);
524 int yMedium
= m_borderSize
? h
-m_borderSize
+1 : h
;
525 dc
.DrawLine(m_sashPosition
+m_sashSize
-2, xShadow
, m_sashPosition
+m_sashSize
-2, yMedium
);
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);
544 dc
.SetPen(*m_facePen
);
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 dc
.SetPen(*m_mediumShadowPen
);
557 dc
.DrawLine(m_borderSize
-1, m_sashPosition
+m_sashSize
-2, w
-m_borderSize
+1, m_sashPosition
+m_sashSize
-2);
559 dc
.SetPen(*m_darkShadowPen
);
560 dc
.DrawLine(m_borderSize
, m_sashPosition
+m_sashSize
-1, w
-m_borderSize
, m_sashPosition
+m_sashSize
-1);
562 // Draw the left and right edges of the sash, if requested
563 if (GetWindowStyle() & wxSP_FULLSASH
)
566 dc
.SetPen(*m_hilightPen
);
567 dc
.DrawLine(m_borderSize
, m_sashPosition
, m_borderSize
, m_sashPosition
+m_sashSize
);
570 dc
.SetPen(*m_darkShadowPen
);
571 dc
.DrawLine(w
-m_borderSize
-1, m_sashPosition
+1, w
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1);
577 if ( m_splitMode
== wxSPLIT_VERTICAL
)
579 dc
.SetPen(*wxBLACK_PEN
);
580 dc
.SetBrush(*wxBLACK_BRUSH
);
583 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
584 h1
+= 1; // Not sure why this is necessary...
585 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
589 dc
.DrawRectangle(m_sashPosition
, y1
, m_sashSize
, h1
);
593 dc
.SetPen(*wxBLACK_PEN
);
594 dc
.SetBrush(*wxBLACK_BRUSH
);
597 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
599 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
603 dc
.DrawRectangle(x1
, m_sashPosition
, w1
, m_sashSize
);
608 dc
.SetPen(wxNullPen
);
609 dc
.SetBrush(wxNullBrush
);
612 // Draw the sash tracker (for whilst moving the sash)
613 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
616 GetClientSize(&w
, &h
);
622 if ( m_splitMode
== wxSPLIT_VERTICAL
)
653 ClientToScreen(&x1
, &y1
);
654 ClientToScreen(&x2
, &y2
);
656 screenDC
.SetLogicalFunction(wxINVERT
);
657 screenDC
.SetPen(*m_sashTrackerPen
);
658 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
660 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
662 screenDC
.SetLogicalFunction(wxCOPY
);
664 screenDC
.SetPen(wxNullPen
);
665 screenDC
.SetBrush(wxNullBrush
);
668 // Position and size subwindows.
669 // Note that the border size applies to each subwindow, not
670 // including the edges next to the sash.
671 void wxSplitterWindow::SizeWindows()
674 GetClientSize(&w
, &h
);
676 if ( GetWindow1() && !GetWindow2() )
678 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(), w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
681 else if ( GetWindow1() && GetWindow2() )
683 if (GetSplitMode() == wxSPLIT_VERTICAL
)
685 int x1
= GetBorderSize();
686 int y1
= GetBorderSize();
687 int w1
= GetSashPosition() - GetBorderSize();
688 int h1
= h
- 2*GetBorderSize();
690 int x2
= GetSashPosition() + GetSashSize();
691 int y2
= GetBorderSize();
692 int w2
= w
- 2*GetBorderSize() - GetSashSize() - w1
;
693 int h2
= h
- 2*GetBorderSize();
695 GetWindow1()->SetSize(x1
, y1
, w1
, h1
);
696 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
700 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
701 w
- 2*GetBorderSize(), GetSashPosition() - GetBorderSize());
702 GetWindow2()->SetSize(GetBorderSize(), GetSashPosition() + GetSashSize(),
703 w
- 2*GetBorderSize(), h
- 2*GetBorderSize() - GetSashSize() - (GetSashPosition() - GetBorderSize()));
707 if ( GetBorderSize() > 0 )
711 SetNeedUpdating(FALSE
);
714 // Set pane for unsplit window
715 void wxSplitterWindow::Initialize(wxWindow
*window
)
717 m_windowOne
= window
;
718 m_windowTwo
= (wxWindow
*) NULL
;
722 // Associates the given window with window 2, drawing the appropriate sash
723 // and changing the split mode.
724 // Does nothing and returns FALSE if the window is already split.
725 bool wxSplitterWindow::SplitVertically(wxWindow
*window1
, wxWindow
*window2
, int sashPosition
)
731 GetClientSize(&w
, &h
);
733 m_splitMode
= wxSPLIT_VERTICAL
;
734 m_windowOne
= window1
;
735 m_windowTwo
= window2
;
736 if ( sashPosition
> 0 )
737 m_sashPosition
= sashPosition
;
738 else if ( sashPosition
< 0 )
739 m_sashPosition
= w
+ sashPosition
; // It's negative so adding is subtracting
741 m_sashPosition
= w
/2;
748 bool wxSplitterWindow::SplitHorizontally(wxWindow
*window1
, wxWindow
*window2
, int sashPosition
)
754 GetClientSize(&w
, &h
);
756 m_splitMode
= wxSPLIT_HORIZONTAL
;
757 m_windowOne
= window1
;
758 m_windowTwo
= window2
;
759 if ( sashPosition
> 0 )
760 m_sashPosition
= sashPosition
;
761 else if ( sashPosition
< 0 )
762 m_sashPosition
= h
+ sashPosition
; // It's negative so adding is subtracting
764 m_sashPosition
= h
/2;
772 // Remove the specified (or second) window from the view
773 // Doesn't actually delete the window.
774 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
779 wxWindow
*win
= NULL
;
780 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
783 m_windowTwo
= (wxWindow
*) NULL
;
785 else if ( toRemove
== m_windowOne
)
788 m_windowOne
= m_windowTwo
;
789 m_windowTwo
= (wxWindow
*) NULL
;
793 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
798 SendUnsplitEvent(win
);
805 // Replace a window with another one
806 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
808 wxCHECK_MSG( winOld
, FALSE
, wxT("use one of Split() functions instead") );
809 wxCHECK_MSG( winNew
, FALSE
, wxT("use Unsplit() functions instead") );
811 if ( winOld
== m_windowTwo
)
813 m_windowTwo
= winNew
;
815 else if ( winOld
== m_windowOne
)
817 m_windowOne
= winNew
;
821 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
831 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
833 m_sashPosition
= position
;
841 // Initialize colours
842 void wxSplitterWindow::InitColours()
844 wxDELETE( m_facePen
);
845 wxDELETE( m_faceBrush
);
846 wxDELETE( m_mediumShadowPen
);
847 wxDELETE( m_darkShadowPen
);
848 wxDELETE( m_lightShadowPen
);
849 wxDELETE( m_hilightPen
);
853 wxColour
faceColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
854 m_facePen
= new wxPen(faceColour
, 1, wxSOLID
);
855 m_faceBrush
= new wxBrush(faceColour
, wxSOLID
);
857 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
858 m_mediumShadowPen
= new wxPen(mediumShadowColour
, 1, wxSOLID
);
860 wxColour
darkShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DDKSHADOW
));
861 m_darkShadowPen
= new wxPen(darkShadowColour
, 1, wxSOLID
);
863 wxColour
lightShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
));
864 m_lightShadowPen
= new wxPen(lightShadowColour
, 1, wxSOLID
);
866 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
867 m_hilightPen
= new wxPen(hilightColour
, 1, wxSOLID
);
869 m_facePen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
870 m_faceBrush
= new wxBrush("LIGHT GREY", wxSOLID
);
871 m_mediumShadowPen
= new wxPen("GREY", 1, wxSOLID
);
872 m_darkShadowPen
= new wxPen("BLACK", 1, wxSOLID
);
873 m_lightShadowPen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
874 m_hilightPen
= new wxPen("WHITE", 1, wxSOLID
);
878 void wxSplitterWindow::SendUnsplitEvent(wxWindow
*winRemoved
)
880 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
881 event
.m_data
.win
= winRemoved
;
883 (void)GetEventHandler()->ProcessEvent(event
);
886 // ---------------------------------------------------------------------------
887 // splitter event handlers
888 // ---------------------------------------------------------------------------
890 void wxSplitterWindow::OnSashPosChanged(wxSplitterEvent
& event
)
892 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
893 const int UNSPLIT_THRESHOLD
= 4;
895 int newSashPosition
= event
.GetSashPosition();
897 // Obtain relevant window dimension for bottom / right threshold check
899 GetClientSize(&w
, &h
);
900 int window_size
= (m_splitMode
== wxSPLIT_VERTICAL
) ? w
: h
;
902 bool unsplit_scenario
= FALSE
;
903 if ( m_permitUnsplitAlways
904 || m_minimumPaneSize
== 0 )
906 // Do edge detection if unsplit premitted
907 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
909 // threshold top / left check
911 unsplit_scenario
= TRUE
;
913 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
915 // threshold bottom/right check
916 newSashPosition
= window_size
;
917 unsplit_scenario
= TRUE
;
921 if ( !unsplit_scenario
)
923 // If resultant pane would be too small, enlarge it
924 if ( newSashPosition
< m_minimumPaneSize
)
925 newSashPosition
= m_minimumPaneSize
;
926 if ( newSashPosition
> window_size
- m_minimumPaneSize
)
927 newSashPosition
= window_size
- m_minimumPaneSize
;
930 // If the result is out of bounds it means minimum size is too big,
931 // so split window in half as best compromise.
932 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
933 newSashPosition
= window_size
/ 2;
935 // for compatibility, call the virtual function
936 if ( !OnSashPositionChange(newSashPosition
) )
938 newSashPosition
= -1;
941 event
.SetSashPosition(newSashPosition
);
944 // Called when the sash is double-clicked. The default behaviour is to remove
945 // the sash if the minimum pane size is zero.
946 void wxSplitterWindow::OnDoubleClick(wxSplitterEvent
& event
)
948 // for compatibility, call the virtual function
949 OnDoubleClickSash(event
.GetX(), event
.GetY());
951 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
957 void wxSplitterWindow::OnUnsplitEvent(wxSplitterEvent
& event
)
959 wxWindow
*win
= event
.GetWindowBeingRemoved();
961 // do it before calling OnUnsplit() which may delete the window
964 // for compatibility, call the virtual function
968 #if defined(__WXMSW__)
969 #define WXUNUSED_UNLESS_MSW(identifier) identifier
971 #define WXUNUSED_UNLESS_MSW(identifier) WXUNUSED(identifier)
974 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& WXUNUSED_UNLESS_MSW(event
))
976 // this is currently called (and needed) under MSW only...
979 // if we don't do it, the resizing cursor might be set for child window:
980 // and like this we explicitly say that our cursor should not be used for
981 // children windows which overlap us
983 if ( SashHitTest(event
.GetX(), event
.GetY()) )
985 // default processing is ok
988 //else: do nothing, in particular, don't call Skip()