[Commits] (davids) colheader - added new item insertion support,
fixed 2-3 bugs, updated demo
commits at osafoundation.org
commits at osafoundation.org
Sun Apr 3 00:49:24 PST 2005
Commit by: davids
Modified files:
internal/wxPython-2.5/include/wx/generic/colheader.h 1.19 1.20
internal/wxPython-2.5/src/generic/colheader.cpp 1.42 1.43
internal/wxPython-2.5/wxPython/demo/ColumnHeader.py 1.18 1.19
internal/wxPython-2.5/wxPython/src/colheader.i 1.10 1.11
Log message:
colheader - added new item insertion support, fixed 2-3 bugs, updated demo
r=TBD
ViewCVS links:
http://cvs.osafoundation.org/index.cgi/internal/wxPython-2.5/include/wx/generic/colheader.h.diff?r1=text&tr1=1.19&r2=text&tr2=1.20
http://cvs.osafoundation.org/index.cgi/internal/wxPython-2.5/src/generic/colheader.cpp.diff?r1=text&tr1=1.42&r2=text&tr2=1.43
http://cvs.osafoundation.org/index.cgi/internal/wxPython-2.5/wxPython/demo/ColumnHeader.py.diff?r1=text&tr1=1.18&r2=text&tr2=1.19
http://cvs.osafoundation.org/index.cgi/internal/wxPython-2.5/wxPython/src/colheader.i.diff?r1=text&tr1=1.10&r2=text&tr2=1.11
Index: internal/wxPython-2.5/include/wx/generic/colheader.h
diff -u internal/wxPython-2.5/include/wx/generic/colheader.h:1.19 internal/wxPython-2.5/include/wx/generic/colheader.h:1.20
--- internal/wxPython-2.5/include/wx/generic/colheader.h:1.19 Fri Apr 1 01:32:00 2005
+++ internal/wxPython-2.5/include/wx/generic/colheader.h Sun Apr 3 00:49:21 2005
@@ -209,6 +209,14 @@
bool bActive,
bool bSortEnabled,
bool bSortAscending );
+ void AddItem(
+ long beforeIndex,
+ const wxString &textBuffer,
+ long textJust,
+ long extentX,
+ bool bActive,
+ bool bSortEnabled,
+ bool bSortAscending );
void GetBitmapRef(
long itemIndex,
@@ -257,9 +265,10 @@
wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL );
protected:
- void AppendItemList(
+ void AddItemList(
const wxColumnHeaderItem *itemList,
- long itemCount );
+ long itemCount,
+ long beforeIndex );
void OnClick_SelectOrToggleSort(
long itemIndex,
Index: internal/wxPython-2.5/wxPython/src/colheader.i
diff -u internal/wxPython-2.5/wxPython/src/colheader.i:1.10 internal/wxPython-2.5/wxPython/src/colheader.i:1.11
--- internal/wxPython-2.5/wxPython/src/colheader.i:1.10 Fri Apr 1 01:32:01 2005
+++ internal/wxPython-2.5/wxPython/src/colheader.i Sun Apr 3 00:49:22 2005
@@ -130,6 +130,14 @@
bool bSelected = false,
bool bSortEnabled = true,
bool bSortAscending = false );
+ void AddItem(
+ long beforeIndex,
+ const wxString &textBuffer,
+ long textJust,
+ long extentX,
+ bool bSelected = false,
+ bool bSortEnabled = true,
+ bool bSortAscending = false );
void DeleteItem(
long itemIndex );
void GetBitmapRef(
Index: internal/wxPython-2.5/wxPython/demo/ColumnHeader.py
diff -u internal/wxPython-2.5/wxPython/demo/ColumnHeader.py:1.18 internal/wxPython-2.5/wxPython/demo/ColumnHeader.py:1.19
--- internal/wxPython-2.5/wxPython/demo/ColumnHeader.py:1.18 Fri Apr 1 11:33:19 2005
+++ internal/wxPython-2.5/wxPython/demo/ColumnHeader.py Sun Apr 3 00:49:22 2005
@@ -16,7 +16,8 @@
# init (non-UI) demo vars
# NB: should be 17 for Mac; 20 for all other platforms
# wxColumnHeader can handle it
- self.baseWidth = 350
+ self.baseWidth1 = 350
+ self.baseWidth2 = 270
self.colHeight = 20
self.colStartX = 175
self.colStartY = 20
@@ -29,10 +30,10 @@
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), (self.baseWidth, self.colHeight), 0 )
+ ch1 = wx.colheader.ColumnHeader( self, cntlID, (self.colStartX, self.colStartY + 20), (self.baseWidth1, 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 )
+ ch1.AddItem( -1, v, wx.colheader.COLUMNHEADER_JUST_Center, 50, 0, 0, 1 )
ch1.SetSelectedItem( 0 )
self.ch1 = ch1
self.Bind( wx.colheader.EVT_COLUMNHEADER_SELCHANGED, self.OnColumnHeaderClick, ch1 )
@@ -43,11 +44,10 @@
prompt = "ColumnHeader (%d)" %(cntlID)
l2 = wx.StaticText( self, -1, prompt, (self.colStartX, self.colStartY + 80), (200, 20) )
- # FIXME: charset - conditionalize the high ASCII value
- ch2 = wx.colheader.ColumnHeader( self, cntlID, (self.colStartX, self.colStartY + 100), (270, self.colHeight), 0 )
+ ch2 = wx.colheader.ColumnHeader( self, cntlID, (self.colStartX, self.colStartY + 100), (self.baseWidth2, self.colHeight), 0 )
coffeeNames = [ "Juan", "Valdez", "coffee guy" ]
for i, v in enumerate( coffeeNames ):
- ch2.AppendItem( v, wx.colheader.COLUMNHEADER_JUST_Left + i, 90, 0, 1, 1 )
+ ch2.AddItem( -1, v, wx.colheader.COLUMNHEADER_JUST_Left + i, 90, 0, 1, 1 )
ch2.SetSelectedItem( 0 )
self.ch2 = ch2
@@ -56,13 +56,13 @@
# add demo UI controls
miscControlsY = 175
- l0O = wx.StaticText( self, -1, "Last Action", (10, miscControlsY), (150, 20) )
- l0 = wx.StaticText( self, -1, "[result]", (10, miscControlsY + 20), (150, 20) )
+ l0O = wx.StaticText( self, -1, "Last Action", (10, miscControlsY + 25), (150, 20) )
+ l0 = wx.StaticText( self, -1, "[result]", (10, miscControlsY + 45), (150, 20) )
self.l0 = l0
prompt = "[Unicode build: %d]" %(ch1.GetFlagUnicode())
hasUnicode = ch1.GetFlagUnicode()
- l1 = wx.StaticText( self, -1, prompt, (10, miscControlsY + 60), (150, 20) )
+ l1 = wx.StaticText( self, -1, prompt, (10, miscControlsY + 85), (150, 20) )
btn = wx.Button( self, -1, "Resize Bounds", (10, self.colStartY) )
self.Bind( wx.EVT_BUTTON, self.OnTestResizeBoundsButton, btn )
@@ -76,6 +76,9 @@
btn = wx.Button( self, -1, "Resize Division", (10, self.colStartY + 80 + 10 + 25) )
self.Bind( wx.EVT_BUTTON, self.OnTestResizeDivisionButton, btn )
+ btn = wx.Button( self, -1, "Deselect", (10, self.colStartY + 80 + 10 + 50) )
+ self.Bind( wx.EVT_BUTTON, self.OnTestDeselectButton, btn )
+
self.colStartX += 60
cb1 = wx.CheckBox( self, -1, "Enable", (self.colStartX, miscControlsY), (100, 20), wx.NO_BORDER )
@@ -98,14 +101,14 @@
# self.log.write( "Click! (%ld)\n" % event.GetEventType() )
def OnTestResizeBoundsButton( self, event ):
- ch = self.ch1
if (self.stepSize == 1):
self.stepDir = (-1)
else:
if (self.stepSize == (-1)):
self.stepDir = 1
self.stepSize = self.stepSize + self.stepDir
- newSize = self.baseWidth + 40 * self.stepSize
+ ch = self.ch1
+ newSize = self.baseWidth1 + 40 * self.stepSize
ch.DoSetSize( self.colStartX, self.colStartY + 20, newSize, 20, 0 )
self.l0.SetLabel( "(%d): resized bounds to %d" %(ch.GetId(), newSize) )
@@ -118,16 +121,23 @@
else:
self.l0.SetLabel( "(%d): no item selected" %(ch.GetId()) )
+ def OnTestDeselectButton( self, event ):
+ self.ch1.SetSelectedItem( -1 )
+ self.ch2.SetSelectedItem( -1 )
+
def OnTestAddBitmapItemButton( self, event ):
ch = self.ch2
itemCount = ch.GetItemCount()
- if itemCount <= 8:
- ch.AppendItem( "", wx.colheader.COLUMNHEADER_JUST_Center, 40, 0, 0, 1 )
+ if (itemCount <= 8):
+ itemIndex = ch.GetSelectedItem()
+ if (itemIndex < 0):
+ itemIndex = itemCount
+ ch.AddItem( itemIndex, "", wx.colheader.COLUMNHEADER_JUST_Center, 40, 0, 0, 1 )
testBmp = images.getTest2Bitmap()
- ch.SetBitmapRef( itemCount, testBmp )
- ch.SetSelectedItem( itemCount )
+ ch.SetBitmapRef( itemIndex, testBmp )
+ ch.SetSelectedItem( itemIndex )
ch.ResizeToFit()
- self.l0.SetLabel( "(%d): added bitmap item (%d)" %(ch.GetId(), itemCount) )
+ self.l0.SetLabel( "(%d): added bitmap item (%d)" %(ch.GetId(), itemIndex) )
else:
self.l0.SetLabel( "(%d): enough items!" %(ch.GetId()) )
@@ -139,7 +149,7 @@
ch.ResizeDivision( itemIndex, curExtent.x - 5 )
self.l0.SetLabel( "(%d): resized btw. %d and %d" %(ch.GetId(), itemIndex - 1, itemIndex) )
else:
- self.l0.SetLabel( "(%d): no item selected" %(ch.GetId()) )
+ self.l0.SetLabel( "(%d): no valid item selected" %(ch.GetId()) )
def OnTestEnableCheckBox( self, event ):
curEnabled = self.ch1.IsEnabled()
Index: internal/wxPython-2.5/src/generic/colheader.cpp
diff -u internal/wxPython-2.5/src/generic/colheader.cpp:1.42 internal/wxPython-2.5/src/generic/colheader.cpp:1.43
--- internal/wxPython-2.5/src/generic/colheader.cpp:1.42 Fri Apr 1 11:33:18 2005
+++ internal/wxPython-2.5/src/generic/colheader.cpp Sun Apr 3 00:49:21 2005
@@ -670,10 +670,17 @@
bool wxColumnHeader::ResizeToFit( void )
{
long extentX;
+bool bScaling;
+
+ // temporarily turn off proportional resizing
+ bScaling = m_BProportionalResizing;
+ m_BProportionalResizing = false;
extentX = GetTotalUIExtent();
DoSetSize( m_NativeBoundsR.x, m_NativeBoundsR.y, extentX, m_NativeBoundsR.height, 0 );
+ m_BProportionalResizing = true;
+
return true;
}
@@ -728,34 +735,33 @@
{
bool bSelected;
- if ((itemIndex >= 0) && (itemIndex < m_ItemCount))
- if (m_ItemSelected != itemIndex)
+ if (m_ItemSelected != itemIndex)
+ {
+ for (long i=0; i<m_ItemCount; i++)
{
- for (long i=0; i<m_ItemCount; i++)
- {
- bSelected = (i == itemIndex);
- if ((m_ItemList != NULL) && (m_ItemList[i] != NULL))
- m_ItemList[i]->SetFlagAttribute( wxCOLUMNHEADER_FLAGATTR_Selected, bSelected );
+ bSelected = (i == itemIndex);
+ if ((m_ItemList != NULL) && (m_ItemList[i] != NULL))
+ m_ItemList[i]->SetFlagAttribute( wxCOLUMNHEADER_FLAGATTR_Selected, bSelected );
#if defined(__WXMSW__)
- bool bSortEnabled, bSortAscending;
+ bool bSortEnabled, bSortAscending;
- bSortEnabled = false;
- bSortAscending = false;
- if ((m_ItemList != NULL) && (m_ItemList[i] != NULL))
- {
- bSortEnabled = m_ItemList[i]->GetFlagAttribute( wxCOLUMNHEADER_FLAGATTR_SortEnabled );
- bSortAscending = m_ItemList[i]->GetFlagAttribute( wxCOLUMNHEADER_FLAGATTR_SortDirection );
- }
+ bSortEnabled = false;
+ bSortAscending = false;
+ if ((m_ItemList != NULL) && (m_ItemList[i] != NULL))
+ {
+ bSortEnabled = m_ItemList[i]->GetFlagAttribute( wxCOLUMNHEADER_FLAGATTR_SortEnabled );
+ bSortAscending = m_ItemList[i]->GetFlagAttribute( wxCOLUMNHEADER_FLAGATTR_SortDirection );
+ }
- (void)Win32ItemSelect( i, bSelected, bSortEnabled, bSortAscending );
+ (void)Win32ItemSelect( i, bSelected, bSortEnabled, bSortAscending );
#endif
- }
+ }
- m_ItemSelected = itemIndex;
+ m_ItemSelected = itemIndex;
- SetViewDirty();
- }
+ SetViewDirty();
+ }
}
void wxColumnHeader::DeleteItem(
@@ -792,19 +798,31 @@
if (m_ItemSelected == itemIndex)
m_ItemSelected = wxCOLUMNHEADER_HITTEST_NoPart;
- // NB: AppendItem doesn't do this
+ // NB: AddItem doesn't do this
SetViewDirty();
}
}
}
void wxColumnHeader::AppendItem(
- const wxString &textBuffer,
- long textJust,
- long extentX,
- bool bSelected,
- bool bSortEnabled,
- bool bSortAscending )
+ const wxString &textBuffer,
+ long textJust,
+ long extentX,
+ bool bSelected,
+ bool bSortEnabled,
+ bool bSortAscending )
+{
+ AddItem( -1, textBuffer, textJust, extentX, bSelected, bSortEnabled, bSortAscending );
+}
+
+void wxColumnHeader::AddItem(
+ long beforeIndex,
+ const wxString &textBuffer,
+ long textJust,
+ long extentX,
+ bool bSelected,
+ bool bSortEnabled,
+ bool bSortAscending )
{
wxColumnHeaderItem itemInfo;
wxPoint targetExtent;
@@ -819,6 +837,7 @@
itemInfo.m_FontID = 0;
#endif
+ // set specified values
itemInfo.m_LabelTextRef = textBuffer;
itemInfo.m_TextJust = textJust;
itemInfo.m_ExtentX = extentX;
@@ -826,16 +845,26 @@
itemInfo.m_BSortEnabled = bSortEnabled;
itemInfo.m_BSortAscending = bSortAscending;
- targetExtent = GetUIExtent( m_ItemCount - 1 );
- originX = ((targetExtent.x > 0) ? targetExtent.x : 0);
+ if ((beforeIndex < 0) || (beforeIndex > m_ItemCount))
+ beforeIndex = m_ItemCount;
+
+ // determine new item origin
+ if (beforeIndex > 0)
+ {
+ targetExtent = GetUIExtent( beforeIndex - 1 );
+ originX = ((targetExtent.x > 0) ? targetExtent.x : 0);
+ itemInfo.m_OriginX = originX + targetExtent.y;
+ }
+ else
+ itemInfo.m_OriginX = 0;
- itemInfo.m_OriginX = originX + targetExtent.y;
- AppendItemList( &itemInfo, 1 );
+ AddItemList( &itemInfo, 1, beforeIndex );
}
-void wxColumnHeader::AppendItemList(
+void wxColumnHeader::AddItemList(
const wxColumnHeaderItem *itemList,
- long itemCount )
+ long itemCount,
+ long beforeIndex )
{
wxColumnHeaderItem **newItemList;
long targetIndex, i;
@@ -844,12 +873,18 @@
if ((itemList == NULL) || (itemCount <= 0))
return;
+ if ((beforeIndex < 0) || (beforeIndex > m_ItemCount))
+ beforeIndex = m_ItemCount;
+
// allocate new item list and copy the original list items into it
newItemList = (wxColumnHeaderItem**)calloc( m_ItemCount + itemCount, sizeof(wxColumnHeaderItem*) );
if (m_ItemList != NULL)
{
for (i=0; i<m_ItemCount; i++)
- newItemList[i] = m_ItemList[i];
+ {
+ targetIndex = ((i < beforeIndex) ? i : itemCount + i);
+ newItemList[targetIndex] = m_ItemList[i];
+ }
free( m_ItemList );
}
@@ -858,7 +893,7 @@
// append the new items
for (i=0; i<itemCount; i++)
{
- targetIndex = m_ItemCount + i;
+ targetIndex = beforeIndex + i;
m_ItemList[targetIndex] = new wxColumnHeaderItem( &itemList[i] );
bIsSelected = (m_ItemList[targetIndex]->m_BSelected && m_ItemList[targetIndex]->m_BEnabled);
@@ -879,8 +914,18 @@
m_ItemSelected = targetIndex;
}
- // update the counter
+ // update the item count
m_ItemCount += itemCount;
+
+ // if this was an insertion, refresh the end items
+ if (beforeIndex < m_ItemCount - itemCount)
+ {
+ RecalculateItemExtents();
+ for (i=0; i<itemCount; i++)
+ RefreshItem( i + (m_ItemCount - itemCount) );
+ }
+
+ SetViewDirty();
}
void wxColumnHeader::DisposeItemList( void )
More information about the Commits
mailing list