GME
13
|
00001 // PartBrowserCtrl.cpp : Implementation of the CPartBrowserCtrl ActiveX Control class. 00002 00003 #include "stdafx.h" 00004 #include "PartBrowser.h" 00005 #include "PartBrowserCtrl.h" 00006 #include "PartBrowserPropPage.h" 00007 00008 #ifdef _DEBUG 00009 #define new DEBUG_NEW 00010 #undef THIS_FILE 00011 static char THIS_FILE[] = __FILE__; 00012 #endif 00013 00014 00015 00016 IMPLEMENT_DYNCREATE(CPartBrowserCtrl, COleControl) 00017 00018 00019 00020 // Message map 00021 00022 BEGIN_MESSAGE_MAP(CPartBrowserCtrl, COleControl) 00023 //{{AFX_MSG_MAP(CPartBrowserCtrl) 00024 ON_WM_CREATE() 00025 //}}AFX_MSG_MAP 00026 ON_OLEVERB(AFX_IDS_VERB_EDIT, OnEdit) 00027 ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties) 00028 END_MESSAGE_MAP() 00029 00030 00031 00032 // Dispatch map 00033 00034 BEGIN_DISPATCH_MAP(CPartBrowserCtrl, COleControl) 00035 //{{AFX_DISPATCH_MAP(CPartBrowserCtrl) 00036 DISP_FUNCTION_ID(CPartBrowserCtrl, "SetCurrentProject", dispidSetCurrentProject, SetCurrentProject, VT_EMPTY, VTS_UNKNOWN) 00037 DISP_FUNCTION_ID(CPartBrowserCtrl, "SetMetaModel", dispidSetMetaModel, SetMetaModel, VT_EMPTY, VTS_UNKNOWN) 00038 DISP_FUNCTION_ID(CPartBrowserCtrl, "SetBgColor", dispidSetBgColor, SetBgColor, VT_EMPTY, VTS_COLOR) 00039 DISP_FUNCTION_ID(CPartBrowserCtrl, "ChangeAspect", dispidChangeAspect, ChangeAspect, VT_EMPTY, VTS_I4) 00040 DISP_FUNCTION_ID(CPartBrowserCtrl, "CycleAspect", dispidCycleAspect, CycleAspect, VT_EMPTY, VTS_NONE) 00041 DISP_FUNCTION_ID(CPartBrowserCtrl, "RePaint", dispidRePaint, RePaint, VT_EMPTY, VTS_NONE) 00042 //}}AFX_DISPATCH_MAP 00043 DISP_FUNCTION_ID(CPartBrowserCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE) 00044 END_DISPATCH_MAP() 00045 00046 00047 00048 // Event map 00049 00050 BEGIN_EVENT_MAP(CPartBrowserCtrl, COleControl) 00051 //{{AFX_EVENT_MAP(CPartBrowserCtrl) 00052 // NOTE - ClassWizard will add and remove event map entries 00053 // DO NOT EDIT what you see in these blocks of generated code ! 00054 //}}AFX_EVENT_MAP 00055 END_EVENT_MAP() 00056 00057 00059 // Native COM interface map - peter 00060 BEGIN_INTERFACE_MAP(CPartBrowserCtrl, COleControl) 00061 INTERFACE_PART(CPartBrowserCtrl, __uuidof(IMgaEventSink), EventSink) 00062 END_INTERFACE_MAP() 00063 00064 00065 // Property pages 00066 00067 // TODO: Add more property pages as needed. Remember to increase the count! 00068 BEGIN_PROPPAGEIDS(CPartBrowserCtrl, 1) 00069 PROPPAGEID(CPartBrowserPropPage::guid) 00070 END_PROPPAGEIDS(CPartBrowserCtrl) 00071 00072 00073 00074 // Initialize class factory and guid 00075 00076 IMPLEMENT_OLECREATE_EX(CPartBrowserCtrl, "PARTBROWSER.PartBrowserCtrl.1", 00077 0x1ff57057, 0xd598, 0x4fc2, 0x8f, 0x9d, 0x70, 0x8f, 0x59, 0xb9, 0xc0, 0x17) 00078 00079 00080 00081 // Type library ID and version 00082 00083 IMPLEMENT_OLETYPELIB(CPartBrowserCtrl, _tlid, _wVerMajor, _wVerMinor) 00084 00085 00086 00087 // Interface IDs 00088 00089 const IID BASED_CODE IID_DPartBrowser = 00090 { 0x2D05F0EE, 0xEB81, 0x4D1D, { 0xA5, 0xC6, 0x43, 0x14, 0x6F, 0x38, 0xBF, 0x81 } }; 00091 const IID BASED_CODE IID_DPartBrowserEvents = 00092 { 0x5042C3E4, 0x58A9, 0x4059, { 0xA5, 0xE4, 0xFD, 0x7B, 0xFB, 0x3A, 0xA2, 0x2B } }; 00093 00094 00095 00096 // Control type information 00097 00098 static const DWORD BASED_CODE _dwPartBrowserOleMisc = 00099 OLEMISC_ACTIVATEWHENVISIBLE | 00100 OLEMISC_SETCLIENTSITEFIRST | 00101 OLEMISC_INSIDEOUT | 00102 OLEMISC_CANTLINKINSIDE | 00103 OLEMISC_RECOMPOSEONRESIZE; 00104 00105 IMPLEMENT_OLECTLTYPE(CPartBrowserCtrl, IDS_PARTBROWSER, _dwPartBrowserOleMisc) 00106 00107 00108 00109 // CPartBrowserCtrl::CPartBrowserCtrlFactory::UpdateRegistry - 00110 // Adds or removes system registry entries for CPartBrowserCtrl 00111 00112 BOOL CPartBrowserCtrl::CPartBrowserCtrlFactory::UpdateRegistry(BOOL bRegister) 00113 { 00114 // TODO: Verify that your control follows apartment-model threading rules. 00115 // Refer to MFC TechNote 64 for more information. 00116 // If your control does not conform to the apartment-model rules, then 00117 // you must modify the code below, changing the 6th parameter from 00118 // afxRegInsertable | afxRegApartmentThreading to afxRegInsertable. 00119 00120 if (bRegister) 00121 return AfxOleRegisterControlClass( 00122 AfxGetInstanceHandle(), 00123 m_clsid, 00124 m_lpszProgID, 00125 IDS_PARTBROWSER, 00126 IDB_PARTBROWSER, 00127 afxRegInsertable | afxRegApartmentThreading, 00128 _dwPartBrowserOleMisc, 00129 _tlid, 00130 _wVerMajor, 00131 _wVerMinor); 00132 else 00133 return AfxOleUnregisterClass(m_clsid, m_lpszProgID); 00134 } 00135 00136 00137 00139 // CPartBrowserCtrl::XEventSink - native COM interface - peter 00140 STDMETHODIMP_(ULONG) CPartBrowserCtrl::XEventSink::AddRef() 00141 { 00142 METHOD_PROLOGUE(CPartBrowserCtrl,EventSink) 00143 return pThis->ExternalAddRef(); 00144 } 00145 00146 STDMETHODIMP_(ULONG) CPartBrowserCtrl::XEventSink::Release() 00147 { 00148 METHOD_PROLOGUE(CPartBrowserCtrl,EventSink) 00149 return pThis->ExternalRelease(); 00150 } 00151 00152 STDMETHODIMP CPartBrowserCtrl::XEventSink::QueryInterface(REFIID riid, void** ppv) 00153 { 00154 METHOD_PROLOGUE(CPartBrowserCtrl,EventSink) 00155 return pThis->ExternalQueryInterface(&riid, ppv); 00156 } 00157 00158 STDMETHODIMP CPartBrowserCtrl::XEventSink::GlobalEvent(globalevent_enum event) 00159 { 00160 METHOD_PROLOGUE(CPartBrowserCtrl,EventSink) 00161 // TODO: Handle global events here - peter 00162 pThis->OnMgaGlobalEvent(event); 00163 return S_OK; 00164 } 00165 00166 STDMETHODIMP CPartBrowserCtrl::XEventSink::ObjectEvent(IMgaObject* obj, unsigned long eventmask, VARIANT v) 00167 { 00168 METHOD_PROLOGUE(CPartBrowserCtrl,EventSink) 00169 // TODO: Handle object events here - peter 00170 pThis->m_MgaObjectEventList.Add(obj,eventmask); 00171 return S_OK; 00172 } 00173 00174 00175 // CPartBrowserCtrl::CPartBrowserCtrl - Constructor 00176 00177 CPartBrowserCtrl::CPartBrowserCtrl() 00178 { 00179 InitializeIIDs(&IID_DPartBrowser, &IID_DPartBrowserEvents); 00180 // TODO: Initialize your control's instance data here. 00181 } 00182 00183 00184 00185 // CPartBrowserCtrl::~CPartBrowserCtrl - Destructor 00186 00187 CPartBrowserCtrl::~CPartBrowserCtrl() 00188 { 00189 // TODO: Cleanup your control's instance data here. 00190 } 00191 00192 00193 00194 // CPartBrowserCtrl::OnDraw - Drawing function 00195 00196 void CPartBrowserCtrl::OnDraw( 00197 CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) 00198 { 00199 if (!pdc) 00200 return; 00201 00202 if (m_partBrowserDlg.GetSafeHwnd()) { 00203 m_partBrowserDlg.MoveWindow(rcBounds, TRUE); 00204 } else { 00205 AFX_MANAGE_STATE(AfxGetStaticModuleState()); 00206 CBrush brush(RGB(255, 255, 255)); 00207 pdc->FillRect(rcBounds, &brush); 00208 00209 CRect edge(rcBounds); 00210 pdc->DrawEdge(&edge, EDGE_BUMP, BF_RECT); 00211 00212 CString label("PartBrowser OCX"); 00213 00214 BITMAP bm; 00215 CBitmap bitmap; 00216 bitmap.LoadBitmap(IDB_PARTBROWSER); 00217 bitmap.GetBitmap(&bm); 00218 CSize size(bm.bmWidth, bm.bmHeight); 00219 pdc->DPtoLP(&size); 00220 CPoint org(0,0); 00221 pdc->DPtoLP(&org); 00222 CPoint pos(rcBounds.Width() / 2, rcBounds.Height() / 2 - (pdc->GetTextExtent(label).cy)); 00223 CDC dcMem; 00224 dcMem.CreateCompatibleDC(pdc); 00225 CBitmap* oldbitmap = dcMem.SelectObject(&bitmap); 00226 dcMem.SetMapMode(pdc->GetMapMode()); 00227 pdc->BitBlt(pos.x, pos.y, size.cx, size.cy, &dcMem, org.x, org.y, SRCCOPY); 00228 dcMem.SelectObject(oldbitmap); 00229 00230 pdc->SetTextAlign(TA_CENTER); 00231 pdc->TextOut(rcBounds.Width() / 2, rcBounds.Height() / 2, CString("PartBrowser ActiveX Control")); 00232 } 00233 } 00234 00235 00236 // CPartBrowserCtrl::DoPropExchange - Persistence support 00237 00238 void CPartBrowserCtrl::DoPropExchange(CPropExchange* pPX) 00239 { 00240 ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor)); 00241 COleControl::DoPropExchange(pPX); 00242 00243 // TODO: Call PX_ functions for each persistent custom property. 00244 } 00245 00246 00247 00248 // CPartBrowserCtrl::OnResetState - Reset control to default state 00249 00250 void CPartBrowserCtrl::OnResetState() 00251 { 00252 COleControl::OnResetState(); // Resets defaults found in DoPropExchange 00253 00254 // TODO: Reset any other control state here. 00255 } 00256 00257 00258 00259 // CPartBrowserCtrl::AboutBox - Display an "About" box to the user 00260 00261 void CPartBrowserCtrl::AboutBox() 00262 { 00263 CDialog dlgAbout(IDD_ABOUTBOX_PARTBROWSER); 00264 dlgAbout.DoModal(); 00265 } 00266 00267 00268 00269 // CPartBrowserCtrl message handlers 00270 00271 int CPartBrowserCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 00272 { 00273 if (COleControl::OnCreate(lpCreateStruct) == -1) 00274 return -1; 00275 00276 if (m_partBrowserDlg.Create(IDD_PARTBROWSER_DIALOG, this) == FALSE) 00277 return -1; 00278 00279 return 0; 00280 } 00281 00282 BOOL CPartBrowserCtrl::PreCreateWindow(CREATESTRUCT& cs) 00283 { 00284 cs.dwExStyle |= WS_EX_CONTROLPARENT; 00285 return COleControl::PreCreateWindow(cs); 00286 } 00287 00288 void CPartBrowserCtrl::SetCurrentProject(IUnknown* project) 00289 { 00290 AFX_MANAGE_STATE(AfxGetStaticModuleState()); 00291 00292 CComQIPtr<IMgaProject> ccpMgaProject(project); 00293 00294 if (project != NULL && ccpMgaProject == NULL) { 00295 ThrowError(CTL_E_INVALIDPROPERTYVALUE, _T("Unable to cast MgaProject.")); 00296 return; 00297 } 00298 00299 m_partBrowserDlg.SetCurrentProject(ccpMgaProject); 00300 } 00301 00302 void CPartBrowserCtrl::SetMetaModel(IUnknown* meta) 00303 { 00304 AFX_MANAGE_STATE(AfxGetStaticModuleState()); 00305 00306 CComQIPtr<IMgaMetaModel> ccpMgaMetaModel(meta); 00307 00308 if (meta != NULL && ccpMgaMetaModel == NULL) { 00309 ThrowError(CTL_E_INVALIDPROPERTYVALUE, _T("Unable to cast MgaMetaModel.")); 00310 return; 00311 } 00312 00313 m_partBrowserDlg.SetMetaModel(ccpMgaMetaModel); 00314 } 00315 00316 void CPartBrowserCtrl::SetBgColor(OLE_COLOR oleBgColor) 00317 { 00318 AFX_MANAGE_STATE(AfxGetStaticModuleState()); 00319 00320 COLORREF bgColor = TranslateColor(oleBgColor); 00321 m_partBrowserDlg.SetBgColor(bgColor); 00322 } 00323 00324 void CPartBrowserCtrl::ChangeAspect(LONG index) 00325 { 00326 AFX_MANAGE_STATE(AfxGetStaticModuleState()); 00327 00328 m_partBrowserDlg.ChangeAspect(index); 00329 } 00330 00331 void CPartBrowserCtrl::CycleAspect(void) 00332 { 00333 AFX_MANAGE_STATE(AfxGetStaticModuleState()); 00334 00335 m_partBrowserDlg.CycleAspect(); 00336 } 00337 00338 void CPartBrowserCtrl::RePaint(void) 00339 { 00340 AFX_MANAGE_STATE(AfxGetStaticModuleState()); 00341 00342 m_partBrowserDlg.PostMessage(WM_PAINT); 00343 } 00344 00345 void CPartBrowserCtrl::OnMgaObjectEvent(IMgaObject* obj, unsigned long eventmask) 00346 { 00347 CComPtr<IMgaObject> ccpMgaObject(obj); 00348 // Handling Object Events 00349 EVENT_TRACE("\n__________ Object Event Begin _________\n"); 00350 00351 #ifdef _DEBUG 00352 if (eventmask & OBJEVENT_DESTROYED) { 00353 EVENT_TRACE("OBJEVENT_DESTROYED\n"); 00354 } 00355 if (eventmask & OBJEVENT_REGISTRY) { 00356 EVENT_TRACE("OBJEVENT_REGISTRY\n"); 00357 } 00358 if (eventmask & OBJEVENT_PROPERTIES) { 00359 EVENT_TRACE("OBJEVENT_PROPERTIES\n"); 00360 } 00361 if (eventmask & OBJEVENT_CREATED) { 00362 EVENT_TRACE("OBJEVENT_CREATED\n"); 00363 } 00364 if (eventmask & OBJEVENT_ATTR) { 00365 EVENT_TRACE("OBJEVENT_ATTR\n"); 00366 } 00367 if(eventmask & OBJEVENT_NEWCHILD) { 00368 EVENT_TRACE("OBJEVENT_NEWCHILD\n"); 00369 } 00370 if(eventmask & OBJEVENT_RELATION) { 00371 EVENT_TRACE("OBJEVENT_RELATION\n"); 00372 } 00373 if(eventmask & OBJEVENT_SUBT_INST) { 00374 EVENT_TRACE("OBJEVENT_SUBT_INST\n"); 00375 } 00376 if(eventmask & OBJEVENT_PARENT) { 00377 EVENT_TRACE("OBJEVENT_PARENT\n"); 00378 } 00379 if(eventmask & OBJEVENT_LOSTCHILD) { 00380 EVENT_TRACE("OBJEVENT_LOSTCHILD\n"); 00381 } 00382 if(eventmask & OBJEVENT_REFERENCED) { 00383 EVENT_TRACE("OBJEVENT_REFERENCED\n"); 00384 } 00385 if(eventmask & OBJEVENT_CONNECTED) { 00386 EVENT_TRACE("OBJEVENT_CONNECTED\n"); 00387 } 00388 if(eventmask & OBJEVENT_SETINCLUDED) { 00389 EVENT_TRACE("OBJEVENT_SETINCLUDED\n"); 00390 } 00391 if(eventmask & OBJEVENT_REFRELEASED) { 00392 EVENT_TRACE("OBJEVENT_REFRELEASED\n"); 00393 } 00394 if(eventmask & OBJEVENT_DISCONNECTED) { 00395 EVENT_TRACE("OBJEVENT_DISCONNECTED\n"); 00396 } 00397 if(eventmask & OBJEVENT_SETEXCLUDED) { 00398 EVENT_TRACE("OBJEVENT_SETEXCLUDED\n"); 00399 } 00400 if(eventmask & OBJEVENT_USERBITS) { 00401 EVENT_TRACE("OBJEVENT_USERBITS\n"); 00402 } 00403 if(eventmask & OBJEVENT_CLOSEMODEL) { 00404 EVENT_TRACE("OBJEVENT_CLOSEMODEL\n"); 00405 } 00406 #endif /*_DEBUG */ 00407 00408 EVENT_TRACE("_________ Object Event End _______\n"); 00409 } 00410 00411 void CPartBrowserCtrl::OnMgaGlobalEvent(globalevent_enum event) 00412 { 00413 // Handling Global Events 00414 if (event == GLOBALEVENT_COMMIT_TRANSACTION) { 00415 EVENT_TRACE("GLOBALEVENT_COMMIT_TRANSACTION\n"); 00416 00417 // Send message to UI 00418 PropagateMgaMessages(); 00419 } else if (event == GLOBALEVENT_NOTIFICATION_READY) { 00420 EVENT_TRACE("GLOBALEVENT_NOTIFICATION_READY\n"); 00421 00422 // Send message to UI 00423 PropagateMgaMessages(); 00424 } else if (event == GLOBALEVENT_ABORT_TRANSACTION) { 00425 EVENT_TRACE("GLOBALEVENT_ABORT_TRANSACTION\n"); 00426 00427 // Removing the elements 00428 m_MgaObjectEventList.RemoveAll(); 00429 } else if (event == GLOBALEVENT_UNDO) { 00430 EVENT_TRACE("GLOBALEVENT_UNDO\n"); 00431 // Refresh 00432 } else if (event==GLOBALEVENT_REDO) { 00433 EVENT_TRACE("GLOBALEVENT_REDO\n"); 00434 // Refresh 00435 } 00436 00437 // Not handled messages are not in the release 00438 // but useful for development 00439 #ifdef _DEBUG 00440 if (event == GLOBALEVENT_PROJECT_PROPERTIES) { 00441 EVENT_TRACE("GLOBALEVENT_PROJECT_PROPERTIES\n"); 00442 } 00443 if (event == GLOBALEVENT_OPEN_PROJECT) { 00444 EVENT_TRACE("GLOBALEVENT_OPEN_PROJECT\n"); 00445 } 00446 if (event == GLOBALEVENT_CLOSE_PROJECT) { 00447 EVENT_TRACE("GLOBALEVENT_CLOSE_PROJECT\n"); 00448 } 00449 if (event == GLOBALEVENT_NEW_TERRITORY) { 00450 EVENT_TRACE("GLOBALEVENT_NEW_TERRITORY\n"); 00451 } 00452 if (event == GLOBALEVENT_DESTROY_TERRITORY) { 00453 EVENT_TRACE("GLOBALEVENT_DESTROY_TERRITORY\n"); 00454 } 00455 00456 #endif /* _DEBUG */ 00457 00458 EVENT_TRACE("_________ Global Event End _________\n"); 00459 } 00460 00461 void CPartBrowserCtrl::SendAspectChanged(LONG index) 00462 { 00463 this->FireAspectChanged(index); 00464 } 00465 00466 void CPartBrowserCtrl::PropagateMgaMessages() 00467 { 00468 // Iterating through the list 00469 while (!m_MgaObjectEventList.IsEmpty()) { 00470 CMgaObjectEventWrapper* pEventWrapper = 00471 (CMgaObjectEventWrapper*)m_MgaObjectEventList.RemoveHead(); 00472 // Propagating message to AggregatePropertyPage 00473 00474 OnMgaObjectEvent(pEventWrapper->m_ccpMgaObject, pEventWrapper->m_eventmask); 00475 00476 delete pEventWrapper; 00477 } 00478 } 00479