2 #include "NamingViewer.h"
3 #include "NamingViewerDlg.h"
4 #include "ViewIORDialog.h"
5 #include "orbsvcs/Naming/Naming_Client.h"
6 #include "SelectNSDialog.h"
11 static char THIS_FILE
[] = __FILE__
;
15 /////////////////////////////////////////////////////////////////////////////
16 // CAboutDlg dialog used for App About
18 class CAboutDlg
: public CDialog
24 //{{AFX_DATA(CAboutDlg)
25 enum { IDD
= IDD_ABOUTBOX
};
28 // ClassWizard generated virtual function overrides
29 //{{AFX_VIRTUAL(CAboutDlg)
31 virtual void DoDataExchange(CDataExchange
* pDX
); // DDX/DDV support
36 //{{AFX_MSG(CAboutDlg)
41 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD
)
43 //{{AFX_DATA_INIT(CAboutDlg)
47 void CAboutDlg::DoDataExchange(CDataExchange
* pDX
)
49 CDialog::DoDataExchange(pDX
);
50 //{{AFX_DATA_MAP(CAboutDlg)
54 BEGIN_MESSAGE_MAP(CAboutDlg
, CDialog
)
55 //{{AFX_MSG_MAP(CAboutDlg)
56 // No message handlers
60 /////////////////////////////////////////////////////////////////////////////
61 // CNamingViewerDlg dialog
63 CNamingViewerDlg::CNamingViewerDlg(CORBA::ORB_ptr pORB
, CWnd
* pParent
/*=0*/)
64 : CDialog(CNamingViewerDlg::IDD
, pParent
)
66 //{{AFX_DATA_INIT(CNamingViewerDlg)
69 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
70 m_hIcon
= AfxGetApp()->LoadIcon(IDR_MAINFRAME
);
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
);
84 BEGIN_MESSAGE_MAP(CNamingViewerDlg
, CDialog
)
85 //{{AFX_MSG_MAP(CNamingViewerDlg)
89 ON_BN_CLICKED(IDC_SELECT_NS
, OnSelectNs
)
92 #if !defined (_WIN32_WCE)
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
);
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
);
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;
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);
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
)
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()
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
);
184 GetClientRect(&rect
);
185 int x
= (rect
.Width() - cxIcon
+ 1) / 2;
186 int y
= (rect
.Height() - cyIcon
+ 1) / 2;
189 dc
.DrawIcon(x
, y
, m_hIcon
);
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
)
219 CORBA::Object_var Object
= m_pORB
->string_to_object(Dialog
.GetIOR());
220 m_RootContext
= CosNaming::NamingContext::_narrow(Object
);
221 m_Server
= Dialog
.GetName();
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
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
);
257 pSelect
->GetWindowRect(Size
);
258 ScreenToClient(Size
);
259 lpMMI
->ptMinTrackSize
.x
= Size
.right
+ Size
.left
+ 7;
260 lpMMI
->ptMinTrackSize
.y
= 200;