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