1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtext/richtextformatdlg.h
3 // Purpose: interface of wxRichTextFormattingDialog*
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxRichTextFormattingDialogFactory
12 This class provides pages for wxRichTextFormattingDialog, and allows other
13 customization of the dialog.
15 A default instance of this class is provided automatically.
16 If you wish to change the behaviour of the formatting dialog (for example add
17 or replace a page), you may derive from this class, override one or more
18 functions, and call the static function
19 wxRichTextFormattingDialog::SetFormattingDialogFactory.
24 class wxRichTextFormattingDialogFactory
: public wxObject
30 wxRichTextFormattingDialogFactory();
35 virtual ~wxRichTextFormattingDialogFactory();
38 Creates the main dialog buttons.
40 virtual bool CreateButtons(wxRichTextFormattingDialog
* dialog
);
43 Creates a page, given a page identifier.
45 virtual wxPanel
* CreatePage(int page
, wxString
& title
,
46 wxRichTextFormattingDialog
* dialog
);
49 Creates all pages under the dialog's book control, also calling AddPage().
51 virtual bool CreatePages(long pages
,
52 wxRichTextFormattingDialog
* dialog
);
55 Enumerate all available page identifiers.
57 virtual int GetPageId(int i
) const;
60 Gets the number of available page identifiers.
62 virtual int GetPageIdCount() const;
65 Gets the image index for the given page identifier.
67 virtual int GetPageImage(int id
) const;
70 Set the property sheet style, called at the start of
71 wxRichTextFormattingDialog::Create.
73 virtual bool SetSheetStyle(wxRichTextFormattingDialog
* dialog
);
76 Invokes help for the dialog.
78 virtual bool ShowHelp(int page
,
79 wxRichTextFormattingDialog
* dialog
);
84 #define wxRICHTEXT_FORMAT_STYLE_EDITOR 0x0001
85 #define wxRICHTEXT_FORMAT_FONT 0x0002
86 #define wxRICHTEXT_FORMAT_TABS 0x0004
87 #define wxRICHTEXT_FORMAT_BULLETS 0x0008
88 #define wxRICHTEXT_FORMAT_INDENTS_SPACING 0x0010
91 @class wxRichTextFormattingDialog
93 This dialog allows the user to edit a character and/or paragraph style.
95 In the constructor, specify the pages that will be created.
96 Use wxRichTextFormattingDialog::GetStyle() to retrieve the common style
97 for a given range, and then use wxRichTextFormattingDialog::ApplyStyle()
98 to apply the user-selected formatting to a control.
102 wxRichTextRange range;
103 if (m_richTextCtrl-HasSelection())
104 range = m_richTextCtrl-GetSelectionRange();
106 range = wxRichTextRange(0, m_richTextCtrl-GetLastPosition()+1);
108 int pages = wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_INDENTS_SPACING| \
109 wxRICHTEXT_FORMAT_TABS|wxRICHTEXT_FORMAT_BULLETS;
111 wxRichTextFormattingDialog formatDlg(pages, this);
112 formatDlg.GetStyle(m_richTextCtrl, range);
114 if (formatDlg.ShowModal() == wxID_OK)
116 formatDlg.ApplyStyle(m_richTextCtrl, range);
123 class wxRichTextFormattingDialog
: public wxPropertySheetDialog
126 enum { Option_AllowPixelFontSize
= 0x0001 };
131 wxRichTextFormattingDialog();
145 The dialog's position.
149 The dialog's window style.
151 wxRichTextFormattingDialog(long flags
, wxWindow
* parent
, const wxString
& title
= "Formatting",
152 wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
153 const wxSize
& sz
= wxDefaultSize
, long style
= wxDEFAULT_DIALOG_STYLE
);
158 virtual ~wxRichTextFormattingDialog();
161 Apply attributes to the given range, only changing attributes that
164 virtual bool ApplyStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
,
165 int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
);
168 Creation: see wxRichTextFormattingDialog() "the constructor" for
169 details about the parameters.
171 bool Create(long flags
, wxWindow
* parent
,
172 const wxString
& title
= wxGetTranslation("Formatting"), wxWindowID id
= wxID_ANY
,
173 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
174 long style
= wxDEFAULT_DIALOG_STYLE
);
178 Gets the attributes being edited.
180 const wxTextAttr
& GetAttributes() const;
181 wxTextAttr
& GetAttributes();
185 Helper for pages to get the top-level dialog.
187 static wxRichTextFormattingDialog
* GetDialog(wxWindow
* win
);
190 Helper for pages to get the attributes.
192 static wxTextAttr
* GetDialogAttributes(wxWindow
* win
);
195 Helper for pages to get the style.
197 static wxRichTextStyleDefinition
* GetDialogStyleDefinition(wxWindow
* win
);
200 Returns the object to be used to customize the dialog and provide pages.
202 static wxRichTextFormattingDialogFactory
* GetFormattingDialogFactory();
205 Returns the image list associated with the dialog, used for example if showing
206 the dialog as a toolbook.
208 wxImageList
* GetImageList() const;
211 Gets common attributes from the given range and calls SetAttributes().
212 Attributes that do not have common values in the given range
213 will be omitted from the style's flags.
215 virtual bool GetStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
);
218 Gets the associated style definition, if any.
220 virtual wxRichTextStyleDefinition
* GetStyleDefinition() const;
223 Gets the associated style sheet, if any.
225 virtual wxRichTextStyleSheet
* GetStyleSheet() const;
228 Sets the attributes to be edited.
230 void SetAttributes(const wxTextAttr
& attr
);
233 Sets the dialog options, determining what the interface presents to the user.
234 Currently the only option is Option_AllowPixelFontSize.
236 void SetOptions(int options
) { m_options
= options
; }
239 Gets the dialog options, determining what the interface presents to the user.
240 Currently the only option is Option_AllowPixelFontSize.
242 int GetOptions() const { return m_options
; }
245 Returns @true if the given option is present.
247 bool HasOption(int option
) const { return (m_options
& option
) != 0; }
250 Sets the formatting factory object to be used for customization and page
253 It deletes the existing factory object.
255 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
);
258 Sets the image list associated with the dialog's property sheet.
260 void SetImageList(wxImageList
* imageList
);
263 Sets the attributes and optionally updates the display, if @a update is @true.
265 virtual bool SetStyle(const wxTextAttr
& style
, bool update
= true);
268 Sets the style definition and optionally update the display,
269 if @a update is @true.
271 virtual bool SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
,
272 wxRichTextStyleSheet
* sheet
,
278 virtual bool UpdateDisplay();