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