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