All (GUI):
+- Added strike-through support to wxFont (Igor Korot).
- Added wxFilePickerCtrl::SetInitialDirectory().
- Added wxDataViewItemAttr::SetBackgroundColour() and implemented it in generic
wxDataViewCtrl (Andrew Xu).
virtual wxFontStyle GetStyle() const = 0;
virtual wxFontWeight GetWeight() const = 0;
virtual bool GetUnderlined() const = 0;
+ virtual bool GetStrikethrough() const { return false; }
virtual wxString GetFaceName() const = 0;
virtual wxFontEncoding GetEncoding() const = 0;
virtual const wxNativeFontInfo *GetNativeFontInfo() const = 0;
virtual void SetWeight( wxFontWeight weight ) = 0;
virtual void SetUnderlined( bool underlined ) = 0;
+ virtual void SetStrikethrough( bool WXUNUSED(strikethrough) ) {}
virtual void SetEncoding(wxFontEncoding encoding) = 0;
virtual bool SetFaceName( const wxString& faceName );
void SetNativeFontInfo(const wxNativeFontInfo& info)
wxFont& MakeBold(); \
wxFont& MakeItalic(); \
wxFont& MakeUnderlined(); \
+ wxFont& MakeStrikethrough(); \
wxFont& MakeLarger() { return Scale(1.2f); } \
wxFont& MakeSmaller() { return Scale(1/1.2f); } \
wxFont& Scale(float x); \
wxFont Bold() const; \
wxFont Italic() const; \
wxFont Underlined() const; \
+ wxFont Strikethrough() const; \
wxFont Larger() const { return Scaled(1.2f); } \
wxFont Smaller() const { return Scaled(1/1.2f); } \
wxFont Scaled(float x) const
wxFontStyle m_style;
wxFontWeight m_weight;
bool m_underlined;
+ bool m_strikethrough;
wxString m_faceName;
wxFontEncoding m_encoding;
public :
wxFontStyle style;
wxFontWeight weight;
bool underlined;
+ bool strikethrough;
wxString faceName;
wxFontEncoding encoding;
#endif // platforms
SetStyle((wxFontStyle)font.GetStyle());
SetWeight((wxFontWeight)font.GetWeight());
SetUnderlined(font.GetUnderlined());
+ SetStrikethrough(font.GetStrikethrough());
#if defined(__WXMSW__)
if ( font.IsUsingSizeInPixels() )
SetPixelSize(font.GetPixelSize());
wxFontStyle GetStyle() const;
wxFontWeight GetWeight() const;
bool GetUnderlined() const;
+ bool GetStrikethrough() const;
wxString GetFaceName() const;
wxFontFamily GetFamily() const;
wxFontEncoding GetEncoding() const;
void SetStyle(wxFontStyle style);
void SetWeight(wxFontWeight weight);
void SetUnderlined(bool underlined);
+ void SetStrikethrough(bool strikethrough);
bool SetFaceName(const wxString& facename);
void SetFamily(wxFontFamily family);
void SetEncoding(wxFontEncoding encoding);
virtual wxFontWeight GetWeight() const;
virtual wxString GetFaceName() const;
virtual bool GetUnderlined() const;
+ virtual bool GetStrikethrough() const;
virtual wxFontEncoding GetEncoding() const;
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
virtual bool IsFixedWidth() const;
virtual void SetWeight(wxFontWeight weight);
virtual bool SetFaceName( const wxString& faceName );
virtual void SetUnderlined( bool underlined );
+ virtual void SetStrikethrough(bool strikethrough);
virtual void SetEncoding(wxFontEncoding encoding);
wxDECLARE_COMMON_FONT_METHODS();
GtkWidget *GetTextEntryWidget();
GtkWidget *GetTreeWidget();
+// Set Pango attributes corresponding to the given font for the span 0..len (or
+// without any bounds if len == 0) in the specified layout. Currently only
+// underlined and strike-through attributes are handled by this function.
+//
+// Special "addDummyAttrs" parameter is used to work around a bug in old Pango
+// versions in wxWindowDCImpl::DoDrawText(), see comment there.
+//
+// If neither of them is specified, returns false, otherwise sets up the
+// attributes and returns true.
+//
+// This function is implemented in src/gtk/dcclient.cpp.
+bool
+SetPangoAttrsForFont(const wxFont& font, PangoLayout* layout, size_t len = 0,
+ bool addDummyAttrs = false);
+
} // wxGTKPrivate
#endif // _WX_GTK_PRIVATE_H_
virtual wxFontStyle GetStyle() const;
virtual wxFontWeight GetWeight() const;
virtual bool GetUnderlined() const;
+ virtual bool GetStrikethrough() const;
virtual wxString GetFaceName() const;
virtual wxFontEncoding GetEncoding() const;
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
virtual void SetWeight(wxFontWeight weight);
virtual bool SetFaceName(const wxString& faceName);
virtual void SetUnderlined(bool underlined);
+ virtual void SetStrikethrough(bool strikethrough);
virtual void SetEncoding(wxFontEncoding encoding);
wxDECLARE_COMMON_FONT_METHODS();
wxTEXT_ATTR_FONT_WEIGHT = 0x00000010,
wxTEXT_ATTR_FONT_ITALIC = 0x00000020,
wxTEXT_ATTR_FONT_UNDERLINE = 0x00000040,
+ wxTEXT_ATTR_FONT_STRIKETHROUGH = 0x08000000,
wxTEXT_ATTR_FONT_ENCODING = 0x02000000,
wxTEXT_ATTR_FONT_FAMILY = 0x04000000,
wxTEXT_ATTR_FONT = \
( wxTEXT_ATTR_FONT_FACE | wxTEXT_ATTR_FONT_SIZE | wxTEXT_ATTR_FONT_WEIGHT | \
- wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE | wxTEXT_ATTR_FONT_ENCODING | wxTEXT_ATTR_FONT_FAMILY ),
+ wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE | wxTEXT_ATTR_FONT_STRIKETHROUGH | wxTEXT_ATTR_FONT_ENCODING | wxTEXT_ATTR_FONT_FAMILY ),
wxTEXT_ATTR_ALIGNMENT = 0x00000080,
wxTEXT_ATTR_LEFT_INDENT = 0x00000100,
void SetFontWeight(wxFontWeight fontWeight) { m_fontWeight = fontWeight; m_flags |= wxTEXT_ATTR_FONT_WEIGHT; }
void SetFontFaceName(const wxString& faceName) { m_fontFaceName = faceName; m_flags |= wxTEXT_ATTR_FONT_FACE; }
void SetFontUnderlined(bool underlined) { m_fontUnderlined = underlined; m_flags |= wxTEXT_ATTR_FONT_UNDERLINE; }
+ void SetFontStrikethrough(bool strikethrough) { m_fontStrikethrough = strikethrough; m_flags |= wxTEXT_ATTR_FONT_STRIKETHROUGH; }
void SetFontEncoding(wxFontEncoding encoding) { m_fontEncoding = encoding; m_flags |= wxTEXT_ATTR_FONT_ENCODING; }
void SetFontFamily(wxFontFamily family) { m_fontFamily = family; m_flags |= wxTEXT_ATTR_FONT_FAMILY; }
wxFontStyle GetFontStyle() const { return m_fontStyle; }
wxFontWeight GetFontWeight() const { return m_fontWeight; }
bool GetFontUnderlined() const { return m_fontUnderlined; }
+ bool GetFontStrikethrough() const { return m_fontStrikethrough; }
const wxString& GetFontFaceName() const { return m_fontFaceName; }
wxFontEncoding GetFontEncoding() const { return m_fontEncoding; }
wxFontFamily GetFontFamily() const { return m_fontFamily; }
bool HasFontSize() const { return HasFlag(wxTEXT_ATTR_FONT_SIZE); }
bool HasFontItalic() const { return HasFlag(wxTEXT_ATTR_FONT_ITALIC); }
bool HasFontUnderlined() const { return HasFlag(wxTEXT_ATTR_FONT_UNDERLINE); }
+ bool HasFontStrikethrough() const { return HasFlag(wxTEXT_ATTR_FONT_STRIKETHROUGH); }
bool HasFontFaceName() const { return HasFlag(wxTEXT_ATTR_FONT_FACE); }
bool HasFontEncoding() const { return HasFlag(wxTEXT_ATTR_FONT_ENCODING); }
bool HasFontFamily() const { return HasFlag(wxTEXT_ATTR_FONT_FAMILY); }
wxFontWeight m_fontWeight;
wxFontFamily m_fontFamily;
bool m_fontUnderlined;
+ bool m_fontStrikethrough;
wxString m_fontFaceName;
// Character style
wxFONTFLAG_ANTIALIASED = 1 << 4,
wxFONTFLAG_NOT_ANTIALIASED = 1 << 5,
- /// underlined/strikethrough flags (default: no lines)
+ /// Underlined style (not underlined by default).
wxFONTFLAG_UNDERLINED = 1 << 6,
+
+ /// Strike-through style (only supported in wxMSW and wxGTK currently).
wxFONTFLAG_STRIKETHROUGH = 1 << 7,
/// the mask of all currently used flags
The meaning of the remaining arguments is the same as in the other
constructors, please see their documentation for details.
+ Notice that this constructor provides the only way of creating fonts
+ with strike-through style.
+
@since 2.9.4
*/
wxFont(int pointSize, wxFontFamily family, int flags,
*/
virtual bool GetUnderlined() const;
+ /**
+ Returns @true if the font is stricken-through, @false otherwise.
+
+ @see SetStrikethrough()
+
+ @since 2.9.4
+ */
+ virtual bool GetStrikethrough() const;
+
/**
Gets the font weight. See ::wxFontWeight for a list of valid weight identifiers.
*/
wxFont Underlined() const;
+ /**
+ Returns stricken-through version of this font.
+
+ Currently stricken-through fonts are only supported in wxMSW and wxGTK.
+
+ @see MakeStrikethrough()
+
+ @since 2.9.4
+ */
+ wxFont Strikethrough() const;
+
/**
Changes this font to be bold.
*/
wxFont& MakeUnderlined();
+ /**
+ Changes this font to be stricken-through.
+
+ Currently stricken-through fonts are only supported in wxMSW and wxGTK.
+
+ @see Strikethrough()
+
+ @since 2.9.4
+ */
+ wxFont& MakeStrikethrough();
+
/**
Changes the size of this font.
*/
virtual void SetUnderlined(bool underlined);
+ /**
+ Sets strike-through attribute of the font.
+
+ Currently stricken-through fonts are only supported in wxMSW and wxGTK.
+
+ @param strikethrough
+ @true to add strike-through style, @false to remove it.
+
+ @see GetStrikethrough()
+
+ @since 2.9.4
+ */
+ virtual void SetStrikethrough(bool strikethrough);
+
/**
Sets the font weight.
void OnSlant(wxCommandEvent& event);
void OnUnderline(wxCommandEvent& event);
+ void OnStrikethrough(wxCommandEvent& event);
void OnwxPointerFont(wxCommandEvent& event);
void OnwxSystemSettingsFont(wxCommandEvent& event);
Font_Slant,
Font_Underlined,
+ Font_Strikethrough,
// standard global wxFont objects:
Font_wxNORMAL_FONT,
EVT_MENU(Font_Slant, MyFrame::OnSlant)
EVT_MENU(Font_Underlined, MyFrame::OnUnderline)
+ EVT_MENU(Font_Strikethrough, MyFrame::OnStrikethrough)
EVT_MENU(Font_wxNORMAL_FONT, MyFrame::OnwxPointerFont)
EVT_MENU(Font_wxSMALL_FONT, MyFrame::OnwxPointerFont)
menuFont->AppendSeparator();
menuFont->AppendCheckItem(Font_Underlined, wxT("&Underlined\tCtrl-U"),
wxT("Toggle underlined state"));
+ menuFont->AppendCheckItem(Font_Strikethrough, wxT("&Strikethrough"),
+ wxT("Toggle strikethrough state"));
menuFont->AppendSeparator();
menuFont->Append(Font_SetNativeDesc,
DoChangeFont(font);
}
+void MyFrame::OnStrikethrough(wxCommandEvent& event)
+{
+ wxFont font = m_canvas->GetTextFont();
+ font.SetStrikethrough(event.IsChecked());
+ DoChangeFont(font);
+}
+
void MyFrame::OnwxPointerFont(wxCommandEvent& event)
{
wxFont font;
m_textctrl->SetFont(font);
if ( col.IsOk() )
m_textctrl->SetForegroundColour(col);
+ m_textctrl->Refresh();
// update the state of the bold/italic/underlined menu items
wxMenuBar *mbar = GetMenuBar();
#endif
mbar->Check(Font_Underlined, font.GetUnderlined());
+ mbar->Check(Font_Strikethrough, font.GetStrikethrough());
}
}
wxT("Helpstring"), wxT("group")) // wxFontWeight
wxPROPERTY( Underlined, bool, SetUnderlined, GetUnderlined, false, 0 /*flags*/, \
wxT("Helpstring"), wxT("group"))
+wxPROPERTY( Strikethrough, bool, SetStrikethrough, GetStrikethrough, false, 0, \
+ wxT("Helpstring"), wxT("group"))
wxPROPERTY( Face, wxString, SetFaceName, GetFaceName, wxEMPTY_PARAMETER_VALUE, \
0 /*flags*/, wxT("Helpstring"), wxT("group"))
wxPROPERTY( Encoding, wxFontEncoding, SetEncoding, GetEncoding, \
SetStyle(info.style);
SetWeight(info.weight);
SetUnderlined(info.underlined);
+ SetStrikethrough(info.strikethrough);
SetFaceName(info.faceName);
SetEncoding(info.encoding);
#else
GetStyle() == font.GetStyle() &&
GetWeight() == font.GetWeight() &&
GetUnderlined() == font.GetUnderlined() &&
+ GetStrikethrough() == font.GetStrikethrough() &&
GetFaceName().IsSameAs(font.GetFaceName(), false) &&
GetEncoding() == font.GetEncoding()
);
return font;
}
+wxFont wxFont::Strikethrough() const
+{
+ wxFont font(*this);
+ font.MakeStrikethrough();
+ return font;
+}
+
+wxFont& wxFont::MakeStrikethrough()
+{
+ SetStrikethrough(true);
+ return *this;
+}
+
wxFont& wxFont::Scale(float x)
{
SetPointSize(int(x*GetPointSize() + 0.5));
// These are the generic forms of FromString()/ToString.
//
-// convert to/from the string representation: format is
-// version;pointsize;family;style;weight;underlined;facename;encoding
+// convert to/from the string representation: the general format is
+// "version;the rest..." with currently defined versions being:
+//
+// 0;pointsize;family;style;weight;underlined;facename;encoding
+// 1;pointsize;family;style;weight;underlined;strikethrough;facename;encoding
bool wxNativeFontInfo::FromString(const wxString& s)
{
long l;
+ short version;
wxStringTokenizer tokenizer(s, wxT(";"));
wxString token = tokenizer.GetNextToken();
- //
- // Ignore the version for now
- //
+ if ( !token.ToLong(&version) || version < 0 || version > 1 )
+ return false;
token = tokenizer.GetNextToken();
if ( !token.ToLong(&l) )
return false;
underlined = l != 0;
+ if ( version == 1 )
+ {
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ strikethrough = l != 0;
+ }
+
faceName = tokenizer.GetNextToken();
#ifndef __WXMAC__
{
wxString s;
- s.Printf(wxT("%d;%d;%d;%d;%d;%d;%s;%d"),
- 0, // version
+ s.Printf(wxT("%d;%d;%d;%d;%d;%d;%d;%s;%d"),
+ 1, // version
pointSize,
family,
(int)style,
(int)weight,
underlined,
+ strikethrough,
faceName.GetData(),
(int)encoding);
style = wxFONTSTYLE_NORMAL;
weight = wxFONTWEIGHT_NORMAL;
underlined = false;
+ strikethrough = false;
faceName.clear();
encoding = wxFONTENCODING_DEFAULT;
}
return underlined;
}
+bool wxNativeFontInfo::GetStrikethrough() const
+{
+ return strikethrough;
+}
+
wxString wxNativeFontInfo::GetFaceName() const
{
return faceName;
underlined = underlined_;
}
+void wxNativeFontInfo::SetStrikethrough(bool strikethrough_)
+{
+ strikethrough = strikethrough_;
+}
+
bool wxNativeFontInfo::SetFaceName(const wxString& facename_)
{
faceName = facename_;
desc << _("underlined");
}
+ if ( GetStrikethrough() )
+ {
+ desc << _("strikethrough");
+ }
+
switch ( GetWeight() )
{
default:
{
SetUnderlined(true);
}
+ else if ( token == wxT("strikethrough") || token == _("strikethrough") )
+ {
+ SetStrikethrough(true);
+ }
else if ( token == wxT("light") || token == _("light") )
{
SetWeight(wxFONTWEIGHT_LIGHT);
if (HasFontUnderlined())
underlined = GetFontUnderlined();
+ bool strikethrough = false;
+ if ( HasFontStrikethrough() )
+ strikethrough = GetFontStrikethrough();
+
wxString fontFaceName;
if (HasFontFaceName())
fontFaceName = GetFontFaceName();
fontFamily = GetFontFamily();
wxFont font(fontSize, fontFamily, fontStyle, fontWeight, underlined, fontFaceName, encoding);
+ if ( strikethrough )
+ font.SetStrikethrough( true );
return font;
}
if (flags & wxTEXT_ATTR_FONT_UNDERLINE)
m_fontUnderlined = font.GetUnderlined();
+ if (flags & wxTEXT_ATTR_FONT_STRIKETHROUGH)
+ m_fontStrikethrough = font.GetStrikethrough();
+
if (flags & wxTEXT_ATTR_FONT_FACE)
m_fontFaceName = font.GetFaceName();
destStyle.SetFontUnderlined(style.GetFontUnderlined());
}
+ if (style.HasFontStrikethrough())
+ {
+ if (!(compareWith && compareWith->HasFontStrikethrough() && compareWith->GetFontStrikethrough() == style.GetFontStrikethrough()))
+ destStyle.SetFontStrikethrough(style.GetFontStrikethrough());
+ }
+
if (style.HasFontFaceName())
{
if (!(compareWith && compareWith->HasFontFaceName() && compareWith->GetFontFaceName() == style.GetFontFaceName()))
#include "wx/gtk/private.h"
#include "wx/gtk/private/object.h"
+using wxGTKPrivate::SetPangoAttrsForFont;
+
//-----------------------------------------------------------------------------
// local defines
//-----------------------------------------------------------------------------
}
pango_layout_set_text(m_layout, data, datalen);
-
- if (underlined)
- {
- PangoAttrList *attrs = pango_attr_list_new();
- PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
- a->start_index = 0;
- a->end_index = datalen;
- pango_attr_list_insert(attrs, a);
-
- if (needshack)
- {
- // dummy colour for the leading space
- a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
- a->start_index = 0;
- a->end_index = 1;
- pango_attr_list_insert(attrs, a);
-
- // dummy colour for the trailing space
- a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
- a->start_index = datalen - 1;
- a->end_index = datalen;
- pango_attr_list_insert(attrs, a);
- }
-
- pango_layout_set_attributes(m_layout, attrs);
- pango_attr_list_unref(attrs);
- }
+ const bool
+ setAttrs = SetPangoAttrsForFont(m_font, m_layout, datalen, needshack);
int oldSize = 0;
const bool isScaled = fabs(m_scaleY - 1.0) > 0.00001;
// actually apply unscaled font
pango_layout_set_font_description( m_layout, m_fontdesc );
}
- if (underlined)
+ if (setAttrs)
{
// undo underline attributes setting:
pango_layout_set_attributes(m_layout, NULL);
y = YLOG2DEV(y);
pango_layout_set_text(m_layout, wxGTK_CONV(text), -1);
-
- if (m_font.GetUnderlined())
- {
- PangoAttrList *attrs = pango_attr_list_new();
- PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
- pango_attr_list_insert(attrs, a);
- pango_layout_set_attributes(m_layout, attrs);
- pango_attr_list_unref(attrs);
- }
-
+ SetPangoAttrsForFont( m_font, m_layout );
int oldSize = 0;
const bool isScaled = fabs(m_scaleY - 1.0) > 0.00001;
if (isScaled)
gdk_draw_layout_with_colors(m_gdkwindow, m_textGC, x+minX, y+minY,
m_layout, NULL, bg_col);
- if (m_font.GetUnderlined())
+ if (m_font.GetUnderlined() || m_font.GetStrikethrough())
pango_layout_set_attributes(m_layout, NULL);
// clean up the transformation matrix
return gdk_drawable_get_depth(m_gdkwindow);
}
+bool
+wxGTKPrivate::SetPangoAttrsForFont(const wxFont& font,
+ PangoLayout *layout,
+ size_t len,
+ bool addDummyAttrs)
+{
+ if ( !font.IsOk() || !(font.GetUnderlined() || font.GetStrikethrough()) )
+ return false;
+
+ PangoAttrList* attrs = pango_attr_list_new();
+
+ if ( font.GetUnderlined() )
+ {
+ PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
+ if ( len )
+ {
+ a->start_index = 0;
+ a->end_index = len;
+ }
+ pango_attr_list_insert(attrs, a);
+
+ // Add dummy attributes (use colour as it's invisible anyhow for 0
+ // width spaces) to ensure that the spaces in the beginning/end of the
+ // string are underlined too.
+ if ( addDummyAttrs )
+ {
+ wxASSERT_MSG( len > 2, "Must have 0-width spaces at string ends" );
+
+ a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
+ a->start_index = 0;
+ a->end_index = 1;
+ pango_attr_list_insert(attrs, a);
+
+ a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
+ a->start_index = len - 1;
+ a->end_index = len;
+ pango_attr_list_insert(attrs, a);
+ }
+ }
+
+ if ( font.GetStrikethrough() )
+ {
+ PangoAttribute *a = pango_attr_strikethrough_new( TRUE );
+ if ( len )
+ {
+ a->start_index = 0;
+ a->end_index = len;
+ }
+ pango_attr_list_insert(attrs, a);
+ }
+
+ pango_layout_set_attributes(layout, attrs);
+ pango_attr_list_unref(attrs);
+
+ return true;
+}
//-----------------------------------------------------------------------------
// wxClientDCImpl
wxFontStyle style = wxFONTSTYLE_NORMAL,
wxFontWeight weight = wxFONTWEIGHT_NORMAL,
bool underlined = false,
+ bool strikethrough = false,
const wxString& faceName = wxEmptyString,
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
void SetStyle(wxFontStyle style);
void SetWeight(wxFontWeight weight);
void SetUnderlined(bool underlined);
+ void SetStrikethrough(bool strikethrough);
bool SetFaceName(const wxString& facename);
void SetEncoding(wxFontEncoding encoding);
wxFontStyle style,
wxFontWeight weight,
bool underlined,
+ bool strikethrough,
const wxString& faceName,
wxFontEncoding encoding);
private:
bool m_underlined;
-
+ bool m_strikethrough;
// The native font info: basically a PangoFontDescription
wxNativeFontInfo m_nativeFontInfo;
wxFontStyle style,
wxFontWeight weight,
bool underlined,
+ bool strikethrough,
const wxString& faceName,
wxFontEncoding WXUNUSED(encoding))
{
family = wxFONTFAMILY_SWISS;
m_underlined = underlined;
+ m_strikethrough = strikethrough;
// Create native font info
m_nativeFontInfo.description = pango_font_description_new();
// Pango description are never underlined
m_underlined = false;
+ m_strikethrough = false;
}
wxFontRefData::wxFontRefData( const wxFontRefData& data )
: wxGDIRefData()
{
m_underlined = data.m_underlined;
+ m_strikethrough = data.m_strikethrough;
// Forces a copy of the internal data. wxNativeFontInfo should probably
// have a copy ctor and assignment operator to fix this properly but that
}
wxFontRefData::wxFontRefData(int size, wxFontFamily family, wxFontStyle style,
- wxFontWeight weight, bool underlined,
+ wxFontWeight weight, bool underlined, bool strikethrough,
const wxString& faceName,
wxFontEncoding encoding)
{
- Init(size, family, style, weight, underlined, faceName, encoding);
+ Init(size, family, style, weight, underlined, strikethrough, faceName, encoding);
}
wxFontRefData::wxFontRefData(const wxString& nativeFontInfoString)
// here we just need to save the underlined attribute
}
+void wxFontRefData::SetStrikethrough(bool strikethrough)
+{
+ m_strikethrough = strikethrough;
+}
+
bool wxFontRefData::SetFaceName(const wxString& facename)
{
return m_nativeFontInfo.SetFaceName(facename);
GetStyleFromFlags(flags),
GetWeightFromFlags(flags),
GetUnderlinedFromFlags(flags),
- face, encoding);
+ false, face, encoding);
}
bool wxFont::Create( int pointSize,
UnRef();
m_refData = new wxFontRefData(pointSize, family, style, weight,
- underlined, face, encoding);
+ underlined, false, face, encoding);
return true;
}
return M_FONTDATA->m_underlined;
}
+bool wxFont::GetStrikethrough() const
+{
+ wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
+
+ return M_FONTDATA->m_strikethrough;
+}
+
wxFontEncoding wxFont::GetEncoding() const
{
wxCHECK_MSG( IsOk(), wxFONTENCODING_SYSTEM, wxT("invalid font") );
M_FONTDATA->SetUnderlined(underlined);
}
+void wxFont::SetStrikethrough(bool strikethrough)
+{
+ AllocExclusive();
+
+ M_FONTDATA->SetStrikethrough(strikethrough);
+}
+
void wxFont::SetEncoding(wxFontEncoding encoding)
{
AllocExclusive();
double xx = XLOG2DEV(x);
double yy = YLOG2DEV(y);
- bool underlined = m_font.IsOk() && m_font.GetUnderlined();
-
const wxScopedCharBuffer data(text.utf8_str());
size_t datalen = strlen(data);
pango_layout_set_text( m_layout, data, datalen);
- if (underlined)
- {
- PangoAttrList *attrs = pango_attr_list_new();
- PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
- a->start_index = 0;
- a->end_index = datalen;
- pango_attr_list_insert(attrs, a);
- pango_layout_set_attributes(m_layout, attrs);
- pango_attr_list_unref(attrs);
- }
+ const bool
+ setAttrs = wxGTKPrivate::SetPangoAttrsForFont(m_font, m_layout, datalen);
if (m_textForegroundColour.IsOk())
{
gs_libGnomePrint->gnome_print_grestore( m_gpc );
- if (underlined)
+ if (setAttrs)
{
// undo underline attributes setting:
pango_layout_set_attributes(m_layout, NULL);
angle = -angle;
- bool underlined = m_font.IsOk() && m_font.GetUnderlined();
-
const wxScopedCharBuffer data = text.utf8_str();
size_t datalen = strlen(data);
pango_layout_set_text( m_layout, data, datalen);
- if (underlined)
- {
- PangoAttrList *attrs = pango_attr_list_new();
- PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
- a->start_index = 0;
- a->end_index = datalen;
- pango_attr_list_insert(attrs, a);
- pango_layout_set_attributes(m_layout, attrs);
- pango_attr_list_unref(attrs);
- }
-
+ const bool
+ setAttrs = wxGTKPrivate::SetPangoAttrsForFont(m_font, m_layout, datalen);
if (m_textForegroundColour.IsOk())
{
unsigned char red = m_textForegroundColour.Red();
cairo_restore( m_cairo );
- if (underlined)
+ if (setAttrs)
{
// Undo underline attributes setting
pango_layout_set_attributes(m_layout, NULL);
bool wxStaticText::SetFont( const wxFont &font )
{
const bool wasUnderlined = GetFont().GetUnderlined();
+ const bool wasStrickenThrough = GetFont().GetStrikethrough();
bool ret = wxControl::SetFont(font);
- if ( font.GetUnderlined() != wasUnderlined )
- {
- // the underlines for mnemonics are incompatible with using attributes
- // so turn them off when setting underlined font and restore them when
- // unsetting it
- gtk_label_set_use_underline(GTK_LABEL(m_widget), wasUnderlined);
+ const bool isUnderlined = GetFont().GetUnderlined();
+ const bool isStrickenThrough = GetFont().GetStrikethrough();
- if ( wasUnderlined )
- {
- // it's not underlined any more, remove the attributes we set
- gtk_label_set_attributes(GTK_LABEL(m_widget), NULL);
- }
- else // the text is underlined now
+ if ( (isUnderlined != wasUnderlined) ||
+ (isStrickenThrough != wasStrickenThrough) )
+ {
+ // We need to update the Pango attributes used for the text.
+ if ( isUnderlined || isStrickenThrough )
{
- PangoAttrList *attrs = pango_attr_list_new();
- PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
- a->start_index = 0;
- a->end_index = (guint)-1;
- pango_attr_list_insert(attrs, a);
+ PangoAttrList* const attrs = pango_attr_list_new();
+ if ( isUnderlined )
+ {
+ PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
+ a->start_index = 0;
+ a->end_index = (guint)-1;
+ pango_attr_list_insert(attrs, a);
+ }
+
+ if ( isStrickenThrough )
+ {
+ PangoAttribute *a = pango_attr_strikethrough_new( TRUE );
+ a->start_index = 0;
+ a->end_index = (guint) -1;
+ pango_attr_list_insert(attrs, a);
+ }
+
gtk_label_set_attributes(GTK_LABEL(m_widget), attrs);
pango_attr_list_unref(attrs);
}
+ else // No special attributes any more.
+ {
+ // Just remove any attributes we had set.
+ gtk_label_set_attributes(GTK_LABEL(m_widget), NULL);
+ }
+
+ // The underlines for mnemonics are incompatible with using attributes
+ // so turn them off when setting underlined font.
+ gtk_label_set_use_underline(GTK_LABEL(m_widget), !isUnderlined);
}
// adjust the label size to the new label unless disabled
NULL );
gtk_text_buffer_apply_tag (text_buffer, tag, start, end);
}
+ if ( font.GetStrikethrough() )
+ {
+ g_snprintf(buf, sizeof(buf), "WXFONTSTRIKETHROUGH");
+ tag = gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer ),
+ buf );
+ if (!tag)
+ tag = gtk_text_buffer_create_tag( text_buffer, buf,
+ "strikethrough-set", TRUE,
+ "strikethrough", TRUE,
+ NULL );
+ gtk_text_buffer_apply_tag (text_buffer, tag, start, end);
+ }
}
if (attr.HasTextColour())
wxFontRefData()
{
Init(-1, wxSize(0,0), false, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
- wxFONTWEIGHT_NORMAL, false, wxEmptyString,
+ wxFONTWEIGHT_NORMAL, false, false, wxEmptyString,
wxFONTENCODING_DEFAULT);
}
wxFontStyle style,
wxFontWeight weight,
bool underlined,
+ bool strikethrough,
const wxString& faceName,
wxFontEncoding encoding)
{
Init(size, pixelSize, sizeUsingPixels, family, style, weight,
- underlined, faceName, encoding);
+ underlined, strikethrough, faceName, encoding);
}
wxFontRefData(const wxNativeFontInfo& info, WXHFONT hFont = 0)
return m_nativeFontInfo.GetUnderlined();
}
+ bool GetStrikethrough() const
+ {
+ return m_nativeFontInfo.GetStrikethrough();
+ }
+
wxString GetFaceName() const
{
wxString facename = m_nativeFontInfo.GetFaceName();
m_nativeFontInfo.SetUnderlined(underlined);
}
+ void SetStrikethrough(bool strikethrough)
+ {
+ Free();
+
+ m_nativeFontInfo.SetStrikethrough(strikethrough);
+ }
+
void SetEncoding(wxFontEncoding encoding)
{
Free();
wxFontStyle style,
wxFontWeight weight,
bool underlined,
+ bool strikethrough,
const wxString& faceName,
wxFontEncoding encoding);
wxFontStyle style,
wxFontWeight weight,
bool underlined,
+ bool strikethrough,
const wxString& faceName,
wxFontEncoding encoding)
{
SetStyle(style);
SetWeight(weight);
SetUnderlined(underlined);
+ SetStrikethrough(strikethrough);
// set the family/facename
SetFamily(family);
return lf.lfUnderline != 0;
}
+bool wxNativeFontInfo::GetStrikethrough() const
+{
+ return lf.lfStrikeOut != 0;
+}
+
wxString wxNativeFontInfo::GetFaceName() const
{
return lf.lfFaceName;
lf.lfUnderline = underlined;
}
+void wxNativeFontInfo::SetStrikethrough(bool strikethrough)
+{
+ lf.lfStrikeOut = strikethrough;
+}
+
bool wxNativeFontInfo::SetFaceName(const wxString& facename)
{
wxStrlcpy(lf.lfFaceName, facename.c_str(), WXSIZEOF(lf.lfFaceName));
GetStyleFromFlags(flags),
GetWeightFromFlags(flags),
GetUnderlinedFromFlags(flags),
- face, encoding);
+ false, face, encoding);
}
bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont)
m_refData = new wxFontRefData(pointSize, pixelSize, sizeUsingPixels,
family, style, weight,
- underlined, faceName, encoding);
+ underlined, false, faceName, encoding);
return RealizeResource();
}
M_FONTDATA->SetUnderlined(underlined);
}
+void wxFont::SetStrikethrough(bool strikethrough)
+{
+ AllocExclusive();
+
+ M_FONTDATA->SetStrikethrough(strikethrough);
+}
+
void wxFont::SetEncoding(wxFontEncoding encoding)
{
AllocExclusive();
return M_FONTDATA->GetUnderlined();
}
+bool wxFont::GetStrikethrough() const
+{
+ wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
+
+ return M_FONTDATA->GetStrikethrough();
+}
+
wxString wxFont::GetFaceName() const
{
wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") );