]> git.saurik.com Git - wxWidgets.git/blame - include/wx/richtext/richtextstyles.h
Compile fix
[wxWidgets.git] / include / wx / richtext / richtextstyles.h
CommitLineData
5d7836c4 1/////////////////////////////////////////////////////////////////////////////
b3298d1d 2// Name: wx/richtext/richtextstyles.h
5d7836c4
JS
3// Purpose: Style management for wxRichTextCtrl
4// Author: Julian Smart
e637208a 5// Modified by:
5d7836c4 6// Created: 2005-09-30
41a85215 7// RCS-ID: $Id$
5d7836c4
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_RICHTEXTSTYLES_H_
13#define _WX_RICHTEXTSTYLES_H_
14
15/*!
16 * Includes
17 */
18
b3298d1d 19#include "wx/defs.h"
5d7836c4
JS
20
21#if wxUSE_RICHTEXT
22
b3298d1d
WS
23#include "wx/richtext/richtextbuffer.h"
24
5d7836c4
JS
25#if wxUSE_HTML
26#include "wx/htmllbox.h"
27#endif
28
e637208a
JS
29#if wxUSE_COMBOCTRL
30#include "wx/combo.h"
31#endif
32
38f833b1
JS
33#include "wx/choice.h"
34
5d7836c4
JS
35/*!
36 * Forward declarations
37 */
38
b5dbe15d
VS
39class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCtrl;
40class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer;
5d7836c4
JS
41
42/*!
43 * wxRichTextStyleDefinition class declaration
44 * A base class for paragraph and character styles.
45 */
46
3b2cb431 47class WXDLLIMPEXP_RICHTEXT wxRichTextStyleDefinition: public wxObject
5d7836c4
JS
48{
49 DECLARE_CLASS(wxRichTextStyleDefinition)
50public:
51
38f833b1 52 /// Copy constructors
b3298d1d
WS
53 wxRichTextStyleDefinition(const wxRichTextStyleDefinition& def)
54 : wxObject()
55 {
38f833b1 56 Init();
b3298d1d
WS
57 Copy(def);
58 }
38f833b1
JS
59
60 /// Default constructor
5d7836c4 61 wxRichTextStyleDefinition(const wxString& name = wxEmptyString) { Init(); m_name = name; }
38f833b1
JS
62
63 /// Destructor
d3c7fc99 64 virtual ~wxRichTextStyleDefinition() {}
5d7836c4 65
38f833b1 66 /// Initialises members
5d7836c4 67 void Init() {}
38f833b1
JS
68
69 /// Copies from def
fe5aa22c 70 void Copy(const wxRichTextStyleDefinition& def);
38f833b1
JS
71
72 /// Equality test
fe5aa22c 73 bool Eq(const wxRichTextStyleDefinition& def) const;
38f833b1
JS
74
75 /// Assignment operator
fe5aa22c 76 void operator =(const wxRichTextStyleDefinition& def) { Copy(def); }
38f833b1
JS
77
78 /// Equality operator
fe5aa22c 79 bool operator ==(const wxRichTextStyleDefinition& def) const { return Eq(def); }
38f833b1
JS
80
81 /// Override to clone the object
86015e55 82 virtual wxRichTextStyleDefinition* Clone() const = 0;
5d7836c4 83
38f833b1 84 /// Sets and gets the name of the style
5d7836c4
JS
85 void SetName(const wxString& name) { m_name = name; }
86 const wxString& GetName() const { return m_name; }
87
42688aea
JS
88 /// Sets and gets the style description
89 void SetDescription(const wxString& descr) { m_description = descr; }
90 const wxString& GetDescription() const { return m_description; }
91
38f833b1 92 /// Sets and gets the name of the style that this style is based on
5d7836c4
JS
93 void SetBaseStyle(const wxString& name) { m_baseStyle = name; }
94 const wxString& GetBaseStyle() const { return m_baseStyle; }
95
336d8ae9 96 /// Sets and gets the style
24777478
JS
97 void SetStyle(const wxRichTextAttr& style) { m_style = style; }
98 const wxRichTextAttr& GetStyle() const { return m_style; }
99 wxRichTextAttr& GetStyle() { return m_style; }
5d7836c4 100
336d8ae9 101 /// Gets the style combined with the base style
24777478 102 virtual wxRichTextAttr GetStyleMergedWithBase(const wxRichTextStyleSheet* sheet) const;
336d8ae9 103
5d7836c4
JS
104protected:
105 wxString m_name;
106 wxString m_baseStyle;
42688aea 107 wxString m_description;
24777478 108 wxRichTextAttr m_style;
5d7836c4
JS
109};
110
111/*!
112 * wxRichTextCharacterStyleDefinition class declaration
113 */
114
3b2cb431 115class WXDLLIMPEXP_RICHTEXT wxRichTextCharacterStyleDefinition: public wxRichTextStyleDefinition
5d7836c4
JS
116{
117 DECLARE_DYNAMIC_CLASS(wxRichTextCharacterStyleDefinition)
118public:
119
38f833b1 120 /// Copy constructor
fe5aa22c 121 wxRichTextCharacterStyleDefinition(const wxRichTextCharacterStyleDefinition& def): wxRichTextStyleDefinition(def) {}
38f833b1
JS
122
123 /// Default constructor
5d7836c4
JS
124 wxRichTextCharacterStyleDefinition(const wxString& name = wxEmptyString):
125 wxRichTextStyleDefinition(name) {}
38f833b1
JS
126
127 /// Destructor
d3c7fc99 128 virtual ~wxRichTextCharacterStyleDefinition() {}
5d7836c4 129
38f833b1 130 /// Clones the object
86015e55
JS
131 virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextCharacterStyleDefinition(*this); }
132
5d7836c4
JS
133protected:
134};
135
136/*!
137 * wxRichTextParagraphStyleDefinition class declaration
138 */
139
3b2cb431 140class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphStyleDefinition: public wxRichTextStyleDefinition
5d7836c4
JS
141{
142 DECLARE_DYNAMIC_CLASS(wxRichTextParagraphStyleDefinition)
143public:
144
38f833b1 145 /// Copy constructor
fe5aa22c 146 wxRichTextParagraphStyleDefinition(const wxRichTextParagraphStyleDefinition& def): wxRichTextStyleDefinition(def) { m_nextStyle = def.m_nextStyle; }
38f833b1
JS
147
148 /// Default constructor
5d7836c4
JS
149 wxRichTextParagraphStyleDefinition(const wxString& name = wxEmptyString):
150 wxRichTextStyleDefinition(name) {}
38f833b1
JS
151
152 // Destructor
d3c7fc99 153 virtual ~wxRichTextParagraphStyleDefinition() {}
5d7836c4 154
38f833b1 155 /// Sets and gets the next style
5d7836c4
JS
156 void SetNextStyle(const wxString& name) { m_nextStyle = name; }
157 const wxString& GetNextStyle() const { return m_nextStyle; }
158
38f833b1 159 /// Copies from def
fe5aa22c 160 void Copy(const wxRichTextParagraphStyleDefinition& def);
38f833b1
JS
161
162 /// Assignment operator
fe5aa22c 163 void operator =(const wxRichTextParagraphStyleDefinition& def) { Copy(def); }
38f833b1
JS
164
165 /// Equality operator
fe5aa22c
JS
166 bool operator ==(const wxRichTextParagraphStyleDefinition& def) const;
167
38f833b1 168 /// Clones the object
86015e55
JS
169 virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextParagraphStyleDefinition(*this); }
170
5d7836c4
JS
171protected:
172
173 /// The next style to use when adding a paragraph after this style.
174 wxString m_nextStyle;
175};
176
38f833b1
JS
177/*!
178 * wxRichTextListStyleDefinition class declaration
179 */
180
181class WXDLLIMPEXP_RICHTEXT wxRichTextListStyleDefinition: public wxRichTextParagraphStyleDefinition
182{
183 DECLARE_DYNAMIC_CLASS(wxRichTextListStyleDefinition)
184public:
185
186 /// Copy constructor
187 wxRichTextListStyleDefinition(const wxRichTextListStyleDefinition& def): wxRichTextParagraphStyleDefinition(def) { Init(); Copy(def); }
188
189 /// Default constructor
190 wxRichTextListStyleDefinition(const wxString& name = wxEmptyString):
191 wxRichTextParagraphStyleDefinition(name) { Init(); }
192
193 /// Destructor
194 virtual ~wxRichTextListStyleDefinition() {}
195
196 /// Copies from def
197 void Copy(const wxRichTextListStyleDefinition& def);
198
199 /// Assignment operator
200 void operator =(const wxRichTextListStyleDefinition& def) { Copy(def); }
201
202 /// Equality operator
203 bool operator ==(const wxRichTextListStyleDefinition& def) const;
204
205 /// Clones the object
206 virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextListStyleDefinition(*this); }
207
208 /// Sets/gets the attributes for the given level
24777478
JS
209 void SetLevelAttributes(int i, const wxRichTextAttr& attr);
210 wxRichTextAttr* GetLevelAttributes(int i);
211 const wxRichTextAttr* GetLevelAttributes(int i) const;
38f833b1
JS
212
213 /// Convenience function for setting the major attributes for a list level specification
214 void SetAttributes(int i, int leftIndent, int leftSubIndent, int bulletStyle, const wxString& bulletSymbol = wxEmptyString);
215
216 /// Finds the level corresponding to the given indentation
217 int FindLevelForIndent(int indent) const;
218
219 /// Combine the base and list style with a paragraph style, using the given indent (from which
220 /// an appropriate level is found)
24777478 221 wxRichTextAttr CombineWithParagraphStyle(int indent, const wxRichTextAttr& paraStyle, wxRichTextStyleSheet* styleSheet = NULL);
38f833b1
JS
222
223 /// Combine the base and list style, using the given indent (from which
224 /// an appropriate level is found)
24777478 225 wxRichTextAttr GetCombinedStyle(int indent, wxRichTextStyleSheet* styleSheet = NULL);
38f833b1
JS
226
227 /// Combine the base and list style, using the given level from which
228 /// an appropriate level is found)
24777478 229 wxRichTextAttr GetCombinedStyleForLevel(int level, wxRichTextStyleSheet* styleSheet = NULL);
38f833b1
JS
230
231 /// Gets the number of available levels
232 int GetLevelCount() const { return 10; }
233
234 /// Is this a numbered list?
235 bool IsNumbered(int i) const;
236
237protected:
238
239 /// The styles for each level (up to 10)
24777478 240 wxRichTextAttr m_levelStyles[10];
38f833b1
JS
241};
242
603f702b
JS
243/*!
244 * wxRichTextBoxStyleDefinition class declaration, for box attributes in objects such as wxRichTextBox.
245 */
246
247class WXDLLIMPEXP_RICHTEXT wxRichTextBoxStyleDefinition: public wxRichTextStyleDefinition
248{
249 DECLARE_DYNAMIC_CLASS(wxRichTextBoxStyleDefinition)
250public:
251
252 /// Copy constructor
253 wxRichTextBoxStyleDefinition(const wxRichTextBoxStyleDefinition& def) { Copy(def); }
254
255 /// Default constructor
256 wxRichTextBoxStyleDefinition(const wxString& name = wxEmptyString):
257 wxRichTextStyleDefinition(name) {}
258
259 // Destructor
260 virtual ~wxRichTextBoxStyleDefinition() {}
261
262 /// Copies from def
263 void Copy(const wxRichTextBoxStyleDefinition& def);
264
265 /// Assignment operator
266 void operator =(const wxRichTextBoxStyleDefinition& def) { Copy(def); }
267
268 /// Equality operator
269 bool operator ==(const wxRichTextBoxStyleDefinition& def) const;
270
271 /// Clones the object
272 virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextBoxStyleDefinition(*this); }
273
274protected:
275};
276
5d7836c4
JS
277/*!
278 * The style sheet
279 */
280
3b2cb431 281class WXDLLIMPEXP_RICHTEXT wxRichTextStyleSheet: public wxObject
5d7836c4
JS
282{
283 DECLARE_CLASS( wxRichTextStyleSheet )
284
285public:
286 /// Constructors
b3298d1d
WS
287 wxRichTextStyleSheet(const wxRichTextStyleSheet& sheet)
288 : wxObject()
289 {
44cc96a8 290 Init();
b3298d1d
WS
291 Copy(sheet);
292 }
5d7836c4 293 wxRichTextStyleSheet() { Init(); }
38f833b1 294 virtual ~wxRichTextStyleSheet();
5d7836c4
JS
295
296 /// Initialisation
297 void Init();
298
fe5aa22c
JS
299 /// Copy
300 void Copy(const wxRichTextStyleSheet& sheet);
301
302 /// Assignment
303 void operator=(const wxRichTextStyleSheet& sheet) { Copy(sheet); }
304
305 /// Equality
306 bool operator==(const wxRichTextStyleSheet& sheet) const;
307
5d7836c4 308 /// Add a definition to the character style list
fe5aa22c 309 bool AddCharacterStyle(wxRichTextCharacterStyleDefinition* def);
5d7836c4
JS
310
311 /// Add a definition to the paragraph style list
fe5aa22c 312 bool AddParagraphStyle(wxRichTextParagraphStyleDefinition* def);
5d7836c4 313
38f833b1
JS
314 /// Add a definition to the list style list
315 bool AddListStyle(wxRichTextListStyleDefinition* def);
316
603f702b
JS
317 /// Add a definition to the box style list
318 bool AddBoxStyle(wxRichTextBoxStyleDefinition* def);
319
336d8ae9
VZ
320 /// Add a definition to the appropriate style list
321 bool AddStyle(wxRichTextStyleDefinition* def);
322
5d7836c4
JS
323 /// Remove a character style
324 bool RemoveCharacterStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_characterStyleDefinitions, def, deleteStyle); }
325
326 /// Remove a paragraph style
fe5aa22c 327 bool RemoveParagraphStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_paragraphStyleDefinitions, def, deleteStyle); }
5d7836c4 328
38f833b1
JS
329 /// Remove a list style
330 bool RemoveListStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_listStyleDefinitions, def, deleteStyle); }
331
603f702b
JS
332 /// Remove a box style
333 bool RemoveBoxStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_boxStyleDefinitions, def, deleteStyle); }
334
336d8ae9
VZ
335 /// Remove a style
336 bool RemoveStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false);
337
5d7836c4 338 /// Find a character definition by name
38f833b1 339 wxRichTextCharacterStyleDefinition* FindCharacterStyle(const wxString& name, bool recurse = true) const { return (wxRichTextCharacterStyleDefinition*) FindStyle(m_characterStyleDefinitions, name, recurse); }
5d7836c4
JS
340
341 /// Find a paragraph definition by name
38f833b1 342 wxRichTextParagraphStyleDefinition* FindParagraphStyle(const wxString& name, bool recurse = true) const { return (wxRichTextParagraphStyleDefinition*) FindStyle(m_paragraphStyleDefinitions, name, recurse); }
5d7836c4 343
38f833b1
JS
344 /// Find a list definition by name
345 wxRichTextListStyleDefinition* FindListStyle(const wxString& name, bool recurse = true) const { return (wxRichTextListStyleDefinition*) FindStyle(m_listStyleDefinitions, name, recurse); }
346
603f702b
JS
347 /// Find a box definition by name
348 wxRichTextBoxStyleDefinition* FindBoxStyle(const wxString& name, bool recurse = true) const { return (wxRichTextBoxStyleDefinition*) FindStyle(m_boxStyleDefinitions, name, recurse); }
349
336d8ae9
VZ
350 /// Find any definition by name
351 wxRichTextStyleDefinition* FindStyle(const wxString& name, bool recurse = true) const;
352
38f833b1 353 /// Return the number of character styles
5d7836c4
JS
354 size_t GetCharacterStyleCount() const { return m_characterStyleDefinitions.GetCount(); }
355
38f833b1 356 /// Return the number of paragraph styles
5d7836c4
JS
357 size_t GetParagraphStyleCount() const { return m_paragraphStyleDefinitions.GetCount(); }
358
38f833b1
JS
359 /// Return the number of list styles
360 size_t GetListStyleCount() const { return m_listStyleDefinitions.GetCount(); }
361
603f702b
JS
362 /// Return the number of box styles
363 size_t GetBoxStyleCount() const { return m_boxStyleDefinitions.GetCount(); }
364
5d7836c4
JS
365 /// Return the nth character style
366 wxRichTextCharacterStyleDefinition* GetCharacterStyle(size_t n) const { return (wxRichTextCharacterStyleDefinition*) m_characterStyleDefinitions.Item(n)->GetData(); }
367
368 /// Return the nth paragraph style
369 wxRichTextParagraphStyleDefinition* GetParagraphStyle(size_t n) const { return (wxRichTextParagraphStyleDefinition*) m_paragraphStyleDefinitions.Item(n)->GetData(); }
370
38f833b1
JS
371 /// Return the nth list style
372 wxRichTextListStyleDefinition* GetListStyle(size_t n) const { return (wxRichTextListStyleDefinition*) m_listStyleDefinitions.Item(n)->GetData(); }
373
603f702b
JS
374 /// Return the nth box style
375 wxRichTextBoxStyleDefinition* GetBoxStyle(size_t n) const { return (wxRichTextBoxStyleDefinition*) m_boxStyleDefinitions.Item(n)->GetData(); }
376
5d7836c4
JS
377 /// Delete all styles
378 void DeleteStyles();
379
38f833b1
JS
380 /// Insert into list of style sheets
381 bool InsertSheet(wxRichTextStyleSheet* before);
382
383 /// Append to list of style sheets
384 bool AppendSheet(wxRichTextStyleSheet* after);
385
386 /// Unlink from the list of style sheets
387 void Unlink();
388
389 /// Get/set next sheet
390 wxRichTextStyleSheet* GetNextSheet() const { return m_nextSheet; }
391 void SetNextSheet(wxRichTextStyleSheet* sheet) { m_nextSheet = sheet; }
392
393 /// Get/set previous sheet
394 wxRichTextStyleSheet* GetPreviousSheet() const { return m_previousSheet; }
395 void SetPreviousSheet(wxRichTextStyleSheet* sheet) { m_previousSheet = sheet; }
396
42688aea
JS
397 /// Sets and gets the name of the style sheet
398 void SetName(const wxString& name) { m_name = name; }
399 const wxString& GetName() const { return m_name; }
400
401 /// Sets and gets the style description
402 void SetDescription(const wxString& descr) { m_description = descr; }
403 const wxString& GetDescription() const { return m_description; }
404
5d7836c4
JS
405/// Implementation
406
407 /// Add a definition to one of the style lists
408 bool AddStyle(wxList& list, wxRichTextStyleDefinition* def);
409
410 /// Remove a style
411 bool RemoveStyle(wxList& list, wxRichTextStyleDefinition* def, bool deleteStyle);
412
413 /// Find a definition by name
38f833b1 414 wxRichTextStyleDefinition* FindStyle(const wxList& list, const wxString& name, bool recurse = true) const;
5d7836c4
JS
415
416protected:
417
42688aea
JS
418 wxString m_description;
419 wxString m_name;
420
421 wxList m_characterStyleDefinitions;
422 wxList m_paragraphStyleDefinitions;
423 wxList m_listStyleDefinitions;
603f702b 424 wxList m_boxStyleDefinitions;
38f833b1 425
42688aea
JS
426 wxRichTextStyleSheet* m_previousSheet;
427 wxRichTextStyleSheet* m_nextSheet;
5d7836c4
JS
428};
429
430#if wxUSE_HTML
431/*!
432 * wxRichTextStyleListBox class declaration
433 * A listbox to display styles.
434 */
435
3b2cb431 436class WXDLLIMPEXP_RICHTEXT wxRichTextStyleListBox: public wxHtmlListBox
5d7836c4
JS
437{
438 DECLARE_CLASS(wxRichTextStyleListBox)
439 DECLARE_EVENT_TABLE()
440
441public:
38f833b1
JS
442 /// Which type of style definition is currently showing?
443 enum wxRichTextStyleType
444 {
445 wxRICHTEXT_STYLE_ALL,
446 wxRICHTEXT_STYLE_PARAGRAPH,
447 wxRICHTEXT_STYLE_CHARACTER,
603f702b
JS
448 wxRICHTEXT_STYLE_LIST,
449 wxRICHTEXT_STYLE_BOX
38f833b1
JS
450 };
451
e637208a
JS
452 wxRichTextStyleListBox()
453 {
454 Init();
455 }
5d7836c4
JS
456 wxRichTextStyleListBox(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
457 const wxSize& size = wxDefaultSize, long style = 0);
d3c7fc99 458 virtual ~wxRichTextStyleListBox();
5d7836c4 459
e637208a
JS
460 void Init()
461 {
462 m_styleSheet = NULL;
463 m_richTextCtrl = NULL;
38f833b1
JS
464 m_applyOnSelection = false;
465 m_styleType = wxRICHTEXT_STYLE_PARAGRAPH;
dadd4f55 466 m_autoSetSelection = true;
e637208a
JS
467 }
468
469 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
470 const wxSize& size = wxDefaultSize, long style = 0);
471
5d7836c4
JS
472 /// Creates a suitable HTML fragment for a definition
473 wxString CreateHTML(wxRichTextStyleDefinition* def) const;
474
1f65137f 475 /// Associates the control with a style sheet
5d7836c4
JS
476 void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; }
477 wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
478
479 /// Associates the control with a wxRichTextCtrl
480 void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_richTextCtrl = ctrl; }
481 wxRichTextCtrl* GetRichTextCtrl() const { return m_richTextCtrl; }
482
e637208a 483 /// Get style for index
5d7836c4
JS
484 wxRichTextStyleDefinition* GetStyle(size_t i) const ;
485
e637208a
JS
486 /// Get index for style name
487 int GetIndexForStyle(const wxString& name) const ;
488
489 /// Set selection for string, returning the index.
490 int SetStyleSelection(const wxString& name);
491
5d7836c4
JS
492 /// Updates the list
493 void UpdateStyles();
494
86015e55
JS
495 /// Apply the style
496 void ApplyStyle(int i);
e637208a 497
5d7836c4
JS
498 /// Left click
499 void OnLeftDown(wxMouseEvent& event);
500
38f833b1
JS
501 /// Left double-click
502 void OnLeftDoubleClick(wxMouseEvent& event);
503
e637208a
JS
504 /// Auto-select from style under caret in idle time
505 void OnIdle(wxIdleEvent& event);
506
e637208a 507 /// Convert units in tends of a millimetre to device units
5d7836c4
JS
508 int ConvertTenthsMMToPixels(wxDC& dc, int units) const;
509
e637208a
JS
510 /// Can we set the selection based on the editor caret position?
511 /// Need to override this if being used in a combobox popup
dadd4f55
JS
512 virtual bool CanAutoSetSelection() { return m_autoSetSelection; }
513 virtual void SetAutoSetSelection(bool autoSet) { m_autoSetSelection = autoSet; }
e637208a 514
86015e55
JS
515 /// Set whether the style should be applied as soon as the item is selected (the default)
516 void SetApplyOnSelection(bool applyOnSel) { m_applyOnSelection = applyOnSel; }
517 bool GetApplyOnSelection() const { return m_applyOnSelection; }
518
38f833b1
JS
519 /// Set the style type to display
520 void SetStyleType(wxRichTextStyleType styleType) { m_styleType = styleType; UpdateStyles(); }
521 wxRichTextStyleType GetStyleType() const { return m_styleType; }
522
523 /// Helper for listbox and combo control
524 static wxString GetStyleToShowInIdleTime(wxRichTextCtrl* ctrl, wxRichTextStyleType styleType);
525
6f02a879
VZ
526protected:
527 /// Returns the HTML for this item
528 virtual wxString OnGetItem(size_t n) const;
529
5d7836c4
JS
530private:
531
532 wxRichTextStyleSheet* m_styleSheet;
533 wxRichTextCtrl* m_richTextCtrl;
86015e55 534 bool m_applyOnSelection; // if true, applies style on selection
38f833b1 535 wxRichTextStyleType m_styleType; // style type to display
dadd4f55 536 bool m_autoSetSelection;
486dd03a 537 wxArrayString m_styleNames;
38f833b1
JS
538};
539
540/*!
541 * wxRichTextStyleListCtrl class declaration
542 * This is a container for the list control plus a combobox to switch between
543 * style types.
544 */
545
dadd4f55
JS
546#define wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR 0x1000
547
38f833b1
JS
548class WXDLLIMPEXP_RICHTEXT wxRichTextStyleListCtrl: public wxControl
549{
550 DECLARE_CLASS(wxRichTextStyleListCtrl)
551 DECLARE_EVENT_TABLE()
552
553public:
554
555 /// Constructors
556 wxRichTextStyleListCtrl()
557 {
558 Init();
559 }
560
561 wxRichTextStyleListCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
562 const wxSize& size = wxDefaultSize, long style = 0);
563
564 /// Constructors
565 virtual ~wxRichTextStyleListCtrl();
566
567 /// Member initialisation
568 void Init()
569 {
570 m_styleListBox = NULL;
571 m_styleChoice = NULL;
572 m_dontUpdate = false;
573 }
574
575 /// Creates the windows
576 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
577 const wxSize& size = wxDefaultSize, long style = 0);
578
dadd4f55
JS
579 /// Updates the style list box
580 void UpdateStyles();
581
1f65137f 582 /// Associates the control with a style sheet
38f833b1
JS
583 void SetStyleSheet(wxRichTextStyleSheet* styleSheet);
584 wxRichTextStyleSheet* GetStyleSheet() const;
585
586 /// Associates the control with a wxRichTextCtrl
587 void SetRichTextCtrl(wxRichTextCtrl* ctrl);
588 wxRichTextCtrl* GetRichTextCtrl() const;
589
38f833b1
JS
590 /// Set/get the style type to display
591 void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType);
592 wxRichTextStyleListBox::wxRichTextStyleType GetStyleType() const;
593
594 /// Get the choice index for style type
595 int StyleTypeToIndex(wxRichTextStyleListBox::wxRichTextStyleType styleType);
596
597 /// Get the style type for choice index
598 wxRichTextStyleListBox::wxRichTextStyleType StyleIndexToType(int i);
599
600 /// Get the listbox
601 wxRichTextStyleListBox* GetStyleListBox() const { return m_styleListBox; }
602
603 /// Get the choice
604 wxChoice* GetStyleChoice() const { return m_styleChoice; }
605
606 /// React to style type choice
607 void OnChooseType(wxCommandEvent& event);
608
609 /// Lay out the controls
610 void OnSize(wxSizeEvent& event);
611
612private:
613
614 wxRichTextStyleListBox* m_styleListBox;
615 wxChoice* m_styleChoice;
616 bool m_dontUpdate;
5d7836c4 617};
e637208a
JS
618
619#if wxUSE_COMBOCTRL
620
621/*!
622 * Style drop-down for a wxComboCtrl
623 */
624
625class wxRichTextStyleComboPopup : public wxRichTextStyleListBox, public wxComboPopup
626{
627public:
628 virtual void Init()
629 {
630 m_itemHere = -1; // hot item in list
631 m_value = -1;
632 }
633
a047aff2 634 virtual bool Create( wxWindow* parent );
e637208a
JS
635
636 virtual wxWindow *GetControl() { return this; }
637
638 virtual void SetStringValue( const wxString& s );
639
640 virtual wxString GetStringValue() const;
641
642 /// Can we set the selection based on the editor caret position?
643 // virtual bool CanAutoSetSelection() { return ((m_combo == NULL) || !m_combo->IsPopupShown()); }
644 virtual bool CanAutoSetSelection() { return false; }
645
646 //
647 // Popup event handlers
648 //
649
650 // Mouse hot-tracking
651 void OnMouseMove(wxMouseEvent& event);
652
653 // On mouse left, set the value and close the popup
654 void OnMouseClick(wxMouseEvent& WXUNUSED(event));
655
656protected:
657
658 int m_itemHere; // hot item in popup
659 int m_value;
660
661private:
662 DECLARE_EVENT_TABLE()
663};
664
665/*!
666 * wxRichTextStyleComboCtrl
667 * A combo for applying styles.
668 */
669
670class WXDLLIMPEXP_RICHTEXT wxRichTextStyleComboCtrl: public wxComboCtrl
671{
672 DECLARE_CLASS(wxRichTextStyleComboCtrl)
673 DECLARE_EVENT_TABLE()
674
675public:
676 wxRichTextStyleComboCtrl()
677 {
678 Init();
679 }
680
681 wxRichTextStyleComboCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
682 const wxSize& size = wxDefaultSize, long style = wxCB_READONLY)
683 {
684 Init();
685 Create(parent, id, pos, size, style);
686 }
687
688 virtual ~wxRichTextStyleComboCtrl() {}
689
690 void Init()
691 {
692 m_stylePopup = NULL;
693 }
694
695 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
696 const wxSize& size = wxDefaultSize, long style = 0);
697
698 /// Updates the list
699 void UpdateStyles() { m_stylePopup->UpdateStyles(); }
700
1f65137f 701 /// Associates the control with a style sheet
e637208a
JS
702 void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_stylePopup->SetStyleSheet(styleSheet); }
703 wxRichTextStyleSheet* GetStyleSheet() const { return m_stylePopup->GetStyleSheet(); }
704
705 /// Associates the control with a wxRichTextCtrl
706 void SetRichTextCtrl(wxRichTextCtrl* ctrl) { m_stylePopup->SetRichTextCtrl(ctrl); }
707 wxRichTextCtrl* GetRichTextCtrl() const { return m_stylePopup->GetRichTextCtrl(); }
708
709 /// Gets the style popup
710 wxRichTextStyleComboPopup* GetStylePopup() const { return m_stylePopup; }
711
712 /// Auto-select from style under caret in idle time
713 void OnIdle(wxIdleEvent& event);
714
715protected:
716 wxRichTextStyleComboPopup* m_stylePopup;
717};
718
719#endif
720 // wxUSE_COMBOCTRL
721
5d7836c4 722#endif
e637208a 723 // wxUSE_HTML
5d7836c4
JS
724
725#endif
726 // wxUSE_RICHTEXT
727
728#endif
729 // _WX_RICHTEXTSTYLES_H_