GME  13
ObjectInspectorCtl.cpp
Go to the documentation of this file.
00001 // ObjectInspectorCtl.cpp : Implementation of the CObjectInspectorCtrl ActiveX Control class.
00002 
00003 #include "stdafx.h"
00004 #include "ObjectInspector.h"
00005 #include "ObjectInspectorCtl.h"
00006 #include "ObjectInspectorPpg.h"
00007 #include "Preference.h"
00008 #include "Mga_i.c"
00009 
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015 
00016 IMPLEMENT_DYNCREATE(CObjectInspectorCtrl, COleControl)
00017 
00018 
00019 
00020 // Message map
00021 
00022 BEGIN_MESSAGE_MAP(CObjectInspectorCtrl, COleControl)
00023         //{{AFX_MSG_MAP(CObjectInspectorCtrl)
00024         ON_WM_CREATE()
00025         //}}AFX_MSG_MAP
00026         ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
00027 END_MESSAGE_MAP()
00028 
00029 
00031 // Dispatch map
00032 
00033 BEGIN_DISPATCH_MAP(CObjectInspectorCtrl, COleControl)
00034         //{{AFX_DISPATCH_MAP(CObjectInspectorCtrl)
00035         DISP_PROPERTY_EX(CObjectInspectorCtrl, "MgaProject", GetMgaProject, SetMgaProject, VT_UNKNOWN)
00036         DISP_PROPERTY_EX(CObjectInspectorCtrl, "MgaObject", GetMgaObjects, SetMgaObjects, VT_UNKNOWN)
00037         DISP_FUNCTION(CObjectInspectorCtrl, "ShowPanel", ShowPanel, VT_EMPTY, VTS_I4)
00038         DISP_FUNCTION(CObjectInspectorCtrl, "EditName", EditName, VT_EMPTY, VTS_NONE)
00039         DISP_FUNCTION_ID(CObjectInspectorCtrl, "CyclePanel", dispidCyclePanel, CyclePanel, VT_EMPTY, VTS_BOOL)
00040         //}}AFX_DISPATCH_MAP
00041         DISP_FUNCTION_ID(CObjectInspectorCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
00042 END_DISPATCH_MAP()
00043 
00044 
00046 // Event map
00047 
00048 BEGIN_EVENT_MAP(CObjectInspectorCtrl, COleControl)
00049         //{{AFX_EVENT_MAP(CObjectInspectorCtrl)
00050         EVENT_CUSTOM("RootFolderNameChanged", FireRootFolderNameChanged, VTS_NONE)
00051         EVENT_CUSTOM("ConvertPathToCustom", FireConvertPathToCustom, VTS_UNKNOWN)
00052         //}}AFX_EVENT_MAP
00053 END_EVENT_MAP()
00054 
00056 // Native COM interface map - peter
00057 BEGIN_INTERFACE_MAP(CObjectInspectorCtrl, COleControl)
00058         INTERFACE_PART(CObjectInspectorCtrl, IID_IMgaEventSink, EventSink)
00059 END_INTERFACE_MAP()
00060 
00062 // Property pages
00063 
00064 // TODO: Add more property pages as needed.  Remember to increase the count!
00065 BEGIN_PROPPAGEIDS(CObjectInspectorCtrl, 1)
00066         PROPPAGEID(CObjectInspectorPropPage::guid)
00067 END_PROPPAGEIDS(CObjectInspectorCtrl)
00068 
00069 
00071 // Initialize class factory and guid
00072 
00073 IMPLEMENT_OLECREATE_EX(CObjectInspectorCtrl, "GME.ObjectInspectorCtrl.1",
00074         0xb786f53c, 0x297f, 0x4db8, 0x80, 0x60, 0xd4, 0x50, 0x57, 0x21, 0x7a, 0xee)
00075 
00076 
00078 // Type library ID and version
00079 
00080 IMPLEMENT_OLETYPELIB(CObjectInspectorCtrl, _tlid, _wVerMajor, _wVerMinor)
00081 
00082 
00084 // Interface IDs
00085 
00086 const IID BASED_CODE IID_DObjectInspector =
00087                 { 0xa7dc846c, 0xdae3, 0x4b3f, { 0xb9, 0x47, 0x71, 0xd8, 0x5b, 0x5f, 0x64, 0x37 } };
00088 const IID BASED_CODE IID_DObjectInspectorEvents =
00089                 { 0xb2858a8, 0x321a, 0x43e1, { 0x99, 0x9d, 0x68, 0x6b, 0x8e, 0xfc, 0xa, 0xf2 } };
00090 
00091 
00093 // Control type information
00094 
00095 static const DWORD BASED_CODE _dwObjectInspectorOleMisc =
00096         OLEMISC_ACTIVATEWHENVISIBLE |
00097         OLEMISC_SETCLIENTSITEFIRST |
00098         OLEMISC_INSIDEOUT |
00099         OLEMISC_CANTLINKINSIDE |
00100         OLEMISC_RECOMPOSEONRESIZE;
00101 
00102 IMPLEMENT_OLECTLTYPE(CObjectInspectorCtrl, IDS_OBJECTINSPECTOR, _dwObjectInspectorOleMisc)
00103 
00104 
00105 
00106 // CObjectInspectorCtrl::CObjectInspectorCtrlFactory::UpdateRegistry -
00107 // Adds or removes system registry entries for CObjectInspectorCtrl
00108 
00109 BOOL CObjectInspectorCtrl::CObjectInspectorCtrlFactory::UpdateRegistry(BOOL bRegister)
00110 {
00111         // TODO: Verify that your control follows apartment-model threading rules.
00112         // Refer to MFC TechNote 64 for more information.
00113         // If your control does not conform to the apartment-model rules, then
00114         // you must modify the code below, changing the 6th parameter from
00115         // afxRegApartmentThreading to 0.
00116 
00117         if (bRegister)
00118                 return AfxOleRegisterControlClass(
00119                         AfxGetInstanceHandle(),
00120                         m_clsid,
00121                         m_lpszProgID,
00122                         IDS_OBJECTINSPECTOR,
00123                         IDB_OBJECTINSPECTOR,
00124                         afxRegApartmentThreading,
00125                         _dwObjectInspectorOleMisc,
00126                         _tlid,
00127                         _wVerMajor,
00128                         _wVerMinor);
00129         else
00130                 return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
00131 }
00132 
00134 // CObjectInspectorCtrl::XEventSink - native COM interface - peter
00135 STDMETHODIMP_(ULONG) CObjectInspectorCtrl::XEventSink::AddRef()
00136 {
00137         METHOD_PROLOGUE(CObjectInspectorCtrl,EventSink)
00138         return pThis->ExternalAddRef();
00139 }
00140 
00141 STDMETHODIMP_(ULONG) CObjectInspectorCtrl::XEventSink::Release()
00142 {
00143         METHOD_PROLOGUE(CObjectInspectorCtrl,EventSink)
00144         return pThis->ExternalRelease();
00145 }
00146 
00147 STDMETHODIMP CObjectInspectorCtrl::XEventSink::QueryInterface(REFIID riid, void** ppv)
00148 {
00149         METHOD_PROLOGUE(CObjectInspectorCtrl,EventSink)
00150         return pThis->ExternalQueryInterface(&riid, ppv);
00151 }
00152 
00153 STDMETHODIMP CObjectInspectorCtrl::XEventSink::GlobalEvent(globalevent_enum event)
00154 {
00155         METHOD_PROLOGUE(CObjectInspectorCtrl,EventSink)
00156         // TODO: Handle global events here - peter
00157         pThis->OnMgaGlobalEvent(event);
00158         return S_OK;
00159 }
00160 
00161 STDMETHODIMP CObjectInspectorCtrl::XEventSink::ObjectEvent(IMgaObject * obj, unsigned long eventmask, VARIANT v)
00162 {
00163         METHOD_PROLOGUE(CObjectInspectorCtrl,EventSink)
00164         // TODO: Handle object events here - peter
00165         pThis->m_MgaObjectEventList.Add(obj,eventmask);
00166         return S_OK;
00167 }
00168 
00170 // CObjectInspectorCtrl::CObjectInspectorCtrl - Constructor
00171 
00172 CObjectInspectorCtrl::CObjectInspectorCtrl()
00173 {
00174         InitializeIIDs(&IID_DObjectInspector, &IID_DObjectInspectorEvents);
00175 
00176         // TODO: Initialize your control's instance data here.
00177         SetInitialSize(INSP_INITIAL_SIZEX, INSP_INITIAL_SIZEY);
00178 
00179         m_territory = NULL;
00180         m_project = NULL;
00181         m_objects = NULL;
00182 
00183         ignoreNextEvents = false;
00184 }
00185 
00186 
00188 // CObjectInspectorCtrl::~CObjectInspectorCtrl - Destructor
00189 
00190 CObjectInspectorCtrl::~CObjectInspectorCtrl()
00191 {
00192         // TODO: Cleanup your control's instance data here.
00193         m_territory = NULL;
00194         m_project = NULL;
00195         m_objects = NULL;
00196 
00197         m_FCOList.RemoveAll();
00198         m_FolderList.RemoveAll();
00199 }
00200 
00201 
00203 // CObjectInspectorCtrl::OnDraw - Drawing function
00204 
00205 void CObjectInspectorCtrl::OnDraw(
00206                         CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
00207 {
00208         if (m_inspectorDlg.GetSafeHwnd()) {
00209                 m_inspectorDlg.MoveWindow(rcBounds, TRUE);
00210         }
00211         else {
00212                 AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
00213                 CBrush brush (RGB(255,255,255));
00214                 pdc->FillRect (rcBounds, &brush);
00215 
00216                 CRect edge(rcBounds);
00217                 pdc->DrawEdge(&edge, EDGE_BUMP, BF_RECT);
00218                 
00219                 CString label(_T("ObjectInspector OCX"));
00220 
00221                 BITMAP bm;
00222                 CBitmap bitmap;
00223                 bitmap.LoadBitmap(IDB_OBJECTINSPECTOR);
00224                 bitmap.GetBitmap(&bm);
00225                 CSize size(bm.bmWidth, bm.bmHeight);
00226                 pdc->DPtoLP(&size);
00227                 CPoint org(0,0);
00228                 pdc->DPtoLP(&org);
00229                 CPoint pos(rcBounds.Width()/2, rcBounds.Height()/2 - (pdc->GetTextExtent(label).cy) );
00230                 CDC dcMem;
00231                 dcMem.CreateCompatibleDC(pdc);
00232                 CBitmap *oldbitmap = dcMem.SelectObject(&bitmap);
00233                 dcMem.SetMapMode (pdc->GetMapMode());
00234                 pdc->BitBlt(pos.x, pos.y, size.cx, size.cy, &dcMem, org.x, org.y, SRCCOPY);
00235                 dcMem.SelectObject(oldbitmap);
00236                 
00237                 pdc->SetTextAlign(TA_CENTER);
00238                 pdc->TextOut(rcBounds.Width()/2, rcBounds.Height()/2, CString(_T("ObjectInspector ActiveX Control")));
00239         }
00240 }
00241 
00242 
00244 // CObjectInspectorCtrl::DoPropExchange - Persistence support
00245 
00246 void CObjectInspectorCtrl::DoPropExchange(CPropExchange* pPX)
00247 {
00248         ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
00249         COleControl::DoPropExchange(pPX);
00250 
00251         // TODO: Call PX_ functions for each persistent custom property.
00252 
00253 }
00254 
00255 
00257 // CObjectInspectorCtrl::OnResetState - Reset control to default state
00258 
00259 void CObjectInspectorCtrl::OnResetState()
00260 {
00261         COleControl::OnResetState();  // Resets defaults found in DoPropExchange
00262 
00263         // TODO: Reset any other control state here.
00264 }
00265 
00266 
00268 // CObjectInspectorCtrl::AboutBox - Display an "About" box to the user
00269 
00270 void CObjectInspectorCtrl::AboutBox()
00271 {
00272         CDialog dlgAbout(IDD_ABOUTBOX_OBJECTINSPECTOR);
00273         dlgAbout.DoModal();
00274 }
00275 
00276 
00278 // CObjectInspectorCtrl message handlers
00279 
00280 int CObjectInspectorCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
00281 {
00282         if (COleControl::OnCreate(lpCreateStruct) == -1)
00283                 return -1;
00284         
00285         m_inspectorDlg.Create(IDD_INSPECTOR_DIALOG, this);
00286 
00287         return 0;
00288 }
00289 
00290 BOOL CObjectInspectorCtrl::PreCreateWindow(CREATESTRUCT& cs) 
00291 {
00292         cs.dwExStyle |= WS_EX_CONTROLPARENT;
00293         return COleControl::PreCreateWindow(cs);
00294 }
00295 
00296 void CObjectInspectorCtrl::ShowPanel(long panelID) 
00297 {
00298         m_inspectorDlg.ShowPanel(panelID);
00299 
00300 }
00301 
00302 void CObjectInspectorCtrl::EditName() 
00303 {
00304         m_inspectorDlg.m_NameCtrl.SetFocus();
00305 
00306 }
00307 
00308 void CObjectInspectorCtrl::CyclePanel(VARIANT_BOOL frwd)
00309 {
00310         AFX_MANAGE_STATE(AfxGetStaticModuleState());
00311         m_inspectorDlg.CyclePanel( frwd != VARIANT_FALSE);
00312 }
00313 
00314 LPUNKNOWN CObjectInspectorCtrl::GetMgaProject() 
00315 {
00316         if (m_project == NULL) {
00317                 return NULL;
00318         }
00319         CComPtr<IUnknown> unk;
00320         if (FAILED(m_project.QueryInterface(&unk))) {
00321                 ThrowError(CTL_E_INVALIDPROPERTYVALUE, _T("Unable to cast MgaProject."));
00322                 return NULL;
00323         }
00324         return unk;
00325 }
00326 
00327 void CObjectInspectorCtrl::SetMgaProject(LPUNKNOWN newValue) 
00328 {
00329         if(newValue==NULL)
00330         {
00331                 m_objects.Release();
00332                 m_FCOList.RemoveAll();
00333                 m_FolderList.RemoveAll();
00334                 
00335                 if(!m_project)
00336                 {
00337                         return;
00338                 }
00339 
00340                 RefreshPanels();
00341 
00342         
00343                 if(m_territory.p!=NULL)
00344                 {
00345                         COMTHROW(m_territory->Destroy() );
00346                 }
00347                 m_territory.Release();
00348                 m_project.Release();
00349         }
00350         else
00351         {
00352                 CComQIPtr<IMgaProject> ccpMgaProject(newValue);
00353 
00354                 if (ccpMgaProject==NULL) 
00355                 {
00356                         ThrowError(CTL_E_INVALIDPROPERTYVALUE, _T("Unable to cast MgaProject."));
00357                         return;
00358                 }
00359 
00360                 m_project=ccpMgaProject;
00361                 SetModifiedFlag();
00362 
00363                 // Creating Territory
00364                 COMTHROW( m_project->CreateTerritory(&m_xEventSink,&m_territory,NULL) );        
00365 
00366                 m_objects.Release();
00367                 m_FCOList.RemoveAll();
00368                 m_FolderList.RemoveAll();
00369                 RefreshPanels();
00370         }
00371 }
00372 
00373 
00374 LPUNKNOWN CObjectInspectorCtrl::GetMgaObjects() 
00375 {
00376         if( !m_objects) {
00377                 return NULL;
00378         }
00379 
00380         CComPtr<IMgaObjects> obj_coll;
00381         try
00382         {
00383                 long len = 0;
00384                 COMTHROW( m_objects->get_Count( &len));
00385 
00386                 if( len >= 1)
00387                         COMTHROW( obj_coll.CoCreateInstance( L"Mga.MgaObjects"));
00388 
00389                 ASSERT( obj_coll);
00390                 for( long i = 1; i <= len; ++i)
00391                 {
00392                         CComPtr<IMgaObject> obj;
00393                         COMTHROW( m_objects->get_Item( i, &obj));
00394 
00395                         ASSERT( obj);
00396                         COMTHROW( obj_coll->Append( obj));
00397                 }
00398         } catch(...) {
00399                 ThrowError(CTL_E_INVALIDPROPERTYVALUE, _T("Unable to cast IMgaObjects collection"));
00400                 return NULL;
00401         }
00402 
00403         return obj_coll.Detach();
00404 }
00405 
00406 void CObjectInspectorCtrl::SetMgaObjects(LPUNKNOWN newValue) 
00407 {
00408         if( !m_project) {
00409                 m_objects.Release();
00410                 m_FCOList.RemoveAll();
00411                 m_FolderList.RemoveAll();
00412                 return;
00413         }
00414         CComQIPtr<IMgaObjects> ccpMgaObjects(newValue);
00415         if(!ccpMgaObjects)
00416         {
00417                 ThrowError(CTL_E_INVALIDPROPERTYVALUE, _T("Unable to cast to IMgaObjects."));
00418                 return;
00419         }
00420 
00421         
00422         m_FCOList.RemoveAll();
00423         m_FolderList.RemoveAll();
00424 
00425         try
00426         {
00427                 COMTHROW(m_project->BeginTransaction(m_territory,TRANSACTION_READ_ONLY));
00428                 // Iterate through the objects
00429                 MGACOLL_ITERATE(IMgaObject, ccpMgaObjects) 
00430                 {
00431                         CComPtr<IMgaObject>ccpMgaObject;
00432                         COMTHROW(m_territory->OpenObj(MGACOLL_ITER,&ccpMgaObject));
00433                         objtype_enum oeType;
00434                          
00435                         COMTHROW(ccpMgaObject->get_ObjType(&oeType));
00436                         if(oeType==OBJTYPE_FOLDER)
00437                         {
00438                                 CComQIPtr<IMgaFolder> ccpMgaFolder(ccpMgaObject);
00439                                 if(ccpMgaFolder)
00440                                 {
00441                                         CComPtr<IMgaFolder> ccpMgaFolderElement=ccpMgaFolder;
00442                                         m_FolderList.AddTail(ADAPT_FOLDER(ccpMgaFolderElement));
00443                                 }
00444                                 else
00445                                 {
00446                                         ASSERT(0);
00447                                 }
00448 
00449                         }
00450                         else
00451                         {
00452                                 CComQIPtr<IMgaFCO> ccpMgaFCO(ccpMgaObject);
00453                                 if(ccpMgaFCO)
00454                                 {
00455                                         CComPtr<IMgaFCO> ccpMgaFCOElement=ccpMgaFCO;
00456                                         m_FCOList.AddTail(ADAPT_FCO(ccpMgaFCOElement));
00457                                 }
00458                                 else
00459                                 {
00460                                         ASSERT(0);
00461                                 }
00462                         }
00463                         
00464                 } MGACOLL_ITERATE_END;  
00465 
00466                 COMTHROW(m_project->CommitTransaction());
00467 
00468                 RefreshPanels();
00469                 m_objects = ccpMgaObjects;
00470                 
00471         }
00472         catch (hresult_exception e)
00473         {
00474                 m_project->AbortTransaction();
00475                 m_FCOList.RemoveAll();
00476                 m_FolderList.RemoveAll();
00477                 m_objects=NULL;
00478 
00479                 CWnd::MessageBox(_T("Object Inspector could not hand over the project data due to an unexpected error. We apologize for the inconvenience."),_T("Object inspector"),MB_ICONERROR);
00480 
00481         }
00482         SetModifiedFlag();
00483 }
00484 
00485 void CObjectInspectorCtrl::RefreshPanels()
00486 {
00487         try
00488         {
00489                 long lProjectStatus;
00490                 COMTHROW(m_project->get_ProjectStatus(&lProjectStatus));
00491                 bool bInTransaction = ((lProjectStatus & 0x08) != 0);
00492 
00493                 if(!bInTransaction)
00494                 {
00495                         COMTHROW(m_project->BeginTransaction(m_territory,TRANSACTION_READ_ONLY));
00496                 }       
00497                         // Refresh Attribute Panel
00498                         RefreshAttributePanel();        
00499 
00500                         // Refresh Reference Panel
00501                         RefreshReferencePanel();
00502 
00503                         // Refresh Properties Panel
00504                         RefreshPropertyPanel();
00505 
00506                         // Refresh name field
00507                         RefreshName();
00508 
00509                         CString strEmpty;
00510                         m_inspectorDlg.SetHelp(strEmpty,strEmpty);
00511                 if(!bInTransaction)
00512                 {
00513                         COMTHROW(m_project->CommitTransaction());
00514                 }
00515 
00516                 
00517         }
00518         catch (hresult_exception e)
00519         {
00520                 ASSERT(0);
00521                 m_project->AbortTransaction();
00522                 CWnd::MessageBox(_T("Object Inspector could not load object data due to an unexpected MGA error. We apologize for the inconvenience."),_T("Object inspector"),MB_ICONERROR);
00523         }
00524 
00525         m_inspectorDlg.Refresh();
00526 }
00527 
00528 bool CObjectInspectorCtrl::IsInitialized(bool withObject) const
00529 {
00530         return ( (m_project != NULL) && ( (!withObject) || (m_objects != NULL) ) );
00531 }
00532 
00533 void CObjectInspectorCtrl::IgnoreNextEvents(void)
00534 {
00535         ignoreNextEvents = true;
00536 }
00537 
00538 void CObjectInspectorCtrl::RefreshReferencePanel()
00539 {
00540 
00541         int nCount=m_FCOList.GetCount();
00542 
00543         if(!m_FolderList.IsEmpty())
00544         {               
00545                 CMgaFCOPtrList EmptyFCOList;
00546                 
00547                 m_inspectorDlg.ShowPanel(INSP_PREF_PANEL,false);        
00548                 m_Preference.CreateList(EmptyFCOList);
00549         }
00550         else
00551         {       
00552                 if(nCount==0)
00553                 {
00554                         m_inspectorDlg.ShowPanel(INSP_PREF_PANEL,false);
00555                 }
00556                 else
00557                 {
00558                         m_inspectorDlg.ShowPanel(INSP_PREF_PANEL,true);
00559                 }
00560 
00561                 m_Preference.CreateList(m_FCOList);
00562         }
00563         
00564         m_inspectorDlg.m_inspectorLists[INSP_PREF_PANEL]->
00565                                                                         UpdateItems(m_Preference.m_ListItemArray);
00566         
00567 }
00568 
00569 
00570 void CObjectInspectorCtrl::RefreshAttributePanel()
00571 {
00572         int nCount=m_FCOList.GetCount();
00573 
00574         CArray<CListItem,CListItem&> ListItemArray;
00575         
00576         if(!m_FolderList.IsEmpty())
00577         {       
00578                 CComPtr<IMgaFolder> ccpMgaFolder = m_FolderList.GetHead();
00579                 objtype_enum oeType;
00580                 CComPtr<IMgaObject> ccpParent;
00581                 COMTHROW(ccpMgaFolder->GetParent(&ccpParent,&oeType));
00582 
00583                 if ((nCount == 0) && (m_FolderList.GetCount() == 1) && (ccpParent == NULL)) {
00584                         // Root Folder - Show project attributes
00585                         m_inspectorDlg.ShowPanel(INSP_ATTR_PANEL,true);
00586                         m_Attribute.CreateList(m_project, ListItemArray);
00587                 }
00588                 else {
00589                         CMgaFCOPtrList EmptyFCOList;
00590                         EmptyFCOList.RemoveAll();
00591                         
00592                         m_inspectorDlg.ShowPanel(INSP_ATTR_PANEL,false);        
00593                         m_Attribute.CreateList(EmptyFCOList,ListItemArray);
00594                 }
00595         }
00596         else
00597         {
00598                 if(nCount==0)
00599                 {
00600 
00601                         m_inspectorDlg.ShowPanel(INSP_ATTR_PANEL,false);        
00602                 }       
00603                 else
00604                 {
00605                         m_inspectorDlg.ShowPanel(INSP_ATTR_PANEL,true);
00606                 }
00607                 m_Attribute.CreateList(m_FCOList,ListItemArray);
00608         }
00609 
00610         m_inspectorDlg.m_inspectorLists[INSP_ATTR_PANEL]->UpdateItems(ListItemArray);
00611 }
00612 
00613 
00614 
00615 void CObjectInspectorCtrl::RefreshPropertyPanel()
00616 {
00617         int nCount=m_FCOList.GetCount()+m_FolderList.GetCount();
00618 
00619         
00620         if(nCount==0)
00621         {
00622                 m_inspectorDlg.ShowPanel(INSP_PROP_PANEL,false);                
00623         }       
00624         else
00625         {
00626                 m_inspectorDlg.ShowPanel(INSP_PROP_PANEL,true);
00627         }
00628 
00629         CArray<CListItem,CListItem&> ListItemArray;
00630         m_Property.CreateList(m_FCOList,m_FolderList,ListItemArray);
00631 
00632         m_inspectorDlg.m_inspectorLists[INSP_PROP_PANEL]->UpdateItems(ListItemArray);
00633 
00634 }
00635 
00636 
00637 void CObjectInspectorCtrl::OnMgaObjectEvent(IMgaObject  *obj, unsigned long eventmask)
00638 {
00639         if (ignoreNextEvents) {
00640                 ignoreNextEvents = false;
00641                 return;
00642         }
00643 
00644         CComPtr<IMgaObject> ccpMgaObject(obj);
00645         // Handling Object Events
00646         EVENT_TRACE("\n__________ Object Event Begin _________\n");
00647 
00648         if(eventmask&OBJEVENT_DESTROYED)
00649         {
00650                 EVENT_TRACE("OBJEVENT_DESTROYED\n");
00651                 
00652                 // Remove object from the list
00653 
00654                 POSITION posFCO=m_FCOList.GetHeadPosition();
00655                 POSITION posPrevFCO=posFCO;
00656                 while(posFCO)
00657                 {
00658                         posPrevFCO=posFCO;
00659                         CComPtr<IMgaFCO> ccpMgaFCO=m_FCOList.GetNext(posFCO);
00660                         if(ccpMgaFCO==ccpMgaObject)
00661                         {
00662                                 m_FCOList.RemoveAt(posPrevFCO);
00663                                 return;
00664                         }
00665                 }
00666                 
00667                 POSITION posFolder=m_FolderList.GetHeadPosition();
00668                 POSITION posPrevFolder=posFolder;
00669                 while(posFolder)
00670                 {
00671                         posPrevFolder=posFolder;
00672                         CComPtr<IMgaFolder> ccpMgaFolder=m_FolderList.GetNext(posFolder);
00673                         if(ccpMgaFolder==ccpMgaObject)
00674                         {
00675                                 m_FolderList.RemoveAt(posPrevFolder);
00676                                 return;
00677                         }
00678                 }
00679 
00680 
00681 
00682         }
00683 
00684 #ifdef _DEBUG
00685         if(eventmask&OBJEVENT_REGISTRY)
00686         {
00687                 EVENT_TRACE("OBJEVENT_REGISTRY\n");
00688         }
00689 
00690         if(eventmask&OBJEVENT_PROPERTIES)
00691         {
00692                 EVENT_TRACE("OBJEVENT_PROPERTIES\n");
00693         }
00694 
00695         if(eventmask&OBJEVENT_CREATED)
00696         {
00697                 EVENT_TRACE("OBJEVENT_CREATED\n");
00698 
00699         }
00700         if(eventmask&OBJEVENT_ATTR)
00701         {
00702                 EVENT_TRACE("OBJEVENT_ATTR\n");
00703 
00704         }
00705                 if(eventmask&OBJEVENT_NEWCHILD)
00706         {
00707                 EVENT_TRACE("OBJEVENT_NEWCHILD\n");
00708         }
00709         if(eventmask&OBJEVENT_RELATION)
00710         {
00711                 EVENT_TRACE("OBJEVENT_RELATION\n");
00712         }
00713         if(eventmask&OBJEVENT_SUBT_INST)
00714         {
00715                 EVENT_TRACE("OBJEVENT_SUBT_INST\n");
00716         }
00717         if(eventmask&OBJEVENT_PARENT)
00718         {
00719                 EVENT_TRACE("OBJEVENT_PARENT\n");
00720         }
00721         if(eventmask&OBJEVENT_LOSTCHILD)
00722         {
00723                 EVENT_TRACE("OBJEVENT_LOSTCHILD\n");
00724         }
00725         if(eventmask&OBJEVENT_REFERENCED)
00726         {
00727                 EVENT_TRACE("OBJEVENT_REFERENCED\n");
00728         }
00729         if(eventmask&OBJEVENT_CONNECTED)
00730         {
00731                 EVENT_TRACE("OBJEVENT_CONNECTED\n");
00732         }
00733         if(eventmask&OBJEVENT_SETINCLUDED)
00734         {
00735                 EVENT_TRACE("OBJEVENT_SETINCLUDED\n");
00736         }
00737         if(eventmask&OBJEVENT_REFRELEASED)
00738         {
00739                 EVENT_TRACE("OBJEVENT_REFRELEASED\n");
00740         }
00741         if(eventmask&OBJEVENT_DISCONNECTED)
00742         {
00743                 EVENT_TRACE("OBJEVENT_DISCONNECTED\n");
00744         }
00745         if(eventmask&OBJEVENT_SETEXCLUDED)
00746         {
00747                 EVENT_TRACE("OBJEVENT_SETEXCLUDED\n");
00748         }
00749         if(eventmask&OBJEVENT_USERBITS)
00750         {
00751                 EVENT_TRACE("OBJEVENT_USERBITS\n");
00752         }
00753         if(eventmask&OBJEVENT_CLOSEMODEL)
00754         {
00755                 EVENT_TRACE("OBJEVENT_CLOSEMODEL\n");
00756         }
00757 #endif /*_DEBUG */
00758 
00759         EVENT_TRACE("_________ Object Event End _______\n");
00760 
00761          
00762 }
00763 
00764 void CObjectInspectorCtrl::OnMgaGlobalEvent(globalevent_enum event)
00765 {
00766         if (ignoreNextEvents)
00767                 return;
00768 
00769         // Handling Global Events
00770         if(event==GLOBALEVENT_COMMIT_TRANSACTION)
00771         {
00772                 EVENT_TRACE("GLOBALEVENT_COMMIT_TRANSACTION\n");
00773 
00774                 // Send message to UI
00775                 PropagateMgaMessages();
00776         }
00777         else if(event==GLOBALEVENT_NOTIFICATION_READY)
00778         {
00779                 EVENT_TRACE("GLOBALEVENT_NOTIFICATION_READY\n");
00780 
00781                 // Send message to UI
00782                 PropagateMgaMessages();
00783                 return;
00784         }
00785 
00786         else if(event==GLOBALEVENT_ABORT_TRANSACTION)
00787         {
00788                 EVENT_TRACE("GLOBALEVENT_ABORT_TRANSACTION\n");
00789 
00790                 // Removing the elements
00791                 m_MgaObjectEventList.RemoveAll();
00792         }
00793         else if(event==GLOBALEVENT_UNDO)
00794         {
00795                 EVENT_TRACE("GLOBALEVENT_UNDO\n");
00796                 RemoveZombies();
00797                 // Refresh
00798         }
00799         else if(event==GLOBALEVENT_REDO)
00800         {               
00801                 EVENT_TRACE("GLOBALEVENT_REDO\n");
00802                 RemoveZombies();
00803                 // Refresh
00804         }
00805 
00806         // Not handled messages are not in the release
00807         // but useful for development
00808 #ifdef _DEBUG
00809         if(event==GLOBALEVENT_PROJECT_PROPERTIES)
00810         {
00811                 EVENT_TRACE("GLOBALEVENT_PROJECT_PROPERTIES\n");
00812         }
00813 
00814         if(event==GLOBALEVENT_OPEN_PROJECT)
00815         {
00816                 EVENT_TRACE("GLOBALEVENT_OPEN_PROJECT\n");
00817         }
00818         if(event==GLOBALEVENT_CLOSE_PROJECT)
00819         {
00820                 EVENT_TRACE("GLOBALEVENT_CLOSE_PROJECT\n");
00821         }
00822         if(event==GLOBALEVENT_NEW_TERRITORY)
00823         {
00824                 EVENT_TRACE("GLOBALEVENT_NEW_TERRITORY\n");
00825         }
00826         if(event==GLOBALEVENT_DESTROY_TERRITORY)
00827         {
00828                 EVENT_TRACE("GLOBALEVENT_DESTROY_TERRITORY\n");
00829         }
00830 
00831 #endif /* _DEBUG */
00832 
00833         EVENT_TRACE("_________ Global Event End _________\n");
00834 
00835 
00836         RefreshPanels();
00837 }
00838 
00839 void CObjectInspectorCtrl::RemoveZombies()
00840 {
00841         POSITION posFCO=m_FCOList.GetHeadPosition();
00842         POSITION posPrevFCO=posFCO;
00843         while(posFCO)
00844         {
00845                 posPrevFCO=posFCO;
00846                 CComPtr<IMgaFCO> ccpMgaFCO=m_FCOList.GetNext(posFCO);
00847                 long oStatus;
00848                 COMTHROW(ccpMgaFCO->get_Status(&oStatus));
00849                 if(oStatus != OBJECT_EXISTS)
00850                 {
00851                         m_FCOList.RemoveAt(posPrevFCO);
00852                 }
00853         }
00854         
00855         POSITION posFolder=m_FolderList.GetHeadPosition();
00856         POSITION posPrevFolder=posFolder;
00857         while(posFolder)
00858         {
00859                 posPrevFolder=posFolder;
00860                 CComPtr<IMgaFolder> ccpMgaFolder=m_FolderList.GetNext(posFolder);
00861                 long fStatus;
00862                 COMTHROW(ccpMgaFolder->get_Status(&fStatus));
00863                 if(fStatus != OBJECT_EXISTS)
00864                 {
00865                         m_FolderList.RemoveAt(posPrevFolder);
00866                 }
00867         }
00868 }
00869 
00870 
00871 
00872 void CObjectInspectorCtrl::WriteAttributeItemToMga(CListItem ListItem)
00873 {
00874         CComPtr<IMgaMetaProject> ccpMetaProject;
00875         try
00876         {
00877                 long lProjectStatus;
00878                 COMTHROW(m_project->get_ProjectStatus(&lProjectStatus));
00879                 bool bInTransaction = ((lProjectStatus & 0x08) != 0);
00880 
00881                 ASSERT(!bInTransaction);
00882 
00883                 if(!bInTransaction)
00884                 {
00885                         COMTHROW(m_project->BeginTransaction(m_territory,TRANSACTION_GENERAL));
00886                 }       
00887 
00888                 // Writing change to MGA
00889                 if (m_FCOList.IsEmpty()) {
00890                         m_Attribute.WriteItemToMga(ListItem,m_project);
00891                 }
00892                 else {
00893                         m_Attribute.WriteItemToMga(ListItem,m_FCOList);
00894                 }
00895 
00896                 if(!bInTransaction)
00897                 {
00898                         HRESULT hResult = m_project->CommitTransaction();
00899                         if  ( FAILED(hResult) ) {
00900                                 if ( hResult == E_MGA_CONSTRAINT_VIOLATION )
00901                                         COMTHROW( m_project->AbortTransaction() );
00902                                 else 
00903                                         COMTHROW( hResult );
00904                         }
00905                 }               
00906         }
00907         catch (hresult_exception e)
00908         {
00909                 ASSERT(0);
00910                 m_project->AbortTransaction();
00911                 CWnd::MessageBox(_T("Object Inspector could not write attribute data due to an unexpected error. We apologize for the inconvenience."),_T("Object inspector"),MB_ICONERROR);
00912         }
00913         catch (_com_error& e)
00914         {
00915                 ASSERT(0);
00916                 m_project->AbortTransaction();
00917                 CWnd::MessageBox(CString(L"Object Inspector could not write attribute data: ") + static_cast<const wchar_t*>(e.Description()), L"Object inspector",MB_ICONERROR);
00918         }
00919 
00920 }
00921 
00922 void CObjectInspectorCtrl::WritePreferenceItemToMga(CListItem ListItem, bool bIsForKind)
00923 {
00924         CComPtr<IMgaMetaProject> ccpMetaProject;
00925         try
00926         {
00927                 m_Preference.IssuePossiblePathConversion(ListItem, m_FCOList, this);
00928 
00929                 long lProjectStatus;
00930                 COMTHROW(m_project->get_ProjectStatus(&lProjectStatus));
00931                 bool bInTransaction = ((lProjectStatus & 0x08) != 0);
00932 
00933                 ASSERT(!bInTransaction);
00934 
00935                 if(!bInTransaction)
00936                 {
00937                         COMTHROW(m_project->BeginTransaction(m_territory,TRANSACTION_GENERAL));
00938                 }       
00939 
00940                 // Here we will modify meta, so need the transaction for the meta
00941                 if(bIsForKind) 
00942                 {                               
00943                                 COMTHROW(m_project->get_RootMeta(&ccpMetaProject));                                     
00944                                 COMTHROW(ccpMetaProject->BeginTransaction());
00945                 }
00946                 // Writing change to MGA
00947                 m_Preference.WriteItemToMga(ListItem,m_FCOList,bIsForKind);
00948 
00949                 if(bIsForKind)
00950                 {
00951                         // Close meta transaction
00952                         COMTHROW(ccpMetaProject->CommitTransaction());
00953                 }
00954 
00955                 if(!bInTransaction)
00956                 {
00957                         COMTHROW(m_project->CommitTransaction());
00958                 }
00959 
00960                 
00961         }
00962         catch (hresult_exception& e)
00963         {
00964                 ASSERT(0);
00965                 m_project->AbortTransaction();
00966                 if(bIsForKind)
00967                 {
00968                         ccpMetaProject->AbortTransaction();
00969                 }
00970                 if (e.hr == E_MGA_LIBOBJECT)
00971                         CWnd::MessageBox(_T("Library objects cannot be modified."), _T("GME"), MB_ICONERROR);
00972                 else if (e.hr != E_MGA_CONSTRAINT_VIOLATION)
00973                         CWnd::MessageBox(_T("GME could not write object preference data due to an unexpected MGA error. We apologize for the inconvenience."), _T("GME"), MB_ICONERROR);
00974         }
00975         catch (_com_error& e)
00976         {
00977                 m_project->AbortTransaction();
00978                 if(bIsForKind)
00979                 {
00980                         ccpMetaProject->AbortTransaction();
00981                 }
00982                 if (e.Error() != E_MGA_CONSTRAINT_VIOLATION)
00983                         CWnd::MessageBox(CString(L"GME could not write attribute data: ") + static_cast<const wchar_t*>(e.Description()), L"GME",MB_ICONERROR);
00984         }
00985         
00986 }
00987 
00988 
00989 void CObjectInspectorCtrl::RefreshName()
00990 {
00991 
00992         CString strName;
00993         bool bIsFirst=true;
00994 
00995 
00996         POSITION posFCO=m_FCOList.GetHeadPosition();
00997 
00998         while(posFCO)
00999         {
01000                 CComPtr<IMgaFCO> ccpMgaFCO=m_FCOList.GetNext(posFCO);
01001                 // Getting name
01002                 CComBSTR bstrName;
01003                 COMTHROW(ccpMgaFCO->get_Name(&bstrName));
01004 
01005                 if(bIsFirst)
01006                 {
01007                         strName=CString(bstrName);
01008                         bIsFirst=false;
01009                 }
01010                 else
01011                 {
01012                         strName+=_T(";")+CString(bstrName);
01013                 }
01014 
01015         }
01016 
01017         POSITION posFolder=m_FolderList.GetHeadPosition();
01018 
01019         while(posFolder)
01020         {
01021                 CComPtr<IMgaFolder> ccpMgaFolder=m_FolderList.GetNext(posFolder);
01022 
01023                 // Getting name
01024                 CComBSTR bstrName;
01025 
01026                 COMTHROW(ccpMgaFolder->get_Name(&bstrName));
01027 
01028                 if(bIsFirst)
01029                 {
01030                         strName=CString(bstrName);
01031                         bIsFirst=false;
01032                 }
01033                 else
01034                 {
01035                         strName+=_T(";")+CString(bstrName);
01036                 }
01037 
01038         }
01039 
01040         int nCount=m_FolderList.GetCount()+m_FCOList.GetCount();
01041         m_inspectorDlg.SetName(strName,(nCount>1),!(nCount<1));
01042         
01043 }
01044 
01045 
01046 void CObjectInspectorCtrl::WriteNameToMga(const CString &strName)
01047 {
01048         bool rootfolder_name_edited = false;
01049         CComPtr<IMgaMetaProject> ccpMetaProject;
01050         try
01051         {
01052                 long lProjectStatus;
01053                 COMTHROW(m_project->get_ProjectStatus(&lProjectStatus));
01054                 bool bInTransaction = ((lProjectStatus & 0x08) != 0);
01055 
01056 
01057                 if(bInTransaction)
01058                 {
01059                         return; 
01060                 }
01061 
01062                 COMTHROW(m_project->BeginTransaction(m_territory,TRANSACTION_GENERAL));
01063 
01064                 // Writing change to MGA
01065                 POSITION posFCO=m_FCOList.GetHeadPosition();
01066 
01067                 while(posFCO)
01068                 {
01069                         CComPtr<IMgaFCO> ccpMgaFCO=m_FCOList.GetNext(posFCO);
01070                         // Setting name
01071                         CComBSTR bstrName=strName;
01072                         COMTHROW(ccpMgaFCO->put_Name(bstrName));
01073 
01074 
01075                 }
01076 
01077                 POSITION posFolder=m_FolderList.GetHeadPosition();
01078 
01079                 while(posFolder)
01080                 {
01081                         CComPtr<IMgaFolder> ccpMgaFolder=m_FolderList.GetNext(posFolder);
01082                 
01083                         // Setting name
01084                         CComBSTR bstrName=strName;
01085                         
01086                         // The name is special if folder is a library root
01087                         CComBSTR dummyName;
01088                         COMTHROW(ccpMgaFolder->get_LibraryName(&dummyName));
01089                         if (dummyName != NULL) {
01090                                 COMTHROW(ccpMgaFolder->put_LibraryName(bstrName));
01091                         }
01092                         else {
01093                                 COMTHROW(ccpMgaFolder->put_Name(bstrName));
01094                         }
01095 
01096                         // Checking if it is root folder
01097                         // If it is, change project name as well
01098                         objtype_enum oeType;
01099                         CComPtr<IMgaObject> ccpParent;
01100 
01101                         COMTHROW(ccpMgaFolder->GetParent(&ccpParent,&oeType));
01102                         
01103                         if(ccpParent==NULL)     // Root Folder
01104                         {
01105                                 COMTHROW(m_project->put_Name(bstrName));
01106                                 rootfolder_name_edited = true;
01107                         }
01108 
01109 
01110 
01111                 }
01112 
01113                 COMTHROW(m_project->CommitTransaction());
01114 
01115                 if( rootfolder_name_edited)
01116                 {
01117                         this->FireRootFolderNameChanged();
01118                 }
01119         }
01120         catch (hresult_exception& e)
01121         {
01122                 m_project->AbortTransaction();
01123                 if (e.hr != E_MGA_CONSTRAINT_VIOLATION)
01124                         CWnd::MessageBox(_T("Object Inspector could not write object name due to an unexpected MGA error. We apologize for the inconvenience."),_T("Object inspector"),MB_ICONERROR);
01125         }
01126 
01127 }
01128 
01129 
01130 void CObjectInspectorCtrl::PropagateMgaMessages()
01131 {
01132         // Iterating through the list
01133         while(!m_MgaObjectEventList.IsEmpty())
01134         {
01135                 CMgaObjectEventWrapper* pEventWrapper=
01136                         (CMgaObjectEventWrapper*)m_MgaObjectEventList.RemoveHead();
01137                 // Propagating message to AggregatePropertyPage
01138                 
01139                 OnMgaObjectEvent(pEventWrapper->m_ccpMgaObject,pEventWrapper->m_eventmask);
01140 
01141                 delete pEventWrapper;
01142         }
01143 }
01144 
01145 void CObjectInspectorCtrl::UndoRedo( bool undo /*= true*/)
01146 {
01147         short usz( 0), rsz( 0);
01148         if( m_project)
01149                 COMTHROW(m_project->UndoRedoSize( &usz, &rsz));
01150         if( undo && usz > 0)
01151                 COMTHROW( m_project->Undo());
01152         else if( !undo && rsz > 0)
01153                 COMTHROW( m_project->Redo());
01154 }
01155