Use a variable on the stack to not have a temporary in the call
[ACE_TAO.git] / TAO / utils / NamingViewer / NamingViewerDlg.cpp
blob16ed157e9d1a1194cf6f5d667942dff73243180f
1 #include "stdafx.h"
2 #include "NamingViewer.h"
3 #include "NamingViewerDlg.h"
4 #include "ViewIORDialog.h"
5 #include "orbsvcs/Naming/Naming_Client.h"
6 #include "SelectNSDialog.h"
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
15 /////////////////////////////////////////////////////////////////////////////
16 // CAboutDlg dialog used for App About
18 class CAboutDlg : public CDialog
20 public:
21 CAboutDlg();
23 // Dialog Data
24 //{{AFX_DATA(CAboutDlg)
25 enum { IDD = IDD_ABOUTBOX };
26 //}}AFX_DATA
28 // ClassWizard generated virtual function overrides
29 //{{AFX_VIRTUAL(CAboutDlg)
30 protected:
31 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
32 //}}AFX_VIRTUAL
34 // Implementation
35 protected:
36 //{{AFX_MSG(CAboutDlg)
37 //}}AFX_MSG
38 DECLARE_MESSAGE_MAP()
41 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
43 //{{AFX_DATA_INIT(CAboutDlg)
44 //}}AFX_DATA_INIT
47 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
49 CDialog::DoDataExchange(pDX);
50 //{{AFX_DATA_MAP(CAboutDlg)
51 //}}AFX_DATA_MAP
54 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
55 //{{AFX_MSG_MAP(CAboutDlg)
56 // No message handlers
57 //}}AFX_MSG_MAP
58 END_MESSAGE_MAP()
60 /////////////////////////////////////////////////////////////////////////////
61 // CNamingViewerDlg dialog
63 CNamingViewerDlg::CNamingViewerDlg(CORBA::ORB_ptr pORB, CWnd* pParent /*=0*/)
64 : CDialog(CNamingViewerDlg::IDD, pParent)
66 //{{AFX_DATA_INIT(CNamingViewerDlg)
67 m_Server = _T("");
68 //}}AFX_DATA_INIT
69 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
70 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
72 m_pORB = pORB;
75 void CNamingViewerDlg::DoDataExchange(CDataExchange* pDX)
77 CDialog::DoDataExchange(pDX);
78 //{{AFX_DATA_MAP(CNamingViewerDlg)
79 DDX_Control(pDX, IDC_TREE, m_Tree);
80 DDX_Text(pDX, IDC_SERVER, m_Server);
81 //}}AFX_DATA_MAP
84 BEGIN_MESSAGE_MAP(CNamingViewerDlg, CDialog)
85 //{{AFX_MSG_MAP(CNamingViewerDlg)
86 ON_WM_SYSCOMMAND()
87 ON_WM_PAINT()
88 ON_WM_QUERYDRAGICON()
89 ON_BN_CLICKED(IDC_SELECT_NS, OnSelectNs)
90 ON_WM_SIZE()
91 //}}AFX_MSG_MAP
92 #if !defined (_WIN32_WCE)
93 ON_WM_GETMINMAXINFO()
94 #endif
95 END_MESSAGE_MAP()
97 /////////////////////////////////////////////////////////////////////////////
98 // CNamingViewerDlg message handlers
100 BOOL CNamingViewerDlg::OnInitDialog()
102 CDialog::OnInitDialog();
104 // Add "About..." menu item to system menu.
106 // IDM_ABOUTBOX must be in the system command range.
107 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
108 ASSERT(IDM_ABOUTBOX < 0xF000);
110 #if !defined (_WIN32_WCE)
111 CMenu* pSysMenu = GetSystemMenu(FALSE);
112 if (pSysMenu != 0)
114 CString strAboutMenu;
115 strAboutMenu.LoadString(IDS_ABOUTBOX);
116 if (!strAboutMenu.IsEmpty())
118 pSysMenu->AppendMenu(MF_SEPARATOR);
119 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
122 #endif
124 // Set the icon for this dialog. The framework does this automatically
125 // when the application's main window is not a dialog
126 SetIcon(m_hIcon, TRUE); // Set big icon
127 SetIcon(m_hIcon, FALSE); // Set small icon
129 // TODO: Add extra initialization here
130 m_Tree.SetpORB(m_pORB);
132 // Initialize the naming client and get the root context
133 TAO_Naming_Client Client;
134 ACE_Time_Value Timeout(0,500000);
135 if(!Client.init(m_pORB, &Timeout))
137 m_RootContext = Client.get_context();
138 m_Server = "Default";
139 // For debugging, sets up some initial contexts in the NS
141 CosNaming::Name Name;
142 Name.length(1);
143 Name[0].id = CORBA::string_dup("test");
144 CORBA::Object_var Object = CORBA::Object::_nil();
145 m_RootContext->rebind(Name, Object);
146 CosNaming::NamingContext_var Context = m_RootContext->new_context();
147 Name[0].id = CORBA::string_dup("test context");
148 m_RootContext->rebind_context(Name, Context);
149 Context->rebind_context(Name, Context);
152 Resolve();
153 UpdateData(FALSE);
154 return TRUE; // return TRUE unless you set the focus to a control
157 void CNamingViewerDlg::OnSysCommand(UINT nID, LPARAM lParam)
159 if ((nID & 0xFFF0) == IDM_ABOUTBOX)
161 CAboutDlg dlgAbout;
162 dlgAbout.DoModal();
164 else
166 CDialog::OnSysCommand(nID, lParam);
170 // If you add a minimize button to your dialog, you will need the code below
171 // to draw the icon. For MFC applications using the document/view model,
172 // this is automatically done for you by the framework.
174 void CNamingViewerDlg::OnPaint()
176 if (IsIconic())
178 CPaintDC dc(this); // device context for painting
180 // Center icon in client rectangle
181 int cxIcon = GetSystemMetrics(SM_CXICON);
182 int cyIcon = GetSystemMetrics(SM_CYICON);
183 CRect rect;
184 GetClientRect(&rect);
185 int x = (rect.Width() - cxIcon + 1) / 2;
186 int y = (rect.Height() - cyIcon + 1) / 2;
188 // Draw the icon
189 dc.DrawIcon(x, y, m_hIcon);
191 else
193 CDialog::OnPaint();
197 // The system calls this to obtain the cursor to display while the user drags
198 // the minimized window.
199 HCURSOR CNamingViewerDlg::OnQueryDragIcon()
201 return (HCURSOR) m_hIcon;
204 void CNamingViewerDlg::Resolve()
206 m_Tree.Resolve(m_RootContext);
209 void CNamingViewerDlg::OnSelectNs()
211 // TODO: Add your control notification handler code here
212 CSelectNSDialog Dialog;
213 if(Dialog.DoModal() != IDOK)
215 return;
219 CORBA::Object_var Object = m_pORB->string_to_object(Dialog.GetIOR());
220 m_RootContext = CosNaming::NamingContext::_narrow(Object);
221 m_Server = Dialog.GetName();
222 UpdateData(FALSE);
223 Resolve();
225 catch(CORBA::Exception& ex)
227 MessageBox(ACE_TEXT_CHAR_TO_TCHAR (ex._rep_id()), ACE_TEXT ("CORBA::Exception"));
231 void CNamingViewerDlg::OnSize(UINT nType, int cx, int cy)
233 CDialog::OnSize(nType, cx, cy);
234 // TODO: Add your message handler code here
236 // Resize the tree control
237 if(m_Tree.m_hWnd)
239 CRect Size;
240 m_Tree.GetWindowRect(Size);
241 ScreenToClient(Size);
242 int Border = Size.left;
243 Size.right = cx - Border;
244 Size.bottom = cy - Border;
245 m_Tree.MoveWindow(Size, TRUE);
249 #if !defined (_WIN32_WCE)
250 void CNamingViewerDlg::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
252 // Prevent the window from being resized too small
253 CWnd* pSelect = GetDlgItem(IDC_NS);
254 if(pSelect)
256 CRect Size;
257 pSelect->GetWindowRect(Size);
258 ScreenToClient(Size);
259 lpMMI->ptMinTrackSize.x = Size.right + Size.left + 7;
260 lpMMI->ptMinTrackSize.y = 200;
263 #endif