]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/regtest/regtest.cpp
Change version to 3.0.0.
[wxWidgets.git] / samples / regtest / regtest.cpp
index ac77e7bb811f3d16310c1a6c0d0bd26ffd42fea8..04990e58e47b6cfe9511aee1ad93ed4228117ec0 100644 (file)
@@ -4,7 +4,6 @@
 // Author:      Vadim Zeitlin
 // Modified by:
 // Created:     03.04.98
 // Author:      Vadim Zeitlin
 // Modified by:
 // Created:     03.04.98
-// RCS-ID:      $Id$
 // Copyright:   (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 // Copyright:   (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
@@ -31,7 +30,7 @@
 #include "wx/imaglist.h"
 #include "wx/tokenzr.h"
 
 #include "wx/imaglist.h"
 #include "wx/tokenzr.h"
 
-#if wxUSE_CONFIG_NATIVE && defined( __WXMSW__ )
+#if wxUSE_CONFIG_NATIVE && defined( __WINDOWS__ )
 #   define DO_REGTEST 1
 #else
 #   define DO_REGTEST 0
 #   define DO_REGTEST 1
 #else
 #   define DO_REGTEST 0
@@ -102,6 +101,7 @@ public:
     void CreateNewKey(const wxString& strName);
     void CreateNewTextValue(const wxString& strName);
     void CreateNewBinaryValue(const wxString& strName);
     void CreateNewKey(const wxString& strName);
     void CreateNewTextValue(const wxString& strName);
     void CreateNewBinaryValue(const wxString& strName);
+    void SetRegistryView(wxRegKey::WOW64ViewMode viewMode);
 
     // information
     bool IsKeySelected() const;
 
     // information
     bool IsKeySelected() const;
@@ -119,6 +119,7 @@ private:
         TreeChildren  m_aChildren;  // array of subkeys/values
         bool          m_bKey;       // key or value?
         wxRegKey     *m_pKey;       // only may be !NULL if m_bKey == true
         TreeChildren  m_aChildren;  // array of subkeys/values
         bool          m_bKey;       // key or value?
         wxRegKey     *m_pKey;       // only may be !NULL if m_bKey == true
+        wxRegKey::WOW64ViewMode m_viewMode; // How to view the registry.
 
         // trivial accessors
         wxTreeItemId  Id()     const { return m_id;              }
 
         // trivial accessors
         wxTreeItemId  Id()     const { return m_id;              }
@@ -135,6 +136,7 @@ private:
         bool DeleteChild(TreeNode *child);
         void DestroyChildren();
         const wxChar *FullName() const;
         bool DeleteChild(TreeNode *child);
         void DestroyChildren();
         const wxChar *FullName() const;
+        void SetRegistryView(wxRegKey::WOW64ViewMode viewMode);
 
         // get the associated key: make sure the pointer is !NULL
         wxRegKey& Key() { if ( !m_pKey ) OnExpand(); return *m_pKey; }
 
         // get the associated key: make sure the pointer is !NULL
         wxRegKey& Key() { if ( !m_pKey ) OnExpand(); return *m_pKey; }
@@ -155,6 +157,8 @@ private:
 
     wxString     m_nameOld;           // the initial value of item being renamed
 
 
     wxString     m_nameOld;           // the initial value of item being renamed
 
+    wxRegKey::WOW64ViewMode m_viewMode; // Registry view to use for keys.
+
     TreeNode *GetNode(const wxTreeEvent& event)
         { return (TreeNode *)GetItemData(event.GetItem()); }
 
     TreeNode *GetNode(const wxTreeEvent& event)
         { return (TreeNode *)GetItemData(event.GetItem()); }
 
@@ -163,7 +167,8 @@ public:
     TreeNode *InsertNewTreeNode(TreeNode *pParent,
         const wxString& strName,
         int idImage = RegImageList::ClosedKey,
     TreeNode *InsertNewTreeNode(TreeNode *pParent,
         const wxString& strName,
         int idImage = RegImageList::ClosedKey,
-        const wxString *pstrValue = NULL);
+        const wxString *pstrValue = NULL,
+        wxRegKey::WOW64ViewMode viewMode = wxRegKey::WOW64ViewMode_Default);
 
     // add standard registry keys
     void AddStdKeys();
 
     // add standard registry keys
     void AddStdKeys();
@@ -203,6 +208,8 @@ public:
 
     void OnInfo     (wxCommandEvent& event);
 
 
     void OnInfo     (wxCommandEvent& event);
 
+    void OnViewChange (wxCommandEvent& event);
+
     DECLARE_EVENT_TABLE()
 
 private:
     DECLARE_EVENT_TABLE()
 
 private:
@@ -232,6 +239,10 @@ enum
     Menu_NewBinary,
     Menu_Delete,
     Menu_Info,
     Menu_NewBinary,
     Menu_Delete,
     Menu_Info,
+    Menu_View,
+    Menu_ViewDefault,
+    Menu_View32,
+    Menu_View64,
 
     Ctrl_RegTree  = 200
 };
 
     Ctrl_RegTree  = 200
 };
@@ -241,19 +252,22 @@ enum
 // ----------------------------------------------------------------------------
 
 BEGIN_EVENT_TABLE(RegFrame, wxFrame)
 // ----------------------------------------------------------------------------
 
 BEGIN_EVENT_TABLE(RegFrame, wxFrame)
-    EVT_MENU(Menu_Test,     RegFrame::OnTest)
-    EVT_MENU(Menu_About,    RegFrame::OnAbout)
-    EVT_MENU(Menu_Quit,     RegFrame::OnQuit)
-    EVT_MENU(Menu_GoTo,     RegFrame::OnGoTo)
-    EVT_MENU(Menu_Expand,   RegFrame::OnExpand)
-    EVT_MENU(Menu_Collapse, RegFrame::OnCollapse)
-    EVT_MENU(Menu_Toggle,   RegFrame::OnToggle)
-    EVT_MENU(Menu_Refresh,  RegFrame::OnRefresh)
-    EVT_MENU(Menu_Delete,   RegFrame::OnDelete)
-    EVT_MENU(Menu_NewKey,   RegFrame::OnNewKey)
-    EVT_MENU(Menu_NewText,  RegFrame::OnNewText)
-    EVT_MENU(Menu_NewBinary,RegFrame::OnNewBinary)
-    EVT_MENU(Menu_Info,     RegFrame::OnInfo)
+    EVT_MENU(Menu_Test,        RegFrame::OnTest)
+    EVT_MENU(Menu_About,       RegFrame::OnAbout)
+    EVT_MENU(Menu_Quit,        RegFrame::OnQuit)
+    EVT_MENU(Menu_GoTo,        RegFrame::OnGoTo)
+    EVT_MENU(Menu_Expand,      RegFrame::OnExpand)
+    EVT_MENU(Menu_Collapse,    RegFrame::OnCollapse)
+    EVT_MENU(Menu_Toggle,      RegFrame::OnToggle)
+    EVT_MENU(Menu_Refresh,     RegFrame::OnRefresh)
+    EVT_MENU(Menu_Delete,      RegFrame::OnDelete)
+    EVT_MENU(Menu_NewKey,      RegFrame::OnNewKey)
+    EVT_MENU(Menu_NewText,     RegFrame::OnNewText)
+    EVT_MENU(Menu_NewBinary,   RegFrame::OnNewBinary)
+    EVT_MENU(Menu_Info,        RegFrame::OnInfo)
+    EVT_MENU(Menu_ViewDefault, RegFrame::OnViewChange)
+    EVT_MENU(Menu_View32,      RegFrame::OnViewChange)
+    EVT_MENU(Menu_View64,      RegFrame::OnViewChange)
 END_EVENT_TABLE()
 
 #if DO_REGTEST
 END_EVENT_TABLE()
 
 #if DO_REGTEST
@@ -295,6 +309,20 @@ wxMenu *CreateRegistryMenu()
     pMenuNew->Append(Menu_NewText,   wxT("&Text value"),   wxT("Create a new text value"));
     pMenuNew->Append(Menu_NewBinary, wxT("&Binary value"), wxT("Create a new binary value"));
 
     pMenuNew->Append(Menu_NewText,   wxT("&Text value"),   wxT("Create a new text value"));
     pMenuNew->Append(Menu_NewBinary, wxT("&Binary value"), wxT("Create a new binary value"));
 
+    wxMenu *pMenuView = new wxMenu;
+    pMenuView->AppendRadioItem(
+        Menu_ViewDefault,
+        wxT("&Default"),
+        wxT("Default registry view for the program environment."));
+    pMenuView->AppendRadioItem(
+        Menu_View32,
+        wxT("32-bit Registry"),
+        wxT("View 32-bit registry."));
+    pMenuView->AppendRadioItem(
+        Menu_View64,
+        wxT("64-bit Registry"),
+        wxT("View 64-bit registry."));
+
     wxMenu *pMenuReg = new wxMenu;
     pMenuReg->Append(Menu_New, wxT("&New"), pMenuNew);
     pMenuReg->Append(Menu_Delete,   wxT("&Delete..."), wxT("Delete selected key/value"));
     wxMenu *pMenuReg = new wxMenu;
     pMenuReg->Append(Menu_New, wxT("&New"), pMenuNew);
     pMenuReg->Append(Menu_Delete,   wxT("&Delete..."), wxT("Delete selected key/value"));
@@ -305,6 +333,7 @@ wxMenu *CreateRegistryMenu()
     pMenuReg->Append(Menu_Toggle,   wxT("&Toggle"),    wxT("Toggle current key"));
     pMenuReg->AppendSeparator();
     pMenuReg->Append(Menu_Refresh,  wxT("&Refresh"),   wxT("Refresh the subtree"));
     pMenuReg->Append(Menu_Toggle,   wxT("&Toggle"),    wxT("Toggle current key"));
     pMenuReg->AppendSeparator();
     pMenuReg->Append(Menu_Refresh,  wxT("&Refresh"),   wxT("Refresh the subtree"));
+    pMenuReg->Append(Menu_View,     wxT("&View"),      pMenuView);
     pMenuReg->AppendSeparator();
     pMenuReg->Append(Menu_Info,     wxT("&Properties"),wxT("Information about current selection"));
 
     pMenuReg->AppendSeparator();
     pMenuReg->Append(Menu_Info,     wxT("&Properties"),wxT("Information about current selection"));
 
@@ -326,8 +355,6 @@ bool RegApp::OnInit()
     RegFrame *frame = new RegFrame(NULL, wxT("wxRegTest"), 50, 50, 600, 350);
     frame->Show(true);
 
     RegFrame *frame = new RegFrame(NULL, wxT("wxRegTest"), 50, 50, 600, 350);
     frame->Show(true);
 
-    SetTopWindow(frame);
-
     return true;
 }
 
     return true;
 }
 
@@ -339,7 +366,7 @@ RegFrame::RegFrame(wxFrame *parent, const wxChar *title, int x, int y, int w, in
         : wxFrame(parent, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
 {
     // this reduces flicker effects
         : wxFrame(parent, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
 {
     // this reduces flicker effects
-    SetBackgroundColour(wxColour(255, 255, 255));
+    SetBackgroundColour(*wxWHITE);
 
     // set the icon
     // ------------
 
     // set the icon
     // ------------
@@ -350,7 +377,7 @@ RegFrame::RegFrame(wxFrame *parent, const wxChar *title, int x, int y, int w, in
     wxMenu *pMenuFile = new wxMenu;
     pMenuFile->Append(Menu_Test, wxT("Te&st"), wxT("Test key creation"));
     pMenuFile->AppendSeparator();
     wxMenu *pMenuFile = new wxMenu;
     pMenuFile->Append(Menu_Test, wxT("Te&st"), wxT("Test key creation"));
     pMenuFile->AppendSeparator();
-    pMenuFile->Append(Menu_About, wxT("&About..."), wxT("Show an extraordinarly beautiful dialog"));
+    pMenuFile->Append(Menu_About, wxT("&About"), wxT("Show an extraordinarly beautiful dialog"));
     pMenuFile->AppendSeparator();
     pMenuFile->Append(Menu_Quit,  wxT("E&xit"), wxT("Quit this program"));
 
     pMenuFile->AppendSeparator();
     pMenuFile->Append(Menu_Quit,  wxT("E&xit"), wxT("Quit this program"));
 
@@ -496,6 +523,33 @@ void RegFrame::OnInfo(wxCommandEvent& WXUNUSED(event))
 #endif
 }
 
 #endif
 }
 
+void RegFrame::OnViewChange(wxCommandEvent& event)
+{
+#if DO_REGTEST
+    wxRegKey::WOW64ViewMode view;
+    switch ( event.GetId() )
+    {
+        case Menu_ViewDefault:
+            view = wxRegKey::WOW64ViewMode_Default;
+            break;
+
+        case Menu_View32:
+            view = wxRegKey::WOW64ViewMode_32;
+            break;
+
+        case Menu_View64:
+            view = wxRegKey::WOW64ViewMode_64;
+            break;
+
+        default:
+            wxFAIL_MSG("Unexpected event source for view change.");
+            return;
+    }
+
+    m_treeCtrl->SetRegistryView(view);
+#endif
+}
+
 // ----------------------------------------------------------------------------
 // RegImageList
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // RegImageList
 // ----------------------------------------------------------------------------
@@ -517,10 +571,12 @@ RegImageList::RegImageList() : wxImageList(16, 16, true)
 // ----------------------------------------------------------------------------
 
 // create a new tree item and insert it into the tree
 // ----------------------------------------------------------------------------
 
 // create a new tree item and insert it into the tree
-RegTreeCtrl::TreeNode *RegTreeCtrl::InsertNewTreeNode(TreeNode *pParent,
-                                                      const wxString& strName,
-                                                      int idImage,
-                                                      const wxString *pstrValue)
+RegTreeCtrl::TreeNode *RegTreeCtrl::InsertNewTreeNode(
+    TreeNode *pParent,
+    const wxString& strName,
+    int idImage,
+    const wxString *pstrValue,
+    wxRegKey::WOW64ViewMode viewMode)
 {
     // create new item & insert it
     TreeNode *pNewNode = new TreeNode;
 {
     // create new item & insert it
     TreeNode *pNewNode = new TreeNode;
@@ -529,6 +585,7 @@ RegTreeCtrl::TreeNode *RegTreeCtrl::InsertNewTreeNode(TreeNode *pParent,
     pNewNode->m_strName = strName;
     pNewNode->m_bKey    = pstrValue == NULL;
     pNewNode->m_pKey    = NULL;
     pNewNode->m_strName = strName;
     pNewNode->m_bKey    = pstrValue == NULL;
     pNewNode->m_pKey    = NULL;
+    pNewNode->m_viewMode = viewMode;
     if (pParent)
     {
         pNewNode->m_id  = AppendItem(pParent->Id(),
     if (pParent)
     {
         pNewNode->m_id  = AppendItem(pParent->Id(),
@@ -574,6 +631,7 @@ RegTreeCtrl::RegTreeCtrl(wxWindow *parent, wxWindowID id)
     // init members
     m_draggedItem = NULL;
     m_restoreStatus = false;
     // init members
     m_draggedItem = NULL;
     m_restoreStatus = false;
+    m_viewMode = wxRegKey::WOW64ViewMode_Default;
 
     // create the image list
     // ---------------------
 
     // create the image list
     // ---------------------
@@ -582,7 +640,13 @@ RegTreeCtrl::RegTreeCtrl(wxWindow *parent, wxWindowID id)
 
     // create root keys
     // ----------------
 
     // create root keys
     // ----------------
-    m_pRoot = InsertNewTreeNode(NULL, wxT("Registry Root"), RegImageList::Root);
+    m_pRoot =
+        InsertNewTreeNode(
+            NULL,
+            wxT("Registry Root"),
+            RegImageList::Root,
+            NULL,
+            m_viewMode);
 
     // create popup menu
     // -----------------
 
     // create popup menu
     // -----------------
@@ -600,7 +664,12 @@ void RegTreeCtrl::AddStdKeys()
 {
     for ( unsigned int ui = 0; ui < wxRegKey::nStdKeys; ui++ )
     {
 {
     for ( unsigned int ui = 0; ui < wxRegKey::nStdKeys; ui++ )
     {
-        InsertNewTreeNode(m_pRoot, wxRegKey::GetStdKeyName(ui));
+        InsertNewTreeNode(
+            m_pRoot,
+            wxRegKey::GetStdKeyName(ui),
+            RegImageList::ClosedKey,
+            NULL,
+            m_viewMode);
     }
 }
 
     }
 }
 
@@ -714,7 +783,7 @@ void RegTreeCtrl::OnSelChanged(wxTreeEvent& event)
 void RegTreeCtrl::OnItemExpanding(wxTreeEvent& event)
 {
     TreeNode *pNode = GetNode(event);
 void RegTreeCtrl::OnItemExpanding(wxTreeEvent& event)
 {
     TreeNode *pNode = GetNode(event);
-    bool bExpanding = event.GetEventType() == wxEVT_COMMAND_TREE_ITEM_EXPANDING;
+    bool bExpanding = event.GetEventType() == wxEVT_TREE_ITEM_EXPANDING;
 
     // expansion might take some time
     wxSetCursor(*wxHOURGLASS_CURSOR);
 
     // expansion might take some time
     wxSetCursor(*wxHOURGLASS_CURSOR);
@@ -788,7 +857,7 @@ void RegTreeCtrl::OnEndEdit(wxTreeEvent& event)
 
 void RegTreeCtrl::OnBeginDrag(wxTreeEvent& event)
 {
 
 void RegTreeCtrl::OnBeginDrag(wxTreeEvent& event)
 {
-    m_copyOnDrop = event.GetEventType() == wxEVT_COMMAND_TREE_BEGIN_DRAG;
+    m_copyOnDrop = event.GetEventType() == wxEVT_TREE_BEGIN_DRAG;
 
     TreeNode *pNode = GetNode(event);
     if ( pNode->IsRoot() || pNode->Parent()->IsRoot() )
 
     TreeNode *pNode = GetNode(event);
     if ( pNode->IsRoot() || pNode->Parent()->IsRoot() )
@@ -930,7 +999,7 @@ bool RegTreeCtrl::TreeNode::OnExpand()
     if ( Parent()->IsRoot() )
     {
         // we're a standard key
     if ( Parent()->IsRoot() )
     {
         // we're a standard key
-        m_pKey = new wxRegKey(m_strName);
+        m_pKey = new wxRegKey(m_strName, m_viewMode);
     }
     else
     {
     }
     else
     {
@@ -956,7 +1025,12 @@ bool RegTreeCtrl::TreeNode::OnExpand()
     bCont = m_pKey->GetFirstKey(str, l);
     while ( bCont )
     {
     bCont = m_pKey->GetFirstKey(str, l);
     while ( bCont )
     {
-        m_pTree->InsertNewTreeNode(this, str, RegImageList::ClosedKey);
+        m_pTree->InsertNewTreeNode(
+            this,
+            str,
+            RegImageList::ClosedKey,
+            NULL,
+            m_viewMode);
         bCont = m_pKey->GetNextKey(str, l);
 
         // we have at least this key...
         bCont = m_pKey->GetNextKey(str, l);
 
         // we have at least this key...
@@ -1007,7 +1081,7 @@ bool RegTreeCtrl::TreeNode::OnExpand()
             icon = RegImageList::BinaryValue;
         }
 
             icon = RegImageList::BinaryValue;
         }
 
-        m_pTree->InsertNewTreeNode(this, str, icon, &strItem);
+        m_pTree->InsertNewTreeNode(this, str, icon, &strItem, m_viewMode);
         bCont = m_pKey->GetNextValue(str, l);
 
         // we have at least this value...
         bCont = m_pKey->GetNextValue(str, l);
 
         // we have at least this value...
@@ -1118,10 +1192,20 @@ const wxChar *RegTreeCtrl::TreeNode::FullName() const
         s_strName = Parent()->FullName();
         s_strName << wxT('\\') << m_strName;
 
         s_strName = Parent()->FullName();
         s_strName << wxT('\\') << m_strName;
 
-        return s_strName;
+        return s_strName.t_str();
     }
 }
 
     }
 }
 
+void RegTreeCtrl::TreeNode::SetRegistryView(wxRegKey::WOW64ViewMode viewMode)
+{
+    m_viewMode = viewMode;
+
+    // Update children with new view.
+    size_t nCount = m_aChildren.GetCount();
+    for (size_t n = 0; n < nCount; n++)
+        m_aChildren[n]->SetRegistryView(viewMode);
+}
+
 // ----------------------------------------------------------------------------
 // operations on RegTreeCtrl
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // operations on RegTreeCtrl
 // ----------------------------------------------------------------------------
@@ -1276,6 +1360,13 @@ void RegTreeCtrl::CreateNewBinaryValue(const wxString& strName)
         pCurrent->Refresh();
 }
 
         pCurrent->Refresh();
 }
 
+void RegTreeCtrl::SetRegistryView(wxRegKey::WOW64ViewMode viewMode)
+{
+    m_viewMode = viewMode;
+    m_pRoot->SetRegistryView(viewMode);
+    m_pRoot->Refresh();
+}
+
 void RegTreeCtrl::ShowProperties()
 {
     wxTreeItemId lCurrent = GetSelection();
 void RegTreeCtrl::ShowProperties()
 {
     wxTreeItemId lCurrent = GetSelection();