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