[Commits] (davids) colheader - added proportional resizing

commits at osafoundation.org commits at osafoundation.org
Fri Apr 1 11:33:21 PST 2005


Commit by: davids
Modified files:
internal/wxPython-2.5/src/generic/colheader.cpp 1.41 1.42
internal/wxPython-2.5/wxPython/demo/ColumnHeader.py 1.17 1.18

Log message:

colheader - added proportional resizing
r=TBD



ViewCVS links:
http://cvs.osafoundation.org/index.cgi/internal/wxPython-2.5/src/generic/colheader.cpp.diff?r1=text&tr1=1.41&r2=text&tr2=1.42
http://cvs.osafoundation.org/index.cgi/internal/wxPython-2.5/wxPython/demo/ColumnHeader.py.diff?r1=text&tr1=1.17&r2=text&tr2=1.18

Index: internal/wxPython-2.5/wxPython/demo/ColumnHeader.py
diff -u internal/wxPython-2.5/wxPython/demo/ColumnHeader.py:1.17 internal/wxPython-2.5/wxPython/demo/ColumnHeader.py:1.18
--- internal/wxPython-2.5/wxPython/demo/ColumnHeader.py:1.17	Fri Apr  1 01:32:00 2005
+++ internal/wxPython-2.5/wxPython/demo/ColumnHeader.py	Fri Apr  1 11:33:19 2005
@@ -16,6 +16,7 @@
         # init (non-UI) demo vars
         # NB: should be 17 for Mac; 20 for all other platforms
         # wxColumnHeader can handle it
+        self.baseWidth = 350
         self.colHeight = 20
         self.colStartX = 175
         self.colStartY = 20
@@ -28,7 +29,7 @@
         prompt = "ColumnHeader (%d)" %(cntlID)
         l1 = wx.StaticText( self, -1, prompt, (self.colStartX, self.colStartY), (200, 20) )
 
-        ch1 = wx.colheader.ColumnHeader( self, cntlID, (self.colStartX, self.colStartY + 20), (350, self.colHeight), 0 )
+        ch1 = wx.colheader.ColumnHeader( self, cntlID, (self.colStartX, self.colStartY + 20), (self.baseWidth, self.colHeight), 0 )
         dow = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]
         for v in dow:
             ch1.AppendItem( v, wx.colheader.COLUMNHEADER_JUST_Center, 50, 0, 0, 1 )
@@ -89,33 +90,34 @@
         self.Bind( wx.EVT_CHECKBOX, self.OnTestProportionalResizingCheckBox, cb3 )
         cb3.SetValue( True )
 
+        self.colStartX -= 60
+
     def OnColumnHeaderClick( self, event ):
         ch = event.GetEventObject()
         self.l0.SetLabel( "(%d): clicked - selected (%ld)" %(event.GetId(), ch.GetSelectedItem()) )
         # self.log.write( "Click! (%ld)\n" % event.GetEventType() )
 
-    def OnTestDeleteItemButton( self, event ):
-        ch = self.ch1
-        itemIndex = ch.GetSelectedItem()
-        if (itemIndex >= 0):
-            ch.DeleteItem( itemIndex )
-            self.l0.SetLabel( "(%d): deleted item (%d)" %(ch.GetId(), itemIndex) )
-        else:
-            self.l0.SetLabel( "(%d): no item selected" %(ch.GetId()) )
-
     def OnTestResizeBoundsButton( self, event ):
         ch = self.ch1
-        curWidth = ch.GetTotalUIExtent()
         if (self.stepSize == 1):
             self.stepDir = (-1)
         else:
             if (self.stepSize == (-1)):
                 self.stepDir = 1
         self.stepSize = self.stepSize + self.stepDir
-        newSize = curWidth + 40 * self.stepSize
+        newSize = self.baseWidth + 40 * self.stepSize
         ch.DoSetSize( self.colStartX, self.colStartY + 20, newSize, 20, 0 )
         self.l0.SetLabel( "(%d): resized bounds to %d" %(ch.GetId(), newSize) )
 
+    def OnTestDeleteItemButton( self, event ):
+        ch = self.ch1
+        itemIndex = ch.GetSelectedItem()
+        if (itemIndex >= 0):
+            ch.DeleteItem( itemIndex )
+            self.l0.SetLabel( "(%d): deleted item (%d)" %(ch.GetId(), itemIndex) )
+        else:
+            self.l0.SetLabel( "(%d): no item selected" %(ch.GetId()) )
+
     def OnTestAddBitmapItemButton( self, event ):
         ch = self.ch2
         itemCount = ch.GetItemCount()

Index: internal/wxPython-2.5/src/generic/colheader.cpp
diff -u internal/wxPython-2.5/src/generic/colheader.cpp:1.41 internal/wxPython-2.5/src/generic/colheader.cpp:1.42
--- internal/wxPython-2.5/src/generic/colheader.cpp:1.41	Fri Apr  1 01:32:00 2005
+++ internal/wxPython-2.5/src/generic/colheader.cpp	Fri Apr  1 11:33:18 2005
@@ -196,8 +196,11 @@
 
 	m_BVisibleSelection = bFlagValue;
 
-	RefreshItem( m_ItemSelected );
-	SetViewDirty();
+	if (m_ItemSelected >= 0)
+	{
+		RefreshItem( m_ItemSelected );
+		SetViewDirty();
+	}
 }
 
 bool wxColumnHeader::GetFlagUnicode( void ) const
@@ -608,9 +611,59 @@
 bool wxColumnHeader::RescaleToFit(
 	long				newWidth )
 {
-	if (newWidth <= 0)
+long		scaleItemCount, scaleItemAmount, i;
+long		deltaX, summerX, originX, incX;
+
+	if ((newWidth <= 0) || (m_ItemList == NULL))
 		return false;
 
+	// count non-fixed-width items and tabulate size
+	scaleItemCount = 0;
+	scaleItemAmount = 0;
+	for (i=0; i<m_ItemCount; i++)
+	{
+		if ((m_ItemList[i] == NULL) || m_ItemList[i]->m_BFixedWidth)
+			continue;
+
+		scaleItemCount++;
+		scaleItemAmount += m_ItemList[i]->m_ExtentX;
+	}
+
+	// determine width delta
+	deltaX = newWidth - m_NativeBoundsR.width;
+	summerX = deltaX;
+	originX = 0;
+
+	// move and resize items as appropriate
+	for (i=0; i<m_ItemCount; i++)
+	{
+		if (m_ItemList[i] == NULL)
+			continue;
+
+		// move to new origin
+		m_ItemList[i]->m_OriginX = originX;
+
+		// resize item, if non-fixed
+		if (! m_ItemList[i]->m_BFixedWidth)
+		{
+			scaleItemCount--;
+
+			if (scaleItemCount > 0)
+				incX = (deltaX * m_ItemList[i]->m_ExtentX) / scaleItemAmount;
+			else
+				incX = summerX;
+			m_ItemList[i]->m_ExtentX += incX;
+
+			summerX -= incX;
+		}
+
+		originX += m_ItemList[i]->m_ExtentX;
+	}
+
+	for (i=0; i<m_ItemCount; i++)
+		RefreshItem( i );
+	SetViewDirty();
+
 	return true;
 }
 
@@ -675,9 +728,6 @@
 {
 bool		bSelected;
 
-//	if (! m_BVisibleSelection)
-//		return;
-
 	if ((itemIndex >= 0) && (itemIndex < m_ItemCount))
 		if (m_ItemSelected != itemIndex)
 		{
@@ -833,6 +883,21 @@
 	m_ItemCount += itemCount;
 }
 
+void wxColumnHeader::DisposeItemList( void )
+{
+	if (m_ItemList != NULL)
+	{
+		for (long i=0; i<m_ItemCount; i++)
+			delete m_ItemList[i];
+
+		free( m_ItemList );
+		m_ItemList = NULL;
+	}
+
+	m_ItemCount = 0;
+	m_ItemSelected = wxCOLUMNHEADER_HITTEST_NoPart;
+}
+
 bool wxColumnHeader::GetItemData(
 	long							itemIndex,
 	wxColumnHeaderItem				*info ) const
@@ -1194,21 +1259,6 @@
 	}
 }
 
-void wxColumnHeader::DisposeItemList( void )
-{
-	if (m_ItemList != NULL)
-	{
-		for (long i=0; i<m_ItemCount; i++)
-			delete m_ItemList[i];
-
-		free( m_ItemList );
-		m_ItemList = NULL;
-	}
-
-	m_ItemCount = 0;
-	m_ItemSelected = wxCOLUMNHEADER_HITTEST_NoPart;
-}
-
 // ================
 #if 0
 #pragma mark -
@@ -1460,6 +1510,7 @@
 	, m_BSelected( FALSE )
 	, m_BSortEnabled( FALSE )
 	, m_BSortAscending( FALSE )
+	, m_BFixedWidth( FALSE )
 {
 }
 
@@ -1475,6 +1526,7 @@
 	, m_BSelected( FALSE )
 	, m_BSortEnabled( FALSE )
 	, m_BSortAscending( FALSE )
+	, m_BFixedWidth( FALSE )
 {
 	SetItemData( info );
 }



More information about the Commits mailing list