Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / utils / NamingViewer / NamingViewerDlg.cpp
blobad8f422ae33c740a5aa0425ee41193b348758494
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;
76 void CNamingViewerDlg::DoDataExchange(CDataExchange* pDX)
78 CDialog::DoDataExchange(pDX);
79 //{{AFX_DATA_MAP(CNamingViewerDlg)
80 DDX_Control(pDX, IDC_TREE, m_Tree);
81 DDX_Text(pDX, IDC_SERVER, m_Server);
82 //}}AFX_DATA_MAP
85 BEGIN_MESSAGE_MAP(CNamingViewerDlg, CDialog)
86 //{{AFX_MSG_MAP(CNamingViewerDlg)
87 ON_WM_SYSCOMMAND()
88 ON_WM_PAINT()
89 ON_WM_QUERYDRAGICON()
90 ON_BN_CLICKED(IDC_SELECT_NS, OnSelectNs)
91 ON_WM_SIZE()
92 //}}AFX_MSG_MAP
93 #if !defined (_WIN32_WCE)
94 ON_WM_GETMINMAXINFO()
95 #endif
96 END_MESSAGE_MAP()
98 /////////////////////////////////////////////////////////////////////////////
99 // CNamingViewerDlg message handlers
101 BOOL CNamingViewerDlg::OnInitDialog()
103 CDialog::OnInitDialog();
105 // Add "About..." menu item to system menu.
107 // IDM_ABOUTBOX must be in the system command range.
108 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
109 ASSERT(IDM_ABOUTBOX < 0xF000);
111 #if !defined (_WIN32_WCE)
112 CMenu* pSysMenu = GetSystemMenu(FALSE);
113 if (pSysMenu != 0)
115 CString strAboutMenu;
116 strAboutMenu.LoadString(IDS_ABOUTBOX);
117 if (!strAboutMenu.IsEmpty())
119 pSysMenu->AppendMenu(MF_SEPARATOR);
120 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
123 #endif
125 // Set the icon for this dialog. The framework does this automatically
126 // when the application's main window is not a dialog
127 SetIcon(m_hIcon, TRUE); // Set big icon
128 SetIcon(m_hIcon, FALSE); // Set small icon
130 // TODO: Add extra initialization here
131 m_Tree.SetpORB(m_pORB);
133 // Initialize the naming client and get the root context
134 TAO_Naming_Client Client;
135 ACE_Time_Value Timeout(0,500000);
136 if(!Client.init(m_pORB, &Timeout))
138 m_RootContext = Client.get_context();
139 m_Server = "Default";
140 // For debugging, sets up some initial contexts in the NS
142 CosNaming::Name Name;
143 Name.length(1);
144 Name[0].id = CORBA::string_dup("test");
145 CORBA::Object_var Object = CORBA::Object::_nil();
146 m_RootContext->rebind(Name, Object);
147 CosNaming::NamingContext_var Context = m_RootContext->new_context();
148 Name[0].id = CORBA::string_dup("test context");
149 m_RootContext->rebind_context(Name, Context);
150 Context->rebind_context(Name, Context);
153 Resolve();
154 UpdateData(FALSE);
155 return TRUE; // return TRUE unless you set the focus to a control
158 void CNamingViewerDlg::OnSysCommand(UINT nID, LPARAM lParam)
160 if ((nID & 0xFFF0) == IDM_ABOUTBOX)
162 CAboutDlg dlgAbout;
163 dlgAbout.DoModal();
165 else
167 CDialog::OnSysCommand(nID, lParam);
171 // If you add a minimize button to your dialog, you will need the code below
172 // to draw the icon. For MFC applications using the document/view model,
173 // this is automatically done for you by the framework.
175 void CNamingViewerDlg::OnPaint()
177 if (IsIconic())
179 CPaintDC dc(this); // device context for painting
181 // Center icon in client rectangle
182 int cxIcon = GetSystemMetrics(SM_CXICON);
183 int cyIcon = GetSystemMetrics(SM_CYICON);
184 CRect rect;
185 GetClientRect(&rect);
186 int x = (rect.Width() - cxIcon + 1) / 2;
187 int y = (rect.Height() - cyIcon + 1) / 2;
189 // Draw the icon
190 dc.DrawIcon(x, y, m_hIcon);
192 else
194 CDialog::OnPaint();
198 // The system calls this to obtain the cursor to display while the user drags
199 // the minimized window.
200 HCURSOR CNamingViewerDlg::OnQueryDragIcon()
202 return (HCURSOR) m_hIcon;
205 void CNamingViewerDlg::Resolve()
207 m_Tree.Resolve(m_RootContext);
210 void CNamingViewerDlg::OnSelectNs()
212 // TODO: Add your control notification handler code here
213 CSelectNSDialog Dialog;
214 if(Dialog.DoModal() != IDOK)
216 return;
220 CORBA::Object_var Object = m_pORB->string_to_object(Dialog.GetIOR());
221 m_RootContext = CosNaming::NamingContext::_narrow(Object);
222 m_Server = Dialog.GetName();
223 UpdateData(FALSE);
224 Resolve();
226 catch(CORBA::Exception& ex)
228 MessageBox(ACE_TEXT_CHAR_TO_TCHAR (ex._rep_id()), ACE_TEXT ("CORBA::Exception"));
232 void CNamingViewerDlg::OnSize(UINT nType, int cx, int cy)
234 CDialog::OnSize(nType, cx, cy);
235 // TODO: Add your message handler code here
237 // Resize the tree control
238 if(m_Tree.m_hWnd)
240 CRect Size;
241 m_Tree.GetWindowRect(Size);
242 ScreenToClient(Size);
243 int Border = Size.left;
244 Size.right = cx - Border;
245 Size.bottom = cy - Border;
246 m_Tree.MoveWindow(Size, TRUE);
250 #if !defined (_WIN32_WCE)
251 void CNamingViewerDlg::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
253 // Prevent the window from being resized too small
254 CWnd* pSelect = GetDlgItem(IDC_NS);
255 if(pSelect)
257 CRect Size;
258 pSelect->GetWindowRect(Size);
259 ScreenToClient(Size);
260 lpMMI->ptMinTrackSize.x = Size.right + Size.left + 7;
261 lpMMI->ptMinTrackSize.y = 200;
264 #endif