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