]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/generic/splitter.cpp
add a outside area for borders and focus rects of 3 pixels to a wxWindowDC's clip...
[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#if defined( __WXMAC__ ) && TARGET_API_MAC_OSX == 1
204 bool isLive = true ;
205#else
206 bool isLive = (GetWindowStyleFlag() & wxSP_LIVE_UPDATE) != 0;
207#endif
208 if (event.LeftDown())
209 {
210 if ( SashHitTest(x, y) )
211 {
212 // Start the drag now
213 m_dragMode = wxSPLIT_DRAG_DRAGGING;
214
215 // Capture mouse and set the cursor
216 CaptureMouse();
217 SetResizeCursor();
218
219 if ( !isLive )
220 {
221 // remember the initial sash position and draw the initial
222 // shadow sash
223 m_sashPositionCurrent = m_sashPosition;
224
225 DrawSashTracker(x, y);
226 }
227
228 m_oldX = x;
229 m_oldY = y;
230
231 SetResizeCursor();
232 return;
233 }
234 }
235 else if (event.LeftUp() && m_dragMode == wxSPLIT_DRAG_DRAGGING)
236 {
237 // We can stop dragging now and see what we've got.
238 m_dragMode = wxSPLIT_DRAG_NONE;
239
240 // Release mouse and unset the cursor
241 ReleaseMouse();
242 SetCursor(* wxSTANDARD_CURSOR);
243
244 // exit if unsplit after doubleclick
245 if ( !IsSplit() )
246 {
247 return;
248 }
249
250 // Erase old tracker
251 if ( !isLive )
252 {
253 DrawSashTracker(m_oldX, m_oldY);
254 }
255
256 // the position of the click doesn't exactly correspond to
257 // m_sashPosition, rather it changes it by the distance by which the
258 // mouse has moved
259 int diff = m_splitMode == wxSPLIT_VERTICAL ? x - m_oldX : y - m_oldY;
260
261 int posSashOld = isLive ? m_sashPosition : m_sashPositionCurrent;
262 int posSashNew = OnSashPositionChanging(posSashOld + diff);
263 if ( posSashNew == -1 )
264 {
265 // change not allowed
266 return;
267 }
268
269 if ( m_permitUnsplitAlways || m_minimumPaneSize == 0 )
270 {
271 // Deal with possible unsplit scenarios
272 if ( posSashNew == 0 )
273 {
274 // We remove the first window from the view
275 wxWindow *removedWindow = m_windowOne;
276 m_windowOne = m_windowTwo;
277 m_windowTwo = (wxWindow *) NULL;
278 OnUnsplit(removedWindow);
279 wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
280 event.m_data.win = removedWindow;
281 (void)DoSendEvent(event);
282 SetSashPositionAndNotify(0);
283 }
284 else if ( posSashNew == GetWindowSize() )
285 {
286 // We remove the second window from the view
287 wxWindow *removedWindow = m_windowTwo;
288 m_windowTwo = (wxWindow *) NULL;
289 OnUnsplit(removedWindow);
290 wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
291 event.m_data.win = removedWindow;
292 (void)DoSendEvent(event);
293 SetSashPositionAndNotify(0);
294 }
295 else
296 {
297 SetSashPositionAndNotify(posSashNew);
298 }
299 }
300 else
301 {
302 SetSashPositionAndNotify(posSashNew);
303 }
304
305 SizeWindows();
306 } // left up && dragging
307 else if ((event.Moving() || event.Leaving() || event.Entering()) && (m_dragMode == wxSPLIT_DRAG_NONE))
308 {
309 if ( event.Leaving() || !SashHitTest(x, y) )
310 OnLeaveSash();
311 else
312 OnEnterSash();
313 }
314 else if (event.Dragging() && (m_dragMode == wxSPLIT_DRAG_DRAGGING))
315 {
316 int diff = m_splitMode == wxSPLIT_VERTICAL ? x - m_oldX : y - m_oldY;
317 if ( !diff )
318 {
319 // nothing to do, mouse didn't really move far enough
320 return;
321 }
322
323 int posSashOld = isLive ? m_sashPosition : m_sashPositionCurrent;
324 int posSashNew = OnSashPositionChanging(posSashOld + diff);
325 if ( posSashNew == -1 )
326 {
327 // change not allowed
328 return;
329 }
330
331 if ( posSashNew == m_sashPosition )
332 return;
333
334 // Erase old tracker
335 if ( !isLive )
336 {
337 DrawSashTracker(m_oldX, m_oldY);
338 }
339
340 if (m_splitMode == wxSPLIT_VERTICAL)
341 x = posSashNew;
342 else
343 y = posSashNew;
344
345 // Remember old positions
346 m_oldX = x;
347 m_oldY = y;
348
349#ifdef __WXMSW__
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 )
357 m_oldX = 0;
358 if ( (short)m_oldY < 0 )
359 m_oldY = 0;
360#endif // __WXMSW__
361
362 // Draw new one
363 if ( !isLive )
364 {
365 m_sashPositionCurrent = posSashNew;
366
367 DrawSashTracker(m_oldX, m_oldY);
368 }
369 else
370 {
371 SetSashPositionAndNotify(posSashNew);
372 m_needUpdating = true;
373 }
374 }
375 else if ( event.LeftDClick() && m_windowTwo )
376 {
377 OnDoubleClickSash(x, y);
378 }
379}
380
381void wxSplitterWindow::OnSize(wxSizeEvent& event)
382{
383 // only process this message if we're not iconized - otherwise iconizing
384 // and restoring a window containing the splitter has a funny side effect
385 // of changing the splitter position!
386 wxWindow *parent = wxGetTopLevelParent(this);
387 bool iconized;
388
389 wxTopLevelWindow *winTop = wxDynamicCast(parent, wxTopLevelWindow);
390 if ( winTop )
391 {
392 iconized = winTop->IsIconized();
393 }
394 else
395 {
396 wxFAIL_MSG(wxT("should have a top level parent!"));
397
398 iconized = false;
399 }
400
401 if ( iconized )
402 {
403 event.Skip();
404
405 return;
406 }
407
408 if ( m_windowTwo )
409 {
410 int w, h;
411 GetClientSize(&w, &h);
412
413 int size = m_splitMode == wxSPLIT_VERTICAL ? w : h;
414 if ( m_sashPosition >= size - 5 )
415 SetSashPositionAndNotify(wxMax(10, size - 40));
416 }
417
418 SizeWindows();
419}
420
421bool wxSplitterWindow::SashHitTest(int x, int y, int tolerance)
422{
423 if ( m_windowTwo == NULL || m_sashPosition == 0)
424 return false; // No sash
425
426 int z = m_splitMode == wxSPLIT_VERTICAL ? x : y;
427 int hitMin = m_sashPosition - tolerance;
428 int hitMax = m_sashPosition + GetSashSize() + tolerance;
429
430 return z >= hitMin && z <= hitMax;
431}
432
433int wxSplitterWindow::GetSashSize() const
434{
435 return wxRendererNative::Get().GetSplitterParams(this).widthSash;
436}
437
438int wxSplitterWindow::GetBorderSize() const
439{
440 return wxRendererNative::Get().GetSplitterParams(this).border;
441}
442
443// Draw the sash
444void wxSplitterWindow::DrawSash(wxDC& dc)
445{
446 if (HasFlag(wxSP_3DBORDER))
447 wxRendererNative::Get().DrawSplitterBorder
448 (
449 this,
450 dc,
451 GetClientRect()
452 );
453
454 // don't draw sash if we're not split
455 if ( m_sashPosition == 0 || !m_windowTwo )
456 return;
457
458 // nor if we're configured to not show it
459 if ( HasFlag(wxSP_NOSASH) )
460 return;
461
462 wxRendererNative::Get().DrawSplitterSash
463 (
464 this,
465 dc,
466 GetClientSize(),
467 m_sashPosition,
468 m_splitMode == wxSPLIT_VERTICAL ? wxVERTICAL
469 : wxHORIZONTAL,
470 m_isHot ? wxCONTROL_CURRENT : 0
471 );
472}
473
474// Draw the sash tracker (for whilst moving the sash)
475void wxSplitterWindow::DrawSashTracker(int x, int y)
476{
477 int w, h;
478 GetClientSize(&w, &h);
479
480 wxScreenDC screenDC;
481 int x1, y1;
482 int x2, y2;
483
484 if ( m_splitMode == wxSPLIT_VERTICAL )
485 {
486 x1 = x; y1 = 2;
487 x2 = x; y2 = h-2;
488
489 if ( x1 > w )
490 {
491 x1 = w; x2 = w;
492 }
493 else if ( x1 < 0 )
494 {
495 x1 = 0; x2 = 0;
496 }
497 }
498 else
499 {
500 x1 = 2; y1 = y;
501 x2 = w-2; y2 = y;
502
503 if ( y1 > h )
504 {
505 y1 = h;
506 y2 = h;
507 }
508 else if ( y1 < 0 )
509 {
510 y1 = 0;
511 y2 = 0;
512 }
513 }
514
515 ClientToScreen(&x1, &y1);
516 ClientToScreen(&x2, &y2);
517
518 screenDC.SetLogicalFunction(wxINVERT);
519 screenDC.SetPen(*m_sashTrackerPen);
520 screenDC.SetBrush(*wxTRANSPARENT_BRUSH);
521
522 screenDC.DrawLine(x1, y1, x2, y2);
523
524 screenDC.SetLogicalFunction(wxCOPY);
525}
526
527int wxSplitterWindow::GetWindowSize() const
528{
529 wxSize size = GetClientSize();
530
531 return m_splitMode == wxSPLIT_VERTICAL ? size.x : size.y;
532}
533
534int wxSplitterWindow::AdjustSashPosition(int sashPos) const
535{
536 int window_size = GetWindowSize();
537
538 wxWindow *win;
539
540 win = GetWindow1();
541 if ( win )
542 {
543 // the window shouldn't be smaller than its own minimal size nor
544 // smaller than the minimual pane size specified for this splitter
545 int minSize = m_splitMode == wxSPLIT_VERTICAL ? win->GetMinWidth()
546 : win->GetMinHeight();
547
548 if ( minSize == -1 || m_minimumPaneSize > minSize )
549 minSize = m_minimumPaneSize;
550
551 minSize += GetBorderSize();
552
553 if ( sashPos < minSize )
554 sashPos = minSize;
555 }
556
557 win = GetWindow2();
558 if ( win )
559 {
560 int minSize = m_splitMode == wxSPLIT_VERTICAL ? win->GetMinWidth()
561 : win->GetMinHeight();
562
563 if ( minSize == -1 || m_minimumPaneSize > minSize )
564 minSize = m_minimumPaneSize;
565
566 int maxSize = window_size - minSize - GetBorderSize();
567 if ( sashPos > maxSize )
568 sashPos = maxSize;
569 }
570
571 return sashPos;
572}
573
574bool wxSplitterWindow::DoSetSashPosition(int sashPos)
575{
576 int newSashPosition = AdjustSashPosition(sashPos);
577
578 if ( newSashPosition == m_sashPosition )
579 return false;
580
581 m_sashPosition = newSashPosition;
582
583 return true;
584}
585
586void wxSplitterWindow::SetSashPositionAndNotify(int sashPos)
587{
588 // we must reset the request here, otherwise the sash would be stuck at
589 // old position if the user attempted to move the sash after invalid
590 // (e.g. smaller than minsize) sash position was requested using
591 // SetSashPosition():
592 m_requestedSashPosition = INT_MAX;
593
594 if ( DoSetSashPosition(sashPos) )
595 {
596 wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, this);
597 event.m_data.pos = m_sashPosition;
598
599 (void)DoSendEvent(event);
600 }
601}
602
603// Position and size subwindows.
604// Note that the border size applies to each subwindow, not
605// including the edges next to the sash.
606void wxSplitterWindow::SizeWindows()
607{
608 // check if we have delayed setting the real sash position
609 if ( m_checkRequestedSashPosition && m_requestedSashPosition != INT_MAX )
610 {
611 int newSashPosition = ConvertSashPosition(m_requestedSashPosition);
612 if ( newSashPosition != m_sashPosition )
613 {
614 DoSetSashPosition(newSashPosition);
615 }
616
617 if ( newSashPosition <= m_sashPosition
618 && newSashPosition >= m_sashPosition - GetBorderSize() )
619 {
620 // don't update it any more
621 m_requestedSashPosition = INT_MAX;
622 }
623 }
624
625 int w, h;
626 GetClientSize(&w, &h);
627
628 if ( GetWindow1() && !GetWindow2() )
629 {
630 GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
631 w - 2*GetBorderSize(), h - 2*GetBorderSize());
632 }
633 else if ( GetWindow1() && GetWindow2() )
634 {
635 const int border = GetBorderSize(),
636 sash = GetSashSize();
637
638 int size1 = GetSashPosition() - border,
639 size2 = GetSashPosition() + sash;
640
641 int x2, y2, w1, h1, w2, h2;
642 if ( GetSplitMode() == wxSPLIT_VERTICAL )
643 {
644 w1 = size1;
645 w2 = w - 2*border - sash - w1;
646 h1 =
647 h2 = h - 2*border;
648 x2 = size2;
649 y2 = border;
650 }
651 else // horz splitter
652 {
653 w1 =
654 w2 = w - 2*border;
655 h1 = size1;
656 h2 = h - 2*border - sash - h1;
657 x2 = border;
658 y2 = size2;
659 }
660
661 GetWindow1()->SetSize(border, border, w1, h1);
662 GetWindow2()->SetSize(x2, y2, w2, h2);
663 }
664
665 wxClientDC dc(this);
666 DrawSash(dc);
667
668 SetNeedUpdating(false);
669}
670
671// Set pane for unsplit window
672void wxSplitterWindow::Initialize(wxWindow *window)
673{
674 wxASSERT_MSG( (!window || (window && window->GetParent() == this)),
675 _T("windows in the splitter should have it as parent!") );
676
677 m_windowOne = window;
678 m_windowTwo = (wxWindow *) NULL;
679 DoSetSashPosition(0);
680}
681
682// Associates the given window with window 2, drawing the appropriate sash
683// and changing the split mode.
684// Does nothing and returns false if the window is already split.
685bool wxSplitterWindow::DoSplit(wxSplitMode mode,
686 wxWindow *window1, wxWindow *window2,
687 int sashPosition)
688{
689 if ( IsSplit() )
690 return false;
691
692 wxCHECK_MSG( window1 && window2, false,
693 _T("can not split with NULL window(s)") );
694
695 wxCHECK_MSG( window1->GetParent() == this && window2->GetParent() == this, false,
696 _T("windows in the splitter should have it as parent!") );
697
698 m_splitMode = mode;
699 m_windowOne = window1;
700 m_windowTwo = window2;
701
702 // remember the sash position we want to set for later if we can't set it
703 // right now (e.g. because the window is too small)
704 m_requestedSashPosition = sashPosition;
705 m_checkRequestedSashPosition = false;
706
707 DoSetSashPosition(ConvertSashPosition(sashPosition));
708
709 SizeWindows();
710
711 return true;
712}
713
714int wxSplitterWindow::ConvertSashPosition(int sashPosition) const
715{
716 if ( sashPosition > 0 )
717 {
718 return sashPosition;
719 }
720 else if ( sashPosition < 0 )
721 {
722 // It's negative so adding is subtracting
723 return GetWindowSize() + sashPosition;
724 }
725 else // sashPosition == 0
726 {
727 // default, put it in the centre
728 return GetWindowSize() / 2;
729 }
730}
731
732// Remove the specified (or second) window from the view
733// Doesn't actually delete the window.
734bool wxSplitterWindow::Unsplit(wxWindow *toRemove)
735{
736 if ( ! IsSplit() )
737 return false;
738
739 wxWindow *win;
740 if ( toRemove == NULL || toRemove == m_windowTwo)
741 {
742 win = m_windowTwo ;
743 m_windowTwo = (wxWindow *) NULL;
744 }
745 else if ( toRemove == m_windowOne )
746 {
747 win = m_windowOne ;
748 m_windowOne = m_windowTwo;
749 m_windowTwo = (wxWindow *) NULL;
750 }
751 else
752 {
753 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
754
755 return false;
756 }
757
758 OnUnsplit(win);
759 DoSetSashPosition(0);
760 SizeWindows();
761
762 return true;
763}
764
765// Replace a window with another one
766bool wxSplitterWindow::ReplaceWindow(wxWindow *winOld, wxWindow *winNew)
767{
768 wxCHECK_MSG( winOld, false, wxT("use one of Split() functions instead") );
769 wxCHECK_MSG( winNew, false, wxT("use Unsplit() functions instead") );
770
771 if ( winOld == m_windowTwo )
772 {
773 m_windowTwo = winNew;
774 }
775 else if ( winOld == m_windowOne )
776 {
777 m_windowOne = winNew;
778 }
779 else
780 {
781 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
782
783 return false;
784 }
785
786 SizeWindows();
787
788 return true;
789}
790
791void wxSplitterWindow::SetMinimumPaneSize(int min)
792{
793 m_minimumPaneSize = min;
794 int pos = m_requestedSashPosition != INT_MAX ? m_requestedSashPosition : m_sashPosition;
795 SetSashPosition(pos); // re-check limits
796}
797
798void wxSplitterWindow::SetSashPosition(int position, bool redraw)
799{
800 // remember the sash position we want to set for later if we can't set it
801 // right now (e.g. because the window is too small)
802 m_requestedSashPosition = position;
803 m_checkRequestedSashPosition = false;
804
805 DoSetSashPosition(ConvertSashPosition(position));
806
807 if ( redraw )
808 {
809 SizeWindows();
810 }
811}
812
813// Make sure the child window sizes are updated. This is useful
814// for reducing flicker by updating the sizes before a
815// window is shown, if you know the overall size is correct.
816void wxSplitterWindow::UpdateSize()
817{
818 m_checkRequestedSashPosition = true;
819 SizeWindows();
820 m_checkRequestedSashPosition = false;
821}
822
823bool wxSplitterWindow::DoSendEvent(wxSplitterEvent& event)
824{
825 return !GetEventHandler()->ProcessEvent(event) || event.IsAllowed();
826}
827
828// ---------------------------------------------------------------------------
829// wxSplitterWindow virtual functions: they now just generate the events
830// ---------------------------------------------------------------------------
831
832bool wxSplitterWindow::OnSashPositionChange(int WXUNUSED(newSashPosition))
833{
834 // always allow by default
835 return true;
836}
837
838int wxSplitterWindow::OnSashPositionChanging(int newSashPosition)
839{
840 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
841 const int UNSPLIT_THRESHOLD = 4;
842
843 // first of all, check if OnSashPositionChange() doesn't forbid this change
844 if ( !OnSashPositionChange(newSashPosition) )
845 {
846 // it does
847 return -1;
848 }
849
850 // Obtain relevant window dimension for bottom / right threshold check
851 int window_size = GetWindowSize();
852
853 bool unsplit_scenario = false;
854 if ( m_permitUnsplitAlways || m_minimumPaneSize == 0 )
855 {
856 // Do edge detection if unsplit premitted
857 if ( newSashPosition <= UNSPLIT_THRESHOLD )
858 {
859 // threshold top / left check
860 newSashPosition = 0;
861 unsplit_scenario = true;
862 }
863 if ( newSashPosition >= window_size - UNSPLIT_THRESHOLD )
864 {
865 // threshold bottom/right check
866 newSashPosition = window_size;
867 unsplit_scenario = true;
868 }
869 }
870
871 if ( !unsplit_scenario )
872 {
873 // If resultant pane would be too small, enlarge it
874 newSashPosition = AdjustSashPosition(newSashPosition);
875 }
876
877 // If the result is out of bounds it means minimum size is too big,
878 // so split window in half as best compromise.
879 if ( newSashPosition < 0 || newSashPosition > window_size )
880 newSashPosition = window_size / 2;
881
882 // now let the event handler have it
883 //
884 // FIXME: shouldn't we do it before the adjustments above so as to ensure
885 // that the sash position is always reasonable?
886 wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING, this);
887 event.m_data.pos = newSashPosition;
888
889 if ( !DoSendEvent(event) )
890 {
891 // the event handler vetoed the change
892 newSashPosition = -1;
893 }
894 else
895 {
896 // it could have been changed by it
897 newSashPosition = event.GetSashPosition();
898 }
899
900 return newSashPosition;
901}
902
903// Called when the sash is double-clicked. The default behaviour is to remove
904// the sash if the minimum pane size is zero.
905void wxSplitterWindow::OnDoubleClickSash(int x, int y)
906{
907 wxCHECK_RET(m_windowTwo, wxT("splitter: no window to remove"));
908
909 // new code should handle events instead of using the virtual functions
910 wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, this);
911 event.m_data.pt.x = x;
912 event.m_data.pt.y = y;
913 if ( DoSendEvent(event) )
914 {
915 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways )
916 {
917 wxWindow* win = m_windowTwo;
918 if ( Unsplit(win) )
919 {
920 wxSplitterEvent unsplitEvent(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
921 unsplitEvent.m_data.win = win;
922 (void)DoSendEvent(unsplitEvent);
923 }
924 }
925 }
926 //else: blocked by user
927}
928
929void wxSplitterWindow::OnUnsplit(wxWindow *winRemoved)
930{
931 // call this before calling the event handler which may delete the window
932 winRemoved->Show(false);
933}
934
935#if defined( __WXMSW__ ) || defined( __WXMAC__)
936
937// this is currently called (and needed) under MSW only...
938void wxSplitterWindow::OnSetCursor(wxSetCursorEvent& event)
939{
940 // if we don't do it, the resizing cursor might be set for child window:
941 // and like this we explicitly say that our cursor should not be used for
942 // children windows which overlap us
943
944 if ( SashHitTest(event.GetX(), event.GetY(), 0) )
945 {
946 // default processing is ok
947 event.Skip();
948 }
949 //else: do nothing, in particular, don't call Skip()
950}
951
952#endif // wxMSW || wxMac
953
954#endif // wxUSE_SPLITTER
955