]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: splittree.cpp | |
3 | // Purpose: Classes to achieve a remotely-scrolled tree in a splitter | |
4 | // window that can be scrolled by a scrolled window higher in the | |
5 | // hierarchy | |
6 | // Author: Julian Smart | |
7 | // Modified by: | |
8 | // Created: 8/7/2000 | |
9 | // RCS-ID: $Id$ | |
10 | // Copyright: (c) Julian Smart | |
11 | // Licence: wxWindows licence | |
12 | ///////////////////////////////////////////////////////////////////////////// | |
13 | ||
14 | // ============================================================================ | |
15 | // declarations | |
16 | // ============================================================================ | |
17 | ||
18 | // ---------------------------------------------------------------------------- | |
19 | // headers | |
20 | // ---------------------------------------------------------------------------- | |
21 | ||
22 | // For compilers that support precompilation, includes "wx/wx.h". | |
23 | #include "wx/wxprec.h" | |
24 | ||
25 | #ifdef __BORLANDC__ | |
26 | #pragma hdrstop | |
27 | #endif | |
28 | ||
29 | // for all others, include the necessary headers (this file is usually all you | |
30 | // need because it includes almost all "standard" wxWidgets headers) | |
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/wx.h" | |
33 | #endif | |
34 | ||
35 | #ifdef __WXMSW__ | |
36 | #include <windows.h> | |
37 | #include "wx/msw/winundef.h" | |
38 | #endif | |
39 | ||
40 | #include "wx/gizmos/splittree.h" | |
41 | #include <math.h> | |
42 | ||
43 | /* | |
44 | * wxRemotelyScrolledTreeCtrl | |
45 | */ | |
46 | ||
47 | #if USE_GENERIC_TREECTRL | |
48 | IMPLEMENT_CLASS(wxRemotelyScrolledTreeCtrl, wxGenericTreeCtrl) | |
49 | #else | |
50 | IMPLEMENT_CLASS(wxRemotelyScrolledTreeCtrl, wxTreeCtrl) | |
51 | #endif | |
52 | ||
53 | #if USE_GENERIC_TREECTRL | |
54 | BEGIN_EVENT_TABLE(wxRemotelyScrolledTreeCtrl, wxGenericTreeCtrl) | |
55 | #else | |
56 | BEGIN_EVENT_TABLE(wxRemotelyScrolledTreeCtrl, wxTreeCtrl) | |
57 | #endif | |
58 | EVT_SIZE(wxRemotelyScrolledTreeCtrl::OnSize) | |
59 | EVT_PAINT(wxRemotelyScrolledTreeCtrl::OnPaint) | |
60 | EVT_TREE_ITEM_EXPANDED(wxID_ANY, wxRemotelyScrolledTreeCtrl::OnExpand) | |
61 | EVT_TREE_ITEM_COLLAPSED(wxID_ANY, wxRemotelyScrolledTreeCtrl::OnExpand) | |
62 | EVT_SCROLLWIN(wxRemotelyScrolledTreeCtrl::OnScroll) | |
63 | END_EVENT_TABLE() | |
64 | ||
65 | wxRemotelyScrolledTreeCtrl::wxRemotelyScrolledTreeCtrl( | |
66 | wxWindow* parent, wxWindowID id, const wxPoint& pt, | |
67 | const wxSize& sz, long style) | |
68 | : wxTreeCtrl(parent, id, pt, sz, style & ~wxTR_ROW_LINES) | |
69 | { | |
70 | m_companionWindow = NULL; | |
71 | ||
72 | // We draw the row lines ourself so they match what's done | |
73 | // by the companion window. That is why the flag is turned | |
74 | // off above, so wxGenericTreeCtrl doesn't draw them in a | |
75 | // different colour. | |
76 | m_drawRowLines = (style & wxTR_ROW_LINES) != 0; | |
77 | } | |
78 | ||
79 | wxRemotelyScrolledTreeCtrl::~wxRemotelyScrolledTreeCtrl() | |
80 | { | |
81 | } | |
82 | ||
83 | void wxRemotelyScrolledTreeCtrl::HideVScrollbar() | |
84 | { | |
85 | #if defined(__WXMSW__) | |
86 | #if USE_GENERIC_TREECTRL | |
87 | if (!IsKindOf(CLASSINFO(wxGenericTreeCtrl))) | |
88 | #endif | |
89 | { | |
90 | ::ShowScrollBar((HWND) GetHWND(), SB_VERT, false); | |
91 | } | |
92 | #if USE_GENERIC_TREECTRL | |
93 | else | |
94 | { | |
95 | // Implicit in overriding SetScrollbars | |
96 | } | |
97 | #endif | |
98 | #endif | |
99 | } | |
100 | ||
101 | // Number of pixels per user unit (0 or -1 for no scrollbar) | |
102 | // Length of virtual canvas in user units | |
103 | // Length of page in user units | |
104 | void wxRemotelyScrolledTreeCtrl::SetScrollbars( | |
105 | #if USE_GENERIC_TREECTRL || !defined(__WXMSW__) | |
106 | int pixelsPerUnitX, int pixelsPerUnitY, | |
107 | int noUnitsX, int noUnitsY, | |
108 | int xPos, int yPos, | |
109 | bool noRefresh | |
110 | #else | |
111 | int WXUNUSED(pixelsPerUnitX), int WXUNUSED(pixelsPerUnitY), | |
112 | int WXUNUSED(noUnitsX), int WXUNUSED(noUnitsY), | |
113 | int WXUNUSED(xPos), int WXUNUSED(yPos), | |
114 | bool WXUNUSED(noRefresh) | |
115 | #endif | |
116 | ) | |
117 | { | |
118 | #if USE_GENERIC_TREECTRL || !defined(__WXMSW__) | |
119 | if (IsKindOf(CLASSINFO(wxGenericTreeCtrl))) | |
120 | { | |
121 | wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this; | |
122 | win->wxGenericTreeCtrl::SetScrollbars(pixelsPerUnitX, pixelsPerUnitY, noUnitsX, 0, xPos, 0, /* noRefresh */ true); | |
123 | ||
124 | wxScrolledWindow* scrolledWindow = GetScrolledWindow(); | |
125 | if (scrolledWindow) | |
126 | { | |
127 | scrolledWindow->SetScrollbars(0, pixelsPerUnitY, 0, noUnitsY, 0, yPos, noRefresh); | |
128 | } | |
129 | } | |
130 | #endif | |
131 | } | |
132 | ||
133 | // In case we're using the generic tree control. | |
134 | int wxRemotelyScrolledTreeCtrl::GetScrollPos( | |
135 | #if USE_GENERIC_TREECTRL || !defined(__WXMSW__) | |
136 | int orient | |
137 | #else | |
138 | int WXUNUSED(orient) | |
139 | #endif | |
140 | ) const | |
141 | { | |
142 | ||
143 | #if USE_GENERIC_TREECTRL || !defined(__WXMSW__) | |
144 | // this condition fixes extsitence of warning but | |
145 | wxScrolledWindow* scrolledWindow = | |
146 | // but GetScrolledWindow is still executed in case internally does something | |
147 | #endif | |
148 | GetScrolledWindow(); | |
149 | ||
150 | #if USE_GENERIC_TREECTRL || !defined(__WXMSW__) | |
151 | if (IsKindOf(CLASSINFO(wxGenericTreeCtrl))) | |
152 | { | |
153 | wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this; | |
154 | ||
155 | if (orient == wxHORIZONTAL) | |
156 | return win->wxGenericTreeCtrl::GetScrollPos(orient); | |
157 | else | |
158 | { | |
159 | return scrolledWindow->GetScrollPos(orient); | |
160 | } | |
161 | } | |
162 | #endif | |
163 | return 0; | |
164 | } | |
165 | ||
166 | ||
167 | // In case we're using the generic tree control. | |
168 | // Get the view start | |
169 | void wxRemotelyScrolledTreeCtrl::GetViewStart(int *x, int *y) const | |
170 | { | |
171 | wxScrolledWindow* scrolledWindow = GetScrolledWindow(); | |
172 | ||
173 | #if USE_GENERIC_TREECTRL || !defined(__WXMSW__) | |
174 | if (IsKindOf(CLASSINFO(wxGenericTreeCtrl))) | |
175 | { | |
176 | ||
177 | wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this; | |
178 | int x1, y1, x2, y2; | |
179 | win->wxGenericTreeCtrl::GetViewStart(& x1, & y1); | |
180 | * x = x1; * y = y1; | |
181 | if (!scrolledWindow) | |
182 | return; | |
183 | ||
184 | scrolledWindow->GetViewStart(& x2, & y2); | |
185 | * y = y2; | |
186 | } | |
187 | else | |
188 | #endif | |
189 | { | |
190 | // x is wrong since the horizontal scrollbar is controlled by the | |
191 | // tree control, but we probably don't need it. | |
192 | scrolledWindow->GetViewStart(x, y); | |
193 | } | |
194 | } | |
195 | ||
196 | // In case we're using the generic tree control. | |
197 | void wxRemotelyScrolledTreeCtrl::PrepareDC( | |
198 | #if USE_GENERIC_TREECTRL || !defined(__WXMSW__) | |
199 | wxDC& dc | |
200 | #else | |
201 | wxDC& WXUNUSED(dc) | |
202 | #endif | |
203 | ) | |
204 | { | |
205 | #if USE_GENERIC_TREECTRL || !defined(__WXMSW__) | |
206 | if (IsKindOf(CLASSINFO(wxGenericTreeCtrl))) | |
207 | { | |
208 | wxScrolledWindow* scrolledWindow = GetScrolledWindow(); | |
209 | ||
210 | wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this; | |
211 | ||
212 | int startX, startY; | |
213 | GetViewStart(& startX, & startY); | |
214 | ||
215 | int xppu1, yppu1, xppu2, yppu2; | |
216 | win->wxGenericTreeCtrl::GetScrollPixelsPerUnit(& xppu1, & yppu1); | |
217 | scrolledWindow->GetScrollPixelsPerUnit(& xppu2, & yppu2); | |
218 | ||
219 | dc.SetDeviceOrigin( -startX * xppu1, -startY * yppu2 ); | |
220 | // dc.SetUserScale( win->GetScaleX(), win->GetScaleY() ); | |
221 | } | |
222 | #endif | |
223 | } | |
224 | ||
225 | // Scroll to the given line (in scroll units where each unit is | |
226 | // the height of an item) | |
227 | void wxRemotelyScrolledTreeCtrl::ScrollToLine(int WXUNUSED(posHoriz), int posVert) | |
228 | { | |
229 | #ifdef __WXMSW__ | |
230 | #if USE_GENERIC_TREECTRL | |
231 | if (!IsKindOf(CLASSINFO(wxGenericTreeCtrl))) | |
232 | #endif // USE_GENERIC_TREECTRL | |
233 | { | |
234 | UINT sbCode = SB_THUMBPOSITION; | |
235 | HWND vertScrollBar = 0; | |
236 | MSWDefWindowProc((WXUINT) WM_VSCROLL, MAKELONG(sbCode, posVert), (WXLPARAM) vertScrollBar); | |
237 | } | |
238 | #if USE_GENERIC_TREECTRL | |
239 | else | |
240 | #endif // USE_GENERIC_TREECTRL | |
241 | #endif // __WXMSW__ | |
242 | #if USE_GENERIC_TREECTRL || !defined(__WXMSW__) | |
243 | { | |
244 | wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this; | |
245 | win->Refresh(); | |
246 | /* Doesn't work yet because scrolling is ignored by Scroll | |
247 | int xppu, yppu; | |
248 | wxScrolledWindow* scrolledWindow = GetScrolledWindow(); | |
249 | if (scrolledWindow) | |
250 | { | |
251 | scrolledWindow->GetScrollPixelsPerUnit(& xppu, & yppu); | |
252 | win->Scroll(-1, posVert*yppu); | |
253 | } | |
254 | */ | |
255 | } | |
256 | #endif // USE_GENERIC_TREECTRL || !defined(__WXMSW__) | |
257 | wxUnusedVar(posVert); | |
258 | } | |
259 | ||
260 | void wxRemotelyScrolledTreeCtrl::OnSize(wxSizeEvent& event) | |
261 | { | |
262 | HideVScrollbar(); | |
263 | AdjustRemoteScrollbars(); | |
264 | event.Skip(); | |
265 | } | |
266 | ||
267 | void wxRemotelyScrolledTreeCtrl::OnExpand(wxTreeEvent& event) | |
268 | { | |
269 | AdjustRemoteScrollbars(); | |
270 | event.Skip(); | |
271 | ||
272 | // If we don't have this, we get some bits of lines still remaining | |
273 | if (event.GetEventType() == wxEVT_COMMAND_TREE_ITEM_COLLAPSED) | |
274 | Refresh(); | |
275 | ||
276 | // Pass on the event | |
277 | if (m_companionWindow) | |
278 | m_companionWindow->GetEventHandler()->ProcessEvent(event); | |
279 | } | |
280 | ||
281 | void wxRemotelyScrolledTreeCtrl::OnPaint(wxPaintEvent& event) | |
282 | { | |
283 | wxPaintDC dc(this); | |
284 | ||
285 | wxTreeCtrl::OnPaint(event); | |
286 | ||
287 | if (! m_drawRowLines) | |
288 | return; | |
289 | ||
290 | // Reset the device origin since it may have been set | |
291 | dc.SetDeviceOrigin(0, 0); | |
292 | ||
293 | wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID); | |
294 | dc.SetPen(pen); | |
295 | dc.SetBrush(* wxTRANSPARENT_BRUSH); | |
296 | ||
297 | wxSize clientSize = GetClientSize(); | |
298 | wxRect itemRect; | |
299 | wxTreeItemId h, lastH; | |
300 | for (h=GetFirstVisibleItem(); | |
301 | h.IsOk(); | |
302 | h=GetNextVisible(h)) | |
303 | { | |
304 | if (GetBoundingRect(h, itemRect)) | |
305 | { | |
306 | int cy = itemRect.GetTop(); | |
307 | dc.DrawLine(0, cy, clientSize.x, cy); | |
308 | lastH = h; | |
309 | } | |
310 | if (! IsVisible(h)) | |
311 | break; | |
312 | } | |
313 | if (lastH.IsOk() && GetBoundingRect(lastH, itemRect)) | |
314 | { | |
315 | int cy = itemRect.GetBottom(); | |
316 | dc.DrawLine(0, cy, clientSize.x, cy); | |
317 | } | |
318 | } | |
319 | ||
320 | ||
321 | // Adjust the containing wxScrolledWindow's scrollbars appropriately | |
322 | void wxRemotelyScrolledTreeCtrl::AdjustRemoteScrollbars() | |
323 | { | |
324 | #if USE_GENERIC_TREECTRL || !defined(__WXMSW__) | |
325 | if (IsKindOf(CLASSINFO(wxGenericTreeCtrl))) | |
326 | { | |
327 | // This is for the generic tree control. | |
328 | // It calls SetScrollbars which has been overridden | |
329 | // to adjust the parent scrolled window vertical | |
330 | // scrollbar. | |
331 | ((wxGenericTreeCtrl*) this)->AdjustMyScrollbars(); | |
332 | return; | |
333 | } | |
334 | else | |
335 | #endif | |
336 | { | |
337 | // This is for the wxMSW tree control | |
338 | wxScrolledWindow* scrolledWindow = GetScrolledWindow(); | |
339 | if (scrolledWindow) | |
340 | { | |
341 | wxRect itemRect; | |
342 | if (GetBoundingRect(GetFirstVisibleItem(), itemRect)) | |
343 | { | |
344 | // Actually, the real height seems to be 1 less than reported | |
345 | // (e.g. 16 instead of 16) | |
346 | int itemHeight = itemRect.GetHeight() - 1; | |
347 | ||
348 | int w, h; | |
349 | GetClientSize(&w, &h); | |
350 | ||
351 | wxRect rect(0, 0, 0, 0); | |
352 | CalcTreeSize(rect); | |
353 | ||
354 | double f = ((double) (rect.GetHeight()) / (double) itemHeight) ; | |
355 | int treeViewHeight = (int) ceil(f); | |
356 | ||
357 | int scrollPixelsPerLine = itemHeight; | |
358 | int scrollPos = - (itemRect.y / itemHeight); | |
359 | ||
360 | scrolledWindow->SetScrollbars(0, scrollPixelsPerLine, 0, treeViewHeight, 0, scrollPos); | |
361 | ||
362 | // Ensure that when a scrollbar becomes hidden or visible, | |
363 | // the contained window sizes are right. | |
364 | // Problem: this is called too early (?) | |
365 | wxSizeEvent event(scrolledWindow->GetSize(), scrolledWindow->GetId()); | |
366 | scrolledWindow->GetEventHandler()->ProcessEvent(event); | |
367 | } | |
368 | } | |
369 | } | |
370 | } | |
371 | ||
372 | ||
373 | // Calculate the area that contains both rectangles | |
374 | static wxRect CombineRectangles(const wxRect& rect1, const wxRect& rect2) | |
375 | { | |
376 | wxRect rect; | |
377 | ||
378 | int right1 = rect1.GetRight(); | |
379 | int bottom1 = rect1.GetBottom(); | |
380 | int right2 = rect2.GetRight(); | |
381 | int bottom2 = rect2.GetBottom(); | |
382 | ||
383 | wxPoint topLeft = wxPoint(wxMin(rect1.x, rect2.x), wxMin(rect1.y, rect2.y)); | |
384 | wxPoint bottomRight = wxPoint(wxMax(right1, right2), wxMax(bottom1, bottom2)); | |
385 | ||
386 | rect.x = topLeft.x; rect.y = topLeft.y; | |
387 | rect.SetRight(bottomRight.x); | |
388 | rect.SetBottom(bottomRight.y); | |
389 | ||
390 | return rect; | |
391 | } | |
392 | ||
393 | ||
394 | // Calculate the tree overall size so we can set the scrollbar | |
395 | // correctly | |
396 | void wxRemotelyScrolledTreeCtrl::CalcTreeSize(wxRect& rect) | |
397 | { | |
398 | CalcTreeSize(GetRootItem(), rect); | |
399 | } | |
400 | ||
401 | void wxRemotelyScrolledTreeCtrl::CalcTreeSize(const wxTreeItemId& id, wxRect& rect) | |
402 | { | |
403 | // More efficient implementation would be to find the last item (but how?) | |
404 | // Q: is the bounding rect relative to the top of the virtual tree workspace | |
405 | // or the top of the window? How would we convert? | |
406 | wxRect itemSize; | |
407 | if (GetBoundingRect(id, itemSize)) | |
408 | { | |
409 | rect = CombineRectangles(rect, itemSize); | |
410 | } | |
411 | ||
412 | wxTreeItemIdValue cookie; | |
413 | wxTreeItemId childId = GetFirstChild(id, cookie); | |
414 | while (childId) | |
415 | { | |
416 | CalcTreeSize(childId, rect); | |
417 | childId = GetNextChild(childId, cookie); | |
418 | } | |
419 | } | |
420 | ||
421 | // Find the scrolled window that contains this control | |
422 | wxScrolledWindow* wxRemotelyScrolledTreeCtrl::GetScrolledWindow() const | |
423 | { | |
424 | wxWindow* parent = wxWindow::GetParent(); | |
425 | while (parent) | |
426 | { | |
427 | if (parent->IsKindOf(CLASSINFO(wxScrolledWindow))) | |
428 | return (wxScrolledWindow*) parent; | |
429 | parent = parent->GetParent(); | |
430 | } | |
431 | return NULL; | |
432 | } | |
433 | ||
434 | void wxRemotelyScrolledTreeCtrl::OnScroll(wxScrollWinEvent& event) | |
435 | { | |
436 | int orient = event.GetOrientation(); | |
437 | if (orient == wxHORIZONTAL) | |
438 | { | |
439 | event.Skip(); | |
440 | return; | |
441 | } | |
442 | wxScrolledWindow* scrollWin = GetScrolledWindow(); | |
443 | if (!scrollWin) | |
444 | return; | |
445 | ||
446 | int x, y; | |
447 | scrollWin->GetViewStart(& x, & y); | |
448 | ||
449 | ScrollToLine(-1, y); | |
450 | } | |
451 | ||
452 | /* | |
453 | * wxTreeCompanionWindow | |
454 | * | |
455 | * A window displaying values associated with tree control items. | |
456 | */ | |
457 | ||
458 | IMPLEMENT_CLASS(wxTreeCompanionWindow, wxWindow) | |
459 | ||
460 | BEGIN_EVENT_TABLE(wxTreeCompanionWindow, wxWindow) | |
461 | EVT_PAINT(wxTreeCompanionWindow::OnPaint) | |
462 | EVT_SCROLLWIN(wxTreeCompanionWindow::OnScroll) | |
463 | EVT_TREE_ITEM_EXPANDED(-1, wxTreeCompanionWindow::OnExpand) | |
464 | EVT_TREE_ITEM_COLLAPSED(-1, wxTreeCompanionWindow::OnExpand) | |
465 | END_EVENT_TABLE() | |
466 | ||
467 | wxTreeCompanionWindow::wxTreeCompanionWindow(wxWindow* parent, wxWindowID id, | |
468 | const wxPoint& pos, | |
469 | const wxSize& sz, | |
470 | long style): | |
471 | wxWindow(parent, id, pos, sz, style) | |
472 | { | |
473 | m_treeCtrl = NULL; | |
474 | } | |
475 | ||
476 | void wxTreeCompanionWindow::DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect) | |
477 | { | |
478 | // TEST CODE | |
479 | #if 1 | |
480 | if (m_treeCtrl) | |
481 | { | |
482 | wxString text = m_treeCtrl->GetItemText(id); | |
483 | dc.SetTextForeground(* wxBLACK); | |
484 | dc.SetBackgroundMode(wxTRANSPARENT); | |
485 | ||
486 | int textW, textH; | |
487 | dc.GetTextExtent(text, & textW, & textH); | |
488 | ||
489 | int x = 5; | |
490 | int y = rect.GetY() + wxMax(0, (rect.GetHeight() - textH) / 2); | |
491 | ||
492 | dc.DrawText(text, x, y); | |
493 | } | |
494 | #endif | |
495 | } | |
496 | ||
497 | void wxTreeCompanionWindow::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
498 | { | |
499 | wxPaintDC dc(this); | |
500 | ||
501 | if (!m_treeCtrl) | |
502 | return; | |
503 | ||
504 | wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID); | |
505 | dc.SetPen(pen); | |
506 | dc.SetBrush(* wxTRANSPARENT_BRUSH); | |
507 | wxFont font(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
508 | dc.SetFont(font); | |
509 | ||
510 | wxSize clientSize = GetClientSize(); | |
511 | wxRect itemRect; | |
512 | wxTreeItemId h, lastH; | |
513 | for (h=m_treeCtrl->GetFirstVisibleItem(); | |
514 | h.IsOk(); | |
515 | h=m_treeCtrl->GetNextVisible(h)) | |
516 | { | |
517 | if (m_treeCtrl->GetBoundingRect(h, itemRect)) | |
518 | { | |
519 | int cy = itemRect.GetTop(); | |
520 | wxRect drawItemRect(0, cy, clientSize.x, itemRect.GetHeight()); | |
521 | ||
522 | lastH = h; | |
523 | ||
524 | // Draw the actual item | |
525 | DrawItem(dc, h, drawItemRect); | |
526 | dc.DrawLine(0, cy, clientSize.x, cy); | |
527 | } | |
528 | if (! m_treeCtrl->IsVisible(h)) | |
529 | break; | |
530 | } | |
531 | if (lastH.IsOk() && m_treeCtrl->GetBoundingRect(lastH, itemRect)) | |
532 | { | |
533 | int cy = itemRect.GetBottom(); | |
534 | dc.DrawLine(0, cy, clientSize.x, cy); | |
535 | } | |
536 | } | |
537 | ||
538 | void wxTreeCompanionWindow::OnScroll(wxScrollWinEvent& event) | |
539 | { | |
540 | int orient = event.GetOrientation(); | |
541 | if (orient == wxHORIZONTAL) | |
542 | { | |
543 | event.Skip(); | |
544 | return; | |
545 | } | |
546 | if (!m_treeCtrl) | |
547 | return; | |
548 | ||
549 | // TODO: scroll the window physically instead of just refreshing. | |
550 | Refresh(true); | |
551 | } | |
552 | ||
553 | void wxTreeCompanionWindow::OnExpand(wxTreeEvent& WXUNUSED(event)) | |
554 | { | |
555 | // TODO: something more optimized than simply refresh the whole | |
556 | // window when the tree is expanded/collapsed. Tricky. | |
557 | Refresh(); | |
558 | } | |
559 | ||
560 | /* | |
561 | * wxThinSplitterWindow | |
562 | */ | |
563 | ||
564 | IMPLEMENT_CLASS(wxThinSplitterWindow, wxSplitterWindow) | |
565 | ||
566 | BEGIN_EVENT_TABLE(wxThinSplitterWindow, wxSplitterWindow) | |
567 | EVT_SIZE(wxThinSplitterWindow::OnSize) | |
568 | END_EVENT_TABLE() | |
569 | ||
570 | wxThinSplitterWindow::wxThinSplitterWindow(wxWindow* parent, wxWindowID id, | |
571 | const wxPoint& pos, | |
572 | const wxSize& sz, | |
573 | long style): | |
574 | wxSplitterWindow(parent, id, pos, sz, style) | |
575 | { | |
576 | wxColour faceColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); | |
577 | m_facePen = new wxPen(faceColour, 1, wxSOLID); | |
578 | m_faceBrush = new wxBrush(faceColour, wxSOLID); | |
579 | } | |
580 | ||
581 | wxThinSplitterWindow::~wxThinSplitterWindow() | |
582 | { | |
583 | delete m_facePen; | |
584 | delete m_faceBrush; | |
585 | } | |
586 | ||
587 | ||
588 | void wxThinSplitterWindow::SizeWindows() | |
589 | { | |
590 | // The client size may have changed inbetween | |
591 | // the sizing of the first window and the sizing of | |
592 | // the second. So repeat SizeWindows. | |
593 | wxSplitterWindow::SizeWindows(); | |
594 | wxSplitterWindow::SizeWindows(); | |
595 | } | |
596 | ||
597 | // Tests for x, y over sash | |
598 | bool wxThinSplitterWindow::SashHitTest(int x, int y, int WXUNUSED(tolerance)) | |
599 | { | |
600 | return wxSplitterWindow::SashHitTest(x, y, 4); | |
601 | } | |
602 | ||
603 | void wxThinSplitterWindow::DrawSash(wxDC& dc) | |
604 | { | |
605 | if ( m_sashPosition == 0 || !m_windowTwo) | |
606 | return; | |
607 | if (GetWindowStyle() & wxSP_NOSASH) | |
608 | return; | |
609 | ||
610 | int w, h; | |
611 | GetClientSize(&w, &h); | |
612 | ||
613 | if ( m_splitMode == wxSPLIT_VERTICAL ) | |
614 | { | |
615 | dc.SetPen(* m_facePen); | |
616 | dc.SetBrush(* m_faceBrush); | |
617 | int h1 = h-1; | |
618 | int y1 = 0; | |
619 | if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER ) | |
620 | h1 += 1; // Not sure why this is necessary... | |
621 | if ( (GetWindowStyleFlag() & wxSP_3DBORDER) == wxSP_3DBORDER) | |
622 | { | |
623 | y1 = 2; h1 -= 3; | |
624 | } | |
625 | dc.DrawRectangle(m_sashPosition, y1, GetSashSize(), h1); | |
626 | } | |
627 | else | |
628 | { | |
629 | dc.SetPen(* m_facePen); | |
630 | dc.SetBrush(* m_faceBrush); | |
631 | int w1 = w-1; | |
632 | int x1 = 0; | |
633 | if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER ) | |
634 | w1 ++; | |
635 | if ( (GetWindowStyleFlag() & wxSP_3DBORDER) == wxSP_3DBORDER) | |
636 | { | |
637 | x1 = 2; w1 -= 3; | |
638 | } | |
639 | dc.DrawRectangle(x1, m_sashPosition, w1, GetSashSize()); | |
640 | } | |
641 | ||
642 | dc.SetPen(wxNullPen); | |
643 | dc.SetBrush(wxNullBrush); | |
644 | } | |
645 | ||
646 | void wxThinSplitterWindow::OnSize(wxSizeEvent& event) | |
647 | { | |
648 | wxSplitterWindow::OnSize(event); | |
649 | } | |
650 | ||
651 | /* | |
652 | * wxSplitterScrolledWindow | |
653 | */ | |
654 | ||
655 | IMPLEMENT_CLASS(wxSplitterScrolledWindow, wxScrolledWindow) | |
656 | ||
657 | BEGIN_EVENT_TABLE(wxSplitterScrolledWindow, wxScrolledWindow) | |
658 | EVT_SCROLLWIN(wxSplitterScrolledWindow::OnScroll) | |
659 | EVT_SIZE(wxSplitterScrolledWindow::OnSize) | |
660 | END_EVENT_TABLE() | |
661 | ||
662 | wxSplitterScrolledWindow::wxSplitterScrolledWindow(wxWindow* parent, wxWindowID id, | |
663 | const wxPoint& pos, | |
664 | const wxSize& sz, | |
665 | long style): | |
666 | wxScrolledWindow(parent, id, pos, sz, style) | |
667 | { | |
668 | } | |
669 | ||
670 | void wxSplitterScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event)) | |
671 | { | |
672 | wxSize sz = GetClientSize(); | |
673 | if (GetChildren().GetFirst()) | |
674 | { | |
675 | ((wxWindow*) GetChildren().GetFirst()->GetData())->SetSize(0, 0, sz.x, sz.y); | |
676 | } | |
677 | } | |
678 | ||
679 | void wxSplitterScrolledWindow::OnScroll(wxScrollWinEvent& event) | |
680 | { | |
681 | // Ensure that events being propagated back up the window hierarchy | |
682 | // don't cause an infinite loop | |
683 | static bool inOnScroll = false; | |
684 | if (inOnScroll) | |
685 | { | |
686 | event.Skip(); | |
687 | return; | |
688 | } | |
689 | inOnScroll = true; | |
690 | ||
691 | int orient = event.GetOrientation(); | |
692 | ||
693 | int nScrollInc = CalcScrollInc(event); | |
694 | if (nScrollInc == 0) | |
695 | { | |
696 | inOnScroll = false; | |
697 | return; | |
698 | } | |
699 | ||
700 | if (orient == wxHORIZONTAL) | |
701 | { | |
702 | inOnScroll = false; | |
703 | event.Skip(); | |
704 | return; | |
705 | #if 0 | |
706 | int newPos = m_xScrollPosition + nScrollInc; | |
707 | SetScrollPos(wxHORIZONTAL, newPos, true ); | |
708 | #endif | |
709 | } | |
710 | else | |
711 | { | |
712 | int newPos = m_yScrollPosition + nScrollInc; | |
713 | SetScrollPos(wxVERTICAL, newPos, true ); | |
714 | } | |
715 | ||
716 | if (orient == wxHORIZONTAL) | |
717 | { | |
718 | m_xScrollPosition += nScrollInc; | |
719 | } | |
720 | else | |
721 | { | |
722 | m_yScrollPosition += nScrollInc; | |
723 | } | |
724 | ||
725 | // Find targets in splitter window and send the event to them | |
726 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
727 | while (node) | |
728 | { | |
729 | wxWindow* child = (wxWindow*) node->GetData(); | |
730 | if (child->IsKindOf(CLASSINFO(wxSplitterWindow))) | |
731 | { | |
732 | wxSplitterWindow* splitter = (wxSplitterWindow*) child; | |
733 | if (splitter->GetWindow1()) | |
734 | splitter->GetWindow1()->ProcessEvent(event); | |
735 | if (splitter->GetWindow2()) | |
736 | splitter->GetWindow2()->ProcessEvent(event); | |
737 | break; | |
738 | } | |
739 | node = node->GetNext(); | |
740 | } | |
741 | ||
742 | m_targetWindow->Update() ; | |
743 | ||
744 | inOnScroll = false; | |
745 | } |