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(wxRichTextDialogPage
, wxPanel
)
85 IMPLEMENT_CLASS(wxRichTextFormattingDialog
, wxPropertySheetDialog
)
87 BEGIN_EVENT_TABLE(wxRichTextFormattingDialog
, wxPropertySheetDialog
)
88 EVT_BOOKCTRL_PAGE_CHANGED(wxID_ANY
, wxRichTextFormattingDialog::OnTabChanged
)
89 EVT_BUTTON(wxID_HELP
, wxRichTextFormattingDialog::OnHelp
)
90 EVT_UPDATE_UI(wxID_HELP
, wxRichTextFormattingDialog::OnUpdateHelp
)
93 IMPLEMENT_HELP_PROVISION(wxRichTextFormattingDialog
)
95 wxRichTextFormattingDialogFactory
* wxRichTextFormattingDialog::ms_FormattingDialogFactory
= NULL
;
97 void wxRichTextFormattingDialog::Init()
99 m_styleDefinition
= NULL
;
105 wxRichTextFormattingDialog::~wxRichTextFormattingDialog()
107 delete m_styleDefinition
;
110 bool wxRichTextFormattingDialog::Create(long flags
, wxWindow
* parent
, const wxString
& title
, wxWindowID id
,
111 const wxPoint
& pos
, const wxSize
& sz
, long style
)
113 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP
|wxWS_EX_VALIDATE_RECURSIVELY
);
115 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
118 int resizeBorder
= wxRESIZE_BORDER
;
120 GetFormattingDialogFactory()->SetSheetStyle(this);
122 wxPropertySheetDialog::Create(parent
, id
, title
, pos
, sz
,
123 style
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
126 GetFormattingDialogFactory()->CreateButtons(this);
127 GetFormattingDialogFactory()->CreatePages(flags
, this);
134 /// Get attributes from the given range
135 bool wxRichTextFormattingDialog::GetStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
)
137 if (ctrl
->GetFocusObject()->GetStyleForRange(range
.ToInternal(), m_attributes
))
138 return UpdateDisplay();
143 /// Apply attributes to the given range, only applying if necessary (wxRICHTEXT_SETSTYLE_OPTIMIZE)
144 bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
, int flags
)
146 return ctrl
->SetStyleEx(range
, m_attributes
, flags
);
149 // Apply attributes to the object being edited, if any
150 bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl
* ctrl
, int flags
)
154 ctrl
->SetStyle(GetObject(), m_attributes
, flags
);
161 /// Set the attributes and optionally update the display
162 bool wxRichTextFormattingDialog::SetStyle(const wxRichTextAttr
& style
, bool update
)
164 m_attributes
= style
;
170 /// Set the style definition and optionally update the display
171 bool wxRichTextFormattingDialog::SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
, wxRichTextStyleSheet
* sheet
, bool update
)
173 m_styleSheet
= sheet
;
175 if (m_styleDefinition
)
176 delete m_styleDefinition
;
177 m_styleDefinition
= styleDef
.Clone();
179 return SetStyle(m_styleDefinition
->GetStyle(), update
);
182 /// Transfers the data and from to the window
183 bool wxRichTextFormattingDialog::TransferDataToWindow()
185 if (m_styleDefinition
)
186 m_attributes
= m_styleDefinition
->GetStyle();
188 if (!wxPropertySheetDialog::TransferDataToWindow())
194 bool wxRichTextFormattingDialog::TransferDataFromWindow()
196 if (!wxPropertySheetDialog::TransferDataFromWindow())
199 if (m_styleDefinition
)
200 m_styleDefinition
->GetStyle() = m_attributes
;
205 /// Update the display
206 bool wxRichTextFormattingDialog::UpdateDisplay()
208 return TransferDataToWindow();
211 /// Apply the styles when a different tab is selected, so the previews are
213 void wxRichTextFormattingDialog::OnTabChanged(wxBookCtrlEvent
& event
)
215 if (GetBookCtrl() != event
.GetEventObject())
221 int oldPageId
= event
.GetOldSelection();
224 wxWindow
* page
= GetBookCtrl()->GetPage(oldPageId
);
226 page
->TransferDataFromWindow();
229 int pageId
= event
.GetSelection();
232 wxWindow
* page
= GetBookCtrl()->GetPage(pageId
);
234 page
->TransferDataToWindow();
238 /// Respond to help command
239 void wxRichTextFormattingDialog::OnHelp(wxCommandEvent
& event
)
241 int selPage
= GetBookCtrl()->GetSelection();
242 if (selPage
!= wxNOT_FOUND
)
245 if (selPage
< (int) m_pageIds
.GetCount())
246 pageId
= m_pageIds
[selPage
];
247 if (!GetFormattingDialogFactory()->ShowHelp(pageId
, this))
252 void wxRichTextFormattingDialog::OnUpdateHelp(wxUpdateUIEvent
& event
)
257 void wxRichTextFormattingDialog::SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
)
259 if (ms_FormattingDialogFactory
)
260 delete ms_FormattingDialogFactory
;
261 ms_FormattingDialogFactory
= factory
;
264 // Find a page by class
265 wxWindow
* wxRichTextFormattingDialog::FindPage(wxClassInfo
* info
) const
268 for (i
= 0; i
< GetBookCtrl()->GetPageCount(); i
++)
270 wxWindow
* w
= GetBookCtrl()->GetPage(i
);
271 if (w
&& w
->GetClassInfo() == info
)
279 * Factory for formatting dialog
282 /// Create all pages, under the dialog's book control, also calling AddPage
283 bool wxRichTextFormattingDialogFactory::CreatePages(long pages
, wxRichTextFormattingDialog
* dialog
)
285 if (dialog
->GetImageList())
286 dialog
->GetBookCtrl()->SetImageList(dialog
->GetImageList());
288 int availablePageCount
= GetPageIdCount();
290 bool selected
= false;
291 for (i
= 0; i
< availablePageCount
; i
++)
293 int pageId
= GetPageId(i
);
294 if (pageId
!= -1 && (pages
& pageId
))
297 wxPanel
* panel
= CreatePage(pageId
, title
, dialog
);
298 wxASSERT( panel
!= NULL
);
301 int imageIndex
= GetPageImage(pageId
);
302 dialog
->GetBookCtrl()->AddPage(panel
, title
, !selected
, imageIndex
);
305 dialog
->AddPageId(pageId
);
313 /// Create a page, given a page identifier
314 wxPanel
* wxRichTextFormattingDialogFactory::CreatePage(int page
, wxString
& title
, wxRichTextFormattingDialog
* dialog
)
316 if (page
== wxRICHTEXT_FORMAT_STYLE_EDITOR
)
318 wxRichTextStylePage
* page
= new wxRichTextStylePage(dialog
->GetBookCtrl(), wxID_ANY
);
322 else if (page
== wxRICHTEXT_FORMAT_FONT
)
324 wxRichTextFontPage
* page
= new wxRichTextFontPage(dialog
->GetBookCtrl(), wxID_ANY
);
328 else if (page
== wxRICHTEXT_FORMAT_INDENTS_SPACING
)
330 wxRichTextIndentsSpacingPage
* page
= new wxRichTextIndentsSpacingPage(dialog
->GetBookCtrl(), wxID_ANY
);
331 title
= _("Indents && Spacing");
334 else if (page
== wxRICHTEXT_FORMAT_TABS
)
336 wxRichTextTabsPage
* page
= new wxRichTextTabsPage(dialog
->GetBookCtrl(), wxID_ANY
);
340 else if (page
== wxRICHTEXT_FORMAT_BULLETS
)
342 wxRichTextBulletsPage
* page
= new wxRichTextBulletsPage(dialog
->GetBookCtrl(), wxID_ANY
);
343 title
= _("Bullets");
347 else if (page
== wxRICHTEXT_FORMAT_LIST_STYLE
)
349 wxRichTextListStylePage
* page
= new wxRichTextListStylePage(dialog
->GetBookCtrl(), wxID_ANY
);
350 title
= _("List Style");
354 else if (page
== wxRICHTEXT_FORMAT_SIZE
)
356 wxRichTextSizePage
* page
= new wxRichTextSizePage(dialog
->GetBookCtrl(), wxID_ANY
);
360 else if (page
== wxRICHTEXT_FORMAT_MARGINS
)
362 wxRichTextMarginsPage
* page
= new wxRichTextMarginsPage(dialog
->GetBookCtrl(), wxID_ANY
);
363 title
= _("Margins");
366 else if (page
== wxRICHTEXT_FORMAT_BORDERS
)
368 wxRichTextBordersPage
* page
= new wxRichTextBordersPage(dialog
->GetBookCtrl(), wxID_ANY
);
369 title
= _("Borders");
372 else if (page
== wxRICHTEXT_FORMAT_BACKGROUND
)
374 wxRichTextBackgroundPage
* page
= new wxRichTextBackgroundPage(dialog
->GetBookCtrl(), wxID_ANY
);
375 title
= _("Background");
382 /// Enumerate all available page identifiers
383 int wxRichTextFormattingDialogFactory::GetPageId(int i
) const
386 wxRICHTEXT_FORMAT_STYLE_EDITOR
,
387 wxRICHTEXT_FORMAT_FONT
,
388 wxRICHTEXT_FORMAT_INDENTS_SPACING
,
389 wxRICHTEXT_FORMAT_BULLETS
,
390 wxRICHTEXT_FORMAT_TABS
,
391 wxRICHTEXT_FORMAT_LIST_STYLE
,
392 wxRICHTEXT_FORMAT_SIZE
,
393 wxRICHTEXT_FORMAT_MARGINS
,
394 wxRICHTEXT_FORMAT_BORDERS
,
395 wxRICHTEXT_FORMAT_BACKGROUND
398 if (i
< 0 || i
>= GetPageIdCount())
404 /// Get the number of available page identifiers
405 int wxRichTextFormattingDialogFactory::GetPageIdCount() const
414 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
415 bool wxRichTextFormattingDialogFactory::SetSheetStyle(wxRichTextFormattingDialog
* dialog
)
417 #if wxRICHTEXT_USE_TOOLBOOK
418 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
420 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
422 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
425 dialog
->SetSheetStyle(sheetStyle
);
426 dialog
->SetSheetInnerBorder(0);
427 dialog
->SetSheetOuterBorder(0);
430 #endif // wxRICHTEXT_USE_TOOLBOOK
435 /// Create the main dialog buttons
436 bool wxRichTextFormattingDialogFactory::CreateButtons(wxRichTextFormattingDialog
* dialog
)
438 int flags
= wxOK
|wxCANCEL
;
440 if (dialog
->GetWindowStyleFlag() & wxRICHTEXT_FORMAT_HELP_BUTTON
)
444 // If using a toolbook, also follow Mac style and don't create buttons
445 #if !wxRICHTEXT_USE_TOOLBOOK
446 dialog
->CreateButtons(flags
);
452 // Invoke help for the dialog
453 bool wxRichTextFormattingDialogFactory::ShowHelp(int WXUNUSED(page
), wxRichTextFormattingDialog
* dialog
)
455 wxRichTextDialogPage
* window
= NULL
;
456 int sel
= dialog
->GetBookCtrl()->GetSelection();
458 window
= wxDynamicCast(dialog
->GetBookCtrl()->GetPage(sel
), wxRichTextDialogPage
);
459 if (window
&& window
->GetHelpId() != -1)
461 if (window
->GetUICustomization())
462 return window
->GetUICustomization()->ShowHelp(dialog
, window
->GetHelpId());
463 else if (dialog
->GetUICustomization())
464 return dialog
->GetUICustomization()->ShowHelp(dialog
, window
->GetHelpId());
468 else if (dialog
->GetHelpId() != -1 && dialog
->GetUICustomization())
469 return dialog
->ShowHelp(dialog
);
475 * Module to initialise and clean up handlers
478 class wxRichTextFormattingDialogModule
: public wxModule
480 DECLARE_DYNAMIC_CLASS(wxRichTextFormattingDialogModule
)
482 wxRichTextFormattingDialogModule() {}
483 bool OnInit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(new wxRichTextFormattingDialogFactory
); return true; }
484 void OnExit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(NULL
); }
487 IMPLEMENT_DYNAMIC_CLASS(wxRichTextFormattingDialogModule
, wxModule
)
490 * Font preview control
493 BEGIN_EVENT_TABLE(wxRichTextFontPreviewCtrl
, wxWindow
)
494 EVT_PAINT(wxRichTextFontPreviewCtrl::OnPaint
)
497 wxRichTextFontPreviewCtrl::wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& sz
, long style
)
499 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
500 style
|= wxBORDER_THEME
;
502 wxWindow::Create(parent
, id
, pos
, sz
, style
);
504 SetBackgroundColour(*wxWHITE
);
508 void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
512 wxSize size
= GetSize();
513 wxFont font
= GetFont();
515 if ((GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
) || (GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
))
517 double size
= static_cast<double>(font
.GetPointSize()) / wxSCRIPT_MUL_FACTOR
;
518 font
.SetPointSize( static_cast<int>(size
) );
524 // Calculate vertical and horizontal centre
525 wxCoord w
= 0, h
= 0;
527 wxString
text(_("ABCDEFGabcdefg12345"));
528 if (GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS
)
531 dc
.GetTextExtent( text
, &w
, &h
);
532 int cx
= wxMax(2, (size
.x
/2) - (w
/2));
533 int cy
= wxMax(2, (size
.y
/2) - (h
/2));
535 if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
)
537 if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
)
540 dc
.SetTextForeground(GetForegroundColour());
541 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
542 dc
.DrawText(text
, cx
, cy
);
544 if (GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH
)
546 dc
.SetPen(wxPen(GetForegroundColour(), 1));
547 dc
.DrawLine(cx
, (int) (cy
+ h
/2 + 0.5), cx
+ w
, (int) (cy
+ h
/2 + 0.5));
550 dc
.DestroyClippingRegion();
554 // Helper for pages to get the top-level dialog
555 wxRichTextFormattingDialog
* wxRichTextFormattingDialog::GetDialog(wxWindow
* win
)
557 wxWindow
* p
= win
->GetParent();
558 while (p
&& !wxDynamicCast(p
, wxRichTextFormattingDialog
))
560 wxRichTextFormattingDialog
* dialog
= wxDynamicCast(p
, wxRichTextFormattingDialog
);
564 // Helper for pages to get the attributes
565 wxRichTextAttr
* wxRichTextFormattingDialog::GetDialogAttributes(wxWindow
* win
)
567 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
569 return & dialog
->GetAttributes();
575 // Helper for pages to get the attributes to reset
576 wxRichTextAttr
* wxRichTextFormattingDialog::GetDialogResetAttributes(wxWindow
* win
)
578 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
580 return & dialog
->GetResetAttributes();
586 // Helper for pages to get the style
587 wxRichTextStyleDefinition
* wxRichTextFormattingDialog::GetDialogStyleDefinition(wxWindow
* win
)
589 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
591 return dialog
->GetStyleDefinition();
596 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
);
612 checkBox
->SetValue(true);
613 if (dim
.GetUnits() == wxTEXT_ATTR_UNITS_TENTHS_MM
)
616 float value
= float(dim
.GetValue()) / 100.0;
617 valueCtrl
->SetValue(wxString::Format(wxT("%.2f"), value
));
619 else if (dim
.GetUnits() == wxTEXT_ATTR_UNITS_PERCENTAGE
)
622 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
627 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
630 unitsCtrl
->SetSelection(unitsIdx
);
634 void wxRichTextFormattingDialog::GetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
)
636 if (!checkBox
->GetValue())
642 if (unitsCtrl
->GetSelection() == 1)
643 dim
.SetUnits(wxTEXT_ATTR_UNITS_TENTHS_MM
);
644 else if (unitsCtrl
->GetSelection() == 2)
645 dim
.SetUnits(wxTEXT_ATTR_UNITS_PERCENTAGE
);
647 dim
.SetUnits(wxTEXT_ATTR_UNITS_PIXELS
);
650 if (ConvertFromString(valueCtrl
->GetValue(), value
, dim
.GetUnits()))
655 bool wxRichTextFormattingDialog::ConvertFromString(const wxString
& string
, int& ret
, int scale
)
657 const wxChar
* chars
= string
.GetData();
662 for (unsigned int i
= 0; i
< string
.Len() && remain
; i
++)
664 if (!(chars
[i
] >= wxT('0') && chars
[i
] <= wxT('9')) && !(scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
&& chars
[i
] == wxT('.')))
667 if (chars
[i
] == wxT('.'))
676 ret
= ret
* 10 + chars
[i
] - wxT('0');
679 while (remain
-- > 0 && scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
)
686 * A control for displaying a small preview of a colour or bitmap
689 BEGIN_EVENT_TABLE(wxRichTextColourSwatchCtrl
, wxControl
)
690 EVT_MOUSE_EVENTS(wxRichTextColourSwatchCtrl::OnMouseEvent
)
693 IMPLEMENT_CLASS(wxRichTextColourSwatchCtrl
, wxControl
)
695 wxRichTextColourSwatchCtrl::wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
697 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
698 style
|= wxBORDER_THEME
;
700 wxControl::Create(parent
, id
, pos
, size
, style
);
702 SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
705 wxRichTextColourSwatchCtrl::~wxRichTextColourSwatchCtrl()
709 void wxRichTextColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
711 if (event
.LeftDown())
713 wxWindow
* parent
= GetParent();
714 while (parent
!= NULL
&& !wxDynamicCast(parent
, wxDialog
) && !wxDynamicCast(parent
, wxFrame
))
715 parent
= parent
->GetParent();
718 data
.SetChooseFull(true);
719 data
.SetColour(m_colour
);
721 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
722 // Crashes on wxMac (no m_peer)
724 dialog
->SetTitle(_("Colour"));
726 if (dialog
->ShowModal() == wxID_OK
)
728 wxColourData retData
= dialog
->GetColourData();
729 m_colour
= retData
.GetColour();
730 SetBackgroundColour(m_colour
);
733 #endif // wxUSE_COLOURDLG
736 wxCommandEvent
event(wxEVT_BUTTON
, GetId());
737 GetEventHandler()->ProcessEvent(event
);
744 * wxRichTextFontListBox class declaration
745 * A listbox to display styles.
748 IMPLEMENT_CLASS(wxRichTextFontListBox
, wxHtmlListBox
)
750 BEGIN_EVENT_TABLE(wxRichTextFontListBox
, wxHtmlListBox
)
753 wxRichTextFontListBox::wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
754 const wxSize
& size
, long style
)
757 Create(parent
, id
, pos
, size
, style
);
760 bool wxRichTextFontListBox::Create(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
761 const wxSize
& size
, long style
)
763 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
764 style
|= wxBORDER_THEME
;
766 return wxHtmlListBox::Create(parent
, id
, pos
, size
, style
);
769 wxRichTextFontListBox::~wxRichTextFontListBox()
773 /// Returns the HTML for this item
774 wxString
wxRichTextFontListBox::OnGetItem(size_t n
) const
776 if (m_faceNames
.GetCount() == 0)
777 return wxEmptyString
;
779 wxString str
= CreateHTML(m_faceNames
[n
]);
783 /// Get font name for index
784 wxString
wxRichTextFontListBox::GetFaceName(size_t i
) const
786 return m_faceNames
[i
];
789 /// Set selection for string, returning the index.
790 int wxRichTextFontListBox::SetFaceNameSelection(const wxString
& name
)
792 int i
= m_faceNames
.Index(name
);
798 /// Updates the font list
799 void wxRichTextFontListBox::UpdateFonts()
801 wxArrayString facenames
= wxRichTextCtrl::GetAvailableFontNames();
802 m_faceNames
= facenames
;
805 SetItemCount(m_faceNames
.GetCount());
810 // Convert a colour to a 6-digit hex string
811 static wxString
ColourToHexString(const wxColour
& col
)
815 hex
+= wxDecToHex(col
.Red());
816 hex
+= wxDecToHex(col
.Green());
817 hex
+= wxDecToHex(col
.Blue());
823 /// Creates a suitable HTML fragment for a definition
824 wxString
wxRichTextFontListBox::CreateHTML(const wxString
& facename
) const
826 wxString str
= wxT("<font");
828 str
<< wxT(" size=\"+2\"");;
830 if (!facename
.IsEmpty() && facename
!= _("(none)"))
831 str
<< wxT(" face=\"") << facename
<< wxT("\"");
833 if (def->GetStyle().GetTextColour().IsOk())
834 str << wxT(" color=\"#") << ColourToHexString(def->GetStyle().GetTextColour()) << wxT("\"");
839 bool hasBold
= false;
849 str
<< wxT("</font>");