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