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