]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtextuicustomization.h
ea20a60d69e09faab3f2c6f7d9e1fa6568971558
[wxWidgets.git] / include / wx / richtext / richtextuicustomization.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextuicustomization.h
3 // Purpose: UI customization base class for wxRTC
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2010-11-14
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_RICHTEXTUICUSTOMIZATION_H_
13 #define _WX_RICHTEXTUICUSTOMIZATION_H_
14
15 #if wxUSE_RICHTEXT
16
17 /**
18 @class wxRichTextUICustomization
19 The base class for functionality to plug in to various rich text control dialogs,
20 currently allowing the application to respond to Help button clicks without the
21 need to derive new dialog classes.
22
23 The application will typically have calls like this in its initialisation:
24
25 wxRichTextFormattingDialog::SetHelpId(ID_HELP_FORMATTINGDIALOG);
26 wxRichTextFormattingDialog::SetUICustomization(& wxGetApp().GetRichTextUICustomization());
27 wxRichTextBordersPage::SetHelpId(ID_HELP_BORDERSPAGE);
28
29 Only the wxRichTextFormattingDialog class needs to have its customization object and help id set,
30 though the application set them for individual pages if it wants.
31 **/
32
33 class WXDLLIMPEXP_RICHTEXT wxRichTextUICustomization
34 {
35 public:
36 wxRichTextUICustomization() {}
37 virtual ~wxRichTextUICustomization() {}
38
39 /// Show the help given the current active window, and a help topic id.
40 virtual bool ShowHelp(wxWindow* win, long id) = 0;
41 };
42
43 /**
44 @class wxRichTextHelpInfo
45 This class is used as a static member of dialogs, to store the help topic for the dialog
46 and also the customization object that will allow help to be shown appropriately for the application.
47 **/
48
49 class WXDLLIMPEXP_RICHTEXT wxRichTextHelpInfo
50 {
51 public:
52 wxRichTextHelpInfo()
53 {
54 m_helpTopic = -1;
55 m_uiCustomization = NULL;
56 }
57 virtual ~wxRichTextHelpInfo() {}
58
59 virtual bool ShowHelp(wxWindow* win)
60 {
61 if (m_uiCustomization && m_helpTopic != -1)
62 return m_uiCustomization->ShowHelp(win, m_helpTopic);
63 else
64 return false;
65 }
66
67 /// Get the help topic identifier.
68 long GetHelpId() const { return m_helpTopic; }
69
70 /// Set the help topic identifier.
71 void SetHelpId(long id) { m_helpTopic = id; }
72
73 /// Get the UI customization object.
74 wxRichTextUICustomization* GetUICustomization() const { return m_uiCustomization; }
75
76 /// Set the UI customization object.
77 void SetUICustomization(wxRichTextUICustomization* customization) { m_uiCustomization = customization; }
78
79 /// Is there a valid help topic id?
80 bool HasHelpId() const { return m_helpTopic != -1; }
81
82 /// Is there a valid customization object?
83 bool HasUICustomization() const { return m_uiCustomization != NULL; }
84
85 protected:
86 wxRichTextUICustomization* m_uiCustomization;
87 long m_helpTopic;
88 };
89
90 /// Add this to the base class of dialogs
91
92 #define DECLARE_BASE_CLASS_HELP_PROVISION() \
93 virtual long GetHelpId() const = 0; \
94 virtual wxRichTextUICustomization* GetUICustomization() const = 0; \
95 virtual bool ShowHelp(wxWindow* win) = 0;
96
97 /// A macro to make it easy to add help topic provision and UI customization
98 /// to a class. Optionally, add virtual functions to a base class
99 /// using DECLARE_BASE_CLASS_HELP_PROVISION. This means that the formatting dialog
100 /// can obtain help topics from its individual pages without needing
101 /// to know in advance what page classes are being used, allowing for extension
102 /// of the formatting dialog.
103
104 #define DECLARE_HELP_PROVISION() \
105 virtual long GetHelpId() const { return sm_helpInfo.GetHelpId(); } \
106 virtual void SetHelpId(long id) { sm_helpInfo.SetHelpId(id); } \
107 virtual wxRichTextUICustomization* GetUICustomization() const { return sm_helpInfo.GetUICustomization(); } \
108 virtual void SetUICustomization(wxRichTextUICustomization* customization) { sm_helpInfo.SetUICustomization(customization); } \
109 virtual bool ShowHelp(wxWindow* win) { return sm_helpInfo.ShowHelp(win); } \
110 protected: \
111 static wxRichTextHelpInfo sm_helpInfo; \
112 public:
113
114 /// Add this to the implementation file for each dialog that needs help provision.
115
116 #define IMPLEMENT_HELP_PROVISION(theClass) \
117 wxRichTextHelpInfo theClass::sm_helpInfo;
118
119 #endif
120 // wxUSE_RICHTEXT
121
122 #endif
123 // _WX_RICHTEXTUICUSTOMIZATION_H_