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