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
;
33 class WXDLLIMPEXP_CORE wxImageList
;
36 * Flags determining the pages to be created in the dialog
39 #define wxRICHTEXT_FORMAT_STYLE_EDITOR 0x0001
40 #define wxRICHTEXT_FORMAT_FONT 0x0002
41 #define wxRICHTEXT_FORMAT_TABS 0x0004
42 #define wxRICHTEXT_FORMAT_BULLETS 0x0008
43 #define wxRICHTEXT_FORMAT_INDENTS_SPACING 0x0010
46 * Shorthand for common combinations of pages
49 #define wxRICHTEXT_FORMAT_PARAGRAPH (wxRICHTEXT_FORMAT_INDENTS_SPACING | wxRICHTEXT_FORMAT_BULLETS | wxRICHTEXT_FORMAT_TABS | wxRICHTEXT_FORMAT_FONT)
50 #define wxRICHTEXT_FORMAT_CHARACTER (wxRICHTEXT_FORMAT_FONT)
51 #define wxRICHTEXT_FORMAT_STYLE (wxRICHTEXT_FORMAT_PARAGRAPH | wxRICHTEXT_FORMAT_STYLE_EDITOR)
54 * Factory for formatting dialog
57 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialogFactory
: public wxObject
60 wxRichTextFormattingDialogFactory() {}
61 virtual ~wxRichTextFormattingDialogFactory() {}
65 /// Create all pages, under the dialog's book control, also calling AddPage
66 virtual bool CreatePages(long pages
, wxRichTextFormattingDialog
* dialog
);
68 /// Create a page, given a page identifier
69 virtual wxPanel
* CreatePage(int page
, wxString
& title
, wxRichTextFormattingDialog
* dialog
);
71 /// Enumerate all available page identifiers
72 virtual int GetPageId(int i
) const;
74 /// Get the number of available page identifiers
75 virtual int GetPageIdCount() const;
77 /// Get the image index for the given page identifier
78 virtual int GetPageImage(int WXUNUSED(id
)) const { return -1; }
80 /// Invoke help for the dialog
81 virtual bool ShowHelp(int WXUNUSED(page
), wxRichTextFormattingDialog
* WXUNUSED(dialog
)) { return false; }
83 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
84 virtual bool SetSheetStyle(wxRichTextFormattingDialog
* dialog
);
86 /// Create the main dialog buttons
87 virtual bool CreateButtons(wxRichTextFormattingDialog
* dialog
);
91 * Formatting dialog for a wxRichTextCtrl
94 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog
: public wxPropertySheetDialog
96 DECLARE_CLASS(wxRichTextFormattingDialog
)
98 wxRichTextFormattingDialog() { Init(); }
100 wxRichTextFormattingDialog(long flags
, wxWindow
* parent
, const wxString
& title
= _("Formatting"), wxWindowID id
= wxID_ANY
,
101 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
102 long style
= wxDEFAULT_DIALOG_STYLE
)
105 Create(flags
, parent
, title
, id
, pos
, sz
, style
);
108 ~wxRichTextFormattingDialog();
112 bool Create(long flags
, wxWindow
* parent
, const wxString
& title
, wxWindowID id
,
113 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
114 long style
= wxDEFAULT_DIALOG_STYLE
);
116 /// Get attributes from the given range
117 virtual bool GetStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
);
119 /// Set the attributes and optionally update the display
120 virtual bool SetStyle(const wxTextAttrEx
& style
, bool update
= true);
122 /// Set the style definition and optionally update the display
123 virtual bool SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
, wxRichTextStyleSheet
* sheet
, bool update
= true);
125 /// Get the style definition, if any
126 virtual wxRichTextStyleDefinition
* GetStyleDefinition() const { return m_styleDefinition
; }
128 /// Get the style sheet, if any
129 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
131 /// Update the display
132 virtual bool UpdateDisplay();
134 /// Apply attributes to the given range
135 virtual bool ApplyStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
);
137 /// Gets and sets the attributes
138 const wxTextAttrEx
& GetAttributes() const { return m_attributes
; }
139 wxTextAttrEx
& GetAttributes() { return m_attributes
; }
140 void SetAttributes(const wxTextAttrEx
& attr
) { m_attributes
= attr
; }
142 /// Transfers the data and from to the window
143 virtual bool TransferDataToWindow();
144 virtual bool TransferDataFromWindow();
146 /// Apply the styles when a different tab is selected, so the previews are
148 void OnTabChanged(wxNotebookEvent
& event
);
150 /// Set/get image list
151 void SetImageList(wxImageList
* imageList
) { m_imageList
= imageList
; }
152 wxImageList
* GetImageList() const { return m_imageList
; }
154 /// Get/set formatting factory object
155 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
);
156 static wxRichTextFormattingDialogFactory
* GetFormattingDialogFactory() { return ms_FormattingDialogFactory
; }
158 /// Helper for pages to get the top-level dialog
159 static wxRichTextFormattingDialog
* GetDialog(wxWindow
* win
);
161 /// Helper for pages to get the attributes
162 static wxTextAttrEx
* GetDialogAttributes(wxWindow
* win
);
164 /// Helper for pages to get the style
165 static wxRichTextStyleDefinition
* GetDialogStyleDefinition(wxWindow
* win
);
169 wxImageList
* m_imageList
;
170 wxTextAttrEx m_attributes
;
171 wxRichTextStyleDefinition
* m_styleDefinition
;
172 wxRichTextStyleSheet
* m_styleSheet
;
174 static wxRichTextFormattingDialogFactory
* ms_FormattingDialogFactory
;
176 DECLARE_EVENT_TABLE()
179 //-----------------------------------------------------------------------------
180 // helper class - wxRichTextFontPreviewCtrl
181 //-----------------------------------------------------------------------------
183 class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl
: public wxWindow
186 wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
187 wxWindow(parent
, id
, pos
, sz
, style
)
189 SetBackgroundColour(*wxWHITE
);
193 void OnPaint(wxPaintEvent
& event
);
194 DECLARE_EVENT_TABLE()
198 * A control for displaying a small preview of a colour or bitmap
201 class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl
: public wxControl
203 DECLARE_CLASS(wxRichTextColourSwatchCtrl
)
205 wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
206 ~wxRichTextColourSwatchCtrl();
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_