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