regtest.cpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: regtest.cpp
  3. // Purpose: wxRegKey class demo
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 03.04.98
  7. // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. // ============================================================================
  11. // declarations
  12. // ============================================================================
  13. // ----------------------------------------------------------------------------
  14. // headers
  15. // ----------------------------------------------------------------------------
  16. #include "wx/wxprec.h"
  17. #ifdef __BORLANDC__
  18. # pragma hdrstop
  19. #endif
  20. #ifndef WX_PRECOMP
  21. # include "wx/wx.h"
  22. #endif
  23. #include "wx/treectrl.h"
  24. #include "wx/config.h"
  25. #include "wx/imaglist.h"
  26. #include "wx/tokenzr.h"
  27. #if wxUSE_CONFIG_NATIVE && defined( __WINDOWS__ )
  28. # define DO_REGTEST 1
  29. #else
  30. # define DO_REGTEST 0
  31. #endif
  32. // ----------------------------------------------------------------------------
  33. // application type
  34. // ----------------------------------------------------------------------------
  35. class RegApp : public wxApp
  36. {
  37. public:
  38. bool OnInit();
  39. };
  40. // ----------------------------------------------------------------------------
  41. // image list with registry icons
  42. // ----------------------------------------------------------------------------
  43. class RegImageList : public wxImageList
  44. {
  45. public:
  46. enum Icon
  47. {
  48. Root,
  49. ClosedKey,
  50. OpenedKey,
  51. TextValue,
  52. BinaryValue
  53. };
  54. RegImageList();
  55. };
  56. #if DO_REGTEST
  57. // ----------------------------------------------------------------------------
  58. // our control
  59. // ----------------------------------------------------------------------------
  60. class RegTreeCtrl : public wxTreeCtrl
  61. {
  62. public:
  63. // ctor & dtor
  64. RegTreeCtrl(wxWindow *parent, wxWindowID id);
  65. virtual ~RegTreeCtrl();
  66. // notifications
  67. void OnDeleteItem (wxTreeEvent& event);
  68. void OnItemExpanding (wxTreeEvent& event);
  69. void OnSelChanged (wxTreeEvent& event);
  70. void OnBeginEdit (wxTreeEvent& event);
  71. void OnEndEdit (wxTreeEvent& event);
  72. void OnBeginDrag (wxTreeEvent& event);
  73. void OnEndDrag (wxTreeEvent& event);
  74. void OnRightClick (wxMouseEvent& event);
  75. void OnChar (wxKeyEvent& event);
  76. void OnIdle (wxIdleEvent& event);
  77. // forwarded notifications (by the frame)
  78. void OnMenuTest();
  79. // operations
  80. void GoTo(const wxString& location);
  81. void DoRefresh();
  82. void DeleteSelected();
  83. void ShowProperties();
  84. void CreateNewKey(const wxString& strName);
  85. void CreateNewTextValue(const wxString& strName);
  86. void CreateNewBinaryValue(const wxString& strName);
  87. void SetRegistryView(wxRegKey::WOW64ViewMode viewMode);
  88. // information
  89. bool IsKeySelected() const;
  90. private:
  91. // structure describing a registry key/value
  92. class TreeNode : public wxTreeItemData
  93. {
  94. WX_DEFINE_ARRAY_PTR(TreeNode *, TreeChildren);
  95. public:
  96. RegTreeCtrl *m_pTree; // must be !NULL
  97. TreeNode *m_pParent; // NULL only for the root node
  98. wxTreeItemId m_id; // the id of the tree control item
  99. wxString m_strName; // name of the key/value
  100. TreeChildren m_aChildren; // array of subkeys/values
  101. bool m_bKey; // key or value?
  102. wxRegKey *m_pKey; // only may be !NULL if m_bKey == true
  103. wxRegKey::WOW64ViewMode m_viewMode; // How to view the registry.
  104. // trivial accessors
  105. wxTreeItemId Id() const { return m_id; }
  106. bool IsRoot() const { return m_pParent == NULL; }
  107. bool IsKey() const { return m_bKey; }
  108. TreeNode *Parent() const { return m_pParent; }
  109. // notifications
  110. bool OnExpand();
  111. void OnCollapse();
  112. // operations
  113. void Refresh();
  114. bool DeleteChild(TreeNode *child);
  115. void DestroyChildren();
  116. const wxChar *FullName() const;
  117. void SetRegistryView(wxRegKey::WOW64ViewMode viewMode);
  118. // get the associated key: make sure the pointer is !NULL
  119. wxRegKey& Key() { if ( !m_pKey ) OnExpand(); return *m_pKey; }
  120. // dtor deletes all children
  121. ~TreeNode();
  122. };
  123. wxImageList *m_imageList;
  124. wxMenu *m_pMenuPopup;
  125. TreeNode *m_pRoot;
  126. TreeNode *m_draggedItem; // the item being dragged
  127. bool m_copyOnDrop; // if false, then move
  128. bool m_restoreStatus; // after OnItemExpanding()
  129. wxString m_nameOld; // the initial value of item being renamed
  130. wxRegKey::WOW64ViewMode m_viewMode; // Registry view to use for keys.
  131. TreeNode *GetNode(const wxTreeEvent& event)
  132. { return (TreeNode *)GetItemData(event.GetItem()); }
  133. public:
  134. // create a new node and insert it to the tree
  135. TreeNode *InsertNewTreeNode(TreeNode *pParent,
  136. const wxString& strName,
  137. int idImage = RegImageList::ClosedKey,
  138. const wxString *pstrValue = NULL,
  139. wxRegKey::WOW64ViewMode viewMode = wxRegKey::WOW64ViewMode_Default);
  140. // add standard registry keys
  141. void AddStdKeys();
  142. private:
  143. wxDECLARE_EVENT_TABLE();
  144. };
  145. #endif // #if DO_REGTEST
  146. // ----------------------------------------------------------------------------
  147. // the main window of our application
  148. // ----------------------------------------------------------------------------
  149. class RegFrame : public wxFrame
  150. {
  151. public:
  152. // ctor & dtor
  153. RegFrame(wxFrame *parent, const wxChar *title, int x, int y, int w, int h);
  154. virtual ~RegFrame();
  155. // callbacks
  156. void OnQuit (wxCommandEvent& event);
  157. void OnAbout(wxCommandEvent& event);
  158. void OnTest (wxCommandEvent& event);
  159. void OnGoTo (wxCommandEvent& event);
  160. void OnExpand (wxCommandEvent& event);
  161. void OnCollapse(wxCommandEvent& event);
  162. void OnToggle (wxCommandEvent& event);
  163. void OnRefresh (wxCommandEvent& event);
  164. void OnDelete (wxCommandEvent& event);
  165. void OnNewKey (wxCommandEvent& event);
  166. void OnNewText (wxCommandEvent& event);
  167. void OnNewBinary(wxCommandEvent& event);
  168. void OnInfo (wxCommandEvent& event);
  169. void OnViewChange (wxCommandEvent& event);
  170. wxDECLARE_EVENT_TABLE();
  171. private:
  172. #if DO_REGTEST
  173. RegTreeCtrl *m_treeCtrl;
  174. #endif
  175. };
  176. // ----------------------------------------------------------------------------
  177. // various ids
  178. // ----------------------------------------------------------------------------
  179. enum
  180. {
  181. Menu_Quit = 100,
  182. Menu_About,
  183. Menu_Test,
  184. Menu_GoTo,
  185. Menu_Expand,
  186. Menu_Collapse,
  187. Menu_Toggle,
  188. Menu_Refresh,
  189. Menu_New,
  190. Menu_NewKey,
  191. Menu_NewText,
  192. Menu_NewBinary,
  193. Menu_Delete,
  194. Menu_Info,
  195. Menu_View,
  196. Menu_ViewDefault,
  197. Menu_View32,
  198. Menu_View64,
  199. Ctrl_RegTree = 200
  200. };
  201. // ----------------------------------------------------------------------------
  202. // event tables
  203. // ----------------------------------------------------------------------------
  204. wxBEGIN_EVENT_TABLE(RegFrame, wxFrame)
  205. EVT_MENU(Menu_Test, RegFrame::OnTest)
  206. EVT_MENU(Menu_About, RegFrame::OnAbout)
  207. EVT_MENU(Menu_Quit, RegFrame::OnQuit)
  208. EVT_MENU(Menu_GoTo, RegFrame::OnGoTo)
  209. EVT_MENU(Menu_Expand, RegFrame::OnExpand)
  210. EVT_MENU(Menu_Collapse, RegFrame::OnCollapse)
  211. EVT_MENU(Menu_Toggle, RegFrame::OnToggle)
  212. EVT_MENU(Menu_Refresh, RegFrame::OnRefresh)
  213. EVT_MENU(Menu_Delete, RegFrame::OnDelete)
  214. EVT_MENU(Menu_NewKey, RegFrame::OnNewKey)
  215. EVT_MENU(Menu_NewText, RegFrame::OnNewText)
  216. EVT_MENU(Menu_NewBinary, RegFrame::OnNewBinary)
  217. EVT_MENU(Menu_Info, RegFrame::OnInfo)
  218. EVT_MENU(Menu_ViewDefault, RegFrame::OnViewChange)
  219. EVT_MENU(Menu_View32, RegFrame::OnViewChange)
  220. EVT_MENU(Menu_View64, RegFrame::OnViewChange)
  221. wxEND_EVENT_TABLE()
  222. #if DO_REGTEST
  223. wxBEGIN_EVENT_TABLE(RegTreeCtrl, wxTreeCtrl)
  224. EVT_TREE_DELETE_ITEM (Ctrl_RegTree, RegTreeCtrl::OnDeleteItem)
  225. EVT_TREE_ITEM_EXPANDING (Ctrl_RegTree, RegTreeCtrl::OnItemExpanding)
  226. EVT_TREE_ITEM_COLLAPSING(Ctrl_RegTree, RegTreeCtrl::OnItemExpanding)
  227. EVT_TREE_SEL_CHANGED (Ctrl_RegTree, RegTreeCtrl::OnSelChanged)
  228. EVT_TREE_BEGIN_LABEL_EDIT(Ctrl_RegTree, RegTreeCtrl::OnBeginEdit)
  229. EVT_TREE_END_LABEL_EDIT (Ctrl_RegTree, RegTreeCtrl::OnEndEdit)
  230. EVT_TREE_BEGIN_DRAG (Ctrl_RegTree, RegTreeCtrl::OnBeginDrag)
  231. EVT_TREE_BEGIN_RDRAG (Ctrl_RegTree, RegTreeCtrl::OnBeginDrag)
  232. EVT_TREE_END_DRAG (Ctrl_RegTree, RegTreeCtrl::OnEndDrag)
  233. EVT_CHAR (RegTreeCtrl::OnChar)
  234. EVT_RIGHT_DOWN(RegTreeCtrl::OnRightClick)
  235. EVT_IDLE (RegTreeCtrl::OnIdle)
  236. wxEND_EVENT_TABLE()
  237. #endif
  238. // ============================================================================
  239. // implementation
  240. // ============================================================================
  241. // ----------------------------------------------------------------------------
  242. // global functions
  243. // ----------------------------------------------------------------------------
  244. // create the "registry operations" menu
  245. wxMenu *CreateRegistryMenu()
  246. {
  247. wxMenu *pMenuNew = new wxMenu;
  248. pMenuNew->Append(Menu_NewKey, wxT("&Key"), wxT("Create a new key"));
  249. pMenuNew->AppendSeparator();
  250. pMenuNew->Append(Menu_NewText, wxT("&Text value"), wxT("Create a new text value"));
  251. pMenuNew->Append(Menu_NewBinary, wxT("&Binary value"), wxT("Create a new binary value"));
  252. wxMenu *pMenuView = new wxMenu;
  253. pMenuView->AppendRadioItem(
  254. Menu_ViewDefault,
  255. wxT("&Default"),
  256. wxT("Default registry view for the program environment."));
  257. pMenuView->AppendRadioItem(
  258. Menu_View32,
  259. wxT("32-bit Registry"),
  260. wxT("View 32-bit registry."));
  261. pMenuView->AppendRadioItem(
  262. Menu_View64,
  263. wxT("64-bit Registry"),
  264. wxT("View 64-bit registry."));
  265. wxMenu *pMenuReg = new wxMenu;
  266. pMenuReg->Append(Menu_New, wxT("&New"), pMenuNew);
  267. pMenuReg->Append(Menu_Delete, wxT("&Delete..."), wxT("Delete selected key/value"));
  268. pMenuReg->AppendSeparator();
  269. pMenuReg->Append(Menu_GoTo, wxT("&Go to...\tCtrl-G"), wxT("Go to registry key"));
  270. pMenuReg->Append(Menu_Expand, wxT("&Expand"), wxT("Expand current key"));
  271. pMenuReg->Append(Menu_Collapse, wxT("&Collapse"), wxT("Collapse current key"));
  272. pMenuReg->Append(Menu_Toggle, wxT("&Toggle"), wxT("Toggle current key"));
  273. pMenuReg->AppendSeparator();
  274. pMenuReg->Append(Menu_Refresh, wxT("&Refresh"), wxT("Refresh the subtree"));
  275. pMenuReg->Append(Menu_View, wxT("&View"), pMenuView);
  276. pMenuReg->AppendSeparator();
  277. pMenuReg->Append(Menu_Info, wxT("&Properties"),wxT("Information about current selection"));
  278. return pMenuReg;
  279. }
  280. // ----------------------------------------------------------------------------
  281. // application class
  282. // ----------------------------------------------------------------------------
  283. IMPLEMENT_APP(RegApp)
  284. // `Main program' equivalent, creating windows and returning main app frame
  285. bool RegApp::OnInit()
  286. {
  287. if ( !wxApp::OnInit() )
  288. return false;
  289. // create the main frame window and show it
  290. RegFrame *frame = new RegFrame(NULL, wxT("wxRegTest"), 50, 50, 600, 350);
  291. frame->Show(true);
  292. return true;
  293. }
  294. // ----------------------------------------------------------------------------
  295. // RegFrame
  296. // ----------------------------------------------------------------------------
  297. RegFrame::RegFrame(wxFrame *parent, const wxChar *title, int x, int y, int w, int h)
  298. : wxFrame(parent, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
  299. {
  300. // this reduces flicker effects
  301. SetBackgroundColour(*wxWHITE);
  302. // set the icon
  303. // ------------
  304. SetIcon(wxIcon(wxT("app_icon")));
  305. // create menu
  306. // -----------
  307. wxMenu *pMenuFile = new wxMenu;
  308. pMenuFile->Append(Menu_Test, wxT("Te&st"), wxT("Test key creation"));
  309. pMenuFile->AppendSeparator();
  310. pMenuFile->Append(Menu_About, wxT("&About"), wxT("Show an extraordinarly beautiful dialog"));
  311. pMenuFile->AppendSeparator();
  312. pMenuFile->Append(Menu_Quit, wxT("E&xit"), wxT("Quit this program"));
  313. wxMenuBar *pMenu = new wxMenuBar;
  314. pMenu->Append(pMenuFile, wxT("&File"));
  315. pMenu->Append(CreateRegistryMenu(), wxT("&Registry"));
  316. SetMenuBar(pMenu);
  317. #if DO_REGTEST
  318. // create child controls
  319. // ---------------------
  320. m_treeCtrl = new RegTreeCtrl(this, Ctrl_RegTree);
  321. #endif
  322. #if wxUSE_STATUSBAR
  323. // create the status line
  324. // ----------------------
  325. CreateStatusBar(2);
  326. #endif // wxUSE_STATUSBAR
  327. }
  328. RegFrame::~RegFrame()
  329. {
  330. #if DO_REGTEST
  331. // this makes deletion of it *much* quicker
  332. m_treeCtrl->Hide();
  333. #endif
  334. }
  335. void RegFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
  336. {
  337. Close(true);
  338. }
  339. void RegFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
  340. {
  341. wxMessageDialog dialog(this,
  342. wxT("wxRegistry sample\n")
  343. wxT("(c) 1998, 2000 Vadim Zeitlin"),
  344. wxT("About wxRegTest"), wxOK);
  345. dialog.ShowModal();
  346. }
  347. void RegFrame::OnTest(wxCommandEvent& WXUNUSED(event))
  348. {
  349. #if DO_REGTEST
  350. m_treeCtrl->OnMenuTest();
  351. #endif
  352. }
  353. void RegFrame::OnGoTo(wxCommandEvent& WXUNUSED(event))
  354. {
  355. static wxString s_location = wxT("HKEY_CURRENT_USER\\Software\\wxWidgets");
  356. wxString location = wxGetTextFromUser(
  357. wxT("Enter the location to go to:"),
  358. wxT("wxRegTest question"),
  359. s_location,
  360. this);
  361. if ( !location )
  362. return;
  363. s_location = location;
  364. #if DO_REGTEST
  365. m_treeCtrl->GoTo(location);
  366. #endif
  367. }
  368. void RegFrame::OnExpand(wxCommandEvent& WXUNUSED(event))
  369. {
  370. #if DO_REGTEST
  371. m_treeCtrl->Expand(m_treeCtrl->GetSelection());
  372. #endif
  373. }
  374. void RegFrame::OnCollapse(wxCommandEvent& WXUNUSED(event))
  375. {
  376. #if DO_REGTEST
  377. m_treeCtrl->Collapse(m_treeCtrl->GetSelection());
  378. #endif
  379. }
  380. void RegFrame::OnToggle(wxCommandEvent& WXUNUSED(event))
  381. {
  382. #if DO_REGTEST
  383. m_treeCtrl->Toggle(m_treeCtrl->GetSelection());
  384. #endif
  385. }
  386. void RegFrame::OnRefresh(wxCommandEvent& WXUNUSED(event))
  387. {
  388. #if DO_REGTEST
  389. m_treeCtrl->DoRefresh();
  390. #endif
  391. }
  392. void RegFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
  393. {
  394. #if DO_REGTEST
  395. m_treeCtrl->DeleteSelected();
  396. #endif
  397. }
  398. void RegFrame::OnNewKey(wxCommandEvent& WXUNUSED(event))
  399. {
  400. #if DO_REGTEST
  401. if ( m_treeCtrl->IsKeySelected() )
  402. {
  403. m_treeCtrl->CreateNewKey(
  404. wxGetTextFromUser(wxT("Enter the name of the new key")));
  405. }
  406. #endif
  407. }
  408. void RegFrame::OnNewText(wxCommandEvent& WXUNUSED(event))
  409. {
  410. #if DO_REGTEST
  411. if ( m_treeCtrl->IsKeySelected() )
  412. {
  413. m_treeCtrl->CreateNewTextValue(
  414. wxGetTextFromUser(wxT("Enter the name for the new text value")));
  415. }
  416. #endif
  417. }
  418. void RegFrame::OnNewBinary(wxCommandEvent& WXUNUSED(event))
  419. {
  420. #if DO_REGTEST
  421. if ( m_treeCtrl->IsKeySelected() )
  422. {
  423. m_treeCtrl->CreateNewBinaryValue(
  424. wxGetTextFromUser(wxT("Enter the name for the new binary value")));
  425. }
  426. #endif
  427. }
  428. void RegFrame::OnInfo(wxCommandEvent& WXUNUSED(event))
  429. {
  430. #if DO_REGTEST
  431. m_treeCtrl->ShowProperties();
  432. #endif
  433. }
  434. void RegFrame::OnViewChange(wxCommandEvent& event)
  435. {
  436. #if DO_REGTEST
  437. wxRegKey::WOW64ViewMode view;
  438. switch ( event.GetId() )
  439. {
  440. case Menu_ViewDefault:
  441. view = wxRegKey::WOW64ViewMode_Default;
  442. break;
  443. case Menu_View32:
  444. view = wxRegKey::WOW64ViewMode_32;
  445. break;
  446. case Menu_View64:
  447. view = wxRegKey::WOW64ViewMode_64;
  448. break;
  449. default:
  450. wxFAIL_MSG("Unexpected event source for view change.");
  451. return;
  452. }
  453. m_treeCtrl->SetRegistryView(view);
  454. #endif
  455. }
  456. // ----------------------------------------------------------------------------
  457. // RegImageList
  458. // ----------------------------------------------------------------------------
  459. RegImageList::RegImageList() : wxImageList(16, 16, true)
  460. {
  461. // should be in sync with enum RegImageList::RegIcon
  462. static const wxChar *aszIcons[] = { wxT("key1"),wxT("key2"),wxT("key3"),wxT("value1"),wxT("value2") };
  463. wxString str = wxT("icon_");
  464. for ( unsigned int n = 0; n < WXSIZEOF(aszIcons); n++ )
  465. {
  466. Add(wxIcon(str + aszIcons[n], wxBITMAP_TYPE_ICO_RESOURCE));
  467. }
  468. }
  469. #if DO_REGTEST
  470. // ----------------------------------------------------------------------------
  471. // RegTreeCtrl
  472. // ----------------------------------------------------------------------------
  473. // create a new tree item and insert it into the tree
  474. RegTreeCtrl::TreeNode *RegTreeCtrl::InsertNewTreeNode(
  475. TreeNode *pParent,
  476. const wxString& strName,
  477. int idImage,
  478. const wxString *pstrValue,
  479. wxRegKey::WOW64ViewMode viewMode)
  480. {
  481. // create new item & insert it
  482. TreeNode *pNewNode = new TreeNode;
  483. pNewNode->m_pTree = this;
  484. pNewNode->m_pParent = pParent;
  485. pNewNode->m_strName = strName;
  486. pNewNode->m_bKey = pstrValue == NULL;
  487. pNewNode->m_pKey = NULL;
  488. pNewNode->m_viewMode = viewMode;
  489. if (pParent)
  490. {
  491. pNewNode->m_id = AppendItem(pParent->Id(),
  492. pNewNode->IsKey() ? strName : *pstrValue,
  493. idImage);
  494. }
  495. else
  496. {
  497. pNewNode->m_id = AddRoot(strName);
  498. }
  499. wxASSERT_MSG( pNewNode->m_id, wxT("can't create tree control item!"));
  500. // save the pointer in the item
  501. SetItemData(pNewNode->m_id, pNewNode);
  502. // add it to the list of parent's children
  503. if ( pParent != NULL )
  504. {
  505. pParent->m_aChildren.Add(pNewNode);
  506. }
  507. if ( pNewNode->IsKey() )
  508. {
  509. SetItemHasChildren(pNewNode->Id());
  510. if ( !pNewNode->IsRoot() )
  511. {
  512. // set the expanded icon as well
  513. SetItemImage(pNewNode->Id(),
  514. RegImageList::OpenedKey,
  515. wxTreeItemIcon_Expanded);
  516. }
  517. }
  518. return pNewNode;
  519. }
  520. RegTreeCtrl::RegTreeCtrl(wxWindow *parent, wxWindowID id)
  521. : wxTreeCtrl(parent, id, wxDefaultPosition, wxDefaultSize,
  522. wxTR_HAS_BUTTONS | wxTR_EDIT_LABELS | wxSUNKEN_BORDER)
  523. {
  524. // init members
  525. m_draggedItem = NULL;
  526. m_restoreStatus = false;
  527. m_viewMode = wxRegKey::WOW64ViewMode_Default;
  528. // create the image list
  529. // ---------------------
  530. m_imageList = new RegImageList;
  531. SetImageList(m_imageList);
  532. // create root keys
  533. // ----------------
  534. m_pRoot =
  535. InsertNewTreeNode(
  536. NULL,
  537. wxT("Registry Root"),
  538. RegImageList::Root,
  539. NULL,
  540. m_viewMode);
  541. // create popup menu
  542. // -----------------
  543. m_pMenuPopup = CreateRegistryMenu();
  544. }
  545. RegTreeCtrl::~RegTreeCtrl()
  546. {
  547. delete m_pMenuPopup;
  548. // delete m_pRoot; -- this is done by the tree now
  549. delete m_imageList;
  550. }
  551. void RegTreeCtrl::AddStdKeys()
  552. {
  553. for ( unsigned int ui = 0; ui < wxRegKey::nStdKeys; ui++ )
  554. {
  555. InsertNewTreeNode(
  556. m_pRoot,
  557. wxRegKey::GetStdKeyName(ui),
  558. RegImageList::ClosedKey,
  559. NULL,
  560. m_viewMode);
  561. }
  562. }
  563. // ----------------------------------------------------------------------------
  564. // notifications
  565. // ----------------------------------------------------------------------------
  566. void RegTreeCtrl::OnIdle(wxIdleEvent& WXUNUSED(event))
  567. {
  568. if ( m_restoreStatus )
  569. {
  570. // restore it after OnItemExpanding()
  571. wxLogStatus(wxT("Ok"));
  572. wxSetCursor(*wxSTANDARD_CURSOR);
  573. m_restoreStatus = false;
  574. }
  575. }
  576. void RegTreeCtrl::OnRightClick(wxMouseEvent& event)
  577. {
  578. int iFlags;
  579. wxTreeItemId lId = HitTest(wxPoint(event.GetX(), event.GetY()), iFlags);
  580. if ( iFlags & wxTREE_HITTEST_ONITEMLABEL )
  581. {
  582. // select the item first
  583. SelectItem(lId);
  584. }
  585. //else: take the currently selected item if click not on item
  586. PopupMenu(m_pMenuPopup, event.GetX(), event.GetY());
  587. }
  588. void RegTreeCtrl::OnDeleteItem(wxTreeEvent& WXUNUSED(event))
  589. {
  590. }
  591. // test the key creation functions
  592. void RegTreeCtrl::OnMenuTest()
  593. {
  594. wxTreeItemId lId = GetSelection();
  595. TreeNode *pNode = (TreeNode *)GetItemData(lId);
  596. wxCHECK_RET( pNode != NULL, wxT("tree item without data?") );
  597. if ( pNode->IsRoot() )
  598. {
  599. wxLogError(wxT("Can't create a subkey under the root key."));
  600. return;
  601. }
  602. if ( !pNode->IsKey() )
  603. {
  604. wxLogError(wxT("Can't create a subkey under a value!"));
  605. return;
  606. }
  607. wxRegKey key1(pNode->Key(), wxT("key1"));
  608. if ( key1.Create() )
  609. {
  610. wxRegKey key2a(key1, wxT("key2a")), key2b(key1, wxT("key2b"));
  611. if ( key2a.Create() && key2b.Create() )
  612. {
  613. // put some values under the newly created keys
  614. key1.SetValue(wxT("first_term"), wxT("10"));
  615. key1.SetValue(wxT("second_term"), wxT("7"));
  616. key2a = wxT("this is the unnamed value");
  617. key2b.SetValue(wxT("sum"), 17);
  618. // refresh tree
  619. pNode->Refresh();
  620. wxLogStatus(wxT("Test keys successfully added."));
  621. return;
  622. }
  623. }
  624. wxLogError(wxT("Creation of test keys failed."));
  625. }
  626. void RegTreeCtrl::OnChar(wxKeyEvent& event)
  627. {
  628. switch ( event.GetKeyCode() )
  629. {
  630. case WXK_DELETE:
  631. DeleteSelected();
  632. return;
  633. case WXK_RETURN:
  634. if ( event.AltDown() )
  635. {
  636. ShowProperties();
  637. return;
  638. }
  639. }
  640. event.Skip();
  641. }
  642. void RegTreeCtrl::OnSelChanged(wxTreeEvent& event)
  643. {
  644. #if wxUSE_STATUSBAR
  645. wxFrame *pFrame = (wxFrame *) wxWindow::GetParent();
  646. pFrame->SetStatusText(GetNode(event)->FullName(), 1);
  647. #else
  648. wxUnusedVar(event);
  649. #endif // wxUSE_STATUSBAR
  650. }
  651. void RegTreeCtrl::OnItemExpanding(wxTreeEvent& event)
  652. {
  653. TreeNode *pNode = GetNode(event);
  654. bool bExpanding = event.GetEventType() == wxEVT_TREE_ITEM_EXPANDING;
  655. // expansion might take some time
  656. wxSetCursor(*wxHOURGLASS_CURSOR);
  657. wxLogStatus(wxT("Working..."));
  658. wxYield(); // to give the status line a chance to refresh itself
  659. m_restoreStatus = true; // some time later...
  660. if ( pNode->IsKey() )
  661. {
  662. if ( bExpanding )
  663. {
  664. // expanding: add subkeys/values
  665. if ( !pNode->OnExpand() )
  666. return;
  667. }
  668. else
  669. {
  670. // collapsing: clean up
  671. pNode->OnCollapse();
  672. }
  673. }
  674. }
  675. void RegTreeCtrl::OnBeginEdit(wxTreeEvent& event)
  676. {
  677. TreeNode *pNode = GetNode(event);
  678. if ( pNode->IsRoot() || pNode->Parent()->IsRoot() )
  679. {
  680. wxLogStatus(wxT("This registry key can't be renamed."));
  681. event.Veto();
  682. }
  683. else
  684. {
  685. m_nameOld = pNode->m_strName;
  686. }
  687. }
  688. void RegTreeCtrl::OnEndEdit(wxTreeEvent& event)
  689. {
  690. bool ok;
  691. wxString name = event.GetLabel();
  692. TreeNode *pNode = GetNode(event);
  693. if ( pNode->IsKey() )
  694. {
  695. wxRegKey& key = pNode->Key();
  696. ok = key.Rename(name);
  697. }
  698. else
  699. {
  700. pNode = pNode->Parent();
  701. wxRegKey& key = pNode->Key();
  702. ok = key.RenameValue(m_nameOld, name);
  703. }
  704. if ( !ok )
  705. {
  706. wxLogError(wxT("Failed to rename '%s' to '%s'."),
  707. m_nameOld.c_str(), name.c_str());
  708. }
  709. #if 0 // MSW tree ctrl doesn't like this at all, it hangs
  710. else
  711. {
  712. pNode->Refresh();
  713. }
  714. #endif // 0
  715. }
  716. void RegTreeCtrl::OnBeginDrag(wxTreeEvent& event)
  717. {
  718. m_copyOnDrop = event.GetEventType() == wxEVT_TREE_BEGIN_DRAG;
  719. TreeNode *pNode = GetNode(event);
  720. if ( pNode->IsRoot() || pNode->Parent()->IsRoot() )
  721. {
  722. wxLogStatus(wxT("This registry key can't be %s."),
  723. m_copyOnDrop ? wxT("copied") : wxT("moved"));
  724. }
  725. else
  726. {
  727. wxLogStatus(wxT("%s item %s..."),
  728. m_copyOnDrop ? wxT("Copying") : wxT("Moving"),
  729. pNode->FullName());
  730. m_draggedItem = pNode;
  731. event.Allow();
  732. }
  733. }
  734. void RegTreeCtrl::OnEndDrag(wxTreeEvent& event)
  735. {
  736. wxCHECK_RET( m_draggedItem, wxT("end drag without begin drag?") );
  737. // clear the pointer anyhow
  738. TreeNode *src = m_draggedItem;
  739. m_draggedItem = NULL;
  740. // where are we going to drop it?
  741. TreeNode *dst = GetNode(event);
  742. if ( dst && !dst->IsKey() )
  743. {
  744. // we need a parent key
  745. dst = dst->Parent();
  746. }
  747. if ( !dst || dst->IsRoot() )
  748. {
  749. wxLogError(wxT("Can't create a key here."));
  750. return;
  751. }
  752. bool isKey = src->IsKey();
  753. if ( (isKey && (src == dst)) ||
  754. (!isKey && (dst->Parent() == src)) ) {
  755. wxLogStatus(wxT("Can't copy something on itself"));
  756. return;
  757. }
  758. // remove the "Registry Root\\" from the full name
  759. wxString nameSrc, nameDst;
  760. nameSrc << wxString(src->FullName()).AfterFirst('\\');
  761. nameDst << wxString(dst->FullName()).AfterFirst('\\') << '\\'
  762. << wxString(src->FullName()).AfterLast('\\');
  763. wxString verb = m_copyOnDrop ? wxT("copy") : wxT("move");
  764. wxString what = isKey ? wxT("key") : wxT("value");
  765. if ( wxMessageBox(wxString::Format
  766. (
  767. wxT("Do you really want to %s the %s %s to %s?"),
  768. verb.c_str(),
  769. what.c_str(),
  770. nameSrc.c_str(),
  771. nameDst.c_str()
  772. ),
  773. wxT("RegTest Confirm"),
  774. wxICON_QUESTION | wxYES_NO | wxCANCEL, this) != wxYES ) {
  775. return;
  776. }
  777. bool ok;
  778. if ( isKey )
  779. {
  780. wxRegKey& key = src->Key();
  781. wxRegKey keyDst(dst->Key(), src->m_strName);
  782. ok = keyDst.Create(false);
  783. if ( !ok )
  784. {
  785. wxLogError(wxT("Key '%s' already exists"), keyDst.GetName().c_str());
  786. }
  787. else
  788. {
  789. ok = key.Copy(keyDst);
  790. }
  791. if ( ok && !m_copyOnDrop )
  792. {
  793. // delete the old key
  794. ok = key.DeleteSelf();
  795. if ( ok )
  796. {
  797. src->Parent()->Refresh();
  798. }
  799. }
  800. }
  801. else // value
  802. {
  803. wxRegKey& key = src->Parent()->Key();
  804. ok = key.CopyValue(src->m_strName, dst->Key());
  805. if ( ok && !m_copyOnDrop )
  806. {
  807. // we moved it, so delete the old one
  808. ok = key.DeleteValue(src->m_strName);
  809. }
  810. }
  811. if ( !ok )
  812. {
  813. wxLogError(wxT("Failed to %s registry %s."),
  814. verb.c_str(), what.c_str());
  815. }
  816. else
  817. {
  818. dst->Refresh();
  819. }
  820. }
  821. // ----------------------------------------------------------------------------
  822. // TreeNode implementation
  823. // ----------------------------------------------------------------------------
  824. bool RegTreeCtrl::TreeNode::OnExpand()
  825. {
  826. // we add children only once
  827. if ( !m_aChildren.IsEmpty() )
  828. {
  829. // we've been already expanded
  830. return true;
  831. }
  832. if ( IsRoot() )
  833. {
  834. // we're the root key
  835. m_pTree->AddStdKeys();
  836. return true;
  837. }
  838. if ( Parent()->IsRoot() )
  839. {
  840. // we're a standard key
  841. m_pKey = new wxRegKey(m_strName, m_viewMode);
  842. }
  843. else
  844. {
  845. // we're a normal key
  846. m_pKey = new wxRegKey(*(Parent()->m_pKey), m_strName);
  847. }
  848. if ( !m_pKey->Open() )
  849. {
  850. wxLogError(wxT("The key '%s' can't be opened."), FullName());
  851. return false;
  852. }
  853. // if we're empty, we shouldn't be expandable at all
  854. bool isEmpty = true;
  855. // enumeration variables
  856. long l;
  857. wxString str;
  858. bool bCont;
  859. // enumerate all subkeys
  860. bCont = m_pKey->GetFirstKey(str, l);
  861. while ( bCont )
  862. {
  863. m_pTree->InsertNewTreeNode(
  864. this,
  865. str,
  866. RegImageList::ClosedKey,
  867. NULL,
  868. m_viewMode);
  869. bCont = m_pKey->GetNextKey(str, l);
  870. // we have at least this key...
  871. isEmpty = false;
  872. }
  873. // enumerate all values
  874. bCont = m_pKey->GetFirstValue(str, l);
  875. while ( bCont )
  876. {
  877. wxString strItem;
  878. if (str.empty())
  879. strItem = wxT("<default>");
  880. else
  881. strItem = str;
  882. strItem += wxT(" = ");
  883. // determine the appropriate icon
  884. RegImageList::Icon icon;
  885. switch ( m_pKey->GetValueType(str) )
  886. {
  887. case wxRegKey::Type_String:
  888. case wxRegKey::Type_Expand_String:
  889. case wxRegKey::Type_Multi_String:
  890. {
  891. wxString strValue;
  892. icon = RegImageList::TextValue;
  893. m_pKey->QueryValue(str, strValue);
  894. strItem += strValue;
  895. }
  896. break;
  897. case wxRegKey::Type_None:
  898. // @@ handle the error...
  899. icon = RegImageList::BinaryValue;
  900. break;
  901. case wxRegKey::Type_Dword:
  902. {
  903. long l;
  904. m_pKey->QueryValue(str, &l);
  905. strItem << l;
  906. }
  907. // fall through
  908. default:
  909. icon = RegImageList::BinaryValue;
  910. }
  911. m_pTree->InsertNewTreeNode(this, str, icon, &strItem, m_viewMode);
  912. bCont = m_pKey->GetNextValue(str, l);
  913. // we have at least this value...
  914. isEmpty = false;
  915. }
  916. if ( isEmpty )
  917. {
  918. // this is for the case when our last child was just deleted
  919. wxTreeItemId theId(Id()); // Temp variable seems necessary for BC++
  920. m_pTree->Collapse(theId);
  921. // we won't be expanded any more
  922. m_pTree->SetItemHasChildren(theId, false);
  923. }
  924. return true;
  925. }
  926. void RegTreeCtrl::TreeNode::OnCollapse()
  927. {
  928. DestroyChildren();
  929. wxDELETE(m_pKey);
  930. }
  931. void RegTreeCtrl::TreeNode::Refresh()
  932. {
  933. if ( !IsKey() )
  934. return;
  935. wxTreeItemId theId(Id()); // Temp variable seems necessary for BC++
  936. bool wasExpanded = m_pTree->IsExpanded(theId);
  937. if ( wasExpanded )
  938. m_pTree->Collapse(theId);
  939. OnCollapse();
  940. m_pTree->SetItemHasChildren(theId);
  941. if ( wasExpanded )
  942. {
  943. m_pTree->Expand(theId);
  944. OnExpand();
  945. }
  946. }
  947. bool RegTreeCtrl::TreeNode::DeleteChild(TreeNode *child)
  948. {
  949. int index = m_aChildren.Index(child);
  950. wxCHECK_MSG( index != wxNOT_FOUND, false,
  951. wxT("our child in tree should be in m_aChildren") );
  952. m_aChildren.RemoveAt((size_t)index);
  953. bool ok;
  954. if ( child->IsKey() )
  955. {
  956. // must close key before deleting it
  957. child->OnCollapse();
  958. ok = Key().DeleteKey(child->m_strName);
  959. }
  960. else
  961. {
  962. ok = Key().DeleteValue(child->m_strName);
  963. }
  964. if ( ok )
  965. {
  966. wxTreeItemId theId(child->Id()); // Temp variable seems necessary for BC++
  967. m_pTree->Delete(theId);
  968. Refresh();
  969. }
  970. return ok;
  971. }
  972. void RegTreeCtrl::TreeNode::DestroyChildren()
  973. {
  974. // destroy all children
  975. size_t nCount = m_aChildren.GetCount();
  976. for ( size_t n = 0; n < nCount; n++ )
  977. {
  978. wxTreeItemId lId = m_aChildren[n]->Id();
  979. m_pTree->Delete(lId);
  980. }
  981. m_aChildren.Empty();
  982. }
  983. RegTreeCtrl::TreeNode::~TreeNode()
  984. {
  985. delete m_pKey;
  986. }
  987. const wxChar *RegTreeCtrl::TreeNode::FullName() const
  988. {
  989. static wxString s_strName;
  990. if ( IsRoot() )
  991. {
  992. return wxT("Registry Root");
  993. }
  994. else
  995. {
  996. // our own registry key might not (yet) exist or we might be a value,
  997. // so just use the parent's and concatenate
  998. s_strName = Parent()->FullName();
  999. s_strName << wxT('\\') << m_strName;
  1000. return s_strName.t_str();
  1001. }
  1002. }
  1003. void RegTreeCtrl::TreeNode::SetRegistryView(wxRegKey::WOW64ViewMode viewMode)
  1004. {
  1005. m_viewMode = viewMode;
  1006. // Update children with new view.
  1007. size_t nCount = m_aChildren.GetCount();
  1008. for (size_t n = 0; n < nCount; n++)
  1009. m_aChildren[n]->SetRegistryView(viewMode);
  1010. }
  1011. // ----------------------------------------------------------------------------
  1012. // operations on RegTreeCtrl
  1013. // ----------------------------------------------------------------------------
  1014. void RegTreeCtrl::GoTo(const wxString& location)
  1015. {
  1016. wxStringTokenizer tk(location, wxT("\\"));
  1017. wxTreeItemId id = GetRootItem();
  1018. while ( tk.HasMoreTokens() )
  1019. {
  1020. wxString subkey = tk.GetNextToken();
  1021. wxTreeItemId idCurrent = id;
  1022. if ( !IsExpanded(idCurrent) )
  1023. Expand(idCurrent);
  1024. wxTreeItemIdValue dummy;
  1025. id = GetFirstChild(idCurrent, dummy);
  1026. if ( idCurrent == GetRootItem() )
  1027. {
  1028. // special case: we understand both HKCU and HKEY_CURRENT_USER here
  1029. for ( size_t key = 0; key < wxRegKey::nStdKeys; key++ )
  1030. {
  1031. if ( subkey == wxRegKey::GetStdKeyName(key)
  1032. || subkey == wxRegKey::GetStdKeyShortName(key) )
  1033. {
  1034. break;
  1035. }
  1036. id = GetNextChild(idCurrent, dummy);
  1037. }
  1038. }
  1039. else
  1040. {
  1041. // enum all children
  1042. while ( id.IsOk() )
  1043. {
  1044. if ( subkey == ((TreeNode *)GetItemData(id))->m_strName )
  1045. break;
  1046. id = GetNextChild(idCurrent, dummy);
  1047. }
  1048. }
  1049. if ( !id.IsOk() )
  1050. {
  1051. wxLogError(wxT("No such key '%s'."), location.c_str());
  1052. return;
  1053. }
  1054. }
  1055. if ( id.IsOk() )
  1056. SelectItem(id);
  1057. }
  1058. void RegTreeCtrl::DeleteSelected()
  1059. {
  1060. wxTreeItemId lCurrent = GetSelection(),
  1061. lParent = GetItemParent(lCurrent);
  1062. if ( lParent == GetRootItem() )
  1063. {
  1064. wxLogError(wxT("Can't delete root key."));
  1065. return;
  1066. }
  1067. TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent),
  1068. *pParent = (TreeNode *)GetItemData(lParent);
  1069. wxCHECK_RET(pCurrent && pParent, wxT("either node or parent without data?"));
  1070. if ( pParent->IsRoot() )
  1071. {
  1072. wxLogError(wxT("Can't delete standard key."));
  1073. return;
  1074. }
  1075. wxString what = pCurrent->IsKey() ? wxT("key") : wxT("value");
  1076. if ( wxMessageBox(wxString::Format
  1077. (
  1078. wxT("Do you really want to delete this %s?"),
  1079. what.c_str()
  1080. ),
  1081. wxT("Confirmation"),
  1082. wxICON_QUESTION | wxYES_NO | wxCANCEL, this) != wxYES )
  1083. {
  1084. return;
  1085. }
  1086. pParent->DeleteChild(pCurrent);
  1087. }
  1088. void RegTreeCtrl::CreateNewKey(const wxString& strName)
  1089. {
  1090. wxTreeItemId lCurrent = GetSelection();
  1091. TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent);
  1092. wxCHECK_RET( pCurrent != NULL, wxT("node without data?") );
  1093. wxASSERT( pCurrent->IsKey() ); // check must have been done before
  1094. if ( pCurrent->IsRoot() )
  1095. {
  1096. wxLogError(wxT("Can't create a new key under the root key."));
  1097. return;
  1098. }
  1099. wxRegKey key(pCurrent->Key(), strName);
  1100. if ( key.Create() )
  1101. pCurrent->Refresh();
  1102. }
  1103. void RegTreeCtrl::CreateNewTextValue(const wxString& strName)
  1104. {
  1105. wxTreeItemId lCurrent = GetSelection();
  1106. TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent);
  1107. wxCHECK_RET( pCurrent != NULL, wxT("node without data?") );
  1108. wxASSERT( pCurrent->IsKey() ); // check must have been done before
  1109. if ( pCurrent->IsRoot() )
  1110. {
  1111. wxLogError(wxT("Can't create a new value under the root key."));
  1112. return;
  1113. }
  1114. if ( pCurrent->Key().SetValue(strName, wxEmptyString) )
  1115. pCurrent->Refresh();
  1116. }
  1117. void RegTreeCtrl::CreateNewBinaryValue(const wxString& strName)
  1118. {
  1119. wxTreeItemId lCurrent = GetSelection();
  1120. TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent);
  1121. wxCHECK_RET( pCurrent != NULL, wxT("node without data?") );
  1122. wxASSERT( pCurrent->IsKey() ); // check must have been done before
  1123. if ( pCurrent->IsRoot() )
  1124. {
  1125. wxLogError(wxT("Can't create a new value under the root key."));
  1126. return;
  1127. }
  1128. if ( pCurrent->Key().SetValue(strName, 0) )
  1129. pCurrent->Refresh();
  1130. }
  1131. void RegTreeCtrl::SetRegistryView(wxRegKey::WOW64ViewMode viewMode)
  1132. {
  1133. m_viewMode = viewMode;
  1134. m_pRoot->SetRegistryView(viewMode);
  1135. m_pRoot->Refresh();
  1136. }
  1137. void RegTreeCtrl::ShowProperties()
  1138. {
  1139. wxTreeItemId lCurrent = GetSelection();
  1140. TreeNode *pCurrent = (TreeNode *)GetItemData(lCurrent);
  1141. if ( !pCurrent || pCurrent->IsRoot() )
  1142. {
  1143. wxLogStatus(wxT("No properties"));
  1144. return;
  1145. }
  1146. if ( pCurrent->IsKey() )
  1147. {
  1148. const wxRegKey& key = pCurrent->Key();
  1149. size_t nSubKeys, nValues;
  1150. if ( !key.GetKeyInfo(&nSubKeys, NULL, &nValues, NULL) )
  1151. {
  1152. wxLogError(wxT("Couldn't get key info"));
  1153. }
  1154. else
  1155. {
  1156. wxLogMessage(wxT("Key '%s' has %u subkeys and %u values."),
  1157. key.GetName().c_str(), nSubKeys, nValues);
  1158. }
  1159. }
  1160. else // it's a value
  1161. {
  1162. TreeNode *parent = pCurrent->Parent();
  1163. wxCHECK_RET( parent, wxT("reg value without key?") );
  1164. const wxRegKey& key = parent->Key();
  1165. const wxChar *value = pCurrent->m_strName.c_str();
  1166. wxLogMessage(wxT("Value '%s' under the key '%s' is of type ")
  1167. wxT("%d (%s)."),
  1168. value,
  1169. parent->m_strName.c_str(),
  1170. key.GetValueType(value),
  1171. key.IsNumericValue(value) ? wxT("numeric") : wxT("string"));
  1172. }
  1173. }
  1174. bool RegTreeCtrl::IsKeySelected() const
  1175. {
  1176. wxTreeItemId lCurrent = GetSelection();
  1177. TreeNode *pCurrent = (TreeNode *) GetItemData(lCurrent);
  1178. wxCHECK( pCurrent != NULL, false );
  1179. return pCurrent->IsKey();
  1180. }
  1181. void RegTreeCtrl::DoRefresh()
  1182. {
  1183. wxTreeItemId lId = GetSelection();
  1184. if ( !lId )
  1185. return;
  1186. TreeNode *pNode = (TreeNode *) GetItemData(lId);
  1187. wxCHECK_RET( pNode != NULL, wxT("tree item without data?") );
  1188. pNode->Refresh();
  1189. }
  1190. #endif