]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/generic/splitter.cpp
Improve default size for wxGauge and wxChoice.
[wxWidgets.git] / src / generic / splitter.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/generic/splitter.cpp
3// Purpose: wxSplitterWindow implementation
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "splitter.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#if wxUSE_SPLITTER
20
21#ifdef __BORLANDC__
22 #pragma hdrstop
23#endif
24
25#ifndef WX_PRECOMP
26 #include "wx/string.h"
27 #include "wx/utils.h"
28 #include "wx/log.h"
29
30 #include "wx/dcscreen.h"
31
32 #include "wx/window.h"
33 #include "wx/dialog.h"
34 #include "wx/frame.h"
35
36 #include "wx/settings.h"
37#endif
38
39#include "wx/renderer.h"
40
41#include "wx/splitter.h"
42
43#include <stdlib.h>
44
45DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED)
46DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING)
47DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED)
48DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_UNSPLIT)
49
50IMPLEMENT_DYNAMIC_CLASS(wxSplitterWindow, wxWindow)
51
52/*
53 TODO PROPERTIES
54 style wxSP_3D
55 sashpos (long , 0 )
56 minsize (long -1 )
57 object, object_ref
58 orientation
59*/
60
61IMPLEMENT_DYNAMIC_CLASS(wxSplitterEvent, wxNotifyEvent)
62
63BEGIN_EVENT_TABLE(wxSplitterWindow, wxWindow)
64 EVT_PAINT(wxSplitterWindow::OnPaint)
65 EVT_SIZE(wxSplitterWindow::OnSize)
66 EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent)
67
68#if defined( __WXMSW__ ) || defined( __WXMAC__)
69 EVT_SET_CURSOR(wxSplitterWindow::OnSetCursor)
70#endif // wxMSW
71
72 WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow)
73END_EVENT_TABLE()
74
75WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow);
76
77bool wxSplitterWindow::Create(wxWindow *parent, wxWindowID id,
78 const wxPoint& pos,
79 const wxSize& size,
80 long style,
81 const wxString& name)
82{
83 // allow TABbing from one window to the other
84 style |= wxTAB_TRAVERSAL;
85
86 // we draw our border ourselves to blend the sash with it
87 style &= ~wxBORDER_MASK;
88 style |= wxBORDER_NONE;
89
90 if ( !wxWindow::Create(parent, id, pos, size, style, name) )
91 return false;
92
93 m_permitUnsplitAlways = (style & wxSP_PERMIT_UNSPLIT) != 0;
94
95 return true;
96}
97
98void wxSplitterWindow::Init()
99{
100 m_container.SetContainerWindow(this);
101
102 m_splitMode = wxSPLIT_VERTICAL;
103 m_permitUnsplitAlways = true;
104 m_windowOne = (wxWindow *) NULL;
105 m_windowTwo = (wxWindow *) NULL;
106 m_dragMode = wxSPLIT_DRAG_NONE;
107 m_oldX = 0;
108 m_oldY = 0;
109 m_firstX = 0;
110 m_firstY = 0;
111 m_sashPosition = m_requestedSashPosition = 0;
112 m_checkRequestedSashPosition = false;
113 m_minimumPaneSize = 0;
114 m_sashCursorWE = wxCursor(wxCURSOR_SIZEWE);
115 m_sashCursorNS = wxCursor(wxCURSOR_SIZENS);
116 m_sashTrackerPen = new wxPen(*wxBLACK, 2, wxSOLID);
117
118 m_needUpdating = false;
119 m_isHot = false;
120}
121
122wxSplitterWindow::~wxSplitterWindow()
123{
124 delete m_sashTrackerPen;
125}
126
127// ----------------------------------------------------------------------------
128// entering/leaving sash
129// ----------------------------------------------------------------------------
130
131void wxSplitterWindow::RedrawIfHotSensitive(bool isHot)
132{
133 if ( wxRendererNative::Get().GetSplitterParams(this).isHotSensitive )
134 {
135 m_isHot = isHot;
136
137 wxClientDC dc(this);
138 DrawSash(dc);
139 }
140 //else: we don't change our appearance, don't redraw to avoid flicker
141}
142
143void wxSplitterWindow::OnEnterSash()
144{
145 SetResizeCursor();
146
147 RedrawIfHotSensitive(true);
148}
149
150void wxSplitterWindow::OnLeaveSash()
151{
152 SetCursor(*wxSTANDARD_CURSOR);
153
154 RedrawIfHotSensitive(false);
155}
156
157void wxSplitterWindow::SetResizeCursor()
158{
159 SetCursor(m_splitMode == wxSPLIT_VERTICAL ? m_sashCursorWE
160 : m_sashCursorNS);
161}
162
163// ----------------------------------------------------------------------------
164// other event handlers
165// ----------------------------------------------------------------------------
166
167void wxSplitterWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
168{
169 wxPaintDC dc(this);
170
171 DrawSash(dc);
172}
173
174void wxSplitterWindow::OnInternalIdle()
175{
176 wxWindow::OnInternalIdle();
177
178 // if this is the first idle time after a sash position has potentially
179 // been set, allow SizeWindows to check for a requested size.
180 if (!m_checkRequestedSashPosition)
181 {
182 m_checkRequestedSashPosition = true;
183 SizeWindows();
184 return; // it won't needUpdating in this case
185 }
186
187 if (m_needUpdating)
188 SizeWindows();
189}
190
191void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
192{
193 int x = (int)event.GetX(),
194 y = (int)event.GetY();
195
196 if (GetWindowStyle() & wxSP_NOSASH)
197 return;
198
199 // with wxSP_LIVE_UPDATE style the splitter windows are always resized
200 // following the mouse movement while it drags the sash, without it we only
201 // draw the sash at the new position but only resize the windows when the
202 // dragging is finished
203 bool isLive = (GetWindowStyleFlag() & wxSP_LIVE_UPDATE) != 0;
204
205 if (event.LeftDown())
206 {
207 if ( SashHitTest(x, y) )
208 {
209 // Start the drag now
210 m_dragMode = wxSPLIT_DRAG_DRAGGING;
211
212 // Capture mouse and set the cursor
213 CaptureMouse();
214 SetResizeCursor();
215
216 if ( !isLive )
217 {
218 // remember the initial sash position and draw the initial
219 // shadow sash
220 m_sashPositionCurrent = m_sashPosition;
221
222 DrawSashTracker(x, y);
223 }
224
225 m_oldX = x;
226 m_oldY = y;
227
228 SetResizeCursor();
229 return;
230 }
231 }
232 else if (event.LeftUp() && m_dragMode == wxSPLIT_DRAG_DRAGGING)
233 {
234 // We can stop dragging now and see what we've got.
235 m_dragMode = wxSPLIT_DRAG_NONE;
236
237 // Release mouse and unset the cursor
238 ReleaseMouse();
239 SetCursor(* wxSTANDARD_CURSOR);
240
241 // exit if unsplit after doubleclick
242 if ( !IsSplit() )
243 {
244 return;
245 }
246
247 // Erase old tracker
248 if ( !isLive )
249 {
250 DrawSashTracker(m_oldX, m_oldY);
251 }
252
253 // the position of the click doesn't exactly correspond to
254 // m_sashPosition, rather it changes it by the distance by which the
255 // mouse has moved
256 int diff = m_splitMode == wxSPLIT_VERTICAL ? x - m_oldX : y - m_oldY;
257
258 int posSashOld = isLive ? m_sashPosition : m_sashPositionCurrent;
259 int posSashNew = OnSashPositionChanging(posSashOld + diff);
260 if ( posSashNew == -1 )
261 {
262 // change not allowed
263 return;
264 }
265
266 if ( m_permitUnsplitAlways || m_minimumPaneSize == 0 )
267 {
268 // Deal with possible unsplit scenarios
269 if ( posSashNew == 0 )
270 {
271 // We remove the first window from the view
272 wxWindow *removedWindow = m_windowOne;
273 m_windowOne = m_windowTwo;
274 m_windowTwo = (wxWindow *) NULL;
275 OnUnsplit(removedWindow);
276 wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
277 event.m_data.win = removedWindow;
278 (void)DoSendEvent(event);
279 SetSashPositionAndNotify(0);
280 }
281 else if ( posSashNew == GetWindowSize() )
282 {
283 // We remove the second window from the view
284 wxWindow *removedWindow = m_windowTwo;
285 m_windowTwo = (wxWindow *) NULL;
286 OnUnsplit(removedWindow);
287 wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
288 event.m_data.win = removedWindow;
289 (void)DoSendEvent(event);
290 SetSashPositionAndNotify(0);
291 }
292 else
293 {
294 SetSashPositionAndNotify(posSashNew);
295 }
296 }
297 else
298 {
299 SetSashPositionAndNotify(posSashNew);
300 }
301
302 SizeWindows();
303 } // left up && dragging
304 else if ((event.Moving() || event.Leaving() || event.Entering()) && (m_dragMode == wxSPLIT_DRAG_NONE))
305 {
306 if ( event.Leaving() || !SashHitTest(x, y) )
307 OnLeaveSash();
308 else
309 OnEnterSash();
310 }
311 else if (event.Dragging() && (m_dragMode == wxSPLIT_DRAG_DRAGGING))
312 {
313 int diff = m_splitMode == wxSPLIT_VERTICAL ? x - m_oldX : y - m_oldY;
314 if ( !diff )
315 {
316 // nothing to do, mouse didn't really move far enough
317 return;
318 }
319
320 int posSashOld = isLive ? m_sashPosition : m_sashPositionCurrent;
321 int posSashNew = OnSashPositionChanging(posSashOld + diff);
322 if ( posSashNew == -1 )
323 {
324 // change not allowed
325 return;
326 }
327
328 if ( posSashNew == m_sashPosition )
329 return;
330
331 // Erase old tracker
332 if ( !isLive )
333 {
334 DrawSashTracker(m_oldX, m_oldY);
335 }
336
337 if (m_splitMode == wxSPLIT_VERTICAL)
338 x = posSashNew;
339 else
340 y = posSashNew;
341
342 // Remember old positions
343 m_oldX = x;
344 m_oldY = y;
345
346#ifdef __WXMSW__
347 // As we captured the mouse, we may get the mouse events from outside
348 // our window - for example, negative values in x, y. This has a weird
349 // consequence under MSW where we use unsigned values sometimes and
350 // signed ones other times: the coordinates turn as big positive
351 // numbers and so the sash is drawn on the *right* side of the window
352 // instead of the left (or bottom instead of top). Correct this.
353 if ( (short)m_oldX < 0 )
354 m_oldX = 0;
355 if ( (short)m_oldY < 0 )
356 m_oldY = 0;
357#endif // __WXMSW__
358
359 // Draw new one
360 if ( !isLive )
361 {
362 m_sashPositionCurrent = posSashNew;
363
364 DrawSashTracker(m_oldX, m_oldY);
365 }
366 else
367 {
368 SetSashPositionAndNotify(posSashNew);
369 m_needUpdating = true;
370 }
371 }
372 else if ( event.LeftDClick() && m_windowTwo )
373 {
374 OnDoubleClickSash(x, y);
375 }
376}
377
378void wxSplitterWindow::OnSize(wxSizeEvent& event)
379{
380 // only process this message if we're not iconized - otherwise iconizing
381 // and restoring a window containing the splitter has a funny side effect
382 // of changing the splitter position!
383 wxWindow *parent = wxGetTopLevelParent(this);
384 bool iconized;
385
386 wxTopLevelWindow *winTop = wxDynamicCast(parent, wxTopLevelWindow);
387 if ( winTop )
388 {
389 iconized = winTop->IsIconized();
390 }
391 else
392 {
393 wxFAIL_MSG(wxT("should have a top level parent!"));
394
395 iconized = false;
396 }
397
398 if ( iconized )
399 {
400 event.Skip();
401
402 return;
403 }
404
405 if ( m_windowTwo )
406 {
407 int w, h;
408 GetClientSize(&w, &h);
409
410 int size = m_splitMode == wxSPLIT_VERTICAL ? w : h;
411 if ( m_sashPosition >= size - 5 )
412 SetSashPositionAndNotify(wxMax(10, size - 40));
413 }
414
415 SizeWindows();
416}
417
418bool wxSplitterWindow::SashHitTest(int x, int y, int tolerance)
419{
420 if ( m_windowTwo == NULL || m_sashPosition == 0)
421 return false; // No sash
422
423 int z = m_splitMode == wxSPLIT_VERTICAL ? x : y;
424 int hitMin = m_sashPosition - tolerance;
425 int hitMax = m_sashPosition + GetSashSize() + tolerance;
426
427 return z >= hitMin && z <= hitMax;
428}
429
430int wxSplitterWindow::GetSashSize() const
431{
432 return wxRendererNative::Get().GetSplitterParams(this).widthSash;
433}
434
435int wxSplitterWindow::GetBorderSize() const
436{
437 return wxRendererNative::Get().GetSplitterParams(this).border;
438}
439
440// Draw the sash
441void wxSplitterWindow::DrawSash(wxDC& dc)
442{
443 if (HasFlag(wxSP_3DBORDER))
444 wxRendererNative::Get().DrawSplitterBorder
445 (
446 this,
447 dc,
448 GetClientRect()
449 );
450
451 // don't draw sash if we're not split
452 if ( m_sashPosition == 0 || !m_windowTwo )
453 return;
454
455 // nor if we're configured to not show it
456 if ( HasFlag(wxSP_NOSASH) )
457 return;
458
459 wxRendererNative::Get().DrawSplitterSash
460 (
461 this,
462 dc,
463 GetClientSize(),
464 m_sashPosition,
465 m_splitMode == wxSPLIT_VERTICAL ? wxVERTICAL
466 : wxHORIZONTAL,
467 m_isHot ? wxCONTROL_CURRENT : 0
468 );
469}
470
471// Draw the sash tracker (for whilst moving the sash)
472void wxSplitterWindow::DrawSashTracker(int x, int y)
473{
474 int w, h;
475 GetClientSize(&w, &h);
476
477 wxScreenDC screenDC;
478 int x1, y1;
479 int x2, y2;
480
481 if ( m_splitMode == wxSPLIT_VERTICAL )
482 {
483 x1 = x; y1 = 2;
484 x2 = x; y2 = h-2;
485
486 if ( x1 > w )
487 {
488 x1 = w; x2 = w;
489 }
490 else if ( x1 < 0 )
491 {
492 x1 = 0; x2 = 0;
493 }
494 }
495 else
496 {
497 x1 = 2; y1 = y;
498 x2 = w-2; y2 = y;
499
500 if ( y1 > h )
501 {
502 y1 = h;
503 y2 = h;
504 }
505 else if ( y1 < 0 )
506 {
507 y1 = 0;
508 y2 = 0;
509 }
510 }
511
512 ClientToScreen(&x1, &y1);
513 ClientToScreen(&x2, &y2);
514
515 screenDC.SetLogicalFunction(wxINVERT);
516 screenDC.SetPen(*m_sashTrackerPen);
517 screenDC.SetBrush(*wxTRANSPARENT_BRUSH);
518
519 screenDC.DrawLine(x1, y1, x2, y2);
520
521 screenDC.SetLogicalFunction(wxCOPY);
522}
523
524int wxSplitterWindow::GetWindowSize() const
525{
526 wxSize size = GetClientSize();
527
528 return m_splitMode == wxSPLIT_VERTICAL ? size.x : size.y;
529}
530
531int wxSplitterWindow::AdjustSashPosition(int sashPos) const
532{
533 int window_size = GetWindowSize();
534
535 wxWindow *win;
536
537 win = GetWindow1();
538 if ( win )
539 {
540 // the window shouldn't be smaller than its own minimal size nor
541 // smaller than the minimual pane size specified for this splitter
542 int minSize = m_splitMode == wxSPLIT_VERTICAL ? win->GetMinWidth()
543 : win->GetMinHeight();
544
545 if ( minSize == -1 || m_minimumPaneSize > minSize )
546 minSize = m_minimumPaneSize;
547
548 minSize += GetBorderSize();
549
550 if ( sashPos < minSize )
551 sashPos = minSize;
552 }
553
554 win = GetWindow2();
555 if ( win )
556 {
557 int minSize = m_splitMode == wxSPLIT_VERTICAL ? win->GetMinWidth()
558 : win->GetMinHeight();
559
560 if ( minSize == -1 || m_minimumPaneSize > minSize )
561 minSize = m_minimumPaneSize;
562
563 int maxSize = window_size - minSize - GetBorderSize();
564 if ( sashPos > maxSize )
565 sashPos = maxSize;
566 }
567
568 return sashPos;
569}
570
571bool wxSplitterWindow::DoSetSashPosition(int sashPos)
572{
573 int newSashPosition = AdjustSashPosition(sashPos);
574
575 if ( newSashPosition == m_sashPosition )
576 return false;
577
578 m_sashPosition = newSashPosition;
579
580 return true;
581}
582
583void wxSplitterWindow::SetSashPositionAndNotify(int sashPos)
584{
585 if ( DoSetSashPosition(sashPos) )
586 {
587 wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, this);
588 event.m_data.pos = m_sashPosition;
589
590 (void)DoSendEvent(event);
591 }
592}
593
594// Position and size subwindows.
595// Note that the border size applies to each subwindow, not
596// including the edges next to the sash.
597void wxSplitterWindow::SizeWindows()
598{
599 // check if we have delayed setting the real sash position
600 if ( m_checkRequestedSashPosition && m_requestedSashPosition != INT_MAX )
601 {
602 int newSashPosition = ConvertSashPosition(m_requestedSashPosition);
603 if ( newSashPosition != m_sashPosition )
604 {
605 DoSetSashPosition(newSashPosition);
606 }
607
608 if ( newSashPosition <= m_sashPosition
609 && newSashPosition >= m_sashPosition - GetBorderSize() )
610 {
611 // don't update it any more
612 m_requestedSashPosition = INT_MAX;
613 }
614 }
615
616 int w, h;
617 GetClientSize(&w, &h);
618
619 if ( GetWindow1() && !GetWindow2() )
620 {
621 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
622 w - 2*GetBorderSize(), h - 2*GetBorderSize());
623 }
624 else if ( GetWindow1() && GetWindow2() )
625 {
626 const int border = GetBorderSize(),
627 sash = GetSashSize();
628
629 int size1 = GetSashPosition() - border,
630 size2 = GetSashPosition() + sash;
631
632 int x2, y2, w1, h1, w2, h2;
633 if ( GetSplitMode() == wxSPLIT_VERTICAL )
634 {
635 w1 = size1;
636 w2 = w - 2*border - sash - w1;
637 h1 =
638 h2 = h - 2*border;
639 x2 = size2;
640 y2 = border;
641 }
642 else // horz splitter
643 {
644 w1 =
645 w2 = w - 2*border;
646 h1 = size1;
647 h2 = h - 2*border - sash - h1;
648 x2 = border;
649 y2 = size2;
650 }
651
652 GetWindow1()->SetSize(border, border, w1, h1);
653 GetWindow2()->SetSize(x2, y2, w2, h2);
654 }
655
656 wxClientDC dc(this);
657 DrawSash(dc);
658
659 SetNeedUpdating(false);
660}
661
662// Set pane for unsplit window
663void wxSplitterWindow::Initialize(wxWindow *window)
664{
665 wxASSERT_MSG( window && window->GetParent() == this,
666 _T("windows in the splitter should have it as parent!") );
667
668 m_windowOne = window;
669 m_windowTwo = (wxWindow *) NULL;
670 DoSetSashPosition(0);
671}
672
673// Associates the given window with window 2, drawing the appropriate sash
674// and changing the split mode.
675// Does nothing and returns false if the window is already split.
676bool wxSplitterWindow::DoSplit(wxSplitMode mode,
677 wxWindow *window1, wxWindow *window2,
678 int sashPosition)
679{
680 if ( IsSplit() )
681 return false;
682
683 wxCHECK_MSG( window1 && window2, false,
684 _T("can not split with NULL window(s)") );
685
686 wxCHECK_MSG( window1->GetParent() == this && window2->GetParent() == this, false,
687 _T("windows in the splitter should have it as parent!") );
688
689 m_splitMode = mode;
690 m_windowOne = window1;
691 m_windowTwo = window2;
692
693 // remember the sash position we want to set for later if we can't set it
694 // right now (e.g. because the window is too small)
695 m_requestedSashPosition = sashPosition;
696 m_checkRequestedSashPosition = false;
697
698 DoSetSashPosition(ConvertSashPosition(sashPosition));
699
700 SizeWindows();
701
702 return true;
703}
704
705int wxSplitterWindow::ConvertSashPosition(int sashPosition) const
706{
707 if ( sashPosition > 0 )
708 {
709 return sashPosition;
710 }
711 else if ( sashPosition < 0 )
712 {
713 // It's negative so adding is subtracting
714 return GetWindowSize() + sashPosition;
715 }
716 else // sashPosition == 0
717 {
718 // default, put it in the centre
719 return GetWindowSize() / 2;
720 }
721}
722
723// Remove the specified (or second) window from the view
724// Doesn't actually delete the window.
725bool wxSplitterWindow::Unsplit(wxWindow *toRemove)
726{
727 if ( ! IsSplit() )
728 return false;
729
730 wxWindow *win;
731 if ( toRemove == NULL || toRemove == m_windowTwo)
732 {
733 win = m_windowTwo ;
734 m_windowTwo = (wxWindow *) NULL;
735 }
736 else if ( toRemove == m_windowOne )
737 {
738 win = m_windowOne ;
739 m_windowOne = m_windowTwo;
740 m_windowTwo = (wxWindow *) NULL;
741 }
742 else
743 {
744 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
745
746 return false;
747 }
748
749 OnUnsplit(win);
750 DoSetSashPosition(0);
751 SizeWindows();
752
753 return true;
754}
755
756// Replace a window with another one
757bool wxSplitterWindow::ReplaceWindow(wxWindow *winOld, wxWindow *winNew)
758{
759 wxCHECK_MSG( winOld, false, wxT("use one of Split() functions instead") );
760 wxCHECK_MSG( winNew, false, wxT("use Unsplit() functions instead") );
761
762 if ( winOld == m_windowTwo )
763 {
764 m_windowTwo = winNew;
765 }
766 else if ( winOld == m_windowOne )
767 {
768 m_windowOne = winNew;
769 }
770 else
771 {
772 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
773
774 return false;
775 }
776
777 SizeWindows();
778
779 return true;
780}
781
782void wxSplitterWindow::SetMinimumPaneSize(int min)
783{
784 m_minimumPaneSize = min;
785 int pos = m_requestedSashPosition != INT_MAX ? m_requestedSashPosition : m_sashPosition;
786 SetSashPosition(pos); // re-check limits
787}
788
789void wxSplitterWindow::SetSashPosition(int position, bool redraw)
790{
791 // remember the sash position we want to set for later if we can't set it
792 // right now (e.g. because the window is too small)
793 m_requestedSashPosition = position;
794 m_checkRequestedSashPosition = false;
795
796 DoSetSashPosition(ConvertSashPosition(position));
797
798 if ( redraw )
799 {
800 SizeWindows();
801 }
802}
803
804// Make sure the child window sizes are updated. This is useful
805// for reducing flicker by updating the sizes before a
806// window is shown, if you know the overall size is correct.
807void wxSplitterWindow::UpdateSize()
808{
809 m_checkRequestedSashPosition = true;
810 SizeWindows();
811 m_checkRequestedSashPosition = false;
812}
813
814bool wxSplitterWindow::DoSendEvent(wxSplitterEvent& event)
815{
816 return !GetEventHandler()->ProcessEvent(event) || event.IsAllowed();
817}
818
819// ---------------------------------------------------------------------------
820// wxSplitterWindow virtual functions: they now just generate the events
821// ---------------------------------------------------------------------------
822
823bool wxSplitterWindow::OnSashPositionChange(int WXUNUSED(newSashPosition))
824{
825 // always allow by default
826 return true;
827}
828
829int wxSplitterWindow::OnSashPositionChanging(int newSashPosition)
830{
831 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
832 const int UNSPLIT_THRESHOLD = 4;
833
834 // first of all, check if OnSashPositionChange() doesn't forbid this change
835 if ( !OnSashPositionChange(newSashPosition) )
836 {
837 // it does
838 return -1;
839 }
840
841 // Obtain relevant window dimension for bottom / right threshold check
842 int window_size = GetWindowSize();
843
844 bool unsplit_scenario = false;
845 if ( m_permitUnsplitAlways || m_minimumPaneSize == 0 )
846 {
847 // Do edge detection if unsplit premitted
848 if ( newSashPosition <= UNSPLIT_THRESHOLD )
849 {
850 // threshold top / left check
851 newSashPosition = 0;
852 unsplit_scenario = true;
853 }
854 if ( newSashPosition >= window_size - UNSPLIT_THRESHOLD )
855 {
856 // threshold bottom/right check
857 newSashPosition = window_size;
858 unsplit_scenario = true;
859 }
860 }
861
862 if ( !unsplit_scenario )
863 {
864 // If resultant pane would be too small, enlarge it
865 newSashPosition = AdjustSashPosition(newSashPosition);
866 }
867
868 // If the result is out of bounds it means minimum size is too big,
869 // so split window in half as best compromise.
870 if ( newSashPosition < 0 || newSashPosition > window_size )
871 newSashPosition = window_size / 2;
872
873 // now let the event handler have it
874 //
875 // FIXME: shouldn't we do it before the adjustments above so as to ensure
876 // that the sash position is always reasonable?
877 wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, this);
878 event.m_data.pos = newSashPosition;
879
880 if ( !DoSendEvent(event) )
881 {
882 // the event handler vetoed the change
883 newSashPosition = -1;
884 }
885 else
886 {
887 // it could have been changed by it
888 newSashPosition = event.GetSashPosition();
889 }
890
891 return newSashPosition;
892}
893
894// Called when the sash is double-clicked. The default behaviour is to remove
895// the sash if the minimum pane size is zero.
896void wxSplitterWindow::OnDoubleClickSash(int x, int y)
897{
898 wxCHECK_RET(m_windowTwo, wxT("splitter: no window to remove"));
899
900 // new code should handle events instead of using the virtual functions
901 wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, this);
902 event.m_data.pt.x = x;
903 event.m_data.pt.y = y;
904 if ( DoSendEvent(event) )
905 {
906 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways )
907 {
908 wxWindow* win = m_windowTwo;
909 if ( Unsplit(win) )
910 {
911 wxSplitterEvent unsplitEvent(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
912 unsplitEvent.m_data.win = win;
913 (void)DoSendEvent(unsplitEvent);
914 }
915 }
916 }
917 //else: blocked by user
918}
919
920void wxSplitterWindow::OnUnsplit(wxWindow *winRemoved)
921{
922 // call this before calling the event handler which may delete the window
923 winRemoved->Show(false);
924}
925
926#if defined( __WXMSW__ ) || defined( __WXMAC__)
927
928// this is currently called (and needed) under MSW only...
929void wxSplitterWindow::OnSetCursor(wxSetCursorEvent& event)
930{
931 // if we don't do it, the resizing cursor might be set for child window:
932 // and like this we explicitly say that our cursor should not be used for
933 // children windows which overlap us
934
935 if ( SashHitTest(event.GetX(), event.GetY(), 0) )
936 {
937 // default processing is ok
938 event.Skip();
939 }
940 //else: do nothing, in particular, don't call Skip()
941}
942
943#endif // wxMSW || wxMac
944
945#endif // wxUSE_SPLITTER
946