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();
395 bool iconized
= FALSE
;
397 // wxMotif doesn't yet have a wxTopLevelWindow implementation
399 wxFrame
*winTop
= wxDynamicCast(parent
, wxFrame
);
401 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
405 iconized
= winTop
->IsIconized();
410 wxFAIL_MSG(wxT("should have a top level parent!"));
424 GetClientSize( &cw
, &ch
);
427 if ( m_splitMode
== wxSPLIT_VERTICAL
)
429 if ( m_sashPosition
>= (cw
- 5) )
430 m_sashPosition
= wxMax(10, cw
- 40);
432 else // m_splitMode == wxSPLIT_HORIZONTAL
434 if ( m_sashPosition
>= (ch
- 5) )
435 m_sashPosition
= wxMax(10, ch
- 40);
442 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
444 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
445 return FALSE
; // No sash
447 if ( m_splitMode
== wxSPLIT_VERTICAL
)
449 if ( (x
>= m_sashPosition
- tolerance
) && (x
<= m_sashPosition
+ m_sashSize
+ tolerance
) )
456 if ( (y
>= (m_sashPosition
- tolerance
)) && (y
<= (m_sashPosition
+ m_sashSize
+ tolerance
)) )
463 // Draw 3D effect borders
464 void wxSplitterWindow::DrawBorders(wxDC
& dc
)
467 GetClientSize(&w
, &h
);
469 if ( GetWindowStyleFlag() & wxSP_3DBORDER
)
472 dc
.SetPen(*m_facePen
);
473 dc
.SetBrush(*m_faceBrush
);
474 dc
.DrawRectangle(1, 1 , w
-1, m_borderSize
-2 ); //high
475 dc
.DrawRectangle(1, m_borderSize
-2 , m_borderSize
-2, h
-1 ); // left
476 dc
.DrawRectangle(w
-m_borderSize
+2, m_borderSize
-2 , w
-1, h
-1 ); // right
477 dc
.DrawRectangle(m_borderSize
-2, h
-m_borderSize
+2 , w
-m_borderSize
+2, h
-1 ); //bottom
479 dc
.SetPen(*m_mediumShadowPen
);
480 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, w
-m_borderSize
+1, m_borderSize
-2);
481 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, m_borderSize
-2, h
-m_borderSize
+1);
483 dc
.SetPen(*m_darkShadowPen
);
484 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, w
-m_borderSize
, m_borderSize
-1);
485 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, m_borderSize
-1, h
-m_borderSize
);
487 dc
.SetPen(*m_hilightPen
);
488 dc
.DrawLine(m_borderSize
- 2, h
-m_borderSize
+1, w
-m_borderSize
+1, h
-m_borderSize
+1);
489 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.
490 /// Anyway, h is required for MSW.
492 dc
.SetPen(*m_lightShadowPen
);
493 dc
.DrawLine(w
-m_borderSize
, m_borderSize
-1, w
-m_borderSize
, h
-m_borderSize
); // Right hand side
494 dc
.DrawLine(m_borderSize
-1, h
-m_borderSize
, w
-m_borderSize
+1, h
-m_borderSize
); // Bottom
496 else if ( GetWindowStyleFlag() & wxSP_BORDER
)
498 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
499 dc
.SetPen(*wxBLACK_PEN
);
500 dc
.DrawRectangle(0, 0, w
-1, h
-1);
503 dc
.SetPen(wxNullPen
);
504 dc
.SetBrush(wxNullBrush
);
508 void wxSplitterWindow::DrawSash(wxDC
& dc
)
510 if ( m_sashPosition
== 0 || !m_windowTwo
)
512 if (GetWindowStyle() & wxSP_NOSASH
)
516 GetClientSize(&w
, &h
);
518 if ( GetWindowStyleFlag() & wxSP_3DSASH
)
520 if ( m_splitMode
== wxSPLIT_VERTICAL
)
522 dc
.SetPen(*m_facePen
);
524 if (HasFlag( wxSP_SASH_AQUA
))
525 dc
.SetBrush(*wxWHITE_BRUSH
);
527 dc
.SetBrush(*m_faceBrush
);
528 dc
.DrawRectangle(m_sashPosition
+ 2, 0 , m_sashSize
- 4, h
);
530 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
532 dc
.SetPen(*m_lightShadowPen
);
533 int xShadow
= m_borderSize
? m_borderSize
- 1 : 0 ;
534 dc
.DrawLine(m_sashPosition
, xShadow
, m_sashPosition
, h
-m_borderSize
);
536 dc
.SetPen(*m_hilightPen
);
537 dc
.DrawLine(m_sashPosition
+1, m_borderSize
- 2, m_sashPosition
+1, h
- m_borderSize
+2);
539 if (!HasFlag( wxSP_SASH_AQUA
))
540 dc
.SetPen(*m_mediumShadowPen
);
542 int yMedium
= m_borderSize
? h
-m_borderSize
+1 : h
;
543 dc
.DrawLine(m_sashPosition
+m_sashSize
-2, xShadow
, m_sashPosition
+m_sashSize
-2, yMedium
);
545 if (HasFlag( wxSP_SASH_AQUA
))
546 dc
.SetPen(*m_lightShadowPen
);
548 dc
.SetPen(*m_darkShadowPen
);
549 dc
.DrawLine(m_sashPosition
+m_sashSize
-1, m_borderSize
, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
);
551 // Draw the top and bottom edges of the sash, if requested
552 if (GetWindowStyle() & wxSP_FULLSASH
)
555 dc
.SetPen(*m_hilightPen
);
556 dc
.DrawLine(m_sashPosition
+1, m_borderSize
, m_sashPosition
+m_sashSize
-1, m_borderSize
);
559 dc
.SetPen(*m_darkShadowPen
);
560 dc
.DrawLine(m_sashPosition
+1, h
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
-1);
565 dc
.SetPen(*m_facePen
);
566 if (HasFlag( wxSP_SASH_AQUA
))
567 dc
.SetBrush(*wxWHITE_BRUSH
);
569 dc
.SetBrush(*m_faceBrush
);
570 dc
.DrawRectangle( m_borderSize
-2, m_sashPosition
+ 2, w
-m_borderSize
+2, m_sashSize
- 4);
572 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
574 dc
.SetPen(*m_lightShadowPen
);
575 dc
.DrawLine(m_borderSize
-1, m_sashPosition
, w
-m_borderSize
, m_sashPosition
);
577 dc
.SetPen(*m_hilightPen
);
578 dc
.DrawLine(m_borderSize
-2, m_sashPosition
+1, w
-m_borderSize
+1, m_sashPosition
+1);
580 if (!HasFlag( wxSP_SASH_AQUA
))
581 dc
.SetPen(*m_mediumShadowPen
);
582 dc
.DrawLine(m_borderSize
-1, m_sashPosition
+m_sashSize
-2, w
-m_borderSize
+1, m_sashPosition
+m_sashSize
-2);
584 if (HasFlag( wxSP_SASH_AQUA
))
585 dc
.SetPen(*m_lightShadowPen
);
587 dc
.SetPen(*m_darkShadowPen
);
588 dc
.DrawLine(m_borderSize
, m_sashPosition
+m_sashSize
-1, w
-m_borderSize
, m_sashPosition
+m_sashSize
-1);
590 // Draw the left and right edges of the sash, if requested
591 if (GetWindowStyle() & wxSP_FULLSASH
)
594 dc
.SetPen(*m_hilightPen
);
595 dc
.DrawLine(m_borderSize
, m_sashPosition
, m_borderSize
, m_sashPosition
+m_sashSize
);
598 dc
.SetPen(*m_darkShadowPen
);
599 dc
.DrawLine(w
-m_borderSize
-1, m_sashPosition
+1, w
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1);
605 if ( m_splitMode
== wxSPLIT_VERTICAL
)
607 dc
.SetPen(*wxBLACK_PEN
);
608 dc
.SetBrush(*wxBLACK_BRUSH
);
611 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
612 h1
+= 1; // Not sure why this is necessary...
613 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
617 dc
.DrawRectangle(m_sashPosition
, y1
, m_sashSize
, h1
);
621 dc
.SetPen(*wxBLACK_PEN
);
622 dc
.SetBrush(*wxBLACK_BRUSH
);
625 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
627 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
631 dc
.DrawRectangle(x1
, m_sashPosition
, w1
, m_sashSize
);
636 dc
.SetPen(wxNullPen
);
637 dc
.SetBrush(wxNullBrush
);
640 // Draw the sash tracker (for whilst moving the sash)
641 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
644 GetClientSize(&w
, &h
);
650 if ( m_splitMode
== wxSPLIT_VERTICAL
)
681 ClientToScreen(&x1
, &y1
);
682 ClientToScreen(&x2
, &y2
);
684 screenDC
.SetLogicalFunction(wxINVERT
);
685 screenDC
.SetPen(*m_sashTrackerPen
);
686 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
688 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
690 screenDC
.SetLogicalFunction(wxCOPY
);
692 screenDC
.SetPen(wxNullPen
);
693 screenDC
.SetBrush(wxNullBrush
);
696 int wxSplitterWindow::GetWindowSize() const
698 wxSize size
= GetClientSize();
700 return m_splitMode
== wxSPLIT_VERTICAL
? size
.x
: size
.y
;
703 int wxSplitterWindow::AdjustSashPosition(int sashPos
) const
705 int window_size
= GetWindowSize();
707 // VZ: dirty fix, 20 is the initial window size under wxGTK, this is
708 // going to be replaced with the correct Vaclav's code soon (FIXME)
709 if ( window_size
<= 20 )
711 // don't do anything before the window has a valid size, otherwise we
712 // put the sash to 0 at the very beginning and it doesn't move from
722 // the window shouldn't be smaller than its own minimal size nor
723 // smaller than the minimual pane size specified for this splitter
724 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
725 : win
->GetMinHeight();
727 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
728 minSize
= m_minimumPaneSize
;
730 minSize
+= GetBorderSize();
732 if ( sashPos
< minSize
)
739 int minSize
= m_splitMode
== wxSPLIT_VERTICAL
? win
->GetMinWidth()
740 : win
->GetMinHeight();
742 if ( minSize
== -1 || m_minimumPaneSize
> minSize
)
743 minSize
= m_minimumPaneSize
;
745 int maxSize
= window_size
- minSize
- GetBorderSize();
746 if ( sashPos
> maxSize
)
753 // Position and size subwindows.
754 // Note that the border size applies to each subwindow, not
755 // including the edges next to the sash.
756 void wxSplitterWindow::SizeWindows()
759 GetClientSize(&w
, &h
);
761 if ( GetWindow1() && !GetWindow2() )
763 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(), w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
766 else if ( GetWindow1() && GetWindow2() )
768 if (GetSplitMode() == wxSPLIT_VERTICAL
)
770 int x1
= GetBorderSize();
771 int y1
= GetBorderSize();
772 int w1
= GetSashPosition() - GetBorderSize();
773 int h1
= h
- 2*GetBorderSize();
775 int x2
= GetSashPosition() + GetSashSize();
776 int y2
= GetBorderSize();
777 int w2
= w
- 2*GetBorderSize() - GetSashSize() - w1
;
778 int h2
= h
- 2*GetBorderSize();
780 GetWindow1()->SetSize(x1
, y1
, w1
, h1
);
781 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
785 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
786 w
- 2*GetBorderSize(), GetSashPosition() - GetBorderSize());
787 GetWindow2()->SetSize(GetBorderSize(), GetSashPosition() + GetSashSize(),
788 w
- 2*GetBorderSize(), h
- 2*GetBorderSize() - GetSashSize() - (GetSashPosition() - GetBorderSize()));
792 if ( GetBorderSize() > 0 )
796 SetNeedUpdating(FALSE
);
799 // Set pane for unsplit window
800 void wxSplitterWindow::Initialize(wxWindow
*window
)
802 m_windowOne
= window
;
803 m_windowTwo
= (wxWindow
*) NULL
;
807 // Associates the given window with window 2, drawing the appropriate sash
808 // and changing the split mode.
809 // Does nothing and returns FALSE if the window is already split.
810 bool wxSplitterWindow::DoSplit(wxSplitMode mode
,
811 wxWindow
*window1
, wxWindow
*window2
,
817 int window_size
= GetWindowSize();
820 m_windowOne
= window1
;
821 m_windowTwo
= window2
;
823 if ( sashPosition
> 0 )
825 m_sashPosition
= sashPosition
;
827 else if ( sashPosition
< 0 )
829 // It's negative so adding is subtracting
830 m_sashPosition
= window_size
+ sashPosition
;
835 m_sashPosition
= window_size
/2;
838 // don't do it initially, i.e. when creating the window because it doesn't
839 // have a proper size yet and AdjustSashPosition() would happily set the
840 // sash position to 0!
841 if ( window_size
> 0 )
843 m_sashPosition
= AdjustSashPosition(m_sashPosition
);
851 // Remove the specified (or second) window from the view
852 // Doesn't actually delete the window.
853 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
858 wxWindow
*win
= NULL
;
859 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
862 m_windowTwo
= (wxWindow
*) NULL
;
864 else if ( toRemove
== m_windowOne
)
867 m_windowOne
= m_windowTwo
;
868 m_windowTwo
= (wxWindow
*) NULL
;
872 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
877 SendUnsplitEvent(win
);
884 // Replace a window with another one
885 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
887 wxCHECK_MSG( winOld
, FALSE
, wxT("use one of Split() functions instead") );
888 wxCHECK_MSG( winNew
, FALSE
, wxT("use Unsplit() functions instead") );
890 if ( winOld
== m_windowTwo
)
892 m_windowTwo
= winNew
;
894 else if ( winOld
== m_windowOne
)
896 m_windowOne
= winNew
;
900 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
910 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
912 m_sashPosition
= AdjustSashPosition(position
);
920 // Initialize colours
921 void wxSplitterWindow::InitColours()
923 wxDELETE( m_facePen
);
924 wxDELETE( m_faceBrush
);
925 wxDELETE( m_mediumShadowPen
);
926 wxDELETE( m_darkShadowPen
);
927 wxDELETE( m_lightShadowPen
);
928 wxDELETE( m_hilightPen
);
932 wxColour
faceColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
933 m_facePen
= new wxPen(faceColour
, 1, wxSOLID
);
934 m_faceBrush
= new wxBrush(faceColour
, wxSOLID
);
936 wxColour
mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW
));
937 m_mediumShadowPen
= new wxPen(mediumShadowColour
, 1, wxSOLID
);
939 wxColour
darkShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW
));
940 m_darkShadowPen
= new wxPen(darkShadowColour
, 1, wxSOLID
);
942 wxColour
lightShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
));
943 m_lightShadowPen
= new wxPen(lightShadowColour
, 1, wxSOLID
);
945 wxColour
hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT
));
946 m_hilightPen
= new wxPen(hilightColour
, 1, wxSOLID
);
948 m_facePen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
949 m_faceBrush
= new wxBrush("LIGHT GREY", wxSOLID
);
950 m_mediumShadowPen
= new wxPen("GREY", 1, wxSOLID
);
951 m_darkShadowPen
= new wxPen("BLACK", 1, wxSOLID
);
952 m_lightShadowPen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
953 m_hilightPen
= new wxPen("WHITE", 1, wxSOLID
);
957 void wxSplitterWindow::SendUnsplitEvent(wxWindow
*winRemoved
)
959 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
960 event
.m_data
.win
= winRemoved
;
962 (void)GetEventHandler()->ProcessEvent(event
);
965 // ---------------------------------------------------------------------------
966 // splitter event handlers
967 // ---------------------------------------------------------------------------
969 void wxSplitterWindow::OnSashPosChanged(wxSplitterEvent
& event
)
971 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
972 const int UNSPLIT_THRESHOLD
= 4;
974 int newSashPosition
= event
.GetSashPosition();
976 // Obtain relevant window dimension for bottom / right threshold check
977 int window_size
= GetWindowSize();
979 bool unsplit_scenario
= FALSE
;
980 if ( m_permitUnsplitAlways
981 || m_minimumPaneSize
== 0 )
983 // Do edge detection if unsplit premitted
984 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
986 // threshold top / left check
988 unsplit_scenario
= TRUE
;
990 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
992 // threshold bottom/right check
993 newSashPosition
= window_size
;
994 unsplit_scenario
= TRUE
;
998 if ( !unsplit_scenario
)
1000 // If resultant pane would be too small, enlarge it
1001 newSashPosition
= AdjustSashPosition(newSashPosition
);
1004 // If the result is out of bounds it means minimum size is too big,
1005 // so split window in half as best compromise.
1006 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
1007 newSashPosition
= window_size
/ 2;
1009 // for compatibility, call the virtual function
1010 if ( !OnSashPositionChange(newSashPosition
) )
1012 newSashPosition
= -1;
1015 event
.SetSashPosition(newSashPosition
);
1018 // Called when the sash is double-clicked. The default behaviour is to remove
1019 // the sash if the minimum pane size is zero.
1020 void wxSplitterWindow::OnDoubleClick(wxSplitterEvent
& event
)
1022 // for compatibility, call the virtual function
1023 OnDoubleClickSash(event
.GetX(), event
.GetY());
1025 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
1031 void wxSplitterWindow::OnUnsplitEvent(wxSplitterEvent
& event
)
1033 wxWindow
*win
= event
.GetWindowBeingRemoved();
1035 // do it before calling OnUnsplit() which may delete the window
1038 // for compatibility, call the virtual function
1042 #if defined(__WXMSW__)
1043 #define WXUNUSED_UNLESS_MSW(identifier) identifier
1045 #define WXUNUSED_UNLESS_MSW(identifier) WXUNUSED(identifier)
1048 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& WXUNUSED_UNLESS_MSW(event
))
1050 // this is currently called (and needed) under MSW only...
1053 // if we don't do it, the resizing cursor might be set for child window:
1054 // and like this we explicitly say that our cursor should not be used for
1055 // children windows which overlap us
1057 if ( SashHitTest(event
.GetX(), event
.GetY()) )
1059 // default processing is ok
1062 //else: do nothing, in particular, don't call Skip()