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