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"
36 IMPLEMENT_DYNAMIC_CLASS(wxSplitterWindow
, wxWindow
)
37 IMPLEMENT_DYNAMIC_CLASS(wxSplitterEvent
, wxCommandEvent
)
39 BEGIN_EVENT_TABLE(wxSplitterWindow
, wxWindow
)
40 EVT_PAINT(wxSplitterWindow::OnPaint
)
41 EVT_SIZE(wxSplitterWindow::OnSize
)
42 EVT_IDLE(wxSplitterWindow::OnIdle
)
43 EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent
)
45 EVT_SPLITTER_SASH_POS_CHANGED(-1, wxSplitterWindow::OnSashPosChanged
)
46 // NB: we borrow OnSashPosChanged for purposes of
47 // EVT_SPLITTER_SASH_POS_CHANGING since default implementation is identical
48 EVT_SPLITTER_SASH_POS_CHANGING(-1, wxSplitterWindow::OnSashPosChanged
)
49 EVT_SPLITTER_DCLICK(-1, wxSplitterWindow::OnDoubleClick
)
50 EVT_SPLITTER_UNSPLIT(-1, wxSplitterWindow::OnUnsplitEvent
)
53 wxSplitterWindow::wxSplitterWindow()
55 m_splitMode
= wxSPLIT_VERTICAL
;
56 m_permitUnsplitAlways
= FALSE
;
57 m_windowOne
= (wxWindow
*) NULL
;
58 m_windowTwo
= (wxWindow
*) NULL
;
59 m_dragMode
= wxSPLIT_DRAG_NONE
;
67 m_sashCursorWE
= (wxCursor
*) NULL
;
68 m_sashCursorNS
= (wxCursor
*) NULL
;
69 m_sashTrackerPen
= (wxPen
*) NULL
;
70 m_lightShadowPen
= (wxPen
*) NULL
;
71 m_mediumShadowPen
= (wxPen
*) NULL
;
72 m_darkShadowPen
= (wxPen
*) NULL
;
73 m_faceBrush
= (wxBrush
*) NULL
;
74 m_facePen
= (wxPen
*) NULL
;
75 m_hilightPen
= (wxPen
*) NULL
;
76 m_minimumPaneSize
= 0;
77 m_needUpdating
= FALSE
;
80 wxSplitterWindow::wxSplitterWindow(wxWindow
*parent
, wxWindowID id
,
85 : wxWindow(parent
, id
, pos
, size
, style
, name
)
87 m_splitMode
= wxSPLIT_VERTICAL
;
88 m_permitUnsplitAlways
= (style
& wxSP_PERMIT_UNSPLIT
) != 0;
89 m_windowOne
= (wxWindow
*) NULL
;
90 m_windowTwo
= (wxWindow
*) NULL
;
91 m_dragMode
= wxSPLIT_DRAG_NONE
;
99 m_minimumPaneSize
= 0;
100 m_sashCursorWE
= new wxCursor(wxCURSOR_SIZEWE
);
101 m_sashCursorNS
= new wxCursor(wxCURSOR_SIZENS
);
102 m_sashTrackerPen
= new wxPen(*wxBLACK
, 2, wxSOLID
);
103 m_lightShadowPen
= (wxPen
*) NULL
;
104 m_mediumShadowPen
= (wxPen
*) NULL
;
105 m_darkShadowPen
= (wxPen
*) NULL
;
106 m_faceBrush
= (wxBrush
*) NULL
;
107 m_facePen
= (wxPen
*) NULL
;
108 m_hilightPen
= (wxPen
*) NULL
;
110 if ( style
& wxSP_3D
)
115 else if ( style
& wxSP_BORDER
)
126 // Eventually, we'll respond to colour change messages
129 // For debugging purposes, to see the background.
130 // SetBackground(wxBLUE_BRUSH);
132 m_needUpdating
= FALSE
;
135 wxSplitterWindow::~wxSplitterWindow()
137 delete m_sashCursorWE
;
138 delete m_sashCursorNS
;
139 delete m_sashTrackerPen
;
140 delete m_lightShadowPen
;
141 delete m_darkShadowPen
;
142 delete m_mediumShadowPen
;
148 void wxSplitterWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
152 if ( m_borderSize
> 0 )
157 void wxSplitterWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
))
163 void wxSplitterWindow::OnMouseEvent(wxMouseEvent
& event
)
165 wxCoord x
= event
.GetX(),
170 SetCursor(* wxSTANDARD_CURSOR
);
173 SetCursor(wxCursor());
177 if (event
.LeftDown())
179 if ( SashHitTest(x
, y
) )
183 m_dragMode
= wxSPLIT_DRAG_DRAGGING
;
185 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
187 DrawSashTracker(x
, y
);
195 else if (event
.LeftUp() && m_dragMode
== wxSPLIT_DRAG_DRAGGING
)
197 // We can stop dragging now and see what we've got.
198 m_dragMode
= wxSPLIT_DRAG_NONE
;
202 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
204 DrawSashTracker(m_oldX
, m_oldY
);
207 // Obtain window size. We are only interested in the dimension the sash
210 GetClientSize(&w
, &h
);
211 int window_size
= (m_splitMode
== wxSPLIT_VERTICAL
? w
: h
);
212 int new_sash_position
=
213 (int) ( m_splitMode
== wxSPLIT_VERTICAL
? x
: y
);
215 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
,
217 eventSplitter
.m_data
.pos
= new_sash_position
;
218 if ( GetEventHandler()->ProcessEvent(eventSplitter
) )
220 new_sash_position
= eventSplitter
.GetSashPosition();
221 if ( new_sash_position
== -1 )
223 // change not allowed
228 if ( m_permitUnsplitAlways
229 || m_minimumPaneSize
== 0 )
231 // Deal with possible unsplit scenarios
232 if ( new_sash_position
== 0 )
234 // We remove the first window from the view
235 wxWindow
*removedWindow
= m_windowOne
;
236 m_windowOne
= m_windowTwo
;
237 m_windowTwo
= (wxWindow
*) NULL
;
238 SendUnsplitEvent(removedWindow
);
241 else if ( new_sash_position
== window_size
)
243 // We remove the second window from the view
244 wxWindow
*removedWindow
= m_windowTwo
;
245 m_windowTwo
= (wxWindow
*) NULL
;
246 SendUnsplitEvent(removedWindow
);
251 m_sashPosition
= new_sash_position
;
256 m_sashPosition
= new_sash_position
;
260 } // left up && dragging
261 else if (event
.Moving() && !event
.Dragging())
263 // Just change the cursor if required
264 if ( SashHitTest(x
, y
) )
266 if ( m_splitMode
== wxSPLIT_VERTICAL
)
268 SetCursor(*m_sashCursorWE
);
272 SetCursor(*m_sashCursorNS
);
278 // where else do we unset the cursor?
279 SetCursor(* wxSTANDARD_CURSOR
);
283 else if (event
.Dragging() && (m_dragMode
== wxSPLIT_DRAG_DRAGGING
))
285 // Obtain window size. We are only interested in the dimension the sash
287 int new_sash_position
=
288 (int) ( m_splitMode
== wxSPLIT_VERTICAL
? x
: y
);
290 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
,
292 eventSplitter
.m_data
.pos
= new_sash_position
;
293 if ( GetEventHandler()->ProcessEvent(eventSplitter
) )
295 new_sash_position
= eventSplitter
.GetSashPosition();
296 if ( new_sash_position
== -1 )
298 // change not allowed
304 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
306 DrawSashTracker(m_oldX
, m_oldY
);
309 if (m_splitMode
== wxSPLIT_VERTICAL
)
310 x
= new_sash_position
;
312 y
= new_sash_position
;
314 if (new_sash_position
!= -1)
316 // Only modify if permitted
322 // As we captured the mouse, we may get the mouse events from outside
323 // our window - for example, negative values in x, y. This has a weird
324 // consequence under MSW where we use unsigned values sometimes and
325 // signed ones other times: the coordinates turn as big positive
326 // numbers and so the sash is drawn on the *right* side of the window
327 // instead of the left (or bottom instead of top). Correct this.
328 if ( (short)m_oldX
< 0 )
330 if ( (short)m_oldY
< 0 )
335 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE
) == 0)
337 DrawSashTracker(m_oldX
, m_oldY
);
341 m_sashPosition
= new_sash_position
;
342 m_needUpdating
= TRUE
;
345 else if ( event
.LeftDClick() )
347 wxSplitterEvent
eventSplitter(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
,
349 eventSplitter
.m_data
.pt
.x
= x
;
350 eventSplitter
.m_data
.pt
.y
= y
;
352 (void)GetEventHandler()->ProcessEvent(eventSplitter
);
356 void wxSplitterWindow::OnSize(wxSizeEvent
& event
)
358 // only process this message if we're not iconized - otherwise iconizing
359 // and restoring a window containing the splitter has a funny side effect
360 // of changing the splitter position!
361 wxWindow
*parent
= GetParent();
362 while ( parent
&& !parent
->IsTopLevel() )
364 parent
= parent
->GetParent();
367 bool iconized
= FALSE
;
368 wxFrame
*frame
= wxDynamicCast(parent
, wxFrame
);
370 iconized
= frame
->IsIconized();
373 wxDialog
*dialog
= wxDynamicCast(parent
, wxDialog
);
375 iconized
= dialog
->IsIconized();
377 wxFAIL_MSG(wxT("should have a top level frame or dialog parent!"));
387 GetClientSize( &cw
, &ch
);
390 if ( m_splitMode
== wxSPLIT_VERTICAL
)
392 if ( m_sashPosition
>= (cw
- 5) )
393 m_sashPosition
= wxMax(10, cw
- 40);
395 if ( m_splitMode
== wxSPLIT_HORIZONTAL
)
397 if ( m_sashPosition
>= (ch
- 5) )
398 m_sashPosition
= wxMax(10, ch
- 40);
406 bool wxSplitterWindow::SashHitTest(int x
, int y
, int tolerance
)
408 if ( m_windowTwo
== NULL
|| m_sashPosition
== 0)
409 return FALSE
; // No sash
411 if ( m_splitMode
== wxSPLIT_VERTICAL
)
413 if ( (x
>= m_sashPosition
- tolerance
) && (x
<= m_sashPosition
+ m_sashSize
+ tolerance
) )
420 if ( (y
>= (m_sashPosition
- tolerance
)) && (y
<= (m_sashPosition
+ m_sashSize
+ tolerance
)) )
427 // Draw 3D effect borders
428 void wxSplitterWindow::DrawBorders(wxDC
& dc
)
431 GetClientSize(&w
, &h
);
433 if ( GetWindowStyleFlag() & wxSP_3D
)
436 dc
.SetPen(*m_facePen
);
437 dc
.SetBrush(*m_faceBrush
);
438 dc
.DrawRectangle(1, 1 , w
-1, m_borderSize
-2 ); //high
439 dc
.DrawRectangle(1, m_borderSize
-2 , m_borderSize
-2, h
-1 ); // left
440 dc
.DrawRectangle(w
-m_borderSize
+2, m_borderSize
-2 , w
-1, h
-1 ); // right
441 dc
.DrawRectangle(m_borderSize
-2, h
-m_borderSize
+2 , w
-m_borderSize
+2, h
-1 ); //bottom
443 dc
.SetPen(*m_mediumShadowPen
);
444 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, w
-m_borderSize
+1, m_borderSize
-2);
445 dc
.DrawLine(m_borderSize
-2, m_borderSize
-2, m_borderSize
-2, h
-m_borderSize
+1);
447 dc
.SetPen(*m_darkShadowPen
);
448 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, w
-m_borderSize
, m_borderSize
-1);
449 dc
.DrawLine(m_borderSize
-1, m_borderSize
-1, m_borderSize
-1, h
-m_borderSize
);
451 dc
.SetPen(*m_hilightPen
);
452 dc
.DrawLine(m_borderSize
- 2, h
-m_borderSize
+1, w
-m_borderSize
+1, h
-m_borderSize
+1);
453 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.
454 /// Anyway, h is required for MSW.
456 dc
.SetPen(*m_lightShadowPen
);
457 dc
.DrawLine(w
-m_borderSize
, m_borderSize
-1, w
-m_borderSize
, h
-m_borderSize
); // Right hand side
458 dc
.DrawLine(m_borderSize
-1, h
-m_borderSize
, w
-m_borderSize
+1, h
-m_borderSize
); // Bottom
460 else if ( GetWindowStyleFlag() & wxSP_BORDER
)
462 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
463 dc
.SetPen(*wxBLACK_PEN
);
464 dc
.DrawRectangle(0, 0, w
-1, h
-1);
467 dc
.SetPen(wxNullPen
);
468 dc
.SetBrush(wxNullBrush
);
472 void wxSplitterWindow::DrawSash(wxDC
& dc
)
474 if ( m_sashPosition
== 0 || !m_windowTwo
)
478 GetClientSize(&w
, &h
);
480 if ( GetWindowStyleFlag() & wxSP_3D
)
482 if ( m_splitMode
== wxSPLIT_VERTICAL
)
484 dc
.SetPen(*m_facePen
);
485 dc
.SetBrush(*m_faceBrush
);
486 dc
.DrawRectangle(m_sashPosition
+ 2, 0 , m_sashSize
- 4, h
);
488 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
490 dc
.SetPen(*m_lightShadowPen
);
491 int xShadow
= m_borderSize
? m_borderSize
- 1 : 0 ;
492 dc
.DrawLine(m_sashPosition
, xShadow
, m_sashPosition
, h
-m_borderSize
);
494 dc
.SetPen(*m_hilightPen
);
495 dc
.DrawLine(m_sashPosition
+1, m_borderSize
- 2, m_sashPosition
+1, h
- m_borderSize
+2);
497 dc
.SetPen(*m_mediumShadowPen
);
498 int yMedium
= m_borderSize
? h
-m_borderSize
+1 : h
;
499 dc
.DrawLine(m_sashPosition
+m_sashSize
-2, xShadow
, m_sashPosition
+m_sashSize
-2, yMedium
);
501 dc
.SetPen(*m_darkShadowPen
);
502 dc
.DrawLine(m_sashPosition
+m_sashSize
-1, m_borderSize
, m_sashPosition
+m_sashSize
-1, h
-m_borderSize
);
506 dc
.SetPen(*m_facePen
);
507 dc
.SetBrush(*m_faceBrush
);
508 dc
.DrawRectangle( m_borderSize
-2, m_sashPosition
+ 2, w
-m_borderSize
+2, m_sashSize
- 4);
510 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
512 dc
.SetPen(*m_lightShadowPen
);
513 dc
.DrawLine(m_borderSize
-1, m_sashPosition
, w
-m_borderSize
, m_sashPosition
);
515 dc
.SetPen(*m_hilightPen
);
516 dc
.DrawLine(m_borderSize
-2, m_sashPosition
+1, w
-m_borderSize
+1, m_sashPosition
+1);
518 dc
.SetPen(*m_mediumShadowPen
);
519 dc
.DrawLine(m_borderSize
-1, m_sashPosition
+m_sashSize
-2, w
-m_borderSize
+1, m_sashPosition
+m_sashSize
-2);
521 dc
.SetPen(*m_darkShadowPen
);
522 dc
.DrawLine(m_borderSize
, m_sashPosition
+m_sashSize
-1, w
-m_borderSize
, m_sashPosition
+m_sashSize
-1);
527 if ( m_splitMode
== wxSPLIT_VERTICAL
)
529 dc
.SetPen(*wxBLACK_PEN
);
530 dc
.SetBrush(*wxBLACK_BRUSH
);
532 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
)
533 h1
+= 1; // Not sure why this is necessary...
534 dc
.DrawRectangle(m_sashPosition
, 0, m_sashSize
, h1
);
538 dc
.SetPen(*wxBLACK_PEN
);
539 dc
.SetBrush(*wxBLACK_BRUSH
);
541 if ( (GetWindowStyleFlag() & wxSP_BORDER
) != wxSP_BORDER
)
544 dc
.DrawRectangle(0, m_sashPosition
, w1
, m_sashSize
);
549 dc
.SetPen(wxNullPen
);
550 dc
.SetBrush(wxNullBrush
);
553 // Draw the sash tracker (for whilst moving the sash)
554 void wxSplitterWindow::DrawSashTracker(int x
, int y
)
557 GetClientSize(&w
, &h
);
563 if ( m_splitMode
== wxSPLIT_VERTICAL
)
594 ClientToScreen(&x1
, &y1
);
595 ClientToScreen(&x2
, &y2
);
597 screenDC
.SetLogicalFunction(wxINVERT
);
598 screenDC
.SetPen(*m_sashTrackerPen
);
599 screenDC
.SetBrush(*wxTRANSPARENT_BRUSH
);
601 screenDC
.DrawLine(x1
, y1
, x2
, y2
);
603 screenDC
.SetLogicalFunction(wxCOPY
);
605 screenDC
.SetPen(wxNullPen
);
606 screenDC
.SetBrush(wxNullBrush
);
609 // Position and size subwindows.
610 // Note that the border size applies to each subwindow, not
611 // including the edges next to the sash.
612 void wxSplitterWindow::SizeWindows()
615 GetClientSize(&w
, &h
);
617 if ( m_windowOne
&& !m_windowTwo
)
619 m_windowOne
->SetSize(m_borderSize
, m_borderSize
, w
- 2*m_borderSize
, h
- 2*m_borderSize
);
622 else if ( m_windowOne
&& m_windowTwo
)
624 if (m_splitMode
== wxSPLIT_VERTICAL
)
626 int x1
= m_borderSize
;
627 int y1
= m_borderSize
;
628 int w1
= m_sashPosition
- m_borderSize
;
629 int h1
= h
- 2*m_borderSize
;
631 int x2
= m_sashPosition
+ m_sashSize
;
632 int y2
= m_borderSize
;
633 int w2
= w
- 2*m_borderSize
- m_sashSize
- w1
;
634 int h2
= h
- 2*m_borderSize
;
636 m_windowOne
->SetSize(x1
, y1
, w1
, h1
);
637 m_windowTwo
->SetSize(x2
, y2
, w2
, h2
);
642 m_windowOne
->SetSize(m_borderSize
, m_borderSize
,
643 w
- 2*m_borderSize
, m_sashPosition
- m_borderSize
);
644 m_windowTwo
->SetSize(m_borderSize
, m_sashPosition
+ m_sashSize
,
645 w
- 2*m_borderSize
, h
- 2*m_borderSize
- m_sashSize
- (m_sashPosition
- m_borderSize
));
650 if ( m_borderSize
> 0 )
655 // Set pane for unsplit window
656 void wxSplitterWindow::Initialize(wxWindow
*window
)
658 m_windowOne
= window
;
659 m_windowTwo
= (wxWindow
*) NULL
;
663 // Associates the given window with window 2, drawing the appropriate sash
664 // and changing the split mode.
665 // Does nothing and returns FALSE if the window is already split.
666 bool wxSplitterWindow::SplitVertically(wxWindow
*window1
, wxWindow
*window2
, int sashPosition
)
672 GetClientSize(&w
, &h
);
674 m_splitMode
= wxSPLIT_VERTICAL
;
675 m_windowOne
= window1
;
676 m_windowTwo
= window2
;
677 if ( sashPosition
> 0 )
678 m_sashPosition
= sashPosition
;
679 else if ( sashPosition
< 0 )
680 m_sashPosition
= w
- sashPosition
;
682 m_sashPosition
= w
/2;
689 bool wxSplitterWindow::SplitHorizontally(wxWindow
*window1
, wxWindow
*window2
, int sashPosition
)
695 GetClientSize(&w
, &h
);
697 m_splitMode
= wxSPLIT_HORIZONTAL
;
698 m_windowOne
= window1
;
699 m_windowTwo
= window2
;
700 if ( sashPosition
> 0 )
701 m_sashPosition
= sashPosition
;
702 else if ( sashPosition
< 0 )
703 m_sashPosition
= h
- sashPosition
;
705 m_sashPosition
= h
/2;
713 // Remove the specified (or second) window from the view
714 // Doesn't actually delete the window.
715 bool wxSplitterWindow::Unsplit(wxWindow
*toRemove
)
720 wxWindow
*win
= NULL
;
721 if ( toRemove
== NULL
|| toRemove
== m_windowTwo
)
724 m_windowTwo
= (wxWindow
*) NULL
;
726 else if ( toRemove
== m_windowOne
)
729 m_windowOne
= m_windowTwo
;
730 m_windowTwo
= (wxWindow
*) NULL
;
734 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
739 SendUnsplitEvent(win
);
746 // Replace a window with another one
747 bool wxSplitterWindow::ReplaceWindow(wxWindow
*winOld
, wxWindow
*winNew
)
749 wxCHECK_MSG( winOld
, FALSE
, wxT("use one of Split() functions instead") );
750 wxCHECK_MSG( winNew
, FALSE
, wxT("use Unsplit() functions instead") );
752 if ( winOld
== m_windowTwo
)
754 m_windowTwo
= winNew
;
756 else if ( winOld
== m_windowOne
)
758 m_windowOne
= winNew
;
762 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
772 void wxSplitterWindow::SetSashPosition(int position
, bool redraw
)
774 m_sashPosition
= position
;
782 // Initialize colours
783 void wxSplitterWindow::InitColours()
785 wxDELETE( m_facePen
);
786 wxDELETE( m_faceBrush
);
787 wxDELETE( m_mediumShadowPen
);
788 wxDELETE( m_darkShadowPen
);
789 wxDELETE( m_lightShadowPen
);
790 wxDELETE( m_hilightPen
);
793 #if defined(__WIN95__)
794 wxColour
faceColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
795 m_facePen
= new wxPen(faceColour
, 1, wxSOLID
);
796 m_faceBrush
= new wxBrush(faceColour
, wxSOLID
);
798 wxColour
mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW
));
799 m_mediumShadowPen
= new wxPen(mediumShadowColour
, 1, wxSOLID
);
801 wxColour
darkShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DDKSHADOW
));
802 m_darkShadowPen
= new wxPen(darkShadowColour
, 1, wxSOLID
);
804 wxColour
lightShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
));
805 m_lightShadowPen
= new wxPen(lightShadowColour
, 1, wxSOLID
);
807 wxColour
hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT
));
808 m_hilightPen
= new wxPen(hilightColour
, 1, wxSOLID
);
810 m_facePen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
811 m_faceBrush
= new wxBrush("LIGHT GREY", wxSOLID
);
812 m_mediumShadowPen
= new wxPen("GREY", 1, wxSOLID
);
813 m_darkShadowPen
= new wxPen("BLACK", 1, wxSOLID
);
814 m_lightShadowPen
= new wxPen("LIGHT GREY", 1, wxSOLID
);
815 m_hilightPen
= new wxPen("WHITE", 1, wxSOLID
);
816 #endif // Win32/!Win32
819 void wxSplitterWindow::SendUnsplitEvent(wxWindow
*winRemoved
)
821 wxSplitterEvent
event(wxEVT_COMMAND_SPLITTER_UNSPLIT
, this);
822 event
.m_data
.win
= winRemoved
;
824 (void)GetEventHandler()->ProcessEvent(event
);
827 // ---------------------------------------------------------------------------
828 // splitter event handlers
829 // ---------------------------------------------------------------------------
831 void wxSplitterWindow::OnSashPosChanged(wxSplitterEvent
& event
)
833 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
834 const int UNSPLIT_THRESHOLD
= 4;
836 int newSashPosition
= event
.GetSashPosition();
838 // Obtain relevant window dimension for bottom / right threshold check
840 GetClientSize(&w
, &h
);
841 int window_size
= (m_splitMode
== wxSPLIT_VERTICAL
) ? w
: h
;
843 bool unsplit_scenario
= FALSE
;
844 if ( m_permitUnsplitAlways
845 || m_minimumPaneSize
== 0 )
847 // Do edge detection if unsplit premitted
848 if ( newSashPosition
<= UNSPLIT_THRESHOLD
)
850 // threshold top / left check
852 unsplit_scenario
= TRUE
;
854 if ( newSashPosition
>= window_size
- UNSPLIT_THRESHOLD
)
856 // threshold bottom/right check
857 newSashPosition
= window_size
;
858 unsplit_scenario
= TRUE
;
862 if ( !unsplit_scenario
)
864 // If resultant pane would be too small, enlarge it
865 if ( newSashPosition
< m_minimumPaneSize
)
866 newSashPosition
= m_minimumPaneSize
;
867 if ( newSashPosition
> window_size
- m_minimumPaneSize
)
868 newSashPosition
= window_size
- m_minimumPaneSize
;
871 // If the result is out of bounds it means minimum size is too big,
872 // so split window in half as best compromise.
873 if ( newSashPosition
< 0 || newSashPosition
> window_size
)
874 newSashPosition
= window_size
/ 2;
876 // for compatibility, call the virtual function
877 if ( !OnSashPositionChange(newSashPosition
) )
879 newSashPosition
= -1;
882 event
.SetSashPosition(newSashPosition
);
885 // Called when the sash is double-clicked. The default behaviour is to remove
886 // the sash if the minimum pane size is zero.
887 void wxSplitterWindow::OnDoubleClick(wxSplitterEvent
& event
)
889 // for compatibility, call the virtual function
890 OnDoubleClickSash(event
.GetX(), event
.GetY());
892 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways
)
898 void wxSplitterWindow::OnUnsplitEvent(wxSplitterEvent
& event
)
900 wxWindow
*win
= event
.GetWindowBeingRemoved();
902 // do it before calling OnUnsplit() which may delete the window
905 // for compatibility, call the virtual function