www.pudn.com > ToolBar_ATL.rar > ToolBarDoc.cpp


// ToolBarDoc.cpp: implementation of the CToolBarDoc class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "ktoolbar.h" 
#include "ToolBarDoc.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CToolBarDoc::CToolBarDoc() 
{ 
	m_pButtons = NULL; 
	m_CurHoverIndex = -1; 
	m_PrevHoverIndex = -1; 
	m_nBtnCnt = 0; 
 
	SetBarStyle(BAR_16); 
} 
 
CToolBarDoc::~CToolBarDoc() 
{ 
	if(m_pButtons){ 
		if(m_pButtons->ToolTips){ 
			delete[] m_pButtons->ToolTips; 
		} 
 
		if(m_pButtons->Key){ 
			delete[] m_pButtons->Key; 
		} 
 
		if(m_pButtons->Icon){ 
			m_pButtons->Icon->Release(); 
		} 
		free(m_pButtons); 
	} 
} 
 
int CToolBarDoc::GetBtnCnt() 
{ 
	return m_nBtnCnt; 
} 
 
void CToolBarDoc::SetBtnCnt(int aBtnCnt) 
{ 
	int i; 
	//If the new button count is equal to current button count, 
	//It is not necessary to reallocate buttons. 
	if(aBtnCnt == m_nBtnCnt)return; 
	 
	m_nBtnCnt = aBtnCnt; 
	if(m_pButtons!=NULL){ 
		free(m_pButtons); 
	} 
	 
	if(m_nBtnCnt>0){ 
		m_pButtons = (TBItem*)malloc(m_nBtnCnt*sizeof(TBItem)); 
		memset(m_pButtons,0,m_nBtnCnt*sizeof(TBItem)); 
		for(i=0;i=0); 
	return &m_pButtons[Index]; 
} 
 
int CToolBarDoc::GetPrevHoverIndex() 
{ 
	return m_PrevHoverIndex; 
} 
 
void CToolBarDoc::SetPrevHoverIndex(int newIndex) 
{ 
	m_PrevHoverIndex = newIndex; 
} 
 
 
int CToolBarDoc::GetCurHoverIndex() 
{ 
	return m_CurHoverIndex; 
} 
 
void CToolBarDoc::SetCurHoverIndex(int newIndex) 
{ 
	m_CurHoverIndex = newIndex; 
} 
 
 
BarStyle CToolBarDoc::GetBarStyle() 
{ 
	return m_BarStyle; 
} 
 
void CToolBarDoc::SetBarStyle(BarStyle aNewStyle) 
{ 
	m_BarStyle = aNewStyle; 
}