From 1dbeee57744224e5916ddac05ddce924228bce2a Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sun, 27 Jun 2004 13:10:29 +0000 Subject: [PATCH] implemented underlined text drawing for GTK2 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28040 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/gtk/dcclient.cpp | 22 +++++++++++++++++++++- src/gtk1/dcclient.cpp | 22 +++++++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 7ec0f5c900..e4eb229532 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -136,6 +136,7 @@ wxGTK: - implemented wxColourDialog as native dialog - wxTreeCtrl::GetCount() counts root as well now (compatible with MSW) - added support for wxCHK_3STATE style (GTK2 only) +- implemented text underlining under GTK2 wxMotif: diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 94df22e7d9..ef602b5ea8 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -1467,13 +1467,27 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) wxCHECK_RET( m_layout, wxT("no Pango layout") ); wxCHECK_RET( m_fontdesc, wxT("no Pango font description") ); + bool underlined = m_font.Ok() && m_font.GetUnderlined(); + #if wxUSE_UNICODE const wxCharBuffer data = wxConvUTF8.cWC2MB( text ); #else const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text ); const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); #endif - pango_layout_set_text( m_layout, (const char*) data, strlen( (const char*) data )); + size_t datalen = strlen((const char*)data); + pango_layout_set_text( m_layout, (const char*) 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); + } int w,h; @@ -1520,6 +1534,12 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) // Draw layout. gdk_draw_layout( m_window, m_textGC, x, y, m_layout ); } + + if (underlined) + { + // undo underline attributes setting: + pango_layout_set_attributes(m_layout, NULL); + } wxCoord width = w; wxCoord height = h; diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index 94df22e7d9..ef602b5ea8 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -1467,13 +1467,27 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) wxCHECK_RET( m_layout, wxT("no Pango layout") ); wxCHECK_RET( m_fontdesc, wxT("no Pango font description") ); + bool underlined = m_font.Ok() && m_font.GetUnderlined(); + #if wxUSE_UNICODE const wxCharBuffer data = wxConvUTF8.cWC2MB( text ); #else const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text ); const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); #endif - pango_layout_set_text( m_layout, (const char*) data, strlen( (const char*) data )); + size_t datalen = strlen((const char*)data); + pango_layout_set_text( m_layout, (const char*) 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); + } int w,h; @@ -1520,6 +1534,12 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) // Draw layout. gdk_draw_layout( m_window, m_textGC, x, y, m_layout ); } + + if (underlined) + { + // undo underline attributes setting: + pango_layout_set_attributes(m_layout, NULL); + } wxCoord width = w; wxCoord height = h; -- 2.45.2