source: trunk/ChildFrame.cpp @ 3

Revision 3, 7.7 KB checked in by lowjoel, 7 years ago (diff)

Added the source files from root (SVN migration commit 1)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1// ChildFrame.cpp
2//
3// Eraser. Secure data removal. For Windows.
4// Copyright © 1997-2001  Sami Tolvanen (sami@tolvanen.com).
5//
6// This program is free software; you can redistribute it and/or
7// modify it under the terms of the GNU General Public License
8// as published by the Free Software Foundation; either version 2
9// of the License, or (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19// 02111-1307, USA.
20
21#include "stdafx.h"
22#include "Eraser.h"
23
24#include "EraserDoc.h"
25#include "EraserView.h"
26#include "SchedulerView.h"
27#include "ChildFrame.h"
28
29#ifdef _DEBUG
30#define new DEBUG_NEW
31#undef THIS_FILE
32static char THIS_FILE[] = __FILE__;
33#endif
34
35/////////////////////////////////////////////////////////////////////////////
36// CChildFrame
37
38IMPLEMENT_DYNCREATE(CChildFrame, CFrameWnd)
39
40CChildFrame::CChildFrame() :
41m_iActiveViewID(-1),
42m_pEraserView(0),
43m_pSchedulerView(0),
44m_pExplorerView(0)
45{
46    TRACE("CChildFrame::CChildFrame\n");
47    m_nIDHelp = IDR_CHILDFRAME;
48}
49
50CChildFrame::~CChildFrame()
51{
52    TRACE("CChildFrame::~CChildFrame\n");
53}
54
55
56BEGIN_MESSAGE_MAP(CChildFrame, CFrameWnd)
57    //{{AFX_MSG_MAP(CChildFrame)
58    ON_WM_CREATE()
59    ON_WM_ERASEBKGND()
60    ON_WM_DESTROY()
61    //}}AFX_MSG_MAP
62END_MESSAGE_MAP()
63
64/////////////////////////////////////////////////////////////////////////////
65// CChildFrame message handlers
66
67void CChildFrame::SwitchToForm(int nForm)
68{
69    TRACE("CChildFrame::SwitchToForm\n");
70
71    if (nForm == m_iActiveViewID)
72        return;
73
74    try
75    {
76        CFrameWnd   *pwndMain       = static_cast<CFrameWnd*>(AfxGetMainWnd());
77        CView       *pOldActiveView = 0;
78        CView       *pNewActiveView = 0;
79
80        switch (m_iActiveViewID)
81        {
82        case VIEW_ERASER:
83        default:
84            pOldActiveView = static_cast<CView*>(m_pEraserView);
85            break;
86        case VIEW_SCHEDULER:
87            pOldActiveView = static_cast<CView*>(m_pSchedulerView);
88            break;
89        case VIEW_EXPLORER:
90            pOldActiveView = static_cast<CView*>(m_pExplorerView);
91            break;
92        }
93
94        switch (nForm)
95        {
96        case VIEW_ERASER:
97        default:
98            pNewActiveView = static_cast<CView*>(m_pEraserView);
99            m_nIDHelp = IDR_MENU_ERASERVIEW;
100            break;
101        case VIEW_SCHEDULER:
102            pNewActiveView = static_cast<CView*>(m_pSchedulerView);
103            m_nIDHelp = IDR_MENU_SCHEDULERVIEW;
104            break;
105        case VIEW_EXPLORER:
106            pNewActiveView = static_cast<CView*>(m_pExplorerView);
107            m_nIDHelp = IDR_ERASEREXPLORER;
108            break;
109        }
110
111        SetActiveView(pNewActiveView);
112
113        // set as the main frame's active view to enable message
114        // routing
115
116        if (pwndMain) pwndMain->SetActiveView(pNewActiveView);
117
118        pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
119        if (pOldActiveView) pOldActiveView->SetDlgCtrlID(m_iActiveViewID);
120
121        RecalcLayout();
122
123        pNewActiveView->ShowWindow(SW_SHOW);
124        if (pOldActiveView) pOldActiveView->ShowWindow(SW_HIDE);
125
126        m_iActiveViewID = nForm;
127    }
128    catch (CException *e)
129    {
130        ASSERT(FALSE);
131        REPORT_ERROR(e);
132        e->Delete();
133    }
134}
135
136int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
137{
138    TRACE("CChildFrame::OnCreate\n");
139
140    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
141        return -1;
142
143    m_InfoBar.Create(NULL, NULL, WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | CBRS_TOP,
144                     CRect(0,0,0,0), this, IDW_INFO_BAR);
145
146    m_InfoBar.SetBarStyle(CBRS_ALIGN_TOP);
147    m_InfoBar.SetTextFont("Tahoma");
148
149    ModifyStyleEx(WS_EX_CLIENTEDGE, 0);
150
151    return 0;
152}
153
154BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
155{
156    TRACE("CChildFrame::PreCreateWindow\n");
157    cs.dwExStyle |= WS_EX_STATICEDGE;
158
159    return CFrameWnd::PreCreateWindow(cs);
160}
161
162BOOL CChildFrame::OnEraseBkgnd(CDC* /*pDC*/)
163{
164    return FALSE;
165}
166
167void CChildFrame::OnDestroy()
168{
169    TRACE("CChildFrame::OnDestroy\n");
170
171    try
172    {
173        // set view to null because we will take care
174        // of our views all by ourselves
175
176        SetActiveView(NULL, FALSE);
177
178        // do the same for the main window
179        CFrameWnd *pWnd = static_cast<CFrameWnd*>(AfxGetMainWnd());
180
181        if (AfxIsValidAddress(pWnd, sizeof(CFrameWnd)))
182            pWnd->SetActiveView(NULL, FALSE);
183
184        // now destroy the views
185        if (AfxIsValidAddress(m_pEraserView, sizeof(CEraserView)))
186            m_pEraserView->DestroyWindow();
187        if (AfxIsValidAddress(m_pSchedulerView, sizeof(CSchedulerView)))
188            m_pSchedulerView->DestroyWindow();
189        if (AfxIsValidAddress(m_pExplorerView, sizeof(CShellListView)))
190            m_pExplorerView->DestroyWindow();
191
192        CFrameWnd::OnDestroy();
193    }
194    catch (CException *e)
195    {
196        ASSERT(FALSE);
197        REPORT_ERROR(e);
198        e->Delete();
199    }
200}
201
202
203
204BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
205{
206    TRACE("CChildFrame::OnCreateClient\n");
207
208    if (CFrameWnd::OnCreateClient(lpcs, pContext))
209    {
210        CEraserDoc *pDoc = static_cast<CEraserDoc*>(pContext->m_pCurrentDoc);
211        ASSERT(AfxIsValidAddress(pDoc, sizeof(CEraserDoc)));
212
213        try
214        {
215            // create CEraserView
216
217            m_pEraserView = new CEraserView();
218            m_pEraserView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
219                                  CFrameWnd::rectDefault, this, VIEW_ERASER, pContext);
220
221            // create CSchedulerView
222
223            m_pSchedulerView = new CSchedulerView();
224            m_pSchedulerView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
225                                     CFrameWnd::rectDefault, this, VIEW_SCHEDULER, pContext);
226
227            // create CShellListView
228
229            m_pExplorerView = new CShellListView();
230            m_pExplorerView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
231                                    CFrameWnd::rectDefault, this, VIEW_EXPLORER, pContext);
232
233            // set active view
234
235            CView *pActiveView      = 0;
236            CView *pInactiveView    = 0;
237            int iInactiveViewID     = 0;
238
239            if (pDoc->m_dwStartView == VIEW_SCHEDULER)
240            {
241                pActiveView     = m_pSchedulerView;
242                pInactiveView   = m_pEraserView;
243
244                m_iActiveViewID = VIEW_SCHEDULER;
245                iInactiveViewID = VIEW_ERASER;
246
247                m_nIDHelp       = IDR_MENU_SCHEDULERVIEW;
248            }
249            else
250            {
251                pActiveView     = m_pEraserView;
252                pInactiveView   = m_pSchedulerView;
253
254                m_iActiveViewID = VIEW_ERASER;
255                iInactiveViewID = VIEW_SCHEDULER;
256
257                m_nIDHelp       = IDR_MENU_ERASERVIEW;
258            }
259
260            SetActiveView(pActiveView);
261
262            pActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
263            pInactiveView->SetDlgCtrlID(iInactiveViewID);
264            m_pExplorerView->SetDlgCtrlID(VIEW_EXPLORER);
265
266            RecalcLayout();
267
268            pActiveView->ShowWindow(SW_SHOW);
269            pInactiveView->ShowWindow(SW_HIDE);
270            m_pExplorerView->ShowWindow(SW_HIDE);
271
272            return TRUE;
273        }
274        catch (CException *e)
275        {
276            ASSERT(FALSE);
277            REPORT_ERROR(e);
278
279            try
280            {
281                pDoc->LogException(e);
282            }
283            catch (...)
284            {
285            }
286
287            e->Delete();
288        }
289    }
290
291    return FALSE;
292}
Note: See TracBrowser for help on using the repository browser.