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

📄 umltemplatepropertydialog.cpp

📁 uml编辑器很牛
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ==========================================================================
	Class :			CUMLTemplatePropertyDialog

	Author :		Johan Rosengren, Abstrakt Mekanik AB

	Date :			2004-07-12

	Purpose :		"CUMLTemplatePropertyDialog" derives from "CDiagramPropertyDlg" 
					and is a wrapper for the template property dialog.

	Description :	Class-Wizard created class.

	Usage :			In the "CUMLEntityClassTemplate"-class, add a member of 
					the "CUMLTemplatePropertyDialog"-derived class, and call 
					"SetPropertyDialog" in the constructor.

					The dialog is displayed as a modeless dialog. The 
					editor will hide the dialog automatically when another
					object is selected, no special Close-button is 
					necessary.

					The dialog template with the res id "IDD_UML_DIALOG_PROPERTY_TEMPLATE"
					must be added to the project.

   ========================================================================*/

#include "stdafx.h"
#include "UMLTemplatePropertyDialog.h"
#include "UMLEntityClassTemplate.h"
#include "ClassAttributePropertyDialog.h"
#include "ClassOperationPropertyDialog.h"
#include "PropertyListEditorDialog.h"
#include "ClassDisplayPropertyDialog.h"
#include "GetterSetterDialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CUMLTemplatePropertyDialog dialog


CUMLTemplatePropertyDialog::CUMLTemplatePropertyDialog(CWnd* pParent /*=NULL*/)
	: CDiagramPropertyDlg(CUMLTemplatePropertyDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUMLTemplatePropertyDialog)
	m_name = _T("");
	m_parameter = _T("");
	m_propertylist = _T("");
	//}}AFX_DATA_INIT
}


void CUMLTemplatePropertyDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUMLTemplatePropertyDialog)
	DDX_Control(pDX, IDC_LIST_OPERATIONS, m_operation);
	DDX_Control(pDX, IDC_LIST_ATTRIBUTES, m_attribute);
	DDX_Control(pDX, IDC_EDIT_NAME, m_nameCtrl);
	DDX_Text(pDX, IDC_EDIT_NAME, m_name);
	DDX_Text(pDX, IDC_EDIT_PARAMETER, m_parameter);
	DDX_Text(pDX, IDC_EDIT_PROPERTY_LIST, m_propertylist);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CUMLTemplatePropertyDialog, CDialog)
	//{{AFX_MSG_MAP(CUMLTemplatePropertyDialog)
	ON_BN_CLICKED(IDC_BUTTON_ADD_ATTRIBUTE, OnButtonAddAttribute)
	ON_BN_CLICKED(IDC_BUTTON_ADD_OPERATION, OnButtonAddOperation)
	ON_BN_CLICKED(IDC_BUTTON_FONT, OnButtonFont)
	ON_BN_CLICKED(IDC_BUTTON_COLOR, OnButtonColor)
	ON_BN_CLICKED(IDC_BUTTON_PROPERTY_LIST, OnButtonPropertyList)
	ON_BN_CLICKED(IDC_BUTTON_AUTO_GENERATE, OnButtonAutoGenerate)
	ON_BN_CLICKED(IDC_BUTTON_VISIBILITY, OnButtonVisibility)
	ON_BN_CLICKED(IDC_BUTTON_AUTO_GENERATE2, OnButtonAutoGenerate2)
	//}}AFX_MSG_MAP
	ON_REGISTERED_MESSAGE(rwm_EXLISTBOX_DBLCLICK, OnListboxDblClick)
	ON_REGISTERED_MESSAGE(rwm_EXLISTBOX_DELETE, OnListboxDelete)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUMLTemplatePropertyDialog message handlers


void CUMLTemplatePropertyDialog::OnOK() 
/* ============================================================
	Function :		CUMLTemplatePropertyDialog::OnOK
	Description :	Handler for the dialog OK-button.
	Access :		Protected

	Return :		void
	Parameters :	none

	Usage :			Called from MFC.

   ============================================================*/
{

	CUMLEntityClassTemplate* uml = static_cast< CUMLEntityClassTemplate* >( GetEntity() );

	UpdateData();
	if( m_name.IsEmpty() )
	{
		AfxMessageBox( IDS_UML_CLASS_MUST_HAVE_A_NAME );
		m_nameCtrl.SetFocus();
		return;
	}

	uml->SetTitle( m_name );
	uml->SetBkColor( m_color );
	uml->SetFont( m_font );

	m_parameter.TrimLeft();
	m_parameter.TrimRight();

	uml->SetParameterType( m_parameter );
	uml->GetProperties()->Copy( m_properties );

	CreateAttributes();
	CreateOperations();

	ClearListboxes();

	uml->CalcRestraints();

	Redraw();
	ShowWindow( SW_HIDE );
	GetRedrawWnd()->SetFocus();

}

void CUMLTemplatePropertyDialog::OnCancel() 
/* ============================================================
	Function :		CUMLTemplatePropertyDialog::OnCancel
	Description :	Handler for the dialog Cancel-button.
	Access :		Protected

	Return :		void
	Parameters :	none

	Usage :			Called from MFC.

   ============================================================*/
{

	ClearListboxes();
	CDialog::OnCancel();
	GetRedrawWnd()->SetFocus();

}

void CUMLTemplatePropertyDialog::SetValues() 
/* ============================================================
	Function :		CUMLTemplatePropertyDialog::SetValues
	Description :	Sets the fields in the dialog box with the
					values from the attached object.
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Call to update the dialog box. Note that 
					this function will be called before the 
					dialog is created.

   ============================================================*/
{

	CUMLEntityClassTemplate* uml = static_cast< CUMLEntityClassTemplate* >( GetEntity() );

	m_name = uml->GetTitle();
	m_color = uml->GetBkColor();
	m_font = uml->GetFont();
	m_parameter = uml->GetParameterType();

	m_properties.Copy( *( uml->GetProperties() ) );

	if( m_hWnd && ::IsWindowVisible( m_hWnd ) )
	{
		FillListboxes();
		m_propertylist = m_properties.GetString( STRING_FORMAT_UML );
		UpdateData( FALSE );
	}

}

void CUMLTemplatePropertyDialog::OnButtonAddAttribute() 
/* ============================================================
	Function :		CUMLTemplatePropertyDialog::OnButtonAddAttribute
	Description :	Handler for the dialog button Add Attribute
	Access :		Protected

	Return :		void
	Parameters :	none

	Usage :			Called from MFC.

   ============================================================*/
{

	CClassAttributePropertyDialog	dlg;
	if( dlg.DoModal() == IDOK )
	{
		CAttribute* obj = dlg.GetAttribute();
		CString output = obj->ToString( FALSE );
		int index = m_attribute.AddString( output );
		m_attribute.SetItemData( index, ( DWORD ) obj );
		m_attribute.SetCurSel( index );
		m_attribute.SetFocus();
	}
	else
		delete dlg.GetAttribute();

}

void CUMLTemplatePropertyDialog::EditAttribute() 
/* ============================================================
	Function :		CUMLTemplatePropertyDialog::EditAttribute
	Description :	Edits the selected attribute in the 
					attribute list.
	Access :		Private

	Return :		void
	Parameters :	none

	Usage :			Call to edit the current attribute. The Edit 
					attribute dialog will be displayed.

   ============================================================*/
{

	int index = m_attribute.GetCurSel();
	if( index != LB_ERR )
	{
		CAttribute* obj = reinterpret_cast< CAttribute* >( m_attribute.GetItemData( index ) );
		if( obj )
		{
			CClassAttributePropertyDialog	dlg;
			dlg.SetAttribute( obj );
			if( dlg.DoModal() == IDOK )
				RefreshListboxes();
			m_attribute.SetCurSel( index );
			m_attribute.SetFocus();
		}
	}	

}

void CUMLTemplatePropertyDialog::DeleteAttribute() 
/* ============================================================
	Function :		CUMLTemplatePropertyDialog::DeleteAttribute
	Description :	Deletes the current attribute in the attribute list.
	Access :		Private

	Return :		void
	Parameters :	none

	Usage :			Call to delete the current attribute in the 
					attribute list.

   ============================================================*/
{

	int index = m_attribute.GetCurSel();
	if( index != LB_ERR )
	{
		if( AfxMessageBox( IDS_UML_DELETE_ATTRIBUTE, MB_YESNO ) == IDYES )
		{
			CAttribute* obj = reinterpret_cast< CAttribute* >( m_attribute.GetItemData( index ) );
			m_attribute.DeleteString( index );
			delete obj;
			m_attribute.SetCurSel( index );
			m_attribute.SetFocus();
		}
	}

}

void CUMLTemplatePropertyDialog::OnButtonAddOperation() 
/* ============================================================
	Function :		CUMLTemplatePropertyDialog::OnButtonAddOperation
	Description :	Handler for the dialog button Add Operation
	Access :		Protected

	Return :		void
	Parameters :	none

	Usage :			Called from MFC.

   ============================================================*/
{

	CClassOperationPropertyDialog	dlg;
	if( dlg.DoModal() == IDOK )
	{
		COperation* obj = dlg.GetOperation();
		CString output = obj->ToString( FALSE, FALSE );
		int index = m_operation.AddString( output );
		m_operation.SetItemData( index, ( DWORD ) obj );
		m_operation.SetCurSel( index );
		m_operation.SetFocus();
	}
	else
		delete dlg.GetOperation();

}

void CUMLTemplatePropertyDialog::EditOperation() 
/* ============================================================
	Function :		CUMLTemplatePropertyDialog::EditOperation
	Description :	Edits the selected operation in the 
					operation list.
	Access :		Private

	Return :		void
	Parameters :	none

	Usage :			Call to edit the selected operation in the 
					operation list. The Edit operation dialog 
					will be displayed.

   ============================================================*/
{

	int index = m_operation.GetCurSel();
	if( index != LB_ERR )
	{
		COperation* obj = reinterpret_cast< COperation* >( m_operation.GetItemData( index ) );
		if( obj )
		{
			CClassOperationPropertyDialog	dlg;
			dlg.SetOperation( obj );
			if( dlg.DoModal() == IDOK )
				RefreshListboxes();
			m_operation.SetCurSel( index );
			m_operation.SetFocus();
		}
	}	

}

void CUMLTemplatePropertyDialog::DeleteOperation() 
/* ============================================================
	Function :		CUMLTemplatePropertyDialog::DeleteOperation
	Description :	Delete the currently selected operation in 
					the operation list.
	Access :		

	Return :		void
	Parameters :	none

	Usage :			Call to delete the currently selected 
					operation in the operation list.

   ============================================================*/
{

	int index = m_operation.GetCurSel();
	if( index != LB_ERR )
	{
		if( AfxMessageBox( IDS_UML_DELETE_OPERATION, MB_YESNO ) == IDYES )
		{
			COperation* obj = reinterpret_cast< COperation* >( m_operation.GetItemData( index ) );
			m_operation.DeleteString( index );
			delete obj;
			m_operation.SetCurSel( index );
			m_operation.SetFocus();
		}
	}

}

void CUMLTemplatePropertyDialog::OnButtonFont() 
/* ============================================================
	Function :		CUMLTemplatePropertyDialog::OnButtonFont
	Description :	Handler for the dialog button Font
	Access :		Protected

	Return :		void
	Parameters :	none

	Usage :			Called from MFC.

   ============================================================*/
{

	CFont font;
	CUMLEntityClassTemplate* uml = static_cast< CUMLEntityClassTemplate* >( GetEntity() );
	font.CreatePointFont( 120, uml->GetFont() );
	LOGFONT lf;
	font.GetLogFont( &lf );
	CFontDialog	dlg( &lf );
	if( dlg.DoModal() == IDOK )
	{
		m_font = dlg.GetFaceName();
		Redraw();
	}
	
}

void CUMLTemplatePropertyDialog::OnButtonColor() 
/* ============================================================
	Function :		CUMLTemplatePropertyDialog::OnButtonColor
	Description :	Handler for the dialog button Color
	Access :		Protected

	Return :		void
	Parameters :	none

	Usage :			Called from MFC.

   ============================================================*/
{

	CUMLEntityClassTemplate* uml = static_cast< CUMLEntityClassTemplate* >( GetEntity() );
	COLORREF color = uml->GetBkColor();
	CColorDialog	dlg( color );
	if( dlg.DoModal() == IDOK )
	{
		m_color = dlg.GetColor();
		Redraw();
	}
	
}

void CUMLTemplatePropertyDialog::FillListboxes()
/* ============================================================
	Function :		CUMLTemplatePropertyDialog::FillListboxes
	Description :	Fills the attribute and operation listboxes 
					from the attached "CUMLEntityClassTemplate" object.
	Access :		Private

	Return :		void

⌨️ 快捷键说明

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