1998-05-20 10:21:00 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2000-02-14 19:05:36 -05:00
|
|
|
// Name: regtest.cpp
|
1998-05-20 10:21:00 -04:00
|
|
|
// Purpose: wxRegKey class demo
|
|
|
|
// Author: Vadim Zeitlin
|
2000-02-14 19:05:36 -05:00
|
|
|
// Modified by:
|
1998-05-20 10:21:00 -04:00
|
|
|
// Created: 03.04.98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
|
|
|
// Licence: wxWindows license
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
2003-11-20 20:54:43 -05:00
|
|
|
# pragma hdrstop
|
1998-05-20 10:21:00 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
2003-11-20 20:54:43 -05:00
|
|
|
# include "wx/wx.h"
|
1998-05-20 10:21:00 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/treectrl.h"
|
2003-11-20 20:54:43 -05:00
|
|
|
#include "wx/config.h"
|
|
|
|
#include "wx/imaglist.h"
|
2000-02-24 18:40:42 -05:00
|
|
|
#include "wx/tokenzr.h"
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
#if wxUSE_CONFIG_NATIVE && defined( __WXMSW__ )
|
|
|
|
# define DO_REGTEST 1
|
|
|
|
#else
|
|
|
|
# define DO_REGTEST 0
|
|
|
|
#endif
|
|
|
|
|
1998-05-20 10:21:00 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// application type
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
class RegApp : public wxApp
|
2000-02-14 19:05:36 -05:00
|
|
|
{
|
1998-05-20 10:21:00 -04:00
|
|
|
public:
|
2003-11-20 20:54:43 -05:00
|
|
|
bool OnInit();
|
1998-05-20 10:21:00 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// image list with registry icons
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
class RegImageList : public wxImageList
|
|
|
|
{
|
|
|
|
public:
|
2003-11-20 20:54:43 -05:00
|
|
|
enum Icon
|
|
|
|
{
|
|
|
|
Root,
|
|
|
|
ClosedKey,
|
|
|
|
OpenedKey,
|
|
|
|
TextValue,
|
|
|
|
BinaryValue
|
|
|
|
};
|
|
|
|
|
|
|
|
RegImageList();
|
1998-05-20 10:21:00 -04:00
|
|
|
};
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
|
|
|
|
1998-05-20 10:21:00 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// our control
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
class RegTreeCtrl : public wxTreeCtrl
|
|
|
|
{
|
|
|
|
public:
|
2003-11-20 20:54:43 -05:00
|
|
|
// ctor & dtor
|
|
|
|
RegTreeCtrl(wxWindow *parent, wxWindowID id);
|
|
|
|
virtual ~RegTreeCtrl();
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
// notifications
|
|
|
|
void OnDeleteItem (wxTreeEvent& event);
|
|
|
|
void OnItemExpanding (wxTreeEvent& event);
|
|
|
|
void OnSelChanged (wxTreeEvent& event);
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
void OnBeginEdit (wxTreeEvent& event);
|
|
|
|
void OnEndEdit (wxTreeEvent& event);
|
2000-02-24 18:40:42 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
void OnBeginDrag (wxTreeEvent& event);
|
|
|
|
void OnEndDrag (wxTreeEvent& event);
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
void OnRightClick (wxMouseEvent& event);
|
|
|
|
void OnChar (wxKeyEvent& event);
|
|
|
|
void OnIdle (wxIdleEvent& event);
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
// forwarded notifications (by the frame)
|
|
|
|
void OnMenuTest();
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
// operations
|
|
|
|
void GoTo(const wxString& location);
|
|
|
|
void DoRefresh();
|
|
|
|
void DeleteSelected();
|
|
|
|
void ShowProperties();
|
|
|
|
void CreateNewKey(const wxString& strName);
|
|
|
|
void CreateNewTextValue(const wxString& strName);
|
|
|
|
void CreateNewBinaryValue(const wxString& strName);
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
// information
|
|
|
|
bool IsKeySelected() const;
|
1998-05-20 10:21:00 -04:00
|
|
|
|
|
|
|
private:
|
2003-11-20 20:54:43 -05:00
|
|
|
// structure describing a registry key/value
|
|
|
|
class TreeNode : public wxTreeItemData
|
|
|
|
{
|
|
|
|
WX_DEFINE_ARRAY_PTR(TreeNode *, TreeChildren);
|
|
|
|
public:
|
|
|
|
RegTreeCtrl *m_pTree; // must be !NULL
|
|
|
|
TreeNode *m_pParent; // NULL only for the root node
|
2004-05-25 15:31:13 -04:00
|
|
|
wxTreeItemId m_id; // the id of the tree control item
|
2003-11-20 20:54:43 -05:00
|
|
|
wxString m_strName; // name of the key/value
|
|
|
|
TreeChildren m_aChildren; // array of subkeys/values
|
|
|
|
bool m_bKey; // key or value?
|
|
|
|
wxRegKey *m_pKey; // only may be !NULL if m_bKey == true
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
// trivial accessors
|
2004-05-25 15:31:13 -04:00
|
|
|
wxTreeItemId Id() const { return m_id; }
|
|
|
|
bool IsRoot() const { return m_pParent == NULL; }
|
|
|
|
bool IsKey() const { return m_bKey; }
|
|
|
|
TreeNode *Parent() const { return m_pParent; }
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
// notifications
|
|
|
|
bool OnExpand();
|
|
|
|
void OnCollapse();
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
// operations
|
|
|
|
void Refresh();
|
|
|
|
bool DeleteChild(TreeNode *child);
|
|
|
|
void DestroyChildren();
|
|
|
|
const wxChar *FullName() const;
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
// get the associated key: make sure the pointer is !NULL
|
|
|
|
wxRegKey& Key() { if ( !m_pKey ) OnExpand(); return *m_pKey; }
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
// dtor deletes all children
|
|
|
|
~TreeNode();
|
|
|
|
};
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
wxImageList *m_imageList;
|
|
|
|
wxMenu *m_pMenuPopup;
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
TreeNode *m_pRoot;
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
TreeNode *m_draggedItem; // the item being dragged
|
|
|
|
bool m_copyOnDrop; // if false, then move
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
bool m_restoreStatus; // after OnItemExpanding()
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
wxString m_nameOld; // the initial value of item being renamed
|
2000-02-24 18:40:42 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
TreeNode *GetNode(const wxTreeEvent& event)
|
2004-03-08 15:01:04 -05:00
|
|
|
{ return (TreeNode *)GetItemData(event.GetItem()); }
|
1998-05-20 10:21:00 -04:00
|
|
|
|
|
|
|
public:
|
2003-11-20 20:54:43 -05:00
|
|
|
// create a new node and insert it to the tree
|
|
|
|
TreeNode *InsertNewTreeNode(TreeNode *pParent,
|
|
|
|
const wxString& strName,
|
|
|
|
int idImage = RegImageList::ClosedKey,
|
|
|
|
const wxString *pstrValue = NULL);
|
|
|
|
|
|
|
|
// add standard registry keys
|
|
|
|
void AddStdKeys();
|
2000-02-14 19:05:36 -05:00
|
|
|
|
|
|
|
private:
|
2003-11-20 20:54:43 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
1998-05-20 10:21:00 -04:00
|
|
|
};
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
#endif // #if DO_REGTEST
|
|
|
|
|
1998-05-20 10:21:00 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// the main window of our application
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
class RegFrame : public wxFrame
|
2000-02-14 19:05:36 -05:00
|
|
|
{
|
1998-05-20 10:21:00 -04:00
|
|
|
public:
|
2003-11-20 20:54:43 -05:00
|
|
|
// ctor & dtor
|
2005-09-24 17:43:15 -04:00
|
|
|
RegFrame(wxFrame *parent, const wxChar *title, int x, int y, int w, int h);
|
2003-11-20 20:54:43 -05:00
|
|
|
virtual ~RegFrame();
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
// callbacks
|
|
|
|
void OnQuit (wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
|
|
|
void OnTest (wxCommandEvent& event);
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
void OnGoTo (wxCommandEvent& event);
|
2000-02-24 18:40:42 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
void OnExpand (wxCommandEvent& event);
|
|
|
|
void OnCollapse(wxCommandEvent& event);
|
|
|
|
void OnToggle (wxCommandEvent& event);
|
|
|
|
void OnRefresh (wxCommandEvent& event);
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
void OnDelete (wxCommandEvent& event);
|
|
|
|
void OnNewKey (wxCommandEvent& event);
|
|
|
|
void OnNewText (wxCommandEvent& event);
|
|
|
|
void OnNewBinary(wxCommandEvent& event);
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
void OnInfo (wxCommandEvent& event);
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
1998-05-20 10:21:00 -04:00
|
|
|
|
|
|
|
private:
|
2003-11-20 20:54:43 -05:00
|
|
|
|
|
|
|
#if DO_REGTEST
|
|
|
|
RegTreeCtrl *m_treeCtrl;
|
|
|
|
#endif
|
1998-05-20 10:21:00 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// various ids
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
Menu_Quit = 100,
|
|
|
|
Menu_About,
|
|
|
|
Menu_Test,
|
|
|
|
Menu_GoTo,
|
|
|
|
Menu_Expand,
|
|
|
|
Menu_Collapse,
|
|
|
|
Menu_Toggle,
|
|
|
|
Menu_Refresh,
|
|
|
|
Menu_New,
|
|
|
|
Menu_NewKey,
|
|
|
|
Menu_NewText,
|
|
|
|
Menu_NewBinary,
|
|
|
|
Menu_Delete,
|
|
|
|
Menu_Info,
|
|
|
|
|
|
|
|
Ctrl_RegTree = 200,
|
1998-05-20 10:21:00 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event tables
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(RegFrame, wxFrame)
|
2003-11-20 20:54:43 -05:00
|
|
|
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)
|
1998-05-20 10:21:00 -04:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
|
|
|
|
1998-05-20 10:21:00 -04:00
|
|
|
BEGIN_EVENT_TABLE(RegTreeCtrl, wxTreeCtrl)
|
2003-11-20 20:54:43 -05:00
|
|
|
EVT_TREE_DELETE_ITEM (Ctrl_RegTree, RegTreeCtrl::OnDeleteItem)
|
|
|
|
EVT_TREE_ITEM_EXPANDING(Ctrl_RegTree, RegTreeCtrl::OnItemExpanding)
|
|
|
|
EVT_TREE_SEL_CHANGED (Ctrl_RegTree, RegTreeCtrl::OnSelChanged)
|
2000-02-24 18:40:42 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
EVT_TREE_BEGIN_LABEL_EDIT(Ctrl_RegTree, RegTreeCtrl::OnBeginEdit)
|
|
|
|
EVT_TREE_END_LABEL_EDIT (Ctrl_RegTree, RegTreeCtrl::OnEndEdit)
|
2000-02-24 18:40:42 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
EVT_TREE_BEGIN_DRAG (Ctrl_RegTree, RegTreeCtrl::OnBeginDrag)
|
|
|
|
EVT_TREE_BEGIN_RDRAG (Ctrl_RegTree, RegTreeCtrl::OnBeginDrag)
|
|
|
|
EVT_TREE_END_DRAG (Ctrl_RegTree, RegTreeCtrl::OnEndDrag)
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
EVT_CHAR (RegTreeCtrl::OnChar)
|
|
|
|
EVT_RIGHT_DOWN(RegTreeCtrl::OnRightClick)
|
|
|
|
EVT_IDLE (RegTreeCtrl::OnIdle)
|
1998-05-20 10:21:00 -04:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
#endif
|
|
|
|
|
1998-05-20 10:21:00 -04:00
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// global functions
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// create the "registry operations" menu
|
|
|
|
wxMenu *CreateRegistryMenu()
|
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
wxMenu *pMenuNew = new wxMenu;
|
|
|
|
pMenuNew->Append(Menu_NewKey, _T("&Key"), _T("Create a new key"));
|
|
|
|
pMenuNew->AppendSeparator();
|
|
|
|
pMenuNew->Append(Menu_NewText, _T("&Text value"), _T("Create a new text value"));
|
|
|
|
pMenuNew->Append(Menu_NewBinary, _T("&Binary value"), _T("Create a new binary value"));
|
|
|
|
|
|
|
|
wxMenu *pMenuReg = new wxMenu;
|
|
|
|
pMenuReg->Append(Menu_New, _T("&New"), pMenuNew);
|
|
|
|
pMenuReg->Append(Menu_Delete, _T("&Delete..."), _T("Delete selected key/value"));
|
|
|
|
pMenuReg->AppendSeparator();
|
|
|
|
pMenuReg->Append(Menu_GoTo, _T("&Go to...\tCtrl-G"), _T("Go to registry key"));
|
|
|
|
pMenuReg->Append(Menu_Expand, _T("&Expand"), _T("Expand current key"));
|
|
|
|
pMenuReg->Append(Menu_Collapse, _T("&Collapse"), _T("Collapse current key"));
|
|
|
|
pMenuReg->Append(Menu_Toggle, _T("&Toggle"), _T("Toggle current key"));
|
|
|
|
pMenuReg->AppendSeparator();
|
|
|
|
pMenuReg->Append(Menu_Refresh, _T("&Refresh"), _T("Refresh the subtree"));
|
|
|
|
pMenuReg->AppendSeparator();
|
|
|
|
pMenuReg->Append(Menu_Info, _T("&Properties"),_T("Information about current selection"));
|
|
|
|
|
|
|
|
return pMenuReg;
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// application class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
IMPLEMENT_APP(RegApp)
|
|
|
|
|
|
|
|
// `Main program' equivalent, creating windows and returning main app frame
|
|
|
|
bool RegApp::OnInit()
|
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
// create the main frame window and show it
|
|
|
|
RegFrame *frame = new RegFrame(NULL, _T("wxRegTest"), 50, 50, 600, 350);
|
|
|
|
frame->Show(true);
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
SetTopWindow(frame);
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
return true;
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// RegFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2005-09-24 17:43:15 -04:00
|
|
|
RegFrame::RegFrame(wxFrame *parent, const wxChar *title, int x, int y, int w, int h)
|
2004-05-25 15:31:13 -04:00
|
|
|
: wxFrame(parent, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
// this reduces flicker effects
|
|
|
|
SetBackgroundColour(wxColour(255, 255, 255));
|
|
|
|
|
|
|
|
// set the icon
|
|
|
|
// ------------
|
|
|
|
SetIcon(wxIcon(_T("app_icon")));
|
|
|
|
|
|
|
|
// create menu
|
|
|
|
// -----------
|
|
|
|
wxMenu *pMenuFile = new wxMenu;
|
|
|
|
pMenuFile->Append(Menu_Test, _T("Te&st"), _T("Test key creation"));
|
|
|
|
pMenuFile->AppendSeparator();
|
|
|
|
pMenuFile->Append(Menu_About, _T("&About..."), _T("Show an extraordinarly beautiful dialog"));
|
|
|
|
pMenuFile->AppendSeparator();
|
|
|
|
pMenuFile->Append(Menu_Quit, _T("E&xit"), _T("Quit this program"));
|
|
|
|
|
|
|
|
wxMenuBar *pMenu = new wxMenuBar;
|
|
|
|
pMenu->Append(pMenuFile, _T("&File"));
|
|
|
|
pMenu->Append(CreateRegistryMenu(), _T("&Registry"));
|
|
|
|
SetMenuBar(pMenu);
|
|
|
|
|
|
|
|
#if DO_REGTEST
|
|
|
|
// create child controls
|
|
|
|
// ---------------------
|
|
|
|
m_treeCtrl = new RegTreeCtrl(this, Ctrl_RegTree);
|
|
|
|
#endif
|
|
|
|
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2003-11-20 20:54:43 -05:00
|
|
|
// create the status line
|
|
|
|
// ----------------------
|
|
|
|
CreateStatusBar(2);
|
2004-07-19 11:36:01 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2000-02-14 19:05:36 -05:00
|
|
|
RegFrame::~RegFrame()
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
|
|
|
// this makes deletion of it *much* quicker
|
|
|
|
m_treeCtrl->Hide();
|
|
|
|
#endif
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
void RegFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
Close(true);
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
void RegFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
wxMessageDialog dialog(this,
|
|
|
|
_T("wxRegistry sample\n")
|
2004-10-02 08:36:02 -04:00
|
|
|
_T("(c) 1998, 2000 Vadim Zeitlin"),
|
2003-11-20 20:54:43 -05:00
|
|
|
_T("About wxRegTest"), wxOK);
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
dialog.ShowModal();
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2000-02-24 18:40:42 -05:00
|
|
|
void RegFrame::OnTest(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
|
|
|
m_treeCtrl->OnMenuTest();
|
|
|
|
#endif
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2000-02-24 18:40:42 -05:00
|
|
|
void RegFrame::OnGoTo(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2004-05-25 07:20:37 -04:00
|
|
|
static wxString s_location = _T("HKEY_CURRENT_USER\\Software\\wxWidgets");
|
2000-02-24 18:40:42 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
wxString location = wxGetTextFromUser(
|
|
|
|
_T("Enter the location to go to:"),
|
|
|
|
_T("wxRegTest question"),
|
|
|
|
s_location,
|
|
|
|
this);
|
|
|
|
|
2000-02-24 18:40:42 -05:00
|
|
|
if ( !location )
|
|
|
|
return;
|
|
|
|
|
|
|
|
s_location = location;
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
2000-02-24 18:40:42 -05:00
|
|
|
m_treeCtrl->GoTo(location);
|
2003-11-20 20:54:43 -05:00
|
|
|
#endif
|
2000-02-24 18:40:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegFrame::OnExpand(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
|
|
|
m_treeCtrl->Expand(m_treeCtrl->GetSelection());
|
|
|
|
#endif
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2000-02-24 18:40:42 -05:00
|
|
|
void RegFrame::OnCollapse(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
|
|
|
m_treeCtrl->Collapse(m_treeCtrl->GetSelection());
|
|
|
|
#endif
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2000-02-24 18:40:42 -05:00
|
|
|
void RegFrame::OnToggle(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
|
|
|
m_treeCtrl->Toggle(m_treeCtrl->GetSelection());
|
|
|
|
#endif
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2000-02-24 18:40:42 -05:00
|
|
|
void RegFrame::OnRefresh(wxCommandEvent& WXUNUSED(event))
|
2000-02-15 18:57:33 -05:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
|
|
|
m_treeCtrl->DoRefresh();
|
|
|
|
#endif
|
2000-02-15 18:57:33 -05:00
|
|
|
}
|
|
|
|
|
2000-02-24 18:40:42 -05:00
|
|
|
void RegFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
|
|
|
m_treeCtrl->DeleteSelected();
|
|
|
|
#endif
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2000-02-24 18:40:42 -05:00
|
|
|
void RegFrame::OnNewKey(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
|
|
|
if ( m_treeCtrl->IsKeySelected() )
|
|
|
|
{
|
|
|
|
m_treeCtrl->CreateNewKey(
|
|
|
|
wxGetTextFromUser(_T("Enter the name of the new key")));
|
|
|
|
}
|
|
|
|
#endif
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2000-02-24 18:40:42 -05:00
|
|
|
void RegFrame::OnNewText(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
|
|
|
if ( m_treeCtrl->IsKeySelected() )
|
|
|
|
{
|
|
|
|
m_treeCtrl->CreateNewTextValue(
|
|
|
|
wxGetTextFromUser(_T("Enter the name for the new text value")));
|
|
|
|
}
|
|
|
|
#endif
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2000-02-24 18:40:42 -05:00
|
|
|
void RegFrame::OnNewBinary(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
|
|
|
if ( m_treeCtrl->IsKeySelected() )
|
|
|
|
{
|
|
|
|
m_treeCtrl->CreateNewBinaryValue(
|
|
|
|
wxGetTextFromUser(_T("Enter the name for the new binary value")));
|
|
|
|
}
|
|
|
|
#endif
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2000-02-24 18:40:42 -05:00
|
|
|
void RegFrame::OnInfo(wxCommandEvent& WXUNUSED(event))
|
2000-02-14 19:05:36 -05:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
2000-02-14 19:05:36 -05:00
|
|
|
m_treeCtrl->ShowProperties();
|
2003-11-20 20:54:43 -05:00
|
|
|
#endif
|
2000-02-14 19:05:36 -05:00
|
|
|
}
|
|
|
|
|
1998-05-20 10:21:00 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// RegImageList
|
|
|
|
// ----------------------------------------------------------------------------
|
2003-11-20 20:54:43 -05:00
|
|
|
RegImageList::RegImageList() : wxImageList(16, 16, true)
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
// should be in sync with enum RegImageList::RegIcon
|
|
|
|
static const wxChar *aszIcons[] = { _T("key1"),_T("key2"),_T("key3"),_T("value1"),_T("value2") };
|
|
|
|
wxString str = _T("icon_");
|
|
|
|
for ( unsigned int n = 0; n < WXSIZEOF(aszIcons); n++ )
|
|
|
|
{
|
|
|
|
Add(wxIcon(str + aszIcons[n], wxBITMAP_TYPE_ICO_RESOURCE));
|
|
|
|
}
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
#if DO_REGTEST
|
|
|
|
|
1998-05-20 10:21:00 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// RegTreeCtrl
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// create a new tree item and insert it into the tree
|
2000-02-14 19:05:36 -05:00
|
|
|
RegTreeCtrl::TreeNode *RegTreeCtrl::InsertNewTreeNode(TreeNode *pParent,
|
1998-05-20 10:21:00 -04:00
|
|
|
const wxString& strName,
|
|
|
|
int idImage,
|
|
|
|
const wxString *pstrValue)
|
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
// create new item & insert it
|
|
|
|
TreeNode *pNewNode = new TreeNode;
|
|
|
|
pNewNode->m_pTree = this;
|
|
|
|
pNewNode->m_pParent = pParent;
|
|
|
|
pNewNode->m_strName = strName;
|
|
|
|
pNewNode->m_bKey = pstrValue == NULL;
|
|
|
|
pNewNode->m_pKey = NULL;
|
|
|
|
if (pParent)
|
|
|
|
{
|
|
|
|
pNewNode->m_id = AppendItem(pParent->Id(),
|
|
|
|
pNewNode->IsKey() ? strName : *pstrValue,
|
|
|
|
idImage);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pNewNode->m_id = AddRoot(strName);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxASSERT_MSG( pNewNode->m_id, wxT("can't create tree control item!"));
|
|
|
|
|
|
|
|
// save the pointer in the item
|
|
|
|
SetItemData(pNewNode->m_id, pNewNode);
|
|
|
|
|
|
|
|
// add it to the list of parent's children
|
|
|
|
if ( pParent != NULL )
|
|
|
|
{
|
|
|
|
pParent->m_aChildren.Add(pNewNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( pNewNode->IsKey() )
|
|
|
|
{
|
|
|
|
SetItemHasChildren(pNewNode->Id());
|
|
|
|
|
|
|
|
if ( !pNewNode->IsRoot() )
|
|
|
|
{
|
|
|
|
// set the expanded icon as well
|
|
|
|
SetItemImage(pNewNode->Id(),
|
|
|
|
RegImageList::OpenedKey,
|
|
|
|
wxTreeItemIcon_Expanded);
|
|
|
|
}
|
2000-02-14 19:05:36 -05:00
|
|
|
}
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
return pNewNode;
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
RegTreeCtrl::RegTreeCtrl(wxWindow *parent, wxWindowID id)
|
2003-11-20 20:54:43 -05:00
|
|
|
: wxTreeCtrl(parent, id, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTR_HAS_BUTTONS | wxTR_EDIT_LABELS | wxSUNKEN_BORDER)
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
// init members
|
|
|
|
m_draggedItem = NULL;
|
|
|
|
m_restoreStatus = false;
|
|
|
|
|
|
|
|
// create the image list
|
|
|
|
// ---------------------
|
|
|
|
m_imageList = new RegImageList;
|
|
|
|
SetImageList(m_imageList);
|
|
|
|
|
|
|
|
// create root keys
|
|
|
|
// ----------------
|
|
|
|
m_pRoot = InsertNewTreeNode(NULL, _T("Registry Root"), RegImageList::Root);
|
|
|
|
|
|
|
|
// create popup menu
|
|
|
|
// -----------------
|
|
|
|
m_pMenuPopup = CreateRegistryMenu();
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
RegTreeCtrl::~RegTreeCtrl()
|
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
delete m_pMenuPopup;
|
|
|
|
// delete m_pRoot; -- this is done by the tree now
|
|
|
|
delete m_imageList;
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegTreeCtrl::AddStdKeys()
|
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
for ( unsigned int ui = 0; ui < wxRegKey::nStdKeys; ui++ )
|
|
|
|
{
|
|
|
|
InsertNewTreeNode(m_pRoot, wxRegKey::GetStdKeyName(ui));
|
|
|
|
}
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// notifications
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-02-14 19:05:36 -05:00
|
|
|
void RegTreeCtrl::OnIdle(wxIdleEvent& WXUNUSED(event))
|
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( m_restoreStatus )
|
|
|
|
{
|
2000-02-14 19:05:36 -05:00
|
|
|
// restore it after OnItemExpanding()
|
2001-11-22 04:11:33 -05:00
|
|
|
wxLogStatus(wxT("Ok"));
|
2000-02-14 19:05:36 -05:00
|
|
|
wxSetCursor(*wxSTANDARD_CURSOR);
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
m_restoreStatus = false;
|
2000-02-14 19:05:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-20 10:21:00 -04:00
|
|
|
void RegTreeCtrl::OnRightClick(wxMouseEvent& event)
|
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
int iFlags;
|
2004-05-25 15:31:13 -04:00
|
|
|
wxTreeItemId lId = HitTest(wxPoint(event.GetX(), event.GetY()), iFlags);
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( iFlags & wxTREE_HITTEST_ONITEMLABEL )
|
|
|
|
{
|
|
|
|
// select the item first
|
|
|
|
SelectItem(lId);
|
|
|
|
}
|
|
|
|
//else: take the currently selected item if click not on item
|
|
|
|
|
|
|
|
PopupMenu(m_pMenuPopup, event.GetX(), event.GetY());
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
void RegTreeCtrl::OnDeleteItem(wxTreeEvent& WXUNUSED(event))
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// test the key creation functions
|
|
|
|
void RegTreeCtrl::OnMenuTest()
|
|
|
|
{
|
2004-05-25 15:31:13 -04:00
|
|
|
wxTreeItemId lId = GetSelection();
|
2003-11-20 20:54:43 -05:00
|
|
|
TreeNode *pNode = (TreeNode *)GetItemData(lId);
|
|
|
|
|
|
|
|
wxCHECK_RET( pNode != NULL, wxT("tree item without data?") );
|
|
|
|
|
|
|
|
if ( pNode->IsRoot() )
|
|
|
|
{
|
|
|
|
wxLogError(wxT("Can't create a subkey under the root key."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !pNode->IsKey() )
|
|
|
|
{
|
|
|
|
wxLogError(wxT("Can't create a subkey under a value!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxRegKey key1(pNode->Key(), _T("key1"));
|
|
|
|
if ( key1.Create() )
|
|
|
|
{
|
|
|
|
wxRegKey key2a(key1, _T("key2a")), key2b(key1, _T("key2b"));
|
|
|
|
if ( key2a.Create() && key2b.Create() )
|
|
|
|
{
|
|
|
|
// put some values under the newly created keys
|
|
|
|
key1.SetValue(wxT("first_term"), _T("10"));
|
|
|
|
key1.SetValue(wxT("second_term"), _T("7"));
|
|
|
|
key2a = _T("this is the unnamed value");
|
|
|
|
key2b.SetValue(wxT("sum"), 17);
|
|
|
|
|
|
|
|
// refresh tree
|
|
|
|
pNode->Refresh();
|
|
|
|
wxLogStatus(wxT("Test keys successfully added."));
|
|
|
|
return;
|
|
|
|
}
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
wxLogError(wxT("Creation of test keys failed."));
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegTreeCtrl::OnChar(wxKeyEvent& event)
|
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
switch ( event.GetKeyCode() )
|
|
|
|
{
|
|
|
|
case WXK_DELETE:
|
|
|
|
DeleteSelected();
|
|
|
|
return;
|
|
|
|
|
|
|
|
case WXK_RETURN:
|
|
|
|
if ( event.AltDown() )
|
|
|
|
{
|
|
|
|
ShowProperties();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegTreeCtrl::OnSelChanged(wxTreeEvent& event)
|
|
|
|
{
|
2004-07-19 11:36:01 -04:00
|
|
|
#if wxUSE_STATUSBAR
|
2003-11-20 20:54:43 -05:00
|
|
|
wxFrame *pFrame = (wxFrame *) wxWindow::GetParent();
|
|
|
|
pFrame->SetStatusText(GetNode(event)->FullName(), 1);
|
2004-07-19 11:36:01 -04:00
|
|
|
#else
|
|
|
|
wxUnusedVar(event);
|
|
|
|
#endif // wxUSE_STATUSBAR
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegTreeCtrl::OnItemExpanding(wxTreeEvent& event)
|
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
TreeNode *pNode = GetNode(event);
|
|
|
|
bool bExpanding = event.GetKeyCode() == wxTREE_EXPAND_EXPAND;
|
|
|
|
|
|
|
|
// expansion might take some time
|
|
|
|
wxSetCursor(*wxHOURGLASS_CURSOR);
|
|
|
|
wxLogStatus(wxT("Working..."));
|
|
|
|
wxYield(); // to give the status line a chance to refresh itself
|
|
|
|
m_restoreStatus = true; // some time later...
|
|
|
|
|
|
|
|
if ( pNode->IsKey() )
|
|
|
|
{
|
|
|
|
if ( bExpanding )
|
|
|
|
{
|
|
|
|
// expanding: add subkeys/values
|
|
|
|
if ( !pNode->OnExpand() )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// collapsing: clean up
|
|
|
|
pNode->OnCollapse();
|
|
|
|
}
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
2000-02-14 19:05:36 -05:00
|
|
|
}
|
|
|
|
|
2000-02-24 18:40:42 -05:00
|
|
|
void RegTreeCtrl::OnBeginEdit(wxTreeEvent& event)
|
|
|
|
{
|
|
|
|
TreeNode *pNode = GetNode(event);
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( pNode->IsRoot() || pNode->Parent()->IsRoot() )
|
|
|
|
{
|
2000-02-24 18:40:42 -05:00
|
|
|
wxLogStatus(_T("This registry key can't be renamed."));
|
|
|
|
|
|
|
|
event.Veto();
|
|
|
|
}
|
2003-11-20 20:54:43 -05:00
|
|
|
else
|
|
|
|
{
|
2000-02-24 18:40:42 -05:00
|
|
|
m_nameOld = pNode->m_strName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegTreeCtrl::OnEndEdit(wxTreeEvent& event)
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
|
|
|
|
wxString name = event.GetLabel();
|
|
|
|
|
|
|
|
TreeNode *pNode = GetNode(event);
|
|
|
|
if ( pNode->IsKey() )
|
|
|
|
{
|
|
|
|
wxRegKey& key = pNode->Key();
|
|
|
|
ok = key.Rename(name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pNode = pNode->Parent();
|
|
|
|
wxRegKey& key = pNode->Key();
|
|
|
|
|
|
|
|
ok = key.RenameValue(m_nameOld, name);
|
|
|
|
}
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( !ok )
|
|
|
|
{
|
2000-02-24 18:40:42 -05:00
|
|
|
wxLogError(_T("Failed to rename '%s' to '%s'."),
|
2003-11-20 20:54:43 -05:00
|
|
|
m_nameOld.c_str(), name.c_str());
|
2000-02-24 18:40:42 -05:00
|
|
|
}
|
|
|
|
#if 0 // MSW tree ctrl doesn't like this at all, it hangs
|
2003-11-20 20:54:43 -05:00
|
|
|
else
|
|
|
|
{
|
2000-02-24 18:40:42 -05:00
|
|
|
pNode->Refresh();
|
|
|
|
}
|
|
|
|
#endif // 0
|
|
|
|
}
|
|
|
|
|
2000-02-14 19:05:36 -05:00
|
|
|
void RegTreeCtrl::OnBeginDrag(wxTreeEvent& event)
|
|
|
|
{
|
|
|
|
m_copyOnDrop = event.GetEventType() == wxEVT_COMMAND_TREE_BEGIN_DRAG;
|
|
|
|
|
|
|
|
TreeNode *pNode = GetNode(event);
|
|
|
|
if ( pNode->IsRoot() || pNode->Parent()->IsRoot() )
|
|
|
|
{
|
2001-11-22 04:11:33 -05:00
|
|
|
wxLogStatus(wxT("This registry key can't be %s."),
|
2003-11-20 20:54:43 -05:00
|
|
|
m_copyOnDrop ? wxT("copied") : wxT("moved"));
|
2000-02-14 19:05:36 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-11-22 04:11:33 -05:00
|
|
|
wxLogStatus(wxT("%s item %s..."),
|
2003-11-20 20:54:43 -05:00
|
|
|
m_copyOnDrop ? wxT("Copying") : wxT("Moving"),
|
|
|
|
pNode->FullName());
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2000-02-14 19:05:36 -05:00
|
|
|
m_draggedItem = pNode;
|
|
|
|
|
|
|
|
event.Allow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegTreeCtrl::OnEndDrag(wxTreeEvent& event)
|
|
|
|
{
|
2001-11-22 04:11:33 -05:00
|
|
|
wxCHECK_RET( m_draggedItem, wxT("end drag without begin drag?") );
|
2000-02-14 19:05:36 -05:00
|
|
|
|
|
|
|
// clear the pointer anyhow
|
|
|
|
TreeNode *src = m_draggedItem;
|
|
|
|
m_draggedItem = NULL;
|
|
|
|
|
|
|
|
// where are we going to drop it?
|
|
|
|
TreeNode *dst = GetNode(event);
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( dst && !dst->IsKey() )
|
|
|
|
{
|
2000-02-14 19:05:36 -05:00
|
|
|
// we need a parent key
|
|
|
|
dst = dst->Parent();
|
|
|
|
}
|
2003-11-20 20:54:43 -05:00
|
|
|
|
|
|
|
if ( !dst || dst->IsRoot() )
|
|
|
|
{
|
2001-11-22 04:11:33 -05:00
|
|
|
wxLogError(wxT("Can't create a key here."));
|
2000-02-14 19:05:36 -05:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isKey = src->IsKey();
|
|
|
|
if ( (isKey && (src == dst)) ||
|
2000-02-15 18:57:33 -05:00
|
|
|
(!isKey && (dst->Parent() == src)) ) {
|
2001-11-22 04:11:33 -05:00
|
|
|
wxLogStatus(wxT("Can't copy something on itself"));
|
2000-02-14 19:05:36 -05:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove the "Registry Root\\" from the full name
|
|
|
|
wxString nameSrc, nameDst;
|
|
|
|
nameSrc << wxString(src->FullName()).AfterFirst('\\');
|
|
|
|
nameDst << wxString(dst->FullName()).AfterFirst('\\') << '\\'
|
|
|
|
<< wxString(src->FullName()).AfterLast('\\');
|
|
|
|
|
2002-12-15 12:25:36 -05:00
|
|
|
wxString verb = m_copyOnDrop ? _T("copy") : _T("move");
|
|
|
|
wxString what = isKey ? _T("key") : _T("value");
|
2000-02-14 19:05:36 -05:00
|
|
|
|
|
|
|
if ( wxMessageBox(wxString::Format
|
|
|
|
(
|
2001-11-22 04:11:33 -05:00
|
|
|
wxT("Do you really want to %s the %s %s to %s?"),
|
2000-02-14 19:05:36 -05:00
|
|
|
verb.c_str(),
|
|
|
|
what.c_str(),
|
|
|
|
nameSrc.c_str(),
|
|
|
|
nameDst.c_str()
|
|
|
|
),
|
2002-12-15 12:25:36 -05:00
|
|
|
_T("RegTest Confirm"),
|
2000-02-14 19:05:36 -05:00
|
|
|
wxICON_QUESTION | wxYES_NO | wxCANCEL, this) != wxYES ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok;
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( isKey )
|
|
|
|
{
|
2000-02-14 19:05:36 -05:00
|
|
|
wxRegKey& key = src->Key();
|
2000-02-15 18:57:33 -05:00
|
|
|
wxRegKey keyDst(dst->Key(), src->m_strName);
|
2003-11-20 20:54:43 -05:00
|
|
|
ok = keyDst.Create(false);
|
|
|
|
if ( !ok )
|
|
|
|
{
|
2002-12-04 09:11:26 -05:00
|
|
|
wxLogError(wxT("Key '%s' already exists"), keyDst.GetName().c_str());
|
2000-02-15 18:57:33 -05:00
|
|
|
}
|
2003-11-20 20:54:43 -05:00
|
|
|
else
|
|
|
|
{
|
2000-02-15 18:57:33 -05:00
|
|
|
ok = key.Copy(keyDst);
|
|
|
|
}
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( ok && !m_copyOnDrop )
|
|
|
|
{
|
2000-02-14 19:05:36 -05:00
|
|
|
// delete the old key
|
|
|
|
ok = key.DeleteSelf();
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( ok )
|
|
|
|
{
|
2000-02-14 19:05:36 -05:00
|
|
|
src->Parent()->Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-11-20 20:54:43 -05:00
|
|
|
else // value
|
|
|
|
{
|
2000-02-14 19:05:36 -05:00
|
|
|
wxRegKey& key = src->Parent()->Key();
|
|
|
|
ok = key.CopyValue(src->m_strName, dst->Key());
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( ok && !m_copyOnDrop )
|
|
|
|
{
|
2000-02-15 18:57:33 -05:00
|
|
|
// we moved it, so delete the old one
|
2000-02-14 19:05:36 -05:00
|
|
|
ok = key.DeleteValue(src->m_strName);
|
|
|
|
}
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( !ok )
|
|
|
|
{
|
2001-11-22 04:11:33 -05:00
|
|
|
wxLogError(wxT("Failed to %s registry %s."),
|
|
|
|
verb.c_str(), what.c_str());
|
2000-02-14 19:05:36 -05:00
|
|
|
}
|
2003-11-20 20:54:43 -05:00
|
|
|
else
|
|
|
|
{
|
2000-02-24 18:40:42 -05:00
|
|
|
dst->Refresh();
|
|
|
|
}
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// TreeNode implementation
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
bool RegTreeCtrl::TreeNode::OnExpand()
|
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
// we add children only once
|
|
|
|
if ( !m_aChildren.IsEmpty() )
|
|
|
|
{
|
|
|
|
// we've been already expanded
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( IsRoot() )
|
|
|
|
{
|
|
|
|
// we're the root key
|
|
|
|
m_pTree->AddStdKeys();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Parent()->IsRoot() )
|
|
|
|
{
|
|
|
|
// we're a standard key
|
|
|
|
m_pKey = new wxRegKey(m_strName);
|
|
|
|
}
|
1998-05-20 10:21:00 -04:00
|
|
|
else
|
2003-11-20 20:54:43 -05:00
|
|
|
{
|
|
|
|
// we're a normal key
|
|
|
|
m_pKey = new wxRegKey(*(Parent()->m_pKey), m_strName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !m_pKey->Open() )
|
|
|
|
{
|
|
|
|
wxLogError(wxT("The key '%s' can't be opened."), FullName());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we're empty, we shouldn't be expandable at all
|
|
|
|
bool isEmpty = true;
|
|
|
|
|
|
|
|
// enumeration variables
|
|
|
|
long l;
|
|
|
|
wxString str;
|
|
|
|
bool bCont;
|
|
|
|
|
|
|
|
// enumerate all subkeys
|
|
|
|
bCont = m_pKey->GetFirstKey(str, l);
|
|
|
|
while ( bCont )
|
|
|
|
{
|
|
|
|
m_pTree->InsertNewTreeNode(this, str, RegImageList::ClosedKey);
|
|
|
|
bCont = m_pKey->GetNextKey(str, l);
|
|
|
|
|
|
|
|
// we have at least this key...
|
|
|
|
isEmpty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// enumerate all values
|
|
|
|
bCont = m_pKey->GetFirstValue(str, l);
|
|
|
|
while ( bCont )
|
|
|
|
{
|
|
|
|
wxString strItem;
|
2005-05-23 06:48:27 -04:00
|
|
|
if (str.empty())
|
2003-11-20 20:54:43 -05:00
|
|
|
strItem = _T("<default>");
|
|
|
|
else
|
|
|
|
strItem = str;
|
|
|
|
strItem += _T(" = ");
|
|
|
|
|
|
|
|
// determine the appropriate icon
|
|
|
|
RegImageList::Icon icon;
|
|
|
|
switch ( m_pKey->GetValueType(str) )
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
case wxRegKey::Type_String:
|
|
|
|
case wxRegKey::Type_Expand_String:
|
|
|
|
case wxRegKey::Type_Multi_String:
|
|
|
|
{
|
|
|
|
wxString strValue;
|
|
|
|
icon = RegImageList::TextValue;
|
|
|
|
m_pKey->QueryValue(str, strValue);
|
|
|
|
strItem += strValue;
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
case wxRegKey::Type_None:
|
|
|
|
// @@ handle the error...
|
|
|
|
icon = RegImageList::BinaryValue;
|
|
|
|
break;
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
case wxRegKey::Type_Dword:
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
long l;
|
|
|
|
m_pKey->QueryValue(str, &l);
|
|
|
|
strItem << l;
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// fall through
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
default:
|
|
|
|
icon = RegImageList::BinaryValue;
|
|
|
|
}
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
m_pTree->InsertNewTreeNode(this, str, icon, &strItem);
|
|
|
|
bCont = m_pKey->GetNextValue(str, l);
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
// we have at least this value...
|
|
|
|
isEmpty = false;
|
|
|
|
}
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( isEmpty )
|
|
|
|
{
|
|
|
|
// this is for the case when our last child was just deleted
|
|
|
|
wxTreeItemId theId(Id()); // Temp variable seems necessary for BC++
|
|
|
|
m_pTree->Collapse(theId);
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
// we won't be expanded any more
|
|
|
|
m_pTree->SetItemHasChildren(theId, false);
|
|
|
|
}
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
return true;
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegTreeCtrl::TreeNode::OnCollapse()
|
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
DestroyChildren();
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
delete m_pKey;
|
|
|
|
m_pKey = NULL;
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2000-02-14 19:05:36 -05:00
|
|
|
void RegTreeCtrl::TreeNode::Refresh()
|
|
|
|
{
|
2000-02-15 18:57:33 -05:00
|
|
|
if ( !IsKey() )
|
|
|
|
return;
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
wxTreeItemId theId(Id()); // Temp variable seems necessary for BC++
|
|
|
|
bool wasExpanded = m_pTree->IsExpanded(theId);
|
2000-02-24 18:40:42 -05:00
|
|
|
if ( wasExpanded )
|
2000-07-15 15:51:35 -04:00
|
|
|
m_pTree->Collapse(theId);
|
2000-02-24 18:40:42 -05:00
|
|
|
|
|
|
|
OnCollapse();
|
2000-07-15 15:51:35 -04:00
|
|
|
m_pTree->SetItemHasChildren(theId);
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( wasExpanded )
|
|
|
|
{
|
2000-07-15 15:51:35 -04:00
|
|
|
m_pTree->Expand(theId);
|
2000-02-15 18:57:33 -05:00
|
|
|
OnExpand();
|
|
|
|
}
|
2000-02-14 19:05:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RegTreeCtrl::TreeNode::DeleteChild(TreeNode *child)
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2000-02-14 19:05:36 -05:00
|
|
|
int index = m_aChildren.Index(child);
|
2003-11-20 20:54:43 -05:00
|
|
|
wxCHECK_MSG( index != wxNOT_FOUND, false,
|
2001-11-22 04:11:33 -05:00
|
|
|
wxT("our child in tree should be in m_aChildren") );
|
2000-02-14 19:05:36 -05:00
|
|
|
|
|
|
|
m_aChildren.RemoveAt((size_t)index);
|
|
|
|
|
|
|
|
bool ok;
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( child->IsKey() )
|
|
|
|
{
|
2000-02-14 19:05:36 -05:00
|
|
|
// must close key before deleting it
|
|
|
|
child->OnCollapse();
|
|
|
|
|
|
|
|
ok = Key().DeleteKey(child->m_strName);
|
|
|
|
}
|
2003-11-20 20:54:43 -05:00
|
|
|
else
|
|
|
|
{
|
2000-02-14 19:05:36 -05:00
|
|
|
ok = Key().DeleteValue(child->m_strName);
|
|
|
|
}
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( ok )
|
|
|
|
{
|
2000-07-15 15:51:35 -04:00
|
|
|
wxTreeItemId theId(child->Id()); // Temp variable seems necessary for BC++
|
|
|
|
m_pTree->Delete(theId);
|
2000-02-14 19:05:36 -05:00
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegTreeCtrl::TreeNode::DestroyChildren()
|
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
// destroy all children
|
|
|
|
size_t nCount = m_aChildren.GetCount();
|
|
|
|
for ( size_t n = 0; n < nCount; n++ )
|
|
|
|
{
|
2004-05-25 15:31:13 -04:00
|
|
|
wxTreeItemId lId = m_aChildren[n]->Id();
|
|
|
|
m_pTree->Delete(lId);
|
2003-11-20 20:54:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
m_aChildren.Empty();
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
RegTreeCtrl::TreeNode::~TreeNode()
|
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
delete m_pKey;
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2001-11-22 04:11:33 -05:00
|
|
|
const wxChar *RegTreeCtrl::TreeNode::FullName() const
|
1998-05-20 10:21:00 -04:00
|
|
|
{
|
2003-11-20 20:54:43 -05:00
|
|
|
static wxString s_strName;
|
|
|
|
|
|
|
|
if ( IsRoot() )
|
|
|
|
{
|
|
|
|
return wxT("Registry Root");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// our own registry key might not (yet) exist or we might be a value,
|
|
|
|
// so just use the parent's and concatenate
|
|
|
|
s_strName = Parent()->FullName();
|
|
|
|
s_strName << wxT('\\') << m_strName;
|
|
|
|
|
|
|
|
return s_strName;
|
|
|
|
}
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// operations on RegTreeCtrl
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-02-24 18:40:42 -05:00
|
|
|
void RegTreeCtrl::GoTo(const wxString& location)
|
|
|
|
{
|
|
|
|
wxStringTokenizer tk(location, _T("\\"));
|
|
|
|
|
|
|
|
wxTreeItemId id = GetRootItem();
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
while ( tk.HasMoreTokens() )
|
|
|
|
{
|
2000-02-24 18:40:42 -05:00
|
|
|
wxString subkey = tk.GetNextToken();
|
|
|
|
|
|
|
|
wxTreeItemId idCurrent = id;
|
|
|
|
if ( !IsExpanded(idCurrent) )
|
|
|
|
Expand(idCurrent);
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
wxTreeItemIdValue dummy;
|
2000-02-24 18:40:42 -05:00
|
|
|
id = GetFirstChild(idCurrent, dummy);
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( idCurrent == GetRootItem() )
|
|
|
|
{
|
2000-02-24 18:40:42 -05:00
|
|
|
// special case: we understand both HKCU and HKEY_CURRENT_USER here
|
2003-11-20 20:54:43 -05:00
|
|
|
for ( size_t key = 0; key < wxRegKey::nStdKeys; key++ )
|
|
|
|
{
|
|
|
|
if ( subkey == wxRegKey::GetStdKeyName(key)
|
|
|
|
|| subkey == wxRegKey::GetStdKeyShortName(key) )
|
|
|
|
{
|
2000-02-24 18:40:42 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
id = GetNextChild(idCurrent, dummy);
|
|
|
|
}
|
|
|
|
}
|
2003-11-20 20:54:43 -05:00
|
|
|
else
|
|
|
|
{
|
2000-02-24 18:40:42 -05:00
|
|
|
// enum all children
|
2003-11-20 20:54:43 -05:00
|
|
|
while ( id.IsOk() )
|
|
|
|
{
|
2000-02-24 18:40:42 -05:00
|
|
|
if ( subkey == ((TreeNode *)GetItemData(id))->m_strName )
|
|
|
|
break;
|
|
|
|
|
|
|
|
id = GetNextChild(idCurrent, dummy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( !id.IsOk() )
|
|
|
|
{
|
2000-02-24 18:40:42 -05:00
|
|
|
wxLogError(_T("No such key '%s'."), location.c_str());
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( id.IsOk() )
|
|
|
|
SelectItem(id);
|
|
|
|
}
|
|
|
|
|
1998-05-20 10:21:00 -04:00
|
|
|
void RegTreeCtrl::DeleteSelected()
|
|
|
|
{
|
2004-05-25 15:31:13 -04:00
|
|
|
wxTreeItemId lCurrent = GetSelection(),
|
|
|
|
lParent = GetItemParent(lCurrent);
|
2003-11-20 20:54:43 -05:00
|
|
|
|
2004-05-25 15:31:13 -04:00
|
|
|
if ( lParent == GetRootItem() )
|
2003-11-20 20:54:43 -05:00
|
|
|
{
|
|
|
|
wxLogError(wxT("Can't delete root key."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent),
|
2004-05-25 15:31:13 -04:00
|
|
|
*pParent = (TreeNode *)GetItemData(lParent);
|
2003-11-20 20:54:43 -05:00
|
|
|
|
|
|
|
wxCHECK_RET(pCurrent && pParent, wxT("either node or parent without data?"));
|
|
|
|
|
|
|
|
if ( pParent->IsRoot() )
|
|
|
|
{
|
|
|
|
wxLogError(wxT("Can't delete standard key."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString what = pCurrent->IsKey() ? _T("key") : _T("value");
|
|
|
|
if ( wxMessageBox(wxString::Format
|
|
|
|
(
|
|
|
|
wxT("Do you really want to delete this %s?"),
|
|
|
|
what.c_str()
|
|
|
|
),
|
|
|
|
_T("Confirmation"),
|
|
|
|
wxICON_QUESTION | wxYES_NO | wxCANCEL, this) != wxYES )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pParent->DeleteChild(pCurrent);
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegTreeCtrl::CreateNewKey(const wxString& strName)
|
|
|
|
{
|
2004-05-25 15:31:13 -04:00
|
|
|
wxTreeItemId lCurrent = GetSelection();
|
2003-11-20 20:54:43 -05:00
|
|
|
TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent);
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
wxCHECK_RET( pCurrent != NULL, wxT("node without data?") );
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
wxASSERT( pCurrent->IsKey() ); // check must have been done before
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( pCurrent->IsRoot() )
|
|
|
|
{
|
|
|
|
wxLogError(wxT("Can't create a new key under the root key."));
|
|
|
|
return;
|
|
|
|
}
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
wxRegKey key(pCurrent->Key(), strName);
|
|
|
|
if ( key.Create() )
|
|
|
|
pCurrent->Refresh();
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegTreeCtrl::CreateNewTextValue(const wxString& strName)
|
|
|
|
{
|
2004-05-25 15:31:13 -04:00
|
|
|
wxTreeItemId lCurrent = GetSelection();
|
2003-11-20 20:54:43 -05:00
|
|
|
TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent);
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
wxCHECK_RET( pCurrent != NULL, wxT("node without data?") );
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
wxASSERT( pCurrent->IsKey() ); // check must have been done before
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( pCurrent->IsRoot() )
|
|
|
|
{
|
|
|
|
wxLogError(wxT("Can't create a new value under the root key."));
|
|
|
|
return;
|
|
|
|
}
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( pCurrent->Key().SetValue(strName, wxEmptyString) )
|
|
|
|
pCurrent->Refresh();
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegTreeCtrl::CreateNewBinaryValue(const wxString& strName)
|
|
|
|
{
|
2004-05-25 15:31:13 -04:00
|
|
|
wxTreeItemId lCurrent = GetSelection();
|
2003-11-20 20:54:43 -05:00
|
|
|
TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent);
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
wxCHECK_RET( pCurrent != NULL, wxT("node without data?") );
|
2000-02-14 19:05:36 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
wxASSERT( pCurrent->IsKey() ); // check must have been done before
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( pCurrent->IsRoot() )
|
|
|
|
{
|
|
|
|
wxLogError(wxT("Can't create a new value under the root key."));
|
|
|
|
return;
|
|
|
|
}
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
if ( pCurrent->Key().SetValue(strName, 0) )
|
|
|
|
pCurrent->Refresh();
|
1998-05-20 10:21:00 -04:00
|
|
|
}
|
|
|
|
|
2000-02-14 19:05:36 -05:00
|
|
|
void RegTreeCtrl::ShowProperties()
|
|
|
|
{
|
2004-05-25 15:31:13 -04:00
|
|
|
wxTreeItemId lCurrent = GetSelection();
|
2000-02-14 19:05:36 -05:00
|
|
|
TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent);
|
|
|
|
|
|
|
|
if ( !pCurrent || pCurrent->IsRoot() )
|
|
|
|
{
|
2001-11-22 04:11:33 -05:00
|
|
|
wxLogStatus(wxT("No properties"));
|
2000-02-14 19:05:36 -05:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( pCurrent->IsKey() )
|
|
|
|
{
|
|
|
|
const wxRegKey& key = pCurrent->Key();
|
|
|
|
size_t nSubKeys, nValues;
|
|
|
|
if ( !key.GetKeyInfo(&nSubKeys, NULL, &nValues, NULL) )
|
|
|
|
{
|
2001-11-22 04:11:33 -05:00
|
|
|
wxLogError(wxT("Couldn't get key info"));
|
2000-02-14 19:05:36 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-11-22 04:11:33 -05:00
|
|
|
wxLogMessage(wxT("Key '%s' has %u subkeys and %u values."),
|
2000-02-14 19:05:36 -05:00
|
|
|
key.GetName().c_str(), nSubKeys, nValues);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // it's a value
|
|
|
|
{
|
|
|
|
TreeNode *parent = pCurrent->Parent();
|
2001-11-22 04:11:33 -05:00
|
|
|
wxCHECK_RET( parent, wxT("reg value without key?") );
|
2000-02-14 19:05:36 -05:00
|
|
|
|
|
|
|
const wxRegKey& key = parent->Key();
|
2001-11-22 04:11:33 -05:00
|
|
|
const wxChar *value = pCurrent->m_strName.c_str();
|
|
|
|
wxLogMessage(wxT("Value '%s' under the key '%s' is of type ")
|
2003-11-20 20:54:43 -05:00
|
|
|
wxT("%d (%s)."),
|
|
|
|
value,
|
|
|
|
parent->m_strName.c_str(),
|
|
|
|
key.GetValueType(value),
|
|
|
|
key.IsNumericValue(value) ? wxT("numeric") : wxT("string"));
|
2000-02-14 19:05:36 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-20 10:21:00 -04:00
|
|
|
bool RegTreeCtrl::IsKeySelected() const
|
|
|
|
{
|
2004-05-25 15:31:13 -04:00
|
|
|
wxTreeItemId lCurrent = GetSelection();
|
2003-11-20 20:54:43 -05:00
|
|
|
TreeNode *pCurrent = (TreeNode *) GetItemData(lCurrent);
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
wxCHECK( pCurrent != NULL, false );
|
1998-05-20 10:21:00 -04:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
return pCurrent->IsKey();
|
2000-02-14 19:05:36 -05:00
|
|
|
}
|
2000-02-15 18:57:33 -05:00
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
void RegTreeCtrl::DoRefresh()
|
2000-02-15 18:57:33 -05:00
|
|
|
{
|
2004-05-25 15:31:13 -04:00
|
|
|
wxTreeItemId lId = GetSelection();
|
2000-02-15 18:57:33 -05:00
|
|
|
if ( !lId )
|
|
|
|
return;
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
TreeNode *pNode = (TreeNode *) GetItemData(lId);
|
2000-02-15 18:57:33 -05:00
|
|
|
|
2001-11-22 04:11:33 -05:00
|
|
|
wxCHECK_RET( pNode != NULL, wxT("tree item without data?") );
|
2000-02-15 18:57:33 -05:00
|
|
|
|
|
|
|
pNode->Refresh();
|
|
|
|
}
|
|
|
|
|
2003-11-20 20:54:43 -05:00
|
|
|
#endif
|