1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextformatdlg.cpp
3 // Purpose: Formatting dialog for wxRichTextCtrl
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/richtext/richtextformatdlg.h"
23 #include "wx/listbox.h"
24 #include "wx/combobox.h"
25 #include "wx/textctrl.h"
27 #include "wx/stattext.h"
28 #include "wx/statline.h"
29 #include "wx/radiobut.h"
31 #include "wx/bitmap.h"
32 #include "wx/dcclient.h"
34 #include "wx/checkbox.h"
35 #include "wx/button.h"
38 #include "wx/bookctrl.h"
39 #include "wx/colordlg.h"
40 #include "wx/settings.h"
41 #include "wx/module.h"
42 #include "wx/imaglist.h"
44 #include "wx/richtext/richtextctrl.h"
45 #include "wx/richtext/richtextstyles.h"
48 #include "../../src/richtext/richtextfontpage.cpp"
49 #include "../../src/richtext/richtextindentspage.cpp"
50 #include "../../src/richtext/richtexttabspage.cpp"
51 #include "../../src/richtext/richtextbulletspage.cpp"
52 #include "../../src/richtext/richtextstylepage.cpp"
53 #include "../../src/richtext/richtextliststylepage.cpp"
54 #include "../../src/richtext/richtextsizepage.cpp"
55 #include "../../src/richtext/richtextmarginspage.cpp"
56 #include "../../src/richtext/richtextborderspage.cpp"
57 #include "../../src/richtext/richtextbackgroundpage.cpp"
59 #include "richtextfontpage.cpp"
60 #include "richtextindentspage.cpp"
61 #include "richtexttabspage.cpp"
62 #include "richtextbulletspage.cpp"
63 #include "richtextmarginspage.cpp"
64 #include "richtextsizepage.cpp"
65 #include "richtextborderspage.cpp"
66 #include "richtextbackgroundpage.cpp"
67 // Digital Mars can't cope with this much code
69 #include "richtextliststylepage.cpp"
71 #include "richtextstylepage.cpp"
74 #if 0 // def __WXMAC__
75 #define wxRICHTEXT_USE_TOOLBOOK 1
77 #define wxRICHTEXT_USE_TOOLBOOK 0
80 bool wxRichTextFormattingDialog::sm_showToolTips
= false;
82 IMPLEMENT_CLASS(wxRichTextDialogPage
, wxPanel
)
84 IMPLEMENT_CLASS(wxRichTextFormattingDialog
, wxPropertySheetDialog
)
86 BEGIN_EVENT_TABLE(wxRichTextFormattingDialog
, wxPropertySheetDialog
)
87 EVT_BOOKCTRL_PAGE_CHANGED(wxID_ANY
, wxRichTextFormattingDialog::OnTabChanged
)
88 EVT_BUTTON(wxID_HELP
, wxRichTextFormattingDialog::OnHelp
)
89 EVT_UPDATE_UI(wxID_HELP
, wxRichTextFormattingDialog::OnUpdateHelp
)
92 IMPLEMENT_HELP_PROVISION(wxRichTextFormattingDialog
)
94 wxRichTextFormattingDialogFactory
* wxRichTextFormattingDialog::ms_FormattingDialogFactory
= NULL
;
96 void wxRichTextFormattingDialog::Init()
98 m_styleDefinition
= NULL
;
104 wxRichTextFormattingDialog::~wxRichTextFormattingDialog()
106 delete m_styleDefinition
;
109 bool wxRichTextFormattingDialog::Create(long flags
, wxWindow
* parent
, const wxString
& title
, wxWindowID id
,
110 const wxPoint
& pos
, const wxSize
& sz
, long style
)
112 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
114 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
117 int resizeBorder
= wxRESIZE_BORDER
;
119 GetFormattingDialogFactory()->SetSheetStyle(this);
121 wxPropertySheetDialog::Create(parent
, id
, title
, pos
, sz
,
122 style
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
125 GetFormattingDialogFactory()->CreateButtons(this);
126 GetFormattingDialogFactory()->CreatePages(flags
, this);
133 /// Get attributes from the given range
134 bool wxRichTextFormattingDialog::GetStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
)
136 if (ctrl
->GetFocusObject()->GetStyleForRange(range
.ToInternal(), m_attributes
))
137 return UpdateDisplay();
142 /// Apply attributes to the given range, only applying if necessary (wxRICHTEXT_SETSTYLE_OPTIMIZE)
143 bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
, int flags
)
145 return ctrl
->SetStyleEx(range
, m_attributes
, flags
);
148 // Apply attributes to the object being edited, if any
149 bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl
* ctrl
, int flags
)
153 ctrl
->SetStyle(GetObject(), m_attributes
, flags
);
160 /// Set the attributes and optionally update the display
161 bool wxRichTextFormattingDialog::SetStyle(const wxRichTextAttr
& style
, bool update
)
163 m_attributes
= style
;
169 /// Set the style definition and optionally update the display
170 bool wxRichTextFormattingDialog::SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
, wxRichTextStyleSheet
* sheet
, bool update
)
172 m_styleSheet
= sheet
;
174 if (m_styleDefinition
)
175 delete m_styleDefinition
;
176 m_styleDefinition
= styleDef
.Clone();
178 return SetStyle(m_styleDefinition
->GetStyle(), update
);
181 /// Transfers the data and from to the window
182 bool wxRichTextFormattingDialog::TransferDataToWindow()
184 if (m_styleDefinition
)
185 m_attributes
= m_styleDefinition
->GetStyle();
187 if (!wxPropertySheetDialog::TransferDataToWindow())
193 bool wxRichTextFormattingDialog::TransferDataFromWindow()
195 if (!wxPropertySheetDialog::TransferDataFromWindow())
198 if (m_styleDefinition
)
199 m_styleDefinition
->GetStyle() = m_attributes
;
204 /// Update the display
205 bool wxRichTextFormattingDialog::UpdateDisplay()
207 return TransferDataToWindow();
210 /// Apply the styles when a different tab is selected, so the previews are
212 void wxRichTextFormattingDialog::OnTabChanged(wxBookCtrlEvent
& event
)
214 if (GetBookCtrl() != event
.GetEventObject())
220 int oldPageId
= event
.GetOldSelection();
223 wxWindow
* page
= GetBookCtrl()->GetPage(oldPageId
);
225 page
->TransferDataFromWindow();
228 int pageId
= event
.GetSelection();
231 wxWindow
* page
= GetBookCtrl()->GetPage(pageId
);
233 page
->TransferDataToWindow();
237 /// Respond to help command
238 void wxRichTextFormattingDialog::OnHelp(wxCommandEvent
& event
)
240 int selPage
= GetBookCtrl()->GetSelection();
241 if (selPage
!= wxNOT_FOUND
)
244 if (selPage
< (int) m_pageIds
.GetCount())
245 pageId
= m_pageIds
[selPage
];
246 if (!GetFormattingDialogFactory()->ShowHelp(pageId
, this))
251 void wxRichTextFormattingDialog::OnUpdateHelp(wxUpdateUIEvent
& event
)
256 void wxRichTextFormattingDialog::SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
)
258 if (ms_FormattingDialogFactory
)
259 delete ms_FormattingDialogFactory
;
260 ms_FormattingDialogFactory
= factory
;
263 // Find a page by class
264 wxWindow
* wxRichTextFormattingDialog::FindPage(wxClassInfo
* info
) const
267 for (i
= 0; i
< GetBookCtrl()->GetPageCount(); i
++)
269 wxWindow
* w
= GetBookCtrl()->GetPage(i
);
270 if (w
&& w
->GetClassInfo() == info
)
278 * Factory for formatting dialog
281 /// Create all pages, under the dialog's book control, also calling AddPage
282 bool wxRichTextFormattingDialogFactory::CreatePages(long pages
, wxRichTextFormattingDialog
* dialog
)
284 if (dialog
->GetImageList())
285 dialog
->GetBookCtrl()->SetImageList(dialog
->GetImageList());
287 int availablePageCount
= GetPageIdCount();
289 bool selected
= false;
290 for (i
= 0; i
< availablePageCount
; i
++)
292 int pageId
= GetPageId(i
);
293 if (pageId
!= -1 && (pages
& pageId
))
296 wxPanel
* panel
= CreatePage(pageId
, title
, dialog
);
297 wxASSERT( panel
!= NULL
);
300 int imageIndex
= GetPageImage(pageId
);
301 dialog
->GetBookCtrl()->AddPage(panel
, title
, !selected
, imageIndex
);
304 dialog
->AddPageId(pageId
);
312 /// Create a page, given a page identifier
313 wxPanel
* wxRichTextFormattingDialogFactory::CreatePage(int page
, wxString
& title
, wxRichTextFormattingDialog
* dialog
)
315 if (page
== wxRICHTEXT_FORMAT_STYLE_EDITOR
)
317 wxRichTextStylePage
* page
= new wxRichTextStylePage(dialog
->GetBookCtrl(), wxID_ANY
);
321 else if (page
== wxRICHTEXT_FORMAT_FONT
)
323 wxRichTextFontPage
* page
= new wxRichTextFontPage(dialog
->GetBookCtrl(), wxID_ANY
);
327 else if (page
== wxRICHTEXT_FORMAT_INDENTS_SPACING
)
329 wxRichTextIndentsSpacingPage
* page
= new wxRichTextIndentsSpacingPage(dialog
->GetBookCtrl(), wxID_ANY
);
330 title
= _("Indents && Spacing");
333 else if (page
== wxRICHTEXT_FORMAT_TABS
)
335 wxRichTextTabsPage
* page
= new wxRichTextTabsPage(dialog
->GetBookCtrl(), wxID_ANY
);
339 else if (page
== wxRICHTEXT_FORMAT_BULLETS
)
341 wxRichTextBulletsPage
* page
= new wxRichTextBulletsPage(dialog
->GetBookCtrl(), wxID_ANY
);
342 title
= _("Bullets");
346 else if (page
== wxRICHTEXT_FORMAT_LIST_STYLE
)
348 wxRichTextListStylePage
* page
= new wxRichTextListStylePage(dialog
->GetBookCtrl(), wxID_ANY
);
349 title
= _("List Style");
353 else if (page
== wxRICHTEXT_FORMAT_SIZE
)
355 wxRichTextSizePage
* page
= new wxRichTextSizePage(dialog
->GetBookCtrl(), wxID_ANY
);
359 else if (page
== wxRICHTEXT_FORMAT_MARGINS
)
361 wxRichTextMarginsPage
* page
= new wxRichTextMarginsPage(dialog
->GetBookCtrl(), wxID_ANY
);
362 title
= _("Margins");
365 else if (page
== wxRICHTEXT_FORMAT_BORDERS
)
367 wxRichTextBordersPage
* page
= new wxRichTextBordersPage(dialog
->GetBookCtrl(), wxID_ANY
);
368 title
= _("Borders");
371 else if (page
== wxRICHTEXT_FORMAT_BACKGROUND
)
373 wxRichTextBackgroundPage
* page
= new wxRichTextBackgroundPage(dialog
->GetBookCtrl(), wxID_ANY
);
374 title
= _("Background");
381 /// Enumerate all available page identifiers
382 int wxRichTextFormattingDialogFactory::GetPageId(int i
) const
385 wxRICHTEXT_FORMAT_STYLE_EDITOR
,
386 wxRICHTEXT_FORMAT_FONT
,
387 wxRICHTEXT_FORMAT_INDENTS_SPACING
,
388 wxRICHTEXT_FORMAT_BULLETS
,
389 wxRICHTEXT_FORMAT_TABS
,
390 wxRICHTEXT_FORMAT_LIST_STYLE
,
391 wxRICHTEXT_FORMAT_SIZE
,
392 wxRICHTEXT_FORMAT_MARGINS
,
393 wxRICHTEXT_FORMAT_BORDERS
,
394 wxRICHTEXT_FORMAT_BACKGROUND
397 if (i
< 0 || i
>= GetPageIdCount())
403 /// Get the number of available page identifiers
404 int wxRichTextFormattingDialogFactory::GetPageIdCount() const
413 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
414 bool wxRichTextFormattingDialogFactory::SetSheetStyle(wxRichTextFormattingDialog
* dialog
)
416 #if wxRICHTEXT_USE_TOOLBOOK
417 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
419 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
421 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
424 dialog
->SetSheetStyle(sheetStyle
);
425 dialog
->SetSheetInnerBorder(0);
426 dialog
->SetSheetOuterBorder(0);
429 #endif // wxRICHTEXT_USE_TOOLBOOK
434 /// Create the main dialog buttons
435 bool wxRichTextFormattingDialogFactory::CreateButtons(wxRichTextFormattingDialog
* dialog
)
437 int flags
= wxOK
|wxCANCEL
;
439 if (dialog
->GetWindowStyleFlag() & wxRICHTEXT_FORMAT_HELP_BUTTON
)
443 // If using a toolbook, also follow Mac style and don't create buttons
444 #if !wxRICHTEXT_USE_TOOLBOOK
445 dialog
->CreateButtons(flags
);
451 // Invoke help for the dialog
452 bool wxRichTextFormattingDialogFactory::ShowHelp(int WXUNUSED(page
), wxRichTextFormattingDialog
* dialog
)
454 wxRichTextDialogPage
* window
= NULL
;
455 int sel
= dialog
->GetBookCtrl()->GetSelection();
457 window
= wxDynamicCast(dialog
->GetBookCtrl()->GetPage(sel
), wxRichTextDialogPage
);
458 if (window
&& window
->GetHelpId() != -1)
460 if (window
->GetUICustomization())
461 return window
->GetUICustomization()->ShowHelp(dialog
, window
->GetHelpId());
462 else if (dialog
->GetUICustomization())
463 return dialog
->GetUICustomization()->ShowHelp(dialog
, window
->GetHelpId());
467 else if (dialog
->GetHelpId() != -1 && dialog
->GetUICustomization())
468 return dialog
->ShowHelp(dialog
);
474 * Module to initialise and clean up handlers
477 class wxRichTextFormattingDialogModule
: public wxModule
479 DECLARE_DYNAMIC_CLASS(wxRichTextFormattingDialogModule
)
481 wxRichTextFormattingDialogModule() {}
482 bool OnInit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(new wxRichTextFormattingDialogFactory
); return true; }
483 void OnExit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(NULL
); }
486 IMPLEMENT_DYNAMIC_CLASS(wxRichTextFormattingDialogModule
, wxModule
)
489 * Font preview control
492 BEGIN_EVENT_TABLE(wxRichTextFontPreviewCtrl
, wxWindow
)
493 EVT_PAINT(wxRichTextFontPreviewCtrl::OnPaint
)
496 wxRichTextFontPreviewCtrl::wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& sz
, long style
)
498 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
499 style
|= wxBORDER_THEME
;
501 wxWindow::Create(parent
, id
, pos
, sz
, style
);
503 SetBackgroundColour(*wxWHITE
);
507 void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
511 wxSize size
= GetSize();
512 wxFont font
= GetFont();
514 if ((GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
) || (GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
))
516 double size
= static_cast<double>(font
.GetPointSize()) / wxSCRIPT_MUL_FACTOR
;
517 font
.SetPointSize( static_cast<int>(size
) );
523 // Calculate vertical and horizontal centre
524 wxCoord w
= 0, h
= 0;
526 wxString
text(_("ABCDEFGabcdefg12345"));
527 if (GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS
)
530 dc
.GetTextExtent( text
, &w
, &h
);
531 int cx
= wxMax(2, (size
.x
/2) - (w
/2));
532 int cy
= wxMax(2, (size
.y
/2) - (h
/2));
534 if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
)
536 if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
)
539 dc
.SetTextForeground(GetForegroundColour());
540 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
541 dc
.DrawText(text
, cx
, cy
);
543 if (GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH
)
545 dc
.SetPen(wxPen(GetForegroundColour(), 1));
546 dc
.DrawLine(cx
, (int) (cy
+ h
/2 + 0.5), cx
+ w
, (int) (cy
+ h
/2 + 0.5));
549 dc
.DestroyClippingRegion();
553 // Helper for pages to get the top-level dialog
554 wxRichTextFormattingDialog
* wxRichTextFormattingDialog::GetDialog(wxWindow
* win
)
556 wxWindow
* p
= win
->GetParent();
557 while (p
&& !wxDynamicCast(p
, wxRichTextFormattingDialog
))
559 wxRichTextFormattingDialog
* dialog
= wxDynamicCast(p
, wxRichTextFormattingDialog
);
563 // Helper for pages to get the attributes
564 wxRichTextAttr
* wxRichTextFormattingDialog::GetDialogAttributes(wxWindow
* win
)
566 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
568 return & dialog
->GetAttributes();
574 // Helper for pages to get the attributes to reset
575 wxRichTextAttr
* wxRichTextFormattingDialog::GetDialogResetAttributes(wxWindow
* win
)
577 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
579 return & dialog
->GetResetAttributes();
585 // Helper for pages to get the style
586 wxRichTextStyleDefinition
* wxRichTextFormattingDialog::GetDialogStyleDefinition(wxWindow
* win
)
588 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
590 return dialog
->GetStyleDefinition();
595 void wxRichTextFormattingDialog::SetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
)
602 checkBox
->SetValue(false);
603 valueCtrl
->SetValue(wxT("0"));
604 unitsCtrl
->SetSelection(0);
607 dim
.SetUnits(wxTEXT_ATTR_UNITS_PIXELS
);
613 checkBox
->SetValue(true);
614 if (dim
.GetUnits() == wxTEXT_ATTR_UNITS_TENTHS_MM
)
617 float value
= float(dim
.GetValue()) / 100.0;
618 valueCtrl
->SetValue(wxString::Format(wxT("%.2f"), value
));
620 else if (dim
.GetUnits() == wxTEXT_ATTR_UNITS_PERCENTAGE
)
623 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
628 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
631 unitsCtrl
->SetSelection(unitsIdx
);
635 void wxRichTextFormattingDialog::GetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
)
637 if (checkBox
&& !checkBox
->GetValue())
643 if (unitsCtrl
->GetSelection() == 1)
644 dim
.SetUnits(wxTEXT_ATTR_UNITS_TENTHS_MM
);
645 else if (unitsCtrl
->GetSelection() == 2)
646 dim
.SetUnits(wxTEXT_ATTR_UNITS_PERCENTAGE
);
648 dim
.SetUnits(wxTEXT_ATTR_UNITS_PIXELS
);
651 if (ConvertFromString(valueCtrl
->GetValue(), value
, dim
.GetUnits()))
656 bool wxRichTextFormattingDialog::ConvertFromString(const wxString
& string
, int& ret
, int scale
)
658 const wxChar
* chars
= string
.GetData();
663 for (unsigned int i
= 0; i
< string
.Len() && remain
; i
++)
665 if (!(chars
[i
] >= wxT('0') && chars
[i
] <= wxT('9')) && !(scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
&& chars
[i
] == wxT('.')))
668 if (chars
[i
] == wxT('.'))
677 ret
= ret
* 10 + chars
[i
] - wxT('0');
680 while (remain
-- > 0 && scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
)
687 * A control for displaying a small preview of a colour or bitmap
690 BEGIN_EVENT_TABLE(wxRichTextColourSwatchCtrl
, wxControl
)
691 EVT_MOUSE_EVENTS(wxRichTextColourSwatchCtrl::OnMouseEvent
)
694 IMPLEMENT_CLASS(wxRichTextColourSwatchCtrl
, wxControl
)
696 wxRichTextColourSwatchCtrl::wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
698 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
699 style
|= wxBORDER_THEME
;
701 wxControl::Create(parent
, id
, pos
, size
, style
);
703 SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
706 wxRichTextColourSwatchCtrl::~wxRichTextColourSwatchCtrl()
710 void wxRichTextColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
712 if (event
.LeftDown())
714 wxWindow
* parent
= GetParent();
715 while (parent
!= NULL
&& !wxDynamicCast(parent
, wxDialog
) && !wxDynamicCast(parent
, wxFrame
))
716 parent
= parent
->GetParent();
719 data
.SetChooseFull(true);
720 data
.SetColour(m_colour
);
722 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
723 // Crashes on wxMac (no m_peer)
725 dialog
->SetTitle(_("Colour"));
727 if (dialog
->ShowModal() == wxID_OK
)
729 wxColourData retData
= dialog
->GetColourData();
730 m_colour
= retData
.GetColour();
731 SetBackgroundColour(m_colour
);
734 #endif // wxUSE_COLOURDLG
737 wxCommandEvent
event(wxEVT_BUTTON
, GetId());
738 GetEventHandler()->ProcessEvent(event
);
745 * wxRichTextFontListBox class declaration
746 * A listbox to display styles.
749 IMPLEMENT_CLASS(wxRichTextFontListBox
, wxHtmlListBox
)
751 BEGIN_EVENT_TABLE(wxRichTextFontListBox
, wxHtmlListBox
)
754 wxRichTextFontListBox::wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
755 const wxSize
& size
, long style
)
758 Create(parent
, id
, pos
, size
, style
);
761 bool wxRichTextFontListBox::Create(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
762 const wxSize
& size
, long style
)
764 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
765 style
|= wxBORDER_THEME
;
767 return wxHtmlListBox::Create(parent
, id
, pos
, size
, style
);
770 wxRichTextFontListBox::~wxRichTextFontListBox()
774 /// Returns the HTML for this item
775 wxString
wxRichTextFontListBox::OnGetItem(size_t n
) const
777 if (m_faceNames
.GetCount() == 0)
778 return wxEmptyString
;
780 wxString str
= CreateHTML(m_faceNames
[n
]);
784 /// Get font name for index
785 wxString
wxRichTextFontListBox::GetFaceName(size_t i
) const
787 return m_faceNames
[i
];
790 /// Set selection for string, returning the index.
791 int wxRichTextFontListBox::SetFaceNameSelection(const wxString
& name
)
793 int i
= m_faceNames
.Index(name
);
799 /// Updates the font list
800 void wxRichTextFontListBox::UpdateFonts()
802 wxArrayString facenames
= wxRichTextCtrl::GetAvailableFontNames();
803 m_faceNames
= facenames
;
806 SetItemCount(m_faceNames
.GetCount());
811 // Convert a colour to a 6-digit hex string
812 static wxString
ColourToHexString(const wxColour
& col
)
816 hex
+= wxDecToHex(col
.Red());
817 hex
+= wxDecToHex(col
.Green());
818 hex
+= wxDecToHex(col
.Blue());
824 /// Creates a suitable HTML fragment for a definition
825 wxString
wxRichTextFontListBox::CreateHTML(const wxString
& facename
) const
827 wxString str
= wxT("<font");
829 str
<< wxT(" size=\"+2\"");;
831 if (!facename
.IsEmpty() && facename
!= _("(none)"))
832 str
<< wxT(" face=\"") << facename
<< wxT("\"");
834 if (def->GetStyle().GetTextColour().IsOk())
835 str << wxT(" color=\"#") << ColourToHexString(def->GetStyle().GetTextColour()) << wxT("\"");
840 bool hasBold
= false;
850 str
<< wxT("</font>");