]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't eliminate text completely in Ellipsize().
authorVáclav Slavík <vslavik@fastmail.fm>
Wed, 9 Feb 2011 19:52:34 +0000 (19:52 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Wed, 9 Feb 2011 19:52:34 +0000 (19:52 +0000)
If the shortened text is so short there's nothing left of the original,
show one character and "...". This is standard behaviour on both
Windows and OS X, in addition to making lot of sense.

Fixes #11360.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66874 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/ctrlcmn.cpp

index ce76a886250c8fccfaa26649ab2e9ea52f0d2a91..fc41159953df82b7cd0ebac6b4dceed0e28bdfe3 100755 (executable)
@@ -402,6 +402,11 @@ wxString wxControlBase::DoEllipsizeSingleLine(const wxString& curLine, const wxD
                 calc.Init(0, 1);
                 while ( !calc.IsShortEnough() )
                     calc.RemoveFromEnd();
+
+                // always show at least one character of the string:
+                if ( calc.m_nCharsToRemove == len )
+                    return wxString(wxELLIPSE_REPLACEMENT) + curLine[len-1];
+
                 break;
             }
 
@@ -444,6 +449,15 @@ wxString wxControlBase::DoEllipsizeSingleLine(const wxString& curLine, const wxD
                     else
                         calc.RemoveFromEnd();
                 }
+
+                // Always show at least one character of the string.
+                // Additionally, if there's only one character left, prefer
+                // "a..." to "...a":
+                if ( calc.m_nCharsToRemove == len ||
+                     calc.m_nCharsToRemove == len - 1 )
+                {
+                    return curLine[0] + wxString(wxELLIPSE_REPLACEMENT);
+                }
             }
             break;
 
@@ -452,6 +466,11 @@ wxString wxControlBase::DoEllipsizeSingleLine(const wxString& curLine, const wxD
                 calc.Init(len - 1, 1);
                 while ( !calc.IsShortEnough() )
                     calc.RemoveFromStart();
+
+                // always show at least one character of the string:
+                if ( calc.m_nCharsToRemove == len )
+                    return curLine[0] + wxString(wxELLIPSE_REPLACEMENT);
+
                 break;
             }