GME  13
BoxDecorator.cpp
Go to the documentation of this file.
00001 //################################################################################################
00002 //
00003 // Box decorator class
00004 //      BoxDecorator.cpp
00005 //
00006 //################################################################################################
00007 
00008 #include "StdAfx.h"
00009 #include "BoxDecorator.h"
00010 #include "BoxCompositePart.h"
00011 #include <afxole.h>
00012 #include <sys/types.h>
00013 #include <sys/stat.h>
00014 
00015 #ifdef _DEBUG
00016 #define TRYDRAGNDROP
00017 #endif
00018 
00019 //################################################################################################
00020 //
00021 // CLASS : BoxDecorator
00022 //
00023 //################################################################################################
00024 
00025 BoxDecorator::BoxDecorator(CComPtr<IMgaCommonDecoratorEvents>& eventSink):
00026         m_part(NULL),
00027         m_eventSink(eventSink)
00028 {
00029 }
00030 
00031 BoxDecorator::~BoxDecorator()
00032 {
00033 }
00034 
00035 void BoxDecorator::Initialize(CComPtr<IMgaProject>& pProject, CComPtr<IMgaMetaPart>& pPart, CComPtr<IMgaFCO>& pFCO)
00036 {
00037         m_part->Initialize(pProject, pPart, pFCO);
00038 }
00039 
00040 void BoxDecorator::Destroy()
00041 {
00042         if (m_part) {
00043                 m_part->Destroy();
00044                 delete m_part;
00045                 m_part = NULL;
00046         }
00047 }
00048 
00049 CString BoxDecorator::GetMnemonic(void) const
00050 {
00051         return m_part->GetMnemonic();
00052 }
00053 
00054 feature_code BoxDecorator::GetFeatures(void) const
00055 {
00056         return m_part->GetFeatures();
00057 }
00058 
00059 void BoxDecorator::SetParam(const CString& strName, VARIANT vValue)
00060 {
00061         m_part->SetParam(strName, vValue);
00062 }
00063 
00064 void BoxDecorator::GetParam(const CString& strName, VARIANT* pvValue)
00065 {
00066         m_part->GetParam(strName, pvValue);
00067 }
00068 
00069 void BoxDecorator::SetActive(bool bIsActive)
00070 {
00071         m_part->SetActive(bIsActive);
00072 }
00073 
00074 CSize BoxDecorator::GetPreferredSize(void) const
00075 {
00076         return m_part->GetPreferredSize();
00077 }
00078 
00079 
00080 void BoxDecorator::SetLocation(const CRect& location)
00081 {
00082         m_part->SetLocation(location);
00083 }
00084 
00085 CRect BoxDecorator::GetLocation(void) const
00086 {
00087         return m_part->GetLocation();
00088 }
00089 
00090 CRect BoxDecorator::GetLabelLocation(void) const
00091 {
00092         return m_part->GetLabelLocation();
00093 }
00094 
00095 CRect BoxDecorator::GetPortLocation(CComPtr<IMgaFCO>& fco) const
00096 {
00097         return m_part->GetPortLocation(fco);
00098 }
00099 
00100 void BoxDecorator::GetPorts(CComPtr<IMgaFCOs>& portFCOs) const
00101 {
00102         m_part->GetPorts(portFCOs);
00103 }
00104 
00105 void BoxDecorator::Draw(CDC* pDC, Gdiplus::Graphics* gdip)
00106 {
00107         m_part->Draw(pDC, gdip);
00108 }
00109 
00110 void BoxDecorator::SaveState()
00111 {
00112         m_part->SaveState();
00113 }
00114 
00115 // New functions
00116 void BoxDecorator::InitializeEx(CComPtr<IMgaProject>& pProject, CComPtr<IMgaMetaPart>& pPart, CComPtr<IMgaFCO>& pFCO,
00117                                                                 HWND parentWnd)
00118 {
00119         DecoratorSDK::BoxCompositePart* boxComposite = new DecoratorSDK::BoxCompositePart(NULL, m_eventSink);
00120         m_part = boxComposite;
00121 
00122         boxComposite->InitializeEx(pProject, pPart, pFCO, parentWnd);
00123 }
00124 
00125 void BoxDecorator::SetSelected(bool bIsSelected)
00126 {
00127         m_part->SetSelected(bIsSelected);
00128 }
00129 
00130 bool BoxDecorator::MouseMoved(UINT nFlags, const CPoint& point, HDC transformHDC)
00131 {
00132         return m_part->MouseMoved(nFlags, point, transformHDC);
00133 }
00134 
00135 bool BoxDecorator::MouseLeftButtonDown(UINT nFlags, const CPoint& point, HDC transformHDC)
00136 {
00137         return m_part->MouseLeftButtonDown(nFlags, point, transformHDC);
00138 }
00139 
00140 bool BoxDecorator::MouseLeftButtonUp(UINT nFlags, const CPoint& point, HDC transformHDC)
00141 {
00142         return m_part->MouseLeftButtonUp(nFlags, point, transformHDC);
00143 }
00144 
00145 bool BoxDecorator::MouseLeftButtonDoubleClick(UINT nFlags, const CPoint& point, HDC transformHDC)
00146 {
00147         return m_part->MouseLeftButtonDoubleClick(nFlags, point, transformHDC);
00148 }
00149 
00150 bool BoxDecorator::MouseRightButtonDown(HMENU hCtxMenu, UINT nFlags, const CPoint& point, HDC transformHDC)
00151 {
00152         return m_part->MouseRightButtonDown(hCtxMenu, nFlags, point, transformHDC);
00153 }
00154 
00155 bool BoxDecorator::MouseRightButtonUp(UINT nFlags, const CPoint& point, HDC transformHDC)
00156 {
00157         return m_part->MouseRightButtonUp(nFlags, point, transformHDC);
00158 }
00159 
00160 bool BoxDecorator::MouseRightButtonDoubleClick(UINT nFlags, const CPoint& point, HDC transformHDC)
00161 {
00162         return m_part->MouseRightButtonDoubleClick(nFlags, point, transformHDC);
00163 }
00164 
00165 bool BoxDecorator::MouseMiddleButtonDown(UINT nFlags, const CPoint& point, HDC transformHDC)
00166 {
00167         return m_part->MouseMiddleButtonDown(nFlags, point, transformHDC);
00168 }
00169 
00170 bool BoxDecorator::MouseMiddleButtonUp(UINT nFlags, const CPoint& point, HDC transformHDC)
00171 {
00172         return m_part->MouseMiddleButtonUp(nFlags, point, transformHDC);
00173 }
00174 
00175 bool BoxDecorator::MouseMiddleButtonDoubleClick(UINT nFlags, const CPoint& point, HDC transformHDC)
00176 {
00177         return m_part->MouseMiddleButtonDoubleClick(nFlags, point, transformHDC);
00178 }
00179 
00180 bool BoxDecorator::MouseWheelTurned(UINT nFlags, short distance, const CPoint& point, HDC transformHDC)
00181 {
00182         return m_part->MouseWheelTurned(nFlags, distance, point, transformHDC);
00183 }
00184 
00185 bool BoxDecorator::DragEnter(DROPEFFECT* dropEffect, COleDataObject* pDataObject, DWORD dwKeyState, const CPoint& point, HDC transformHDC)
00186 {
00187 #ifdef TRYDRAGNDROP
00188 //      pDataObject->BeginEnumFormats();
00189 //      FORMATETC fi;
00190 //      TRACE0("DragEnter:\n");
00191 //      while (pDataObject->GetNextFormat(&fi) == TRUE) {
00192 //              TRACE("\tcfFormat %d dwAspect %lu lindex %ld tymed %lu\n", fi.cfFormat, fi.dwAspect, fi.lindex, fi.tymed);
00193 //      }
00194 //      return DROPEFFECT_NONE;
00195         if (pDataObject->IsDataAvailable(CF_HDROP)) {
00196                 *dropEffect = DROPEFFECT_COPY;
00197                 return true;
00198         }
00199 #endif
00200         return m_part->DragEnter(dropEffect, pDataObject, dwKeyState, point, transformHDC);
00201 }
00202 
00203 bool BoxDecorator::DragOver(DROPEFFECT* dropEffect, COleDataObject* pDataObject, DWORD dwKeyState, const CPoint& point, HDC transformHDC)
00204 {
00205 #ifdef TRYDRAGNDROP
00206         if (pDataObject->IsDataAvailable(CF_HDROP)) {
00207                 *dropEffect = DROPEFFECT_COPY;
00208                 return true;
00209         }
00210 #endif
00211         return m_part->DragOver(dropEffect, pDataObject, dwKeyState, point, transformHDC);
00212 }
00213 
00214 bool BoxDecorator::Drop(COleDataObject* pDataObject, DROPEFFECT dropEffect, const CPoint& point, HDC transformHDC)
00215 {
00216 #ifdef TRYDRAGNDROP
00217         if (pDataObject->IsDataAvailable(CF_HDROP) && dropEffect == DROPEFFECT_COPY) {
00218                 STGMEDIUM medium;
00219                 medium.tymed = TYMED_HGLOBAL;
00220                 pDataObject->GetData(CF_HDROP, &medium);
00221                 return DropFile((HDROP)medium.hGlobal, point, transformHDC);
00222         }
00223 #endif
00224         return m_part->Drop(pDataObject, dropEffect, point, transformHDC);
00225 }
00226 
00227 bool BoxDecorator::DropFile(HDROP p_hDropInfo, const CPoint& point, HDC transformHDC)
00228 {
00229 #ifdef TRYDRAGNDROP
00230         UINT nFiles = DragQueryFile(p_hDropInfo, 0xFFFFFFFF, NULL, 0);
00231         if (nFiles < 1)
00232                 return false;
00233 
00234         for (UINT iF = 0; iF < nFiles; ++iF) {
00235                 TCHAR szFileName[_MAX_PATH];
00236                 UINT res = DragQueryFile(p_hDropInfo, iF, szFileName, _MAX_PATH);
00237                 if (res > 0) {
00238                         bool is_dir = false; 
00239                         struct _stat fstatus;
00240                         if (0 == _tstat(szFileName, &fstatus))
00241                                 is_dir = (fstatus.st_mode & _S_IFDIR) == _S_IFDIR;
00242 
00243                         CString conn(szFileName);
00244                         if (!is_dir && conn.Right(4).CompareNoCase(_T(".txt")) == 0) {
00245                                 CFile txtFile(conn, CFile::modeRead);
00246                                 char pbufRead[100];
00247                                 UINT readLen = txtFile.Read(pbufRead, sizeof(pbufRead) - 1);
00248                                 pbufRead[readLen] = 0;
00249                                 AfxMessageBox("Decorator drop: '" + conn + "' first 100 bytes: " + pbufRead + ".");
00250                                 return true;
00251                         } else {
00252                                 AfxMessageBox("Decorator drop: '.txt' files may be dropped only. Can't open file: " + conn + "!");
00253                         }
00254                 } else {
00255                         AfxMessageBox(_T("Decorator drop: Can't inquire file information!"));
00256                 }
00257         }
00258 #endif
00259         return m_part->DropFile(p_hDropInfo, point, transformHDC);
00260 }
00261 
00262 bool BoxDecorator::MenuItemSelected(UINT menuItemId, UINT nFlags, const CPoint& point, HDC transformHDC)
00263 {
00264         return m_part->MenuItemSelected(menuItemId, nFlags, point, transformHDC);
00265 }
00266 
00267 bool BoxDecorator::OperationCanceledByGME(void)
00268 {
00269         return m_part->OperationCanceledByGME();
00270 }