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()) / 100.0;
615 valueCtrl
->SetValue(wxString::Format(wxT("%.2f"), value
));
617 else if (dim
.GetUnits() == wxTEXT_ATTR_UNITS_PERCENTAGE
)
620 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
625 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
628 unitsCtrl
->SetSelection(unitsIdx
);
632 void wxRichTextFormattingDialog::GetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
)
634 if (!checkBox
->GetValue())
640 if (unitsCtrl
->GetSelection() == 1)
641 dim
.SetUnits(wxTEXT_ATTR_UNITS_TENTHS_MM
);
642 else if (unitsCtrl
->GetSelection() == 2)
643 dim
.SetUnits(wxTEXT_ATTR_UNITS_PERCENTAGE
);
645 dim
.SetUnits(wxTEXT_ATTR_UNITS_PIXELS
);
648 if (ConvertFromString(valueCtrl
->GetValue(), value
, dim
.GetUnits()))
653 bool wxRichTextFormattingDialog::ConvertFromString(const wxString
& string
, int& ret
, int scale
)
655 const wxChar
* chars
= string
.GetData();
660 for (unsigned int i
= 0; i
< string
.Len() && remain
; i
++)
662 if (!(chars
[i
] >= wxT('0') && chars
[i
] <= wxT('9')) && !(scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
&& chars
[i
] == wxT('.')))
665 if (chars
[i
] == wxT('.'))
674 ret
= ret
* 10 + chars
[i
] - wxT('0');
677 while (remain
-- > 0 && scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
)
684 * A control for displaying a small preview of a colour or bitmap
687 BEGIN_EVENT_TABLE(wxRichTextColourSwatchCtrl
, wxControl
)
688 EVT_MOUSE_EVENTS(wxRichTextColourSwatchCtrl::OnMouseEvent
)
691 IMPLEMENT_CLASS(wxRichTextColourSwatchCtrl
, wxControl
)
693 wxRichTextColourSwatchCtrl::wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
695 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
696 style
|= wxBORDER_THEME
;
698 wxControl::Create(parent
, id
, pos
, size
, style
);
700 SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
703 wxRichTextColourSwatchCtrl::~wxRichTextColourSwatchCtrl()
707 void wxRichTextColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
709 if (event
.LeftDown())
711 wxWindow
* parent
= GetParent();
712 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
713 parent
= parent
->GetParent();
716 data
.SetChooseFull(true);
717 data
.SetColour(m_colour
);
719 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
720 // Crashes on wxMac (no m_peer)
722 dialog
->SetTitle(_("Colour"));
724 if (dialog
->ShowModal() == wxID_OK
)
726 wxColourData retData
= dialog
->GetColourData();
727 m_colour
= retData
.GetColour();
728 SetBackgroundColour(m_colour
);
731 #endif // wxUSE_COLOURDLG
734 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
735 GetEventHandler()->ProcessEvent(event
);
742 * wxRichTextFontListBox class declaration
743 * A listbox to display styles.
746 IMPLEMENT_CLASS(wxRichTextFontListBox
, wxHtmlListBox
)
748 BEGIN_EVENT_TABLE(wxRichTextFontListBox
, wxHtmlListBox
)
751 wxRichTextFontListBox::wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
752 const wxSize
& size
, long style
)
755 Create(parent
, id
, pos
, size
, style
);
758 bool wxRichTextFontListBox::Create(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
759 const wxSize
& size
, long style
)
761 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
762 style
|= wxBORDER_THEME
;
764 return wxHtmlListBox::Create(parent
, id
, pos
, size
, style
);
767 wxRichTextFontListBox::~wxRichTextFontListBox()
771 /// Returns the HTML for this item
772 wxString
wxRichTextFontListBox::OnGetItem(size_t n
) const
774 if (m_faceNames
.GetCount() == 0)
775 return wxEmptyString
;
777 wxString str
= CreateHTML(m_faceNames
[n
]);
781 /// Get font name for index
782 wxString
wxRichTextFontListBox::GetFaceName(size_t i
) const
784 return m_faceNames
[i
];
787 /// Set selection for string, returning the index.
788 int wxRichTextFontListBox::SetFaceNameSelection(const wxString
& name
)
790 int i
= m_faceNames
.Index(name
);
796 /// Updates the font list
797 void wxRichTextFontListBox::UpdateFonts()
799 wxArrayString facenames
= wxRichTextCtrl::GetAvailableFontNames();
800 m_faceNames
= facenames
;
803 SetItemCount(m_faceNames
.GetCount());
808 // Convert a colour to a 6-digit hex string
809 static wxString
ColourToHexString(const wxColour
& col
)
813 hex
+= wxDecToHex(col
.Red());
814 hex
+= wxDecToHex(col
.Green());
815 hex
+= wxDecToHex(col
.Blue());
821 /// Creates a suitable HTML fragment for a definition
822 wxString
wxRichTextFontListBox::CreateHTML(const wxString
& facename
) const
824 wxString str
= wxT("<font");
826 str
<< wxT(" size=\"+2\"");;
828 if (!facename
.IsEmpty() && facename
!= _("(none)"))
829 str
<< wxT(" face=\"") << facename
<< wxT("\"");
831 if (def->GetStyle().GetTextColour().Ok())
832 str << wxT(" color=\"#") << ColourToHexString(def->GetStyle().GetTextColour()) << wxT("\"");
837 bool hasBold
= false;
847 str
<< wxT("</font>");