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_FWD_RICHTEXT wxRichTextFormattingDialog
;
34 class WXDLLIMPEXP_FWD_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 * Indices for bullet styles in list control
54 wxRICHTEXT_BULLETINDEX_NONE
= 0,
55 wxRICHTEXT_BULLETINDEX_ARABIC
,
56 wxRICHTEXT_BULLETINDEX_UPPER_CASE
,
57 wxRICHTEXT_BULLETINDEX_LOWER_CASE
,
58 wxRICHTEXT_BULLETINDEX_UPPER_CASE_ROMAN
,
59 wxRICHTEXT_BULLETINDEX_LOWER_CASE_ROMAN
,
60 wxRICHTEXT_BULLETINDEX_OUTLINE
,
61 wxRICHTEXT_BULLETINDEX_SYMBOL
,
62 wxRICHTEXT_BULLETINDEX_BITMAP
,
63 wxRICHTEXT_BULLETINDEX_STANDARD
67 * Shorthand for common combinations of pages
70 #define wxRICHTEXT_FORMAT_PARAGRAPH (wxRICHTEXT_FORMAT_INDENTS_SPACING | wxRICHTEXT_FORMAT_BULLETS | wxRICHTEXT_FORMAT_TABS | wxRICHTEXT_FORMAT_FONT)
71 #define wxRICHTEXT_FORMAT_CHARACTER (wxRICHTEXT_FORMAT_FONT)
72 #define wxRICHTEXT_FORMAT_STYLE (wxRICHTEXT_FORMAT_PARAGRAPH | wxRICHTEXT_FORMAT_STYLE_EDITOR)
75 * Factory for formatting dialog
78 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialogFactory
: public wxObject
81 wxRichTextFormattingDialogFactory() {}
82 virtual ~wxRichTextFormattingDialogFactory() {}
86 /// Create all pages, under the dialog's book control, also calling AddPage
87 virtual bool CreatePages(long pages
, wxRichTextFormattingDialog
* dialog
);
89 /// Create a page, given a page identifier
90 virtual wxPanel
* CreatePage(int page
, wxString
& title
, wxRichTextFormattingDialog
* dialog
);
92 /// Enumerate all available page identifiers
93 virtual int GetPageId(int i
) const;
95 /// Get the number of available page identifiers
96 virtual int GetPageIdCount() const;
98 /// Get the image index for the given page identifier
99 virtual int GetPageImage(int WXUNUSED(id
)) const { return -1; }
101 /// Invoke help for the dialog
102 virtual bool ShowHelp(int WXUNUSED(page
), wxRichTextFormattingDialog
* WXUNUSED(dialog
)) { return false; }
104 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
105 virtual bool SetSheetStyle(wxRichTextFormattingDialog
* dialog
);
107 /// Create the main dialog buttons
108 virtual bool CreateButtons(wxRichTextFormattingDialog
* dialog
);
112 * Formatting dialog for a wxRichTextCtrl
115 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog
: public wxPropertySheetDialog
117 DECLARE_CLASS(wxRichTextFormattingDialog
)
119 wxRichTextFormattingDialog() { Init(); }
121 wxRichTextFormattingDialog(long flags
, wxWindow
* parent
, const wxString
& title
= wxGetTranslation(wxT("Formatting")), wxWindowID id
= wxID_ANY
,
122 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
123 long style
= wxDEFAULT_DIALOG_STYLE
)
126 Create(flags
, parent
, title
, id
, pos
, sz
, style
);
129 ~wxRichTextFormattingDialog();
133 bool Create(long flags
, wxWindow
* parent
, const wxString
& title
= wxGetTranslation(wxT("Formatting")), wxWindowID id
= wxID_ANY
,
134 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
135 long style
= wxDEFAULT_DIALOG_STYLE
);
137 /// Get attributes from the given range
138 virtual bool GetStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
);
140 /// Set the attributes and optionally update the display
141 virtual bool SetStyle(const wxTextAttr
& style
, bool update
= true);
143 /// Set the style definition and optionally update the display
144 virtual bool SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
, wxRichTextStyleSheet
* sheet
, bool update
= true);
146 /// Get the style definition, if any
147 virtual wxRichTextStyleDefinition
* GetStyleDefinition() const { return m_styleDefinition
; }
149 /// Get the style sheet, if any
150 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
152 /// Update the display
153 virtual bool UpdateDisplay();
155 /// Apply attributes to the given range
156 virtual bool ApplyStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
);
158 /// Gets and sets the attributes
159 const wxTextAttr
& GetAttributes() const { return m_attributes
; }
160 wxTextAttr
& GetAttributes() { return m_attributes
; }
161 void SetAttributes(const wxTextAttr
& attr
) { m_attributes
= attr
; }
163 /// Transfers the data and from to the window
164 virtual bool TransferDataToWindow();
165 virtual bool TransferDataFromWindow();
167 /// Apply the styles when a different tab is selected, so the previews are
169 void OnTabChanged(wxBookCtrlEvent
& event
);
171 /// Respond to help command
172 void OnHelp(wxCommandEvent
& event
);
174 /// Set/get image list
175 void SetImageList(wxImageList
* imageList
) { m_imageList
= imageList
; }
176 wxImageList
* GetImageList() const { return m_imageList
; }
178 /// Get/set formatting factory object
179 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
);
180 static wxRichTextFormattingDialogFactory
* GetFormattingDialogFactory() { return ms_FormattingDialogFactory
; }
182 /// Helper for pages to get the top-level dialog
183 static wxRichTextFormattingDialog
* GetDialog(wxWindow
* win
);
185 /// Helper for pages to get the attributes
186 static wxTextAttr
* GetDialogAttributes(wxWindow
* win
);
188 /// Helper for pages to get the style
189 static wxRichTextStyleDefinition
* GetDialogStyleDefinition(wxWindow
* win
);
191 /// Should we show tooltips?
192 static bool ShowToolTips() { return sm_showToolTips
; }
194 /// Determines whether tooltips will be shown
195 static void SetShowToolTips(bool show
) { sm_showToolTips
= show
; }
197 /// Map book control page index to our page id
198 void AddPageId(int id
) { m_pageIds
.Add(id
); }
202 wxImageList
* m_imageList
;
203 wxTextAttr m_attributes
;
204 wxRichTextStyleDefinition
* m_styleDefinition
;
205 wxRichTextStyleSheet
* m_styleSheet
;
206 wxArrayInt m_pageIds
; // mapping of book control indexes to page ids
208 static wxRichTextFormattingDialogFactory
* ms_FormattingDialogFactory
;
209 static bool sm_showToolTips
;
211 DECLARE_EVENT_TABLE()
214 //-----------------------------------------------------------------------------
215 // helper class - wxRichTextFontPreviewCtrl
216 //-----------------------------------------------------------------------------
218 class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl
: public wxWindow
221 wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0) :
222 wxWindow(parent
, id
, pos
, sz
, style
)
224 SetBackgroundColour(*wxWHITE
);
228 void SetTextEffects(int effects
) { m_textEffects
= effects
; }
229 int GetTextEffects() const { return m_textEffects
; }
234 void OnPaint(wxPaintEvent
& event
);
235 DECLARE_EVENT_TABLE()
239 * A control for displaying a small preview of a colour or bitmap
242 class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl
: public wxControl
244 DECLARE_CLASS(wxRichTextColourSwatchCtrl
)
246 wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
247 ~wxRichTextColourSwatchCtrl();
249 void OnMouseEvent(wxMouseEvent
& event
);
251 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
253 wxColour
& GetColour() { return m_colour
; }
255 virtual wxSize
DoGetBestSize() const { return GetSize(); }
260 DECLARE_EVENT_TABLE()
264 * wxRichTextFontListBox class declaration
265 * A listbox to display fonts.
268 class WXDLLIMPEXP_RICHTEXT wxRichTextFontListBox
: public wxHtmlListBox
270 DECLARE_CLASS(wxRichTextFontListBox
)
271 DECLARE_EVENT_TABLE()
274 wxRichTextFontListBox()
278 wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
279 const wxSize
& size
= wxDefaultSize
, long style
= 0);
280 virtual ~wxRichTextFontListBox();
286 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
287 const wxSize
& size
= wxDefaultSize
, long style
= 0);
289 /// Creates a suitable HTML fragment for a font
290 wxString
CreateHTML(const wxString
& facename
) const;
292 /// Get font name for index
293 wxString
GetFaceName(size_t i
) const ;
295 /// Set selection for string, returning the index.
296 int SetFaceNameSelection(const wxString
& name
);
298 /// Updates the font list
301 /// Does this face name exist?
302 bool HasFaceName(const wxString
& faceName
) const { return m_faceNames
.Index(faceName
) != wxNOT_FOUND
; }
304 /// Returns the array of face names
305 const wxArrayString
& GetFaceNames() const { return m_faceNames
; }
308 /// Returns the HTML for this item
309 virtual wxString
OnGetItem(size_t n
) const;
313 wxArrayString m_faceNames
;
320 // _WX_RICHTEXTFORMATDLG_H_