Click here to Skip to main content
12,759,231 members (32,813 online)
Click here to Skip to main content

Stats

184K views
20.3K downloads
167 bookmarked
Posted 22 Apr 2008

The Ultimate Toolbox - Updates and User Contributions

, 12 Feb 2013 CPOL
Updates and User Contributions for the Ultimate Toolbox Libraries
Ultimate Grid
Demos
OutlookStyle
OutlookStyle.aps
OutlookStyle.dsp
OutlookStyle.dsw
OutlookStyle.suo
res
bitmap1.bmp
bmattach.bmp
bmp00001.bmp
bmp00002.bmp
bmp00003.bmp
Flags.bmp
OutlookStyle.ico
OutlookStyleDoc.ico
Toolbar.bmp
toolbar1.bmp
toolbar2.bmp
toolbarf.bmp
CellTypes
Include
Source
DataSources
ODBC
OleDB
EditControls
BuildDLL
Build DLL.dsp
Build DLL.dsw
res
BuildLib
ugmfclib.dsp
ugmfclib.dsw
Lib
Skel
Ultimate TCP-IP
Include
Security
Include
Source
source
Examples
Client
Mail
icon1.ico
icon2.ico
MailClientS.suo
test.dsp
test.dsw
Ultimate Toolbox
include
source
lib
Build DLLs
Build Libs
/*************************************************************************
				Class Implementation : CUGButtonType
**************************************************************************
	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 "UGCTbutn.h"

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

//toggle button not currently implemented
#define  UGCT_BUTTONTOGGLE	32

/***************************************************
CUGButtonType - Contstructor
	Initialize member variables
****************************************************/
CUGButtonType::CUGButtonType(){
	
	m_btnDown		= FALSE;
	m_mode			= -1;
	m_btnDownCol	= -1;
	m_btnDownRow	= -1;

	m_canOverLap = FALSE;
}

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

}

/***************************************************
OnDClicked - overloaded CUGCellType::OnDClicked
	Calls the OnLClicked function, allowing this
	celltype to respond to double clicks the same
	way it responds to single left clicks

    **See CUGCellType::OnDClicked for more details
	about this function
****************************************************/
BOOL CUGButtonType::OnDClicked(int col,long row,RECT *rect,POINT *point){
	return OnLClicked(col,row,1,rect,point);
}

/***************************************************
OnLClicked - overloaded CUGCellType::OnLClicked

  	When the mouse button is depressed, the	button 
	down variables are set.
	When the mouse button is released and the mouse was
	over the button then send a button click notification.
	Redraw the cell based on the state of the mouse
	button.

    **See CUGCellType::OnLClicked for more details
	about this function

Return 
	TRUE - since the mouse click was handled here
****************************************************/
BOOL CUGButtonType::OnLClicked(int col,long row,int updn,RECT *rect,POINT *point){

	UNREFERENCED_PARAMETER(col);
	UNREFERENCED_PARAMETER(point);

	if(updn){
		if(OnCellTypeNotify(m_ID,col,row,UGCT_BUTTONDOWN,0) != TRUE){
			m_btnDown = FALSE;
		}
		m_btnDown		= TRUE;
		m_btnDownCol	= col;
		m_btnDownRow	= row;
		CopyRect(&m_btnDownRect,rect);
	}
	else{
		
		OnCellTypeNotify(m_ID,col,row,UGCT_BUTTONUP,0);
		if(m_mode != UGCT_BUTTONTOGGLE){
			if(m_btnDownCol	== col && m_btnDownRow == row && m_btnDown == TRUE){
				OnCellTypeNotify(m_ID,col,row,UGCT_BUTTONCLICK,0);
			}
		}
		m_btnDown = FALSE;
	}
	
	m_ctrl->RedrawCell(col,row);

	return TRUE;
}

/***************************************************
OnMouseMove - overloaded CUGCellType::OnMouseMove
	If the mouse button is not depressed, then this 
	function just returns without further action.
	If the mouse button is depressed, then this function
	will check to see if it is over button or not. If it 
	is then, draw the button in a recessed state. If not
	then, draw the button in its default raised state.

    **See CUGCellType::OnMouseMove for more details
	about this function

Return
	TRUE - if the notification was processed
	FALSE - if the notification was not processed
****************************************************/
BOOL CUGButtonType::OnMouseMove(int col,long row,POINT *point,UINT flags){

	UNREFERENCED_PARAMETER(col);
	UNREFERENCED_PARAMETER(row);
	UNREFERENCED_PARAMETER(point);

	//return if the button is up
	if((flags&MK_LBUTTON) == FALSE)
		return FALSE;

	if(point->x >= m_btnDownRect.left && point->x <= m_btnDownRect.right){
		if(point->y >= m_btnDownRect.top && point->y <= m_btnDownRect.bottom){
			if(m_btnDown == FALSE){
				m_btnDown = TRUE;
				m_ctrl->RedrawCell(m_btnDownCol,m_btnDownRow);
			}
			return TRUE;
		}
	}

	if(m_btnDown){
		m_btnDown = FALSE;
		m_ctrl->RedrawCell(m_btnDownCol,m_btnDownRow);		
	}
	return FALSE;
}

/***************************************************
OnKeyDown - overloaded CUGCellType::OnKeyDown
	If the enter (return) key was pressed then this
	function will send a button click notification. 
	Otherwise it will just return.

    **See CUGCellType::OnKeyDown for more details
	about this function

Return
	TRUE - if the notification was processed
	FALSE - if the notification was not processed
****************************************************/
BOOL CUGButtonType::OnKeyDown(int col,long row,UINT *vcKey){

	UNREFERENCED_PARAMETER(col);
	UNREFERENCED_PARAMETER(row);

	if(*vcKey == VK_RETURN){
		OnCellTypeNotify(m_ID,m_ctrl->m_GI->m_currentCol,
			m_ctrl->m_GI->m_currentRow,UGCT_BUTTONCLICK,0);
		return TRUE;
	}

	return FALSE;
}

/***************************************************
OnKillFocus - overloaded CUGCellType::OnKillFocus
	Upon the lose of focus the button state is reset
	to its default unpressed state.

    **See CUGCellType::OnKillFocus for more details
	about this function

Return
	none
****************************************************/
void CUGButtonType::OnKillFocus(int col,long row,CUGCell *cell){
	
	CUGCellType::OnKillFocus(col,row,cell);

	m_btnDown		= FALSE;
}

/***************************************************
OnDraw - overloaded CUGCellType::OnDraw
	Draws the push button in its current state,
	pressed or unpressed.
	The drawing of text is performed using the 
	CUGCellType's DrawText function, therefore it
	has all of the same text capabilities as the
	default celltype.

    **See CUGCellType::OnDraw for more details
	about this function
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 CUGButtonType::OnDraw(CDC *dc,RECT *rect,int col,long row,
						   CUGCell *cell,int selected,int current)
{
	if (!m_drawThemesSet)
		m_useThemes = cell->UseThemes();
	
	UGXPThemeState state = UGXPThemes::GetState(selected>0, current>0);

	if (m_btnDown && current)
	{
		state = ThemeStatePressed;
	}

	RECT rectout;

	if (m_useThemes && UGXPThemes::DrawBackground(NULL, *dc, XPCellTypeButton, state, rect, NULL))
	{
		UGXPThemes::DrawEdge(NULL, *dc, XPCellTypeButton, state, rect, 0, 0, &rectout);
		cell->SetXPStyle(XPCellTypeButton);
		DrawText(dc,rect,rect->right - rectout.right ,col,row,cell,selected,current);
	}
	else
	{
		//draw the button
		if(m_btnDown && current)
                {
			cell->SetBorder(UG_BDR_RECESSED);
			DrawBorder(dc,rect,&rectout,cell);
		}
		else
                {
			cell->SetBorder(UG_BDR_RAISED);
			DrawBorder(dc,rect,&rectout,cell);
		}
	
	//draw the text in using the default drawing routine
		DrawText(dc,&rectout,0,col,row,cell,selected,current);
	}

	if(cell->IsPropertySet(UGCELL_CELLTYPEEX_SET) && current)
	{
		if(cell->GetCellTypeEx()&UGCT_BUTTONNOFOCUS)
		{
			m_ctrl->TempDisableFocusRect();
		}
	}
}

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)

Share

About the Author

The Ultimate Toolbox
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.
Group type: Organisation

435 members


You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170217.1 | Last Updated 13 Feb 2013
Article Copyright 2008 by The Ultimate Toolbox
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid