1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
27 //===========================================================================
28 //#####DESCRIPTIONBEGIN####
31 // Contact(s): julians
33 // Version: $Id: configtree.h,v 1.5 2001/04/09 12:51:34 julians Exp $
35 // Description: Header file for ecConfigTreeCtrl
42 //####DESCRIPTIONEND####
44 //===========================================================================
46 #ifndef _ECOS_CONFIGTREE_H_
47 #define _ECOS_CONFIGTREE_H_
50 #pragma interface "configtree.h"
54 #include "splittree.h"
55 #include "configitem.h"
57 #define wxMAX_ICON_STATES 4
61 The idea behind wxIconStateInfo, wxIconStateInfoDB
62 is to associate multiple state icons with items in tree controls
63 (and potentially other controls).
65 So instead of having to remember a lot of image list ids,
66 you have a named state info object which contains up to 4 different states
67 (identified by the integers 0 - 3). Each of these states can
68 be in a further 2 sub-states - enabled or disabled.
70 wxIconStateDB holds a list of these state info objects
71 and has a convenient API. For example, the following adds
72 icons for a checkbox item that can be: on/enabled, off/enabled,
73 on/disabled,off/disabled.
75 m_iconDB.AddInfo("Checkbox", wxICON(checked), 0, TRUE);
76 m_iconDB.AddInfo("Checkbox", wxICON(checked_dis), 0, FALSE);
77 m_iconDB.AddInfo("Checkbox", wxICON(unchecked), 1, TRUE);
78 m_iconDB.AddInfo("Checkbox", wxICON(unchecked_dis), 1, FALSE);
80 When you update the item image in response to (e.g.) user interaction,
81 you can say something like this:
83 int iconId = m_iconDB.GetIconId("Checkbox", 0, FALSE);
85 treeCtrl.SetItemImage(itemId, iconId, wxTreeItemIcon_Normal);
86 treeCtrl.SetItemImage(itemId, iconId, wxTreeItemIcon_Selected);
88 See configitem.cpp for further examples.
90 These two classes are prefixed 'wx' because they are generic and may
97 * Stores information about the visual state of an item in a tree control
100 class wxIconStateInfo: public wxObject
103 wxIconStateInfo(const wxString& name);
105 // How many states? (Each state
106 // has enabled/disabled state)
107 // Max (say) 4 states, each with
109 int GetStateCount() const { return m_maxStates; };
111 void SetStateCount(int count) { m_maxStates; }
112 int GetIconId(int state, bool enabled = TRUE) const;
113 void SetIconId(int state, bool enabled, int iconId);
115 const wxString& GetName() const { return m_name; }
119 int m_states[wxMAX_ICON_STATES * 2]; // Enabled/disabled
120 wxString m_name; // Name of icon, e.g. "Package"
125 * Contains a list of wxIconStateInfos
128 class wxIconStateInfoDB: public wxList
131 wxIconStateInfoDB(wxImageList* imageList = NULL);
133 void AppendInfo(wxIconStateInfo* info);
135 // Easy way of initialising both the image list and the
136 // info db. It will generate image ids itself while appending the icon.
137 // 'state' is an integer from 0 up to the max allowed, representing a different
138 // state. There may be only one, or (for a checkbox) there may be two.
139 // A folder that can be open or closed would have two states.
140 // Enabled/disabled is taken as a special case.
141 bool AddInfo(const wxString& name, const wxIcon& icon, int state, bool enabled);
143 wxIconStateInfo* FindInfo(const wxString& name) const;
145 int GetIconId(const wxString& name, int state, bool enabled = TRUE) const;
146 bool SetIconId(const wxString& name, int state, bool enabled, int iconId) ;
148 void SetImageList(wxImageList* imageList) { m_imageList = imageList; }
149 wxImageList* GetImageList() const { return m_imageList; }
152 wxImageList* m_imageList;
157 * This holds an association between the tree control item
158 * and the ecConfigItem.
162 class ecTreeItemData : public wxTreeItemData
165 ecTreeItemData(ecConfigItem* item) : m_configItem(item) { }
166 ~ecTreeItemData() { if (m_configItem) delete m_configItem; }
168 ecConfigItem *GetConfigItem() const { return m_configItem; }
169 void SetConfigItem(ecConfigItem *item) { m_configItem = item; }
172 ecConfigItem* m_configItem;
178 * This control represents the configuration hierarchy.
179 * It's derived from wxRemotelyScrolledTreeCtrl because we want
180 * to synchronize the tree scrolling with the value window scrolling,
181 * and have the scrollbar on the right-hand-side of the value window
182 * (not the tree control).
186 class ecConfigTreeCtrl: public wxRemotelyScrolledTreeCtrl
188 DECLARE_CLASS(ecConfigTreeCtrl)
190 ecConfigTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt = wxDefaultPosition,
191 const wxSize& sz = wxDefaultSize, long style = wxTR_HAS_BUTTONS);
195 void OnPaint(wxPaintEvent& event);
196 void OnMouseEvent(wxMouseEvent& event);
197 void OnSelChanged(wxTreeEvent& event);
198 void OnCollapseExpand(wxTreeEvent& event);
199 void OnHelp(wxHelpEvent& event);
200 void OnKeyDown(wxKeyEvent& event);
203 wxIconStateInfoDB& GetIconDB() { return m_iconDB; }
204 wxMenu* GetPropertiesMenu() const { return m_propertiesMenu; }
210 wxImageList* m_imageList;
211 wxIconStateInfoDB m_iconDB;
212 wxMenu* m_propertiesMenu;
214 DECLARE_EVENT_TABLE()
219 * This window represents the values associated with the configuration tree.
220 * It scrolls synchronously with the tree control.
223 class ecValueWindow: public wxTreeCompanionWindow
226 ecValueWindow(wxWindow* parent, wxWindowID id = -1,
227 const wxPoint& pos = wxDefaultPosition,
228 const wxSize& sz = wxDefaultSize,
232 virtual void DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect);
235 void OnPaint(wxPaintEvent& event);
236 void OnMouseEvent(wxMouseEvent& event);
237 void OnScroll(wxScrollWinEvent& event);
238 void OnExpand(wxTreeEvent& event);
241 wxWindow* GetEditWindow() const { return m_editWindow; }
245 bool BeginEditing(ecConfigItem* item);
247 void PositionEditWindow();
248 wxRect GetItemRect(ecConfigItem* item);
250 ecConfigItem* GetCurrentConfigItem() const { return m_configItem; }
254 wxWindow* m_editWindow; // Edit control
255 ecConfigItem* m_configItem; // Item being edited
257 DECLARE_EVENT_TABLE()
258 DECLARE_CLASS(ecValueWindow)
262 * ecSplitterScrolledWindow
263 * This window holds the tree and value windows.
264 * We derive a new class mainly to intercept popup menu commands from both child windows
265 * without resorting to placing their handlers in the main frame.
268 class ecSplitterScrolledWindow: public wxSplitterScrolledWindow
271 ecSplitterScrolledWindow(wxWindow* parent, wxWindowID id, const wxPoint& pt = wxDefaultPosition,
272 const wxSize& sz = wxDefaultSize, long style = wxVSCROLL):
273 wxSplitterScrolledWindow(parent, id, pt, sz, style)
278 void OnWhatsThis(wxCommandEvent& event);
279 void OnProperties(wxCommandEvent& event);
280 void OnRestoreDefaults(wxCommandEvent& event);
281 void OnVisitDoc(wxCommandEvent& event);
282 void OnViewHeader(wxCommandEvent& event);
283 void OnUnloadPackage(wxCommandEvent& event);
285 void OnUpdateRestoreDefaults(wxUpdateUIEvent& event);
286 void OnUpdateVisitDoc(wxUpdateUIEvent& event);
287 void OnUpdateViewHeader(wxUpdateUIEvent& event);
288 void OnUpdateUnloadPackage(wxUpdateUIEvent& event);
291 void RestoreDefault(wxTreeItemId h, bool bRecurse = FALSE, bool bTopLevel = TRUE);
292 bool IsChanged(wxTreeItemId h, bool bRecurse);
294 DECLARE_EVENT_TABLE()
299 // _ECOS_CONFIGTREE_H_