Alientech 0.01
An extendable game engine
C:/Alientech/AlienPlanets/CntrItem.cpp
Go to the documentation of this file.
00001 
00002 // CntrItem.cpp : implementation of the CAlienPlanetsCntrItem class
00003 //
00004 
00005 #include "stdafx.h"
00006 #include "AlienPlanets.h"
00007 
00008 #include "AlienPlanetsDoc.h"
00009 #include "AlienPlanetsView.h"
00010 #include "CntrItem.h"
00011 
00012 #ifdef _DEBUG
00013 #define new DEBUG_NEW
00014 #endif
00015 
00016 
00017 // CAlienPlanetsCntrItem implementation
00018 
00019 IMPLEMENT_SERIAL(CAlienPlanetsCntrItem, COleClientItem, 0)
00020 
00021 CAlienPlanetsCntrItem::CAlienPlanetsCntrItem(CAlienPlanetsDoc* pContainer)
00022         : COleClientItem(pContainer)
00023 {
00024         // TODO: add one-time construction code here
00025 }
00026 
00027 CAlienPlanetsCntrItem::~CAlienPlanetsCntrItem()
00028 {
00029         // TODO: add cleanup code here
00030 }
00031 
00032 void CAlienPlanetsCntrItem::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam)
00033 {
00034         ASSERT_VALID(this);
00035 
00036         COleClientItem::OnChange(nCode, dwParam);
00037 
00038         // When an item is being edited (either in-place or fully open)
00039         //  it sends OnChange notifications for changes in the state of the
00040         //  item or visual appearance of its content.
00041 
00042         // TODO: invalidate the item by calling UpdateAllViews
00043         //  (with hints appropriate to your application)
00044 
00045         GetDocument()->UpdateAllViews(NULL);
00046                 // for now just update ALL views/no hints
00047 }
00048 
00049 BOOL CAlienPlanetsCntrItem::OnChangeItemPosition(const CRect& rectPos)
00050 {
00051         ASSERT_VALID(this);
00052 
00053         // During in-place activation CAlienPlanetsCntrItem::OnChangeItemPosition
00054         //  is called by the server to change the position of the in-place
00055         //  window.  Usually, this is a result of the data in the server
00056         //  document changing such that the extent has changed or as a result
00057         //  of in-place resizing.
00058         //
00059         // The default here is to call the base class, which will call
00060         //  COleClientItem::SetItemRects to move the item
00061         //  to the new position.
00062 
00063         if (!COleClientItem::OnChangeItemPosition(rectPos))
00064                 return FALSE;
00065 
00066         // TODO: update any cache you may have of the item's rectangle/extent
00067 
00068         return TRUE;
00069 }
00070 
00071 BOOL CAlienPlanetsCntrItem::OnShowControlBars(CFrameWnd* pFrameWnd, BOOL bShow)
00072 {
00073         CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, pFrameWnd);
00074 
00075         if (pMainFrame != NULL)
00076         {
00077                 ASSERT_VALID(pMainFrame);
00078                 return pMainFrame->OnShowPanes(bShow);
00079         }
00080 
00081         return FALSE;
00082 }
00083 
00084 void CAlienPlanetsCntrItem::OnGetItemPosition(CRect& rPosition)
00085 {
00086         ASSERT_VALID(this);
00087 
00088         // During in-place activation, CAlienPlanetsCntrItem::OnGetItemPosition
00089         //  will be called to determine the location of this item.  Usually, this 
00090         //  rectangle would reflect the current position of the item relative to the 
00091         //  view used for activation.  You can obtain the view by calling 
00092         //  CAlienPlanetsCntrItem::GetActiveView.
00093 
00094         // TODO: return correct rectangle (in pixels) in rPosition
00095 
00096         CSize size;
00097         rPosition.SetRectEmpty();
00098         if (GetExtent(&size, m_nDrawAspect))
00099         {
00100                 CAlienPlanetsView* pView = GetActiveView();
00101                 ASSERT_VALID(pView);
00102                 if (!pView)
00103                         return;
00104                 CDC *pDC = pView->GetDC();
00105                 ASSERT(pDC);
00106                 if (!pDC)
00107                         return;
00108                 pDC->HIMETRICtoLP(&size);
00109                 rPosition.SetRect(10, 10, size.cx + 10, size.cy + 10);
00110         }
00111         else
00112                 rPosition.SetRect(10, 10, 210, 210);
00113 }
00114 
00115 void CAlienPlanetsCntrItem::OnActivate()
00116 {
00117     // Allow only one inplace activate item per frame
00118     CAlienPlanetsView* pView = GetActiveView();
00119     ASSERT_VALID(pView);
00120         if (!pView)
00121                 return;
00122     COleClientItem* pItem = GetDocument()->GetInPlaceActiveItem(pView);
00123     if (pItem != NULL && pItem != this)
00124         pItem->Close();
00125     
00126     COleClientItem::OnActivate();
00127 }
00128 
00129 void CAlienPlanetsCntrItem::OnDeactivateUI(BOOL bUndoable)
00130 {
00131         COleClientItem::OnDeactivateUI(bUndoable);
00132 
00133     DWORD dwMisc = 0;
00134     m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc);
00135     if (dwMisc & OLEMISC_INSIDEOUT)
00136         DoVerb(OLEIVERB_HIDE, NULL);
00137 }
00138 
00139 void CAlienPlanetsCntrItem::Serialize(CArchive& ar)
00140 {
00141         ASSERT_VALID(this);
00142 
00143         // Call base class first to read in COleClientItem data.
00144         // Since this sets up the m_pDocument pointer returned from
00145         //  CAlienPlanetsCntrItem::GetDocument, it is a good idea to call
00146         //  the base class Serialize first.
00147         COleClientItem::Serialize(ar);
00148 
00149         // now store/retrieve data specific to CAlienPlanetsCntrItem
00150         if (ar.IsStoring())
00151         {
00152                 // TODO: add storing code here
00153         }
00154         else
00155         {
00156                 // TODO: add loading code here
00157         }
00158 }
00159 
00160 
00161 // CAlienPlanetsCntrItem diagnostics
00162 
00163 #ifdef _DEBUG
00164 void CAlienPlanetsCntrItem::AssertValid() const
00165 {
00166         COleClientItem::AssertValid();
00167 }
00168 
00169 void CAlienPlanetsCntrItem::Dump(CDumpContext& dc) const
00170 {
00171         COleClientItem::Dump(dc);
00172 }
00173 #endif
00174