[Commits] (davids) colheader - checkpoint for smart label text truncation

commits at osafoundation.org commits at osafoundation.org
Fri Apr 15 16:28:39 PDT 2005


Commit by: davids
Modified files:
internal/wxPython-2.5/include/wx/generic/colheader.h 1.31 1.32
internal/wxPython-2.5/src/generic/colheader.cpp 1.66 1.67

Log message:

colheader - checkpoint for smart label text truncation
r=TBD



ViewCVS links:
http://cvs.osafoundation.org/index.cgi/internal/wxPython-2.5/include/wx/generic/colheader.h.diff?r1=text&tr1=1.31&r2=text&tr2=1.32
http://cvs.osafoundation.org/index.cgi/internal/wxPython-2.5/src/generic/colheader.cpp.diff?r1=text&tr1=1.66&r2=text&tr2=1.67

Index: internal/wxPython-2.5/include/wx/generic/colheader.h
diff -u internal/wxPython-2.5/include/wx/generic/colheader.h:1.31 internal/wxPython-2.5/include/wx/generic/colheader.h:1.32
--- internal/wxPython-2.5/include/wx/generic/colheader.h:1.31	Wed Apr 13 21:15:13 2005
+++ internal/wxPython-2.5/include/wx/generic/colheader.h	Fri Apr 15 16:28:38 2005
@@ -80,6 +80,10 @@
 		long			originX,
 		long			extentX );
 
+	void GetTextUIExtent(
+		long			&originX,
+		long			&extentX ) const;
+
 	bool GetFlagAttribute(
 		wxColumnHeaderFlagAttr		flagEnum ) const;
 	bool SetFlagAttribute(
@@ -102,6 +106,12 @@
 		bool				bVisibleSelection );
 #endif
 
+	long TruncateLabelText(
+		wxDC			*dc,
+		wxString			&targetStr,
+		long				maxWidth,
+		long				&charCount );
+
 public:
 	static void GenericDrawSelection(
 		wxClientDC		*dc,

Index: internal/wxPython-2.5/src/generic/colheader.cpp
diff -u internal/wxPython-2.5/src/generic/colheader.cpp:1.66 internal/wxPython-2.5/src/generic/colheader.cpp:1.67
--- internal/wxPython-2.5/src/generic/colheader.cpp:1.66	Wed Apr 13 21:15:14 2005
+++ internal/wxPython-2.5/src/generic/colheader.cpp	Fri Apr 15 16:28:38 2005
@@ -299,9 +299,7 @@
 		if ((m_ItemList != NULL) && (m_ItemList[i] != NULL))
 			m_ItemList[i]->SetFlagAttribute( wxCOLUMNHEADER_FLAGATTR_Enabled, bEnable );
 
-#if defined(__WXMSW__)
-		Win32ItemRefresh( i, false );
-#endif
+		RefreshItem( i );
 	}
 
 	// force a redraw
@@ -803,9 +801,7 @@
 			if ((m_ItemList != NULL) && (m_ItemList[i] != NULL))
 				m_ItemList[i]->SetFlagAttribute( wxCOLUMNHEADER_FLAGATTR_Selected, bSelected );
 
-#if defined(__WXMSW__)
-			Win32ItemRefresh( i, false );
-#endif
+			RefreshItem( i );
 		}
 
 		m_ItemSelected = itemIndex;
@@ -1805,6 +1801,22 @@
 		m_ExtentX = extentX;
 }
 
+// NB: horizontal item layout is as follows:
+// || InsetX | label text or bitmap | InsetX | sort arrow | InsetX ||
+//
+void wxColumnHeaderItem::GetTextUIExtent(
+	long			&originX,
+	long			&extentX ) const
+{
+	originX = m_OriginX + wxCHI_kMetricInsetX;
+	if (extentX > m_ExtentX)
+		extentX = m_ExtentX;
+
+	extentX = m_ExtentX - ((3 * wxCHI_kMetricInsetX) + wxCHI_kMetricArrowSizeX);
+	if (extentX < 0)
+		extentX = 0;
+}
+
 bool wxColumnHeaderItem::GetFlagAttribute(
 	wxColumnHeaderFlagAttr		flagEnum ) const
 {
@@ -2091,6 +2103,57 @@
 	return 0;
 }
 
+long wxColumnHeaderItem::TruncateLabelText(
+	wxDC			*dc,
+	wxString			&targetStr,
+	long				maxWidth,
+	long				&charCount )
+{
+wxString		truncStr, ellipsisStr;
+wxCoord		targetWidth, targetHeight, ellipsisWidth;
+bool			bContinue;
+
+	if ((dc == NULL) || (maxWidth <= 0))
+		return 0;
+
+	charCount = targetStr.Length();
+	if (charCount <= 0)
+		return 0;
+
+	// determine the minimum width
+	ellipsisStr = wxString( wxT("...") );
+	dc->GetTextExtent( ellipsisStr, &ellipsisWidth, &targetHeight );
+	if (ellipsisWidth > maxWidth)
+		return 0;
+
+	// determine if the string can fit inside the current width
+	dc->GetTextExtent( targetStr, &targetWidth, &targetHeight );
+	bContinue = (targetWidth > maxWidth);
+
+	if (bContinue)
+	{
+		charCount--;
+
+		if (charCount > 0)
+		{
+			truncStr = targetStr.Left( charCount );
+			dc->GetTextExtent( truncStr, &targetWidth, &targetHeight );
+			bContinue = (targetWidth + ellipsisWidth > maxWidth);
+
+			if (! bContinue)
+				targetStr = truncStr + ellipsisStr;
+		}
+		else
+		{
+			targetStr = ellipsisStr;
+			targetWidth = ellipsisWidth;
+			bContinue = false;
+		}
+	}
+
+	return (long)targetWidth;
+}
+
 // ================
 #if 0
 #pragma mark -



More information about the Commits mailing list