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 int x
= (int)event
.GetX(),
170 y
= (int)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
224 int window_size
= GetWindowSize();
225 int new_sash_position
= m_splitMode
== wxSPLIT_VERTICAL
? x
: y
;
227 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
,
229 eventSplitter
.m_data
.pos
= new_sash_position
;
230 if ( GetEventHandler()->ProcessEvent(eventSplitter
) )
232 new_sash_position
= eventSplitter
.GetSashPosition();
233 if ( new_sash_position
== -1 )
235 // change not allowed
240 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
242 // Deal with possible unsplit scenarios
243 if ( new_sash_position
== 0 )
245 // We remove the first window from the view
246 wxWindow
*removedWindow
= m_windowOne
;
247 m_windowOne
= m_windowTwo
;
248 m_windowTwo
= (wxWindow
*) NULL
;
249 SendUnsplitEvent(removedWindow
);
252 else if ( new_sash_position
== window_size
)
254 // We remove the second window from the view
255 wxWindow
*removedWindow
= m_windowTwo
;
256 m_windowTwo
= (wxWindow
*) NULL
;
257 SendUnsplitEvent(removedWindow
);
262 m_sashPosition
= new_sash_position
;
267 m_sashPosition
= new_sash_position
;
271 } // left up && dragging
272 else if (event
.Moving() && !event
.Dragging())
274 // Just change the cursor if required
275 if ( SashHitTest(x
, y
) )
277 if ( m_splitMode
== wxSPLIT_VERTICAL
)
279 SetCursor(*m_sashCursorWE
);
283 SetCursor(*m_sashCursorNS
);
286 #if defined(__WXGTK__) || defined(__WXMSW__)
289 // We must set the normal cursor in MSW, because
290 // if the child window doesn't have a cursor, the
291 // parent's (splitter window) will be used, and this
292 // must be the standard cursor.
294 // where else do we unset the cursor?
295 SetCursor(* wxSTANDARD_CURSOR
);
299 else if (event
.Dragging() && (m_dragMode
== wxSPLIT_DRAG_DRAGGING
))
302 // Otherwise, the cursor sometimes reverts to the normal cursor
304 if ( m_splitMode
== wxSPLIT_VERTICAL
)
306 SetCursor(*m_sashCursorWE
);
310 SetCursor(*m_sashCursorNS
);
314 // Obtain window size. We are only interested in the dimension the sash
316 int new_sash_position
= m_splitMode
== wxSPLIT_VERTICAL
? x
: y
;
318 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
,
320 eventSplitter
.m_data
.pos
= new_sash_position
;
321 if ( GetEventHandler()->ProcessEvent(eventSplitter
) )
323 new_sash_position
= eventSplitter
.GetSashPosition();
324 if ( new_sash_position
== -1 )
326 // change not allowed
331 if (new_sash_position
== m_sashPosition
)
335 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
337 DrawSashTracker(m_oldX
, m_oldY
);
340 if (m_splitMode
== wxSPLIT_VERTICAL
)
341 x
= new_sash_position
;
343 y
= new_sash_position
;
345 // Remember old positions
350 // As we captured the mouse, we may get the mouse events from outside
351 // our window - for example, negative values in x, y. This has a weird
352 // consequence under MSW where we use unsigned values sometimes and
353 // signed ones other times: the coordinates turn as big positive
354 // numbers and so the sash is drawn on the *right* side of the window
355 // instead of the left (or bottom instead of top). Correct this.
356 if ( (short)m_oldX
< 0 )
358 if ( (short)m_oldY
< 0 )
363 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
365 DrawSashTracker(m_oldX
, m_oldY
);
369 m_sashPosition
= new_sash_position
;
370 m_needUpdating
= TRUE
;
373 else if ( event
.LeftDClick() )
375 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
,
377 eventSplitter
.m_data
.pt
.x
= x
;
378 eventSplitter
.m_data
.pt
.y
= y
;
380 (void)GetEventHandler()->ProcessEvent(eventSplitter
);
384 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
386 // only process this message if we're not iconized - otherwise iconizing
387 // and restoring a window containing the splitter has a funny side effect
388 // of changing the splitter position!
389 wxWindow
*parent
= GetParent();
390 while ( parent
&& !parent
->IsTopLevel() )
392 parent
= parent
->GetParent();
397 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
400 iconized
= winTop
->IsIconized();
404 wxFAIL_MSG(wxT("should have a top level parent!"));
417 GetClientSize( &cw
, &ch
);
420 if ( m_splitMode
== wxSPLIT_VERTICAL
)
422 if ( m_sashPosition
>= (cw
- 5) )
423 m_sashPosition
= wxMax(10, cw
- 40);
425 else // m_splitMode == wxSPLIT_HORIZONTAL
427 if ( m_sashPosition
>= (ch
- 5) )
428 m_sashPosition
= wxMax(10, ch
- 40);
435 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
437 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
438 return FALSE
; // No sash
440 if ( m_splitMode
== wxSPLIT_VERTICAL
)
442 if ( (x
>= m_sashPosition
- tolerance
) && (x
<= m_sashPosition
+ m_sashSize
+ tolerance
) )
449 if ( (y
>= (m_sashPosition
- tolerance
)) && (y
<= (m_sashPosition
+ m_sashSize
+ tolerance
)) )
456 // Draw 3D effect borders
457 void wxSplitterWindow::DrawBorders(wxDC
& dc
)
460 GetClientSize(&w
, &h
);
462 if ( GetWindowStyleFlag() & wxSP_3DBORDER
)
465 dc
.SetPen(*m_facePen
);
466 dc
.SetBrush(*m_faceBrush
);
467 dc
.DrawRectangle(1, 1 , w
-1, m_borderSize
-2 ); //high
468 dc
.DrawRectangle(1, m_borderSize
-2 , m_borderSize
-2, h
-1 ); // left
469 dc
.DrawRectangle(w
-m_borderSize
+2, m_borderSize
-2 , w
-1, h
-1 ); // right
470 dc
.DrawRectangle(m_borderSize
-2, h
-m_borderSize
+2 , w
-m_borderSize
+2, h
-1 ); //bottom
472 dc
.SetPen(*m_mediumShadowPen
);
473 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, w
-m_borderSize
+1, m_borderSize
-2);
474 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, m_borderSize
-2, h
-m_borderSize
+1);
476 dc
.SetPen(*m_darkShadowPen
);
477 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, w
-m_borderSize
, m_borderSize
-1);
478 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, m_borderSize
-1, h
-m_borderSize
);
480 dc
.SetPen(*m_hilightPen
);
481 dc
.DrawLine(m_borderSize
- 2, h
-m_borderSize
+1, w
-m_borderSize
+1, h
-m_borderSize
+1);
482 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.
483 /// Anyway, h is required for MSW.
485 dc
.SetPen(*m_lightShadowPen
);
486 dc
.DrawLine(w
-m_borderSize
, m_borderSize
-1, w
-m_borderSize
, h
-m_borderSize
); // Right hand side
487 dc
.DrawLine(m_borderSize
-1, h
-m_borderSize
, w
-m_borderSize
+1, h
-m_borderSize
); // Bottom
489 else if ( GetWindowStyleFlag() & wxSP_BORDER
)
491 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
492 dc
.SetPen(*wxBLACK_PEN
);
493 dc
.DrawRectangle(0, 0, w
-1, h
-1);
496 dc
.SetPen(wxNullPen
);
497 dc
.SetBrush(wxNullBrush
);
501 void wxSplitterWindow::DrawSash(wxDC
& dc
)
503 if ( m_sashPosition
== 0 || !m_windowTwo
)
505 if (GetWindowStyle() & wxSP_NOSASH
)
509 GetClientSize(&w
, &h
);
511 if ( GetWindowStyleFlag() & wxSP_3DSASH
)
513 if ( m_splitMode
== wxSPLIT_VERTICAL
)
515 dc
.SetPen(*m_facePen
);
517 if (HasFlag( wxSP_SASH_AQUA
))
518 dc
.SetBrush(*wxWHITE_BRUSH
);
520 dc
.SetBrush(*m_faceBrush
);
521 dc
.DrawRectangle(m_sashPosition
+ 2, 0 , m_sashSize
- 4, h
);
523 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
525 dc
.SetPen(*m_lightShadowPen
);
526 int xShadow
= m_borderSize
? m_borderSize
- 1 : 0 ;
527 dc
.DrawLine(m_sashPosition
, xShadow
, m_sashPosition
, h
-m_borderSize
);
529 dc
.SetPen(*m_hilightPen
);
530 dc
.DrawLine(m_sashPosition
+1, m_borderSize
- 2, m_sashPosition
+1, h
- m_borderSize
+2);
532 if (!HasFlag( wxSP_SASH_AQUA
))
533 dc
.SetPen(*m_mediumShadowPen
);
535 int yMedium
= m_borderSize
? h
-m_borderSize
+1 : h
;
536 dc
.DrawLine(m_sashPosition
+m_sashSize
-2, xShadow
, m_sashPosition
+m_sashSize
-2, yMedium
);
538 if (HasFlag( wxSP_SASH_AQUA
))
539 dc
.SetPen(*m_lightShadowPen
);
541 dc
.SetPen(*m_darkShadowPen
);
542 dc
.DrawLine(m_sashPosition
+m_sashSize
-1, m_borderSize
, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
);
544 // Draw the top and bottom edges of the sash, if requested
545 if (GetWindowStyle() & wxSP_FULLSASH
)
548 dc
.SetPen(*m_hilightPen
);
549 dc
.DrawLine(m_sashPosition
+1, m_borderSize
, m_sashPosition
+m_sashSize
-1, m_borderSize
);
552 dc
.SetPen(*m_darkShadowPen
);
553 dc
.DrawLine(m_sashPosition
+1, h
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
-1);
558 dc
.SetPen(*m_facePen
);
559 if (HasFlag( wxSP_SASH_AQUA
))
560 dc
.SetBrush(*wxWHITE_BRUSH
);
562 dc
.SetBrush(*m_faceBrush
);
563 dc
.DrawRectangle( m_borderSize
-2, m_sashPosition
+ 2, w
-m_borderSize
+2, m_sashSize
- 4);
565 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
567 dc
.SetPen(*m_lightShadowPen
);
568 dc
.DrawLine(m_borderSize
-1, m_sashPosition
, w
-m_borderSize
, m_sashPosition
);
570 dc
.SetPen(*m_hilightPen
);
571 dc
.DrawLine(m_borderSize
-2, m_sashPosition
+1, w
-m_borderSize
+1, m_sashPosition
+1);
573 if (!HasFlag( wxSP_SASH_AQUA
))
574 dc
.SetPen(*m_mediumShadowPen
);
575 dc
.DrawLine(m_borderSize
-1, m_sashPosition
+m_sashSize
-2, w
-m_borderSize
+1, m_sashPosition
+m_sashSize
-2);
577 if (HasFlag( wxSP_SASH_AQUA
))
578 dc
.SetPen(*m_lightShadowPen
);
580 dc
.SetPen(*m_darkShadowPen
);
581 dc
.DrawLine(m_borderSize
, m_sashPosition
+m_sashSize
-1, w
-m_borderSize
, m_sashPosition
+m_sashSize
-1);
583 // Draw the left and right edges of the sash, if requested
584 if (GetWindowStyle() & wxSP_FULLSASH
)
587 dc
.SetPen(*m_hilightPen
);
588 dc
.DrawLine(m_borderSize
, m_sashPosition
, m_borderSize
, m_sashPosition
+m_sashSize
);
591 dc
.SetPen(*m_darkShadowPen
);
592 dc
.DrawLine(w
-m_borderSize
-1, m_sashPosition
+1, w
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1);
598 if ( m_splitMode
== wxSPLIT_VERTICAL
)
600 dc
.SetPen(*wxBLACK_PEN
);
601 dc
.SetBrush(*wxBLACK_BRUSH
);
604 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
605 h1
+= 1; // Not sure why this is necessary...
606 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
610 dc
.DrawRectangle(m_sashPosition
, y1
, m_sashSize
, h1
);
614 dc
.SetPen(*wxBLACK_PEN
);
615 dc
.SetBrush(*wxBLACK_BRUSH
);
618 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
620 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
624 dc
.DrawRectangle(x1
, m_sashPosition
, w1
, m_sashSize
);
629 dc
.SetPen(wxNullPen
);
630 dc
.SetBrush(wxNullBrush
);
633 // Draw the sash tracker (for whilst moving the sash)
634 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
637 GetClientSize(&w
, &h
);
643 if ( m_splitMode
== wxSPLIT_VERTICAL
)
674 ClientToScreen(&x1
, &y1
);
675 ClientToScreen(&x2
, &y2
);
677 screenDC
.SetLogicalFunction(wxINVERT
);
678 screenDC
.SetPen(*m_sashTrackerPen
);
679 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
681 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
683 screenDC
.SetLogicalFunction(wxCOPY
);
685 screenDC
.SetPen(wxNullPen
);
686 screenDC
.SetBrush(wxNullBrush
);
689 int wxSplitterWindow::GetWindowSize() const
691 wxSize size
= GetClientSize();
693 return m_splitMode
== wxSPLIT_VERTICAL
? size
.x
: size
.y
;
696 int wxSplitterWindow::AdjustSashPosition(int sashPos
) const
698 int window_size
= GetWindowSize();
702 // don't do anything before the window has a valid size, otherwise we
703 // put the sash to 0 at the very beginning and it doesn't move from
713 // the window shouldn't be smaller than its own minimal size nor
714 // smaller than the minimual pane size specified for this splitter
715 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
716 : win
->GetMinHeight();
718 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
719 minSize
= m_minimumPaneSize
;
721 minSize
+= GetBorderSize();
723 if ( sashPos
< minSize
)
730 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
731 : win
->GetMinHeight();
733 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
734 minSize
= m_minimumPaneSize
;
736 int maxSize
= window_size
- minSize
- GetBorderSize();
737 if ( sashPos
> maxSize
)
744 // Position and size subwindows.
745 // Note that the border size applies to each subwindow, not
746 // including the edges next to the sash.
747 void wxSplitterWindow::SizeWindows()
750 GetClientSize(&w
, &h
);
752 if ( GetWindow1() && !GetWindow2() )
754 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(), w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
757 else if ( GetWindow1() && GetWindow2() )
759 if (GetSplitMode() == wxSPLIT_VERTICAL
)
761 int x1
= GetBorderSize();
762 int y1
= GetBorderSize();
763 int w1
= GetSashPosition() - GetBorderSize();
764 int h1
= h
- 2*GetBorderSize();
766 int x2
= GetSashPosition() + GetSashSize();
767 int y2
= GetBorderSize();
768 int w2
= w
- 2*GetBorderSize() - GetSashSize() - w1
;
769 int h2
= h
- 2*GetBorderSize();
771 GetWindow1()->SetSize(x1
, y1
, w1
, h1
);
772 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
776 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
777 w
- 2*GetBorderSize(), GetSashPosition() - GetBorderSize());
778 GetWindow2()->SetSize(GetBorderSize(), GetSashPosition() + GetSashSize(),
779 w
- 2*GetBorderSize(), h
- 2*GetBorderSize() - GetSashSize() - (GetSashPosition() - GetBorderSize()));
783 if ( GetBorderSize() > 0 )
787 SetNeedUpdating(FALSE
);
790 // Set pane for unsplit window
791 void wxSplitterWindow::Initialize(wxWindow
*window
)
793 m_windowOne
= window
;
794 m_windowTwo
= (wxWindow
*) NULL
;
798 // Associates the given window with window 2, drawing the appropriate sash
799 // and changing the split mode.
800 // Does nothing and returns FALSE if the window is already split.
801 bool wxSplitterWindow::DoSplit(wxSplitMode mode
,
802 wxWindow
*window1
, wxWindow
*window2
,
808 int window_size
= GetWindowSize();
811 m_windowOne
= window1
;
812 m_windowTwo
= window2
;
814 if ( sashPosition
> 0 )
816 m_sashPosition
= sashPosition
;
818 else if ( sashPosition
< 0 )
820 // It's negative so adding is subtracting
821 m_sashPosition
= window_size
+ sashPosition
;
826 m_sashPosition
= window_size
/2;
829 // don't do it initially, i.e. when creating the window because it doesn't
830 // have a proper size yet and AdjustSashPosition() would happily set the
831 // sash position to 0!
832 if ( window_size
> 0 )
834 m_sashPosition
= AdjustSashPosition(m_sashPosition
);
842 // Remove the specified (or second) window from the view
843 // Doesn't actually delete the window.
844 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
849 wxWindow
*win
= NULL
;
850 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
853 m_windowTwo
= (wxWindow
*) NULL
;
855 else if ( toRemove
== m_windowOne
)
858 m_windowOne
= m_windowTwo
;
859 m_windowTwo
= (wxWindow
*) NULL
;
863 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
868 SendUnsplitEvent(win
);
875 // Replace a window with another one
876 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
878 wxCHECK_MSG( winOld
, FALSE
, wxT("use one of Split() functions instead") );
879 wxCHECK_MSG( winNew
, FALSE
, wxT("use Unsplit() functions instead") );
881 if ( winOld
== m_windowTwo
)
883 m_windowTwo
= winNew
;
885 else if ( winOld
== m_windowOne
)
887 m_windowOne
= winNew
;
891 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
901 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
903 m_sashPosition
= AdjustSashPosition(position
);
911 // Initialize colours
912 void wxSplitterWindow::InitColours()
914 wxDELETE( m_facePen
);
915 wxDELETE( m_faceBrush
);
916 wxDELETE( m_mediumShadowPen
);
917 wxDELETE( m_darkShadowPen
);
918 wxDELETE( m_lightShadowPen
);
919 wxDELETE( m_hilightPen
);
923 wxColour
faceColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
924 m_facePen
= new wxPen(faceColour
, 1, wxSOLID
);
925 m_faceBrush
= new wxBrush(faceColour
, wxSOLID
);
927 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
928 m_mediumShadowPen
= new wxPen(mediumShadowColour
, 1, wxSOLID
);
930 wxColour
darkShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
));
931 m_darkShadowPen
= new wxPen(darkShadowColour
, 1, wxSOLID
);
933 wxColour
lightShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
));
934 m_lightShadowPen
= new wxPen(lightShadowColour
, 1, wxSOLID
);
936 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
937 m_hilightPen
= new wxPen(hilightColour
, 1, wxSOLID
);
939 m_facePen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
940 m_faceBrush
= new wxBrush("LIGHT GREY", wxSOLID
);
941 m_mediumShadowPen
= new wxPen("GREY", 1, wxSOLID
);
942 m_darkShadowPen
= new wxPen("BLACK", 1, wxSOLID
);
943 m_lightShadowPen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
944 m_hilightPen
= new wxPen("WHITE", 1, wxSOLID
);
948 void wxSplitterWindow::SendUnsplitEvent(wxWindow
*winRemoved
)
950 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
951 event
.m_data
.win
= winRemoved
;
953 (void)GetEventHandler()->ProcessEvent(event
);
956 // ---------------------------------------------------------------------------
957 // splitter event handlers
958 // ---------------------------------------------------------------------------
960 void wxSplitterWindow::OnSashPosChanged(wxSplitterEvent
& event
)
962 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
963 const int UNSPLIT_THRESHOLD
= 4;
965 int newSashPosition
= event
.GetSashPosition();
967 // Obtain relevant window dimension for bottom / right threshold check
968 int window_size
= GetWindowSize();
970 bool unsplit_scenario
= FALSE
;
971 if ( m_permitUnsplitAlways
972 || m_minimumPaneSize
== 0 )
974 // Do edge detection if unsplit premitted
975 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
977 // threshold top / left check
979 unsplit_scenario
= TRUE
;
981 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
983 // threshold bottom/right check
984 newSashPosition
= window_size
;
985 unsplit_scenario
= TRUE
;
989 if ( !unsplit_scenario
)
991 // If resultant pane would be too small, enlarge it
992 newSashPosition
= AdjustSashPosition(newSashPosition
);
995 // If the result is out of bounds it means minimum size is too big,
996 // so split window in half as best compromise.
997 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
998 newSashPosition
= window_size
/ 2;
1000 // for compatibility, call the virtual function
1001 if ( !OnSashPositionChange(newSashPosition
) )
1003 newSashPosition
= -1;
1006 event
.SetSashPosition(newSashPosition
);
1009 // Called when the sash is double-clicked. The default behaviour is to remove
1010 // the sash if the minimum pane size is zero.
1011 void wxSplitterWindow::OnDoubleClick(wxSplitterEvent
& event
)
1013 // for compatibility, call the virtual function
1014 OnDoubleClickSash(event
.GetX(), event
.GetY());
1016 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
1022 void wxSplitterWindow::OnUnsplitEvent(wxSplitterEvent
& event
)
1024 wxWindow
*win
= event
.GetWindowBeingRemoved();
1026 // do it before calling OnUnsplit() which may delete the window
1029 // for compatibility, call the virtual function
1033 #if defined(__WXMSW__)
1034 #define WXUNUSED_UNLESS_MSW(identifier) identifier
1036 #define WXUNUSED_UNLESS_MSW(identifier) WXUNUSED(identifier)
1039 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& WXUNUSED_UNLESS_MSW(event
))
1041 // this is currently called (and needed) under MSW only...
1044 // if we don't do it, the resizing cursor might be set for child window:
1045 // and like this we explicitly say that our cursor should not be used for
1046 // children windows which overlap us
1048 if ( SashHitTest(event
.GetX(), event
.GetY()) )
1050 // default processing is ok
1053 //else: do nothing, in particular, don't call Skip()