GME  13
GMEViewDlg.cpp
Go to the documentation of this file.
00001 // GMEViewDlg.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "GMEViewDlg.h"
00006 #include "GMEViewCtrl.h"
00007 #include "GMEViewStd.h"
00008 #include "..\GME\GMEOLEData.h"
00009 #include "Gme_i.c"
00010 #include "memdc.h"
00011 
00012 #include <stdlib.h>
00013 #include <time.h>
00014 
00015 
00016 #ifdef _DEBUG
00017 #define new DEBUG_NEW
00018 #undef THIS_FILE
00019 static char THIS_FILE[] = __FILE__;
00020 #endif
00021 
00022 
00023 typedef enum { GME_NAME_FONT = 0, GME_PORTNAME_FONT, GME_CONNLABEL_FONT, GME_FONT_KIND_NUM } GMEFontKind;
00024 static int  fontSizes[GME_FONT_KIND_NUM]        = { 18, 15, 12 };
00025 #define MODEL_BOX_BORDER                                                5
00026 
00027 #define WINDOWTEST
00028 #define TESTWINDOWCOUNT         2000
00029 #define TESTWINDOWWIDTH         100
00030 #define TESTWINDOWHEIGHT        25
00031 #define TESTMODELWIDTH          4000
00032 #define TESTMODELHEIGHT         8000
00033 #define TESTWINDOWCOLUMN        40
00034 #define TESTWINDOWROW           TESTWINDOWCOUNT / TESTWINDOWCOLUMN
00035 #define TESTWINDOWSPACING       20
00036 
00037 
00039 // CGMEViewDlg dialog
00040 
00041 bool            CGMEViewDlg::offScreenCreated = false;
00042 CDC*            CGMEViewDlg::offScreen;
00043 CBitmap*        CGMEViewDlg::ofsbmp;
00044 int                     CGMEViewDlg::instanceCount = 0;
00045 CString         CGMEViewDlg::strTestWndClass;
00046 
00047 IMPLEMENT_DYNCREATE(CGMEViewDlg, CScrollZoomView)
00048 
00049 CGMEViewDlg::CGMEViewDlg():
00050                 m_DropTarget(this),
00051         mgaProject(NULL),
00052         mgaMetaModel(NULL),
00053         currentAspect(1),
00054         defZoomLev("100"),
00055         m_zoomVal(ZOOM_NO),
00056         inWindowDragging(false)
00057 {
00058         instanceCount++;
00059 
00060         //{{AFX_DATA_INIT(CGMEViewDlg)
00061                 // NOTE: the ClassWizard will add member initialization here
00062         //}}AFX_DATA_INIT
00063 
00064         canvasBgndColor = RGB(0xFF, 0xFF, 0xFF);
00065         txtMetricFont.CreateFont(fontSizes[GME_NAME_FONT], 0, 0, 0, true, 0, 0, 0, ANSI_CHARSET,
00066                                                          OUT_DEVICE_PRECIS, CLIP_DEFAULT_PRECIS,
00067                                                          PROOF_QUALITY, FF_SWISS, "Arial");
00068         modelExtent.SetRectEmpty();
00069         modelExtentCalculated = false;
00070         SetScroll();
00071         srand((unsigned) time(NULL));
00072 }
00073 
00074 CGMEViewDlg::~CGMEViewDlg()
00075 {
00076         DestroyTestWindows();
00077 
00078         // a good idea to release ptrs
00079 /*      baseType.Release();
00080         parent.Release();
00081         currentModel.Release();*/
00082 
00083         if (--instanceCount <= 0) {
00084                 delete offScreen;
00085                 delete ofsbmp;
00086                 offScreenCreated = false;
00087 /*              if (CMainFrame::theInstance != NULL) {
00088                         CMainFrame::theInstance->SetPartBrowserMetaModel(NULL);
00089                         CMainFrame::theInstance->SetPartBrowserBg(::GetSysColor(COLOR_APPWORKSPACE));
00090                 }*/
00091         }
00092 
00093         txtMetricFont.DeleteObject();
00094 }
00095 
00096 void CGMEViewDlg::DoDataExchange(CDataExchange* pDX)
00097 {
00098         CScrollZoomView::DoDataExchange(pDX);
00099         //{{AFX_DATA_MAP(CGMEViewDlg)
00100 //      DDX_Control(pDX, IDC_ASPECT_TAB, tab);
00101         //}}AFX_DATA_MAP
00102 }
00103 
00104 BOOL CGMEViewDlg::PreCreateWindow(CREATESTRUCT& cs) 
00105 {
00106         // TODO: Modify the Window class or styles here by modifying
00107         //  the CREATESTRUCT cs
00108 
00109         return CScrollZoomView::PreCreateWindow(cs);
00110 }
00111 
00112 void CGMEViewDlg::SetCurrentProject(CComPtr<IMgaProject> project)
00113 {
00114         if (mgaProject != NULL)
00115                 mgaProject.Release();
00116         mgaProject = project;
00117         modelExtentCalculated = false;
00118 }
00119 
00120 void CGMEViewDlg::SetMetaModel(CComPtr<IMgaMetaModel> meta)
00121 {
00122         if (mgaMetaModel != NULL)
00123                 mgaMetaModel.Release();
00124         mgaMetaModel = meta;
00125         modelExtentCalculated = false;
00126 
00127 //      Init propBar fields?
00128 }
00129 
00130 void CGMEViewDlg::SetModel(CComPtr<IMgaModel> model)
00131 {
00132         if (mgaModel != NULL)
00133                 mgaModel.Release();
00134         mgaModel = model;
00135 #if defined (WINDOWTEST)
00136         if (strTestWndClass.IsEmpty()) {
00137                 try {
00138                         strTestWndClass = AfxRegisterWndClass(
00139                                 CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW,
00140                                 ::LoadCursor(NULL, IDC_ARROW),
00141                                 (HBRUSH) ::GetStockObject(WHITE_BRUSH),
00142                                 ::LoadIcon(NULL, IDI_APPLICATION));
00143                 }
00144                 catch (CResourceException* pEx) {
00145                         TRACE0("Couldn't register class! (Already registered?)");
00146                         pEx->Delete();
00147                 }
00148         }
00149 
00150         DestroyTestWindows();
00151         if (mgaModel != NULL)
00152                 CreateTestWindows();
00153 
00154 //      modelExtent.SetRect(0, 0, TESTMODELWIDTH, TESTMODELHEIGHT);
00155         modelExtent.SetRect(0, 0, TESTWINDOWCOLUMN * (TESTWINDOWWIDTH + TESTWINDOWSPACING) + TESTWINDOWSPACING,
00156                                                 TESTWINDOWROW * (TESTWINDOWHEIGHT + TESTWINDOWSPACING) + TESTWINDOWSPACING);
00157         modelExtentCalculated = true;
00158         SetScroll();
00159 #else
00160         modelExtentCalculated = false;
00161 #endif
00162 }
00163 
00164 void CGMEViewDlg::ChangeAspect(int aspect)
00165 {
00166         currentAspect = aspect;
00167         Invalidate();
00168 }
00169 
00170 void CGMEViewDlg::Invalidate(void)
00171 {
00172         // TODO
00173 }
00174 
00175 void CGMEViewDlg::SetScroll(void)
00176 {
00177         CSize s((int) (modelExtent.right * EXTENT_ERROR_CORR), (int) (modelExtent.bottom * EXTENT_ERROR_CORR));
00178 
00179         if (m_zoomVal == ZOOM_NO)
00180                 SetScrollSizes(MM_TEXT, s, m_zoomVal);
00181         else
00182                 SetScrollSizes(MM_ISOTROPIC, s, m_zoomVal);
00183 }
00184 
00185 void CGMEViewDlg::CreateOffScreen(CDC* dc)
00186 {
00187         if (offScreenCreated)
00188                 return;
00189         offScreenCreated = true;
00190         offScreen = new CDC;
00191         offScreen->CreateCompatibleDC(dc);
00192         int offScreenWidth = dc->GetDeviceCaps(HORZRES);
00193         int offScreenHeight = dc->GetDeviceCaps(VERTRES);
00194         ofsbmp = new CBitmap;
00195         ofsbmp->CreateCompatibleBitmap(dc,offScreenWidth,offScreenHeight);
00196         // HACK: what about palettes?
00197         offScreen->SelectObject(ofsbmp);
00198 }
00199 
00200 int CGMEViewDlg::RangedRand(int range_min, int range_max)
00201 {
00202         int u = (int) ((double) rand() / (RAND_MAX + 1) * (range_max - range_min) + range_min);
00203         return u;
00204 }
00205 
00206 void CGMEViewDlg::CreateTestWindows(void)
00207 {
00208         for (long i = 0; i < TESTWINDOWCOUNT; i++) {
00209                 char title[256];
00210                 sprintf(title, "%ld. wnd", i);
00211 
00212                 int left = RangedRand(0, TESTMODELWIDTH - TESTWINDOWWIDTH);
00213                 int top = RangedRand(0, TESTMODELHEIGHT - TESTWINDOWHEIGHT);
00214 
00215 //              int left = (i % TESTWINDOWCOLUMN) * (TESTWINDOWWIDTH + TESTWINDOWSPACING) + TESTWINDOWSPACING;
00216 //              int top = (i / TESTWINDOWCOLUMN) * (TESTWINDOWHEIGHT + TESTWINDOWSPACING) + TESTWINDOWSPACING;
00217 //              TRACE3("%ld. wnd: %ld, %ld\n", i, left, top);
00218                 CRect rectClient;
00219                 rectClient.SetRect(left, top, left + TESTWINDOWWIDTH, top + TESTWINDOWHEIGHT);
00220 
00221                 CTestWindow* testWindow = new CTestWindow(title, rectClient, this);
00222 //              testWindow->CreateWindowSpecial(strTestWndClass);
00223                 testWindows.push_back(testWindow);
00224         }
00225 }
00226 
00227 void CGMEViewDlg::DestroyTestWindows(void)
00228 {
00229         for (std::vector<CTestWindow*>::iterator ii = testWindows.begin(); ii != testWindows.end(); ++ii) {
00230                 (*ii)->DestroyWindowSpecial();
00231                 delete (*ii);
00232         }
00233         testWindows.clear();
00234 }
00235 
00236 std::vector<CTestWindow*> CGMEViewDlg::GetWindowsInRect(const CRect& rect)
00237 {
00238         std::vector<CTestWindow*> wndsInRect;
00239         for (std::vector<CTestWindow*>::iterator ii = testWindows.begin(); ii != testWindows.end(); ++ii) {
00240                 if ((*ii)->IsIntersectRect(rect))
00241                         wndsInRect.push_back(*ii);
00242         }
00243         return wndsInRect;
00244 }
00245 
00246 
00247 BEGIN_MESSAGE_MAP(CGMEViewDlg, CScrollZoomView)
00248         //{{AFX_MSG_MAP(CGMEViewDlg)
00249         ON_WM_CREATE()
00250         ON_WM_CLOSE()
00251         ON_WM_SIZE()
00252         ON_WM_MOVE()
00253         ON_WM_WINDOWPOSCHANGED()
00254         ON_WM_PAINT()
00255         ON_WM_ERASEBKGND()
00256         ON_WM_LBUTTONDOWN()
00257         ON_WM_LBUTTONUP()
00258         ON_WM_MOUSEMOVE()
00259         ON_NOTIFY(TCN_SELCHANGE, IDC_ASPECT, OnSelchangeAspectTab)
00260         //}}AFX_MSG_MAP
00261 END_MESSAGE_MAP()
00262 
00264 // CGMEViewDlg message handlers
00265 
00266 int CGMEViewDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
00267 {
00268         // TODO: should contain GMEView::OnInitialUpdate() ???
00269         if (CScrollZoomView::OnCreate(lpCreateStruct) == -1)
00270                 return -1;
00271 
00272         m_DropTarget.Register(this);
00273 
00274         return 0;
00275 }
00276 
00277 void CGMEViewDlg::OnClose()
00278 {
00279         CScrollZoomView::OnClose();
00280 
00281         // CMDIChildWnd::OnClose: when the last ChildWnd is closed
00282         // the document is considered closed and the title changes to Paradigm
00283         // that's why we call this:
00284 //      theApp.UpdateMainTitle();
00285 }
00286 
00287 void CGMEViewDlg::OnSize(UINT nType, int cx, int cy)
00288 {
00289         TRACE2("Size Message: %ld, %ld\n", cx, cy);
00290 
00291         CScrollZoomView::OnSize(nType, cx, cy);
00292 }
00293 
00294 void CGMEViewDlg::OnMove(int x, int y) 
00295 {
00296         TRACE2("Move Message: %ld, %ld\n", x, y);
00297 
00298         CScrollZoomView::OnMove(x, y);
00299 }
00300 
00301 void CGMEViewDlg::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
00302 {
00303         CScrollZoomView::OnWindowPosChanged(lpwndpos);
00304 }
00305 
00306 HRESULT GetPosition(CComPtr<IMgaFCO> fco, CString regPath, long* x, long* y)
00307 {
00308         COMTRY {
00309                 CComBSTR bb;
00310                 COMTHROW(fco->get_RegistryValue(CComBSTR(regPath), &bb));
00311                 long ld, *lx = x?x:&ld, *ly = y?y:&ld;
00312                 if (!bb) {
00313                         *lx = -1;
00314                         *ly = -1;
00315                 } else {
00316                         if (swscanf(bb, OLESTR("%ld,%ld"), lx, ly) != 2)
00317                                 COMTHROW(E_MGA_BAD_POSITIONVALUE);
00318                 }
00319         } COMCATCH(;)
00320 }
00321 
00322 void CGMEViewDlg::OnDraw(CDC* dc)
00323 {
00324         CRect rcBounds;
00325         dc->GetBoundsRect(rcBounds, 0);
00326         TRACE("CGMEViewDlg::OnDraw Rect Bounds %ld %ld %ld %ld\n", rcBounds.left, rcBounds.top, rcBounds.right, rcBounds.bottom);
00327         CMemDC pDC(dc);
00328         {
00329                 AFX_MANAGE_STATE(AfxGetStaticModuleState());
00330 
00331                 CBrush brush(canvasBgndColor);
00332                 pDC->FillRect(rcBounds, &brush);
00333 
00334 #if defined (WINDOWTEST)
00335                 CRect clientRect;
00336                 GetClientRect(&clientRect);
00337 //              TRACE("CGMEViewDlg::OnDraw ClientRect Bounds %ld %ld %ld %ld\n", clientRect.left, clientRect.top, clientRect.right, clientRect.bottom);
00338                 CPoint scrollPos = GetDeviceScrollPosition();
00339                 clientRect.OffsetRect(scrollPos);
00340 //              TRACE("CGMEViewDlg::OnDraw ClientArea Bounds %ld %ld %ld %ld\n", clientRect.left, clientRect.top, clientRect.right, clientRect.bottom);
00341 
00342                 std::vector<CTestWindow*> newArea = GetWindowsInRect(clientRect);
00343                 for (std::vector<CTestWindow*>::iterator ii = displayedWindows.begin(); ii != displayedWindows.end(); ++ii) {
00344                         bool found = false;
00345                         for (std::vector<CTestWindow*>::iterator jj = newArea.begin(); jj != newArea.end(); ++jj) {
00346                                 if (*ii == *jj) {
00347                                         found = true;
00348                                         break;
00349                                 }
00350                         }
00351                         if (!found)
00352                                 (*ii)->DestroyWindowSpecial();
00353                 }
00354 //              TRACE0("Windows in area:\n");
00355                 for (std::vector<CTestWindow*>::iterator kk = newArea.begin(); kk != newArea.end(); ++kk) {
00356 //                      TRACE1("%s\n", (*kk)->GetTitle());
00357                         bool found = false;
00358                         for (std::vector<CTestWindow*>::iterator ll = displayedWindows.begin(); ll != displayedWindows.end(); ++ll) {
00359                                 if (*kk == *ll) {
00360                                         found = true;
00361                                         break;
00362                                 }
00363                         }
00364                         if (!found)
00365                                 (*kk)->CreateWindowSpecial(strTestWndClass);
00366                 }
00367                 displayedWindows = newArea;
00368 #else
00369                 if (mgaModel) {
00370 //                      CGMEEventLogger::LogGMEEvent("CGMEDoc::tellHistorian(ptr,asp)\r\n");
00371 
00372                         try     {
00373                                 long status;
00374                                 COMTHROW(mgaProject->get_ProjectStatus(&status));
00375                                 bool inTrans = (status & 0x08L) != 0;
00376                                 CComPtr<IMgaTerritory> terr;
00377                                 if (!inTrans) {
00378                                         COMTHROW(mgaProject->CreateTerritory(NULL, &terr));
00379                                         COMTHROW(mgaProject->BeginTransaction(terr, TRANSACTION_READ_ONLY));
00380                                 } else {
00381                                         COMTHROW(mgaProject->get_ActiveTerritory(&terr));
00382                                 }
00383 
00384                                 CComPtr<IMgaFCO> modelFco;
00385                                 COMTHROW(terr->OpenFCO(mgaModel, &modelFco));
00386                                 CComQIPtr<IMgaModel> model = modelFco;
00387 
00388                                 status = OBJECT_ZOMBIE;
00389                                 COMTHROW(model->get_Status(&status));
00390                                 if (status == OBJECT_EXISTS) {
00391                                         CComBSTR nameBStr;
00392                                         COMTHROW(model->get_Name(&nameBStr));
00393                                         CString nameCString;
00394                                         CopyTo(nameBStr, nameCString);
00395                                         TRACE0("Model (");
00396                                         TRACE0(nameCString);
00397                                         TRACE0("), aspect: ");
00398 
00399                                         // Get aspect name
00400                                         bool first = true;
00401                                         regPath = "PartRegs/";
00402                                         strAspect = "";
00403                                         if (mgaMetaModel) {
00404                                                 CComPtr<IMgaMetaAspects> mmAspects;
00405                                                 COMTHROW(mgaMetaModel->get_Aspects(&mmAspects));
00406                                                 CComPtr<IMgaMetaAspect> mmAspect;
00407                                                 COMTHROW(mmAspects->get_Item(currentAspect, &mmAspect));
00408                                                 CComBSTR bstr;
00409                                                 COMTHROW(mmAspect->get_DisplayedName(&bstr));
00410                                                 CopyTo(bstr, strAspect);
00411                                         }
00412                                         regPath += strAspect;
00413                                         regPath += "/Position";
00414                                         TRACE0(strAspect);
00415                                         TRACE0("\n");
00416 
00417                                         // create a DC for text metric
00418                                         CFont* oldCFont = pDC->SelectObject(&txtMetricFont);
00419                                         HFONT oldFont = (HFONT)oldCFont->GetSafeHandle();
00420 
00421                                         // Iterate through the children FCOs
00422                                         CComPtr<IMgaFCOs> ccpChildFCOs;
00423                                         COMTHROW(model->get_ChildFCOs(&ccpChildFCOs));
00424 
00425                                         if (!modelExtentCalculated)
00426                                                 modelExtent.SetRectEmpty();
00427                                         MGACOLL_ITERATE(IMgaFCO, ccpChildFCOs) {
00428                                                 CComPtr<IMgaFCO> ccpChildFCO(MGACOLL_ITER);
00429                                                 CComPtr<IMgaFCO> childFco;
00430                                                 COMTHROW(terr->OpenFCO(ccpChildFCO, &childFco));
00431 
00432                                                 CComBSTR nameBStr;
00433                                                 COMTHROW(childFco->get_Name(&nameBStr));
00434                                                 CString nameCString;
00435                                                 CopyTo(nameBStr, nameCString);
00436 
00437                                                 long x, y;
00438                                                 GetPosition(childFco, regPath, &x, &y);
00439                                                 char buf[64];
00440                                                 sprintf(buf, " pos(%d, %d)\n", x, y);
00441 
00442                                                 if (x != -1 && y != -1) {
00443                                                         CSize textSize = pDC->GetTextExtent(nameCString);
00444                                                         if (!modelExtentCalculated) {
00445                                                                 // Update extent information
00446                                                                 if (modelExtent.left > x)
00447                                                                         modelExtent.left = x;
00448                                                                 if (modelExtent.top > y)
00449                                                                         modelExtent.top = y;
00450                                                                 if (modelExtent.right < x + textSize.cx)
00451                                                                         modelExtent.right = x + textSize.cx;
00452                                                                 if (modelExtent.bottom < y + textSize.cy)
00453                                                                         modelExtent.bottom = y + textSize.cy;
00454                                                         }
00455 
00456                                                         CRect edge(x - MODEL_BOX_BORDER, y - MODEL_BOX_BORDER,
00457                                                                            x + textSize.cx + MODEL_BOX_BORDER, y + textSize.cy + MODEL_BOX_BORDER);
00458 
00459                                                         CRect intersectRect;
00460                                                         intersectRect.IntersectRect(edge, rcBounds);
00461                                                         if (!intersectRect.IsRectEmpty()) {
00462 #if !defined (WINDOWTEST)
00463                                                                 pDC->DrawEdge(edge, EDGE_BUMP, BF_RECT);
00464 
00465                                                                 pDC->SetTextAlign(TA_CENTER);
00466                                                                 pDC->TextOut(x + textSize.cx / 2, y, nameCString);
00467 #endif
00468                                                         }
00469                                                 }
00470 
00471                                                 TRACE0("FCO: ");
00472                                                 TRACE0(nameCString);
00473                                                 TRACE0(buf);
00474                                         }
00475                                         MGACOLL_ITERATE_END;
00476 
00477                                         if (!modelExtentCalculated) {
00478                                                 SetScroll();
00479                                                 modelExtentCalculated = true;
00480                                         }
00481 
00482                                         CFont* oldCFont2 = CFont::FromHandle(oldFont);
00483                                         pDC->SelectObject(oldCFont2);
00484                                 }
00485 
00486                                 if (!inTrans) {
00487                                         mgaProject->CommitTransaction();
00488                                 }
00489                         } catch(...) {
00490                                 ASSERT(0);
00491                         }
00492                 }
00493 #endif
00494         }
00495 
00496         // Do not call CWnd::OnPaint() for painting messages
00497 }
00498 
00499 BOOL CGMEViewDlg::OnEraseBkgnd(CDC* pDC)
00500 {
00501         return FALSE;   // kill this message--no default processing
00502 }
00503 
00504 void CGMEViewDlg::OnLButtonDown(UINT nFlags, CPoint point)
00505 {
00506         // Needed to flush the Object Inspector and the Browser (JIRA #GME-52)
00507 /*      SetFocus();
00508 
00509         CPartBrowserPaneFrame* parent = (CPartBrowserPaneFrame*)GetParent();
00510         ASSERT(parent != NULL);
00511 
00512         point.y += parent->GetScrollPosition ();
00513 
00514         PartWithDecorator pdt;
00515         bool found = FindObject(point, pdt);
00516 
00517         if (found) {
00518                 CRect rectAwake = CRect(point.x, point.y, point.x + 1, point.y + 1);
00519                 rectAwake.InflateRect(3, 3);
00520 
00521                 long x1 = 0; long y1 = 0;
00522                 long x2 = 0; long y2 = 0;
00523                 COMTHROW(pdt.decorator->GetLocation(&x1, &y1, &x2, &y2));
00524                 CRect partRect (x1, y1, x2, y2);
00525                 CPoint ptClickOffset(point.x - partRect.left, point.y - partRect.top);
00526 
00527                 CRectList rects;
00528                 rects.AddTail(&partRect);
00529 
00530                 CRectList dummyAnnList;
00531                 CGMEDataDescriptor desc(rects, dummyAnnList, point, ptClickOffset);
00532 //              CGMEDataDescriptor::destructList(rects);
00533 
00534                 CGMEDataSource dataSource(mgaProject);
00535                 CComPtr<IMgaMetaRole> mmRole;
00536                 COMTHROW(pdt.part->get_Role(&mmRole));
00537                 dataSource.SetMetaRole(mmRole);
00538                 dataSource.CacheDescriptor(&desc);
00539                 DROPEFFECT de = dataSource.DoDragDrop(DROPEFFECT_COPY, &rectAwake);
00540         }*/
00541 
00542 #if defined (WINDOWTEST)
00543         inWindowDragging = true;
00544         lastDragPoint = point;
00545 //      TRACE2("CGMEViewDlg::OnLButtonDown, point: %ld, %ld\n", point.x, point.y);
00546 #else
00547         CWnd::OnLButtonDown(nFlags, point);
00548 #endif
00549 }
00550 
00551 void CGMEViewDlg::OnMouseMove(UINT nFlags, CPoint point)
00552 {
00553 #if defined (WINDOWTEST)
00554         if (inWindowDragging) {
00555                 int deltax = point.x - lastDragPoint.x;
00556                 int deltay = point.y - lastDragPoint.y;
00557 //              TRACE("CGMEViewDlg::OnMouseMove, delta: %ld, %ld, point: %ld, %ld\n", deltax, deltay, point.x, point.y);
00558                 for (std::vector<CTestWindow*>::iterator ii = testWindows.begin(); ii != testWindows.end(); ++ii) {
00559                         (*ii)->MoveWindowSpecial(deltax, deltay);
00560                 }
00561                 lastDragPoint = point;
00562         }
00563 #endif
00564 }
00565 
00566 void CGMEViewDlg::OnLButtonUp(UINT nFlags, CPoint point)
00567 {
00568 #if defined (WINDOWTEST)
00569 //      TRACE2("CGMEViewDlg::OnLButtonUp, point: %ld, %ld\n", point.x, point.y);
00570         inWindowDragging = false;
00571 #endif
00572 }
00573 
00574 void CGMEViewDlg::OnSelchangeAspectTab(NMHDR* /*pNMHDR*/, LRESULT* pResult)
00575 {
00576 //      long s = tab.GetCurSel();
00577 //      if (s >= 0) {
00578 //              partFrame.GetPane().ChangeAspect(s);
00579 //              SendAspectChange(s);
00580 //      }
00581 //      Invalidate();
00582         *pResult = 0;
00583 }
00584 
00585 void CGMEViewDlg::SendAspectChange(long index)
00586 {
00587         CWnd* wnd = GetParent();
00588         if (wnd->IsKindOf(RUNTIME_CLASS(CGMEViewFrame))) {
00589                 CGMEViewFrame* frame = STATIC_DOWNCAST(CGMEViewFrame, wnd);
00590                 frame->SendAspectChange(index);
00591         }
00592 }
00593 
00594 void CGMEViewDlg::SendZoomChange(long index)
00595 {
00596         CWnd* wnd = GetParent();
00597         if (wnd->IsKindOf(RUNTIME_CLASS(CGMEViewFrame))) {
00598                 CGMEViewFrame* frame = STATIC_DOWNCAST(CGMEViewFrame, wnd);
00599                 frame->SendZoomChange(index);
00600         }
00601 }
00602 
00603 void CGMEViewDlg::SendWriteStatusZoom(long zoomVal)
00604 {
00605         CWnd* wnd = GetParent();
00606         if (wnd->IsKindOf(RUNTIME_CLASS(CGMEViewFrame))) {
00607                 CGMEViewFrame* frame = STATIC_DOWNCAST(CGMEViewFrame, wnd);
00608                 frame->SendWriteStatusZoom(zoomVal);
00609         }
00610 }
00611 
00612 BOOL CGMEViewDlg::DoDrop(eDragOperation doDragOp, COleDataObject *pDataObject, CPoint point)
00613 {
00614 //      MGATREECTRL_LOGEVENT("CAggregateTreeCtrl::DoDrop\r\n");
00615         CString _t = "";
00616         if( doDragOp == DRAGOP_REFERENCE)
00617                 _t = " REFERENCE\r\n";
00618         if( doDragOp == DRAGOP_SUBTYPE)
00619                 _t = " DERIVE\r\n";
00620         if( doDragOp == DRAGOP_INSTANCE)
00621                 _t = " INSTANCE\r\n";
00622         if( doDragOp == DRAGOP_COPY)
00623                 _t = " COPY\r\n";
00624         if( doDragOp == DRAGOP_MOVE)
00625                 _t = " MOVE\r\n";
00626         if( doDragOp == DRAGOP_CLOSURE)
00627                 _t = " CLOSURE COPY\r\n";
00628         if( doDragOp == DRAGOP_CLOSURE_MERGE)
00629                 _t = " COPY MERGE\r\n";
00630 //      MGATREECTRL_LOGEVENT( _t);
00631 
00632         // PETER: Checking clipboard, paste XML clipboard.
00633         if (!CGMEDataSource::IsGmeNativeDataAvailable(pDataObject, mgaProject))  {
00634                 if (!CGMEDataSource::IsXMLDataAvailable(pDataObject)) {
00635                         MessageBox("Unknown clipboard format.", "Error", MB_OK | MB_ICONERROR);
00636                         return FALSE;
00637                 }
00638                 if (doDragOp != DRAGOP_COPY && doDragOp != DRAGOP_CLOSURE && doDragOp != DRAGOP_CLOSURE_MERGE) {
00639                         MessageBox("Only copy operation is supported on GME XML clipboard format.", "Error", MB_OK | MB_ICONERROR);
00640                         return FALSE;
00641                 }
00642 
00643                 bool res = CGMEDataSource::ParseXMLData(pDataObject, mgaModel, doDragOp == DRAGOP_CLOSURE_MERGE);
00644 
00645                 return res ? TRUE : FALSE;
00646         }
00647         // PETER: end
00648 
00649 
00650         CComPtr<IDataObject> ccpDataObject = pDataObject->GetIDataObject(FALSE);
00651         CComPtr<IMgaDataSource> ccpMgaDataSource;
00652         COMTHROW(ccpDataObject.QueryInterface(&ccpMgaDataSource));
00653 
00654         CComPtr<IUnknown> ccpData;
00655         COMTHROW(ccpMgaDataSource->get_Data(&ccpData));
00656         
00657         CComPtr<IUnknown> ccpFolders;
00658         COMTHROW(ccpMgaDataSource->get_Folders(&ccpFolders));
00659         
00660         CComPtr<IMgaResolver> ccpMgaResolver;
00661         COMTHROW(ccpMgaResolver.CoCreateInstance(L"Mga.MgaResolver"));
00662 
00663         CComQIPtr<IMgaFCOs> ccpDroppedFCOs(ccpData);
00664         CComQIPtr<IMgaFolders> ccpDroppedFolders(ccpFolders);
00665 
00666         if (!ccpDroppedFCOs && !ccpDroppedFolders) {
00667                 BOOL bRetVal = FALSE;
00668 
00669                 MSGTRY {
00670                         CComQIPtr<IMgaMetaRole> metaRole(ccpData);
00671                         if (metaRole) {
00672                                 CComPtr<IMgaFCO> child;
00673 
00674                                 try     {
00675                                         long status;
00676                                         COMTHROW(mgaProject->get_ProjectStatus(&status));
00677                                         bool inTrans = (status & 0x08L) != 0;
00678                                         CComPtr<IMgaTerritory> terr;
00679                                         if (!inTrans) {
00680                                                 COMTHROW(mgaProject->CreateTerritory(NULL, &terr));
00681                                                 COMTHROW(mgaProject->BeginTransaction(terr, TRANSACTION_GENERAL));
00682                                         } else {
00683                                                 COMTHROW(mgaProject->get_ActiveTerritory(&terr));
00684                                         }
00685 
00686                                         CComPtr<IMgaFCO> modelFco;
00687                                         COMTHROW(terr->OpenFCO(mgaModel, &modelFco));
00688                                         CComQIPtr<IMgaModel> model = modelFco;
00689 
00690                                         status = OBJECT_ZOMBIE;
00691                                         COMTHROW(model->get_Status(&status));
00692                                         if (status == OBJECT_EXISTS) {
00693                                                 switch (doDragOp) {
00694                                                         case DRAGOP_MOVE:
00695                                                         case DRAGOP_COPY:
00696                                                         {
00697                                                                 COMTHROW(model->CreateChildObject(metaRole, &child));
00698                                                         } break;                                
00699                                                 }       // switch
00700                                                 if (child) {
00701                                                         CComBSTR nm;
00702                                                         COMTHROW(metaRole->get_DisplayedName(&nm));
00703                                                         COMTHROW(child->put_Name(nm));
00704 
00705                                                         char buf[64];
00706                                                         sprintf(buf, "%ld, %ld", point.x, point.y);
00707                                                         CComBSTR bb = buf;
00708                                                         CComBSTR regP = regPath;
00709                                                         COMTHROW(child->put_RegistryValue(regP, bb));
00710                                                 }
00711                                         }
00712 
00713                                         if (!inTrans) {
00714                                                 mgaProject->CommitTransaction();
00715                                         }
00716                                 } catch(...) {
00717                                         ASSERT(0);
00718                                 }
00719                         }
00720                 } MSGCATCH ("Error completing GME View drop operation", mgaProject->AbortTransaction ();)       
00721 
00722                 return bRetVal;
00723         }
00724 
00725         return FALSE;
00726 }