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