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_splitMode
= wxSPLIT_VERTICAL
;
97 m_permitUnsplitAlways
= TRUE
;
98 m_windowOne
= (wxWindow
*) NULL
;
99 m_windowTwo
= (wxWindow
*) NULL
;
100 m_dragMode
= wxSPLIT_DRAG_NONE
;
108 m_minimumPaneSize
= 0;
109 m_sashCursorWE
= new wxCursor(wxCURSOR_SIZEWE
);
110 m_sashCursorNS
= new wxCursor(wxCURSOR_SIZENS
);
111 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxSOLID
);
112 m_lightShadowPen
= (wxPen
*) NULL
;
113 m_mediumShadowPen
= (wxPen
*) NULL
;
114 m_darkShadowPen
= (wxPen
*) NULL
;
115 m_faceBrush
= (wxBrush
*) NULL
;
116 m_facePen
= (wxPen
*) NULL
;
117 m_hilightPen
= (wxPen
*) NULL
;
124 m_needUpdating
= FALSE
;
127 wxSplitterWindow::~wxSplitterWindow()
129 delete m_sashCursorWE
;
130 delete m_sashCursorNS
;
131 delete m_sashTrackerPen
;
132 delete m_lightShadowPen
;
133 delete m_darkShadowPen
;
134 delete m_mediumShadowPen
;
140 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
144 if ( m_borderSize
> 0 )
149 void wxSplitterWindow::OnIdle(wxIdleEvent
& event
)
157 void wxSplitterWindow::OnMouseEvent(wxMouseEvent
& event
)
159 wxCoord x
= (wxCoord
)event
.GetX(),
160 y
= (wxCoord
)event
.GetY();
164 SetCursor(* wxSTANDARD_CURSOR
);
167 SetCursor(wxCursor());
170 if (GetWindowStyle() & wxSP_NOSASH
)
173 if (event
.LeftDown())
175 if ( SashHitTest(x
, y
) )
179 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
181 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
183 DrawSashTracker(x
, y
);
189 if ( m_splitMode
== wxSPLIT_VERTICAL
)
191 SetCursor(*m_sashCursorWE
);
195 SetCursor(*m_sashCursorNS
);
200 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
202 // We can stop dragging now and see what we've got.
203 m_dragMode
= wxSPLIT_DRAG_NONE
;
207 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
209 DrawSashTracker(m_oldX
, m_oldY
);
212 // Obtain window size. We are only interested in the dimension the sash
215 GetClientSize(&w
, &h
);
216 int window_size
= (m_splitMode
== wxSPLIT_VERTICAL
? w
: h
);
217 int new_sash_position
=
218 (int) ( m_splitMode
== wxSPLIT_VERTICAL
? x
: y
);
220 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
,
222 eventSplitter
.m_data
.pos
= new_sash_position
;
223 if ( GetEventHandler()->ProcessEvent(eventSplitter
) )
225 new_sash_position
= eventSplitter
.GetSashPosition();
226 if ( new_sash_position
== -1 )
228 // change not allowed
233 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
235 // Deal with possible unsplit scenarios
236 if ( new_sash_position
== 0 )
238 // We remove the first window from the view
239 wxWindow
*removedWindow
= m_windowOne
;
240 m_windowOne
= m_windowTwo
;
241 m_windowTwo
= (wxWindow
*) NULL
;
242 SendUnsplitEvent(removedWindow
);
245 else if ( new_sash_position
== window_size
)
247 // We remove the second window from the view
248 wxWindow
*removedWindow
= m_windowTwo
;
249 m_windowTwo
= (wxWindow
*) NULL
;
250 SendUnsplitEvent(removedWindow
);
255 m_sashPosition
= new_sash_position
;
260 m_sashPosition
= new_sash_position
;
264 } // left up && dragging
265 else if (event
.Moving() && !event
.Dragging())
267 // Just change the cursor if required
268 if ( SashHitTest(x
, y
) )
270 if ( m_splitMode
== wxSPLIT_VERTICAL
)
272 SetCursor(*m_sashCursorWE
);
276 SetCursor(*m_sashCursorNS
);
279 #if defined(__WXGTK__) || defined(__WXMSW__)
282 // We must set the normal cursor in MSW, because
283 // if the child window doesn't have a cursor, the
284 // parent's (splitter window) will be used, and this
285 // must be the standard cursor.
287 // where else do we unset the cursor?
288 SetCursor(* wxSTANDARD_CURSOR
);
292 else if (event
.Dragging() && (m_dragMode
== wxSPLIT_DRAG_DRAGGING
))
295 // Otherwise, the cursor sometimes reverts to the normal cursor
297 if ( m_splitMode
== wxSPLIT_VERTICAL
)
299 SetCursor(*m_sashCursorWE
);
303 SetCursor(*m_sashCursorNS
);
307 // Obtain window size. We are only interested in the dimension the sash
309 int new_sash_position
=
310 (int) ( m_splitMode
== wxSPLIT_VERTICAL
? x
: y
);
312 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
,
314 eventSplitter
.m_data
.pos
= new_sash_position
;
315 if ( GetEventHandler()->ProcessEvent(eventSplitter
) )
317 new_sash_position
= eventSplitter
.GetSashPosition();
318 if ( new_sash_position
== -1 )
320 // change not allowed
325 if (new_sash_position
== m_sashPosition
)
329 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
331 DrawSashTracker(m_oldX
, m_oldY
);
334 if (m_splitMode
== wxSPLIT_VERTICAL
)
335 x
= new_sash_position
;
337 y
= new_sash_position
;
339 // Remember old positions
344 // As we captured the mouse, we may get the mouse events from outside
345 // our window - for example, negative values in x, y. This has a weird
346 // consequence under MSW where we use unsigned values sometimes and
347 // signed ones other times: the coordinates turn as big positive
348 // numbers and so the sash is drawn on the *right* side of the window
349 // instead of the left (or bottom instead of top). Correct this.
350 if ( (short)m_oldX
< 0 )
352 if ( (short)m_oldY
< 0 )
357 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
359 DrawSashTracker(m_oldX
, m_oldY
);
363 m_sashPosition
= new_sash_position
;
364 m_needUpdating
= TRUE
;
367 else if ( event
.LeftDClick() )
369 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
,
371 eventSplitter
.m_data
.pt
.x
= x
;
372 eventSplitter
.m_data
.pt
.y
= y
;
374 (void)GetEventHandler()->ProcessEvent(eventSplitter
);
378 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
380 // only process this message if we're not iconized - otherwise iconizing
381 // and restoring a window containing the splitter has a funny side effect
382 // of changing the splitter position!
383 wxWindow
*parent
= GetParent();
384 while ( parent
&& !parent
->IsTopLevel() )
386 parent
= parent
->GetParent();
389 bool iconized
= FALSE
;
390 wxFrame
*frame
= wxDynamicCast(parent
, wxFrame
);
392 iconized
= frame
->IsIconized();
395 wxDialog
*dialog
= wxDynamicCast(parent
, wxDialog
);
397 iconized
= dialog
->IsIconized();
399 wxFAIL_MSG(wxT("should have a top level frame or dialog parent!"));
409 GetClientSize( &cw
, &ch
);
412 if ( m_splitMode
== wxSPLIT_VERTICAL
)
414 if ( m_sashPosition
>= (cw
- 5) )
415 m_sashPosition
= wxMax(10, cw
- 40);
417 if ( m_splitMode
== wxSPLIT_HORIZONTAL
)
419 if ( m_sashPosition
>= (ch
- 5) )
420 m_sashPosition
= wxMax(10, ch
- 40);
428 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
430 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
431 return FALSE
; // No sash
433 if ( m_splitMode
== wxSPLIT_VERTICAL
)
435 if ( (x
>= m_sashPosition
- tolerance
) && (x
<= m_sashPosition
+ m_sashSize
+ tolerance
) )
442 if ( (y
>= (m_sashPosition
- tolerance
)) && (y
<= (m_sashPosition
+ m_sashSize
+ tolerance
)) )
449 // Draw 3D effect borders
450 void wxSplitterWindow::DrawBorders(wxDC
& dc
)
453 GetClientSize(&w
, &h
);
455 if ( GetWindowStyleFlag() & wxSP_3DBORDER
)
458 dc
.SetPen(*m_facePen
);
459 dc
.SetBrush(*m_faceBrush
);
460 dc
.DrawRectangle(1, 1 , w
-1, m_borderSize
-2 ); //high
461 dc
.DrawRectangle(1, m_borderSize
-2 , m_borderSize
-2, h
-1 ); // left
462 dc
.DrawRectangle(w
-m_borderSize
+2, m_borderSize
-2 , w
-1, h
-1 ); // right
463 dc
.DrawRectangle(m_borderSize
-2, h
-m_borderSize
+2 , w
-m_borderSize
+2, h
-1 ); //bottom
465 dc
.SetPen(*m_mediumShadowPen
);
466 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, w
-m_borderSize
+1, m_borderSize
-2);
467 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, m_borderSize
-2, h
-m_borderSize
+1);
469 dc
.SetPen(*m_darkShadowPen
);
470 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, w
-m_borderSize
, m_borderSize
-1);
471 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, m_borderSize
-1, h
-m_borderSize
);
473 dc
.SetPen(*m_hilightPen
);
474 dc
.DrawLine(m_borderSize
- 2, h
-m_borderSize
+1, w
-m_borderSize
+1, h
-m_borderSize
+1);
475 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.
476 /// Anyway, h is required for MSW.
478 dc
.SetPen(*m_lightShadowPen
);
479 dc
.DrawLine(w
-m_borderSize
, m_borderSize
-1, w
-m_borderSize
, h
-m_borderSize
); // Right hand side
480 dc
.DrawLine(m_borderSize
-1, h
-m_borderSize
, w
-m_borderSize
+1, h
-m_borderSize
); // Bottom
482 else if ( GetWindowStyleFlag() & wxSP_BORDER
)
484 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
485 dc
.SetPen(*wxBLACK_PEN
);
486 dc
.DrawRectangle(0, 0, w
-1, h
-1);
489 dc
.SetPen(wxNullPen
);
490 dc
.SetBrush(wxNullBrush
);
494 void wxSplitterWindow::DrawSash(wxDC
& dc
)
496 if ( m_sashPosition
== 0 || !m_windowTwo
)
498 if (GetWindowStyle() & wxSP_NOSASH
)
502 GetClientSize(&w
, &h
);
504 if ( GetWindowStyleFlag() & wxSP_3DSASH
)
506 if ( m_splitMode
== wxSPLIT_VERTICAL
)
508 dc
.SetPen(*m_facePen
);
509 dc
.SetBrush(*m_faceBrush
);
510 dc
.DrawRectangle(m_sashPosition
+ 2, 0 , m_sashSize
- 4, h
);
512 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
514 dc
.SetPen(*m_lightShadowPen
);
515 int xShadow
= m_borderSize
? m_borderSize
- 1 : 0 ;
516 dc
.DrawLine(m_sashPosition
, xShadow
, m_sashPosition
, h
-m_borderSize
);
518 dc
.SetPen(*m_hilightPen
);
519 dc
.DrawLine(m_sashPosition
+1, m_borderSize
- 2, m_sashPosition
+1, h
- m_borderSize
+2);
521 dc
.SetPen(*m_mediumShadowPen
);
522 int yMedium
= m_borderSize
? h
-m_borderSize
+1 : h
;
523 dc
.DrawLine(m_sashPosition
+m_sashSize
-2, xShadow
, m_sashPosition
+m_sashSize
-2, yMedium
);
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 dc
.SetBrush(*m_faceBrush
);
544 dc
.DrawRectangle( m_borderSize
-2, m_sashPosition
+ 2, w
-m_borderSize
+2, m_sashSize
- 4);
546 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
548 dc
.SetPen(*m_lightShadowPen
);
549 dc
.DrawLine(m_borderSize
-1, m_sashPosition
, w
-m_borderSize
, m_sashPosition
);
551 dc
.SetPen(*m_hilightPen
);
552 dc
.DrawLine(m_borderSize
-2, m_sashPosition
+1, w
-m_borderSize
+1, m_sashPosition
+1);
554 dc
.SetPen(*m_mediumShadowPen
);
555 dc
.DrawLine(m_borderSize
-1, m_sashPosition
+m_sashSize
-2, w
-m_borderSize
+1, m_sashPosition
+m_sashSize
-2);
557 dc
.SetPen(*m_darkShadowPen
);
558 dc
.DrawLine(m_borderSize
, m_sashPosition
+m_sashSize
-1, w
-m_borderSize
, m_sashPosition
+m_sashSize
-1);
560 // Draw the left and right edges of the sash, if requested
561 if (GetWindowStyle() & wxSP_FULLSASH
)
564 dc
.SetPen(*m_hilightPen
);
565 dc
.DrawLine(m_borderSize
, m_sashPosition
, m_borderSize
, m_sashPosition
+m_sashSize
);
568 dc
.SetPen(*m_darkShadowPen
);
569 dc
.DrawLine(w
-m_borderSize
-1, m_sashPosition
+1, w
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1);
575 if ( m_splitMode
== wxSPLIT_VERTICAL
)
577 dc
.SetPen(*wxBLACK_PEN
);
578 dc
.SetBrush(*wxBLACK_BRUSH
);
581 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
582 h1
+= 1; // Not sure why this is necessary...
583 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
587 dc
.DrawRectangle(m_sashPosition
, y1
, m_sashSize
, h1
);
591 dc
.SetPen(*wxBLACK_PEN
);
592 dc
.SetBrush(*wxBLACK_BRUSH
);
595 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
597 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
601 dc
.DrawRectangle(x1
, m_sashPosition
, w1
, m_sashSize
);
606 dc
.SetPen(wxNullPen
);
607 dc
.SetBrush(wxNullBrush
);
610 // Draw the sash tracker (for whilst moving the sash)
611 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
614 GetClientSize(&w
, &h
);
620 if ( m_splitMode
== wxSPLIT_VERTICAL
)
651 ClientToScreen(&x1
, &y1
);
652 ClientToScreen(&x2
, &y2
);
654 screenDC
.SetLogicalFunction(wxINVERT
);
655 screenDC
.SetPen(*m_sashTrackerPen
);
656 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
658 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
660 screenDC
.SetLogicalFunction(wxCOPY
);
662 screenDC
.SetPen(wxNullPen
);
663 screenDC
.SetBrush(wxNullBrush
);
666 // Position and size subwindows.
667 // Note that the border size applies to each subwindow, not
668 // including the edges next to the sash.
669 void wxSplitterWindow::SizeWindows()
672 GetClientSize(&w
, &h
);
674 if ( GetWindow1() && !GetWindow2() )
676 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(), w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
679 else if ( GetWindow1() && GetWindow2() )
681 if (GetSplitMode() == wxSPLIT_VERTICAL
)
683 int x1
= GetBorderSize();
684 int y1
= GetBorderSize();
685 int w1
= GetSashPosition() - GetBorderSize();
686 int h1
= h
- 2*GetBorderSize();
688 int x2
= GetSashPosition() + GetSashSize();
689 int y2
= GetBorderSize();
690 int w2
= w
- 2*GetBorderSize() - GetSashSize() - w1
;
691 int h2
= h
- 2*GetBorderSize();
693 GetWindow1()->SetSize(x1
, y1
, w1
, h1
);
694 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
698 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
699 w
- 2*GetBorderSize(), GetSashPosition() - GetBorderSize());
700 GetWindow2()->SetSize(GetBorderSize(), GetSashPosition() + GetSashSize(),
701 w
- 2*GetBorderSize(), h
- 2*GetBorderSize() - GetSashSize() - (GetSashPosition() - GetBorderSize()));
705 if ( GetBorderSize() > 0 )
709 SetNeedUpdating(FALSE
);
712 // Set pane for unsplit window
713 void wxSplitterWindow::Initialize(wxWindow
*window
)
715 m_windowOne
= window
;
716 m_windowTwo
= (wxWindow
*) NULL
;
720 // Associates the given window with window 2, drawing the appropriate sash
721 // and changing the split mode.
722 // Does nothing and returns FALSE if the window is already split.
723 bool wxSplitterWindow::SplitVertically(wxWindow
*window1
, wxWindow
*window2
, int sashPosition
)
729 GetClientSize(&w
, &h
);
731 m_splitMode
= wxSPLIT_VERTICAL
;
732 m_windowOne
= window1
;
733 m_windowTwo
= window2
;
734 if ( sashPosition
> 0 )
735 m_sashPosition
= sashPosition
;
736 else if ( sashPosition
< 0 )
737 m_sashPosition
= w
+ sashPosition
; // It's negative so adding is subtracting
739 m_sashPosition
= w
/2;
746 bool wxSplitterWindow::SplitHorizontally(wxWindow
*window1
, wxWindow
*window2
, int sashPosition
)
752 GetClientSize(&w
, &h
);
754 m_splitMode
= wxSPLIT_HORIZONTAL
;
755 m_windowOne
= window1
;
756 m_windowTwo
= window2
;
757 if ( sashPosition
> 0 )
758 m_sashPosition
= sashPosition
;
759 else if ( sashPosition
< 0 )
760 m_sashPosition
= h
+ sashPosition
; // It's negative so adding is subtracting
762 m_sashPosition
= h
/2;
770 // Remove the specified (or second) window from the view
771 // Doesn't actually delete the window.
772 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
777 wxWindow
*win
= NULL
;
778 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
781 m_windowTwo
= (wxWindow
*) NULL
;
783 else if ( toRemove
== m_windowOne
)
786 m_windowOne
= m_windowTwo
;
787 m_windowTwo
= (wxWindow
*) NULL
;
791 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
796 SendUnsplitEvent(win
);
803 // Replace a window with another one
804 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
806 wxCHECK_MSG( winOld
, FALSE
, wxT("use one of Split() functions instead") );
807 wxCHECK_MSG( winNew
, FALSE
, wxT("use Unsplit() functions instead") );
809 if ( winOld
== m_windowTwo
)
811 m_windowTwo
= winNew
;
813 else if ( winOld
== m_windowOne
)
815 m_windowOne
= winNew
;
819 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
829 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
831 m_sashPosition
= position
;
839 // Initialize colours
840 void wxSplitterWindow::InitColours()
842 wxDELETE( m_facePen
);
843 wxDELETE( m_faceBrush
);
844 wxDELETE( m_mediumShadowPen
);
845 wxDELETE( m_darkShadowPen
);
846 wxDELETE( m_lightShadowPen
);
847 wxDELETE( m_hilightPen
);
851 wxColour
faceColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
852 m_facePen
= new wxPen(faceColour
, 1, wxSOLID
);
853 m_faceBrush
= new wxBrush(faceColour
, wxSOLID
);
855 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
856 m_mediumShadowPen
= new wxPen(mediumShadowColour
, 1, wxSOLID
);
858 wxColour
darkShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DDKSHADOW
));
859 m_darkShadowPen
= new wxPen(darkShadowColour
, 1, wxSOLID
);
861 wxColour
lightShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
));
862 m_lightShadowPen
= new wxPen(lightShadowColour
, 1, wxSOLID
);
864 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
865 m_hilightPen
= new wxPen(hilightColour
, 1, wxSOLID
);
867 m_facePen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
868 m_faceBrush
= new wxBrush("LIGHT GREY", wxSOLID
);
869 m_mediumShadowPen
= new wxPen("GREY", 1, wxSOLID
);
870 m_darkShadowPen
= new wxPen("BLACK", 1, wxSOLID
);
871 m_lightShadowPen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
872 m_hilightPen
= new wxPen("WHITE", 1, wxSOLID
);
876 void wxSplitterWindow::SendUnsplitEvent(wxWindow
*winRemoved
)
878 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
879 event
.m_data
.win
= winRemoved
;
881 (void)GetEventHandler()->ProcessEvent(event
);
884 // ---------------------------------------------------------------------------
885 // splitter event handlers
886 // ---------------------------------------------------------------------------
888 void wxSplitterWindow::OnSashPosChanged(wxSplitterEvent
& event
)
890 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
891 const int UNSPLIT_THRESHOLD
= 4;
893 int newSashPosition
= event
.GetSashPosition();
895 // Obtain relevant window dimension for bottom / right threshold check
897 GetClientSize(&w
, &h
);
898 int window_size
= (m_splitMode
== wxSPLIT_VERTICAL
) ? w
: h
;
900 bool unsplit_scenario
= FALSE
;
901 if ( m_permitUnsplitAlways
902 || m_minimumPaneSize
== 0 )
904 // Do edge detection if unsplit premitted
905 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
907 // threshold top / left check
909 unsplit_scenario
= TRUE
;
911 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
913 // threshold bottom/right check
914 newSashPosition
= window_size
;
915 unsplit_scenario
= TRUE
;
919 if ( !unsplit_scenario
)
921 // If resultant pane would be too small, enlarge it
922 if ( newSashPosition
< m_minimumPaneSize
)
923 newSashPosition
= m_minimumPaneSize
;
924 if ( newSashPosition
> window_size
- m_minimumPaneSize
)
925 newSashPosition
= window_size
- m_minimumPaneSize
;
928 // If the result is out of bounds it means minimum size is too big,
929 // so split window in half as best compromise.
930 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
931 newSashPosition
= window_size
/ 2;
933 // for compatibility, call the virtual function
934 if ( !OnSashPositionChange(newSashPosition
) )
936 newSashPosition
= -1;
939 event
.SetSashPosition(newSashPosition
);
942 // Called when the sash is double-clicked. The default behaviour is to remove
943 // the sash if the minimum pane size is zero.
944 void wxSplitterWindow::OnDoubleClick(wxSplitterEvent
& event
)
946 // for compatibility, call the virtual function
947 OnDoubleClickSash(event
.GetX(), event
.GetY());
949 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
955 void wxSplitterWindow::OnUnsplitEvent(wxSplitterEvent
& event
)
957 wxWindow
*win
= event
.GetWindowBeingRemoved();
959 // do it before calling OnUnsplit() which may delete the window
962 // for compatibility, call the virtual function
966 #if defined(__WXMSW__)
967 #define WXUNUSED_UNLESS_MSW(identifier) identifier
969 #define WXUNUSED_UNLESS_MSW(identifier) WXUNUSED(identifier)
972 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& WXUNUSED_UNLESS_MSW(event
))
974 // this is currently called (and needed) under MSW only...
977 // if we don't do it, the resizing cursor might be set for child window:
978 // and like this we explicitly say that our cursor should not be used for
979 // children windows which overlap us
981 if ( SashHitTest(event
.GetX(), event
.GetY()) )
983 // default processing is ok
986 //else: do nothing, in particular, don't call Skip()