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 int resizeBorder
= wxRESIZE_BORDER
;
114 GetFormattingDialogFactory()->SetSheetStyle(this);
116 wxPropertySheetDialog::Create(parent
, id
, title
, pos
, sz
,
117 style
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
120 GetFormattingDialogFactory()->CreateButtons(this);
121 GetFormattingDialogFactory()->CreatePages(flags
, this);
128 /// Get attributes from the given range
129 bool wxRichTextFormattingDialog::GetStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
)
131 if (ctrl
->GetFocusObject()->GetStyleForRange(range
.ToInternal(), m_attributes
))
132 return UpdateDisplay();
137 /// Apply attributes to the given range, only applying if necessary (wxRICHTEXT_SETSTYLE_OPTIMIZE)
138 bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
, int flags
)
140 return ctrl
->SetStyleEx(range
, m_attributes
, flags
);
143 // Apply attributes to the object being edited, if any
144 bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl
* WXUNUSED(ctrl
), int flags
)
148 wxRichTextParagraphLayoutBox
* parentContainer
= GetObject()->GetParentContainer();
150 parentContainer
->SetStyle(GetObject(), m_attributes
, flags
);
157 /// Set the attributes and optionally update the display
158 bool wxRichTextFormattingDialog::SetStyle(const wxRichTextAttr
& style
, bool update
)
160 m_attributes
= style
;
166 /// Set the style definition and optionally update the display
167 bool wxRichTextFormattingDialog::SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
, wxRichTextStyleSheet
* sheet
, bool update
)
169 m_styleSheet
= sheet
;
171 if (m_styleDefinition
)
172 delete m_styleDefinition
;
173 m_styleDefinition
= styleDef
.Clone();
175 return SetStyle(m_styleDefinition
->GetStyle(), update
);
178 /// Transfers the data and from to the window
179 bool wxRichTextFormattingDialog::TransferDataToWindow()
181 if (m_styleDefinition
)
182 m_attributes
= m_styleDefinition
->GetStyle();
184 if (!wxPropertySheetDialog::TransferDataToWindow())
190 bool wxRichTextFormattingDialog::TransferDataFromWindow()
192 if (!wxPropertySheetDialog::TransferDataFromWindow())
195 if (m_styleDefinition
)
196 m_styleDefinition
->GetStyle() = m_attributes
;
201 /// Update the display
202 bool wxRichTextFormattingDialog::UpdateDisplay()
204 return TransferDataToWindow();
207 /// Apply the styles when a different tab is selected, so the previews are
209 void wxRichTextFormattingDialog::OnTabChanged(wxBookCtrlEvent
& event
)
211 if (GetBookCtrl() != event
.GetEventObject())
217 int oldPageId
= event
.GetOldSelection();
220 wxWindow
* page
= GetBookCtrl()->GetPage(oldPageId
);
222 page
->TransferDataFromWindow();
225 int pageId
= event
.GetSelection();
228 wxWindow
* page
= GetBookCtrl()->GetPage(pageId
);
230 page
->TransferDataToWindow();
234 /// Respond to help command
235 void wxRichTextFormattingDialog::OnHelp(wxCommandEvent
& event
)
237 int selPage
= GetBookCtrl()->GetSelection();
238 if (selPage
!= wxNOT_FOUND
)
241 if (selPage
< (int) m_pageIds
.GetCount())
242 pageId
= m_pageIds
[selPage
];
243 if (!GetFormattingDialogFactory()->ShowHelp(pageId
, this))
248 void wxRichTextFormattingDialog::OnUpdateHelp(wxUpdateUIEvent
& event
)
253 void wxRichTextFormattingDialog::SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
)
255 if (ms_FormattingDialogFactory
)
256 delete ms_FormattingDialogFactory
;
257 ms_FormattingDialogFactory
= factory
;
260 // Find a page by class
261 wxWindow
* wxRichTextFormattingDialog::FindPage(wxClassInfo
* info
) const
264 for (i
= 0; i
< GetBookCtrl()->GetPageCount(); i
++)
266 wxWindow
* w
= GetBookCtrl()->GetPage(i
);
267 if (w
&& w
->GetClassInfo() == info
)
275 * Factory for formatting dialog
278 /// Create all pages, under the dialog's book control, also calling AddPage
279 bool wxRichTextFormattingDialogFactory::CreatePages(long pages
, wxRichTextFormattingDialog
* dialog
)
281 if (dialog
->GetImageList())
282 dialog
->GetBookCtrl()->SetImageList(dialog
->GetImageList());
284 int availablePageCount
= GetPageIdCount();
286 bool selected
= false;
287 for (i
= 0; i
< availablePageCount
; i
++)
289 int pageId
= GetPageId(i
);
290 if (pageId
!= -1 && (pages
& pageId
))
293 wxPanel
* panel
= CreatePage(pageId
, title
, dialog
);
294 wxASSERT( panel
!= NULL
);
297 int imageIndex
= GetPageImage(pageId
);
298 dialog
->GetBookCtrl()->AddPage(panel
, title
, !selected
, imageIndex
);
301 dialog
->AddPageId(pageId
);
309 /// Create a page, given a page identifier
310 wxPanel
* wxRichTextFormattingDialogFactory::CreatePage(int page
, wxString
& title
, wxRichTextFormattingDialog
* dialog
)
312 if (page
== wxRICHTEXT_FORMAT_STYLE_EDITOR
)
314 wxRichTextStylePage
* page
= new wxRichTextStylePage(dialog
->GetBookCtrl(), wxID_ANY
);
318 else if (page
== wxRICHTEXT_FORMAT_FONT
)
320 wxRichTextFontPage
* page
= new wxRichTextFontPage(dialog
->GetBookCtrl(), wxID_ANY
);
324 else if (page
== wxRICHTEXT_FORMAT_INDENTS_SPACING
)
326 wxRichTextIndentsSpacingPage
* page
= new wxRichTextIndentsSpacingPage(dialog
->GetBookCtrl(), wxID_ANY
);
327 title
= _("Indents && Spacing");
330 else if (page
== wxRICHTEXT_FORMAT_TABS
)
332 wxRichTextTabsPage
* page
= new wxRichTextTabsPage(dialog
->GetBookCtrl(), wxID_ANY
);
336 else if (page
== wxRICHTEXT_FORMAT_BULLETS
)
338 wxRichTextBulletsPage
* page
= new wxRichTextBulletsPage(dialog
->GetBookCtrl(), wxID_ANY
);
339 title
= _("Bullets");
343 else if (page
== wxRICHTEXT_FORMAT_LIST_STYLE
)
345 wxRichTextListStylePage
* page
= new wxRichTextListStylePage(dialog
->GetBookCtrl(), wxID_ANY
);
346 title
= _("List Style");
350 else if (page
== wxRICHTEXT_FORMAT_SIZE
)
352 wxRichTextSizePage
* page
= new wxRichTextSizePage(dialog
->GetBookCtrl(), wxID_ANY
);
356 else if (page
== wxRICHTEXT_FORMAT_MARGINS
)
358 wxRichTextMarginsPage
* page
= new wxRichTextMarginsPage(dialog
->GetBookCtrl(), wxID_ANY
);
359 title
= _("Margins");
362 else if (page
== wxRICHTEXT_FORMAT_BORDERS
)
364 wxRichTextBordersPage
* page
= new wxRichTextBordersPage(dialog
->GetBookCtrl(), wxID_ANY
);
365 title
= _("Borders");
368 else if (page
== wxRICHTEXT_FORMAT_BACKGROUND
)
370 wxRichTextBackgroundPage
* page
= new wxRichTextBackgroundPage(dialog
->GetBookCtrl(), wxID_ANY
);
371 title
= _("Background");
378 /// Enumerate all available page identifiers
379 int wxRichTextFormattingDialogFactory::GetPageId(int i
) const
382 wxRICHTEXT_FORMAT_STYLE_EDITOR
,
383 wxRICHTEXT_FORMAT_FONT
,
384 wxRICHTEXT_FORMAT_INDENTS_SPACING
,
385 wxRICHTEXT_FORMAT_BULLETS
,
386 wxRICHTEXT_FORMAT_TABS
,
387 wxRICHTEXT_FORMAT_LIST_STYLE
,
388 wxRICHTEXT_FORMAT_SIZE
,
389 wxRICHTEXT_FORMAT_MARGINS
,
390 wxRICHTEXT_FORMAT_BORDERS
,
391 wxRICHTEXT_FORMAT_BACKGROUND
394 if (i
< 0 || i
>= GetPageIdCount())
400 /// Get the number of available page identifiers
401 int wxRichTextFormattingDialogFactory::GetPageIdCount() const
410 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
411 bool wxRichTextFormattingDialogFactory::SetSheetStyle(wxRichTextFormattingDialog
* dialog
)
413 #if wxRICHTEXT_USE_TOOLBOOK
414 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
416 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
418 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
421 dialog
->SetSheetStyle(sheetStyle
);
422 dialog
->SetSheetInnerBorder(0);
423 dialog
->SetSheetOuterBorder(0);
426 #endif // wxRICHTEXT_USE_TOOLBOOK
431 /// Create the main dialog buttons
432 bool wxRichTextFormattingDialogFactory::CreateButtons(wxRichTextFormattingDialog
* dialog
)
434 int flags
= wxOK
|wxCANCEL
;
436 if (dialog
->GetWindowStyleFlag() & wxRICHTEXT_FORMAT_HELP_BUTTON
)
440 // If using a toolbook, also follow Mac style and don't create buttons
441 #if !wxRICHTEXT_USE_TOOLBOOK
442 dialog
->CreateButtons(flags
);
448 // Invoke help for the dialog
449 bool wxRichTextFormattingDialogFactory::ShowHelp(int WXUNUSED(page
), wxRichTextFormattingDialog
* dialog
)
451 wxRichTextDialogPage
* window
= NULL
;
452 int sel
= dialog
->GetBookCtrl()->GetSelection();
454 window
= wxDynamicCast(dialog
->GetBookCtrl()->GetPage(sel
), wxRichTextDialogPage
);
455 if (window
&& window
->GetHelpId() != -1)
457 if (window
->GetUICustomization())
458 return window
->GetUICustomization()->ShowHelp(dialog
, window
->GetHelpId());
459 else if (dialog
->GetUICustomization())
460 return dialog
->GetUICustomization()->ShowHelp(dialog
, window
->GetHelpId());
464 else if (dialog
->GetHelpId() != -1 && dialog
->GetUICustomization())
465 return dialog
->ShowHelp(dialog
);
471 * Module to initialise and clean up handlers
474 class wxRichTextFormattingDialogModule
: public wxModule
476 DECLARE_DYNAMIC_CLASS(wxRichTextFormattingDialogModule
)
478 wxRichTextFormattingDialogModule() {}
479 bool OnInit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(new wxRichTextFormattingDialogFactory
); return true; }
480 void OnExit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(NULL
); }
483 IMPLEMENT_DYNAMIC_CLASS(wxRichTextFormattingDialogModule
, wxModule
)
486 * Font preview control
489 BEGIN_EVENT_TABLE(wxRichTextFontPreviewCtrl
, wxWindow
)
490 EVT_PAINT(wxRichTextFontPreviewCtrl::OnPaint
)
493 wxRichTextFontPreviewCtrl::wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& sz
, long style
)
495 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
496 style
|= wxBORDER_THEME
;
498 wxWindow::Create(parent
, id
, pos
, sz
, style
);
500 SetBackgroundColour(*wxWHITE
);
504 void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
508 wxSize size
= GetSize();
509 wxFont font
= GetFont();
511 if ((GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
) || (GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
))
513 double size
= static_cast<double>(font
.GetPointSize()) / wxSCRIPT_MUL_FACTOR
;
514 font
.SetPointSize( static_cast<int>(size
) );
520 // Calculate vertical and horizontal centre
521 wxCoord w
= 0, h
= 0;
523 wxString
text(_("ABCDEFGabcdefg12345"));
524 if (GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS
)
527 dc
.GetTextExtent( text
, &w
, &h
);
528 int cx
= wxMax(2, (size
.x
/2) - (w
/2));
529 int cy
= wxMax(2, (size
.y
/2) - (h
/2));
531 if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
)
533 if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
)
536 dc
.SetTextForeground(GetForegroundColour());
537 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
538 dc
.DrawText(text
, cx
, cy
);
540 if (GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH
)
542 dc
.SetPen(wxPen(GetForegroundColour(), 1));
543 dc
.DrawLine(cx
, (int) (cy
+ h
/2 + 0.5), cx
+ w
, (int) (cy
+ h
/2 + 0.5));
546 dc
.DestroyClippingRegion();
550 // Helper for pages to get the top-level dialog
551 wxRichTextFormattingDialog
* wxRichTextFormattingDialog::GetDialog(wxWindow
* win
)
553 wxWindow
* p
= win
->GetParent();
554 while (p
&& !p
->IsKindOf(CLASSINFO(wxRichTextFormattingDialog
)))
556 wxRichTextFormattingDialog
* dialog
= wxDynamicCast(p
, wxRichTextFormattingDialog
);
560 // Helper for pages to get the attributes
561 wxRichTextAttr
* wxRichTextFormattingDialog::GetDialogAttributes(wxWindow
* win
)
563 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
565 return & dialog
->GetAttributes();
571 // Helper for pages to get the attributes to reset
572 wxRichTextAttr
* wxRichTextFormattingDialog::GetDialogResetAttributes(wxWindow
* win
)
574 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
576 return & dialog
->GetResetAttributes();
582 // Helper for pages to get the style
583 wxRichTextStyleDefinition
* wxRichTextFormattingDialog::GetDialogStyleDefinition(wxWindow
* win
)
585 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
587 return dialog
->GetStyleDefinition();
592 void wxRichTextFormattingDialog::SetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
)
598 checkBox
->SetValue(false);
599 valueCtrl
->SetValue(wxT("0"));
600 unitsCtrl
->SetSelection(0);
603 dim
.SetUnits(wxTEXT_ATTR_UNITS_PIXELS
);
608 checkBox
->SetValue(true);
609 if (dim
.GetUnits() == wxTEXT_ATTR_UNITS_TENTHS_MM
)
612 float value
= float(dim
.GetValue()) / 100.0;
613 valueCtrl
->SetValue(wxString::Format(wxT("%.2f"), value
));
615 else if (dim
.GetUnits() == wxTEXT_ATTR_UNITS_PERCENTAGE
)
618 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
623 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
626 unitsCtrl
->SetSelection(unitsIdx
);
630 void wxRichTextFormattingDialog::GetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
)
632 if (!checkBox
->GetValue())
638 if (unitsCtrl
->GetSelection() == 1)
639 dim
.SetUnits(wxTEXT_ATTR_UNITS_TENTHS_MM
);
640 else if (unitsCtrl
->GetSelection() == 2)
641 dim
.SetUnits(wxTEXT_ATTR_UNITS_PERCENTAGE
);
643 dim
.SetUnits(wxTEXT_ATTR_UNITS_PIXELS
);
646 if (ConvertFromString(valueCtrl
->GetValue(), value
, dim
.GetUnits()))
651 bool wxRichTextFormattingDialog::ConvertFromString(const wxString
& string
, int& ret
, int scale
)
653 const wxChar
* chars
= string
.GetData();
658 for (unsigned int i
= 0; i
< string
.Len() && remain
; i
++)
660 if (!(chars
[i
] >= wxT('0') && chars
[i
] <= wxT('9')) && !(scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
&& chars
[i
] == wxT('.')))
663 if (chars
[i
] == wxT('.'))
672 ret
= ret
* 10 + chars
[i
] - wxT('0');
675 while (remain
-- > 0 && scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
)
682 * A control for displaying a small preview of a colour or bitmap
685 BEGIN_EVENT_TABLE(wxRichTextColourSwatchCtrl
, wxControl
)
686 EVT_MOUSE_EVENTS(wxRichTextColourSwatchCtrl::OnMouseEvent
)
689 IMPLEMENT_CLASS(wxRichTextColourSwatchCtrl
, wxControl
)
691 wxRichTextColourSwatchCtrl::wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
693 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
694 style
|= wxBORDER_THEME
;
696 wxControl::Create(parent
, id
, pos
, size
, style
);
698 SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
701 wxRichTextColourSwatchCtrl::~wxRichTextColourSwatchCtrl()
705 void wxRichTextColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
707 if (event
.LeftDown())
709 wxWindow
* parent
= GetParent();
710 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
711 parent
= parent
->GetParent();
714 data
.SetChooseFull(true);
715 data
.SetColour(m_colour
);
717 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
718 // Crashes on wxMac (no m_peer)
720 dialog
->SetTitle(_("Colour"));
722 if (dialog
->ShowModal() == wxID_OK
)
724 wxColourData retData
= dialog
->GetColourData();
725 m_colour
= retData
.GetColour();
726 SetBackgroundColour(m_colour
);
729 #endif // wxUSE_COLOURDLG
732 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
733 GetEventHandler()->ProcessEvent(event
);
740 * wxRichTextFontListBox class declaration
741 * A listbox to display styles.
744 IMPLEMENT_CLASS(wxRichTextFontListBox
, wxHtmlListBox
)
746 BEGIN_EVENT_TABLE(wxRichTextFontListBox
, wxHtmlListBox
)
749 wxRichTextFontListBox::wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
750 const wxSize
& size
, long style
)
753 Create(parent
, id
, pos
, size
, style
);
756 bool wxRichTextFontListBox::Create(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
757 const wxSize
& size
, long style
)
759 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
760 style
|= wxBORDER_THEME
;
762 return wxHtmlListBox::Create(parent
, id
, pos
, size
, style
);
765 wxRichTextFontListBox::~wxRichTextFontListBox()
769 /// Returns the HTML for this item
770 wxString
wxRichTextFontListBox::OnGetItem(size_t n
) const
772 if (m_faceNames
.GetCount() == 0)
773 return wxEmptyString
;
775 wxString str
= CreateHTML(m_faceNames
[n
]);
779 /// Get font name for index
780 wxString
wxRichTextFontListBox::GetFaceName(size_t i
) const
782 return m_faceNames
[i
];
785 /// Set selection for string, returning the index.
786 int wxRichTextFontListBox::SetFaceNameSelection(const wxString
& name
)
788 int i
= m_faceNames
.Index(name
);
794 /// Updates the font list
795 void wxRichTextFontListBox::UpdateFonts()
797 wxArrayString facenames
= wxRichTextCtrl::GetAvailableFontNames();
798 m_faceNames
= facenames
;
801 SetItemCount(m_faceNames
.GetCount());
806 // Convert a colour to a 6-digit hex string
807 static wxString
ColourToHexString(const wxColour
& col
)
811 hex
+= wxDecToHex(col
.Red());
812 hex
+= wxDecToHex(col
.Green());
813 hex
+= wxDecToHex(col
.Blue());
819 /// Creates a suitable HTML fragment for a definition
820 wxString
wxRichTextFontListBox::CreateHTML(const wxString
& facename
) const
822 wxString str
= wxT("<font");
824 str
<< wxT(" size=\"+2\"");;
826 if (!facename
.IsEmpty() && facename
!= _("(none)"))
827 str
<< wxT(" face=\"") << facename
<< wxT("\"");
829 if (def->GetStyle().GetTextColour().IsOk())
830 str << wxT(" color=\"#") << ColourToHexString(def->GetStyle().GetTextColour()) << wxT("\"");
835 bool hasBold
= false;
845 str
<< wxT("</font>");