Improve underline changes of wxTextCtrl

Get rid of m_fontUnderlined, use m_fontUnderlineType instead.
Bugfixes in wxMSW, wxGTK and wxOSX code.
Show more underline usage in the text sample.
This commit is contained in:
Maarten Bent
2019-07-06 13:47:00 +02:00
parent f99ae84d7c
commit 4afea28aab
7 changed files with 126 additions and 128 deletions

View File

@@ -328,12 +328,10 @@ public:
void SetFontStyle(wxFontStyle fontStyle) { m_fontStyle = fontStyle; m_flags |= wxTEXT_ATTR_FONT_ITALIC; } void SetFontStyle(wxFontStyle fontStyle) { m_fontStyle = fontStyle; m_flags |= wxTEXT_ATTR_FONT_ITALIC; }
void SetFontWeight(wxFontWeight fontWeight) { m_fontWeight = fontWeight; m_flags |= wxTEXT_ATTR_FONT_WEIGHT; } 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 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 SetFontUnderlined(bool underlined) { SetFontUnderlined(underlined ? wxTEXT_ATTR_UNDERLINE_SOLID : wxTEXT_ATTR_UNDERLINE_NONE); }
void SetFontUnderline(/*bool underlined, */wxTextAttrUnderlineType type = wxTEXT_ATTR_UNDERLINE_NONE, const wxColour& colour = wxNullColour) void SetFontUnderlined(wxTextAttrUnderlineType type, const wxColour& colour = wxNullColour)
{ {
if( type != wxTEXT_ATTR_UNDERLINE_NONE )
m_flags |= wxTEXT_ATTR_FONT_UNDERLINE; m_flags |= wxTEXT_ATTR_FONT_UNDERLINE;
// m_fontUnderlined = underlined;
m_fontUnderlineType = type; m_fontUnderlineType = type;
m_colUnderline = colour; m_colUnderline = colour;
} }
@@ -375,7 +373,7 @@ public:
int GetFontSize() const { return m_fontSize; } int GetFontSize() const { return m_fontSize; }
wxFontStyle GetFontStyle() const { return m_fontStyle; } wxFontStyle GetFontStyle() const { return m_fontStyle; }
wxFontWeight GetFontWeight() const { return m_fontWeight; } wxFontWeight GetFontWeight() const { return m_fontWeight; }
bool GetFontUnderlined() const { return m_fontUnderlined; } bool GetFontUnderlined() const { return m_fontUnderlineType != wxTEXT_ATTR_UNDERLINE_NONE; }
wxTextAttrUnderlineType GetUnderlineType() const { return m_fontUnderlineType; } wxTextAttrUnderlineType GetUnderlineType() const { return m_fontUnderlineType; }
const wxColour& GetUnderlineColour() const { return m_colUnderline; } const wxColour& GetUnderlineColour() const { return m_colUnderline; }
bool GetFontStrikethrough() const { return m_fontStrikethrough; } bool GetFontStrikethrough() const { return m_fontStrikethrough; }
@@ -414,8 +412,7 @@ public:
bool HasFontPointSize() const { return HasFlag(wxTEXT_ATTR_FONT_POINT_SIZE); } bool HasFontPointSize() const { return HasFlag(wxTEXT_ATTR_FONT_POINT_SIZE); }
bool HasFontPixelSize() const { return HasFlag(wxTEXT_ATTR_FONT_PIXEL_SIZE); } bool HasFontPixelSize() const { return HasFlag(wxTEXT_ATTR_FONT_PIXEL_SIZE); }
bool HasFontItalic() const { return HasFlag(wxTEXT_ATTR_FONT_ITALIC); } bool HasFontItalic() const { return HasFlag(wxTEXT_ATTR_FONT_ITALIC); }
bool HasFontUnderlined() const { return m_fontUnderlined; } bool HasFontUnderlined() const { return HasFlag(wxTEXT_ATTR_FONT_UNDERLINE); }
bool HasFontUnderline() const { return HasFlag(wxTEXT_ATTR_FONT_UNDERLINE); }
bool HasFontStrikethrough() const { return HasFlag(wxTEXT_ATTR_FONT_STRIKETHROUGH); } bool HasFontStrikethrough() const { return HasFlag(wxTEXT_ATTR_FONT_STRIKETHROUGH); }
bool HasFontFaceName() const { return HasFlag(wxTEXT_ATTR_FONT_FACE); } bool HasFontFaceName() const { return HasFlag(wxTEXT_ATTR_FONT_FACE); }
bool HasFontEncoding() const { return HasFlag(wxTEXT_ATTR_FONT_ENCODING); } bool HasFontEncoding() const { return HasFlag(wxTEXT_ATTR_FONT_ENCODING); }
@@ -527,7 +524,6 @@ private:
wxFontStyle m_fontStyle; wxFontStyle m_fontStyle;
wxFontWeight m_fontWeight; wxFontWeight m_fontWeight;
wxFontFamily m_fontFamily; wxFontFamily m_fontFamily;
bool m_fontUnderlined;
wxTextAttrUnderlineType m_fontUnderlineType; wxTextAttrUnderlineType m_fontUnderlineType;
wxColour m_colUnderline; wxColour m_colUnderline;
bool m_fontStrikethrough; bool m_fontStrikethrough;

View File

@@ -1230,16 +1230,22 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
m_textrich->AppendText("And this should be in blue and the text you " m_textrich->AppendText("And this should be in blue and the text you "
"type should be in blue as well.\n"); "type should be in blue as well.\n");
m_textrich->SetDefaultStyle(wxTextAttr()); m_textrich->SetDefaultStyle(wxTextAttr());
m_textrich->AppendText("And there is a ");
wxTextAttr attr = m_textrich->GetDefaultStyle(); wxTextAttr attr = m_textrich->GetDefaultStyle();
attr.SetFontUnderline( /*true, */wxTEXT_ATTR_UNDERLINE_WAVE, *wxRED ); attr.SetFontUnderlined(true);
m_textrich->SetDefaultStyle(attr);
m_textrich->AppendText("\nAnd there");
attr.SetFontUnderlined(false);
m_textrich->SetDefaultStyle(attr);
m_textrich->AppendText(" is a ");
attr.SetFontUnderlined(wxTEXT_ATTR_UNDERLINE_WAVE, *wxRED);
m_textrich->SetDefaultStyle(attr); m_textrich->SetDefaultStyle(attr);
m_textrich->AppendText("mispeled"); m_textrich->AppendText("mispeled");
attr.SetFontUnderline( /*false, */wxTEXT_ATTR_UNDERLINE_NONE ); attr.SetFontUnderlined(false);
m_textrich->SetDefaultStyle(attr); m_textrich->SetDefaultStyle(attr);
m_textrich->AppendText("word"); m_textrich->AppendText(" word.");
m_textrich->SetDefaultStyle(wxTextAttr(*wxBLUE, *wxWHITE)); attr.SetFontUnderlined(wxTEXT_ATTR_UNDERLINE_DOUBLE, *wxGREEN);
const long endPos = m_textrich->GetLastPosition();
m_textrich->SetStyle(endPos - 4, endPos - 2, attr);
// lay out the controls // lay out the controls
wxBoxSizer *column1 = new wxBoxSizer(wxVERTICAL); wxBoxSizer *column1 = new wxBoxSizer(wxVERTICAL);

View File

@@ -328,6 +328,7 @@ void wxColourDatabase::Initialize()
{wxT("INDIAN RED"), 79, 47, 47}, {wxT("INDIAN RED"), 79, 47, 47},
{wxT("KHAKI"), 159, 159, 95}, {wxT("KHAKI"), 159, 159, 95},
{wxT("LIGHT BLUE"), 191, 216, 216}, {wxT("LIGHT BLUE"), 191, 216, 216},
{wxT("LIGHT GREEN"), 0, 128, 0},
{wxT("LIGHT GREY"), 192, 192, 192}, {wxT("LIGHT GREY"), 192, 192, 192},
{wxT("LIGHT STEEL BLUE"), 143, 143, 188}, {wxT("LIGHT STEEL BLUE"), 143, 143, 188},
{wxT("LIME GREEN"), 50, 204, 50}, {wxT("LIME GREEN"), 50, 204, 50},
@@ -347,6 +348,7 @@ void wxColourDatabase::Initialize()
{wxT("MEDIUM VIOLET RED"), 219, 112, 147}, {wxT("MEDIUM VIOLET RED"), 219, 112, 147},
{wxT("MIDNIGHT BLUE"), 47, 47, 79}, {wxT("MIDNIGHT BLUE"), 47, 47, 79},
{wxT("NAVY"), 35, 35, 142}, {wxT("NAVY"), 35, 35, 142},
{wxT("OLIVE"), 128, 128, 0},
{wxT("ORANGE"), 204, 50, 50}, {wxT("ORANGE"), 204, 50, 50},
{wxT("ORANGE RED"), 255, 0, 127}, {wxT("ORANGE RED"), 255, 0, 127},
{wxT("ORCHID"), 219, 112, 219}, {wxT("ORCHID"), 219, 112, 219},
@@ -363,6 +365,7 @@ void wxColourDatabase::Initialize()
{wxT("SPRING GREEN"), 0, 255, 127}, {wxT("SPRING GREEN"), 0, 255, 127},
{wxT("STEEL BLUE"), 35, 107, 142}, {wxT("STEEL BLUE"), 35, 107, 142},
{wxT("TAN"), 219, 147, 112}, {wxT("TAN"), 219, 147, 112},
{wxT("TEAL"), 0, 128, 128},
{wxT("THISTLE"), 216, 191, 216}, {wxT("THISTLE"), 216, 191, 216},
{wxT("TURQUOISE"), 173, 234, 234}, {wxT("TURQUOISE"), 173, 234, 234},
{wxT("VIOLET"), 79, 47, 79}, {wxT("VIOLET"), 79, 47, 79},
@@ -370,13 +373,7 @@ void wxColourDatabase::Initialize()
{wxT("WHEAT"), 216, 216, 191}, {wxT("WHEAT"), 216, 216, 191},
{wxT("WHITE"), 255, 255, 255}, {wxT("WHITE"), 255, 255, 255},
{wxT("YELLOW"), 255, 255, 0}, {wxT("YELLOW"), 255, 255, 0},
{wxT("YELLOW GREEN"), 153, 204, 50}, {wxT("YELLOW GREEN"), 153, 204, 50}
{wxT("wxNAVY"), 0, 0, 128},
{wxT("wxTEAL"), 0, 128, 128},
{wxT("wxLIGHT GREEN"), 0, 128, 0},
{wxT("wxPURPLE"), 128, 0, 128},
{wxT("wxMAROON"), 128, 0, 0},
{wxT("wxDARK GREY"), 128, 128, 128}
}; };
size_t n; size_t n;

View File

@@ -162,7 +162,6 @@ void wxTextAttr::Init()
m_fontSize = 12; m_fontSize = 12;
m_fontStyle = wxFONTSTYLE_NORMAL; m_fontStyle = wxFONTSTYLE_NORMAL;
m_fontWeight = wxFONTWEIGHT_NORMAL; m_fontWeight = wxFONTWEIGHT_NORMAL;
m_fontUnderlined = false;
m_fontUnderlineType = wxTEXT_ATTR_UNDERLINE_NONE; m_fontUnderlineType = wxTEXT_ATTR_UNDERLINE_NONE;
m_fontStrikethrough = false; m_fontStrikethrough = false;
m_fontEncoding = wxFONTENCODING_DEFAULT; m_fontEncoding = wxFONTENCODING_DEFAULT;
@@ -194,7 +193,6 @@ void wxTextAttr::Copy(const wxTextAttr& attr)
m_fontSize = attr.m_fontSize; m_fontSize = attr.m_fontSize;
m_fontStyle = attr.m_fontStyle; m_fontStyle = attr.m_fontStyle;
m_fontWeight = attr.m_fontWeight; m_fontWeight = attr.m_fontWeight;
m_fontUnderlined = attr.m_fontUnderlined;
m_fontUnderlineType = attr.m_fontUnderlineType; m_fontUnderlineType = attr.m_fontUnderlineType;
m_colUnderline = attr.m_colUnderline; m_colUnderline = attr.m_colUnderline;
m_fontStrikethrough = attr.m_fontStrikethrough; m_fontStrikethrough = attr.m_fontStrikethrough;
@@ -261,8 +259,7 @@ bool wxTextAttr::operator== (const wxTextAttr& attr) const
(!HasFontSize() || (GetFontSize() == attr.GetFontSize())) && (!HasFontSize() || (GetFontSize() == attr.GetFontSize())) &&
(!HasFontItalic() || (GetFontStyle() == attr.GetFontStyle())) && (!HasFontItalic() || (GetFontStyle() == attr.GetFontStyle())) &&
(!HasFontWeight() || (GetFontWeight() == attr.GetFontWeight())) && (!HasFontWeight() || (GetFontWeight() == attr.GetFontWeight())) &&
(!HasFontUnderlined() || (GetFontUnderlined() == attr.GetFontUnderlined())) && (!HasFontUnderlined() || ((GetUnderlineType() == attr.GetUnderlineType()) && (GetUnderlineColour() == attr.GetUnderlineColour()) )) &&
( ( GetUnderlineType() == attr.GetUnderlineType() ) && ( GetUnderlineColour() == attr.GetUnderlineColour() ) ) &&
(!HasFontStrikethrough() || (GetFontStrikethrough() == attr.GetFontStrikethrough())) && (!HasFontStrikethrough() || (GetFontStrikethrough() == attr.GetFontStrikethrough())) &&
(!HasFontFaceName() || (GetFontFaceName() == attr.GetFontFaceName())) && (!HasFontFaceName() || (GetFontFaceName() == attr.GetFontFaceName())) &&
(!HasFontEncoding() || (GetFontEncoding() == attr.GetFontEncoding())) && (!HasFontEncoding() || (GetFontEncoding() == attr.GetFontEncoding())) &&
@@ -332,7 +329,8 @@ bool wxTextAttr::EqPartial(const wxTextAttr& attr, bool weakTest) const
if (HasFontItalic() && attr.HasFontItalic() && GetFontStyle() != attr.GetFontStyle()) if (HasFontItalic() && attr.HasFontItalic() && GetFontStyle() != attr.GetFontStyle())
return false; return false;
if (HasFontUnderlined() && attr.HasFontUnderlined() && GetFontUnderlined() != attr.GetFontUnderlined()) if (HasFontUnderlined() && attr.HasFontUnderlined() &&
( (GetUnderlineType() != attr.GetUnderlineType()) || (GetUnderlineColour() != attr.GetUnderlineColour()) ))
return false; return false;
if (HasFontStrikethrough() && attr.HasFontStrikethrough() && GetFontStrikethrough() != attr.GetFontStrikethrough()) if (HasFontStrikethrough() && attr.HasFontStrikethrough() && GetFontStrikethrough() != attr.GetFontStrikethrough())
@@ -507,7 +505,7 @@ bool wxTextAttr::GetFontAttributes(const wxFont& font, int flags)
m_fontWeight = font.GetWeight(); m_fontWeight = font.GetWeight();
if (flags & wxTEXT_ATTR_FONT_UNDERLINE) if (flags & wxTEXT_ATTR_FONT_UNDERLINE)
m_fontUnderlined = font.GetUnderlined(); m_fontUnderlineType = font.GetUnderlined() ? wxTEXT_ATTR_UNDERLINE_SOLID : wxTEXT_ATTR_UNDERLINE_NONE;
if (flags & wxTEXT_ATTR_FONT_STRIKETHROUGH) if (flags & wxTEXT_ATTR_FONT_STRIKETHROUGH)
m_fontStrikethrough = font.GetStrikethrough(); m_fontStrikethrough = font.GetStrikethrough();
@@ -576,8 +574,10 @@ bool wxTextAttr::Apply(const wxTextAttr& style, const wxTextAttr* compareWith)
if (style.HasFontUnderlined()) if (style.HasFontUnderlined())
{ {
if (!(compareWith && compareWith->HasFontUnderlined() && compareWith->GetFontUnderlined() == style.GetFontUnderlined())) if (!(compareWith && compareWith->HasFontUnderlined() &&
destStyle.SetFontUnderlined(style.GetFontUnderlined()); compareWith->GetUnderlineType() == style.GetUnderlineType() &&
compareWith->GetUnderlineColour() == style.GetUnderlineColour()))
destStyle.SetFontUnderlined(style.GetUnderlineType(), style.GetUnderlineColour());
} }
if (style.HasFontStrikethrough()) if (style.HasFontStrikethrough())
@@ -796,7 +796,8 @@ wxTextAttr wxTextAttr::Combine(const wxTextAttr& attr,
} }
wxTextAttr newAttr(colFg, colBg, font); wxTextAttr newAttr(colFg, colBg, font);
newAttr.SetFontUnderline( /*attr.GetFontUnderlined(), */attr.GetUnderlineType(), attr.GetUnderlineColour()); if (attr.HasFontUnderlined())
newAttr.SetFontUnderlined(attr.GetUnderlineType(), attr.GetUnderlineColour());
if (attr.HasAlignment()) if (attr.HasAlignment())
newAttr.SetAlignment(attr.GetAlignment()); newAttr.SetAlignment(attr.GetAlignment());

View File

@@ -126,7 +126,6 @@ static void wxGtkTextApplyTagsFromAttr(GtkWidget *text,
if ( attr.HasFontUnderlined() ) if ( attr.HasFontUnderlined() )
{ {
GtkTextTag *underlineColorTag;
PangoUnderline pangoUnderlineStyle; PangoUnderline pangoUnderlineStyle;
switch ( attr.GetUnderlineType() ) switch ( attr.GetUnderlineType() )
{ {
@@ -144,40 +143,34 @@ static void wxGtkTextApplyTagsFromAttr(GtkWidget *text,
break; break;
} }
g_snprintf(buf, sizeof(buf), "WXFONTUNDERLINEWITHEFFECT"); g_snprintf(buf, sizeof(buf), "WXFONTUNDERLINESTYLE %u",
(unsigned)pangoUnderlineStyle);
tag = gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer ), tag = gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer ),
buf ); buf );
if (!tag) if (!tag)
{
tag = gtk_text_buffer_create_tag( text_buffer, buf, tag = gtk_text_buffer_create_tag( text_buffer, buf,
"underline-set", TRUE, "underline-set", TRUE,
"underline", pangoUnderlineStyle, "underline", pangoUnderlineStyle,
NULL ); NULL );
}
gtk_text_buffer_apply_tag (text_buffer, tag, start, end); gtk_text_buffer_apply_tag (text_buffer, tag, start, end);
#ifdef __WXGTK3__ #ifdef __WXGTK3__
if ( gtk_check_version( 3, 16, 0 ) ) if ( wx_is_at_least_gtk3(16) )
{ {
wxColour color = attr.GetUnderlineColour(); wxColour colour = attr.GetUnderlineColour();
if ( !color.IsOk() ) if ( colour.IsOk() )
{ {
color = attr.GetTextColour(); g_snprintf(buf, sizeof(buf), "WXFONTUNDERLINECOLOUR %u %u %u %u",
if( !color.IsOk() ) colour.Red(), colour.Green(), colour.Blue(), colour.Alpha());
color = *wxBLACK; tag = gtk_text_tag_table_lookup( gtk_text_buffer_get_tag_table( text_buffer ),
} buf );
const GdkColor *gdkColor = attr.GetUnderlineColour().GetColor(); if (!tag)
GdkRGBA color_rgba = { tag = gtk_text_buffer_create_tag( text_buffer, buf,
.red = CLAMP( (double) gdkColor->red / 65535.0, 0.0, 1.0 ),
.green = CLAMP( (double) gdkColor->green / 65535.0, 0.0, 1.0 ),
.blue = CLAMP ((double) gdkColor->blue / 65535.0, 0.0, 1.0 ),
.alpha = 1.0,
};
underlineColorTag = gtk_text_buffer_create_tag( text_buffer, buf,
"underline-rgba-set", TRUE, "underline-rgba-set", TRUE,
"underline-rgba", color_rgba, "underline-rgba", static_cast<const GdkRGBA*>(colour),
NULL ); NULL );
gtk_text_buffer_apply_tag (text_buffer, underlineColorTag, start, end); gtk_text_buffer_apply_tag (text_buffer, tag, start, end);
}
} }
#endif #endif
} }

View File

@@ -85,6 +85,10 @@
#define CFM_UNDERLINETYPE 0x00800000 #define CFM_UNDERLINETYPE 0x00800000
#endif #endif
#ifndef CFU_UNDERLINENONE
#define CFU_UNDERLINENONE 0
#endif
#ifndef CFU_UNDERLINE #ifndef CFU_UNDERLINE
#define CFU_UNDERLINE 1 #define CFU_UNDERLINE 1
#endif #endif
@@ -2879,12 +2883,14 @@ bool wxTextCtrl::MSWSetCharFormat(const wxTextAttr& style, long start, long end)
} }
} }
if ( style.HasFontUnderline() ) if ( style.HasFontUnderlined() )
{ {
cf.dwMask |= CFM_UNDERLINETYPE; cf.dwMask |= CFM_UNDERLINETYPE;
wxTextAttrUnderlineType underlineType = style.GetUnderlineType(); switch ( style.GetUnderlineType() )
switch ( underlineType )
{ {
case wxTEXT_ATTR_UNDERLINE_NONE:
cf.bUnderlineType = CFU_UNDERLINENONE;
break;
case wxTEXT_ATTR_UNDERLINE_SOLID: case wxTEXT_ATTR_UNDERLINE_SOLID:
cf.bUnderlineType = CFU_UNDERLINE; cf.bUnderlineType = CFU_UNDERLINE;
break; break;
@@ -2898,42 +2904,42 @@ bool wxTextCtrl::MSWSetCharFormat(const wxTextAttr& style, long start, long end)
#if _RICHEDIT_VER >= 0x0800 #if _RICHEDIT_VER >= 0x0800
// The colours are coming from https://docs.microsoft.com/en-us/windows/desktop/api/tom/nf-tom-itextdocument2-geteffectcolor. // The colours are coming from https://docs.microsoft.com/en-us/windows/desktop/api/tom/nf-tom-itextdocument2-geteffectcolor.
// Not all values from wxTheColourDatabase are supported as can be seen from the code
// Those are commented out currently
BYTE colour = 0; BYTE colour = 0;
wxColour col = style.GetUnderlineColour(); wxColour col = style.GetUnderlineColour();
if ( col == wxTheColourDatabase->Find( "BLACK" ) ) if ( col == wxNullColour )
colour = 0x01; colour = 0;
else if ( col == wxTheColourDatabase->Find("BLACK") )
colour = 1;
else if ( col == wxTheColourDatabase->Find("BLUE") ) else if ( col == wxTheColourDatabase->Find("BLUE") )
colour = 0x02; colour = 2;
else if ( col == wxTheColourDatabase->Find("CYAN") ) else if ( col == wxTheColourDatabase->Find("CYAN") )
colour = 0x03; colour = 3;
else if ( col == wxTheColourDatabase->Find("GREEN") ) else if ( col == wxTheColourDatabase->Find("GREEN") )
colour = 0x04; colour = 4;
else if ( col == wxTheColourDatabase->Find("MAGENTA") ) else if ( col == wxTheColourDatabase->Find("MAGENTA") )
colour = 0x05; colour = 5;
else if ( col == wxTheColourDatabase->Find("RED") ) else if ( col == wxTheColourDatabase->Find("RED") )
colour = 0x06; colour = 6;
else if ( col == wxTheColourDatabase->Find("YELLOW") ) else if ( col == wxTheColourDatabase->Find("YELLOW") )
colour = 0x07; colour = 7;
else if ( col == wxTheColourDatabase->Find("WHITE") ) else if ( col == wxTheColourDatabase->Find("WHITE") )
colour = 0x08; colour = 8;
else if ( col == wxTheColourDatabase->Find( "WXNAVY" ) ) else if ( col == wxColour(0, 0, 128) ) // navy
colour = 0x09; colour = 9;
else if ( col == wxTheColourDatabase->Find( "WXTEAL" ) ) else if ( col == wxTheColourDatabase->Find("TEAL") )
colour = 0x0A; colour = 10;
else if ( col == wxTheColourDatabase->Find( "WXLIGHT GREEN" ) ) else if ( col == wxTheColourDatabase->Find("LIGHT GREEN") )
colour = 0x0B; colour = 11;
else if ( col == wxTheColourDatabase->Find( "WXPURPLE" ) ) else if ( col == wxColour(128, 0, 128) ) // purple
colour = 0x0C; colour = 12;
else if ( col == wxTheColourDatabase->Find( "WXMAROON" ) ) else if ( col == wxColour(128, 0, 0) ) // maroon
colour = 0x0D; colour = 13;
else if ( col == wxTheColourDatabase->Find("OLIVE") ) else if ( col == wxTheColourDatabase->Find("OLIVE") )
colour = 0x0E; colour = 14;
else if ( col == wxTheColourDatabase->Find( "wxDARK GREY" ) ) else if ( col == wxTheColourDatabase->Find("GREY") )
colour = 0x0F; colour = 15;
else if ( col == wxTheColourDatabase->Find("LIGHT GREY") ) else if ( col == wxTheColourDatabase->Find("LIGHT GREY") )
colour = 0x10; colour = 16;
cf.bUnderlineColor = colour; cf.bUnderlineColor = colour;
#endif #endif
} }

View File

@@ -1089,35 +1089,31 @@ void wxNSTextViewControl::SetStyle(long start,
[attrs setValue:style.GetBackgroundColour().OSXGetNSColor() forKey:NSBackgroundColorAttributeName]; [attrs setValue:style.GetBackgroundColour().OSXGetNSColor() forKey:NSBackgroundColorAttributeName];
if ( style.HasTextColour() ) if ( style.HasTextColour() )
[attrs setValue:style.GetTextColour().OSXGetNSColor() forKey:NSForegroundColorAttributeName]; [attrs setValue:style.GetTextColour().OSXGetNSColor() forKey:NSForegroundColorAttributeName];
if ( style.GetUnderlineType() ) if ( style.HasFontUnderlined() )
{ {
wxTextAttrUnderlineType underlineType = style.GetUnderlineType(); switch ( style.GetUnderlineType() )
switch ( underlineType )
{ {
case wxTEXT_ATTR_UNDERLINE_NONE: case wxTEXT_ATTR_UNDERLINE_NONE:
[attrs setObject:[NSNumber numberWithInt:( NSUnderlineStyleNone )] forKey:NSUnderlineStyleAttributeName]; [attrs setObject:[NSNumber numberWithInt:( NSUnderlineStyleNone )] forKey:NSUnderlineStyleAttributeName];
break; break;
case wxTEXT_ATTR_UNDERLINE_SOLID: case wxTEXT_ATTR_UNDERLINE_SOLID:
[attrs setObject:[NSNumber numberWithInt:( NSUnderlineStyleSingle | NSUnderlineStyleSingle )] forKey:NSUnderlineStyleAttributeName]; [attrs setObject:[NSNumber numberWithInt:( NSUnderlineStyleSingle )] forKey:NSUnderlineStyleAttributeName];
break; break;
case wxTEXT_ATTR_UNDERLINE_DOUBLE: case wxTEXT_ATTR_UNDERLINE_DOUBLE:
[attrs setObject:[NSNumber numberWithInt:( NSUnderlineStyleSingle | NSUnderlineStyleDouble )] forKey:NSUnderlineStyleAttributeName]; [attrs setObject:[NSNumber numberWithInt:( NSUnderlineStyleDouble )] forKey:NSUnderlineStyleAttributeName];
break; break;
case wxTEXT_ATTR_UNDERLINE_WAVE: case wxTEXT_ATTR_UNDERLINE_WAVE:
[attrs setObject:[NSNumber numberWithInt:( NSUnderlineStyleSingle | NSUnderlinePatternDot )] forKey:NSUnderlineStyleAttributeName]; [attrs setObject:[NSNumber numberWithInt:( NSUnderlineStyleSingle | NSUnderlinePatternDot )] forKey:NSUnderlineStyleAttributeName];
break; break;
} }
wxColour color = style.GetUnderlineColour(); wxColour colour = style.GetUnderlineColour();
if ( !color.IsOk() ) if ( colour.IsOk() )
{ {
color = style.GetTextColour(); [attrs setValue:colour.OSXGetNSColor() forKey:NSUnderlineColorAttributeName];
if ( !color.IsOk() )
color = *wxBLACK;
} }
[attrs setValue:color.OSXGetNSColor() forKey:NSUnderlineColorAttributeName];
} }
[m_textView setTypingAttributes:attrs]; [m_textView setTypingAttributes:attrs];
} }
@@ -1138,26 +1134,29 @@ void wxNSTextViewControl::SetStyle(long start,
if( style.HasFontUnderlined() ) if( style.HasFontUnderlined() )
{ {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
if( style.GetUnderlineType() == wxTEXT_ATTR_UNDERLINE_NONE ) switch ( style.GetUnderlineType() )
[dict setObject:[NSNumber numberWithInt:(NSUnderlineStyleNone)] forKey:NSUnderlineStyleAttributeName];
if( style.GetUnderlineType() == wxTEXT_ATTR_UNDERLINE_SOLID )
[dict setObject:[NSNumber numberWithInt:( NSUnderlineStyleSingle )] forKey:NSUnderlineStyleAttributeName];
if( style.GetUnderlineType() == wxTEXT_ATTR_UNDERLINE_DOUBLE )
[dict setObject:[NSNumber numberWithInt:( NSUnderlineStyleDouble )] forKey:NSUnderlineStyleAttributeName];
if( style.GetUnderlineType() == wxTEXT_ATTR_UNDERLINE_WAVE )
[dict setObject:[NSNumber numberWithInt:( NSUnderlinePatternDot )] forKey:NSUnderlineStyleAttributeName];
wxColour color = style.GetUnderlineColour();
if( !color.IsOk() )
{ {
color = style.GetTextColour(); case wxTEXT_ATTR_UNDERLINE_NONE:
if( !color.IsOk() ) [dict setObject:[NSNumber numberWithInt:( NSUnderlineStyleNone )] forKey:NSUnderlineStyleAttributeName];
color = *wxBLACK; break;
}
[dict setValue:color.OSXGetNSColor() forKey:NSUnderlineColorAttributeName];
case wxTEXT_ATTR_UNDERLINE_SOLID:
[dict setObject:[NSNumber numberWithInt:( NSUnderlineStyleSingle )] forKey:NSUnderlineStyleAttributeName];
break;
case wxTEXT_ATTR_UNDERLINE_DOUBLE:
[dict setObject:[NSNumber numberWithInt:( NSUnderlineStyleDouble )] forKey:NSUnderlineStyleAttributeName];
break;
case wxTEXT_ATTR_UNDERLINE_WAVE:
[dict setObject:[NSNumber numberWithInt:( NSUnderlineStyleSingle | NSUnderlinePatternDot )] forKey:NSUnderlineStyleAttributeName];
break;
}
wxColour colour = style.GetUnderlineColour();
if ( colour.IsOk() )
{
[dict setValue:colour.OSXGetNSColor() forKey:NSUnderlineColorAttributeName];
}
[storage addAttributes:dict range:range]; [storage addAttributes:dict range:range];
[dict release]; [dict release];
} }