]> git.saurik.com Git - wxWidgets.git/blob - include/wx/richtext/richtextformatdlg.h
also define wxLstat in ANSI build
[wxWidgets.git] / include / wx / richtext / richtextformatdlg.h
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"
24 #include "wx/bookctrl.h"
25
26 #if wxUSE_HTML
27 #include "wx/htmllbox.h"
28 #endif
29
30 #include "wx/richtext/richtextbuffer.h"
31 #include "wx/richtext/richtextstyles.h"
32
33 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog;
34 class WXDLLIMPEXP_CORE wxImageList;
35
36 /*!
37 * Flags determining the pages and buttons to be created in the dialog
38 */
39
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
46
47 #define wxRICHTEXT_FORMAT_HELP_BUTTON 0x0100
48
49 /*!
50 * Shorthand for common combinations of pages
51 */
52
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)
56
57 /*!
58 * Factory for formatting dialog
59 */
60
61 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialogFactory: public wxObject
62 {
63 public:
64 wxRichTextFormattingDialogFactory() {}
65 virtual ~wxRichTextFormattingDialogFactory() {}
66
67 // Overrideables
68
69 /// Create all pages, under the dialog's book control, also calling AddPage
70 virtual bool CreatePages(long pages, wxRichTextFormattingDialog* dialog);
71
72 /// Create a page, given a page identifier
73 virtual wxPanel* CreatePage(int page, wxString& title, wxRichTextFormattingDialog* dialog);
74
75 /// Enumerate all available page identifiers
76 virtual int GetPageId(int i) const;
77
78 /// Get the number of available page identifiers
79 virtual int GetPageIdCount() const;
80
81 /// Get the image index for the given page identifier
82 virtual int GetPageImage(int WXUNUSED(id)) const { return -1; }
83
84 /// Invoke help for the dialog
85 virtual bool ShowHelp(int WXUNUSED(page), wxRichTextFormattingDialog* WXUNUSED(dialog)) { return false; }
86
87 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
88 virtual bool SetSheetStyle(wxRichTextFormattingDialog* dialog);
89
90 /// Create the main dialog buttons
91 virtual bool CreateButtons(wxRichTextFormattingDialog* dialog);
92 };
93
94 /*!
95 * Formatting dialog for a wxRichTextCtrl
96 */
97
98 class WXDLLIMPEXP_RICHTEXT wxRichTextFormattingDialog: public wxPropertySheetDialog
99 {
100 DECLARE_CLASS(wxRichTextFormattingDialog)
101 public:
102 wxRichTextFormattingDialog() { Init(); }
103
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)
107 {
108 Init();
109 Create(flags, parent, title, id, pos, sz, style);
110 }
111
112 ~wxRichTextFormattingDialog();
113
114 void Init();
115
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);
119
120 /// Get attributes from the given range
121 virtual bool GetStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range);
122
123 /// Set the attributes and optionally update the display
124 virtual bool SetStyle(const wxTextAttrEx& style, bool update = true);
125
126 /// Set the style definition and optionally update the display
127 virtual bool SetStyleDefinition(const wxRichTextStyleDefinition& styleDef, wxRichTextStyleSheet* sheet, bool update = true);
128
129 /// Get the style definition, if any
130 virtual wxRichTextStyleDefinition* GetStyleDefinition() const { return m_styleDefinition; }
131
132 /// Get the style sheet, if any
133 virtual wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
134
135 /// Update the display
136 virtual bool UpdateDisplay();
137
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);
140
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; }
145
146 /// Transfers the data and from to the window
147 virtual bool TransferDataToWindow();
148 virtual bool TransferDataFromWindow();
149
150 /// Apply the styles when a different tab is selected, so the previews are
151 /// up to date
152 void OnTabChanged(wxBookCtrlEvent& event);
153
154 /// Respond to help command
155 void OnHelp(wxCommandEvent& event);
156
157 /// Set/get image list
158 void SetImageList(wxImageList* imageList) { m_imageList = imageList; }
159 wxImageList* GetImageList() const { return m_imageList; }
160
161 /// Get/set formatting factory object
162 static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory* factory);
163 static wxRichTextFormattingDialogFactory* GetFormattingDialogFactory() { return ms_FormattingDialogFactory; }
164
165 /// Helper for pages to get the top-level dialog
166 static wxRichTextFormattingDialog* GetDialog(wxWindow* win);
167
168 /// Helper for pages to get the attributes
169 static wxTextAttrEx* GetDialogAttributes(wxWindow* win);
170
171 /// Helper for pages to get the style
172 static wxRichTextStyleDefinition* GetDialogStyleDefinition(wxWindow* win);
173
174 /// Should we show tooltips?
175 static bool ShowToolTips() { return sm_showToolTips; }
176
177 /// Determines whether tooltips will be shown
178 static void SetShowToolTips(bool show) { sm_showToolTips = show; }
179
180 /// Map book control page index to our page id
181 void AddPageId(int id) { m_pageIds.Add(id); }
182
183 protected:
184
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
190
191 static wxRichTextFormattingDialogFactory* ms_FormattingDialogFactory;
192 static bool sm_showToolTips;
193
194 DECLARE_EVENT_TABLE()
195 };
196
197 //-----------------------------------------------------------------------------
198 // helper class - wxRichTextFontPreviewCtrl
199 //-----------------------------------------------------------------------------
200
201 class WXDLLIMPEXP_RICHTEXT wxRichTextFontPreviewCtrl : public wxWindow
202 {
203 public:
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)
206 {
207 SetBackgroundColour(*wxWHITE);
208 }
209
210 private:
211 void OnPaint(wxPaintEvent& event);
212 DECLARE_EVENT_TABLE()
213 };
214
215 /*
216 * A control for displaying a small preview of a colour or bitmap
217 */
218
219 class WXDLLIMPEXP_RICHTEXT wxRichTextColourSwatchCtrl: public wxControl
220 {
221 DECLARE_CLASS(wxRichTextColourSwatchCtrl)
222 public:
223 wxRichTextColourSwatchCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
224 ~wxRichTextColourSwatchCtrl();
225
226 void OnMouseEvent(wxMouseEvent& event);
227
228 void SetColour(const wxColour& colour) { m_colour = colour; SetBackgroundColour(m_colour); }
229
230 wxColour& GetColour() { return m_colour; }
231
232 virtual wxSize DoGetBestSize() const { return GetSize(); }
233
234 protected:
235 wxColour m_colour;
236
237 DECLARE_EVENT_TABLE()
238 };
239
240 /*!
241 * wxRichTextFontListBox class declaration
242 * A listbox to display fonts.
243 */
244
245 class WXDLLIMPEXP_RICHTEXT wxRichTextFontListBox: public wxHtmlListBox
246 {
247 DECLARE_CLASS(wxRichTextFontListBox)
248 DECLARE_EVENT_TABLE()
249
250 public:
251 wxRichTextFontListBox()
252 {
253 Init();
254 }
255 wxRichTextFontListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
256 const wxSize& size = wxDefaultSize, long style = 0);
257 virtual ~wxRichTextFontListBox();
258
259 void Init()
260 {
261 }
262
263 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
264 const wxSize& size = wxDefaultSize, long style = 0);
265
266 /// Creates a suitable HTML fragment for a font
267 wxString CreateHTML(const wxString& facename) const;
268
269 /// Get font name for index
270 wxString GetFaceName(size_t i) const ;
271
272 /// Set selection for string, returning the index.
273 int SetFaceNameSelection(const wxString& name);
274
275 /// Updates the font list
276 void UpdateFonts();
277
278 /// Does this face name exist?
279 bool HasFaceName(const wxString& faceName) const { return m_faceNames.Index(faceName) != wxNOT_FOUND; }
280
281 /// Returns the array of face names
282 const wxArrayString& GetFaceNames() const { return m_faceNames; }
283
284 protected:
285 /// Returns the HTML for this item
286 virtual wxString OnGetItem(size_t n) const;
287
288 private:
289
290 wxArrayString m_faceNames;
291 };
292
293 #endif
294 // wxUSE_RICHTEXT
295
296 #endif
297 // _WX_RICHTEXTFORMATDLG_H_