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
)
61 bool wxSplitterWindow::Create(wxWindow
*parent
, wxWindowID id
,
67 if (!wxWindow::Create(parent
, id
, pos
, size
, style
, name
))
70 m_permitUnsplitAlways
= (style
& wxSP_PERMIT_UNSPLIT
) != 0;
72 if ( style
& wxSP_3DSASH
)
77 if ( style
& wxSP_3DBORDER
)
79 else if ( style
& wxSP_BORDER
)
87 void wxSplitterWindow::Init()
89 m_splitMode
= wxSPLIT_VERTICAL
;
90 m_permitUnsplitAlways
= TRUE
;
91 m_windowOne
= (wxWindow
*) NULL
;
92 m_windowTwo
= (wxWindow
*) NULL
;
93 m_dragMode
= wxSPLIT_DRAG_NONE
;
101 m_minimumPaneSize
= 0;
102 m_sashCursorWE
= new wxCursor(wxCURSOR_SIZEWE
);
103 m_sashCursorNS
= new wxCursor(wxCURSOR_SIZENS
);
104 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxSOLID
);
105 m_lightShadowPen
= (wxPen
*) NULL
;
106 m_mediumShadowPen
= (wxPen
*) NULL
;
107 m_darkShadowPen
= (wxPen
*) NULL
;
108 m_faceBrush
= (wxBrush
*) NULL
;
109 m_facePen
= (wxPen
*) NULL
;
110 m_hilightPen
= (wxPen
*) NULL
;
117 m_needUpdating
= FALSE
;
120 wxSplitterWindow::~wxSplitterWindow()
122 delete m_sashCursorWE
;
123 delete m_sashCursorNS
;
124 delete m_sashTrackerPen
;
125 delete m_lightShadowPen
;
126 delete m_darkShadowPen
;
127 delete m_mediumShadowPen
;
133 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
137 if ( m_borderSize
> 0 )
142 void wxSplitterWindow::OnIdle(wxIdleEvent
& event
)
150 void wxSplitterWindow::OnMouseEvent(wxMouseEvent
& event
)
152 wxCoord x
= (wxCoord
)event
.GetX(),
153 y
= (wxCoord
)event
.GetY();
157 SetCursor(* wxSTANDARD_CURSOR
);
160 SetCursor(wxCursor());
163 if (GetWindowStyle() & wxSP_NOSASH
)
166 if (event
.LeftDown())
168 if ( SashHitTest(x
, y
) )
172 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
174 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
176 DrawSashTracker(x
, y
);
182 if ( m_splitMode
== wxSPLIT_VERTICAL
)
184 SetCursor(*m_sashCursorWE
);
188 SetCursor(*m_sashCursorNS
);
193 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
195 // We can stop dragging now and see what we've got.
196 m_dragMode
= wxSPLIT_DRAG_NONE
;
200 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
202 DrawSashTracker(m_oldX
, m_oldY
);
205 // Obtain window size. We are only interested in the dimension the sash
208 GetClientSize(&w
, &h
);
209 int window_size
= (m_splitMode
== wxSPLIT_VERTICAL
? w
: h
);
210 int new_sash_position
=
211 (int) ( m_splitMode
== wxSPLIT_VERTICAL
? x
: y
);
213 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
,
215 eventSplitter
.m_data
.pos
= new_sash_position
;
216 if ( GetEventHandler()->ProcessEvent(eventSplitter
) )
218 new_sash_position
= eventSplitter
.GetSashPosition();
219 if ( new_sash_position
== -1 )
221 // change not allowed
226 if ( m_permitUnsplitAlways
|| m_minimumPaneSize
== 0 )
228 // Deal with possible unsplit scenarios
229 if ( new_sash_position
== 0 )
231 // We remove the first window from the view
232 wxWindow
*removedWindow
= m_windowOne
;
233 m_windowOne
= m_windowTwo
;
234 m_windowTwo
= (wxWindow
*) NULL
;
235 SendUnsplitEvent(removedWindow
);
238 else if ( new_sash_position
== window_size
)
240 // We remove the second window from the view
241 wxWindow
*removedWindow
= m_windowTwo
;
242 m_windowTwo
= (wxWindow
*) NULL
;
243 SendUnsplitEvent(removedWindow
);
248 m_sashPosition
= new_sash_position
;
253 m_sashPosition
= new_sash_position
;
257 } // left up && dragging
258 else if (event
.Moving() && !event
.Dragging())
260 // Just change the cursor if required
261 if ( SashHitTest(x
, y
) )
263 if ( m_splitMode
== wxSPLIT_VERTICAL
)
265 SetCursor(*m_sashCursorWE
);
269 SetCursor(*m_sashCursorNS
);
272 #if defined(__WXGTK__) || defined(__WXMSW__)
275 // We must set the normal cursor in MSW, because
276 // if the child window doesn't have a cursor, the
277 // parent's (splitter window) will be used, and this
278 // must be the standard cursor.
280 // where else do we unset the cursor?
281 SetCursor(* wxSTANDARD_CURSOR
);
285 else if (event
.Dragging() && (m_dragMode
== wxSPLIT_DRAG_DRAGGING
))
288 // Otherwise, the cursor sometimes reverts to the normal cursor
290 if ( m_splitMode
== wxSPLIT_VERTICAL
)
292 SetCursor(*m_sashCursorWE
);
296 SetCursor(*m_sashCursorNS
);
300 // Obtain window size. We are only interested in the dimension the sash
302 int new_sash_position
=
303 (int) ( m_splitMode
== wxSPLIT_VERTICAL
? x
: y
);
305 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
,
307 eventSplitter
.m_data
.pos
= new_sash_position
;
308 if ( GetEventHandler()->ProcessEvent(eventSplitter
) )
310 new_sash_position
= eventSplitter
.GetSashPosition();
311 if ( new_sash_position
== -1 )
313 // change not allowed
318 if (new_sash_position
== m_sashPosition
)
322 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
324 DrawSashTracker(m_oldX
, m_oldY
);
327 if (m_splitMode
== wxSPLIT_VERTICAL
)
328 x
= new_sash_position
;
330 y
= new_sash_position
;
332 // Remember old positions
337 // As we captured the mouse, we may get the mouse events from outside
338 // our window - for example, negative values in x, y. This has a weird
339 // consequence under MSW where we use unsigned values sometimes and
340 // signed ones other times: the coordinates turn as big positive
341 // numbers and so the sash is drawn on the *right* side of the window
342 // instead of the left (or bottom instead of top). Correct this.
343 if ( (short)m_oldX
< 0 )
345 if ( (short)m_oldY
< 0 )
350 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
352 DrawSashTracker(m_oldX
, m_oldY
);
356 m_sashPosition
= new_sash_position
;
357 m_needUpdating
= TRUE
;
360 else if ( event
.LeftDClick() )
362 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
,
364 eventSplitter
.m_data
.pt
.x
= x
;
365 eventSplitter
.m_data
.pt
.y
= y
;
367 (void)GetEventHandler()->ProcessEvent(eventSplitter
);
371 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
373 // only process this message if we're not iconized - otherwise iconizing
374 // and restoring a window containing the splitter has a funny side effect
375 // of changing the splitter position!
376 wxWindow
*parent
= GetParent();
377 while ( parent
&& !parent
->IsTopLevel() )
379 parent
= parent
->GetParent();
382 bool iconized
= FALSE
;
383 wxFrame
*frame
= wxDynamicCast(parent
, wxFrame
);
385 iconized
= frame
->IsIconized();
388 wxDialog
*dialog
= wxDynamicCast(parent
, wxDialog
);
390 iconized
= dialog
->IsIconized();
392 wxFAIL_MSG(wxT("should have a top level frame or dialog parent!"));
402 GetClientSize( &cw
, &ch
);
405 if ( m_splitMode
== wxSPLIT_VERTICAL
)
407 if ( m_sashPosition
>= (cw
- 5) )
408 m_sashPosition
= wxMax(10, cw
- 40);
410 if ( m_splitMode
== wxSPLIT_HORIZONTAL
)
412 if ( m_sashPosition
>= (ch
- 5) )
413 m_sashPosition
= wxMax(10, ch
- 40);
421 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
423 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
424 return FALSE
; // No sash
426 if ( m_splitMode
== wxSPLIT_VERTICAL
)
428 if ( (x
>= m_sashPosition
- tolerance
) && (x
<= m_sashPosition
+ m_sashSize
+ tolerance
) )
435 if ( (y
>= (m_sashPosition
- tolerance
)) && (y
<= (m_sashPosition
+ m_sashSize
+ tolerance
)) )
442 // Draw 3D effect borders
443 void wxSplitterWindow::DrawBorders(wxDC
& dc
)
446 GetClientSize(&w
, &h
);
448 if ( GetWindowStyleFlag() & wxSP_3DBORDER
)
451 dc
.SetPen(*m_facePen
);
452 dc
.SetBrush(*m_faceBrush
);
453 dc
.DrawRectangle(1, 1 , w
-1, m_borderSize
-2 ); //high
454 dc
.DrawRectangle(1, m_borderSize
-2 , m_borderSize
-2, h
-1 ); // left
455 dc
.DrawRectangle(w
-m_borderSize
+2, m_borderSize
-2 , w
-1, h
-1 ); // right
456 dc
.DrawRectangle(m_borderSize
-2, h
-m_borderSize
+2 , w
-m_borderSize
+2, h
-1 ); //bottom
458 dc
.SetPen(*m_mediumShadowPen
);
459 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, w
-m_borderSize
+1, m_borderSize
-2);
460 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, m_borderSize
-2, h
-m_borderSize
+1);
462 dc
.SetPen(*m_darkShadowPen
);
463 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, w
-m_borderSize
, m_borderSize
-1);
464 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, m_borderSize
-1, h
-m_borderSize
);
466 dc
.SetPen(*m_hilightPen
);
467 dc
.DrawLine(m_borderSize
- 2, h
-m_borderSize
+1, w
-m_borderSize
+1, h
-m_borderSize
+1);
468 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.
469 /// Anyway, h is required for MSW.
471 dc
.SetPen(*m_lightShadowPen
);
472 dc
.DrawLine(w
-m_borderSize
, m_borderSize
-1, w
-m_borderSize
, h
-m_borderSize
); // Right hand side
473 dc
.DrawLine(m_borderSize
-1, h
-m_borderSize
, w
-m_borderSize
+1, h
-m_borderSize
); // Bottom
475 else if ( GetWindowStyleFlag() & wxSP_BORDER
)
477 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
478 dc
.SetPen(*wxBLACK_PEN
);
479 dc
.DrawRectangle(0, 0, w
-1, h
-1);
482 dc
.SetPen(wxNullPen
);
483 dc
.SetBrush(wxNullBrush
);
487 void wxSplitterWindow::DrawSash(wxDC
& dc
)
489 if ( m_sashPosition
== 0 || !m_windowTwo
)
491 if (GetWindowStyle() & wxSP_NOSASH
)
495 GetClientSize(&w
, &h
);
497 if ( GetWindowStyleFlag() & wxSP_3DSASH
)
499 if ( m_splitMode
== wxSPLIT_VERTICAL
)
501 dc
.SetPen(*m_facePen
);
502 dc
.SetBrush(*m_faceBrush
);
503 dc
.DrawRectangle(m_sashPosition
+ 2, 0 , m_sashSize
- 4, h
);
505 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
507 dc
.SetPen(*m_lightShadowPen
);
508 int xShadow
= m_borderSize
? m_borderSize
- 1 : 0 ;
509 dc
.DrawLine(m_sashPosition
, xShadow
, m_sashPosition
, h
-m_borderSize
);
511 dc
.SetPen(*m_hilightPen
);
512 dc
.DrawLine(m_sashPosition
+1, m_borderSize
- 2, m_sashPosition
+1, h
- m_borderSize
+2);
514 dc
.SetPen(*m_mediumShadowPen
);
515 int yMedium
= m_borderSize
? h
-m_borderSize
+1 : h
;
516 dc
.DrawLine(m_sashPosition
+m_sashSize
-2, xShadow
, m_sashPosition
+m_sashSize
-2, yMedium
);
518 dc
.SetPen(*m_darkShadowPen
);
519 dc
.DrawLine(m_sashPosition
+m_sashSize
-1, m_borderSize
, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
);
521 // Draw the top and bottom edges of the sash, if requested
522 if (GetWindowStyle() & wxSP_FULLSASH
)
525 dc
.SetPen(*m_hilightPen
);
526 dc
.DrawLine(m_sashPosition
+1, m_borderSize
, m_sashPosition
+m_sashSize
-1, m_borderSize
);
529 dc
.SetPen(*m_darkShadowPen
);
530 dc
.DrawLine(m_sashPosition
+1, h
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
-1);
535 dc
.SetPen(*m_facePen
);
536 dc
.SetBrush(*m_faceBrush
);
537 dc
.DrawRectangle( m_borderSize
-2, m_sashPosition
+ 2, w
-m_borderSize
+2, m_sashSize
- 4);
539 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
541 dc
.SetPen(*m_lightShadowPen
);
542 dc
.DrawLine(m_borderSize
-1, m_sashPosition
, w
-m_borderSize
, m_sashPosition
);
544 dc
.SetPen(*m_hilightPen
);
545 dc
.DrawLine(m_borderSize
-2, m_sashPosition
+1, w
-m_borderSize
+1, m_sashPosition
+1);
547 dc
.SetPen(*m_mediumShadowPen
);
548 dc
.DrawLine(m_borderSize
-1, m_sashPosition
+m_sashSize
-2, w
-m_borderSize
+1, m_sashPosition
+m_sashSize
-2);
550 dc
.SetPen(*m_darkShadowPen
);
551 dc
.DrawLine(m_borderSize
, m_sashPosition
+m_sashSize
-1, w
-m_borderSize
, m_sashPosition
+m_sashSize
-1);
553 // Draw the left and right edges of the sash, if requested
554 if (GetWindowStyle() & wxSP_FULLSASH
)
557 dc
.SetPen(*m_hilightPen
);
558 dc
.DrawLine(m_borderSize
, m_sashPosition
, m_borderSize
, m_sashPosition
+m_sashSize
);
561 dc
.SetPen(*m_darkShadowPen
);
562 dc
.DrawLine(w
-m_borderSize
-1, m_sashPosition
+1, w
-m_borderSize
-1, m_sashPosition
+m_sashSize
-1);
568 if ( m_splitMode
== wxSPLIT_VERTICAL
)
570 dc
.SetPen(*wxBLACK_PEN
);
571 dc
.SetBrush(*wxBLACK_BRUSH
);
574 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
575 h1
+= 1; // Not sure why this is necessary...
576 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
580 dc
.DrawRectangle(m_sashPosition
, y1
, m_sashSize
, h1
);
584 dc
.SetPen(*wxBLACK_PEN
);
585 dc
.SetBrush(*wxBLACK_BRUSH
);
588 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
&& (GetWindowStyleFlag() & wxSP_3DBORDER
) != wxSP_3DBORDER
)
590 if ( (GetWindowStyleFlag() & wxSP_3DBORDER
) == wxSP_3DBORDER
)
594 dc
.DrawRectangle(x1
, m_sashPosition
, w1
, m_sashSize
);
599 dc
.SetPen(wxNullPen
);
600 dc
.SetBrush(wxNullBrush
);
603 // Draw the sash tracker (for whilst moving the sash)
604 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
607 GetClientSize(&w
, &h
);
613 if ( m_splitMode
== wxSPLIT_VERTICAL
)
644 ClientToScreen(&x1
, &y1
);
645 ClientToScreen(&x2
, &y2
);
647 screenDC
.SetLogicalFunction(wxINVERT
);
648 screenDC
.SetPen(*m_sashTrackerPen
);
649 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
651 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
653 screenDC
.SetLogicalFunction(wxCOPY
);
655 screenDC
.SetPen(wxNullPen
);
656 screenDC
.SetBrush(wxNullBrush
);
659 // Position and size subwindows.
660 // Note that the border size applies to each subwindow, not
661 // including the edges next to the sash.
662 void wxSplitterWindow::SizeWindows()
665 GetClientSize(&w
, &h
);
667 if ( GetWindow1() && !GetWindow2() )
669 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(), w
- 2*GetBorderSize(), h
- 2*GetBorderSize());
672 else if ( GetWindow1() && GetWindow2() )
674 if (GetSplitMode() == wxSPLIT_VERTICAL
)
676 int x1
= GetBorderSize();
677 int y1
= GetBorderSize();
678 int w1
= GetSashPosition() - GetBorderSize();
679 int h1
= h
- 2*GetBorderSize();
681 int x2
= GetSashPosition() + GetSashSize();
682 int y2
= GetBorderSize();
683 int w2
= w
- 2*GetBorderSize() - GetSashSize() - w1
;
684 int h2
= h
- 2*GetBorderSize();
686 GetWindow1()->SetSize(x1
, y1
, w1
, h1
);
687 GetWindow2()->SetSize(x2
, y2
, w2
, h2
);
691 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
692 w
- 2*GetBorderSize(), GetSashPosition() - GetBorderSize());
693 GetWindow2()->SetSize(GetBorderSize(), GetSashPosition() + GetSashSize(),
694 w
- 2*GetBorderSize(), h
- 2*GetBorderSize() - GetSashSize() - (GetSashPosition() - GetBorderSize()));
698 if ( GetBorderSize() > 0 )
702 SetNeedUpdating(FALSE
);
705 // Set pane for unsplit window
706 void wxSplitterWindow::Initialize(wxWindow
*window
)
708 m_windowOne
= window
;
709 m_windowTwo
= (wxWindow
*) NULL
;
713 // Associates the given window with window 2, drawing the appropriate sash
714 // and changing the split mode.
715 // Does nothing and returns FALSE if the window is already split.
716 bool wxSplitterWindow::SplitVertically(wxWindow
*window1
, wxWindow
*window2
, int sashPosition
)
722 GetClientSize(&w
, &h
);
724 m_splitMode
= wxSPLIT_VERTICAL
;
725 m_windowOne
= window1
;
726 m_windowTwo
= window2
;
727 if ( sashPosition
> 0 )
728 m_sashPosition
= sashPosition
;
729 else if ( sashPosition
< 0 )
730 m_sashPosition
= w
- sashPosition
;
732 m_sashPosition
= w
/2;
739 bool wxSplitterWindow::SplitHorizontally(wxWindow
*window1
, wxWindow
*window2
, int sashPosition
)
745 GetClientSize(&w
, &h
);
747 m_splitMode
= wxSPLIT_HORIZONTAL
;
748 m_windowOne
= window1
;
749 m_windowTwo
= window2
;
750 if ( sashPosition
> 0 )
751 m_sashPosition
= sashPosition
;
752 else if ( sashPosition
< 0 )
753 m_sashPosition
= h
- sashPosition
;
755 m_sashPosition
= h
/2;
763 // Remove the specified (or second) window from the view
764 // Doesn't actually delete the window.
765 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
770 wxWindow
*win
= NULL
;
771 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
774 m_windowTwo
= (wxWindow
*) NULL
;
776 else if ( toRemove
== m_windowOne
)
779 m_windowOne
= m_windowTwo
;
780 m_windowTwo
= (wxWindow
*) NULL
;
784 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
789 SendUnsplitEvent(win
);
796 // Replace a window with another one
797 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
799 wxCHECK_MSG( winOld
, FALSE
, wxT("use one of Split() functions instead") );
800 wxCHECK_MSG( winNew
, FALSE
, wxT("use Unsplit() functions instead") );
802 if ( winOld
== m_windowTwo
)
804 m_windowTwo
= winNew
;
806 else if ( winOld
== m_windowOne
)
808 m_windowOne
= winNew
;
812 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
822 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
824 m_sashPosition
= position
;
832 // Initialize colours
833 void wxSplitterWindow::InitColours()
835 wxDELETE( m_facePen
);
836 wxDELETE( m_faceBrush
);
837 wxDELETE( m_mediumShadowPen
);
838 wxDELETE( m_darkShadowPen
);
839 wxDELETE( m_lightShadowPen
);
840 wxDELETE( m_hilightPen
);
844 wxColour
faceColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
845 m_facePen
= new wxPen(faceColour
, 1, wxSOLID
);
846 m_faceBrush
= new wxBrush(faceColour
, wxSOLID
);
848 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
849 m_mediumShadowPen
= new wxPen(mediumShadowColour
, 1, wxSOLID
);
851 wxColour
darkShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DDKSHADOW
));
852 m_darkShadowPen
= new wxPen(darkShadowColour
, 1, wxSOLID
);
854 wxColour
lightShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
));
855 m_lightShadowPen
= new wxPen(lightShadowColour
, 1, wxSOLID
);
857 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
858 m_hilightPen
= new wxPen(hilightColour
, 1, wxSOLID
);
860 m_facePen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
861 m_faceBrush
= new wxBrush("LIGHT GREY", wxSOLID
);
862 m_mediumShadowPen
= new wxPen("GREY", 1, wxSOLID
);
863 m_darkShadowPen
= new wxPen("BLACK", 1, wxSOLID
);
864 m_lightShadowPen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
865 m_hilightPen
= new wxPen("WHITE", 1, wxSOLID
);
869 void wxSplitterWindow::SendUnsplitEvent(wxWindow
*winRemoved
)
871 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
872 event
.m_data
.win
= winRemoved
;
874 (void)GetEventHandler()->ProcessEvent(event
);
877 // ---------------------------------------------------------------------------
878 // splitter event handlers
879 // ---------------------------------------------------------------------------
881 void wxSplitterWindow::OnSashPosChanged(wxSplitterEvent
& event
)
883 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
884 const int UNSPLIT_THRESHOLD
= 4;
886 int newSashPosition
= event
.GetSashPosition();
888 // Obtain relevant window dimension for bottom / right threshold check
890 GetClientSize(&w
, &h
);
891 int window_size
= (m_splitMode
== wxSPLIT_VERTICAL
) ? w
: h
;
893 bool unsplit_scenario
= FALSE
;
894 if ( m_permitUnsplitAlways
895 || m_minimumPaneSize
== 0 )
897 // Do edge detection if unsplit premitted
898 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
900 // threshold top / left check
902 unsplit_scenario
= TRUE
;
904 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
906 // threshold bottom/right check
907 newSashPosition
= window_size
;
908 unsplit_scenario
= TRUE
;
912 if ( !unsplit_scenario
)
914 // If resultant pane would be too small, enlarge it
915 if ( newSashPosition
< m_minimumPaneSize
)
916 newSashPosition
= m_minimumPaneSize
;
917 if ( newSashPosition
> window_size
- m_minimumPaneSize
)
918 newSashPosition
= window_size
- m_minimumPaneSize
;
921 // If the result is out of bounds it means minimum size is too big,
922 // so split window in half as best compromise.
923 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
924 newSashPosition
= window_size
/ 2;
926 // for compatibility, call the virtual function
927 if ( !OnSashPositionChange(newSashPosition
) )
929 newSashPosition
= -1;
932 event
.SetSashPosition(newSashPosition
);
935 // Called when the sash is double-clicked. The default behaviour is to remove
936 // the sash if the minimum pane size is zero.
937 void wxSplitterWindow::OnDoubleClick(wxSplitterEvent
& event
)
939 // for compatibility, call the virtual function
940 OnDoubleClickSash(event
.GetX(), event
.GetY());
942 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
948 void wxSplitterWindow::OnUnsplitEvent(wxSplitterEvent
& event
)
950 wxWindow
*win
= event
.GetWindowBeingRemoved();
952 // do it before calling OnUnsplit() which may delete the window
955 // for compatibility, call the virtual function
959 #if defined(__WXMSW__)
960 #define WXUNUSED_UNLESS_MSW(identifier) identifier
962 #define WXUNUSED_UNLESS_MSW(identifier) WXUNUSED(identifier)
965 void wxSplitterWindow::OnSetCursor(wxSetCursorEvent
& WXUNUSED_UNLESS_MSW(event
))
967 // this is currently called (and needed) under MSW only...
970 // if we don't do it, the resizing cursor might be set for child window:
971 // and like this we explicitly say that our cursor should not be used for
972 // children windows which overlap us
974 if ( SashHitTest(event
.GetX(), event
.GetY()) )
976 // default processing is ok
979 //else: do nothing, in particular, don't call Skip()