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