From 1f91072fc86dca08851486ec19cd573f5bf27279 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 25 Jul 2006 00:33:14 +0000 Subject: [PATCH 1/1] handlers added using AddHandler() last must have the highest priority (patch 1522807) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43590 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/dcclient.h | 1 + src/gtk/dcclient.cpp | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/include/wx/gtk/dcclient.h b/include/wx/gtk/dcclient.h index 0239bc5cdd..de91b5c126 100644 --- a/include/wx/gtk/dcclient.h +++ b/include/wx/gtk/dcclient.h @@ -69,6 +69,7 @@ protected: wxCoord *descent = (wxCoord *) NULL, wxCoord *externalLeading = (wxCoord *) NULL, wxFont *theFont = (wxFont *) NULL) const; + virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; virtual void DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); virtual void DoSetClippingRegionAsRegion( const wxRegion ®ion ); diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 15b718f7a5..6022888051 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -1775,6 +1775,51 @@ void wxWindowDC::DoGetTextExtent(const wxString &string, pango_layout_set_font_description( m_layout, m_fontdesc ); } + +bool wxWindowDC::DoGetPartialTextExtents(const wxString& text, + wxArrayInt& widths) const +{ + const size_t len = text.length(); + widths.Empty(); + widths.Add(0, len); + + if (text.empty()) + return true; + + // Set layout's text + const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(text, m_font); + if ( !dataUTF8 ) + { + // hardly ideal, but what else can we do if conversion failed? + wxLogLastError(wxT("DoGetPartialTextExtents")); + return false; + } + + pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); + + // Calculate the position of each character based on the widths of + // the previous characters + + // Code borrowed from Scintilla's PlatGTK + PangoLayoutIter *iter = pango_layout_get_iter(m_layout); + PangoRectangle pos; + pango_layout_iter_get_cluster_extents(iter, NULL, &pos); + size_t i = 0; + while (pango_layout_iter_next_cluster(iter)) + { + pango_layout_iter_get_cluster_extents(iter, NULL, &pos); + int position = PANGO_PIXELS(pos.x); + size_t curIndex = pango_layout_iter_get_index(iter); + widths[i++] = position; + } + while (i < len) + widths[i++] = PANGO_PIXELS(pos.x + pos.width); + pango_layout_iter_free(iter); + + return true; +} + + wxCoord wxWindowDC::GetCharWidth() const { pango_layout_set_text( m_layout, "H", 1 ); -- 2.45.2