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