Click here to Skip to main content
11,495,331 members (66,782 online)
Click here to Skip to main content
Add your own
alternative version

Resource ID Organiser Add-In for Visual C++ 5.0/6.0/.NET

, 10 Jan 2005 CPOL 351K 10K 199
An application/add-in to organise and renumber resource symbol IDs
resorg103.zip
ResOrg103.exe
resorg104.zip
ResOrg104.exe
resorgaddinsetup.zip
ResOrgAddInSetup.exe
resorgaddin_executables.zip
ResOrg.exe
BXFileDialog.dll
CJ609Lib.dll
NGLib103.dll
ResOrgAddIn.dll
ResOrgCore.dll
ResOrg.cnt
resorg.fts
ResOrg.hlp
resorgnetaddinsetup.zip
ResOrgNETAddInSetup.msi
resorgnetaddin_executables.zip
ResOrgNETAddInToolWindows.ocx
ResOrgNET.exe
CJ609LibVc7.dll
NGLib103Vc7.dll
ResOrgNETAddIn.dll
ResOrgNETCore.dll
ResOrg.cnt
resorg.fts
ResOrg.hlp
ReadMe.rtf
Licence.rtf
resorgnet_executables.zip
ResOrgNET_executables
CJ609LibVc7.dll
NGLib103Vc7.dll
QHTMLight.dll
ResOrg.cnt
resorg.fts
ResOrg.hlp
ResOrgNETAddIn.dll
ResOrgNETAddInToolWindows.ocx
ResOrgNETCore.dll
resorg_demo.zip
ResOrg103.exe
resorg_executables.zip
ResOrgAddIn.dll
BXFileDialog.dll
CJ609Lib.dll
ResOrg.exe
ResOrg.cnt
resorg.fts
ResOrg.hlp
ResOrgCore.dll
NGLib103.dll
resorg_src.zip
BXFileDialog
BXFileDialog.dsp
Lib
Release
Res
bitmap2.bmp
FileOpen.bmp
filesave.bmp
CJLibrary
CJLibrary
CJLibrary.def
CJLibrary.dsp
CJLibrary.dsw
CJLibrarydep.jpg
CJLibraryStatic.dsp
Debug_Unicode
Release
Release_Unicode
res
Include
res
btn_arro.bmp
btn_explorer.bmp
button_images.bmp
cj_logo.bmp
dragging.cur
handcur.cur
headerba.bmp
hsplitba.cur
icr_hand.cur
nodraggi.cur
PushPin.bmp
Toolbar.bmp
vsplitba.cur
Lib
default.doxygen
NGLibrary
Bin
NGLibrary.def
NGLibrary.dsp
NGLibrary.dsw
Release
Res
Drives.bmp
Release
ResOrg.dsw
ResOrgAddIn
Release
Res
HtmlDoc.ico
ResOrg.ico
ResOrgDoc.ico
TBarLrge.bmp
TBarMedm.bmp
Toolbar.bmp
WorkspaceTabs.bmp
ResOrgAddIn.def
ResOrgAddIn.dsp
ResOrgAddIn.odl
ResOrgAddIn_Res.hm
ResOrgApp
Lint
Release
Res
HtmlDoc.ico
MAINFRAM.BMP
ResOrg.ico
ResOrgDoc.ico
TBarLrge.bmp
TBarMedm.bmp
Toolbar.bmp
workspace.ico
WorkspaceTabs.bmp
ResOrgApp.dsp
ResOrgApp_Res.hm
ResOrgApp_Res.resorg
ResOrgCore
Lint
Release
Res
Anna.bmp
BuildOptions.ico
ComCtl Version Prompt.rtf
File Reload Warning Ex.rtf
File Reload Warning.rtf
Global Next Symbol Value Warning Prompt.rtf
information.ico
Invalid Symbol Name.rtf
Mailing List Prompt.rtf
Next Symbol Value Warning Prompt.rtf
project context menu.bmp
project.ico
RenumWiz Completion.rtf
Report.ico
ResOrg Logo.bmp
ResOrg Updated.rtf
ResOrg.ico
resource file.ico
riverblade_logo.bmp
solution.ico
Symbol Delete Warning.rtf
Symbol Name Warning.rtf
Symbol Rename Warning.rtf
SymbolFile.ico
Symbols Delete Warning.rtf
sym_binary.ico
sym_bitmap.ico
sym_command.ico
sym_control.ico
sym_dialog.ico
sym_icon.ico
sym_menu.ico
sym_prompt.ico
sym_resource.ico
sym_string.ico
Toolbar.bmp
VcAddIn.ico
VersionCheck.ico
warning.ico
WizardHeader256.bmp
WizardWatermark256.bmp
ResOrgCore.def
ResOrgCore.dsp
ResOrgCore_Res.hm
ResOrgCore_Res.resorg
Xml
ProblemSymbolReportHtml.xsl
SymbolsReportHtml.xsl
ResOrgNETAddIn
AddIn.def
Release
Res
AddIn.rgs
HtmlDoc.ico
ResOrg.ico
ResOrgDoc.ico
Toolbar.bmp
WorkspaceTabs.bmp
ResOrgNETAddInSetup
Banner.jpg
Intro screen.jpg
Licence.rtf
ReadMe.rtf
Release
ResOrg.ico
ResOrgNETAddInSetup.vdproj
ResOrgNETAddInToolWindows
Release
Res
Edit.ico
Properties.ico
Renumber.ico
ResOrgNETAddInToolWindows.ico
ResOrgNETAddInToolWindowsCtrl.bmp
ResOrgNETAddInToolWindows.def
SatelliteDll
Release
res
AboutBoxCmd.bmp
OpenResOrgCmd.bmp
OptionsCmd.bmp
ViewMainToolWinCmd.bmp
/************************************************************************
 *
 *                 Resource ID Organiser Core Library
 *
 * (c) Copyright 2000-2004 by Riverblade Limited (UK). All rights reserved.
 *
 ************************************************************************
 *                                                                       
 *  Description : CResOrgSymbolsListCtrl - list control class for a
 *                resource symbol file
 *                                                                       
 *  Target                                                               
 *  Environment : Windows 98/NT/2000/XP
 *
 *  NOTE:
 *
 *    This software is provided "as is". All title and copyrights in and
 *    to the software, including but not limited to any images, text etc.
 *    etc. incorporated into it, are the property of Anna-Jayne Metcalfe
 *    and Riverblade Limited, except where acknowledged otherwise.
 *
 *    Your may freely use this code in your own products, PROVIDED
 *    this notice is not removed or modified.
 *
 *    For support and updates please visit http://www.riverblade.co.uk/products/resorg
 *    or email support@riverblade.co.uk  
 *
 ************************************************************************
 *
 *   MODIFICATION HISTORY:
 *
 *           This is a controlled document. See project configuration
 *           control tool for latest version and full version history.
 *
 *    $Archive: /Projects/AddIns/ResOrg/ResOrgCore/ResOrgSymbolsListCtrl.cpp $
 *   $Revision: 18 $
 *       $Date: 13/12/04 3:56 $
 *     $Author: Anna $
 *
 *    $History: ResOrgSymbolsListCtrl.cpp $
 * 
 * *****************  Version 18  *****************
 * User: Anna         Date: 13/12/04   Time: 3:56
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * 1.  Modifications fo compatibility with dynamic splitters
 * 2.  Updated file banners
 * 
 * *****************  Version 17  *****************
 * User: Anna         Date: 11/07/04   Time: 16:16
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Added support for detection of out of range symbols
 * 
 * *****************  Version 16  *****************
 * User: Anna         Date: 15/04/03   Time: 20:37
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * 1.  Removed unnecessary file guards (#pragma once works well enough)
 * 2.  Updated file banners
 * 
 * *****************  Version 15  *****************
 * User: Anna         Date: 3/01/03    Time: 7:36
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Added an option to filter multi-file Symbols Displays by default
 * 
 * *****************  Version 14  *****************
 * User: Anna         Date: 2/01/03    Time: 23:54
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Added filtering to the Symbols Display
 * 
 * *****************  Version 13  *****************
 * User: Anna         Date: 2/01/03    Time: 0:07
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Guarded m_pResourceSymbolManager against NULL in
 * CResOrgSymbolsListCtrl::AddSymbols() [for compatibility with multi-file
 * conflict analysis]
 * 
 * *****************  Version 12  *****************
 * User: Anna         Date: 17/12/02   Time: 15:37
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * CResOrgSymbolsListCtrl::Initialise() now only subclasses the header
 * control if a WinXP theme is not active 
 * 
 * *****************  Version 11  *****************
 * User: Anna         Date: 25/11/02   Time: 15:14
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Changed website address in banner
 * 
 * *****************  Version 10  *****************
 * User: Anna         Date: 22/10/02   Time: 13:24
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Changed name/mail address (at last!)
 * 
 * *****************  Version 9  *****************
 * User: Andy         Date: 7/06/02    Time: 17:04
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Renamed the ResOrgUtils module to ResOrgCore. Updated file banners
 * accordingly
 * 
 * *****************  Version 8  *****************
 * User: Andy         Date: 27/05/02   Time: 14:50
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 * Knock on changes from CResourceSymbolBuffer (now
 * CResourceSymbolManager)
 * 
 * *****************  Version 7  *****************
 * User: Andy         Date: 12/28/01   Time: 4:34p
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 * Added a new override of CResOrgSymbolsListCtrl::AddSymbols()
 * 
 * *****************  Version 6  *****************
 * User: Andy         Date: 12/27/01   Time: 11:20p
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 * 1.  Added "Original ID" column
 * 2.  Added CResOrgSymbolsListCtrl::SetSymbolManager(),
 * UpdateAllSymbols() and GetSymbol()
 * 3.  Renamed CResOrgSymbolsListCtrl::LookupSelection() to GetSelection()
 * and added an overload which works with multiple selections
 * 
 * *****************  Version 5  *****************
 * User: Andy         Date: 2/04/01    Time: 17:39
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 * 1.  Fix a bug introduced in ResOrg 1.3.2: icons were not displaying
 * when the control was used as a child window of a view
 * 2.  Highlight symbols with name (as well as value) conflicts in bold
 * 
 * *****************  Version 4  *****************
 * User: Andy         Date: 27/03/01   Time: 15:23
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 * 1.  Made the "Status" column optional
 * 2.  Modifications to allow use in the "Symbol Conflicts" property page
 * 
 * *****************  Version 3  *****************
 * User: Andy         Date: 5/03/01    Time: 19:01
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 * CResOrgSymbolsListCtrl::SortList() now calls the base class to set the
 * sort image on the header control
 * 
 * *****************  Version 2  *****************
 * User: Andy         Date: 2/03/01    Time: 17:07
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 * Increased the width of the "Status" column
 * 
 * *****************  Version 1  *****************
 * User: Andy         Date: 17/02/01   Time: 6:47
 * Created in $/Projects/AddIns/ResOrg/ResOrgUtils
 * 
 * *****************  Version 3  *****************
 * User: Andy         Date: 29/11/00   Time: 18:38
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 *  Added file banners
 *
 * $Nokeywords: $
 *
 ************************************************************************/

#include "StdAfx.h"
#include "ResOrgCore_Priv.h"

#include "ResourceSymbol.h"
#include "ResourceSymbolManager.h"

#include "ResOrgSymbolsListCtrl.h"


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



// Definitions for List Control column indices and titles
enum
{
	UNKNOWN_COLUMN = -1,
	NAME_COLUMN = 0,
	TYPE_COLUMN,
	ID_COLUMN,
	ORIGINAL_ID_COLUMN,
	FILE_COLUMN,
	STATUS_COLUMN
};



static DATA_TYPE eColumnType[] = 
{
	DT_STRING,		// Name
	DT_STRING,		// Type
	DT_DEC,			// ID
	DT_DEC,			// Original ID
	DT_STRING,		// File
	DT_STRING		// Status
};


const UINT WM_SETSCROLLINFO	= ::RegisterWindowMessage( _T("SetScrollInfo") );



static bool IsViewContainedInSplitterWindow(CWnd* pView)
{
	CWnd* pViewParent = pView->GetParent();
	if (NULL != pViewParent)
	{
		if (pViewParent->IsKindOf(RUNTIME_CLASS(CSplitterWnd) ) )
		{
			return true;
		}
	}
	return false;
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgSymbolsListCtrl class

/******************************************************************************
 *	Message Map implementation
 *
 ******************************************************************************/

BEGIN_MESSAGE_MAP(CResOrgSymbolsListCtrl, CResOrgSymbolsListCtrl_BASE)

	ON_WM_CREATE()
	ON_WM_NCCALCSIZE()
	ON_WM_KEYDOWN()
	ON_NOTIFY_REFLECT(	NM_CUSTOMDRAW,							OnCustomDraw)

END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CResOrgSymbolsListCtrl construction/destruction

CResOrgSymbolsListCtrl::CResOrgSymbolsListCtrl(void)
{
	m_nSortColumn				= ID_COLUMN;
	m_bSortAscending			= true;
	m_pResourceSymbolManager	= NULL;
	m_bShowStatusColumn			= true;
	m_bShowProblemSymbolsOnly	= false;
}

CResOrgSymbolsListCtrl::~CResOrgSymbolsListCtrl(void)
{
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgSymbolsListCtrl overrides

void CResOrgSymbolsListCtrl::PreSubclassWindow(void)
{
	if (m_ctrlImages.GetSafeHandle() == NULL)
	{
		m_ctrlImages.Create(SMALL_ICON_CX,
							SMALL_ICON_CY,						// Small icon
							ILC_COLOR | ILC_MASK,				// Colour depth
							0,									// Initial images
							1);									// Growby

		SetImageList(&m_ctrlImages, LVSIL_SMALL);
	}

	CResOrgSymbolsListCtrl_BASE::PreSubclassWindow();
}


/******************************************************************************
 *	Sort the contents of the control by the specified column
 *
 ******************************************************************************/

bool CResOrgSymbolsListCtrl::SortList(int nColumn, bool bAscending)
{
	CResOrgSymbolsListCtrl_BASE::SortList(nColumn, bAscending);

	m_nSortColumn		= nColumn;
	m_bSortAscending	= bAscending;

	// Re-sort contents if sorted before
	if (m_nSortColumn >= 0)
	{
		CResOrgSymbolsListCtrl_BASE::SortList(nColumn, bAscending);

		CCJSortClass sorter(this, nColumn);
		sorter.Sort(bAscending, eColumnType[nColumn]);

		return true;
	}
	return false;
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgSymbolsListCtrl implementation

/// Initialise the list control before display.
///
void CResOrgSymbolsListCtrl::Initialise(bool bFlatHeader /*= false*/,
										bool bShowStatusColumn /*= true*/)
{
	m_bShowStatusColumn = bShowStatusColumn;

	// Create the columns in the the List Control
	//
	// For each row the properties specified are:
	//
	//		1.	SubItem field number (0 based)
	//		2.	Text
	//		3.	Justification
	//		4.	Initial width in pixels, size to content (LVSCW_AUTOSIZE) or
	//			size to header (LVSCW_AUTOSIZE_USEHEADER)
	//
	// Change list control style to have:
	//
	//	1.	Flat header (requires CJListCtrl)
	//	2.	Full row selection (requires ComCtl32.dll v4.71)
	//
	if (bFlatHeader)
	{
		CCJThemeHelper theme;
		if (!theme.IsAppThemed() )
		{
			SubclassHeader();
		}
	}

	SetExtendedStyle(GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);

	VERIFY (-1 != InsertColumn(NAME_COLUMN,			_T("Name"),			LVCFMT_LEFT, 200,	0) );
	VERIFY (-1 != InsertColumn(TYPE_COLUMN,			_T("Type"),			LVCFMT_LEFT, 100,	0) );
	VERIFY (-1 != InsertColumn(ID_COLUMN,			_T("Value"),		LVCFMT_LEFT, 80,	1));
	VERIFY (-1 != InsertColumn(ORIGINAL_ID_COLUMN,	_T("Orig. Value"),	LVCFMT_LEFT, 80,	1));
	VERIFY (-1 != InsertColumn(FILE_COLUMN,			_T("File"),			LVCFMT_LEFT, 150,	1));
	
	if (m_bShowStatusColumn)
	{
		VERIFY (-1 != InsertColumn(STATUS_COLUMN,	_T("Status"),	LVCFMT_LEFT, 300,	1));
	}
}


bool CResOrgSymbolsListCtrl::SetSymbolManager(CResourceSymbolManager* pResourceSymbolManager)
{
	if (m_pResourceSymbolManager != pResourceSymbolManager)
	{
		if (::IsWindow(m_hWnd) )
		{
			DeleteAllItems();
		}
		m_pResourceSymbolManager = pResourceSymbolManager;
	}
	return (NULL != m_pResourceSymbolManager);
}


bool CResOrgSymbolsListCtrl::ShowProblemSymbolsOnly(bool bShow)
{
	if (bShow != m_bShowProblemSymbolsOnly)
	{
		m_bShowProblemSymbolsOnly = bShow;

		if (NULL != m_pResourceSymbolManager)
		{
			AddSymbols(m_pResourceSymbolManager);
		}

		return true;
	}
	return false;
}


bool CResOrgSymbolsListCtrl::IsVisible(CResourceSymbol* pSymbol) const
{
	ASSERT(NULL != pSymbol);
	if (NULL == m_pResourceSymbolManager)
	{
		ASSERT(FALSE);
		return false;
	}

	bool bShow = false;

	if (NULL != pSymbol)
	{
		if (m_bShowProblemSymbolsOnly)
		{
			if (pSymbol->HasConflicts() || m_pResourceSymbolManager->IsOutOfRange(pSymbol) )
			{
				bShow = true;
			}
		}
		else
		{
			bShow = true;
		}
	}
	return bShow;
}


/// Fill the list control with data
///
void CResOrgSymbolsListCtrl::AddSymbols(CResourceSymbolManager* pResourceSymbolManager)
{
	SetSymbolManager(pResourceSymbolManager);

	SetRedraw(FALSE);

	DeleteAllItems();

	if (NULL != m_pResourceSymbolManager)
	{
		if (m_pResourceSymbolManager->GetSymbolCount() > 0)
		{
			POSITION pos = m_pResourceSymbolManager->GetFirstSymbolPosition();
			while (NULL != pos)
			{
				CResourceSymbol* pSymbol = m_pResourceSymbolManager->GetNextSymbol(pos);

				if ( (NULL != pSymbol) && IsVisible(pSymbol) )
				{
					AddSymbol(pSymbol);
				}
			}
			SortList(m_nSortColumn, m_bSortAscending);

			//AutoSizeColumn();
		}
	}
	SetRedraw(TRUE);

	Invalidate();
	UpdateWindow();
	RedrawWindow();
}


void CResOrgSymbolsListCtrl::AddSymbols(const CResourceSymbolList& listSymbols)
{
	ASSERT(NULL != m_pResourceSymbolManager);

	SetRedraw(FALSE);

	DeleteAllItems();

	if (listSymbols.GetCount() > 0)
	{
		POSITION pos = listSymbols.GetHeadPosition();
		while (pos != NULL)
		{
			CResourceSymbol* pSymbol = listSymbols.GetNext(pos);

			if ( (NULL != pSymbol) && IsVisible(pSymbol) )
			{
				AddSymbol(pSymbol);
			}
		}
		SortList(m_nSortColumn, m_bSortAscending);
	}
	SetRedraw(TRUE);

	Invalidate();
	UpdateWindow();
	RedrawWindow();
}


bool CResOrgSymbolsListCtrl::AddSymbol(CResourceSymbol* pSymbol)
{
	int nItem = FindSymbol(pSymbol);
	if (nItem < 0)
	{
		int nItem = InsertItem(	GetItemCount(),
								_T(""));

		if (nItem >= 0)
		{
			SetItemData(nItem, (LPARAM)pSymbol);
			UpdateSymbol(pSymbol);
			
			return true;
		}
	}
	return false;
}


bool CResOrgSymbolsListCtrl::UpdateSymbol(CResourceSymbol* pSymbol)
{
	int nItem = FindSymbol(pSymbol);
	if (nItem >= 0)
	{
		CString sLabel = pSymbol->GetName();
		if (pSymbol->IsModified())
		{
			sLabel += _T(" *");
		}

		int nIconID = SymbolTypes.GetIconID( pSymbol->GetType() );

		LVITEM item;
		item.iItem		= nItem;
		item.iSubItem	= NAME_COLUMN;
		item.mask		= LVIF_IMAGE;
		item.iImage		= m_ctrlImages.AddIcon(nIconID);
		SetItem(&item);

		SetItemText(nItem, NAME_COLUMN,			sLabel);
		SetItemText(nItem, TYPE_COLUMN,			pSymbol->GetTypeName() );
		SetItemText(nItem, ID_COLUMN,			::UIntToStr(pSymbol->GetValue()) );

		CString sOrigValue;
		if (pSymbol->IsModified() && pSymbol->GetValue() != pSymbol->GetOriginalValue())
		{
			sOrigValue = ::UIntToStr(pSymbol->GetOriginalValue() );
		}	
		SetItemText(nItem, ORIGINAL_ID_COLUMN,	sOrigValue);

		CNGSplitPath split(pSymbol->GetFileName() );
		SetItemText(nItem, FILE_COLUMN,			split.GetFileName() + split.GetExtension() );

		if (m_bShowStatusColumn)
		{
			SetItemText(nItem, STATUS_COLUMN,	m_pResourceSymbolManager->GetDisplayedStatus(pSymbol) );
		}
	}
	return (nItem != -1);
}


bool CResOrgSymbolsListCtrl::UpdateAllSymbols(void)
{
	SetRedraw(FALSE);

	for (int nItem = 0; nItem < GetItemCount(); nItem++)
	{
		CResourceSymbol* pSymbol = GetSymbol(nItem);

		if (NULL != pSymbol)
		{
			UpdateSymbol(pSymbol);
		}
	}
	SetRedraw(TRUE);

	return (GetItemCount() > 0);
}


bool CResOrgSymbolsListCtrl::RemoveSymbol(CResourceSymbol* pSymbol)
{
	int nItem = FindSymbol(pSymbol);
	if (nItem >= 0)
	{
		DeleteItem(nItem);
		
		return true;
	}
	return false;
}


void CResOrgSymbolsListCtrl::RemoveAllSymbols(void)
{
	DeleteAllItems();
}


bool CResOrgSymbolsListCtrl::Sort(void)
{
	if (m_nSortColumn >= NAME_COLUMN)
	{
		SortList(m_nSortColumn, m_bSortAscending);

		return true;
	}
	return false;
}


int CResOrgSymbolsListCtrl::FindSymbol(CResourceSymbol* pSymbol) const
{
	int nItem = -1;
	if (pSymbol != NULL)
	{
		LV_FINDINFO FindInfo;
		FindInfo.flags = LVFI_PARAM;
		FindInfo.lParam = (DWORD)pSymbol;
		nItem = FindItem(&FindInfo);
	}
	return nItem;
}


int CResOrgSymbolsListCtrl::GetSelection(CResourceSymbolList& rlistSymbols) const
{
	rlistSymbols.RemoveAll();

	POSITION pos = GetFirstSelectedItemPosition();
	while (NULL != pos)
	{
		int nItem = GetNextSelectedItem(pos);
		if (nItem >= 0)
		{
			// Get the data value from nItem
			// This translates into a pointer to the data object
			CResourceSymbol* pSymbol = GetSymbol(nItem);

			if (NULL != pSymbol)
			{
				rlistSymbols.AddTail(pSymbol);
			}
		}
	}
	return rlistSymbols.GetCount();
}


CResourceSymbol* CResOrgSymbolsListCtrl::GetSelection(void) const
{
	if (1 == GetSelectedCount() )
	{
		// Work out which one is selected
		int nItem = GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
		if (-1 != nItem)
		{
			// Get the data value from nItem
			// This translates into a pointer to the data object
			CResourceSymbol* pSymbol = GetSymbol(nItem);
#ifdef _DEBUG
			ASSERT(pSymbol != NULL);
			if (pSymbol != NULL)
			{
				ASSERT_KINDOF(CResourceSymbol, pSymbol);
			}
#endif
			return pSymbol;
		}
	}
	return NULL;
}


CResourceSymbol* CResOrgSymbolsListCtrl::GetSymbol(int nItem) const
{
	if (nItem >= 0)
	{
		// Get the data value from nItem
		// This translates into a pointer to the data object
		CResourceSymbol* pSymbol = reinterpret_cast<CResourceSymbol*>( GetItemData(nItem) );
#ifdef _DEBUG
		ASSERT(pSymbol != NULL);
		if (pSymbol != NULL)
		{
			ASSERT_KINDOF(CResourceSymbol, pSymbol);
		}
#endif
		return pSymbol;
	}
	return NULL;
}


/////////////////////////////////////////////////////////////////////////////
// CResOrgSymbolsListCtrl message handlers

int CResOrgSymbolsListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	int nResult = CResOrgSymbolsListCtrl_BASE::OnCreate(lpCreateStruct);

	if (-1 != nResult)
	{
		if (m_ctrlImages.GetSafeHandle() == NULL)
		{
			m_ctrlImages.Create(SMALL_ICON_CX,
								SMALL_ICON_CY,						// Small icon
								ILC_COLOR | ILC_MASK,				// Colour depth
								0,									// Initial images
								1);									// Growby

		}
		if (NULL == GetImageList(LVSIL_SMALL) )
		{
			SetImageList(&m_ctrlImages, LVSIL_SMALL);
		}
	}
	return nResult;
}


void CResOrgSymbolsListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) 
{
	LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
	
	CResOrgSymbolsListCtrl_BASE::OnCustomDraw(pNMHDR, pResult);

    switch (lplvcd->nmcd.dwDrawStage)
	{
		case CDDS_PREPAINT:
			*pResult = CDRF_NOTIFYITEMDRAW;		// Request prepaint notifications for each item.
			break;
			
		case CDDS_ITEMPREPAINT: // Requested notification
			if (lplvcd->nmcd.dwItemSpec >= 0)
			{
				if (m_bShowStatusColumn)
				{
					CResourceSymbol* pSymbol = (CResourceSymbol*)lplvcd->nmcd.lItemlParam;
					if (NULL != pSymbol)
					{
						if (pSymbol->IsReadOnly())
						{
							lplvcd->clrText   = ::GetSysColor(COLOR_GRAYTEXT);

							// Request a post-paint notification so we can draw a grayed icon
							*pResult = CDRF_NOTIFYPOSTPAINT;	
						}
						else if ( !m_pResourceSymbolManager->IsUnique(pSymbol->GetName() ) ||
								  !m_pResourceSymbolManager->IsUnique(pSymbol->GetValue() ) )
						{
							// Highlight conflicting symbols in red...
							lplvcd->clrText   = RGB(255,0,0);
						}
						else if ( m_pResourceSymbolManager->IsOutOfRange(pSymbol) )
						{
							// Highlight out of range symbols in a slightly darker red...
							lplvcd->clrText   = RGB(160,0,0);
						}
						else if (pSymbol->IsModified())
						{
							// ...and changed symbols in blue...
							lplvcd->clrText   = RGB(0,0,255);
						}
					}
				}
				else
				{
					lplvcd->clrText = m_clrText;
				}
			}
			break;

		case CDDS_ITEMPOSTPAINT:
			{
				// Draw a "grayed" icon for read-only symbols
				CResourceSymbol* pSymbol = (CResourceSymbol*)lplvcd->nmcd.lItemlParam;
				if (NULL != pSymbol)
				{
					if (pSymbol->IsReadOnly())
					{
						// First, retrieve the image index
						LV_ITEM item;
						item.iItem		= (int)lplvcd->nmcd.dwItemSpec;
						item.iSubItem	= 0;
						item.mask		= LVIF_IMAGE | LVIF_STATE;

						GetItem(&item);

						// Get the rectangle of the item from the list control
						// The topleft corner is the point we need to draw the icon at
						CRect rectIcon;
						GetItemRect(item.iItem, &rectIcon, LVIR_ICON);
						CPoint p( rectIcon.TopLeft() );

						// Obtain a device context and a handle to the icon
						CDC* pDC = CDC::FromHandle(lplvcd->nmcd.hdc);
						ASSERT(pDC != NULL);

						HICON hIcon = m_ctrlImages.ExtractIcon(item.iImage);
						ASSERT(hIcon != NULL);

						// At last! Draw it...
						pDC->DrawState(p, CSize(0,0), hIcon, DSS_DISABLED, (HBRUSH)NULL);

						// Finally - a bit of cleanup to keep the auditors happy...
						::DestroyIcon(hIcon);
					}
				}
			}
			*pResult = CDRF_DODEFAULT;
			break;
			
		default:
			break;
	}
}


void CResOrgSymbolsListCtrl::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 
{
	CWnd* pParent = GetParent();
	if ( (NULL != pParent) && IsViewContainedInSplitterWindow(pParent) )
	{
		// If we're running inside a view within a splitter, remove our own scrollbars
		// so the splitter scrollbars can do their thing instead
		ModifyStyle(WS_HSCROLL | WS_VSCROLL, 0, 0);
	}
	CResOrgSymbolsListCtrl_BASE::OnNcCalcSize(bCalcValidRects, lpncsp);
}


void CResOrgSymbolsListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	CResOrgSymbolsListCtrl_BASE::OnKeyDown(nChar, nRepCnt, nFlags);

	switch (nChar)
	{
		case VK_PRIOR:
		case VK_NEXT:
		case VK_DOWN:
		case VK_UP:
		case VK_HOME:
		case VK_LEFT:
		case VK_RIGHT:
		case VK_END:
			{
				// If we're running inside a view within a splitter, forward the settings from
				// our own scrollbars to it so that its internal state is maintained
				CWnd* pParent = GetParent();
				if ( (NULL != pParent) && IsViewContainedInSplitterWindow(pParent) )
				{
					SCROLLINFO infoHorz;
					GetScrollInfo(SB_HORZ, &infoHorz); 
					
					pParent->SendMessage(WM_SETSCROLLINFO, (WPARAM)SB_HORZ, (LPARAM)&infoHorz);

					SCROLLINFO infoVert;
					GetScrollInfo(SB_VERT, &infoVert); 
					
					pParent->SendMessage(WM_SETSCROLLINFO, (WPARAM)SB_VERT, (LPARAM)&infoVert);
				}
			}						
			break;

		default:
			break;
	}
}

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

Anna-Jayne Metcalfe
Founder Riverblade Limited
United Kingdom United Kingdom
I haven't always written software for a living. When I graduated from Surrey University in 1989, it was with an Electronic Engineering degree, but unfortunately that never really gave me the opportunity to do anything particularly interesting (with the possible exception of designing Darth Vader's Codpiece * for the UK Army in 1990).
    * Also known as the Standard Army Bootswitch. But that's another story...
Since the opportunity arose to lead a software team developing C++ software for Avionic Test Systems in 1996, I've not looked back. More recently I've been involved in the development of subsea acoustic navigation systems, digital TV broadcast systems, port security/tracking systems, and most recently software development tools with my own company, Riverblade Ltd.

One of my personal specialities is IDE plug-in development. ResOrg was my first attempt at a plug-in, but my day to day work is with Visual Lint, an interactive code analysis tool environment with works within the Visual Studio and Eclipse IDEs or on build servers.

I love lots of things, but particularly music, photography and anything connected with history or engineering. I despise ignorant, intolerant and obstructive people - and it shows...I can be a bolshy cow if you wind me up the wrong way...Laugh | :laugh:

I'm currently based 15 minutes walk from the beach in Bournemouth on the south coast of England. Since I moved here I've grown to love the place - even if it is full of grockles in Summer!
Follow on   Twitter

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 10 Jan 2005
Article Copyright 2001 by Anna-Jayne Metcalfe
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid