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