1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindows Configuration Tool tree class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "configtree.h"
16 // Includes other headers for precompiled compilation
23 #include "wx/imaglist.h"
24 #include "wx/cshelp.h"
27 #include "bitmaps/folder1.xpm"
29 #include "bitmaps/closedfolder.xpm"
30 #include "bitmaps/closedfolder_dis.xpm"
32 #include "bitmaps/checked.xpm"
33 #include "bitmaps/checked_dis.xpm"
34 #include "bitmaps/unchecked.xpm"
35 #include "bitmaps/unchecked_dis.xpm"
37 #include "bitmaps/radioon.xpm"
38 #include "bitmaps/radioon_dis.xpm"
39 #include "bitmaps/radiooff.xpm"
40 #include "bitmaps/radiooff_dis.xpm"
42 #include "bitmaps/checkedfolder.xpm"
43 #include "bitmaps/checkedfolder_dis.xpm"
44 #include "bitmaps/uncheckedfolder.xpm"
45 #include "bitmaps/uncheckedfolder_dis.xpm"
47 #include "bitmaps/radiofolderon.xpm"
48 #include "bitmaps/radiofolderon_dis.xpm"
49 #include "bitmaps/radiofolderoff.xpm"
50 #include "bitmaps/radiofolderoff_dis.xpm"
52 #include "configtree.h"
53 #include "configtooldoc.h"
54 #include "configtoolview.h"
55 #include "wxconfigtool.h"
56 #include "mainframe.h"
62 IMPLEMENT_CLASS(ctConfigTreeCtrl
, wxTreeCtrl
)
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
)
71 ctConfigTreeCtrl::ctConfigTreeCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pt
,
72 const wxSize
& sz
, long style
):
73 wxTreeCtrl(parent
, id
, pt
, sz
, style
)
78 m_contextMenu
= new wxMenu
;
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"));
87 SetHelpText(_("This shows configuration settings that you can enable and disable."));
90 // Load the icons and initialize the tree
91 void ctConfigTreeCtrl::LoadIcons()
93 m_imageList
= new wxImageList(16, 16, TRUE
);
94 m_iconTable
.SetImageList(m_imageList
);
95 SetImageList(m_imageList
);
97 m_iconTable
.AddInfo("Group", wxIcon(closedfolder_xpm
), 0, TRUE
);
98 m_iconTable
.AddInfo("Group", wxIcon(closedfolder_dis_xpm
), 0, FALSE
);
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
);
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
);
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
);
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
);
121 ctConfigTreeCtrl::~ctConfigTreeCtrl()
126 delete m_contextMenu
;
129 void ctConfigTreeCtrl::OnSelChanged(wxTreeEvent
& event
)
131 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
134 ctConfigToolHint
hint(NULL
, ctSelChanged
);
135 doc
->UpdateAllViews(NULL
, & hint
);
139 void ctConfigTreeCtrl::OnMouseEvent(wxMouseEvent
& event
)
142 wxTreeItemId item
= HitTest(wxPoint(event
.GetX(), event
.GetY()), flags
);
144 if (event
.LeftDown())
146 if (flags
& wxTREE_HITTEST_ONITEMICON
)
148 ctTreeItemData
* data
= (ctTreeItemData
*) GetItemData(item
);
149 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
152 ctConfigToolView
* view
= wxDynamicCast(doc
->GetFirstView(), ctConfigToolView
);
154 view
->OnIconLeftDown(this, data
->GetConfigItem());
158 else if (event
.RightDown())
160 if ((flags
& wxTREE_HITTEST_ONITEMBUTTON
) ||
161 (flags
& wxTREE_HITTEST_ONITEMICON
) ||
162 (flags
& wxTREE_HITTEST_ONITEMINDENT
) ||
163 (flags
& wxTREE_HITTEST_ONITEMLABEL
))
165 ctTreeItemData
* data
= (ctTreeItemData
*) GetItemData(item
);
166 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
169 m_contextItem
= data
->GetConfigItem();
170 PopupMenu(m_contextMenu
, event
.GetX(), event
.GetY());
178 void ctConfigTreeCtrl::OnKeyDown(wxKeyEvent
& event
)
180 wxTreeItemId id
= GetSelection();
181 if (event
.GetKeyCode() == WXK_SPACE
)
185 ctConfigItem
* item
= ((ctTreeItemData
*) GetItemData(id
))->GetConfigItem();
186 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
189 ctConfigToolView
* view
= wxDynamicCast(doc
->GetFirstView(), ctConfigToolView
);
191 view
->OnIconLeftDown(this, item
);
201 // Show help for this window
202 void ctConfigTreeCtrl::OnHelp(wxHelpEvent
& event
)
204 wxPoint pt
= ScreenToClient(event
.GetPosition());
206 wxTreeItemId id
= HitTest(pt
, flags
);
207 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
208 if ( helpProvider
&& id
> 0)
210 ctConfigItem
* item
= ((ctTreeItemData
*) GetItemData(id
))->GetConfigItem();
213 wxString helpTopic
= item
->GetPropertyString(wxT("help-topic"));
214 if (!helpTopic
.IsEmpty())
216 wxGetApp().GetReferenceHelpController().DisplaySection(helpTopic
);
225 ctTreeItemData::~ctTreeItemData()
227 if (m_configItem
) delete m_configItem
;