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

The SBJ MVC Framework - The Model, from Abstraction to Realization

, 20 Mar 2009
A Model-View-Controller Framework that integrates with the MFC Doc/View architecture
SbjDevBin201.zip
SbjDevSrc201.zip
Shapes
Data
res
buttons.bmp
filelarge.bmp
filesmall.bmp
filesmall.png
main.bmp
Shapes.ico
ShapesDoc.ico
Toolbar.bmp
Toolbar256.bmp
treeimages.bmp
vssver.scc
Write - Copy.png
Write.png
Write1.png
writelarge.bmp
writesmall - Copy.bmp
writesmall - Copy.png
writesmall.bmp
writesmall.png
XmlMvc
res
vssver.scc
SbjCore
res
bigcat.ico
main.bmp
properties.bmp
properties_hc.bmp
properties_wnd_hc.ico
vssver.scc
//------------------------------------------------------------------------------
// $Workfile: CtrlUtils.cpp $
// $Header:  $
//
//	Copyright � 2008 SbjCat
// All rights reserved.
//
//
// *** Authors ***
//	 Steve Johnson
//
// $Revision: $
//
//-----------------------------------------------------------------------------

#include "stdafx.h"
#include "CtrlUtils.h"

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

namespace SbjCore
{
	namespace Utils
	{
		namespace Ctrl
		{
			/** \struct TVItem 
			wrapper for the TVITEMEX struct

			Each Set method sets the appropriate mask field flags along with its
			associated TVITEMEX field. See the TVITEMEX documentation for further information.

			*/

			/// default ctor - zeros the struct
			TVItem::TVItem()
			{
				::ZeroMemory(this, sizeof(TVItem));	
			}

			void TVItem::SetMask(UINT nMask)
			{
				TVITEMEX::mask = nMask;
			}

			void TVItem::SetItemText(LPCTSTR lpszItemText)
			{
				TVITEMEX::mask |= TVIF_TEXT;
				TVITEMEX::pszText = const_cast<LPTSTR>(lpszItemText);
			}

			void TVItem::SetImage(long nImage)
			{
				TVITEMEX::mask |= TVIF_IMAGE;
				TVITEMEX::iImage = nImage;
			}

			void TVItem::SetSelectedImage(long nImage)
			{
				TVITEMEX::mask |= TVIF_SELECTEDIMAGE;
				TVITEMEX::iSelectedImage = nImage;
			}

			void TVItem::SetHandle(HTREEITEM hti)
			{
				TVITEMEX::mask |= TVIF_HANDLE;
				TVITEMEX::hItem = hti;
			}


			void TVItem::SetState(UINT nState, UINT nStateMask)
			{
				//1.21.2004 SBJ - prevents deselect
				//	if (nState)
				{
					TVITEMEX::mask |= TVIF_STATE;
					TVITEMEX::state |= nState;
					TVITEMEX::stateMask |= nStateMask;
				}
			}

			void TVItem::SetOverlayIndex(UINT nIndex)
			{
				if (nIndex)
				{
					TVITEMEX::mask |= TVIF_STATE;
					TVITEMEX::stateMask |= TVIS_OVERLAYMASK;
					TVITEMEX::state = INDEXTOOVERLAYMASK(nIndex);
				}
			}

			void TVItem::SetStateImageIndex(UINT nIndex)
			{
				if (nIndex)
				{
					TVITEMEX::mask |= TVIF_STATE;
					TVITEMEX::stateMask |= TVIS_STATEIMAGEMASK;
					TVITEMEX::state = INDEXTOSTATEIMAGEMASK(nIndex);
				}
			}

			void TVItem::SetChildren(int nChildren)
			{
				TVITEMEX::mask |= TVIF_CHILDREN;
				TVITEMEX::cChildren = nChildren;
			}

			void TVItem::SetParam(LPARAM nParam)
			{
				TVITEMEX::mask |= TVIF_PARAM;
				TVITEMEX::lParam = nParam;
			}

			TVItem::operator TVITEMEX&()
			{
				return *(TVITEMEX*)this;
			}

			const TVItem& TVItem::operator=(const TVItem& other)
			{
				if (this != &other)	
				{
					memcpy(this, &other, sizeof(TVItem));
				}

				return *this;
			}
			
			/** \struct LVColumn 
			wrapper for the LVCOLUMN struct 

			Each Set method sets the appropriate mask field flags along with its
			associated LVCOLUMN field. See LVCOLUMN documentation for furture information.
			*/


			/// default ctor - zeros the struct
			LVColumn::LVColumn()
			{
				::ZeroMemory(this, sizeof(LVColumn));	
			}

			/// ctor - see LVCOLUMN documentation for details on parameters
			LVColumn::LVColumn(LPCTSTR pszText,	
				int cx, 
				int fmt /*= LVCFMT_CENTER*/, 
				int iImage /*= -1*/,
				int iSubItem /*= -1*/, 
				int iOrder /*= 0*/)
			{
				::ZeroMemory(this, sizeof(LVColumn));	
				SetFmt(fmt);
				SetWidth(cx);
				SetItemText(pszText);
				SetSubItem(iSubItem);
				SetImage(iImage);
				SetOrder(iOrder);
			}




			void LVColumn::SetMask(UINT nMask)
			{
				LVCOLUMN::mask = nMask;
			}

			void LVColumn::SetFmt(const int nFmt)
			{
				LVCOLUMN::mask |= LVCF_FMT;
				LVCOLUMN::fmt = nFmt;
			}

			void LVColumn::SetWidth(const int cx)
			{
				LVCOLUMN::mask |= LVCF_WIDTH;
				LVCOLUMN::cx = cx;
			}

			void LVColumn::SetItemText(LPCTSTR lpszItemText)
			{
				LVCOLUMN::mask |= LVCF_TEXT;
				LVCOLUMN::pszText = const_cast<LPTSTR>(lpszItemText);
			}

			void LVColumn::SetSubItem(const int nSubItem)
			{
				LVCOLUMN::mask |= LVCF_SUBITEM;
				LVCOLUMN::iSubItem = nSubItem;
			}

			void LVColumn::SetImage(const int nImage)
			{
				LVCOLUMN::mask |= LVCF_IMAGE;
				LVCOLUMN::iImage = nImage;
			}

			void LVColumn::SetOrder(const int nOrder)
			{
				LVCOLUMN::mask |= LVCF_ORDER;
				LVCOLUMN::iOrder = nOrder;
			}

		}
	}
}

/// LVCOLUMN stream operator - outside namespace (here for convenience)
std::ostream& operator<<(std::ostream& rStream, const LVCOLUMN& rColumn)
{
	rStream << rColumn.mask << " " << rColumn.fmt << " " << rColumn.cx << " ";
	rStream << rColumn.iSubItem << " ";
	rStream << rColumn.iImage << " " << rColumn.iOrder << " ";

	if (rColumn.pszText)
	{
		USES_CONVERSION;

		rStream << T2CA(rColumn.pszText);
	}

	return rStream;
}


/// LVCOLUMN stream operator - outside namespace (here for convenience)
std::istream& operator>>(std::istream& rStream, LVCOLUMN& rColumn)
{
	rStream >> rColumn.mask >> rColumn.fmt >> rColumn.cx >> rColumn.iSubItem;
	rStream >> rColumn.iImage >> rColumn.iOrder;

	(void) rStream.ignore();

	std::string strLine;

	(void) std::getline(rStream, strLine);

	USES_CONVERSION;

	_tcscpy_s(rColumn.pszText, _tcslen(A2CT(strLine.c_str())), A2CT(strLine.c_str()));

	rColumn.cchTextMax = static_cast<int>(strLine.size());

	return rStream;
}

//*** Modification History ***
// $Log:  $

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

SBJ

United States United States
Real name is Steve Johnson. Programming since 1979. Started on a Heathkit Micro with a DEC LSI-11 and UCSD Pascal. Moved to PCs & DOS as soon as Turbo Pascal became available. Did some Assembly, ISR, TSR etc. All this while working for a Manufacturing Co. for 8 years. Had my own solo Co. doing barcode labeling software for 4 years (terrible business man, all I wanted to do was code). Since then working for various software companies. Moved to Windows around the time of 3.1 with Borland C then C++. Then on to VC++ and MFC, and just about anything I could get my hands on or had to learn for my job, and been at it ever since. Of course recently I've been playing with .NET, ASP, C#, WPF etc.

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 20 Mar 2009
Article Copyright 2008 by SBJ
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid