#include "wx/log.h"
#include "wx/treectrl.h"
#include "wx/msw/registry.h"
+#include "wx/msw/imaglist.h"
// ----------------------------------------------------------------------------
// application type
RegImageList();
};
+// array of children of the node
+//class TreeNode;
+
// ----------------------------------------------------------------------------
// our control
// ----------------------------------------------------------------------------
DECLARE_EVENT_TABLE();
private:
- // array of children of the node
- struct TreeNode;
- WX_DEFINE_ARRAY(TreeNode *, TreeChildren);
-
+
// structure describing a registry key/value
- struct TreeNode
+ class TreeNode : public wxTreeItemData
{
+WX_DEFINE_ARRAY(TreeNode *, TreeChildren);
+ public:
RegTreeCtrl *m_pTree; // must be !NULL
TreeNode *m_pParent; // NULL only for the root node
long m_id; // the id of the tree control item
wxImageList *m_imageList;
TreeNode *GetNode(const wxTreeEvent& event)
- { return (TreeNode *)GetItemData(event.m_item.m_itemId); }
+ { return (TreeNode *)GetItemData((WXHTREEITEM)event.GetItem()); }
public:
// create a new node and insert it to the tree
// should be in sync with enum RegImageList::RegIcon
static const char *aszIcons[] = { "key1","key2","key3","value1","value2" };
wxString str = "icon_";
- for ( uint n = 0; n < WXSIZEOF(aszIcons); n++ ) {
+ for ( unsigned int n = 0; n < WXSIZEOF(aszIcons); n++ ) {
Add(wxIcon(str + aszIcons[n], wxBITMAP_TYPE_ICO_RESOURCE));
}
}
wxASSERT_MSG( pNewNode->m_id, "can't create tree control item!");
// save the pointer in the item
- if ( !SetItemData(pNewNode->m_id, (long)pNewNode) ) {
- wxFAIL_MSG("can't store item's data in tree control!");
- }
+ SetItemData(pNewNode->m_id, pNewNode);
// add it to the list of parent's children
if ( pParent != NULL ) {
void RegTreeCtrl::AddStdKeys()
{
- for ( uint ui = 0; ui < wxRegKey::nStdKeys; ui++ ) {
+ for ( unsigned int ui = 0; ui < wxRegKey::nStdKeys; ui++ ) {
InsertNewTreeNode(m_pRoot, wxRegKey::GetStdKeyName(ui));
}
}
long lId = GetSelection();
TreeNode *pNode = (TreeNode *)GetItemData(lId);
- wxCHECK( pNode != NULL );
+ wxCHECK_RET( pNode != NULL, "tree item without data?" );
if ( pNode->IsRoot() ) {
wxLogError("Can't create a subkey under the root key.");
if ( event.KeyCode() == WXK_DELETE )
DeleteSelected();
else
- wxTreeCtrl::OnChar(event);
+ event.Skip();
}
void RegTreeCtrl::OnSelChanged(wxTreeEvent& event)
void RegTreeCtrl::OnItemExpanding(wxTreeEvent& event)
{
TreeNode *pNode = GetNode(event);
- bool bExpanding = event.m_code == wxTREE_EXPAND_EXPAND;
+ bool bExpanding = event.GetCode() == wxTREE_EXPAND_EXPAND;
// expansion might take some time
wxSetCursor(*wxHOURGLASS_CURSOR);
if ( !pNode->IsRoot() ) {
int idIcon = bExpanding ? RegImageList::OpenedKey
: RegImageList::ClosedKey;
- SetItemImage(pNode->Id(), idIcon, idIcon);
+ SetItemImage(pNode->Id(), idIcon);
}
}
bool RegTreeCtrl::TreeNode::OnExpand()
{
// remove dummy item
- if ( m_lDummy != 0 )
- m_pTree->DeleteItem(m_lDummy);
+ if ( m_lDummy != 0 ) {
+ m_pTree->Delete(m_lDummy);
+ m_lDummy = 0;
+ }
+ else {
+ // we've been already expanded
+ return TRUE;
+ }
if ( IsRoot() ) {
// we're the root key
}
if ( !m_pKey->Open() ) {
- m_lDummy = 0;
wxLogError("The key '%s' can't be opened.", FullName());
return false;
}
void RegTreeCtrl::TreeNode::DestroyChildren()
{
// destroy all children
- uint nCount = m_aChildren.Count();
- for ( uint n = 0; n < nCount; n++ ) {
- long lId = m_aChildren[n]->Id();
+ unsigned int nCount = m_aChildren.Count();
+ for ( unsigned int n = 0; n < nCount; n++ ) {
+ long lId = m_aChildren[n]->Id();
delete m_aChildren[n];
- m_pTree->DeleteItem(lId);
+ m_pTree->Delete(lId);
}
m_aChildren.Empty();
TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent),
*pParent = (TreeNode *)GetItemData(lParent);
- wxCHECK ( pCurrent && pParent );
+ wxCHECK_RET( pCurrent && pParent, "either node or parent without data?" );
if ( pParent->IsRoot() ) {
wxLogError("Can't delete standard key.");
long lCurrent = GetSelection();
TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent);
- wxCHECK( pCurrent != NULL );
+ wxCHECK_RET( pCurrent != NULL, "node without data?" );
wxASSERT( pCurrent->IsKey() ); // check must have been done before
long lCurrent = GetSelection();
TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent);
- wxCHECK( pCurrent != NULL );
+ wxCHECK_RET( pCurrent != NULL, "node without data?" );
wxASSERT( pCurrent->IsKey() ); // check must have been done before
long lCurrent = GetSelection();
TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent);
- wxCHECK( pCurrent != NULL );
+ wxCHECK_RET( pCurrent != NULL, "node without data?" );
wxASSERT( pCurrent->IsKey() ); // check must have been done before
long lCurrent = GetSelection();
TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent);
- wxCHECK_RET( pCurrent != NULL, false );
+ wxCHECK( pCurrent != NULL, false );
return pCurrent->IsKey();
}
\ No newline at end of file