]>
Commit | Line | Data |
---|---|---|
a6d70308 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: sashwin.cpp | |
3 | // Purpose: wxSashWindow implementation. A sash window has an optional | |
4 | // sash on each edge, allowing it to be dragged. An event | |
5 | // is generated when the sash is released. | |
6 | // Author: Julian Smart | |
7 | // Modified by: | |
8 | // Created: 01/02/97 | |
9 | // RCS-ID: $Id$ | |
10 | // Copyright: (c) Julian Smart | |
65571936 | 11 | // Licence: wxWindows licence |
a6d70308 JS |
12 | ///////////////////////////////////////////////////////////////////////////// |
13 | ||
14f355c2 | 14 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
a6d70308 JS |
15 | #pragma implementation "sashwin.h" |
16 | #endif | |
17 | ||
18 | // For compilers that support precompilation, includes "wx.h". | |
19 | #include "wx/wxprec.h" | |
20 | ||
21 | #ifdef __BORLANDC__ | |
22 | #pragma hdrstop | |
23 | #endif | |
24 | ||
1e6feb95 VZ |
25 | #if wxUSE_SASH |
26 | ||
a6d70308 | 27 | #ifndef WX_PRECOMP |
04dbb646 VZ |
28 | #include "wx/dialog.h" |
29 | #include "wx/frame.h" | |
30 | #include "wx/settings.h" | |
a6d70308 JS |
31 | #endif |
32 | ||
33 | #include <math.h> | |
34 | #include <stdlib.h> | |
35 | ||
a6d70308 JS |
36 | #include "wx/dcscreen.h" |
37 | #include "wx/sashwin.h" | |
f9b1708c | 38 | #include "wx/laywin.h" |
a6d70308 | 39 | |
32956769 JS |
40 | DEFINE_EVENT_TYPE(wxEVT_SASH_DRAGGED) |
41 | ||
a6d70308 JS |
42 | IMPLEMENT_DYNAMIC_CLASS(wxSashWindow, wxWindow) |
43 | IMPLEMENT_DYNAMIC_CLASS(wxSashEvent, wxCommandEvent) | |
44 | ||
45 | BEGIN_EVENT_TABLE(wxSashWindow, wxWindow) | |
46 | EVT_PAINT(wxSashWindow::OnPaint) | |
47 | EVT_SIZE(wxSashWindow::OnSize) | |
48 | EVT_MOUSE_EVENTS(wxSashWindow::OnMouseEvent) | |
64407854 | 49 | #if defined( __WXMSW__ ) || defined( __WXMAC__) |
2b5f62a0 VZ |
50 | EVT_SET_CURSOR(wxSashWindow::OnSetCursor) |
51 | #endif // wxMSW | |
52 | ||
a6d70308 | 53 | END_EVENT_TABLE() |
a6d70308 | 54 | |
f6bcfd97 BP |
55 | bool wxSashWindow::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, |
56 | const wxSize& size, long style, const wxString& name) | |
a6d70308 | 57 | { |
f6bcfd97 BP |
58 | return wxWindow::Create(parent, id, pos, size, style, name); |
59 | } | |
a6d70308 | 60 | |
f6bcfd97 BP |
61 | wxSashWindow::~wxSashWindow() |
62 | { | |
63 | delete m_sashCursorWE; | |
64 | delete m_sashCursorNS; | |
a6d70308 JS |
65 | } |
66 | ||
f6bcfd97 | 67 | void wxSashWindow::Init() |
a6d70308 JS |
68 | { |
69 | m_draggingEdge = wxSASH_NONE; | |
70 | m_dragMode = wxSASH_DRAG_NONE; | |
71 | m_oldX = 0; | |
72 | m_oldY = 0; | |
73 | m_firstX = 0; | |
74 | m_firstY = 0; | |
75 | m_borderSize = 3; | |
76 | m_extraBorderSize = 0; | |
77 | m_minimumPaneSizeX = 0; | |
78 | m_minimumPaneSizeY = 0; | |
f66b7050 MR |
79 | m_maximumPaneSizeX = 10000; |
80 | m_maximumPaneSizeY = 10000; | |
a6d70308 JS |
81 | m_sashCursorWE = new wxCursor(wxCURSOR_SIZEWE); |
82 | m_sashCursorNS = new wxCursor(wxCURSOR_SIZENS); | |
ca65c044 | 83 | m_mouseCaptured = false; |
2b5f62a0 | 84 | m_currentCursor = NULL; |
a6d70308 JS |
85 | |
86 | // Eventually, we'll respond to colour change messages | |
87 | InitColours(); | |
88 | } | |
89 | ||
a6d70308 JS |
90 | void wxSashWindow::OnPaint(wxPaintEvent& WXUNUSED(event)) |
91 | { | |
92 | wxPaintDC dc(this); | |
93 | ||
ee4c6942 | 94 | DrawBorders(dc); |
a6d70308 JS |
95 | DrawSashes(dc); |
96 | } | |
97 | ||
98 | void wxSashWindow::OnMouseEvent(wxMouseEvent& event) | |
99 | { | |
cfeb83fd VZ |
100 | wxCoord x, y; |
101 | event.GetPosition(&x, &y); | |
a6d70308 JS |
102 | |
103 | wxSashEdgePosition sashHit = SashHitTest(x, y); | |
104 | ||
a1b82138 VZ |
105 | if (event.LeftDown()) |
106 | { | |
9f334bea | 107 | CaptureMouse(); |
ca65c044 | 108 | m_mouseCaptured = true; |
9f334bea | 109 | |
a6d70308 JS |
110 | if ( sashHit != wxSASH_NONE ) |
111 | { | |
a1b82138 | 112 | // Required for X to specify that |
b412f9be JS |
113 | // that we wish to draw on top of all windows |
114 | // - and we optimise by specifying the area | |
115 | // for creating the overlap window. | |
116 | // Find the first frame or dialog and use this to specify | |
117 | // the area to draw on. | |
118 | wxWindow* parent = this; | |
119 | ||
120 | while (parent && !parent->IsKindOf(CLASSINFO(wxDialog)) && | |
121 | !parent->IsKindOf(CLASSINFO(wxFrame))) | |
122 | parent = parent->GetParent(); | |
123 | ||
124 | wxScreenDC::StartDrawingOnTop(parent); | |
a6d70308 JS |
125 | |
126 | // We don't say we're dragging yet; we leave that | |
127 | // decision for the Dragging() branch, to ensure | |
128 | // the user has dragged a little bit. | |
129 | m_dragMode = wxSASH_DRAG_LEFT_DOWN; | |
130 | m_draggingEdge = sashHit; | |
131 | m_firstX = x; | |
132 | m_firstY = y; | |
9f334bea JS |
133 | |
134 | if ( (sashHit == wxSASH_LEFT) || (sashHit == wxSASH_RIGHT) ) | |
135 | { | |
2b5f62a0 VZ |
136 | if (m_currentCursor != m_sashCursorWE) |
137 | { | |
138 | SetCursor(*m_sashCursorWE); | |
139 | } | |
140 | m_currentCursor = m_sashCursorWE; | |
9f334bea JS |
141 | } |
142 | else | |
143 | { | |
2b5f62a0 VZ |
144 | if (m_currentCursor != m_sashCursorNS) |
145 | { | |
146 | SetCursor(*m_sashCursorNS); | |
147 | } | |
148 | m_currentCursor = m_sashCursorNS; | |
9f334bea | 149 | } |
a6d70308 | 150 | } |
a1b82138 | 151 | } |
a6d70308 JS |
152 | else if ( event.LeftUp() && m_dragMode == wxSASH_DRAG_LEFT_DOWN ) |
153 | { | |
154 | // Wasn't a proper drag | |
40fab78b JS |
155 | if (m_mouseCaptured) |
156 | ReleaseMouse(); | |
ca65c044 | 157 | m_mouseCaptured = false; |
40fab78b | 158 | |
a6d70308 JS |
159 | wxScreenDC::EndDrawingOnTop(); |
160 | m_dragMode = wxSASH_DRAG_NONE; | |
161 | m_draggingEdge = wxSASH_NONE; | |
a6d70308 | 162 | } |
a1b82138 VZ |
163 | else if (event.LeftUp() && m_dragMode == wxSASH_DRAG_DRAGGING) |
164 | { | |
a6d70308 JS |
165 | // We can stop dragging now and see what we've got. |
166 | m_dragMode = wxSASH_DRAG_NONE; | |
40fab78b JS |
167 | if (m_mouseCaptured) |
168 | ReleaseMouse(); | |
ca65c044 | 169 | m_mouseCaptured = false; |
40fab78b | 170 | |
a6d70308 JS |
171 | // Erase old tracker |
172 | DrawSashTracker(m_draggingEdge, m_oldX, m_oldY); | |
173 | ||
174 | // End drawing on top (frees the window used for drawing | |
175 | // over the screen) | |
176 | wxScreenDC::EndDrawingOnTop(); | |
177 | ||
178 | int w, h; | |
a1b82138 | 179 | GetSize(&w, &h); |
a6d70308 | 180 | int xp, yp; |
a1b82138 | 181 | GetPosition(&xp, &yp); |
a6d70308 JS |
182 | |
183 | wxSashEdgePosition edge = m_draggingEdge; | |
184 | m_draggingEdge = wxSASH_NONE; | |
185 | ||
186 | wxRect dragRect; | |
187 | wxSashDragStatus status = wxSASH_STATUS_OK; | |
a1b82138 VZ |
188 | |
189 | // the new height and width of the window - if -1, it didn't change | |
422d0ff0 WS |
190 | int newHeight = wxDefaultCoord, |
191 | newWidth = wxDefaultCoord; | |
a1b82138 VZ |
192 | |
193 | // NB: x and y may be negative and they're relative to the sash window | |
194 | // upper left corner, while xp and yp are expressed in the parent | |
195 | // window system of coordinates, so adjust them! After this | |
196 | // adjustment, all coordinates are relative to the parent window. | |
197 | y += yp; | |
198 | x += xp; | |
199 | ||
a6d70308 JS |
200 | switch (edge) |
201 | { | |
202 | case wxSASH_TOP: | |
a1b82138 VZ |
203 | if ( y > yp + h ) |
204 | { | |
205 | // top sash shouldn't get below the bottom one | |
a6d70308 | 206 | status = wxSASH_STATUS_OUT_OF_RANGE; |
a1b82138 VZ |
207 | } |
208 | else | |
209 | { | |
210 | newHeight = h - (y - yp); | |
211 | } | |
a6d70308 | 212 | break; |
a1b82138 | 213 | |
a6d70308 | 214 | case wxSASH_BOTTOM: |
a1b82138 VZ |
215 | if ( y < yp ) |
216 | { | |
217 | // bottom sash shouldn't get above the top one | |
a6d70308 | 218 | status = wxSASH_STATUS_OUT_OF_RANGE; |
a1b82138 VZ |
219 | } |
220 | else | |
221 | { | |
222 | newHeight = y - yp; | |
223 | } | |
a6d70308 | 224 | break; |
a1b82138 | 225 | |
a6d70308 | 226 | case wxSASH_LEFT: |
a1b82138 VZ |
227 | if ( x > xp + w ) |
228 | { | |
229 | // left sash shouldn't get beyond the right one | |
a6d70308 | 230 | status = wxSASH_STATUS_OUT_OF_RANGE; |
a1b82138 VZ |
231 | } |
232 | else | |
233 | { | |
234 | newWidth = w - (x - xp); | |
235 | } | |
a6d70308 | 236 | break; |
a1b82138 | 237 | |
a6d70308 | 238 | case wxSASH_RIGHT: |
a1b82138 VZ |
239 | if ( x < xp ) |
240 | { | |
241 | // and the right sash, finally, shouldn't be beyond the | |
242 | // left one | |
a6d70308 | 243 | status = wxSASH_STATUS_OUT_OF_RANGE; |
a1b82138 VZ |
244 | } |
245 | else | |
246 | { | |
247 | newWidth = x - xp; | |
248 | } | |
a6d70308 | 249 | break; |
a1b82138 VZ |
250 | |
251 | case wxSASH_NONE: | |
252 | // can this happen at all? | |
253 | break; | |
254 | } | |
255 | ||
422d0ff0 | 256 | if ( newHeight == wxDefaultCoord ) |
a1b82138 VZ |
257 | { |
258 | // didn't change | |
259 | newHeight = h; | |
260 | } | |
261 | else | |
262 | { | |
263 | // make sure it's in m_minimumPaneSizeY..m_maximumPaneSizeY range | |
264 | newHeight = wxMax(newHeight, m_minimumPaneSizeY); | |
265 | newHeight = wxMin(newHeight, m_maximumPaneSizeY); | |
a6d70308 JS |
266 | } |
267 | ||
422d0ff0 | 268 | if ( newWidth == wxDefaultCoord ) |
a1b82138 VZ |
269 | { |
270 | // didn't change | |
271 | newWidth = w; | |
272 | } | |
273 | else | |
274 | { | |
275 | // make sure it's in m_minimumPaneSizeY..m_maximumPaneSizeY range | |
276 | newWidth = wxMax(newWidth, m_minimumPaneSizeX); | |
277 | newWidth = wxMin(newWidth, m_maximumPaneSizeX); | |
278 | } | |
279 | ||
280 | dragRect = wxRect(x, y, newWidth, newHeight); | |
281 | ||
a6d70308 JS |
282 | wxSashEvent event(GetId(), edge); |
283 | event.SetEventObject(this); | |
284 | event.SetDragStatus(status); | |
285 | event.SetDragRect(dragRect); | |
286 | GetEventHandler()->ProcessEvent(event); | |
a1b82138 | 287 | } |
9f334bea JS |
288 | else if ( event.LeftUp() ) |
289 | { | |
40fab78b JS |
290 | if (m_mouseCaptured) |
291 | ReleaseMouse(); | |
ca65c044 | 292 | m_mouseCaptured = false; |
9f334bea | 293 | } |
a1b82138 VZ |
294 | else if (event.Moving() && !event.Dragging()) |
295 | { | |
a6d70308 JS |
296 | // Just change the cursor if required |
297 | if ( sashHit != wxSASH_NONE ) | |
298 | { | |
a1b82138 VZ |
299 | if ( (sashHit == wxSASH_LEFT) || (sashHit == wxSASH_RIGHT) ) |
300 | { | |
2b5f62a0 VZ |
301 | if (m_currentCursor != m_sashCursorWE) |
302 | { | |
303 | SetCursor(*m_sashCursorWE); | |
304 | } | |
305 | m_currentCursor = m_sashCursorWE; | |
a1b82138 VZ |
306 | } |
307 | else | |
308 | { | |
2b5f62a0 VZ |
309 | if (m_currentCursor != m_sashCursorNS) |
310 | { | |
311 | SetCursor(*m_sashCursorNS); | |
312 | } | |
313 | m_currentCursor = m_sashCursorNS; | |
a1b82138 VZ |
314 | } |
315 | } | |
c0bcc480 JS |
316 | else |
317 | { | |
8a9c2246 | 318 | SetCursor(wxNullCursor); |
2b5f62a0 | 319 | m_currentCursor = NULL; |
c0bcc480 | 320 | } |
a1b82138 VZ |
321 | } |
322 | else if ( event.Dragging() && | |
323 | ((m_dragMode == wxSASH_DRAG_DRAGGING) || | |
324 | (m_dragMode == wxSASH_DRAG_LEFT_DOWN)) ) | |
325 | { | |
326 | if ( (m_draggingEdge == wxSASH_LEFT) || (m_draggingEdge == wxSASH_RIGHT) ) | |
327 | { | |
2b5f62a0 VZ |
328 | if (m_currentCursor != m_sashCursorWE) |
329 | { | |
330 | SetCursor(*m_sashCursorWE); | |
331 | } | |
332 | m_currentCursor = m_sashCursorWE; | |
a1b82138 VZ |
333 | } |
334 | else | |
335 | { | |
2b5f62a0 VZ |
336 | if (m_currentCursor != m_sashCursorNS) |
337 | { | |
338 | SetCursor(*m_sashCursorNS); | |
339 | } | |
340 | m_currentCursor = m_sashCursorNS; | |
a6d70308 | 341 | } |
a6d70308 JS |
342 | |
343 | if (m_dragMode == wxSASH_DRAG_LEFT_DOWN) | |
344 | { | |
345 | m_dragMode = wxSASH_DRAG_DRAGGING; | |
346 | DrawSashTracker(m_draggingEdge, x, y); | |
347 | } | |
348 | else | |
349 | { | |
a1b82138 VZ |
350 | if ( m_dragMode == wxSASH_DRAG_DRAGGING ) |
351 | { | |
352 | // Erase old tracker | |
353 | DrawSashTracker(m_draggingEdge, m_oldX, m_oldY); | |
a6d70308 | 354 | |
a1b82138 VZ |
355 | // Draw new one |
356 | DrawSashTracker(m_draggingEdge, x, y); | |
357 | } | |
a6d70308 JS |
358 | } |
359 | m_oldX = x; | |
360 | m_oldY = y; | |
a1b82138 | 361 | } |
a6d70308 JS |
362 | else if ( event.LeftDClick() ) |
363 | { | |
364 | // Nothing | |
365 | } | |
366 | else | |
367 | { | |
368 | } | |
369 | } | |
370 | ||
371 | void wxSashWindow::OnSize(wxSizeEvent& WXUNUSED(event)) | |
372 | { | |
373 | SizeWindows(); | |
374 | } | |
375 | ||
341287bf | 376 | wxSashEdgePosition wxSashWindow::SashHitTest(int x, int y, int WXUNUSED(tolerance)) |
a6d70308 JS |
377 | { |
378 | int cx, cy; | |
379 | GetClientSize(& cx, & cy); | |
380 | ||
381 | int i; | |
382 | for (i = 0; i < 4; i++) | |
383 | { | |
384 | wxSashEdge& edge = m_sashes[i]; | |
385 | wxSashEdgePosition position = (wxSashEdgePosition) i ; | |
386 | ||
387 | if (edge.m_show) | |
388 | { | |
389 | switch (position) | |
390 | { | |
391 | case wxSASH_TOP: | |
392 | { | |
393 | if (y >= 0 && y <= GetEdgeMargin(position)) | |
394 | return wxSASH_TOP; | |
395 | break; | |
396 | } | |
397 | case wxSASH_RIGHT: | |
398 | { | |
399 | if ((x >= cx - GetEdgeMargin(position)) && (x <= cx)) | |
400 | return wxSASH_RIGHT; | |
401 | break; | |
402 | } | |
403 | case wxSASH_BOTTOM: | |
404 | { | |
405 | if ((y >= cy - GetEdgeMargin(position)) && (y <= cy)) | |
406 | return wxSASH_BOTTOM; | |
407 | break; | |
408 | } | |
409 | case wxSASH_LEFT: | |
410 | { | |
82540ef2 | 411 | if ((x <= GetEdgeMargin(position)) && (x >= 0)) |
a6d70308 JS |
412 | return wxSASH_LEFT; |
413 | break; | |
414 | } | |
341287bf JS |
415 | case wxSASH_NONE: |
416 | { | |
417 | break; | |
418 | } | |
a6d70308 JS |
419 | } |
420 | } | |
421 | } | |
422 | return wxSASH_NONE; | |
423 | } | |
424 | ||
425 | // Draw 3D effect borders | |
426 | void wxSashWindow::DrawBorders(wxDC& dc) | |
427 | { | |
428 | int w, h; | |
429 | GetClientSize(&w, &h); | |
430 | ||
431 | wxPen mediumShadowPen(m_mediumShadowColour, 1, wxSOLID); | |
432 | wxPen darkShadowPen(m_darkShadowColour, 1, wxSOLID); | |
433 | wxPen lightShadowPen(m_lightShadowColour, 1, wxSOLID); | |
434 | wxPen hilightPen(m_hilightColour, 1, wxSOLID); | |
435 | ||
f6bcfd97 | 436 | if ( GetWindowStyleFlag() & wxSW_3DBORDER ) |
a6d70308 JS |
437 | { |
438 | dc.SetPen(mediumShadowPen); | |
439 | dc.DrawLine(0, 0, w-1, 0); | |
440 | dc.DrawLine(0, 0, 0, h - 1); | |
441 | ||
442 | dc.SetPen(darkShadowPen); | |
443 | dc.DrawLine(1, 1, w-2, 1); | |
444 | dc.DrawLine(1, 1, 1, h-2); | |
445 | ||
446 | dc.SetPen(hilightPen); | |
447 | dc.DrawLine(0, h-1, w-1, h-1); | |
448 | dc.DrawLine(w-1, 0, w-1, h); // Surely the maximum y pos. should be h - 1. | |
449 | /// Anyway, h is required for MSW. | |
450 | ||
451 | dc.SetPen(lightShadowPen); | |
452 | dc.DrawLine(w-2, 1, w-2, h-2); // Right hand side | |
453 | dc.DrawLine(1, h-2, w-1, h-2); // Bottom | |
454 | } | |
448af9a4 | 455 | else if ( GetWindowStyleFlag() & wxSW_BORDER ) |
a6d70308 JS |
456 | { |
457 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
458 | dc.SetPen(*wxBLACK_PEN); | |
459 | dc.DrawRectangle(0, 0, w-1, h-1); | |
460 | } | |
461 | ||
462 | dc.SetPen(wxNullPen); | |
463 | dc.SetBrush(wxNullBrush); | |
464 | } | |
465 | ||
466 | void wxSashWindow::DrawSashes(wxDC& dc) | |
467 | { | |
468 | int i; | |
469 | for (i = 0; i < 4; i++) | |
470 | if (m_sashes[i].m_show) | |
471 | DrawSash((wxSashEdgePosition) i, dc); | |
472 | } | |
473 | ||
474 | // Draw the sash | |
475 | void wxSashWindow::DrawSash(wxSashEdgePosition edge, wxDC& dc) | |
476 | { | |
477 | int w, h; | |
478 | GetClientSize(&w, &h); | |
479 | ||
480 | wxPen facePen(m_faceColour, 1, wxSOLID); | |
481 | wxBrush faceBrush(m_faceColour, wxSOLID); | |
482 | wxPen mediumShadowPen(m_mediumShadowColour, 1, wxSOLID); | |
483 | wxPen darkShadowPen(m_darkShadowColour, 1, wxSOLID); | |
484 | wxPen lightShadowPen(m_lightShadowColour, 1, wxSOLID); | |
485 | wxPen hilightPen(m_hilightColour, 1, wxSOLID); | |
42841dfc WS |
486 | wxColour blackClr(0, 0, 0); |
487 | wxColour whiteClr(255, 255, 255); | |
488 | wxPen blackPen(blackClr, 1, wxSOLID); | |
489 | wxPen whitePen(whiteClr, 1, wxSOLID); | |
a6d70308 JS |
490 | |
491 | if ( edge == wxSASH_LEFT || edge == wxSASH_RIGHT ) | |
492 | { | |
999836aa | 493 | int sashPosition = (edge == wxSASH_LEFT) ? 0 : ( w - GetEdgeMargin(edge) ); |
a6d70308 JS |
494 | |
495 | dc.SetPen(facePen); | |
496 | dc.SetBrush(faceBrush); | |
497 | dc.DrawRectangle(sashPosition, 0, GetEdgeMargin(edge), h); | |
498 | ||
f6bcfd97 | 499 | if (GetWindowStyleFlag() & wxSW_3DSASH) |
a6d70308 JS |
500 | { |
501 | if (edge == wxSASH_LEFT) | |
502 | { | |
d0b223a1 | 503 | // Draw a dark grey line on the left to indicate that the |
a6d70308 | 504 | // sash is raised |
d0b223a1 | 505 | dc.SetPen(mediumShadowPen); |
a6d70308 JS |
506 | dc.DrawLine(GetEdgeMargin(edge), 0, GetEdgeMargin(edge), h); |
507 | } | |
508 | else | |
509 | { | |
f6bcfd97 | 510 | // Draw a highlight line on the right to indicate that the |
a6d70308 | 511 | // sash is raised |
f6bcfd97 | 512 | dc.SetPen(hilightPen); |
a6d70308 JS |
513 | dc.DrawLine(w - GetEdgeMargin(edge), 0, w - GetEdgeMargin(edge), h); |
514 | } | |
515 | } | |
516 | } | |
517 | else // top or bottom | |
518 | { | |
999836aa | 519 | int sashPosition = (edge == wxSASH_TOP) ? 0 : ( h - GetEdgeMargin(edge) ); |
a6d70308 JS |
520 | |
521 | dc.SetPen(facePen); | |
522 | dc.SetBrush(faceBrush); | |
523 | dc.DrawRectangle(0, sashPosition, w, GetEdgeMargin(edge)); | |
524 | ||
f6bcfd97 | 525 | if (GetWindowStyleFlag() & wxSW_3DSASH) |
a6d70308 JS |
526 | { |
527 | if (edge == wxSASH_BOTTOM) | |
528 | { | |
f6bcfd97 | 529 | // Draw a highlight line on the bottom to indicate that the |
a6d70308 | 530 | // sash is raised |
f6bcfd97 | 531 | dc.SetPen(hilightPen); |
058939fc | 532 | dc.DrawLine(0, h - GetEdgeMargin(edge), w, h - GetEdgeMargin(edge)); |
a6d70308 JS |
533 | } |
534 | else | |
535 | { | |
d0b223a1 | 536 | // Draw a drak grey line on the top to indicate that the |
a6d70308 | 537 | // sash is raised |
d0b223a1 | 538 | dc.SetPen(mediumShadowPen); |
c0bcc480 | 539 | dc.DrawLine(1, GetEdgeMargin(edge), w-1, GetEdgeMargin(edge)); |
a6d70308 JS |
540 | } |
541 | } | |
542 | } | |
543 | ||
544 | dc.SetPen(wxNullPen); | |
545 | dc.SetBrush(wxNullBrush); | |
546 | } | |
547 | ||
548 | // Draw the sash tracker (for whilst moving the sash) | |
549 | void wxSashWindow::DrawSashTracker(wxSashEdgePosition edge, int x, int y) | |
550 | { | |
551 | int w, h; | |
552 | GetClientSize(&w, &h); | |
553 | ||
554 | wxScreenDC screenDC; | |
555 | int x1, y1; | |
556 | int x2, y2; | |
557 | ||
558 | if ( edge == wxSASH_LEFT || edge == wxSASH_RIGHT ) | |
559 | { | |
560 | x1 = x; y1 = 2; | |
561 | x2 = x; y2 = h-2; | |
562 | ||
563 | if ( (edge == wxSASH_LEFT) && (x1 > w) ) | |
564 | { | |
565 | x1 = w; x2 = w; | |
566 | } | |
567 | else if ( (edge == wxSASH_RIGHT) && (x1 < 0) ) | |
568 | { | |
569 | x1 = 0; x2 = 0; | |
570 | } | |
571 | } | |
572 | else | |
573 | { | |
574 | x1 = 2; y1 = y; | |
575 | x2 = w-2; y2 = y; | |
576 | ||
577 | if ( (edge == wxSASH_TOP) && (y1 > h) ) | |
578 | { | |
579 | y1 = h; | |
580 | y2 = h; | |
581 | } | |
582 | else if ( (edge == wxSASH_BOTTOM) && (y1 < 0) ) | |
583 | { | |
584 | y1 = 0; | |
585 | y2 = 0; | |
586 | } | |
587 | } | |
588 | ||
589 | ClientToScreen(&x1, &y1); | |
590 | ClientToScreen(&x2, &y2); | |
591 | ||
592 | wxPen sashTrackerPen(*wxBLACK, 2, wxSOLID); | |
593 | ||
3c679789 | 594 | screenDC.SetLogicalFunction(wxINVERT); |
a6d70308 JS |
595 | screenDC.SetPen(sashTrackerPen); |
596 | screenDC.SetBrush(*wxTRANSPARENT_BRUSH); | |
597 | ||
598 | screenDC.DrawLine(x1, y1, x2, y2); | |
599 | ||
600 | screenDC.SetLogicalFunction(wxCOPY); | |
601 | ||
602 | screenDC.SetPen(wxNullPen); | |
603 | screenDC.SetBrush(wxNullBrush); | |
604 | } | |
605 | ||
606 | // Position and size subwindows. | |
607 | // Note that the border size applies to each subwindow, not | |
608 | // including the edges next to the sash. | |
609 | void wxSashWindow::SizeWindows() | |
610 | { | |
611 | int cw, ch; | |
612 | GetClientSize(&cw, &ch); | |
613 | ||
b1d4dd7a | 614 | if (GetChildren().GetCount() == 1) |
a6d70308 | 615 | { |
b1d4dd7a | 616 | wxWindow* child = GetChildren().GetFirst()->GetData(); |
a6d70308 JS |
617 | |
618 | int x = 0; | |
619 | int y = 0; | |
620 | int width = cw; | |
621 | int height = ch; | |
622 | ||
623 | // Top | |
624 | if (m_sashes[0].m_show) | |
625 | { | |
626 | y = m_borderSize; | |
627 | height -= m_borderSize; | |
628 | } | |
629 | y += m_extraBorderSize; | |
630 | ||
631 | // Left | |
632 | if (m_sashes[3].m_show) | |
633 | { | |
634 | x = m_borderSize; | |
635 | width -= m_borderSize; | |
636 | } | |
637 | x += m_extraBorderSize; | |
638 | ||
639 | // Right | |
640 | if (m_sashes[1].m_show) | |
641 | { | |
642 | width -= m_borderSize; | |
643 | } | |
644 | width -= 2*m_extraBorderSize; | |
645 | ||
646 | // Bottom | |
647 | if (m_sashes[2].m_show) | |
648 | { | |
649 | height -= m_borderSize; | |
650 | } | |
651 | height -= 2*m_extraBorderSize; | |
652 | ||
653 | child->SetSize(x, y, width, height); | |
654 | } | |
b1d4dd7a | 655 | else if (GetChildren().GetCount() > 1) |
f9b1708c JS |
656 | { |
657 | // Perhaps multiple children are themselves sash windows. | |
658 | // TODO: this doesn't really work because the subwindows sizes/positions | |
659 | // must be set to leave a gap for the parent's sash (hit-test and decorations). | |
660 | // Perhaps we can allow for this within LayoutWindow, testing whether the parent | |
661 | // is a sash window, and if so, allowing some space for the edges. | |
662 | wxLayoutAlgorithm layout; | |
663 | layout.LayoutWindow(this); | |
664 | } | |
a6d70308 JS |
665 | |
666 | wxClientDC dc(this); | |
667 | DrawBorders(dc); | |
668 | DrawSashes(dc); | |
669 | } | |
670 | ||
671 | // Initialize colours | |
672 | void wxSashWindow::InitColours() | |
673 | { | |
674 | // Shadow colours | |
a756f210 VS |
675 | m_faceColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); |
676 | m_mediumShadowColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW); | |
677 | m_darkShadowColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW); | |
678 | m_lightShadowColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); | |
679 | m_hilightColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT); | |
a6d70308 JS |
680 | } |
681 | ||
682 | void wxSashWindow::SetSashVisible(wxSashEdgePosition edge, bool sash) | |
683 | { | |
684 | m_sashes[edge].m_show = sash; | |
685 | if (sash) | |
686 | m_sashes[edge].m_margin = m_borderSize; | |
687 | else | |
688 | m_sashes[edge].m_margin = 0; | |
689 | } | |
690 | ||
64407854 | 691 | #if defined( __WXMSW__ ) || defined( __WXMAC__) |
2b5f62a0 VZ |
692 | |
693 | // this is currently called (and needed) under MSW only... | |
694 | void wxSashWindow::OnSetCursor(wxSetCursorEvent& event) | |
695 | { | |
696 | // if we don't do it, the resizing cursor might be set for child window: | |
697 | // and like this we explicitly say that our cursor should not be used for | |
698 | // children windows which overlap us | |
699 | ||
700 | if ( SashHitTest(event.GetX(), event.GetY()) != wxSASH_NONE) | |
701 | { | |
702 | // default processing is ok | |
703 | event.Skip(); | |
704 | } | |
705 | //else: do nothing, in particular, don't call Skip() | |
706 | } | |
707 | ||
708 | #endif // wxMSW | |
709 | ||
75be3f5e | 710 | #endif // wxUSE_SASH |