1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextformatdlg.h
3 // Purpose: Formatting dialog for wxRichTextCtrl
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_RICHTEXTFORMATDLG_H_
13 #define _WX_RICHTEXTFORMATDLG_H_
23 #include "wx/propdlg.h"
25 #include "wx/htmllbox.h"
28 #include "wx/richtext/richtextbuffer.h"
29 #include "wx/richtext/richtextstyles.h"
31 class WXDLLEXPORT wxNotebookEvent
;
32 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog
;
35 * Flags determining the pages to be created in the dialog
38 #define wxRICHTEXT_FORMAT_STYLE_EDITOR 0x0001
39 #define wxRICHTEXT_FORMAT_FONT 0x0002
40 #define wxRICHTEXT_FORMAT_TABS 0x0004
41 #define wxRICHTEXT_FORMAT_BULLETS 0x0008
42 #define wxRICHTEXT_FORMAT_INDENTS_SPACING 0x0010
45 * Shorthand for common combinations of pages
48 #define wxRICHTEXT_FORMAT_PARAGRAPH (wxRICHTEXT_FORMAT_INDENTS_SPACING | wxRICHTEXT_FORMAT_BULLETS | wxRICHTEXT_FORMAT_TABS | wxRICHTEXT_FORMAT_FONT)
49 #define wxRICHTEXT_FORMAT_CHARACTER (wxRICHTEXT_FORMAT_FONT)
50 #define wxRICHTEXT_FORMAT_STYLE (wxRICHTEXT_FORMAT_PARAGRAPH | wxRICHTEXT_FORMAT_STYLE_EDITOR)
53 * Factory for formatting dialog
56 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialogFactory
: public wxObject
59 wxRichTextFormattingDialogFactory() {}
60 virtual ~wxRichTextFormattingDialogFactory() {}
64 /// Create all pages, under the dialog's book control, also calling AddPage
65 virtual bool CreatePages(long pages
, wxRichTextFormattingDialog
* dialog
);
67 /// Create a page, given a page identifier
68 virtual wxPanel
* CreatePage(int page
, wxString
& title
, wxRichTextFormattingDialog
* dialog
);
70 /// Enumerate all available page identifiers
71 virtual int GetPageId(int i
) const;
73 /// Get the number of available page identifiers
74 virtual int GetPageIdCount() const;
76 /// Get the image index for the given page identifier
77 virtual int GetPageImage(int WXUNUSED(id
)) const { return -1; }
79 /// Invoke help for the dialog
80 virtual bool ShowHelp(int WXUNUSED(page
), wxRichTextFormattingDialog
* WXUNUSED(dialog
)) { return false; }
82 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
83 virtual bool SetSheetStyle(wxRichTextFormattingDialog
* dialog
);
85 /// Create the main dialog buttons
86 virtual bool CreateButtons(wxRichTextFormattingDialog
* dialog
);
90 * Formatting dialog for a wxRichTextCtrl
93 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog
: public wxPropertySheetDialog
95 DECLARE_CLASS(wxRichTextFormattingDialog
)
97 wxRichTextFormattingDialog() { Init(); }
99 wxRichTextFormattingDialog(long flags
, wxWindow
* parent
, const wxString
& title
= _("Formatting"), wxWindowID id
= wxID_ANY
,
100 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
101 long style
= wxDEFAULT_DIALOG_STYLE
)
104 Create(flags
, parent
, title
, id
, pos
, sz
, style
);
107 ~wxRichTextFormattingDialog();
111 bool Create(long flags
, wxWindow
* parent
, const wxString
& title
, wxWindowID id
,
112 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
113 long style
= wxDEFAULT_DIALOG_STYLE
);
115 /// Get attributes from the given range
116 virtual bool GetStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
);
118 /// Set the attributes and optionally update the display
119 virtual bool SetStyle(const wxTextAttrEx
& style
, bool update
= true);
121 /// Set the style definition and optionally update the display
122 virtual bool SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
, wxRichTextStyleSheet
* sheet
, bool update
= true);
124 /// Get the style definition, if any
125 virtual wxRichTextStyleDefinition
* GetStyleDefinition() const { return m_styleDefinition
; }
127 /// Get the style sheet, if any
128 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
130 /// Update the display
131 virtual bool UpdateDisplay();
133 /// Apply attributes to the given range
134 virtual bool ApplyStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
);
136 /// Gets and sets the attributes
137 const wxTextAttrEx
& GetAttributes() const { return m_attributes
; }
138 wxTextAttrEx
& GetAttributes() { return m_attributes
; }
139 void SetAttributes(const wxTextAttrEx
& attr
) { m_attributes
= attr
; }
141 /// Transfers the data and from to the window
142 virtual bool TransferDataToWindow();
143 virtual bool TransferDataFromWindow();
145 /// Apply the styles when a different tab is selected, so the previews are
147 void OnTabChanged(wxNotebookEvent
& event
);
149 /// Set/get image list
150 void SetImageList(wxImageList
* imageList
) { m_imageList
= imageList
; }
151 wxImageList
* GetImageList() const { return m_imageList
; }
153 /// Get/set formatting factory object
154 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
);
155 static wxRichTextFormattingDialogFactory
* GetFormattingDialogFactory() { return ms_FormattingDialogFactory
; }
157 /// Helper for pages to get the top-level dialog
158 static wxRichTextFormattingDialog
* GetDialog(wxWindow
* win
);
160 /// Helper for pages to get the attributes
161 static wxTextAttrEx
* GetDialogAttributes(wxWindow
* win
);
163 /// Helper for pages to get the style
164 static wxRichTextStyleDefinition
* GetDialogStyleDefinition(wxWindow
* win
);
168 wxImageList
* m_imageList
;
169 wxTextAttrEx m_attributes
;
170 wxRichTextStyleDefinition
* m_styleDefinition
;
171 wxRichTextStyleSheet
* m_styleSheet
;
173 static wxRichTextFormattingDialogFactory
* ms_FormattingDialogFactory
;
175 DECLARE_EVENT_TABLE()
178 //-----------------------------------------------------------------------------
179 // helper class - wxRichTextFontPreviewCtrl
180 //-----------------------------------------------------------------------------
182 class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl
: public wxWindow
185 wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
186 wxWindow(parent
, id
, pos
, sz
, style
)
188 SetBackgroundColour(*wxWHITE
);
192 void OnPaint(wxPaintEvent
& event
);
193 DECLARE_EVENT_TABLE()
197 * A control for displaying a small preview of a colour or bitmap
200 class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl
: public wxControl
202 DECLARE_CLASS(wxRichTextColourSwatchCtrl
)
204 wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
205 ~wxRichTextColourSwatchCtrl();
207 void OnPaint(wxPaintEvent
& event
);
208 void OnMouseEvent(wxMouseEvent
& event
);
210 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
212 wxColour
& GetColour() { return m_colour
; }
214 virtual wxSize
DoGetBestSize() const { return GetSize(); }
219 DECLARE_EVENT_TABLE()
223 * wxRichTextFontListBox class declaration
224 * A listbox to display fonts.
227 class WXDLLIMPEXP_RICHTEXT wxRichTextFontListBox
: public wxHtmlListBox
229 DECLARE_CLASS(wxRichTextFontListBox
)
230 DECLARE_EVENT_TABLE()
233 wxRichTextFontListBox()
237 wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
238 const wxSize
& size
= wxDefaultSize
, long style
= 0);
239 virtual ~wxRichTextFontListBox();
245 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
246 const wxSize
& size
= wxDefaultSize
, long style
= 0);
248 /// Creates a suitable HTML fragment for a font
249 wxString
CreateHTML(const wxString
& facename
) const;
251 /// Get font name for index
252 wxString
GetFaceName(size_t i
) const ;
254 /// Set selection for string, returning the index.
255 int SetFaceNameSelection(const wxString
& name
);
257 /// Updates the font list
260 /// Does this face name exist?
261 bool HasFaceName(const wxString
& faceName
) const { return m_faceNames
.Index(faceName
) != wxNOT_FOUND
; }
263 /// Returns the array of face names
264 const wxArrayString
& GetFaceNames() const { return m_faceNames
; }
267 /// Returns the HTML for this item
268 virtual wxString
OnGetItem(size_t n
) const;
272 wxArrayString m_faceNames
;
279 // _WX_RICHTEXTFORMATDLG_H_