]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxDC::GetPartialTextExtents
authorRobin Dunn <robin@alldunn.com>
Thu, 12 Feb 2004 00:25:49 +0000 (00:25 +0000)
committerRobin Dunn <robin@alldunn.com>
Thu, 12 Feb 2004 00:25:49 +0000 (00:25 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25754 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/dc.h
src/msw/dc.cpp

index 13a549c82e6a82f175c5d0e26533011a500e275c..5a82ad56098fb6d26f813b171be93c19ec0f74bf 100644 (file)
@@ -80,6 +80,7 @@ public:
                                  wxCoord *descent = NULL,
                                  wxCoord *externalLeading = NULL,
                                  wxFont *theFont = NULL) const;
+    virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const;
 
     virtual bool CanDrawBitmap() const;
     virtual bool CanGetTextExtent() const;
index b83bf5ba55a21064b3158c70a02accf438781bf5..4871d1f8ded777c5bd88d379742d1e9219f82071 100644 (file)
@@ -1611,6 +1611,47 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
     }
 }
 
+
+// Each element of the array will be the width of the string up to and
+// including the coresoponding character in text.  
+
+bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const
+{
+    static int maxLenText = -1;
+    static int maxWidth = -1;
+    int fit = 0;
+    SIZE sz = {0,0};
+    int stlen = text.Length();
+
+    if (maxLenText == -1)
+    {
+        // Win9x and WinNT+ have different limits
+        int version = wxGetOsVersion();
+        maxLenText = version == wxWINDOWS_NT ? 65535 : 8192;
+        maxWidth =   version == wxWINDOWS_NT ? INT_MAX : 32767;
+    }
+        
+    widths.Empty();
+    widths.Add(0, stlen);  // fill the array with zeros
+    
+    if (!::GetTextExtentExPoint(GetHdc(),
+                                text.c_str(),           // string to check
+                                wxMin(stlen, maxLenText),
+                                maxWidth, 
+                                &fit,                   // receives count of chars
+                                                        // that will fit
+                                widths.begin(),         // array to fill
+                                &sz)) {
+        // API failed
+        wxLogLastError(wxT("GetTextExtentExPoint"));
+        return false;        
+    } 
+    return true;
+}
+
+
+
+
 void wxDC::SetMapMode(int mode)
 {
     WXMICROWIN_CHECK_HDC