[Commits] (davids) colheader - checkpoint for bitmap support

commits at osafoundation.org commits at osafoundation.org
Sun Mar 20 12:19:03 PST 2005


Commit by: davids
Modified files:
internal/wxPython-2.5/include/wx/generic/colheader.h 1.11 1.12
internal/wxPython-2.5/src/generic/colheader.cpp 1.18 1.19
internal/wxPython-2.5/wxPython/demo/ColumnHeader.py 1.5 1.6
internal/wxPython-2.5/wxPython/src/colheader.i 1.4 1.5

Log message:

colheader - checkpoint for bitmap support
r=TBD



ViewCVS links:
http://cvs.osafoundation.org/index.cgi/internal/wxPython-2.5/include/wx/generic/colheader.h.diff?r1=text&tr1=1.11&r2=text&tr2=1.12
http://cvs.osafoundation.org/index.cgi/internal/wxPython-2.5/src/generic/colheader.cpp.diff?r1=text&tr1=1.18&r2=text&tr2=1.19
http://cvs.osafoundation.org/index.cgi/internal/wxPython-2.5/wxPython/demo/ColumnHeader.py.diff?r1=text&tr1=1.5&r2=text&tr2=1.6
http://cvs.osafoundation.org/index.cgi/internal/wxPython-2.5/wxPython/src/colheader.i.diff?r1=text&tr1=1.4&r2=text&tr2=1.5

Index: internal/wxPython-2.5/include/wx/generic/colheader.h
diff -u internal/wxPython-2.5/include/wx/generic/colheader.h:1.11 internal/wxPython-2.5/include/wx/generic/colheader.h:1.12
--- internal/wxPython-2.5/include/wx/generic/colheader.h:1.11	Thu Mar 17 10:32:01 2005
+++ internal/wxPython-2.5/include/wx/generic/colheader.h	Sun Mar 20 12:19:00 2005
@@ -19,10 +19,12 @@
 #include "wx/control.h"			// the base class
 #include "wx/dcclient.h"
 #include "wx/font.h"
+#include "wx/bitmap.h"
 
 
 // forward decls
 // class wxColumnHeaderItem;
+// class wxBitmap;
 
 // ----------------------------------------------------------------------------
 // wxColumnHeader: a control that provides a native-appearance column header
@@ -49,10 +51,16 @@
 	void SetItemData(
 		const wxColumnHeaderItem		*info );
 
+	void GetImageRef(
+		wxBitmap			&imageRef );
+	void SetImageRef(
+		wxBitmap			&imageRef,
+		const wxRect		*boundsR );
+
 	void GetLabelText(
-		wxString		&textBuffer );
+		wxString			&textBuffer );
 	void SetLabelText(
-		const wxString	&textBuffer );
+		const wxString		&textBuffer );
 
 	long GetLabelJustification( void );
 	void SetLabelJustification(
@@ -81,7 +89,7 @@
 #if defined(__WXGTK__)
 	static void GTKGetSortArrowBounds(
 		const wxRect		*itemBoundsR,
-		wxRect			*arrowBoundsR );
+		wxRect			*targetBoundsR );
 	static void GTKDrawSortArrow(
 		wxClientDC		*dc,
 		const wxRect		*boundsR,
@@ -94,6 +102,11 @@
 		bool				bSelected );
 #endif
 
+	static void GetBitmapBounds(
+		const wxRect		*itemBoundsR,
+		long				targetJustification,
+		wxRect			*targetBoundsR );
+
 	static long ConvertJustification(
 		long				sourceEnum,
 		bool				bToNative );
@@ -102,6 +115,7 @@
 	wxString				m_LabelTextRef;
 	unsigned long			m_FontID;
 	long					m_TextJust;
+	wxBitmap				*m_ImageRef;
 	long					m_ImageID;
 	long					m_OriginX;
 	long					m_ExtentX;
@@ -135,6 +149,16 @@
 
 	virtual bool Destroy( void );
 
+	// embellish (override) some base class virtuals
+	virtual void DoMoveWindow( int x, int y, int width, int height );
+	virtual bool Enable( bool bEnable = true );
+	virtual bool Show( bool bShow = true );
+	virtual void DoSetSize( int x, int y, int width, int height, int sizeFlags );
+	virtual wxSize DoGetBestSize( void ) const;
+
+	void ResizeToFit( void );
+	long GetTotalUIExtent( void );
+
 	void SetUnicodeFlag(
 		bool				bSetFlag );
 
@@ -157,6 +181,14 @@
 		bool				bActive,
 		bool				bSortEnabled,
 		bool				bSortAscending );
+
+	void GetImageRef(
+		long				itemIndex,
+		wxBitmap			&imageRef );
+	void SetImageRef(
+		long				itemIndex,
+		wxBitmap			&imageRef );
+
 	wxString GetLabelText(
 		long				itemIndex );
 	void SetLabelText(
@@ -184,13 +216,6 @@
 	// implementation only from now on
 	// -------------------------------
 
-	// embellish (override) some base class virtuals
-	virtual void DoMoveWindow( int x, int y, int width, int height );
-	virtual bool Enable( bool bEnable = true );
-	virtual bool Show( bool bShow = true );
-	virtual void DoSetSize( int x, int y, int width, int height, int sizeFlags );
-	virtual wxSize DoGetBestSize( void ) const;
-
 #if defined(__WXMSW__)
 	virtual WXDWORD MSWGetStyle(
 		long		style,

Index: internal/wxPython-2.5/src/generic/colheader.cpp
diff -u internal/wxPython-2.5/src/generic/colheader.cpp:1.18 internal/wxPython-2.5/src/generic/colheader.cpp:1.19
--- internal/wxPython-2.5/src/generic/colheader.cpp:1.18	Thu Mar 17 10:32:01 2005
+++ internal/wxPython-2.5/src/generic/colheader.cpp	Sun Mar 20 12:19:00 2005
@@ -380,13 +380,40 @@
 	int		height,
 	int		sizeFlags )
 {
+	// FIXME: should be - invalidate( origBoundsR )
+
 	wxControl::DoSetSize( x, y, width, height, sizeFlags );
 
 	// FIXME: sloppy hack
 	wxControl::DoGetPosition( &(m_NativeBoundsR.x), &(m_NativeBoundsR.y) );
 	wxControl::DoGetSize( &(m_NativeBoundsR.width), &(m_NativeBoundsR.height) );
 
-	RecalculateItemExtents();
+	// FIXME: should be - invalidate( newBoundsR )
+	// RecalculateItemExtents();
+	SetViewDirty();
+}
+
+void wxColumnHeader::ResizeToFit( void )
+{
+long		extentX;
+
+	extentX = GetTotalUIExtent();
+	DoSetSize( m_NativeBoundsR.x, m_NativeBoundsR.y, extentX, m_NativeBoundsR.height, 0 );
+}
+
+long wxColumnHeader::GetTotalUIExtent( void )
+{
+long		extentX, i;
+
+	extentX = 0;
+	if (m_ItemList != NULL)
+		for (i=0; i<m_ItemCount; i++)
+		{
+			if (m_ItemList[i] != NULL)
+				extentX += m_ItemList[i]->m_ExtentX;
+		}
+
+	return extentX;
 }
 
 // ----------------------------------------------------------------------------
@@ -771,8 +798,41 @@
 		return NULL;
 }
 
+void wxColumnHeader::GetImageRef(
+	long				itemIndex,
+	wxBitmap			&imageRef )
+{
+wxColumnHeaderItem		*itemRef;
+bool					bResultV;
+
+	itemRef = GetItemRef( itemIndex );
+	bResultV = (itemRef != NULL);
+	if (bResultV)
+	{
+		itemRef->GetImageRef( imageRef );
+	}
+	else
+	{
+//		imageRef.Init();
+	}
+}
+
+void wxColumnHeader::SetImageRef(
+	long				itemIndex,
+	wxBitmap			&imageRef )
+{
+wxColumnHeaderItem		*itemRef;
+
+	itemRef = GetItemRef( itemIndex );
+	if (itemRef != NULL)
+	{
+		itemRef->SetImageRef( imageRef, &m_NativeBoundsR );
+		RefreshItem( itemIndex );
+	}
+}
+
 wxString wxColumnHeader::GetLabelText(
-	long			itemIndex )
+	long				itemIndex )
 {
 wxColumnHeaderItem		*itemRef;
 wxString				textBuffer;
@@ -956,9 +1016,9 @@
 long wxColumnHeader::Draw( void )
 {
 wxRect		boundsR;
-long			errStatus;
+long			resultV;
 
-	errStatus = 0;
+	resultV = 0;
 
 #if defined(__WXMSW__)
 	// render native control window
@@ -975,20 +1035,20 @@
 		}
 	}
 
-#elif defined(__WXMAC__)
-	// no DC needed for Mac rendering (yet)
+#elif 0 && defined(__WXMAC__)
+	// no DC needed for Mac rendering (except for bitmaps)
 	for (long i=0; i<m_ItemCount; i++)
 		if (GetItemBounds( i, &boundsR ))
-			errStatus |= m_ItemList[i]->DrawItem( this, NULL, &boundsR );
+			resultV |= m_ItemList[i]->DrawItem( this, NULL, &boundsR );
 #else
 wxClientDC	dc( this );
 
 	for (long i=0; i<m_ItemCount; i++)
 		if (GetItemBounds( i, &boundsR ))
-			errStatus |= m_ItemList[i]->DrawItem( this, &dc, &boundsR );
+			resultV |= m_ItemList[i]->DrawItem( this, &dc, &boundsR );
 #endif
 
-	return errStatus;
+	return resultV;
 }
 
 void wxColumnHeader::SetViewDirty( void )
@@ -1228,6 +1288,7 @@
 	:
 	m_FontID( 0 )
 	, m_TextJust( 0 )
+	, m_ImageRef( NULL )
 	, m_ImageID( -1 )
 	, m_OriginX( 0 )
 	, m_ExtentX( 0 )
@@ -1243,6 +1304,7 @@
 	:
 	m_FontID( 0 )
 	, m_TextJust( 0 )
+	, m_ImageRef( NULL )
 	, m_ImageID( -1 )
 	, m_OriginX( 0 )
 	, m_ExtentX( 0 )
@@ -1256,6 +1318,7 @@
 
 wxColumnHeaderItem::~wxColumnHeaderItem()
 {
+	delete m_ImageRef;
 }
 
 // NB: a copy and nothing else...
@@ -1277,6 +1340,13 @@
 	info->m_BSortAscending = m_BSortAscending;
 
 	GetLabelText( info->m_LabelTextRef );
+
+	if (info->m_ImageRef != m_ImageRef)
+	{
+		if (info->m_ImageRef != NULL)
+			;
+		//GetImageRef( info->m_ImageRef );
+	}
 }
 
 void wxColumnHeaderItem::SetItemData(
@@ -1296,6 +1366,35 @@
 	m_BSortAscending = info->m_BSortAscending;
 
 	SetLabelText( info->m_LabelTextRef );
+	if (m_ImageRef != NULL)
+		SetImageRef( *(info->m_ImageRef), NULL );
+}
+
+void wxColumnHeaderItem::GetImageRef(
+	wxBitmap			&imageRef )
+{
+	if (m_ImageRef != NULL)
+		imageRef = *m_ImageRef;
+//	else
+//		imageRef.Init();
+}
+
+void wxColumnHeaderItem::SetImageRef(
+	wxBitmap			&imageRef,
+	const wxRect		*boundsR )
+{
+wxRect			targetBoundsR;
+
+	delete m_ImageRef;
+	m_ImageRef = new wxBitmap( imageRef );
+
+	if ((boundsR != NULL) && (m_ImageRef != NULL) && m_ImageRef->Ok())
+	{
+		GetBitmapBounds( boundsR, m_TextJust, &targetBoundsR );
+
+		m_ImageRef->SetWidth( targetBoundsR.width );
+		m_ImageRef->SetHeight( targetBoundsR.height );
+	}
 }
 
 void wxColumnHeaderItem::GetLabelText(
@@ -1507,6 +1606,15 @@
 		}
 	}
 
+	// render the bitmap, should one be present
+	if ((dc != NULL) && (m_ImageRef != NULL) && m_ImageRef->Ok())
+	{
+	wxRect		iconBoundsR;
+
+		GetBitmapBounds( boundsR, m_TextJust, &iconBoundsR );
+		dc->DrawBitmap( *m_ImageRef, iconBoundsR.x, iconBoundsR.y, false );
+	}
+
 #if 0
 	// FIXME: need implementation
 	// TODO: can label text and a bitmap (icon) be shown simultaneously?
@@ -1617,6 +1725,16 @@
 #else
 		// FIXME: what about non-(Mac,MSW,GTK) platforms?
 #endif
+
+	}
+
+	// render the bitmap, should one be present
+	if ((dc != NULL) && (m_ImageRef != NULL) && m_ImageRef->Ok())
+	{
+	wxRect		iconBoundsR;
+
+		GetBitmapBounds( &iconBoundsR );
+		dc->DrawBitmap( imageRef, iconBoundsR.x, iconBoundsR.y, false );
 	}
 
 	return 0;
@@ -1711,11 +1829,11 @@
 // static
 void wxColumnHeaderItem::GTKGetSortArrowBounds(
 	const wxRect			*itemBoundsR,
-	wxRect				*arrowBoundsR )
+	wxRect				*targetBoundsR )
 {
 int		sizeX, sizeY, insetX;
 
-	if (arrowBoundsR == NULL)
+	if (targetBoundsR == NULL)
 		return;
 
 	if (itemBoundsR != NULL)
@@ -1724,17 +1842,17 @@
 		sizeY = 12;
 		insetX = 8;
 
-		arrowBoundsR->x = itemBoundsR->x - (sizeX + insetX);
-		arrowBoundsR->y = itemBoundsR->y + (itemBoundsR->height - sizeY) / 2;
-		arrowBoundsR->width = sizeX;
-		arrowBoundsR->height = sizeY;
+		targetBoundsR->x = itemBoundsR->x - (sizeX + insetX);
+		targetBoundsR->y = itemBoundsR->y + (itemBoundsR->height - sizeY) / 2;
+		targetBoundsR->width = sizeX;
+		targetBoundsR->height = sizeY;
 	}
 	else
 	{
-		arrowBoundsR->x =
-		arrowBoundsR->y =
-		arrowBoundsR->width =
-		arrowBoundsR->height = 0;
+		targetBoundsR->x =
+		targetBoundsR->y =
+		targetBoundsR->width =
+		targetBoundsR->height = 0;
 	}
 }
 
@@ -1773,6 +1891,52 @@
 #endif
 
 // static
+void wxColumnHeaderItem::GetBitmapBounds(
+	const wxRect			*itemBoundsR,
+	long					targetJustification,
+	wxRect				*targetBoundsR )
+{
+int		sizeX, sizeY, insetX;
+
+	if (targetBoundsR == NULL)
+		return;
+
+	if (itemBoundsR != NULL)
+	{
+		sizeX =
+		sizeY = 12;
+		insetX = 8;
+
+		targetBoundsR->x = itemBoundsR->x + insetX;
+		targetBoundsR->y = itemBoundsR->y + (itemBoundsR->height - sizeY) / 2;
+		targetBoundsR->width = sizeX;
+		targetBoundsR->height = sizeY;
+
+		switch (targetJustification)
+		{
+		case wxCOLUMNHEADER_JUST_Right:
+			targetBoundsR->x += (itemBoundsR->width - sizeX) - (2 * insetX);
+			break;
+
+		case wxCOLUMNHEADER_JUST_Center:
+			targetBoundsR->x += (itemBoundsR->width - sizeX) / 2;
+			break;
+
+		case wxCOLUMNHEADER_JUST_Left:
+		default:
+			break;
+		}
+	}
+	else
+	{
+		targetBoundsR->x =
+		targetBoundsR->y =
+		targetBoundsR->width =
+		targetBoundsR->height = 0;
+	}
+}
+
+// static
 long wxColumnHeaderItem::ConvertJustification(
 	long			sourceEnum,
 	bool			bToNative )

Index: internal/wxPython-2.5/wxPython/demo/ColumnHeader.py
diff -u internal/wxPython-2.5/wxPython/demo/ColumnHeader.py:1.5 internal/wxPython-2.5/wxPython/demo/ColumnHeader.py:1.6
--- internal/wxPython-2.5/wxPython/demo/ColumnHeader.py:1.5	Thu Mar 17 10:32:02 2005
+++ internal/wxPython-2.5/wxPython/demo/ColumnHeader.py	Sun Mar 20 12:19:01 2005
@@ -1,6 +1,10 @@
-
-import  wx
-import  wx.colheader
+#
+# ColumnHeader.py
+#
+
+import wx
+import wx.colheader
+import images
 
 #----------------------------------------------------------------------
 
@@ -44,23 +48,38 @@
         btn = wx.Button( self, -1, "Delete", (110, 190) )
         self.Bind( wx.EVT_BUTTON, self.OnTestDeleteButton, btn )
 
+        btn = wx.Button( self, -1, "Add Bitmap Item", (210, 190) )
+        self.Bind( wx.EVT_BUTTON, self.OnAddBitmapItemButton, btn )
+
     def OnColumnHeaderClick( self, event ):
         ch = event.GetEventObject()
         self.l0.SetLabel( "clicked (%d) - selected (%ld)" %(event.GetId(), ch.GetSelectedItemIndex()) )
         # self.log.write( "Click! (%ld)\n" % event.GetEventType())
 
     def OnTestResizeButton(self, event):
+        curWidth =  self.ch1.GetTotalUIExtent()
         if (self.stepSize == 1):
             self.stepDir = (-1)
         else:
             if (self.stepSize == (-1)):
                 self.stepDir = 1
         self.stepSize = self.stepSize + self.stepDir
-        self.ch1.DoSetSize( 20, 40, 351 + 40 * self.stepSize, 20, 0 )
+        self.ch1.DoSetSize( 20, 40, curWidth + 40 * self.stepSize, 20, 0 )
 
     def OnTestDeleteButton(self, event):
-        self.ch1.DeleteItem( 1 )
-        self.l0.SetLabel( "deleted item (%d) from (%d)" %(1, 1001) )
+        ch = self.ch1
+        ch.DeleteItem( 1 )
+        self.l0.SetLabel( "deleted item (%d) from (%d)" %(1, ch.GetId()) )
+
+    def OnAddBitmapItemButton(self, event):
+        ch = self.ch2
+        itemCount = ch.GetItemCount() + 1
+        ch.AppendItem( "", wx.colheader.COLUMNHEADER_JUST_Center, 40, 0, 0, 1 )
+        testBmp = images.getTest2Bitmap()
+        ch.SetImageRef( itemCount, testBmp )
+        ch.SetSelectedItemIndex( itemCount - 1 )
+        ch.ResizeToFit()
+        self.l0.SetLabel( "added bitmap item (%d) to (%d)" %(itemCount, ch.GetId()) )
 
 #----------------------------------------------------------------------
 

Index: internal/wxPython-2.5/wxPython/src/colheader.i
diff -u internal/wxPython-2.5/wxPython/src/colheader.i:1.4 internal/wxPython-2.5/wxPython/src/colheader.i:1.5
--- internal/wxPython-2.5/wxPython/src/colheader.i:1.4	Mon Mar  7 11:12:53 2005
+++ internal/wxPython-2.5/wxPython/src/colheader.i	Sun Mar 20 12:19:01 2005
@@ -97,6 +97,9 @@
     virtual void DoSetSize( int x, int y, int width, int height, int sizeFlags );
     virtual wxSize DoGetBestSize( void ) const;
 
+    void ResizeToFit( void );
+    long GetTotalUIExtent( void );
+
     void SetUnicodeFlag(
         bool            bSetFlag );
     long GetSelectedItemIndex( void );
@@ -114,6 +117,12 @@
         bool                bSortAscending = false );
     void DeleteItem(
         long                itemIndex );
+    void GetImageRef(
+        long                itemIndex,
+        wxBitmap        &imageRef );
+    void SetImageRef(
+        long                itemIndex,
+        wxBitmap        &imageRef );
     wxString GetLabelText(
         long                itemIndex );
     void SetLabelText(



More information about the Commits mailing list