richtextuicustomization.h 4.5 KB

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