⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diagramdlg.cpp

📁 TabBars的开源源码
💻 CPP
字号:
// DiagramDlg.cpp : implementation file
//

#include "stdafx.h"
#include "tabbars.h"
#include "Globals.h"
#include "DiagramDlg.h"
#include "EditConnectionDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDiagramDlg dialog

BOOL CDiagramDlg::GetDiagram(CString& sDiagram)
{
	return m_ctrlDiagram.GetDiagram(sDiagram);
}

CDiagramDlg::CDiagramDlg(LPCTSTR szDiagram,CWnd* pParent /*=NULL*/)
	: CDialog(CDiagramDlg::IDD, pParent), m_strDiagram(szDiagram)
{
	//{{AFX_DATA_INIT(CDiagramDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDiagramDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDiagramDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDiagramDlg, CDialog)
	//{{AFX_MSG_MAP(CDiagramDlg)
	ON_BN_CLICKED(IDC_BTN_NEW_BOX, OnBtnNewBox)
	ON_BN_CLICKED(IDC_BTN_EDIT_TEXT, OnBtnEditText)
	ON_BN_CLICKED(IDC_BTN_DELETE_BOX, OnBtnDeleteBox)
	ON_BN_CLICKED(IDC_BTN_NEW_CONNECT, OnBtnNewConnect)
	ON_BN_CLICKED(IDC_BTN_CLEAR, OnBtnClear)
	//}}AFX_MSG_MAP
	ON_NOTIFY(TDN_SELCHANGE, IDC_DIAGRAM, OnDiagramSelChange)
	ON_NOTIFY(TDN_SELRECTMOVE, IDC_DIAGRAM, OnDiagramRectMove)
	ON_NOTIFY(TDN_INTERNALERROR, IDC_DIAGRAM, OnDiagramInternalError)
	ON_NOTIFY(TDN_DBLCLK, IDC_DIAGRAM, OnDiagramDblClk)
	ON_NOTIFY(TDN_IMPLCONNNEW, IDC_DIAGRAM, OnDiagramImplNewConn)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDiagramDlg message handlers

BOOL CDiagramDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CRect rect;
	GetDlgItem(IDC_DIAGRAM)->GetWindowRect(rect);
	GetDlgItem(IDC_DIAGRAM)->DestroyWindow();

	ScreenToClient(rect);
	rect.DeflateRect(1, 1);

	m_ctrlDiagram.Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP, rect, this, IDC_DIAGRAM);
	m_ctrlDiagram.ModifyStyleEx(0, WS_EX_STATICEDGE);

	rect.InflateRect(1, 1);
	m_ctrlDiagram.MoveWindow(rect);
	m_ctrlDiagram.SetDiagram(m_strDiagram);

	SetDlgItemText(IDC_EDIT_TITLE,m_ctrlDiagram.GetTitle());
	// grab the current diagram as the first backup
	m_diagramBackup.SetDiagram(m_ctrlDiagram);
	
	EnableOK();
	UpdateControls();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDiagramDlg::OnDiagramRectMove(TDNHDR* pTDHdr, LRESULT* pResult)
{
	EnableOK();
	UpdateControls();
}

void CDiagramDlg::OnDiagramSelChange(TDNHDR* pTDHdr, LRESULT* pResult)
{
	UpdateControls();
}

void CDiagramDlg::OnDiagramInternalError(TDNHDR* pTDHdr, LRESULT* pResult)
{
	if (m_diagramBackup.GetRectCount())
	{
		// restore the last backup and message the user
		m_ctrlDiagram.SetDiagram(m_diagramBackup);
		
		MessageBox("Sorry, the last edit could not be completed.\n\nHowever, the diagram was backed-up and has been restored so that you can try the edit again.",
					"CodePlotter Error");

		EnableOK();
	}
}

void CDiagramDlg::OnDiagramDblClk(TDNHDR* pTDHdr, LRESULT* pResult)
{
	CPoint point(pTDHdr->ptCursor);

	int nConn = m_ctrlDiagram.HitTestConn(point);

	if (nConn != -1)
		EditConnection(nConn);
}

void CDiagramDlg::OnDiagramImplNewConn(TDNHDR* pTDHdr, LRESULT* pResult)
{
	int nSelRect = m_ctrlDiagram.GetSelRect();

	if (nSelRect == -1)
		return;

	CEditConnectionDlg dialog(m_ctrlDiagram, nSelRect);

	if (dialog.DoModal() != IDOK)
		return;

	CTDConnection conn;

	if (dialog.GetConnection(conn) && 
		m_ctrlDiagram.AddConnection(nSelRect, conn.RectTo(), conn.SideFrom()) >= 0)
	{
		// update UI
		EnableOK();
		UpdateControls(); 
	}
	else
		MessageBox("Sorry, the requested connection could not be added.", "CodePlotter");
}

void CDiagramDlg::OnBtnNewBox() 
{
	if(m_ctrlDiagram.AddRect() >= 0)
	{
		// refresh UI
		EnableOK();
		UpdateControls();

		m_ctrlDiagram.EditSelectedText();
	}
	else
#ifdef _VER_CHINESE
		MessageBox(_T("试图新建文本框时出现错误!"), lpszMsgBoxTitle);
#else
		MessageBox(_T("Sorry, a new rectangle could not be added."), lpszMsgBoxTitle);
#endif
}

void CDiagramDlg::OnBtnEditText() 
{
	m_ctrlDiagram.EditSelectedText();	
}

void CDiagramDlg::OnBtnDeleteBox() 
{
	if(m_ctrlDiagram.DeleteRect(m_ctrlDiagram.GetSelRect()))
	{
		// refresh UI
		EnableOK();
		UpdateControls();
	}
}

void CDiagramDlg::OnBtnNewConnect() 
{
	int nSelRect = m_ctrlDiagram.GetSelRect();

	if (nSelRect == -1)
		return;

	CEditConnectionDlg dialog(m_ctrlDiagram, nSelRect);

	if (dialog.DoModal() != IDOK)
		return;

	CTDConnection conn;

	if (dialog.GetConnection(conn) && m_ctrlDiagram.AddConnection(nSelRect, conn.RectTo(), conn.SideFrom()) >= 0)
	{
		// update UI
		EnableOK();
	}
	else
#ifdef _VER_CHINESE
		MessageBox(_T("试图新建连接关系时出现错误!"), lpszMsgBoxTitle);
#else
		MessageBox(_T("Sorry, the requested connection could not be added."), lpszMsgBoxTitle);
#endif
}

void CDiagramDlg::OnBtnClear() 
{
	m_ctrlDiagram.ResetDiagram();
	m_diagramBackup.ResetDiagram();
	
	SetDlgItemText(IDC_EDIT_TITLE,lpszNull);

	GetDlgItem(IDC_BTN_EDIT_TEXT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_DELETE_BOX)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_NEW_CONNECT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_CLEAR)->EnableWindow(FALSE);
}

BOOL CDiagramDlg::EnableOK()
{
	BOOL bOK = m_ctrlDiagram.VerifyDiagram();

	m_diagramBackup.SetDiagram(m_ctrlDiagram);

	GetDlgItem(IDOK)->EnableWindow(bOK);

	return bOK;
}

void CDiagramDlg::EditConnection(int nConn)
{
	CTDConnection conn;

	if (!m_ctrlDiagram.GetConnection(nConn, conn))
		return;

	CEditConnectionDlg dialog(m_ctrlDiagram, conn.RectFrom(), conn.RectTo());

	if (dialog.DoModal() != IDOK)
		return;

	if (dialog.GetConnection(conn) && m_ctrlDiagram.SetConnection(nConn, conn))
	{
		// update UI
		EnableOK();
		UpdateControls();
	}
	else
#ifdef _VER_CHINESE
		MessageBox(_T("试图编辑这个连接关系时出现错误!"), lpszMsgBoxTitle);
#else
		MessageBox(_T("Sorry, the connection could not be edited as requested."), lpszMsgBoxTitle);
#endif
}

void CDiagramDlg::UpdateControls()
{
	int nSel = m_ctrlDiagram.GetSelRect();

	GetDlgItem(IDC_BTN_EDIT_TEXT)->EnableWindow(nSel != -1 && !m_ctrlDiagram.EditingText());
	GetDlgItem(IDC_BTN_DELETE_BOX)->EnableWindow(nSel != -1);
	GetDlgItem(IDC_BTN_NEW_CONNECT)->EnableWindow(nSel != -1 && m_ctrlDiagram.GetRectCount() > 1);
	GetDlgItem(IDC_BTN_CLEAR)->EnableWindow(!m_ctrlDiagram.IsEmpty());
}

void CDiagramDlg::OnOK() 
{
	TCHAR szTitle[256];
	GetDlgItemText(IDC_EDIT_TITLE,szTitle,256);
	m_ctrlDiagram.SetTitle(szTitle);
	
	CDialog::OnOK();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -