1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextformatdlg.cpp
3 // Purpose: Formatting dialog for wxRichTextCtrl
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/richtext/richtextformatdlg.h"
24 #include "wx/listbox.h"
25 #include "wx/combobox.h"
26 #include "wx/textctrl.h"
28 #include "wx/stattext.h"
29 #include "wx/statline.h"
30 #include "wx/radiobut.h"
32 #include "wx/bitmap.h"
33 #include "wx/dcclient.h"
35 #include "wx/checkbox.h"
36 #include "wx/button.h"
39 #include "wx/bookctrl.h"
40 #include "wx/colordlg.h"
41 #include "wx/settings.h"
42 #include "wx/module.h"
43 #include "wx/imaglist.h"
45 #include "wx/richtext/richtextctrl.h"
46 #include "wx/richtext/richtextstyles.h"
49 #include "../../src/richtext/richtextfontpage.cpp"
50 #include "../../src/richtext/richtextindentspage.cpp"
51 #include "../../src/richtext/richtexttabspage.cpp"
52 #include "../../src/richtext/richtextbulletspage.cpp"
53 #include "../../src/richtext/richtextstylepage.cpp"
54 #include "../../src/richtext/richtextliststylepage.cpp"
55 #include "../../src/richtext/richtextsizepage.cpp"
56 #include "../../src/richtext/richtextmarginspage.cpp"
57 #include "../../src/richtext/richtextborderspage.cpp"
58 #include "../../src/richtext/richtextbackgroundpage.cpp"
60 #include "richtextfontpage.cpp"
61 #include "richtextindentspage.cpp"
62 #include "richtexttabspage.cpp"
63 #include "richtextbulletspage.cpp"
64 #include "richtextmarginspage.cpp"
65 #include "richtextsizepage.cpp"
66 #include "richtextborderspage.cpp"
67 #include "richtextbackgroundpage.cpp"
68 // Digital Mars can't cope with this much code
70 #include "richtextliststylepage.cpp"
72 #include "richtextstylepage.cpp"
75 #if 0 // def __WXMAC__
76 #define wxRICHTEXT_USE_TOOLBOOK 1
78 #define wxRICHTEXT_USE_TOOLBOOK 0
81 bool wxRichTextFormattingDialog::sm_showToolTips
= false;
83 IMPLEMENT_CLASS(wxRichTextFormattingDialog
, wxPropertySheetDialog
)
85 BEGIN_EVENT_TABLE(wxRichTextFormattingDialog
, wxPropertySheetDialog
)
86 EVT_BOOKCTRL_PAGE_CHANGED(wxID_ANY
, wxRichTextFormattingDialog::OnTabChanged
)
87 EVT_BUTTON(wxID_HELP
, wxRichTextFormattingDialog::OnHelp
)
88 EVT_UPDATE_UI(wxID_HELP
, wxRichTextFormattingDialog::OnUpdateHelp
)
91 IMPLEMENT_HELP_PROVISION(wxRichTextFormattingDialog
)
93 wxRichTextFormattingDialogFactory
* wxRichTextFormattingDialog::ms_FormattingDialogFactory
= NULL
;
95 void wxRichTextFormattingDialog::Init()
98 m_styleDefinition
= NULL
;
103 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 int resizeBorder
= wxRESIZE_BORDER
;
116 GetFormattingDialogFactory()->SetSheetStyle(this);
118 wxPropertySheetDialog::Create(parent
, id
, title
, pos
, sz
,
119 style
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
122 GetFormattingDialogFactory()->CreateButtons(this);
123 GetFormattingDialogFactory()->CreatePages(flags
, this);
130 /// Get attributes from the given range
131 bool wxRichTextFormattingDialog::GetStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
)
133 if (ctrl
->GetFocusObject()->GetStyleForRange(range
.ToInternal(), m_attributes
))
134 return UpdateDisplay();
139 /// Apply attributes to the given range, only applying if necessary (wxRICHTEXT_SETSTYLE_OPTIMIZE)
140 bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
, int flags
)
142 return ctrl
->SetStyleEx(range
, m_attributes
, flags
);
145 // Apply attributes to the object being edited, if any
146 bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl
* WXUNUSED(ctrl
), int flags
)
150 wxRichTextParagraphLayoutBox
* parentContainer
= GetObject()->GetParentContainer();
152 parentContainer
->SetStyle(GetObject(), m_attributes
, flags
);
159 /// Set the attributes and optionally update the display
160 bool wxRichTextFormattingDialog::SetStyle(const wxRichTextAttr
& style
, bool update
)
162 m_attributes
= style
;
168 /// Set the style definition and optionally update the display
169 bool wxRichTextFormattingDialog::SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
, wxRichTextStyleSheet
* sheet
, bool update
)
171 m_styleSheet
= sheet
;
173 if (m_styleDefinition
)
174 delete m_styleDefinition
;
175 m_styleDefinition
= styleDef
.Clone();
177 return SetStyle(m_styleDefinition
->GetStyle(), update
);
180 /// Transfers the data and from to the window
181 bool wxRichTextFormattingDialog::TransferDataToWindow()
183 if (m_styleDefinition
)
184 m_attributes
= m_styleDefinition
->GetStyle();
186 if (!wxPropertySheetDialog::TransferDataToWindow())
192 bool wxRichTextFormattingDialog::TransferDataFromWindow()
194 if (!wxPropertySheetDialog::TransferDataFromWindow())
197 if (m_styleDefinition
)
198 m_styleDefinition
->GetStyle() = m_attributes
;
203 /// Update the display
204 bool wxRichTextFormattingDialog::UpdateDisplay()
206 return TransferDataToWindow();
209 /// Apply the styles when a different tab is selected, so the previews are
211 void wxRichTextFormattingDialog::OnTabChanged(wxBookCtrlEvent
& event
)
213 if (GetBookCtrl() != event
.GetEventObject())
219 int oldPageId
= event
.GetOldSelection();
222 wxWindow
* page
= GetBookCtrl()->GetPage(oldPageId
);
224 page
->TransferDataFromWindow();
227 int pageId
= event
.GetSelection();
230 wxWindow
* page
= GetBookCtrl()->GetPage(pageId
);
232 page
->TransferDataToWindow();
236 /// Respond to help command
237 void wxRichTextFormattingDialog::OnHelp(wxCommandEvent
& event
)
239 int selPage
= GetBookCtrl()->GetSelection();
240 if (selPage
!= wxNOT_FOUND
)
243 if (selPage
< (int) m_pageIds
.GetCount())
244 pageId
= m_pageIds
[selPage
];
245 if (!GetFormattingDialogFactory()->ShowHelp(pageId
, this))
250 void wxRichTextFormattingDialog::OnUpdateHelp(wxUpdateUIEvent
& event
)
255 void wxRichTextFormattingDialog::SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
)
257 if (ms_FormattingDialogFactory
)
258 delete ms_FormattingDialogFactory
;
259 ms_FormattingDialogFactory
= factory
;
262 // Find a page by class
263 wxWindow
* wxRichTextFormattingDialog::FindPage(wxClassInfo
* info
) const
266 for (i
= 0; i
< GetBookCtrl()->GetPageCount(); i
++)
268 wxWindow
* w
= GetBookCtrl()->GetPage(i
);
269 if (w
&& w
->GetClassInfo() == info
)
277 * Factory for formatting dialog
280 /// Create all pages, under the dialog's book control, also calling AddPage
281 bool wxRichTextFormattingDialogFactory::CreatePages(long pages
, wxRichTextFormattingDialog
* dialog
)
283 if (dialog
->GetImageList())
284 dialog
->GetBookCtrl()->SetImageList(dialog
->GetImageList());
286 int availablePageCount
= GetPageIdCount();
288 bool selected
= false;
289 for (i
= 0; i
< availablePageCount
; i
++)
291 int pageId
= GetPageId(i
);
292 if (pageId
!= -1 && (pages
& pageId
))
295 wxPanel
* panel
= CreatePage(pageId
, title
, dialog
);
296 wxASSERT( panel
!= NULL
);
299 int imageIndex
= GetPageImage(pageId
);
300 dialog
->GetBookCtrl()->AddPage(panel
, title
, !selected
, imageIndex
);
303 dialog
->AddPageId(pageId
);
311 /// Create a page, given a page identifier
312 wxPanel
* wxRichTextFormattingDialogFactory::CreatePage(int page
, wxString
& title
, wxRichTextFormattingDialog
* dialog
)
314 if (page
== wxRICHTEXT_FORMAT_STYLE_EDITOR
)
316 wxRichTextStylePage
* page
= new wxRichTextStylePage(dialog
->GetBookCtrl(), wxID_ANY
);
320 else if (page
== wxRICHTEXT_FORMAT_FONT
)
322 wxRichTextFontPage
* page
= new wxRichTextFontPage(dialog
->GetBookCtrl(), wxID_ANY
);
326 else if (page
== wxRICHTEXT_FORMAT_INDENTS_SPACING
)
328 wxRichTextIndentsSpacingPage
* page
= new wxRichTextIndentsSpacingPage(dialog
->GetBookCtrl(), wxID_ANY
);
329 title
= _("Indents && Spacing");
332 else if (page
== wxRICHTEXT_FORMAT_TABS
)
334 wxRichTextTabsPage
* page
= new wxRichTextTabsPage(dialog
->GetBookCtrl(), wxID_ANY
);
338 else if (page
== wxRICHTEXT_FORMAT_BULLETS
)
340 wxRichTextBulletsPage
* page
= new wxRichTextBulletsPage(dialog
->GetBookCtrl(), wxID_ANY
);
341 title
= _("Bullets");
345 else if (page
== wxRICHTEXT_FORMAT_LIST_STYLE
)
347 wxRichTextListStylePage
* page
= new wxRichTextListStylePage(dialog
->GetBookCtrl(), wxID_ANY
);
348 title
= _("List Style");
352 else if (page
== wxRICHTEXT_FORMAT_SIZE
)
354 wxRichTextSizePage
* page
= new wxRichTextSizePage(dialog
->GetBookCtrl(), wxID_ANY
);
358 else if (page
== wxRICHTEXT_FORMAT_MARGINS
)
360 wxRichTextMarginsPage
* page
= new wxRichTextMarginsPage(dialog
->GetBookCtrl(), wxID_ANY
);
361 title
= _("Margins");
364 else if (page
== wxRICHTEXT_FORMAT_BORDERS
)
366 wxRichTextBordersPage
* page
= new wxRichTextBordersPage(dialog
->GetBookCtrl(), wxID_ANY
);
367 title
= _("Borders");
370 else if (page
== wxRICHTEXT_FORMAT_BACKGROUND
)
372 wxRichTextBackgroundPage
* page
= new wxRichTextBackgroundPage(dialog
->GetBookCtrl(), wxID_ANY
);
373 title
= _("Background");
380 /// Enumerate all available page identifiers
381 int wxRichTextFormattingDialogFactory::GetPageId(int i
) const
384 wxRICHTEXT_FORMAT_STYLE_EDITOR
,
385 wxRICHTEXT_FORMAT_FONT
,
386 wxRICHTEXT_FORMAT_INDENTS_SPACING
,
387 wxRICHTEXT_FORMAT_BULLETS
,
388 wxRICHTEXT_FORMAT_TABS
,
389 wxRICHTEXT_FORMAT_LIST_STYLE
,
390 wxRICHTEXT_FORMAT_SIZE
,
391 wxRICHTEXT_FORMAT_MARGINS
,
392 wxRICHTEXT_FORMAT_BORDERS
,
393 wxRICHTEXT_FORMAT_BACKGROUND
396 if (i
< 0 || i
>= GetPageIdCount())
402 /// Get the number of available page identifiers
403 int wxRichTextFormattingDialogFactory::GetPageIdCount() const
412 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
413 bool wxRichTextFormattingDialogFactory::SetSheetStyle(wxRichTextFormattingDialog
* dialog
)
415 #if wxRICHTEXT_USE_TOOLBOOK
416 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
418 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
420 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
423 dialog
->SetSheetStyle(sheetStyle
);
424 dialog
->SetSheetInnerBorder(0);
425 dialog
->SetSheetOuterBorder(0);
428 #endif // wxRICHTEXT_USE_TOOLBOOK
433 /// Create the main dialog buttons
434 bool wxRichTextFormattingDialogFactory::CreateButtons(wxRichTextFormattingDialog
* dialog
)
436 int flags
= wxOK
|wxCANCEL
;
438 if (dialog
->GetWindowStyleFlag() & wxRICHTEXT_FORMAT_HELP_BUTTON
)
442 // If using a toolbook, also follow Mac style and don't create buttons
443 #if !wxRICHTEXT_USE_TOOLBOOK
444 dialog
->CreateButtons(flags
);
450 // Invoke help for the dialog
451 bool wxRichTextFormattingDialogFactory::ShowHelp(int WXUNUSED(page
), wxRichTextFormattingDialog
* dialog
)
453 wxRichTextDialogPage
* window
= NULL
;
454 int sel
= dialog
->GetBookCtrl()->GetSelection();
456 window
= wxDynamicCast(dialog
->GetBookCtrl()->GetPage(sel
), wxRichTextDialogPage
);
457 if (window
&& window
->GetHelpId() != -1)
459 if (window
->GetUICustomization())
460 return window
->GetUICustomization()->ShowHelp(dialog
, window
->GetHelpId());
461 else if (dialog
->GetUICustomization())
462 return dialog
->GetUICustomization()->ShowHelp(dialog
, window
->GetHelpId());
466 else if (dialog
->GetHelpId() != -1 && dialog
->GetUICustomization())
467 return dialog
->ShowHelp(dialog
);
473 * Module to initialise and clean up handlers
476 class wxRichTextFormattingDialogModule
: public wxModule
478 DECLARE_DYNAMIC_CLASS(wxRichTextFormattingDialogModule
)
480 wxRichTextFormattingDialogModule() {}
481 bool OnInit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(new wxRichTextFormattingDialogFactory
); return true; }
482 void OnExit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(NULL
); }
485 IMPLEMENT_DYNAMIC_CLASS(wxRichTextFormattingDialogModule
, wxModule
)
488 * Font preview control
491 BEGIN_EVENT_TABLE(wxRichTextFontPreviewCtrl
, wxWindow
)
492 EVT_PAINT(wxRichTextFontPreviewCtrl::OnPaint
)
495 wxRichTextFontPreviewCtrl::wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& sz
, long style
)
497 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
498 style
|= wxBORDER_THEME
;
500 wxWindow::Create(parent
, id
, pos
, sz
, style
);
502 SetBackgroundColour(*wxWHITE
);
506 void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
510 wxSize size
= GetSize();
511 wxFont font
= GetFont();
513 if ((GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
) || (GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
))
515 double size
= static_cast<double>(font
.GetPointSize()) / wxSCRIPT_MUL_FACTOR
;
516 font
.SetPointSize( static_cast<int>(size
) );
522 // Calculate vertical and horizontal centre
523 wxCoord w
= 0, h
= 0;
525 wxString
text(_("ABCDEFGabcdefg12345"));
526 if (GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS
)
529 dc
.GetTextExtent( text
, &w
, &h
);
530 int cx
= wxMax(2, (size
.x
/2) - (w
/2));
531 int cy
= wxMax(2, (size
.y
/2) - (h
/2));
533 if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
)
535 if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
)
538 dc
.SetTextForeground(GetForegroundColour());
539 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
540 dc
.DrawText(text
, cx
, cy
);
542 if (GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH
)
544 dc
.SetPen(wxPen(GetForegroundColour(), 1));
545 dc
.DrawLine(cx
, (int) (cy
+ h
/2 + 0.5), cx
+ w
, (int) (cy
+ h
/2 + 0.5));
548 dc
.DestroyClippingRegion();
552 // Helper for pages to get the top-level dialog
553 wxRichTextFormattingDialog
* wxRichTextFormattingDialog::GetDialog(wxWindow
* win
)
555 wxWindow
* p
= win
->GetParent();
556 while (p
&& !p
->IsKindOf(CLASSINFO(wxRichTextFormattingDialog
)))
558 wxRichTextFormattingDialog
* dialog
= wxDynamicCast(p
, wxRichTextFormattingDialog
);
562 // Helper for pages to get the attributes
563 wxRichTextAttr
* wxRichTextFormattingDialog::GetDialogAttributes(wxWindow
* win
)
565 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
567 return & dialog
->GetAttributes();
573 // Helper for pages to get the attributes to reset
574 wxRichTextAttr
* wxRichTextFormattingDialog::GetDialogResetAttributes(wxWindow
* win
)
576 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
578 return & dialog
->GetResetAttributes();
584 // Helper for pages to get the style
585 wxRichTextStyleDefinition
* wxRichTextFormattingDialog::GetDialogStyleDefinition(wxWindow
* win
)
587 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
589 return dialog
->GetStyleDefinition();
594 void wxRichTextFormattingDialog::SetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
)
600 checkBox
->SetValue(false);
601 valueCtrl
->SetValue(wxT("0"));
602 unitsCtrl
->SetSelection(0);
605 dim
.SetUnits(wxTEXT_ATTR_UNITS_PIXELS
);
610 checkBox
->SetValue(true);
611 if (dim
.GetUnits() == wxTEXT_ATTR_UNITS_TENTHS_MM
)
614 float value
= float(dim
.GetValue()) / 10.0;
615 valueCtrl
->SetValue(wxString::Format(wxT("%.2f"), value
));
620 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
623 unitsCtrl
->SetSelection(unitsIdx
);
627 void wxRichTextFormattingDialog::GetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
)
629 if (!checkBox
->GetValue())
635 if (unitsCtrl
->GetSelection() == 1)
636 dim
.SetUnits(wxTEXT_ATTR_UNITS_TENTHS_MM
);
638 dim
.SetUnits(wxTEXT_ATTR_UNITS_PIXELS
);
641 if (ConvertFromString(valueCtrl
->GetValue(), value
, dim
.GetUnits()))
646 bool wxRichTextFormattingDialog::ConvertFromString(const wxString
& string
, int& ret
, int scale
)
648 const wxChar
* chars
= string
.GetData();
653 for (unsigned int i
= 0; i
< string
.Len() && remain
; i
++)
655 if (!(chars
[i
] >= wxT('0') && chars
[i
] <= wxT('9')) && !(scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
&& chars
[i
] == wxT('.')))
658 if (chars
[i
] == wxT('.'))
667 ret
= ret
* 10 + chars
[i
] - wxT('0');
670 while (remain
-- > 0 && scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
)
677 * A control for displaying a small preview of a colour or bitmap
680 BEGIN_EVENT_TABLE(wxRichTextColourSwatchCtrl
, wxControl
)
681 EVT_MOUSE_EVENTS(wxRichTextColourSwatchCtrl::OnMouseEvent
)
684 IMPLEMENT_CLASS(wxRichTextColourSwatchCtrl
, wxControl
)
686 wxRichTextColourSwatchCtrl::wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
688 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
689 style
|= wxBORDER_THEME
;
691 wxControl::Create(parent
, id
, pos
, size
, style
);
693 SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
696 wxRichTextColourSwatchCtrl::~wxRichTextColourSwatchCtrl()
700 void wxRichTextColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
702 if (event
.LeftDown())
704 wxWindow
* parent
= GetParent();
705 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
706 parent
= parent
->GetParent();
709 data
.SetChooseFull(true);
710 data
.SetColour(m_colour
);
712 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
713 // Crashes on wxMac (no m_peer)
715 dialog
->SetTitle(_("Colour"));
717 if (dialog
->ShowModal() == wxID_OK
)
719 wxColourData retData
= dialog
->GetColourData();
720 m_colour
= retData
.GetColour();
721 SetBackgroundColour(m_colour
);
724 #endif // wxUSE_COLOURDLG
727 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
728 GetEventHandler()->ProcessEvent(event
);
735 * wxRichTextFontListBox class declaration
736 * A listbox to display styles.
739 IMPLEMENT_CLASS(wxRichTextFontListBox
, wxHtmlListBox
)
741 BEGIN_EVENT_TABLE(wxRichTextFontListBox
, wxHtmlListBox
)
744 wxRichTextFontListBox::wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
745 const wxSize
& size
, long style
)
748 Create(parent
, id
, pos
, size
, style
);
751 bool wxRichTextFontListBox::Create(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
752 const wxSize
& size
, long style
)
754 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
755 style
|= wxBORDER_THEME
;
757 return wxHtmlListBox::Create(parent
, id
, pos
, size
, style
);
760 wxRichTextFontListBox::~wxRichTextFontListBox()
764 /// Returns the HTML for this item
765 wxString
wxRichTextFontListBox::OnGetItem(size_t n
) const
767 if (m_faceNames
.GetCount() == 0)
768 return wxEmptyString
;
770 wxString str
= CreateHTML(m_faceNames
[n
]);
774 /// Get font name for index
775 wxString
wxRichTextFontListBox::GetFaceName(size_t i
) const
777 return m_faceNames
[i
];
780 /// Set selection for string, returning the index.
781 int wxRichTextFontListBox::SetFaceNameSelection(const wxString
& name
)
783 int i
= m_faceNames
.Index(name
);
789 /// Updates the font list
790 void wxRichTextFontListBox::UpdateFonts()
792 wxArrayString facenames
= wxRichTextCtrl::GetAvailableFontNames();
793 m_faceNames
= facenames
;
796 SetItemCount(m_faceNames
.GetCount());
801 // Convert a colour to a 6-digit hex string
802 static wxString
ColourToHexString(const wxColour
& col
)
806 hex
+= wxDecToHex(col
.Red());
807 hex
+= wxDecToHex(col
.Green());
808 hex
+= wxDecToHex(col
.Blue());
814 /// Creates a suitable HTML fragment for a definition
815 wxString
wxRichTextFontListBox::CreateHTML(const wxString
& facename
) const
817 wxString str
= wxT("<font");
819 str
<< wxT(" size=\"+2\"");;
821 if (!facename
.IsEmpty() && facename
!= _("(none)"))
822 str
<< wxT(" face=\"") << facename
<< wxT("\"");
824 if (def->GetStyle().GetTextColour().Ok())
825 str << wxT(" color=\"#") << ColourToHexString(def->GetStyle().GetTextColour()) << wxT("\"");
830 bool hasBold
= false;
840 str
<< wxT("</font>");