1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/richtext/richtextformatdlg.h
3 // Purpose: Formatting dialog for wxRichTextCtrl
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_RICHTEXTFORMATDLG_H_
12 #define _WX_RICHTEXTFORMATDLG_H_
22 #include "wx/propdlg.h"
23 #include "wx/bookctrl.h"
24 #include "wx/withimages.h"
27 #include "wx/htmllbox.h"
30 #include "wx/richtext/richtextbuffer.h"
31 #include "wx/richtext/richtextstyles.h"
32 #include "wx/richtext/richtextuicustomization.h"
34 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextFormattingDialog
;
35 class WXDLLIMPEXP_FWD_CORE wxComboBox
;
36 class WXDLLIMPEXP_FWD_CORE wxCheckBox
;
39 * Flags determining the pages and buttons to be created in the dialog
42 #define wxRICHTEXT_FORMAT_STYLE_EDITOR 0x0001
43 #define wxRICHTEXT_FORMAT_FONT 0x0002
44 #define wxRICHTEXT_FORMAT_TABS 0x0004
45 #define wxRICHTEXT_FORMAT_BULLETS 0x0008
46 #define wxRICHTEXT_FORMAT_INDENTS_SPACING 0x0010
47 #define wxRICHTEXT_FORMAT_LIST_STYLE 0x0020
48 #define wxRICHTEXT_FORMAT_MARGINS 0x0040
49 #define wxRICHTEXT_FORMAT_SIZE 0x0080
50 #define wxRICHTEXT_FORMAT_BORDERS 0x0100
51 #define wxRICHTEXT_FORMAT_BACKGROUND 0x0200
53 #define wxRICHTEXT_FORMAT_HELP_BUTTON 0x1000
56 * Indices for bullet styles in list control
60 wxRICHTEXT_BULLETINDEX_NONE
= 0,
61 wxRICHTEXT_BULLETINDEX_ARABIC
,
62 wxRICHTEXT_BULLETINDEX_UPPER_CASE
,
63 wxRICHTEXT_BULLETINDEX_LOWER_CASE
,
64 wxRICHTEXT_BULLETINDEX_UPPER_CASE_ROMAN
,
65 wxRICHTEXT_BULLETINDEX_LOWER_CASE_ROMAN
,
66 wxRICHTEXT_BULLETINDEX_OUTLINE
,
67 wxRICHTEXT_BULLETINDEX_SYMBOL
,
68 wxRICHTEXT_BULLETINDEX_BITMAP
,
69 wxRICHTEXT_BULLETINDEX_STANDARD
73 * Shorthand for common combinations of pages
76 #define wxRICHTEXT_FORMAT_PARAGRAPH (wxRICHTEXT_FORMAT_INDENTS_SPACING | wxRICHTEXT_FORMAT_BULLETS | wxRICHTEXT_FORMAT_TABS | wxRICHTEXT_FORMAT_FONT)
77 #define wxRICHTEXT_FORMAT_CHARACTER (wxRICHTEXT_FORMAT_FONT)
78 #define wxRICHTEXT_FORMAT_STYLE (wxRICHTEXT_FORMAT_PARAGRAPH | wxRICHTEXT_FORMAT_STYLE_EDITOR)
81 * Factory for formatting dialog
84 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialogFactory
: public wxObject
87 wxRichTextFormattingDialogFactory() {}
88 virtual ~wxRichTextFormattingDialogFactory() {}
92 /// Create all pages, under the dialog's book control, also calling AddPage
93 virtual bool CreatePages(long pages
, wxRichTextFormattingDialog
* dialog
);
95 /// Create a page, given a page identifier
96 virtual wxPanel
* CreatePage(int page
, wxString
& title
, wxRichTextFormattingDialog
* dialog
);
98 /// Enumerate all available page identifiers
99 virtual int GetPageId(int i
) const;
101 /// Get the number of available page identifiers
102 virtual int GetPageIdCount() const;
104 /// Get the image index for the given page identifier
105 virtual int GetPageImage(int WXUNUSED(id
)) const { return -1; }
107 /// Invoke help for the dialog
108 virtual bool ShowHelp(int page
, wxRichTextFormattingDialog
* dialog
);
110 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
111 virtual bool SetSheetStyle(wxRichTextFormattingDialog
* dialog
);
113 /// Create the main dialog buttons
114 virtual bool CreateButtons(wxRichTextFormattingDialog
* dialog
);
118 * Formatting dialog for a wxRichTextCtrl
121 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog
: public wxPropertySheetDialog
,
124 DECLARE_CLASS(wxRichTextFormattingDialog
)
125 DECLARE_HELP_PROVISION()
128 enum { Option_AllowPixelFontSize
= 0x0001 };
130 wxRichTextFormattingDialog() { Init(); }
132 wxRichTextFormattingDialog(long flags
, wxWindow
* parent
, const wxString
& title
= wxGetTranslation(wxT("Formatting")), wxWindowID id
= wxID_ANY
,
133 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
134 long style
= wxDEFAULT_DIALOG_STYLE
)
137 Create(flags
, parent
, title
, id
, pos
, sz
, style
);
140 ~wxRichTextFormattingDialog();
144 bool Create(long flags
, wxWindow
* parent
, const wxString
& title
= wxGetTranslation(wxT("Formatting")), wxWindowID id
= wxID_ANY
,
145 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
146 long style
= wxDEFAULT_DIALOG_STYLE
);
148 /// Get attributes from the given range
149 virtual bool GetStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
);
151 /// Set the attributes and optionally update the display
152 virtual bool SetStyle(const wxRichTextAttr
& style
, bool update
= true);
154 /// Set the style definition and optionally update the display
155 virtual bool SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
, wxRichTextStyleSheet
* sheet
, bool update
= true);
157 /// Get the style definition, if any
158 virtual wxRichTextStyleDefinition
* GetStyleDefinition() const { return m_styleDefinition
; }
160 /// Get the style sheet, if any
161 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
163 /// Update the display
164 virtual bool UpdateDisplay();
166 /// Apply attributes to the given range
167 virtual bool ApplyStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
);
169 /// Apply attributes to the object being edited, if any
170 virtual bool ApplyStyle(wxRichTextCtrl
* ctrl
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
172 /// Gets and sets the attributes
173 const wxRichTextAttr
& GetAttributes() const { return m_attributes
; }
174 wxRichTextAttr
& GetAttributes() { return m_attributes
; }
175 void SetAttributes(const wxRichTextAttr
& attr
) { m_attributes
= attr
; }
177 /// Sets the dialog options, determining what the interface presents to the user.
178 /// Currently the only option is Option_AllowPixelFontSize.
179 void SetOptions(int options
) { m_options
= options
; }
181 /// Gets the dialog options, determining what the interface presents to the user.
182 /// Currently the only option is Option_AllowPixelFontSize.
183 int GetOptions() const { return m_options
; }
185 /// Returns @true if the given option is present.
186 bool HasOption(int option
) const { return (m_options
& option
) != 0; }
188 /// If editing the attributes for a particular object, such as an image,
189 /// set the object so the code can initialize attributes such as size correctly.
190 wxRichTextObject
* GetObject() const { return m_object
; }
191 void SetObject(wxRichTextObject
* obj
) { m_object
= obj
; }
193 /// Transfers the data and from to the window
194 virtual bool TransferDataToWindow();
195 virtual bool TransferDataFromWindow();
197 /// Apply the styles when a different tab is selected, so the previews are
199 void OnTabChanged(wxBookCtrlEvent
& event
);
201 /// Respond to help command
202 void OnHelp(wxCommandEvent
& event
);
203 void OnUpdateHelp(wxUpdateUIEvent
& event
);
205 /// Get/set formatting factory object
206 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
);
207 static wxRichTextFormattingDialogFactory
* GetFormattingDialogFactory() { return ms_FormattingDialogFactory
; }
209 /// Helper for pages to get the top-level dialog
210 static wxRichTextFormattingDialog
* GetDialog(wxWindow
* win
);
212 /// Helper for pages to get the attributes
213 static wxRichTextAttr
* GetDialogAttributes(wxWindow
* win
);
215 /// Helper for pages to get the reset attributes
216 static wxRichTextAttr
* GetDialogResetAttributes(wxWindow
* win
);
218 /// Helper for pages to get the style
219 static wxRichTextStyleDefinition
* GetDialogStyleDefinition(wxWindow
* win
);
221 /// Should we show tooltips?
222 static bool ShowToolTips() { return sm_showToolTips
; }
224 /// Determines whether tooltips will be shown
225 static void SetShowToolTips(bool show
) { sm_showToolTips
= show
; }
227 /// Set the dimension into the value and units controls
228 static void SetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
);
230 /// Get the dimension from the value and units controls
231 static void GetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
);
234 static bool ConvertFromString(const wxString
& string
, int& ret
, int scale
);
236 /// Map book control page index to our page id
237 void AddPageId(int id
) { m_pageIds
.Add(id
); }
239 /// Find a page by class
240 wxWindow
* FindPage(wxClassInfo
* info
) const;
244 wxRichTextAttr m_attributes
;
245 wxRichTextStyleDefinition
* m_styleDefinition
;
246 wxRichTextStyleSheet
* m_styleSheet
;
247 wxRichTextObject
* m_object
;
248 wxArrayInt m_pageIds
; // mapping of book control indexes to page ids
249 int m_options
; // UI options
251 static wxRichTextFormattingDialogFactory
* ms_FormattingDialogFactory
;
252 static bool sm_showToolTips
;
254 DECLARE_EVENT_TABLE()
257 //-----------------------------------------------------------------------------
258 // helper class - wxRichTextFontPreviewCtrl
259 //-----------------------------------------------------------------------------
261 class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl
: public wxWindow
264 wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0);
266 void SetTextEffects(int effects
) { m_textEffects
= effects
; }
267 int GetTextEffects() const { return m_textEffects
; }
272 void OnPaint(wxPaintEvent
& event
);
273 DECLARE_EVENT_TABLE()
277 * A control for displaying a small preview of a colour or bitmap
280 class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl
: public wxControl
282 DECLARE_CLASS(wxRichTextColourSwatchCtrl
)
284 wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
285 ~wxRichTextColourSwatchCtrl();
287 void OnMouseEvent(wxMouseEvent
& event
);
289 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
291 wxColour
& GetColour() { return m_colour
; }
293 virtual wxSize
DoGetBestSize() const { return GetSize(); }
298 DECLARE_EVENT_TABLE()
302 * wxRichTextFontListBox class declaration
303 * A listbox to display fonts.
306 class WXDLLIMPEXP_RICHTEXT wxRichTextFontListBox
: public wxHtmlListBox
308 DECLARE_CLASS(wxRichTextFontListBox
)
309 DECLARE_EVENT_TABLE()
312 wxRichTextFontListBox()
316 wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
317 const wxSize
& size
= wxDefaultSize
, long style
= 0);
318 virtual ~wxRichTextFontListBox();
324 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
325 const wxSize
& size
= wxDefaultSize
, long style
= 0);
327 /// Creates a suitable HTML fragment for a font
328 wxString
CreateHTML(const wxString
& facename
) const;
330 /// Get font name for index
331 wxString
GetFaceName(size_t i
) const ;
333 /// Set selection for string, returning the index.
334 int SetFaceNameSelection(const wxString
& name
);
336 /// Updates the font list
339 /// Does this face name exist?
340 bool HasFaceName(const wxString
& faceName
) const { return m_faceNames
.Index(faceName
) != wxNOT_FOUND
; }
342 /// Returns the array of face names
343 const wxArrayString
& GetFaceNames() const { return m_faceNames
; }
346 /// Returns the HTML for this item
347 virtual wxString
OnGetItem(size_t n
) const;
351 wxArrayString m_faceNames
;
358 // _WX_RICHTEXTFORMATDLG_H_