Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / utils / NamingViewer / SelectNSDialog.cpp
blob32d9378bc2164b79de0cfd6bc178e8651cb9b8d3
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);
83 void CSelectNSDialog::OnRemove()
85 // TODO: Add your control notification handler code here
86 int const index = m_Servers.GetCurSel();
87 if(index == LB_ERR)
89 return;
91 delete (char*)m_Servers.GetItemData(index);
92 CString Name;
93 m_Servers.GetText(index, Name);
94 ACE_Configuration_Section_Key Section = m_pConfig->root_section();
95 m_pConfig->remove_value(Section, Name);
96 m_Servers.DeleteString(index);
99 BOOL CSelectNSDialog::OnInitDialog()
101 CDialog::OnInitDialog();
103 // TODO: Add extra initialization here
104 HKEY hKey = ACE_Configuration_Win32Registry::resolve_key(HKEY_LOCAL_MACHINE, ACE_TEXT("Software\\TAO\\NamingViewer\\Servers"));
105 m_pConfig = new ACE_Configuration_Win32Registry(hKey);
106 ACE_Configuration_Section_Key Section = m_pConfig->root_section();
107 int index = 0;
108 ACE_TString name;
109 ACE_Configuration::VALUETYPE type;
110 while(m_pConfig->enumerate_values(Section, index, name, type) == 0)
112 ACE_TString value;
113 if(m_pConfig->get_string_value(Section, name.c_str(), value) == 0)
115 int pos = m_Servers.AddString(name.c_str());
116 ACE_TCHAR* pIOR = new ACE_TCHAR[value.length() + 1];
117 ACE_OS::strcpy(pIOR, value.c_str());
118 m_Servers.SetItemData(pos, (DWORD)pIOR);
120 ++index;
123 return TRUE; // return TRUE unless you set the focus to a control
124 // EXCEPTION: OCX Property Pages should return FALSE
127 void CSelectNSDialog::OnDestroy()
129 CDialog::OnDestroy();
131 // TODO: Add your message handler code here
132 int const count = m_Servers.GetCount();
133 for(int i=0; i < count; i++)
135 delete (char*)m_Servers.GetItemData(i);