⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 treepropsheetbase.h

📁 人事管理系统
💻 H
📖 第 1 页 / 共 2 页
字号:
// TreePropSheetBase.h
//
/////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2004 by Yves Tkaczyk
// (http://www.tkaczyk.net - yves@tkaczyk.net)
//
// The contents of this file are subject to the Artistic License (the "License").
// You may not use this file except in compliance with the License. 
// You may obtain a copy of the License at:
// http://www.opensource.org/licenses/artistic-license.html
//
// Documentation: http://www.codeproject.com/property/treepropsheetex.asp
// CVS tree:      http://sourceforge.net/projects/treepropsheetex
//
//  /********************************************************************
//  *
//  * Copyright (c) 2002 Sven Wiegand <forum@sven-wiegand.de>
//  *
//  * You can use this and modify this in any way you want,
//  * BUT LEAVE THIS HEADER INTACT.
//  *
//  * Redistribution is appreciated.
//  *
//  * $Workfile:$
//  * $Revision: 1.4 $
//  * $Modtime:$
//  * $Author: ytkaczyk $
//  *
//  * Revision History:
//  *	$History:$
//  *
//  *********************************************************************/
//
/////////////////////////////////////////////////////////////////////////////



#ifndef _TREEPROPSHEET_TREEPROPSHEETBASE_H__INCLUDED_
#define _TREEPROPSHEET_TREEPROPSHEETBASE_H__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

//#pragma warning (push)
#pragma warning (disable:4786)

#include "PropPageFrame.h"
#include <afxtempl.h>
#include <map>

class CTreeCtrlEx; 

namespace TreePropSheet
{

  // Registered message to communicate with the library
  // (defined so that in the same executable it is initialized only once)
  
  // Message handled by CTreePropSheetBase to enable/disable property pages.
  // WPARAM: Pointer to property page
  // LPARAM: Enable/disable state
  const UINT WMU_ENABLEPAGE     = ::RegisterWindowMessage(_T("WMU_TPS_ENABLEPAGE"));

  // Message handled by the tree to change the color of the specified item.
  // WPARAM: HTREEITEM of the tree item.
  // LPARAM: COLORREF Color of the tree item text.
  const UINT WMU_ENABLETREEITEM = ::RegisterWindowMessage(_T("WMU_TPS_ENABLETREEITEM"));

  /////////////////////////////////////////////////////////////////////////////
  // utility functions
  inline BOOL Send_EnablePage(HWND hWndTarget, CPropertyPage* pPage, const bool bEnable)
  {
	  ASSERT(::IsWindow(hWndTarget));
    return (0 != ::SendMessage(hWndTarget, WMU_ENABLEPAGE, (WPARAM)pPage, (LPARAM)bEnable));
  }

/*! @brief Base class for CTreePropSheetEx
  Base class for property sheet allowing navigation using an
  optional tree control on the left of the window.

  See CTreePropSheet for more details on class functionality.

  @internal 
    CTreePropSheetBase is an update of CTreePropSheet. 
    Accessibility of several methods has been changed as well as 
    some implementation details. New functionality (such as
    skipping empty pages) has also been added. 
    This class was introduced in order 
    to leave CTreePropSheet intact hence allowing using 
    CTreePropSheet and CTreePropSheetEx in the same project 
    without risking to break the existing code using CTreePropSheet.

  @sa CTreePropSheet CTreePropSheetEx
  @version 0.1
  @author Yves Tkaczyk <yves@tkaczyk.net>
  @author Sven Wiegand (original CTreePropSheet)
  @date 07/2004 */
class CTreePropSheetBase
 : public CPropertySheet
{
	DECLARE_DYNAMIC(CTreePropSheetBase)

// Construction/Destruction
public:
	CTreePropSheetBase();
	CTreePropSheetBase(UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
	CTreePropSheetBase(LPCTSTR pszCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
	virtual ~CTreePropSheetBase();

// Operations
public:
	/**
	Call this method, if you would like to use a tree control to browse
	the pages, instead of the tab control.

	This method needs to be called, before DoModal() or Create(). If the 
	window has already been created, the method will fail.

	@param bTreeViewMode
		Pass TRUE to provide a tree view control instead of a tab control
		to browse the pages, pass FALSE to use the normal tab control.
	@param bPageCaption
		TRUE if a caption should be displayed for each page. The caption
		contains the page title and an icon if specified with the page.
		Ignored if bTreeViewMode is FALSE.
	@param bTreeImages
		TRUE if the page icons should be displayed in the page tree, 
		FALSE if there should be no icons in the page tree. Ignored if
		bTreeViewMode is FALSE. If not all of your pages are containing
		icons, or if there will be empty pages (parent nodes without a
		related page, you need to call SetTreeDefaultImages() to avoid 
		display errors.

	@return
		TRUE on success or FALSE, if the window has already been created.
	*/
	BOOL SetTreeViewMode(BOOL bTreeViewMode = TRUE, BOOL bPageCaption = FALSE, BOOL bTreeImages = FALSE);

  //@{
  /** Indicates if empty pages should be skipped when navigating the tree. 
  @param
    bSkipEmptyPages Skip empty pages if true. */
  void SetSkipEmptyPages(const bool bSkipEmptyPages);

  /** Returns true if empty pages are skipped and false if the default
      message is displayed. 
  @return True if empty pages are skipped, false if 'Empty Page Text' is 
          displayed. */
  bool IsSkippingEmptyPages() const;

  /**
	Specifies the text to be drawn on empty pages (pages for tree view
	items, that are not related to a page, because they are only 
	parents for other items). This is only needed in tree view mode.

	The specified text can contains a single "%s" placeholder which 
	will be replaced with the title of the empty page.
	*/
	void SetEmptyPageText(LPCTSTR lpszEmptyPageText);

	/**
	Allows you to specify, how the empty page message (see 
	SetEmptyPageText()) should be drawn.

	@param dwFormat
		A combination of the DT_* flags available for the Win32-API
		function DrawText(), that should be used to draw the text.
		The default value is:
		\code
		DT_CENTER|DT_VCENTER|DT_NOPREFIX|DT_SINGLELINE
		\endcode

	@return
		The previous format.
	*/
	DWORD SetEmptyPageTextFormat(DWORD dwFormat);
  //@}

	//@{
	/**
	Defines the images, that should be used for pages without icons and
	for empty parent nodes. The list contains exactly to images:
	1. An image that should be used for parent tree nodes, without a
	   page assigned.
	2. An image that should be used for pages, which are not specifying
	   any icons.
	Standard image size is 16x16 Pixels, but if you call this method 
	before creating the sheet, the size of image 0 in this list will
	be assumed as your preferred image size and all other icons must
	have the same size.

	@param pImages
		Pointer to an image list with exactly to images, that should be
		used as default images. The images are copied to an internal 
		list, so that the given list can be deleted after this call.
	@param unBitmapID
		Resource identifier for the bitmap, that contains the default
		images. The resource should contain exactly to images.
	@param cx
		Width of a singe image in pixels.
	@param crMask
		Color that should be interpreted as transparent.
	
	@return
		TRUE on success, FALSE otherwise.
	*/
	BOOL SetTreeDefaultImages(CImageList *pImages);
	BOOL SetTreeDefaultImages(UINT unBitmapID, int cx, COLORREF crMask);
	//@}

	/**
	Returns a pointer to the tree control, when the sheet is in
	tree view mode, NULL otherwise.
  @return 
    Tree control if in tree mode, NULL otherwise.
	*/
	CTreeCtrl* GetPageTreeControl();

	/**
	Returns a pointer to the frame control, when the sheet is in
	tree view mode, NULL otherwise.
  @return 
    Frame control if in tree mode, NULL otherwise.
	*/
  CPropPageFrame* GetFrameControl();

  /** 
  Indicate if the sheet is in tree view mode.
    
  @return
    Returns true if in tree view mode, false otherwise. 
  */
  bool IsTreeViewMode() const;

  /**
  Returns the tree width set by SetTreeWidth if the tree control has not
  yet been created or the actual tree control width if the tree exists.

  @return
    Width of the tree control.
  */
  int GetTreeWidth() const;

  /** 
  Set if all items in the tree should be expanded when the tree
  is displayed. 
  @param bAutoExpandTree True to have the tree in expanded automatically. */
  void SetAutoExpandTree(const bool bAutoExpandTree);

  /**
  Returns true if the tree will be expanded automatically when displayed. 

  @return 
    True if the tree will be expanded automatically when displayed. Default 
    is false. */
  bool IsAutoExpandTree() const;

 	//@{
  /** 
  Enable/disable the specified property page. The property page window does not have to 
  exist. Once a page is disabled, the tree is updated and the page is disabled (i.e. 
  the user cannot edit control in the page. 
  If the current page is disabled, the next page is selected. Because of this, it is not 
  valid to disable all the property pages. In this case, disabling the last property page
  will fail.

  @param pPage Property page for which the status is to be changed.
  @param bEnable Desired new status (true for enabled, false for disabled).
  @return Previous enable status of the property page. */
  bool EnablePage(const CPropertyPage* const pPage, const bool bEnable);

  /** 
  Returns the enabled status of the specified property page. 

  @param pPage Property page for which the status is to be changed.
  @return True if the page is enabled, false if disabled. */
  bool IsPageEnabled(const CPropertyPage* const pPage) const;
	//@}


// Public helpers
public:
	//@{
	/**
	This helper allows you to easily set the icon of a property page.

	This static method does nothing more, than extracting the specified
	image as an icon from the given image list and assign the 
	icon-handle to the hIcon property of the pages PROPSHEETPAGE
	structure (m_psp) and modify the structures flags, so that the 
	image will be recognized.

	You need to call this method for a page, before adding the page
	to a property sheet.

	@attention
	If you are using the CImageList-version, you are responsible for
	destroying the extracted icon with DestroyIcon() or the static
	DestroyPageIcon() method.

	@see DestroyPageIcon()

	@param pPage
		Property page to set the image for.
	@param hIcon
		Handle to icon that should be set for the page.
	@param unIconId
		Resource identifier for the icon to set.
	@param Images
		Reference of the image list to extract the icon from.
	@param nImage
		Zero based index of the image in pImages, that should be used
		as an icon.

	@return
		TRUE on success, FALSE if an error occurred.
	*/
	static BOOL SetPageIcon(CPropertyPage *pPage, HICON hIcon);
	static BOOL SetPageIcon(CPropertyPage *pPage, UINT unIconId);
	static BOOL SetPageIcon(CPropertyPage *pPage, CImageList &Images, int nImage);
	//@}

	/**
	Checks, if the PSP_USEHICON flag is set in the PROPSHEETPAGE struct;
	If this is the case, the flag will be removed and the icon 
	specified by the hIcon attribute of the PROPSHEETPAGE struct will
	be destroyed using DestroyIcon().

	@note
	You only have to call DestroyIcon() for icons, that have been
	created using CreateIconIndirect() (i.e. used by 
	CImageList::ExtractIcon()).

	@return
		TRUE on success, FALSE if the PSP_USEHICON flag was not set or
		if the icon handle was NULL.
	*/
	static BOOL DestroyPageIcon(CPropertyPage *pPage);

// Overridables
public:
	/**
	Specifies the width of the tree control, when the sheet is in tree
	view mode. The default value (if this method is not called) is 150
	pixels.

	This method needs to be called, before DoModal() or Create(). 
	Otherwise it will fail.

	@param nWidth
		The width in pixels for the page tree. 

	@return
		TRUE on success, FALSE otherwise (if the window has already been
		created).

  @internal
    Made virtual in order to support resizing after the control has 
    been created.
	*/
	virtual BOOL SetTreeWidth(int nWidth);

// Overridable implementation helpers
protected:
	/**
	Will be called to generate the message, that should be displayed on

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -