Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / utils / wxNamingViewer / wxNamingViewerFrame.cpp
blobe9859892e31f8d720c1c3fbfdbfa4c1817e7c8fa
1 // @file wxNamingViewerFrame.cpp
2 //
3 // @author Charlie Frasch <cfrasch@atdesk.com>
4 #include "pch.h"
5 #include "wxNamingViewerFrame.h"
7 #include "wx/clipbrd.h"
8 #include "orbsvcs/Naming/Naming_Client.h"
9 #include "wxNamingViewer.h"
10 #include "wxSelectNSDialog.h"
11 #include "ace/SString.h"
13 #if defined(__WXGTK__) || defined(__WXMOTIF__)
14 #include "mondrian.xpm"
15 #endif
18 enum {
19 menuQuit = 1,
20 menuAbout,
21 menuCopy,
22 buttonSelectNS = IDC_SELECT_NS
26 BEGIN_EVENT_TABLE( WxNamingViewerFrame, wxFrame)
27 EVT_MENU( menuQuit, WxNamingViewerFrame::OnQuit)
28 EVT_MENU( menuAbout, WxNamingViewerFrame::OnAbout)
29 EVT_MENU( menuCopy, WxNamingViewerFrame::onMenuCopy)
30 EVT_UPDATE_UI( menuCopy, WxNamingViewerFrame::onUpdateUICopy)
31 EVT_BUTTON( buttonSelectNS, WxNamingViewerFrame::onSelectNS)
32 END_EVENT_TABLE()
35 WxNamingViewerFrame::WxNamingViewerFrame(
36 const wxString& title,
37 const wxPoint& pos,
38 const wxSize& size,
39 CORBA::ORB_ptr pOrb):
40 wxFrame(
42 -1, title,
43 pos,
44 size),
45 pOrb( pOrb),
46 tree( 0),
47 server( "")
49 SetIcon( wxICON( mondrian));
51 wxMenu* fileMenu = new wxMenu( "", wxMENU_TEAROFF);
52 fileMenu->Append( menuQuit, "E&xit", "Quit this program");
54 wxMenu* editMenu = new wxMenu( "", wxMENU_TEAROFF);
55 editMenu->Append( menuCopy, "&Copy\tCtrl+C");
57 wxMenu* helpMenu = new wxMenu();
58 helpMenu->Append( menuAbout, "&About...", "Show about dialog");
60 wxMenuBar* menuBar = new wxMenuBar();
61 menuBar->Append( fileMenu, "&File");
62 menuBar->Append( editMenu, "&Edit");
63 menuBar->Append( helpMenu, "&Help");
64 SetMenuBar( menuBar);
66 wxPanel* panel = new wxPanel(
67 this,
68 -1);
69 wxBoxSizer* topSizer = new wxBoxSizer( wxVERTICAL);
70 topSizer->Add( panel, 1, wxGROW);
72 wxBoxSizer* nsSizer = new wxStaticBoxSizer(
73 new wxStaticBox(
74 panel,
75 IDC_NS,
76 "Name Server"),
77 wxHORIZONTAL);
78 serverText = new wxTextCtrl(
79 panel,
80 IDC_SERVER,
81 "",
82 wxDefaultPosition,
83 wxSize( 158, 20),
84 wxTE_READONLY);
85 wxButton* selectNSButton = new wxButton(
86 panel,
87 IDC_SELECT_NS,
88 "Select",
89 wxDefaultPosition,
90 wxSize( 50, 20));
91 nsSizer->Add( serverText, 1, wxGROW);
92 nsSizer->Add( selectNSButton, 0, wxALIGN_LEFT | wxLEFT, 10);
94 wxBoxSizer* treeSizer = new wxBoxSizer( wxVERTICAL);
95 treeSizer->Add( nsSizer, 0, wxGROW);
96 tree = new WxNamingTree(
97 panel,
98 WxNamingTree::treeCtrl);
99 treeSizer->Add( tree, 1, wxGROW);
101 panel->SetAutoLayout( TRUE );
102 panel->SetSizer( treeSizer );
103 treeSizer->Fit( this);
104 treeSizer->SetSizeHints( this);
106 selectNS = new WxSelectNSDialog( this);
108 tree->setOrb( pOrb);
109 setDefaultNS();
110 resolve();
114 WxNamingViewerFrame::~WxNamingViewerFrame()
116 selectNS->Destroy();
120 void WxNamingViewerFrame::OnQuit( wxCommandEvent& WXUNUSED(event))
122 Close( TRUE);
126 void WxNamingViewerFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
128 wxString msg(
129 "wxNamingViewer Version 1.1\n"
130 "Author: Charlie Frasch <cfrasch@atdesk.com>");
132 wxMessageBox(
133 msg.c_str(),
134 "About wxNamingViewer",
135 wxOK | wxICON_INFORMATION,
136 this);
140 void WxNamingViewerFrame::onMenuCopy( wxCommandEvent& WXUNUSED( event))
142 tree->copySelectedToClipboard();
146 void WxNamingViewerFrame::onSelectNS( wxCommandEvent& WXUNUSED( event))
148 switch( selectNS->ShowModal()) {
149 case wxID_OK:
150 try {
151 // TODO: need hourglass
152 CORBA::Object_var object = pOrb->string_to_object(
153 selectNS->getIOR().c_str());
154 rootContext = CosNaming::NamingContext::_narrow( object.in ());
155 server = selectNS->getServerName();
156 serverText->SetValue( server);
157 resolve();
158 } catch( CORBA::Exception const & ex) {
159 wxMessageBox(
160 ex._info().c_str(),
161 "CORBA::Exception");
163 break;
165 case IDC_DEFAULT:
166 // TODO: need hourglass
167 setDefaultNS();
168 resolve();
169 break;
174 void WxNamingViewerFrame::onUpdateUICopy( wxUpdateUIEvent& event)
176 event.Enable( tree->isNodeSelected());
180 void WxNamingViewerFrame::resolve()
182 tree->resolve( rootContext.in ());
186 void WxNamingViewerFrame::setDefaultNS()
188 server = "Default";
189 serverText->SetValue( server);
191 TAO_Naming_Client client;
192 if (client.init( pOrb) == 0) {
193 rootContext = client.get_context();
195 // For debugging, sets up some initial contexts in the NS
197 CosNaming::NamingContext_var app2;
198 app2 = rootContext->new_context();
200 CosNaming::Name name;
201 name.length( 1);
202 name[0].id = CORBA::string_dup( "app2");
203 rootContext->rebind_context( name, app2);
205 CosNaming::NamingContext_var devices;
206 devices = app2->new_context();
207 name[0].id = CORBA::string_dup( "devices");
208 app2->rebind_context( name, devices);
210 CosNaming::NamingContext_var collections;
211 collections = app2->new_context();
212 name[0].id = CORBA::string_dup( "collections");
213 app2->rebind_context( name, collections);
215 name[0].id = CORBA::string_dup( "my app");
216 CORBA::Object_var myApp = CORBA::Object::_nil();
217 app2->rebind( name, myApp);
219 name[0].id = CORBA::string_dup( "dev1");
220 CORBA::Object_var dev1 = CORBA::Object::_nil();
221 devices->rebind( name, myApp);
223 name[0].id = CORBA::string_dup( "dev2");
224 CORBA::Object_var dev2 = CORBA::Object::_nil();
225 devices->rebind( name, myApp);