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

The Ultimate Toolbox - Updates and User Contributions

, 12 Feb 2013 CPOL
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 : CUGCTMailSort
**************************************************************************
	Source file : UGCTMail.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 "UGCTMailSort.h"

#include <sstream>

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

namespace
{
	const int sortByRightMargin = 40;
}
/***************************************************
CUGCTMail - Constructor
	Initialize member variables
****************************************************/
CUGCTMailSort::CUGCTMailSort() : m_whitePen(PS_SOLID, 1, RGB(255, 255, 255)), 
								 m_arrowPen(PS_SOLID, 1, RGB(172, 168, 153))
{
	m_normalFont.CreateFont(14, 0, 0, 0, 500, 0, 0, 0, 0, 0, 0, 0, 0, _T("Arial"));
	m_sortAscending = false;
	m_sortOrder = sortByDate;
}

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

/***************************************************
OnDraw
	The Ultimate Grid calls this visual function
	every time it is drawing a cell.  It is up to
	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 CUGCTMailSort::OnDraw(CDC *dc,RECT *rect,int col,long row,CUGCell *cell,int selected,int current)
{
	if (!m_drawThemesSet)
		m_useThemes = cell->UseThemes();

	// Draw background
	dc->FillSolidRect(rect, RGB(236, 233, 216));
	int oldBkMode = dc->SetBkMode(TRANSPARENT);

	RECT rcLine = *rect;
	rcLine.top = rcLine.bottom - 3;

	dc->FillSolidRect(&rcLine, RGB(220, 216, 200));

	rcLine.top += 1;
	dc->FillSolidRect(&rcLine, RGB(210, 207, 190));

	rcLine.top += 1;
	rcLine.bottom += 1;
	dc->FillSolidRect(&rcLine, RGB(197, 194, 178));

	CFont * pOldFont = dc->SelectObject(&m_normalFont);

	CString output;

	switch(m_sortOrder)
	{
	case sortByAttachments:
		output = "Arranged By: Attachments";
		break;
	case sortByCategories:
		output = "Arranged By: Categories";
		break;
	case sortByConversation:
		output = "Arranged By: Conversation";
		break;
	case sortByDate:
		output = "Arranged By: Date";
		break;
	case sortByFlag:
		output = "Arranged By: Flag";
		break;
	case sortByFrom:
		output = "Arranged By: From";
		break;
	case sortByImportance:
		output = "Arranged By: Importance";
		break;
	case sortBySize:
		output = "Arranged By: Size";
		break;
	case sortBySubject:
		output = "Arranged By: Subject";
		break;
	case sortByTo:
		output = "Arranged By: To";
		break;
	case sortByType:
		output = "Arranged By: Type";
		break;
	}

	CSize szArrBy = dc->GetTextExtent(output);

	CString sortOrder;

	switch (m_sortOrder)
	{
	case sortByFlag:
		sortOrder =  ((m_sortAscending) ? "Unflagged on top" : "Red on top");
		break;
	case sortByDate:
		sortOrder =  ((m_sortAscending) ? "Oldest on top" : "Newest on top");
		break;
	case sortBySize:
		sortOrder =  ((m_sortAscending) ? "Smallest on top" : "Largest on top");
		break;
	case sortByAttachments:
		sortOrder =  ((m_sortAscending) ? "None on top" : "With on top");
		break;
	default:
		sortOrder =  ((m_sortAscending) ? "Z on top" : "A on top");
		break;
	}

	CSize szSortText = dc->GetTextExtent(sortOrder);

	int divider = rect->right - (szSortText.cx + sortByRightMargin);

	if (divider < szArrBy.cx + 10) divider = szArrBy.cx + 10;
	if (divider > rect->right - rect->left - 15) divider = rect->right - rect->left - 15;	
		

	// Now we have all the info we need to draw this string
	RECT rcLeftText = *rect;
	rcLeftText.right = rect->left + divider;
	rcLeftText.top += 2;
	rcLeftText.left += 2;
	dc->DrawText(output, &rcLeftText, DT_END_ELLIPSIS);

	rcLine.left = divider;
	rcLine.top = rect->top + 2;
	rcLine.right = divider + 1;
	rcLine.bottom = rect->bottom - 4;
	dc->FillSolidRect(&rcLine, RGB(172, 168, 153));

	rcLine.left += 1;
	rcLine.right += 1;
	dc->FillSolidRect(&rcLine, RGB(255, 255, 255));

	rcLine.left += 3;
	rcLine.right =  rect->right - 14; //szSortText.cx;

	rcLine.top = rect->top + 2;

	dc->DrawText(sortOrder, &rcLine, DT_END_ELLIPSIS);

	// Draw arrow

	CPen * pOldPen = dc->SelectObject(&m_whitePen);

	if (m_sortAscending)
	{
		dc->MoveTo(rect->right - 11, rect->top + 12);
		dc->LineTo(rect->right - 4, rect->top + 12);
		dc->LineTo(rect->right - 4, rect->top + 11);
		dc->LineTo(rect->right - 5, rect->top + 11);
		dc->LineTo(rect->right - 5, rect->top + 9);
		dc->LineTo(rect->right - 6, rect->top + 9);
		dc->LineTo(rect->right - 6, rect->top + 7);
		dc->LineTo(rect->right - 7, rect->top + 7);
		dc->LineTo(rect->right - 7, rect->top + 5);
		dc->SelectObject(&m_arrowPen);
		dc->MoveTo(rect->right - 8, rect->top + 6);
		dc->LineTo(rect->right - 8, rect->top + 7);
		dc->LineTo(rect->right - 9, rect->top + 7);
		dc->LineTo(rect->right - 9, rect->top + 9);
		dc->LineTo(rect->right - 10, rect->top + 9);
		dc->LineTo(rect->right - 10, rect->top + 11);
		dc->LineTo(rect->right - 11, rect->top + 11);
		dc->LineTo(rect->right - 11, rect->top + 13);
	}
	else
	{
		dc->MoveTo(rect->right - 5, rect->top + 7);
		dc->LineTo(rect->right - 6, rect->top + 7);
		dc->LineTo(rect->right - 6, rect->top + 9);
		dc->LineTo(rect->right - 7, rect->top + 9);
		dc->LineTo(rect->right - 7, rect->top + 11);
		dc->LineTo(rect->right - 8, rect->top + 11);
		dc->LineTo(rect->right - 8, rect->top + 12);
		dc->LineTo(rect->right - 8, rect->top + 13);
		dc->SelectObject(&m_arrowPen);
		dc->MoveTo(rect->right - 9, rect->top + 12);
		dc->LineTo(rect->right - 9, rect->top + 11);
		dc->LineTo(rect->right - 10, rect->top + 11);
		dc->LineTo(rect->right - 10, rect->top + 9);
		dc->LineTo(rect->right - 11, rect->top + 9);
		dc->LineTo(rect->right - 11, rect->top + 7);
		dc->LineTo(rect->right - 12, rect->top + 7);
		dc->LineTo(rect->right - 12, rect->top + 6);
		dc->LineTo(rect->right - 4, rect->top + 6);
	}


	dc->SelectObject(pOldPen);
	dc->SelectObject(pOldFont);
	dc->SetBkMode(oldBkMode);
}

/***************************************************
OnRClicked - is called whenever a cell of this type
is right clicked.  In this case, we use the built in
notification to send a message to our grid-derived 
class, letting it know if we clicked over the right
most icon, or on the rest of the cell, this then
controls which context menu is shown.
****************************************************/

BOOL CUGCTMailSort::OnRClicked(int col,long row,int updn,RECT *rect,POINT *point)
{
	m_ctrl->OnCellTypeNotify(m_ID, col, row, 0, (LONG_PTR)point);

	return TRUE;
}

/***************************************************
OnLClicked - is called whenever a cell of this type
is left clicked.  We respond to this event by working
out if the cell has been clicked over the right most 
icon, and if so, we change the flag state.
****************************************************/
BOOL CUGCTMailSort::OnLClicked(int col,long row,int updn,RECT *rect,POINT *point)
{
	BOOL retval = FALSE;

	if(updn)
	{
		CDC dc;
		dc.CreateCompatibleDC(NULL);
		CFont * pOldFont = dc.SelectObject(&m_normalFont);

		CString sortOrder((m_sortAscending) ? "Oldest on top" : "Newest on top");
		CSize sz = dc.GetTextExtent(sortOrder);
		dc.SelectObject(pOldFont);

		if (point->x >= rect->right - (sz.cx + sortByRightMargin))
		{
			// We clicked on the sort icon
			m_sortAscending = !m_sortAscending;
			m_ctrl->OnCellTypeNotify(m_ID, col, row, 1, (LONG_PTR)point);
			m_ctrl->Invalidate();
			retval = TRUE;
		}
		else
		{
			m_ctrl->OnCellTypeNotify(m_ID, col, row, 0, (LONG_PTR)point);
		}
	}
	
	return retval;
}

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

394 members


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