]>
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; | |
ca39e409 | 117 | m_sashPosition = m_requestedSashPosition = 0; |
c801d85f KB |
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); | |
ca39e409 | 250 | DoSetSashPosition(0); |
370938d9 UB |
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); | |
ca39e409 | 258 | DoSetSashPosition(0); |
370938d9 UB |
259 | } |
260 | else | |
261 | { | |
ca39e409 | 262 | DoSetSashPosition(new_sash_position); |
370938d9 | 263 | } |
c801d85f | 264 | } |
4c013092 | 265 | else |
c801d85f | 266 | { |
ca39e409 | 267 | DoSetSashPosition(new_sash_position); |
4c013092 | 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 | { | |
ca39e409 | 369 | DoSetSashPosition(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 | ||
642d2dc8 | 395 | bool iconized = FALSE; |
2e8cc3e8 | 396 | |
642d2dc8 JS |
397 | // wxMotif doesn't yet have a wxTopLevelWindow implementation |
398 | #ifdef __WXMOTIF__ | |
399 | wxFrame *winTop = wxDynamicCast(parent, wxFrame); | |
400 | #else | |
2e8cc3e8 | 401 | wxTopLevelWindow *winTop = wxDynamicCast(parent, wxTopLevelWindow); |
642d2dc8 | 402 | #endif |
2e8cc3e8 VZ |
403 | if ( winTop ) |
404 | { | |
405 | iconized = winTop->IsIconized(); | |
406 | } | |
642d2dc8 | 407 | #ifndef __WXMOTIF__ |
a8731351 VZ |
408 | else |
409 | { | |
2e8cc3e8 VZ |
410 | wxFAIL_MSG(wxT("should have a top level parent!")); |
411 | ||
412 | iconized = FALSE; | |
a8731351 | 413 | } |
642d2dc8 JS |
414 | #endif |
415 | ||
a8731351 VZ |
416 | if ( iconized ) |
417 | { | |
418 | event.Skip(); | |
2e8cc3e8 VZ |
419 | |
420 | return; | |
a8731351 | 421 | } |
2e8cc3e8 VZ |
422 | |
423 | int cw, ch; | |
424 | GetClientSize( &cw, &ch ); | |
425 | if ( m_windowTwo ) | |
a8731351 | 426 | { |
2e8cc3e8 | 427 | if ( m_splitMode == wxSPLIT_VERTICAL ) |
c801d85f | 428 | { |
2e8cc3e8 | 429 | if ( m_sashPosition >= (cw - 5) ) |
ca39e409 | 430 | DoSetSashPosition(wxMax(10, cw - 40)); |
2e8cc3e8 VZ |
431 | } |
432 | else // m_splitMode == wxSPLIT_HORIZONTAL | |
433 | { | |
434 | if ( m_sashPosition >= (ch - 5) ) | |
ca39e409 | 435 | DoSetSashPosition(wxMax(10, ch - 40)); |
c801d85f KB |
436 | } |
437 | } | |
2e8cc3e8 VZ |
438 | |
439 | SizeWindows(); | |
c801d85f KB |
440 | } |
441 | ||
debe6624 | 442 | bool wxSplitterWindow::SashHitTest(int x, int y, int tolerance) |
c801d85f KB |
443 | { |
444 | if ( m_windowTwo == NULL || m_sashPosition == 0) | |
445 | return FALSE; // No sash | |
446 | ||
447 | if ( m_splitMode == wxSPLIT_VERTICAL ) | |
448 | { | |
449 | if ( (x >= m_sashPosition - tolerance) && (x <= m_sashPosition + m_sashSize + tolerance) ) | |
450 | return TRUE; | |
451 | else | |
452 | return FALSE; | |
453 | } | |
454 | else | |
455 | { | |
456 | if ( (y >= (m_sashPosition- tolerance)) && (y <= (m_sashPosition + m_sashSize + tolerance)) ) | |
457 | return TRUE; | |
458 | else | |
459 | return FALSE; | |
460 | } | |
c801d85f KB |
461 | } |
462 | ||
463 | // Draw 3D effect borders | |
464 | void wxSplitterWindow::DrawBorders(wxDC& dc) | |
465 | { | |
466 | int w, h; | |
467 | GetClientSize(&w, &h); | |
468 | ||
f6bcfd97 | 469 | if ( GetWindowStyleFlag() & wxSP_3DBORDER ) |
c801d85f | 470 | { |
a6aa9b1e | 471 | |
1e2c86ca PA |
472 | dc.SetPen(*m_facePen); |
473 | dc.SetBrush(*m_faceBrush); | |
474 | dc.DrawRectangle(1, 1 , w-1, m_borderSize-2 ); //high | |
475 | dc.DrawRectangle(1, m_borderSize-2 , m_borderSize-2, h-1 ); // left | |
476 | dc.DrawRectangle(w-m_borderSize+2, m_borderSize-2 , w-1, h-1 ); // right | |
477 | dc.DrawRectangle(m_borderSize-2, h-m_borderSize+2 , w-m_borderSize+2, h-1 ); //bottom | |
478 | ||
c801d85f | 479 | dc.SetPen(*m_mediumShadowPen); |
1e2c86ca PA |
480 | dc.DrawLine(m_borderSize-2, m_borderSize-2, w-m_borderSize+1, m_borderSize-2); |
481 | dc.DrawLine(m_borderSize-2, m_borderSize-2, m_borderSize-2, h-m_borderSize+1); | |
c801d85f KB |
482 | |
483 | dc.SetPen(*m_darkShadowPen); | |
1e2c86ca PA |
484 | dc.DrawLine(m_borderSize-1, m_borderSize-1, w-m_borderSize, m_borderSize-1); |
485 | dc.DrawLine(m_borderSize-1, m_borderSize-1, m_borderSize-1, h-m_borderSize); | |
c801d85f KB |
486 | |
487 | dc.SetPen(*m_hilightPen); | |
1e2c86ca PA |
488 | dc.DrawLine(m_borderSize - 2, h-m_borderSize+1, w-m_borderSize+1, h-m_borderSize+1); |
489 | 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 |
490 | /// Anyway, h is required for MSW. |
491 | ||
492 | dc.SetPen(*m_lightShadowPen); | |
1e2c86ca PA |
493 | dc.DrawLine(w-m_borderSize, m_borderSize-1, w-m_borderSize, h-m_borderSize); // Right hand side |
494 | dc.DrawLine(m_borderSize-1, h-m_borderSize, w-m_borderSize+1, h-m_borderSize); // Bottom | |
c801d85f KB |
495 | } |
496 | else if ( GetWindowStyleFlag() & wxSP_BORDER ) | |
497 | { | |
498 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
499 | dc.SetPen(*wxBLACK_PEN); | |
500 | dc.DrawRectangle(0, 0, w-1, h-1); | |
501 | } | |
502 | ||
503 | dc.SetPen(wxNullPen); | |
504 | dc.SetBrush(wxNullBrush); | |
505 | } | |
506 | ||
507 | // Draw the sash | |
508 | void wxSplitterWindow::DrawSash(wxDC& dc) | |
509 | { | |
510 | if ( m_sashPosition == 0 || !m_windowTwo) | |
511 | return; | |
f6bcfd97 BP |
512 | if (GetWindowStyle() & wxSP_NOSASH) |
513 | return; | |
c801d85f KB |
514 | |
515 | int w, h; | |
516 | GetClientSize(&w, &h); | |
517 | ||
f6bcfd97 | 518 | if ( GetWindowStyleFlag() & wxSP_3DSASH ) |
c801d85f KB |
519 | { |
520 | if ( m_splitMode == wxSPLIT_VERTICAL ) | |
521 | { | |
522 | dc.SetPen(*m_facePen); | |
d30f0930 RR |
523 | |
524 | if (HasFlag( wxSP_SASH_AQUA )) | |
525 | dc.SetBrush(*wxWHITE_BRUSH); | |
526 | else | |
527 | dc.SetBrush(*m_faceBrush); | |
1e2c86ca | 528 | dc.DrawRectangle(m_sashPosition + 2, 0 , m_sashSize - 4, h ); |
c801d85f KB |
529 | |
530 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
531 | ||
532 | dc.SetPen(*m_lightShadowPen); | |
f6bcfd97 | 533 | int xShadow = m_borderSize ? m_borderSize - 1 : 0 ; |
1e2c86ca | 534 | dc.DrawLine(m_sashPosition, xShadow , m_sashPosition, h-m_borderSize); |
c801d85f KB |
535 | |
536 | dc.SetPen(*m_hilightPen); | |
1e2c86ca | 537 | dc.DrawLine(m_sashPosition+1, m_borderSize - 2, m_sashPosition+1, h - m_borderSize+2); |
c801d85f | 538 | |
d30f0930 RR |
539 | if (!HasFlag( wxSP_SASH_AQUA )) |
540 | dc.SetPen(*m_mediumShadowPen); | |
541 | ||
542 | int yMedium = m_borderSize ? h-m_borderSize+1 : h ; | |
1e2c86ca | 543 | dc.DrawLine(m_sashPosition+m_sashSize-2, xShadow, m_sashPosition+m_sashSize-2, yMedium); |
c801d85f | 544 | |
d30f0930 RR |
545 | if (HasFlag( wxSP_SASH_AQUA )) |
546 | dc.SetPen(*m_lightShadowPen); | |
547 | else | |
548 | dc.SetPen(*m_darkShadowPen); | |
1e2c86ca | 549 | dc.DrawLine(m_sashPosition+m_sashSize-1, m_borderSize, m_sashPosition+m_sashSize-1, h-m_borderSize ); |
2e8cc3e8 | 550 | |
f6bcfd97 BP |
551 | // Draw the top and bottom edges of the sash, if requested |
552 | if (GetWindowStyle() & wxSP_FULLSASH) | |
553 | { | |
554 | // Top | |
555 | dc.SetPen(*m_hilightPen); | |
556 | dc.DrawLine(m_sashPosition+1, m_borderSize, m_sashPosition+m_sashSize-1, m_borderSize); | |
557 | ||
558 | // Bottom | |
559 | dc.SetPen(*m_darkShadowPen); | |
560 | dc.DrawLine(m_sashPosition+1, h-m_borderSize-1, m_sashPosition+m_sashSize-1, h-m_borderSize-1); | |
561 | } | |
0d559d69 | 562 | } |
c801d85f KB |
563 | else |
564 | { | |
565 | dc.SetPen(*m_facePen); | |
d30f0930 RR |
566 | if (HasFlag( wxSP_SASH_AQUA )) |
567 | dc.SetBrush(*wxWHITE_BRUSH); | |
568 | else | |
569 | dc.SetBrush(*m_faceBrush); | |
1e2c86ca | 570 | dc.DrawRectangle( m_borderSize-2, m_sashPosition + 2, w-m_borderSize+2, m_sashSize - 4); |
c801d85f KB |
571 | |
572 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
573 | ||
574 | dc.SetPen(*m_lightShadowPen); | |
1e2c86ca | 575 | dc.DrawLine(m_borderSize-1, m_sashPosition, w-m_borderSize, m_sashPosition); |
c801d85f KB |
576 | |
577 | dc.SetPen(*m_hilightPen); | |
1e2c86ca | 578 | dc.DrawLine(m_borderSize-2, m_sashPosition+1, w-m_borderSize+1, m_sashPosition+1); |
c801d85f | 579 | |
d30f0930 RR |
580 | if (!HasFlag( wxSP_SASH_AQUA )) |
581 | dc.SetPen(*m_mediumShadowPen); | |
1e2c86ca | 582 | dc.DrawLine(m_borderSize-1, m_sashPosition+m_sashSize-2, w-m_borderSize+1, m_sashPosition+m_sashSize-2); |
c801d85f | 583 | |
d30f0930 RR |
584 | if (HasFlag( wxSP_SASH_AQUA )) |
585 | dc.SetPen(*m_lightShadowPen); | |
586 | else | |
587 | dc.SetPen(*m_darkShadowPen); | |
1e2c86ca | 588 | dc.DrawLine(m_borderSize, m_sashPosition+m_sashSize-1, w-m_borderSize, m_sashPosition+m_sashSize-1); |
f6bcfd97 BP |
589 | |
590 | // Draw the left and right edges of the sash, if requested | |
591 | if (GetWindowStyle() & wxSP_FULLSASH) | |
592 | { | |
593 | // Left | |
594 | dc.SetPen(*m_hilightPen); | |
595 | dc.DrawLine(m_borderSize, m_sashPosition, m_borderSize, m_sashPosition+m_sashSize); | |
596 | ||
597 | // Right | |
598 | dc.SetPen(*m_darkShadowPen); | |
599 | dc.DrawLine(w-m_borderSize-1, m_sashPosition+1, w-m_borderSize-1, m_sashPosition+m_sashSize-1); | |
600 | } | |
c801d85f KB |
601 | } |
602 | } | |
603 | else | |
604 | { | |
605 | if ( m_splitMode == wxSPLIT_VERTICAL ) | |
606 | { | |
607 | dc.SetPen(*wxBLACK_PEN); | |
608 | dc.SetBrush(*wxBLACK_BRUSH); | |
609 | int h1 = h-1; | |
f6bcfd97 BP |
610 | int y1 = 0; |
611 | if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER ) | |
c801d85f | 612 | h1 += 1; // Not sure why this is necessary... |
f6bcfd97 BP |
613 | if ( (GetWindowStyleFlag() & wxSP_3DBORDER) == wxSP_3DBORDER) |
614 | { | |
615 | y1 = 2; h1 -= 3; | |
616 | } | |
617 | dc.DrawRectangle(m_sashPosition, y1, m_sashSize, h1); | |
c801d85f KB |
618 | } |
619 | else | |
620 | { | |
621 | dc.SetPen(*wxBLACK_PEN); | |
622 | dc.SetBrush(*wxBLACK_BRUSH); | |
623 | int w1 = w-1; | |
f6bcfd97 BP |
624 | int x1 = 0; |
625 | if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER ) | |
c801d85f | 626 | w1 ++; |
f6bcfd97 BP |
627 | if ( (GetWindowStyleFlag() & wxSP_3DBORDER) == wxSP_3DBORDER) |
628 | { | |
629 | x1 = 2; w1 -= 3; | |
630 | } | |
631 | dc.DrawRectangle(x1, m_sashPosition, w1, m_sashSize); | |
c801d85f KB |
632 | } |
633 | ||
634 | } | |
635 | ||
636 | dc.SetPen(wxNullPen); | |
637 | dc.SetBrush(wxNullBrush); | |
638 | } | |
639 | ||
640 | // Draw the sash tracker (for whilst moving the sash) | |
debe6624 | 641 | void wxSplitterWindow::DrawSashTracker(int x, int y) |
c801d85f KB |
642 | { |
643 | int w, h; | |
644 | GetClientSize(&w, &h); | |
645 | ||
646 | wxScreenDC screenDC; | |
647 | int x1, y1; | |
648 | int x2, y2; | |
649 | ||
650 | if ( m_splitMode == wxSPLIT_VERTICAL ) | |
651 | { | |
652 | x1 = x; y1 = 2; | |
653 | x2 = x; y2 = h-2; | |
654 | ||
655 | if ( x1 > w ) | |
656 | { | |
657 | x1 = w; x2 = w; | |
658 | } | |
659 | else if ( x1 < 0 ) | |
660 | { | |
661 | x1 = 0; x2 = 0; | |
662 | } | |
663 | } | |
664 | else | |
665 | { | |
666 | x1 = 2; y1 = y; | |
667 | x2 = w-2; y2 = y; | |
668 | ||
669 | if ( y1 > h ) | |
670 | { | |
671 | y1 = h; | |
672 | y2 = h; | |
673 | } | |
674 | else if ( y1 < 0 ) | |
675 | { | |
676 | y1 = 0; | |
677 | y2 = 0; | |
678 | } | |
679 | } | |
680 | ||
681 | ClientToScreen(&x1, &y1); | |
682 | ClientToScreen(&x2, &y2); | |
683 | ||
3c679789 | 684 | screenDC.SetLogicalFunction(wxINVERT); |
c801d85f KB |
685 | screenDC.SetPen(*m_sashTrackerPen); |
686 | screenDC.SetBrush(*wxTRANSPARENT_BRUSH); | |
687 | ||
688 | screenDC.DrawLine(x1, y1, x2, y2); | |
689 | ||
690 | screenDC.SetLogicalFunction(wxCOPY); | |
691 | ||
692 | screenDC.SetPen(wxNullPen); | |
693 | screenDC.SetBrush(wxNullBrush); | |
694 | } | |
695 | ||
2e8cc3e8 | 696 | int wxSplitterWindow::GetWindowSize() const |
d76ac8ed | 697 | { |
2e8cc3e8 VZ |
698 | wxSize size = GetClientSize(); |
699 | ||
700 | return m_splitMode == wxSPLIT_VERTICAL ? size.x : size.y; | |
701 | } | |
702 | ||
703 | int wxSplitterWindow::AdjustSashPosition(int sashPos) const | |
704 | { | |
705 | int window_size = GetWindowSize(); | |
706 | ||
d76ac8ed VS |
707 | wxWindow *win; |
708 | ||
d76ac8ed VS |
709 | win = GetWindow1(); |
710 | if ( win ) | |
711 | { | |
2e8cc3e8 VZ |
712 | // the window shouldn't be smaller than its own minimal size nor |
713 | // smaller than the minimual pane size specified for this splitter | |
714 | int minSize = m_splitMode == wxSPLIT_VERTICAL ? win->GetMinWidth() | |
715 | : win->GetMinHeight(); | |
716 | ||
717 | if ( minSize == -1 || m_minimumPaneSize > minSize ) | |
718 | minSize = m_minimumPaneSize; | |
719 | ||
720 | minSize += GetBorderSize(); | |
721 | ||
722 | if ( sashPos < minSize ) | |
723 | sashPos = minSize; | |
d76ac8ed VS |
724 | } |
725 | ||
726 | win = GetWindow2(); | |
727 | if ( win ) | |
728 | { | |
2e8cc3e8 VZ |
729 | int minSize = m_splitMode == wxSPLIT_VERTICAL ? win->GetMinWidth() |
730 | : win->GetMinHeight(); | |
731 | ||
732 | if ( minSize == -1 || m_minimumPaneSize > minSize ) | |
733 | minSize = m_minimumPaneSize; | |
734 | ||
735 | int maxSize = window_size - minSize - GetBorderSize(); | |
736 | if ( sashPos > maxSize ) | |
737 | sashPos = maxSize; | |
d76ac8ed | 738 | } |
2e8cc3e8 VZ |
739 | |
740 | return sashPos; | |
d76ac8ed VS |
741 | } |
742 | ||
ca39e409 VS |
743 | void wxSplitterWindow::DoSetSashPosition(int sashPos) |
744 | { | |
745 | m_requestedSashPosition = sashPos; | |
746 | m_sashPosition = (sashPos == 0) ? 0 : AdjustSashPosition(sashPos); | |
747 | } | |
748 | ||
c801d85f KB |
749 | // Position and size subwindows. |
750 | // Note that the border size applies to each subwindow, not | |
751 | // including the edges next to the sash. | |
0d559d69 | 752 | void wxSplitterWindow::SizeWindows() |
c801d85f | 753 | { |
ca39e409 VS |
754 | if ( m_requestedSashPosition != m_sashPosition ) |
755 | DoSetSashPosition(m_requestedSashPosition); | |
756 | ||
c801d85f KB |
757 | int w, h; |
758 | GetClientSize(&w, &h); | |
759 | ||
f6bcfd97 | 760 | if ( GetWindow1() && !GetWindow2() ) |
c801d85f | 761 | { |
ca39e409 VS |
762 | GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(), |
763 | w - 2*GetBorderSize(), h - 2*GetBorderSize()); | |
c801d85f | 764 | } |
f6bcfd97 | 765 | else if ( GetWindow1() && GetWindow2() ) |
c801d85f | 766 | { |
f6bcfd97 | 767 | if (GetSplitMode() == wxSPLIT_VERTICAL) |
c801d85f | 768 | { |
f6bcfd97 BP |
769 | int x1 = GetBorderSize(); |
770 | int y1 = GetBorderSize(); | |
771 | int w1 = GetSashPosition() - GetBorderSize(); | |
772 | int h1 = h - 2*GetBorderSize(); | |
773 | ||
774 | int x2 = GetSashPosition() + GetSashSize(); | |
775 | int y2 = GetBorderSize(); | |
776 | int w2 = w - 2*GetBorderSize() - GetSashSize() - w1; | |
777 | int h2 = h - 2*GetBorderSize(); | |
778 | ||
779 | GetWindow1()->SetSize(x1, y1, w1, h1); | |
780 | GetWindow2()->SetSize(x2, y2, w2, h2); | |
c801d85f KB |
781 | } |
782 | else | |
783 | { | |
f6bcfd97 BP |
784 | GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(), |
785 | w - 2*GetBorderSize(), GetSashPosition() - GetBorderSize()); | |
786 | GetWindow2()->SetSize(GetBorderSize(), GetSashPosition() + GetSashSize(), | |
787 | w - 2*GetBorderSize(), h - 2*GetBorderSize() - GetSashSize() - (GetSashPosition() - GetBorderSize())); | |
c801d85f KB |
788 | } |
789 | } | |
790 | wxClientDC dc(this); | |
f6bcfd97 | 791 | if ( GetBorderSize() > 0 ) |
4419ba31 | 792 | DrawBorders(dc); |
c801d85f | 793 | DrawSash(dc); |
00a32dc1 | 794 | |
f6bcfd97 | 795 | SetNeedUpdating(FALSE); |
c801d85f KB |
796 | } |
797 | ||
798 | // Set pane for unsplit window | |
799 | void wxSplitterWindow::Initialize(wxWindow *window) | |
800 | { | |
801 | m_windowOne = window; | |
c67daf87 | 802 | m_windowTwo = (wxWindow *) NULL; |
ca39e409 | 803 | DoSetSashPosition(0); |
c801d85f KB |
804 | } |
805 | ||
806 | // Associates the given window with window 2, drawing the appropriate sash | |
807 | // and changing the split mode. | |
808 | // Does nothing and returns FALSE if the window is already split. | |
2e8cc3e8 VZ |
809 | bool wxSplitterWindow::DoSplit(wxSplitMode mode, |
810 | wxWindow *window1, wxWindow *window2, | |
811 | int sashPosition) | |
c801d85f KB |
812 | { |
813 | if ( IsSplit() ) | |
814 | return FALSE; | |
815 | ||
2e8cc3e8 | 816 | int window_size = GetWindowSize(); |
0d559d69 | 817 | |
2e8cc3e8 | 818 | m_splitMode = mode; |
c801d85f KB |
819 | m_windowOne = window1; |
820 | m_windowTwo = window2; | |
c801d85f | 821 | |
0d559d69 | 822 | if ( sashPosition > 0 ) |
2e8cc3e8 | 823 | { |
ca39e409 | 824 | DoSetSashPosition(sashPosition); |
2e8cc3e8 | 825 | } |
0d559d69 | 826 | else if ( sashPosition < 0 ) |
2e8cc3e8 VZ |
827 | { |
828 | // It's negative so adding is subtracting | |
ca39e409 | 829 | DoSetSashPosition(window_size + sashPosition); |
2e8cc3e8 VZ |
830 | } |
831 | else | |
832 | { | |
833 | // default | |
ca39e409 | 834 | DoSetSashPosition(window_size/2); |
2e8cc3e8 | 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); |
ca39e409 | 869 | DoSetSashPosition(0); |
3ad5e06b VZ |
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 | ||
ca39e409 VS |
901 | void wxSplitterWindow::SetMinimumPaneSize(int min) |
902 | { | |
903 | m_minimumPaneSize = min; | |
904 | SetSashPosition(m_sashPosition); // re-check limits | |
905 | } | |
906 | ||
debe6624 | 907 | void wxSplitterWindow::SetSashPosition(int position, bool redraw) |
c801d85f | 908 | { |
ca39e409 | 909 | DoSetSashPosition(position); |
c801d85f KB |
910 | |
911 | if ( redraw ) | |
912 | { | |
913 | SizeWindows(); | |
914 | } | |
915 | } | |
916 | ||
c801d85f | 917 | // Initialize colours |
0d559d69 | 918 | void wxSplitterWindow::InitColours() |
c801d85f | 919 | { |
0d559d69 VZ |
920 | wxDELETE( m_facePen ); |
921 | wxDELETE( m_faceBrush ); | |
922 | wxDELETE( m_mediumShadowPen ); | |
923 | wxDELETE( m_darkShadowPen ); | |
924 | wxDELETE( m_lightShadowPen ); | |
925 | wxDELETE( m_hilightPen ); | |
c801d85f KB |
926 | |
927 | // Shadow colours | |
37d403aa | 928 | #ifndef __WIN16__ |
a756f210 | 929 | wxColour faceColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); |
c801d85f KB |
930 | m_facePen = new wxPen(faceColour, 1, wxSOLID); |
931 | m_faceBrush = new wxBrush(faceColour, wxSOLID); | |
932 | ||
a756f210 | 933 | wxColour mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)); |
c801d85f KB |
934 | m_mediumShadowPen = new wxPen(mediumShadowColour, 1, wxSOLID); |
935 | ||
a756f210 | 936 | wxColour darkShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW)); |
c801d85f KB |
937 | m_darkShadowPen = new wxPen(darkShadowColour, 1, wxSOLID); |
938 | ||
a756f210 | 939 | wxColour lightShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT)); |
c801d85f KB |
940 | m_lightShadowPen = new wxPen(lightShadowColour, 1, wxSOLID); |
941 | ||
a756f210 | 942 | wxColour hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT)); |
c801d85f | 943 | m_hilightPen = new wxPen(hilightColour, 1, wxSOLID); |
37d403aa | 944 | #else |
c801d85f KB |
945 | m_facePen = new wxPen("LIGHT GREY", 1, wxSOLID); |
946 | m_faceBrush = new wxBrush("LIGHT GREY", wxSOLID); | |
947 | m_mediumShadowPen = new wxPen("GREY", 1, wxSOLID); | |
948 | m_darkShadowPen = new wxPen("BLACK", 1, wxSOLID); | |
949 | m_lightShadowPen = new wxPen("LIGHT GREY", 1, wxSOLID); | |
950 | m_hilightPen = new wxPen("WHITE", 1, wxSOLID); | |
37d403aa | 951 | #endif // __WIN16__ |
c801d85f KB |
952 | } |
953 | ||
42e69d6b VZ |
954 | void wxSplitterWindow::SendUnsplitEvent(wxWindow *winRemoved) |
955 | { | |
956 | wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_UNSPLIT, this); | |
957 | event.m_data.win = winRemoved; | |
958 | ||
959 | (void)GetEventHandler()->ProcessEvent(event); | |
960 | } | |
961 | ||
962 | // --------------------------------------------------------------------------- | |
963 | // splitter event handlers | |
964 | // --------------------------------------------------------------------------- | |
965 | ||
966 | void wxSplitterWindow::OnSashPosChanged(wxSplitterEvent& event) | |
967 | { | |
968 | // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure. | |
969 | const int UNSPLIT_THRESHOLD = 4; | |
970 | ||
971 | int newSashPosition = event.GetSashPosition(); | |
972 | ||
973 | // Obtain relevant window dimension for bottom / right threshold check | |
2e8cc3e8 | 974 | int window_size = GetWindowSize(); |
42e69d6b | 975 | |
370938d9 UB |
976 | bool unsplit_scenario = FALSE; |
977 | if ( m_permitUnsplitAlways | |
978 | || m_minimumPaneSize == 0 ) | |
bc79aa6b | 979 | { |
370938d9 UB |
980 | // Do edge detection if unsplit premitted |
981 | if ( newSashPosition <= UNSPLIT_THRESHOLD ) | |
982 | { | |
983 | // threshold top / left check | |
984 | newSashPosition = 0; | |
985 | unsplit_scenario = TRUE; | |
986 | } | |
987 | if ( newSashPosition >= window_size - UNSPLIT_THRESHOLD ) | |
988 | { | |
989 | // threshold bottom/right check | |
990 | newSashPosition = window_size; | |
991 | unsplit_scenario = TRUE; | |
992 | } | |
bc79aa6b UB |
993 | } |
994 | ||
370938d9 | 995 | if ( !unsplit_scenario ) |
bc79aa6b UB |
996 | { |
997 | // If resultant pane would be too small, enlarge it | |
2e8cc3e8 | 998 | newSashPosition = AdjustSashPosition(newSashPosition); |
bc79aa6b | 999 | } |
42e69d6b VZ |
1000 | |
1001 | // If the result is out of bounds it means minimum size is too big, | |
1002 | // so split window in half as best compromise. | |
1003 | if ( newSashPosition < 0 || newSashPosition > window_size ) | |
1004 | newSashPosition = window_size / 2; | |
1005 | ||
1006 | // for compatibility, call the virtual function | |
1007 | if ( !OnSashPositionChange(newSashPosition) ) | |
1008 | { | |
1009 | newSashPosition = -1; | |
1010 | } | |
1011 | ||
1012 | event.SetSashPosition(newSashPosition); | |
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. | |
1017 | void wxSplitterWindow::OnDoubleClick(wxSplitterEvent& event) | |
1018 | { | |
1019 | // for compatibility, call the virtual function | |
1020 | OnDoubleClickSash(event.GetX(), event.GetY()); | |
1021 | ||
4419ba31 | 1022 | if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways ) |
42e69d6b VZ |
1023 | { |
1024 | Unsplit(); | |
1025 | } | |
1026 | } | |
1027 | ||
1028 | void wxSplitterWindow::OnUnsplitEvent(wxSplitterEvent& event) | |
1029 | { | |
1030 | wxWindow *win = event.GetWindowBeingRemoved(); | |
1031 | ||
4419ba31 VZ |
1032 | // do it before calling OnUnsplit() which may delete the window |
1033 | win->Show(FALSE); | |
1034 | ||
42e69d6b VZ |
1035 | // for compatibility, call the virtual function |
1036 | OnUnsplit(win); | |
42e69d6b | 1037 | } |
43b5058d | 1038 | |
bc1dcfc1 VZ |
1039 | #if defined(__WXMSW__) |
1040 | #define WXUNUSED_UNLESS_MSW(identifier) identifier | |
1041 | #else | |
1042 | #define WXUNUSED_UNLESS_MSW(identifier) WXUNUSED(identifier) | |
1043 | #endif | |
1044 | ||
1045 | void wxSplitterWindow::OnSetCursor(wxSetCursorEvent& WXUNUSED_UNLESS_MSW(event)) | |
43b5058d VZ |
1046 | { |
1047 | // this is currently called (and needed) under MSW only... | |
1048 | #ifdef __WXMSW__ | |
1049 | ||
1050 | // if we don't do it, the resizing cursor might be set for child window: | |
1051 | // and like this we explicitly say that our cursor should not be used for | |
1052 | // children windows which overlap us | |
1053 | ||
1054 | if ( SashHitTest(event.GetX(), event.GetY()) ) | |
1055 | { | |
1056 | // default processing is ok | |
1057 | event.Skip(); | |
1058 | } | |
1059 | //else: do nothing, in particular, don't call Skip() | |
1060 | #endif // wxMSW | |
1061 | } |