source: trunk/MFCtooling/TestProg/TestProgView.cpp @ 431

Last change on this file since 431 was 32, checked in by sherbold, 14 years ago
File size: 7.2 KB
RevLine 
[32]1// TestProgView.cpp : implementation of the CTestProgView class
2//
3
4#include "stdafx.h"
5#include "TestProg.h"
6
7#include "TestProgDoc.h"
8#include "CntrItem.h"
9#include "TestProgView.h"
10
11#ifdef _DEBUG
12#define new DEBUG_NEW
13#endif
14
15
16// CTestProgView
17
18IMPLEMENT_DYNCREATE(CTestProgView, CView)
19
20BEGIN_MESSAGE_MAP(CTestProgView, CView)
21        ON_WM_DESTROY()
22        ON_WM_SETFOCUS()
23        ON_WM_SIZE()
24        ON_COMMAND(ID_OLE_INSERT_NEW, &CTestProgView::OnInsertObject)
25        ON_COMMAND(ID_CANCEL_EDIT_CNTR, &CTestProgView::OnCancelEditCntr)
26        ON_COMMAND(ID_FILE_PRINT, &CTestProgView::OnFilePrint)
27        ON_COMMAND(ID_CANCEL_EDIT_SRVR, &CTestProgView::OnCancelEditSrvr)
28        ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
29        ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
30END_MESSAGE_MAP()
31
32// CTestProgView construction/destruction
33
34CTestProgView::CTestProgView()
35{
36        m_pSelection = NULL;
37        // TODO: add construction code here
38
39}
40
41CTestProgView::~CTestProgView()
42{
43}
44
45BOOL CTestProgView::PreCreateWindow(CREATESTRUCT& cs)
46{
47        // TODO: Modify the Window class or styles here by modifying
48        //  the CREATESTRUCT cs
49
50        return CView::PreCreateWindow(cs);
51}
52
53// CTestProgView drawing
54
55void CTestProgView::OnDraw(CDC* pDC)
56{
57        if (!pDC)
58                return;
59
60        CTestProgDoc* pDoc = GetDocument();
61        ASSERT_VALID(pDoc);
62        if (!pDoc)
63                return;
64
65        // TODO: add draw code for native data here
66        // TODO: also draw all OLE items in the document
67
68        // Draw the selection at an arbitrary position.  This code should be
69        //  removed once your real drawing code is implemented.  This position
70        //  corresponds exactly to the rectangle returned by CTestProgCntrItem,
71        //  to give the effect of in-place editing.
72
73        // TODO: remove this code when final draw code is complete.
74        if (m_pSelection != NULL)
75        {
76                CSize size;
77                CRect rect(10, 10, 210, 210);
78               
79                if (m_pSelection->GetExtent(&size, m_pSelection->m_nDrawAspect))
80                {
81                        pDC->HIMETRICtoLP(&size);
82                        rect.right = size.cx + 10;
83                        rect.bottom = size.cy + 10;
84                }
85                m_pSelection->Draw(pDC, rect);
86        }
87}
88
89void CTestProgView::OnInitialUpdate()
90{
91        CView::OnInitialUpdate();
92
93
94        // TODO: remove this code when final selection model code is written
95        m_pSelection = NULL;    // initialize selection
96
97}
98
99
100// CTestProgView printing
101
102BOOL CTestProgView::OnPreparePrinting(CPrintInfo* pInfo)
103{
104        // default preparation
105        return DoPreparePrinting(pInfo);
106}
107
108void CTestProgView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
109{
110        // TODO: add extra initialization before printing
111}
112
113void CTestProgView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
114{
115        // TODO: add cleanup after printing
116}
117
118void CTestProgView::OnDestroy()
119{
120        // Deactivate the item on destruction; this is important
121        // when a splitter view is being used
122   COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
123   if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
124   {
125      pActiveItem->Deactivate();
126      ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
127   }
128   CView::OnDestroy();
129}
130
131
132
133// OLE Client support and commands
134
135BOOL CTestProgView::IsSelected(const CObject* pDocItem) const
136{
137        // The implementation below is adequate if your selection consists of
138        //  only CTestProgCntrItem objects.  To handle different selection
139        //  mechanisms, the implementation here should be replaced
140
141        // TODO: implement this function that tests for a selected OLE client item
142
143        return pDocItem == m_pSelection;
144}
145
146void CTestProgView::OnInsertObject()
147{
148        // Invoke the standard Insert Object dialog box to obtain information
149        //  for new CTestProgCntrItem object
150        COleInsertDialog dlg;
151        if (dlg.DoModal() != IDOK)
152                return;
153
154        BeginWaitCursor();
155
156        CTestProgCntrItem* pItem = NULL;
157        TRY
158        {
159                // Create new item connected to this document
160                CTestProgDoc* pDoc = GetDocument();
161                ASSERT_VALID(pDoc);
162                pItem = new CTestProgCntrItem(pDoc);
163                ASSERT_VALID(pItem);
164
165                // Initialize the item from the dialog data
166                if (!dlg.CreateItem(pItem))
167                        AfxThrowMemoryException();  // any exception will do
168                ASSERT_VALID(pItem);
169               
170        if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
171                        pItem->DoVerb(OLEIVERB_SHOW, this);
172
173                ASSERT_VALID(pItem);
174                // As an arbitrary user interface design, this sets the selection
175                //  to the last item inserted
176
177                // TODO: reimplement selection as appropriate for your application
178                m_pSelection = pItem;   // set selection to last inserted item
179                pDoc->UpdateAllViews(NULL);
180        }
181        CATCH(CException, e)
182        {
183                if (pItem != NULL)
184                {
185                        ASSERT_VALID(pItem);
186                        pItem->Delete();
187                }
188                AfxMessageBox(IDP_FAILED_TO_CREATE);
189        }
190        END_CATCH
191
192        EndWaitCursor();
193}
194
195// The following command handler provides the standard keyboard
196//  user interface to cancel an in-place editing session.  Here,
197//  the container (not the server) causes the deactivation
198void CTestProgView::OnCancelEditCntr()
199{
200        // Close any in-place active item on this view.
201        COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
202        if (pActiveItem != NULL)
203        {
204                pActiveItem->Close();
205        }
206        ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
207}
208
209// Special handling of OnSetFocus and OnSize are required for a container
210//  when an object is being edited in-place
211void CTestProgView::OnSetFocus(CWnd* pOldWnd)
212{
213        COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
214        if (pActiveItem != NULL &&
215                pActiveItem->GetItemState() == COleClientItem::activeUIState)
216        {
217                // need to set focus to this item if it is in the same view
218                CWnd* pWnd = pActiveItem->GetInPlaceWindow();
219                if (pWnd != NULL)
220                {
221                        pWnd->SetFocus();   // don't call the base class
222                        return;
223                }
224        }
225
226        CView::OnSetFocus(pOldWnd);
227}
228
229void CTestProgView::OnSize(UINT nType, int cx, int cy)
230{
231        CView::OnSize(nType, cx, cy);
232        COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
233        if (pActiveItem != NULL)
234                pActiveItem->SetItemRects();
235}
236
237void CTestProgView::OnFilePrint()
238{
239        //By default, we ask the Active document to print itself
240        //using IOleCommandTarget. If you don't want this behavior
241        //remove the call to COleDocObjectItem::DoDefaultPrinting.
242        //If the call fails for some reason, we will try printing
243        //the docobject using the IPrint interface.
244        CPrintInfo printInfo;
245        ASSERT(printInfo.m_pPD != NULL);
246        if (S_OK == COleDocObjectItem::DoDefaultPrinting(this, &printInfo))
247                return;
248       
249        CView::OnFilePrint();
250
251}
252
253
254
255// OLE Server support
256
257// The following command handler provides the standard keyboard
258//  user interface to cancel an in-place editing session.  Here,
259//  the server (not the container) causes the deactivation
260void CTestProgView::OnCancelEditSrvr()
261{
262        GetDocument()->OnDeactivateUI(FALSE);
263}
264
265
266// CTestProgView diagnostics
267
268#ifdef _DEBUG
269void CTestProgView::AssertValid() const
270{
271        CView::AssertValid();
272}
273
274void CTestProgView::Dump(CDumpContext& dc) const
275{
276        CView::Dump(dc);
277}
278
279CTestProgDoc* CTestProgView::GetDocument() const // non-debug version is inline
280{
281        ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestProgDoc)));
282        return (CTestProgDoc*)m_pDocument;
283}
284#endif //_DEBUG
285
286
287// CTestProgView message handlers
Note: See TracBrowser for help on using the repository browser.