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