]> git.saurik.com Git - wxWidgets.git/blame - src/generic/splitter.cpp
setting parameters for wxGridCellFloatRenderer seems to work
[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
2f073eb2
RR
24 #include "wx/window.h"
25 #include "wx/dialog.h"
26 #include "wx/frame.h"
c801d85f
KB
27#endif
28
c801d85f
KB
29#include <stdlib.h>
30
31#include "wx/string.h"
32#include "wx/splitter.h"
33#include "wx/dcscreen.h"
1a7f3062 34#include "wx/settings.h"
c801d85f 35
c801d85f 36IMPLEMENT_DYNAMIC_CLASS(wxSplitterWindow, wxWindow)
42e69d6b 37IMPLEMENT_DYNAMIC_CLASS(wxSplitterEvent, wxCommandEvent)
c801d85f
KB
38
39BEGIN_EVENT_TABLE(wxSplitterWindow, wxWindow)
40 EVT_PAINT(wxSplitterWindow::OnPaint)
41 EVT_SIZE(wxSplitterWindow::OnSize)
72195a0f 42 EVT_IDLE(wxSplitterWindow::OnIdle)
c801d85f 43 EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent)
42e69d6b
VZ
44
45 EVT_SPLITTER_SASH_POS_CHANGED(-1, wxSplitterWindow::OnSashPosChanged)
370938d9
UB
46 // NB: we borrow OnSashPosChanged for purposes of
47 // EVT_SPLITTER_SASH_POS_CHANGING since default implementation is identical
48 EVT_SPLITTER_SASH_POS_CHANGING(-1, wxSplitterWindow::OnSashPosChanged)
42e69d6b
VZ
49 EVT_SPLITTER_DCLICK(-1, wxSplitterWindow::OnDoubleClick)
50 EVT_SPLITTER_UNSPLIT(-1, wxSplitterWindow::OnUnsplitEvent)
c801d85f 51END_EVENT_TABLE()
c801d85f 52
0d559d69 53wxSplitterWindow::wxSplitterWindow()
c801d85f
KB
54{
55 m_splitMode = wxSPLIT_VERTICAL;
370938d9 56 m_permitUnsplitAlways = FALSE;
c67daf87
UR
57 m_windowOne = (wxWindow *) NULL;
58 m_windowTwo = (wxWindow *) NULL;
c801d85f
KB
59 m_dragMode = wxSPLIT_DRAG_NONE;
60 m_oldX = 0;
61 m_oldY = 0;
62 m_firstX = 0;
63 m_firstY = 0;
64 m_sashSize = 7;
65 m_borderSize = 2;
66 m_sashPosition = 0;
c67daf87
UR
67 m_sashCursorWE = (wxCursor *) NULL;
68 m_sashCursorNS = (wxCursor *) NULL;
69 m_sashTrackerPen = (wxPen *) NULL;
70 m_lightShadowPen = (wxPen *) NULL;
71 m_mediumShadowPen = (wxPen *) NULL;
72 m_darkShadowPen = (wxPen *) NULL;
73 m_faceBrush = (wxBrush *) NULL;
74 m_facePen = (wxPen *) NULL;
75 m_hilightPen = (wxPen *) NULL;
c801d85f 76 m_minimumPaneSize = 0;
72195a0f 77 m_needUpdating = FALSE;
c801d85f
KB
78}
79
0d559d69
VZ
80wxSplitterWindow::wxSplitterWindow(wxWindow *parent, wxWindowID id,
81 const wxPoint& pos,
82 const wxSize& size,
83 long style,
84 const wxString& name)
85 : wxWindow(parent, id, pos, size, style, name)
c801d85f
KB
86{
87 m_splitMode = wxSPLIT_VERTICAL;
370938d9 88 m_permitUnsplitAlways = (style & wxSP_PERMIT_UNSPLIT) != 0;
c67daf87
UR
89 m_windowOne = (wxWindow *) NULL;
90 m_windowTwo = (wxWindow *) NULL;
c801d85f
KB
91 m_dragMode = wxSPLIT_DRAG_NONE;
92 m_oldX = 0;
93 m_oldY = 0;
94 m_firstX = 0;
95 m_firstY = 0;
96 m_sashSize = 7;
97 m_borderSize = 2;
98 m_sashPosition = 0;
99 m_minimumPaneSize = 0;
100 m_sashCursorWE = new wxCursor(wxCURSOR_SIZEWE);
101 m_sashCursorNS = new wxCursor(wxCURSOR_SIZENS);
102 m_sashTrackerPen = new wxPen(*wxBLACK, 2, wxSOLID);
c67daf87
UR
103 m_lightShadowPen = (wxPen *) NULL;
104 m_mediumShadowPen = (wxPen *) NULL;
105 m_darkShadowPen = (wxPen *) NULL;
106 m_faceBrush = (wxBrush *) NULL;
107 m_facePen = (wxPen *) NULL;
108 m_hilightPen = (wxPen *) NULL;
c801d85f
KB
109
110 if ( style & wxSP_3D )
111 {
112 m_borderSize = 2;
113 m_sashSize = 7;
114 }
115 else if ( style & wxSP_BORDER )
116 {
117 m_borderSize = 1;
118 m_sashSize = 3;
119 }
120 else
121 {
122 m_borderSize = 0;
123 m_sashSize = 3;
124 }
125
126 // Eventually, we'll respond to colour change messages
127 InitColours();
128
c801d85f
KB
129 // For debugging purposes, to see the background.
130// SetBackground(wxBLUE_BRUSH);
72195a0f
RR
131
132 m_needUpdating = FALSE;
c801d85f
KB
133}
134
0d559d69 135wxSplitterWindow::~wxSplitterWindow()
c801d85f
KB
136{
137 delete m_sashCursorWE;
138 delete m_sashCursorNS;
139 delete m_sashTrackerPen;
140 delete m_lightShadowPen;
141 delete m_darkShadowPen;
142 delete m_mediumShadowPen;
143 delete m_hilightPen;
144 delete m_facePen;
145 delete m_faceBrush;
146}
147
148void wxSplitterWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
149{
150 wxPaintDC dc(this);
151
152 if ( m_borderSize > 0 )
153 DrawBorders(dc);
154 DrawSash(dc);
155}
156
72195a0f
RR
157void wxSplitterWindow::OnIdle(wxIdleEvent& WXUNUSED(event))
158{
159 if (m_needUpdating)
160 SizeWindows();
161}
4c013092 162
c801d85f
KB
163void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
164{
6f2a55e3
VZ
165 wxCoord x = (wxCoord)event.GetX(),
166 y = (wxCoord)event.GetY();
c801d85f 167
f4621a09 168 // reset the cursor
b69f1bd1
JS
169#ifdef __WXMOTIF__
170 SetCursor(* wxSTANDARD_CURSOR);
17867d61
RR
171#endif
172#ifdef __WXMSW__
f4621a09 173 SetCursor(wxCursor());
b69f1bd1 174#endif
f4621a09 175
58d1c1ae 176
0d559d69
VZ
177 if (event.LeftDown())
178 {
c801d85f
KB
179 if ( SashHitTest(x, y) )
180 {
0d559d69 181 CaptureMouse();
c801d85f 182
4a33eba6 183 m_dragMode = wxSPLIT_DRAG_DRAGGING;
f4621a09 184
72195a0f 185 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE) == 0)
4419ba31
VZ
186 {
187 DrawSashTracker(x, y);
188 }
a6aa9b1e 189
4a33eba6
RR
190 m_oldX = x;
191 m_oldY = y;
9f334bea
JS
192
193 if ( m_splitMode == wxSPLIT_VERTICAL )
194 {
195 SetCursor(*m_sashCursorWE);
196 }
197 else
198 {
199 SetCursor(*m_sashCursorNS);
200 }
f4621a09 201 return;
c801d85f 202 }
0d559d69 203 }
0d559d69
VZ
204 else if (event.LeftUp() && m_dragMode == wxSPLIT_DRAG_DRAGGING)
205 {
c801d85f
KB
206 // We can stop dragging now and see what we've got.
207 m_dragMode = wxSPLIT_DRAG_NONE;
0d559d69 208 ReleaseMouse();
dbc208e9 209
c801d85f 210 // Erase old tracker
72195a0f 211 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE) == 0)
4419ba31 212 {
72195a0f 213 DrawSashTracker(m_oldX, m_oldY);
4419ba31 214 }
c801d85f 215
4c013092
UB
216 // Obtain window size. We are only interested in the dimension the sash
217 // splits up
c801d85f 218 int w, h;
0d559d69 219 GetClientSize(&w, &h);
4c013092
UB
220 int window_size = (m_splitMode == wxSPLIT_VERTICAL ? w : h );
221 int new_sash_position =
222 (int) ( m_splitMode == wxSPLIT_VERTICAL ? x : y );
223
42e69d6b
VZ
224 wxSplitterEvent eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED,
225 this);
226 eventSplitter.m_data.pos = new_sash_position;
227 if ( GetEventHandler()->ProcessEvent(eventSplitter) )
228 {
229 new_sash_position = eventSplitter.GetSashPosition();
230 if ( new_sash_position == -1 )
231 {
232 // change not allowed
233 return;
234 }
235 }
4c013092 236
370938d9
UB
237 if ( m_permitUnsplitAlways
238 || m_minimumPaneSize == 0 )
4c013092 239 {
370938d9
UB
240 // Deal with possible unsplit scenarios
241 if ( new_sash_position == 0 )
242 {
243 // We remove the first window from the view
244 wxWindow *removedWindow = m_windowOne;
245 m_windowOne = m_windowTwo;
246 m_windowTwo = (wxWindow *) NULL;
247 SendUnsplitEvent(removedWindow);
248 m_sashPosition = 0;
249 }
250 else if ( new_sash_position == window_size )
251 {
252 // We remove the second window from the view
253 wxWindow *removedWindow = m_windowTwo;
254 m_windowTwo = (wxWindow *) NULL;
255 SendUnsplitEvent(removedWindow);
256 m_sashPosition = 0;
257 }
258 else
259 {
260 m_sashPosition = new_sash_position;
261 }
c801d85f 262 }
4c013092 263 else
c801d85f 264 {
4c013092
UB
265 m_sashPosition = new_sash_position;
266 }
42e69d6b 267
c801d85f 268 SizeWindows();
4a33eba6 269 } // left up && dragging
0d559d69
VZ
270 else if (event.Moving() && !event.Dragging())
271 {
c801d85f
KB
272 // Just change the cursor if required
273 if ( SashHitTest(x, y) )
274 {
0d559d69 275 if ( m_splitMode == wxSPLIT_VERTICAL )
c801d85f 276 {
0d559d69 277 SetCursor(*m_sashCursorWE);
c801d85f
KB
278 }
279 else
280 {
0d559d69 281 SetCursor(*m_sashCursorNS);
c801d85f
KB
282 }
283 }
58d1c1ae
RR
284#ifdef __WXGTK__
285 else
42e69d6b
VZ
286 {
287 // where else do we unset the cursor?
58d1c1ae 288 SetCursor(* wxSTANDARD_CURSOR);
42e69d6b
VZ
289 }
290#endif // __WXGTK__
0d559d69 291 }
a6aa9b1e 292 else if (event.Dragging() && (m_dragMode == wxSPLIT_DRAG_DRAGGING))
0d559d69 293 {
9f334bea
JS
294#ifdef __WXMSW__
295 // Otherwise, the cursor sometimes reverts to the normal cursor
296 // during dragging.
297 if ( m_splitMode == wxSPLIT_VERTICAL )
298 {
299 SetCursor(*m_sashCursorWE);
300 }
301 else
302 {
303 SetCursor(*m_sashCursorNS);
304 }
305#endif
306
370938d9
UB
307 // Obtain window size. We are only interested in the dimension the sash
308 // splits up
309 int new_sash_position =
310 (int) ( m_splitMode == wxSPLIT_VERTICAL ? x : y );
311
312 wxSplitterEvent eventSplitter(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING,
313 this);
314 eventSplitter.m_data.pos = new_sash_position;
315 if ( GetEventHandler()->ProcessEvent(eventSplitter) )
316 {
317 new_sash_position = eventSplitter.GetSashPosition();
318 if ( new_sash_position == -1 )
319 {
320 // change not allowed
321 return;
322 }
323 }
324
4a33eba6 325 // Erase old tracker
72195a0f 326 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE) == 0)
4419ba31 327 {
72195a0f 328 DrawSashTracker(m_oldX, m_oldY);
4419ba31 329 }
c801d85f 330
370938d9
UB
331 if (m_splitMode == wxSPLIT_VERTICAL)
332 x = new_sash_position;
333 else
334 y = new_sash_position;
335
336 if (new_sash_position != -1)
337 {
338 // Only modify if permitted
339 m_oldX = x;
340 m_oldY = y;
341 }
342
d66a042c
VZ
343#ifdef __WXMSW__
344 // As we captured the mouse, we may get the mouse events from outside
345 // our window - for example, negative values in x, y. This has a weird
346 // consequence under MSW where we use unsigned values sometimes and
347 // signed ones other times: the coordinates turn as big positive
348 // numbers and so the sash is drawn on the *right* side of the window
349 // instead of the left (or bottom instead of top). Correct this.
d66a042c
VZ
350 if ( (short)m_oldX < 0 )
351 m_oldX = 0;
352 if ( (short)m_oldY < 0 )
353 m_oldY = 0;
354#endif // __WXMSW__
355
356 // Draw new one
72195a0f 357 if ((GetWindowStyleFlag() & wxSP_LIVE_UPDATE) == 0)
4419ba31 358 {
72195a0f 359 DrawSashTracker(m_oldX, m_oldY);
4419ba31
VZ
360 }
361 else
362 {
72195a0f 363 m_sashPosition = new_sash_position;
4419ba31
VZ
364 m_needUpdating = TRUE;
365 }
0d559d69 366 }
c801d85f
KB
367 else if ( event.LeftDClick() )
368 {
42e69d6b
VZ
369 wxSplitterEvent eventSplitter(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED,
370 this);
371 eventSplitter.m_data.pt.x = x;
372 eventSplitter.m_data.pt.y = y;
373
374 (void)GetEventHandler()->ProcessEvent(eventSplitter);
c801d85f 375 }
c801d85f
KB
376}
377
a8731351 378void wxSplitterWindow::OnSize(wxSizeEvent& event)
c801d85f 379{
a8731351
VZ
380 // only process this message if we're not iconized - otherwise iconizing
381 // and restoring a window containing the splitter has a funny side effect
382 // of changing the splitter position!
383 wxWindow *parent = GetParent();
384 while ( parent && !parent->IsTopLevel() )
c801d85f 385 {
a8731351
VZ
386 parent = parent->GetParent();
387 }
388
58c7cd12 389 bool iconized = FALSE;
a8731351
VZ
390 wxFrame *frame = wxDynamicCast(parent, wxFrame);
391 if ( frame )
392 iconized = frame->IsIconized();
393 else
394 {
395 wxDialog *dialog = wxDynamicCast(parent, wxDialog);
396 if ( dialog )
397 iconized = dialog->IsIconized();
398 else
223d09f6 399 wxFAIL_MSG(wxT("should have a top level frame or dialog parent!"));
a8731351
VZ
400 }
401
402 if ( iconized )
403 {
404 event.Skip();
405 }
406 else
407 {
408 int cw, ch;
409 GetClientSize( &cw, &ch );
410 if ( m_windowTwo )
c801d85f 411 {
a8731351
VZ
412 if ( m_splitMode == wxSPLIT_VERTICAL )
413 {
414 if ( m_sashPosition >= (cw - 5) )
415 m_sashPosition = wxMax(10, cw - 40);
416 }
417 if ( m_splitMode == wxSPLIT_HORIZONTAL )
418 {
419 if ( m_sashPosition >= (ch - 5) )
420 m_sashPosition = wxMax(10, ch - 40);
421 }
c801d85f 422 }
a8731351
VZ
423
424 SizeWindows();
c801d85f 425 }
c801d85f
KB
426}
427
debe6624 428bool wxSplitterWindow::SashHitTest(int x, int y, int tolerance)
c801d85f
KB
429{
430 if ( m_windowTwo == NULL || m_sashPosition == 0)
431 return FALSE; // No sash
432
433 if ( m_splitMode == wxSPLIT_VERTICAL )
434 {
435 if ( (x >= m_sashPosition - tolerance) && (x <= m_sashPosition + m_sashSize + tolerance) )
436 return TRUE;
437 else
438 return FALSE;
439 }
440 else
441 {
442 if ( (y >= (m_sashPosition- tolerance)) && (y <= (m_sashPosition + m_sashSize + tolerance)) )
443 return TRUE;
444 else
445 return FALSE;
446 }
c801d85f
KB
447}
448
449// Draw 3D effect borders
450void wxSplitterWindow::DrawBorders(wxDC& dc)
451{
452 int w, h;
453 GetClientSize(&w, &h);
454
455 if ( GetWindowStyleFlag() & wxSP_3D )
456 {
a6aa9b1e 457
1e2c86ca
PA
458 dc.SetPen(*m_facePen);
459 dc.SetBrush(*m_faceBrush);
460 dc.DrawRectangle(1, 1 , w-1, m_borderSize-2 ); //high
461 dc.DrawRectangle(1, m_borderSize-2 , m_borderSize-2, h-1 ); // left
462 dc.DrawRectangle(w-m_borderSize+2, m_borderSize-2 , w-1, h-1 ); // right
463 dc.DrawRectangle(m_borderSize-2, h-m_borderSize+2 , w-m_borderSize+2, h-1 ); //bottom
464
c801d85f 465 dc.SetPen(*m_mediumShadowPen);
1e2c86ca
PA
466 dc.DrawLine(m_borderSize-2, m_borderSize-2, w-m_borderSize+1, m_borderSize-2);
467 dc.DrawLine(m_borderSize-2, m_borderSize-2, m_borderSize-2, h-m_borderSize+1);
c801d85f
KB
468
469 dc.SetPen(*m_darkShadowPen);
1e2c86ca
PA
470 dc.DrawLine(m_borderSize-1, m_borderSize-1, w-m_borderSize, m_borderSize-1);
471 dc.DrawLine(m_borderSize-1, m_borderSize-1, m_borderSize-1, h-m_borderSize);
c801d85f
KB
472
473 dc.SetPen(*m_hilightPen);
1e2c86ca
PA
474 dc.DrawLine(m_borderSize - 2, h-m_borderSize+1, w-m_borderSize+1, h-m_borderSize+1);
475 dc.DrawLine(w-m_borderSize+1, m_borderSize - 2, w-m_borderSize+1, h-m_borderSize+2); // Surely the maximum y pos. should be h - 1.
c801d85f
KB
476 /// Anyway, h is required for MSW.
477
478 dc.SetPen(*m_lightShadowPen);
1e2c86ca
PA
479 dc.DrawLine(w-m_borderSize, m_borderSize-1, w-m_borderSize, h-m_borderSize); // Right hand side
480 dc.DrawLine(m_borderSize-1, h-m_borderSize, w-m_borderSize+1, h-m_borderSize); // Bottom
c801d85f
KB
481 }
482 else if ( GetWindowStyleFlag() & wxSP_BORDER )
483 {
484 dc.SetBrush(*wxTRANSPARENT_BRUSH);
485 dc.SetPen(*wxBLACK_PEN);
486 dc.DrawRectangle(0, 0, w-1, h-1);
487 }
488
489 dc.SetPen(wxNullPen);
490 dc.SetBrush(wxNullBrush);
491}
492
493// Draw the sash
494void wxSplitterWindow::DrawSash(wxDC& dc)
495{
496 if ( m_sashPosition == 0 || !m_windowTwo)
497 return;
498
499 int w, h;
500 GetClientSize(&w, &h);
501
502 if ( GetWindowStyleFlag() & wxSP_3D )
503 {
504 if ( m_splitMode == wxSPLIT_VERTICAL )
505 {
506 dc.SetPen(*m_facePen);
507 dc.SetBrush(*m_faceBrush);
1e2c86ca 508 dc.DrawRectangle(m_sashPosition + 2, 0 , m_sashSize - 4, h );
c801d85f
KB
509
510 dc.SetBrush(*wxTRANSPARENT_BRUSH);
511
512 dc.SetPen(*m_lightShadowPen);
4419ba31 513 int xShadow = m_borderSize ? m_borderSize - 1 : 0 ;
1e2c86ca 514 dc.DrawLine(m_sashPosition, xShadow , m_sashPosition, h-m_borderSize);
c801d85f
KB
515
516 dc.SetPen(*m_hilightPen);
1e2c86ca 517 dc.DrawLine(m_sashPosition+1, m_borderSize - 2, m_sashPosition+1, h - m_borderSize+2);
c801d85f
KB
518
519 dc.SetPen(*m_mediumShadowPen);
4419ba31 520 int yMedium = m_borderSize ? h-m_borderSize+1 : h ;
1e2c86ca 521 dc.DrawLine(m_sashPosition+m_sashSize-2, xShadow, m_sashPosition+m_sashSize-2, yMedium);
c801d85f
KB
522
523 dc.SetPen(*m_darkShadowPen);
1e2c86ca 524 dc.DrawLine(m_sashPosition+m_sashSize-1, m_borderSize, m_sashPosition+m_sashSize-1, h-m_borderSize );
0d559d69 525 }
c801d85f
KB
526 else
527 {
528 dc.SetPen(*m_facePen);
529 dc.SetBrush(*m_faceBrush);
1e2c86ca 530 dc.DrawRectangle( m_borderSize-2, m_sashPosition + 2, w-m_borderSize+2, m_sashSize - 4);
c801d85f
KB
531
532 dc.SetBrush(*wxTRANSPARENT_BRUSH);
533
534 dc.SetPen(*m_lightShadowPen);
1e2c86ca 535 dc.DrawLine(m_borderSize-1, m_sashPosition, w-m_borderSize, m_sashPosition);
c801d85f
KB
536
537 dc.SetPen(*m_hilightPen);
1e2c86ca 538 dc.DrawLine(m_borderSize-2, m_sashPosition+1, w-m_borderSize+1, m_sashPosition+1);
c801d85f
KB
539
540 dc.SetPen(*m_mediumShadowPen);
1e2c86ca 541 dc.DrawLine(m_borderSize-1, m_sashPosition+m_sashSize-2, w-m_borderSize+1, m_sashPosition+m_sashSize-2);
c801d85f
KB
542
543 dc.SetPen(*m_darkShadowPen);
1e2c86ca 544 dc.DrawLine(m_borderSize, m_sashPosition+m_sashSize-1, w-m_borderSize, m_sashPosition+m_sashSize-1);
c801d85f
KB
545 }
546 }
547 else
548 {
549 if ( m_splitMode == wxSPLIT_VERTICAL )
550 {
551 dc.SetPen(*wxBLACK_PEN);
552 dc.SetBrush(*wxBLACK_BRUSH);
553 int h1 = h-1;
554 if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER )
555 h1 += 1; // Not sure why this is necessary...
556 dc.DrawRectangle(m_sashPosition, 0, m_sashSize, h1);
557 }
558 else
559 {
560 dc.SetPen(*wxBLACK_PEN);
561 dc.SetBrush(*wxBLACK_BRUSH);
562 int w1 = w-1;
563 if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER )
564 w1 ++;
565
566 dc.DrawRectangle(0, m_sashPosition, w1, m_sashSize);
567 }
568
569 }
570
571 dc.SetPen(wxNullPen);
572 dc.SetBrush(wxNullBrush);
573}
574
575// Draw the sash tracker (for whilst moving the sash)
debe6624 576void wxSplitterWindow::DrawSashTracker(int x, int y)
c801d85f
KB
577{
578 int w, h;
579 GetClientSize(&w, &h);
580
581 wxScreenDC screenDC;
582 int x1, y1;
583 int x2, y2;
584
585 if ( m_splitMode == wxSPLIT_VERTICAL )
586 {
587 x1 = x; y1 = 2;
588 x2 = x; y2 = h-2;
589
590 if ( x1 > w )
591 {
592 x1 = w; x2 = w;
593 }
594 else if ( x1 < 0 )
595 {
596 x1 = 0; x2 = 0;
597 }
598 }
599 else
600 {
601 x1 = 2; y1 = y;
602 x2 = w-2; y2 = y;
603
604 if ( y1 > h )
605 {
606 y1 = h;
607 y2 = h;
608 }
609 else if ( y1 < 0 )
610 {
611 y1 = 0;
612 y2 = 0;
613 }
614 }
615
616 ClientToScreen(&x1, &y1);
617 ClientToScreen(&x2, &y2);
618
3c679789 619 screenDC.SetLogicalFunction(wxINVERT);
c801d85f
KB
620 screenDC.SetPen(*m_sashTrackerPen);
621 screenDC.SetBrush(*wxTRANSPARENT_BRUSH);
622
623 screenDC.DrawLine(x1, y1, x2, y2);
624
625 screenDC.SetLogicalFunction(wxCOPY);
626
627 screenDC.SetPen(wxNullPen);
628 screenDC.SetBrush(wxNullBrush);
629}
630
631// Position and size subwindows.
632// Note that the border size applies to each subwindow, not
633// including the edges next to the sash.
0d559d69 634void wxSplitterWindow::SizeWindows()
c801d85f
KB
635{
636 int w, h;
637 GetClientSize(&w, &h);
638
639 if ( m_windowOne && !m_windowTwo )
640 {
641 m_windowOne->SetSize(m_borderSize, m_borderSize, w - 2*m_borderSize, h - 2*m_borderSize);
a6aa9b1e 642
c801d85f
KB
643 }
644 else if ( m_windowOne && m_windowTwo )
645 {
646 if (m_splitMode == wxSPLIT_VERTICAL)
647 {
648 int x1 = m_borderSize;
649 int y1 = m_borderSize;
650 int w1 = m_sashPosition - m_borderSize;
651 int h1 = h - 2*m_borderSize;
652
653 int x2 = m_sashPosition + m_sashSize;
654 int y2 = m_borderSize;
655 int w2 = w - 2*m_borderSize - m_sashSize - w1;
656 int h2 = h - 2*m_borderSize;
657
0d559d69
VZ
658 m_windowOne->SetSize(x1, y1, w1, h1);
659 m_windowTwo->SetSize(x2, y2, w2, h2);
a6aa9b1e 660
c801d85f
KB
661 }
662 else
663 {
664 m_windowOne->SetSize(m_borderSize, m_borderSize,
665 w - 2*m_borderSize, m_sashPosition - m_borderSize);
666 m_windowTwo->SetSize(m_borderSize, m_sashPosition + m_sashSize,
667 w - 2*m_borderSize, h - 2*m_borderSize - m_sashSize - (m_sashPosition - m_borderSize));
a6aa9b1e 668
c801d85f
KB
669 }
670 }
671 wxClientDC dc(this);
4419ba31
VZ
672 if ( m_borderSize > 0 )
673 DrawBorders(dc);
c801d85f
KB
674 DrawSash(dc);
675}
676
677// Set pane for unsplit window
678void wxSplitterWindow::Initialize(wxWindow *window)
679{
680 m_windowOne = window;
c67daf87 681 m_windowTwo = (wxWindow *) NULL;
c801d85f
KB
682 m_sashPosition = 0;
683}
684
685// Associates the given window with window 2, drawing the appropriate sash
686// and changing the split mode.
687// Does nothing and returns FALSE if the window is already split.
debe6624 688bool wxSplitterWindow::SplitVertically(wxWindow *window1, wxWindow *window2, int sashPosition)
c801d85f
KB
689{
690 if ( IsSplit() )
691 return FALSE;
692
0d559d69
VZ
693 int w, h;
694 GetClientSize(&w, &h);
695
c801d85f
KB
696 m_splitMode = wxSPLIT_VERTICAL;
697 m_windowOne = window1;
698 m_windowTwo = window2;
0d559d69 699 if ( sashPosition > 0 )
c801d85f 700 m_sashPosition = sashPosition;
0d559d69
VZ
701 else if ( sashPosition < 0 )
702 m_sashPosition = w - sashPosition;
703 else // default
704 m_sashPosition = w/2;
c801d85f
KB
705
706 SizeWindows();
707
708 return TRUE;
709}
710
debe6624 711bool wxSplitterWindow::SplitHorizontally(wxWindow *window1, wxWindow *window2, int sashPosition)
c801d85f
KB
712{
713 if ( IsSplit() )
714 return FALSE;
715
0d559d69
VZ
716 int w, h;
717 GetClientSize(&w, &h);
718
c801d85f
KB
719 m_splitMode = wxSPLIT_HORIZONTAL;
720 m_windowOne = window1;
721 m_windowTwo = window2;
0d559d69 722 if ( sashPosition > 0 )
c801d85f 723 m_sashPosition = sashPosition;
0d559d69
VZ
724 else if ( sashPosition < 0 )
725 m_sashPosition = h - sashPosition;
726 else // default
727 m_sashPosition = h/2;
c801d85f
KB
728
729 SizeWindows();
730
731 return TRUE;
732}
733
734
735// Remove the specified (or second) window from the view
736// Doesn't actually delete the window.
737bool wxSplitterWindow::Unsplit(wxWindow *toRemove)
738{
739 if ( ! IsSplit() )
740 return FALSE;
741
3ad5e06b 742 wxWindow *win = NULL;
c801d85f
KB
743 if ( toRemove == NULL || toRemove == m_windowTwo)
744 {
3ad5e06b 745 win = m_windowTwo ;
c67daf87 746 m_windowTwo = (wxWindow *) NULL;
c801d85f
KB
747 }
748 else if ( toRemove == m_windowOne )
749 {
3ad5e06b 750 win = m_windowOne ;
c801d85f 751 m_windowOne = m_windowTwo;
c67daf87 752 m_windowTwo = (wxWindow *) NULL;
c801d85f
KB
753 }
754 else
dbc208e9 755 {
223d09f6 756 wxFAIL_MSG(wxT("splitter: attempt to remove a non-existent window"));
dbc208e9 757
c801d85f 758 return FALSE;
dbc208e9 759 }
c801d85f 760
42e69d6b 761 SendUnsplitEvent(win);
3ad5e06b
VZ
762 m_sashPosition = 0;
763 SizeWindows();
764
765 return TRUE;
766}
767
768// Replace a window with another one
769bool wxSplitterWindow::ReplaceWindow(wxWindow *winOld, wxWindow *winNew)
770{
223d09f6
KB
771 wxCHECK_MSG( winOld, FALSE, wxT("use one of Split() functions instead") );
772 wxCHECK_MSG( winNew, FALSE, wxT("use Unsplit() functions instead") );
3ad5e06b
VZ
773
774 if ( winOld == m_windowTwo )
775 {
776 m_windowTwo = winNew;
777 }
778 else if ( winOld == m_windowOne )
779 {
780 m_windowOne = winNew;
781 }
782 else
783 {
223d09f6 784 wxFAIL_MSG(wxT("splitter: attempt to replace a non-existent window"));
3ad5e06b
VZ
785
786 return FALSE;
787 }
788
789 SizeWindows();
790
c801d85f
KB
791 return TRUE;
792}
793
debe6624 794void wxSplitterWindow::SetSashPosition(int position, bool redraw)
c801d85f
KB
795{
796 m_sashPosition = position;
797
798 if ( redraw )
799 {
800 SizeWindows();
801 }
802}
803
c801d85f 804// Initialize colours
0d559d69 805void wxSplitterWindow::InitColours()
c801d85f 806{
0d559d69
VZ
807 wxDELETE( m_facePen );
808 wxDELETE( m_faceBrush );
809 wxDELETE( m_mediumShadowPen );
810 wxDELETE( m_darkShadowPen );
811 wxDELETE( m_lightShadowPen );
812 wxDELETE( m_hilightPen );
c801d85f
KB
813
814 // Shadow colours
815#if defined(__WIN95__)
c801d85f
KB
816 wxColour faceColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
817 m_facePen = new wxPen(faceColour, 1, wxSOLID);
818 m_faceBrush = new wxBrush(faceColour, wxSOLID);
819
c801d85f
KB
820 wxColour mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW));
821 m_mediumShadowPen = new wxPen(mediumShadowColour, 1, wxSOLID);
822
c801d85f
KB
823 wxColour darkShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DDKSHADOW));
824 m_darkShadowPen = new wxPen(darkShadowColour, 1, wxSOLID);
825
c801d85f
KB
826 wxColour lightShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT));
827 m_lightShadowPen = new wxPen(lightShadowColour, 1, wxSOLID);
828
c801d85f
KB
829 wxColour hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT));
830 m_hilightPen = new wxPen(hilightColour, 1, wxSOLID);
0d559d69 831#else // !Win32
c801d85f
KB
832 m_facePen = new wxPen("LIGHT GREY", 1, wxSOLID);
833 m_faceBrush = new wxBrush("LIGHT GREY", wxSOLID);
834 m_mediumShadowPen = new wxPen("GREY", 1, wxSOLID);
835 m_darkShadowPen = new wxPen("BLACK", 1, wxSOLID);
836 m_lightShadowPen = new wxPen("LIGHT GREY", 1, wxSOLID);
837 m_hilightPen = new wxPen("WHITE", 1, wxSOLID);
0d559d69 838#endif // Win32/!Win32
c801d85f
KB
839}
840
42e69d6b
VZ
841void wxSplitterWindow::SendUnsplitEvent(wxWindow *winRemoved)
842{
843 wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
844 event.m_data.win = winRemoved;
845
846 (void)GetEventHandler()->ProcessEvent(event);
847}
848
849// ---------------------------------------------------------------------------
850// splitter event handlers
851// ---------------------------------------------------------------------------
852
853void wxSplitterWindow::OnSashPosChanged(wxSplitterEvent& event)
854{
855 // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
856 const int UNSPLIT_THRESHOLD = 4;
857
858 int newSashPosition = event.GetSashPosition();
859
860 // Obtain relevant window dimension for bottom / right threshold check
861 int w, h;
862 GetClientSize(&w, &h);
863 int window_size = (m_splitMode == wxSPLIT_VERTICAL) ? w : h ;
864
370938d9
UB
865 bool unsplit_scenario = FALSE;
866 if ( m_permitUnsplitAlways
867 || m_minimumPaneSize == 0 )
bc79aa6b 868 {
370938d9
UB
869 // Do edge detection if unsplit premitted
870 if ( newSashPosition <= UNSPLIT_THRESHOLD )
871 {
872 // threshold top / left check
873 newSashPosition = 0;
874 unsplit_scenario = TRUE;
875 }
876 if ( newSashPosition >= window_size - UNSPLIT_THRESHOLD )
877 {
878 // threshold bottom/right check
879 newSashPosition = window_size;
880 unsplit_scenario = TRUE;
881 }
bc79aa6b
UB
882 }
883
370938d9 884 if ( !unsplit_scenario )
bc79aa6b
UB
885 {
886 // If resultant pane would be too small, enlarge it
370938d9
UB
887 if ( newSashPosition < m_minimumPaneSize )
888 newSashPosition = m_minimumPaneSize;
889 if ( newSashPosition > window_size - m_minimumPaneSize )
890 newSashPosition = window_size - m_minimumPaneSize;
bc79aa6b 891 }
42e69d6b
VZ
892
893 // If the result is out of bounds it means minimum size is too big,
894 // so split window in half as best compromise.
895 if ( newSashPosition < 0 || newSashPosition > window_size )
896 newSashPosition = window_size / 2;
897
898 // for compatibility, call the virtual function
899 if ( !OnSashPositionChange(newSashPosition) )
900 {
901 newSashPosition = -1;
902 }
903
904 event.SetSashPosition(newSashPosition);
905}
906
907// Called when the sash is double-clicked. The default behaviour is to remove
908// the sash if the minimum pane size is zero.
909void wxSplitterWindow::OnDoubleClick(wxSplitterEvent& event)
910{
911 // for compatibility, call the virtual function
912 OnDoubleClickSash(event.GetX(), event.GetY());
913
4419ba31 914 if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways )
42e69d6b
VZ
915 {
916 Unsplit();
917 }
918}
919
920void wxSplitterWindow::OnUnsplitEvent(wxSplitterEvent& event)
921{
922 wxWindow *win = event.GetWindowBeingRemoved();
923
4419ba31
VZ
924 // do it before calling OnUnsplit() which may delete the window
925 win->Show(FALSE);
926
42e69d6b
VZ
927 // for compatibility, call the virtual function
928 OnUnsplit(win);
42e69d6b 929}