// TcxOwnerDrawEngine.cpp : implementation file
//
// Author: Thales P. Carvalho
// e-mail: thalesc@uol.com.br
//
// HISTORY:
// 10/17/1999
#include "stdafx.h"
#include "TcxOde.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Local functions
// Convert string to DWORD
// RETURN: pointer to the first character after converted string
static LPCTSTR _ParseNum( LPCTSTR psz, DWORD& dwOut )
{
dwOut = 0;
while( _istdigit(*psz) )
{
( dwOut *= 10 ) += ( *psz - _T('0') );
psz = _tcsinc(psz);
}
return psz;
}
// Skip text up to the next tag
// RETURN: pointer to the first tag character ('<'),
// or, if none is found, pointer to the end of
// the string (null terminator)
static LPCTSTR _SkipText( LPCTSTR psz )
{
while(
*psz != _T('\0') &&
*psz != _T('<') &&
*psz != _T('>')
)
psz = _tcsinc(psz);
return psz;
}
/////////////////////////////////////////////////////////////////////////////
// CTcxOwnerDrawEngine members
// Constructor
CTcxOwnerDrawEngine::CTcxOwnerDrawEngine() :
m_pImgList(NULL),
m_ColorHighLightText( ::GetSysColor( COLOR_HIGHLIGHTTEXT ) ),
m_ColorHighLightBk( ::GetSysColor( COLOR_HIGHLIGHT ) )
{
m_Tabs.SetSize( 0, 8 );
m_Styles.SetSize( 0, 8 );
m_DefaultStyle.dwId = MAXDWORD;
m_DefaultStyle.chFontStyle = 0;
m_DefaultTab.dwId = MAXDWORD;
m_DefaultTab.xTab = 0;
::memset( m_ahFonts, 0, sizeof(m_ahFonts) );
}
// Destructor
CTcxOwnerDrawEngine::~CTcxOwnerDrawEngine()
{
DeleteFonts();
}
// Set a style attributes
void CTcxOwnerDrawEngine::SetStyle(
DWORD dwStyleId, // style ID
COLORREF clrText, // style's text color
BOOL bBold, // style's font attribute (bold)
BOOL bItalic, // style's font attribute (italic)
BOOL bUnderline // style's font attribute (underline)
)
{
// Looking up the style ID in the style array.
// If there's no entry for this style, LookupStyle
// will create one and return its index.
int i = LookupStyle( dwStyleId );
STYLE& style = m_Styles[i];
// Saving style information
style.clrText = clrText;
style.chFontStyle = 0;
if( bBold )
style.chFontStyle |= STYLE::fBold;
if( bItalic )
style.chFontStyle |= STYLE::fItalic;
if( bUnderline )
style.chFontStyle |= STYLE::fUnderline;
}
// Called by the aggregator object to draw the item.
void CTcxOwnerDrawEngine::DrawItem(
LPDRAWITEMSTRUCT pDrw, // see DRAWITEMSTRUCT
LPCTSTR pszText // item's tagged text
)
{
m_bUpdateLayout = false;
if( !( pDrw->itemAction & (ODA_DRAWENTIRE|ODA_SELECT) ) )
{
::DrawFocusRect( pDrw->hDC, &pDrw->rcItem );
return;
}
ASSERT( m_DefaultStyle.dwId == MAXDWORD );
ASSERT( m_DefaultStyle.chFontStyle == 0 );
m_dwCurrentStyleId = MAXDWORD;
m_bSelected = ( pDrw->itemState & ODS_SELECTED ) ? true : false;
// Saving the DC's attributes (this is the default style)
COLORREF clrBk = ::GetBkColor( pDrw->hDC );
COLORREF clrText = ::GetTextColor( pDrw->hDC );
HGDIOBJ hFont = ::GetCurrentObject( pDrw->hDC, OBJ_FONT );
ASSERT( hFont != NULL );
if( m_bSelected )
{
// Modifying the DC to draw a selected item.
::SetTextColor( pDrw->hDC, m_ColorHighLightText );
::SetBkColor( pDrw->hDC, m_ColorHighLightBk );
}
// Erasing the item's background
::ExtTextOut( pDrw->hDC, 0, 0, ETO_OPAQUE, &pDrw->rcItem, NULL, 0, NULL );
// Storing the default style attributes
m_ahFonts[0] = hFont;
m_DefaultStyle.clrText = ::GetTextColor( pDrw->hDC );
// Doing the pre-calculations
PreDraw( pszText, pDrw->hDC );
// Restoring the default style
// (it might have been changed by PreDraw)
SelectStyle( pDrw->hDC, &m_DefaultStyle );
// Drawing (finally!)
Draw( pszText, pDrw->hDC, pDrw->rcItem );
// Drawing the focus rectangle - if any
if( pDrw->itemState & ODS_FOCUS )
::DrawFocusRect( pDrw->hDC, &pDrw->rcItem );
// Restoring DC's attributes
::SetTextColor( pDrw->hDC, clrText );
::SetBkColor( pDrw->hDC, clrBk );
::SelectObject( pDrw->hDC, hFont );
}
// Release all created fonts.
void CTcxOwnerDrawEngine::DeleteFonts()
{
// Font 0 (the default font) is never created by the engine.
// Although, it uses the DC's font.
m_ahFonts[0] = NULL;
// Destroying all font objects that might have been
// created by the engine.
for( int i = 1; i < sizeof(m_ahFonts)/sizeof(m_ahFonts[0]); ++i )
{
if( m_ahFonts[i] != NULL )
{
::DeleteObject( m_ahFonts[i] );
m_ahFonts[i] = NULL;
}
}
}
// Reset all tab marks
void CTcxOwnerDrawEngine::DeleteTabs()
{
m_Tabs.RemoveAll();
m_DefaultTab.dwId = MAXDWORD;
m_DefaultTab.xTab = 0;
}
/////////////////////////////////////////////////////////////////////////////
// CTcxOwnerDrawEngine private members
// Look up a tab mark id in the array of tab marks.
// RETURN: the tab mark index, or -1, if no item has been found or created
int CTcxOwnerDrawEngine::LookupTab(
DWORD dwId, // the tab mark id
BOOL bCreate // if TRUE, creates the item if none is found
)
{
// Performing a binary search
int iFirst = 0;
int iLast = m_Tabs.GetUpperBound();
while( iFirst <= iLast )
{
int i = ( iLast + iFirst ) / 2;
int c = m_Tabs[i].dwId - dwId;
if( c == 0 )
return i;
if( c < 0 )
iFirst = i+1;
else
iLast = i-1;
}
if( !bCreate )
return -1; // no item found, no item created
// No item found. Creating the item.
TAB newTab = { dwId, MAXDWORD, 0, { 0, 0, 0 } };
m_Tabs.InsertAt( ++iLast, newTab );
return iLast;
}
// Look up a style id in the array of styles.
// RETURN: the style index, or -1, if no item has been found or created
int CTcxOwnerDrawEngine::LookupStyle( DWORD dwId, BOOL bCreate )
{
// Performing a binary search
int iFirst = 0;
int iLast = m_Styles.GetUpperBound();
while( iFirst <= iLast )
{
int i = ( iLast + iFirst ) / 2;
int c = m_Styles[i].dwId - dwId;
if( c == 0 )
return i;
if( c < 0 )
iFirst = i+1;
else
iLast = i-1;
}
if( !bCreate )
return -1; // no item found, no item created
// No item found. Creating the item.
STYLE newStyle = { dwId, m_DefaultStyle.clrText, 0 };
m_Styles.InsertAt( ++iLast, newStyle );
return iLast;
}
// Called by PreDraw and Draw to select a style
void CTcxOwnerDrawEngine::SelectStyleFromId( HDC hDC, DWORD dwStyleId )
{
int i = LookupStyle( dwStyleId );
if( i < 0 )
return;
SelectStyle( hDC, &m_Styles[i] );
}
// Called by PreDraw and Draw to select a style
void CTcxOwnerDrawEngine::SelectStyle( HDC hDC, const STYLE* pStyle )
{
if( m_dwCurrentStyleId == pStyle->dwId )
return;
m_dwCurrentStyleId = pStyle->dwId;
if( !m_bSelected )
{
// Only change the text color if the item is not selected.
// Otherwise, the item will be drawn using the default
// selected item colors.
::SetTextColor( hDC, pStyle->clrText );
}
ASSERT( 0 <= pStyle->chFontStyle && pStyle->chFontStyle < 8 );
HGDIOBJ hFont = m_ahFonts[pStyle->chFontStyle];
if( hFont == NULL )
{
// Regular font (default) must always be suplied
ASSERT( pStyle->chFontStyle != 0 );
// The font for the selected style doesn't exist yet.
// Creating the font.
LOGFONT lf;
::GetObject( m_ahF
根据定义好的格式进行绘图 .zip_zip_绘图
版权申诉
195 浏览量
2022-09-21
03:18:08
上传
评论
收藏 24KB ZIP 举报
朱moyimi
- 粉丝: 65
- 资源: 1万+
最新资源
- student.sql
- 一个简单的卷积神经网络(Convolutional Neural Network, CNN)示例
- EXP9-1-dataPageDisplay.php
- buildType设计模式课程设计
- 省市区下拉选择:3个el-select(json)
- 堆排序(Heap Sort)是一种基于比较的排序算法
- ebatis 是一个简单方便上手的声明式 Elasticsearch ORM 框架
- 威纶通触摸屏编程软件Easy builder pro V6.09.02安装包(2024.06).txt
- ES查询客户端,elasticsearch可视化工具 elasticsearch查询客户端
- html css js网页制作实例 dldtdd实现列表功能
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈