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