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()
97 m_styleDefinition
= NULL
;
102 wxRichTextFormattingDialog::~wxRichTextFormattingDialog()
104 delete m_styleDefinition
;
107 bool wxRichTextFormattingDialog::Create(long flags
, wxWindow
* parent
, const wxString
& title
, wxWindowID id
,
108 const wxPoint
& pos
, const wxSize
& sz
, long style
)
110 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
112 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
115 int resizeBorder
= wxRESIZE_BORDER
;
117 GetFormattingDialogFactory()->SetSheetStyle(this);
119 wxPropertySheetDialog::Create(parent
, id
, title
, pos
, sz
,
120 style
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
123 GetFormattingDialogFactory()->CreateButtons(this);
124 GetFormattingDialogFactory()->CreatePages(flags
, this);
131 /// Get attributes from the given range
132 bool wxRichTextFormattingDialog::GetStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
)
134 if (ctrl
->GetFocusObject()->GetStyleForRange(range
.ToInternal(), m_attributes
))
135 return UpdateDisplay();
140 /// Apply attributes to the given range, only applying if necessary (wxRICHTEXT_SETSTYLE_OPTIMIZE)
141 bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
, int flags
)
143 return ctrl
->SetStyleEx(range
, m_attributes
, flags
);
146 // Apply attributes to the object being edited, if any
147 bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl
* ctrl
, int flags
)
151 ctrl
->SetStyle(GetObject(), m_attributes
, flags
);
158 /// Set the attributes and optionally update the display
159 bool wxRichTextFormattingDialog::SetStyle(const wxRichTextAttr
& style
, bool update
)
161 m_attributes
= style
;
167 /// Set the style definition and optionally update the display
168 bool wxRichTextFormattingDialog::SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
, wxRichTextStyleSheet
* sheet
, bool update
)
170 m_styleSheet
= sheet
;
172 if (m_styleDefinition
)
173 delete m_styleDefinition
;
174 m_styleDefinition
= styleDef
.Clone();
176 return SetStyle(m_styleDefinition
->GetStyle(), update
);
179 /// Transfers the data and from to the window
180 bool wxRichTextFormattingDialog::TransferDataToWindow()
182 if (m_styleDefinition
)
183 m_attributes
= m_styleDefinition
->GetStyle();
185 if (!wxPropertySheetDialog::TransferDataToWindow())
191 bool wxRichTextFormattingDialog::TransferDataFromWindow()
193 if (!wxPropertySheetDialog::TransferDataFromWindow())
196 if (m_styleDefinition
)
197 m_styleDefinition
->GetStyle() = m_attributes
;
202 /// Update the display
203 bool wxRichTextFormattingDialog::UpdateDisplay()
205 return TransferDataToWindow();
208 /// Apply the styles when a different tab is selected, so the previews are
210 void wxRichTextFormattingDialog::OnTabChanged(wxBookCtrlEvent
& event
)
212 if (GetBookCtrl() != event
.GetEventObject())
218 int oldPageId
= event
.GetOldSelection();
221 wxWindow
* page
= GetBookCtrl()->GetPage(oldPageId
);
223 page
->TransferDataFromWindow();
226 int pageId
= event
.GetSelection();
229 wxWindow
* page
= GetBookCtrl()->GetPage(pageId
);
231 page
->TransferDataToWindow();
235 /// Respond to help command
236 void wxRichTextFormattingDialog::OnHelp(wxCommandEvent
& event
)
238 int selPage
= GetBookCtrl()->GetSelection();
239 if (selPage
!= wxNOT_FOUND
)
242 if (selPage
< (int) m_pageIds
.GetCount())
243 pageId
= m_pageIds
[selPage
];
244 if (!GetFormattingDialogFactory()->ShowHelp(pageId
, this))
249 void wxRichTextFormattingDialog::OnUpdateHelp(wxUpdateUIEvent
& event
)
254 void wxRichTextFormattingDialog::SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
)
256 if (ms_FormattingDialogFactory
)
257 delete ms_FormattingDialogFactory
;
258 ms_FormattingDialogFactory
= factory
;
261 // Find a page by class
262 wxWindow
* wxRichTextFormattingDialog::FindPage(wxClassInfo
* info
) const
265 for (i
= 0; i
< GetBookCtrl()->GetPageCount(); i
++)
267 wxWindow
* w
= GetBookCtrl()->GetPage(i
);
268 if (w
&& w
->GetClassInfo() == info
)
276 * Factory for formatting dialog
279 /// Create all pages, under the dialog's book control, also calling AddPage
280 bool wxRichTextFormattingDialogFactory::CreatePages(long pages
, wxRichTextFormattingDialog
* dialog
)
282 if (dialog
->GetImageList())
283 dialog
->GetBookCtrl()->SetImageList(dialog
->GetImageList());
285 int availablePageCount
= GetPageIdCount();
287 bool selected
= false;
288 for (i
= 0; i
< availablePageCount
; i
++)
290 int pageId
= GetPageId(i
);
291 if (pageId
!= -1 && (pages
& pageId
))
294 wxPanel
* panel
= CreatePage(pageId
, title
, dialog
);
295 wxASSERT( panel
!= NULL
);
298 int imageIndex
= GetPageImage(pageId
);
299 dialog
->GetBookCtrl()->AddPage(panel
, title
, !selected
, imageIndex
);
302 dialog
->AddPageId(pageId
);
310 /// Create a page, given a page identifier
311 wxPanel
* wxRichTextFormattingDialogFactory::CreatePage(int page
, wxString
& title
, wxRichTextFormattingDialog
* dialog
)
313 if (page
== wxRICHTEXT_FORMAT_STYLE_EDITOR
)
315 wxRichTextStylePage
* page
= new wxRichTextStylePage(dialog
->GetBookCtrl(), wxID_ANY
);
319 else if (page
== wxRICHTEXT_FORMAT_FONT
)
321 wxRichTextFontPage
* page
= new wxRichTextFontPage(dialog
->GetBookCtrl(), wxID_ANY
);
325 else if (page
== wxRICHTEXT_FORMAT_INDENTS_SPACING
)
327 wxRichTextIndentsSpacingPage
* page
= new wxRichTextIndentsSpacingPage(dialog
->GetBookCtrl(), wxID_ANY
);
328 title
= _("Indents && Spacing");
331 else if (page
== wxRICHTEXT_FORMAT_TABS
)
333 wxRichTextTabsPage
* page
= new wxRichTextTabsPage(dialog
->GetBookCtrl(), wxID_ANY
);
337 else if (page
== wxRICHTEXT_FORMAT_BULLETS
)
339 wxRichTextBulletsPage
* page
= new wxRichTextBulletsPage(dialog
->GetBookCtrl(), wxID_ANY
);
340 title
= _("Bullets");
344 else if (page
== wxRICHTEXT_FORMAT_LIST_STYLE
)
346 wxRichTextListStylePage
* page
= new wxRichTextListStylePage(dialog
->GetBookCtrl(), wxID_ANY
);
347 title
= _("List Style");
351 else if (page
== wxRICHTEXT_FORMAT_SIZE
)
353 wxRichTextSizePage
* page
= new wxRichTextSizePage(dialog
->GetBookCtrl(), wxID_ANY
);
357 else if (page
== wxRICHTEXT_FORMAT_MARGINS
)
359 wxRichTextMarginsPage
* page
= new wxRichTextMarginsPage(dialog
->GetBookCtrl(), wxID_ANY
);
360 title
= _("Margins");
363 else if (page
== wxRICHTEXT_FORMAT_BORDERS
)
365 wxRichTextBordersPage
* page
= new wxRichTextBordersPage(dialog
->GetBookCtrl(), wxID_ANY
);
366 title
= _("Borders");
369 else if (page
== wxRICHTEXT_FORMAT_BACKGROUND
)
371 wxRichTextBackgroundPage
* page
= new wxRichTextBackgroundPage(dialog
->GetBookCtrl(), wxID_ANY
);
372 title
= _("Background");
379 /// Enumerate all available page identifiers
380 int wxRichTextFormattingDialogFactory::GetPageId(int i
) const
383 wxRICHTEXT_FORMAT_STYLE_EDITOR
,
384 wxRICHTEXT_FORMAT_FONT
,
385 wxRICHTEXT_FORMAT_INDENTS_SPACING
,
386 wxRICHTEXT_FORMAT_BULLETS
,
387 wxRICHTEXT_FORMAT_TABS
,
388 wxRICHTEXT_FORMAT_LIST_STYLE
,
389 wxRICHTEXT_FORMAT_SIZE
,
390 wxRICHTEXT_FORMAT_MARGINS
,
391 wxRICHTEXT_FORMAT_BORDERS
,
392 wxRICHTEXT_FORMAT_BACKGROUND
395 if (i
< 0 || i
>= GetPageIdCount())
401 /// Get the number of available page identifiers
402 int wxRichTextFormattingDialogFactory::GetPageIdCount() const
411 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
412 bool wxRichTextFormattingDialogFactory::SetSheetStyle(wxRichTextFormattingDialog
* dialog
)
414 #if wxRICHTEXT_USE_TOOLBOOK
415 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
417 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
419 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
422 dialog
->SetSheetStyle(sheetStyle
);
423 dialog
->SetSheetInnerBorder(0);
424 dialog
->SetSheetOuterBorder(0);
427 #endif // wxRICHTEXT_USE_TOOLBOOK
432 /// Create the main dialog buttons
433 bool wxRichTextFormattingDialogFactory::CreateButtons(wxRichTextFormattingDialog
* dialog
)
435 int flags
= wxOK
|wxCANCEL
;
437 if (dialog
->GetWindowStyleFlag() & wxRICHTEXT_FORMAT_HELP_BUTTON
)
441 // If using a toolbook, also follow Mac style and don't create buttons
442 #if !wxRICHTEXT_USE_TOOLBOOK
443 dialog
->CreateButtons(flags
);
449 // Invoke help for the dialog
450 bool wxRichTextFormattingDialogFactory::ShowHelp(int WXUNUSED(page
), wxRichTextFormattingDialog
* dialog
)
452 wxRichTextDialogPage
* window
= NULL
;
453 int sel
= dialog
->GetBookCtrl()->GetSelection();
455 window
= wxDynamicCast(dialog
->GetBookCtrl()->GetPage(sel
), wxRichTextDialogPage
);
456 if (window
&& window
->GetHelpId() != -1)
458 if (window
->GetUICustomization())
459 return window
->GetUICustomization()->ShowHelp(dialog
, window
->GetHelpId());
460 else if (dialog
->GetUICustomization())
461 return dialog
->GetUICustomization()->ShowHelp(dialog
, window
->GetHelpId());
465 else if (dialog
->GetHelpId() != -1 && dialog
->GetUICustomization())
466 return dialog
->ShowHelp(dialog
);
472 * Module to initialise and clean up handlers
475 class wxRichTextFormattingDialogModule
: public wxModule
477 DECLARE_DYNAMIC_CLASS(wxRichTextFormattingDialogModule
)
479 wxRichTextFormattingDialogModule() {}
480 bool OnInit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(new wxRichTextFormattingDialogFactory
); return true; }
481 void OnExit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(NULL
); }
484 IMPLEMENT_DYNAMIC_CLASS(wxRichTextFormattingDialogModule
, wxModule
)
487 * Font preview control
490 BEGIN_EVENT_TABLE(wxRichTextFontPreviewCtrl
, wxWindow
)
491 EVT_PAINT(wxRichTextFontPreviewCtrl::OnPaint
)
494 wxRichTextFontPreviewCtrl::wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& sz
, long style
)
496 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
497 style
|= wxBORDER_THEME
;
499 wxWindow::Create(parent
, id
, pos
, sz
, style
);
501 SetBackgroundColour(*wxWHITE
);
505 void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
509 wxSize size
= GetSize();
510 wxFont font
= GetFont();
512 if ((GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
) || (GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
))
514 double size
= static_cast<double>(font
.GetPointSize()) / wxSCRIPT_MUL_FACTOR
;
515 font
.SetPointSize( static_cast<int>(size
) );
521 // Calculate vertical and horizontal centre
522 wxCoord w
= 0, h
= 0;
524 wxString
text(_("ABCDEFGabcdefg12345"));
525 if (GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS
)
528 dc
.GetTextExtent( text
, &w
, &h
);
529 int cx
= wxMax(2, (size
.x
/2) - (w
/2));
530 int cy
= wxMax(2, (size
.y
/2) - (h
/2));
532 if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
)
534 if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
)
537 dc
.SetTextForeground(GetForegroundColour());
538 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
539 dc
.DrawText(text
, cx
, cy
);
541 if (GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH
)
543 dc
.SetPen(wxPen(GetForegroundColour(), 1));
544 dc
.DrawLine(cx
, (int) (cy
+ h
/2 + 0.5), cx
+ w
, (int) (cy
+ h
/2 + 0.5));
547 dc
.DestroyClippingRegion();
551 // Helper for pages to get the top-level dialog
552 wxRichTextFormattingDialog
* wxRichTextFormattingDialog::GetDialog(wxWindow
* win
)
554 wxWindow
* p
= win
->GetParent();
555 while (p
&& !p
->IsKindOf(CLASSINFO(wxRichTextFormattingDialog
)))
557 wxRichTextFormattingDialog
* dialog
= wxDynamicCast(p
, wxRichTextFormattingDialog
);
561 // Helper for pages to get the attributes
562 wxRichTextAttr
* wxRichTextFormattingDialog::GetDialogAttributes(wxWindow
* win
)
564 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
566 return & dialog
->GetAttributes();
572 // Helper for pages to get the attributes to reset
573 wxRichTextAttr
* wxRichTextFormattingDialog::GetDialogResetAttributes(wxWindow
* win
)
575 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
577 return & dialog
->GetResetAttributes();
583 // Helper for pages to get the style
584 wxRichTextStyleDefinition
* wxRichTextFormattingDialog::GetDialogStyleDefinition(wxWindow
* win
)
586 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
588 return dialog
->GetStyleDefinition();
593 void wxRichTextFormattingDialog::SetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
)
599 checkBox
->SetValue(false);
600 valueCtrl
->SetValue(wxT("0"));
601 unitsCtrl
->SetSelection(0);
604 dim
.SetUnits(wxTEXT_ATTR_UNITS_PIXELS
);
609 checkBox
->SetValue(true);
610 if (dim
.GetUnits() == wxTEXT_ATTR_UNITS_TENTHS_MM
)
613 float value
= float(dim
.GetValue()) / 100.0;
614 valueCtrl
->SetValue(wxString::Format(wxT("%.2f"), value
));
616 else if (dim
.GetUnits() == wxTEXT_ATTR_UNITS_PERCENTAGE
)
619 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
624 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
627 unitsCtrl
->SetSelection(unitsIdx
);
631 void wxRichTextFormattingDialog::GetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
)
633 if (!checkBox
->GetValue())
639 if (unitsCtrl
->GetSelection() == 1)
640 dim
.SetUnits(wxTEXT_ATTR_UNITS_TENTHS_MM
);
641 else if (unitsCtrl
->GetSelection() == 2)
642 dim
.SetUnits(wxTEXT_ATTR_UNITS_PERCENTAGE
);
644 dim
.SetUnits(wxTEXT_ATTR_UNITS_PIXELS
);
647 if (ConvertFromString(valueCtrl
->GetValue(), value
, dim
.GetUnits()))
652 bool wxRichTextFormattingDialog::ConvertFromString(const wxString
& string
, int& ret
, int scale
)
654 const wxChar
* chars
= string
.GetData();
659 for (unsigned int i
= 0; i
< string
.Len() && remain
; i
++)
661 if (!(chars
[i
] >= wxT('0') && chars
[i
] <= wxT('9')) && !(scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
&& chars
[i
] == wxT('.')))
664 if (chars
[i
] == wxT('.'))
673 ret
= ret
* 10 + chars
[i
] - wxT('0');
676 while (remain
-- > 0 && scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
)
683 * A control for displaying a small preview of a colour or bitmap
686 BEGIN_EVENT_TABLE(wxRichTextColourSwatchCtrl
, wxControl
)
687 EVT_MOUSE_EVENTS(wxRichTextColourSwatchCtrl::OnMouseEvent
)
690 IMPLEMENT_CLASS(wxRichTextColourSwatchCtrl
, wxControl
)
692 wxRichTextColourSwatchCtrl::wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
694 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
695 style
|= wxBORDER_THEME
;
697 wxControl::Create(parent
, id
, pos
, size
, style
);
699 SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
702 wxRichTextColourSwatchCtrl::~wxRichTextColourSwatchCtrl()
706 void wxRichTextColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
708 if (event
.LeftDown())
710 wxWindow
* parent
= GetParent();
711 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
712 parent
= parent
->GetParent();
715 data
.SetChooseFull(true);
716 data
.SetColour(m_colour
);
718 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
719 // Crashes on wxMac (no m_peer)
721 dialog
->SetTitle(_("Colour"));
723 if (dialog
->ShowModal() == wxID_OK
)
725 wxColourData retData
= dialog
->GetColourData();
726 m_colour
= retData
.GetColour();
727 SetBackgroundColour(m_colour
);
730 #endif // wxUSE_COLOURDLG
733 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
734 GetEventHandler()->ProcessEvent(event
);
741 * wxRichTextFontListBox class declaration
742 * A listbox to display styles.
745 IMPLEMENT_CLASS(wxRichTextFontListBox
, wxHtmlListBox
)
747 BEGIN_EVENT_TABLE(wxRichTextFontListBox
, wxHtmlListBox
)
750 wxRichTextFontListBox::wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
751 const wxSize
& size
, long style
)
754 Create(parent
, id
, pos
, size
, style
);
757 bool wxRichTextFontListBox::Create(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
758 const wxSize
& size
, long style
)
760 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
761 style
|= wxBORDER_THEME
;
763 return wxHtmlListBox::Create(parent
, id
, pos
, size
, style
);
766 wxRichTextFontListBox::~wxRichTextFontListBox()
770 /// Returns the HTML for this item
771 wxString
wxRichTextFontListBox::OnGetItem(size_t n
) const
773 if (m_faceNames
.GetCount() == 0)
774 return wxEmptyString
;
776 wxString str
= CreateHTML(m_faceNames
[n
]);
780 /// Get font name for index
781 wxString
wxRichTextFontListBox::GetFaceName(size_t i
) const
783 return m_faceNames
[i
];
786 /// Set selection for string, returning the index.
787 int wxRichTextFontListBox::SetFaceNameSelection(const wxString
& name
)
789 int i
= m_faceNames
.Index(name
);
795 /// Updates the font list
796 void wxRichTextFontListBox::UpdateFonts()
798 wxArrayString facenames
= wxRichTextCtrl::GetAvailableFontNames();
799 m_faceNames
= facenames
;
802 SetItemCount(m_faceNames
.GetCount());
807 // Convert a colour to a 6-digit hex string
808 static wxString
ColourToHexString(const wxColour
& col
)
812 hex
+= wxDecToHex(col
.Red());
813 hex
+= wxDecToHex(col
.Green());
814 hex
+= wxDecToHex(col
.Blue());
820 /// Creates a suitable HTML fragment for a definition
821 wxString
wxRichTextFontListBox::CreateHTML(const wxString
& facename
) const
823 wxString str
= wxT("<font");
825 str
<< wxT(" size=\"+2\"");;
827 if (!facename
.IsEmpty() && facename
!= _("(none)"))
828 str
<< wxT(" face=\"") << facename
<< wxT("\"");
830 if (def->GetStyle().GetTextColour().IsOk())
831 str << wxT(" color=\"#") << ColourToHexString(def->GetStyle().GetTextColour()) << wxT("\"");
836 bool hasBold
= false;
846 str
<< wxT("</font>");