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

📄 umlentitylabel.cpp

📁 uml编辑器很牛
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	Description :	Sets the object rectangle
	Access :		Public

	Return :		void
	Parameters :	double left		-	New left position
					double top		-	New top position
					double right	-	New right position
					double bottom	-	New bottom position
					
	Usage :			This function is overridden to recalculate 
					rectangle restraints.	

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

	CDiagramEntity::SetRect( left, top, right, bottom );
	CalcRestraints();

}

void CUMLEntityLabel::CalcRestraints()
/* ============================================================
	Function :		CUMLEntityLabel::CalcRestraints
	Description :	Calculates, depending on the contents, the 
					minimum size for this object.
	Access :		Public

	Return :		void
	Parameters :	none

	Usage :			Call when the contents change. The size is 
					calculated by calling "DrawText" on a "CDC", 
					getting back the height from the given 
					width.

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

	CString title = GetTitle();
	if( title.GetLength() )
	{

		CDC* dc = CWnd::GetDesktopWindow()->GetDC();

		CRect rect = GetRect();
		CRect newRect( rect );
		CFont font;
		int weight = FW_NORMAL;
		if( GetBold() )
			weight = FW_BOLD;

		font.CreateFont( -GetPointsize(), 0,0,0,weight, ( BYTE ) GetItalic(), ( BYTE ) GetUnderline(),0,0,0,0,0,0, GetFont() );
		CFont* oldfont = dc->SelectObject( &font );
		dc->DrawText( GetTitle(), newRect, DT_WORDBREAK | DT_CALCRECT );
		dc->SelectObject( oldfont );
		CWnd::GetDesktopWindow()->ReleaseDC( dc );

		int diff = newRect.Height() - rect.Height();
		rect.bottom += diff;
		if( GetBottom() - GetTop() < rect.Height() )
			SetBottom( GetTop() + rect.Height() );

		if( GetDefaultSize().cy < rect.Height() )
		{
			SetMinimumSize( CSize( GetDefaultSize().cx, rect.Height() ) );
			CRect rc = GetRect();
			if( rc.Height() < rect.Height() )
				SetRect( GetLeft(), GetTop(), GetRight(), GetTop() + rect.Height() );
		}
		else
			SetMinimumSize( GetDefaultSize() );

	}

}

int CUMLEntityLabel::GetLinkCode( CPoint /*point*/ ) const
/* ============================================================
	Function :		CUMLEntityLabel::GetLinkCode
	Description :	Returns the link code of this object for 
					the position "point".
	Access :		Public

	Return :		int				-	Always "LINK_NONE"
	Parameters :	CPoint point	-	Position to test
					
	Usage :			Labels can't be linked to.

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

	return LINK_NONE;

}

CString CUMLEntityLabel::Export( UINT format ) const
/* ============================================================
	Function :		CUMLEntityLabel::Export
	Description :	Exports this object to the desired format.
	Access :		Public
					
	Return :		CString		-	Result
	Parameters :	UINT format	-	Format to export to
					
	Usage :			"format" can be one of the following:
						"EXPORT_CPP" Export to cpp-files
						"EXPORT_H" Export to header files
						"EXPORT_HTML" Export to HTML-files

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

	CString result;

	switch( format )
	{
		case EXPORT_HTML:
			result = ExportHTML();
			break;
	}

	return result;

}

CString CUMLEntityLabel::ExportHTML() const
/* ============================================================
	Function :		CUMLEntityLabel::ExportHTML
	Description :	Exports the label to HTML
	Access :		Private

	Return :		CString	-	Resulting HTML-code.
	Parameters :	none

	Usage :			Call to export the label to HTML

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

	CString result;
	CRect rect = GetRect();

	int font_size = GetPointsize();
	CString fontweight( _T( "normal" ) );
	if( GetBold() )
		fontweight = _T( "bold" );
	CString fontstyle( _T( "normal" ) );
	if( GetItalic() )
		fontstyle = _T( "italic" );
	CString textdecoration( _T( "none" ) );
	if( GetUnderline() )
		textdecoration = _T( "underline" );

	CString color = ColorrefToString( GetBkColor() );
	CString title = GetTitle();
	title.Replace( _T( "<" ), _T( "&lt;" ) );
	title.Replace( _T( ">" ), _T( "&gt;" ) );
	title.Replace( _T( "\r\n" ), _T( "<br>" ) );

	result.Format( _T( "<div style='position:absolute;left:%i;top:%i;width:%i;height:%i;font-family:%s;font-size:%i;overflow:hidden;font-weight:%s;font-style:%s;text-decoration:%s;'>%s</div>" ),
		rect.left, rect.top, rect.Width(), rect.Height(), GetFont(), font_size, fontweight, fontstyle, textdecoration, title );

	return result;
}

void CUMLEntityLabel::SetPointsize( int pointsize )
/* ============================================================
	Function :		CUMLEntityLabel::SetPointsize
	Description :	Sets the point size (or, more correctly, 
					the pixel size) of the label font.
	Access :		Public

	Return :		void
	Parameters :	int pointsize	-	New size
					
	Usage :			Call to set a new font size.

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

	if( pointsize != m_pointsize )
	{
		m_pointsize = pointsize;
		CalcRestraints();
	}

}

void CUMLEntityLabel::SetBold( BOOL bold )
/* ============================================================
	Function :		CUMLEntityLabel::SetBold
	Description :	Sets the bold-flag of the label font.
	Access :		Public

	Return :		void
	Parameters :	BOOL bold	-	"TRUE" if the font should be bold.
					
	Usage :			Call to set (or reset) a bold font for the 
					label.

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

	m_bold = bold;

}

void CUMLEntityLabel::SetItalic( BOOL italic )
/* ============================================================
	Function :		CUMLEntityLabel::SetItalic
	Description :	Sets the italic flag for the label font.
	Access :		Public

	Return :		void
	Parameters :	BOOL italic	-	"TRUE" if the font should be 
									italic.
					
	Usage :			Call to set (or reset) an italic font for the 
					label.


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

	m_italic = italic;

}

void CUMLEntityLabel::SetUnderline( BOOL underline )
/* ============================================================
	Function :		CUMLEntityLabel::SetUnderline
	Description :	Sets the underline flag for the label font.
	Access :		Public

	Return :		void
	Parameters :	BOOL underline	-	"TRUE" if the font should be 
										underlined.
					
	Usage :			Call to set (or reset) an underlined font 
					for the label.


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

	m_underline = underline;

}

int CUMLEntityLabel::GetPointsize() const
/* ============================================================
	Function :		CUMLEntityLabel::GetPointsize
	Description :	Gets the pixel size for the label font.
	Access :		Public

	Return :		int	-	Current size
	Parameters :	none

	Usage :			Call to get the font size of the label.

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

	return m_pointsize;

}

BOOL CUMLEntityLabel::GetBold() const
/* ============================================================
	Function :		CUMLEntityLabel::GetBold
	Description :	Gets the bold flag from the label
	Access :		Public

	Return :		BOOL	-	"TRUE" if bold
	Parameters :	none

	Usage :			Call to get the bold-flag of the label.

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

	return m_bold;

}

BOOL CUMLEntityLabel::GetItalic() const
/* ============================================================
	Function :		CUMLEntityLabel::GetItalic
	Description :	Gets the italic flag from the label
	Access :		Public

	Return :		BOOL	-	"TRUE" if italic
	Parameters :	none

	Usage :			Call to get the italic-flag of the label.

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

	return m_italic;

}

BOOL CUMLEntityLabel::GetUnderline() const
/* ============================================================
	Function :		CUMLEntityLabel::GetUnderline
	Description :	Gets the underline-flag from the label
	Access :		Public

	Return :		BOOL	-	"TRUE" if underlined
	Parameters :	none

	Usage :			Call to get the underline-flag of the label.

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

	return m_underline;

}

⌨️ 快捷键说明

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