]> git.saurik.com Git - wxWidgets.git/blob - src/generic/splitter.cpp
Augmented version to b5
[wxWidgets.git] / src / generic / splitter.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 and Markus Holzem
9 // Licence: wxWindows license
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 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include <stdlib.h>
28
29 #include "wx/string.h"
30 #include "wx/splitter.h"
31 #include "wx/dcscreen.h"
32
33 #if !USE_SHARED_LIBRARY
34 IMPLEMENT_DYNAMIC_CLASS(wxSplitterWindow, wxWindow)
35 IMPLEMENT_DYNAMIC_CLASS(wxSplitterEvent, wxCommandEvent)
36
37 BEGIN_EVENT_TABLE(wxSplitterWindow, wxWindow)
38 EVT_PAINT(wxSplitterWindow::OnPaint)
39 EVT_SIZE(wxSplitterWindow::OnSize)
40 EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent)
41
42 EVT_SPLITTER_SASH_POS_CHANGED(-1, wxSplitterWindow::OnSashPosChanged)
43 EVT_SPLITTER_DCLICK(-1, wxSplitterWindow::OnDoubleClick)
44 EVT_SPLITTER_UNSPLIT(-1, wxSplitterWindow::OnUnsplitEvent)
45 END_EVENT_TABLE()
46 #endif
47
48 wxSplitterWindow::wxSplitterWindow()
49 {
50 m_splitMode = wxSPLIT_VERTICAL;
51 m_windowOne = (wxWindow *) NULL;
52 m_windowTwo = (wxWindow *) NULL;
53 m_dragMode = wxSPLIT_DRAG_NONE;
54 m_oldX = 0;
55 m_oldY = 0;
56 m_firstX = 0;
57 m_firstY = 0;
58 m_sashSize = 7;
59 m_borderSize = 2;
60 m_sashPosition = 0;
61 m_sashCursorWE = (wxCursor *) NULL;
62 m_sashCursorNS = (wxCursor *) NULL;
63 m_sashTrackerPen = (wxPen *) NULL;
64 m_lightShadowPen = (wxPen *) NULL;
65 m_mediumShadowPen = (wxPen *) NULL;
66 m_darkShadowPen = (wxPen *) NULL;
67 m_faceBrush = (wxBrush *) NULL;
68 m_facePen = (wxPen *) NULL;
69 m_hilightPen = (wxPen *) NULL;
70 m_minimumPaneSize = 0;
71 }
72
73 wxSplitterWindow::wxSplitterWindow(wxWindow *parent, wxWindowID id,
74 const wxPoint& pos,
75 const wxSize& size,
76 long style,
77 const wxString& name)
78 : wxWindow(parent, id, pos, size, style, name)
79 {
80 m_splitMode = wxSPLIT_VERTICAL;
81 m_windowOne = (wxWindow *) NULL;
82 m_windowTwo = (wxWindow *) NULL;
83 m_dragMode = wxSPLIT_DRAG_NONE;
84 m_oldX = 0;
85 m_oldY = 0;
86 m_firstX = 0;
87 m_firstY = 0;
88 m_sashSize = 7;
89 m_borderSize = 2;
90 m_sashPosition = 0;
91 m_minimumPaneSize = 0;
92 m_sashCursorWE = new wxCursor(wxCURSOR_SIZEWE);
93 m_sashCursorNS = new wxCursor(wxCURSOR_SIZENS);
94 m_sashTrackerPen = new wxPen(*wxBLACK, 2, wxSOLID);
95 m_lightShadowPen = (wxPen *) NULL;
96 m_mediumShadowPen = (wxPen *) NULL;
97 m_darkShadowPen = (wxPen *) NULL;
98 m_faceBrush = (wxBrush *) NULL;
99 m_facePen = (wxPen *) NULL;
100 m_hilightPen = (wxPen *) NULL;
101
102 if ( style & wxSP_3D )
103 {
104 m_borderSize = 2;
105 m_sashSize = 7;
106 }
107 else if ( style & wxSP_BORDER )
108 {
109 m_borderSize = 1;
110 m_sashSize = 3;
111 }
112 else
113 {
114 m_borderSize = 0;
115 m_sashSize = 3;
116 }
117
118 // Eventually, we'll respond to colour change messages
119 InitColours();
120
121 // For debugging purposes, to see the background.
122 // SetBackground(wxBLUE_BRUSH);
123 }
124
125 wxSplitterWindow::~wxSplitterWindow()
126 {
127 delete m_sashCursorWE;
128 delete m_sashCursorNS;
129 delete m_sashTrackerPen;
130 delete m_lightShadowPen;
131 delete m_darkShadowPen;
132 delete m_mediumShadowPen;
133 delete m_hilightPen;
134 delete m_facePen;
135 delete m_faceBrush;
136 }
137
138 void wxSplitterWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
139 {
140 wxPaintDC dc(this);
141
142 if ( m_borderSize > 0 )
143 DrawBorders(dc);
144 DrawSash(dc);
145 }
146
147
148 void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
149 {
150 long x = event.GetX();
151 long y = event.GetY();
152
153 // reset the cursor
154 #ifdef __WXMOTIF__
155 SetCursor(* wxSTANDARD_CURSOR);
156 #endif
157 #ifdef __WXMSW__
158 SetCursor(wxCursor());
159 #endif
160
161 // under wxGTK the method above causes the mouse
162 // to flicker so we set the standard cursor only
163 // when leaving the window and when moving over
164 // non-sash parts of the window. this should work
165 // on the other platforms as well, but who knows.
166 #ifdef __WXGTK__
167 if (event.Leaving())
168 SetCursor(* wxSTANDARD_CURSOR);
169 #endif
170
171 if (event.LeftDown())
172 {
173 if ( SashHitTest(x, y) )
174 {
175 CaptureMouse();
176
177 m_dragMode = wxSPLIT_DRAG_DRAGGING;
178
179 DrawSashTracker(x, y);
180 m_oldX = x;
181 m_oldY = y;
182 return;
183 }
184 }
185 else if (event.LeftUp() && m_dragMode == wxSPLIT_DRAG_DRAGGING)
186 {
187 // We can stop dragging now and see what we've got.
188 m_dragMode = wxSPLIT_DRAG_NONE;
189 ReleaseMouse();
190
191 // Erase old tracker
192 DrawSashTracker(m_oldX, m_oldY);
193
194 // Obtain window size. We are only interested in the dimension the sash
195 // splits up
196 int w, h;
197 GetClientSize(&w, &h);
198 int window_size = (m_splitMode == wxSPLIT_VERTICAL ? w : h );
199 int new_sash_position =
200 (int) ( m_splitMode == wxSPLIT_VERTICAL ? x : y );
201
202 wxSplitterEvent eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED,
203 this);
204 eventSplitter.m_data.pos = new_sash_position;
205 if ( GetEventHandler()->ProcessEvent(eventSplitter) )
206 {
207 new_sash_position = eventSplitter.GetSashPosition();
208 if ( new_sash_position == -1 )
209 {
210 // change not allowed
211 return;
212 }
213 }
214
215 if ( new_sash_position == 0 )
216 {
217 // We remove the first window from the view
218 wxWindow *removedWindow = m_windowOne;
219 m_windowOne = m_windowTwo;
220 m_windowTwo = (wxWindow *) NULL;
221 SendUnsplitEvent(removedWindow);
222 m_sashPosition = 0;
223 }
224 else if ( new_sash_position == window_size )
225 {
226 // We remove the second window from the view
227 wxWindow *removedWindow = m_windowTwo;
228 m_windowTwo = (wxWindow *) NULL;
229 SendUnsplitEvent(removedWindow);
230 m_sashPosition = 0;
231 }
232 else
233 {
234 m_sashPosition = new_sash_position;
235 }
236
237 SizeWindows();
238 } // left up && dragging
239 else if (event.Moving() && !event.Dragging())
240 {
241 // Just change the cursor if required
242 if ( SashHitTest(x, y) )
243 {
244 if ( m_splitMode == wxSPLIT_VERTICAL )
245 {
246 SetCursor(*m_sashCursorWE);
247 }
248 else
249 {
250 SetCursor(*m_sashCursorNS);
251 }
252 }
253 #ifdef __WXGTK__
254 else
255 {
256 // where else do we unset the cursor?
257 SetCursor(* wxSTANDARD_CURSOR);
258 }
259 #endif // __WXGTK__
260 }
261 else if (event.Dragging() && (m_dragMode == wxSPLIT_DRAG_DRAGGING))
262 {
263 // Erase old tracker
264 DrawSashTracker(m_oldX, m_oldY);
265
266 // Draw new one
267 DrawSashTracker(x, y);
268
269 m_oldX = x;
270 m_oldY = y;
271 }
272 else if ( event.LeftDClick() )
273 {
274 wxSplitterEvent eventSplitter(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED,
275 this);
276 eventSplitter.m_data.pt.x = x;
277 eventSplitter.m_data.pt.y = y;
278
279 (void)GetEventHandler()->ProcessEvent(eventSplitter);
280 }
281 }
282
283 void wxSplitterWindow::OnSize(wxSizeEvent& WXUNUSED(event))
284 {
285 int cw, ch;
286 GetClientSize( &cw, &ch );
287 if ( m_windowTwo )
288 {
289 if ( m_splitMode == wxSPLIT_VERTICAL )
290 {
291 if ( m_sashPosition >= (cw - 5) )
292 m_sashPosition = wxMax(10, cw - 40);
293 }
294 if ( m_splitMode == wxSPLIT_HORIZONTAL )
295 {
296 if ( m_sashPosition >= (ch - 5) )
297 m_sashPosition = wxMax(10, ch - 40);
298 }
299 }
300 SizeWindows();
301 }
302
303 bool wxSplitterWindow::SashHitTest(int x, int y, int tolerance)
304 {
305 if ( m_windowTwo == NULL || m_sashPosition == 0)
306 return FALSE; // No sash
307
308 if ( m_splitMode == wxSPLIT_VERTICAL )
309 {
310 if ( (x >= m_sashPosition - tolerance) && (x <= m_sashPosition + m_sashSize + tolerance) )
311 return TRUE;
312 else
313 return FALSE;
314 }
315 else
316 {
317 if ( (y >= (m_sashPosition- tolerance)) && (y <= (m_sashPosition + m_sashSize + tolerance)) )
318 return TRUE;
319 else
320 return FALSE;
321 }
322
323 return FALSE;
324 }
325
326 // Draw 3D effect borders
327 void wxSplitterWindow::DrawBorders(wxDC& dc)
328 {
329 int w, h;
330 GetClientSize(&w, &h);
331
332 if ( GetWindowStyleFlag() & wxSP_3D )
333 {
334 dc.SetPen(*m_mediumShadowPen);
335 dc.DrawLine(0, 0, w-1, 0);
336 dc.DrawLine(0, 0, 0, h - 1);
337
338 dc.SetPen(*m_darkShadowPen);
339 dc.DrawLine(1, 1, w-2, 1);
340 dc.DrawLine(1, 1, 1, h-2);
341
342 dc.SetPen(*m_hilightPen);
343 dc.DrawLine(0, h-1, w-1, h-1);
344 dc.DrawLine(w-1, 0, w-1, h); // Surely the maximum y pos. should be h - 1.
345 /// Anyway, h is required for MSW.
346
347 dc.SetPen(*m_lightShadowPen);
348 dc.DrawLine(w-2, 1, w-2, h-2); // Right hand side
349 dc.DrawLine(1, h-2, w-1, h-2); // Bottom
350 }
351 else if ( GetWindowStyleFlag() & wxSP_BORDER )
352 {
353 dc.SetBrush(*wxTRANSPARENT_BRUSH);
354 dc.SetPen(*wxBLACK_PEN);
355 dc.DrawRectangle(0, 0, w-1, h-1);
356 }
357
358 dc.SetPen(wxNullPen);
359 dc.SetBrush(wxNullBrush);
360 }
361
362 // Draw the sash
363 void wxSplitterWindow::DrawSash(wxDC& dc)
364 {
365 if ( m_sashPosition == 0 || !m_windowTwo)
366 return;
367
368 int w, h;
369 GetClientSize(&w, &h);
370
371 if ( GetWindowStyleFlag() & wxSP_3D )
372 {
373 if ( m_splitMode == wxSPLIT_VERTICAL )
374 {
375 dc.SetPen(*m_facePen);
376 dc.SetBrush(*m_faceBrush);
377 dc.DrawRectangle(m_sashPosition + 2, 0, m_sashSize - 4, h);
378
379 dc.SetBrush(*wxTRANSPARENT_BRUSH);
380
381 dc.SetPen(*m_lightShadowPen);
382 dc.DrawLine(m_sashPosition, 1, m_sashPosition, h-2);
383
384 dc.SetPen(*m_hilightPen);
385 dc.DrawLine(m_sashPosition+1, 0, m_sashPosition+1, h);
386
387 dc.SetPen(*m_mediumShadowPen);
388 dc.DrawLine(m_sashPosition+m_sashSize-2, 1, m_sashPosition+m_sashSize-2, h-1);
389
390 dc.SetPen(*m_darkShadowPen);
391 dc.DrawLine(m_sashPosition+m_sashSize-1, 2, m_sashPosition+m_sashSize-1, h-2);
392 }
393 else
394 {
395 dc.SetPen(*m_facePen);
396 dc.SetBrush(*m_faceBrush);
397 dc.DrawRectangle(0, m_sashPosition + 2, w, m_sashSize - 4);
398
399 dc.SetBrush(*wxTRANSPARENT_BRUSH);
400
401 dc.SetPen(*m_lightShadowPen);
402 dc.DrawLine(1, m_sashPosition, w-2, m_sashPosition);
403
404 dc.SetPen(*m_hilightPen);
405 dc.DrawLine(0, m_sashPosition+1, w, m_sashPosition+1);
406
407 dc.SetPen(*m_mediumShadowPen);
408 dc.DrawLine(1, m_sashPosition+m_sashSize-2, w-1, m_sashPosition+m_sashSize-2);
409
410 dc.SetPen(*m_darkShadowPen);
411 dc.DrawLine(2, m_sashPosition+m_sashSize-1, w-2, m_sashPosition+m_sashSize-1);
412 }
413 }
414 else
415 {
416 if ( m_splitMode == wxSPLIT_VERTICAL )
417 {
418 dc.SetPen(*wxBLACK_PEN);
419 dc.SetBrush(*wxBLACK_BRUSH);
420 int h1 = h-1;
421 if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER )
422 h1 += 1; // Not sure why this is necessary...
423 dc.DrawRectangle(m_sashPosition, 0, m_sashSize, h1);
424 }
425 else
426 {
427 dc.SetPen(*wxBLACK_PEN);
428 dc.SetBrush(*wxBLACK_BRUSH);
429 int w1 = w-1;
430 if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER )
431 w1 ++;
432
433 dc.DrawRectangle(0, m_sashPosition, w1, m_sashSize);
434 }
435
436 }
437
438 dc.SetPen(wxNullPen);
439 dc.SetBrush(wxNullBrush);
440 }
441
442 // Draw the sash tracker (for whilst moving the sash)
443 void wxSplitterWindow::DrawSashTracker(int x, int y)
444 {
445 int w, h;
446 GetClientSize(&w, &h);
447
448 wxScreenDC screenDC;
449 int x1, y1;
450 int x2, y2;
451
452 if ( m_splitMode == wxSPLIT_VERTICAL )
453 {
454 x1 = x; y1 = 2;
455 x2 = x; y2 = h-2;
456
457 if ( x1 > w )
458 {
459 x1 = w; x2 = w;
460 }
461 else if ( x1 < 0 )
462 {
463 x1 = 0; x2 = 0;
464 }
465 }
466 else
467 {
468 x1 = 2; y1 = y;
469 x2 = w-2; y2 = y;
470
471 if ( y1 > h )
472 {
473 y1 = h;
474 y2 = h;
475 }
476 else if ( y1 < 0 )
477 {
478 y1 = 0;
479 y2 = 0;
480 }
481 }
482
483 ClientToScreen(&x1, &y1);
484 ClientToScreen(&x2, &y2);
485
486 screenDC.SetLogicalFunction(wxXOR);
487 screenDC.SetPen(*m_sashTrackerPen);
488 screenDC.SetBrush(*wxTRANSPARENT_BRUSH);
489
490 screenDC.DrawLine(x1, y1, x2, y2);
491
492 screenDC.SetLogicalFunction(wxCOPY);
493
494 screenDC.SetPen(wxNullPen);
495 screenDC.SetBrush(wxNullBrush);
496 }
497
498 // Position and size subwindows.
499 // Note that the border size applies to each subwindow, not
500 // including the edges next to the sash.
501 void wxSplitterWindow::SizeWindows()
502 {
503 int w, h;
504 GetClientSize(&w, &h);
505
506 if ( m_windowOne && !m_windowTwo )
507 {
508 m_windowOne->SetSize(m_borderSize, m_borderSize, w - 2*m_borderSize, h - 2*m_borderSize);
509
510 if (m_windowOne->GetAutoLayout())
511 m_windowOne->Layout();
512 }
513 else if ( m_windowOne && m_windowTwo )
514 {
515 if (m_splitMode == wxSPLIT_VERTICAL)
516 {
517 int x1 = m_borderSize;
518 int y1 = m_borderSize;
519 int w1 = m_sashPosition - m_borderSize;
520 int h1 = h - 2*m_borderSize;
521
522 int x2 = m_sashPosition + m_sashSize;
523 int y2 = m_borderSize;
524 int w2 = w - 2*m_borderSize - m_sashSize - w1;
525 int h2 = h - 2*m_borderSize;
526
527 m_windowOne->SetSize(x1, y1, w1, h1);
528 m_windowTwo->SetSize(x2, y2, w2, h2);
529
530 if (m_windowOne->GetAutoLayout())
531 m_windowOne->Layout();
532 if (m_windowTwo->GetAutoLayout())
533 m_windowTwo->Layout();
534 }
535 else
536 {
537 m_windowOne->SetSize(m_borderSize, m_borderSize,
538 w - 2*m_borderSize, m_sashPosition - m_borderSize);
539 m_windowTwo->SetSize(m_borderSize, m_sashPosition + m_sashSize,
540 w - 2*m_borderSize, h - 2*m_borderSize - m_sashSize - (m_sashPosition - m_borderSize));
541
542 if (m_windowOne->GetAutoLayout())
543 m_windowOne->Layout();
544 if (m_windowTwo->GetAutoLayout())
545 m_windowTwo->Layout();
546 }
547 }
548 wxClientDC dc(this);
549 DrawBorders(dc);
550 DrawSash(dc);
551 }
552
553 // Set pane for unsplit window
554 void wxSplitterWindow::Initialize(wxWindow *window)
555 {
556 m_windowOne = window;
557 m_windowTwo = (wxWindow *) NULL;
558 m_sashPosition = 0;
559 }
560
561 // Associates the given window with window 2, drawing the appropriate sash
562 // and changing the split mode.
563 // Does nothing and returns FALSE if the window is already split.
564 bool wxSplitterWindow::SplitVertically(wxWindow *window1, wxWindow *window2, int sashPosition)
565 {
566 if ( IsSplit() )
567 return FALSE;
568
569 int w, h;
570 GetClientSize(&w, &h);
571
572 m_splitMode = wxSPLIT_VERTICAL;
573 m_windowOne = window1;
574 m_windowTwo = window2;
575 if ( sashPosition > 0 )
576 m_sashPosition = sashPosition;
577 else if ( sashPosition < 0 )
578 m_sashPosition = w - sashPosition;
579 else // default
580 m_sashPosition = w/2;
581
582 SizeWindows();
583
584 return TRUE;
585 }
586
587 bool wxSplitterWindow::SplitHorizontally(wxWindow *window1, wxWindow *window2, int sashPosition)
588 {
589 if ( IsSplit() )
590 return FALSE;
591
592 int w, h;
593 GetClientSize(&w, &h);
594
595 m_splitMode = wxSPLIT_HORIZONTAL;
596 m_windowOne = window1;
597 m_windowTwo = window2;
598 if ( sashPosition > 0 )
599 m_sashPosition = sashPosition;
600 else if ( sashPosition < 0 )
601 m_sashPosition = h - sashPosition;
602 else // default
603 m_sashPosition = h/2;
604
605 SizeWindows();
606
607 return TRUE;
608 }
609
610
611 // Remove the specified (or second) window from the view
612 // Doesn't actually delete the window.
613 bool wxSplitterWindow::Unsplit(wxWindow *toRemove)
614 {
615 if ( ! IsSplit() )
616 return FALSE;
617
618 wxWindow *win = NULL;
619 if ( toRemove == NULL || toRemove == m_windowTwo)
620 {
621 win = m_windowTwo ;
622 m_windowTwo = (wxWindow *) NULL;
623 }
624 else if ( toRemove == m_windowOne )
625 {
626 win = m_windowOne ;
627 m_windowOne = m_windowTwo;
628 m_windowTwo = (wxWindow *) NULL;
629 }
630 else
631 {
632 wxFAIL_MSG(_T("splitter: attempt to remove a non-existent window"));
633
634 return FALSE;
635 }
636
637 SendUnsplitEvent(win);
638 m_sashPosition = 0;
639 SizeWindows();
640
641 return TRUE;
642 }
643
644 // Replace a window with another one
645 bool wxSplitterWindow::ReplaceWindow(wxWindow *winOld, wxWindow *winNew)
646 {
647 wxCHECK_MSG( winOld, FALSE, _T("use one of Split() functions instead") );
648 wxCHECK_MSG( winNew, FALSE, _T("use Unsplit() functions instead") );
649
650 if ( winOld == m_windowTwo )
651 {
652 m_windowTwo = winNew;
653 }
654 else if ( winOld == m_windowOne )
655 {
656 m_windowOne = winNew;
657 }
658 else
659 {
660 wxFAIL_MSG(_T("splitter: attempt to replace a non-existent window"));
661
662 return FALSE;
663 }
664
665 SizeWindows();
666
667 return TRUE;
668 }
669
670 void wxSplitterWindow::SetSashPosition(int position, bool redraw)
671 {
672 m_sashPosition = position;
673
674 if ( redraw )
675 {
676 SizeWindows();
677 }
678 }
679
680 // Initialize colours
681 void wxSplitterWindow::InitColours()
682 {
683 wxDELETE( m_facePen );
684 wxDELETE( m_faceBrush );
685 wxDELETE( m_mediumShadowPen );
686 wxDELETE( m_darkShadowPen );
687 wxDELETE( m_lightShadowPen );
688 wxDELETE( m_hilightPen );
689
690 // Shadow colours
691 #if defined(__WIN95__)
692 wxColour faceColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
693 m_facePen = new wxPen(faceColour, 1, wxSOLID);
694 m_faceBrush = new wxBrush(faceColour, wxSOLID);
695
696 wxColour mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW));
697 m_mediumShadowPen = new wxPen(mediumShadowColour, 1, wxSOLID);
698
699 wxColour darkShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DDKSHADOW));
700 m_darkShadowPen = new wxPen(darkShadowColour, 1, wxSOLID);
701
702 wxColour lightShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT));
703 m_lightShadowPen = new wxPen(lightShadowColour, 1, wxSOLID);
704
705 wxColour hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT));
706 m_hilightPen = new wxPen(hilightColour, 1, wxSOLID);
707 #else // !Win32
708 m_facePen = new wxPen("LIGHT GREY", 1, wxSOLID);
709 m_faceBrush = new wxBrush("LIGHT GREY", wxSOLID);
710 m_mediumShadowPen = new wxPen("GREY", 1, wxSOLID);
711 m_darkShadowPen = new wxPen("BLACK", 1, wxSOLID);
712 m_lightShadowPen = new wxPen("LIGHT GREY", 1, wxSOLID);
713 m_hilightPen = new wxPen("WHITE", 1, wxSOLID);
714 #endif // Win32/!Win32
715 }
716
717 void wxSplitterWindow::SendUnsplitEvent(wxWindow *winRemoved)
718 {
719 wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
720 event.m_data.win = winRemoved;
721
722 (void)GetEventHandler()->ProcessEvent(event);
723 }
724
725 // ---------------------------------------------------------------------------
726 // splitter event handlers
727 // ---------------------------------------------------------------------------
728
729 void wxSplitterWindow::OnSashPosChanged(wxSplitterEvent& event)
730 {
731 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
732 const int UNSPLIT_THRESHOLD = 4;
733
734 int newSashPosition = event.GetSashPosition();
735
736 // Obtain relevant window dimension for bottom / right threshold check
737 int w, h;
738 GetClientSize(&w, &h);
739 int window_size = (m_splitMode == wxSPLIT_VERTICAL) ? w : h ;
740
741 if ( newSashPosition <= UNSPLIT_THRESHOLD )
742 {
743 // threshold top / left check
744 newSashPosition = 0;
745 }
746 else if ( newSashPosition >= window_size - UNSPLIT_THRESHOLD )
747 {
748 // threshold bottom/right check
749 newSashPosition = window_size;
750 }
751
752 // If resultant pane would be too small, enlarge it.
753
754 // Check upper / left pane
755 if ( newSashPosition < m_minimumPaneSize )
756 newSashPosition = m_minimumPaneSize;
757
758 // Check lower / right pane (check even if sash was just adjusted)
759 if ( newSashPosition > window_size - m_minimumPaneSize )
760 newSashPosition = window_size - m_minimumPaneSize;
761
762 // If the result is out of bounds it means minimum size is too big,
763 // so split window in half as best compromise.
764 if ( newSashPosition < 0 || newSashPosition > window_size )
765 newSashPosition = window_size / 2;
766
767 // for compatibility, call the virtual function
768 if ( !OnSashPositionChange(newSashPosition) )
769 {
770 newSashPosition = -1;
771 }
772
773 event.SetSashPosition(newSashPosition);
774 }
775
776 // Called when the sash is double-clicked. The default behaviour is to remove
777 // the sash if the minimum pane size is zero.
778 void wxSplitterWindow::OnDoubleClick(wxSplitterEvent& event)
779 {
780 // for compatibility, call the virtual function
781 OnDoubleClickSash(event.GetX(), event.GetY());
782
783 if ( GetMinimumPaneSize() == 0 )
784 {
785 Unsplit();
786 }
787 }
788
789 void wxSplitterWindow::OnUnsplitEvent(wxSplitterEvent& event)
790 {
791 wxWindow *win = event.GetWindowBeingRemoved();
792
793 // for compatibility, call the virtual function
794 OnUnsplit(win);
795
796 win->Show(FALSE);
797 }