author | Michael Krelin <hacker@klever.net> | 2004-07-05 01:53:09 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2004-07-05 01:53:09 (UTC) |
commit | fb8b43dbce8bc310718614384297aeaabb9a3cbb (patch) (unidiff) | |
tree | af9d2c2b71ddffff93a97a02fe26611096b78645 /MainFrm.cpp | |
download | bigbrother-fb8b43dbce8bc310718614384297aeaabb9a3cbb.zip bigbrother-fb8b43dbce8bc310718614384297aeaabb9a3cbb.tar.gz bigbrother-fb8b43dbce8bc310718614384297aeaabb9a3cbb.tar.bz2 |
initial commit into svn repository
git-svn-id: http://svn.klever.net/kin/bigbrother/trunk@1 fe716a7a-6dde-0310-88d9-d003556173a8
-rw-r--r-- | MainFrm.cpp | 299 |
1 files changed, 299 insertions, 0 deletions
diff --git a/MainFrm.cpp b/MainFrm.cpp new file mode 100644 index 0000000..97de7b2 --- a/dev/null +++ b/MainFrm.cpp | |||
@@ -0,0 +1,299 @@ | |||
1 | // MainFrm.cpp : implementation of the CMainFrame class | ||
2 | // | ||
3 | |||
4 | #include "stdafx.h" | ||
5 | #include "BigBrother.h" | ||
6 | |||
7 | #include "MainFrm.h" | ||
8 | #include "BigBrotherView.h" | ||
9 | #include "ActivityView.h" | ||
10 | #include "BigBrotherDoc.h" | ||
11 | #include "HostPropertyPages.h" | ||
12 | |||
13 | #ifdef _DEBUG | ||
14 | #define new DEBUG_NEW | ||
15 | #undef THIS_FILE | ||
16 | static char THIS_FILE[] = __FILE__; | ||
17 | #endif | ||
18 | |||
19 | ///////////////////////////////////////////////////////////////////////////// | ||
20 | // CMainFrame | ||
21 | |||
22 | IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) | ||
23 | |||
24 | BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) | ||
25 | //{{AFX_MSG_MAP(CMainFrame) | ||
26 | ON_WM_CREATE() | ||
27 | ON_WM_DESTROY() | ||
28 | ON_UPDATE_COMMAND_UI(ID_VIEW_MAINWINDOW, OnUpdateViewMainwindow) | ||
29 | ON_COMMAND(ID_VIEW_MAINWINDOW, OnViewMainwindow) | ||
30 | ON_WM_WINDOWPOSCHANGING() | ||
31 | ON_UPDATE_COMMAND_UI(ID_INDICATOR_PINGBAR, OnUpdateIndicatorPingbar) | ||
32 | ON_WM_CLOSE() | ||
33 | ON_MESSAGE(WM_TRAYICONMESSAGE, OnNotifyIcon) | ||
34 | ON_WM_QUERYENDSESSION() | ||
35 | //}}AFX_MSG_MAP | ||
36 | // Global help commands | ||
37 | ON_COMMAND(ID_HELP_FINDER, CFrameWnd::OnHelpFinder) | ||
38 | ON_COMMAND(ID_HELP, CFrameWnd::OnHelp) | ||
39 | ON_COMMAND(ID_CONTEXT_HELP, CFrameWnd::OnContextHelp) | ||
40 | ON_COMMAND(ID_DEFAULT_HELP, CFrameWnd::OnHelpFinder) | ||
41 | END_MESSAGE_MAP() | ||
42 | |||
43 | static UINT indicators[] = | ||
44 | { | ||
45 | ID_INDICATOR_PINGBAR, | ||
46 | ID_SEPARATOR // status line indicator | ||
47 | /*ID_INDICATOR_CAPS, | ||
48 | ID_INDICATOR_NUM, | ||
49 | ID_INDICATOR_SCRL*/ | ||
50 | }; | ||
51 | |||
52 | ///////////////////////////////////////////////////////////////////////////// | ||
53 | // CMainFrame construction/destruction | ||
54 | |||
55 | CMainFrame::CMainFrame() | ||
56 | { | ||
57 | m_bExiting=FALSE; | ||
58 | m_bShuttingDown=FALSE; | ||
59 | } | ||
60 | |||
61 | CMainFrame::~CMainFrame() | ||
62 | { | ||
63 | } | ||
64 | |||
65 | int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) | ||
66 | { | ||
67 | if (CFrameWnd::OnCreate(lpCreateStruct) == -1) | ||
68 | return -1; | ||
69 | |||
70 | if (!m_wndToolBar.Create(this) || | ||
71 | !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) | ||
72 | { | ||
73 | TRACE0("Failed to create toolbar\n"); | ||
74 | return -1; // fail to create | ||
75 | } | ||
76 | |||
77 | if (!m_wndStatusBar.Create(this,WS_CHILD | WS_VISIBLE | CBRS_BOTTOM|CBRS_SIZE_DYNAMIC) || | ||
78 | !m_wndStatusBar.SetIndicators(indicators, | ||
79 | sizeof(indicators)/sizeof(UINT))) | ||
80 | { | ||
81 | TRACE0("Failed to create status bar\n"); | ||
82 | return -1; // fail to create | ||
83 | } | ||
84 | m_wndStatusBar.SetPaneStyle(1,m_wndStatusBar.GetPaneStyle(1)|SBPS_STRETCH); | ||
85 | VERIFY(m_PingBar.Create(WS_CHILD|WS_VISIBLE|ACS_TRANSPARENT,CRect(0,0,0,0),&m_wndStatusBar,ID_INDICATOR_PINGBAR)); | ||
86 | m_PingBar.Open(IDR_PINGBAR); | ||
87 | CRect rc; | ||
88 | m_PingBar.GetWindowRect(rc); | ||
89 | int nHorz, nVert, nSpacing; | ||
90 | m_wndStatusBar.GetStatusBarCtrl().GetBorders(nHorz,nVert,nSpacing); | ||
91 | m_wndStatusBar.GetStatusBarCtrl().SetMinHeight(rc.Height()+nVert*2); | ||
92 | m_wndStatusBar.SetTheMinHeight(rc.Height()+nVert*2); | ||
93 | m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_PINGBAR),ID_INDICATOR_PINGBAR,SBPS_NORMAL,rc.Width()); | ||
94 | m_PingBar.SetWindowPos(NULL,nHorz+nSpacing+1,nVert+1,0,0,SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER); | ||
95 | |||
96 | m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | | ||
97 | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC); | ||
98 | |||
99 | m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); | ||
100 | EnableDocking(CBRS_ALIGN_ANY); | ||
101 | DockControlBar(&m_wndToolBar); | ||
102 | |||
103 | NOTIFYICONDATA nid; | ||
104 | memset(&nid,0,sizeof(nid)); | ||
105 | nid.cbSize=sizeof(nid); | ||
106 | nid.hWnd=m_hWnd; | ||
107 | nid.uID=IDC_TRAYICON; | ||
108 | nid.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP; | ||
109 | nid.uCallbackMessage=WM_TRAYICONMESSAGE; | ||
110 | nid.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME); | ||
111 | // *** Load from resource | ||
112 | strcpy(nid.szTip,"Big Brother"); | ||
113 | VERIFY(Shell_NotifyIcon(NIM_ADD,&nid)); | ||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/, | ||
118 | CCreateContext* pContext) | ||
119 | { | ||
120 | if(!m_wndSplitter.CreateStatic(this,2,1)){ | ||
121 | TRACE0("Failed to create static splitter\n"); | ||
122 | return FALSE; | ||
123 | } | ||
124 | CRect rc; | ||
125 | GetClientRect(rc); | ||
126 | int cySize = AfxGetApp()->GetProfileInt("SplitterPosition","TreeSize",-1); | ||
127 | if(!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CBigBrotherView),CSize(0,(cySize<0)?(rc.Height()/2):cySize),pContext)){ | ||
128 | TRACE0("Failed to create Tree View\n"); | ||
129 | return FALSE; | ||
130 | } | ||
131 | cySize = AfxGetApp()->GetProfileInt("SplitterPosition","ActivitySize",-1); | ||
132 | if(!m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(CActivityView),CSize(0,(cySize<0)?(rc.Height()/2):cySize),pContext)){ | ||
133 | TRACE0("Failed to create Activity View\n"); | ||
134 | return FALSE; | ||
135 | } | ||
136 | return TRUE; | ||
137 | } | ||
138 | |||
139 | BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) | ||
140 | { | ||
141 | CRect rc; | ||
142 | CWinApp *app = AfxGetApp(); | ||
143 | rc.left=app->GetProfileInt("FramePosition","left",-1); | ||
144 | rc.top=app->GetProfileInt("FramePosition","top",-1); | ||
145 | rc.right=app->GetProfileInt("FramePosition","right",-1); | ||
146 | rc.bottom=app->GetProfileInt("FramePosition","bottom",-1); | ||
147 | if(rc.left>=0 && rc.top>=0 && rc.right>=0 && rc.bottom>=0){ | ||
148 | cs.x=rc.left, cs.y=rc.top; | ||
149 | cs.cx=rc.Width(), cs.cy=rc.Height(); | ||
150 | } | ||
151 | inttmp = app->GetProfileInt("FramePosition","shown",-1); | ||
152 | if(!tmp){ | ||
153 | cs.style&=~WS_VISIBLE; | ||
154 | m_bShown=FALSE; | ||
155 | }else | ||
156 | m_bShown=TRUE; | ||
157 | cs.style&=~WS_MINIMIZEBOX|WS_MAXIMIZEBOX; | ||
158 | return CFrameWnd::PreCreateWindow(cs); | ||
159 | } | ||
160 | |||
161 | ///////////////////////////////////////////////////////////////////////////// | ||
162 | // CMainFrame diagnostics | ||
163 | |||
164 | #ifdef _DEBUG | ||
165 | void CMainFrame::AssertValid() const | ||
166 | { | ||
167 | CFrameWnd::AssertValid(); | ||
168 | } | ||
169 | |||
170 | void CMainFrame::Dump(CDumpContext& dc) const | ||
171 | { | ||
172 | CFrameWnd::Dump(dc); | ||
173 | } | ||
174 | |||
175 | #endif //_DEBUG | ||
176 | |||
177 | ///////////////////////////////////////////////////////////////////////////// | ||
178 | // CMainFrame message handlers | ||
179 | |||
180 | void CMainFrame::OnDestroy() | ||
181 | { | ||
182 | CFrameWnd::OnDestroy(); | ||
183 | |||
184 | m_bExiting=TRUE; | ||
185 | |||
186 | // Save window size and position | ||
187 | CRect rc; | ||
188 | GetWindowRect(rc); | ||
189 | CWinApp *app = AfxGetApp(); | ||
190 | app->WriteProfileInt("FramePosition","left",rc.left); | ||
191 | app->WriteProfileInt("FramePosition","top",rc.top); | ||
192 | app->WriteProfileInt("FramePosition","right",rc.right); | ||
193 | app->WriteProfileInt("FramePosition","bottom",rc.bottom); | ||
194 | int cyCur,cyMin; | ||
195 | m_wndSplitter.GetRowInfo(0,cyCur,cyMin); | ||
196 | app->WriteProfileInt("SplitterPosition","TreeSize",cyCur); | ||
197 | m_wndSplitter.GetRowInfo(1,cyCur,cyMin); | ||
198 | app->WriteProfileInt("SplitterPosition","ActivitySize",cyCur); | ||
199 | app->WriteProfileInt("FramePosition","shown",m_bShown); | ||
200 | |||
201 | NOTIFYICONDATA nid; | ||
202 | memset(&nid,0,sizeof(nid)); | ||
203 | nid.cbSize=sizeof(nid); | ||
204 | nid.hWnd=m_hWnd; | ||
205 | nid.uID=IDC_TRAYICON; | ||
206 | nid.uFlags=0; | ||
207 | VERIFY(Shell_NotifyIcon(NIM_DELETE,&nid)); | ||
208 | } | ||
209 | |||
210 | LRESULT CMainFrame::OnNotifyIcon(WPARAM wP,LPARAM lP) | ||
211 | { | ||
212 | ASSERT(wP==IDC_TRAYICON); | ||
213 | switch(lP){ | ||
214 | case WM_LBUTTONDOWN: | ||
215 | OnViewMainwindow(); | ||
216 | break; | ||
217 | case WM_RBUTTONDOWN: | ||
218 | { | ||
219 | CMenu menu; | ||
220 | VERIFY(menu.LoadMenu(IDM_POPUPS)); | ||
221 | CMenu *popUp = menu.GetSubMenu(0); | ||
222 | ASSERT(popUp); | ||
223 | CPoint pt; | ||
224 | VERIFY(::GetCursorPos(&pt)); | ||
225 | popUp->TrackPopupMenu(TPM_RIGHTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON,pt.x,pt.y,this,NULL); | ||
226 | } | ||
227 | break; | ||
228 | default: | ||
229 | /* { | ||
230 | CString tmp; | ||
231 | tmp.Format("NIMESSAGE: %08lX\n",lP); | ||
232 | TRACE0(tmp); | ||
233 | }*/ | ||
234 | break; | ||
235 | } | ||
236 | return 0; | ||
237 | } | ||
238 | |||
239 | void CMainFrame::FrameDisplayState(BOOL bShow) | ||
240 | { | ||
241 | m_bShown=bShow; | ||
242 | ShowWindow(bShow?SW_SHOW:SW_HIDE); | ||
243 | CBigBrotherDoc *doc = (CBigBrotherDoc*)GetActiveDocument(); | ||
244 | if(doc){ | ||
245 | ASSERT(doc->IsKindOf(RUNTIME_CLASS(CBigBrotherDoc))); | ||
246 | ASSERT(doc->m_BBView); | ||
247 | ASSERT(doc->m_BBView->m_Pages); | ||
248 | ASSERT(::IsWindow(doc->m_BBView->m_Pages->m_hWnd)); | ||
249 | doc->m_BBView->m_Pages->ShowWindow(bShow?SW_SHOW:SW_HIDE); | ||
250 | } | ||
251 | if(bShow){ | ||
252 | SetForegroundWindow(); | ||
253 | SetFocus(); | ||
254 | } | ||
255 | } | ||
256 | |||
257 | void CMainFrame::OnUpdateViewMainwindow(CCmdUI* pCmdUI) | ||
258 | { | ||
259 | pCmdUI->SetCheck(IsWindowVisible()?1:0); | ||
260 | } | ||
261 | |||
262 | void CMainFrame::OnViewMainwindow() | ||
263 | { | ||
264 | FrameDisplayState(!IsWindowVisible()); | ||
265 | } | ||
266 | |||
267 | void CMainFrame::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) | ||
268 | { | ||
269 | if(!m_bExiting){ | ||
270 | if(m_bShown){ | ||
271 | lpwndpos->flags&=~SWP_HIDEWINDOW; | ||
272 | lpwndpos->flags|=SWP_SHOWWINDOW; | ||
273 | }else{ | ||
274 | lpwndpos->flags&=~SWP_SHOWWINDOW; | ||
275 | lpwndpos->flags|=SWP_HIDEWINDOW; | ||
276 | } | ||
277 | } | ||
278 | CFrameWnd::OnWindowPosChanging(lpwndpos); | ||
279 | } | ||
280 | |||
281 | void CMainFrame::OnUpdateIndicatorPingbar(CCmdUI* pCmdUI) | ||
282 | { | ||
283 | pCmdUI->Enable(TRUE); | ||
284 | } | ||
285 | |||
286 | void CMainFrame::OnClose() | ||
287 | { | ||
288 | m_bExiting=TRUE; | ||
289 | CFrameWnd::OnClose(); | ||
290 | } | ||
291 | |||
292 | BOOL CMainFrame::OnQueryEndSession() | ||
293 | { | ||
294 | m_bShuttingDown=TRUE; | ||
295 | if (!CFrameWnd::OnQueryEndSession()) | ||
296 | return FALSE; | ||
297 | ::PostQuitMessage(0); | ||
298 | return TRUE; | ||
299 | } | ||