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) {
128 if(config
->get_string_value( section
, name
.c_str(), value
) == 0) {
131 new wxString( value
.c_str()));
138 WxSelectNSDialog::~WxSelectNSDialog()
140 int count
= servers
->Number();
141 for (int i
= 0; i
< count
; i
++) {
142 delete static_cast<wxString
*>( servers
->GetClientData( i
));
147 void WxSelectNSDialog::onAdd( wxCommandEvent
& WXUNUSED(event
))
149 WxAutoDialog
<WxAddNameServerDlg
> dialog( new WxAddNameServerDlg( this));
150 if (dialog
->ShowModal() == wxID_OK
) {
152 dialog
->getServerName(),
153 new wxString( dialog
->getIor()));
154 ACE_Configuration_Section_Key section
= config
->root_section();
155 ACE_TString value
= dialog
->getIor().c_str();
156 config
->set_string_value(
158 dialog
->getServerName().c_str(),
164 void WxSelectNSDialog::onDefault( wxCommandEvent
& WXUNUSED(event
))
166 EndModal( IDC_DEFAULT
);
170 void WxSelectNSDialog::onInitDialog( wxInitDialogEvent
& event
)
172 ACE_UNUSED_ARG( event
);
174 wxButton
* ctrl
= static_cast<wxButton
*>( wxFindWindowByName(
183 void WxSelectNSDialog::onLeftDClick( wxMouseEvent
& event
)
185 ACE_UNUSED_ARG( event
);
187 int index
= servers
->GetSelection();
188 // I don't think index will ever be -1!
189 assert( index
!= -1);
190 ior
= *static_cast<wxString
*>( servers
->GetClientData( index
));
191 serverName
= servers
->GetString( index
);
196 void WxSelectNSDialog::onOK( wxCommandEvent
& WXUNUSED(event
))
198 int index
= servers
->GetSelection();
201 "You must select a server or cancel",
203 wxOK
| wxICON_EXCLAMATION
);
206 ior
= *static_cast<wxString
*>( servers
->GetClientData( index
));
207 serverName
= servers
->GetString( index
);
212 void WxSelectNSDialog::onRemove( wxCommandEvent
& WXUNUSED(event
))
214 int index
= servers
->GetSelection();
216 wxString name
= servers
->GetString( index
);
217 delete static_cast<wxString
*>( servers
->GetClientData( index
));
218 servers
->Delete( index
);
220 ACE_Configuration_Section_Key section
= config
->root_section();
221 config
->remove_value( section
, name
);