Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / utils / wxNamingViewer / wxBindDialog.cpp
blob6baafd53a19c8f8eff57b75eb9c913b664a8b724
1 // @file wxBindDialog.cpp
2 //
3 // @author Charlie Frasch <cfrasch@atdesk.com>
4 #include "pch.h"
5 #include "wxBindDialog.h"
7 #include "wxAutoDialog.h"
8 #include "wxNamingViewer.h"
9 #include "wxViewIORDialog.h"
11 #include "wx/sizer.h"
13 namespace // anonymous
15 void create_dialog_components(wxDialog* dialog)
17 wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
20 wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
21 sizer->Add(new wxStaticText(dialog, -1, "ID:" ), 0, wxALL, 5);
22 wxTextCtrl* text = new wxTextCtrl(dialog, IDC_ID);
23 text->SetName("idTextCtrl");
24 sizer->Add(text, 1, wxALL, 5);
25 topsizer->Add(sizer, 0, wxALIGN_LEFT | wxEXPAND);
29 wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
30 sizer->Add(new wxStaticText(dialog, -1, "Kind:" ), 0, wxALL, 5);
31 wxTextCtrl* text = new wxTextCtrl(dialog, IDC_KIND);
32 text->SetName("kindTextCtrl");
33 sizer->Add(text, 1, wxALL, 5);
34 topsizer->Add(sizer, 0, wxALIGN_LEFT | wxEXPAND);
38 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL);
39 sizer->Add(new wxStaticText( dialog, -1, "IOR:" ), 0, wxALL, 5);
40 wxTextCtrl* text = new wxTextCtrl(dialog, IDC_IOR);
41 text->SetName( "iorTextCtrl");
42 sizer->Add(text, 1, wxALL, 5);
43 topsizer->Add(sizer, 0, wxALIGN_LEFT | wxEXPAND);
46 wxBoxSizer* button_sizer = new wxBoxSizer( wxHORIZONTAL);
48 wxButton* button = new wxButton( dialog, wxID_OK, "OK" );
49 button->SetName( "okButton");
50 button_sizer->Add(button, 0, wxALL, 5);
53 button_sizer->Add(new wxButton( dialog, wxID_CANCEL, "Cancel" ),
55 wxALL,
56 5);
58 topsizer->Add(button_sizer, 0, wxALIGN_CENTER);
60 dialog->SetSizer( topsizer);
61 topsizer->SetSizeHints( dialog);
64 }; // anonymous
67 BEGIN_EVENT_TABLE( WxBindDialog, wxDialog)
68 EVT_BUTTON( IDC_VIEWIOR, WxBindDialog::onViewIOR)
69 END_EVENT_TABLE()
72 WxBindDialog::WxBindDialog(
73 bool isContext,
74 CORBA::ORB_ptr orb,
75 wxWindow* parent)
76 #if defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
77 : wxDialog()
78 #else
79 : wxDialog(
80 parent,
81 IDD_BIND,
82 "Bind Object/Context",
83 wxDefaultPosition,
84 wxSize( 300, 75),
85 wxRAISED_BORDER | wxCAPTION | wxTHICK_FRAME | wxSYSTEM_MENU,
86 "bindObject")
87 #endif // defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
88 , ior()
89 , id ()
90 , kind ()
91 , object ()
92 , orb (orb)
93 , name ()
94 , isContext (isContext)
96 #if defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
97 LoadFromResource( parent, "bindObject");
98 #else
99 create_dialog_components( this);
100 #endif // defined(wxUSE_RESOURCES) && (wxUSE_RESOURCES == 1)
101 if (isContext) {
102 SetTitle( "Bind Context");
103 } else {
104 SetTitle( "Bind Object");
106 wxButton* ctrl = static_cast<wxButton*>( wxFindWindowByName(
107 "okButton",
108 this));
109 assert( ctrl);
110 ctrl->SetDefault();
114 void WxBindDialog::onViewIOR( wxCommandEvent& WXUNUSED(event))
116 TransferDataFromWindow();
117 WxAutoDialog<WxViewIORDialog> dialog( new WxViewIORDialog( orb, object.in(), 0));
118 dialog->ShowModal();
122 bool WxBindDialog::TransferDataFromWindow()
124 wxTextCtrl* ctrl = static_cast<wxTextCtrl*>( wxFindWindowByName(
125 "iorTextCtrl",
126 this));
127 assert( ctrl);
128 ior = ctrl->GetValue();
130 ctrl = static_cast<wxTextCtrl*>( wxFindWindowByName(
131 "idTextCtrl",
132 this));
133 assert( ctrl);
134 id = ctrl->GetValue();
136 ctrl = static_cast<wxTextCtrl*>( wxFindWindowByName(
137 "kindTextCtrl",
138 this));
139 assert( ctrl);
140 kind = ctrl->GetValue();
142 name.length( 1);
143 name[0].id = CORBA::string_dup( id);
144 name[0].kind = CORBA::string_dup( kind);
145 try {
146 object = orb->string_to_object( ior);
147 } catch(CORBA::Exception& ex) {
148 wxMessageBox( ex._rep_id(), "Invalid IOR");
149 object = CORBA::Object::_nil();
151 return true;