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