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