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