Click here to Skip to main content
15,884,099 members
Articles / Desktop Programming / MFC

The Ultimate Toolbox - Updates and User Contributions

Rate me:
Please Sign up or sign in to vote.
4.79/5 (26 votes)
12 Feb 2013CPOL8 min read 254.7K   23.7K   170  
Updates and User Contributions for the Ultimate Toolbox Libraries
/*************************************************************************
				Class Implementation : CUGCTAutoSize
**************************************************************************
	Source file : UGCTButn.cpp
// This software along with its related components, documentation and files ("The Libraries")
// is � 1994-2007 The Code Project (1612916 Ontario Limited) and use of The Libraries is
// governed by a software license agreement ("Agreement").  Copies of the Agreement are
// available at The Code Project (www.codeproject.com), as part of the package you downloaded
// to obtain this file, or directly from our office.  For a copy of the license governing
// this software, you may contact us at legalaffairs@codeproject.com, or by calling 416-849-8900.
*************************************************************************/

#include "stdafx.h"
#include "UGCtrl.h"
#include "UGCTAutoSize.h"

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

/***************************************************
CUGCTAutoSize - Contstructor
	Initialize member variables
****************************************************/
CUGCTAutoSize::CUGCTAutoSize()
{
}

/***************************************************
~CUGCTAutoSize - Destructor
	Clean up all allocated resources
****************************************************/
CUGCTAutoSize::~CUGCTAutoSize()
{
}

/***************************************************
OnDraw
	The Ultimate Grid calls this vistual function
	every time it is drawing a cell.  It is upto
	the individual cell type to properly draw itself.
Params:
	dc		- device context to draw the cell with
	rect	- rectangle to draw the cell in
	col		- column that is being drawn
	row		- row that is being drawn
	cell	- cell that is being drawn
	selected- TRUE if the cell is selected, otherwise FALSE
	current - TRUE if the cell is the current cell, otherwise FALSE
Return
	<none>
****************************************************/
void CUGCTAutoSize::OnDraw(CDC *dc,RECT *rect,int col,long row,CUGCell *cell,int selected,int current)
{
	if (!m_drawThemesSet)
		m_useThemes = cell->UseThemes();

	// before drawing of the cell check if it's content will fuly fit
	CSize size( 0, 0 );
	GetBestSize( dc, &size, cell );

	if ( size.cx > m_ctrl->GetColWidth( col ))
	{
		m_ctrl->SetColWidth( col, size.cx );
		m_ctrl->Invalidate();
	}
	else if ( size.cy > m_ctrl->GetRowHeight( row ))
	{
		m_ctrl->SetRowHeight( row, size.cy );
		m_ctrl->Invalidate();
	}
	else
		// call the default implementation
		CUGCellType::OnDraw( dc, rect, col, row, cell, selected, current );
}

/***************************************************
OnChangedCellWidth
	This notification is sent to all visible
	cells is affected column when the user has
	changed width of a column.
Params:
	col - column that the mouse is over
	row - row that the mouse is over
	width - pointer to new column width
Return:
	<none>
****************************************************/
void CUGCTAutoSize::OnChangedCellWidth(int col, long row, int* width)
{
	CClientDC dc( m_ctrl );
	CUGCell cell;
	CSize size;

	m_ctrl->GetCellIndirect( col, row, &cell );
	GetBestSize( &dc, &size, &cell );

	if ( size.cx > *width )
		*width = size.cy;
}

/***************************************************
OnChangedCellHeight
	This notification is sent to all visible
	cells is affected row when the user has
	changed height of a column.
Params:
	col - column that the mouse is over
	row - row that the mouse is over
	height - pointer to new row height
Return:
	<none>
****************************************************/
void CUGCTAutoSize::OnChangedCellHeight(int col, long row, int* height) 
{
	CClientDC dc( m_ctrl );
	CUGCell cell;
	CSize size;

	m_ctrl->GetCellIndirect( col, row, &cell );
	GetBestSize( &dc, &size, &cell );

	if ( size.cy > *height )
		*height = size.cy;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
This is a Organisation

476 members

Comments and Discussions