1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextformatdlg.cpp
3 // Purpose: Formatting dialog for wxRichTextCtrl
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/richtext/richtextformatdlg.h"
23 #include "wx/listbox.h"
24 #include "wx/combobox.h"
25 #include "wx/textctrl.h"
27 #include "wx/stattext.h"
28 #include "wx/statline.h"
29 #include "wx/radiobut.h"
31 #include "wx/bitmap.h"
32 #include "wx/dcclient.h"
34 #include "wx/checkbox.h"
35 #include "wx/button.h"
38 #include "wx/bookctrl.h"
39 #include "wx/colordlg.h"
40 #include "wx/settings.h"
41 #include "wx/module.h"
42 #include "wx/imaglist.h"
44 #include "wx/richtext/richtextctrl.h"
45 #include "wx/richtext/richtextstyles.h"
48 #include "../../src/richtext/richtextfontpage.cpp"
49 #include "../../src/richtext/richtextindentspage.cpp"
50 #include "../../src/richtext/richtexttabspage.cpp"
51 #include "../../src/richtext/richtextbulletspage.cpp"
52 #include "../../src/richtext/richtextstylepage.cpp"
53 #include "../../src/richtext/richtextliststylepage.cpp"
54 #include "../../src/richtext/richtextsizepage.cpp"
55 #include "../../src/richtext/richtextmarginspage.cpp"
56 #include "../../src/richtext/richtextborderspage.cpp"
57 #include "../../src/richtext/richtextbackgroundpage.cpp"
59 #include "richtextfontpage.cpp"
60 #include "richtextindentspage.cpp"
61 #include "richtexttabspage.cpp"
62 #include "richtextbulletspage.cpp"
63 #include "richtextmarginspage.cpp"
64 #include "richtextsizepage.cpp"
65 #include "richtextborderspage.cpp"
66 #include "richtextbackgroundpage.cpp"
67 // Digital Mars can't cope with this much code
69 #include "richtextliststylepage.cpp"
71 #include "richtextstylepage.cpp"
74 #if 0 // def __WXMAC__
75 #define wxRICHTEXT_USE_TOOLBOOK 1
77 #define wxRICHTEXT_USE_TOOLBOOK 0
80 bool wxRichTextFormattingDialog::sm_showToolTips
= false;
82 IMPLEMENT_CLASS(wxRichTextDialogPage
, wxPanel
)
84 IMPLEMENT_CLASS(wxRichTextFormattingDialog
, wxPropertySheetDialog
)
86 BEGIN_EVENT_TABLE(wxRichTextFormattingDialog
, wxPropertySheetDialog
)
87 EVT_BOOKCTRL_PAGE_CHANGED(wxID_ANY
, wxRichTextFormattingDialog::OnTabChanged
)
88 EVT_BUTTON(wxID_HELP
, wxRichTextFormattingDialog::OnHelp
)
89 EVT_UPDATE_UI(wxID_HELP
, wxRichTextFormattingDialog::OnUpdateHelp
)
92 IMPLEMENT_HELP_PROVISION(wxRichTextFormattingDialog
)
94 wxRichTextFormattingDialogFactory
* wxRichTextFormattingDialog::ms_FormattingDialogFactory
= NULL
;
96 void wxRichTextFormattingDialog::Init()
98 m_styleDefinition
= NULL
;
104 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 SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
117 int resizeBorder
= wxRESIZE_BORDER
;
119 GetFormattingDialogFactory()->SetSheetStyle(this);
121 wxPropertySheetDialog::Create(parent
, id
, title
, pos
, sz
,
122 style
| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE
, resizeBorder
)
125 GetFormattingDialogFactory()->CreateButtons(this);
126 GetFormattingDialogFactory()->CreatePages(flags
, this);
133 /// Get attributes from the given range
134 bool wxRichTextFormattingDialog::GetStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
)
136 if (ctrl
->GetFocusObject()->GetStyleForRange(range
.ToInternal(), m_attributes
))
137 return UpdateDisplay();
142 /// Apply attributes to the given range, only applying if necessary (wxRICHTEXT_SETSTYLE_OPTIMIZE)
143 bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl
* ctrl
, const wxRichTextRange
& range
, int flags
)
145 return ctrl
->SetStyleEx(range
, m_attributes
, flags
);
148 // Apply attributes to the object being edited, if any
149 bool wxRichTextFormattingDialog::ApplyStyle(wxRichTextCtrl
* ctrl
, int flags
)
153 ctrl
->SetStyle(GetObject(), m_attributes
, flags
);
160 /// Set the attributes and optionally update the display
161 bool wxRichTextFormattingDialog::SetStyle(const wxRichTextAttr
& style
, bool update
)
163 m_attributes
= style
;
169 /// Set the style definition and optionally update the display
170 bool wxRichTextFormattingDialog::SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
, wxRichTextStyleSheet
* sheet
, bool update
)
172 m_styleSheet
= sheet
;
174 if (m_styleDefinition
)
175 delete m_styleDefinition
;
176 m_styleDefinition
= styleDef
.Clone();
178 return SetStyle(m_styleDefinition
->GetStyle(), update
);
181 /// Transfers the data and from to the window
182 bool wxRichTextFormattingDialog::TransferDataToWindow()
184 if (m_styleDefinition
)
185 m_attributes
= m_styleDefinition
->GetStyle();
187 if (!wxPropertySheetDialog::TransferDataToWindow())
193 bool wxRichTextFormattingDialog::TransferDataFromWindow()
195 if (!wxPropertySheetDialog::TransferDataFromWindow())
198 if (m_styleDefinition
)
199 m_styleDefinition
->GetStyle() = m_attributes
;
204 /// Update the display
205 bool wxRichTextFormattingDialog::UpdateDisplay()
207 return TransferDataToWindow();
210 /// Apply the styles when a different tab is selected, so the previews are
212 void wxRichTextFormattingDialog::OnTabChanged(wxBookCtrlEvent
& event
)
214 if (GetBookCtrl() != event
.GetEventObject())
220 int oldPageId
= event
.GetOldSelection();
223 wxWindow
* page
= GetBookCtrl()->GetPage(oldPageId
);
225 page
->TransferDataFromWindow();
228 int pageId
= event
.GetSelection();
231 wxWindow
* page
= GetBookCtrl()->GetPage(pageId
);
233 page
->TransferDataToWindow();
237 /// Respond to help command
238 void wxRichTextFormattingDialog::OnHelp(wxCommandEvent
& event
)
240 int selPage
= GetBookCtrl()->GetSelection();
241 if (selPage
!= wxNOT_FOUND
)
244 if (selPage
< (int) m_pageIds
.GetCount())
245 pageId
= m_pageIds
[selPage
];
246 if (!GetFormattingDialogFactory()->ShowHelp(pageId
, this))
251 void wxRichTextFormattingDialog::OnUpdateHelp(wxUpdateUIEvent
& event
)
256 void wxRichTextFormattingDialog::SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
)
258 if (ms_FormattingDialogFactory
)
259 delete ms_FormattingDialogFactory
;
260 ms_FormattingDialogFactory
= factory
;
263 // Find a page by class
264 wxWindow
* wxRichTextFormattingDialog::FindPage(wxClassInfo
* info
) const
267 for (i
= 0; i
< GetBookCtrl()->GetPageCount(); i
++)
269 wxWindow
* w
= GetBookCtrl()->GetPage(i
);
270 if (w
&& w
->GetClassInfo() == info
)
278 * Factory for formatting dialog
281 /// Create all pages, under the dialog's book control, also calling AddPage
282 bool wxRichTextFormattingDialogFactory::CreatePages(long pages
, wxRichTextFormattingDialog
* dialog
)
284 if (dialog
->GetImageList())
285 dialog
->GetBookCtrl()->SetImageList(dialog
->GetImageList());
287 int availablePageCount
= GetPageIdCount();
289 bool selected
= false;
290 for (i
= 0; i
< availablePageCount
; i
++)
292 int pageId
= GetPageId(i
);
293 if (pageId
!= -1 && (pages
& pageId
))
296 wxPanel
* panel
= CreatePage(pageId
, title
, dialog
);
297 wxASSERT( panel
!= NULL
);
300 int imageIndex
= GetPageImage(pageId
);
301 dialog
->GetBookCtrl()->AddPage(panel
, title
, !selected
, imageIndex
);
304 dialog
->AddPageId(pageId
);
312 /// Create a page, given a page identifier
313 wxPanel
* wxRichTextFormattingDialogFactory::CreatePage(int page
, wxString
& title
, wxRichTextFormattingDialog
* dialog
)
315 if (page
== wxRICHTEXT_FORMAT_STYLE_EDITOR
)
317 wxRichTextStylePage
* page
= new wxRichTextStylePage(dialog
->GetBookCtrl(), wxID_ANY
);
321 else if (page
== wxRICHTEXT_FORMAT_FONT
)
323 wxRichTextFontPage
* page
= new wxRichTextFontPage(dialog
->GetBookCtrl(), wxID_ANY
);
327 else if (page
== wxRICHTEXT_FORMAT_INDENTS_SPACING
)
329 wxRichTextIndentsSpacingPage
* page
= new wxRichTextIndentsSpacingPage(dialog
->GetBookCtrl(), wxID_ANY
);
330 title
= _("Indents && Spacing");
333 else if (page
== wxRICHTEXT_FORMAT_TABS
)
335 wxRichTextTabsPage
* page
= new wxRichTextTabsPage(dialog
->GetBookCtrl(), wxID_ANY
);
339 else if (page
== wxRICHTEXT_FORMAT_BULLETS
)
341 wxRichTextBulletsPage
* page
= new wxRichTextBulletsPage(dialog
->GetBookCtrl(), wxID_ANY
);
342 title
= _("Bullets");
346 else if (page
== wxRICHTEXT_FORMAT_LIST_STYLE
)
348 wxRichTextListStylePage
* page
= new wxRichTextListStylePage(dialog
->GetBookCtrl(), wxID_ANY
);
349 title
= _("List Style");
353 else if (page
== wxRICHTEXT_FORMAT_SIZE
)
355 wxRichTextSizePage
* page
= new wxRichTextSizePage(dialog
->GetBookCtrl(), wxID_ANY
);
359 else if (page
== wxRICHTEXT_FORMAT_MARGINS
)
361 wxRichTextMarginsPage
* page
= new wxRichTextMarginsPage(dialog
->GetBookCtrl(), wxID_ANY
);
362 title
= _("Margins");
365 else if (page
== wxRICHTEXT_FORMAT_BORDERS
)
367 wxRichTextBordersPage
* page
= new wxRichTextBordersPage(dialog
->GetBookCtrl(), wxID_ANY
);
368 title
= _("Borders");
371 else if (page
== wxRICHTEXT_FORMAT_BACKGROUND
)
373 wxRichTextBackgroundPage
* page
= new wxRichTextBackgroundPage(dialog
->GetBookCtrl(), wxID_ANY
);
374 title
= _("Background");
381 /// Enumerate all available page identifiers
382 int wxRichTextFormattingDialogFactory::GetPageId(int i
) const
385 wxRICHTEXT_FORMAT_STYLE_EDITOR
,
386 wxRICHTEXT_FORMAT_FONT
,
387 wxRICHTEXT_FORMAT_INDENTS_SPACING
,
388 wxRICHTEXT_FORMAT_BULLETS
,
389 wxRICHTEXT_FORMAT_TABS
,
390 wxRICHTEXT_FORMAT_LIST_STYLE
,
391 wxRICHTEXT_FORMAT_SIZE
,
392 wxRICHTEXT_FORMAT_MARGINS
,
393 wxRICHTEXT_FORMAT_BORDERS
,
394 wxRICHTEXT_FORMAT_BACKGROUND
397 if (i
< 0 || i
>= GetPageIdCount())
403 /// Get the number of available page identifiers
404 int wxRichTextFormattingDialogFactory::GetPageIdCount() const
413 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
414 bool wxRichTextFormattingDialogFactory::SetSheetStyle(wxRichTextFormattingDialog
* dialog
)
416 #if wxRICHTEXT_USE_TOOLBOOK
417 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
419 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
421 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
424 dialog
->SetSheetStyle(sheetStyle
);
425 dialog
->SetSheetInnerBorder(0);
426 dialog
->SetSheetOuterBorder(0);
429 #endif // wxRICHTEXT_USE_TOOLBOOK
434 /// Create the main dialog buttons
435 bool wxRichTextFormattingDialogFactory::CreateButtons(wxRichTextFormattingDialog
* dialog
)
437 int flags
= wxOK
|wxCANCEL
;
439 if (dialog
->GetWindowStyleFlag() & wxRICHTEXT_FORMAT_HELP_BUTTON
)
443 // If using a toolbook, also follow Mac style and don't create buttons
444 #if !wxRICHTEXT_USE_TOOLBOOK
445 dialog
->CreateButtons(flags
);
451 // Invoke help for the dialog
452 bool wxRichTextFormattingDialogFactory::ShowHelp(int WXUNUSED(page
), wxRichTextFormattingDialog
* dialog
)
454 wxRichTextDialogPage
* window
= NULL
;
455 int sel
= dialog
->GetBookCtrl()->GetSelection();
457 window
= wxDynamicCast(dialog
->GetBookCtrl()->GetPage(sel
), wxRichTextDialogPage
);
458 if (window
&& window
->GetHelpId() != -1)
460 if (window
->GetUICustomization())
461 return window
->GetUICustomization()->ShowHelp(dialog
, window
->GetHelpId());
462 else if (dialog
->GetUICustomization())
463 return dialog
->GetUICustomization()->ShowHelp(dialog
, window
->GetHelpId());
467 else if (dialog
->GetHelpId() != -1 && dialog
->GetUICustomization())
468 return dialog
->ShowHelp(dialog
);
474 * Module to initialise and clean up handlers
477 class wxRichTextFormattingDialogModule
: public wxModule
479 DECLARE_DYNAMIC_CLASS(wxRichTextFormattingDialogModule
)
481 wxRichTextFormattingDialogModule() {}
482 bool OnInit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(new wxRichTextFormattingDialogFactory
); return true; }
483 void OnExit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(NULL
); }
486 IMPLEMENT_DYNAMIC_CLASS(wxRichTextFormattingDialogModule
, wxModule
)
489 * Font preview control
492 BEGIN_EVENT_TABLE(wxRichTextFontPreviewCtrl
, wxWindow
)
493 EVT_PAINT(wxRichTextFontPreviewCtrl::OnPaint
)
496 wxRichTextFontPreviewCtrl::wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& sz
, long style
)
498 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
499 style
|= wxBORDER_THEME
;
501 wxWindow::Create(parent
, id
, pos
, sz
, style
);
503 SetBackgroundColour(*wxWHITE
);
507 void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
511 wxSize size
= GetSize();
512 wxFont font
= GetFont();
514 if ((GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
) || (GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
))
516 double size
= static_cast<double>(font
.GetPointSize()) / wxSCRIPT_MUL_FACTOR
;
517 font
.SetPointSize( static_cast<int>(size
) );
523 // Calculate vertical and horizontal centre
524 wxCoord w
= 0, h
= 0;
526 wxString
text(_("ABCDEFGabcdefg12345"));
527 if (GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS
)
530 dc
.GetTextExtent( text
, &w
, &h
);
531 int cx
= wxMax(2, (size
.x
/2) - (w
/2));
532 int cy
= wxMax(2, (size
.y
/2) - (h
/2));
534 if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
)
536 if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
)
539 dc
.SetTextForeground(GetForegroundColour());
540 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
541 dc
.DrawText(text
, cx
, cy
);
543 if (GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH
)
545 dc
.SetPen(wxPen(GetForegroundColour(), 1));
546 dc
.DrawLine(cx
, (int) (cy
+ h
/2 + 0.5), cx
+ w
, (int) (cy
+ h
/2 + 0.5));
549 dc
.DestroyClippingRegion();
553 // Helper for pages to get the top-level dialog
554 wxRichTextFormattingDialog
* wxRichTextFormattingDialog::GetDialog(wxWindow
* win
)
556 wxWindow
* p
= win
->GetParent();
557 while (p
&& !wxDynamicCast(p
, wxRichTextFormattingDialog
))
559 wxRichTextFormattingDialog
* dialog
= wxDynamicCast(p
, wxRichTextFormattingDialog
);
563 // Helper for pages to get the attributes
564 wxRichTextAttr
* wxRichTextFormattingDialog::GetDialogAttributes(wxWindow
* win
)
566 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
568 return & dialog
->GetAttributes();
574 // Helper for pages to get the attributes to reset
575 wxRichTextAttr
* wxRichTextFormattingDialog::GetDialogResetAttributes(wxWindow
* win
)
577 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
579 return & dialog
->GetResetAttributes();
585 // Helper for pages to get the style
586 wxRichTextStyleDefinition
* wxRichTextFormattingDialog::GetDialogStyleDefinition(wxWindow
* win
)
588 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
590 return dialog
->GetStyleDefinition();
595 void wxRichTextFormattingDialog::SetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
)
601 checkBox
->SetValue(false);
602 valueCtrl
->SetValue(wxT("0"));
603 unitsCtrl
->SetSelection(0);
606 dim
.SetUnits(wxTEXT_ATTR_UNITS_PIXELS
);
611 checkBox
->SetValue(true);
612 if (dim
.GetUnits() == wxTEXT_ATTR_UNITS_TENTHS_MM
)
615 float value
= float(dim
.GetValue()) / 100.0;
616 valueCtrl
->SetValue(wxString::Format(wxT("%.2f"), value
));
618 else if (dim
.GetUnits() == wxTEXT_ATTR_UNITS_PERCENTAGE
)
621 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
626 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
629 unitsCtrl
->SetSelection(unitsIdx
);
633 void wxRichTextFormattingDialog::GetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
)
635 if (!checkBox
->GetValue())
641 if (unitsCtrl
->GetSelection() == 1)
642 dim
.SetUnits(wxTEXT_ATTR_UNITS_TENTHS_MM
);
643 else if (unitsCtrl
->GetSelection() == 2)
644 dim
.SetUnits(wxTEXT_ATTR_UNITS_PERCENTAGE
);
646 dim
.SetUnits(wxTEXT_ATTR_UNITS_PIXELS
);
649 if (ConvertFromString(valueCtrl
->GetValue(), value
, dim
.GetUnits()))
654 bool wxRichTextFormattingDialog::ConvertFromString(const wxString
& string
, int& ret
, int scale
)
656 const wxChar
* chars
= string
.GetData();
661 for (unsigned int i
= 0; i
< string
.Len() && remain
; i
++)
663 if (!(chars
[i
] >= wxT('0') && chars
[i
] <= wxT('9')) && !(scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
&& chars
[i
] == wxT('.')))
666 if (chars
[i
] == wxT('.'))
675 ret
= ret
* 10 + chars
[i
] - wxT('0');
678 while (remain
-- > 0 && scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
)
685 * A control for displaying a small preview of a colour or bitmap
688 BEGIN_EVENT_TABLE(wxRichTextColourSwatchCtrl
, wxControl
)
689 EVT_MOUSE_EVENTS(wxRichTextColourSwatchCtrl::OnMouseEvent
)
692 IMPLEMENT_CLASS(wxRichTextColourSwatchCtrl
, wxControl
)
694 wxRichTextColourSwatchCtrl::wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
696 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
697 style
|= wxBORDER_THEME
;
699 wxControl::Create(parent
, id
, pos
, size
, style
);
701 SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
704 wxRichTextColourSwatchCtrl::~wxRichTextColourSwatchCtrl()
708 void wxRichTextColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
710 if (event
.LeftDown())
712 wxWindow
* parent
= GetParent();
713 while (parent
!= NULL
&& !wxDynamicCast(parent
, wxDialog
) && !wxDynamicCast(parent
, wxFrame
))
714 parent
= parent
->GetParent();
717 data
.SetChooseFull(true);
718 data
.SetColour(m_colour
);
720 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
721 // Crashes on wxMac (no m_peer)
723 dialog
->SetTitle(_("Colour"));
725 if (dialog
->ShowModal() == wxID_OK
)
727 wxColourData retData
= dialog
->GetColourData();
728 m_colour
= retData
.GetColour();
729 SetBackgroundColour(m_colour
);
732 #endif // wxUSE_COLOURDLG
735 wxCommandEvent
event(wxEVT_BUTTON
, GetId());
736 GetEventHandler()->ProcessEvent(event
);
743 * wxRichTextFontListBox class declaration
744 * A listbox to display styles.
747 IMPLEMENT_CLASS(wxRichTextFontListBox
, wxHtmlListBox
)
749 BEGIN_EVENT_TABLE(wxRichTextFontListBox
, wxHtmlListBox
)
752 wxRichTextFontListBox::wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
753 const wxSize
& size
, long style
)
756 Create(parent
, id
, pos
, size
, style
);
759 bool wxRichTextFontListBox::Create(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
760 const wxSize
& size
, long style
)
762 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
763 style
|= wxBORDER_THEME
;
765 return wxHtmlListBox::Create(parent
, id
, pos
, size
, style
);
768 wxRichTextFontListBox::~wxRichTextFontListBox()
772 /// Returns the HTML for this item
773 wxString
wxRichTextFontListBox::OnGetItem(size_t n
) const
775 if (m_faceNames
.GetCount() == 0)
776 return wxEmptyString
;
778 wxString str
= CreateHTML(m_faceNames
[n
]);
782 /// Get font name for index
783 wxString
wxRichTextFontListBox::GetFaceName(size_t i
) const
785 return m_faceNames
[i
];
788 /// Set selection for string, returning the index.
789 int wxRichTextFontListBox::SetFaceNameSelection(const wxString
& name
)
791 int i
= m_faceNames
.Index(name
);
797 /// Updates the font list
798 void wxRichTextFontListBox::UpdateFonts()
800 wxArrayString facenames
= wxRichTextCtrl::GetAvailableFontNames();
801 m_faceNames
= facenames
;
804 SetItemCount(m_faceNames
.GetCount());
809 // Convert a colour to a 6-digit hex string
810 static wxString
ColourToHexString(const wxColour
& col
)
814 hex
+= wxDecToHex(col
.Red());
815 hex
+= wxDecToHex(col
.Green());
816 hex
+= wxDecToHex(col
.Blue());
822 /// Creates a suitable HTML fragment for a definition
823 wxString
wxRichTextFontListBox::CreateHTML(const wxString
& facename
) const
825 wxString str
= wxT("<font");
827 str
<< wxT(" size=\"+2\"");;
829 if (!facename
.IsEmpty() && facename
!= _("(none)"))
830 str
<< wxT(" face=\"") << facename
<< wxT("\"");
832 if (def->GetStyle().GetTextColour().IsOk())
833 str << wxT(" color=\"#") << ColourToHexString(def->GetStyle().GetTextColour()) << wxT("\"");
838 bool hasBold
= false;
848 str
<< wxT("</font>");