1 /********************************************************************
\r
3 * Copyright (c) 2002 Sven Wiegand <mail@sven-wiegand.de>
\r
5 * You can use this and modify this in any way you want,
\r
6 * BUT LEAVE THIS HEADER INTACT.
\r
8 * Redistribution is appreciated.
\r
18 *********************************************************************/
\r
21 #if !defined(AFX_TREEPROPSHEET_H__50695CFB_FCE4_4188_ADB4_BF05A5488E41__INCLUDED_)
\r
22 #define AFX_TREEPROPSHEET_H__50695CFB_FCE4_4188_ADB4_BF05A5488E41__INCLUDED_
\r
26 #endif // _MSC_VER > 1000
\r
28 #include "PropPageFrame.h"
\r
29 #include <afxtempl.h>
\r
31 namespace TreePropSheet
\r
35 A property sheet, which can use a tree control instead of a tab
\r
36 control, to give the user access to the different pages.
\r
38 You can use it exactly the same way, as a CPropertySheet object.
\r
39 Simply create CPropertyPage objects and add them via AddPage() to
\r
40 the sheet. If you would like to use the tree view mode (default),
\r
41 you can specify the path of the pages in the tree, by their name:
\r
42 The names of the pages can contain
\r
43 double colons ("::"), which will specify the path of that page in the
\r
44 tree control. I.e. if you have three pages with the following names:
\r
45 1. _T("Appearance::Toolbars")
\r
46 2. _T("Appearance::Menus")
\r
47 3. _T("Directories")
\r
48 the tree would look as follow:
\r
58 If you would like to use a double colon, which should not be
\r
59 interpreted as a path seperator, prefix it with a backslash ("\\::").
\r
61 To disable tree view mode and use the standard tabbed mode, call
\r
62 the SetTreeViewMode() method. This also allows you, to enable page
\r
63 captions and tree images for tree view mode. If you would like to
\r
64 have images in the tree, but not all of your pages specify images or
\r
65 there are tree view items, which are not attached to a page (only
\r
66 parent items for real page items), you have to set default images
\r
67 using the SetTreeDefaultImages() method -- otherwise their may appear
\r
70 If the user selects a tree view item, which does not belong to a page,
\r
71 because it is just a parent item for real page items, no page will
\r
72 be displayed, instead a message will be displayed, that can be set
\r
73 via SetEmptyPageText().
\r
75 @author Sven Wiegand
\r
77 class /*AFX_EXT_CLASS*/ CTreePropSheet : public CPropertySheet
\r
79 DECLARE_DYNAMIC(CTreePropSheet)
\r
81 // Construction/Destruction
\r
84 CTreePropSheet(UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
\r
85 CTreePropSheet(LPCTSTR pszCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
\r
86 virtual ~CTreePropSheet();
\r
91 Call this method, if you would like to use a tree control to browse
\r
92 the pages, instead of the tab control.
\r
94 This method needs to becalled, before DoModal() or Create(). If the
\r
95 window has already been created, the method will fail.
\r
97 @param bTreeViewMode
\r
98 Pass TRUE to provide a tree view control instead of a tab control
\r
99 to browse the pages, pass FALSE to use the normal tab control.
\r
100 @param bPageCaption
\r
101 TRUE if a caption should be displayed for each page. The caption
\r
102 contains the page title and an icon if specified with the page.
\r
103 Ignored if bTreeViewMode is FALSE.
\r
105 TRUE if the page icons should be displayed in the page tree,
\r
106 FALSE if there should be no icons in the page tree. Ignored if
\r
107 bTreeViewMode is FALSE. If not all of your pages are containing
\r
108 icons, or if there will be empty pages (parent nodes without a
\r
109 related page, you need to call SetTreeDefaultImages() to avoid
\r
113 TRUE on success or FALSE, if the window has already been created.
\r
115 BOOL SetTreeViewMode(BOOL bTreeViewMode = TRUE, BOOL bPageCaption = FALSE, BOOL bTreeImages = FALSE);
\r
118 Specifies the width of the tree control, when the sheet is in tree
\r
119 view mode. The default value (if this method is not called) is 150
\r
122 This method needs to be called, before DoModeal() or Create().
\r
123 Otherwise it will fail.
\r
126 The width in pixels for the page tree.
\r
129 TRUE on success, FALSE otherwise (if the window has already been
\r
132 BOOL SetTreeWidth(int nWidth);
\r
135 Specifies the text to be drawn on empty pages (pages for tree view
\r
136 items, that are not related to a page, because they are only
\r
137 parents for other items). This is only needed in tree view mode.
\r
139 The specified text can contains a single "%s" placeholder which
\r
140 will be replaced with the title of the empty page.
\r
142 void SetEmptyPageText(LPCTSTR lpszEmptyPageText);
\r
145 Allows you to specify, how the empty page message (see
\r
146 SetEmptyPageText()) should be drawn.
\r
149 A combination of the DT_* flags available for the Win32-API
\r
150 function DrawText(), that should be used to draw the text.
\r
151 The default value is:
\r
153 DT_CENTER|DT_VCENTER|DT_NOPREFIX|DT_SINGLELINE
\r
157 The previous format.
\r
159 DWORD SetEmptyPageTextFormat(DWORD dwFormat);
\r
163 Defines the images, that should be used for pages without icons and
\r
164 for empty parent nodes. The list contains exactly to images:
\r
165 1. An image that should be used for parent tree nodes, without a
\r
167 2. An image that should be used for pages, which are not specifying
\r
169 Standard image size is 16x16 Pixels, but if you call this method
\r
170 before creating the sheet, the size of image 0 in this list will
\r
171 be assumed as your preferred image size and all other icons must
\r
172 have the same size.
\r
175 Pointer to an image list with exactly to images, that should be
\r
176 used as default images. The images are copied to an internal
\r
177 list, so that the given list can be deleted after this call.
\r
179 Resource identifier for the bitmap, that contains the default
\r
180 images. The resource should contain exactly to images.
\r
182 Width of a singe image in pixels.
\r
184 Color that should be interpreted as transparent.
\r
187 TRUE on success, FALSE otherwise.
\r
189 BOOL SetTreeDefaultImages(CImageList *pImages);
\r
190 BOOL SetTreeDefaultImages(UINT unBitmapID, int cx, COLORREF crMask);
\r
194 Returns a pointer to the tree control, when the sheet is in
\r
195 tree view mode, NULL otherwise.
\r
197 CTreeCtrl* GetPageTreeControl();
\r
203 This helper allows you to easily set the icon of a property page.
\r
205 This static method does nothing more, than extracting the specified
\r
206 image as an icon from the given image list and assign the
\r
207 icon-handle to the hIcon property of the pages PROPSHEETPAGE
\r
208 structure (m_psp) and modify the structures flags, so that the
\r
209 image will be recognized.
\r
211 You need to call this method for a page, before adding the page
\r
212 to a property sheet.
\r
215 If you are using the CImageList-version, you are responsible for
\r
216 destroying the extracted icon with DestroyIcon() or the static
\r
217 DestroyPageIcon() method.
\r
219 @see DestroyPageIcon()
\r
222 Property page to set the image for.
\r
224 Handle to icon that should be set for the page.
\r
226 Ressource identifier for the icon to set.
\r
228 Reference of the image list to extract the icon from.
\r
230 Zero based index of the image in pImages, that should be used
\r
234 TRUE on success, FALSE if an error occured.
\r
236 static BOOL SetPageIcon(CPropertyPage *pPage, HICON hIcon);
\r
237 static BOOL SetPageIcon(CPropertyPage *pPage, UINT unIconId);
\r
238 static BOOL SetPageIcon(CPropertyPage *pPage, CImageList &Images, int nImage);
\r
242 Checks, if the PSP_USEHICON flag is set in the PROPSHEETPAGE struct;
\r
243 If this is the case, the flag will be removed and the icon
\r
244 specified by the hIcon attribute of the PROPSHEETPAGE struct will
\r
245 be destroyed using DestroyIcon().
\r
248 You only have to call DestroyIcon() for icons, that have been
\r
249 created using CreateIconIndirect() (i.e. used by
\r
250 CImageList::ExtractIcon()).
\r
253 TRUE on success, FALSE if the PSP_USEHICON flag was not set or
\r
254 if the icon handle was NULL.
\r
256 static BOOL DestroyPageIcon(CPropertyPage *pPage);
\r
258 // Overridable implementation helpers
\r
261 Will be called to generate the message, that should be displayed on
\r
262 an empty page, when the sheet is in tree view mode
\r
264 This default implementation simply returns lpszEmptyPageMessage
\r
265 with the optional "%s" placeholder replaced by lpszCaption.
\r
267 @param lpszEmptyPageMessage
\r
268 The string, set by SetEmptyPageMessage(). This string may contain
\r
269 a "%s" placeholder.
\r
271 The title of the empty page.
\r
273 virtual CString GenerateEmptyPageMessage(LPCTSTR lpszEmptyPageMessage, LPCTSTR lpszCaption);
\r
276 Will be called during creation process, to create the CTreeCtrl
\r
277 object (the object, not the window!).
\r
279 Allows you to inject your own CTreeCtrl-derived classes.
\r
281 This default implementation simply creates a CTreeCtrl with new
\r
284 virtual CTreeCtrl* CreatePageTreeObject();
\r
287 Will be called during creation process, to create the object, that
\r
288 is responsible for drawing the frame around the pages, drawing the
\r
289 empty page message and the caption.
\r
291 Allows you to inject your own CPropPageFrame-derived classes.
\r
293 This default implementation simply creates a CPropPageFrameTab with
\r
294 new and returns it.
\r
296 virtual CPropPageFrame* CreatePageFrame();
\r
298 // Implementation helpers
\r
301 Moves all childs by the specified amount of pixels.
\r
304 Pixels to move the childs in horizontal direction (can be
\r
307 Pixels to move the childs in vertical direction (can be
\r
310 void MoveChildWindows(int nDx, int nDy);
\r
313 Refills the tree that contains the entries for the several pages.
\r
315 void RefillPageTree();
\r
318 Creates the specified path in the page tree and returns the handle
\r
319 of the most child item created.
\r
322 Path of the item to create (see description of this class).
\r
324 Handle of the item under which the path should be created or
\r
325 TVI_ROOT to start from the root.
\r
327 HTREEITEM CreatePageTreeItem(LPCTSTR lpszPath, HTREEITEM hParent = TVI_ROOT);
\r
330 Splits the given path into the topmost item and the rest. See
\r
331 description of this class for detailed path information.
\r
333 I.e. when given the string "Appearance::Toolbars::Customize", the
\r
334 method will return "Appearance" and after the call strRest will
\r
335 be "Toolbars::Customize".
\r
337 CString SplitPageTreePath(CString &strRest);
\r
340 Tries to deactivate the current page, and hides it if successfull,
\r
341 so that an empty page becomes visible.
\r
344 TRUE if the current page has been deactivated successfully,
\r
345 FALSE if the currently active page prevents a page change.
\r
347 BOOL KillActiveCurrentPage();
\r
350 Returns the page tree item, that representates the specified page
\r
351 or NULL, if no such icon exists.
\r
354 Zero based page index, for which the item to retrieve.
\r
356 Item to start the search at or TVI_ROOT to search the whole
\r
359 HTREEITEM GetPageTreeItem(int nPage, HTREEITEM hRoot = TVI_ROOT);
\r
362 Selects and shows the item, representing the specified page.
\r
365 Zero based page index.
\r
368 TRUE on success, FALSE if no item does exist for the specified
\r
371 BOOL SelectPageTreeItem(int nPage);
\r
374 Selects and shows the tree item for the currently active page.
\r
377 TRUE on success, FALSE if no item exists for the currently active
\r
378 page or if it was not possible to get information about the
\r
379 currently active page.
\r
381 BOOL SelectCurrentPageTreeItem();
\r
384 Updates the caption for the currently selected page (if the caption
\r
387 void UpdateCaption();
\r
390 Activates the previous page in the page order or the last one, if
\r
391 the current one is the first.
\r
393 This method does never fail.
\r
395 void ActivatePreviousPage();
\r
398 Activates the next page in the page order or the first one, if the
\r
399 current one is the last.
\r
401 This method does never fail.
\r
403 void ActivateNextPage();
\r
407 //{{AFX_VIRTUAL(CTreePropSheet)
\r
409 virtual BOOL OnInitDialog();
\r
412 // Message handlers
\r
414 //{{AFX_MSG(CTreePropSheet)
\r
415 afx_msg void OnDestroy();
\r
417 afx_msg LRESULT OnAddPage(WPARAM wParam, LPARAM lParam);
\r
418 afx_msg LRESULT OnRemovePage(WPARAM wParam, LPARAM lParam);
\r
419 afx_msg LRESULT OnSetCurSel(WPARAM wParam, LPARAM lParam);
\r
420 afx_msg LRESULT OnSetCurSelId(WPARAM wParam, LPARAM lParam);
\r
421 afx_msg LRESULT OnIsDialogMessage(WPARAM wParam, LPARAM lParam);
\r
423 afx_msg void OnPageTreeSelChanging(NMHDR *pNotifyStruct, LRESULT *plResult);
\r
424 afx_msg void OnPageTreeSelChanged(NMHDR *pNotifyStruct, LRESULT *plResult);
\r
425 DECLARE_MESSAGE_MAP()
\r
429 /** TRUE if we should use the tree control instead of the tab ctrl. */
\r
430 BOOL m_bTreeViewMode;
\r
432 /** The tree control */
\r
433 CTreeCtrl *m_pwndPageTree;
\r
435 /** The frame around the pages */
\r
436 CPropPageFrame *m_pFrame;
\r
439 TRUE, if a tree item selection by OnPageTreeSelChanged() is
\r
440 performed currently.
\r
442 BOOL m_bPageTreeSelChangedActive;
\r
444 /** TRUE if a page caption should be displayed, FALSE otherwise. */
\r
445 BOOL m_bPageCaption;
\r
447 /** TRUE if images should be displayed in the tree. */
\r
448 BOOL m_bTreeImages;
\r
450 /** Images to be displayed in the tree control. */
\r
451 CImageList m_Images;
\r
453 /** Default images. */
\r
454 CImageList m_DefaultImages;
\r
457 Message to be displayed on empty pages. May contain a "%s"
\r
458 placeholder which will be replaced by the caption of the empty
\r
461 CString m_strEmptyPageMessage;
\r
463 /** The width of the page tree control in pixels. */
\r
464 int m_nPageTreeWidth;
\r
466 // Static Properties
\r
468 /** The id of the tree view control, that shows the pages. */
\r
469 static const UINT s_unPageTreeId;
\r
473 } //namespace TreePropSheet
\r
475 /////////////////////////////////////////////////////////////////////////////
\r
477 //{{AFX_INSERT_LOCATION}}
\r
478 // Microsoft Visual C++ fügt unmittelbar vor der vorhergehenden Zeile zusätzliche Deklarationen ein.
\r
480 #endif // AFX_TREEPROPSHEET_H__50695CFB_FCE4_4188_ADB4_BF05A5488E41__INCLUDED_
\r