Alientech 0.01
An extendable game engine
C:/Alientech/AlienPlanets/AlienPlanetsView.cpp
Go to the documentation of this file.
00001 
00002 // AlienPlanetsView.cpp : implementation of the CAlienPlanetsView class
00003 //
00004 
00005 #include "stdafx.h"
00006 // SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
00007 // and search filter handlers and allows sharing of document code with that project.
00008 #ifndef SHARED_HANDLERS
00009 #include "AlienPlanets.h"
00010 #endif
00011 
00012 #include "AlienPlanetsDoc.h"
00013 #include "CntrItem.h"
00014 #include "resource.h"
00015 #include "AlienPlanetsView.h"
00016 
00017 #ifdef _DEBUG
00018 #define new DEBUG_NEW
00019 #endif
00020 
00021 
00022 // CAlienPlanetsView
00023 
00024 IMPLEMENT_DYNCREATE(CAlienPlanetsView, CView)
00025 
00026 BEGIN_MESSAGE_MAP(CAlienPlanetsView, CView)
00027         ON_WM_DESTROY()
00028         ON_WM_SETFOCUS()
00029         ON_WM_SIZE()
00030         ON_COMMAND(ID_OLE_INSERT_NEW, &CAlienPlanetsView::OnInsertObject)
00031         ON_COMMAND(ID_CANCEL_EDIT_CNTR, &CAlienPlanetsView::OnCancelEditCntr)
00032         ON_COMMAND(ID_FILE_PRINT, &CAlienPlanetsView::OnFilePrint)
00033         ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
00034         ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CAlienPlanetsView::OnFilePrintPreview)
00035         ON_WM_CONTEXTMENU()
00036         ON_WM_RBUTTONUP()
00037 END_MESSAGE_MAP()
00038 
00039 // CAlienPlanetsView construction/destruction
00040 
00041 CAlienPlanetsView::CAlienPlanetsView()
00042 {
00043         m_pSelection = NULL;
00044         // TODO: add construction code here
00045 
00046 }
00047 
00048 CAlienPlanetsView::~CAlienPlanetsView()
00049 {
00050 }
00051 
00052 BOOL CAlienPlanetsView::PreCreateWindow(CREATESTRUCT& cs)
00053 {
00054         // TODO: Modify the Window class or styles here by modifying
00055         //  the CREATESTRUCT cs
00056 
00057         return CView::PreCreateWindow(cs);
00058 }
00059 
00060 // CAlienPlanetsView drawing
00061 
00062 void CAlienPlanetsView::OnDraw(CDC* pDC)
00063 {
00064         if (!pDC)
00065                 return;
00066 
00067         CAlienPlanetsDoc* pDoc = GetDocument();
00068         ASSERT_VALID(pDoc);
00069         if (!pDoc)
00070                 return;
00071 
00072         // TODO: add draw code for native data here
00073         // TODO: also draw all OLE items in the document
00074 
00075         // Draw the selection at an arbitrary position.  This code should be
00076         //  removed once your real drawing code is implemented.  This position
00077         //  corresponds exactly to the rectangle returned by CAlienPlanetsCntrItem,
00078         //  to give the effect of in-place editing.
00079 
00080         // TODO: remove this code when final draw code is complete.
00081         if (m_pSelection != NULL)
00082         {
00083                 CSize size;
00084                 CRect rect(10, 10, 210, 210);
00085                 
00086                 if (m_pSelection->GetExtent(&size, m_pSelection->m_nDrawAspect))
00087                 {
00088                         pDC->HIMETRICtoLP(&size);
00089                         rect.right = size.cx + 10;
00090                         rect.bottom = size.cy + 10;
00091                 }
00092                 m_pSelection->Draw(pDC, rect);
00093         }
00094 }
00095 
00096 void CAlienPlanetsView::OnInitialUpdate()
00097 {
00098         CView::OnInitialUpdate();
00099 
00100 
00101         // TODO: remove this code when final selection model code is written
00102         m_pSelection = NULL;    // initialize selection
00103 
00104 }
00105 
00106 
00107 // CAlienPlanetsView printing
00108 
00109 
00110 void CAlienPlanetsView::OnFilePrintPreview()
00111 {
00112 #ifndef SHARED_HANDLERS
00113         AFXPrintPreview(this);
00114 #endif
00115 }
00116 
00117 BOOL CAlienPlanetsView::OnPreparePrinting(CPrintInfo* pInfo)
00118 {
00119         // default preparation
00120         return DoPreparePrinting(pInfo);
00121 }
00122 
00123 void CAlienPlanetsView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
00124 {
00125         // TODO: add extra initialization before printing
00126 }
00127 
00128 void CAlienPlanetsView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
00129 {
00130         // TODO: add cleanup after printing
00131 }
00132 
00133 void CAlienPlanetsView::OnDestroy()
00134 {
00135         // Deactivate the item on destruction; this is important
00136         // when a splitter view is being used
00137    COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
00138    if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
00139    {
00140       pActiveItem->Deactivate();
00141       ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
00142    }
00143    CView::OnDestroy();
00144 }
00145 
00146 
00147 
00148 // OLE Client support and commands
00149 
00150 BOOL CAlienPlanetsView::IsSelected(const CObject* pDocItem) const
00151 {
00152         // The implementation below is adequate if your selection consists of
00153         //  only CAlienPlanetsCntrItem objects.  To handle different selection
00154         //  mechanisms, the implementation here should be replaced
00155 
00156         // TODO: implement this function that tests for a selected OLE client item
00157 
00158         return pDocItem == m_pSelection;
00159 }
00160 
00161 void CAlienPlanetsView::OnInsertObject()
00162 {
00163         // Invoke the standard Insert Object dialog box to obtain information
00164         //  for new CAlienPlanetsCntrItem object
00165         COleInsertDialog dlg;
00166         if (dlg.DoModal() != IDOK)
00167                 return;
00168 
00169         BeginWaitCursor();
00170 
00171         CAlienPlanetsCntrItem* pItem = NULL;
00172         TRY
00173         {
00174                 // Create new item connected to this document
00175                 CAlienPlanetsDoc* pDoc = GetDocument();
00176                 ASSERT_VALID(pDoc);
00177                 pItem = new CAlienPlanetsCntrItem(pDoc);
00178                 ASSERT_VALID(pItem);
00179 
00180                 // Initialize the item from the dialog data
00181                 if (!dlg.CreateItem(pItem))
00182                         AfxThrowMemoryException();  // any exception will do
00183                 ASSERT_VALID(pItem);
00184                 
00185         if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
00186                         pItem->DoVerb(OLEIVERB_SHOW, this);
00187 
00188                 ASSERT_VALID(pItem);
00189                 // As an arbitrary user interface design, this sets the selection
00190                 //  to the last item inserted
00191 
00192                 // TODO: reimplement selection as appropriate for your application
00193                 m_pSelection = pItem;   // set selection to last inserted item
00194                 pDoc->UpdateAllViews(NULL);
00195         }
00196         CATCH(CException, e)
00197         {
00198                 if (pItem != NULL)
00199                 {
00200                         ASSERT_VALID(pItem);
00201                         pItem->Delete();
00202                 }
00203                 AfxMessageBox(IDP_FAILED_TO_CREATE);
00204         }
00205         END_CATCH
00206 
00207         EndWaitCursor();
00208 }
00209 
00210 // The following command handler provides the standard keyboard
00211 //  user interface to cancel an in-place editing session.  Here,
00212 //  the container (not the server) causes the deactivation
00213 void CAlienPlanetsView::OnCancelEditCntr()
00214 {
00215         // Close any in-place active item on this view.
00216         COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
00217         if (pActiveItem != NULL)
00218         {
00219                 pActiveItem->Close();
00220         }
00221         ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
00222 }
00223 
00224 // Special handling of OnSetFocus and OnSize are required for a container
00225 //  when an object is being edited in-place
00226 void CAlienPlanetsView::OnSetFocus(CWnd* pOldWnd)
00227 {
00228         COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
00229         if (pActiveItem != NULL &&
00230                 pActiveItem->GetItemState() == COleClientItem::activeUIState)
00231         {
00232                 // need to set focus to this item if it is in the same view
00233                 CWnd* pWnd = pActiveItem->GetInPlaceWindow();
00234                 if (pWnd != NULL)
00235                 {
00236                         pWnd->SetFocus();   // don't call the base class
00237                         return;
00238                 }
00239         }
00240 
00241         CView::OnSetFocus(pOldWnd);
00242 }
00243 
00244 void CAlienPlanetsView::OnSize(UINT nType, int cx, int cy)
00245 {
00246         CView::OnSize(nType, cx, cy);
00247         COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
00248         if (pActiveItem != NULL)
00249                 pActiveItem->SetItemRects();
00250 }
00251 
00252 void CAlienPlanetsView::OnFilePrint()
00253 {
00254         //By default, we ask the Active document to print itself
00255         //using IOleCommandTarget. If you don't want this behavior
00256         //remove the call to COleDocObjectItem::DoDefaultPrinting.
00257         //If the call fails for some reason, we will try printing
00258         //the docobject using the IPrint interface.
00259         CPrintInfo printInfo;
00260         ASSERT(printInfo.m_pPD != NULL); 
00261         if (S_OK == COleDocObjectItem::DoDefaultPrinting(this, &printInfo))
00262                 return;
00263         
00264         CView::OnFilePrint();
00265 
00266 }
00267 
00268 
00269 void CAlienPlanetsView::OnRButtonUp(UINT /* nFlags */, CPoint point)
00270 {
00271         ClientToScreen(&point);
00272         OnContextMenu(this, point);
00273 }
00274 
00275 void CAlienPlanetsView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
00276 {
00277 #ifndef SHARED_HANDLERS
00278         theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
00279 #endif
00280 }
00281 
00282 
00283 // CAlienPlanetsView diagnostics
00284 
00285 #ifdef _DEBUG
00286 void CAlienPlanetsView::AssertValid() const
00287 {
00288         CView::AssertValid();
00289 }
00290 
00291 void CAlienPlanetsView::Dump(CDumpContext& dc) const
00292 {
00293         CView::Dump(dc);
00294 }
00295 
00296 CAlienPlanetsDoc* CAlienPlanetsView::GetDocument() const // non-debug version is inline
00297 {
00298         ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAlienPlanetsDoc)));
00299         return (CAlienPlanetsDoc*)m_pDocument;
00300 }
00301 #endif //_DEBUG
00302 
00303 
00304 // CAlienPlanetsView message handlers