]> git.saurik.com Git - wxWidgets.git/blob - utils/configtool/src/configtree.cpp
Added first cut wxWindows Configuration Tool
[wxWidgets.git] / utils / configtool / src / configtree.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: configtree.h
3 // Purpose: wxWindows Configuration Tool tree class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2003-06-03
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence:
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "configtree.h"
14 #endif
15
16 // Includes other headers for precompiled compilation
17 #include "wx/wx.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #include "wx/imaglist.h"
24 #include "wx/cshelp.h"
25
26 // Include XPM icons
27 #include "bitmaps/folder1.xpm"
28
29 #include "bitmaps/closedfolder.xpm"
30 #include "bitmaps/closedfolder_dis.xpm"
31
32 #include "bitmaps/checked.xpm"
33 #include "bitmaps/checked_dis.xpm"
34 #include "bitmaps/unchecked.xpm"
35 #include "bitmaps/unchecked_dis.xpm"
36
37 #include "bitmaps/radioon.xpm"
38 #include "bitmaps/radioon_dis.xpm"
39 #include "bitmaps/radiooff.xpm"
40 #include "bitmaps/radiooff_dis.xpm"
41
42 #include "bitmaps/checkedfolder.xpm"
43 #include "bitmaps/checkedfolder_dis.xpm"
44 #include "bitmaps/uncheckedfolder.xpm"
45 #include "bitmaps/uncheckedfolder_dis.xpm"
46
47 #include "bitmaps/radiofolderon.xpm"
48 #include "bitmaps/radiofolderon_dis.xpm"
49 #include "bitmaps/radiofolderoff.xpm"
50 #include "bitmaps/radiofolderoff_dis.xpm"
51
52 #include "configtree.h"
53 #include "configtooldoc.h"
54 #include "configtoolview.h"
55 #include "wxconfigtool.h"
56 #include "mainframe.h"
57
58 /*
59 * ctConfigTreeCtrl
60 */
61
62 IMPLEMENT_CLASS(ctConfigTreeCtrl, wxTreeCtrl)
63
64 BEGIN_EVENT_TABLE(ctConfigTreeCtrl, wxTreeCtrl)
65 EVT_MOUSE_EVENTS(ctConfigTreeCtrl::OnMouseEvent)
66 EVT_CHAR(ctConfigTreeCtrl::OnKeyDown)
67 EVT_TREE_SEL_CHANGED(-1, ctConfigTreeCtrl::OnSelChanged)
68 EVT_HELP(-1, ctConfigTreeCtrl::OnHelp)
69 END_EVENT_TABLE()
70
71 ctConfigTreeCtrl::ctConfigTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt,
72 const wxSize& sz, long style):
73 wxTreeCtrl(parent, id, pt, sz, style)
74 {
75 LoadIcons();
76
77 m_contextMenu = NULL;
78 m_contextMenu = new wxMenu;
79
80 m_contextMenu->Append(ctID_TREE_PASTE_BEFORE, _("Paste &before this option"));
81 m_contextMenu->Append(ctID_TREE_PASTE_AFTER, _("Paste &after this option"));
82 m_contextMenu->Append(ctID_TREE_PASTE_AS_CHILD, _("Paste as &child of this option"));
83 m_contextMenu->AppendSeparator();
84 m_contextMenu->Append(ctID_TREE_COPY, _("C&opy"));
85 m_contextMenu->Append(ctID_TREE_CUT, _("Cu&t"));
86
87 SetHelpText(_("This shows configuration settings that you can enable and disable."));
88 }
89
90 // Load the icons and initialize the tree
91 void ctConfigTreeCtrl::LoadIcons()
92 {
93 m_imageList = new wxImageList(16, 16, TRUE);
94 m_iconTable.SetImageList(m_imageList);
95 SetImageList(m_imageList);
96
97 m_iconTable.AddInfo("Group", wxIcon(closedfolder_xpm), 0, TRUE);
98 m_iconTable.AddInfo("Group", wxIcon(closedfolder_dis_xpm), 0, FALSE);
99
100 m_iconTable.AddInfo("Checkbox", wxIcon(checked_xpm), 0, TRUE);
101 m_iconTable.AddInfo("Checkbox", wxIcon(checked_dis_xpm), 0, FALSE);
102 m_iconTable.AddInfo("Checkbox", wxIcon(unchecked_xpm), 1, TRUE);
103 m_iconTable.AddInfo("Checkbox", wxIcon(unchecked_dis_xpm), 1, FALSE);
104
105 m_iconTable.AddInfo("CheckGroup", wxIcon(checkedfolder_xpm), 0, TRUE);
106 m_iconTable.AddInfo("CheckGroup", wxIcon(checkedfolder_dis_xpm), 0, FALSE);
107 m_iconTable.AddInfo("CheckGroup", wxIcon(uncheckedfolder_xpm), 1, TRUE);
108 m_iconTable.AddInfo("CheckGroup", wxIcon(uncheckedfolder_dis_xpm), 1, FALSE);
109
110 m_iconTable.AddInfo("RadioGroup", wxIcon(radiofolderon_xpm), 0, TRUE);
111 m_iconTable.AddInfo("RadioGroup", wxIcon(radiofolderon_dis_xpm), 0, FALSE);
112 m_iconTable.AddInfo("RadioGroup", wxIcon(radiofolderoff_xpm), 1, TRUE);
113 m_iconTable.AddInfo("RadioGroup", wxIcon(radiofolderoff_dis_xpm), 1, FALSE);
114
115 m_iconTable.AddInfo("Radiobutton", wxIcon(radioon_xpm), 0, TRUE);
116 m_iconTable.AddInfo("Radiobutton", wxIcon(radioon_dis_xpm), 0, FALSE);
117 m_iconTable.AddInfo("Radiobutton", wxIcon(radiooff_xpm), 1, TRUE);
118 m_iconTable.AddInfo("Radiobutton", wxIcon(radiooff_dis_xpm), 1, FALSE);
119 }
120
121 ctConfigTreeCtrl::~ctConfigTreeCtrl()
122 {
123 SetImageList(NULL);
124 delete m_imageList;
125
126 delete m_contextMenu;
127 }
128
129 void ctConfigTreeCtrl::OnSelChanged(wxTreeEvent& event)
130 {
131 ctConfigToolDoc* doc = wxGetApp().GetMainFrame()->GetDocument();
132 if (doc)
133 {
134 ctConfigToolHint hint(NULL, ctSelChanged);
135 doc->UpdateAllViews(NULL, & hint);
136 }
137 }
138
139 void ctConfigTreeCtrl::OnMouseEvent(wxMouseEvent& event)
140 {
141 int flags = 0;
142 wxTreeItemId item = HitTest(wxPoint(event.GetX(), event.GetY()), flags);
143
144 if (event.LeftDown())
145 {
146 if (flags & wxTREE_HITTEST_ONITEMICON)
147 {
148 ctTreeItemData* data = (ctTreeItemData*) GetItemData(item);
149 ctConfigToolDoc* doc = wxGetApp().GetMainFrame()->GetDocument();
150 if (doc)
151 {
152 ctConfigToolView* view = wxDynamicCast(doc->GetFirstView(), ctConfigToolView);
153 if (view)
154 view->OnIconLeftDown(this, data->GetConfigItem());
155 }
156 }
157 }
158 else if (event.RightDown())
159 {
160 if ((flags & wxTREE_HITTEST_ONITEMBUTTON) ||
161 (flags & wxTREE_HITTEST_ONITEMICON) ||
162 (flags & wxTREE_HITTEST_ONITEMINDENT) ||
163 (flags & wxTREE_HITTEST_ONITEMLABEL))
164 {
165 ctTreeItemData* data = (ctTreeItemData*) GetItemData(item);
166 ctConfigToolDoc* doc = wxGetApp().GetMainFrame()->GetDocument();
167 if (doc && data)
168 {
169 m_contextItem = data->GetConfigItem();
170 PopupMenu(m_contextMenu, event.GetX(), event.GetY());
171 }
172 }
173 }
174
175 event.Skip();
176 }
177
178 void ctConfigTreeCtrl::OnKeyDown(wxKeyEvent& event)
179 {
180 wxTreeItemId id = GetSelection();
181 if (event.GetKeyCode() == WXK_SPACE)
182 {
183 if (id.IsOk())
184 {
185 ctConfigItem* item = ((ctTreeItemData*) GetItemData(id))->GetConfigItem();
186 ctConfigToolDoc* doc = wxGetApp().GetMainFrame()->GetDocument();
187 if (doc)
188 {
189 ctConfigToolView* view = wxDynamicCast(doc->GetFirstView(), ctConfigToolView);
190 if (view)
191 view->OnIconLeftDown(this, item);
192 }
193 }
194 }
195 else
196 {
197 event.Skip();
198 }
199 }
200
201 // Show help for this window
202 void ctConfigTreeCtrl::OnHelp(wxHelpEvent& event)
203 {
204 wxPoint pt = ScreenToClient(event.GetPosition());
205 int flags = 0;
206 wxTreeItemId id = HitTest(pt, flags);
207 wxHelpProvider *helpProvider = wxHelpProvider::Get();
208 if ( helpProvider && id > 0)
209 {
210 ctConfigItem* item = ((ctTreeItemData*) GetItemData(id))->GetConfigItem();
211 if (item)
212 {
213 wxString helpTopic = item->GetPropertyString(wxT("help-topic"));
214 if (!helpTopic.IsEmpty())
215 {
216 wxGetApp().GetReferenceHelpController().DisplaySection(helpTopic);
217 return;
218 }
219 }
220 }
221
222 event.Skip();
223 }
224
225 ctTreeItemData::~ctTreeItemData()
226 {
227 if (m_configItem) delete m_configItem;
228 }
229