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"
24 #include "wx/bookctrl.h"
27 #include "wx/htmllbox.h"
30 #include "wx/richtext/richtextbuffer.h"
31 #include "wx/richtext/richtextstyles.h"
33 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog
;
34 class WXDLLIMPEXP_CORE wxImageList
;
37 * Flags determining the pages to be created in the dialog
40 #define wxRICHTEXT_FORMAT_STYLE_EDITOR 0x0001
41 #define wxRICHTEXT_FORMAT_FONT 0x0002
42 #define wxRICHTEXT_FORMAT_TABS 0x0004
43 #define wxRICHTEXT_FORMAT_BULLETS 0x0008
44 #define wxRICHTEXT_FORMAT_INDENTS_SPACING 0x0010
47 * Shorthand for common combinations of pages
50 #define wxRICHTEXT_FORMAT_PARAGRAPH (wxRICHTEXT_FORMAT_INDENTS_SPACING | wxRICHTEXT_FORMAT_BULLETS | wxRICHTEXT_FORMAT_TABS | wxRICHTEXT_FORMAT_FONT)
51 #define wxRICHTEXT_FORMAT_CHARACTER (wxRICHTEXT_FORMAT_FONT)
52 #define wxRICHTEXT_FORMAT_STYLE (wxRICHTEXT_FORMAT_PARAGRAPH | wxRICHTEXT_FORMAT_STYLE_EDITOR)
55 * Factory for formatting dialog
58 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialogFactory
: public wxObject
61 wxRichTextFormattingDialogFactory() {}
62 virtual ~wxRichTextFormattingDialogFactory() {}
66 /// Create all pages, under the dialog's book control, also calling AddPage
67 virtual bool CreatePages(long pages
, wxRichTextFormattingDialog
* dialog
);
69 /// Create a page, given a page identifier
70 virtual wxPanel
* CreatePage(int page
, wxString
& title
, wxRichTextFormattingDialog
* dialog
);
72 /// Enumerate all available page identifiers
73 virtual int GetPageId(int i
) const;
75 /// Get the number of available page identifiers
76 virtual int GetPageIdCount() const;
78 /// Get the image index for the given page identifier
79 virtual int GetPageImage(int WXUNUSED(id
)) const { return -1; }
81 /// Invoke help for the dialog
82 virtual bool ShowHelp(int WXUNUSED(page
), wxRichTextFormattingDialog
* WXUNUSED(dialog
)) { return false; }
84 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
85 virtual bool SetSheetStyle(wxRichTextFormattingDialog
* dialog
);
87 /// Create the main dialog buttons
88 virtual bool CreateButtons(wxRichTextFormattingDialog
* dialog
);
92 * Formatting dialog for a wxRichTextCtrl
95 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog
: public wxPropertySheetDialog
97 DECLARE_CLASS(wxRichTextFormattingDialog
)
99 wxRichTextFormattingDialog() { Init(); }
101 wxRichTextFormattingDialog(long flags
, wxWindow
* parent
, const wxString
& title
= _("Formatting"), wxWindowID id
= wxID_ANY
,
102 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
103 long style
= wxDEFAULT_DIALOG_STYLE
)
106 Create(flags
, parent
, title
, id
, pos
, sz
, style
);
109 ~wxRichTextFormattingDialog();
113 bool Create(long flags
, wxWindow
* parent
, const wxString
& title
, wxWindowID id
,
114 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
115 long style
= wxDEFAULT_DIALOG_STYLE
);
117 /// Get attributes from the given range
118 virtual bool GetStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
);
120 /// Set the attributes and optionally update the display
121 virtual bool SetStyle(const wxTextAttrEx
& style
, bool update
= true);
123 /// Set the style definition and optionally update the display
124 virtual bool SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
, wxRichTextStyleSheet
* sheet
, bool update
= true);
126 /// Get the style definition, if any
127 virtual wxRichTextStyleDefinition
* GetStyleDefinition() const { return m_styleDefinition
; }
129 /// Get the style sheet, if any
130 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
132 /// Update the display
133 virtual bool UpdateDisplay();
135 /// Apply attributes to the given range
136 virtual bool ApplyStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
);
138 /// Gets and sets the attributes
139 const wxTextAttrEx
& GetAttributes() const { return m_attributes
; }
140 wxTextAttrEx
& GetAttributes() { return m_attributes
; }
141 void SetAttributes(const wxTextAttrEx
& attr
) { m_attributes
= attr
; }
143 /// Transfers the data and from to the window
144 virtual bool TransferDataToWindow();
145 virtual bool TransferDataFromWindow();
147 /// Apply the styles when a different tab is selected, so the previews are
149 void OnTabChanged(wxBookCtrlEvent
& event
);
151 /// Set/get image list
152 void SetImageList(wxImageList
* imageList
) { m_imageList
= imageList
; }
153 wxImageList
* GetImageList() const { return m_imageList
; }
155 /// Get/set formatting factory object
156 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
);
157 static wxRichTextFormattingDialogFactory
* GetFormattingDialogFactory() { return ms_FormattingDialogFactory
; }
159 /// Helper for pages to get the top-level dialog
160 static wxRichTextFormattingDialog
* GetDialog(wxWindow
* win
);
162 /// Helper for pages to get the attributes
163 static wxTextAttrEx
* GetDialogAttributes(wxWindow
* win
);
165 /// Helper for pages to get the style
166 static wxRichTextStyleDefinition
* GetDialogStyleDefinition(wxWindow
* win
);
170 wxImageList
* m_imageList
;
171 wxTextAttrEx m_attributes
;
172 wxRichTextStyleDefinition
* m_styleDefinition
;
173 wxRichTextStyleSheet
* m_styleSheet
;
175 static wxRichTextFormattingDialogFactory
* ms_FormattingDialogFactory
;
177 DECLARE_EVENT_TABLE()
180 //-----------------------------------------------------------------------------
181 // helper class - wxRichTextFontPreviewCtrl
182 //-----------------------------------------------------------------------------
184 class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl
: public wxWindow
187 wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
188 wxWindow(parent
, id
, pos
, sz
, style
)
190 SetBackgroundColour(*wxWHITE
);
194 void OnPaint(wxPaintEvent
& event
);
195 DECLARE_EVENT_TABLE()
199 * A control for displaying a small preview of a colour or bitmap
202 class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl
: public wxControl
204 DECLARE_CLASS(wxRichTextColourSwatchCtrl
)
206 wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
207 ~wxRichTextColourSwatchCtrl();
209 void OnMouseEvent(wxMouseEvent
& event
);
211 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
213 wxColour
& GetColour() { return m_colour
; }
215 virtual wxSize
DoGetBestSize() const { return GetSize(); }
220 DECLARE_EVENT_TABLE()
224 * wxRichTextFontListBox class declaration
225 * A listbox to display fonts.
228 class WXDLLIMPEXP_RICHTEXT wxRichTextFontListBox
: public wxHtmlListBox
230 DECLARE_CLASS(wxRichTextFontListBox
)
231 DECLARE_EVENT_TABLE()
234 wxRichTextFontListBox()
238 wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
239 const wxSize
& size
= wxDefaultSize
, long style
= 0);
240 virtual ~wxRichTextFontListBox();
246 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
247 const wxSize
& size
= wxDefaultSize
, long style
= 0);
249 /// Creates a suitable HTML fragment for a font
250 wxString
CreateHTML(const wxString
& facename
) const;
252 /// Get font name for index
253 wxString
GetFaceName(size_t i
) const ;
255 /// Set selection for string, returning the index.
256 int SetFaceNameSelection(const wxString
& name
);
258 /// Updates the font list
261 /// Does this face name exist?
262 bool HasFaceName(const wxString
& faceName
) const { return m_faceNames
.Index(faceName
) != wxNOT_FOUND
; }
264 /// Returns the array of face names
265 const wxArrayString
& GetFaceNames() const { return m_faceNames
; }
268 /// Returns the HTML for this item
269 virtual wxString
OnGetItem(size_t n
) const;
273 wxArrayString m_faceNames
;
280 // _WX_RICHTEXTFORMATDLG_H_