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