GME  13
ActiveBrowserPropertyPage.cpp
Go to the documentation of this file.
00001 // ActiveBrowserPropertyPage.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "resource.h"
00006 #include "ActiveBrowserPropertyPage.h"
00007 #include "GMEActiveBrowser.h"
00008 #include "GMEActiveBrowserCtl.h"
00009 #include "Meta_i.c"
00010 #include "AggregateContextMenu.h"
00011 #include "..\Gme\GMEOLEData.h"
00012 #include "AttachLibDlg.h"
00013 #include <comdef.h>
00014 #include "Parser.h"
00015 #include "CommonMfc.h"
00016 #include <map>
00017 #include <vector>
00018 
00019 #define GET_X_LPARAM(lp)                        ((int)(short)LOWORD(lp))
00020 #define GET_Y_LPARAM(lp)                        ((int)(short)HIWORD(lp))
00021 
00022 #define ICON_NUMBER 11
00023 
00024 #ifdef _DEBUG
00025 #undef THIS_FILE
00026 static char BASED_CODE THIS_FILE[] = __FILE__;
00027 #endif
00028 
00029 IMPLEMENT_DYNCREATE(CAggregatePropertyPage, CPropertyPage)
00030 IMPLEMENT_DYNCREATE(CInheritancePropertyPage, CPropertyPage)
00031 IMPLEMENT_DYNCREATE(CMetaPropertyPage, CPropertyPage)
00032 
00033 
00034 
00035 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 CAggregatePropertyPage::CAggregatePropertyPage() : CPropertyPage(CAggregatePropertyPage::IDD),
00052         m_ComboEditCtrl                 (&m_ComboSearchCtrl),
00053         m_ComboSearchCtrl               (&m_TreeAggregate),
00054         m_bProjectOpen                  (FALSE),
00055         m_SearchButtonCtrlBitmap(NULL)
00056 {
00057         //{{AFX_DATA_INIT(CAggregatePropertyPage)
00058         //}}AFX_DATA_INIT
00059 }
00060 
00061 CAggregatePropertyPage::~CAggregatePropertyPage()
00062 {
00063         m_ImageList.DeleteImageList();
00064         m_StateImageList.DeleteImageList();
00065         VERIFY( m_ImageList.GetSafeHandle() == NULL);
00066         VERIFY( m_StateImageList.GetSafeHandle() == NULL);
00067         BOOL success = ::DeleteObject(m_SearchButtonCtrlBitmap);
00068         ASSERT(success == TRUE);
00069 }
00070 
00071 void CAggregatePropertyPage::DoDataExchange(CDataExchange* pDX)
00072 {
00073         CPropertyPage::DoDataExchange(pDX);
00074         //{{AFX_DATA_MAP(CAggregatePropertyPage)
00075         DDX_Control(pDX, IDC_COMBO_SEARCH_AGGREGATE, m_ComboSearchCtrl);
00076         DDX_Control(pDX, IDC_SEARCH, m_SearchButtonCtrl);
00077         DDX_Control(pDX, IDC_TREE_AGGREGATE, m_TreeAggregate);
00078         //}}AFX_DATA_MAP
00079 }
00080 
00081 
00082 BEGIN_MESSAGE_MAP(CAggregatePropertyPage, CPropertyPage)
00083         ON_WM_CONTEXTMENU()
00084         //{{AFX_MSG_MAP(CAggregatePropertyPage)
00085         ON_WM_SIZE()
00086         ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREE_AGGREGATE, OnItemExpandingTreeAggregate)
00087         ON_NOTIFY(NM_CLICK, IDC_TREE_AGGREGATE, OnClickTreeAggregate)
00088         ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_AGGREGATE, OnSelChangedTreeAggregate)
00089         ON_NOTIFY(NM_DBLCLK, IDC_TREE_AGGREGATE, OnDblclkTreeAggregate)
00090         ON_NOTIFY(TVN_ENDLABELEDIT, IDC_TREE_AGGREGATE, OnEndLabelEditTreeAggregate)
00091         ON_NOTIFY(TVN_KEYDOWN, IDC_TREE_AGGREGATE, OnKeyDownTreeAggregate)
00092         ON_NOTIFY(TVN_GETDISPINFO, IDC_TREE_AGGREGATE, OnGetDispInfoTreeAggregate)
00093         ON_NOTIFY(TVN_ITEMEXPANDED, IDC_TREE_AGGREGATE, OnItemExpandedTreeAggregate)
00094         ON_BN_CLICKED(IDC_SEARCH, OnSearch)
00095         ON_NOTIFY(TVN_BEGINDRAG, IDC_TREE_AGGREGATE, OnBeginDragTreeAggregate)
00096         ON_WM_KILLFOCUS()
00097         //}}AFX_MSG_MAP
00098         ON_WM_KEYDOWN()
00099 END_MESSAGE_MAP()
00100 
00101 
00102 
00103 void CAggregatePropertyPage::OnSize(UINT nType, int cx, int cy) 
00104 {
00105 
00106 //      CPropertyPage::OnSize(nType, cx, cy);
00107         if(     ::IsWindow(m_ComboSearchCtrl.GetSafeHwnd()) )
00108         {
00109                 int ySpace = GetSystemMetrics(SM_CYBORDER);
00110                 RECT clientRect;
00111                 m_ComboSearchCtrl.GetClientRect(&clientRect);
00112                 
00113                 m_TreeAggregate.MoveWindow(0, clientRect.bottom + 2*ySpace, cx-1, cy-clientRect.bottom - 2*ySpace - 1);
00114                 m_ComboSearchCtrl.MoveWindow(0, ySpace, cx-1, cy-1);
00115 
00117                 //m_ComboSearchCtrl.MoveWindow(3,3,cx-29,20);
00118                 //m_SearchButtonCtrl.SetWindowPos(NULL,cx-22,2,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);             
00119 
00120         }
00121 }
00122 
00123 
00124 
00125 BOOL CAggregatePropertyPage::OnInitDialog() 
00126 {
00127         CPropertyPage::OnInitDialog();
00128         
00129 
00130         m_TreeAggregate.ModifyStyle(0,TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT
00131                                                                 |TVS_EDITLABELS|TVS_SHOWSELALWAYS );
00132 
00133 
00134         m_ImageList.Create(16,16,ILC_MASK|ILC_COLOR24,0,0);
00135         
00136         // Creating the state image list
00137         PrepareStateImageList();
00138 
00139 
00140         SetDefID(IDC_SEARCH);
00141 
00142         if (m_SearchButtonCtrlBitmap == NULL)
00143                 m_SearchButtonCtrlBitmap = ::LoadBitmap(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDB_SEARCH));
00144         m_SearchButtonCtrl.SetBitmap(m_SearchButtonCtrlBitmap);
00145 
00147         m_SearchButtonCtrl.ShowWindow(SW_HIDE);
00149 
00150         m_SearchButtonCtrl.EnableWindow(FALSE);
00151         m_TreeAggregate.EnableWindow(FALSE);
00152         m_ComboSearchCtrl.EnableWindow(FALSE);
00153 
00154 
00155         // Get edit control which happens to be the first child window
00156         // and subclass it
00157         m_ComboEditCtrl.SubclassWindow(m_ComboSearchCtrl.GetWindow(GW_CHILD)->GetSafeHwnd());
00158 
00159         m_TreeAggregate.RegisterDropTarget();
00160         
00161         return TRUE;  // return TRUE unless you set the focus to a control
00162                       // EXCEPTION: OCX Property Pages should return FALSE
00163 }
00164 
00165 void CAggregatePropertyPage::OnItemExpandingTreeAggregate(NMHDR* pNMHDR, LRESULT* pResult) 
00166 {
00167 
00168         NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
00169 
00170 
00171         if(pNMTreeView->action==TVE_EXPAND)
00172         {
00173                 if(m_TreeAggregate.GetItemState(pNMTreeView->itemNew.hItem,TVIS_EXPANDED)
00174                                                                                                                                         &TVIS_EXPANDED)
00175                 {
00176                         return;
00177                 }
00178 
00179                 if(m_Options.m_bIsDynamicLoading)
00180                 {
00181                         AfxGetApp()->LoadStandardCursor(IDC_WAIT);
00182                         HTREEITEM hItem=pNMTreeView->itemNew.hItem;
00183                         LPUNKNOWN pUnknown=NULL;
00184 
00185                         if(m_TreeAggregate.m_MgaMap.LookupObjectUnknown(hItem,pUnknown))
00186                         {
00187                                 CComQIPtr<IMgaObject>ccpMgaObject(pUnknown);
00188                                 if(ccpMgaObject)
00189                                 {
00190                                         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
00191                                         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
00192 
00193                                         MSGTRY{
00194                                                 // Starting transaction
00195                                                 pMgaContext->BeginTransaction();
00196                                                 reqBuildAggregateTree(hItem,ccpMgaObject,2);
00197                                                 m_TreeAggregate.SortItems(hItem);
00198                                                 pMgaContext->CommitTransaction ();                                                              
00199                                         }MSGCATCH(_T("Error completing the operation"),pMgaContext->AbortTransaction();)        
00200                                         
00201                                         
00202                                 }
00203                         }
00204                         m_TreeAggregate.EnsureVisible(hItem);
00205                         AfxGetApp()->LoadStandardCursor(IDC_ARROW);
00206                 }
00207 #ifdef _DEBUG
00208                 TRACE("\nEXPAND:\n");
00209                 m_TreeAggregate.m_MgaMap.Dump(afxDump); 
00210 #endif
00211 
00212                 int nImage,nSelectedImage;
00213                 m_TreeAggregate.GetItemImage(pNMTreeView->itemNew.hItem,nImage,nSelectedImage);
00214 
00215                 if (nImage<8*ICON_NUMBER)
00216                         m_TreeAggregate.SetItemImage(pNMTreeView->itemNew.hItem,nImage+ICON_NUMBER,nSelectedImage+ICON_NUMBER);
00217                 else
00218                         m_TreeAggregate.SetItemImage(pNMTreeView->itemNew.hItem, (nImage & ~1) + 1, (nImage & ~1) + 1);
00219 
00220         }
00221         else // Collapsing
00222         {
00223                 if(!(m_TreeAggregate.GetItemState(pNMTreeView->itemNew.hItem,TVIS_EXPANDED)
00224                                                                                                                                         &TVIS_EXPANDED))
00225                 {
00226                         return;
00227                 }
00228 
00229                 int nImage,nSelectedImage;
00230                 m_TreeAggregate.GetItemImage(pNMTreeView->itemNew.hItem,nImage,nSelectedImage);
00231                 
00232                 ASSERT(nImage-ICON_NUMBER>=0);
00233                 if (nImage<8*ICON_NUMBER)
00234                         m_TreeAggregate.SetItemImage(pNMTreeView->itemNew.hItem,nImage-ICON_NUMBER,nSelectedImage-ICON_NUMBER);
00235                 else
00236                         m_TreeAggregate.SetItemImage(pNMTreeView->itemNew.hItem, (nImage & ~1), (nImage & ~1));
00237         }
00238 
00239         
00240 
00241         *pResult = 0;
00242 }
00243 
00244 void CAggregatePropertyPage::OnItemExpandedTreeAggregate(NMHDR* pNMHDR, LRESULT* pResult) 
00245 {
00246 
00247         if(!m_bProjectOpen)return;
00248         NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
00249 
00250         if(pNMTreeView->action!=TVE_EXPAND)
00251         {
00252         
00253                 if(m_Options.m_bIsDynamicLoading)
00254                 {                               
00255                         
00256                         m_TreeAggregate.DeleteAllChildren(pNMTreeView->itemNew.hItem);                  
00257                         
00258 #ifdef _DEBUG
00259                         TRACE("\nCollapse:\n");
00260                         m_TreeAggregate.m_MgaMap.Dump(afxDump); 
00261 #endif
00262 
00263                 }
00264 
00265                 m_TreeAggregate.CTreeCtrl::SetItemState(pNMTreeView->itemNew.hItem,0,TVIS_EXPANDEDONCE);
00266                 
00267         }
00268 
00269         *pResult = 0;
00270 }
00271 
00272 int CAggregatePropertyPage::GetSourceControlStateOffset(IMgaObject * obj, int * latent)
00273 {
00274         int ret_val = 0; bool saved = true;
00275         long st = 0; // state of the object
00276 
00277         try
00278         {
00279                 CComQIPtr<IMgaModel> mod( obj);
00280                 if( mod != NULL ) // if model
00281                 {
00282                         COMTHROW( mod->GetSourceControlInfo( &st));
00283                 }
00284                 else
00285                 {
00286                         CComQIPtr<IMgaFolder> fol( obj);
00287                         if( fol != NULL) // if folder
00288                                 COMTHROW( fol->GetSourceControlInfo( &st));
00289                         else
00290                                 return ret_val;
00291                 }
00292         }
00293         catch(...)
00294         {
00295                 return ret_val;
00296         }
00297 
00298         const int LOC = 0x1; // "GME_SourceControl_State_local"
00299         const int OTH = 0x2; // "GME_SourceControl_State_other"
00300 
00301         if( st & LOC)                // "GME_SourceControl_State_local"
00302                 ret_val = 4*ICON_NUMBER; 
00303         else if( st & OTH)           // "GME_SourceControl_State_other"
00304                 ret_val = 2*ICON_NUMBER; 
00305         else 
00306                 ret_val = 0;
00307 
00308 
00309         //const int UTD = 0x000; // "GME_SourceControl_File_UpToDate"
00310         const int MBO = 0x100; // "GME_SourceControl_File_ModByOthers"
00311         const int NYS = 0x200; // "GME_SourceControl_File_NotYetSaved"
00312 
00313         if( st & MBO)                // "GME_SourceControl_File_ModByOthers"
00314                 *latent = 1;
00315         else if( st & NYS)           // "GME_SourceControl_File_NotYetSaved"
00316                 saved = false, *latent = 0;//ret_val = 6 * ICON_NUMBER;
00317         else// if( st & UTD)           // "GME_SourceControl_File_UpToDate"
00318                 *latent = 0;
00319 
00320         if( !saved)
00321                 ret_val = 6*ICON_NUMBER, *latent = 0;
00322         return ret_val;
00323 }
00324 
00325 CString CAggregatePropertyPage::GetDisplayedName(IMgaObject *pIMgaObject)
00326 {    
00327         CComPtr<IMgaObject>ccpMgaObject(pIMgaObject);
00328         
00329         CComBSTR pDisplayedName;
00330         
00331         COMTHROW(ccpMgaObject->get_Name(&pDisplayedName));
00332 
00333     CString ret = pDisplayedName;
00334 
00335         return ret;
00336 }
00337 
00338 // Must be called from transaction
00339 void CAggregatePropertyPage::SetupTree()
00340 {
00341         
00342         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
00343         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
00344 
00345         m_TreeAggregate.treeIcons.clear();
00346         m_ImageList.DeleteImageList();
00347         m_ImageList.Create(16,16,ILC_MASK|ILC_COLOR24,0,0);
00348         CBitmap bm;
00349         bm.LoadBitmap(IDB_IMAGELIST_AGGREGATE);
00350         m_ImageList.Add(&bm,RGB(128, 158, 8));  // Pretty natural transparency color 
00351                                                                                         // provided by Tamas Paka
00352         m_TreeAggregate.SetImageList(&m_ImageList,TVSIL_NORMAL);
00353 
00354 
00355         // Getting Project
00356         CComPtr<IMgaProject> ccpMgaProject=pMgaContext->m_ccpProject;
00357         
00358 
00359         // Setting Project name
00360         CComBSTR bszProjectName;
00361         COMTHROW(pMgaContext->m_ccpProject->get_Name(&bszProjectName));
00362         m_strProjectName=bszProjectName;
00363 
00364         // Getting RootFolder
00365         CComPtr<IMgaFolder> ccpRootFolder;
00366         COMTHROW(pMgaContext->m_ccpProject->get_RootFolder(&ccpRootFolder));
00367 
00368         if(!m_Options.m_bIsDynamicLoading)
00369         {
00370                 // Load the whole tree
00371                 reqBuildAggregateTree(NULL,ccpRootFolder,-1);
00372         }
00373         else
00374         {
00375                 // Only the root folder will be displayed
00376                 reqBuildAggregateTree(NULL,ccpRootFolder,1);
00377         }
00378 
00379 }
00380 
00381 void CAggregatePropertyPage::reqBuildAggregateTree(HTREEITEM hParent,IMgaObject* pIMgaObject, int nDepthLevel, int nCounter, bool bWithUpdate)
00382 {
00383         // Checking depth level
00384         if(nDepthLevel==0)return;
00385         
00386         CComPtr<IMgaObject> ccpMgaObject(pIMgaObject);
00387 
00388         // Determining Object Type
00389         objtype_enum otObjectType;
00390         COMTHROW(ccpMgaObject->get_ObjType(&otObjectType));
00391         
00392         switch(otObjectType)
00393         {
00394                 case OBJTYPE_MODEL:
00395                         {
00396                                 CComQIPtr<IMgaModel>ccpMgaModel(ccpMgaObject);
00397                                 
00398                                 HTREEITEM hItem=hParent;  // Because of possible level skip
00399                                 if(m_Options.m_bDispModel)
00400                                 {
00401                                         if(m_Options.m_bIsDynamicLoading && nCounter)
00402                                         {
00403                                                 // Inserting item into the aggregate tree
00404                                                 if(bWithUpdate)
00405                                                 {
00406                                                         hItem=m_TreeAggregate.InsertItemUpdate(hParent,GetDisplayedName(ccpMgaModel),
00407                                                                                                                                                         ccpMgaModel,OBJTYPE_MODEL);
00408                                                 }
00409                                                 else
00410                                                 {
00411                                                         hItem=m_TreeAggregate.InsertItem(hParent,GetDisplayedName(ccpMgaModel),
00412                                                                                                                                                         ccpMgaModel,OBJTYPE_MODEL);
00413                                                 }
00414                                         }
00415                                 }
00416                                 else
00417                                 {
00418                                         // Increase depth level, because we did not do anything
00419                                         nDepthLevel++;
00420                                         nCounter++;
00421                                         // Next parent is the same as mine
00422                                         hItem=hParent;
00423                                 }
00424                                 if(hItem==NULL) // Duplicate element - should not happen here
00425                                 {
00426                                         ASSERT(FALSE);
00427                                         return;
00428                                 }
00429                                 else
00430                                 {
00431                                         // Getting children FCOs
00432                                         CComPtr<IMgaFCOs> ccpMgaFCOs;
00433                                         COMTHROW(ccpMgaModel->get_ChildFCOs(&ccpMgaFCOs));
00434 
00435                                         if(nDepthLevel!=1)
00436                                         {
00437                                                 // Iterate through the children FCOs
00438                                                 MGACOLL_ITERATE(IMgaFCO, ccpMgaFCOs) 
00439                                                 {                                               
00440                                                         // Recursive call for each children                                                     
00441                                                         reqBuildAggregateTree(hItem,MGACOLL_ITER,nDepthLevel-1, nCounter-1,bWithUpdate);
00442                                                         
00443                                                 } MGACOLL_ITERATE_END;
00444                                         }
00445 
00446                                 }
00447                         }break;
00448                 
00449                 case OBJTYPE_FOLDER:
00450                         {
00451                                 CComQIPtr<IMgaFolder>ccpMgaFolder(ccpMgaObject);        
00452                                 
00453                                 // Inserting item into the aggregation tree
00454                                 HTREEITEM hItem=hParent; // If level skip
00455                                 if(hParent==NULL)// Root folder
00456                                 {
00457                                                 if(bWithUpdate)
00458                                                 {
00459                                                         hItem=m_TreeAggregate.InsertItemUpdate(hParent,
00460                                                                         m_strProjectName,ccpMgaFolder,OBJTYPE_FOLDER);
00461                                                 }
00462                                                 else
00463                                                 {
00464                                                         hItem=m_TreeAggregate.InsertItem(hParent,
00465                                                                         m_strProjectName,ccpMgaFolder,OBJTYPE_FOLDER);
00466                                                 }
00467                                 }
00468                                 else
00469                                 {
00470                                         if(m_Options.m_bIsDynamicLoading && nCounter)
00471                                         {
00472                                                 if(bWithUpdate)
00473                                                 {
00474                                                         hItem=m_TreeAggregate.InsertItemUpdate(hParent,
00475                                                                 GetDisplayedName(ccpMgaFolder),ccpMgaFolder,OBJTYPE_FOLDER);
00476                                                 }
00477                                                 else
00478                                                 {
00479                                                         hItem=m_TreeAggregate.InsertItem(hParent,
00480                                                                 GetDisplayedName(ccpMgaFolder),ccpMgaFolder,OBJTYPE_FOLDER);
00481 
00482                                                 }
00483                                         }
00484                                 }
00485                                 if(hItem==NULL) 
00486                                 {
00487                                         return;
00488                                 }
00489                                 else
00490                                 {
00491 
00492                                         /*********  Getting Subfolders ***********/
00493                                         CComPtr<IMgaFolders> ccpChildFolders;
00494                                         COMTHROW(ccpMgaFolder->get_ChildFolders(&ccpChildFolders));
00495                                         
00496                                         if(ccpChildFolders!=NULL)
00497                                         {
00498                                                 if(nDepthLevel!=1)
00499                                                 {
00500                                                         // Iterate through the subfolders
00501                                                         MGACOLL_ITERATE(IMgaFolder, ccpChildFolders) 
00502                                                         {
00503                                                                 // Recursive call to each child folder                                                  
00504                                                                 reqBuildAggregateTree(hItem,MGACOLL_ITER,nDepthLevel-1,nCounter-1,bWithUpdate);
00505                                                         } MGACOLL_ITERATE_END;
00506                                                 }
00507 
00508                                         }                                       
00509                                         /********* Getting children FCOs **********/
00510                                         CComPtr<IMgaFCOs> ccpChildFCOs;
00511                                         COMTHROW(ccpMgaFolder->get_ChildFCOs(&ccpChildFCOs));
00512                                         
00513                                         if(nDepthLevel!=1)
00514                                         {
00515                                                 // Iterate through the children FCOs
00516                                                 MGACOLL_ITERATE(IMgaFCO, ccpChildFCOs) 
00517                                                 {
00518                                                         // Recursive call to each children
00519                                                                 reqBuildAggregateTree(hItem,MGACOLL_ITER,nDepthLevel-1,nCounter-1,bWithUpdate);
00520                                                 } MGACOLL_ITERATE_END;
00521                                         }
00522 
00523                                 }
00524 
00525                         }break;
00526                 case OBJTYPE_ATOM:
00527                         {
00528                                 if(m_Options.m_bDispAtom)
00529                                 {
00530                                         CComQIPtr<IMgaAtom>ccpMgaAtom(ccpMgaObject);                                                            
00531                                         
00532                                         // Inserting item into the aggregation tree
00533                                         if(bWithUpdate)
00534                                         {
00535                                                 HTREEITEM hItem=m_TreeAggregate.InsertItemUpdate(hParent,
00536                                                                 GetDisplayedName(ccpMgaAtom),ccpMgaAtom,OBJTYPE_ATOM);  
00537                                         }
00538                                         else
00539                                         {
00540                                                 HTREEITEM hItem=m_TreeAggregate.InsertItem(hParent,
00541                                                                 GetDisplayedName(ccpMgaAtom),ccpMgaAtom,OBJTYPE_ATOM);  
00542                                         }
00543                                 }
00544                         }break;         
00545 
00546                 case OBJTYPE_CONNECTION:
00547                         {
00548                                 if(m_Options.m_bDispConnections)//hack!!!
00549                                 {
00550                                         CComQIPtr<IMgaConnection>ccpMgaConnection(ccpMgaObject);
00551                                         if(bWithUpdate)
00552                                         {
00553                                                 HTREEITEM hItem=m_TreeAggregate.InsertItemUpdate(hParent,
00554                                                         GetDisplayedName(ccpMgaConnection),ccpMgaConnection,OBJTYPE_CONNECTION);
00555                                         }
00556                                         else
00557                                         {
00558                                                 HTREEITEM hItem=m_TreeAggregate.InsertItem(hParent,
00559                                                         GetDisplayedName(ccpMgaConnection),ccpMgaConnection,OBJTYPE_CONNECTION);
00560                                         }
00561                                 }
00562                         }break;
00563 
00564                 case OBJTYPE_REFERENCE:
00565                         {
00566                                 if(m_Options.m_bDispReference)
00567                                 {
00568                                         CComQIPtr<IMgaReference>ccpMgaReference(ccpMgaObject);                                                          
00569                                         // Inserting item into the aggregation tree
00570                                         if(bWithUpdate)
00571                                         {
00572                                                 HTREEITEM hItem=m_TreeAggregate.InsertItemUpdate(hParent,
00573                                                         GetDisplayedName(ccpMgaReference),ccpMgaReference,OBJTYPE_REFERENCE);
00574                                         }
00575                                         else
00576                                         {
00577                                                 HTREEITEM hItem=m_TreeAggregate.InsertItem(hParent,
00578                                                         GetDisplayedName(ccpMgaReference),ccpMgaReference,OBJTYPE_REFERENCE);
00579                                         }
00580                                 }                                                                                               
00581                         }break;
00582                 case OBJTYPE_SET:
00583                         {
00584                                 if(m_Options.m_bDispSet)
00585                                 {
00586                                         CComQIPtr<IMgaSet>ccpMgaSet(ccpMgaObject);                                                              
00587                                         // Inserting item into the aggregation tree
00588                                         if(bWithUpdate)
00589                                         {
00590                                                 HTREEITEM hItem=m_TreeAggregate.InsertItemUpdate(hParent,
00591                                                                         GetDisplayedName(ccpMgaSet),ccpMgaSet,OBJTYPE_SET);
00592                                         }
00593                                         else
00594                                         {
00595                                                 HTREEITEM hItem=m_TreeAggregate.InsertItem(hParent,
00596                                                                         GetDisplayedName(ccpMgaSet),ccpMgaSet,OBJTYPE_SET);
00597                                         }
00598                                 }
00599                                 return;
00600                         }break;
00601                 
00602                 case OBJTYPE_ATTRIBUTE:;// Not handled
00603                 case OBJTYPE_ROLE:;             // Not handled
00604                 case OBJTYPE_ASPECT:;   // Not handled
00605                 case OBJTYPE_PART:;             // Not handled
00606                 default:
00607                         {
00608                                 TRACE(_T("Unknown MGA object type detected building the aggregation tree\n"));
00609                                 ASSERT(0);
00610                                 return;
00611                         }
00612         }
00613 }
00614 
00615 
00616 
00617 BOOL CAggregatePropertyPage::reqHasDisplayedChild(IMgaObject* pIMgaObject, int nDepthLevel)
00618 {
00619         static int nFirstRun=nDepthLevel;
00620 
00621         // Checking depth level
00622         if(nDepthLevel==0)return FALSE;
00623 
00624         
00625         CComPtr<IMgaObject> ccpMgaObject(pIMgaObject);
00626 
00627         // Determining Object Type
00628         objtype_enum otObjectType;
00629         COMTHROW(ccpMgaObject->get_ObjType(&otObjectType));
00630         
00631         switch(otObjectType)
00632         {
00633                 case OBJTYPE_MODEL:
00634                         {
00635                                 CComQIPtr<IMgaModel>ccpMgaModel(ccpMgaObject);
00636                                 
00637                                 if(nFirstRun!= nDepthLevel && m_Options.IsDisplayedType(OBJTYPE_MODEL)) return TRUE;
00638                                 // Getting children FCOs
00639                                 CComPtr<IMgaFCOs> ccpMgaFCOs;
00640                                 COMTHROW(ccpMgaModel->get_ChildFCOs(&ccpMgaFCOs));
00641 
00642                                 // Iterate through the children FCOs
00643                                 bool doHasChild = false;
00644                                 MGACOLL_ITERATE(IMgaFCO, ccpMgaFCOs) 
00645                                 {                                               
00646                                         // Recursive call for each children
00647                                         if(reqHasDisplayedChild(MGACOLL_ITER,nDepthLevel-1)){
00648                                                 doHasChild = true;
00649                                                 break;
00650                                         }                                               
00651                                         
00652                                 } MGACOLL_ITERATE_END;
00653                                 if (doHasChild) {
00654                                         return TRUE;
00655                                 }
00656 
00657                                 
00658                         }break;
00659                 
00660                 case OBJTYPE_FOLDER:
00661                         {
00662                                 CComQIPtr<IMgaFolder>ccpMgaFolder(ccpMgaObject);        
00663                                 
00664                                 if(nFirstRun!= nDepthLevel && m_Options.IsDisplayedType(OBJTYPE_FOLDER)) return TRUE;
00665                                 
00666                                 /*********  Getting Subfolders ***********/
00667                                 CComPtr<IMgaFolders> ccpChildFolders;
00668                                 COMTHROW(ccpMgaFolder->get_ChildFolders(&ccpChildFolders));
00669         
00670                                 // Iterate through the subfolders
00671                                 bool doHasChild = false;
00672                                 MGACOLL_ITERATE(IMgaFolder, ccpChildFolders) 
00673                                 {
00674                                         // Recursive call to each child folder
00675                                         if(reqHasDisplayedChild(MGACOLL_ITER,nDepthLevel-1)) {
00676                                                 doHasChild = true;
00677                                                 break;
00678                                         }
00679                                 } MGACOLL_ITERATE_END;
00680                                 if (doHasChild) {
00681                                         return TRUE;
00682                                 }
00683                                         
00684                                 /********* Getting children FCOs **********/
00685                                 CComPtr<IMgaFCOs> ccpChildFCOs;
00686                                 COMTHROW(ccpMgaFolder->get_ChildFCOs(&ccpChildFCOs));
00687                                 // Iterate through the children FCOs
00688                                 MGACOLL_ITERATE(IMgaFCO, ccpChildFCOs) 
00689                                 {
00690                                         // Recursive call to each children
00691                                         if(reqHasDisplayedChild(MGACOLL_ITER,nDepthLevel-1)) {
00692                                                 doHasChild = true;
00693                                                 break;
00694                                         }
00695                                 } MGACOLL_ITERATE_END;
00696                                 if (doHasChild) {
00697                                         return TRUE;
00698                                 }
00699 
00700                         }break;
00701                 case OBJTYPE_ATOM:
00702                         {
00703                                 return nFirstRun!= nDepthLevel &&  m_Options.IsDisplayedType(OBJTYPE_ATOM);
00704                         }break;         
00705 
00706                 case OBJTYPE_CONNECTION:
00707                         {
00708                                 return nFirstRun!= nDepthLevel && m_Options.IsDisplayedType(OBJTYPE_CONNECTION);
00709                         }break;
00710 
00711                 case OBJTYPE_REFERENCE:
00712                         {
00713                                 return nFirstRun!= nDepthLevel && m_Options.IsDisplayedType(OBJTYPE_REFERENCE);
00714                         }break;
00715                 case OBJTYPE_SET:
00716                         {
00717                                 return nFirstRun!= nDepthLevel && m_Options.IsDisplayedType(OBJTYPE_SET);
00718                                 
00719                         }break;
00720                 
00721                 case OBJTYPE_ATTRIBUTE:;// Not handled
00722                 case OBJTYPE_ROLE:;             // Not handled
00723                 case OBJTYPE_ASPECT:;   // Not handled
00724                 case OBJTYPE_PART:;             // Not handled
00725                 default:
00726                         {
00727                                 return FALSE;
00728                         }
00729         }
00730         return FALSE;
00731         
00732 }
00733 
00734 
00735 
00736 void CAggregatePropertyPage::OpenProject()
00737 {
00738         m_TreeAggregate.EnableWindow(TRUE);
00739         m_ComboSearchCtrl.EnableWindow(TRUE);
00740         m_SearchButtonCtrl.EnableWindow(TRUE);
00741 
00742         m_bIsBrowserCreatedNewObject=FALSE;
00743 
00744         AfxGetApp()->LoadStandardCursor(IDC_WAIT);
00745 
00746         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
00747         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
00748 
00749         MSGTRY{
00750                 // Starting transaction
00751                 pMgaContext->BeginTransaction();
00752                 
00753 
00754                 SetupTree();
00755 
00756                 if(m_Options.m_bStoreTreeInRegistry)
00757                 {
00758 
00759                         /* Loading tree state from the registry */                      
00760                         m_TreeAggregate.LoadTreeStateFromRegistry(m_strProjectName);
00761                                                 
00762                         
00763                 }
00764 
00765                 m_TreeAggregate.SortItems();    
00766                 pMgaContext->CommitTransaction();
00767 
00768         }MSGCATCH(_T("Error opening aggregate tab"),pMgaContext->AbortTransaction();)   
00769         
00770         
00771 
00772         
00773 
00774 
00775         m_bProjectOpen=TRUE;
00776         AfxGetApp()->LoadStandardCursor(IDC_ARROW);
00777         
00778 
00779 
00780 
00781 #ifdef _DEBUG
00782         m_TreeAggregate.m_MgaMap.Dump(afxDump);
00783 #endif
00784 
00785 }
00786 
00787 void CAggregatePropertyPage::SetFocus2()
00788 {
00789         m_TreeAggregate.SetFocus();
00790 }
00791 
00792 void CAggregatePropertyPage::CloseProject()
00793 {
00794         m_bProjectOpen=FALSE;
00795         AfxGetApp()->LoadStandardCursor(IDC_WAIT);
00796 
00797         // by ZolMol
00798         if(CGMEDataSource::myData) // it is true when object copied onto clipboard from the active browser tree
00799                 OleFlushClipboard();
00800         // end
00801         
00802                 if(m_Options.m_bStoreTreeInRegistry)
00803                 {
00804                         // Saving tree state to registry
00805                         // Opening transaction
00806                         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
00807                         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
00808                         MSGTRY{ 
00809                                 pMgaContext->BeginTransaction();
00810                                 
00811                                 // Saving to registry
00812                                 m_TreeAggregate.SaveTreeStateToRegistry(m_strProjectName);
00813                                 // Close transaction
00814                                 pMgaContext->CommitTransaction();
00815                         }MSGCATCH(_T("Error closing the aggragate tab"),pMgaContext->AbortTransaction();)       
00816                         
00817                         
00818                 }
00819 
00820                 m_TreeAggregate.CleanUp();
00821                 m_TreeAggregate.EnableWindow(FALSE);
00822                 
00823                 m_SearchButtonCtrl.EnableWindow(FALSE);
00824 
00825                 m_ComboSearchCtrl.ResetContent();
00826                 m_ComboSearchCtrl.EnableWindow(FALSE);
00827                 AfxGetApp()->LoadStandardCursor(IDC_ARROW);
00828 
00829         
00830 
00831 }
00832 
00833 void CAggregatePropertyPage::DoCopy()
00834 {
00835 
00836         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
00837         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
00838         
00839 
00840 
00841         CComObjPtr<IMgaFCOs> ccpSelectedFCOs;
00842         COMTHROW( ccpSelectedFCOs.CoCreateInstance( L"Mga.MgaFCOs"));
00843         CComObjPtr<IMgaFolders> ccpSelectedFolders;
00844         COMTHROW( ccpSelectedFolders.CoCreateInstance( L"Mga.MgaFolders"));
00845 
00846         typedef CTypedPtrList<CPtrList, CRect *> CRectList;
00847         CRectList rectSelectedList;
00848         CRect   rectItem;
00849         CRect rectFrame(0,0,0,0);
00850 
00851 
00852         for(HTREEITEM hItem=m_TreeAggregate.GetFirstSelectedItem();hItem;
00853                                                 hItem=m_TreeAggregate.GetNextSelectedItem(hItem))
00854         {
00855                 CAggregateMgaObjectProxy ObjectProxy;
00856                 if(m_TreeAggregate.m_MgaMap.LookupObjectProxy(hItem, ObjectProxy))
00857                 {
00858                         if ( ObjectProxy.m_TypeInfo == OBJTYPE_MODEL     ||     // FCOs
00859                              ObjectProxy.m_TypeInfo == OBJTYPE_ATOM      ||
00860                              ObjectProxy.m_TypeInfo == OBJTYPE_REFERENCE ||
00861                              ObjectProxy.m_TypeInfo == OBJTYPE_CONNECTION ||
00862                              ObjectProxy.m_TypeInfo == OBJTYPE_SET)
00863                         {
00864                                 CComQIPtr<IMgaFCO> ccpMgaFCO( ObjectProxy.m_pMgaObject);
00865                                 if( ccpMgaFCO)
00866                                 {
00867                                         // Finding the rectangle of the selected item
00868                                         m_TreeAggregate.GetItemRect( hItem, rectItem, TRUE);
00869                                         // Computing the frame of all rectangles
00870                                         rectFrame.UnionRect( rectFrame, rectItem);
00871 
00872                                         // Adding to the selected rectangle list to create the image
00873                                         rectSelectedList.AddTail(new CRect( rectItem));
00874 
00875                                         // Append to the selected FCO list
00876                                         COMTHROW(ccpSelectedFCOs->Append( ccpMgaFCO));
00877                                 }
00878                         }
00879                         else if ( ObjectProxy.m_TypeInfo == OBJTYPE_FOLDER )
00880                         {
00881                                 CComQIPtr<IMgaFolder> ccpMgaFolder( ObjectProxy.m_pMgaObject);
00882                                 if( ccpMgaFolder)
00883                                 {
00884                                         // Finding the rectangle of the selected item
00885                                         m_TreeAggregate.GetItemRect( hItem, rectItem, TRUE);
00886                                         // Computing the frame of all rectangles
00887                                         rectFrame.UnionRect( rectFrame, rectItem);
00888 
00889                                         // Adding to the selected rectangle list to create the image
00890                                         rectSelectedList.AddTail( new CRect( rectItem));
00891 
00892                                         // Append to the selected FCO list
00893                                         COMTHROW(ccpSelectedFolders->Append( ccpMgaFolder));
00894                                 }
00895                         }
00896                 }               
00897         }
00898         
00899         if( rectSelectedList.GetCount() != 0)
00900         {
00901                 CRectList dummyAnnList;
00902 
00903                 CGMEDataDescriptor GMEDataDescriptor( rectSelectedList, dummyAnnList, rectFrame.TopLeft(), CPoint( 0, 0));
00904 
00905                 CGMEDataSource *pGMEDataSource = new CGMEDataSource( pMgaContext->m_ccpProject);
00906                 
00907                 if ( ccpSelectedFCOs)           pGMEDataSource->SetNodes( CComPtr<IMgaFCOs>( ccpSelectedFCOs));
00908                 if ( ccpSelectedFolders)        pGMEDataSource->SetFolders( CComPtr<IMgaFolders>( ccpSelectedFolders));
00909                 
00910                 pGMEDataSource->CacheDescriptor(&GMEDataDescriptor);
00911 
00912                 pGMEDataSource->SetClipboard();
00913         }
00914 
00915         CGMEDataDescriptor::destructList( rectSelectedList);
00916 }
00917 
00918 void CAggregatePropertyPage::DoCopyClosure()
00919 {
00920 
00921         bool is_any_folder_selected = false;
00922         CGMEActiveBrowserApp * pApp = (CGMEActiveBrowserApp*) AfxGetApp();
00923         CMgaContext * pMgaContext = &pApp->m_CurrentProject.m_MgaContext;
00924         
00925         CComObjPtr<IMgaFCOs> ccpSelectedFCOs;
00926         CComObjPtr<IMgaFolders> ccpSelectedFolders;
00927         COMTHROW( ccpSelectedFCOs.CoCreateInstance( L"Mga.MgaFCOs"));
00928         COMTHROW( ccpSelectedFolders.CoCreateInstance( L"Mga.MgaFolders"));
00929 
00930         typedef CTypedPtrList< CPtrList, CRect *> CRectList;
00931         CRectList rectSelectedList;
00932         CRect rectItem;
00933         CRect rectFrame(0,0,0,0);
00934 
00935 
00936         for( HTREEITEM hItem = m_TreeAggregate.GetFirstSelectedItem(); 
00937                 hItem; 
00938                 hItem = m_TreeAggregate.GetNextSelectedItem( hItem))
00939         {
00940                 CAggregateMgaObjectProxy ObjectProxy;
00941                 if( m_TreeAggregate.m_MgaMap.LookupObjectProxy( hItem, ObjectProxy))
00942                 {
00943                         if ( ObjectProxy.m_TypeInfo == OBJTYPE_MODEL                    // FCOs: connection too
00944                            || ObjectProxy.m_TypeInfo == OBJTYPE_ATOM
00945                            || ObjectProxy.m_TypeInfo == OBJTYPE_REFERENCE
00946                            || ObjectProxy.m_TypeInfo == OBJTYPE_SET
00947                            || ObjectProxy.m_TypeInfo == OBJTYPE_CONNECTION)
00948                         {
00949                                 CComQIPtr<IMgaFCO> ccpMgaFCO( ObjectProxy.m_pMgaObject);
00950                                 if( ccpMgaFCO)
00951                                 {
00952                                         // Finding the rectangle of the selected item
00953                                         m_TreeAggregate.GetItemRect( hItem, rectItem, TRUE);
00954                                         // Computing the frame of all rectangles
00955                                         rectFrame.UnionRect( rectFrame, rectItem);
00956 
00957                                         // Adding to the selected rectangle list to create the image
00958                                         rectSelectedList.AddTail( new CRect( rectItem));
00959                                         
00960                                         // Append to the selected FCO list
00961                                         COMTHROW(ccpSelectedFCOs->Append( ccpMgaFCO));
00962                                 }
00963                         }
00964                         else if ( ObjectProxy.m_TypeInfo == OBJTYPE_FOLDER )
00965                         {
00966                                 CComQIPtr<IMgaFolder> ccpMgaFolder( ObjectProxy.m_pMgaObject);
00967                                 if( ccpMgaFolder)
00968                                 {
00969                                         {
00970                                                 // Finding the rectangle of the selected item
00971                                                 m_TreeAggregate.GetItemRect( hItem, rectItem, TRUE);
00972                                                 // Computing the frame of all rectangles
00973                                                 rectFrame.UnionRect( rectFrame, rectItem);
00974 
00975                                                 // Adding to the selected rectangle list to create the image
00976                                                 rectSelectedList.AddTail( new CRect( rectItem));
00977                                                 
00978                                                 // Append to the selected FCO list
00979                                                 COMTHROW(ccpSelectedFolders->Append( ccpMgaFolder));
00980                                                 is_any_folder_selected = true;
00981                                         }
00982                                 }
00983                         }
00984                 }               
00985         }
00986         
00987         if ( rectSelectedList.GetCount()!=0)
00988         {
00989                 CComPtr<IMgaClosure> cl;
00990                 VARIANT_BOOL _refersTo           ; VARIANT_BOOL _referredBy;
00991                 VARIANT_BOOL _connections        ; VARIANT_BOOL _connsThroughRefport;
00992                 VARIANT_BOOL _setMembers         ; VARIANT_BOOL _memberOfSets;
00993                 VARIANT_BOOL _modelContainment   ; VARIANT_BOOL _partOfModels;
00994                 VARIANT_BOOL _folderContainment  ; VARIANT_BOOL _partOfFolders;
00995                 VARIANT_BOOL _baseTypeOf         ; VARIANT_BOOL _derivedTypesOf;
00996                 long _libraryElementHandling;         // 0: stubs; 1: stop; 2: continue
00997                 long _wrappingMode;                   // 0: miniproject; 1: automatic; 2: as is
00998                 long _kindFilter;                     // -1 = all; otherwise calculate the 0b000rsamf mask; where f = Folders; m = Models; a = Atoms; s = Sets; r = References
00999                 long _markThem;
01000                 long _options;
01001                 VARIANT_BOOL _directionDown;
01002                 VARIANT_BOOL _copyToFile;             // file or clipboard
01003                 VARIANT_BOOL _okPressed;              // how ended the dialog
01004                 CComBSTR _userSelFileName;
01005 
01006                 COMTHROW( cl.CoCreateInstance(L"Mga.MgaClosure") );
01007 
01008                 // ask the last closure id in a RO transaction
01009                 CMgaContext* pMgaContext = &pApp->m_CurrentProject.m_MgaContext;
01010                 pMgaContext->BeginTransaction(true); // readonly
01011                 try {
01012                         COMTHROW( cl->GetLastClosureId( pMgaContext->m_ccpProject, &_markThem));
01013                         pMgaContext->CommitTransaction();
01014                 } catch( hresult_exception& ) {
01015                         pMgaContext->AbortTransaction();
01016                         _markThem = -2; // will be increased to -1
01017                 }
01018 
01019                 ++_markThem; // propose this as the next closure id
01020 
01021                 COMTHROW( cl->SelectiveClosureDlg
01022                         ( is_any_folder_selected ? VARIANT_TRUE : VARIANT_FALSE
01023                         , &_refersTo           , &_referredBy
01024                         , &_connections        , &_connsThroughRefport
01025                         , &_setMembers         , &_memberOfSets
01026                         , &_modelContainment   , &_partOfModels
01027                         , &_folderContainment  , &_partOfFolders
01028                         , &_baseTypeOf         , &_derivedTypesOf
01029                         , &_libraryElementHandling          // 0: stubs; 1: stop; 2: continue
01030                         , &_wrappingMode                    // 0: miniproject; 1: automatic; 2: as is
01031                         , &_kindFilter                      // -1 = all; otherwise calculate the 0b000rsamf mask; where f = Folders; m = Models; a = Atoms; s = Sets; r = References
01032                         , &_markThem                        // -1 = do not mark
01033                         , &_options
01034                         , &_directionDown
01035                         , &_copyToFile              // file or clipboard
01036                         , &_okPressed               // how ended the dialog
01037                         , &_userSelFileName
01038                         ));
01039                 if( _okPressed == VARIANT_FALSE) return;
01040 
01041                 if( _markThem != -1) // save this if elements need to be marked
01042                 {
01043                         pMgaContext->BeginTransaction(false);
01044                         try {
01045                                 COMTHROW( cl->PutLastClosureId( pMgaContext->m_ccpProject, _markThem));
01046                                 pMgaContext->CommitTransaction();
01047                         } catch( hresult_exception& ) {
01048                                 pMgaContext->AbortTransaction();
01049                         }
01050                 }
01051 
01052                 CComObjPtr<IMgaFCOs> sel_fcos, top_fcos;
01053                 CComObjPtr<IMgaFolders> sel_folders, top_folders;
01054                 //long options;
01055                 VARIANT_BOOL tops_filled = VARIANT_FALSE;
01056                 CComBstrObj acc_kinds;
01057 
01058                 COMTHROW( cl->SelectiveClosureCalc
01059                         ( ccpSelectedFCOs    , ccpSelectedFolders
01060                         , _refersTo          , _referredBy
01061                         , _connections       , _connsThroughRefport
01062                         , _setMembers        , _memberOfSets
01063                         , _modelContainment  , _partOfModels
01064                         , _folderContainment , _partOfFolders
01065                         , _baseTypeOf        , _derivedTypesOf
01066                         , _libraryElementHandling          // 0: stubs, 1: stop, 2: continue
01067                         , _wrappingMode                    // 0: miniproject, 1: automatic, 2: as is
01068                         , _kindFilter                      // -1 = all, otherwise calculate the 0b000rsamf mask, where f = Folders, m = Models, a = Atoms, s = Sets, r = References
01069                         , _markThem                        // -1 = do not mark
01070                         , _directionDown
01071                         , PutOut( sel_fcos), PutOut( sel_folders)
01072                         , PutOut( top_fcos), PutOut( top_folders)
01073                         , &tops_filled
01074                         , PutOut( acc_kinds)
01075                         ));
01076 
01077                 if( !sel_fcos && !sel_folders) return;
01078 
01079                 if( _copyToFile == VARIANT_TRUE) 
01080                 {
01081                         CComPtr<IMgaDumper> dumper;
01082                         COMTHROW( dumper.CoCreateInstance(L"Mga.MgaDumper") );
01083 
01084                         if( _wrappingMode == 0)
01085                         {
01086                                         COMTHROW( dumper->DumpClos( sel_fcos, sel_folders, _userSelFileName, _options) );
01087                         }
01088                         else if( _wrappingMode == 1 || _wrappingMode == 2)
01089                         {
01090                                 if ( tops_filled == VARIANT_TRUE)
01091                                         COMTHROW( dumper->DumpClosR( sel_fcos, sel_folders, _userSelFileName, top_fcos, top_folders, _options, 0, acc_kinds));
01092                                 else 
01093                                         // dump like in miniproject case from The RootFolder
01094                                         // if the data is copied to clipboard then the DumpClosR will call the 
01095                                         // DumpClos when it will realize the topfco and topfolders are empty
01096                                         COMTHROW( dumper->DumpClos( sel_fcos, sel_folders, _userSelFileName, _options));
01097                         }
01098                 }
01099                 else // _copyToFile == VARIANT_FALSE 
01100                 {
01101                         CGMEDataDescriptor GMEDataDescriptor( rectSelectedList, CRectList(), rectFrame.TopLeft(), CPoint( 0,0));
01102                         CGMEClosureDataSource * pGMEClosureDataSource = new CGMEClosureDataSource( pMgaContext->m_ccpProject);
01103 
01104                         if ( sel_fcos)          pGMEClosureDataSource->SetNodes( sel_fcos);
01105                         if ( sel_folders)       pGMEClosureDataSource->SetFolders( sel_folders);
01106                         
01107                         if ( top_fcos)          pGMEClosureDataSource->SetTopNodes( top_fcos);
01108                         if ( top_folders)       pGMEClosureDataSource->SetTopNodes( top_folders);
01109 
01110                         pGMEClosureDataSource->SetOptions( _options);
01111                         pGMEClosureDataSource->SetAcceptingKinds( acc_kinds);
01112 
01113                         pGMEClosureDataSource->CacheDescriptor( &GMEDataDescriptor);
01114                         pGMEClosureDataSource->SetClipboard();
01115                         pGMEClosureDataSource->FlushClipboard();
01116                 }
01117         }
01118         else
01119         {
01120                 MessageBox(_T("No object selected"),_T("Copy Error"), MB_ICONERROR);
01121         }
01122 
01123         CGMEDataDescriptor::destructList( rectSelectedList);
01124 }
01125 
01126 void CAggregatePropertyPage::DoCopySmart( int k /*= 0*/)
01127 {
01128         bool is_any_folder_selected = false;
01129         bool all_containers = true;
01130         bool all_refs = true;
01131         bool all_sets = true;
01132         bool all_conns = true;
01133 
01134         bool any_container = false;
01135         bool any_ref = false;
01136         bool any_set = false;
01137         bool any_conn = false;
01138 
01139         CGMEActiveBrowserApp * pApp = (CGMEActiveBrowserApp*) AfxGetApp();
01140         CMgaContext * pMgaContext = &pApp->m_CurrentProject.m_MgaContext;
01141         
01142         CComObjPtr<IMgaFCOs> ccpSelectedFCOs;
01143         CComObjPtr<IMgaFolders> ccpSelectedFolders;
01144         COMTHROW( ccpSelectedFCOs.CoCreateInstance( L"Mga.MgaFCOs"));
01145         COMTHROW( ccpSelectedFolders.CoCreateInstance( L"Mga.MgaFolders"));
01146 
01147         typedef CTypedPtrList< CPtrList, CRect *> CRectList;
01148         CRectList rectSelectedList;
01149         CRect rectItem;
01150         CRect rectFrame(0,0,0,0);
01151 
01152 
01153         for( HTREEITEM hItem = m_TreeAggregate.GetFirstSelectedItem(); 
01154                 hItem; 
01155                 hItem = m_TreeAggregate.GetNextSelectedItem( hItem))
01156         {
01157                 CAggregateMgaObjectProxy ObjectProxy;
01158                 if( m_TreeAggregate.m_MgaMap.LookupObjectProxy( hItem, ObjectProxy))
01159                 {
01160                         all_containers &= (ObjectProxy.m_TypeInfo == OBJTYPE_MODEL || ObjectProxy.m_TypeInfo == OBJTYPE_FOLDER);
01161                         all_refs  &= (ObjectProxy.m_TypeInfo == OBJTYPE_REFERENCE);
01162                         all_sets  &= (ObjectProxy.m_TypeInfo == OBJTYPE_SET);
01163                         all_conns &= (ObjectProxy.m_TypeInfo == OBJTYPE_CONNECTION);
01164 
01165                         any_container |= (ObjectProxy.m_TypeInfo == OBJTYPE_MODEL || ObjectProxy.m_TypeInfo == OBJTYPE_FOLDER);
01166                         any_ref  |= (ObjectProxy.m_TypeInfo == OBJTYPE_REFERENCE);
01167                         any_set  |= (ObjectProxy.m_TypeInfo == OBJTYPE_SET);
01168                         any_conn |= (ObjectProxy.m_TypeInfo == OBJTYPE_CONNECTION);
01169 
01170                         if ( ObjectProxy.m_TypeInfo == OBJTYPE_MODEL                    // FCOs: connection too
01171                            || ObjectProxy.m_TypeInfo == OBJTYPE_ATOM
01172                            || ObjectProxy.m_TypeInfo == OBJTYPE_REFERENCE
01173                            || ObjectProxy.m_TypeInfo == OBJTYPE_SET
01174                            || ObjectProxy.m_TypeInfo == OBJTYPE_CONNECTION)
01175                         {
01176                                 CComQIPtr<IMgaFCO> ccpMgaFCO( ObjectProxy.m_pMgaObject);
01177                                 if( ccpMgaFCO)
01178                                 {
01179                                         // Finding the rectangle of the selected item
01180                                         m_TreeAggregate.GetItemRect( hItem, rectItem, TRUE);
01181                                         // Computing the frame of all rectangles
01182                                         rectFrame.UnionRect( rectFrame, rectItem);
01183 
01184                                         // Adding to the selected rectangle list to create the image
01185                                         rectSelectedList.AddTail( new CRect( rectItem));
01186                                         
01187                                         // Append to the selected FCO list
01188                                         COMTHROW(ccpSelectedFCOs->Append( ccpMgaFCO));
01189                                 }
01190                         }
01191                         else if ( ObjectProxy.m_TypeInfo == OBJTYPE_FOLDER )
01192                         {
01193                                 CComQIPtr<IMgaFolder> ccpMgaFolder( ObjectProxy.m_pMgaObject);
01194                                 if( ccpMgaFolder)
01195                                 {
01196                                         {
01197                                                 // Finding the rectangle of the selected item
01198                                                 m_TreeAggregate.GetItemRect( hItem, rectItem, TRUE);
01199                                                 // Computing the frame of all rectangles
01200                                                 rectFrame.UnionRect( rectFrame, rectItem);
01201 
01202                                                 // Adding to the selected rectangle list to create the image
01203                                                 rectSelectedList.AddTail( new CRect( rectItem));
01204                                                 
01205                                                 // Append to the selected FCO list
01206                                                 COMTHROW(ccpSelectedFolders->Append( ccpMgaFolder));
01207                                                 is_any_folder_selected = true;
01208                                         }
01209                                 }
01210                         }
01211                 }               
01212         }
01213         
01214         if ( rectSelectedList.GetCount()!=0)
01215         {
01216                 CComPtr<IMgaClosure> cl;
01217                 CComObjPtr<IMgaFCOs> sel_fcos, top_fcos;
01218                 CComObjPtr<IMgaFolders> sel_folders, top_folders;
01219                 long options;
01220                 CComBstrObj acckinds; 
01221                 CComBstrObj path; 
01222 
01223                 // commented out when new smart copy introduced
01224                 // if container selected then it must be lonely (no multiple selection)
01225                 // if container selected no other kinds allowed
01226                 //if( any_container && !all_containers || rectSelectedList.GetCount() > 1 && all_containers)
01227                 //{
01228                 //      MessageBox("Invalid selection for smart copy. You can select either one container or several non-containers.","Copy Error", MB_ICONERROR);
01229                 //      return;
01230                 //}
01231 
01232                 if( any_container) k |= 1024;
01233 
01234                 if( any_ref) k |= 2048;
01235                 if( any_set) k |= 4096;
01236                 if( any_conn) k |= 8192;
01237                 if( is_any_folder_selected)  k |= 16384;
01238 
01239                 COMTHROW( cl.CoCreateInstance(L"Mga.MgaClosure") );
01240                 
01241                 COMTHROW( cl->SmartCopy( 
01242                         ccpSelectedFCOs, 
01243                         ccpSelectedFolders, 
01244                         PutOut( sel_fcos), 
01245                         PutOut( sel_folders), 
01246                         PutOut( top_fcos), 
01247                         PutOut( top_folders), 
01248                         k,
01249                         &options,
01250                         PutOut( acckinds),
01251                         PutOut( path)
01252                         ));
01253 
01254                 if ( sel_fcos || sel_folders) // if both null the operation is not needed (either dumped to file already or unsuccessful)
01255                 {
01256                         CRectList dummyAnnList;
01257 
01258                         CGMEDataDescriptor GMEDataDescriptor( rectSelectedList, dummyAnnList, rectFrame.TopLeft(), CPoint( 0,0));
01259 
01260                         CGMEClosureDataSource * pGMEClosureDataSource = new CGMEClosureDataSource( pMgaContext->m_ccpProject);
01261                         
01262                         if ( sel_fcos)          pGMEClosureDataSource->SetNodes( sel_fcos);
01263                         if ( sel_folders)       pGMEClosureDataSource->SetFolders( sel_folders);
01264 
01265                         if ( top_fcos)          pGMEClosureDataSource->SetTopNodes( top_fcos);
01266                         if ( top_folders)       pGMEClosureDataSource->SetTopNodes( top_folders);
01267 
01268 
01269                         pGMEClosureDataSource->SetOptions( options);
01270                         pGMEClosureDataSource->SetAbsPathPart( path);
01271                         pGMEClosureDataSource->SetAcceptingKinds( acckinds);
01272 
01273                         pGMEClosureDataSource->CacheDescriptor( &GMEDataDescriptor);
01274 
01275                         pGMEClosureDataSource->SetClipboard();
01276                         pGMEClosureDataSource->FlushClipboard();
01277                 }
01278         }
01279         else
01280         {
01281                 MessageBox(_T("No object selected"),_T("Copy Error"), MB_ICONERROR);
01282         }
01283 
01284         CGMEDataDescriptor::destructList( rectSelectedList);
01285 }
01286 
01287 void CAggregatePropertyPage::DoDrag( CPoint ptDrag)
01288 {
01289         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
01290         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
01291         
01292         CGMEDataSource GMEDataSource(pMgaContext->m_ccpProject);
01293 
01294         CComObjPtr<IMgaFCOs> ccpSelectedFCOs;
01295         COMTHROW(ccpSelectedFCOs.CoCreateInstance(L"Mga.MgaFCOs"));
01296         CComObjPtr<IMgaFolders> ccpSelectedFolders;
01297         COMTHROW( ccpSelectedFolders.CoCreateInstance( L"Mga.MgaFolders"));
01298 
01299         typedef CTypedPtrList<CPtrList, CRect *> CRectList;
01300         CRectList rectSelectedList;
01301         CRect   rectItem;
01302         CRect rectFrame(0,0,0,0);
01303 
01304 
01305         for(HTREEITEM hItem=m_TreeAggregate.GetFirstSelectedItem();hItem;
01306                                                 hItem=m_TreeAggregate.GetNextSelectedItem(hItem))
01307         {
01308                 CAggregateMgaObjectProxy ObjectProxy;
01309                 if(m_TreeAggregate.m_MgaMap.LookupObjectProxy(hItem, ObjectProxy))
01310                 {
01311                         if(ObjectProxy.m_TypeInfo==OBJTYPE_MODEL||                      // FCOs
01312                            ObjectProxy.m_TypeInfo==OBJTYPE_ATOM||
01313                            ObjectProxy.m_TypeInfo==OBJTYPE_CONNECTION||
01314                            ObjectProxy.m_TypeInfo==OBJTYPE_REFERENCE||
01315                            ObjectProxy.m_TypeInfo==OBJTYPE_SET)
01316                         {
01317                                 CComQIPtr<IMgaFCO>ccpMgaFCO(ObjectProxy.m_pMgaObject);
01318                                 if(ccpMgaFCO)
01319                                 {
01320                                         // Finding the rectangle of the selected item
01321                                         m_TreeAggregate.GetItemRect(hItem,rectItem,TRUE);
01322                                         // Computing the frame of all rectangles
01323                                         rectFrame.UnionRect(rectFrame,rectItem);
01324 
01325                                         // Adding to the selected rectangle list to create the image
01326                                         rectSelectedList.AddTail(new CRect(rectItem));
01327                                         
01328                                         // Append to the selected FCO list
01329                                         COMTHROW(ccpSelectedFCOs->Append(ccpMgaFCO));
01330                                 }
01331                         }
01332                         else if ( ObjectProxy.m_TypeInfo == OBJTYPE_FOLDER )
01333                         {
01334                                 CComQIPtr<IMgaFolder> ccpMgaFolder( ObjectProxy.m_pMgaObject);
01335                                 if( ccpMgaFolder)
01336                                 {
01337                                         // Finding the rectangle of the selected item
01338                                         m_TreeAggregate.GetItemRect( hItem, rectItem, TRUE);
01339                                         // Computing the frame of all rectangles
01340                                         rectFrame.UnionRect( rectFrame, rectItem);
01341 
01342                                         // Adding to the selected rectangle list to create the image
01343                                         rectSelectedList.AddTail( new CRect( rectItem));
01344 
01345                                         // Append to the selected FCO list
01346                                         COMTHROW(ccpSelectedFolders->Append( ccpMgaFolder));
01347                                 }
01348                         }
01349                         else
01350                         {
01351                                 m_TreeAggregate.SelectItemEx(hItem,FALSE);
01352                         }
01353                 }               
01354         }
01355         
01356         if(rectSelectedList.GetCount()!=0)
01357         {
01358                 CRectList dummyAnnList;
01359 
01360                 CGMEDataDescriptor GMEDataDescriptor(rectSelectedList, dummyAnnList,rectFrame.TopLeft(),CPoint(0,0));
01361 
01362                 if ( ccpSelectedFCOs)           GMEDataSource.SetNodes( CComPtr<IMgaFCOs>(ccpSelectedFCOs));
01363                 if ( ccpSelectedFolders)        GMEDataSource.SetFolders( CComPtr<IMgaFolders>(ccpSelectedFolders));
01364 
01365                 GMEDataSource.CacheDescriptor(&GMEDataDescriptor);
01366 
01367                 m_TreeAggregate.CreateDragImageEx(ptDrag);              
01368                 GMEDataSource.DoDragDrop(DROPEFFECT_COPY | DROPEFFECT_LINK | DROPEFFECT_MOVE);
01369                 m_TreeAggregate.DeleteDragImageEx();
01370                 
01371         }
01372 
01373         CGMEDataDescriptor::destructList( rectSelectedList);
01374 }
01375 
01376 
01377 void CAggregatePropertyPage::OnClickTreeAggregate(NMHDR* pNMHDR, LRESULT* pResult) 
01378 {
01379         *pResult = 0;
01380 }
01381 
01382 void CAggregatePropertyPage::OnSelChangedTreeAggregate(NMHDR* pNMHDR, LRESULT* pResult) 
01383 {
01384         NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
01385 
01386         
01387         // Setting the focus here, because combo could make the selection
01388         // PETER: I have commented this, since it prevented multiple undo-s (CTRL-Z)
01389         // m_TreeAggregate.SetFocus();
01390 
01391         // Displaying the first selection in the combo edit
01392         HTREEITEM hItem=m_TreeAggregate.GetFirstSelectedItem();
01393         if(hItem)
01394         {
01395                 m_ComboSearchCtrl.SetSelection(hItem);
01396                 
01397                 LPUNKNOWN pUnknown=NULL;
01398 
01399                 if(m_TreeAggregate.m_MgaMap.LookupObjectUnknown(hItem,pUnknown))
01400                 {
01401                         TRACE(m_TreeAggregate.GetItemText(hItem));
01402 
01403                         // Firing the event
01404                         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
01405                         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
01406 
01407                         // MOD by Peter: do not fire events from transactions
01408                         if (!pMgaContext->IsInTransaction()) {
01409                                 pApp->GetCtrl()->FireClickMgaObject(pUnknown);
01410                         }
01411                 }
01412 
01413         }
01414 
01415         *pResult = 0;
01416 }
01417 
01418 
01419 void CAggregatePropertyPage::OnDblclkTreeAggregate(NMHDR* pNMHDR, LRESULT* pResult) 
01420 {
01421 
01422         
01423 
01424         DWORD dwMsgPos = ::GetMessagePos();
01425 
01426         CPoint point = CPoint(GET_X_LPARAM(dwMsgPos), GET_Y_LPARAM(dwMsgPos) );
01427         UINT nHitFlags;
01428         
01429         m_TreeAggregate.ScreenToClient(&point);
01430         m_TreeAggregate.HitTest( point, &nHitFlags );
01431 
01432         
01433         if(nHitFlags&TVHT_ONITEMBUTTON)
01434         {
01435                 return;
01436         }
01437 
01438         HTREEITEM hItem=m_TreeAggregate.GetSelectedItem();
01439         
01440         LPUNKNOWN pUnknown=NULL;
01441 
01442         if(m_TreeAggregate.m_MgaMap.LookupObjectUnknown(hItem,pUnknown))
01443         {
01444                 TRACE(m_TreeAggregate.GetItemText(hItem));
01445 
01446                 // Firing the event
01447                 CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
01448                 if( ::GetKeyState( VK_SHIFT) < 0)
01449                         pApp->GetCtrl()->FireShowInParentMgaObject(pUnknown);
01450                 else
01451                         pApp->GetCtrl()->FireDblClickMgaObject(pUnknown);
01452         }
01453 
01454         *pResult = -1; // Nonzero return: disables auto expanding (default action)
01455 }
01456 
01457 void CAggregatePropertyPage::PrepareStateImageList()
01458 {
01459         CImageList ImageList;
01460         ImageList.Create(16,16,ILC_MASK|ILC_COLOR24,0,0);
01461         
01462         CBitmap bm;
01463         bm.LoadBitmap(IDB_IMAGELIST_AGGREGATE_STATE);
01464 
01465         ImageList.Add(&bm,RGB(128, 158, 8));    // Pretty natural transparent color 
01466                                                                                         // provided by Tamas Paka
01467 
01468 
01469         CClientDC dcClient(this);
01470          CDC dcMem;
01471          CBitmap Bitmap;
01472 
01473          if (!dcMem.CreateCompatibleDC(&dcClient))return;
01474 
01475          if (!Bitmap.CreateCompatibleBitmap(&dcClient,256,16)) return;
01476 
01477          CBitmap *pOldMemDCBitmap = dcMem.SelectObject(&Bitmap);
01478 
01479          COLORREF cMaskColor=RGB(128,58,8);
01480          dcMem.FillSolidRect(0, 0, 256, 16, cMaskColor);
01481 
01482          // Paint each Image in the DC
01483 
01484          for(BYTE i=0;i<=15;i++)
01485         {
01486                 if(i&0x0001) // Access
01487                 {
01488                         
01489                         ImageList.Draw(&dcMem, 1, CPoint(i*16,0), ILD_TRANSPARENT);
01490 
01491                 }
01492                 else
01493                 {
01494                         
01495                 }
01496 
01497                 if(i&0x0002) // LibObject
01498                 {
01499                         ImageList.Draw(&dcMem, 0, CPoint(i*16,0), ILD_TRANSPARENT);
01500                 }
01501                 if(i&0x0004) // Instance
01502                 {
01503                         ImageList.Draw(&dcMem, 5, CPoint(i*16,0), ILD_TRANSPARENT);
01504                 }
01505 
01506                 if(i&0x0008)    // Derived (subtype)
01507                 {
01508                         ImageList.Draw(&dcMem, 4, CPoint(i*16,0), ILD_TRANSPARENT);
01509                 }
01510                 
01511 
01512         }
01513 
01514 /*
01515                         #ifdef _DEBUG
01516                                    CDC *pWndDC=GetDC();
01517                                    BitBlt(pWndDC->GetSafeHdc(),0,0,rectComplete.Width(),rectComplete.Height(),dcMem.GetSafeHdc(),0,0,SRCCOPY);
01518                                    ReleaseDC(pWndDC);
01519                         #endif
01520 */
01521          dcMem.SelectObject(pOldMemDCBitmap);
01522 
01523 
01524          
01525          m_StateImageList.Create(16,16, ILC_COLOR | ILC_MASK, 0, 1);
01526 
01527          // Green is used as mask color
01528          m_StateImageList.Add(&Bitmap, cMaskColor); 
01529 
01530          Bitmap.DeleteObject();
01531         
01532 
01533         m_TreeAggregate.SetImageList(&m_StateImageList,TVSIL_STATE);
01534 
01535 }
01536 
01537 void CAggregatePropertyPage::AttachLibrary()
01538 {
01539 
01540         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
01541         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
01542 
01543         CAttachLibDlg dlg;      
01544         _bstr_t conn;
01545         COMTHROW(pMgaContext->m_ccpProject->get_ProjectConnStr(conn.GetAddress()));
01546         dlg.m_strParentConnection = static_cast<const wchar_t*>(conn);
01547         dlg.m_strCaption=_T("Attach Library");
01548         
01549         if(dlg.DoModal() == IDOK && !dlg.m_strConnString.IsEmpty()) 
01550         {
01551                 // be flexible in MGA case ( if _T("MGX") is not present )
01552                 if( dlg.m_strConnString.Left(4) == _T("MGX="))
01553                 {
01554                         // add quotes to the folderpath if not there
01555                         if( dlg.m_strConnString.Mid(4,1) != _T("\"") && dlg.m_strConnString.Right(1) != _T("\""))
01556                                 dlg.m_strConnString = _T("MGX=\"") + dlg.m_strConnString.Mid( 4) + _T("\"");
01557                 }
01558                 else // MGA is presumed in this case
01559                 {
01560                         if (dlg.relativePath != "")
01561                                 dlg.m_strConnString = dlg.relativePath;
01562                 }
01563 
01564                 MSGTRY {
01565                         HTREEITEM hItem = m_TreeAggregate.GetFirstSelectedItem();
01566                         if (hItem != NULL) 
01567                         { 
01568                                 
01569                                 LPUNKNOWN pUnknown;
01570                                 
01571                                 if(m_TreeAggregate.m_MgaMap.LookupObjectUnknown(hItem,pUnknown))
01572                                 {
01573                                         
01574                                         CComQIPtr<IMgaFolder> ccpFolder(pUnknown);
01575                                         if(!ccpFolder)return;
01576                                         
01577                                         CGMEActiveBrowserApp* pApp = (CGMEActiveBrowserApp*)AfxGetApp();
01578                                         CMgaContext* pMgaContext = &pApp->m_CurrentProject.m_MgaContext;
01579                                         
01580                                         // toggle off Constraint Manager
01581                                         CComPtr<IMgaComponentEx> constrMgr;
01582                                         if (pMgaContext) {
01583                                                 constrMgr = pMgaContext->FindConstraintManager();
01584                                                 if (constrMgr)
01585                                                         COMTHROW(constrMgr->Enable(false));
01586                                                 if (pMgaContext->m_ccpProject)
01587                                                         COMTHROW(pMgaContext->m_ccpProject->Notify(APPEVENT_LIB_ATTACH_BEGIN));
01588                                         }
01589 
01590                                         pMgaContext->BeginTransaction(TRANSACTION_NON_NESTED);
01591 
01592                                         COMTHROW(ccpFolder->AttachLibraryV3( CComBSTR( dlg.m_strConnString), dlg.m_bOptimized, NULL));
01593                                         pMgaContext->CommitTransaction();
01594                                         
01595                                         // toggle back Constraint Manager (done only after commit, so that it will not catch the events happened in the transaction)
01596                                         if (pMgaContext) {
01597                                                 if (constrMgr)
01598                                                         COMTHROW(constrMgr->Enable(true));
01599                                                 if(pMgaContext->m_ccpProject)
01600                                                         COMTHROW(pMgaContext->m_ccpProject->Notify(APPEVENT_LIB_ATTACH_END));
01601                                         }
01602 
01603                                         CComBSTR msg( L"Library attached: ");
01604                                         COMTHROW(msg.Append( dlg.m_strConnString));
01605                                         COMTHROW(msg.Append( L" (Note: Constraint Manager was turned off during attach to speed it up.)"));
01606                                         Utils::put2Console( Utils::get_GME( pMgaContext->m_ccpProject)
01607                                                 , msg
01608                                                 , MSG_INFO);
01609                                 }
01610                         }
01611         
01612                 }
01613                 MSGCATCH(_T("Error while trying to attach library"),pMgaContext->AbortTransaction();)   
01614                 Refresh();
01615         }
01616 }
01617 
01618 void CAggregatePropertyPage::RefreshLibrary()
01619 {
01620         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
01621         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
01622 
01623         HTREEITEM hItem = m_TreeAggregate.GetFirstSelectedItem();
01624         if (hItem != NULL) 
01625         { 
01626                 
01627                 LPUNKNOWN pUnknown;
01628                 
01629                 if(!m_TreeAggregate.m_MgaMap.LookupObjectUnknown(hItem,pUnknown))return;
01630                                         
01631                 CComQIPtr<IMgaFolder> ccpFolder(pUnknown);
01632                 if(!ccpFolder)return;
01633 
01634                 MSGTRY {
01635                         
01636                         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
01637                         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
01638 
01639                         pMgaContext->BeginTransaction(true);
01640 
01641                         CComBSTR bszLibName;                                            
01642                         COMTHROW(ccpFolder->get_LibraryName(&bszLibName));
01643                         ASSERT( bszLibName); // it should be a library
01644 
01645                         bool was_opt = false;
01646                         if( bszLibName)
01647                                 was_opt = CAggregateTreeCtrl::IsUngroupedLibrary( ccpFolder); // was optimized/ungrouped
01648 
01649                         pMgaContext->CommitTransaction();
01650                 
01651                         if(!bszLibName)
01652                         {
01653                 
01654                                 AfxMessageBox(_T("Selected node is not a library"));
01655                                 return;
01656                         }
01657                 
01658                         CAttachLibDlg dlg;
01659                         _bstr_t conn;
01660                         COMTHROW(pMgaContext->m_ccpProject->get_ProjectConnStr(conn.GetAddress()));
01661                         dlg.m_strParentConnection = static_cast<const wchar_t*>(conn);
01662                         dlg.m_strConnString=bszLibName;
01663                         dlg.m_strCaption=_T("Refresh Library");
01664                         dlg.m_bOptimized = was_opt;
01665 
01666                         if(dlg.DoModal() == IDOK) 
01667                         {
01668                                 pMgaContext->BeginTransaction(TRANSACTION_NON_NESTED);
01669                                         
01670                                 long errs;
01671                                 if (dlg.relativePath != "") {
01672                                         COMTHROW(ccpFolder->RefreshLibraryV3( CComBSTR( dlg.relativePath), dlg.m_bOptimized, &errs) );
01673                                 } else {
01674                                         COMTHROW(ccpFolder->RefreshLibraryV3( CComBSTR( dlg.m_strConnString), dlg.m_bOptimized, &errs) );
01675                                 }
01676                                 ccpFolder.Release();
01677                                 pMgaContext->CommitTransaction();
01678                         }
01679                 } MSGCATCH(_T("Error while refreshing library"),pMgaContext->AbortTransaction();)       
01680                 Refresh();
01681         }
01682 }
01683 
01684 void CAggregatePropertyPage::LibraryDependencies()
01685 {
01686         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
01687         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
01688 
01689         HTREEITEM hItem = m_TreeAggregate.GetFirstSelectedItem();
01690         if (hItem != NULL) 
01691         { 
01692                 
01693                 LPUNKNOWN pUnknown;
01694                 
01695                 if(!m_TreeAggregate.m_MgaMap.LookupObjectUnknown(hItem,pUnknown))return;
01696                                         
01697                 CComQIPtr<IMgaFolder> ccpFolder(pUnknown);
01698                 if(!ccpFolder)return;
01699 
01700                 MSGTRY {
01701                         
01702                         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
01703                         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
01704 
01705                         pMgaContext->BeginTransaction(false);
01706 
01707                         CComBSTR bszLibName;                                            
01708                         COMTHROW(ccpFolder->get_LibraryName(&bszLibName));
01709                 
01710                         if(!bszLibName)
01711                         {
01712                                 AfxMessageBox(_T("Selected node is not a library"));
01713                         }
01714                         else
01715                         {
01716                                 CString msg0; CopyTo( bszLibName, msg0);
01717                                 msg0 = _T("Library [") + msg0 + _T("] dependencies");
01718 
01719                                 CComPtr<IMgaFolders> coll_inc, coll_iby;
01720 
01721                                 COMTHROW( ccpFolder->GetVirtuallyIncludedBy( &coll_iby));
01722                                 COMTHROW( ccpFolder->GetVirtuallyIncludes  ( &coll_inc));
01723 
01724                                 CString msg1, msg2;
01725                                 composeInfo( _T("Included virtually in:\n"), coll_iby, msg1);
01726                                 composeInfo( _T("Virtually includes:\n"), coll_inc, msg2);
01727 
01728                                 AfxMessageBox( msg0 + _T("\n\n") + msg1 + _T("\n\n") + msg2, MB_ICONINFORMATION);
01729                         }
01730 
01731                         //pMgaContext->CommitTransaction();
01732                         pMgaContext->AbortTransaction();
01733 
01734                 } MSGCATCH(_T("Error while viewing library dependencies"),pMgaContext->AbortTransaction();)     
01735                 //Refresh();
01736         }
01737 }
01738 
01739 bool CAggregatePropertyPage::askUserAndDeleteLibrary( CComPtr<IMgaFolder> p_ccpFolder)
01740 {
01741         if( !p_ccpFolder) return false;
01742         CComBSTR bszLibName;
01743         COMTHROW( p_ccpFolder->get_LibraryName(&bszLibName));
01744 
01745         if( !bszLibName)
01746         {
01747                 ASSERT( 0);
01748                 AfxMessageBox( _T("Selected node is not a library"));
01749                 return false;
01750         }
01751 
01752         CString ln;
01753         CopyTo( bszLibName, ln);
01754 
01755         CString deps; CComBSTR depb;
01756         CComBSTR path( L"_includedBy");
01757 
01758         COMTHROW( p_ccpFolder->get_RegistryValue( path, &depb));
01759 
01760         CopyTo( depb, deps);
01761         if( deps.IsEmpty())
01762         {
01763                 deps = _T("No dependent libraries found.");
01764         }
01765         else
01766         {
01767                 deps = _T("Dependent libraries found:\n") + deps;
01768         }
01769         deps += _T("\n\nDelete ") + ln + _T("?");
01770         if( IDYES == AfxMessageBox( deps, MB_YESNO))
01771         {
01772                 //p_ccpFolder->PutReadOnlyAccess( VARIANT_FALSE);
01773                 COMTHROW(p_ccpFolder->DestroyObject());
01774                 return true;
01775         }
01776 
01777         return false;
01778 }
01779 
01780 void CAggregatePropertyPage::OnContextMenu(CWnd*, CPoint point)
01781 {
01782 
01783         if(!m_TreeAggregate.IsWindowEnabled())return;
01784 
01785         if (point.x == -1 && point.y == -1){
01786                 //keystroke invocation
01787                 CRect rect;
01788                 GetClientRect(rect);
01789                 ClientToScreen(rect);
01790 
01791                 point = rect.TopLeft();
01792                 point.Offset(5, 5);
01793         }
01794 
01795         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
01796         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
01797 
01798         MSGTRY{
01799                 CAggregateContextMenu menu(this);
01800                 menu.Run(point);
01801         } MSGCATCH(_T("Cannot complete operation"),pMgaContext->AbortTransaction();)
01802 
01803 
01804 }
01805 
01806 
01807 void CAggregatePropertyPage::OnEndLabelEditTreeAggregate(NMHDR* pNMHDR, LRESULT* pResult) 
01808 {
01809         TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
01810         
01811         if(!pTVDispInfo->item.pszText)return; // Edit cancelled
01812 
01813         CString strNewLabel(pTVDispInfo->item.pszText);
01814 
01815         CComBSTR bszDispName(strNewLabel);
01816 
01817         HTREEITEM hSelItem=m_TreeAggregate.GetFirstSelectedItem();
01818         LPUNKNOWN pUnknown;
01819         if(m_TreeAggregate.m_MgaMap.LookupObjectUnknown(hSelItem,pUnknown))
01820         {
01821                 CComQIPtr<IMgaObject> ccpMgaObject(pUnknown);
01822                 if(ccpMgaObject)
01823                 {
01824                         // Starting transaction
01825                         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
01826                         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
01827 
01828                         MSGTRY{
01829                                 pMgaContext->BeginTransaction(false);
01830 
01831                                 bool isLibraryRoot = false;
01832 
01833                                 // The name is special if folder is a library root
01834                                 CComPtr<IMgaFolder>ccpMgaFolder;
01835                                 if (SUCCEEDED(ccpMgaObject.QueryInterface(&ccpMgaFolder))) {
01836                                         CComBSTR dummyName;
01837                                         COMTHROW(ccpMgaFolder->get_LibraryName(&dummyName));
01838                                         if (dummyName != NULL) {
01839                                                 isLibraryRoot = true;
01840                                                 COMTHROW(ccpMgaFolder->put_LibraryName(bszDispName));
01841                                         }
01842                                 }
01843 
01844                                 if (!isLibraryRoot) {
01845                                         COMTHROW(ccpMgaObject->put_Name(bszDispName));
01846                                 }
01847 
01848 
01849                                 // Checking if it is root folder
01850                                 // If it is, change project name as well
01851                                 objtype_enum oeType;
01852                                 CComPtr<IMgaObject> ccpParent;
01853 
01854                                 COMTHROW(ccpMgaObject->GetParent(&ccpParent,&oeType));
01855                                 
01856                                 if(ccpParent==NULL)     // Root Folder
01857                                 {
01858                                         COMTHROW( pMgaContext->m_ccpProject->put_Name(bszDispName));
01859                                 }
01860 
01861                                 // Ending transaction
01862                                 pMgaContext->CommitTransaction();
01863 
01864                                 if( !ccpParent) // parentless, means> Root Folder 
01865                                 {
01866                                         // FireRootFolderNameChanged event fired
01867                                         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
01868                                         pApp->GetCtrl()->FireRootFolderNameChanged();
01869                                 }
01870 
01871                         }MSGCATCH(_T("Error retrieving object name"),pMgaContext->AbortTransaction();)  
01872                 }
01873         }
01874 
01875 
01876         *pResult = 0;
01877 }
01878 
01879 #define DEBUG_EVENTS
01880 
01881 
01882 #ifdef DEBUG_EVENTS
01883  #define EVENT_TRACE(x) TRACE(x)
01884 #else
01885  #define EVENT_TRACE(x)
01886 #endif 
01887 
01888 
01889 // This function is indirectly initiated by MGA, 
01890 // so we do not need transaction handling
01891 void CAggregatePropertyPage::OnMgaEvent(CComPtr<IMgaObject> ccpMgaObject, unsigned long lEventMask)
01892 {
01893         EVENT_TRACE("\n__________ MGA Event Handling Begin _________\n");
01894 
01895         // Handling Object Events
01896 
01897         if(lEventMask&OBJEVENT_PROPERTIES)
01898         {
01899                 EVENT_TRACE("OBJEVENT_PROPERTIES handled.\n");
01900                 
01901                 // Finding the object in the tree
01902                 HTREEITEM hItem;
01903                 
01904                 if(m_TreeAggregate.m_MgaMap.LookupTreeItem(ccpMgaObject,hItem)) // The changed object is in the tree
01905                 {
01906                         // Change name
01907                         m_TreeAggregate.SetItemText(hItem,GetDisplayedName(ccpMgaObject));
01908                         m_TreeAggregate.SortItems();
01909 
01910                         // Setting the state icons
01911                         m_TreeAggregate.SetItemProperties(hItem);
01912 
01913                 }
01914         }
01915 
01916         if(lEventMask&OBJEVENT_CREATED)
01917         {
01918                 EVENT_TRACE("OBJEVENT_CREATED handled.\n");
01919 
01920                 CComPtr<IMgaObject> ccpParent;
01921                 objtype_enum otParentType;
01922                 //objtype_enum otMgaObjectType;
01923                 COMTHROW( ccpMgaObject->GetParent(&ccpParent,&otParentType) );
01924                 if(ccpParent)
01925                 {
01926                         // Finding the parent in the tree
01927                         HTREEITEM hParentItem;
01928                         
01929                         if(m_TreeAggregate.m_MgaMap.LookupTreeItem(ccpParent,hParentItem)) // The parent of the created object is in the tree
01930                         {
01931                                 // Setting parent state
01932                                 if(m_Options.m_bIsDynamicLoading &&
01933                                         !(m_TreeAggregate.GetItemState(hParentItem,TVIS_EXPANDED)&TVIS_EXPANDED)) 
01934                                 {
01935                                         TVITEM tvItem;
01936                                         tvItem.hItem=hParentItem;
01937                                         tvItem.mask=TVIF_CHILDREN|TVIF_HANDLE;
01938                                         tvItem.cChildren=1;
01939                                         m_TreeAggregate.SetItem(&tvItem);
01940 
01941                                         if(m_bIsBrowserCreatedNewObject)
01942                                         {
01943                                                 // Deleting TVIS_EXPANDEDONCE otherwise parent does not
01944                                                 // get notification
01945                                                 m_TreeAggregate.CTreeCtrl::SetItemState(hParentItem,0,TVIS_EXPANDEDONCE);
01946                                                 m_TreeAggregate.Expand(hParentItem,TVE_EXPAND);
01947                                                 HTREEITEM hNewItem;
01948                                                 if(m_TreeAggregate.m_MgaMap.LookupTreeItem(ccpMgaObject,hNewItem))
01949                                                 {
01950                                                         m_TreeAggregate.EnsureVisible(hNewItem);
01951                                                         m_TreeAggregate.ClearSelection(TRUE);
01952                                                         m_TreeAggregate.SelectItem(hNewItem);
01953                                                         m_TreeAggregate.SetFocus();                     
01954                                                         m_TreeAggregate.Invalidate();
01955                                                         m_TreeAggregate.EditLabel(hNewItem);
01956                                                 }
01957                                         }
01958                 
01959 
01960                                 }
01961                                 else
01962                                 {
01963                                         if(m_bIsBrowserCreatedNewObject||
01964                                                 m_TreeAggregate.GetItemState(hParentItem,TVIS_EXPANDED)&TVIS_EXPANDED) 
01965                                         {
01966                                                 BOOL bisBrwCreNwObj = m_bIsBrowserCreatedNewObject; // save the value
01967                                                 Refresh(); // will reset m_bIsBrowserCreatedNewObject
01968 
01969                                                 // inserted to correct the behaviour that labels were edited
01970                                                 // by default only when 
01971                                                 //    1. the first child has been created in a container
01972                                                 //    2. a child was created in a container, but the container was not expanded
01973                                                 // Now it will always edit the label!
01974                                                 HTREEITEM hNewItem;
01975                                                 if( bisBrwCreNwObj // browser created new object
01976                                                  && m_TreeAggregate.m_MgaMap.LookupTreeItem(ccpMgaObject,hNewItem))
01977                                                 {
01978                                                         m_TreeAggregate.EnsureVisible(hNewItem);
01979                                                         m_TreeAggregate.ClearSelection(TRUE);
01980                                                         m_TreeAggregate.SelectItem(hNewItem);
01981                                                         m_TreeAggregate.SetFocus();                     
01982                                                         m_TreeAggregate.Invalidate();
01983                                                         m_TreeAggregate.EditLabel(hNewItem);
01984                                                 }
01985                                                 // end of insertion by Zolmol
01986 
01987                                                 /*COMTHROW( ccpMgaObject->get_ObjType(&otMgaObjectType) );
01988                                                 HTREEITEM hNewItem=m_TreeAggregate.InsertItem(hParentItem,GetDisplayedName(ccpMgaObject),
01989                                                                                                                 ccpMgaObject,otMgaObjectType);
01990                                         
01991                                                 m_TreeAggregate.SortItems(hParentItem);
01992                                                 // If the browser created the object select it, and offer editing
01993                                                 if(m_bIsBrowserCreatedNewObject)
01994                                                 {                       
01995                                                         m_TreeAggregate.EnsureVisible(hNewItem);
01996                                                         m_TreeAggregate.SetFocus();                     
01997                                                         m_TreeAggregate.SelectItem(hNewItem);
01998                                                         m_TreeAggregate.Invalidate(TRUE);                                                       
01999                                                         m_TreeAggregate.EditLabel(hNewItem);//->MoveWindow(rectItem,TRUE);
02000                                                 }       */
02001                                         
02002                                         }
02003                                 }
02004                         }
02005                 }
02006                 m_bIsBrowserCreatedNewObject=FALSE;
02007         }
02008         if(lEventMask&OBJEVENT_DESTROYED)
02009         {
02010                 EVENT_TRACE("OBJEVENT_DESTROYED handled.\n");
02011                 
02012                 // Finding the object in the tree
02013                 HTREEITEM hItem = NULL, hParentItem = NULL;
02014                 
02015                 if(m_TreeAggregate.m_MgaMap.LookupTreeItem(ccpMgaObject,hItem)) // The deleted object is in the tree
02016                 {       
02017                         // Remember the parent
02018                         hParentItem=m_TreeAggregate.GetParentItem(hItem);
02019                         // Remove item                  
02020                         m_TreeAggregate.DeleteItem(hItem);
02021                 }
02022                 
02023                 CComBSTR id;
02024                 ccpMgaObject->get_ID(&id);
02025                 auto highlightIt = m_TreeAggregate.m_highlightedObjects.find(id);
02026                 if (highlightIt != m_TreeAggregate.m_highlightedObjects.end())
02027                 {
02028                         m_TreeAggregate.m_highlightedObjects.erase(highlightIt);
02029                 }
02030 
02031                 // If the parent is in the object tree and there is dynamic loading
02032                 // we set the +/- button
02033                 if(m_Options.m_bIsDynamicLoading)
02034                 {
02035                         if(hParentItem) // The parent of the deleted object is in the tree
02036                         {
02037                                 TVITEM tvItem;
02038                                 tvItem.hItem=hParentItem;
02039                                 tvItem.mask=TVIF_CHILDREN|TVIF_HANDLE;
02040                                 tvItem.cChildren=HasDisplayedChild(hParentItem);
02041 
02042                                 // Setting icons
02043                                 int nImage,nSelectedImage;
02044                                 m_TreeAggregate.GetItemImage(hParentItem,nImage,nSelectedImage);                                
02045 
02046                                 bool bIsExpanded =!!(m_TreeAggregate.GetItemState(hParentItem,TVIS_EXPANDED)&TVIS_EXPANDED);
02047                                 if (nImage >= ICON_NUMBER * 8)
02048                                 {
02049                                         bIsExpanded &= !!tvItem.cChildren;
02050                                         m_TreeAggregate.SetItemImage(hParentItem, (nImage & ~1) + (bIsExpanded ? 1 : 0), (nImage & ~1) + (bIsExpanded ? 1 : 0));
02051                                 }
02052                                 else
02053                                 {
02054                                         if(tvItem.cChildren)
02055                                         {
02056                                                 if(bIsExpanded && nImage<ICON_NUMBER)
02057                                                 {
02058                                                         m_TreeAggregate.SetItemImage(hParentItem,nImage+ICON_NUMBER,nSelectedImage+ICON_NUMBER);
02059                                                 }
02060                                         }
02061                                         else
02062                                         {       if (nImage>=ICON_NUMBER)
02063                                                 {
02064                                                         m_TreeAggregate.SetItemImage(hParentItem,nImage-ICON_NUMBER,nSelectedImage-ICON_NUMBER);
02065                                                 }
02066                                         }
02067                                 }
02068 
02069                                 m_TreeAggregate.SetItem(&tvItem);
02070                         }
02071                 }
02072 
02073         }
02074         if(lEventMask&OBJEVENT_PARENT)
02075         {
02076                 EVENT_TRACE("OBJEVENT_PARENT handled.\n");
02077                                 
02078                 // Finding the object in the tree
02079                 HTREEITEM hItem, hParentItem;
02080                 
02081                 if(m_TreeAggregate.m_MgaMap.LookupTreeItem(ccpMgaObject,hItem)) // The deleted object is in the tree
02082                 {       
02083                         // Remember the parent
02084                         hParentItem=m_TreeAggregate.GetParentItem(hItem);
02085 
02086                         // Remove the children of the item
02087                         if(m_Options.m_bIsDynamicLoading) // inserted by ZolMol to correct the bug when a model/folder is moved elsewhere in expanded state
02088                                 m_TreeAggregate.DeleteAllChildren( hItem);
02089 
02090                         // Remove item
02091                         m_TreeAggregate.DeleteItem(hItem);
02092                 }
02093                 // If the parent is in the object tree and there is dynamic loading
02094                 // we set the +/- button
02095                 if(m_Options.m_bIsDynamicLoading)
02096                 {
02097                         if(hParentItem) // The parent of the deleted object is in the tree
02098                         {
02099                                 TVITEM tvItem;
02100                                 tvItem.hItem=hParentItem;
02101                                 tvItem.mask=TVIF_CHILDREN|TVIF_HANDLE;
02102                                 tvItem.cChildren=HasDisplayedChild(hParentItem);
02103         
02104                                 // Setting icons
02105                                 int nImage,nSelectedImage;
02106                                 m_TreeAggregate.GetItemImage(hParentItem,nImage,nSelectedImage);
02107 
02108                                 bool bIsExpanded = !!(m_TreeAggregate.GetItemState(hParentItem,TVIS_EXPANDED)&TVIS_EXPANDED);
02109                                 if (nImage >= ICON_NUMBER * 8)
02110                                 {
02111                                         bIsExpanded &= !!tvItem.cChildren;
02112                                         m_TreeAggregate.SetItemImage(hParentItem, (nImage & ~1) + (bIsExpanded ? 1 : 0), (nImage & ~1) + (bIsExpanded ? 1 : 0));
02113                                 }
02114                                 else
02115                                 {
02116                                         if(tvItem.cChildren)
02117                                         {
02118                                                 if(bIsExpanded && nImage<ICON_NUMBER)
02119                                                 {
02120                                                         m_TreeAggregate.SetItemImage(hParentItem,nImage+ICON_NUMBER,nSelectedImage+ICON_NUMBER);
02121                                                 }
02122                                         }
02123                                         else
02124                                         {       
02125                                                 if(nImage>=ICON_NUMBER)
02126                                                 {
02127                                                         m_TreeAggregate.SetItemImage(hParentItem,nImage-ICON_NUMBER,nSelectedImage-ICON_NUMBER);
02128                                                 }
02129                                         }
02130                                 }
02131 
02132                                 m_TreeAggregate.SetItem(&tvItem);
02133                         }
02134                 }       
02135         }
02136 
02137         if(lEventMask&OBJEVENT_NEWCHILD)
02138         {
02139                 EVENT_TRACE("OBJEVENT_NEWCHILD handled.\n");
02140 
02141                 HTREEITEM hParentItem;
02142                 if(m_TreeAggregate.m_MgaMap.LookupTreeItem(ccpMgaObject,hParentItem))
02143                 {
02144                         if(m_Options.m_bIsDynamicLoading)
02145                         {
02146                                 bool bIsExpanded=!!(m_TreeAggregate.GetItemState(hParentItem,TVIS_EXPANDED)&TVIS_EXPANDED);
02147                                 if(bIsExpanded)
02148                                 {
02149                                         reqBuildAggregateTree(hParentItem,ccpMgaObject,2,0,true);
02150                                 }
02151 
02152                                 TVITEM tvItem;
02153                                 tvItem.hItem=hParentItem;
02154                                 tvItem.mask=TVIF_CHILDREN|TVIF_HANDLE;
02155                                 tvItem.cChildren=HasDisplayedChild(hParentItem);
02156 
02157                                 // Setting icons
02158                                 int nImage,nSelectedImage;
02159                                 m_TreeAggregate.GetItemImage(hParentItem,nImage,nSelectedImage);                                
02160 
02161                                 if (nImage >= ICON_NUMBER * 8)
02162                                 {
02163                                         m_TreeAggregate.SetItemImage(hParentItem, (nImage & ~1) + (bIsExpanded ? 1 : 0), (nImage & ~1) + (bIsExpanded ? 1 : 0));
02164                                 }
02165                                 else
02166                                 {
02167                                         if(tvItem.cChildren)
02168                                         {
02169                                                 if(bIsExpanded && nImage<ICON_NUMBER)
02170                                                 {
02171                                                         m_TreeAggregate.SetItemImage(hParentItem,nImage+ICON_NUMBER,nSelectedImage+ICON_NUMBER);
02172                                                 }
02173                                         }
02174                                         else
02175                                         {       if(nImage>=ICON_NUMBER)
02176                                                 {
02177                                                         m_TreeAggregate.SetItemImage(hParentItem,nImage-ICON_NUMBER,nSelectedImage-ICON_NUMBER);
02178                                                 }
02179 
02180                                         }
02181                                 }
02182 
02183                                 m_TreeAggregate.SetItem(&tvItem);
02184                         }
02185                         else
02186                         {
02187                                 Refresh();
02188                         }
02189                 }
02190         }
02191 
02192         if(lEventMask&OBJEVENT_LOSTCHILD)
02193         {
02194                 EVENT_TRACE("OBJEVENT_LOSTCHILD is partially handled.\n");              
02195 
02196                 // Finding the object in the tree
02197                 HTREEITEM hParentItem = NULL;
02198                 
02199                 if(m_TreeAggregate.m_MgaMap.LookupTreeItem(ccpMgaObject,hParentItem))           // If parent is in the tree
02200                 {
02201                         if(m_Options.m_bIsDynamicLoading)
02202                         {
02203                                 bool bIsExpanded=!!(m_TreeAggregate.GetItemState(hParentItem,TVIS_EXPANDED)&TVIS_EXPANDED);
02204                                 if(!bIsExpanded)        // If the parent was expanded, the whole stuff was handled by OBJECT_DESTROYED
02205                                 {
02206                                         TVITEM tvItem;
02207                                         tvItem.hItem=hParentItem;
02208                                         tvItem.mask=TVIF_CHILDREN|TVIF_HANDLE;
02209                                         tvItem.cChildren=reqHasDisplayedChild(ccpMgaObject);
02210 
02211                                         // Setting icons
02212                                         int nImage,nSelectedImage;
02213                                         m_TreeAggregate.GetItemImage(hParentItem,nImage,nSelectedImage);                                
02214 
02215                                         if (nImage >= ICON_NUMBER * 8)
02216                                         {
02217                                                 bIsExpanded &= !!tvItem.cChildren;
02218                                                 m_TreeAggregate.SetItemImage(hParentItem, (nImage & ~1) + (bIsExpanded ? 1 : 0), (nImage & ~1) + (bIsExpanded ? 1 : 0));
02219                                         }
02220                                         else
02221                                         // if no children then if opened icon used previously, change it to the closed icon
02222                                         {       
02223                                                 if(nImage>=ICON_NUMBER)
02224                                                 {
02225                                                         m_TreeAggregate.SetItemImage(hParentItem,nImage-ICON_NUMBER,nSelectedImage-ICON_NUMBER);
02226                                                 }
02227                                         }
02228 
02229                                         m_TreeAggregate.SetItem(&tvItem);
02230                                 }
02231                         }
02232                 }
02233         }
02234 
02235 
02236         if(lEventMask&OBJEVENT_REGISTRY)
02237         {
02238                 EVENT_TRACE("OBJEVENT_REGISTRY is partially  handled.\n");
02239 
02240                 // PETER: We need this, because of Library names
02241 
02242                 // Finding the object in the tree
02243                 HTREEITEM hItem;
02244                 
02245                 if(m_TreeAggregate.m_MgaMap.LookupTreeItem(ccpMgaObject,hItem)) // The changed object is in the tree
02246                 {
02247                         // Change name
02248                         m_TreeAggregate.SetItemText(hItem,GetDisplayedName(ccpMgaObject));
02249                         m_TreeAggregate.SortItems();
02250 
02251                         // Setting the state icons
02252                         m_TreeAggregate.SetItemProperties(hItem);
02253 
02254                 }
02255         }
02256 
02257         
02258 #ifdef _DEBUG
02259         // Messages that are not handled are not included in release, 
02260         // but useful for further development, so left here
02261 
02262         if(lEventMask&OBJEVENT_ATTR)
02263         {
02264                 EVENT_TRACE("OBJEVENT_ATTR not handled.\n");
02265         }
02266         
02267         if(lEventMask&OBJEVENT_RELATION)
02268         {
02269                 EVENT_TRACE("OBJEVENT_RELATION not handled.\n");
02270         }
02271         if(lEventMask&OBJEVENT_SUBT_INST)
02272         {
02273                 EVENT_TRACE("OBJEVENT_SUBT_INST not handled.\n");
02274         }
02275         if(lEventMask&OBJEVENT_REFERENCED)
02276         {
02277                 EVENT_TRACE("OBJEVENT_REFERENCED not handled.\n");
02278         }
02279         if(lEventMask&OBJEVENT_CONNECTED)
02280         {
02281                 EVENT_TRACE("OBJEVENT_CONNECTED not handled.\n");
02282         }
02283         if(lEventMask&OBJEVENT_SETINCLUDED)
02284         {
02285                 EVENT_TRACE("OBJEVENT_SETINCLUDED not handled.\n");
02286         }
02287         if(lEventMask&OBJEVENT_REFRELEASED)
02288         {
02289                 EVENT_TRACE("OBJEVENT_REFRELEASED not handled.\n");
02290         }
02291         if(lEventMask&OBJEVENT_DISCONNECTED)
02292         {
02293                 EVENT_TRACE("OBJEVENT_DISCONNECTED not handled.\n");
02294         }
02295         if(lEventMask&OBJEVENT_SETEXCLUDED)
02296         {
02297                 EVENT_TRACE("OBJEVENT_SETEXCLUDED not handled.\n");
02298         }
02299         if(lEventMask&OBJEVENT_USERBITS)
02300         {
02301                 EVENT_TRACE("OBJEVENT_USERBITS not handled.\n");
02302         }
02303         if(lEventMask&OBJEVENT_CLOSEMODEL)
02304         {
02305                 EVENT_TRACE("OBJEVENT_CLOSEMODEL not handled.\n");
02306         }
02307 
02308         EVENT_TRACE("_________ MGA Event Handling End _______\n");
02309 #endif /*_DEBUG */
02310 
02311 }
02312 
02313 
02314 void CAggregatePropertyPage::GotoIUnk(BSTR Id)
02315 {
02316         bool worked = false;
02317         IUnknown *pUnknown = NULL;
02318         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
02319         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
02320         MSGTRY{
02321                 // Starting transaction
02322                 pMgaContext->BeginTransaction();
02323                 HTREEITEM hNewItem;
02324                 if(m_TreeAggregate.m_MgaMap.SearchTreeItem(Id,hNewItem, pUnknown))
02325                 {
02326                                                 m_TreeAggregate.EnsureVisible(hNewItem);
02327                                                 m_TreeAggregate.ClearSelection(TRUE);
02328                                                 m_TreeAggregate.SelectItem(hNewItem);
02329                                                 m_TreeAggregate.SetFocus();                     
02330                                                 m_TreeAggregate.Invalidate();
02331                                                 worked = true;
02332                 }
02333                 else  // expand the tree until item reached
02334                 {
02335                         _bstr_t id;
02336                         _bstr_t bId = Id;
02337                         CComPtr<IMgaObject> iitem;
02338                         CComPtr<IMgaFCO> fiitem;
02339                         std::vector<_bstr_t> item;
02340                         int itemcount = 0;
02341                         CComPtr<IMgaObject> parent;
02342                         
02343                         pMgaContext->BeginTransaction();
02344                         CComPtr<IMgaProject> project = pMgaContext->m_ccpProject;
02345                         COMTHROW(project->GetFCOByID(bId, &fiitem));
02346                         COMTHROW(fiitem.QueryInterface(&iitem));
02347                         item.push_back(Id);
02348                         itemcount++;
02349                         do
02350                         {
02351                                 objtype_enum objtype;
02352                                 COMTHROW(iitem->GetParent(&parent, &objtype));
02353                                 _bstr_t bstrid;
02354                                 COMTHROW(parent->get_ID(bstrid.GetAddress()));
02355                                 id = bstrid;
02356                                 item.push_back(id);
02357                                 itemcount++;
02358                                 iitem = parent;
02359                                 parent.Release();
02360                         } while (!m_TreeAggregate.m_MgaMap.SearchTreeItem(id,hNewItem, pUnknown));
02361                         pMgaContext->CommitTransaction();
02362                         // open the parents in backward order
02363                         worked = true;
02364                         m_TreeAggregate.EnsureVisible(hNewItem);
02365                         m_TreeAggregate.ClearSelection(TRUE);
02366                         m_TreeAggregate.SelectItem(hNewItem);
02367                         m_TreeAggregate.SendMessage(WM_KEYDOWN, (WPARAM)107, (LPARAM)0);
02368                         for (itemcount-=2; itemcount > 0; itemcount--)
02369                         {
02370                                 if (m_TreeAggregate.m_MgaMap.SearchTreeItem(item[itemcount],hNewItem, pUnknown))
02371                                 {
02372                                         m_TreeAggregate.EnsureVisible(hNewItem);
02373                                         m_TreeAggregate.ClearSelection(TRUE);
02374                                         m_TreeAggregate.SelectItem(hNewItem);
02375                                         m_TreeAggregate.SendMessage(WM_KEYDOWN, (WPARAM)107, (LPARAM)0);
02376                                 }
02377                         }
02378                         if (m_TreeAggregate.m_MgaMap.SearchTreeItem(item[0],hNewItem, pUnknown))
02379                         {
02380                                 m_TreeAggregate.EnsureVisible(hNewItem);
02381                                 m_TreeAggregate.ClearSelection(TRUE);
02382                                 m_TreeAggregate.SelectItem(hNewItem);
02383                         }
02384                 }
02385                 pMgaContext->CommitTransaction ();                                                              
02386         }MSGCATCH(_T("Error completing the operation"),pMgaContext->AbortTransaction();)        
02387         if (worked)
02388                 pApp->GetCtrl()->FireClickMgaObject(pUnknown);
02389 
02390 }
02391 
02392 void CAggregatePropertyPage::GotoIUnkPtr( IMgaObject * p_obj)
02393 {
02394         if( !p_obj) return;
02395 
02396         bool worked = false;
02397         IUnknown *pUnknown = NULL;
02398 
02399         CGMEActiveBrowserApp* pApp = (CGMEActiveBrowserApp*)AfxGetApp();
02400         CMgaContext* pMgaContext = &pApp->m_CurrentProject.m_MgaContext;
02401 
02402         MSGTRY
02403         {
02404                 // Starting transaction
02405                 pMgaContext->BeginTransaction();
02406                 HTREEITEM hNewItem;
02407 
02408                 CComPtr<IMgaObject>  obj        ( p_obj);
02409                 COMTHROW( p_obj->QueryInterface( &pUnknown));
02410 
02411                 if( !obj) 
02412                         throw hresult_exception( E_INVALIDARG);
02413 
02414                 //if(m_TreeAggregate.m_MgaMap.SearchTreeItem(Id,hNewItem, pUnknown))
02415                 if( m_TreeAggregate.m_MgaMap.LookupTreeItem( pUnknown, hNewItem))
02416                 {
02417                                                 m_TreeAggregate.EnsureVisible(hNewItem);
02418                                                 m_TreeAggregate.ClearSelection(TRUE);
02419                                                 m_TreeAggregate.SelectItem(hNewItem);
02420                                                 m_TreeAggregate.SetFocus();                     
02421                                                 m_TreeAggregate.Invalidate();
02422                                                 worked = true;
02423                 }
02424                 else // expand the tree until item reached
02425                 {
02426                         //CComPtr<IMgaProject> project = pMgaContext->m_ccpProject;
02427                         CComPtr<IMgaObject> parent;
02428                         CComPtr<IMgaObject> iitem = obj;
02429 
02430                         // coll of ptrs
02431                         CComObjPtr<IMgaObjects> coll;
02432                         COMTHROW( coll.CoCreateInstance( L"Mga.MgaObjects"));
02433                         if( !coll) 
02434                                 throw hresult_exception( E_INVALIDARG);
02435 
02436                         // strings of ids
02437                         _bstr_t id;
02438                         _bstr_t item[ 100];
02439                         int     itemcount = 0;
02440 
02441                         pMgaContext->BeginTransaction(true); // read-only transaction
02442 
02443                         // coll of ptrs
02444                         COMTHROW( coll->Append( obj));
02445 
02446                         // strings of ids
02447                         CComBSTR Id;
02448                         COMTHROW( obj->get_ID( &Id));
02449                         item[ itemcount++] = Id;
02450 
02451                         do
02452                         {
02453                                 objtype_enum objtype;
02454                                 COMTHROW(iitem->GetParent(&parent, &objtype));
02455 
02456                                 // coll of ptrs
02457                                 COMTHROW( coll->Append( parent));
02458 
02459                                 // strings of ids
02460                                 BSTR bstrid = NULL;
02461                                 COMTHROW(parent->get_ID(&bstrid));
02462                                 id = bstrid;
02463                                 item[itemcount++] = id;
02464 
02465                                 iitem = parent;
02466                                 parent.Release();
02467                         } while( !m_TreeAggregate.m_MgaMap.LookupTreeItem( iitem, hNewItem));
02468                         //} while( !m_TreeAggregate.m_MgaMap.SearchTreeItem( (wchar_t*)((char*)id), hNewItem, pUnknown));
02469 
02470                         pMgaContext->CommitTransaction();
02471                         
02472                         // open the parents in backward order
02473                         worked = true;
02474                         m_TreeAggregate.EnsureVisible(hNewItem);
02475                         m_TreeAggregate.ClearSelection(TRUE);
02476                         m_TreeAggregate.SelectItem(hNewItem);
02477                         m_TreeAggregate.SendMessage(WM_KEYDOWN, (WPARAM)107, (LPARAM)0);
02478                         for (itemcount-=2; itemcount > 0; itemcount--) // valid itemcount range will be: from last-1 to 1
02479                         {
02480                                 CComPtr<IMgaObject> obj_i;
02481                                 COMTHROW( coll->get_Item( itemcount + 1, &obj_i)); // plus 1
02482 
02483                                 //if (m_TreeAggregate.m_MgaMap.SearchTreeItem((wchar_t*)((char*)item[itemcount]),hNewItem, pUnknown))
02484                                 if( m_TreeAggregate.m_MgaMap.LookupTreeItem( obj_i, hNewItem))
02485                                 {
02486                                         m_TreeAggregate.EnsureVisible( hNewItem);
02487                                         m_TreeAggregate.ClearSelection( TRUE);
02488                                         m_TreeAggregate.SelectItem( hNewItem);
02489                                         m_TreeAggregate.SendMessage( WM_KEYDOWN, (WPARAM)107, (LPARAM)0);
02490                                 }
02491                         }
02492                         
02493                         CComPtr<IMgaObject> obj_1st;
02494                         COMTHROW( coll->get_Item( 1, &obj_1st));
02495                         //if (m_TreeAggregate.m_MgaMap.SearchTreeItem(item[0],hNewItem, pUnknown))
02496                         if( m_TreeAggregate.m_MgaMap.LookupTreeItem( obj_1st, hNewItem))
02497                         {
02498                                 m_TreeAggregate.EnsureVisible( hNewItem);
02499                                 m_TreeAggregate.ClearSelection( TRUE);
02500                                 m_TreeAggregate.SelectItem( hNewItem);
02501                         }
02502                 }
02503                 pMgaContext->CommitTransaction();
02504         }
02505         MSGCATCH( _T("Error completing the operation"), pMgaContext->AbortTransaction();)
02506 
02507         if( worked)
02508                 pApp->GetCtrl()->FireClickMgaObject( pUnknown);
02509 }
02510 
02511 
02512 void CAggregatePropertyPage::Refresh()
02513 {
02514 
02515         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
02516         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
02517         
02518         MSGTRY{
02519                 // Starting transaction
02520                 pMgaContext->BeginTransaction();
02521 
02522                 m_TreeAggregate.StoreState();
02523 
02524                 m_TreeAggregate.CleanUp();
02525                 m_ComboSearchCtrl.ResetContent();
02526 
02527                 m_bIsBrowserCreatedNewObject=FALSE;
02528                 SetupTree();
02529                 m_TreeAggregate.SortItems();
02530 
02531                 m_TreeAggregate.RestoreState();
02532         }MSGCATCH(_T("Error refreshing tree browser data"),pMgaContext->AbortTransaction();)    
02533         // Ending transaction
02534         pMgaContext->CommitTransaction();
02535 
02536 
02537 }
02538 
02539 void CAggregatePropertyPage::OnKeyDownTreeAggregate(NMHDR* pNMHDR, LRESULT* pResult) 
02540 {
02541         TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*)pNMHDR;
02542         switch(pTVKeyDown->wVKey)
02543         {
02544         case VK_DELETE: // Delete selected items
02545                 {
02546                         CAggregateContextMenu menu(this);
02547                         menu.OnEditDelete();
02548                 }break;
02549         case VK_RETURN: // Display the first selected item in GME editor
02550                 {
02551                                 HTREEITEM hItem=m_TreeAggregate.GetSelectedItem();
02552                                 LPUNKNOWN pUnknown=NULL;
02553 
02554                                 if(m_TreeAggregate.m_MgaMap.LookupObjectUnknown(hItem,pUnknown))
02555                                 {
02556                                         TRACE(m_TreeAggregate.GetItemText(hItem));
02557 
02558                                         // Firing the event
02559                                         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
02560                                         if( ::GetKeyState( VK_SHIFT) < 0)
02561                                                 pApp->GetCtrl()->FireShowInParentMgaObject(pUnknown);
02562                                         else
02563                                                 pApp->GetCtrl()->FireDblClickMgaObject(pUnknown);
02564                                         m_TreeAggregate.SetFocus();
02565                                 }
02566                 }break;
02567         case VK_TAB:
02568                 {
02569                         if( ::GetKeyState( VK_CONTROL) < 0) {
02570                                 m_parent->nextTab( ::GetKeyState( VK_SHIFT) >= 0);
02571                         }
02572                         else {
02573                                 m_ComboEditCtrl.SetFocus();
02574                         }
02575                 }break;
02576         case 0x43: //VK_C
02577                 {
02578                         if( ::GetKeyState( VK_CONTROL) < 0) {
02579                                 this->DoCopy();
02580                         }
02581                 }break;
02582         case 0x59: //VK_Y
02583                 {
02584                         if( ::GetKeyState( VK_CONTROL) < 0) {
02585                                 CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
02586                                 CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
02587                                 
02588                                 short nRedoSize,nUndoSize;
02589                                 COMTHROW(pMgaContext->m_ccpProject->UndoRedoSize(&nUndoSize,&nRedoSize));
02590 
02591                                 if( nRedoSize > 0)
02592                                 {
02593                                         COMTHROW(pMgaContext->m_ccpProject->Redo());
02594                                         m_TreeAggregate.SetFocus();
02595                                 }
02596                         }
02597                 }break;
02598         case 0x5A: // VK_Z
02599                 {
02600                         if( ::GetKeyState( VK_CONTROL) < 0) {
02601                                 CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
02602                                 CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
02603                                 
02604                                 short nRedoSize,nUndoSize;
02605                                 COMTHROW(pMgaContext->m_ccpProject->UndoRedoSize(&nUndoSize,&nRedoSize));
02606 
02607                                 if( nUndoSize > 0)
02608                                 {
02609                                         COMTHROW(pMgaContext->m_ccpProject->Undo());
02610                                         m_TreeAggregate.SetFocus();
02611                                 }
02612                         }
02613                 }break;
02614         case 0x56: //VK_V
02615                 {
02616                         if( ::GetKeyState( VK_CONTROL) < 0) {
02617                                 COleDataObject OleDataObject;
02618                                 CString msg;
02619                                 if( OleDataObject.AttachClipboard()) {
02620                                         auto op = DRAGOP_COPY;
02621                                         if (::GetKeyState(VK_SHIFT) & 0x8000)
02622                                         {
02623                                                 op = DRAGOP_REFERENCE;
02624                                         }
02625                                         if( m_TreeAggregate.DoDrop(op, &OleDataObject, CPoint( 0, 0))) {
02626                                                 // what about set focus back
02627                                                 m_TreeAggregate.SetFocus();
02628                                         }
02629                                 } else msg = _T("Cannot recover data from the clipboard.");
02630 
02631                                 if( !msg.IsEmpty()) MessageBox( msg, _T("Paste Error"), MB_ICONERROR);
02632                         }
02633                 }break;
02634         case 0x46: //VK_F:
02635                 {
02636                         if( ::GetKeyState( VK_CONTROL) < 0) { // launch Find Box
02637                                 CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
02638                                 pApp->GetCtrl()->FireShowFindDlg();
02639                         }
02640                 }break;
02641         case 0x41: // VK_A
02642         case 0x49: // VK_I
02643                 {
02644                         if( ::GetKeyState( VK_CONTROL) < 0) { // launch ObjectInspector Box
02645                                 CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
02646                                 pApp->GetCtrl()->FireShowObjInspDlg();
02647                         }
02648                         else if( ::GetKeyState( VK_MENU) < 0) { // alt pressed
02649                                 CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
02650                                 pApp->GetCtrl()->FireCycleObjInsp( (::GetKeyState( VK_SHIFT) >= 0)? VARIANT_TRUE:VARIANT_FALSE);
02651                         }
02652                 }break;
02653         case VK_F2: // rename
02654                 {
02655                                 HTREEITEM hItem=m_TreeAggregate.GetSelectedItem();
02656                                 m_TreeAggregate.EditLabel(hItem);
02657                 }break;
02658         }
02659         
02660         *pResult = 0;
02661 }
02662 
02663 void CAggregatePropertyPage::OnGetDispInfoTreeAggregate(NMHDR* pNMHDR, LRESULT* pResult) 
02664 {
02665         TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
02666 
02667 /*
02668         // Children callback
02669         if(pTVDispInfo->item.mask&TVIF_CHILDREN)
02670         {
02671                 if(m_Options.m_bIsDynamicLoading)
02672                 {
02673                         if(HasDisplayedChild(pTVDispInfo->item.hItem))
02674                         {
02675                                 pTVDispInfo->item.cChildren = 1;
02676                         }
02677                         else
02678                         {
02679                                 pTVDispInfo->item.cChildren = 0;
02680                         }
02681                 }
02682         }
02683 */      
02684         *pResult = 0;
02685 }
02686 
02687 BOOL CAggregatePropertyPage::HasDisplayedChild(HTREEITEM hItem)
02688 {
02689         
02690         LPUNKNOWN pUnknown=NULL;
02691 
02692 
02693         if(m_TreeAggregate.m_MgaMap.LookupObjectUnknown(hItem,pUnknown))
02694         {
02695                 CComQIPtr<IMgaObject> ccpMgaObject(pUnknown);
02696                 if(ccpMgaObject)
02697                 {
02698                         long status;
02699                         COMTHROW(ccpMgaObject->get_Status(&status));
02700                         if (status != OBJECT_EXISTS) {
02701                                 return FALSE;
02702                         }
02703 
02704                         return reqHasDisplayedChild(ccpMgaObject);
02705                 }
02706         }
02707         return FALSE;
02708 
02709 
02710 }
02711 
02712 
02713 BOOL CAggregatePropertyPage::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
02714 {
02715         // TODO: Add your specialized code here and/or call the base class
02716         
02717         return CPropertyPage::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
02718 }
02719 
02720 
02721 void CAggregatePropertyPage::OnSearch() 
02722 {
02723         AfxMessageBox(_T("Pushed."));   
02724 }
02725 
02726 BOOL CAggregatePropertyPage::OnSetActive() 
02727 {
02728         CActiveBrowserPropertySheet* pParent=(CActiveBrowserPropertySheet*)GetParent();
02729         pParent->m_PageInheritance.ResetRoot();
02730         pParent->SendMessage(DM_SETDEFID,IDC_SEARCH,0);
02731         ::SetFocus(GetDlgItem(IDC_SEARCH)->GetSafeHwnd());
02732         return CPropertyPage::OnSetActive();
02733 }
02734 
02735 
02736 void CAggregatePropertyPage::OnBeginDragTreeAggregate(NMHDR* pNMHDR, LRESULT* pResult) 
02737 {
02738         NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
02739         
02740         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
02741         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
02742 
02743 
02744         MSGTRY{
02745                 DoDrag(pNMTreeView->ptDrag);
02746         } MSGCATCH(_T("Error while dragging"),pMgaContext->AbortTransaction();)
02747         
02748 
02749         *pResult = 0;
02750 }
02751 
02752 
02753 
02754 
02755 
02756 
02757 
02758 
02759 
02760 
02761 
02762 
02770 
02771 
02772 
02773 
02774 
02775 
02776 
02777 
02778 
02779 
02780 
02781 CInheritancePropertyPage::CInheritancePropertyPage() 
02782         : CPropertyPage(CInheritancePropertyPage::IDD)
02783         , m_ComboEditCtrl(&m_ComboSearchCtrl)
02784         , m_ComboSearchCtrl(&m_TreeInheritance)
02785         , m_theCurrentRootFCO( NULL)
02786         , m_pPrevSelectedItem( NULL)
02787 {
02788         //{{AFX_DATA_INIT(CInheritancePropertyPage)
02789         //}}AFX_DATA_INIT
02790 }
02791 
02792 CInheritancePropertyPage::~CInheritancePropertyPage()
02793 {
02794         m_theCurrentRootFCO = NULL;
02795         m_pPrevSelectedItem = NULL;
02796         m_ImageList.DeleteImageList();
02797         m_StateImageList.DeleteImageList();
02798         VERIFY( m_ImageList.GetSafeHandle() == NULL);
02799         VERIFY( m_StateImageList.GetSafeHandle() == NULL);
02800 }
02801 
02802 void CInheritancePropertyPage::DoDataExchange(CDataExchange* pDX)
02803 {
02804         CPropertyPage::DoDataExchange(pDX);
02805         //{{AFX_DATA_MAP(CInheritancePropertyPage)
02806         DDX_Control(pDX, IDC__COMBO_SEARCH_INHERITANCE, m_ComboSearchCtrl);
02807         DDX_Control(pDX, IDC_TREE_INHERITANCE, m_TreeInheritance);
02808         //}}AFX_DATA_MAP
02809 }
02810 
02811 
02812 BEGIN_MESSAGE_MAP(CInheritancePropertyPage, CPropertyPage)
02813         //{{AFX_MSG_MAP(CInheritancePropertyPage)
02814         ON_WM_SIZE()
02815         ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_INHERITANCE, OnSelChangedTreeInheritance)
02816         ON_NOTIFY(NM_DBLCLK, IDC_TREE_INHERITANCE, OnDblclkTreeInheritance)
02817         ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREE_INHERITANCE, OnItemExpandingTreeInheritance)
02818         ON_NOTIFY(TVN_KEYDOWN, IDC_TREE_INHERITANCE, OnKeyDownTreeInheritance)
02819         //}}AFX_MSG_MAP
02820 END_MESSAGE_MAP()
02821 
02822 
02823 
02824 BOOL CInheritancePropertyPage::OnInitDialog() 
02825 {
02826         CPropertyPage::OnInitDialog();
02827         
02828         
02829         m_TreeInheritance.ModifyStyle(0,TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT
02830                                                                 |TVS_SHOWSELALWAYS );
02831 
02832         m_ImageList.Create(16,16,ILC_MASK|ILC_COLOR24,0,0);
02833         CBitmap bm;
02834         bm.LoadBitmap(IDB_IMAGELIST_INHERITANCE);
02835         m_ImageList.Add(&bm,RGB(128, 158, 8));
02836 
02837         m_TreeInheritance.SetImageList(&m_ImageList,TVSIL_NORMAL);
02838 
02839         // Creating the state image list
02840         PrepareStateImageList();
02841 
02842         m_TreeInheritance.EnableWindow(FALSE);
02843         m_ComboSearchCtrl.EnableWindow(FALSE);
02844 
02845         // Get edit control which happens to be the first child window
02846         // and subclass it
02847         m_ComboEditCtrl.SubclassWindow(m_ComboSearchCtrl.GetWindow(GW_CHILD)->GetSafeHwnd());
02848 
02849 
02850         return TRUE;  // return TRUE unless you set the focus to a control
02851                       // EXCEPTION: OCX Property Pages should return FALSE
02852 }
02853 
02854 void CInheritancePropertyPage::OnSize(UINT nType, int cx, int cy) 
02855 {
02856         CPropertyPage::OnSize(nType, cx, cy);
02857         
02858         if(     ::IsWindow(m_ComboSearchCtrl.GetSafeHwnd()) )
02859         {
02860                 int ySpace = GetSystemMetrics(SM_CYBORDER);
02861                 RECT clientRect;
02862                 m_ComboSearchCtrl.GetClientRect(&clientRect);
02863                 
02864                 m_TreeInheritance.MoveWindow(0, clientRect.bottom + 2*ySpace, cx-1, cy-clientRect.bottom - 2*ySpace - 1);
02865                 m_ComboSearchCtrl.MoveWindow(0, ySpace, cx-1, cy-1);
02866         }
02867         
02868 }
02869 
02870 void CInheritancePropertyPage::OpenProject()
02871 {
02872         m_TreeInheritance.EnableWindow(TRUE);
02873         m_ComboSearchCtrl.EnableWindow(TRUE);
02874         m_theCurrentRootFCO = NULL;
02875         m_pPrevSelectedItem=NULL;
02876 
02877 }
02878 
02879 void CInheritancePropertyPage::CloseProject()
02880 {
02881         m_TreeInheritance.CleanUp();
02882         m_TreeInheritance.EnableWindow(FALSE);
02883         
02884         m_ComboSearchCtrl.ResetContent();
02885         m_ComboSearchCtrl.EnableWindow(FALSE);
02886 
02887         m_theCurrentRootFCO = NULL;
02888         m_pPrevSelectedItem=NULL;
02889 
02890 }
02891 
02892 void CInheritancePropertyPage::PrepareStateImageList()
02893 {
02894         CImageList ImageList;
02895         ImageList.Create(16,16,ILC_MASK|ILC_COLOR24,0,0);
02896 
02897         CBitmap bm;
02898         bm.LoadBitmap(IDB_IMAGELIST_AGGREGATE_STATE);
02899 
02900         ImageList.Add(&bm,RGB(128, 158, 8));    // Pretty natural transparent color 
02901                                                                                         // provided by Tamas Paka
02902 
02903         CClientDC dcClient(this);
02904         CDC dcMem;
02905         CBitmap Bitmap;
02906 
02907         if (!dcMem.CreateCompatibleDC(&dcClient)) return;
02908 
02909         if (!Bitmap.CreateCompatibleBitmap(&dcClient,256,16)) return;
02910 
02911         CBitmap *pOldMemDCBitmap = dcMem.SelectObject(&Bitmap);
02912 
02913         COLORREF cMaskColor=RGB(128,58,8);
02914         dcMem.FillSolidRect(0, 0, 256, 16, cMaskColor);
02915 
02916         // Paint each Image in the DC
02917         for(BYTE i=0;i<=15;i++)
02918         {
02919                 if(i&0x0001) // Access
02920                 {
02921                         ImageList.Draw(&dcMem, 1, CPoint(i*16,0), ILD_TRANSPARENT);
02922                 }
02923 
02924                 if(i&0x0002) // LibObject
02925                 {
02926                         ImageList.Draw(&dcMem, 0, CPoint(i*16,0), ILD_TRANSPARENT);
02927                 }
02928                 if(i&0x0004) // Instance
02929                 {
02930                         ImageList.Draw(&dcMem, 5, CPoint(i*16,0), ILD_TRANSPARENT);
02931                 }
02932 
02933                 if(i&0x0008)    // Derived (subtype)
02934                 {
02935                         ImageList.Draw(&dcMem, 4, CPoint(i*16,0), ILD_TRANSPARENT);
02936                 }
02937         }
02938         dcMem.SelectObject(pOldMemDCBitmap);
02939 
02940         m_StateImageList.Create(16,16, ILC_COLOR | ILC_MASK, 0, 1);
02941 
02942         // Green is used as mask color
02943         m_StateImageList.Add(&Bitmap, cMaskColor); 
02944 
02945         Bitmap.DeleteObject();
02946 
02947         m_TreeInheritance.SetImageList(&m_StateImageList,TVSIL_STATE);
02948 }
02949 
02950 // This function is indirectly initiated by MGA, 
02951 // so we do not need transaction handling
02952 void CInheritancePropertyPage::OnMgaEvent(CComPtr<IMgaObject> ccpMgaObject, unsigned long lEventMask)
02953 {
02954         if( !m_theCurrentRootFCO) return;
02955         EVENT_TRACE("\n__________ MGA Event Handling Begin _________\n");
02956 
02957         // Handling Object Events
02958 
02959         if(lEventMask&OBJEVENT_CREATED)
02960         {
02961                 EVENT_TRACE("OBJEVENT_CREATED handled.\n");
02962 
02963                 m_TreeInheritance.StoreState();
02964                 m_TreeInheritance.CleanUp();
02965                 SetupTree2();
02966                 m_TreeInheritance.RestoreState();
02967         }
02968 
02969         if(lEventMask&OBJEVENT_DESTROYED)
02970         {
02971                 EVENT_TRACE("OBJEVENT_DESTROYED handled.\n");
02972 
02973                 m_TreeInheritance.StoreState();
02974                 m_TreeInheritance.CleanUp();
02975                 SetupTree2();
02976                 m_TreeInheritance.RestoreState();
02977         }
02978 
02979         if(lEventMask&OBJEVENT_PROPERTIES)
02980         {
02981                 EVENT_TRACE("OBJEVENT_PROPERTIES handled.\n");
02982 
02983                 // Finding the object in the tree
02984                 HTREEITEM hItem;
02985                 if(m_TreeInheritance.m_MgaMap.LookupTreeItem(ccpMgaObject,hItem)) // The changed object is in the tree
02986                 {
02987                         // Change name
02988                         m_TreeInheritance.SetItemText(hItem,GetDisplayedName(ccpMgaObject));
02989 
02990                         // Setting the state icons
02991                         //m_TreeInheritance.SetItemProperties(hItem);
02992                 }
02993         }
02994 
02995         if(lEventMask&OBJEVENT_REGISTRY)
02996         {
02997                 EVENT_TRACE("OBJEVENT_REGISTRY is partially  handled.\n");
02998 
02999                 // PETER: We need this, because of Library names
03000 
03001                 // Finding the object in the tree
03002                 HTREEITEM hItem;
03003                 if(m_TreeInheritance.m_MgaMap.LookupTreeItem(ccpMgaObject,hItem)) // The changed object is in the tree
03004                 {
03005                         // Change name
03006                         m_TreeInheritance.SetItemText(hItem,GetDisplayedName(ccpMgaObject));
03007 
03008                         // Setting the state icons
03009                         //m_TreeInheritance.SetItemProperties(hItem);
03010                 }
03011         }
03012 }
03013 
03014 void CInheritancePropertyPage::OnKeyDownTreeInheritance(NMHDR* pNMHDR, LRESULT* pResult) 
03015 {
03016         TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*)pNMHDR;
03017         switch(pTVKeyDown->wVKey)
03018         {
03019         case VK_RETURN: // Display the first selected item in GME editor
03020                 {
03021                                 HTREEITEM hItem=m_TreeInheritance.GetSelectedItem();
03022                                 LPUNKNOWN pUnknown=NULL;
03023 
03024                                 if(m_TreeInheritance.m_MgaMap.LookupObjectUnknown(hItem,pUnknown))
03025                                 {
03026                                         TRACE(m_TreeInheritance.GetItemText(hItem));
03027 
03028                                         // Firing the event
03029                                         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
03030                                         if( ::GetKeyState( VK_SHIFT) < 0)
03031                                                 pApp->GetCtrl()->FireShowInParentMgaObject(pUnknown);
03032                                         else
03033                                                 pApp->GetCtrl()->FireDblClickMgaObject(pUnknown);
03034                                         m_TreeInheritance.SetFocus();
03035                                 }
03036                 }break;
03037         case VK_TAB:
03038                 {
03039                         if( ::GetKeyState( VK_CONTROL) < 0) {
03040                                 m_parent->nextTab( ::GetKeyState( VK_SHIFT) >= 0);
03041                         }
03042                         else {
03043                                 m_ComboEditCtrl.SetFocus();
03044                         }
03045                 }break;
03046         }
03047 
03048         
03049         *pResult = 0;
03050 }
03051 
03052 
03053 void CInheritancePropertyPage::OnItemExpandingTreeInheritance(NMHDR* pNMHDR, LRESULT* pResult) 
03054 {
03055         NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
03056                 
03057         if(pNMTreeView->action==TVE_EXPAND)
03058         {
03059                 if(m_TreeInheritance.GetItemState(pNMTreeView->itemNew.hItem,TVIS_EXPANDED)
03060                                                                                                                                         &TVIS_EXPANDED)
03061                 {
03062                         return;
03063                 }
03064 
03065                 int nImage,nSelectedImage;
03066                 m_TreeInheritance.GetItemImage(pNMTreeView->itemNew.hItem,nImage,nSelectedImage);
03067                 m_TreeInheritance.SetItemImage(pNMTreeView->itemNew.hItem,nImage+ICON_NUMBER,nSelectedImage+ICON_NUMBER);
03068         }
03069         else
03070         {
03071                 if(!(m_TreeInheritance.GetItemState(pNMTreeView->itemNew.hItem,TVIS_EXPANDED)
03072                                                                                                                                         &TVIS_EXPANDED))
03073                 {
03074                         return;
03075                 }
03076 
03077                 int nImage,nSelectedImage;
03078                 m_TreeInheritance.GetItemImage(pNMTreeView->itemNew.hItem,nImage,nSelectedImage);
03079                 m_TreeInheritance.SetItemImage(pNMTreeView->itemNew.hItem,nImage-ICON_NUMBER,nSelectedImage-ICON_NUMBER);
03080 
03081         }
03082         
03083         *pResult = 0;
03084 }
03085 
03086 
03087 CString CInheritancePropertyPage::GetDisplayedName(IMgaObject *pIMgaObject)
03088 {
03089 
03090         CComPtr<IMgaObject>ccpMgaObject(pIMgaObject);
03091         CComBSTR pDisplayedName;
03092         
03093         COMTHROW(ccpMgaObject->get_Name(&pDisplayedName));
03094 
03095         CString ret = pDisplayedName;
03096         
03097         return ret;
03098 }
03099 
03100 
03101 void CInheritancePropertyPage::SetupTree()
03102 {
03103 
03104         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
03105         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
03106         
03107         // No open poject - error
03108         if(pApp->m_CurrentProject.GetCurrentProjectState()!=CURRENT_PROJECT_OPEN) return;
03109 
03110         CActiveBrowserPropertySheet* pParent=(CActiveBrowserPropertySheet*)GetParent();
03111         
03112         // Getting selection from aggregate tree
03113         CAggregateMgaObjectProxy MgaObjectProxy;
03114         
03115 
03116         // condition modified> inheritance tree empty for all folders
03117         // previously was empty for rootfolder only
03118         if(!pParent->m_PageAggregate.m_TreeAggregate.GetSelectedItemProxy(MgaObjectProxy)
03119         || MgaObjectProxy.m_TypeInfo == OBJTYPE_FOLDER) // all folders, by zolmol
03120         {
03121                 // No selection in the aggregate tree - or root wa selected
03122                 m_TreeInheritance.CleanUp();
03123                 m_ComboSearchCtrl.ResetContent();
03124                 //m_TreeInheritance.EnableWindow(FALSE);
03125                 //m_ComboSearchCtrl.EnableWindow(FALSE);
03126                 // previously disabled, but let's not do that anymore, 
03127                 // thus we allow seamless CTRL+TABbing through the PropertyPages
03128                 // without the focus wandering away from the tree ctrl
03129                 // by zolmol
03130                 return;
03131         }
03132         m_TreeInheritance.EnableWindow(TRUE);
03133         m_ComboSearchCtrl.EnableWindow(TRUE);
03134 
03135         
03136         // We maintain the previous selection in  
03137         // m_pPrevSelectedItem for efficiency reasons
03138         // If the selection is the same as previous, return
03139         if(m_pPrevSelectedItem==MgaObjectProxy.m_pMgaObject)
03140         {
03141                 //return; // commented by ZolMol, recreate the tree always
03142         }
03143         else
03144         {
03145                 m_pPrevSelectedItem=MgaObjectProxy.m_pMgaObject;
03146         }
03147 
03148         // Casting to FCO
03149         CComQIPtr<IMgaFCO>ccpMgaFCO(MgaObjectProxy.m_pMgaObject);
03150         if(ccpMgaFCO==NULL)
03151         {
03152                 // No selection in the aggreagate tree
03153                 m_TreeInheritance.CleanUp();
03154                 m_ComboSearchCtrl.ResetContent();
03155                 return;
03156         }
03157 
03158         // Cleaning up
03159         m_TreeInheritance.CleanUp();
03160         m_ComboSearchCtrl.ResetContent();
03161         
03162         MSGTRY{
03163                 // Starting transaction
03164                 pMgaContext->BeginTransaction();
03165 
03166                 CComPtr<IMgaFCO> ccpMgaRootFCO(ccpMgaFCO);
03167                 // Getting the root
03168                 reqFindInheritanceRoot(ccpMgaRootFCO);
03169                 
03170                 // Storing it in a member
03171                 m_theCurrentRootFCO = ccpMgaRootFCO;
03172 
03173                 // Building inheritance tree
03174                 reqBuildInheritanceTree(NULL,ccpMgaRootFCO,-1);
03175         
03176                 // Ending transaction
03177                 pMgaContext->CommitTransaction();
03178 
03179         }MSGCATCH(_T("Error retrieving data for inheritance tab"),pMgaContext->AbortTransaction();)     
03180 
03181 
03182         // Select the current item
03183         HTREEITEM hSelectedItem;
03184         m_TreeInheritance.m_MgaMap.LookupTreeItem(ccpMgaFCO,hSelectedItem);
03185         m_TreeInheritance.SelectItem(hSelectedItem);
03186         m_TreeInheritance.EnsureVisible(hSelectedItem);
03187 
03188 }
03189 
03190 void CInheritancePropertyPage::ResetRoot()
03191 {
03192         m_theCurrentRootFCO = 0;
03193 }
03194 
03195 void CInheritancePropertyPage::SetupTree2()
03196 {
03197         ASSERT( m_theCurrentRootFCO != 0);
03198         if( !m_theCurrentRootFCO) return; // if root not set then return
03199 
03200         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
03201         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
03202         
03203         // No open poject - error
03204         if(pApp->m_CurrentProject.GetCurrentProjectState()!=CURRENT_PROJECT_OPEN) return;
03205 
03206         CActiveBrowserPropertySheet* pParent=(CActiveBrowserPropertySheet*)GetParent();
03207         
03208         m_TreeInheritance.EnableWindow(TRUE);
03209         m_ComboSearchCtrl.EnableWindow(TRUE);
03210 
03211         // Cleaning up
03212         m_TreeInheritance.CleanUp();
03213         m_ComboSearchCtrl.ResetContent();
03214         
03215         MSGTRY{
03216                 // Starting transaction
03217                 pMgaContext->BeginTransaction();
03218 
03219                 long status;
03220                 COMTHROW(m_theCurrentRootFCO->get_Status(&status));
03221                 if (status != OBJECT_EXISTS) { // if zombie then return
03222                         return;
03223                 }
03224 
03225                 // Getting the root
03226                 CComPtr<IMgaFCO> ccpMgaRootFCO;
03227                 ccpMgaRootFCO = m_theCurrentRootFCO;
03228 
03229                 // Building inheritance tree
03230                 reqBuildInheritanceTree(NULL,ccpMgaRootFCO,-1);
03231         
03232                 // Ending transaction
03233                 pMgaContext->CommitTransaction();
03234 
03235         }MSGCATCH(_T("Error retrieving data for inheritance tab"),pMgaContext->AbortTransaction();)     
03236 }
03237 
03238 void CInheritancePropertyPage::Refresh()
03239 {
03240         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
03241         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
03242         
03243         MSGTRY{
03244                 // Starting transaction
03245                 pMgaContext->BeginTransaction();
03246 
03247                 m_ComboSearchCtrl.ResetContent();
03248 
03249                 m_TreeInheritance.StoreState();
03250                 m_TreeInheritance.CleanUp();
03251                 if( m_theCurrentRootFCO)
03252                         SetupTree2();
03253                 else
03254                         SetupTree(); 
03255                 m_TreeInheritance.RestoreState();
03256 
03257         }MSGCATCH(_T("Error refreshing tree browser data"),pMgaContext->AbortTransaction();)    
03258         // Ending transaction
03259         pMgaContext->CommitTransaction();
03260 }
03261 
03262 void CInheritancePropertyPage::reqBuildInheritanceTree(HTREEITEM hParent, IMgaFCO* pIMgaFCO, int nDepthLevel)
03263 {
03264 
03265         CComQIPtr<IMgaFCO> ccpMgaFCO(pIMgaFCO);
03266         CComPtr<IMgaFCOs> ccpChildrenFCOs;
03267 
03268         // Insert FCO into the tree
03269         enum objtype_enum eObjectType;
03270         COMTHROW(ccpMgaFCO->get_ObjType(&eObjectType)); // Getting object type
03271 
03272         HTREEITEM hItem=m_TreeInheritance.InsertItem(hParent,GetDisplayedName(ccpMgaFCO),
03273                                                                                                                 ccpMgaFCO,eObjectType);
03274 
03275 
03276         // Getting children
03277         COMTHROW(ccpMgaFCO->get_DerivedObjects(&ccpChildrenFCOs));
03278 
03279 
03280         if(ccpChildrenFCOs)
03281         {
03282                 // Iterate through the children FCOs
03283                 MGACOLL_ITERATE(IMgaFCO, ccpChildrenFCOs)
03284                 {
03285                         // Recursive call for each children
03286                         reqBuildInheritanceTree(hItem,MGACOLL_ITER,nDepthLevel-1);
03287 
03288                 } MGACOLL_ITERATE_END;
03289         }
03290         
03291 }
03292 
03293 void CInheritancePropertyPage::reqFindInheritanceRoot(CComPtr<IMgaFCO>&ccpMgaFCO)
03294 {
03295 
03296         CComPtr<IMgaFCO> ccpParentFCO;
03297 
03298         // Getting parent
03299         COMTHROW(ccpMgaFCO->get_DerivedFrom(&ccpParentFCO));
03300 
03301         if(ccpParentFCO==NULL) // No parent, we got the root object
03302         {               
03303                 return;
03304         }
03305         else
03306         {
03307                 ccpMgaFCO = ccpParentFCO;
03308                 reqFindInheritanceRoot(ccpMgaFCO);
03309         }
03310 
03311 }
03312 
03313 BOOL CInheritancePropertyPage::OnSetActive() 
03314 {
03315         ResetRoot();
03316         SetupTree();
03317         return CPropertyPage::OnSetActive();
03318 }
03319 
03320 void CInheritancePropertyPage::OnSelChangedTreeInheritance(NMHDR* pNMHDR, LRESULT* pResult) 
03321 {
03322         NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
03323         // Setting the focus here, because combo could make the selection
03324         m_TreeInheritance.SetFocus();
03325 
03326         // Displaying the first selection in the combo edit
03327         HTREEITEM hItem=m_TreeInheritance.GetFirstSelectedItem();
03328         if(hItem)
03329         {
03330                 m_ComboSearchCtrl.SetSelection(hItem);
03331 
03332                 LPUNKNOWN pUnknown=NULL;
03333 
03334                 if(m_TreeInheritance.m_MgaMap.LookupObjectUnknown(hItem,pUnknown))
03335                 {
03336                         TRACE(m_TreeInheritance.GetItemText(hItem));
03337 
03338                         // Firing the event
03339                         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
03340                         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
03341 
03342                         // MOD by Peter: do not fire events from transactions
03343                         if (!pMgaContext->IsInTransaction()) {
03344                                 pApp->GetCtrl()->FireClickMgaObject(pUnknown);
03345                         }
03346                 }
03347 
03348         }
03349         
03350         *pResult = 0;
03351 }
03352 
03353 
03354 void CInheritancePropertyPage::OnDblclkTreeInheritance(NMHDR* pNMHDR, LRESULT* pResult) 
03355 {
03356         HTREEITEM hItem=m_TreeInheritance.GetSelectedItem();
03357         
03358         LPUNKNOWN pUnknown=NULL;
03359 
03360         if(m_TreeInheritance.m_MgaMap.LookupObjectUnknown(hItem,pUnknown))
03361         {
03362                 TRACE(m_TreeInheritance.GetItemText(hItem));
03363 
03364                 // Firing the event
03365                 CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
03366                 if( ::GetKeyState( VK_SHIFT) < 0)
03367                         pApp->GetCtrl()->FireShowInParentMgaObject(pUnknown);
03368                 else
03369                         pApp->GetCtrl()->FireDblClickMgaObject(pUnknown);
03370         }
03371 
03372         *pResult = -1; // Nonzero return: disables auto expanding (default action)      
03373 }
03374 
03375 
03376 
03377 
03378 
03379 
03380 
03381 
03382 
03383 
03384 
03392 
03393 
03394 
03395 
03396 
03397 
03398 
03399 
03400 
03401 
03402 CMetaPropertyPage::CMetaPropertyPage() : CPropertyPage(CMetaPropertyPage::IDD),
03403                         m_ComboEditCtrl(&m_ComboSearchCtrl), m_ComboSearchCtrl(&m_TreeMeta)
03404 {
03405         //{{AFX_DATA_INIT(CMetaPropertyPage)
03406         //}}AFX_DATA_INIT
03407 }
03408 
03409 CMetaPropertyPage::~CMetaPropertyPage()
03410 {
03411         m_ImageList.DeleteImageList();
03412         VERIFY( m_ImageList.GetSafeHandle() == NULL);
03413 }
03414 
03415 void CMetaPropertyPage::DoDataExchange(CDataExchange* pDX)
03416 {
03417         CPropertyPage::DoDataExchange(pDX);
03418         //{{AFX_DATA_MAP(CMetaPropertyPage)
03419         DDX_Control(pDX, IDC_COMBO_SERACH_META, m_ComboSearchCtrl);
03420         DDX_Control(pDX, IDC_TREE_META, m_TreeMeta);
03421         //}}AFX_DATA_MAP
03422 }
03423 
03424 
03425 BEGIN_MESSAGE_MAP(CMetaPropertyPage, CPropertyPage)
03426         //{{AFX_MSG_MAP(CMetaPropertyPage)
03427         ON_WM_SIZE()
03428         ON_NOTIFY(NM_DBLCLK, IDC_TREE_META, OnDblclkTreeMeta)
03429         ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_META, OnSelChangedTreeMeta)
03430         ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREE_META, OnItemExpandingTreeMeta)
03431         ON_NOTIFY(TVN_KEYDOWN, IDC_TREE_META, OnKeyDownTreeMeta)
03432         //}}AFX_MSG_MAP
03433 END_MESSAGE_MAP()
03434 
03435 
03436 BOOL CMetaPropertyPage::OnInitDialog() 
03437 {
03438         CPropertyPage::OnInitDialog();
03439         
03440         m_TreeMeta.ModifyStyle(0,TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT
03441                                                                         |TVS_SHOWSELALWAYS );
03442 
03443         m_ImageList.Create(16,16,ILC_MASK|ILC_COLOR24,0,0);
03444         
03445         CBitmap bm;
03446         bm.LoadBitmap(IDB_IMAGELIST_META);
03447         
03448 
03449 
03450         m_ImageList.Add(&bm,RGB(128, 158, 8));
03451 
03452         
03453 
03454         m_TreeMeta.SetImageList(&m_ImageList,TVSIL_NORMAL);
03455 
03456         
03457         m_TreeMeta.EnableWindow(FALSE);
03458         m_ComboSearchCtrl.EnableWindow(FALSE);
03459 
03460 
03461         // Get edit control which happens to be the first child window
03462         // and subclass it
03463         m_ComboEditCtrl.SubclassWindow(m_ComboSearchCtrl.GetWindow(GW_CHILD)->GetSafeHwnd());
03464 
03465 
03466         return TRUE;  // return TRUE unless you set the focus to a control
03467                       // EXCEPTION: OCX Property Pages should return FALSE
03468 }
03469 
03470 BOOL CMetaPropertyPage::OnSetActive() 
03471 {
03472         CActiveBrowserPropertySheet* pParent=(CActiveBrowserPropertySheet*)GetParent();
03473         pParent->m_PageInheritance.ResetRoot();
03474         return CPropertyPage::OnSetActive();
03475 }
03476 
03477 void CMetaPropertyPage::OnSize(UINT nType, int cx, int cy) 
03478 {
03479         CPropertyPage::OnSize(nType, cx, cy);
03480         
03481         if(     ::IsWindow(m_ComboSearchCtrl.GetSafeHwnd()) )
03482         {
03483                 int ySpace = GetSystemMetrics(SM_CYBORDER);
03484                 RECT clientRect;
03485                 m_ComboSearchCtrl.GetClientRect(&clientRect);
03486                 
03487                 m_TreeMeta.MoveWindow(0, clientRect.bottom + 2*ySpace, cx-1, cy-clientRect.bottom - 2*ySpace - 1);
03488                 m_ComboSearchCtrl.MoveWindow(0, ySpace, cx-1, cy-1);
03489         }
03490         
03491 }
03492 
03493 void CMetaPropertyPage::SetupTree()
03494 {
03495         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
03496         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
03497 
03498         // Getting Metaproject
03499         CComPtr<IMgaMetaProject> ccpMetaProject;
03500         COMTHROW(pMgaContext->m_ccpProject->get_RootMeta(&ccpMetaProject));
03501 
03502         // Setting Project name
03503         CComBSTR bszProjectName;
03504         ccpMetaProject->get_DisplayedName(&bszProjectName);
03505         m_strProjectName=bszProjectName;
03506 
03507         // Getting RootFolder
03508         CComPtr<IMgaMetaFolder> ccpRootMetaFolder;
03509         COMTHROW(ccpMetaProject->get_RootFolder(&ccpRootMetaFolder));
03510 
03511         
03512         InsertIntoMetaTree(NULL,ccpRootMetaFolder,_T(""));
03513         
03514         CMetaObjectList ObjListParents;
03515         CMetaObjectList ObjListChildren;
03516 
03517         CComPtr<IMgaMetaBase> ccpMetaBase(ccpRootMetaFolder);
03518         ObjListParents.AddTail(ADAPT_META_OBJECT(ccpMetaBase));
03519 
03520 
03521         // Performing breadth first search
03522         while(!ObjListParents.IsEmpty())
03523         {
03524                 ObjListChildren.RemoveAll();
03525                 
03526                 POSITION pos=ObjListParents.GetHeadPosition();
03527                 
03528                 while(pos)
03529                 {
03530                         CComPtr<IMgaMetaBase> ccpMetaObject=ObjListParents.GetNext(pos);
03531                         InsertChildren(ccpMetaObject,ObjListChildren);
03532                 }
03533 
03534                 ObjListParents.RemoveAll();
03535                 ObjListParents.AddTail(&ObjListChildren);
03536         }
03537         
03538 }
03539 
03540 int CMetaPropertyPage::InsertChildren(CComPtr<IMgaMetaBase>& ccpMetaObject,CMetaObjectList& MetaObjectList)
03541 {
03542         int c=0;
03543         // Determining Object Type
03544         objtype_enum otObjectType;
03545         COMTHROW(ccpMetaObject->get_ObjType(&otObjectType));
03546         
03547         HTREEITEM hParent;
03548         if(!m_TreeMeta.m_MgaMap.LookupTreeItem(ccpMetaObject,hParent))
03549         {
03550                 ASSERT(0);
03551                 return 0;
03552         }
03553 
03554 
03555         switch(otObjectType)
03556         {
03557                 case OBJTYPE_MODEL:
03558                         {
03559                                 CComQIPtr<IMgaMetaModel>ccpMgaMetaModel(ccpMetaObject);                                                                                 
03560         
03561                                 // Getting children roles
03562                                 CComPtr<IMgaMetaRoles> ccpMgaMetaRoles;
03563                                 COMTHROW(ccpMgaMetaModel->get_Roles(&ccpMgaMetaRoles));
03564 
03565                                 // Iterate through the children roles
03566                                 MGACOLL_ITERATE(IMgaMetaRole, ccpMgaMetaRoles) 
03567                                 {
03568                                         CComPtr<IMgaMetaFCO> ccpRoleKind=NULL;
03569                                         COMTHROW(MGACOLL_ITER->get_Kind(&ccpRoleKind));
03570                                         if(ccpRoleKind.p!=NULL)
03571                                         {       
03572                                                 // If it is already in the tree we do not add it
03573                                                 if(InsertIntoMetaTree(hParent,ccpRoleKind,GetDisplayedName(MGACOLL_ITER)))
03574                                                 {
03575                                                         CComPtr<IMgaMetaBase> ccpMetaBase(ccpRoleKind);
03576 
03577                                                         MetaObjectList.AddTail(ADAPT_META_OBJECT(ccpMetaBase));
03578                                                         c++;
03579                                                 }
03580                                         }
03581                                 } MGACOLL_ITERATE_END;
03582 
03583                         }break;
03584                 
03585                 case OBJTYPE_FOLDER: 
03586                         {                               
03587                                 CComQIPtr<IMgaMetaFolder>ccpMgaMetaFolder(ccpMetaObject);       
03588 
03589                                 /*********  Getting Subfolders ***********/
03590                                 CComPtr<IMgaMetaFolders> ccpLegalFolders;
03591                                 COMTHROW(ccpMgaMetaFolder->get_LegalChildFolders(&ccpLegalFolders));
03592                                 
03593                                 // Iterate through the subfolders
03594                                 MGACOLL_ITERATE(IMgaMetaFolder, ccpLegalFolders) 
03595                                 {
03596                                         // If it is already in the tree we do not add it
03597                                         if(InsertIntoMetaTree(hParent,MGACOLL_ITER,GetDisplayedName(MGACOLL_ITER)))
03598                                         {
03599                                                 CComPtr<IMgaMetaBase> ccpMetaBase(MGACOLL_ITER);
03600 
03601                                                 MetaObjectList.AddTail(ADAPT_META_OBJECT(ccpMetaBase));
03602                                                 c++;
03603                                         }
03604                                 } MGACOLL_ITERATE_END;
03605 
03606                                 
03607                                 /********* Getting children FCOs **********/
03608                                 CComPtr<IMgaMetaFCOs> ccpLegalRootObjects;
03609                                 COMTHROW(ccpMgaMetaFolder->get_LegalRootObjects(&ccpLegalRootObjects));
03610                                 // Iterate through the children FCOs
03611                                 MGACOLL_ITERATE(IMgaMetaFCO, ccpLegalRootObjects) 
03612                                 {
03613                                         // If it is already in the tree we do not add it
03614                                         if(InsertIntoMetaTree(hParent,MGACOLL_ITER,GetDisplayedName(MGACOLL_ITER)))
03615                                         {
03616                                                 CComPtr<IMgaMetaBase> ccpMetaBase(MGACOLL_ITER);
03617                                                 MetaObjectList.AddTail(ADAPT_META_OBJECT(ccpMetaBase));
03618                                                 c++;
03619                                         }
03620                                 
03621                                 } MGACOLL_ITERATE_END;
03622 
03623                         }break;
03624         }
03625         return c;
03626 }
03627 
03628 
03629 
03630 
03631 void CMetaPropertyPage::ProcessConnection(CString &strConnectionToolTip, IMgaMetaConnection *pIMetaConnection)
03632 {
03633         CComPtr<IMgaMetaConnection> ccpMetaConnection(pIMetaConnection);
03634         
03635         strConnectionToolTip=_T("Name: ")+GetDisplayedName(ccpMetaConnection)+_T("\r\n");
03636         
03637         // Is the connection simple? Not simple connections are not implemented here!!!
03638         VARIANT_BOOL bIsSimple=VARIANT_FALSE;
03639         COMTHROW(ccpMetaConnection->get_IsSimple(&bIsSimple));
03640         
03641         // Simple connection case
03642         if(bIsSimple!=FALSE)
03643         {
03644                 // Getting connection joins
03645                 CComPtr<IMgaMetaConnJoints> ccpMgaMetaConnJoints;
03646                 CComPtr<IMgaMetaConnJoint> ccpMgaMetaConnJoint;
03647                 COMTHROW(ccpMetaConnection->get_Joints(&ccpMgaMetaConnJoints));         
03648 
03649                 // Iterate through the joints
03650                 int i=0; // Numbering joins
03651                 MGACOLL_ITERATE(IMgaMetaConnJoint, ccpMgaMetaConnJoints) 
03652                 {
03653                         i++;
03654                         // Formatting tooltip
03655                         CString strJoint;
03656                         strJoint.Format(_T("Joint %d: \r\n"),i);
03657                         strConnectionToolTip+=strJoint;
03658 
03659                         // Iterator renamed for sake of readability
03660                         ccpMgaMetaConnJoint = MGACOLL_ITER;
03661         
03662                         // Getting pointer specifications (source and destination)
03663                         CComBSTR bszSourceName(_T("src"));
03664                         CComBSTR bszDestName(_T("dst"));
03665 
03666                         CComPtr<IMgaMetaPointerSpec> ccpMgaMetaPointerSpecSrc;
03667                         CComPtr<IMgaMetaPointerSpec> ccpMgaMetaPointerSpecDest;
03668                         
03669 
03670                         if(E_NOTFOUND!= ccpMgaMetaConnJoint->get_PointerSpecByName(bszSourceName, 
03671                                                                                                                 &ccpMgaMetaPointerSpecSrc) )
03672                         {
03673                                 // Source side *************************************************
03674                                 CString strSrcToolTip(_T("[Source:]\r\n"));
03675 
03676                                 CComPtr<IMgaMetaPointerItems> ccpMgaMetaPointerItemsSrc;
03677                                 ccpMgaMetaPointerSpecSrc->get_Items(&ccpMgaMetaPointerItemsSrc);
03678                                 
03679                                 // Iterating through the pointer items
03680                                 MGACOLL_ITERATE(IMgaMetaPointerItem,ccpMgaMetaPointerItemsSrc) 
03681                                 {
03682                                         // Getting item description
03683                                         CComBSTR bszDesc;
03684                                         COMTHROW(MGACOLL_ITER->get_Desc(&bszDesc));
03685 
03686                                         // Formatting description
03687                                         strSrcToolTip+=_T("\t")+CString(bszDesc)+_T("\r\n");                    
03688 
03689                                 }MGACOLL_ITERATE_END;  // Source Pointer Items
03690                                 strConnectionToolTip+=strSrcToolTip;    
03691                         }
03692                         else
03693                         {
03694                                 CString strSrcToolTip(_T("[Source:] <not found>\r\n"));
03695                                 strConnectionToolTip+=strSrcToolTip;    
03696                         }
03697 
03698                         if(E_NOTFOUND!= ccpMgaMetaConnJoint->get_PointerSpecByName(bszDestName, 
03699                                                                                                                 &ccpMgaMetaPointerSpecDest))
03700                         {
03701                                 // Destination side ********************************************
03702                                 CString strDestToolTip(_T("[Destination:] \r\n"));
03703 
03704                                 CComPtr<IMgaMetaPointerItems> ccpMgaMetaPointerItemsDest;
03705                                 ccpMgaMetaPointerSpecDest->get_Items(&ccpMgaMetaPointerItemsDest);
03706                                 
03707                                 // Iterating through the pointer items
03708                                 MGACOLL_ITERATE(IMgaMetaPointerItem,ccpMgaMetaPointerItemsDest) 
03709                                 {
03710                                         // Getting item description
03711                                         CComBSTR bszDesc;
03712                                         COMTHROW(MGACOLL_ITER->get_Desc(&bszDesc));
03713 
03714                                         // Formatting description
03715                                         strDestToolTip+=_T("\t")+CString(bszDesc)+_T("\r\n");                                   
03716                                 }MGACOLL_ITERATE_END; // Destination pointer items
03717                                 strConnectionToolTip+=strDestToolTip;   
03718                         }
03719                         else
03720                         {
03721                                 CString strDestToolTip(_T("[Destination:] <not found>\r\n"));
03722                                 strConnectionToolTip+=strDestToolTip;   
03723                         }
03724                                                 
03725                 }MGACOLL_ITERATE_END; // Joints
03726 
03727         }
03728         else
03729         {
03730                 // Not simple connection case is not implemented!!!!            
03731                 strConnectionToolTip=_T("Information available only for simple connections.");
03732         }
03733 
03734 }
03735 
03736 
03737 // Called recursively from reqBuildMetaTree function and calls it again.
03738 void CMetaPropertyPage::ProcessAttributes(HTREEITEM hParent, IMgaMetaFCO *pIMgaMetaFCO)
03739 {
03740         if(hParent==NULL) return;
03741 
03742         CComPtr<IMgaMetaFCO>ccpMgaMetaFCO(pIMgaMetaFCO);
03743 
03744         /*********  Getting Attributes ***********/
03745         CComPtr<IMgaMetaAttributes> ccpAttributes;
03746         COMTHROW(ccpMgaMetaFCO->get_Attributes(&ccpAttributes));
03747         
03748         // Iterate through the attributes
03749         MGACOLL_ITERATE(IMgaMetaAttribute, ccpAttributes) 
03750         {
03751                 CComPtr<IMgaMetaAttribute>ccpMgaMetaAttribute(MGACOLL_ITER);
03752                 
03753                 // Inserting item into the meta tree
03754                 HTREEITEM hItem=m_TreeMeta.InsertItem(hParent,GetDisplayedName(ccpMgaMetaAttribute),ccpMgaMetaAttribute,OBJTYPE_ATTRIBUTE);
03755                 
03756         } MGACOLL_ITERATE_END;  
03757 
03758 
03759 }
03760 
03761 
03762 void CMetaPropertyPage::OpenProject()
03763 {
03764         m_TreeMeta.EnableWindow(TRUE);
03765         m_ComboSearchCtrl.EnableWindow(TRUE);
03766 
03767         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
03768         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
03769 
03770         MSGTRY{
03771                 SetupTree();
03772         }MSGCATCH(_T("Error opening meta tab"),pMgaContext->AbortTransaction();)        
03773 
03774 }
03775 
03776 
03777 void CMetaPropertyPage::CloseProject()
03778 {
03779         m_TreeMeta.CleanUp();   
03780         m_TreeMeta.EnableWindow(FALSE);
03781 
03782         m_ComboSearchCtrl.ResetContent();
03783         m_ComboSearchCtrl.EnableWindow(FALSE);
03784 
03785 }
03786 
03787 
03788 
03789 void CMetaPropertyPage::OnDblclkTreeMeta(NMHDR* pNMHDR, LRESULT* pResult) 
03790 {
03791         DWORD dwMsgPos = ::GetMessagePos();
03792 
03793         CPoint point = CPoint(GET_X_LPARAM(dwMsgPos), GET_Y_LPARAM(dwMsgPos) );
03794         UINT nHitFlags;
03795         
03796         m_TreeMeta.ScreenToClient(&point);
03797         m_TreeMeta.HitTest( point, &nHitFlags );
03798 
03799         
03800         if(nHitFlags&TVHT_ONITEMBUTTON)
03801         {
03802                 return;
03803         }
03804 
03805         HTREEITEM hItem=m_TreeMeta.GetSelectedItem();
03806         
03807         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
03808         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
03809 
03810 
03811         if(hItem)
03812         {
03813                 HTREEITEM hReferencedItem;
03814                 if( hReferencedItem=(HTREEITEM)m_TreeMeta.GetItemData(hItem) )
03815                 {
03816                         m_TreeMeta.SelectItem(hReferencedItem);
03817                         m_TreeMeta.EnsureVisible(hReferencedItem);
03818 
03819                 }
03820                 
03821                 MSGTRY{
03822                         if(GetKeyState(VK_MENU)&0x8000) // Alt + dblclick - connection properties
03823                         {
03824 
03825                                 HTREEITEM hItem=m_TreeMeta.GetSelectedItem();
03826                                 CMgaObjectProxy ObjectProxy;
03827                                 if(!m_TreeMeta.m_MgaMap.LookupObjectProxy(hItem,ObjectProxy)) return; // Not in the map
03828                                 if(ObjectProxy.m_TypeInfo==OBJTYPE_CONNECTION)
03829                                 {
03830                                         CComQIPtr<IMgaMetaConnection> ccpMetaConnection(ObjectProxy.m_pMgaObject);
03831                                         if(ccpMetaConnection)
03832                                         {
03833                                                 CString strConnDesc;
03834                                                 ProcessConnection(strConnDesc,ccpMetaConnection);
03835 
03836                                                 CMetaConnectionDlg dlg(this);
03837                                                 dlg.m_strConnectionProperties=strConnDesc;
03838                                                 dlg.DoModal();
03839                                         }
03840                                 }
03841                         }
03842                 }MSGCATCH(_T("Error retrieving connection properties"),pMgaContext->AbortTransaction();)        
03843 
03844         }
03845         *pResult = -1;
03846 }
03847 
03848 
03849 
03850 
03851 void CMetaPropertyPage::OnSelChangedTreeMeta(NMHDR* pNMHDR, LRESULT* pResult) 
03852 {
03853         NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
03854 
03855         // Setting the focus here, because combo could make the selection
03856         m_TreeMeta.SetFocus();
03857 
03858         // Displaying the first selection in the combo edit
03859         HTREEITEM hItem=m_TreeMeta.GetFirstSelectedItem();
03860         if(hItem)
03861         {
03862                 m_ComboSearchCtrl.SetSelection(hItem);
03863         }
03864         
03865         *pResult = 0;
03866 }
03867 
03868 
03869 
03870 
03871 
03872 
03873 
03874 void CMetaPropertyPage::OnItemExpandingTreeMeta(NMHDR* pNMHDR, LRESULT* pResult) 
03875 {
03876         NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
03877 
03878         
03879         if(pNMTreeView->action==TVE_EXPAND)
03880         {
03881                 if(m_TreeMeta.GetItemState(pNMTreeView->itemNew.hItem,TVIS_EXPANDED)
03882                                                                                                                                         &TVIS_EXPANDED)
03883                 {
03884                         return;
03885                 }
03886 
03887         
03888                 int nImage,nSelectedImage;
03889                 m_TreeMeta.GetItemImage(pNMTreeView->itemNew.hItem,nImage,nSelectedImage);
03890                 m_TreeMeta.SetItemImage(pNMTreeView->itemNew.hItem,nImage+ICON_NUMBER,nSelectedImage+ICON_NUMBER);
03891         }
03892         else
03893         {
03894                 if(!(m_TreeMeta.GetItemState(pNMTreeView->itemNew.hItem,TVIS_EXPANDED)
03895                                                                                                                                         &TVIS_EXPANDED))
03896                 {
03897                         return;
03898                 }
03899 
03900                 int nImage,nSelectedImage;
03901                 m_TreeMeta.GetItemImage(pNMTreeView->itemNew.hItem,nImage,nSelectedImage);
03902                 m_TreeMeta.SetItemImage(pNMTreeView->itemNew.hItem,nImage-ICON_NUMBER,nSelectedImage-ICON_NUMBER);
03903 
03904         }
03905 
03906         *pResult = 0;
03907 }
03908 
03909 
03910 void CMetaPropertyPage::OnKeyDownTreeMeta(NMHDR* pNMHDR, LRESULT* pResult)
03911 {
03912         TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*)pNMHDR;
03913         switch(pTVKeyDown->wVKey)
03914         {
03915         case VK_TAB:
03916                 {
03917                         if( ::GetKeyState( VK_CONTROL) < 0) {
03918                                 m_parent->nextTab( ::GetKeyState( VK_SHIFT) >= 0);
03919                         }
03920                         else {
03921                                 m_ComboEditCtrl.SetFocus();
03922                         }
03923                 }break;
03924         }
03925 
03926         
03927         *pResult = 0;
03928 }
03929 
03930 
03931 
03932 HTREEITEM CMetaPropertyPage::InsertIntoMetaTree(HTREEITEM hParent,IMgaMetaBase* IMetaObject, CString strRoleName)
03933 {
03934         
03935         CComPtr<IMgaMetaBase> ccpMetaObject(IMetaObject);
03936 
03937         // Determining Object Type
03938         objtype_enum otObjectType;
03939         COMTHROW(ccpMetaObject->get_ObjType(&otObjectType));
03940 
03941         // FILTERING: these type won't be inserted
03942         if(otObjectType==OBJTYPE_ASPECT || otObjectType==OBJTYPE_PART)
03943         {
03944                 return 0;
03945         }
03946 
03947 
03948 
03949         // Inserting item into the meta tree
03950         CString strName;
03951         if(strRoleName!=_T(""))
03952         {
03953                 strName=strRoleName+_T(" (")+GetDisplayedName(ccpMetaObject)+_T(")");
03954         }
03955         else
03956         {
03957                 strName=GetDisplayedName(ccpMetaObject);
03958         }
03959 
03960         HTREEITEM hItem= m_TreeMeta.InsertItem(hParent,strName,ccpMetaObject,otObjectType);
03961         
03962         // Inserting attributes 
03963         CComQIPtr<IMgaMetaFCO>ccpMetaFCO(ccpMetaObject);
03964         if(ccpMetaFCO)
03965         {
03966                 ProcessAttributes(hItem,ccpMetaFCO);
03967         }
03968 
03969         return hItem;
03970 }
03971 
03972 CString CMetaPropertyPage::GetDisplayedName(IMgaMetaBase *pIMgaMetaBase)
03973 {
03974 
03975         CComPtr<IMgaMetaBase>ccpMgaMetaBase(pIMgaMetaBase);
03976         CComBSTR pDisplayedName;
03977         COMTHROW(ccpMgaMetaBase->get_DisplayedName(&pDisplayedName));
03978         
03979         CString ret = pDisplayedName;
03980         
03981         return ret;
03982 }
03983 
03984 void CAggregatePropertyPage::OnKillFocus(CWnd* pNewWnd) 
03985 {
03986         CPropertyPage::OnKillFocus(pNewWnd);
03987         HTREEITEM hItem=m_TreeAggregate.GetFirstSelectedItem();
03988         
03989         // TODO: Add your message handler code here
03990         
03991 }
03992 
03993 bool CAggregatePropertyPage::askUserAndDetach( CComPtr<IMgaObject> object)
03994 {
03995         CComQIPtr<IMgaFCO> fco( object);
03996         if( !fco) return false;
03997         // check whether dependends of fco exist
03998         CComPtr<IMgaFCOs> der_objs;
03999         COMTHROW(fco->get_DerivedObjects( &der_objs));
04000         long cnt = 0;
04001         if( der_objs) COMTHROW( der_objs->get_Count( &cnt));
04002         if( cnt > 0) // if dependents exist should they be deleted?
04003         {
04004                 bool question_asked = false;
04005                 bool detach_answered = false;
04006                 MGACOLL_ITERATE(IMgaFCO, der_objs) {
04007                         CComPtr<IMgaFCO> one_derived(MGACOLL_ITER);
04008 
04009                         VARIANT_BOOL prim_deriv;
04010                         COMTHROW( one_derived->get_IsPrimaryDerived( &prim_deriv));
04011                         if( prim_deriv == VARIANT_TRUE)
04012                         {
04013                                 if( !question_asked) // pop up dialog only for the first time / per basetype
04014                                 {
04015                                         CComBSTR nm;
04016                                         COMTHROW( fco->get_Name( &nm));
04017                                         CString msg = _T("There are objects primary derived from: \"");
04018                                         msg += nm;
04019                                         msg += _T("\". Would you like to delete them as well?\n");
04020                                         msg += _T("If you answer 'No' the derived objects will be detached, thus preserved.");
04021 
04022                                         // this answer will be applied to all deriveds of this fco
04023                                         int resp = AfxMessageBox( msg, MB_YESNOCANCEL);
04024                                         if( resp == IDCANCEL) COMTHROW(E_MGA_MUST_ABORT);
04025                                         else if( resp == IDNO) detach_answered = true;
04026                                         
04027                                         question_asked = true;
04028                                 }
04029 
04030                                 // if detach and preserve selected by the user:
04031                                 if( detach_answered)
04032                                         COMTHROW( one_derived->DetachFromArcheType());
04033                         }
04034                 }MGACOLL_ITERATE_END;
04035 
04036                 return detach_answered;
04037         }
04038         return false;
04039 }
04040 
04041 void CAggregatePropertyPage::accessRights( bool pbProtectIt)
04042 {
04043         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
04044         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
04045 
04046         HTREEITEM hItem = m_TreeAggregate.GetFirstSelectedItem();
04047         if (hItem != NULL) 
04048         { 
04049                 
04050                 LPUNKNOWN pUnknown;
04051                 
04052                 if(!m_TreeAggregate.m_MgaMap.LookupObjectUnknown(hItem,pUnknown))return;
04053                                         
04054                 CComQIPtr<IMgaObject> ccpObj(pUnknown);
04055                 if( !ccpObj)
04056                         return;
04057 
04058                 MSGTRY {
04059                         
04060                         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
04061                         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
04062 
04063                         pMgaContext->BeginTransaction(false);
04064 
04065                         COMTHROW(ccpObj->PutReadOnlyAccessWithPropagate( pbProtectIt ? VARIANT_TRUE:VARIANT_FALSE));
04066                         pMgaContext->CommitTransaction();
04067 
04068                 } MSGCATCH(_T("Error while applying new access rights"),pMgaContext->AbortTransaction();)       
04069                 Refresh();
04070         }
04071 }
04072 
04073 void CAggregatePropertyPage::LibraryAmbiguityChk()
04074 {
04075         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
04076         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
04077 
04078         HTREEITEM hItem = m_TreeAggregate.GetFirstSelectedItem();
04079         if (hItem != NULL) 
04080         { 
04081                 
04082                 LPUNKNOWN pUnknown;
04083                 
04084                 if(!m_TreeAggregate.m_MgaMap.LookupObjectUnknown(hItem,pUnknown))return;
04085                                         
04086                 CComQIPtr<IMgaFolder> ccpFolder(pUnknown);
04087                 if(!ccpFolder)return;
04088 
04089                 MSGTRY {
04090                         
04091                         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
04092                         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
04093 
04094                         CComBSTR msg;
04095                         pMgaContext->BeginTransaction(false);
04096 
04097                         CComPtr<IMgaFolders> fols;
04098                         std::map< CComBSTR, std::vector< CComBSTR > > guidmap;
04099                         
04100                         // the rootfolder's guid might have a guid conflict also
04101                         CComBSTR gd_of_project;
04102                         COMTHROW( ccpFolder->GetGuidDisp( &gd_of_project));
04103                         // save its guid
04104                         guidmap[ gd_of_project].push_back( CComBSTR( _T("Main Project")));
04105 
04106                         // check toplevel folders
04107                         COMTHROW( ccpFolder->get_ChildFolders( &fols));
04108                         long len = 0;
04109                         if( fols) COMTHROW( fols->get_Count( &len));
04110                         for( long i = 1; i <= len; ++i)
04111                         {
04112                                 CComPtr<IMgaFolder> fol;
04113                                 COMTHROW( fols->get_Item( i, &fol));
04114 
04115                                 if( !fol) { ASSERT(0); continue; }
04116 
04117                                 CComBSTR bszLibName;
04118                                 COMTHROW( fol->get_LibraryName(&bszLibName));
04119 
04120                                 if( bszLibName) // if library
04121                                 {
04122                                         CComBSTR gd;
04123                                         COMTHROW( fol->GetGuidDisp( &gd));
04124 
04125                                         // save its guid
04126                                         guidmap[ gd].push_back( bszLibName);
04127                                 }
04128                         }
04129                 
04130                         for( std::map< CComBSTR, std::vector< CComBSTR > >::iterator it = guidmap.begin(), en = guidmap.end(); it != en; ++it)
04131                         {
04132                                 if( it->second.size() > 1) // duplicates found
04133                                 {
04134                                         if (msg.Length() > 0)
04135                                                 COMTHROW(msg.Append( _T("\n\n")));
04136                                         COMTHROW(msg.AppendBSTR( it->first));
04137                                         COMTHROW(msg.Append( _T("\nShared by multiple toplevel libraries:")));
04138                                         for( unsigned int i = 0; i < it->second.size(); ++i)
04139                                         {
04140                                                 COMTHROW(msg.Append( _T("\n\t")));
04141                                                 COMTHROW(msg.AppendBSTR( it->second[i]));
04142                                         }
04143                                 }
04144                         }
04145                         if( msg.Length() != 0)
04146                         {
04147                                 CString msgs;
04148                                 CopyTo( msg, msgs);
04149                                 AfxMessageBox( msgs, MB_OK | MB_ICONSTOP);
04150                         }
04151                         else
04152                                 AfxMessageBox( _T("No duplicate GUID found among the toplevel libraries."), MB_ICONINFORMATION);
04153 
04154                         //pMgaContext->CommitTransaction();
04155                         pMgaContext->AbortTransaction();
04156 
04157                 } MSGCATCH(_T("Error while analyzing library guid ambiguities"),pMgaContext->AbortTransaction();)       
04158                 //Refresh();
04159         }
04160 }
04161 
04162 void CAggregatePropertyPage::ProjectSourceControlUpdate( CComBSTR id)
04163 {
04164         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
04165         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
04166 
04167 
04168         MSGTRY 
04169         {
04170                 CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
04171                 CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
04172 
04173                 // no transaction needed
04174                 COMTHROW( pMgaContext->m_ccpProject->UpdateSourceControlInfo( id));
04175         }
04176         MSGCATCH(_T("Error while updating source control info!"),;)
04177 
04178         Refresh();
04179 }
04180 
04181 void CAggregatePropertyPage::SourceControlObjectOwner( CComBSTR p_id)
04182 {
04183         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
04184         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
04185 
04186         MSGTRY 
04187         {
04188                 CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
04189                 CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
04190 
04191                 // no transaction needed
04192                 COMTHROW( pMgaContext->m_ccpProject->SourceControlObjectOwner( p_id));
04193         }
04194         MSGCATCH(_T("Error while fetching source control info!"),;)
04195 
04196         Refresh();
04197 }
04198 
04199 void CAggregatePropertyPage::SourceControlActiveUsers()
04200 {
04201         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
04202         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
04203 
04204         MSGTRY 
04205         {
04206                 CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
04207                 CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
04208 
04209                 // no transaction needed
04210                 COMTHROW( pMgaContext->m_ccpProject->SourceControlActiveUsers());
04211         }
04212         MSGCATCH(_T("Error while fetching source control info!"),;)
04213 
04214         Refresh();
04215 }
04216 
04217 //static
04218 void CAggregatePropertyPage::composeInfo( CString p_msgText, CComPtr<IMgaFolders>& coll, CString& p_msg)
04219 {
04220         CString&       msg = p_msg;
04221         CString        lst;
04222 
04223         long len = 0;
04224         if( coll) COMTHROW( coll->get_Count( &len));
04225         for( long i = 1; i <= len; ++i)
04226         {
04227                 CComPtr<IMgaFolder> ele;
04228                 COMTHROW( coll->get_Item( i, &ele));
04229 
04230                 ASSERT( ele);
04231                 if( ele)
04232                 {
04233                         long stat = OBJECT_ZOMBIE;
04234                         COMTHROW( ele->get_Status( &stat));
04235                         if( stat == OBJECT_EXISTS)
04236                         {
04237                                 CComBSTR connstr;
04238                                 CComBSTR guiddsp;
04239                                 COMTHROW( ele->get_LibraryName( &connstr));
04240                                 COMTHROW( ele->GetGuidDisp( &guiddsp));
04241                                 if( connstr && connstr.Length() > 0) 
04242                                 {
04243                                         CString cs, gs;
04244                                         CopyTo( connstr, cs);
04245                                         CopyTo( guiddsp, gs);
04246                                         lst += cs + _T(" ") + gs + _T("\n");
04247                                 }
04248                         }
04249                 }
04250         }
04251 
04252         msg = p_msgText + (lst.IsEmpty()?_T("None"):lst);
04253 }
04254 
04255 void CAggregatePropertyPage::HighlightItem(IMgaObject* pObj, int highlight)
04256 {
04257         CGMEActiveBrowserApp* pApp=(CGMEActiveBrowserApp*)AfxGetApp();
04258         CMgaContext* pMgaContext=&pApp->m_CurrentProject.m_MgaContext;
04259         CComPtr<IMgaObject> terrObj;
04260         pMgaContext->m_ccpTerritory->__OpenObj(pObj, &terrObj);
04261         CComPtr<IUnknown> pUnk;
04262         terrObj.QueryInterface(&pUnk.p);
04263 
04264         CComBSTR id = static_cast<BSTR>(pObj->ID);
04265 
04266         auto& highlightedObjects = m_TreeAggregate.m_highlightedObjects;
04267         if (highlight)
04268         {
04269                 highlightedObjects[id] = highlight;
04270         }
04271         else
04272         {
04273                 auto it = highlightedObjects.find(id);
04274                 if (it != highlightedObjects.end())
04275                 {
04276                         highlightedObjects.erase(it);
04277                 }
04278         }
04279         HTREEITEM hItem;
04280         IUnknown* punk;
04281         if (m_TreeAggregate.m_MgaMap.SearchTreeItem(id, hItem, punk))
04282         {
04283                 m_TreeAggregate.SetItemProperties(hItem);
04284         }
04285 }