Use a variable on the stack to not have a temporary in the call
[ACE_TAO.git] / TAO / utils / wxNamingViewer / wxSelectNSDialog.cpp
blobca363fcfd1ce9d255785b22dd84e666c85b4f926
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) {
127 ACE_TString value;
128 if(config->get_string_value( section, name.c_str(), value) == 0) {
129 servers->Append(
130 name.c_str(),
131 new wxString( value.c_str()));
133 index++;
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) {
151 servers->Append(
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(
157 section,
158 dialog->getServerName().c_str(),
159 value);
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(
175 "okButton",
176 this));
177 assert( ctrl);
178 ctrl->SetDefault();
179 servers->SetFocus();
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);
192 EndModal( wxID_OK);
196 void WxSelectNSDialog::onOK( wxCommandEvent& WXUNUSED(event))
198 int index = servers->GetSelection();
199 if (index == -1) {
200 wxMessageBox(
201 "You must select a server or cancel",
202 "Error",
203 wxOK | wxICON_EXCLAMATION);
204 return;
206 ior = *static_cast<wxString*>( servers->GetClientData( index));
207 serverName = servers->GetString( index);
208 EndModal( wxID_OK);
212 void WxSelectNSDialog::onRemove( wxCommandEvent& WXUNUSED(event))
214 int index = servers->GetSelection();
215 if (index != -1) {
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);