Added wxRichTextCtrl superscript and subscript support (Knut Petter Lehre).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53106 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2008-04-10 14:05:44 +00:00
parent ffac5996ab
commit 30bf763039
6 changed files with 322 additions and 24 deletions

View File

@ -202,6 +202,12 @@ class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer;
// flag to InsertFragment and DeleteRange to indicate the appropriate mode.
#define wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE 0x10000000
/*!
* Default superscript/subscript font multiplication factor
*/
#define wxSCRIPT_MUL_FACTOR 1.5
/*!
* wxRichTextFontTable
* Manages quick access to a pool of fonts for rendering rich text

View File

@ -35,6 +35,7 @@ class wxRichTextFontPreviewCtrl;
////@begin control identifiers
#define SYMBOL_WXRICHTEXTFONTPAGE_STYLE wxTAB_TRAVERSAL
#define SYMBOL_WXRICHTEXTFONTPAGE_TITLE _("wxRichTextFontPage")
#define SYMBOL_WXRICHTEXTFONTPAGE_IDNAME ID_RICHTEXTFONTPAGE
#define SYMBOL_WXRICHTEXTFONTPAGE_SIZE wxSize(200, 100)
#define SYMBOL_WXRICHTEXTFONTPAGE_POSITION wxDefaultPosition
@ -102,6 +103,12 @@ public:
/// wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_CAPSCTRL
void OnCapsctrlClick( wxCommandEvent& event );
/// wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUPERSCRIPT
void OnRichtextfontpageSuperscriptClick( wxCommandEvent& event );
/// wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUBSCRIPT
void OnRichtextfontpageSubscriptClick( wxCommandEvent& event );
////@end wxRichTextFontPage event handler declarations
////@begin wxRichTextFontPage member function declarations
@ -127,6 +134,8 @@ public:
wxRichTextColourSwatchCtrl* m_colourCtrl;
wxCheckBox* m_strikethroughCtrl;
wxCheckBox* m_capitalsCtrl;
wxCheckBox* m_superscriptCtrl;
wxCheckBox* m_subscriptCtrl;
wxRichTextFontPreviewCtrl* m_previewCtrl;
/// Control identifiers
enum {
@ -141,6 +150,8 @@ public:
ID_RICHTEXTFONTPAGE_COLOURCTRL = 10009,
ID_RICHTEXTFONTPAGE_STRIKETHROUGHCTRL = 10010,
ID_RICHTEXTFONTPAGE_CAPSCTRL = 10011,
ID_RICHTEXTFONTPAGE_SUPERSCRIPT = 10012,
ID_RICHTEXTFONTPAGE_SUBSCRIPT = 10013,
ID_RICHTEXTFONTPAGE_PREVIEWCTRL = 10003
};
////@end wxRichTextFontPage member variables

View File

@ -4317,16 +4317,44 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR
long len = range.GetLength();
wxString stringChunk = str.Mid(range.GetStart() - offset, (size_t) len);
int charHeight = dc.GetCharHeight();
int x = rect.x;
int y = rect.y + (rect.height - charHeight - (descent - m_descent));
// Test for the optimized situations where all is selected, or none
// is selected.
wxFont font(GetBuffer()->GetFontTable().FindFont(textAttr));
wxCheckSetFont(dc, font);
wxFont textFont(GetBuffer()->GetFontTable().FindFont(textAttr));
wxCheckSetFont(dc, textFont);
int charHeight = dc.GetCharHeight();
int x, y;
if ( textFont.Ok() )
{
if ( textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT) )
{
double size = static_cast<double>(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR;
textFont.SetPointSize( static_cast<int>(size) );
x = rect.x;
y = rect.y;
wxCheckSetFont(dc, textFont);
}
else if ( textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT) )
{
double size = static_cast<double>(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR;
textFont.SetPointSize( static_cast<int>(size) );
x = rect.x;
int sub_height = static_cast<int>( static_cast<double>(charHeight) / wxSCRIPT_MUL_FACTOR);
y = rect.y + (rect.height - sub_height + (descent - m_descent));
wxCheckSetFont(dc, textFont);
}
else
{
x = rect.x;
y = rect.y + (rect.height - charHeight - (descent - m_descent));
}
}
else
{
x = rect.x;
y = rect.y + (rect.height - charHeight - (descent - m_descent));
}
// (a) All selected.
if (selectionRange.GetStart() <= range.GetStart() && selectionRange.GetEnd() >= range.GetEnd())
@ -4581,8 +4609,24 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz
// of line breaks - and we don't need it, since we'll calculate size within
// formatted text by doing it in chunks according to the line ranges
bool bScript(false);
wxFont font(GetBuffer()->GetFontTable().FindFont(textAttr));
wxCheckSetFont(dc, font);
if (font.Ok())
{
if ( textAttr.HasTextEffects() && ( (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT)
|| (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT) ) )
{
wxFont textFont = font;
double size = static_cast<double>(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR;
textFont.SetPointSize( static_cast<int>(size) );
wxCheckSetFont(dc, textFont);
bScript = true;
}
else
{
wxCheckSetFont(dc, font);
}
}
int startPos = range.GetStart() - GetRange().GetStart();
long len = range.GetLength();
@ -4650,8 +4694,13 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz
}
}
}
dc.GetTextExtent(stringChunk, & w, & h, & descent);
width += w;
if ( bScript )
dc.SetFont(font);
size = wxSize(width, dc.GetCharHeight());
return true;

View File

@ -136,6 +136,7 @@
<long name="locked">0</long>
<string name="template-name">""</string>
<bool name="dirty">1</bool>
<long name="makefile-last-written">-8519680</long>
<string name="Compiler name">""</string>
<string name="Build mode">"Debug"</string>
<string name="Unicode mode">"ANSI"</string>
@ -177,6 +178,8 @@
<string name="wxWidgets build command">"%AUTO%"</string>
<string name="wxWidgets clean command">"%AUTO%"</string>
<string name="PATH variable">"%AUTO%"</string>
<bool name="Suppress source rules">0</bool>
<bool name="Enable makefile generation">1</bool>
</document>
</document>
</data>
@ -248,7 +251,6 @@
<bool name="proxy-wxDEFAULT_DIALOG_STYLE">0</bool>
<bool name="proxy-wxCAPTION">0</bool>
<bool name="proxy-wxRESIZE_BORDER">0</bool>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<bool name="proxy-wxSYSTEM_MENU">0</bool>
<bool name="proxy-wxSTAY_ON_TOP">0</bool>
<bool name="proxy-wxDIALOG_NO_PARENT">0</bool>
@ -291,14 +293,6 @@
<string name="proxy-type">"wbBoxSizerProxy"</string>
<string name="proxy-Orientation">"Vertical"</string>
<string name="proxy-Member variable name">""</string>
<string name="proxy-AlignH">"Centre"</string>
<string name="proxy-AlignV">"Centre"</string>
<long name="proxy-Stretch factor">0</long>
<long name="proxy-Border">5</long>
<bool name="proxy-wxLEFT">1</bool>
<bool name="proxy-wxRIGHT">1</bool>
<bool name="proxy-wxTOP">1</bool>
<bool name="proxy-wxBOTTOM">1</bool>
<bool name="proxy-wxSHAPED">0</bool>
<bool name="proxy-wxADJUST_MINSIZE">0</bool>
<bool name="proxy-wxFIXED_MINSIZE">0</bool>
@ -1688,6 +1682,136 @@
<string name="proxy-Custom arguments">""</string>
<string name="proxy-Custom ctor arguments">""</string>
</document>
<document>
<string name="title">"wxCheckBox: ID_RICHTEXTFONTPAGE_SUPERSCRIPT"</string>
<string name="type">"dialog-control-document"</string>
<string name="filename">""</string>
<string name="icon-name">"checkbox"</string>
<long name="is-transient">0</long>
<long name="owns-file">1</long>
<long name="title-mode">0</long>
<long name="locked">0</long>
<string name="created">"10/4/2008"</string>
<string name="proxy-type">"wbCheckBoxProxy"</string>
<string name="event-handler-0">"wxEVT_COMMAND_CHECKBOX_CLICKED|OnRichtextfontpageSuperscriptClick|NONE||wxRichTextFontPage"</string>
<string name="proxy-Id name">"ID_RICHTEXTFONTPAGE_SUPERSCRIPT"</string>
<long name="proxy-Id value">10012</long>
<string name="proxy-Name">""</string>
<string name="proxy-Class">"wxCheckBox"</string>
<string name="proxy-Base class">"wxCheckBox"</string>
<bool name="proxy-External implementation">1</bool>
<bool name="proxy-Separate files">0</bool>
<string name="proxy-Implementation filename">""</string>
<string name="proxy-Header filename">""</string>
<string name="proxy-Member variable name">"m_superscriptCtrl"</string>
<string name="proxy-Label">"Supe&amp;rscript"</string>
<bool name="proxy-Initial value">0</bool>
<string name="proxy-Help text">"Check to show the text in superscript."</string>
<string name="proxy-Tooltip text">""</string>
<string name="proxy-Data variable">""</string>
<string name="proxy-Data validator">""</string>
<string name="proxy-Data source">""</string>
<string name="proxy-Data class name">""</string>
<string name="proxy-Data class implementation filename">""</string>
<string name="proxy-Data class header filename">""</string>
<string name="proxy-Data class manager window">""</string>
<string name="proxy-Background colour">""</string>
<string name="proxy-Foreground colour">""</string>
<string name="proxy-Font">""</string>
<bool name="proxy-Hidden">0</bool>
<bool name="proxy-Enabled">1</bool>
<string name="proxy-Platform">"&lt;Any platform&gt;"</string>
<bool name="proxy-wxALIGN_RIGHT">0</bool>
<bool name="proxy-wxCHK_2STATE">0</bool>
<bool name="proxy-wxCHK_3STATE">1</bool>
<bool name="proxy-wxCHK_ALLOW_3RD_STATE_FOR_USER">0</bool>
<bool name="proxy-wxWANTS_CHARS">0</bool>
<bool name="proxy-wxNO_FULL_REPAINT_ON_RESIZE">0</bool>
<bool name="proxy-wxFULL_REPAINT_ON_RESIZE">0</bool>
<string name="proxy-Custom styles">""</string>
<long name="proxy-X">-1</long>
<long name="proxy-Y">-1</long>
<long name="proxy-Width">-1</long>
<long name="proxy-Height">-1</long>
<string name="proxy-AlignH">"Centre"</string>
<string name="proxy-AlignV">"Centre"</string>
<long name="proxy-Stretch factor">0</long>
<long name="proxy-Border">5</long>
<bool name="proxy-wxLEFT">1</bool>
<bool name="proxy-wxRIGHT">1</bool>
<bool name="proxy-wxTOP">1</bool>
<bool name="proxy-wxBOTTOM">1</bool>
<bool name="proxy-wxSHAPED">0</bool>
<bool name="proxy-wxADJUST_MINSIZE">0</bool>
<bool name="proxy-wxFIXED_MINSIZE">0</bool>
<string name="proxy-Custom arguments">""</string>
<string name="proxy-Custom ctor arguments">""</string>
</document>
<document>
<string name="title">"wxCheckBox: ID_RICHTEXTFONTPAGE_SUBSCRIPT"</string>
<string name="type">"dialog-control-document"</string>
<string name="filename">""</string>
<string name="icon-name">"checkbox"</string>
<long name="is-transient">0</long>
<long name="owns-file">1</long>
<long name="title-mode">0</long>
<long name="locked">0</long>
<string name="created">"10/4/2008"</string>
<string name="proxy-type">"wbCheckBoxProxy"</string>
<string name="event-handler-0">"wxEVT_COMMAND_CHECKBOX_CLICKED|OnRichtextfontpageSubscriptClick|NONE||wxRichTextFontPage"</string>
<string name="proxy-Id name">"ID_RICHTEXTFONTPAGE_SUBSCRIPT"</string>
<long name="proxy-Id value">10013</long>
<string name="proxy-Name">""</string>
<string name="proxy-Class">"wxCheckBox"</string>
<string name="proxy-Base class">"wxCheckBox"</string>
<bool name="proxy-External implementation">1</bool>
<bool name="proxy-Separate files">0</bool>
<string name="proxy-Implementation filename">""</string>
<string name="proxy-Header filename">""</string>
<string name="proxy-Member variable name">"m_subscriptCtrl"</string>
<string name="proxy-Label">"Subscrip&amp;t"</string>
<bool name="proxy-Initial value">0</bool>
<string name="proxy-Help text">"Check to show the text in subscript."</string>
<string name="proxy-Tooltip text">""</string>
<string name="proxy-Data variable">""</string>
<string name="proxy-Data validator">""</string>
<string name="proxy-Data source">""</string>
<string name="proxy-Data class name">""</string>
<string name="proxy-Data class implementation filename">""</string>
<string name="proxy-Data class header filename">""</string>
<string name="proxy-Data class manager window">""</string>
<string name="proxy-Background colour">""</string>
<string name="proxy-Foreground colour">""</string>
<string name="proxy-Font">""</string>
<bool name="proxy-Hidden">0</bool>
<bool name="proxy-Enabled">1</bool>
<string name="proxy-Platform">"&lt;Any platform&gt;"</string>
<bool name="proxy-wxALIGN_RIGHT">0</bool>
<bool name="proxy-wxCHK_2STATE">0</bool>
<bool name="proxy-wxCHK_3STATE">1</bool>
<bool name="proxy-wxCHK_ALLOW_3RD_STATE_FOR_USER">0</bool>
<bool name="proxy-wxWANTS_CHARS">0</bool>
<bool name="proxy-wxNO_FULL_REPAINT_ON_RESIZE">0</bool>
<bool name="proxy-wxFULL_REPAINT_ON_RESIZE">0</bool>
<string name="proxy-Custom styles">""</string>
<long name="proxy-X">-1</long>
<long name="proxy-Y">-1</long>
<long name="proxy-Width">-1</long>
<long name="proxy-Height">-1</long>
<string name="proxy-AlignH">"Centre"</string>
<string name="proxy-AlignV">"Centre"</string>
<long name="proxy-Stretch factor">0</long>
<long name="proxy-Border">5</long>
<bool name="proxy-wxLEFT">1</bool>
<bool name="proxy-wxRIGHT">1</bool>
<bool name="proxy-wxTOP">1</bool>
<bool name="proxy-wxBOTTOM">1</bool>
<bool name="proxy-wxSHAPED">0</bool>
<bool name="proxy-wxADJUST_MINSIZE">0</bool>
<bool name="proxy-wxFIXED_MINSIZE">0</bool>
<string name="proxy-Custom arguments">""</string>
<string name="proxy-Custom ctor arguments">""</string>
</document>
</document>
<document>
<string name="title">"Spacer"</string>
@ -1836,7 +1960,6 @@
<bool name="proxy-wxDEFAULT_DIALOG_STYLE">0</bool>
<bool name="proxy-wxCAPTION">0</bool>
<bool name="proxy-wxRESIZE_BORDER">1</bool>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<bool name="proxy-wxSYSTEM_MENU">0</bool>
<bool name="proxy-wxSTAY_ON_TOP">0</bool>
<bool name="proxy-wxDIALOG_NO_PARENT">0</bool>
@ -1867,6 +1990,7 @@
<long name="proxy-Height">300</long>
<bool name="proxy-AUI manager">0</bool>
<string name="proxy-Event sources">""</string>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<document>
<string name="title">"wxBoxSizer V"</string>
<string name="type">"dialog-control-document"</string>
@ -4347,7 +4471,6 @@
<bool name="proxy-wxDEFAULT_DIALOG_STYLE">0</bool>
<bool name="proxy-wxCAPTION">0</bool>
<bool name="proxy-wxRESIZE_BORDER">1</bool>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<bool name="proxy-wxSYSTEM_MENU">0</bool>
<bool name="proxy-wxSTAY_ON_TOP">0</bool>
<bool name="proxy-wxDIALOG_NO_PARENT">0</bool>
@ -4378,6 +4501,7 @@
<long name="proxy-Height">300</long>
<bool name="proxy-AUI manager">0</bool>
<string name="proxy-Event sources">""</string>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<document>
<string name="title">"wxBoxSizer V"</string>
<string name="type">"dialog-control-document"</string>
@ -5084,7 +5208,6 @@
<bool name="proxy-wxDEFAULT_DIALOG_STYLE">0</bool>
<bool name="proxy-wxCAPTION">0</bool>
<bool name="proxy-wxRESIZE_BORDER">1</bool>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<bool name="proxy-wxSYSTEM_MENU">0</bool>
<bool name="proxy-wxSTAY_ON_TOP">0</bool>
<bool name="proxy-wxDIALOG_NO_PARENT">0</bool>
@ -5115,6 +5238,7 @@
<long name="proxy-Height">300</long>
<bool name="proxy-AUI manager">0</bool>
<string name="proxy-Event sources">""</string>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<document>
<string name="title">"wxBoxSizer V"</string>
<string name="type">"dialog-control-document"</string>
@ -6757,7 +6881,6 @@
<bool name="proxy-wxDEFAULT_DIALOG_STYLE">0</bool>
<bool name="proxy-wxCAPTION">0</bool>
<bool name="proxy-wxRESIZE_BORDER">1</bool>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<bool name="proxy-wxSYSTEM_MENU">0</bool>
<bool name="proxy-wxSTAY_ON_TOP">0</bool>
<bool name="proxy-wxDIALOG_NO_PARENT">0</bool>
@ -6788,6 +6911,7 @@
<long name="proxy-Height">300</long>
<bool name="proxy-AUI manager">0</bool>
<string name="proxy-Event sources">""</string>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<document>
<string name="title">"wxBoxSizer V"</string>
<string name="type">"dialog-control-document"</string>
@ -7393,7 +7517,6 @@
<bool name="proxy-wxDEFAULT_DIALOG_STYLE">1</bool>
<bool name="proxy-wxCAPTION">0</bool>
<bool name="proxy-wxRESIZE_BORDER">1</bool>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<bool name="proxy-wxSYSTEM_MENU">0</bool>
<bool name="proxy-wxSTAY_ON_TOP">0</bool>
<bool name="proxy-wxDIALOG_NO_PARENT">0</bool>
@ -7424,6 +7547,7 @@
<long name="proxy-Height">300</long>
<bool name="proxy-AUI manager">0</bool>
<string name="proxy-Event sources">""</string>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<document>
<string name="title">"wxBoxSizer V"</string>
<string name="type">"dialog-control-document"</string>
@ -7437,6 +7561,14 @@
<string name="proxy-type">"wbBoxSizerProxy"</string>
<string name="proxy-Orientation">"Vertical"</string>
<string name="proxy-Member variable name">""</string>
<string name="proxy-AlignH">"Centre"</string>
<string name="proxy-AlignV">"Centre"</string>
<long name="proxy-Stretch factor">0</long>
<long name="proxy-Border">5</long>
<bool name="proxy-wxLEFT">1</bool>
<bool name="proxy-wxRIGHT">1</bool>
<bool name="proxy-wxTOP">1</bool>
<bool name="proxy-wxBOTTOM">1</bool>
<bool name="proxy-wxSHAPED">0</bool>
<bool name="proxy-wxADJUST_MINSIZE">0</bool>
<bool name="proxy-wxFIXED_MINSIZE">0</bool>
@ -8589,7 +8721,6 @@
<bool name="proxy-wxDEFAULT_DIALOG_STYLE">1</bool>
<bool name="proxy-wxCAPTION">0</bool>
<bool name="proxy-wxRESIZE_BORDER">1</bool>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<bool name="proxy-wxSYSTEM_MENU">1</bool>
<bool name="proxy-wxSTAY_ON_TOP">0</bool>
<bool name="proxy-wxDIALOG_NO_PARENT">0</bool>
@ -8620,6 +8751,7 @@
<long name="proxy-Height">300</long>
<bool name="proxy-AUI manager">0</bool>
<string name="proxy-Event sources">""</string>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<document>
<string name="title">"wxBoxSizer V"</string>
<string name="type">"dialog-control-document"</string>
@ -10016,7 +10148,6 @@
<bool name="proxy-wxDEFAULT_DIALOG_STYLE">0</bool>
<bool name="proxy-wxCAPTION">0</bool>
<bool name="proxy-wxRESIZE_BORDER">1</bool>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<bool name="proxy-wxSYSTEM_MENU">0</bool>
<bool name="proxy-wxSTAY_ON_TOP">0</bool>
<bool name="proxy-wxDIALOG_NO_PARENT">0</bool>
@ -10047,6 +10178,7 @@
<long name="proxy-Height">300</long>
<bool name="proxy-AUI manager">0</bool>
<string name="proxy-Event sources">""</string>
<bool name="proxy-wxTHICK_FRAME">0</bool>
<document>
<string name="title">"wxBoxSizer V"</string>
<string name="type">"dialog-control-document"</string>

View File

@ -42,6 +42,10 @@ BEGIN_EVENT_TABLE( wxRichTextFontPage, wxPanel )
EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_CAPSCTRL, wxRichTextFontPage::OnCapsctrlClick )
EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_SUPERSCRIPT, wxRichTextFontPage::OnRichtextfontpageSuperscriptClick )
EVT_CHECKBOX( ID_RICHTEXTFONTPAGE_SUBSCRIPT, wxRichTextFontPage::OnRichtextfontpageSubscriptClick )
////@end wxRichTextFontPage event table entries
END_EVENT_TABLE()
@ -81,6 +85,8 @@ void wxRichTextFontPage::Init()
m_colourCtrl = NULL;
m_strikethroughCtrl = NULL;
m_capitalsCtrl = NULL;
m_superscriptCtrl = NULL;
m_subscriptCtrl = NULL;
m_previewCtrl = NULL;
////@end wxRichTextFontPage member initialisation
}
@ -230,6 +236,20 @@ void wxRichTextFontPage::CreateControls()
m_capitalsCtrl->SetToolTip(_("Check to show the text in capitals."));
itemBoxSizer26->Add(m_capitalsCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
m_superscriptCtrl = new wxCheckBox( itemPanel1, ID_RICHTEXTFONTPAGE_SUPERSCRIPT, _("Supe&rscript"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE );
m_superscriptCtrl->SetValue(false);
m_superscriptCtrl->SetHelpText(_("Check to show the text in superscript."));
if (wxRichTextFontPage::ShowToolTips())
m_superscriptCtrl->SetToolTip(_("Check to show the text in superscript."));
itemBoxSizer26->Add(m_superscriptCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
m_subscriptCtrl = new wxCheckBox( itemPanel1, ID_RICHTEXTFONTPAGE_SUBSCRIPT, _("Subscrip&t"), wxDefaultPosition, wxDefaultSize, wxCHK_3STATE );
m_subscriptCtrl->SetValue(false);
m_subscriptCtrl->SetHelpText(_("Check to show the text in subscript."));
if (wxRichTextFontPage::ShowToolTips())
m_subscriptCtrl->SetToolTip(_("Check to show the text in subscript."));
itemBoxSizer26->Add(m_subscriptCtrl, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL, 5);
m_previewCtrl = new wxRichTextFontPreviewCtrl( itemPanel1, ID_RICHTEXTFONTPAGE_PREVIEWCTRL, wxDefaultPosition, wxSize(100, 60), 0 );
@ -358,6 +378,24 @@ bool wxRichTextFontPage::TransferDataFromWindow()
attr->SetTextEffects(attr->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_CAPITALS);
}
if (m_superscriptCtrl->Get3StateValue() == wxCHK_CHECKED)
{
attr->SetTextEffectFlags(attr->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_SUPERSCRIPT);
attr->SetTextEffects(attr->GetTextEffects() | wxTEXT_ATTR_EFFECT_SUPERSCRIPT);
attr->SetTextEffects(attr->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_SUBSCRIPT);
}
else if (m_subscriptCtrl->Get3StateValue() == wxCHK_CHECKED)
{
attr->SetTextEffectFlags(attr->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_SUBSCRIPT);
attr->SetTextEffects(attr->GetTextEffects() | wxTEXT_ATTR_EFFECT_SUBSCRIPT);
attr->SetTextEffects(attr->GetTextEffects() & ~wxTEXT_ATTR_EFFECT_SUPERSCRIPT);
}
else
{
attr->SetTextEffectFlags(attr->GetTextEffectFlags() | wxTEXT_ATTR_EFFECT_SUBSCRIPT | wxTEXT_ATTR_EFFECT_SUPERSCRIPT );
attr->SetTextEffects(attr->GetTextEffects() & ~( wxTEXT_ATTR_EFFECT_SUPERSCRIPT | wxTEXT_ATTR_EFFECT_SUBSCRIPT));
}
return true;
}
@ -455,11 +493,37 @@ bool wxRichTextFontPage::TransferDataToWindow()
}
else
m_capitalsCtrl->Set3StateValue(wxCHK_UNDETERMINED);
if ( attr->GetTextEffectFlags() & (wxTEXT_ATTR_EFFECT_SUPERSCRIPT | wxTEXT_ATTR_EFFECT_SUBSCRIPT) )
{
if (attr->GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT)
{
m_superscriptCtrl->Set3StateValue(wxCHK_CHECKED);
m_subscriptCtrl->Set3StateValue(wxCHK_UNCHECKED);
}
else if (attr->GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT)
{
m_superscriptCtrl->Set3StateValue(wxCHK_UNCHECKED);
m_subscriptCtrl->Set3StateValue(wxCHK_CHECKED);
}
else
{
m_superscriptCtrl->Set3StateValue(wxCHK_UNCHECKED);
m_subscriptCtrl->Set3StateValue(wxCHK_UNCHECKED);
}
}
else
{
m_superscriptCtrl->Set3StateValue(wxCHK_UNCHECKED);
m_subscriptCtrl->Set3StateValue(wxCHK_UNCHECKED);
}
}
else
{
m_strikethroughCtrl->Set3StateValue(wxCHK_UNDETERMINED);
m_capitalsCtrl->Set3StateValue(wxCHK_UNDETERMINED);
m_superscriptCtrl->Set3StateValue(wxCHK_UNCHECKED);
m_subscriptCtrl->Set3StateValue(wxCHK_UNCHECKED);
}
UpdatePreview();
@ -541,6 +605,11 @@ void wxRichTextFontPage::UpdatePreview()
textEffects |= wxTEXT_ATTR_EFFECT_CAPITALS;
}
if ( m_superscriptCtrl->Get3StateValue() == wxCHK_CHECKED )
textEffects |= wxTEXT_ATTR_EFFECT_SUPERSCRIPT;
else if ( m_subscriptCtrl->Get3StateValue() == wxCHK_CHECKED )
textEffects |= wxTEXT_ATTR_EFFECT_SUBSCRIPT;
m_previewCtrl->SetFont(font);
m_previewCtrl->SetTextEffects(textEffects);
m_previewCtrl->Refresh();
@ -715,4 +784,24 @@ void wxRichTextFontPage::OnCapsctrlClick( wxCommandEvent& WXUNUSED(event) )
UpdatePreview();
}
/*!
* wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUPERSCRIPT
*/
void wxRichTextFontPage::OnRichtextfontpageSuperscriptClick( wxCommandEvent& WXUNUSED(event) )
{
if ( m_superscriptCtrl->Get3StateValue() == wxCHK_CHECKED && m_subscriptCtrl->Get3StateValue() == wxCHK_CHECKED )
m_subscriptCtrl->Set3StateValue( wxCHK_UNCHECKED );
UpdatePreview();
}
/*!
* wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_RICHTEXTFONTPAGE_SUBSCRIPT
*/
void wxRichTextFontPage::OnRichtextfontpageSubscriptClick( wxCommandEvent& WXUNUSED(event) )
{
if ( m_superscriptCtrl->Get3StateValue() == wxCHK_CHECKED && m_subscriptCtrl->Get3StateValue() == wxCHK_CHECKED )
m_superscriptCtrl->Set3StateValue( wxCHK_UNCHECKED );
UpdatePreview();
}

View File

@ -411,6 +411,12 @@ void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
wxSize size = GetSize();
wxFont font = GetFont();
if ((GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT) || (GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT))
{
double size = static_cast<double>(font.GetPointSize()) / wxSCRIPT_MUL_FACTOR;
font.SetPointSize( static_cast<int>(size) );
}
if ( font.Ok() )
{
dc.SetFont(font);
@ -425,6 +431,11 @@ void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
int cx = wxMax(2, (size.x/2) - (w/2));
int cy = wxMax(2, (size.y/2) - (h/2));
if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT )
cy -= h/2;
if ( GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT )
cy += h/2;
dc.SetTextForeground(GetForegroundColour());
dc.SetClippingRegion(2, 2, size.x-4, size.y-4);
dc.DrawText(text, cx, cy);