]> git.saurik.com Git - wxWidgets.git/blame - samples/regtest/regtest.cpp
added network-to-host noops
[wxWidgets.git] / samples / regtest / regtest.cpp
CommitLineData
bbf1f0e5 1///////////////////////////////////////////////////////////////////////////////
23f681ec 2// Name: regtest.cpp
bbf1f0e5
KB
3// Purpose: wxRegKey class demo
4// Author: Vadim Zeitlin
23f681ec 5// Modified by:
bbf1f0e5
KB
6// Created: 03.04.98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9// Licence: wxWindows license
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19#include "wx/wxprec.h"
20
21#ifdef __BORLANDC__
721b8397 22# pragma hdrstop
bbf1f0e5
KB
23#endif
24
25#ifndef WX_PRECOMP
721b8397 26# include "wx/wx.h"
bbf1f0e5
KB
27#endif
28
bbf1f0e5 29#include "wx/treectrl.h"
721b8397
DS
30#include "wx/config.h"
31#include "wx/imaglist.h"
c41ea66a
VZ
32#include "wx/tokenzr.h"
33
721b8397
DS
34#if wxUSE_CONFIG_NATIVE && defined( __WXMSW__ )
35# define DO_REGTEST 1
36#else
37# define DO_REGTEST 0
38#endif
39
bbf1f0e5
KB
40// ----------------------------------------------------------------------------
41// application type
42// ----------------------------------------------------------------------------
43class RegApp : public wxApp
23f681ec 44{
bbf1f0e5 45public:
721b8397 46 bool OnInit();
bbf1f0e5
KB
47};
48
49// ----------------------------------------------------------------------------
50// image list with registry icons
51// ----------------------------------------------------------------------------
52class RegImageList : public wxImageList
53{
54public:
721b8397
DS
55 enum Icon
56 {
57 Root,
58 ClosedKey,
59 OpenedKey,
60 TextValue,
61 BinaryValue
62 };
63
64 RegImageList();
bbf1f0e5
KB
65};
66
721b8397
DS
67#if DO_REGTEST
68
bbf1f0e5
KB
69// ----------------------------------------------------------------------------
70// our control
71// ----------------------------------------------------------------------------
72class RegTreeCtrl : public wxTreeCtrl
73{
74public:
721b8397
DS
75 // ctor & dtor
76 RegTreeCtrl(wxWindow *parent, wxWindowID id);
77 virtual ~RegTreeCtrl();
bbf1f0e5 78
721b8397
DS
79 // notifications
80 void OnDeleteItem (wxTreeEvent& event);
81 void OnItemExpanding (wxTreeEvent& event);
82 void OnSelChanged (wxTreeEvent& event);
bbf1f0e5 83
721b8397
DS
84 void OnBeginEdit (wxTreeEvent& event);
85 void OnEndEdit (wxTreeEvent& event);
c41ea66a 86
721b8397
DS
87 void OnBeginDrag (wxTreeEvent& event);
88 void OnEndDrag (wxTreeEvent& event);
23f681ec 89
721b8397
DS
90 void OnRightClick (wxMouseEvent& event);
91 void OnChar (wxKeyEvent& event);
92 void OnIdle (wxIdleEvent& event);
bbf1f0e5 93
721b8397
DS
94 // forwarded notifications (by the frame)
95 void OnMenuTest();
bbf1f0e5 96
721b8397
DS
97 // operations
98 void GoTo(const wxString& location);
99 void DoRefresh();
100 void DeleteSelected();
101 void ShowProperties();
102 void CreateNewKey(const wxString& strName);
103 void CreateNewTextValue(const wxString& strName);
104 void CreateNewBinaryValue(const wxString& strName);
bbf1f0e5 105
721b8397
DS
106 // information
107 bool IsKeySelected() const;
bbf1f0e5 108
bbf1f0e5 109private:
721b8397
DS
110 // structure describing a registry key/value
111 class TreeNode : public wxTreeItemData
112 {
113 WX_DEFINE_ARRAY_PTR(TreeNode *, TreeChildren);
114 public:
115 RegTreeCtrl *m_pTree; // must be !NULL
116 TreeNode *m_pParent; // NULL only for the root node
117 long m_id; // the id of the tree control item
118 wxString m_strName; // name of the key/value
119 TreeChildren m_aChildren; // array of subkeys/values
120 bool m_bKey; // key or value?
121 wxRegKey *m_pKey; // only may be !NULL if m_bKey == true
23f681ec 122
721b8397
DS
123 // trivial accessors
124 long Id() const { return m_id; }
125 bool IsRoot() const { return m_pParent == NULL; }
126 bool IsKey() const { return m_bKey; }
127 TreeNode *Parent() const { return m_pParent; }
23f681ec 128
721b8397
DS
129 // notifications
130 bool OnExpand();
131 void OnCollapse();
23f681ec 132
721b8397
DS
133 // operations
134 void Refresh();
135 bool DeleteChild(TreeNode *child);
136 void DestroyChildren();
137 const wxChar *FullName() const;
23f681ec 138
721b8397
DS
139 // get the associated key: make sure the pointer is !NULL
140 wxRegKey& Key() { if ( !m_pKey ) OnExpand(); return *m_pKey; }
23f681ec 141
721b8397
DS
142 // dtor deletes all children
143 ~TreeNode();
144 };
bbf1f0e5 145
721b8397
DS
146 wxImageList *m_imageList;
147 wxMenu *m_pMenuPopup;
23f681ec 148
721b8397 149 TreeNode *m_pRoot;
23f681ec 150
721b8397
DS
151 TreeNode *m_draggedItem; // the item being dragged
152 bool m_copyOnDrop; // if false, then move
23f681ec 153
721b8397 154 bool m_restoreStatus; // after OnItemExpanding()
bbf1f0e5 155
721b8397 156 wxString m_nameOld; // the initial value of item being renamed
c41ea66a 157
721b8397 158 TreeNode *GetNode(const wxTreeEvent& event)
2e3b8fa7 159 { return (TreeNode *)GetItemData(event.GetItem()); }
bbf1f0e5
KB
160
161public:
721b8397
DS
162 // create a new node and insert it to the tree
163 TreeNode *InsertNewTreeNode(TreeNode *pParent,
164 const wxString& strName,
165 int idImage = RegImageList::ClosedKey,
166 const wxString *pstrValue = NULL);
167
168 // add standard registry keys
169 void AddStdKeys();
23f681ec
VZ
170
171private:
721b8397 172 DECLARE_EVENT_TABLE()
bbf1f0e5
KB
173};
174
721b8397
DS
175#endif // #if DO_REGTEST
176
bbf1f0e5
KB
177// ----------------------------------------------------------------------------
178// the main window of our application
179// ----------------------------------------------------------------------------
180class RegFrame : public wxFrame
23f681ec 181{
bbf1f0e5 182public:
721b8397
DS
183 // ctor & dtor
184 RegFrame(wxFrame *parent, wxChar *title, int x, int y, int w, int h);
185 virtual ~RegFrame();
23f681ec 186
721b8397
DS
187 // callbacks
188 void OnQuit (wxCommandEvent& event);
189 void OnAbout(wxCommandEvent& event);
190 void OnTest (wxCommandEvent& event);
bbf1f0e5 191
721b8397 192 void OnGoTo (wxCommandEvent& event);
c41ea66a 193
721b8397
DS
194 void OnExpand (wxCommandEvent& event);
195 void OnCollapse(wxCommandEvent& event);
196 void OnToggle (wxCommandEvent& event);
197 void OnRefresh (wxCommandEvent& event);
bbf1f0e5 198
721b8397
DS
199 void OnDelete (wxCommandEvent& event);
200 void OnNewKey (wxCommandEvent& event);
201 void OnNewText (wxCommandEvent& event);
202 void OnNewBinary(wxCommandEvent& event);
bbf1f0e5 203
721b8397 204 void OnInfo (wxCommandEvent& event);
bbf1f0e5 205
721b8397 206 DECLARE_EVENT_TABLE()
bbf1f0e5
KB
207
208private:
721b8397
DS
209
210#if DO_REGTEST
211 RegTreeCtrl *m_treeCtrl;
212#endif
bbf1f0e5
KB
213};
214
215// ----------------------------------------------------------------------------
216// various ids
217// ----------------------------------------------------------------------------
218
219enum
220{
721b8397
DS
221 Menu_Quit = 100,
222 Menu_About,
223 Menu_Test,
224 Menu_GoTo,
225 Menu_Expand,
226 Menu_Collapse,
227 Menu_Toggle,
228 Menu_Refresh,
229 Menu_New,
230 Menu_NewKey,
231 Menu_NewText,
232 Menu_NewBinary,
233 Menu_Delete,
234 Menu_Info,
235
236 Ctrl_RegTree = 200,
bbf1f0e5
KB
237};
238
239// ----------------------------------------------------------------------------
240// event tables
241// ----------------------------------------------------------------------------
242
243BEGIN_EVENT_TABLE(RegFrame, wxFrame)
721b8397
DS
244 EVT_MENU(Menu_Test, RegFrame::OnTest)
245 EVT_MENU(Menu_About, RegFrame::OnAbout)
246 EVT_MENU(Menu_Quit, RegFrame::OnQuit)
247 EVT_MENU(Menu_GoTo, RegFrame::OnGoTo)
248 EVT_MENU(Menu_Expand, RegFrame::OnExpand)
249 EVT_MENU(Menu_Collapse, RegFrame::OnCollapse)
250 EVT_MENU(Menu_Toggle, RegFrame::OnToggle)
251 EVT_MENU(Menu_Refresh, RegFrame::OnRefresh)
252 EVT_MENU(Menu_Delete, RegFrame::OnDelete)
253 EVT_MENU(Menu_NewKey, RegFrame::OnNewKey)
254 EVT_MENU(Menu_NewText, RegFrame::OnNewText)
255 EVT_MENU(Menu_NewBinary,RegFrame::OnNewBinary)
256 EVT_MENU(Menu_Info, RegFrame::OnInfo)
bbf1f0e5
KB
257END_EVENT_TABLE()
258
721b8397
DS
259#if DO_REGTEST
260
bbf1f0e5 261BEGIN_EVENT_TABLE(RegTreeCtrl, wxTreeCtrl)
721b8397
DS
262 EVT_TREE_DELETE_ITEM (Ctrl_RegTree, RegTreeCtrl::OnDeleteItem)
263 EVT_TREE_ITEM_EXPANDING(Ctrl_RegTree, RegTreeCtrl::OnItemExpanding)
264 EVT_TREE_SEL_CHANGED (Ctrl_RegTree, RegTreeCtrl::OnSelChanged)
c41ea66a 265
721b8397
DS
266 EVT_TREE_BEGIN_LABEL_EDIT(Ctrl_RegTree, RegTreeCtrl::OnBeginEdit)
267 EVT_TREE_END_LABEL_EDIT (Ctrl_RegTree, RegTreeCtrl::OnEndEdit)
c41ea66a 268
721b8397
DS
269 EVT_TREE_BEGIN_DRAG (Ctrl_RegTree, RegTreeCtrl::OnBeginDrag)
270 EVT_TREE_BEGIN_RDRAG (Ctrl_RegTree, RegTreeCtrl::OnBeginDrag)
271 EVT_TREE_END_DRAG (Ctrl_RegTree, RegTreeCtrl::OnEndDrag)
bbf1f0e5 272
721b8397
DS
273 EVT_CHAR (RegTreeCtrl::OnChar)
274 EVT_RIGHT_DOWN(RegTreeCtrl::OnRightClick)
275 EVT_IDLE (RegTreeCtrl::OnIdle)
bbf1f0e5
KB
276END_EVENT_TABLE()
277
721b8397
DS
278#endif
279
bbf1f0e5
KB
280// ============================================================================
281// implementation
282// ============================================================================
283
284// ----------------------------------------------------------------------------
285// global functions
286// ----------------------------------------------------------------------------
287
288// create the "registry operations" menu
289wxMenu *CreateRegistryMenu()
290{
721b8397
DS
291 wxMenu *pMenuNew = new wxMenu;
292 pMenuNew->Append(Menu_NewKey, _T("&Key"), _T("Create a new key"));
293 pMenuNew->AppendSeparator();
294 pMenuNew->Append(Menu_NewText, _T("&Text value"), _T("Create a new text value"));
295 pMenuNew->Append(Menu_NewBinary, _T("&Binary value"), _T("Create a new binary value"));
296
297 wxMenu *pMenuReg = new wxMenu;
298 pMenuReg->Append(Menu_New, _T("&New"), pMenuNew);
299 pMenuReg->Append(Menu_Delete, _T("&Delete..."), _T("Delete selected key/value"));
300 pMenuReg->AppendSeparator();
301 pMenuReg->Append(Menu_GoTo, _T("&Go to...\tCtrl-G"), _T("Go to registry key"));
302 pMenuReg->Append(Menu_Expand, _T("&Expand"), _T("Expand current key"));
303 pMenuReg->Append(Menu_Collapse, _T("&Collapse"), _T("Collapse current key"));
304 pMenuReg->Append(Menu_Toggle, _T("&Toggle"), _T("Toggle current key"));
305 pMenuReg->AppendSeparator();
306 pMenuReg->Append(Menu_Refresh, _T("&Refresh"), _T("Refresh the subtree"));
307 pMenuReg->AppendSeparator();
308 pMenuReg->Append(Menu_Info, _T("&Properties"),_T("Information about current selection"));
309
310 return pMenuReg;
bbf1f0e5
KB
311}
312
313// ----------------------------------------------------------------------------
314// application class
315// ----------------------------------------------------------------------------
316IMPLEMENT_APP(RegApp)
317
318// `Main program' equivalent, creating windows and returning main app frame
319bool RegApp::OnInit()
320{
721b8397
DS
321 // create the main frame window and show it
322 RegFrame *frame = new RegFrame(NULL, _T("wxRegTest"), 50, 50, 600, 350);
323 frame->Show(true);
23f681ec 324
721b8397 325 SetTopWindow(frame);
bbf1f0e5 326
721b8397 327 return true;
bbf1f0e5
KB
328}
329
330// ----------------------------------------------------------------------------
331// RegFrame
332// ----------------------------------------------------------------------------
333
600683ca 334RegFrame::RegFrame(wxFrame *parent, wxChar *title, int x, int y, int w, int h)
bbf1f0e5
KB
335 : wxFrame(parent, -1, title, wxPoint(x, y), wxSize(w, h))
336{
721b8397
DS
337 // this reduces flicker effects
338 SetBackgroundColour(wxColour(255, 255, 255));
339
340 // set the icon
341 // ------------
342 SetIcon(wxIcon(_T("app_icon")));
343
344 // create menu
345 // -----------
346 wxMenu *pMenuFile = new wxMenu;
347 pMenuFile->Append(Menu_Test, _T("Te&st"), _T("Test key creation"));
348 pMenuFile->AppendSeparator();
349 pMenuFile->Append(Menu_About, _T("&About..."), _T("Show an extraordinarly beautiful dialog"));
350 pMenuFile->AppendSeparator();
351 pMenuFile->Append(Menu_Quit, _T("E&xit"), _T("Quit this program"));
352
353 wxMenuBar *pMenu = new wxMenuBar;
354 pMenu->Append(pMenuFile, _T("&File"));
355 pMenu->Append(CreateRegistryMenu(), _T("&Registry"));
356 SetMenuBar(pMenu);
357
358#if DO_REGTEST
359 // create child controls
360 // ---------------------
361 m_treeCtrl = new RegTreeCtrl(this, Ctrl_RegTree);
362#endif
363
364 // create the status line
365 // ----------------------
366 CreateStatusBar(2);
bbf1f0e5
KB
367}
368
23f681ec 369RegFrame::~RegFrame()
bbf1f0e5 370{
721b8397
DS
371#if DO_REGTEST
372 // this makes deletion of it *much* quicker
373 m_treeCtrl->Hide();
374#endif
bbf1f0e5
KB
375}
376
721b8397 377void RegFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
bbf1f0e5 378{
721b8397 379 Close(true);
bbf1f0e5
KB
380}
381
721b8397 382void RegFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
bbf1f0e5 383{
721b8397
DS
384 wxMessageDialog dialog(this,
385 _T("wxRegistry sample\n")
386