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
, wxCommandEvent
)
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
)
52 EVT_SET_CURSOR(wxSplitterWindow::OnSetCursor
)
54 EVT_SPLITTER_SASH_POS_CHANGED(-1, wxSplitterWindow::OnSashPosChanged
)
55 // NB: we borrow OnSashPosChanged for purposes of
56 // EVT_SPLITTER_SASH_POS_CHANGING since default implementation is identical
57 EVT_SPLITTER_SASH_POS_CHANGING(-1, wxSplitterWindow::OnSashPosChanged
)
58 EVT_SPLITTER_DCLICK(-1, wxSplitterWindow::OnDoubleClick
)
59 EVT_SPLITTER_UNSPLIT(-1, wxSplitterWindow::OnUnsplitEvent
)
61 WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow
)
64 WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow
);
66 bool wxSplitterWindow::Create(wxWindow
*parent
, wxWindowID id
,
72 // allow TABbing from one window to the other
73 style
|= wxTAB_TRAVERSAL
;
75 if (!wxWindow::Create(parent
, id
, pos
, size
, style
, name
))
78 m_permitUnsplitAlways
= (style
& wxSP_PERMIT_UNSPLIT
) != 0;
80 if ( style
& wxSP_3DSASH
)
85 if ( style
& wxSP_3DBORDER
)
87 else if ( style
& wxSP_BORDER
)
94 wxGetOsVersion( &major
, &minor
);
96 m_windowStyle
|= wxSP_SASH_AQUA
;
102 void wxSplitterWindow::Init()
104 m_container
.SetContainerWindow(this);
106 m_splitMode
= wxSPLIT_VERTICAL
;
107 m_permitUnsplitAlways
= TRUE
;
108 m_windowOne
= (wxWindow
*) NULL
;
109 m_windowTwo
= (wxWindow
*) NULL
;
110 m_dragMode
= wxSPLIT_DRAG_NONE
;
118 m_minimumPaneSize
= 0;
119 m_sashCursorWE
= new wxCursor(wxCURSOR_SIZEWE
);
120 m_sashCursorNS
= new wxCursor(wxCURSOR_SIZENS
);
121 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxSOLID
);
122 m_lightShadowPen
= (wxPen
*) NULL
;
123 m_mediumShadowPen
= (wxPen
*) NULL
;
124 m_darkShadowPen
= (wxPen
*) NULL
;
125 m_faceBrush
= (wxBrush
*) NULL
;
126 m_facePen
= (wxPen
*) NULL
;
127 m_hilightPen
= (wxPen
*) NULL
;
134 m_needUpdating
= FALSE
;
137 wxSplitterWindow::~wxSplitterWindow()
139 delete m_sashCursorWE
;
140 delete m_sashCursorNS
;
141 delete m_sashTrackerPen
;
142 delete m_lightShadowPen
;
143 delete m_darkShadowPen
;
144 delete m_mediumShadowPen
;
150 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
154 if ( m_borderSize
> 0 )
159 void wxSplitterWindow::OnIdle(wxIdleEvent
& event
)
167 void wxSplitterWindow::OnMouseEvent(wxMouseEvent
& event
)
169 wxCoord x
= (wxCoord
)event
.GetX(),
170 y
= (wxCoord
)event
.GetY();
174 SetCursor(* wxSTANDARD_CURSOR
);
177 SetCursor(wxCursor());
180 if (GetWindowStyle() & wxSP_NOSASH
)
183 if (event
.LeftDown())
185 if ( SashHitTest(x
, y
) )
189 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
191 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
193 DrawSashTracker(x
, y
);
199 if ( m_splitMode
== wxSPLIT_VERTICAL
)
201 SetCursor(*m_sashCursorWE
);
205 SetCursor(*m_sashCursorNS
);
210 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
212 // We can stop dragging now and see what we've got.
213 m_dragMode
= wxSPLIT_DRAG_NONE
;
217 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
219 DrawSashTracker(m_oldX
, m_oldY
);
222 // Obtain window size. We are only interested in the dimension the sash
225 GetClientSize(&w
, &h
);
226 int window_size
= (m_splitMode
== wxSPLIT_VERTICAL
? w
: h
);
227 int new_sash_position
=
228 (int) ( m_splitMode
== wxSPLIT_VERTICAL
? x
: y
);
230 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
,
232 eventSplitter
.m_data
.pos
= new_sash_position
;
233 if ( GetEventHandler()->ProcessEvent(eventSplitter
) )
235 new_sash_position
= eventSplitter
.GetSashPosition();
236 if ( new_sash_position
== -1 )
238 // change not allowed
243 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
245 // Deal with possible unsplit scenarios
246 if ( new_sash_position
== 0 )
248 // We remove the first window from the view
249 wxWindow
*removedWindow
= m_windowOne
;
250 m_windowOne
= m_windowTwo
;
251 m_windowTwo
= (wxWindow
*) NULL
;
252 SendUnsplitEvent(removedWindow
);
255 else if ( new_sash_position
== window_size
)
257 // We remove the second window from the view
258 wxWindow
*removedWindow
= m_windowTwo
;
259 m_windowTwo
= (wxWindow
*) NULL
;
260 SendUnsplitEvent(removedWindow
);
265 m_sashPosition
= new_sash_position
;
270 m_sashPosition
= new_sash_position
;
274 } // left up && dragging
275 else if (event
.Moving() && !event
.Dragging())
277 // Just change the cursor if required
278 if ( SashHitTest(x
, y
) )
280 if ( m_splitMode
== wxSPLIT_VERTICAL
)
282 SetCursor(*m_sashCursorWE
);
286 SetCursor(*m_sashCursorNS
);
289 #if defined(__WXGTK__) || defined(__WXMSW__)
292 // We must set the normal cursor in MSW, because
293 // if the child window doesn't have a cursor, the
294 // parent's (splitter window) will be used, and this
295 // must be the standard cursor.
297 // where else do we unset the cursor?
298 SetCursor(* wxSTANDARD_CURSOR
);
302 else if (event
.Dragging() && (m_dragMode
== wxSPLIT_DRAG_DRAGGING
))
305 // Otherwise, the cursor sometimes reverts to the normal cursor
307 if ( m_splitMode
== wxSPLIT_VERTICAL
)
309 SetCursor(*m_sashCursorWE
);
313 SetCursor(*m_sashCursorNS
);
317 // Obtain window size. We are only interested in the dimension the sash
319 int new_sash_position
=
320 (int) ( m_splitMode
== wxSPLIT_VERTICAL
? x
: y
);
322 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
,
324 eventSplitter
.m_data
.pos
= new_sash_position
;
325 if ( GetEventHandler()->ProcessEvent(eventSplitter
) )
327 new_sash_position
= eventSplitter
.GetSashPosition();
328 if ( new_sash_position
== -1 )
330 // change not allowed
335 if (new_sash_position
== m_sashPosition
)
339 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
341 DrawSashTracker(m_oldX
, m_oldY
);
344 if (m_splitMode
== wxSPLIT_VERTICAL
)
345 x
= new_sash_position
;
347 y
= new_sash_position
;
349 // Remember old positions
354 // As we captured the mouse, we may get the mouse events from outside
355 // our window - for example, negative values in x, y. This has a weird
356 // consequence under MSW where we use unsigned values sometimes and
357 // signed ones other times: the coordinates turn as big positive
358 // numbers and so the sash is drawn on the *right* side of the window
359 // instead of the left (or bottom instead of top). Correct this.
360 if ( (short)m_oldX
< 0 )
362 if ( (short)m_oldY
< 0 )
367 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
369 DrawSashTracker(m_oldX
, m_oldY
);
373 m_sashPosition
= new_sash_position
;
374 m_needUpdating
= TRUE
;
377 else if ( event
.LeftDClick() )
379 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
,
381 eventSplitter
.m_data
.pt
.x
= x
;
382 eventSplitter
.m_data
.pt
.y
= y
;
384 (void)GetEventHandler()->ProcessEvent(eventSplitter
);
388 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
390 // only process this message if we're not iconized - otherwise iconizing
391 // and restoring a window containing the splitter has a funny side effect
392 // of changing the splitter position!
393 wxWindow
*parent
= GetParent();
394 while ( parent
&& !parent
->IsTopLevel() )
396 parent
= parent
->GetParent();
399 bool iconized
= FALSE
;
400 wxFrame
*frame
= wxDynamicCast(parent
, wxFrame
);
402 iconized
= frame
->IsIconized();
405 wxDialog
*dialog
= wxDynamicCast(parent
, wxDialog
);
407 iconized
= dialog
->IsIconized();
409 wxFAIL_MSG(wxT("should have a top level frame or dialog parent!"));
419 GetClientSize( &cw
, &ch
);
422 if ( m_splitMode
== wxSPLIT_VERTICAL
)
424 if ( m_sashPosition
>= (cw
- 5) )
425 m_sashPosition
= wxMax(10, cw
- 40);
427 if ( m_splitMode
== wxSPLIT_HORIZONTAL
)
429 if ( m_sashPosition
>= (ch
- 5) )
430 m_sashPosition
= wxMax(10, ch
- 40);
438 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
440 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
441 return FALSE
; // No sash
443 if ( m_splitMode
== wxSPLIT_VERTICAL
)
445 if ( (x
>= m_sashPosition
- tolerance
) && (x
<= m_sashPosition
+ m_sashSize
+ tolerance
) )
452 if ( (y
>= (m_sashPosition
- tolerance
)) && (y
<= (m_sashPosition
+ m_sashSize
+ tolerance
)) )
459 // Draw 3D effect borders
460 void wxSplitterWindow::DrawBorders(wxDC
& dc
)
463 GetClientSize(&w
, &h
);
465 if ( GetWindowStyleFlag() & wxSP_3DBORDER
)
468 dc
.SetPen(*m_facePen
);
469 dc
.SetBrush(*m_faceBrush
);
470 dc
.DrawRectangle(1, 1 , w
-1, m_borderSize
-2 ); //high
471 dc
.DrawRectangle(1, m_borderSize
-2 , m_borderSize
-2, h
-1 ); // left
472 dc
.DrawRectangle(w
-m_borderSize
+2, m_borderSize
-2 , w
-1, h
-1 ); // right
473 dc
.DrawRectangle(m_borderSize
-2, h
-m_borderSize
+2 , w
-m_borderSize
+2, h
-1 ); //bottom
475 dc
.SetPen(*m_mediumShadowPen
);
476 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, w
-m_borderSize
+1, m_borderSize
-2);
477 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, m_borderSize
-2, h
-m_borderSize
+1);
479 dc
.SetPen(*m_darkShadowPen
);
480 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, w
-m_borderSize
, m_borderSize
-1);
481 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, m_borderSize
-1, h
-m_borderSize
);
483 dc
.SetPen(*m_hilightPen
);
484 dc
.DrawLine(m_borderSize
- 2, h
-m_borderSize
+1, w
-m_borderSize
+1, h
-m_borderSize
+1);
485 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.
486 /// Anyway, h is required for MSW.
488 dc
.SetPen(*m_lightShadowPen
);
489 dc
.DrawLine(w
-m_borderSize
, m_borderSize
-1, w
-m_borderSize
, h
-m_borderSize
); // Right hand side
490 dc
.DrawLine(m_borderSize
-1, h
-m_borderSize
, w
-m_borderSize
+1, h
-m_borderSize
); // Bottom
492 else if ( GetWindowStyleFlag() & wxSP_BORDER
)
494 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
495 dc
.SetPen(*wxBLACK_PEN
);
496 dc
.DrawRectangle(0, 0, w
-1, h
-1);
499 dc
.SetPen(wxNullPen
);
500 dc
.SetBrush(wxNullBrush
);
504 void wxSplitterWindow::DrawSash(wxDC
& dc
)
506 if ( m_sashPosition
== 0 || !m_windowTwo
)
508 if (GetWindowStyle() & wxSP_NOSASH
)
512 GetClientSize(&w
, &h
);
514 if ( GetWindowStyleFlag() & wxSP_3DSASH
)
516 if ( m_splitMode
== wxSPLIT_VERTICAL
)
518 dc
.SetPen(*m_facePen
);
520 if (HasFlag( wxSP_SASH_AQUA
))
521 dc
.SetBrush(*wxWHITE_BRUSH
);
523 dc
.SetBrush(*m_faceBrush
);
524 dc
.DrawRectangle(m_sashPosition
+ 2, 0 , m_sashSize
- 4, h
);
526 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
528 dc
.SetPen(*m_lightShadowPen
);
529 int xShadow
= m_borderSize
? m_borderSize
- 1 : 0 ;
530 dc
.DrawLine(m_sashPosition
, xShadow
, m_sashPosition
, h
-m_borderSize
);
532 dc
.SetPen(*m_hilightPen
);
533 dc
.DrawLine(m_sashPosition
+1, m_borderSize
- 2, m_sashPosition
+1, h
- m_borderSize
+2);
535 if (!HasFlag( wxSP_SASH_AQUA
))
536 dc
.SetPen(*m_mediumShadowPen
);
538 int yMedium
= m_borderSize
? h
-m_borderSize
+1 : h
;
539 dc
.DrawLine(m_sashPosition
+m_sashSize
-2, xShadow
, m_sashPosition
+m_sashSize
-2, yMedium
);
541 if (HasFlag( wxSP_SASH_AQUA
))
542 dc
.SetPen(*m_lightShadowPen
);
544 dc
.SetPen(*m_darkShadowPen
);
545 dc
.DrawLine(m_sashPosition
+m_sashSize
-1, m_borderSize
, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
);
547 // Draw the top and bottom edges of the sash, if requested
548 if (GetWindowStyle() & wxSP_FULLSASH
)
551 dc
.SetPen(*m_hilightPen
);
552 dc
.DrawLine(m_sashPosition
+1, m_borderSize
, m_sashPosition
+m_sashSize
-1, m_borderSize
);
555 dc
.SetPen(*m_darkShadowPen
);
556 dc
.DrawLine(m_sashPosition
+1, h
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
-1);
561 dc
.SetPen(*m_facePen
);
562 if (HasFlag( wxSP_SASH_AQUA
))
563 dc
.SetBrush(*wxWHITE_BRUSH
);
565 dc
.SetBrush(*m_faceBrush
);
566 dc
.DrawRectangle( m_borderSize
-2, m_sashPosition
+ 2, w
-m_borderSize
+2, m_sashSize
- 4);
568 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
570 dc
.SetPen(*m_lightShadowPen
);
571 dc
.DrawLine(m_borderSize
-1, m_sashPosition
, w
-m_borderSize
, m_sashPosition
);
573 dc
.SetPen(*m_hilightPen
);
574 dc
.DrawLine(m_borderSize
-2, m_sashPosition
+1, w
-m_borderSize
+1, m_sashPosition
+1);
576 if (!HasFlag( wxSP_SASH_AQUA
))
577 dc
.SetPen(*m_mediumShadowPen
);
578 dc
.DrawLine(m_borderSize
-1, m_sashPosition
+m_sashSize
-2, w
-m_borderSize
+1, m_sashPosition
+m_sashSize
-2);
580 if (HasFlag( wxSP_SASH_AQUA
))
581 dc
.SetPen(*m_lightShadowPen
);
583 dc
.SetPen(*m_darkShadowPen
);
584 dc
.DrawLine(m_borderSize
, m_sashPosition
+m_sashSize
-1, w
-m_borderSize
, m_sashPosition
+m_sashSize
-1);
586 // Draw the left and right edges of the sash, if requested
587 if (GetWindowStyle() & wxSP_FULLSASH
)
590 dc
.SetPen(*m_hilightPen
);
591 dc
.DrawLine(m_borderSize
, m_sashPosition
, m_borderSize
, m_sashPosition
+m_sashSize
);
594 dc
.SetPen(*m_darkShadowPen
);
595 dc
.DrawLine(w
-m_borderSize
-1, m_sashPosition
+1, w
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1);
601 if ( m_splitMode
== wxSPLIT_VERTICAL
)
603 dc
.SetPen(*wxBLACK_PEN
);
604 dc
.SetBrush(*wxBLACK_BRUSH
);
607 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
608 h1
+= 1; // Not sure why this is necessary...
609 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
613 dc
.DrawRectangle(m_sashPosition
, y1
, m_sashSize
, h1
);
617 dc
.SetPen(*wxBLACK_PEN
);
618 dc
.SetBrush(*wxBLACK_BRUSH
);
621 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
623 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
627 dc
.DrawRectangle(x1
, m_sashPosition
, w1
, m_sashSize
);
632 dc
.SetPen(wxNullPen
);
633 dc
.SetBrush(wxNullBrush
);
636 // Draw the sash tracker (for whilst moving the sash)
637 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
640 GetClientSize(&w
, &h
);
646 if ( m_splitMode
== wxSPLIT_VERTICAL
)
677 ClientToScreen(&x1
, &y1
);
678 ClientToScreen(&x2
, &y2
);
680 screenDC
.SetLogicalFunction(wxINVERT
);
681 screenDC
.SetPen(*m_sashTrackerPen
);
682 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
684 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
686 screenDC
.SetLogicalFunction(wxCOPY
);
688 screenDC
.SetPen(wxNullPen
);
689 screenDC
.SetBrush(wxNullBrush
);
692 // Position and size subwindows.
693 // Note that the border size applies to each subwindow, not
694 // including the edges next to the sash.
695 void wxSplitterWindow::SizeWindows()
698 GetClientSize(&w
, &h
);
700 if ( GetWindow1() && !GetWindow2() )
702 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(), w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
705 else if ( GetWindow1() && GetWindow2() )
707 if (GetSplitMode() == wxSPLIT_VERTICAL
)
709 int x1
= GetBorderSize();
710 int y1
= GetBorderSize();
711 int w1
= GetSashPosition() - GetBorderSize();
712 int h1
= h
- 2*GetBorderSize();
714 int x2
= GetSashPosition() + GetSashSize();
715 int y2
= GetBorderSize();
716 int w2
= w
- 2*GetBorderSize() - GetSashSize() - w1
;
717 int h2
= h
- 2*GetBorderSize();
719 GetWindow1()->SetSize(x1
, y1
, w1
, h1
);
720 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
724 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
725 w
- 2*GetBorderSize(), GetSashPosition() - GetBorderSize());
726 GetWindow2()->SetSize(GetBorderSize(), GetSashPosition() + GetSashSize(),
727 w
- 2*GetBorderSize(), h
- 2*GetBorderSize() - GetSashSize() - (GetSashPosition() - GetBorderSize()));
731 if ( GetBorderSize() > 0 )
735 SetNeedUpdating(FALSE
);
738 // Set pane for unsplit window
739 void wxSplitterWindow::Initialize(wxWindow
*window
)
741 m_windowOne
= window
;
742 m_windowTwo
= (wxWindow
*) NULL
;
746 // Associates the given window with window 2, drawing the appropriate sash
747 // and changing the split mode.
748 // Does nothing and returns FALSE if the window is already split.
749 bool wxSplitterWindow::SplitVertically(wxWindow
*window1
, wxWindow
*window2
, int sashPosition
)
755 GetClientSize(&w
, &h
);
757 m_splitMode
= wxSPLIT_VERTICAL
;
758 m_windowOne
= window1
;
759 m_windowTwo
= window2
;
760 if ( sashPosition
> 0 )
761 m_sashPosition
= sashPosition
;
762 else if ( sashPosition
< 0 )
763 m_sashPosition
= w
+ sashPosition
; // It's negative so adding is subtracting
765 m_sashPosition
= w
/2;
772 bool wxSplitterWindow::SplitHorizontally(wxWindow
*window1
, wxWindow
*window2
, int sashPosition
)
778 GetClientSize(&w
, &h
);
780 m_splitMode
= wxSPLIT_HORIZONTAL
;
781 m_windowOne
= window1
;
782 m_windowTwo
= window2
;
783 if ( sashPosition
> 0 )
784 m_sashPosition
= sashPosition
;
785 else if ( sashPosition
< 0 )
786 m_sashPosition
= h
+ sashPosition
; // It's negative so adding is subtracting
788 m_sashPosition
= h
/2;
796 // Remove the specified (or second) window from the view
797 // Doesn't actually delete the window.
798 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
803 wxWindow
*win
= NULL
;
804 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
807 m_windowTwo
= (wxWindow
*) NULL
;
809 else if ( toRemove
== m_windowOne
)
812 m_windowOne
= m_windowTwo
;
813 m_windowTwo
= (wxWindow
*) NULL
;
817 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
822 SendUnsplitEvent(win
);
829 // Replace a window with another one
830 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
832 wxCHECK_MSG( winOld
, FALSE
, wxT("use one of Split() functions instead") );
833 wxCHECK_MSG( winNew
, FALSE
, wxT("use Unsplit() functions instead") );
835 if ( winOld
== m_windowTwo
)
837 m_windowTwo
= winNew
;
839 else if ( winOld
== m_windowOne
)
841 m_windowOne
= winNew
;
845 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
855 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
857 m_sashPosition
= position
;
865 // Initialize colours
866 void wxSplitterWindow::InitColours()
868 wxDELETE( m_facePen
);
869 wxDELETE( m_faceBrush
);
870 wxDELETE( m_mediumShadowPen
);
871 wxDELETE( m_darkShadowPen
);
872 wxDELETE( m_lightShadowPen
);
873 wxDELETE( m_hilightPen
);
877 wxColour
faceColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
878 m_facePen
= new wxPen(faceColour
, 1, wxSOLID
);
879 m_faceBrush
= new wxBrush(faceColour
, wxSOLID
);
881 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
882 m_mediumShadowPen
= new wxPen(mediumShadowColour
, 1, wxSOLID
);
884 wxColour
darkShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DDKSHADOW
));
885 m_darkShadowPen
= new wxPen(darkShadowColour
, 1, wxSOLID
);
887 wxColour
lightShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
));
888 m_lightShadowPen
= new wxPen(lightShadowColour
, 1, wxSOLID
);
890 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
891 m_hilightPen
= new wxPen(hilightColour
, 1, wxSOLID
);
893 m_facePen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
894 m_faceBrush
= new wxBrush("LIGHT GREY", wxSOLID
);
895 m_mediumShadowPen
= new wxPen("GREY", 1, wxSOLID
);
896 m_darkShadowPen
= new wxPen("BLACK", 1, wxSOLID
);
897 m_lightShadowPen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
898 m_hilightPen
= new wxPen("WHITE", 1, wxSOLID
);
902 void wxSplitterWindow::SendUnsplitEvent(wxWindow
*winRemoved
)
904 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
905 event
.m_data
.win
= winRemoved
;
907 (void)GetEventHandler()->ProcessEvent(event
);
910 // ---------------------------------------------------------------------------
911 // splitter event handlers
912 // ---------------------------------------------------------------------------
914 void wxSplitterWindow::OnSashPosChanged(wxSplitterEvent
& event
)
916 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
917 const int UNSPLIT_THRESHOLD
= 4;
919 int newSashPosition
= event
.GetSashPosition();
921 // Obtain relevant window dimension for bottom / right threshold check
923 GetClientSize(&w
, &h
);
924 int window_size
= (m_splitMode
== wxSPLIT_VERTICAL
) ? w
: h
;
926 bool unsplit_scenario
= FALSE
;
927 if ( m_permitUnsplitAlways
928 || m_minimumPaneSize
== 0 )
930 // Do edge detection if unsplit premitted
931 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
933 // threshold top / left check
935 unsplit_scenario
= TRUE
;
937 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
939 // threshold bottom/right check
940 newSashPosition
= window_size
;
941 unsplit_scenario
= TRUE
;
945 if ( !unsplit_scenario
)
947 // If resultant pane would be too small, enlarge it
948 if ( newSashPosition
< m_minimumPaneSize
)
949 newSashPosition
= m_minimumPaneSize
;
950 if ( newSashPosition
> window_size
- m_minimumPaneSize
)
951 newSashPosition
= window_size
- m_minimumPaneSize
;
954 // If the result is out of bounds it means minimum size is too big,
955 // so split window in half as best compromise.
956 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
957 newSashPosition
= window_size
/ 2;
959 // for compatibility, call the virtual function
960 if ( !OnSashPositionChange(newSashPosition
) )
962 newSashPosition
= -1;
965 event
.SetSashPosition(newSashPosition
);
968 // Called when the sash is double-clicked. The default behaviour is to remove
969 // the sash if the minimum pane size is zero.
970 void wxSplitterWindow::OnDoubleClick(wxSplitterEvent
& event
)
972 // for compatibility, call the virtual function
973 OnDoubleClickSash(event
.GetX(), event
.GetY());
975 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
981 void wxSplitterWindow::OnUnsplitEvent(wxSplitterEvent
& event
)
983 wxWindow
*win
= event
.GetWindowBeingRemoved();
985 // do it before calling OnUnsplit() which may delete the window
988 // for compatibility, call the virtual function
992 #if defined(__WXMSW__)
993 #define WXUNUSED_UNLESS_MSW(identifier) identifier
995 #define WXUNUSED_UNLESS_MSW(identifier) WXUNUSED(identifier)
998 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& WXUNUSED_UNLESS_MSW(event
))
1000 // this is currently called (and needed) under MSW only...
1003 // if we don't do it, the resizing cursor might be set for child window:
1004 // and like this we explicitly say that our cursor should not be used for
1005 // children windows which overlap us
1007 if ( SashHitTest(event
.GetX(), event
.GetY()) )
1009 // default processing is ok
1012 //else: do nothing, in particular, don't call Skip()