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"
32 #include "wx/richtext/richtextuicustomization.h"
34 class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextFormattingDialog
;
35 class WXDLLIMPEXP_FWD_CORE wxImageList
;
38 * Flags determining the pages and buttons to be created in the dialog
41 #define wxRICHTEXT_FORMAT_STYLE_EDITOR 0x0001
42 #define wxRICHTEXT_FORMAT_FONT 0x0002
43 #define wxRICHTEXT_FORMAT_TABS 0x0004
44 #define wxRICHTEXT_FORMAT_BULLETS 0x0008
45 #define wxRICHTEXT_FORMAT_INDENTS_SPACING 0x0010
46 #define wxRICHTEXT_FORMAT_LIST_STYLE 0x0020
47 #define wxRICHTEXT_FORMAT_MARGINS 0x0040
48 #define wxRICHTEXT_FORMAT_SIZE 0x0080
49 #define wxRICHTEXT_FORMAT_BORDERS 0x0100
50 #define wxRICHTEXT_FORMAT_BACKGROUND 0x0200
52 #define wxRICHTEXT_FORMAT_HELP_BUTTON 0x1000
55 * Indices for bullet styles in list control
59 wxRICHTEXT_BULLETINDEX_NONE
= 0,
60 wxRICHTEXT_BULLETINDEX_ARABIC
,
61 wxRICHTEXT_BULLETINDEX_UPPER_CASE
,
62 wxRICHTEXT_BULLETINDEX_LOWER_CASE
,
63 wxRICHTEXT_BULLETINDEX_UPPER_CASE_ROMAN
,
64 wxRICHTEXT_BULLETINDEX_LOWER_CASE_ROMAN
,
65 wxRICHTEXT_BULLETINDEX_OUTLINE
,
66 wxRICHTEXT_BULLETINDEX_SYMBOL
,
67 wxRICHTEXT_BULLETINDEX_BITMAP
,
68 wxRICHTEXT_BULLETINDEX_STANDARD
72 * Shorthand for common combinations of pages
75 #define wxRICHTEXT_FORMAT_PARAGRAPH (wxRICHTEXT_FORMAT_INDENTS_SPACING | wxRICHTEXT_FORMAT_BULLETS | wxRICHTEXT_FORMAT_TABS | wxRICHTEXT_FORMAT_FONT)
76 #define wxRICHTEXT_FORMAT_CHARACTER (wxRICHTEXT_FORMAT_FONT)
77 #define wxRICHTEXT_FORMAT_STYLE (wxRICHTEXT_FORMAT_PARAGRAPH | wxRICHTEXT_FORMAT_STYLE_EDITOR)
80 * Factory for formatting dialog
83 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialogFactory
: public wxObject
86 wxRichTextFormattingDialogFactory() {}
87 virtual ~wxRichTextFormattingDialogFactory() {}
91 /// Create all pages, under the dialog's book control, also calling AddPage
92 virtual bool CreatePages(long pages
, wxRichTextFormattingDialog
* dialog
);
94 /// Create a page, given a page identifier
95 virtual wxPanel
* CreatePage(int page
, wxString
& title
, wxRichTextFormattingDialog
* dialog
);
97 /// Enumerate all available page identifiers
98 virtual int GetPageId(int i
) const;
100 /// Get the number of available page identifiers
101 virtual int GetPageIdCount() const;
103 /// Get the image index for the given page identifier
104 virtual int GetPageImage(int WXUNUSED(id
)) const { return -1; }
106 /// Invoke help for the dialog
107 virtual bool ShowHelp(int page
, wxRichTextFormattingDialog
* dialog
);
109 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
110 virtual bool SetSheetStyle(wxRichTextFormattingDialog
* dialog
);
112 /// Create the main dialog buttons
113 virtual bool CreateButtons(wxRichTextFormattingDialog
* dialog
);
117 * Formatting dialog for a wxRichTextCtrl
120 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog
: public wxPropertySheetDialog
122 DECLARE_CLASS(wxRichTextFormattingDialog
)
123 DECLARE_HELP_PROVISION()
126 wxRichTextFormattingDialog() { Init(); }
128 wxRichTextFormattingDialog(long flags
, wxWindow
* parent
, const wxString
& title
= wxGetTranslation(wxT("Formatting")), wxWindowID id
= wxID_ANY
,
129 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
130 long style
= wxDEFAULT_DIALOG_STYLE
)
133 Create(flags
, parent
, title
, id
, pos
, sz
, style
);
136 ~wxRichTextFormattingDialog();
140 bool Create(long flags
, wxWindow
* parent
, const wxString
& title
= wxGetTranslation(wxT("Formatting")), wxWindowID id
= wxID_ANY
,
141 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
,
142 long style
= wxDEFAULT_DIALOG_STYLE
);
144 /// Get attributes from the given range
145 virtual bool GetStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
);
147 /// Set the attributes and optionally update the display
148 virtual bool SetStyle(const wxRichTextAttr
& style
, bool update
= true);
150 /// Set the style definition and optionally update the display
151 virtual bool SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
, wxRichTextStyleSheet
* sheet
, bool update
= true);
153 /// Get the style definition, if any
154 virtual wxRichTextStyleDefinition
* GetStyleDefinition() const { return m_styleDefinition
; }
156 /// Get the style sheet, if any
157 virtual wxRichTextStyleSheet
* GetStyleSheet() const { return m_styleSheet
; }
159 /// Update the display
160 virtual bool UpdateDisplay();
162 /// Apply attributes to the given range
163 virtual bool ApplyStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
|wxRICHTEXT_SETSTYLE_OPTIMIZE
);
165 /// Apply attributes to the object being edited, if any
166 virtual bool ApplyStyle(wxRichTextCtrl
* ctrl
, int flags
= wxRICHTEXT_SETSTYLE_WITH_UNDO
);
168 /// Gets and sets the attributes
169 const wxRichTextAttr
& GetAttributes() const { return m_attributes
; }
170 wxRichTextAttr
& GetAttributes() { return m_attributes
; }
171 void SetAttributes(const wxRichTextAttr
& attr
) { m_attributes
= attr
; }
173 /// Gets and sets the attributes that the user wants to reset
174 const wxRichTextAttr
& GetResetAttributes() const { return m_resetAttributes
; }
175 wxRichTextAttr
& GetResetAttributes() { return m_resetAttributes
; }
176 void SetResetAttributes(const wxRichTextAttr
& attr
) { m_resetAttributes
= attr
; }
178 /// If editing the attributes for a particular object, such as an image,
179 /// set the object so the code can initialize attributes such as size correctly.
180 wxRichTextObject
* GetObject() const { return m_object
; }
181 void SetObject(wxRichTextObject
* obj
) { m_object
= obj
; }
183 /// Transfers the data and from to the window
184 virtual bool TransferDataToWindow();
185 virtual bool TransferDataFromWindow();
187 /// Apply the styles when a different tab is selected, so the previews are
189 void OnTabChanged(wxBookCtrlEvent
& event
);
191 /// Respond to help command
192 void OnHelp(wxCommandEvent
& event
);
193 void OnUpdateHelp(wxUpdateUIEvent
& event
);
195 /// Set/get image list
196 void SetImageList(wxImageList
* imageList
) { m_imageList
= imageList
; }
197 wxImageList
* GetImageList() const { return m_imageList
; }
199 /// Get/set formatting factory object
200 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
);
201 static wxRichTextFormattingDialogFactory
* GetFormattingDialogFactory() { return ms_FormattingDialogFactory
; }
203 /// Helper for pages to get the top-level dialog
204 static wxRichTextFormattingDialog
* GetDialog(wxWindow
* win
);
206 /// Helper for pages to get the attributes
207 static wxRichTextAttr
* GetDialogAttributes(wxWindow
* win
);
209 /// Helper for pages to get the reset attributes
210 static wxRichTextAttr
* GetDialogResetAttributes(wxWindow
* win
);
212 /// Helper for pages to get the style
213 static wxRichTextStyleDefinition
* GetDialogStyleDefinition(wxWindow
* win
);
215 /// Should we show tooltips?
216 static bool ShowToolTips() { return sm_showToolTips
; }
218 /// Determines whether tooltips will be shown
219 static void SetShowToolTips(bool show
) { sm_showToolTips
= show
; }
221 /// Set the dimension into the value and units controls
222 static void SetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
);
224 /// Get the dimension from the value and units controls
225 static void GetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
);
228 static bool ConvertFromString(const wxString
& string
, int& ret
, int scale
);
230 /// Map book control page index to our page id
231 void AddPageId(int id
) { m_pageIds
.Add(id
); }
233 /// Find a page by class
234 wxWindow
* FindPage(wxClassInfo
* info
) const;
238 wxImageList
* m_imageList
;
239 wxRichTextAttr m_attributes
;
240 //wxRichTextAttr m_resetAttributes;
241 wxRichTextStyleDefinition
* m_styleDefinition
;
242 wxRichTextStyleSheet
* m_styleSheet
;
243 wxRichTextObject
* m_object
;
244 wxArrayInt m_pageIds
; // mapping of book control indexes to page ids
246 static wxRichTextFormattingDialogFactory
* ms_FormattingDialogFactory
;
247 static bool sm_showToolTips
;
249 DECLARE_EVENT_TABLE()
252 //-----------------------------------------------------------------------------
253 // helper class - wxRichTextFontPreviewCtrl
254 //-----------------------------------------------------------------------------
256 class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl
: public wxWindow
259 wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= 0);
261 void SetTextEffects(int effects
) { m_textEffects
= effects
; }
262 int GetTextEffects() const { return m_textEffects
; }
267 void OnPaint(wxPaintEvent
& event
);
268 DECLARE_EVENT_TABLE()
272 * A control for displaying a small preview of a colour or bitmap
275 class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl
: public wxControl
277 DECLARE_CLASS(wxRichTextColourSwatchCtrl
)
279 wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& size
= wxDefaultSize
, long style
= 0);
280 ~wxRichTextColourSwatchCtrl();
282 void OnMouseEvent(wxMouseEvent
& event
);
284 void SetColour(const wxColour
& colour
) { m_colour
= colour
; SetBackgroundColour(m_colour
); }
286 wxColour
& GetColour() { return m_colour
; }
288 virtual wxSize
DoGetBestSize() const { return GetSize(); }
293 DECLARE_EVENT_TABLE()
297 * wxRichTextFontListBox class declaration
298 * A listbox to display fonts.
301 class WXDLLIMPEXP_RICHTEXT wxRichTextFontListBox
: public wxHtmlListBox
303 DECLARE_CLASS(wxRichTextFontListBox
)
304 DECLARE_EVENT_TABLE()
307 wxRichTextFontListBox()
311 wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
312 const wxSize
& size
= wxDefaultSize
, long style
= 0);
313 virtual ~wxRichTextFontListBox();
319 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
, const wxPoint
& pos
= wxDefaultPosition
,
320 const wxSize
& size
= wxDefaultSize
, long style
= 0);
322 /// Creates a suitable HTML fragment for a font
323 wxString
CreateHTML(const wxString
& facename
) const;
325 /// Get font name for index
326 wxString
GetFaceName(size_t i
) const ;
328 /// Set selection for string, returning the index.
329 int SetFaceNameSelection(const wxString
& name
);
331 /// Updates the font list
334 /// Does this face name exist?
335 bool HasFaceName(const wxString
& faceName
) const { return m_faceNames
.Index(faceName
) != wxNOT_FOUND
; }
337 /// Returns the array of face names
338 const wxArrayString
& GetFaceNames() const { return m_faceNames
; }
341 /// Returns the HTML for this item
342 virtual wxString
OnGetItem(size_t n
) const;
346 wxArrayString m_faceNames
;
353 // _WX_RICHTEXTFORMATDLG_H_