GME  13
GMEOLEAspect.cpp
Go to the documentation of this file.
00001 // GMEOLEAspect.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "gme.h"
00006 #include "GMEOLEAspect.h"
00007 #include "GMEOLEError.h"
00008 #include "GMEOLEColl.h"
00009 #include "GMEDoc.h"
00010 #include "MainFrm.h"
00011 #include "GMEEventLogger.h"
00012 
00013 
00014 #ifdef _DEBUG
00015 #define new DEBUG_NEW
00016 #undef THIS_FILE
00017 static char THIS_FILE[] = __FILE__;
00018 #endif
00019 
00021 // CGMEOLEAspect
00022 
00023 IMPLEMENT_DYNCREATE(CGMEOLEAspect, CCmdTarget)
00024 
00025 CGMEOLEAspect::CGMEOLEAspect()
00026 {
00027         EnableAutomation();
00028 }
00029 
00030 CGMEOLEAspect::~CGMEOLEAspect()
00031 {
00032 }
00033 
00034 
00035 void CGMEOLEAspect::OnFinalRelease()
00036 {
00037         // When the last reference for an automation object is released
00038         // OnFinalRelease is called.  The base class will automatically
00039         // deletes the object.  Add additional cleanup required for your
00040         // object before calling the base class.
00041 
00042         CCmdTarget::OnFinalRelease();
00043 }
00044 
00045 
00046 bool CGMEOLEAspect::AmIValid() {
00047 
00048         if (CGMEDoc::theInstance) {
00049                 POSITION pos = CGMEDoc::theInstance->GetFirstViewPosition();
00050                 while (pos) {
00051 #if !defined (ACTIVEXGMEVIEW)
00052                         CGMEView* view = (CGMEView*)(CGMEDoc::theInstance->GetNextView(pos));
00053                         ASSERT(view);
00054                         if (view == m_view) {
00055                                 POSITION apos = view->guiMeta->aspects.GetHeadPosition();
00056                                 while (apos) {
00057                                         CGuiMetaAspect *guiAspect = view->guiMeta->aspects.GetNext(apos);
00058                                         ASSERT(guiAspect);
00059                                         if (guiAspect == m_guiAspect) {
00060                                                 return true;
00061                                         }
00062                                 }
00063                         }
00064 #endif
00065                 }
00066         }
00067         return false;
00068 }
00069 
00070 BEGIN_MESSAGE_MAP(CGMEOLEAspect, CCmdTarget)
00071         //{{AFX_MSG_MAP(CGMEOLEAspect)
00072                 // NOTE - the ClassWizard will add and remove mapping macros here.
00073         //}}AFX_MSG_MAP
00074 END_MESSAGE_MAP()
00075 
00076 BEGIN_DISPATCH_MAP(CGMEOLEAspect, CCmdTarget)
00077         //{{AFX_DISPATCH_MAP(CGMEOLEAspect)
00078         DISP_PROPERTY_EX(CGMEOLEAspect, "MgaAspect", GetMgaAspect, SetMgaAspect, VT_DISPATCH)
00079         DISP_PROPERTY_EX(CGMEOLEAspect, "Active", GetActive, SetActive, VT_BOOL)
00080         DISP_PROPERTY_EX(CGMEOLEAspect, "Valid", GetValid, SetValid, VT_BOOL)
00081         //}}AFX_DISPATCH_MAP
00082 END_DISPATCH_MAP()
00083 
00084 // Note: we add support for IID_IGMEOLEAspect to support typesafe binding
00085 //  from VBA.  This IID must match the GUID that is attached to the 
00086 //  dispinterface in the .ODL file.
00087 
00088 // {EDEEB1F8-BC44-40d2-BE91-83E8CCD59845}
00089 //static const IID IID_IGMEOLEAspect = 
00090 //{ 0xedeeb1f8, 0xbc44, 0x40d2, { 0xbe, 0x91, 0x83, 0xe8, 0xcc, 0xd5, 0x98, 0x45 } };
00091 
00092 
00093 BEGIN_INTERFACE_MAP(CGMEOLEAspect, CCmdTarget)
00094         INTERFACE_PART(CGMEOLEAspect, __uuidof(IGMEOLEAspect), Dual)
00095         DUAL_ERRORINFO_PART(CGMEOLEAspect)
00096 END_INTERFACE_MAP()
00097 
00099 // CGMEOLEAspect message handlers
00100 
00101 LPDISPATCH CGMEOLEAspect::GetMgaAspect() 
00102 {
00103         CGMEEventLogger::LogGMEEvent("CGMEOLEAspect::GetMgaAspect()\r\n");
00104 
00105         PRECONDITION_VALID_ASPECT;
00106 
00107         return m_guiAspect->mgaMeta;
00108 }
00109 
00110 void CGMEOLEAspect::SetMgaAspect(LPDISPATCH) 
00111 {
00112         CGMEEventLogger::LogGMEEvent("CGMEOLEAspect::SetMgaAspect()\r\n");
00113         
00114         SetNotSupported();
00115 }
00116 
00117 BOOL CGMEOLEAspect::GetActive() 
00118 {
00119         CGMEEventLogger::LogGMEEvent("CGMEOLEAspect::GetActive()\r\n");
00120 
00121         PRECONDITION_VALID_ASPECT;
00122 
00123         return (m_view->currentAspect == m_guiAspect) ? TRUE : FALSE;
00124 }
00125 
00126 void CGMEOLEAspect::SetActive(BOOL bNewValue) 
00127 {
00128         CGMEEventLogger::LogGMEEvent("CGMEOLEAspect::SetActive()\r\n");
00129 
00130         PRECONDITION_VALID_ASPECT;
00131 
00132         if (bNewValue == TRUE) {
00133                 m_view->ChangeAspect(m_guiAspect->name);
00134         }
00135 }
00136 
00137 
00138 BOOL CGMEOLEAspect::GetValid() 
00139 {
00140         CGMEEventLogger::LogGMEEvent("CGMEOLEAspect::GetValid()\r\n");
00141         
00142         // PRECONDITIONS: None
00143 
00144         return (AmIValid() ? TRUE : FALSE);
00145 }
00146 
00147 void CGMEOLEAspect::SetValid(BOOL) 
00148 {
00149         CGMEEventLogger::LogGMEEvent("CGMEOLEAspect::SetValid()\r\n");
00150 
00151         SetNotSupported();
00152 
00153 }
00154 
00155 DELEGATE_DUAL_INTERFACE(CGMEOLEAspect, Dual)
00156 
00157 // Implement ISupportErrorInfo to indicate we support the
00158 // OLE Automation error handler.
00159 IMPLEMENT_DUAL_ERRORINFO(CGMEOLEAspect, __uuidof(IGMEOLEAspect))
00160 
00161 STDMETHODIMP CGMEOLEAspect::XDual::get_MgaAspect(IMgaMetaAspect** aspect)
00162 {
00163         METHOD_PROLOGUE(CGMEOLEAspect, Dual)
00164 
00165         TRY_DUAL(__uuidof(IGMEOLEAspect))
00166         {
00167                 LPDISPATCH lpDisp = pThis->GetMgaAspect();
00168                 lpDisp->QueryInterface(__uuidof(IMgaMetaAspect), (LPVOID*)aspect);
00169                 return NOERROR;
00170         }
00171         CATCH_ALL_DUAL
00172 }
00173 
00174 STDMETHODIMP CGMEOLEAspect::XDual::put_Active(VARIANT_BOOL isActive)
00175 {
00176         METHOD_PROLOGUE(CGMEOLEAspect, Dual)
00177 
00178         TRY_DUAL(__uuidof(IGMEOLEAspect))
00179         {
00180                 pThis->SetActive(isActive);
00181                 return NOERROR;
00182         }
00183         CATCH_ALL_DUAL
00184 }
00185 
00186 STDMETHODIMP CGMEOLEAspect::XDual::get_Active(VARIANT_BOOL* isActive)
00187 {
00188         METHOD_PROLOGUE(CGMEOLEAspect, Dual)
00189 
00190         TRY_DUAL(__uuidof(IGMEOLEAspect))
00191         {
00192                 *isActive = (pThis->GetActive() == FALSE) ? VARIANT_FALSE : VARIANT_TRUE;
00193                 return NOERROR;
00194         }
00195         CATCH_ALL_DUAL
00196 }
00197 
00198 STDMETHODIMP CGMEOLEAspect::XDual::get_Valid(VARIANT_BOOL* isValid)
00199 {
00200         METHOD_PROLOGUE(CGMEOLEAspect, Dual)
00201 
00202         TRY_DUAL(__uuidof(IGMEOLEAspect))
00203         {
00204                 *isValid = (pThis->GetValid() == FALSE) ? VARIANT_FALSE : VARIANT_TRUE;
00205                 return NOERROR;
00206         }
00207         CATCH_ALL_DUAL
00208 }