richtextformatdlg.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: richtext/richtextformatdlg.h
  3. // Purpose: interface of wxRichTextFormattingDialog*
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxRichTextFormattingDialogFactory
  9. This class provides pages for wxRichTextFormattingDialog, and allows other
  10. customization of the dialog.
  11. A default instance of this class is provided automatically.
  12. If you wish to change the behaviour of the formatting dialog (for example add
  13. or replace a page), you may derive from this class, override one or more
  14. functions, and call the static function
  15. wxRichTextFormattingDialog::SetFormattingDialogFactory.
  16. @library{wxrichtext}
  17. @category{richtext}
  18. */
  19. class wxRichTextFormattingDialogFactory : public wxObject
  20. {
  21. public:
  22. /**
  23. Constructor.
  24. */
  25. wxRichTextFormattingDialogFactory();
  26. /**
  27. Destructor.
  28. */
  29. virtual ~wxRichTextFormattingDialogFactory();
  30. /**
  31. Creates the main dialog buttons.
  32. */
  33. virtual bool CreateButtons(wxRichTextFormattingDialog* dialog);
  34. /**
  35. Creates a page, given a page identifier.
  36. */
  37. virtual wxPanel* CreatePage(int page, wxString& title,
  38. wxRichTextFormattingDialog* dialog);
  39. /**
  40. Creates all pages under the dialog's book control, also calling AddPage().
  41. */
  42. virtual bool CreatePages(long pages,
  43. wxRichTextFormattingDialog* dialog);
  44. /**
  45. Enumerate all available page identifiers.
  46. */
  47. virtual int GetPageId(int i) const;
  48. /**
  49. Gets the number of available page identifiers.
  50. */
  51. virtual int GetPageIdCount() const;
  52. /**
  53. Gets the image index for the given page identifier.
  54. */
  55. virtual int GetPageImage(int id) const;
  56. /**
  57. Set the property sheet style, called at the start of
  58. wxRichTextFormattingDialog::Create.
  59. */
  60. virtual bool SetSheetStyle(wxRichTextFormattingDialog* dialog);
  61. /**
  62. Invokes help for the dialog.
  63. */
  64. virtual bool ShowHelp(int page,
  65. wxRichTextFormattingDialog* dialog);
  66. };
  67. #define wxRICHTEXT_FORMAT_STYLE_EDITOR 0x0001
  68. #define wxRICHTEXT_FORMAT_FONT 0x0002
  69. #define wxRICHTEXT_FORMAT_TABS 0x0004
  70. #define wxRICHTEXT_FORMAT_BULLETS 0x0008
  71. #define wxRICHTEXT_FORMAT_INDENTS_SPACING 0x0010
  72. /**
  73. @class wxRichTextFormattingDialog
  74. This dialog allows the user to edit a character and/or paragraph style.
  75. In the constructor, specify the pages that will be created.
  76. Use wxRichTextFormattingDialog::GetStyle() to retrieve the common style
  77. for a given range, and then use wxRichTextFormattingDialog::ApplyStyle()
  78. to apply the user-selected formatting to a control.
  79. For example:
  80. @code
  81. wxRichTextRange range;
  82. if (m_richTextCtrl-HasSelection())
  83. range = m_richTextCtrl-GetSelectionRange();
  84. else
  85. range = wxRichTextRange(0, m_richTextCtrl-GetLastPosition()+1);
  86. int pages = wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_INDENTS_SPACING| \
  87. wxRICHTEXT_FORMAT_TABS|wxRICHTEXT_FORMAT_BULLETS;
  88. wxRichTextFormattingDialog formatDlg(pages, this);
  89. formatDlg.GetStyle(m_richTextCtrl, range);
  90. if (formatDlg.ShowModal() == wxID_OK)
  91. {
  92. formatDlg.ApplyStyle(m_richTextCtrl, range);
  93. }
  94. @endcode
  95. @library{wxrichtext}
  96. @category{richtext}
  97. */
  98. class wxRichTextFormattingDialog : public wxPropertySheetDialog
  99. {
  100. public:
  101. enum { Option_AllowPixelFontSize = 0x0001 };
  102. /**
  103. Default ctor.
  104. */
  105. wxRichTextFormattingDialog();
  106. /**
  107. Constructors.
  108. @param flags
  109. The pages to show.
  110. @param parent
  111. The dialog's parent.
  112. @param title
  113. The dialog's title.
  114. @param id
  115. The dialog's ID.
  116. @param pos
  117. The dialog's position.
  118. @param sz
  119. The dialog's size.
  120. @param style
  121. The dialog's window style.
  122. */
  123. wxRichTextFormattingDialog(long flags, wxWindow* parent, const wxString& title = "Formatting",
  124. wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
  125. const wxSize& sz = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE);
  126. /**
  127. Destructor.
  128. */
  129. virtual ~wxRichTextFormattingDialog();
  130. /**
  131. Apply attributes to the given range, only changing attributes that
  132. need to be changed.
  133. */
  134. virtual bool ApplyStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range,
  135. int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE);
  136. /**
  137. Creation: see wxRichTextFormattingDialog() "the constructor" for
  138. details about the parameters.
  139. */
  140. bool Create(long flags, wxWindow* parent,
  141. const wxString& title = wxGetTranslation("Formatting"), wxWindowID id = wxID_ANY,
  142. const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize,
  143. long style = wxDEFAULT_DIALOG_STYLE);
  144. //@{
  145. /**
  146. Gets the attributes being edited.
  147. */
  148. const wxTextAttr& GetAttributes() const;
  149. wxTextAttr& GetAttributes();
  150. //@}
  151. /**
  152. Helper for pages to get the top-level dialog.
  153. */
  154. static wxRichTextFormattingDialog* GetDialog(wxWindow* win);
  155. /**
  156. Helper for pages to get the attributes.
  157. */
  158. static wxTextAttr* GetDialogAttributes(wxWindow* win);
  159. /**
  160. Helper for pages to get the style.
  161. */
  162. static wxRichTextStyleDefinition* GetDialogStyleDefinition(wxWindow* win);
  163. /**
  164. Returns the object to be used to customize the dialog and provide pages.
  165. */
  166. static wxRichTextFormattingDialogFactory* GetFormattingDialogFactory();
  167. /**
  168. Returns the image list associated with the dialog, used for example if showing
  169. the dialog as a toolbook.
  170. */
  171. wxImageList* GetImageList() const;
  172. /**
  173. Gets common attributes from the given range and calls SetAttributes().
  174. Attributes that do not have common values in the given range
  175. will be omitted from the style's flags.
  176. */
  177. virtual bool GetStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range);
  178. /**
  179. Gets the associated style definition, if any.
  180. */
  181. virtual wxRichTextStyleDefinition* GetStyleDefinition() const;
  182. /**
  183. Gets the associated style sheet, if any.
  184. */
  185. virtual wxRichTextStyleSheet* GetStyleSheet() const;
  186. /**
  187. Sets the attributes to be edited.
  188. */
  189. void SetAttributes(const wxTextAttr& attr);
  190. /**
  191. Sets the dialog options, determining what the interface presents to the user.
  192. Currently the only option is Option_AllowPixelFontSize.
  193. */
  194. void SetOptions(int options) { m_options = options; }
  195. /**
  196. Gets the dialog options, determining what the interface presents to the user.
  197. Currently the only option is Option_AllowPixelFontSize.
  198. */
  199. int GetOptions() const { return m_options; }
  200. /**
  201. Returns @true if the given option is present.
  202. */
  203. bool HasOption(int option) const { return (m_options & option) != 0; }
  204. /**
  205. Sets the formatting factory object to be used for customization and page
  206. creation.
  207. It deletes the existing factory object.
  208. */
  209. static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory* factory);
  210. /**
  211. Sets the image list associated with the dialog's property sheet.
  212. */
  213. void SetImageList(wxImageList* imageList);
  214. /**
  215. Sets the attributes and optionally updates the display, if @a update is @true.
  216. */
  217. virtual bool SetStyle(const wxTextAttr& style, bool update = true);
  218. /**
  219. Sets the style definition and optionally update the display,
  220. if @a update is @true.
  221. */
  222. virtual bool SetStyleDefinition(const wxRichTextStyleDefinition& styleDef,
  223. wxRichTextStyleSheet* sheet,
  224. bool update = true);
  225. /**
  226. Updates the display.
  227. */
  228. virtual bool UpdateDisplay();
  229. };