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