1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWidgets Configuration Tool tree class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/cshelp.h"
20 #include "wx/imaglist.h"
23 #include "bitmaps/closedfolder.xpm"
24 #include "bitmaps/closedfolder_dis.xpm"
26 #include "bitmaps/checked.xpm"
27 #include "bitmaps/checked_dis.xpm"
28 #include "bitmaps/unchecked.xpm"
29 #include "bitmaps/unchecked_dis.xpm"
31 #include "bitmaps/radioon.xpm"
32 #include "bitmaps/radioon_dis.xpm"
33 #include "bitmaps/radiooff.xpm"
34 #include "bitmaps/radiooff_dis.xpm"
36 #include "bitmaps/checkedfolder.xpm"
37 #include "bitmaps/checkedfolder_dis.xpm"
38 #include "bitmaps/uncheckedfolder.xpm"
39 #include "bitmaps/uncheckedfolder_dis.xpm"
41 #include "bitmaps/radiofolderon.xpm"
42 #include "bitmaps/radiofolderon_dis.xpm"
43 #include "bitmaps/radiofolderoff.xpm"
44 #include "bitmaps/radiofolderoff_dis.xpm"
46 #include "configtree.h"
47 #include "configtooldoc.h"
48 #include "configtoolview.h"
49 #include "wxconfigtool.h"
50 #include "mainframe.h"
56 IMPLEMENT_CLASS(ctConfigTreeCtrl
, wxTreeCtrl
)
58 BEGIN_EVENT_TABLE(ctConfigTreeCtrl
, wxTreeCtrl
)
59 EVT_MOUSE_EVENTS(ctConfigTreeCtrl::OnMouseEvent
)
60 EVT_CHAR(ctConfigTreeCtrl::OnKeyDown
)
61 EVT_TREE_SEL_CHANGED(wxID_ANY
, ctConfigTreeCtrl::OnSelChanged
)
62 EVT_HELP(wxID_ANY
, ctConfigTreeCtrl::OnHelp
)
65 ctConfigTreeCtrl::ctConfigTreeCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pt
,
66 const wxSize
& sz
, long style
):
67 wxTreeCtrl(parent
, id
, pt
, sz
, style
)
72 m_contextMenu
= new wxMenu
;
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"));
81 SetHelpText(_("This shows configuration settings that you can enable and disable."));
84 // Load the icons and initialize the tree
85 void ctConfigTreeCtrl::LoadIcons()
87 m_imageList
= new wxImageList(16, 16, true);
88 m_iconTable
.SetImageList(m_imageList
);
89 SetImageList(m_imageList
);
91 m_iconTable
.AddInfo(_T("Group"), wxIcon(closedfolder_xpm
), 0, true);
92 m_iconTable
.AddInfo(_T("Group"), wxIcon(closedfolder_dis_xpm
), 0, false);
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);
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);
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);
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);
115 ctConfigTreeCtrl::~ctConfigTreeCtrl()
120 delete m_contextMenu
;
123 void ctConfigTreeCtrl::OnSelChanged(wxTreeEvent
& WXUNUSED(event
))
125 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
128 ctConfigToolHint
hint(NULL
, ctSelChanged
);
129 doc
->UpdateAllViews(NULL
, & hint
);
133 void ctConfigTreeCtrl::OnMouseEvent(wxMouseEvent
& event
)
136 wxTreeItemId item
= HitTest(wxPoint(event
.GetX(), event
.GetY()), flags
);
138 if (event
.LeftDown())
140 if (flags
& wxTREE_HITTEST_ONITEMICON
)
142 ctTreeItemData
* data
= (ctTreeItemData
*) GetItemData(item
);
143 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
146 ctConfigToolView
* view
= wxDynamicCast(doc
->GetFirstView(), ctConfigToolView
);
148 view
->OnIconLeftDown(this, data
->GetConfigItem());
152 else if (event
.RightDown())
154 if ((flags
& wxTREE_HITTEST_ONITEMBUTTON
) ||
155 (flags
& wxTREE_HITTEST_ONITEMICON
) ||
156 (flags
& wxTREE_HITTEST_ONITEMINDENT
) ||
157 (flags
& wxTREE_HITTEST_ONITEMLABEL
))
159 ctTreeItemData
* data
= (ctTreeItemData
*) GetItemData(item
);
160 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
163 m_contextItem
= data
->GetConfigItem();
164 PopupMenu(m_contextMenu
, event
.GetX(), event
.GetY());
172 void ctConfigTreeCtrl::OnKeyDown(wxKeyEvent
& event
)
174 wxTreeItemId id
= GetSelection();
175 if (event
.GetKeyCode() == WXK_SPACE
)
179 ctConfigItem
* item
= ((ctTreeItemData
*) GetItemData(id
))->GetConfigItem();
180 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
183 ctConfigToolView
* view
= wxDynamicCast(doc
->GetFirstView(), ctConfigToolView
);
185 view
->OnIconLeftDown(this, item
);
195 // Show help for this window
196 void ctConfigTreeCtrl::OnHelp(wxHelpEvent
& event
)
198 wxPoint pt
= ScreenToClient(event
.GetPosition());
200 wxTreeItemId id
= HitTest(pt
, flags
);
201 ctTreeItemData
*itemData
= (ctTreeItemData
*) GetItemData(id
);
202 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
203 if ( helpProvider
&& itemData
)
205 ctConfigItem
* item
= itemData
->GetConfigItem();
208 wxString helpTopic
= item
->GetPropertyString(wxT("help-topic"));
209 if (!helpTopic
.IsEmpty())
211 wxGetApp().GetReferenceHelpController().DisplaySection(helpTopic
);
220 ctTreeItemData::~ctTreeItemData()
222 if (m_configItem
) delete m_configItem
;