]>
Commit | Line | Data |
---|---|---|
97ff49b3 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/richtext/richtextformatdlg.h | |
3 | // Purpose: Formatting dialog for wxRichTextCtrl | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 2006-10-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_RICHTEXTFORMATDLG_H_ | |
13 | #define _WX_RICHTEXTFORMATDLG_H_ | |
14 | ||
15 | /*! | |
16 | * Includes | |
17 | */ | |
18 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | #if wxUSE_RICHTEXT | |
22 | ||
23 | #include "wx/propdlg.h" | |
2b741a39 WS |
24 | #include "wx/bookctrl.h" |
25 | ||
97ff49b3 JS |
26 | #if wxUSE_HTML |
27 | #include "wx/htmllbox.h" | |
28 | #endif | |
29 | ||
30 | #include "wx/richtext/richtextbuffer.h" | |
31 | #include "wx/richtext/richtextstyles.h" | |
603f702b | 32 | #include "wx/richtext/richtextuicustomization.h" |
97ff49b3 | 33 | |
b5dbe15d VS |
34 | class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextFormattingDialog; |
35 | class WXDLLIMPEXP_FWD_CORE wxImageList; | |
2be72ac2 JS |
36 | class WXDLLIMPEXP_FWD_CORE wxComboBox; |
37 | class WXDLLIMPEXP_FWD_CORE wxCheckBox; | |
97ff49b3 JS |
38 | |
39 | /*! | |
dadd4f55 | 40 | * Flags determining the pages and buttons to be created in the dialog |
97ff49b3 JS |
41 | */ |
42 | ||
43 | #define wxRICHTEXT_FORMAT_STYLE_EDITOR 0x0001 | |
44 | #define wxRICHTEXT_FORMAT_FONT 0x0002 | |
45 | #define wxRICHTEXT_FORMAT_TABS 0x0004 | |
46 | #define wxRICHTEXT_FORMAT_BULLETS 0x0008 | |
47 | #define wxRICHTEXT_FORMAT_INDENTS_SPACING 0x0010 | |
dadd4f55 | 48 | #define wxRICHTEXT_FORMAT_LIST_STYLE 0x0020 |
603f702b JS |
49 | #define wxRICHTEXT_FORMAT_MARGINS 0x0040 |
50 | #define wxRICHTEXT_FORMAT_SIZE 0x0080 | |
51 | #define wxRICHTEXT_FORMAT_BORDERS 0x0100 | |
52 | #define wxRICHTEXT_FORMAT_BACKGROUND 0x0200 | |
dadd4f55 | 53 | |
603f702b | 54 | #define wxRICHTEXT_FORMAT_HELP_BUTTON 0x1000 |
97ff49b3 | 55 | |
d2d0adc7 JS |
56 | /*! |
57 | * Indices for bullet styles in list control | |
58 | */ | |
59 | ||
60 | enum { | |
61 | wxRICHTEXT_BULLETINDEX_NONE = 0, | |
62 | wxRICHTEXT_BULLETINDEX_ARABIC, | |
63 | wxRICHTEXT_BULLETINDEX_UPPER_CASE, | |
64 | wxRICHTEXT_BULLETINDEX_LOWER_CASE, | |
65 | wxRICHTEXT_BULLETINDEX_UPPER_CASE_ROMAN, | |
66 | wxRICHTEXT_BULLETINDEX_LOWER_CASE_ROMAN, | |
67 | wxRICHTEXT_BULLETINDEX_OUTLINE, | |
68 | wxRICHTEXT_BULLETINDEX_SYMBOL, | |
69 | wxRICHTEXT_BULLETINDEX_BITMAP, | |
70 | wxRICHTEXT_BULLETINDEX_STANDARD | |
71 | }; | |
72 | ||
97ff49b3 JS |
73 | /*! |
74 | * Shorthand for common combinations of pages | |
75 | */ | |
76 | ||
77 | #define wxRICHTEXT_FORMAT_PARAGRAPH (wxRICHTEXT_FORMAT_INDENTS_SPACING | wxRICHTEXT_FORMAT_BULLETS | wxRICHTEXT_FORMAT_TABS | wxRICHTEXT_FORMAT_FONT) | |
78 | #define wxRICHTEXT_FORMAT_CHARACTER (wxRICHTEXT_FORMAT_FONT) | |
79 | #define wxRICHTEXT_FORMAT_STYLE (wxRICHTEXT_FORMAT_PARAGRAPH | wxRICHTEXT_FORMAT_STYLE_EDITOR) | |
80 | ||
81 | /*! | |
82 | * Factory for formatting dialog | |
83 | */ | |
84 | ||
85 | class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialogFactory: public wxObject | |
86 | { | |
87 | public: | |
88 | wxRichTextFormattingDialogFactory() {} | |
89 | virtual ~wxRichTextFormattingDialogFactory() {} | |
90 | ||
d13b34d3 | 91 | // Overridables |
97ff49b3 JS |
92 | |
93 | /// Create all pages, under the dialog's book control, also calling AddPage | |
94 | virtual bool CreatePages(long pages, wxRichTextFormattingDialog* dialog); | |
95 | ||
96 | /// Create a page, given a page identifier | |
97 | virtual wxPanel* CreatePage(int page, wxString& title, wxRichTextFormattingDialog* dialog); | |
98 | ||
99 | /// Enumerate all available page identifiers | |
100 | virtual int GetPageId(int i) const; | |
101 | ||
102 | /// Get the number of available page identifiers | |
103 | virtual int GetPageIdCount() const; | |
104 | ||
105 | /// Get the image index for the given page identifier | |
106 | virtual int GetPageImage(int WXUNUSED(id)) const { return -1; } | |
107 | ||
108 | /// Invoke help for the dialog | |
603f702b | 109 | virtual bool ShowHelp(int page, wxRichTextFormattingDialog* dialog); |
97ff49b3 JS |
110 | |
111 | /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create | |
112 | virtual bool SetSheetStyle(wxRichTextFormattingDialog* dialog); | |
113 | ||
114 | /// Create the main dialog buttons | |
115 | virtual bool CreateButtons(wxRichTextFormattingDialog* dialog); | |
116 | }; | |
117 | ||
118 | /*! | |
119 | * Formatting dialog for a wxRichTextCtrl | |
120 | */ | |
121 | ||
122 | class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog: public wxPropertySheetDialog | |
123 | { | |
124 | DECLARE_CLASS(wxRichTextFormattingDialog) | |
603f702b JS |
125 | DECLARE_HELP_PROVISION() |
126 | ||
97ff49b3 JS |
127 | public: |
128 | wxRichTextFormattingDialog() { Init(); } | |
129 | ||
be6d15fb | 130 | wxRichTextFormattingDialog(long flags, wxWindow* parent, const wxString& title = wxGetTranslation(wxT("Formatting")), wxWindowID id = wxID_ANY, |
97ff49b3 JS |
131 | const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize, |
132 | long style = wxDEFAULT_DIALOG_STYLE) | |
133 | { | |
134 | Init(); | |
135 | Create(flags, parent, title, id, pos, sz, style); | |
136 | } | |
137 | ||
138 | ~wxRichTextFormattingDialog(); | |
139 | ||
140 | void Init(); | |
141 | ||
be6d15fb | 142 | bool Create(long flags, wxWindow* parent, const wxString& title = wxGetTranslation(wxT("Formatting")), wxWindowID id = wxID_ANY, |
97ff49b3 JS |
143 | const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize, |
144 | long style = wxDEFAULT_DIALOG_STYLE); | |
145 | ||
146 | /// Get attributes from the given range | |
147 | virtual bool GetStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range); | |
148 | ||
149 | /// Set the attributes and optionally update the display | |
24777478 | 150 | virtual bool SetStyle(const wxRichTextAttr& style, bool update = true); |
97ff49b3 JS |
151 | |
152 | /// Set the style definition and optionally update the display | |
153 | virtual bool SetStyleDefinition(const wxRichTextStyleDefinition& styleDef, wxRichTextStyleSheet* sheet, bool update = true); | |
154 | ||
155 | /// Get the style definition, if any | |
156 | virtual wxRichTextStyleDefinition* GetStyleDefinition() const { return m_styleDefinition; } | |
157 | ||
158 | /// Get the style sheet, if any | |
159 | virtual wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; } | |
160 | ||
161 | /// Update the display | |
162 | virtual bool UpdateDisplay(); | |
163 | ||
164 | /// Apply attributes to the given range | |
165 | virtual bool ApplyStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE); | |
603f702b JS |
166 | |
167 | /// Apply attributes to the object being edited, if any | |
168 | virtual bool ApplyStyle(wxRichTextCtrl* ctrl, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); | |
97ff49b3 JS |
169 | |
170 | /// Gets and sets the attributes | |
24777478 JS |
171 | const wxRichTextAttr& GetAttributes() const { return m_attributes; } |
172 | wxRichTextAttr& GetAttributes() { return m_attributes; } | |
173 | void SetAttributes(const wxRichTextAttr& attr) { m_attributes = attr; } | |
603f702b JS |
174 | #if 0 |
175 | /// Gets and sets the attributes that the user wants to reset | |
176 | const wxRichTextAttr& GetResetAttributes() const { return m_resetAttributes; } | |
177 | wxRichTextAttr& GetResetAttributes() { return m_resetAttributes; } | |
178 | void SetResetAttributes(const wxRichTextAttr& attr) { m_resetAttributes = attr; } | |
179 | #endif | |
180 | /// If editing the attributes for a particular object, such as an image, | |
181 | /// set the object so the code can initialize attributes such as size correctly. | |
182 | wxRichTextObject* GetObject() const { return m_object; } | |
183 | void SetObject(wxRichTextObject* obj) { m_object = obj; } | |
97ff49b3 JS |
184 | |
185 | /// Transfers the data and from to the window | |
186 | virtual bool TransferDataToWindow(); | |
187 | virtual bool TransferDataFromWindow(); | |
188 | ||
189 | /// Apply the styles when a different tab is selected, so the previews are | |
190 | /// up to date | |
2b741a39 | 191 | void OnTabChanged(wxBookCtrlEvent& event); |
97ff49b3 | 192 | |
1807a1f3 JS |
193 | /// Respond to help command |
194 | void OnHelp(wxCommandEvent& event); | |
603f702b | 195 | void OnUpdateHelp(wxUpdateUIEvent& event); |
1807a1f3 | 196 | |
97ff49b3 JS |
197 | /// Set/get image list |
198 | void SetImageList(wxImageList* imageList) { m_imageList = imageList; } | |
199 | wxImageList* GetImageList() const { return m_imageList; } | |
200 | ||
201 | /// Get/set formatting factory object | |
202 | static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory* factory); | |
203 | static wxRichTextFormattingDialogFactory* GetFormattingDialogFactory() { return ms_FormattingDialogFactory; } | |
204 | ||
205 | /// Helper for pages to get the top-level dialog | |
206 | static wxRichTextFormattingDialog* GetDialog(wxWindow* win); | |
207 | ||
208 | /// Helper for pages to get the attributes | |
24777478 | 209 | static wxRichTextAttr* GetDialogAttributes(wxWindow* win); |
97ff49b3 | 210 | |
603f702b JS |
211 | /// Helper for pages to get the reset attributes |
212 | static wxRichTextAttr* GetDialogResetAttributes(wxWindow* win); | |
213 | ||
97ff49b3 JS |
214 | /// Helper for pages to get the style |
215 | static wxRichTextStyleDefinition* GetDialogStyleDefinition(wxWindow* win); | |
216 | ||
dadd4f55 JS |
217 | /// Should we show tooltips? |
218 | static bool ShowToolTips() { return sm_showToolTips; } | |
41a85215 | 219 | |
dadd4f55 JS |
220 | /// Determines whether tooltips will be shown |
221 | static void SetShowToolTips(bool show) { sm_showToolTips = show; } | |
41a85215 | 222 | |
603f702b JS |
223 | /// Set the dimension into the value and units controls |
224 | static void SetDimensionValue(wxTextAttrDimension& dim, wxTextCtrl* valueCtrl, wxComboBox* unitsCtrl, wxCheckBox* checkBox); | |
225 | ||
226 | /// Get the dimension from the value and units controls | |
227 | static void GetDimensionValue(wxTextAttrDimension& dim, wxTextCtrl* valueCtrl, wxComboBox* unitsCtrl, wxCheckBox* checkBox); | |
228 | ||
229 | /// Convert CM to MM | |
230 | static bool ConvertFromString(const wxString& string, int& ret, int scale); | |
231 | ||
1807a1f3 JS |
232 | /// Map book control page index to our page id |
233 | void AddPageId(int id) { m_pageIds.Add(id); } | |
603f702b JS |
234 | |
235 | /// Find a page by class | |
236 | wxWindow* FindPage(wxClassInfo* info) const; | |
1807a1f3 | 237 | |
97ff49b3 JS |
238 | protected: |
239 | ||
240 | wxImageList* m_imageList; | |
24777478 | 241 | wxRichTextAttr m_attributes; |
603f702b | 242 | //wxRichTextAttr m_resetAttributes; |
97ff49b3 JS |
243 | wxRichTextStyleDefinition* m_styleDefinition; |
244 | wxRichTextStyleSheet* m_styleSheet; | |
603f702b | 245 | wxRichTextObject* m_object; |
1807a1f3 | 246 | wxArrayInt m_pageIds; // mapping of book control indexes to page ids |
97ff49b3 JS |
247 | |
248 | static wxRichTextFormattingDialogFactory* ms_FormattingDialogFactory; | |
dadd4f55 | 249 | static bool sm_showToolTips; |
97ff49b3 JS |
250 | |
251 | DECLARE_EVENT_TABLE() | |
252 | }; | |
253 | ||
254 | //----------------------------------------------------------------------------- | |
255 | // helper class - wxRichTextFontPreviewCtrl | |
256 | //----------------------------------------------------------------------------- | |
257 | ||
258 | class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl : public wxWindow | |
259 | { | |
260 | public: | |
2fce6547 | 261 | wxRichTextFontPreviewCtrl(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize, long style = 0); |
97ff49b3 | 262 | |
42688aea JS |
263 | void SetTextEffects(int effects) { m_textEffects = effects; } |
264 | int GetTextEffects() const { return m_textEffects; } | |
265 | ||
97ff49b3 | 266 | private: |
42688aea JS |
267 | int m_textEffects; |
268 | ||
97ff49b3 JS |
269 | void OnPaint(wxPaintEvent& event); |
270 | DECLARE_EVENT_TABLE() | |
271 | }; | |
272 | ||
273 | /* | |
274 | * A control for displaying a small preview of a colour or bitmap | |
275 | */ | |
276 | ||
277 | class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl: public wxControl | |
278 | { | |
279 | DECLARE_CLASS(wxRichTextColourSwatchCtrl) | |
280 | public: | |
281 | wxRichTextColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0); | |
282 | ~wxRichTextColourSwatchCtrl(); | |
283 | ||
97ff49b3 JS |
284 | void OnMouseEvent(wxMouseEvent& event); |
285 | ||
286 | void SetColour(const wxColour& colour) { m_colour = colour; SetBackgroundColour(m_colour); } | |
287 | ||
288 | wxColour& GetColour() { return m_colour; } | |
289 | ||
290 | virtual wxSize DoGetBestSize() const { return GetSize(); } | |
291 | ||
292 | protected: | |
293 | wxColour m_colour; | |
294 | ||
295 | DECLARE_EVENT_TABLE() | |
296 | }; | |
297 | ||
298 | /*! | |
299 | * wxRichTextFontListBox class declaration | |
300 | * A listbox to display fonts. | |
301 | */ | |
302 | ||
303 | class WXDLLIMPEXP_RICHTEXT wxRichTextFontListBox: public wxHtmlListBox | |
304 | { | |
305 | DECLARE_CLASS(wxRichTextFontListBox) | |
306 | DECLARE_EVENT_TABLE() | |
307 | ||
308 | public: | |
309 | wxRichTextFontListBox() | |
310 | { | |
311 | Init(); | |
312 | } | |
313 | wxRichTextFontListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, | |
314 | const wxSize& size = wxDefaultSize, long style = 0); | |
315 | virtual ~wxRichTextFontListBox(); | |
316 | ||
317 | void Init() | |
318 | { | |
319 | } | |
320 | ||
321 | bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, | |
322 | const wxSize& size = wxDefaultSize, long style = 0); | |
323 | ||
324 | /// Creates a suitable HTML fragment for a font | |
325 | wxString CreateHTML(const wxString& facename) const; | |
326 | ||
327 | /// Get font name for index | |
328 | wxString GetFaceName(size_t i) const ; | |
329 | ||
330 | /// Set selection for string, returning the index. | |
331 | int SetFaceNameSelection(const wxString& name); | |
332 | ||
333 | /// Updates the font list | |
334 | void UpdateFonts(); | |
335 | ||
336 | /// Does this face name exist? | |
337 | bool HasFaceName(const wxString& faceName) const { return m_faceNames.Index(faceName) != wxNOT_FOUND; } | |
338 | ||
339 | /// Returns the array of face names | |
340 | const wxArrayString& GetFaceNames() const { return m_faceNames; } | |
341 | ||
342 | protected: | |
343 | /// Returns the HTML for this item | |
344 | virtual wxString OnGetItem(size_t n) const; | |
345 | ||
346 | private: | |
347 | ||
348 | wxArrayString m_faceNames; | |
349 | }; | |
350 | ||
351 | #endif | |
352 | // wxUSE_RICHTEXT | |
353 | ||
354 | #endif | |
355 | // _WX_RICHTEXTFORMATDLG_H_ |