]> git.saurik.com Git - wxWidgets.git/blame - utils/configtool/src/configtree.cpp
Oops, I left an extra { in there.
[wxWidgets.git] / utils / configtool / src / configtree.cpp
CommitLineData
d7463f75
JS
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
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
60IMPLEMENT_CLASS(ctConfigTreeCtrl, wxTreeCtrl)
61
62BEGIN_EVENT_TABLE(ctConfigTreeCtrl, wxTreeCtrl)
63 EVT_MOUSE_EVENTS(ctConfigTreeCtrl::OnMouseEvent)
64 EVT_CHAR(ctConfigTreeCtrl::OnKeyDown)
65 EVT_TREE_SEL_CHANGED(-1, ctConfigTreeCtrl::OnSelChanged)
66 EVT_HELP(-1, ctConfigTreeCtrl::OnHelp)
67END_EVENT_TABLE()
68
69ctConfigTreeCtrl::ctConfigTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt,
70 const wxSize& sz, long style):
71wxTreeCtrl(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
89void ctConfigTreeCtrl::LoadIcons()
90{
91 m_imageList = new wxImageList(16, 16, TRUE);
92 m_iconTable.SetImageList(m_imageList);
93 SetImageList(m_imageList);
94
69da0d99
JS
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
69da0d99
JS
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
69da0d99
JS
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
69da0d99
JS
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
69da0d99
JS
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
119ctConfigTreeCtrl::~ctConfigTreeCtrl()
120{
121 SetImageList(NULL);
122 delete m_imageList;
123
124 delete m_contextMenu;
125}
126
69da0d99 127void 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
137void 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
176void 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
200void ctConfigTreeCtrl::OnHelp(wxHelpEvent& event)
201{
202 wxPoint pt = ScreenToClient(event.GetPosition());
203 int flags = 0;
204 wxTreeItemId id = HitTest(pt, flags);
205 wxHelpProvider *helpProvider = wxHelpProvider::Get();
206 if ( helpProvider && id > 0)
207 {
208 ctConfigItem* item = ((ctTreeItemData*) GetItemData(id))->GetConfigItem();
209 if (item)
210 {
211 wxString helpTopic = item->GetPropertyString(wxT("help-topic"));
212 if (!helpTopic.IsEmpty())
213 {
214 wxGetApp().GetReferenceHelpController().DisplaySection(helpTopic);
215 return;
216 }
217 }
218 }
219
220 event.Skip();
221}
222
223ctTreeItemData::~ctTreeItemData()
224{
225 if (m_configItem) delete m_configItem;
226}
227