ACE+TAO-6_5_17
[ACE_TAO.git] / TAO / utils / NamingViewer / SelectNSDialog.cpp
blobab5f2cbc1540a84e7885c8caa76cac962f9c1940
1 // SelectNSDialog.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "NamingViewer.h"
6 #include "SelectNSDialog.h"
7 #include "AddNameServerDlg.h"
8 #include "ace/SString.h"
9 #include "ace/OS_NS_String.h"
11 #ifdef _DEBUG
12 #define new DEBUG_NEW
13 #undef THIS_FILE
14 static char THIS_FILE[] = __FILE__;
15 #endif
17 /////////////////////////////////////////////////////////////////////////////
18 // CSelectNSDialog dialog
21 CSelectNSDialog::CSelectNSDialog(CWnd* pParent /*=NULL*/)
22 : CDialog(CSelectNSDialog::IDD, pParent)
24 //{{AFX_DATA_INIT(CSelectNSDialog)
25 // NOTE: the ClassWizard will add member initialization here
26 //}}AFX_DATA_INIT
27 m_pConfig = 0;
31 void CSelectNSDialog::DoDataExchange(CDataExchange* pDX)
33 CDialog::DoDataExchange(pDX);
34 //{{AFX_DATA_MAP(CSelectNSDialog)
35 DDX_Control(pDX, IDC_SERVERS, m_Servers);
36 //}}AFX_DATA_MAP
40 BEGIN_MESSAGE_MAP(CSelectNSDialog, CDialog)
41 //{{AFX_MSG_MAP(CSelectNSDialog)
42 ON_BN_CLICKED(IDC_ADD, OnAdd)
43 ON_BN_CLICKED(IDC_REMOVE, OnRemove)
44 ON_WM_DESTROY()
45 //}}AFX_MSG_MAP
46 END_MESSAGE_MAP()
48 /////////////////////////////////////////////////////////////////////////////
49 // CSelectNSDialog message handlers
51 void CSelectNSDialog::OnOK()
53 // TODO: Add extra validation here
54 int index = m_Servers.GetCurSel();
55 if(index == LB_ERR)
57 AfxMessageBox(ACE_TEXT ("You must select a server or cancel"));
58 return;
60 char* pIOR = (char*)m_Servers.GetItemData(index);
61 m_IOR = pIOR;
62 m_Servers.GetText(index, m_Name);
63 CDialog::OnOK();
66 void CSelectNSDialog::OnAdd()
68 // TODO: Add your control notification handler code here
69 CAddNameServerDlg Dialog;
70 if(Dialog.DoModal() != IDOK)
72 return;
74 ACE_Configuration_Section_Key Section = m_pConfig->root_section();
75 ACE_TString Value = Dialog.m_IOR;
76 m_pConfig->set_string_value(Section, Dialog.m_Name, Value);
77 int pos = m_Servers.AddString(Dialog.m_Name);
78 ACE_TCHAR* pIOR = new ACE_TCHAR[Value.length() + 1];
79 ACE_OS::strcpy(pIOR, Value.c_str());
80 m_Servers.SetItemData(pos, (DWORD)pIOR);
84 void CSelectNSDialog::OnRemove()
86 // TODO: Add your control notification handler code here
87 int const index = m_Servers.GetCurSel();
88 if(index == LB_ERR)
90 return;
92 delete (char*)m_Servers.GetItemData(index);
93 CString Name;
94 m_Servers.GetText(index, Name);
95 ACE_Configuration_Section_Key Section = m_pConfig->root_section();;
96 m_pConfig->remove_value(Section, Name);
97 m_Servers.DeleteString(index);
100 BOOL CSelectNSDialog::OnInitDialog()
102 CDialog::OnInitDialog();
104 // TODO: Add extra initialization here
105 HKEY hKey = ACE_Configuration_Win32Registry::resolve_key(HKEY_LOCAL_MACHINE, ACE_TEXT("Software\\TAO\\NamingViewer\\Servers"));
106 m_pConfig = new ACE_Configuration_Win32Registry(hKey);
107 ACE_Configuration_Section_Key Section = m_pConfig->root_section();;
108 int index = 0;
109 ACE_TString name;
110 ACE_Configuration::VALUETYPE type;
111 while(m_pConfig->enumerate_values(Section, index, name, type) == 0)
113 ACE_TString value;
114 if(m_pConfig->get_string_value(Section, name.c_str(), value) == 0)
116 int pos = m_Servers.AddString(name.c_str());
117 ACE_TCHAR* pIOR = new ACE_TCHAR[value.length() + 1];
118 ACE_OS::strcpy(pIOR, value.c_str());
119 m_Servers.SetItemData(pos, (DWORD)pIOR);
121 ++index;
124 return TRUE; // return TRUE unless you set the focus to a control
125 // EXCEPTION: OCX Property Pages should return FALSE
128 void CSelectNSDialog::OnDestroy()
130 CDialog::OnDestroy();
132 // TODO: Add your message handler code here
133 int const count = m_Servers.GetCount();
134 for(int i=0; i < count; i++)
136 delete (char*)m_Servers.GetItemData(i);