1 // SelectNSDialog.cpp : implementation file
5 #include "NamingViewer.h"
6 #include "SelectNSDialog.h"
7 #include "AddNameServerDlg.h"
8 #include "ace/SString.h"
9 #include "ace/OS_NS_String.h"
14 static char THIS_FILE
[] = __FILE__
;
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
31 void CSelectNSDialog::DoDataExchange(CDataExchange
* pDX
)
33 CDialog::DoDataExchange(pDX
);
34 //{{AFX_DATA_MAP(CSelectNSDialog)
35 DDX_Control(pDX
, IDC_SERVERS
, m_Servers
);
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
)
48 /////////////////////////////////////////////////////////////////////////////
49 // CSelectNSDialog message handlers
51 void CSelectNSDialog::OnOK()
53 // TODO: Add extra validation here
54 int index
= m_Servers
.GetCurSel();
57 AfxMessageBox(ACE_TEXT ("You must select a server or cancel"));
60 char* pIOR
= (char*)m_Servers
.GetItemData(index
);
62 m_Servers
.GetText(index
, m_Name
);
66 void CSelectNSDialog::OnAdd()
68 // TODO: Add your control notification handler code here
69 CAddNameServerDlg Dialog
;
70 if(Dialog
.DoModal() != IDOK
)
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();
91 delete (char*)m_Servers
.GetItemData(index
);
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();
109 ACE_Configuration::VALUETYPE type
;
110 while(m_pConfig
->enumerate_values(Section
, index
, name
, type
) == 0)
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
);
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
);