0c3e6bcee7e84a67d11454cb0f66adbd74d4068c
[public/netxms.git] / src / console / win32 / MainFrm.cpp
1 // MainFrm.cpp : implementation of the CMainFrame class
2 //
3
4 #include "stdafx.h"
5 #include "nxcon.h"
6
7 #include "MainFrm.h"
8
9 #ifdef _DEBUG
10 #define new DEBUG_NEW
11 #undef THIS_FILE
12 static char THIS_FILE[] = __FILE__;
13 #endif
14
15 /////////////////////////////////////////////////////////////////////////////
16 // CMainFrame
17
18 IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
19
20 BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
21 //{{AFX_MSG_MAP(CMainFrame)
22 ON_WM_CREATE()
23 ON_WM_DESTROY()
24 ON_COMMAND(ID_UPDATE_EVENT_LIST, OnUpdateEventList)
25 ON_WM_CLOSE()
26 //}}AFX_MSG_MAP
27 // ON_UPDATE_COMMAND_UI(ID_INDICATOR_CONNECT, OnUpdateConnState)
28 ON_MESSAGE(WM_OBJECT_CHANGE, OnObjectChange)
29 ON_MESSAGE(WM_USERDB_CHANGE, OnUserDBChange)
30 ON_MESSAGE(WM_STATE_CHANGE, OnStateChange)
31 ON_MESSAGE(WM_ALARM_UPDATE, OnAlarmUpdate)
32 END_MESSAGE_MAP()
33
34 static UINT indicators[] =
35 {
36 ID_SEPARATOR,
37 ID_INDICATOR_CONNECT,
38 ID_INDICATOR_CAPS,
39 ID_INDICATOR_NUM,
40 ID_INDICATOR_SCRL
41 };
42
43
44 //
45 // CMainFrame construction/destruction
46 //
47
48 CMainFrame::CMainFrame()
49 {
50 }
51
52 CMainFrame::~CMainFrame()
53 {
54 }
55
56
57 //
58 // Handler for WM_CREATE message
59 //
60
61 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
62 {
63 if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
64 return -1;
65
66 if (!m_wndToolBar.CreateEx(this) ||
67 !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
68 {
69 TRACE0("Failed to create toolbar\n");
70 return -1; // fail to create
71 }
72
73 if (!m_wndReBar.Create(this) ||
74 !m_wndReBar.AddBar(&m_wndToolBar))
75 {
76 TRACE0("Failed to create rebar\n");
77 return -1; // fail to create
78 }
79
80 if (!m_wndStatusBar.Create(this) ||
81 !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT)))
82 {
83 TRACE0("Failed to create status bar\n");
84 return -1; // fail to create
85 }
86
87 m_wndStatusBar.GetStatusBarCtrl().SetIcon(1, NULL);
88 m_wndStatusBar.GetStatusBarCtrl().SetText("", 1, 0);
89
90 // TODO: Remove this if you don't want tool tips
91 m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
92 CBRS_TOOLTIPS | CBRS_FLYBY);
93
94 return 0;
95 }
96
97 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
98 {
99 if( !CMDIFrameWnd::PreCreateWindow(cs) )
100 return FALSE;
101 // TODO: Modify the Window class or styles here by modifying
102 // the CREATESTRUCT cs
103
104 return TRUE;
105 }
106
107 /////////////////////////////////////////////////////////////////////////////
108 // CMainFrame diagnostics
109
110 #ifdef _DEBUG
111 void CMainFrame::AssertValid() const
112 {
113 CMDIFrameWnd::AssertValid();
114 }
115
116 void CMainFrame::Dump(CDumpContext& dc) const
117 {
118 CMDIFrameWnd::Dump(dc);
119 }
120
121 #endif //_DEBUG
122
123 /////////////////////////////////////////////////////////////////////////////
124 // CMainFrame message handlers
125
126
127 void CMainFrame::OnDestroy()
128 {
129 CMDIFrameWnd::OnDestroy();
130 }
131
132
133 //
134 // Broadcast message to all MDI child windows
135 //
136
137 void CMainFrame::BroadcastMessage(UINT msg, WPARAM wParam, LPARAM lParam, BOOL bUsePost)
138 {
139 CWnd *pWnd;
140
141 pWnd = MDIGetActive();
142 while(pWnd != NULL)
143 {
144 if (bUsePost)
145 pWnd->PostMessage(msg, wParam, lParam);
146 else
147 pWnd->SendMessage(msg, wParam, lParam);
148
149 // If pWnd still exist, call GetNextWindow()
150 if (IsWindow(pWnd->m_hWnd))
151 pWnd = pWnd->GetNextWindow();
152 else
153 pWnd = MDIGetActive();
154 }
155 theApp.DebugPrintf("CMainFrame::BroadcastMessage(%d, %d, %d)", msg, wParam, lParam);
156 }
157
158
159 //
160 // Handler for WM_OBJECT_CHANGE message
161 //
162
163 void CMainFrame::OnObjectChange(WPARAM wParam, LPARAM lParam)
164 {
165 BroadcastMessage(WM_OBJECT_CHANGE, wParam, lParam, TRUE);
166 }
167
168
169 //
170 // Handler for WM_USERDB_CHANGE message
171 //
172
173 void CMainFrame::OnUserDBChange(WPARAM wParam, LPARAM lParam)
174 {
175 BroadcastMessage(WM_USERDB_CHANGE, wParam, lParam, TRUE);
176 }
177
178
179 //
180 // WM_COMMAND::ID_UPDATE_EVENT_LIST message handler
181 //
182
183 void CMainFrame::OnUpdateEventList(void)
184 {
185 DoRequest(NXCLoadEventDB, "Reloading event information...");
186 }
187
188
189 //
190 // Handler for WM_STATE_CHANGE message
191 //
192
193 void CMainFrame::OnStateChange(WPARAM wParam, LPARAM lParam)
194 {
195 if (wParam == STATE_CONNECTED)
196 {
197 m_wndStatusBar.GetStatusBarCtrl().SetIcon(1,
198 (HICON)LoadImage(theApp.m_hInstance, MAKEINTRESOURCE(IDI_CONNECT),
199 IMAGE_ICON, 16, 16, LR_SHARED));
200 m_wndStatusBar.GetStatusBarCtrl().SetText(g_szServer, 1, 0);
201 }
202 else
203 {
204 m_wndStatusBar.GetStatusBarCtrl().SetIcon(1, NULL);
205 m_wndStatusBar.GetStatusBarCtrl().SetText("", 1, 0);
206 }
207 }
208
209
210 //
211 // WM_ALARM_UPDATE message handler
212 //
213
214 void CMainFrame::OnAlarmUpdate(WPARAM wParam, LPARAM lParam)
215 {
216 CAlarmBrowser *pWnd;
217
218 pWnd = theApp.GetAlarmBrowser();
219 if (pWnd != NULL)
220 pWnd->OnAlarmUpdate(wParam, (NXC_ALARM *)lParam);
221 free((void *)lParam);
222 }
223
224
225 //
226 // WM_CLOSE message handler
227 //
228
229 void CMainFrame::OnClose()
230 {
231 WINDOWPLACEMENT wndPlacement;
232
233 // Save window placement
234 GetWindowPlacement(&wndPlacement);
235 AfxGetApp()->WriteProfileBinary(_T("General"), _T("WindowPlacement"),
236 (BYTE *)&wndPlacement, sizeof(WINDOWPLACEMENT));
237
238 // Send WM_CLOSE to all active MDI windows
239 BroadcastMessage(WM_CLOSE, 0, 0, FALSE);
240
241 CMDIFrameWnd::OnClose();
242 }
243
244
245 //
246 // Overrided frame window title update
247 //
248
249 void CMainFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
250 {
251 CMDIChildWnd *pActiveChild = NULL;
252
253 if (!bAddToTitle)
254 {
255 CMDIFrameWnd::OnUpdateFrameTitle(FALSE);
256 }
257 else
258 {
259 pActiveChild = MDIGetActive();
260 if (pActiveChild != NULL)
261 {
262 if (pActiveChild->GetStyle() & WS_MAXIMIZE)
263 {
264 CMDIFrameWnd::OnUpdateFrameTitle(FALSE);
265 }
266 else
267 {
268 UpdateFrameTitleForDocument(pActiveChild->GetTitle());
269 }
270 }
271 else
272 {
273 CMDIFrameWnd::OnUpdateFrameTitle(FALSE);
274 }
275 }
276 }