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
* ctrl
, int WXUNUSED(flags
))
148 ctrl
->SetStyle(GetObject(), m_attributes
);
155 /// Set the attributes and optionally update the display
156 bool wxRichTextFormattingDialog::SetStyle(const wxRichTextAttr
& style
, bool update
)
158 m_attributes
= style
;
164 /// Set the style definition and optionally update the display
165 bool wxRichTextFormattingDialog::SetStyleDefinition(const wxRichTextStyleDefinition
& styleDef
, wxRichTextStyleSheet
* sheet
, bool update
)
167 m_styleSheet
= sheet
;
169 if (m_styleDefinition
)
170 delete m_styleDefinition
;
171 m_styleDefinition
= styleDef
.Clone();
173 return SetStyle(m_styleDefinition
->GetStyle(), update
);
176 /// Transfers the data and from to the window
177 bool wxRichTextFormattingDialog::TransferDataToWindow()
179 if (m_styleDefinition
)
180 m_attributes
= m_styleDefinition
->GetStyle();
182 if (!wxPropertySheetDialog::TransferDataToWindow())
188 bool wxRichTextFormattingDialog::TransferDataFromWindow()
190 if (!wxPropertySheetDialog::TransferDataFromWindow())
193 if (m_styleDefinition
)
194 m_styleDefinition
->GetStyle() = m_attributes
;
199 /// Update the display
200 bool wxRichTextFormattingDialog::UpdateDisplay()
202 return TransferDataToWindow();
205 /// Apply the styles when a different tab is selected, so the previews are
207 void wxRichTextFormattingDialog::OnTabChanged(wxBookCtrlEvent
& event
)
209 if (GetBookCtrl() != event
.GetEventObject())
215 int oldPageId
= event
.GetOldSelection();
218 wxWindow
* page
= GetBookCtrl()->GetPage(oldPageId
);
220 page
->TransferDataFromWindow();
223 int pageId
= event
.GetSelection();
226 wxWindow
* page
= GetBookCtrl()->GetPage(pageId
);
228 page
->TransferDataToWindow();
232 /// Respond to help command
233 void wxRichTextFormattingDialog::OnHelp(wxCommandEvent
& event
)
235 int selPage
= GetBookCtrl()->GetSelection();
236 if (selPage
!= wxNOT_FOUND
)
239 if (selPage
< (int) m_pageIds
.GetCount())
240 pageId
= m_pageIds
[selPage
];
241 if (!GetFormattingDialogFactory()->ShowHelp(pageId
, this))
246 void wxRichTextFormattingDialog::OnUpdateHelp(wxUpdateUIEvent
& event
)
251 void wxRichTextFormattingDialog::SetFormattingDialogFactory(wxRichTextFormattingDialogFactory
* factory
)
253 if (ms_FormattingDialogFactory
)
254 delete ms_FormattingDialogFactory
;
255 ms_FormattingDialogFactory
= factory
;
258 // Find a page by class
259 wxWindow
* wxRichTextFormattingDialog::FindPage(wxClassInfo
* info
) const
262 for (i
= 0; i
< GetBookCtrl()->GetPageCount(); i
++)
264 wxWindow
* w
= GetBookCtrl()->GetPage(i
);
265 if (w
&& w
->GetClassInfo() == info
)
273 * Factory for formatting dialog
276 /// Create all pages, under the dialog's book control, also calling AddPage
277 bool wxRichTextFormattingDialogFactory::CreatePages(long pages
, wxRichTextFormattingDialog
* dialog
)
279 if (dialog
->GetImageList())
280 dialog
->GetBookCtrl()->SetImageList(dialog
->GetImageList());
282 int availablePageCount
= GetPageIdCount();
284 bool selected
= false;
285 for (i
= 0; i
< availablePageCount
; i
++)
287 int pageId
= GetPageId(i
);
288 if (pageId
!= -1 && (pages
& pageId
))
291 wxPanel
* panel
= CreatePage(pageId
, title
, dialog
);
292 wxASSERT( panel
!= NULL
);
295 int imageIndex
= GetPageImage(pageId
);
296 dialog
->GetBookCtrl()->AddPage(panel
, title
, !selected
, imageIndex
);
299 dialog
->AddPageId(pageId
);
307 /// Create a page, given a page identifier
308 wxPanel
* wxRichTextFormattingDialogFactory::CreatePage(int page
, wxString
& title
, wxRichTextFormattingDialog
* dialog
)
310 if (page
== wxRICHTEXT_FORMAT_STYLE_EDITOR
)
312 wxRichTextStylePage
* page
= new wxRichTextStylePage(dialog
->GetBookCtrl(), wxID_ANY
);
316 else if (page
== wxRICHTEXT_FORMAT_FONT
)
318 wxRichTextFontPage
* page
= new wxRichTextFontPage(dialog
->GetBookCtrl(), wxID_ANY
);
322 else if (page
== wxRICHTEXT_FORMAT_INDENTS_SPACING
)
324 wxRichTextIndentsSpacingPage
* page
= new wxRichTextIndentsSpacingPage(dialog
->GetBookCtrl(), wxID_ANY
);
325 title
= _("Indents && Spacing");
328 else if (page
== wxRICHTEXT_FORMAT_TABS
)
330 wxRichTextTabsPage
* page
= new wxRichTextTabsPage(dialog
->GetBookCtrl(), wxID_ANY
);
334 else if (page
== wxRICHTEXT_FORMAT_BULLETS
)
336 wxRichTextBulletsPage
* page
= new wxRichTextBulletsPage(dialog
->GetBookCtrl(), wxID_ANY
);
337 title
= _("Bullets");
341 else if (page
== wxRICHTEXT_FORMAT_LIST_STYLE
)
343 wxRichTextListStylePage
* page
= new wxRichTextListStylePage(dialog
->GetBookCtrl(), wxID_ANY
);
344 title
= _("List Style");
348 else if (page
== wxRICHTEXT_FORMAT_SIZE
)
350 wxRichTextSizePage
* page
= new wxRichTextSizePage(dialog
->GetBookCtrl(), wxID_ANY
);
354 else if (page
== wxRICHTEXT_FORMAT_MARGINS
)
356 wxRichTextMarginsPage
* page
= new wxRichTextMarginsPage(dialog
->GetBookCtrl(), wxID_ANY
);
357 title
= _("Margins");
360 else if (page
== wxRICHTEXT_FORMAT_BORDERS
)
362 wxRichTextBordersPage
* page
= new wxRichTextBordersPage(dialog
->GetBookCtrl(), wxID_ANY
);
363 title
= _("Borders");
366 else if (page
== wxRICHTEXT_FORMAT_BACKGROUND
)
368 wxRichTextBackgroundPage
* page
= new wxRichTextBackgroundPage(dialog
->GetBookCtrl(), wxID_ANY
);
369 title
= _("Background");
376 /// Enumerate all available page identifiers
377 int wxRichTextFormattingDialogFactory::GetPageId(int i
) const
380 wxRICHTEXT_FORMAT_STYLE_EDITOR
,
381 wxRICHTEXT_FORMAT_FONT
,
382 wxRICHTEXT_FORMAT_INDENTS_SPACING
,
383 wxRICHTEXT_FORMAT_BULLETS
,
384 wxRICHTEXT_FORMAT_TABS
,
385 wxRICHTEXT_FORMAT_LIST_STYLE
,
386 wxRICHTEXT_FORMAT_SIZE
,
387 wxRICHTEXT_FORMAT_MARGINS
,
388 wxRICHTEXT_FORMAT_BORDERS
,
389 wxRICHTEXT_FORMAT_BACKGROUND
392 if (i
< 0 || i
>= GetPageIdCount())
398 /// Get the number of available page identifiers
399 int wxRichTextFormattingDialogFactory::GetPageIdCount() const
408 /// Set the sheet style, called at the start of wxRichTextFormattingDialog::Create
409 bool wxRichTextFormattingDialogFactory::SetSheetStyle(wxRichTextFormattingDialog
* dialog
)
411 #if wxRICHTEXT_USE_TOOLBOOK
412 int sheetStyle
= wxPROPSHEET_SHRINKTOFIT
;
414 sheetStyle
|= wxPROPSHEET_BUTTONTOOLBOOK
;
416 sheetStyle
|= wxPROPSHEET_TOOLBOOK
;
419 dialog
->SetSheetStyle(sheetStyle
);
420 dialog
->SetSheetInnerBorder(0);
421 dialog
->SetSheetOuterBorder(0);
424 #endif // wxRICHTEXT_USE_TOOLBOOK
429 /// Create the main dialog buttons
430 bool wxRichTextFormattingDialogFactory::CreateButtons(wxRichTextFormattingDialog
* dialog
)
432 int flags
= wxOK
|wxCANCEL
;
434 if (dialog
->GetWindowStyleFlag() & wxRICHTEXT_FORMAT_HELP_BUTTON
)
438 // If using a toolbook, also follow Mac style and don't create buttons
439 #if !wxRICHTEXT_USE_TOOLBOOK
440 dialog
->CreateButtons(flags
);
446 // Invoke help for the dialog
447 bool wxRichTextFormattingDialogFactory::ShowHelp(int WXUNUSED(page
), wxRichTextFormattingDialog
* dialog
)
449 wxRichTextDialogPage
* window
= NULL
;
450 int sel
= dialog
->GetBookCtrl()->GetSelection();
452 window
= wxDynamicCast(dialog
->GetBookCtrl()->GetPage(sel
), wxRichTextDialogPage
);
453 if (window
&& window
->GetHelpId() != -1)
455 if (window
->GetUICustomization())
456 return window
->GetUICustomization()->ShowHelp(dialog
, window
->GetHelpId());
457 else if (dialog
->GetUICustomization())
458 return dialog
->GetUICustomization()->ShowHelp(dialog
, window
->GetHelpId());
462 else if (dialog
->GetHelpId() != -1 && dialog
->GetUICustomization())
463 return dialog
->ShowHelp(dialog
);
469 * Module to initialise and clean up handlers
472 class wxRichTextFormattingDialogModule
: public wxModule
474 DECLARE_DYNAMIC_CLASS(wxRichTextFormattingDialogModule
)
476 wxRichTextFormattingDialogModule() {}
477 bool OnInit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(new wxRichTextFormattingDialogFactory
); return true; }
478 void OnExit() { wxRichTextFormattingDialog::SetFormattingDialogFactory(NULL
); }
481 IMPLEMENT_DYNAMIC_CLASS(wxRichTextFormattingDialogModule
, wxModule
)
484 * Font preview control
487 BEGIN_EVENT_TABLE(wxRichTextFontPreviewCtrl
, wxWindow
)
488 EVT_PAINT(wxRichTextFontPreviewCtrl::OnPaint
)
491 wxRichTextFontPreviewCtrl::wxRichTextFontPreviewCtrl(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& sz
, long style
)
493 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
494 style
|= wxBORDER_THEME
;
496 wxWindow::Create(parent
, id
, pos
, sz
, style
);
498 SetBackgroundColour(*wxWHITE
);
502 void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent
& WXUNUSED(event
))
506 wxSize size
= GetSize();
507 wxFont font
= GetFont();
509 if ((GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
) || (GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
))
511 double size
= static_cast<double>(font
.GetPointSize()) / wxSCRIPT_MUL_FACTOR
;
512 font
.SetPointSize( static_cast<int>(size
) );
518 // Calculate vertical and horizontal centre
519 wxCoord w
= 0, h
= 0;
521 wxString
text(_("ABCDEFGabcdefg12345"));
522 if (GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS
)
525 dc
.GetTextExtent( text
, &w
, &h
);
526 int cx
= wxMax(2, (size
.x
/2) - (w
/2));
527 int cy
= wxMax(2, (size
.y
/2) - (h
/2));
529 if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT
)
531 if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT
)
534 dc
.SetTextForeground(GetForegroundColour());
535 dc
.SetClippingRegion(2, 2, size
.x
-4, size
.y
-4);
536 dc
.DrawText(text
, cx
, cy
);
538 if (GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH
)
540 dc
.SetPen(wxPen(GetForegroundColour(), 1));
541 dc
.DrawLine(cx
, (int) (cy
+ h
/2 + 0.5), cx
+ w
, (int) (cy
+ h
/2 + 0.5));
544 dc
.DestroyClippingRegion();
548 // Helper for pages to get the top-level dialog
549 wxRichTextFormattingDialog
* wxRichTextFormattingDialog::GetDialog(wxWindow
* win
)
551 wxWindow
* p
= win
->GetParent();
552 while (p
&& !p
->IsKindOf(CLASSINFO(wxRichTextFormattingDialog
)))
554 wxRichTextFormattingDialog
* dialog
= wxDynamicCast(p
, wxRichTextFormattingDialog
);
558 // Helper for pages to get the attributes
559 wxRichTextAttr
* wxRichTextFormattingDialog::GetDialogAttributes(wxWindow
* win
)
561 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
563 return & dialog
->GetAttributes();
569 // Helper for pages to get the attributes to reset
570 wxRichTextAttr
* wxRichTextFormattingDialog::GetDialogResetAttributes(wxWindow
* win
)
572 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
574 return & dialog
->GetResetAttributes();
580 // Helper for pages to get the style
581 wxRichTextStyleDefinition
* wxRichTextFormattingDialog::GetDialogStyleDefinition(wxWindow
* win
)
583 wxRichTextFormattingDialog
* dialog
= GetDialog(win
);
585 return dialog
->GetStyleDefinition();
590 void wxRichTextFormattingDialog::SetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
)
596 checkBox
->SetValue(false);
597 valueCtrl
->SetValue(wxT("0"));
598 unitsCtrl
->SetSelection(0);
601 dim
.SetUnits(wxTEXT_ATTR_UNITS_PIXELS
);
606 checkBox
->SetValue(true);
607 if (dim
.GetUnits() == wxTEXT_ATTR_UNITS_TENTHS_MM
)
610 float value
= float(dim
.GetValue()) / 100.0;
611 valueCtrl
->SetValue(wxString::Format(wxT("%.2f"), value
));
613 else if (dim
.GetUnits() == wxTEXT_ATTR_UNITS_PERCENTAGE
)
616 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
621 valueCtrl
->SetValue(wxString::Format(wxT("%d"), (int) dim
.GetValue()));
624 unitsCtrl
->SetSelection(unitsIdx
);
628 void wxRichTextFormattingDialog::GetDimensionValue(wxTextAttrDimension
& dim
, wxTextCtrl
* valueCtrl
, wxComboBox
* unitsCtrl
, wxCheckBox
* checkBox
)
630 if (!checkBox
->GetValue())
636 if (unitsCtrl
->GetSelection() == 1)
637 dim
.SetUnits(wxTEXT_ATTR_UNITS_TENTHS_MM
);
638 else if (unitsCtrl
->GetSelection() == 2)
639 dim
.SetUnits(wxTEXT_ATTR_UNITS_PERCENTAGE
);
641 dim
.SetUnits(wxTEXT_ATTR_UNITS_PIXELS
);
644 if (ConvertFromString(valueCtrl
->GetValue(), value
, dim
.GetUnits()))
649 bool wxRichTextFormattingDialog::ConvertFromString(const wxString
& string
, int& ret
, int scale
)
651 const wxChar
* chars
= string
.GetData();
656 for (unsigned int i
= 0; i
< string
.Len() && remain
; i
++)
658 if (!(chars
[i
] >= wxT('0') && chars
[i
] <= wxT('9')) && !(scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
&& chars
[i
] == wxT('.')))
661 if (chars
[i
] == wxT('.'))
670 ret
= ret
* 10 + chars
[i
] - wxT('0');
673 while (remain
-- > 0 && scale
== wxTEXT_ATTR_UNITS_TENTHS_MM
)
680 * A control for displaying a small preview of a colour or bitmap
683 BEGIN_EVENT_TABLE(wxRichTextColourSwatchCtrl
, wxControl
)
684 EVT_MOUSE_EVENTS(wxRichTextColourSwatchCtrl::OnMouseEvent
)
687 IMPLEMENT_CLASS(wxRichTextColourSwatchCtrl
, wxControl
)
689 wxRichTextColourSwatchCtrl::wxRichTextColourSwatchCtrl(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
691 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
692 style
|= wxBORDER_THEME
;
694 wxControl::Create(parent
, id
, pos
, size
, style
);
696 SetColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
699 wxRichTextColourSwatchCtrl::~wxRichTextColourSwatchCtrl()
703 void wxRichTextColourSwatchCtrl::OnMouseEvent(wxMouseEvent
& event
)
705 if (event
.LeftDown())
707 wxWindow
* parent
= GetParent();
708 while (parent
!= NULL
&& !parent
->IsKindOf(CLASSINFO(wxDialog
)) && !parent
->IsKindOf(CLASSINFO(wxFrame
)))
709 parent
= parent
->GetParent();
712 data
.SetChooseFull(true);
713 data
.SetColour(m_colour
);
715 wxColourDialog
*dialog
= new wxColourDialog(parent
, &data
);
716 // Crashes on wxMac (no m_peer)
718 dialog
->SetTitle(_("Colour"));
720 if (dialog
->ShowModal() == wxID_OK
)
722 wxColourData retData
= dialog
->GetColourData();
723 m_colour
= retData
.GetColour();
724 SetBackgroundColour(m_colour
);
727 #endif // wxUSE_COLOURDLG
730 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, GetId());
731 GetEventHandler()->ProcessEvent(event
);
738 * wxRichTextFontListBox class declaration
739 * A listbox to display styles.
742 IMPLEMENT_CLASS(wxRichTextFontListBox
, wxHtmlListBox
)
744 BEGIN_EVENT_TABLE(wxRichTextFontListBox
, wxHtmlListBox
)
747 wxRichTextFontListBox::wxRichTextFontListBox(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
748 const wxSize
& size
, long style
)
751 Create(parent
, id
, pos
, size
, style
);
754 bool wxRichTextFontListBox::Create(wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
755 const wxSize
& size
, long style
)
757 if ((style
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
758 style
|= wxBORDER_THEME
;
760 return wxHtmlListBox::Create(parent
, id
, pos
, size
, style
);
763 wxRichTextFontListBox::~wxRichTextFontListBox()
767 /// Returns the HTML for this item
768 wxString
wxRichTextFontListBox::OnGetItem(size_t n
) const
770 if (m_faceNames
.GetCount() == 0)
771 return wxEmptyString
;
773 wxString str
= CreateHTML(m_faceNames
[n
]);
777 /// Get font name for index
778 wxString
wxRichTextFontListBox::GetFaceName(size_t i
) const
780 return m_faceNames
[i
];
783 /// Set selection for string, returning the index.
784 int wxRichTextFontListBox::SetFaceNameSelection(const wxString
& name
)
786 int i
= m_faceNames
.Index(name
);
792 /// Updates the font list
793 void wxRichTextFontListBox::UpdateFonts()
795 wxArrayString facenames
= wxRichTextCtrl::GetAvailableFontNames();
796 m_faceNames
= facenames
;
799 SetItemCount(m_faceNames
.GetCount());
804 // Convert a colour to a 6-digit hex string
805 static wxString
ColourToHexString(const wxColour
& col
)
809 hex
+= wxDecToHex(col
.Red());
810 hex
+= wxDecToHex(col
.Green());
811 hex
+= wxDecToHex(col
.Blue());
817 /// Creates a suitable HTML fragment for a definition
818 wxString
wxRichTextFontListBox::CreateHTML(const wxString
& facename
) const
820 wxString str
= wxT("<font");
822 str
<< wxT(" size=\"+2\"");;
824 if (!facename
.IsEmpty() && facename
!= _("(none)"))
825 str
<< wxT(" face=\"") << facename
<< wxT("\"");
827 if (def->GetStyle().GetTextColour().IsOk())
828 str << wxT(" color=\"#") << ColourToHexString(def->GetStyle().GetTextColour()) << wxT("\"");
833 bool hasBold
= false;
843 str
<< wxT("</font>");