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