home *** CD-ROM | disk | FTP | other *** search
- // dbmodvw.cpp : implementation of the CDbmodelView class
- //
-
- #include "stdafx.h"
- #include "dbmodel.h"
-
- #include "dbmoddoc.h"
- #include "dbmodvw.h"
- #include "idomfc.h"
- #include "textdlg.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CDbmodelView
-
- IMPLEMENT_DYNCREATE(CDbmodelView, CView)
-
- BEGIN_MESSAGE_MAP(CDbmodelView, CView)
- //{{AFX_MSG_MAP(CDbmodelView)
- ON_WM_CREATE()
- ON_WM_SIZE()
- ON_COMMAND(ID_EDIT_ADDE1, OnEditAdde1)
- ON_COMMAND(ID_EDIT_ADDE2, OnEditAdde2)
- ON_COMMAND(ID_EDIT_ADDR1, OnEditAddr1)
- ON_COMMAND(ID_EDIT_ADDR2, OnEditAddr2)
- ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
- ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
- ON_COMMAND(ID_FILE_SAVE, OnFileSave)
- //}}AFX_MSG_MAP
- ON_IDOM_N_CLICK_ENTITY(OnClickEntity)
- ON_IDOM_N_ENTITYADDED(OnEntityAdded)
- ON_IDOM_N_RELATIONADDREQUEST(OnRelationAddRequest)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CDbmodelView construction/destruction
-
- CDbmodelView::CDbmodelView()
- {
- // TODO: add construction code here
- m_pIDO = NULL;
- }
-
- CDbmodelView::~CDbmodelView()
- {
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CDbmodelView drawing
-
- void CDbmodelView::OnDraw(CDC* pDC)
- {
- CDbmodelDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- // TODO: add draw code for native data here
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CDbmodelView diagnostics
-
- #ifdef _DEBUG
- void CDbmodelView::AssertValid() const
- {
- CView::AssertValid();
- }
-
- void CDbmodelView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
-
- CDbmodelDoc* CDbmodelView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDbmodelDoc)));
- return (CDbmodelDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CDbmodelView message handlers
-
- int CDbmodelView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- long lStyle = WS_VISIBLE | WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_TABSTOP;
- RECT rect;
-
- rect.top = 10;
- rect.bottom = 20;
- rect.left = 0;
- rect.right = 10;
-
- m_pIDO = new CIDO;
- m_pIDO->Create(lStyle, rect, this, 101);
-
- if(m_pIDO)
- {
- // allow the IDO to be editable
- m_pIDO->SetEditMode(TRUE);
-
- // hide the tools palette
- m_pIDO->SetToolsPalette(FALSE);
-
- // rules are not enforced in this diagram
- m_pIDO->SetRulesEnforced(FALSE);
-
- // turn off default menus of IDO
- // m_pIDO->SetPopupMenu(IDOMENU_IDO, FALSE);
- m_pIDO->SetPopupMenu(IDOMENU_ENTITY, FALSE);
- m_pIDO->SetPopupMenu(IDOMENU_LINE, FALSE);
-
- // configure the classes for the diagram
- m_pIDO->ResetPalette();
- m_pIDO->ReadPalette("dbmodel.plt");
- }
-
-
- return 0;
- }
-
- void CDbmodelView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
-
- if(m_pIDO)
- {
- m_pIDO->SetWindowPos(NULL, 0, 20, cx, cy - 20, SWP_NOZORDER | SWP_NOACTIVATE);
- }
- }
-
-
- void CDbmodelView::OnFilePrint()
- {
- if(m_pIDO)
- {
- m_pIDO->PrintDiagram();
- }
- }
- void CDbmodelView::OnEditAdde1()
- {
- if(m_pIDO)
- {
- m_pIDO->DragAddEntity("entity1");
- }
- }
- void CDbmodelView::OnEditAdde2()
- {
- if(m_pIDO)
- {
- m_pIDO->DragAddEntity("entity2");
- }
- }
- void CDbmodelView::OnEditAddr1()
- {
- if(m_pIDO)
- {
- m_pIDO->DragAddRelation("link1");
- }
- }
- void CDbmodelView::OnEditAddr2()
- {
- if(m_pIDO)
- {
- m_pIDO->DragAddRelation("link2");
- }
- }
-
- LRESULT CDbmodelView::OnEntityAdded(WPARAM wParam, LPARAM lParam)
- {
- CEntity * pEntity;
- CString text;
-
-
- // get some text to place in this node
- CTextDlg textDlg(this, &text);
- textDlg.DoModal();
-
- // info is passed in the LPARAM of the message -
- // create a CEntity from this info
- pEntity = new CEntity((LPENTITY)lParam);
- pEntity->SetText(text.GetBuffer(0));
- // you must always call Repaint when changing attributes of an object
- pEntity->Repaint();
- delete pEntity;
-
- return TRUE;
- }
- LRESULT CDbmodelView::OnClickEntity(WPARAM wParam, LPARAM lParam)
- {
- CEntity * pEntity;
- CString text;
-
-
- if(lParam == NOTIFY_CLICK_LEFT_DBL)
- {
- // info is passed in the LPARAM of the message -
- // create a CEntity from this info
- pEntity = m_pIDO->GetNotifyEntity();
- if(!pEntity)
- return FALSE;
-
- text = pEntity->GetText();
-
- // get some text to place in this node
- CTextDlg textDlg(this, &text);
- textDlg.DoModal();
-
- pEntity->SetText(text.GetBuffer(0));
- // you must always call Repaint when changing attributes of an object
- pEntity->Repaint();
-
- delete pEntity;
- }
-
- return TRUE;
- }
-
-
-
- LRESULT CDbmodelView::OnRelationAddRequest(WPARAM wParam, LPARAM lParam)
- {
- CRelation * pRelation;
- CString classname;
-
-
- // info is passed in the LPARAM of the message -
- // create a CEntity from this info
- pRelation = new CRelation((LPRELATION)lParam);
- classname = pRelation->GetClassName();
-
- if(IDNO == MessageBox("Are you sure you want to add this link?", "Question", MB_YESNO | MB_ICONQUESTION))
- m_pIDO->CancelAction();
-
- delete pRelation;
-
- return TRUE;
- }
-
-
- void CDbmodelView::OnFileOpen()
- {
- int bOFRetCode;
- char szOFFilePath[80+1];
- char szOFFileTitle[40+1];
- char szOFFileDialogExt[] = "IDO";
- char szOFFileDialogFilter[] = "Diagram File|*.IDO||";
-
-
-
- CFileDialog fileDialogOF(TRUE, szOFFileDialogExt, NULL,
- OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,szOFFileDialogFilter);
-
- szOFFilePath[0] = '\0';
- fileDialogOF.m_ofn.lStructSize = sizeof(OPENFILENAME);
- fileDialogOF.m_ofn.hwndOwner = m_hWnd;
- fileDialogOF.m_ofn.lpstrCustomFilter = (LPSTR)NULL;
- fileDialogOF.m_ofn.nMaxCustFilter = 0L;
- fileDialogOF.m_ofn.nFilterIndex = 0;
- fileDialogOF.m_ofn.lpstrFile = szOFFilePath;
- fileDialogOF.m_ofn.nMaxFile = 256;
- fileDialogOF.m_ofn.lpstrFileTitle = szOFFileTitle;
- fileDialogOF.m_ofn.nMaxFileTitle = sizeof(szOFFileTitle);
- fileDialogOF.m_ofn.lpstrInitialDir = NULL;
- fileDialogOF.m_ofn.lpstrTitle = (LPSTR)"Open Diagram File";
- fileDialogOF.m_ofn.nFileOffset = 0;
- fileDialogOF.m_ofn.nFileExtension = 0;
-
- bOFRetCode = fileDialogOF.DoModal();
-
-
- if(bOFRetCode)
- {
- m_pIDO->ReadDiagram(szOFFilePath);
- SetWindowText(szOFFilePath);
- }
-
- }
-
- void CDbmodelView::OnFileSave()
- {
- int bSFRetCode;
- char szSFFilePath[80+1];
- char szSFFileTitle[40+1];
- char szSFFileDialogExt[] = "IDO";
- char szSFFileDialogFilter[] = "Diagram File|*.IDO||";
-
-
-
- CFileDialog fileDialogSF(FALSE, szSFFileDialogExt, NULL,
- OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST,szSFFileDialogFilter);
-
- szSFFilePath[0] = '\0';
- fileDialogSF.m_ofn.lStructSize = sizeof(OPENFILENAME);
- fileDialogSF.m_ofn.hwndOwner = m_hWnd;
- fileDialogSF.m_ofn.lpstrCustomFilter = (LPSTR)NULL;
- fileDialogSF.m_ofn.nMaxCustFilter = 0L;
- fileDialogSF.m_ofn.nFilterIndex = 0;
- fileDialogSF.m_ofn.lpstrFile = szSFFilePath;
- fileDialogSF.m_ofn.nMaxFile = 256;
- fileDialogSF.m_ofn.lpstrFileTitle = szSFFileTitle;
- fileDialogSF.m_ofn.nMaxFileTitle = sizeof(szSFFileTitle);
- fileDialogSF.m_ofn.lpstrInitialDir = NULL;
- fileDialogSF.m_ofn.lpstrTitle = (LPSTR)"Save Diagram File";
- fileDialogSF.m_ofn.nFileOffset = 0;
- fileDialogSF.m_ofn.nFileExtension = 0;
-
- bSFRetCode = fileDialogSF.DoModal();
-
-
- if(bSFRetCode)
- {
- m_pIDO->SaveDiagram(szSFFilePath);
- SetWindowText(szSFFilePath);
- }
- }
-