1 // @file wxSelectNSDialog.cpp
3 // @author Charlie Frasch <cfrasch@atdesk.com>
5 #include "wxSelectNSDialog.h"
7 #include "ace/Configuration.h"
9 #include "wxAddNameServerDlg.h"
10 #include "wxAutoDialog.h"
11 #include "wxNamingViewer.h"
13 namespace // anonymous
15 void create_dialog_components( wxDialog
* dialog
)
17 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
35 wxBoxSizer
*button_sizer
= new wxBoxSizer( wxHORIZONTAL
);
37 wxButton
* okButton
= new wxButton( dialog
, wxID_OK
, "OK" );
38 okButton
->SetName( "okButton");
46 new wxButton( dialog
, IDC_DEFAULT
, "Default" ),
51 new wxButton( dialog
, IDC_ADD
, "Add" ),
56 new wxButton( dialog
, IDC_REMOVE
, "Remove" ),
61 new wxButton( dialog
, wxID_CANCEL
, "Cancel" ),
71 dialog
->SetSizer( topsizer
);
72 topsizer
->SetSizeHints( dialog
);
76 BEGIN_EVENT_TABLE( WxSelectNSDialog
, wxDialog
)
77 EVT_BUTTON( IDC_ADD
, WxSelectNSDialog::onAdd
)
78 EVT_BUTTON( IDC_DEFAULT
, WxSelectNSDialog::onDefault
)
79 EVT_BUTTON( wxID_OK
, WxSelectNSDialog::onOK
)
80 EVT_BUTTON( IDC_REMOVE
, WxSelectNSDialog::onRemove
)
81 EVT_INIT_DIALOG( WxSelectNSDialog::onInitDialog
)
82 EVT_LISTBOX_DCLICK( IDC_SERVERS
, WxSelectNSDialog::onLeftDClick
)
86 WxSelectNSDialog::WxSelectNSDialog( wxWindow
* parent
)
87 #if defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
93 "Select Naming Service",
96 wxRAISED_BORDER
| wxCAPTION
| wxTHICK_FRAME
| wxSYSTEM_MENU
,
98 #endif // defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
101 #if defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
102 LoadFromResource( parent
, "selectNS");
104 create_dialog_components( this);
105 #endif // defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
106 servers
= static_cast<wxListBox
*>( wxFindWindowByName(
111 #if defined (ACE_WIN32)
112 HKEY hKey
= ACE_Configuration_Win32Registry::resolve_key(
114 "Software\\TAO\\NamingViewer\\Servers");
115 config
= new ACE_Configuration_Win32Registry( hKey
);
118 ACE_Configuration_Heap
*heap
= new ACE_Configuration_Heap
;
122 ACE_Configuration_Section_Key section
= config
->root_section();
125 ACE_Configuration::VALUETYPE type
;
126 while(config
->enumerate_values( section
, index
, name
, type
) == 0) {
129 if(config
->get_string_value( section
, name
.c_str(), value
) == 0) {
133 new wxString( value
.c_str()));
142 WxSelectNSDialog::~WxSelectNSDialog()
144 int count
= servers
->Number();
145 for (int i
= 0; i
< count
; i
++) {
147 delete static_cast<wxString
*>( servers
->GetClientData( i
));
153 void WxSelectNSDialog::onAdd( wxCommandEvent
& WXUNUSED(event
))
155 WxAutoDialog
<WxAddNameServerDlg
> dialog( new WxAddNameServerDlg( this));
156 if (dialog
->ShowModal() == wxID_OK
) {
159 dialog
->getServerName(),
160 new wxString( dialog
->getIor()));
161 ACE_Configuration_Section_Key section
= config
->root_section();
162 ACE_TString value
= dialog
->getIor().c_str();
163 config
->set_string_value(
165 dialog
->getServerName().c_str(),
172 void WxSelectNSDialog::onDefault( wxCommandEvent
& WXUNUSED(event
))
174 EndModal( IDC_DEFAULT
);
178 void WxSelectNSDialog::onInitDialog( wxInitDialogEvent
& event
)
180 ACE_UNUSED_ARG( event
);
182 wxButton
* ctrl
= static_cast<wxButton
*>( wxFindWindowByName(
191 void WxSelectNSDialog::onLeftDClick( wxMouseEvent
& event
)
193 ACE_UNUSED_ARG( event
);
195 int index
= servers
->GetSelection();
196 // I don't think index will ever be -1!
197 assert( index
!= -1);
198 ior
= *static_cast<wxString
*>( servers
->GetClientData( index
));
199 serverName
= servers
->GetString( index
);
204 void WxSelectNSDialog::onOK( wxCommandEvent
& WXUNUSED(event
))
206 int index
= servers
->GetSelection();
210 "You must select a server or cancel",
212 wxOK
| wxICON_EXCLAMATION
);
215 ior
= *static_cast<wxString
*>( servers
->GetClientData( index
));
216 serverName
= servers
->GetString( index
);
221 void WxSelectNSDialog::onRemove( wxCommandEvent
& WXUNUSED(event
))
223 int index
= servers
->GetSelection();
226 wxString name
= servers
->GetString( index
);
227 delete static_cast<wxString
*>( servers
->GetClientData( index
));
228 servers
->Delete( index
);
230 ACE_Configuration_Section_Key section
= config
->root_section();;
231 config
->remove_value( section
, name
);