GME  13
GMEActiveBrowserCtl.cpp
Go to the documentation of this file.
00001 // GMEActiveBrowserCtl.cpp : Implementation of the CGMEActiveBrowserCtrl ActiveX Control class.
00002 
00003 #include "stdafx.h"
00004 #include "GMEActiveBrowser.h"
00005 #include "GMEActiveBrowserCtl.h"
00006 #include "GMEActiveBrowserPpg.h"
00007 #include "Mga_i.c"
00008 
00009 #ifdef _DEBUG
00010 #define new DEBUG_NEW
00011 #undef THIS_FILE
00012 static char THIS_FILE[] = __FILE__;
00013 #endif
00014 
00015 
00016 
00017 
00018 IMPLEMENT_DYNCREATE(CGMEActiveBrowserCtrl, COleControl)
00019 
00020 
00021 
00022 // Message map
00023 
00024 BEGIN_MESSAGE_MAP(CGMEActiveBrowserCtrl, COleControl)
00025         //{{AFX_MSG_MAP(CGMEActiveBrowserCtrl)
00026         ON_WM_CREATE()
00027         ON_WM_WINDOWPOSCHANGED()
00028         //}}AFX_MSG_MAP
00029         ON_OLEVERB(AFX_IDS_VERB_EDIT, OnEdit)
00030         ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
00031 END_MESSAGE_MAP()
00032 
00033 
00035 // Dispatch map
00036 
00037 BEGIN_DISPATCH_MAP(CGMEActiveBrowserCtrl, COleControl)
00038         //{{AFX_DISPATCH_MAP(CGMEActiveBrowserCtrl)
00039         DISP_FUNCTION(CGMEActiveBrowserCtrl, "SetCurrentProject", SetCurrentProject, VT_I2, VTS_UNKNOWN)
00040         DISP_FUNCTION(CGMEActiveBrowserCtrl, "CloseCurrentProject", CloseCurrentProject, VT_I2, VTS_NONE)
00041         DISP_FUNCTION(CGMEActiveBrowserCtrl, "RefreshAll", RefreshAll, VT_EMPTY, VTS_NONE)
00042         DISP_FUNCTION(CGMEActiveBrowserCtrl, "GetSelectedMgaObjects", GetSelectedMgaObjects, VT_UNKNOWN, VTS_NONE)
00043         DISP_FUNCTION(CGMEActiveBrowserCtrl, "OpenProject", OpenProject, VT_EMPTY, VTS_BSTR)
00044         DISP_FUNCTION(CGMEActiveBrowserCtrl, "FocusItem", FocusItem, VT_EMPTY, VTS_BSTR)
00045         DISP_FUNCTION(CGMEActiveBrowserCtrl, "OpenItem", OpenItem, VT_EMPTY, VTS_BSTR)
00046         DISP_FUNCTION(CGMEActiveBrowserCtrl, "OpenSubtree", OpenSubtree, VT_EMPTY, VTS_BSTR)
00047         DISP_FUNCTION(CGMEActiveBrowserCtrl, "CloseSubtree", CloseSubtree, VT_EMPTY, VTS_BSTR)
00048         DISP_FUNCTION(CGMEActiveBrowserCtrl, "Up", Up, VT_EMPTY, VTS_NONE)
00049         DISP_FUNCTION(CGMEActiveBrowserCtrl, "Down", Down, VT_EMPTY, VTS_NONE)
00050         DISP_FUNCTION(CGMEActiveBrowserCtrl, "ChangePropPage", ChangePropPage, VT_EMPTY, VTS_I2)
00051         //}}AFX_DISPATCH_MAP
00052         DISP_FUNCTION(CGMEActiveBrowserCtrl, "HighlightItem", HighlightItem, VT_EMPTY, VTS_UNKNOWN VTS_I4)
00053 END_DISPATCH_MAP()
00054 
00055 
00057 // Event map
00058 
00059 BEGIN_EVENT_MAP(CGMEActiveBrowserCtrl, COleControl)
00060         //{{AFX_EVENT_MAP(CGMEActiveBrowserCtrl)
00061         EVENT_CUSTOM("DblClickMgaObject", FireDblClickMgaObject, VTS_UNKNOWN)
00062         EVENT_CUSTOM("ShowAttributes", FireShowAttributes, VTS_UNKNOWN)
00063         EVENT_CUSTOM("ShowPreferences", FireShowPreferences, VTS_UNKNOWN)
00064         EVENT_CUSTOM("ShowProperties", FireShowProperties, VTS_NONE)
00065         EVENT_CUSTOM("ClickMgaObject", FireClickMgaObject, VTS_UNKNOWN)
00066         EVENT_CUSTOM("ShowInParentMgaObject", FireShowInParentMgaObject, VTS_UNKNOWN)
00067         EVENT_CUSTOM("RootFolderNameChanged", FireRootFolderNameChanged, VTS_NONE)
00068         EVENT_CUSTOM("ShowFindDlg", FireShowFindDlg, VTS_NONE)
00069         EVENT_CUSTOM("ShowObjInspDlg", FireShowObjInspDlg, VTS_NONE)
00070         EVENT_CUSTOM("CycleObjInsp", CycleObjInsp, VTS_BOOL)
00071         //}}AFX_EVENT_MAP
00072 END_EVENT_MAP()
00073 
00075 // Native COM interface map - peter
00076 BEGIN_INTERFACE_MAP(CGMEActiveBrowserCtrl, COleControl)
00077         INTERFACE_PART(CGMEActiveBrowserCtrl, IID_IMgaEventSink, EventSink)
00078 END_INTERFACE_MAP()
00079 
00080 
00082 // Property pages
00083 
00084 // TODO: Add more property pages as needed.  Remember to increase the count!
00085 BEGIN_PROPPAGEIDS(CGMEActiveBrowserCtrl, 1)
00086         PROPPAGEID(CGMEActiveBrowserPropPage::guid)
00087 END_PROPPAGEIDS(CGMEActiveBrowserCtrl)
00088 
00089 
00091 // Initialize class factory and guid
00092 
00093 IMPLEMENT_OLECREATE_EX(CGMEActiveBrowserCtrl, "GME.GMEActiveBrowserCtrl.1",
00094         0xdd4f2deb, 0xd064, 0x4844, 0x9e, 0xe1, 0x4, 0x67, 0x3c, 0x87, 0x2e, 0x7b)
00095 
00096 
00098 // Type library ID and version
00099 
00100 IMPLEMENT_OLETYPELIB(CGMEActiveBrowserCtrl, _tlid, _wVerMajor, _wVerMinor)
00101 
00102 
00104 // Interface IDs
00105 
00106 const IID BASED_CODE IID_DGMEActiveBrowser =
00107                 { 0x9d345706, 0xde7, 0x4a6a, { 0xb3, 0x2a, 0xdd, 0x1b, 0xb2, 0xf8, 0xb8, 0x1f } };
00108 const IID BASED_CODE IID_DGMEActiveBrowserEvents =
00109                 { 0x9953ea94, 0x3294, 0x4f9e, { 0xbf, 0x48, 0x99, 0xae, 0x7f, 0x47, 0x3, 0x8b } };
00110 
00111 
00113 // Control type information
00114 
00115 static const DWORD BASED_CODE _dwGMEActiveBrowserOleMisc =
00116         OLEMISC_ACTIVATEWHENVISIBLE |
00117         OLEMISC_IGNOREACTIVATEWHENVISIBLE |     // TODO: this ignores the previous value, why is this needed?
00118         OLEMISC_SETCLIENTSITEFIRST |
00119         OLEMISC_INSIDEOUT |
00120         OLEMISC_CANTLINKINSIDE |
00121         OLEMISC_RECOMPOSEONRESIZE;
00122 
00123 IMPLEMENT_OLECTLTYPE(CGMEActiveBrowserCtrl, IDS_GMEACTIVEBROWSER, _dwGMEActiveBrowserOleMisc)
00124 
00125 
00126 
00127 // CGMEActiveBrowserCtrl::CGMEActiveBrowserCtrlFactory::UpdateRegistry -
00128 // Adds or removes system registry entries for CGMEActiveBrowserCtrl
00129 
00130 BOOL CGMEActiveBrowserCtrl::CGMEActiveBrowserCtrlFactory::UpdateRegistry(BOOL bRegister)
00131 {
00132         // TODO: Verify that your control follows apartment-model threading rules.
00133         // Refer to MFC TechNote 64 for more information.
00134         // If your control does not conform to the apartment-model rules, then
00135         // you must modify the code below, changing the 6th parameter from
00136         // afxRegInsertable | afxRegApartmentThreading to afxRegInsertable.
00137 
00138         if (bRegister)
00139                 return AfxOleRegisterControlClass(
00140                         AfxGetInstanceHandle(),
00141                         m_clsid,
00142                         m_lpszProgID,
00143                         IDS_GMEACTIVEBROWSER,
00144                         IDB_GMEACTIVEBROWSER,
00145                         afxRegInsertable | afxRegApartmentThreading,
00146                         _dwGMEActiveBrowserOleMisc,
00147                         _tlid,
00148                         _wVerMajor,
00149                         _wVerMinor);
00150         else
00151                 return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
00152 }
00153 
00154 
00156 // CGMEActiveBrowserCtrl::XEventSink - native COM interface - peter
00157 STDMETHODIMP_(ULONG) CGMEActiveBrowserCtrl::XEventSink::AddRef()
00158 {
00159         METHOD_PROLOGUE(CGMEActiveBrowserCtrl,EventSink)
00160         return pThis->ExternalAddRef();
00161 }
00162 
00163 STDMETHODIMP_(ULONG) CGMEActiveBrowserCtrl::XEventSink::Release()
00164 {
00165         METHOD_PROLOGUE(CGMEActiveBrowserCtrl,EventSink)
00166         return pThis->ExternalRelease();
00167 }
00168 
00169 STDMETHODIMP CGMEActiveBrowserCtrl::XEventSink::QueryInterface(REFIID riid, void** ppv)
00170 {
00171         METHOD_PROLOGUE(CGMEActiveBrowserCtrl,EventSink)
00172         return pThis->ExternalQueryInterface(&riid, ppv);
00173 }
00174 
00175 STDMETHODIMP CGMEActiveBrowserCtrl::XEventSink::GlobalEvent(globalevent_enum event)
00176 {
00177         METHOD_PROLOGUE(CGMEActiveBrowserCtrl,EventSink)
00178 
00179         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
00180         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
00181 
00182         // Stopping transaction handling
00183         pMgaContext->SetEventTransactionMode(true);
00184 
00185         // Forwarding MGA messages to the control
00186         pThis->OnMgaGlobalEvent(event);
00187 
00188         // Starting transaction handling
00189         pMgaContext->SetEventTransactionMode(false);
00190         return S_OK;
00191 }
00192 
00193 STDMETHODIMP CGMEActiveBrowserCtrl::XEventSink::ObjectEvent(IMgaObject * obj, unsigned long eventmask, VARIANT v)
00194 {
00195         METHOD_PROLOGUE(CGMEActiveBrowserCtrl,EventSink)
00196 
00197         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
00198         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
00199 
00200 
00201         // Stopping transaction handling
00202         pMgaContext->SetEventTransactionMode(TRUE);
00203 
00204         // Forwarding MGA messages to the control
00205         pThis->OnMgaObjectEvent(obj, eventmask, v);
00206 
00207         // Starting transaction handling
00208         pMgaContext->SetEventTransactionMode(FALSE);
00209 
00210         return S_OK;
00211 }
00212 
00213 
00214 
00216 // CGMEActiveBrowserCtrl::CGMEActiveBrowserCtrl - Constructor
00217 
00218 CGMEActiveBrowserCtrl::CGMEActiveBrowserCtrl()
00219 {
00220         InitializeIIDs(&IID_DGMEActiveBrowser, &IID_DGMEActiveBrowserEvents);
00221         
00222         m_pApp=(CGMEActiveBrowserApp*)AfxGetApp();
00223         m_pApp->SetCtrl(this);
00224         m_pPropFrame=NULL;
00225 
00226 
00227         
00228 }
00229 
00230 
00232 // CGMEActiveBrowserCtrl::~CGMEActiveBrowserCtrl - Destructor
00233 
00234 CGMEActiveBrowserCtrl::~CGMEActiveBrowserCtrl()
00235 {
00236         // TODO: Cleanup your control's instance data here.     
00237 
00238 
00239 }
00240 
00241 
00243 // CGMEActiveBrowserCtrl::OnDraw - Drawing function
00244 
00245 void CGMEActiveBrowserCtrl::OnDraw( CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
00246 {
00247         if (m_pPropFrame != NULL) {
00248                 m_pPropFrame->MoveWindow(rcBounds, TRUE);
00249         } else {
00250                 pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH) GetStockObject(WHITE_BRUSH)));
00251                 pdc->TextOut(rcBounds.left + 1, rcBounds.top + 1, _T("GME ActiveBrowser"));
00252         }
00253 }
00254 
00255 
00257 // CGMEActiveBrowserCtrl::DoPropExchange - Persistence support
00258 
00259 void CGMEActiveBrowserCtrl::DoPropExchange(CPropExchange* pPX)
00260 {
00261         ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
00262         COleControl::DoPropExchange(pPX);
00263 
00264         // TODO: Call PX_ functions for each persistent custom property.
00265 
00266 }
00267 
00268 
00270 // CGMEActiveBrowserCtrl::GetControlFlags -
00271 // Flags to customize MFC's implementation of ActiveX controls.
00272 //
00273 // For information on using these flags, please see MFC technical note
00274 // #nnn, "Optimizing an ActiveX Control".
00275 DWORD CGMEActiveBrowserCtrl::GetControlFlags()
00276 {
00277         DWORD dwFlags = COleControl::GetControlFlags();
00278 
00279 
00280         // The control can receive mouse notifications when inactive.
00281         // TODO: if you write handlers for WM_SETCURSOR and WM_MOUSEMOVE,
00282         //              avoid using the m_hWnd member variable without first
00283         //              checking that its value is non-NULL.
00284         dwFlags |= pointerInactive;
00285         return dwFlags;
00286 }
00287 
00288 
00290 // CGMEActiveBrowserCtrl::OnResetState - Reset control to default state
00291 
00292 void CGMEActiveBrowserCtrl::OnResetState()
00293 {
00294         COleControl::OnResetState();  // Resets defaults found in DoPropExchange
00295 
00296         // TODO: Reset any other control state here.
00297 }
00298 
00299 
00301 // CGMEActiveBrowserCtrl message handlers
00302 
00303 int CGMEActiveBrowserCtrl::CreateActiveBrowser()
00304 {
00305         if (m_pPropFrame == NULL) {
00306                 m_pPropFrame = new CActiveBrowserPropertyFrame;
00307                 CRect rect(0, 0, 0, 0);
00308                 CString strTitle;
00309                 VERIFY(strTitle.LoadString(IDS_PROPSHT_CAPTION));
00310 
00311                 if (!m_pPropFrame->CreateEx(WS_EX_CONTROLPARENT, NULL, strTitle,  WS_CHILD, rect, this)) {
00312                         delete m_pPropFrame;
00313                         m_pPropFrame = NULL;
00314                         return -1;
00315                 }
00316         }
00317 
00318         // Before unhiding the modeless property sheet, update its
00319         // settings appropriately.  For example, if you are reflecting
00320         // the state of the currently selected item, pick up that
00321         // information from the active view and change the property
00322         // sheet settings now.
00323 
00324         if (m_pPropFrame != NULL && !m_pPropFrame->IsWindowVisible())
00325                 m_pPropFrame->ShowWindow(SW_SHOW);
00326         
00327         return 0;
00328 }
00329 
00330 int CGMEActiveBrowserCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
00331 {
00332         if (COleControl::OnCreate(lpCreateStruct) == -1)
00333                 return -1;
00334 
00335         return CreateActiveBrowser();
00336 }
00337 
00338 short CGMEActiveBrowserCtrl::SetCurrentProject(LPUNKNOWN pMgaProject) 
00339 {
00340         return m_pApp->m_CurrentProject.CreateCurrentProject(pMgaProject);
00341 }
00342 
00343 short CGMEActiveBrowserCtrl::CloseCurrentProject() 
00344 {
00345         m_pApp->m_CurrentProject.CloseCurrentProject();
00346         return 0;
00347 }
00348 
00349 void CGMEActiveBrowserCtrl::RefreshAll() 
00350 {
00351         m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.Refresh();
00352 }
00353 
00354 
00355 LPUNKNOWN CGMEActiveBrowserCtrl::GetSelectedMgaObjects() 
00356 {
00357         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
00358         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
00359 
00360         CMgaMappedTreeCtrlBase* pTreeCtrl = &m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.m_TreeAggregate;
00361 
00362         if( 1 == m_pPropFrame->m_pModelessPropSheet->GetActiveIndex()) // if the INHER tree is active use that tree
00363                 pTreeCtrl = &m_pPropFrame->m_pModelessPropSheet->m_PageInheritance.m_TreeInheritance;
00364         
00365 
00366         CComPtr<IMgaObjects> ccpSelectedObjects;
00367 
00368         try
00369         {
00370                 pMgaContext->BeginTransaction(true);
00371                 
00372                 COMTHROW(ccpSelectedObjects.CoCreateInstance(L"Mga.MgaObjects"));
00373                 
00374                 HTREEITEM hItem=pTreeCtrl->GetFirstSelectedItem();
00375 
00376                 while(hItem)
00377                 {
00378                         LPUNKNOWN pUnknown;
00379                         pTreeCtrl->LookupObjectUnknown(hItem, pUnknown);
00380                         CComQIPtr<IMgaObject> ccpMgaObject(pUnknown);
00381                         
00382                         ASSERT(ccpMgaObject!=NULL);
00383                         COMTHROW(ccpSelectedObjects->Append(ccpMgaObject));
00384 
00385                         hItem=pTreeCtrl->GetNextSelectedItem(hItem);
00386                 }
00387                 
00388 
00389                 pMgaContext->CommitTransaction();
00390         }
00391         catch (hresult_exception& )
00392         {
00393                 pMgaContext->AbortTransaction();
00394         }
00395 
00396         return ccpSelectedObjects.Detach();
00397 }
00398 
00399 
00400 void CGMEActiveBrowserCtrl::FocusItem(BSTR Id) 
00401 {
00402         m_pPropFrame->m_pModelessPropSheet->SetActivePage(0);
00403         m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.GotoIUnk(Id);
00404 }
00405 
00406 
00407 void CGMEActiveBrowserCtrl::OpenItem(BSTR Id) 
00408 {
00409         // focus + enter
00410         m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.GotoIUnk(Id);
00411         m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.m_TreeAggregate.SendMessage(WM_KEYDOWN, (WPARAM)VK_RETURN, (LPARAM)0);
00412 }
00413 
00414 void CGMEActiveBrowserCtrl::OpenSubtree(BSTR Id) 
00415 {
00416          // focus + '+'
00417         m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.GotoIUnk(Id);
00418         m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.m_TreeAggregate.SendMessage(WM_KEYDOWN, (WPARAM)107, (LPARAM)0);
00419 }
00420 
00421 void CGMEActiveBrowserCtrl::CloseSubtree(BSTR Id) 
00422 {
00423          // focus + '-'
00424         m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.GotoIUnk(Id);
00425         m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.m_TreeAggregate.SendMessage(WM_KEYDOWN, (WPARAM)109, (LPARAM)0);
00426 }
00427 
00428 void CGMEActiveBrowserCtrl::Up() 
00429 {
00430         m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.m_TreeAggregate.SendMessage(WM_KEYDOWN, (WPARAM)VK_UP, (LPARAM)0);
00431 }
00432 
00433 void CGMEActiveBrowserCtrl::Down() 
00434 {
00435         m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.m_TreeAggregate.SendMessage(WM_KEYDOWN, (WPARAM)VK_DOWN, (LPARAM)0);
00436 }
00437 
00438 void CGMEActiveBrowserCtrl::ChangePropPage(browser_page page) 
00439 {
00440          switch (page)
00441          {
00442          case   MODE_AGGRE:
00443                  m_pPropFrame->m_pModelessPropSheet->SetActivePage(0);
00444                  break;
00445          case   MODE_INHERI:
00446                  m_pPropFrame->m_pModelessPropSheet->SetActivePage(1);
00447                  break;
00448          case   MODE_META:
00449                  m_pPropFrame->m_pModelessPropSheet->SetActivePage(2);
00450                  break;
00451          }
00452 }
00453 
00454 void CGMEActiveBrowserCtrl::OnMgaObjectEvent(IMgaObject * obj, unsigned long eventmask, VARIANT v)
00455 {
00456 
00457         m_MgaObjectEventList.Add(obj,eventmask);
00458 
00459 #ifdef _DEBUG
00460         EVENT_TRACE("\n__________ Object Event Begin _________\n");
00461 
00462         // Handling Object Events
00463         if(eventmask&OBJEVENT_CREATED)
00464         {
00465                 EVENT_TRACE("OBJEVENT_CREATED\n");
00466 
00467         }
00468         if(eventmask&OBJEVENT_DESTROYED)
00469         {
00470                 EVENT_TRACE("OBJEVENT_DESTROYED\n");
00471 
00472         }
00473         if(eventmask&OBJEVENT_ATTR)
00474         {
00475                 EVENT_TRACE("OBJEVENT_ATTR\n");
00476 
00477         }
00478         if(eventmask&OBJEVENT_REGISTRY)
00479         {
00480                 EVENT_TRACE("OBJEVENT_REGISTRY\n");
00481         }
00482         if(eventmask&OBJEVENT_NEWCHILD)
00483         {
00484                 EVENT_TRACE("OBJEVENT_NEWCHILD\n");
00485         }
00486         if(eventmask&OBJEVENT_RELATION)
00487         {
00488                 EVENT_TRACE("OBJEVENT_RELATION\n");
00489         }
00490         if(eventmask&OBJEVENT_PROPERTIES)
00491         {
00492                 EVENT_TRACE("OBJEVENT_PROPERTIES\n");
00493         }
00494         if(eventmask&OBJEVENT_SUBT_INST)
00495         {
00496                 EVENT_TRACE("OBJEVENT_SUBT_INST\n");
00497         }
00498         if(eventmask&OBJEVENT_PARENT)
00499         {
00500                 EVENT_TRACE("OBJEVENT_PARENT\n");
00501         }
00502         if(eventmask&OBJEVENT_LOSTCHILD)
00503         {
00504                 EVENT_TRACE("OBJEVENT_LOSTCHILD\n");
00505         }
00506         if(eventmask&OBJEVENT_REFERENCED)
00507         {
00508                 EVENT_TRACE("OBJEVENT_REFERENCED\n");
00509         }
00510         if(eventmask&OBJEVENT_CONNECTED)
00511         {
00512                 EVENT_TRACE("OBJEVENT_CONNECTED\n");
00513         }
00514         if(eventmask&OBJEVENT_SETINCLUDED)
00515         {
00516                 EVENT_TRACE("OBJEVENT_SETINCLUDED\n");
00517         }
00518         if(eventmask&OBJEVENT_REFRELEASED)
00519         {
00520                 EVENT_TRACE("OBJEVENT_REFRELEASED\n");
00521         }
00522         if(eventmask&OBJEVENT_DISCONNECTED)
00523         {
00524                 EVENT_TRACE("OBJEVENT_DISCONNECTED\n");
00525         }
00526         if(eventmask&OBJEVENT_SETEXCLUDED)
00527         {
00528                 EVENT_TRACE("OBJEVENT_SETEXCLUDED\n");
00529         }
00530         if(eventmask&OBJEVENT_USERBITS)
00531         {
00532                 EVENT_TRACE("OBJEVENT_USERBITS\n");
00533         }
00534         if(eventmask&OBJEVENT_CLOSEMODEL)
00535         {
00536                 EVENT_TRACE("OBJEVENT_CLOSEMODEL\n");
00537         }
00538 #endif /*_DEBUG */
00539 
00540         EVENT_TRACE("_________ Object Event End _______\n");
00541 
00542 }
00543 
00544 
00545 void CGMEActiveBrowserCtrl::OnMgaGlobalEvent(globalevent_enum event)
00546 {
00547         EVENT_TRACE("\n________ Global Event Begin _________\n");
00548 
00549         // Handling Global Events
00550         if(event==GLOBALEVENT_COMMIT_TRANSACTION)
00551         {
00552                 EVENT_TRACE("GLOBALEVENT_COMMIT_TRANSACTION\n");
00553 
00554                 // Send message to UI
00555                 PropagateMgaMessages();
00556         }
00557         else if(event==GLOBALEVENT_NOTIFICATION_READY)
00558         {
00559                 EVENT_TRACE("GLOBALEVENT_NOTIFICATION_READY\n");
00560 
00561                 // Send message to UI
00562                 PropagateMgaMessages();
00563         }
00564         else if(event==GLOBALEVENT_ABORT_TRANSACTION)
00565         {
00566                 EVENT_TRACE("GLOBALEVENT_ABORT_TRANSACTION\n");
00567 
00568         //m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.Refresh();
00569 
00570                 // Removing the elements
00571                 m_MgaObjectEventList.RemoveAll();
00572 
00573                 m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.Refresh();
00574                 m_pPropFrame->m_pModelessPropSheet->m_PageInheritance.Refresh();
00575         }
00576         else if(event==GLOBALEVENT_UNDO)
00577         {
00578                 EVENT_TRACE("GLOBALEVENT_UNDO\n");
00579                 m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.Refresh();
00580                 m_pPropFrame->m_pModelessPropSheet->m_PageInheritance.Refresh();
00581         }
00582         else if(event==GLOBALEVENT_REDO)
00583         {
00584                 m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.Refresh();
00585                 m_pPropFrame->m_pModelessPropSheet->m_PageInheritance.Refresh();
00586                 EVENT_TRACE("GLOBALEVENT_REDO\n");
00587         }
00588 
00589         // Not handled messages are not in the release
00590         // but useful for development
00591 #ifdef _DEBUG
00592         if(event==GLOBALEVENT_PROJECT_PROPERTIES)
00593         {
00594                 EVENT_TRACE("GLOBALEVENT_PROJECT_PROPERTIES\n");
00595         }
00596 
00597         if(event==GLOBALEVENT_OPEN_PROJECT)
00598         {
00599                 EVENT_TRACE("GLOBALEVENT_OPEN_PROJECT\n");
00600         }
00601         if(event==GLOBALEVENT_CLOSE_PROJECT)
00602         {
00603                 EVENT_TRACE("GLOBALEVENT_CLOSE_PROJECT\n");
00604         }
00605         if(event==GLOBALEVENT_NEW_TERRITORY)
00606         {
00607                 EVENT_TRACE("GLOBALEVENT_NEW_TERRITORY\n");
00608         }
00609         if(event==GLOBALEVENT_DESTROY_TERRITORY)
00610         {
00611                 EVENT_TRACE("GLOBALEVENT_DESTROY_TERRITORY\n");
00612         }
00613         if(event==APPEVENT_XML_IMPORT_BEGIN)
00614         {
00615                 EVENT_TRACE("APPEVENT_XML_IMPORT_BEGIN\n");
00616         }
00617         if(event==APPEVENT_XML_IMPORT_END)
00618         {
00619                 EVENT_TRACE("APPEVENT_XML_IMPORT_END\n");
00620         }
00621         if(event==APPEVENT_XML_IMPORT_FCOS_BEGIN)
00622         {
00623                 EVENT_TRACE("APPEVENT_XML_IMPORT_FCOS_BEGIN\n");
00624         }
00625         if(event==APPEVENT_XML_IMPORT_FCOS_END)
00626         {
00627                 EVENT_TRACE("APPEVENT_XML_IMPORT_FCOS_END\n");
00628         }
00629         if(event==APPEVENT_XML_IMPORT_SPECIAL_BEGIN)
00630         {
00631                 EVENT_TRACE("APPEVENT_XML_IMPORT_SPECIAL_BEGIN\n");
00632         }
00633         if(event==APPEVENT_XML_IMPORT_SPECIAL_END)
00634         {
00635                 EVENT_TRACE("APPEVENT_XML_IMPORT_SPECIAL_END\n");
00636         }
00637 
00638 #endif /* _DEBUG */
00639 
00640         EVENT_TRACE("_________ Global Event End _________\n");
00641         
00642 
00643 }
00644 
00645 void CGMEActiveBrowserCtrl::PropagateMgaMessages()
00646 {
00647         // Iterating through the list
00648         while(!m_MgaObjectEventList.IsEmpty())
00649         {
00650                 CMgaObjectEventWrapper* pEventWrapper=
00651                         (CMgaObjectEventWrapper*)m_MgaObjectEventList.RemoveHead();
00652                 // Propagating message to AggregatePropertyPage
00653                 m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.OnMgaEvent\
00654                                                 (pEventWrapper->m_ccpMgaObject,pEventWrapper->m_eventmask);
00655 
00656                 // ... and to the InheritancePropertyPage as well
00657                 m_pPropFrame->m_pModelessPropSheet->m_PageInheritance.OnMgaEvent\
00658                                                 (pEventWrapper->m_ccpMgaObject,pEventWrapper->m_eventmask);
00659 
00660                 delete pEventWrapper;
00661         }
00662 }
00663 
00664 
00665 void CGMEActiveBrowserCtrl::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos) 
00666 {
00667         COleControl::OnWindowPosChanged(lpwndpos);
00668 
00669         CRect clientRect;
00670         GetClientRect(clientRect);
00671 
00672         m_pPropFrame->MoveWindow(clientRect, TRUE);
00673 }
00674 
00675 
00676 void CGMEActiveBrowserCtrl::OpenProject(LPCTSTR pProjectName) 
00677 {
00678         
00679         CComPtr<IMgaProject> ccpMgaProject;
00680         try
00681         {
00682                 COMTHROW(ccpMgaProject.CoCreateInstance(OLESTR("Mga.MgaProject")));
00683         
00684                 VARIANT_BOOL vtbMode;   
00685                 CComBSTR bszProjectName(pProjectName);
00686         
00687                 COMTHROW(ccpMgaProject->Open(bszProjectName, &vtbMode));
00688                 SetCurrentProject(ccpMgaProject);
00689 
00690         }catch (hresult_exception &)
00691         {
00692                 MessageBox(_T("Error opening project"),_T("Error"),MB_ICONERROR|MB_OK);
00693         }
00694 
00695 }
00696 
00697 BOOL CGMEActiveBrowserCtrl::PreCreateWindow(CREATESTRUCT& cs) 
00698 {
00699         cs.dwExStyle |= WS_EX_CONTROLPARENT;
00700         return COleControl::PreCreateWindow(cs);
00701 }
00702 
00703 
00704 void CGMEActiveBrowserCtrl::HighlightItem(IUnknown* item, int highlight)
00705 {
00706         if (item == nullptr)
00707                 AfxThrowOleDispatchException(201, _T("First parameter must not be null."));
00708         CComPtr<IMgaObject> object;
00709         item->QueryInterface(&object.p);
00710         if (!object)
00711                 AfxThrowOleDispatchException(202, L"First parameter is of wrong type. It must be IMgaObject.");
00712 
00713         CGMEActiveBrowserApp* pApp = (CGMEActiveBrowserApp*)AfxGetApp();
00714         try
00715         {
00716                 if (pApp)
00717                 {
00718                         pApp->m_CurrentProject.m_MgaContext.SetEventTransactionMode(true);
00719                         try
00720                         {
00721                                 m_pPropFrame->m_pModelessPropSheet->m_PageAggregate.HighlightItem(object, highlight);
00722                         }
00723                         catch (...)
00724                         {
00725                                 pApp->m_CurrentProject.m_MgaContext.SetEventTransactionMode(false);
00726                                 throw;
00727                         }
00728                         pApp->m_CurrentProject.m_MgaContext.SetEventTransactionMode(false);
00729                 }
00730         }
00731         catch (const _com_error& e)
00732         {
00733                 AfxThrowOleDispatchException(203, e.Description());
00734         }
00735 }