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
);
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
);
85 BEGIN_MESSAGE_MAP(CNamingViewerDlg
, CDialog
)
86 //{{AFX_MSG_MAP(CNamingViewerDlg)
90 ON_BN_CLICKED(IDC_SELECT_NS
, OnSelectNs
)
93 #if !defined (_WIN32_WCE)
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
);
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
);
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;
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);
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
)
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()
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
);
185 GetClientRect(&rect
);
186 int x
= (rect
.Width() - cxIcon
+ 1) / 2;
187 int y
= (rect
.Height() - cyIcon
+ 1) / 2;
190 dc
.DrawIcon(x
, y
, m_hIcon
);
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
)
220 CORBA::Object_var Object
= m_pORB
->string_to_object(Dialog
.GetIOR());
221 m_RootContext
= CosNaming::NamingContext::_narrow(Object
);
222 m_Server
= Dialog
.GetName();
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
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
);
258 pSelect
->GetWindowRect(Size
);
259 ScreenToClient(Size
);
260 lpMMI
->ptMinTrackSize
.x
= Size
.right
+ Size
.left
+ 7;
261 lpMMI
->ptMinTrackSize
.y
= 200;