OSDN Git Service

Add SVN DCommit Command
[tortoisegit/TortoiseGitJp.git] / src / Utils / TreePropSheet / TreePropSheet.h
1 /********************************************************************\r
2 *\r
3 * Copyright (c) 2002 Sven Wiegand <mail@sven-wiegand.de>\r
4 *\r
5 * You can use this and modify this in any way you want,\r
6 * BUT LEAVE THIS HEADER INTACT.\r
7 *\r
8 * Redistribution is appreciated.\r
9 *\r
10 * $Workfile:$\r
11 * $Revision:$\r
12 * $Modtime:$\r
13 * $Author:$\r
14 *\r
15 * Revision History:\r
16 *       $History:$\r
17 *\r
18 *********************************************************************/\r
19 \r
20 \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
23 \r
24 #if _MSC_VER > 1000\r
25 #pragma once\r
26 #endif // _MSC_VER > 1000\r
27 \r
28 #include "PropPageFrame.h"\r
29 #include <afxtempl.h>\r
30 \r
31 namespace TreePropSheet\r
32 {\r
33 \r
34 /**\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
37 \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
49 \verbatim\r
50 Appearance\r
51 |\r
52 +-Toolbars\r
53 |\r
54 +-Menus\r
55 \r
56 Directories\r
57 \endverbatim\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
60 \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
68 display errors.\r
69 \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
74 \r
75 @author Sven Wiegand\r
76 */\r
77 class /*AFX_EXT_CLASS*/ CTreePropSheet : public CPropertySheet\r
78 {\r
79         DECLARE_DYNAMIC(CTreePropSheet)\r
80 \r
81 // Construction/Destruction\r
82 public:\r
83         CTreePropSheet();\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
87 \r
88 // Operations\r
89 public:\r
90         /**\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
93 \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
96 \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
104         @param bTreeImages\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
110                 display errors.\r
111 \r
112         @return\r
113                 TRUE on success or FALSE, if the window has already been created.\r
114         */\r
115         BOOL SetTreeViewMode(BOOL bTreeViewMode = TRUE, BOOL bPageCaption = FALSE, BOOL bTreeImages = FALSE);\r
116 \r
117         /**\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
120         pixels.\r
121 \r
122         This method needs to be called, before DoModeal() or Create(). \r
123         Otherwise it will fail.\r
124 \r
125         @param nWidth\r
126                 The width in pixels for the page tree. \r
127 \r
128         @return\r
129                 TRUE on success, FALSE otherwise (if the window has already been\r
130                 created).\r
131         */\r
132         BOOL SetTreeWidth(int nWidth);\r
133 \r
134         /**\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
138 \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
141         */\r
142         void SetEmptyPageText(LPCTSTR lpszEmptyPageText);\r
143 \r
144         /**\r
145         Allows you to specify, how the empty page message (see \r
146         SetEmptyPageText()) should be drawn.\r
147 \r
148         @param dwFormat\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
152                 \code\r
153                 DT_CENTER|DT_VCENTER|DT_NOPREFIX|DT_SINGLELINE\r
154                 \endcode\r
155 \r
156         @return\r
157                 The previous format.\r
158         */\r
159         DWORD SetEmptyPageTextFormat(DWORD dwFormat);\r
160 \r
161         //@{\r
162         /**\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
166            page asignd.\r
167         2. An image that should be used for pages, which are not specifying\r
168            any icons.\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
173 \r
174         @param pImages\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
178         @param unBitmapID\r
179                 Resource identifier for the bitmap, that contains the default\r
180                 images. The resource should contain exactly to images.\r
181         @param cx\r
182                 Width of a singe image in pixels.\r
183         @param crMask\r
184                 Color that should be interpreted as transparent.\r
185         \r
186         @return\r
187                 TRUE on success, FALSE otherwise.\r
188         */\r
189         BOOL SetTreeDefaultImages(CImageList *pImages);\r
190         BOOL SetTreeDefaultImages(UINT unBitmapID, int cx, COLORREF crMask);\r
191         //@}\r
192 \r
193         /**\r
194         Returns a pointer to the tree control, when the sheet is in\r
195         tree view mode, NULL otherwise.\r
196         */\r
197         CTreeCtrl* GetPageTreeControl();\r
198 \r
199 // Public helpers\r
200 public:\r
201         //@{\r
202         /**\r
203         This helper allows you to easily set the icon of a property page.\r
204 \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
210 \r
211         You need to call this method for a page, before adding the page\r
212         to a property sheet.\r
213 \r
214         @important\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
218 \r
219         @see DestroyPageIcon()\r
220 \r
221         @param pPage\r
222                 Property page to set the image for.\r
223         @param hIcon\r
224                 Handle to icon that should be set for the page.\r
225         @param unIconId\r
226                 Ressource identifier for the icon to set.\r
227         @param Images\r
228                 Reference of the image list to extract the icon from.\r
229         @param nImage\r
230                 Zero based index of the image in pImages, that should be used\r
231                 as an icon.\r
232 \r
233         @return\r
234                 TRUE on success, FALSE if an error occured.\r
235         */\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
239         //@}\r
240 \r
241         /**\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
246 \r
247         @note\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
251 \r
252         @return\r
253                 TRUE on success, FALSE if the PSP_USEHICON flag was not set or\r
254                 if the icon handle was NULL.\r
255         */\r
256         static BOOL DestroyPageIcon(CPropertyPage *pPage);\r
257 \r
258 // Overridable implementation helpers\r
259 protected:\r
260         /**\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
263 \r
264         This default implementation simply returns lpszEmptyPageMessage \r
265         with the optional "%s" placeholder replaced by lpszCaption.\r
266 \r
267         @param lpszEmptyPageMessage\r
268                 The string, set by SetEmptyPageMessage(). This string may contain\r
269                 a "%s" placeholder.\r
270         @param lpszCaption\r
271                 The title of the empty page.\r
272         */\r
273         virtual CString GenerateEmptyPageMessage(LPCTSTR lpszEmptyPageMessage, LPCTSTR lpszCaption);\r
274 \r
275         /**\r
276         Will be called during creation process, to create the CTreeCtrl\r
277         object (the object, not the window!).\r
278 \r
279         Allows you to inject your own CTreeCtrl-derived classes.\r
280 \r
281         This default implementation simply creates a CTreeCtrl with new\r
282         and returns it.\r
283         */\r
284         virtual CTreeCtrl* CreatePageTreeObject();\r
285 \r
286         /**\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
290 \r
291         Allows you to inject your own CPropPageFrame-derived classes.\r
292 \r
293         This default implementation simply creates a CPropPageFrameTab with\r
294         new and returns it.\r
295         */\r
296         virtual CPropPageFrame* CreatePageFrame();\r
297 \r
298 // Implementation helpers\r
299 protected:\r
300         /**\r
301         Moves all childs by the specified amount of pixels.\r
302 \r
303         @param nDx\r
304                 Pixels to move the childs in horizontal direction (can be \r
305                 negative).\r
306         @param nDy\r
307                 Pixels to move the childs in vertical direction (can be \r
308                 negative).\r
309         */\r
310         void MoveChildWindows(int nDx, int nDy);\r
311 \r
312         /**\r
313         Refills the tree that contains the entries for the several pages.\r
314         */\r
315         void RefillPageTree();\r
316 \r
317         /**\r
318         Creates the specified path in the page tree and returns the handle\r
319         of the most child item created.\r
320 \r
321         @param lpszPath\r
322                 Path of the item to create (see description of this class).\r
323         @param hParentItem\r
324                 Handle of the item under which the path should be created or \r
325                 TVI_ROOT to start from the root.\r
326         */\r
327         HTREEITEM CreatePageTreeItem(LPCTSTR lpszPath, HTREEITEM hParent = TVI_ROOT);\r
328 \r
329         /**\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
332 \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
336         */\r
337         CString SplitPageTreePath(CString &strRest);\r
338 \r
339         /**\r
340         Tries to deactivate the current page, and hides it if successfull,\r
341         so that an empty page becomes visible.\r
342         \r
343         @return\r
344                 TRUE if the current page has been deactivated successfully,\r
345                 FALSE if the currently active page prevents a page change.\r
346         */\r
347         BOOL KillActiveCurrentPage();\r
348 \r
349         /**\r
350         Returns the page tree item, that representates the specified page\r
351         or NULL, if no such icon exists.\r
352 \r
353         @param nPage\r
354                 Zero based page index, for which the item to retrieve.\r
355         @param hRoot\r
356                 Item to start the search at or TVI_ROOT to search the whole\r
357                 tree.\r
358         */\r
359         HTREEITEM GetPageTreeItem(int nPage, HTREEITEM hRoot = TVI_ROOT);\r
360 \r
361         /**\r
362         Selects and shows the item, representing the specified page.\r
363 \r
364         @param nPage\r
365                 Zero based page index.\r
366 \r
367         @return\r
368                 TRUE on success, FALSE if no item does exist for the specified\r
369                 page.\r
370         */\r
371         BOOL SelectPageTreeItem(int nPage);\r
372 \r
373         /**\r
374         Selects and shows the tree item for the currently active page.\r
375 \r
376         @return\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
380         */\r
381         BOOL SelectCurrentPageTreeItem();\r
382 \r
383         /**\r
384         Updates the caption for the currently selected page (if the caption \r
385         is enabled).\r
386         */\r
387         void UpdateCaption();\r
388 \r
389         /**\r
390         Activates the previous page in the page order or the last one, if\r
391         the current one is the first.\r
392 \r
393         This method does never fail.\r
394         */\r
395         void ActivatePreviousPage();\r
396 \r
397         /**\r
398         Activates the next page in the page order or the first one, if the\r
399         current one is the last.\r
400 \r
401         This method does never fail.\r
402         */\r
403         void ActivateNextPage();\r
404 \r
405 // Overridings\r
406 protected:\r
407         //{{AFX_VIRTUAL(CTreePropSheet)\r
408         public:\r
409         virtual BOOL OnInitDialog();\r
410         //}}AFX_VIRTUAL\r
411 \r
412 // Message handlers\r
413 protected:\r
414         //{{AFX_MSG(CTreePropSheet)\r
415         afx_msg void OnDestroy();\r
416         //}}AFX_MSG\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
422 \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
426 \r
427 // Properties\r
428 private:\r
429         /** TRUE if we should use the tree control instead of the tab ctrl. */\r
430         BOOL m_bTreeViewMode;\r
431 \r
432         /** The tree control */\r
433         CTreeCtrl *m_pwndPageTree;\r
434 \r
435         /** The frame around the pages */\r
436         CPropPageFrame *m_pFrame;\r
437 \r
438         /** \r
439         TRUE, if a tree item selection by OnPageTreeSelChanged() is \r
440         performed currently.\r
441         */\r
442         BOOL m_bPageTreeSelChangedActive;\r
443 \r
444         /** TRUE if a page caption should be displayed, FALSE otherwise. */\r
445         BOOL m_bPageCaption;\r
446 \r
447         /** TRUE if images should be displayed in the tree. */\r
448         BOOL m_bTreeImages;\r
449 \r
450         /** Images to be displayed in the tree control. */\r
451         CImageList m_Images;\r
452 \r
453         /** Default images. */\r
454         CImageList m_DefaultImages;\r
455 \r
456         /** \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
459         page.\r
460         */\r
461         CString m_strEmptyPageMessage;\r
462 \r
463         /** The width of the page tree control in pixels. */\r
464         int m_nPageTreeWidth;\r
465 \r
466 // Static Properties\r
467 private:\r
468         /** The id of the tree view control, that shows the pages. */\r
469         static const UINT s_unPageTreeId;\r
470 };\r
471 \r
472 \r
473 } //namespace TreePropSheet\r
474 \r
475 /////////////////////////////////////////////////////////////////////////////\r
476 \r
477 //{{AFX_INSERT_LOCATION}}\r
478 // Microsoft Visual C++ fügt unmittelbar vor der vorhergehenden Zeile zusätzliche Deklarationen ein.\r
479 \r
480 #endif // AFX_TREEPROPSHEET_H__50695CFB_FCE4_4188_ADB4_BF05A5488E41__INCLUDED_\r