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