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