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: TreeItemController.h $
// $Header: /SbjDev/SbjCore/TreeItemController.h 3     11/12/08 2:22p Steve $
//
//	Copyright � 2008 SbjCat
// All rights reserved.
//
//
// *** Authors ***
//	 Steve Johnson
//
// $Revision: 3 $
//
//-----------------------------------------------------------------------------

#pragma once

#include "WndController.h"

namespace SbjCore
{
	namespace Mvc
	{
		namespace  Model
		{
			class Controller;
		}
		namespace TreeView
		{
			class Controller;
			class ItemDisplayModel;

			struct ItemControllerImpl;

			class AFX_EXT_CLASS ItemController : public WndController
			{
				DECLARE_DYNCREATE(ItemController)
			public:
				ItemController();

				virtual ~ItemController();

			public:

				/// calls CTreeCtrl::EditLabel
				void EditLabel();

				/// update the item text,  must have valid handle to update
				virtual void UpdateItemText(LPCTSTR lpszItemText);
				/// update the item image,  must have valid handle to update
				void UpdateImage(const long nImage);
				/// update the item selected image,  must have valid handle to update
				void UpdateSelectedImage(const long nImage);
				/// update the item state,  must have valid handle to update
				void UpdateState(const UINT nState, const UINT nStateMask);
				/// update the item overlay image,  must have valid handle to update
				void UpdateOverlayImage(const UINT nIndex);
				/// update the item state image,  must have valid handle to update
				void UpdateStateImage(const UINT nIndex);
				/// update the item children,  must have valid handle to update
				void UpdateChildren(const long nCount);

				/// deselect this item
				void DeselectItem();
				
				void InsertAfter(const HTREEITEM hti);
				HTREEITEM InsertAfter() const; // defaults to TVI_LAST

			public: // attributes
				virtual void Create(const SbjCore::Mvc::Model::Controller* pModelCtrlr, const SbjCore::Mvc::TreeView::Controller* pTreeController, HANDLE hItem);

				/// assign the TreeView::Controller
				void SetTreeController(const SbjCore::Mvc::TreeView::Controller* p);

				/// return a pointer to the TreeView::Controller
				const SbjCore::Mvc::TreeView::Controller* GetTreeController() const;

				void SetModelItemHandle(const HANDLE h);

				HANDLE GetModelItemHandle() const;

				/// set the ItemDisplayModel
				void SetItemDisplayModel(const ItemDisplayModel *p);

				/// return a pointer to the ItemDisplayModel
				const ItemDisplayModel *GetItemDisplayModel() const;

				/// return this item's parent TreeView::ItemController
				TreeView::ItemController* GetParentItem() const;

				/// return true if this item is a child of the pItem TreeView::ItemController
				bool IsChildOf(TreeView::ItemController* pItem);

				/// return a reference to this item's TVITEM struct 
				TVITEMEX& TreeView::ItemController::GetTVItem() const;

				/// set this item's TVItem::hItem
				void SetHandle(const HTREEITEM hti); 
				/// get this item's TVItem::hItem
				HTREEITEM GetHandle() const; 

				/// keeps a local copy of the item text
				LPTSTR SaveItemText(LPCTSTR lpszItemText); 

				/// get this item's overlay image index
				UINT GetOverlayImage() const;
				/// get this item's state image index
				UINT GetStateImage() const;

				/// get this item's TVItem::state value for the given nState
				UINT GetState(UINT nState) const;
				/// returns true of this item's TVItem::state value is true for the given nState
				BOOL IsState(UINT nState);
				/// returns true of this item's TVItem::state selected value is true
				BOOL IsSelected();
				/// returns true of this item's TVItem::state cut value is true
				BOOL IsCut();
				/// returns true of this item's TVItem::state dropHilited value is true
				BOOL IsDropHilited();
				/// returns true of this item's TVItem::state bold value is true
				BOOL IsBold();
				/// returns true of this item's TVItem::state expanded value is true
				BOOL IsExpanded();
				/// returns true of this item's TVItem::state expanded once value is true
				BOOL IsExpandedOnce();
				/// returns true of this item's TVItem::state expanded partial value is true
				BOOL IsExpandPartial();

			public: //virtual

				/// returns true of this item's item text can be edited
				virtual bool CanEdit();			
				/// returns true of this item can be deleted
				virtual bool CanDelete();			
				/// returns true of this item can accept children
				virtual bool CanAcceptChildren();			
				/// called from TreeView::Controller::InsertItem();
				virtual void OnInserted();

				virtual Utils::Menu::ItemRange OnPrepareCtxMenu(CMenu& ctxMenu);

			private:
				/// private implementation struct
				struct TreeView::ItemControllerImpl* const m_pImpl;
			};
		}
	}
}

//*** Modification History ***
// $Log: /SbjDev/SbjCore/TreeItemController.h $
// 
// 3     11/12/08 2:22p Steve
// Finished Generalization of Model  v2.0.1
// 
// 2     10/14/08 1:12p Steve
// Implemented Deletes

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
Web04 | 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