1 /////////////////////////////////////////////////////////////////////////////
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
6 // Author: Julian Smart
10 // Copyright: (c) Julian Smart
12 // This program is part of the eCos host tools.
14 // This program is free software; you can redistribute it and/or modify it
15 // under the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 of the License, or (at your option)
19 // This program is distributed in the hope that it will be useful, but WITHOUT
20 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
24 // You should have received a copy of the GNU General Public License along with
25 // this program; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 /////////////////////////////////////////////////////////////////////////////
30 #ifndef _WX_SPLITTREE_H_
31 #define _WX_SPLITTREE_H_
34 #pragma interface "splittree.cpp"
37 // Set this to 1 to use generic tree control (doesn't yet work properly)
38 #define USE_GENERIC_TREECTRL 0
41 #include "wx/treectrl.h"
42 #include "wx/splitter.h"
43 #include "ecscrolwin.h"
45 #if USE_GENERIC_TREECTRL
46 #include "wx/generic/treectlg.h"
48 #define wxTreeCtrl wxGenericTreeCtrl
49 #define sm_classwxTreeCtrl sm_classwxGenericTreeCtrl
53 class wxRemotelyScrolledTreeCtrl;
54 class wxThinSplitterWindow;
55 class wxSplitterScrolledWindow;
58 * wxRemotelyScrolledTreeCtrl
60 * This tree control disables its vertical scrollbar and catches scroll
61 * events passed by a scrolled window higher in the hierarchy.
62 * It also updates the scrolled window vertical scrollbar as appropriate.
65 class wxRemotelyScrolledTreeCtrl: public wxTreeCtrl
67 DECLARE_CLASS(wxRemotelyScrolledTreeCtrl)
69 wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt = wxDefaultPosition,
70 const wxSize& sz = wxDefaultSize, long style = wxTR_HAS_BUTTONS);
71 ~wxRemotelyScrolledTreeCtrl();
74 void OnSize(wxSizeEvent& event);
75 void OnExpand(wxTreeEvent& event);
76 void OnScroll(wxScrollWinEvent& event);
79 // Override this in case we're using the generic tree control.
80 // Calls to this should disable the vertical scrollbar.
82 // Number of pixels per user unit (0 or -1 for no scrollbar)
83 // Length of virtual canvas in user units
84 // Length of page in user units
85 virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
86 int noUnitsX, int noUnitsY,
87 int xPos = 0, int yPos = 0,
88 bool noRefresh = FALSE );
90 // In case we're using the generic tree control.
92 virtual void GetViewStart(int *x, int *y) const;
94 // In case we're using the generic tree control.
95 virtual void PrepareDC(wxDC& dc);
97 // In case we're using the generic tree control.
98 virtual int GetScrollPos(int orient) const;
101 void HideVScrollbar();
103 // Calculate the tree overall size so we can set the scrollbar
105 void CalcTreeSize(wxRect& rect);
106 void CalcTreeSize(const wxTreeItemId& id, wxRect& rect);
108 // Adjust the containing wxScrolledWindow's scrollbars appropriately
109 void AdjustRemoteScrollbars();
111 // Find the scrolled window that contains this control
112 ecScrolledWindow* GetScrolledWindow() const;
114 // Scroll to the given line (in scroll units where each unit is
115 // the height of an item)
116 void ScrollToLine(int posHoriz, int posVert);
120 // The companion window is one which will get notified when certain
121 // events happen such as node expansion
122 void SetCompanionWindow(wxWindow* companion) { m_companionWindow = companion; }
123 wxWindow* GetCompanionWindow() const { return m_companionWindow; }
126 DECLARE_EVENT_TABLE()
128 wxWindow* m_companionWindow;
132 * wxTreeCompanionWindow
134 * A window displaying values associated with tree control items.
137 class wxTreeCompanionWindow: public wxWindow
140 DECLARE_CLASS(wxTreeCompanionWindow)
142 wxTreeCompanionWindow(wxWindow* parent, wxWindowID id = -1,
143 const wxPoint& pos = wxDefaultPosition,
144 const wxSize& sz = wxDefaultSize,
148 virtual void DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect);
151 void OnPaint(wxPaintEvent& event);
152 void OnScroll(wxScrollWinEvent& event);
153 void OnExpand(wxTreeEvent& event);
158 wxRemotelyScrolledTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; };
159 void SetTreeCtrl(wxRemotelyScrolledTreeCtrl* treeCtrl) { m_treeCtrl = treeCtrl; }
163 wxRemotelyScrolledTreeCtrl* m_treeCtrl;
165 DECLARE_EVENT_TABLE()
170 * wxThinSplitterWindow
172 * Implements a splitter with a less obvious sash
173 * than the usual one.
176 class wxThinSplitterWindow: public wxSplitterWindow
179 DECLARE_DYNAMIC_CLASS(wxThinSplitterWindow)
181 wxThinSplitterWindow(wxWindow* parent, wxWindowID id = -1,
182 const wxPoint& pos = wxDefaultPosition,
183 const wxSize& sz = wxDefaultSize,
184 long style = wxSP_3D | wxCLIP_CHILDREN);
189 // Tests for x, y over sash. Overriding this allows us to increase
191 bool SashHitTest(int x, int y, int tolerance = 2);
192 void DrawSash(wxDC& dc);
196 void OnSize(wxSizeEvent& event);
204 DECLARE_EVENT_TABLE()
208 * wxSplitterScrolledWindow
210 * This scrolled window is aware of the fact that one of its
211 * children is a splitter window. It passes on its scroll events
212 * (after some processing) to both splitter children for them
213 * scroll appropriately.
216 class wxSplitterScrolledWindow: public ecScrolledWindow
219 DECLARE_DYNAMIC_CLASS(wxSplitterScrolledWindow)
221 wxSplitterScrolledWindow(wxWindow* parent, wxWindowID id = -1,
222 const wxPoint& pos = wxDefaultPosition,
223 const wxSize& sz = wxDefaultSize,
230 void OnScroll(wxScrollWinEvent& event);
231 void OnSize(wxSizeEvent& event);
239 DECLARE_EVENT_TABLE()