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 and buttons 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
45 #define wxRICHTEXT_FORMAT_LIST_STYLE 0x0020
47 #define wxRICHTEXT_FORMAT_HELP_BUTTON 0x0100
50 * Shorthand for common combinations of pages
53 #define wxRICHTEXT_FORMAT_PARAGRAPH (wxRICHTEXT_FORMAT_INDENTS_SPACING | wxRICHTEXT_FORMAT_BULLETS | wxRICHTEXT_FORMAT_TABS | wxRICHTEXT_FORMAT_FONT)
54 #define wxRICHTEXT_FORMAT_CHARACTER (wxRICHTEXT_FORMAT_FONT)
55 #define wxRICHTEXT_FORMAT_STYLE (wxRICHTEXT_FORMAT_PARAGRAPH | wxRICHTEXT_FORMAT_STYLE_EDITOR)
58 * Factory for formatting dialog
61 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialogFactory
: public wxObject
64 wxRichTextFormattingDialogFactory() {}
65 virtual ~wxRichTextFormattingDialogFactory() {}
69 /// Create all pages, under the dialog's book control, also calling AddPage
70 virtual bool CreatePages(long pages
, wxRichTextFormattingDialog
* dialog
);
72 /// Create a page, given a page identifier
73 virtual wxPanel
* CreatePage(int page
, wxString
& title
, wxRichTextFormattingDialog
* dialog
);
75 /// Enumerate all available page identifiers
76 virtual int GetPageId(int i
) const;
78 /// Get the number of available page identifiers
79 virtual int GetPageIdCount() const;
81 /// Get the image index for the given page identifier
82 virtual int GetPageImage(int WXUNUSED(id
)) const { return -1; }
84 /// Invoke help for the dialog
85 virtual bool ShowHelp(int WXUNUSED(page
), wxRichTextFormattingDialog
* WXUNUSED(dialog
)) { return false; }
87 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
88 virtual bool SetSheetStyle(wxRichTextFormattingDialog
* dialog
);
90 /// Create the main dialog buttons
91 virtual bool CreateButtons(wxRichTextFormattingDialog
* dialog
);
95 * Formatting dialog for a wxRichTextCtrl
98 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog
: public wxPropertySheetDialog
100 DECLARE_CLASS(wxRichTextFormattingDialog
)
102 wxRichTextFormattingDialog() { Init(); }
104 wxRichTextFormattingDialog(long flags
, wxWindow
* parent
, const wxString
& title
= _("Formatting"), wxWindowID id
= wxID_ANY
,
105 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
106 long style
= wxDEFAULT_DIALOG_STYLE
)
109 Create(flags
, parent
, title
, id
, pos
, sz
, style
);
112 ~wxRichTextFormattingDialog();
116 bool Create(long flags
, wxWindow
* parent
, const wxString
& title
= _("Formatting"), wxWindowID id
= wxID_ANY
,
117 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
118 long style
= wxDEFAULT_DIALOG_STYLE
);
120 /// Get attributes from the given range
121 virtual bool GetStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
);
123 /// Set the attributes and optionally update the display
124 virtual bool SetStyle(const wxTextAttrEx
& style
, bool update
= true);
126 /// Set the style definition and optionally update the display
127 virtual bool SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
, wxRichTextStyleSheet
* sheet
, bool update
= true);
129 /// Get the style definition, if any
130 virtual wxRichTextStyleDefinition
* GetStyleDefinition() const { return m_styleDefinition
; }
132 /// Get the style sheet, if any
133 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
135 /// Update the display
136 virtual bool UpdateDisplay();
138 /// Apply attributes to the given range
139 virtual bool ApplyStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
);
141 /// Gets and sets the attributes
142 const wxTextAttrEx
& GetAttributes() const { return m_attributes
; }
143 wxTextAttrEx
& GetAttributes() { return m_attributes
; }
144 void SetAttributes(const wxTextAttrEx
& attr
) { m_attributes
= attr
; }
146 /// Transfers the data and from to the window
147 virtual bool TransferDataToWindow();
148 virtual bool TransferDataFromWindow();
150 /// Apply the styles when a different tab is selected, so the previews are
152 void OnTabChanged(wxBookCtrlEvent
& event
);
154 /// Respond to help command
155 void OnHelp(wxCommandEvent
& event
);
157 /// Set/get image list
158 void SetImageList(wxImageList
* imageList
) { m_imageList
= imageList
; }
159 wxImageList
* GetImageList() const { return m_imageList
; }
161 /// Get/set formatting factory object
162 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
);
163 static wxRichTextFormattingDialogFactory
* GetFormattingDialogFactory() { return ms_FormattingDialogFactory
; }
165 /// Helper for pages to get the top-level dialog
166 static wxRichTextFormattingDialog
* GetDialog(wxWindow
* win
);
168 /// Helper for pages to get the attributes
169 static wxTextAttrEx
* GetDialogAttributes(wxWindow
* win
);
171 /// Helper for pages to get the style
172 static wxRichTextStyleDefinition
* GetDialogStyleDefinition(wxWindow
* win
);
174 /// Should we show tooltips?
175 static bool ShowToolTips() { return sm_showToolTips
; }
177 /// Determines whether tooltips will be shown
178 static void SetShowToolTips(bool show
) { sm_showToolTips
= show
; }
180 /// Map book control page index to our page id
181 void AddPageId(int id
) { m_pageIds
.Add(id
); }
185 wxImageList
* m_imageList
;
186 wxTextAttrEx m_attributes
;
187 wxRichTextStyleDefinition
* m_styleDefinition
;
188 wxRichTextStyleSheet
* m_styleSheet
;
189 wxArrayInt m_pageIds
; // mapping of book control indexes to page ids
191 static wxRichTextFormattingDialogFactory
* ms_FormattingDialogFactory
;
192 static bool sm_showToolTips
;
194 DECLARE_EVENT_TABLE()
197 //-----------------------------------------------------------------------------
198 // helper class - wxRichTextFontPreviewCtrl
199 //-----------------------------------------------------------------------------
201 class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl
: public wxWindow
204 wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
205 wxWindow(parent
, id
, pos
, sz
, style
)
207 SetBackgroundColour(*wxWHITE
);
211 void OnPaint(wxPaintEvent
& event
);
212 DECLARE_EVENT_TABLE()
216 * A control for displaying a small preview of a colour or bitmap
219 class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl
: public wxControl
221 DECLARE_CLASS(wxRichTextColourSwatchCtrl
)
223 wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
224 ~wxRichTextColourSwatchCtrl();
226 void OnMouseEvent(wxMouseEvent
& event
);
228 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
230 wxColour
& GetColour() { return m_colour
; }
232 virtual wxSize
DoGetBestSize() const { return GetSize(); }
237 DECLARE_EVENT_TABLE()
241 * wxRichTextFontListBox class declaration
242 * A listbox to display fonts.
245 class WXDLLIMPEXP_RICHTEXT wxRichTextFontListBox
: public wxHtmlListBox
247 DECLARE_CLASS(wxRichTextFontListBox
)
248 DECLARE_EVENT_TABLE()
251 wxRichTextFontListBox()
255 wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
256 const wxSize
& size
= wxDefaultSize
, long style
= 0);
257 virtual ~wxRichTextFontListBox();
263 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
264 const wxSize
& size
= wxDefaultSize
, long style
= 0);
266 /// Creates a suitable HTML fragment for a font
267 wxString
CreateHTML(const wxString
& facename
) const;
269 /// Get font name for index
270 wxString
GetFaceName(size_t i
) const ;
272 /// Set selection for string, returning the index.
273 int SetFaceNameSelection(const wxString
& name
);
275 /// Updates the font list
278 /// Does this face name exist?
279 bool HasFaceName(const wxString
& faceName
) const { return m_faceNames
.Index(faceName
) != wxNOT_FOUND
; }
281 /// Returns the array of face names
282 const wxArrayString
& GetFaceNames() const { return m_faceNames
; }
285 /// Returns the HTML for this item
286 virtual wxString
OnGetItem(size_t n
) const;
290 wxArrayString m_faceNames
;
297 // _WX_RICHTEXTFORMATDLG_H_