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