Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / utils / wxNamingViewer / wxSelectNSDialog.cpp
blob5b0a83863249fcf586613ec87ece1ae132ab17ba
1 // @file wxSelectNSDialog.cpp
2 //
3 // @author Charlie Frasch <cfrasch@atdesk.com>
4 #include "pch.h"
5 #include "wxSelectNSDialog.h"
7 #include "ace/Configuration.h"
8 #include "wx/sizer.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);
19 topsizer->Add(
20 new wxListBox(
21 dialog,
22 IDC_SERVERS,
23 wxDefaultPosition,
24 wxDefaultSize,
27 wxLB_SINGLE,
28 wxDefaultValidator,
29 "serversList"
32 wxEXPAND | wxALL,
33 5);
35 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
37 wxButton* okButton = new wxButton( dialog, wxID_OK, "OK" );
38 okButton->SetName( "okButton");
39 button_sizer->Add(
40 okButton,
42 wxALL,
43 5);
45 button_sizer->Add(
46 new wxButton( dialog, IDC_DEFAULT, "Default" ),
48 wxALL,
49 5);
50 button_sizer->Add(
51 new wxButton( dialog, IDC_ADD, "Add" ),
53 wxALL,
54 5);
55 button_sizer->Add(
56 new wxButton( dialog, IDC_REMOVE, "Remove" ),
58 wxALL,
59 5);
60 button_sizer->Add(
61 new wxButton( dialog, wxID_CANCEL, "Cancel" ),
63 wxALL,
64 5);
66 topsizer->Add(
67 button_sizer,
69 wxALIGN_CENTER);
71 dialog->SetSizer( topsizer);
72 topsizer->SetSizeHints( dialog);
74 }; // anonymous
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)
83 END_EVENT_TABLE()
86 WxSelectNSDialog::WxSelectNSDialog( wxWindow* parent)
87 #if defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
88 : wxDialog()
89 #else
90 : wxDialog(
91 parent,
92 IDD_SELECT_NS,
93 "Select Naming Service",
94 wxDefaultPosition,
95 wxSize(181,94),
96 wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU,
97 "selectNS")
98 #endif // defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
99 , config( 0)
101 #if defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
102 LoadFromResource( parent, "selectNS");
103 #else
104 create_dialog_components( this);
105 #endif // defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
106 servers = static_cast<wxListBox*>( wxFindWindowByName(
107 "serversList",
108 this));
109 assert( servers);
111 #if defined (ACE_WIN32)
112 HKEY hKey = ACE_Configuration_Win32Registry::resolve_key(
113 HKEY_LOCAL_MACHINE,
114 "Software\\TAO\\NamingViewer\\Servers");
115 config = new ACE_Configuration_Win32Registry( hKey);
116 #else
117 // TODO: non-windoz
118 ACE_Configuration_Heap *heap = new ACE_Configuration_Heap;
119 heap->open ();
120 config = heap;
121 #endif
122 ACE_Configuration_Section_Key section = config->root_section();
123 int index = 0;
124 ACE_TString name;
125 ACE_Configuration::VALUETYPE type;
126 while(config->enumerate_values( section, index, name, type) == 0) {
128 ACE_TString value;
129 if(config->get_string_value( section, name.c_str(), value) == 0) {
131 servers->Append(
132 name.c_str(),
133 new wxString( value.c_str()));
136 index++;
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) {
158 servers->Append(
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(
164 section,
165 dialog->getServerName().c_str(),
166 value);
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(
183 "okButton",
184 this));
185 assert( ctrl);
186 ctrl->SetDefault();
187 servers->SetFocus();
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);
200 EndModal( wxID_OK);
204 void WxSelectNSDialog::onOK( wxCommandEvent& WXUNUSED(event))
206 int index = servers->GetSelection();
207 if (index == -1) {
209 wxMessageBox(
210 "You must select a server or cancel",
211 "Error",
212 wxOK | wxICON_EXCLAMATION);
213 return;
215 ior = *static_cast<wxString*>( servers->GetClientData( index));
216 serverName = servers->GetString( index);
217 EndModal( wxID_OK);
221 void WxSelectNSDialog::onRemove( wxCommandEvent& WXUNUSED(event))
223 int index = servers->GetSelection();
224 if (index != -1) {
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);