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 /// Respond to help command
152 void OnHelp(wxCommandEvent
& event
);
154 /// Set/get image list
155 void SetImageList(wxImageList
* imageList
) { m_imageList
= imageList
; }
156 wxImageList
* GetImageList() const { return m_imageList
; }
158 /// Get/set formatting factory object
159 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
);
160 static wxRichTextFormattingDialogFactory
* GetFormattingDialogFactory() { return ms_FormattingDialogFactory
; }
162 /// Helper for pages to get the top-level dialog
163 static wxRichTextFormattingDialog
* GetDialog(wxWindow
* win
);
165 /// Helper for pages to get the attributes
166 static wxTextAttrEx
* GetDialogAttributes(wxWindow
* win
);
168 /// Helper for pages to get the style
169 static wxRichTextStyleDefinition
* GetDialogStyleDefinition(wxWindow
* win
);
171 /// Map book control page index to our page id
172 void AddPageId(int id
) { m_pageIds
.Add(id
); }
176 wxImageList
* m_imageList
;
177 wxTextAttrEx m_attributes
;
178 wxRichTextStyleDefinition
* m_styleDefinition
;
179 wxRichTextStyleSheet
* m_styleSheet
;
180 wxArrayInt m_pageIds
; // mapping of book control indexes to page ids
182 static wxRichTextFormattingDialogFactory
* ms_FormattingDialogFactory
;
184 DECLARE_EVENT_TABLE()
187 //-----------------------------------------------------------------------------
188 // helper class - wxRichTextFontPreviewCtrl
189 //-----------------------------------------------------------------------------
191 class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl
: public wxWindow
194 wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
195 wxWindow(parent
, id
, pos
, sz
, style
)
197 SetBackgroundColour(*wxWHITE
);
201 void OnPaint(wxPaintEvent
& event
);
202 DECLARE_EVENT_TABLE()
206 * A control for displaying a small preview of a colour or bitmap
209 class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl
: public wxControl
211 DECLARE_CLASS(wxRichTextColourSwatchCtrl
)
213 wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
214 ~wxRichTextColourSwatchCtrl();
216 void OnMouseEvent(wxMouseEvent
& event
);
218 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
220 wxColour
& GetColour() { return m_colour
; }
222 virtual wxSize
DoGetBestSize() const { return GetSize(); }
227 DECLARE_EVENT_TABLE()
231 * wxRichTextFontListBox class declaration
232 * A listbox to display fonts.
235 class WXDLLIMPEXP_RICHTEXT wxRichTextFontListBox
: public wxHtmlListBox
237 DECLARE_CLASS(wxRichTextFontListBox
)
238 DECLARE_EVENT_TABLE()
241 wxRichTextFontListBox()
245 wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
246 const wxSize
& size
= wxDefaultSize
, long style
= 0);
247 virtual ~wxRichTextFontListBox();
253 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
254 const wxSize
& size
= wxDefaultSize
, long style
= 0);
256 /// Creates a suitable HTML fragment for a font
257 wxString
CreateHTML(const wxString
& facename
) const;
259 /// Get font name for index
260 wxString
GetFaceName(size_t i
) const ;
262 /// Set selection for string, returning the index.
263 int SetFaceNameSelection(const wxString
& name
);
265 /// Updates the font list
268 /// Does this face name exist?
269 bool HasFaceName(const wxString
& faceName
) const { return m_faceNames
.Index(faceName
) != wxNOT_FOUND
; }
271 /// Returns the array of face names
272 const wxArrayString
& GetFaceNames() const { return m_faceNames
; }
275 /// Returns the HTML for this item
276 virtual wxString
OnGetItem(size_t n
) const;
280 wxArrayString m_faceNames
;
287 // _WX_RICHTEXTFORMATDLG_H_