GME  13
InheritanceTreeCtrl.cpp
Go to the documentation of this file.
00001 // InheritanceTreeCtrl.cpp: implementation of the CInheritanceTreeCtrl class.
00002 //
00004 
00005 #include "stdafx.h"
00006 #include "gmeactivebrowser.h"
00007 #include "InheritanceTreeCtrl.h"
00008 #include "ActiveBrowserPropertyPage.h"
00009 
00010 #ifdef _DEBUG
00011 #undef THIS_FILE
00012 static char THIS_FILE[]=__FILE__;
00013 #define new DEBUG_NEW
00014 #endif
00015 
00017 // Construction/Destruction
00019 
00020 CInheritanceTreeCtrl::CInheritanceTreeCtrl()
00021 {
00022 
00023 }
00024 
00025 CInheritanceTreeCtrl::~CInheritanceTreeCtrl()
00026 {
00027 
00028 }
00029 
00030 HTREEITEM CInheritanceTreeCtrl::InsertItem(HTREEITEM hParent, CString strObjectName, LPUNKNOWN pUnknown, objtype_enum otObjectType)
00031 {
00032         MGATREECTRL_LOGEVENT("CInheritanceTreeCtrl::InsertItem "+strObjectName+"\r\n");
00033         
00034         if(m_MgaMap.bIsInMap(pUnknown)) // Should not happen
00035         {
00036                 TRACE(" Duplicate element found inserting a new element into the aggregation tree map.\n");
00037                 ASSERT(FALSE);
00038                 
00039 
00040                 return NULL;
00041         }
00042         else
00043         {
00044                 HTREEITEM hItem=CTreeCtrlEx::InsertItem(strObjectName,(int)otObjectType,(int)otObjectType,hParent);     
00045                 CMgaObjectProxy ObjectProxy(pUnknown,otObjectType);
00046                 m_MgaMap.AddEntry(hItem,ObjectProxy);
00047                 SetItemData(hItem,(DWORD)0);
00048 
00049                 SetItemProperties(hItem);
00050 
00051                 return hItem;
00052         }
00053 
00054 }
00055 
00056 void CInheritanceTreeCtrl::SetItemProperties(HTREEITEM hItem)
00057 {
00058         CMgaObjectProxy ObjectProxy;
00059 
00060         if(!m_MgaMap.LookupObjectProxy(hItem, ObjectProxy))return;
00061 
00062         CComQIPtr<IMgaObject> ccpObject(ObjectProxy.m_pMgaObject);
00063 
00064         if(!ccpObject)return; // Not an MgaObject
00065         
00066         BYTE cState=0;
00067 
00068         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
00069         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
00070 
00071         pMgaContext->BeginTransaction();
00072 
00073 
00074         // Checking access rights
00075         VARIANT_BOOL vtbIsWritable=VARIANT_FALSE;
00076         COMTHROW( ccpObject->get_IsWritable(&vtbIsWritable));
00077 
00078         if (vtbIsWritable != VARIANT_TRUE)
00079         {
00080                 cState|=0x0001;// Read only object
00081         } // If the object is writable then nothing
00082 
00083 
00084         VARIANT_BOOL vtbIsLibObject=VARIANT_FALSE;;
00085         COMTHROW(ccpObject->get_IsLibObject(&vtbIsLibObject));
00086         
00087         if(vtbIsLibObject!=VARIANT_TRUE)
00088         { } // Not a LibObject
00089         else
00090         {               
00091                 cState|=0x0002;// LibObject
00092         }
00093 
00094         pMgaContext->CommitTransaction();
00095 
00097         // If not an FCO
00098         if(ObjectProxy.m_TypeInfo==OBJTYPE_FOLDER)return;
00099 
00100         CComQIPtr<IMgaFCO> ccpMgaFCO(ObjectProxy.m_pMgaObject);
00101         if(!ccpMgaFCO)return; // Not an FCO
00102 
00103         pMgaContext->BeginTransaction();
00104         // Is it instance?
00105         VARIANT_BOOL vtbIsInstance=VARIANT_FALSE;
00106         COMTHROW(ccpMgaFCO->get_IsInstance(&vtbIsInstance));
00107 
00108         if(vtbIsInstance!=VARIANT_TRUE)
00109         {
00110                 CComPtr<IMgaFCO> ccpBaseType;
00111                 COMTHROW(ccpMgaFCO->get_BaseType(&ccpBaseType));
00112 
00113                 if(!ccpBaseType)
00114                 { } // Not derived
00115                 else
00116                 {
00117                         cState|=0x0008;// Derived
00118                 }
00119         }
00120         else
00121         {
00122                 cState|=0x0004;// Instance
00123         }
00124 
00125         pMgaContext->CommitTransaction();       
00126         
00127 
00128         if(cState)
00129         {
00130                 CTreeCtrl::SetItemState( hItem,INDEXTOSTATEIMAGEMASK(cState), TVIS_STATEIMAGEMASK );
00131         }
00132         else
00133         {               
00134                 CTreeCtrl::SetItemState( hItem,0, TVIS_STATEIMAGEMASK );
00135         }
00136 }
00137 
00138 void CInheritanceTreeCtrl::StoreState()
00139 {
00140 
00141         m_StateBuffer.RemoveAll();
00142 
00143         // Traverse all items in tree control
00144         HTREEITEM hItem= GetRootItem();
00145 
00146         while ( hItem )
00147         {
00148                 /* Saving the items to the state buffer         */
00149                 // Getting item state
00150                 UINT nItemState=CTreeCtrlEx::GetItemState(hItem,0x000000ff);
00151                 CString strItemState;
00152                 strItemState.Format(_T("%ul"),nItemState);
00153 
00154                 // Searching the map for the Mga pointer
00155                 LPUNKNOWN pUnknown;
00156                 if(m_MgaMap.LookupObjectUnknown(hItem,pUnknown))
00157                 {
00158                         CComQIPtr<IMgaObject>ccpMgaObject(pUnknown);
00159                         if(ccpMgaObject) // succesful conversion
00160                         {
00161                                 CComBSTR IDObj;
00162                                 COMTHROW(ccpMgaObject->get_ID(&IDObj));
00163 
00164                                 // Put Object id and item state in the buffer
00165                                 CString strID(IDObj);
00166                                 m_StateBuffer.SetAt(strID,strItemState);
00167                                 
00168                         }
00169                 }
00170 
00171                 // Get first child node
00172                 HTREEITEM hNextItem = GetChildItem( hItem );
00173 
00174                 if ( !hNextItem )
00175                 {
00176                         // Get next sibling child
00177                         hNextItem = GetNextSiblingItem( hItem );
00178 
00179                         if ( !hNextItem )
00180                         {
00181                                 HTREEITEM hParentItem=hItem;
00182                                 while ( !hNextItem && hParentItem )
00183                                 {
00184                                         // No more children: Get next sibling to parent
00185                                         hParentItem = GetParentItem( hParentItem );
00186                                         hNextItem = GetNextSiblingItem( hParentItem );
00187                                 }
00188                         }
00189                 }
00190 
00191                 hItem = hNextItem;
00192         }
00193 
00194         m_bIsStateStored=TRUE;
00195         return;
00196 
00197 }
00198 
00199 
00200 
00201 void CInheritanceTreeCtrl::RestoreState()
00202 {
00203         if(!m_bIsStateStored)return;
00204 
00205         // Traverse all items in tree control
00206         HTREEITEM hItem= GetRootItem();
00207 
00208         while ( hItem )
00209         {
00210                 /* Getting the item from the map                */
00211                 
00212                 // Searching the map for the Mga pointer
00213                 LPUNKNOWN pUnknown;
00214                 if(m_MgaMap.LookupObjectUnknown(hItem,pUnknown))
00215                 {
00216                         CComQIPtr<IMgaObject>ccpMgaObject(pUnknown);
00217                         if(ccpMgaObject) // succesful conversion
00218                         {
00219                                 CComBSTR IDObj;
00220                                 COMTHROW(ccpMgaObject->get_ID(&IDObj));
00221 
00222                                 // Get Object id and item state from the map
00223                                 CString strID(IDObj);
00224                                 CString strItemState;
00225                                 if(m_StateBuffer.Lookup(strID,strItemState))
00226                                 {
00227                                         TCHAR* pszEndPtr=NULL;
00228                                         UINT nItemState = _tcstoul(strItemState, &pszEndPtr, 10);
00229                                         CMgaMappedTreeCtrl::SetItemState(hItem,nItemState);
00230                                 }
00231                         }
00232                 }
00233                 
00234                 // Get first child node
00235                 HTREEITEM hNextItem = GetChildItem( hItem );
00236 
00237                 if ( !hNextItem )
00238                 {
00239                         // Get next sibling child
00240                         hNextItem = GetNextSiblingItem( hItem );
00241 
00242                         if ( !hNextItem )
00243                         {
00244                                 HTREEITEM hParentItem=hItem;
00245                                 while ( !hNextItem && hParentItem )
00246                                 {
00247                                         // No more children: Get next sibling to parent
00248                                         hParentItem = GetParentItem( hParentItem );
00249                                         hNextItem = GetNextSiblingItem( hParentItem );
00250                                 }
00251                         }
00252                 }
00253 
00254                 hItem = hNextItem;
00255         }
00256 
00257         m_StateBuffer.RemoveAll();
00258         m_bIsStateStored=FALSE;
00259         return;
00260 }