X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c99a3a1d94cafb4e6f24321773eb06fa7b9275f1..ce6d2511f82aafc78aba320018c868f826ab172b:/samples/regtest/regtest.cpp diff --git a/samples/regtest/regtest.cpp b/samples/regtest/regtest.cpp index b04dd8748c..f670fc00ad 100644 --- a/samples/regtest/regtest.cpp +++ b/samples/regtest/regtest.cpp @@ -29,6 +29,7 @@ #include "wx/log.h" #include "wx/treectrl.h" #include "wx/msw/registry.h" +#include "wx/msw/imaglist.h" // ---------------------------------------------------------------------------- // application type @@ -57,6 +58,9 @@ public: RegImageList(); }; +// array of children of the node +//class TreeNode; + // ---------------------------------------------------------------------------- // our control // ---------------------------------------------------------------------------- @@ -90,13 +94,12 @@ public: 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 @@ -137,7 +140,7 @@ private: 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 @@ -388,7 +391,7 @@ RegImageList::RegImageList() : wxImageList(16, 16, TRUE) // 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)); } } @@ -417,9 +420,7 @@ RegTreeCtrl::TreeNode *RegTreeCtrl::InsertNewTreeNode(TreeNode *pParent, 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 ) { @@ -460,7 +461,7 @@ RegTreeCtrl::~RegTreeCtrl() 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)); } } @@ -528,7 +529,7 @@ void RegTreeCtrl::OnChar(wxKeyEvent& event) if ( event.KeyCode() == WXK_DELETE ) DeleteSelected(); else - wxTreeCtrl::OnChar(event); + event.Skip(); } void RegTreeCtrl::OnSelChanged(wxTreeEvent& event) @@ -540,7 +541,7 @@ 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); @@ -562,7 +563,7 @@ void RegTreeCtrl::OnItemExpanding(wxTreeEvent& event) if ( !pNode->IsRoot() ) { int idIcon = bExpanding ? RegImageList::OpenedKey : RegImageList::ClosedKey; - SetItemImage(pNode->Id(), idIcon, idIcon); + SetItemImage(pNode->Id(), idIcon); } } @@ -576,8 +577,14 @@ void RegTreeCtrl::OnItemExpanding(wxTreeEvent& event) 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 @@ -595,7 +602,6 @@ bool RegTreeCtrl::TreeNode::OnExpand() } if ( !m_pKey->Open() ) { - m_lDummy = 0; wxLogError("The key '%s' can't be opened.", FullName()); return false; } @@ -685,11 +691,11 @@ void RegTreeCtrl::TreeNode::AddDummy() 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();