- Initial work on maps
[public/netxms.git] / src / console / win32 / MapFrame.cpp
1 // MapFrame.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "nxcon.h"
6 #include "MapFrame.h"
7
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
13
14 /////////////////////////////////////////////////////////////////////////////
15 // CMapFrame
16
17 IMPLEMENT_DYNCREATE(CMapFrame, CMDIChildWnd)
18
19 CMapFrame::CMapFrame()
20 {
21 }
22
23 CMapFrame::~CMapFrame()
24 {
25 }
26
27
28 BEGIN_MESSAGE_MAP(CMapFrame, CMDIChildWnd)
29 //{{AFX_MSG_MAP(CMapFrame)
30 ON_WM_CREATE()
31 ON_WM_SIZE()
32 ON_WM_SETFOCUS()
33 ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
34 //}}AFX_MSG_MAP
35 END_MESSAGE_MAP()
36
37 /////////////////////////////////////////////////////////////////////////////
38 // CMapFrame message handlers
39
40 BOOL CMapFrame::PreCreateWindow(CREATESTRUCT& cs)
41 {
42 if (cs.lpszClass == NULL)
43 cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, NULL, NULL,
44 AfxGetApp()->LoadIcon(IDI_NETMAP));
45 return CMDIChildWnd::PreCreateWindow(cs);
46 }
47
48
49 //
50 // WM_CREATE message handler
51 //
52
53 int CMapFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
54 {
55 RECT rect;
56 static TBBUTTON tbButtons[] =
57 {
58 { 0, 0, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 },
59 { 1, 0, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 }
60 };
61
62 if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
63 return -1;
64
65 EnableDocking(CBRS_ALIGN_ANY);
66
67 // Create toolbar
68 m_wndToolBar.CreateEx(this);
69 m_wndToolBar.LoadToolBar(IDT_MAP);
70 //FloatControlBar(&m_wndToolBar, TRUE, FALSE);
71 /* m_wndToolBar.Create(WS_CHILD | WS_VISIBLE | CCS_NODIVIDER | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | TBSTYLE_TRANSPARENT, rect, this, ID_TOOLBAR_CTRL);
72 m_wndToolBar.SetExtendedStyle(WS_EX_WINDOWEDGE);
73 m_wndToolBar.SetButtonSize(CSize(20, 20));
74 m_wndToolBar.LoadImages(IDB_HIST_SMALL_COLOR, HINST_COMMCTRL);
75 m_wndToolBar.AddButtons(2, tbButtons);*/
76
77 // Create and initialize map view
78 GetClientRect(&rect);
79 m_wndMapView.Create(NULL, NULL, WS_CHILD | WS_VISIBLE, rect, this, 0);
80
81 PostMessage(WM_COMMAND, ID_VIEW_REFRESH, 0);
82
83 return 0;
84 }
85
86
87 //
88 // WM_SIZE message handler
89 //
90
91 void CMapFrame::OnSize(UINT nType, int cx, int cy)
92 {
93 int nToolBarHeight;
94
95 CMDIChildWnd::OnSize(nType, cx, cy);
96 // m_wndToolBar.AutoSize();
97 nToolBarHeight = GetWindowSize(&m_wndToolBar).cy;
98 m_wndMapView.SetWindowPos(NULL, 0, nToolBarHeight, cx, cy - nToolBarHeight, SWP_NOZORDER);
99 }
100
101
102 //
103 // WM_SETFOCUS message handler
104 //
105
106 void CMapFrame::OnSetFocus(CWnd* pOldWnd)
107 {
108 CMDIChildWnd::OnSetFocus(pOldWnd);
109 m_wndMapView.SetFocus();
110 }
111
112
113 //
114 // WM_COMMAND::ID_VIEW_REFRESH message handler
115 //
116
117 void CMapFrame::OnViewRefresh()
118 {
119 m_wndMapView.SetMap(new nxMap(1, _T("Default"), _T("Default map")));
120 /* NXC_OBJECT *pObject;
121 DWORD i;
122 CString strFullString, strTitle;
123
124 if (strFullString.LoadString(IDR_MAPFRAME))
125 AfxExtractSubString(strTitle, strFullString, CDocTemplate::docName);
126
127 m_wndMapView.DeleteAllItems();
128 if (m_pRootObject == NULL)
129 {
130 pObject = NXCGetTopologyRootObject(g_hSession);
131 if (pObject != NULL)
132 AddObjectToView(pObject);
133
134 pObject = NXCGetServiceRootObject(g_hSession);
135 if (pObject != NULL)
136 AddObjectToView(pObject);
137
138 pObject = NXCGetTemplateRootObject(g_hSession);
139 if (pObject != NULL)
140 AddObjectToView(pObject);
141
142 // add object name to title
143 strTitle += " - [root]";
144 }
145 else
146 {
147 for(i = 0; i < m_pRootObject->dwNumChilds; i++)
148 {
149 pObject = NXCFindObjectById(g_hSession, m_pRootObject->pdwChildList[i]);
150 if (pObject != NULL)
151 if (!pObject->bIsDeleted)
152 AddObjectToView(pObject);
153 }
154
155 // add object name to title
156 strTitle += " - [";
157 strTitle += m_pRootObject->szName;
158 strTitle += "]";
159 }
160
161 ::SetWindowText(m_hWnd, strTitle);*/
162 }