1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindows Configuration Tool tree class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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/closedfolder.xpm"
28 #include "bitmaps/closedfolder_dis.xpm"
30 #include "bitmaps/checked.xpm"
31 #include "bitmaps/checked_dis.xpm"
32 #include "bitmaps/unchecked.xpm"
33 #include "bitmaps/unchecked_dis.xpm"
35 #include "bitmaps/radioon.xpm"
36 #include "bitmaps/radioon_dis.xpm"
37 #include "bitmaps/radiooff.xpm"
38 #include "bitmaps/radiooff_dis.xpm"
40 #include "bitmaps/checkedfolder.xpm"
41 #include "bitmaps/checkedfolder_dis.xpm"
42 #include "bitmaps/uncheckedfolder.xpm"
43 #include "bitmaps/uncheckedfolder_dis.xpm"
45 #include "bitmaps/radiofolderon.xpm"
46 #include "bitmaps/radiofolderon_dis.xpm"
47 #include "bitmaps/radiofolderoff.xpm"
48 #include "bitmaps/radiofolderoff_dis.xpm"
50 #include "configtree.h"
51 #include "configtooldoc.h"
52 #include "configtoolview.h"
53 #include "wxconfigtool.h"
54 #include "mainframe.h"
60 IMPLEMENT_CLASS(ctConfigTreeCtrl
, wxTreeCtrl
)
62 BEGIN_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
)
69 ctConfigTreeCtrl::ctConfigTreeCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pt
,
70 const wxSize
& sz
, long style
):
71 wxTreeCtrl(parent
, id
, pt
, sz
, style
)
76 m_contextMenu
= new wxMenu
;
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"));
85 SetHelpText(_("This shows configuration settings that you can enable and disable."));
88 // Load the icons and initialize the tree
89 void ctConfigTreeCtrl::LoadIcons()
91 m_imageList
= new wxImageList(16, 16, TRUE
);
92 m_iconTable
.SetImageList(m_imageList
);
93 SetImageList(m_imageList
);
95 m_iconTable
.AddInfo(_T("Group"), wxIcon(closedfolder_xpm
), 0, TRUE
);
96 m_iconTable
.AddInfo(_T("Group"), wxIcon(closedfolder_dis_xpm
), 0, FALSE
);
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
);
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
);
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
);
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
);
119 ctConfigTreeCtrl::~ctConfigTreeCtrl()
124 delete m_contextMenu
;
127 void ctConfigTreeCtrl::OnSelChanged(wxTreeEvent
& WXUNUSED(event
))
129 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
132 ctConfigToolHint
hint(NULL
, ctSelChanged
);
133 doc
->UpdateAllViews(NULL
, & hint
);
137 void ctConfigTreeCtrl::OnMouseEvent(wxMouseEvent
& event
)
140 wxTreeItemId item
= HitTest(wxPoint(event
.GetX(), event
.GetY()), flags
);
142 if (event
.LeftDown())
144 if (flags
& wxTREE_HITTEST_ONITEMICON
)
146 ctTreeItemData
* data
= (ctTreeItemData
*) GetItemData(item
);
147 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
150 ctConfigToolView
* view
= wxDynamicCast(doc
->GetFirstView(), ctConfigToolView
);
152 view
->OnIconLeftDown(this, data
->GetConfigItem());
156 else if (event
.RightDown())
158 if ((flags
& wxTREE_HITTEST_ONITEMBUTTON
) ||
159 (flags
& wxTREE_HITTEST_ONITEMICON
) ||
160 (flags
& wxTREE_HITTEST_ONITEMINDENT
) ||
161 (flags
& wxTREE_HITTEST_ONITEMLABEL
))
163 ctTreeItemData
* data
= (ctTreeItemData
*) GetItemData(item
);
164 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
167 m_contextItem
= data
->GetConfigItem();
168 PopupMenu(m_contextMenu
, event
.GetX(), event
.GetY());
176 void ctConfigTreeCtrl::OnKeyDown(wxKeyEvent
& event
)
178 wxTreeItemId id
= GetSelection();
179 if (event
.GetKeyCode() == WXK_SPACE
)
183 ctConfigItem
* item
= ((ctTreeItemData
*) GetItemData(id
))->GetConfigItem();
184 ctConfigToolDoc
* doc
= wxGetApp().GetMainFrame()->GetDocument();
187 ctConfigToolView
* view
= wxDynamicCast(doc
->GetFirstView(), ctConfigToolView
);
189 view
->OnIconLeftDown(this, item
);
199 // Show help for this window
200 void ctConfigTreeCtrl::OnHelp(wxHelpEvent
& event
)
202 wxPoint pt
= ScreenToClient(event
.GetPosition());
204 wxTreeItemId id
= HitTest(pt
, flags
);
205 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
206 if ( helpProvider
&& id
> 0)
208 ctConfigItem
* item
= ((ctTreeItemData
*) GetItemData(id
))->GetConfigItem();
211 wxString helpTopic
= item
->GetPropertyString(wxT("help-topic"));
212 if (!helpTopic
.IsEmpty())
214 wxGetApp().GetReferenceHelpController().DisplaySection(helpTopic
);
223 ctTreeItemData::~ctTreeItemData()
225 if (m_configItem
) delete m_configItem
;