Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

The Ultimate Toolbox - Updates and User Contributions

, 12 Feb 2013
Updates and User Contributions for the Ultimate Toolbox Libraries
OutlookDemoUpdate.zip
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
UltimateGrid72_Src_Update01.zip
CellTypes
Include
Source
UltimateGrid72_Src_Update02.zip
DataSources
ODBC
OleDB
EditControls
UltimateGrid72_Src_Update03.zip
UltimateGrid72_Src_Update04.zip
UltimateGrid73_src.zip
BuildDLL
Build DLL.dsp
Build DLL.dsw
res
BuildLib
ugmfclib.dsp
ugmfclib.dsw
Lib
Skel
UltimateTCP-IP42_Src_Update01.zip
Ultimate TCP-IP
Include
Security
Include
Source
source
UltimateTCP-IP42_Src_Update02.zip
Examples
Client
Mail
icon1.ico
icon2.ico
MailClientS.suo
test.dsp
test.dsw
UltimateTCP-IP42_Src_Update03.zip
ultimatetoolbox93_src_update01.zip
Ultimate Toolbox
include
source
UltimateToolbox93_Src_Update02.zip
lib
Build DLLs
Build Libs
UltimateToolbox93_Src_Update03.zip
UltimateToolbox93_Src_Update04.zip
UltimateToolbox93_Src_Update05.zip
/*************************************************************************
				Class Implementation : CUGLstBox
**************************************************************************
	Source file : ugLstBox.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"

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

/***************************************************
	Standard construction/desrtuction
***************************************************/
CUGLstBox::CUGLstBox()
{
	m_HasFocus	= FALSE;
	m_col		= NULL;
	m_row		= NULL;
	m_selected	= FALSE;

	m_ctrl		= NULL;
}

CUGLstBox::~CUGLstBox()
{
}

BEGIN_MESSAGE_MAP(CUGLstBox, CListBox)
	//{{AFX_MSG_MAP(CUGLstBox)
	ON_WM_KILLFOCUS()
	ON_WM_MOUSEACTIVATE()
	ON_WM_LBUTTONUP()
	ON_WM_KEYDOWN()
	ON_WM_SETFOCUS()
	ON_WM_GETDLGCODE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/***************************************************
OnSetFocus
	event is fired when the list box is gaining focus.
	The drop list cell type uses this event handler
	to setup mouse capture.
Params:
	pOldWnd	- pointer to window that has lost focus
Return:
	<none>
****************************************************/
void CUGLstBox::OnSetFocus(CWnd* pOldWnd) 
{
	CListBox::OnSetFocus(pOldWnd);

	ReleaseCapture();
	SetCapture();

	m_HasFocus = TRUE;
	m_selected = FALSE;
}

/***************************************************
OnKillFocus
	event is called when the list control is loosing
	the focus.  The drop list cell type uses this event
	to clear the mouse capture, and to hide the list
	control.
Params:
	pNewWnd	- pointer to the window that is gaining
			  the focus.
Return:
	<none>
****************************************************/
void CUGLstBox::OnKillFocus(CWnd* pNewWnd) 
{
	ReleaseCapture();

	CListBox::OnKillFocus(pNewWnd);

	DestroyWindow();
	
	m_HasFocus = FALSE;
	if(m_selected == FALSE){
		*m_col = -2;
		*m_row = -2;
	}
	m_selected = FALSE;
	m_ctrl->m_CUGGrid->SendMessage(WM_PAINT,0,0);
}

/***************************************************
OnMouseActivate
	The framework calls this member function when the
	cursor is in an inactive window and the user presses
	a mouse button. 
Params:
	The drop list cell type does not use any of the
	parameters passed into this event handler.  To
	get more information on the meaning of these
	parameters please refer to the MSDN.
Return:
	MA_ACTIVATE to allow the inactive window to activate.
****************************************************/
int CUGLstBox::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message) 
{
	UNREFERENCED_PARAMETER(pDesktopWnd);
	UNREFERENCED_PARAMETER(nHitTest);
	UNREFERENCED_PARAMETER(message);

	return MA_ACTIVATE;	
}

/***************************************************
OnLButtonUp
	event handler is called when user clicks left mouse
	button in the drop list.  The drop list cell type
	uses this event as a signal that the user has
	selected an item.
Params:
	The drop list cell type does not use any of the
	parameters passed into this event handler.  To
	get more information on the meaning of these
	parameters please refer to the MSDN.
Return:
	<none>
****************************************************/
void CUGLstBox::OnLButtonUp(UINT nFlags, CPoint point) 
{
	UNREFERENCED_PARAMETER(nFlags);
	UNREFERENCED_PARAMETER(point);

	ReleaseCapture();

	//update the string in the current cell if the list box had a selected item
	if(GetCurSel() != LB_ERR)
	{
		Select();		
	}
}

/***************************************************
OnKeyDown
	event is called when user presses a key when the drop
	list window is active.  The drop list cell type checks
	the key pressed for ESC or ENTER keys.
Params:
	nChar	- if the user hits the ESC key than the drop
			  list will be hidden and selection cancelled.
			  If the user hits ENTER key than the item
			  currently selected will be set to the cell.
Return:
	<none>
****************************************************/
void CUGLstBox::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if(nChar == VK_ESCAPE)
		DestroyWindow();

	if(nChar == VK_RETURN)
	{
		if(GetCurSel() != LB_ERR)
		{
			Select();
		}
		else
		{
			m_HasFocus = FALSE;
			DestroyWindow();
		}
	}
	
	CListBox::OnKeyDown(nChar, nRepCnt, nFlags);
}

/***************************************************
Select
	this internal function is used by the drop list
	cell type to set the item selected by the user
	to the cell.  It will also fire the OnCellTypeNotify
	notification to inform CUGCtrl derived class 
	that user made his selection.
Params:
	<none>
Return:
	<none>
****************************************************/
void CUGLstBox::Select()
{
	CUGCell cell;
	CString string;
	int col = *m_col; //m_ctrl->GetCurrentCol();
	long row = *m_row; //m_ctrl->GetCurrentRow();

	m_selected = TRUE;

	// make sure that the cell is not read only before making
	// user's selection permanent
	m_ctrl->GetCellIndirect(col,row,&cell);
	if ( cell.GetReadOnly() == FALSE )
	{
		//get the string selected
		GetText(GetCurSel(),string);

		// send notification with index of the selected item
		m_cellType->OnCellTypeNotify(	m_cellTypeId, col, row,
									UGCT_DROPLISTSELECTEX, (long)GetCurSel());

		//notify the user of the selection
		if(m_cellType->OnCellTypeNotify(m_cellTypeId,col,row, //set the id
			UGCT_DROPLISTSELECT,(LONG_PTR)&string) != FALSE){

			m_ctrl->GetCellIndirect(col,row,&cell);
			cell.SetText(string);
			m_ctrl->SetCell(col,row,&cell);

			// notify the user that the selection was set
			m_cellType->OnCellTypeNotify(m_cellTypeId,col,row,UGCT_DROPLISTPOSTSELECT,(LONG_PTR)&string);

			m_ctrl->RedrawCell(col,row);
		}
	}
	
	m_HasFocus = FALSE;
	if(m_col != NULL)
		*m_col = -1;
	if(m_row != NULL)
		*m_row = -1;

	m_ctrl->m_CUGGrid->SetFocus();
}

/***************************************************
OnGetDlgCode
	is required when the grid is on the dialog.
Params:
	<none>
Return:
	<none>
****************************************************/
UINT CUGLstBox::OnGetDlgCode() 
{
	return CListBox::OnGetDlgCode() | DLGC_WANTALLKEYS | DLGC_WANTARROWS;
}

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

387 members


| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 13 Feb 2013
Article Copyright 2008 by The Ultimate Toolbox
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid