Add markup support to generic wxStaticText implementation.
wxMarkupText allows to easily support markup in the controls that we draw ourselves so use it in wxGenericStaticText to have a possibility to use markup on all platforms, even those where there is no native markup support in wxStaticText itself. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67067 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
class WXDLLIMPEXP_CORE wxGenericStaticText : public wxStaticTextBase
|
class WXDLLIMPEXP_CORE wxGenericStaticText : public wxStaticTextBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxGenericStaticText() { }
|
wxGenericStaticText() { Init(); }
|
||||||
|
|
||||||
wxGenericStaticText(wxWindow *parent,
|
wxGenericStaticText(wxWindow *parent,
|
||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
@@ -32,6 +32,8 @@ public:
|
|||||||
long style = 0,
|
long style = 0,
|
||||||
const wxString& name = wxStaticTextNameStr)
|
const wxString& name = wxStaticTextNameStr)
|
||||||
{
|
{
|
||||||
|
Init();
|
||||||
|
|
||||||
Create(parent, id, label, pos, size, style, name);
|
Create(parent, id, label, pos, size, style, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +45,8 @@ public:
|
|||||||
long style = 0,
|
long style = 0,
|
||||||
const wxString& name = wxStaticTextNameStr);
|
const wxString& name = wxStaticTextNameStr);
|
||||||
|
|
||||||
|
virtual ~wxGenericStaticText();
|
||||||
|
|
||||||
|
|
||||||
// overridden base class virtual methods
|
// overridden base class virtual methods
|
||||||
virtual void SetLabel(const wxString& label);
|
virtual void SetLabel(const wxString& label);
|
||||||
@@ -56,12 +60,30 @@ protected:
|
|||||||
|
|
||||||
void DoSetSize(int x, int y, int width, int height, int sizeFlags);
|
void DoSetSize(int x, int y, int width, int height, int sizeFlags);
|
||||||
|
|
||||||
|
#if wxUSE_MARKUP
|
||||||
|
virtual bool DoSetLabelMarkup(const wxString& markup);
|
||||||
|
#endif // wxUSE_MARKUP
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void Init()
|
||||||
|
{
|
||||||
|
#if wxUSE_MARKUP
|
||||||
|
m_markupText = NULL;
|
||||||
|
#endif // wxUSE_MARKUP
|
||||||
|
}
|
||||||
|
|
||||||
void OnPaint(wxPaintEvent& event);
|
void OnPaint(wxPaintEvent& event);
|
||||||
|
|
||||||
|
void DoDrawLabel(wxDC& dc, const wxRect& rect);
|
||||||
|
|
||||||
|
// These fields are only used if m_markupText == NULL.
|
||||||
wxString m_label;
|
wxString m_label;
|
||||||
int m_mnemonic;
|
int m_mnemonic;
|
||||||
|
|
||||||
|
#if wxUSE_MARKUP
|
||||||
|
class wxMarkupText *m_markupText;
|
||||||
|
#endif // wxUSE_MARKUP
|
||||||
|
|
||||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxGenericStaticText)
|
DECLARE_DYNAMIC_CLASS_NO_COPY(wxGenericStaticText)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -24,6 +24,9 @@
|
|||||||
|
|
||||||
#include "wx/generic/stattextg.h"
|
#include "wx/generic/stattextg.h"
|
||||||
|
|
||||||
|
#if wxUSE_MARKUP
|
||||||
|
#include "wx/generic/private/markuptext.h"
|
||||||
|
#endif // wxUSE_MARKUP
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxGenericStaticText, wxStaticTextBase)
|
IMPLEMENT_DYNAMIC_CLASS(wxGenericStaticText, wxStaticTextBase)
|
||||||
|
|
||||||
@@ -46,12 +49,26 @@ bool wxGenericStaticText::Create(wxWindow *parent,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxGenericStaticText::~wxGenericStaticText()
|
||||||
|
{
|
||||||
|
#if wxUSE_MARKUP
|
||||||
|
delete m_markupText;
|
||||||
|
#endif // wxUSE_MARKUP
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGenericStaticText::DoDrawLabel(wxDC& dc, const wxRect& rect)
|
||||||
|
{
|
||||||
|
#if wxUSE_MARKUP
|
||||||
|
if ( m_markupText )
|
||||||
|
m_markupText->Render(dc, rect, wxMarkupText::Render_ShowAccels);
|
||||||
|
else
|
||||||
|
#endif // wxUSE_MARKUP
|
||||||
|
dc.DrawLabel(m_label, rect, GetAlignment(), m_mnemonic);
|
||||||
|
}
|
||||||
|
|
||||||
void wxGenericStaticText::OnPaint(wxPaintEvent& WXUNUSED(event))
|
void wxGenericStaticText::OnPaint(wxPaintEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
if ( m_label.empty() )
|
|
||||||
return;
|
|
||||||
wxPaintDC dc(this);
|
wxPaintDC dc(this);
|
||||||
PrepareDC(dc);
|
|
||||||
|
|
||||||
wxRect rect = GetClientRect();
|
wxRect rect = GetClientRect();
|
||||||
if ( IsEnabled() )
|
if ( IsEnabled() )
|
||||||
@@ -66,20 +83,24 @@ void wxGenericStaticText::OnPaint(wxPaintEvent& WXUNUSED(event))
|
|||||||
wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT));
|
wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT));
|
||||||
wxRect rectShadow = rect;
|
wxRect rectShadow = rect;
|
||||||
rectShadow.Offset(1, 1);
|
rectShadow.Offset(1, 1);
|
||||||
dc.DrawLabel(m_label, rectShadow, GetAlignment(), m_mnemonic);
|
DoDrawLabel(dc, rectShadow);
|
||||||
dc.SetTextForeground(
|
dc.SetTextForeground(
|
||||||
wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));
|
wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));
|
||||||
}
|
}
|
||||||
dc.DrawLabel(m_label, wxNullBitmap, rect, GetAlignment(), m_mnemonic);
|
DoDrawLabel(dc, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxSize wxGenericStaticText::DoGetBestClientSize() const
|
wxSize wxGenericStaticText::DoGetBestClientSize() const
|
||||||
{
|
{
|
||||||
wxClientDC dc(wxConstCast(this, wxGenericStaticText));
|
wxClientDC dc(wxConstCast(this, wxGenericStaticText));
|
||||||
wxCoord width, height;
|
|
||||||
dc.GetMultiLineTextExtent(GetLabel(), &width, &height);
|
#if wxUSE_MARKUP
|
||||||
return wxSize(width, height);
|
if ( m_markupText )
|
||||||
|
return m_markupText->Measure(dc);
|
||||||
|
#endif // wxUSE_MARKUP
|
||||||
|
|
||||||
|
return dc.GetMultiLineTextExtent(GetLabel());
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGenericStaticText::SetLabel(const wxString& label)
|
void wxGenericStaticText::SetLabel(const wxString& label)
|
||||||
@@ -88,6 +109,15 @@ void wxGenericStaticText::SetLabel(const wxString& label)
|
|||||||
DoSetLabel(GetEllipsizedLabel());
|
DoSetLabel(GetEllipsizedLabel());
|
||||||
if ( !HasFlag(wxST_NO_AUTORESIZE) && !IsEllipsized() )
|
if ( !HasFlag(wxST_NO_AUTORESIZE) && !IsEllipsized() )
|
||||||
InvalidateBestSize();
|
InvalidateBestSize();
|
||||||
|
|
||||||
|
#if wxUSE_MARKUP
|
||||||
|
if ( m_markupText )
|
||||||
|
{
|
||||||
|
delete m_markupText;
|
||||||
|
m_markupText = NULL;
|
||||||
|
}
|
||||||
|
#endif // wxUSE_MARKUP
|
||||||
|
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,6 +126,28 @@ void wxGenericStaticText::DoSetLabel(const wxString& label)
|
|||||||
m_mnemonic = FindAccelIndex(label, &m_label);
|
m_mnemonic = FindAccelIndex(label, &m_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if wxUSE_MARKUP
|
||||||
|
|
||||||
|
bool wxGenericStaticText::DoSetLabelMarkup(const wxString& markup)
|
||||||
|
{
|
||||||
|
if ( !wxStaticTextBase::DoSetLabelMarkup(markup) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ( !m_markupText )
|
||||||
|
m_markupText = new wxMarkupText(markup);
|
||||||
|
else
|
||||||
|
m_markupText->SetMarkup(markup);
|
||||||
|
|
||||||
|
if ( !HasFlag(wxST_NO_AUTORESIZE) )
|
||||||
|
InvalidateBestSize();
|
||||||
|
|
||||||
|
Refresh();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // wxUSE_MARKUP
|
||||||
|
|
||||||
bool wxGenericStaticText::SetFont(const wxFont &font)
|
bool wxGenericStaticText::SetFont(const wxFont &font)
|
||||||
{
|
{
|
||||||
if ( !wxControl::SetFont(font) )
|
if ( !wxControl::SetFont(font) )
|
||||||
|
Reference in New Issue
Block a user