many wxItemContainer-related changes:

1. the main function for item insertion is now DoInsertItems() which allows
   for much more efficient addition of many new items at once
2. the items client data management is done entirely in wxItemContainer
   itself, the derived classes don't have to distinguish between void and
   object client data
3. many fixes for sorted controls, in particular implemented wxCB_SORT support
   in wxGTK combobox


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47730 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-07-26 13:54:14 +00:00
parent 7f73c398d5
commit a236aa2058
98 changed files with 2825 additions and 2678 deletions

View File

@@ -284,10 +284,13 @@ void wxCheckListBox::Delete(unsigned int n)
m_aItems.RemoveAt(n);
} // end of wxCheckListBox::Delete
void wxCheckListBox::DoInsertItems(const wxArrayString& items, unsigned int pos)
int wxCheckListBox::DoInsertItems(const wxArrayStringsAdapter& items,
unsigned int pos,
void **clientData,
wxClientDataType type)
{
// pos is validated in wxListBox
wxListBox::DoInsertItems( items, pos );
int result = wxListBox::DoInsertItems( items, pos, clientData, type );
unsigned int n = items.GetCount();
for (unsigned int i = 0; i < n; i++)
{
@@ -301,7 +304,8 @@ void wxCheckListBox::DoInsertItems(const wxArrayString& items, unsigned int pos)
MPFROMP(pNewItem)
);
}
} // end of wxCheckListBox::InsertItems
return result;
} // end of wxCheckListBox::DoInsertItems
bool wxCheckListBox::SetFont ( const wxFont& rFont )
{

View File

@@ -114,69 +114,62 @@ bool wxChoice::Create(
wxChoice::~wxChoice()
{
Free();
Clear();
}
// ----------------------------------------------------------------------------
// adding/deleting items to/from the list
// ----------------------------------------------------------------------------
int wxChoice::DoAppend(
const wxString& rsItem
)
int wxChoice::DoInsertItems(const wxArrayStringsAdapter& items
, unsigned int pos
, void **clientData
, wxClientDataType type
)
{
int nIndex;
int nIndex = wxNOT_FOUND;
LONG nIndexType = 0;
if (m_windowStyle & wxCB_SORT)
bool incrementPos = false;
if ( IsSorted() )
nIndexType = LIT_SORTASCENDING;
else
else if (pos == GetCount())
nIndexType = LIT_END;
nIndex = (int)::WinSendMsg( GetHwnd()
,LM_INSERTITEM
,(MPARAM)nIndexType
,(MPARAM)rsItem.wx_str()
);
return nIndex;
} // end of wxChoice::DoAppend
int wxChoice::DoInsert( const wxString& rsItem, unsigned int pos )
{
wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
wxCHECK_MSG(IsValidInsert(pos), -1, wxT("invalid index"));
if (pos == GetCount())
return DoAppend(rsItem);
int nIndex;
LONG nIndexType = 0;
if (m_windowStyle & wxCB_SORT)
nIndexType = LIT_SORTASCENDING;
else
{
nIndexType = pos;
nIndex = (int)::WinSendMsg( GetHwnd()
,LM_INSERTITEM
,(MPARAM)nIndexType
,(MPARAM)rsItem.wx_str()
);
return nIndex;
} // end of wxChoice::DoInsert
incrementPos = true;
}
void wxChoice::Delete(unsigned int n)
const unsigned int count = items.GetCount();
for( unsigned int i = 0; i < count; ++i )
{
nIndex = (int)::WinSendMsg( GetHwnd()
,LM_INSERTITEM
,(MPARAM)nIndexType
,(MPARAM)items[i].wx_str()
);
if (nIndex < 0)
{
nIndex = wxNOT_FOUND;
break;
}
AssignNewItemClientData(nIndex, clientData, i, type);
if (incrementPos)
++nIndexType;
}
return nIndex;
} // end of wxChoice::DoInsertAppendItemsWithData
void wxChoice::DoDeleteOneItem(unsigned int n)
{
wxCHECK_RET( IsValid(n), wxT("invalid item index in wxChoice::Delete") );
if ( HasClientObjectData() )
{
delete GetClientObject(n);
}
::WinSendMsg(GetHwnd(), LM_DELETEITEM, (MPARAM)n, (MPARAM)0);
} // end of wxChoice::Delete
void wxChoice::Clear()
void wxChoice::DoClear()
{
Free();
::WinSendMsg(GetHwnd(), LM_DELETEALL, (MPARAM)0, (MPARAM)0);
} // end of wxChoice::Clear
@@ -277,16 +270,6 @@ void* wxChoice::DoGetItemClientData(unsigned int n) const
return((void*)rc);
} // end of wxChoice::DoGetItemClientData
void wxChoice::DoSetItemClientObject(unsigned int n, wxClientData* pClientData)
{
DoSetItemClientData(n, pClientData);
} // end of wxChoice::DoSetItemClientObject
wxClientData* wxChoice::DoGetItemClientObject(unsigned int n) const
{
return (wxClientData *)DoGetItemClientData(n);
} // end of wxChoice::DoGetItemClientObject
// ----------------------------------------------------------------------------
// wxOS2 specific helpers
// ----------------------------------------------------------------------------
@@ -399,17 +382,4 @@ bool wxChoice::OS2Command(
return true;
} // end of wxChoice::OS2Command
void wxChoice::Free()
{
if (HasClientObjectData())
{
const unsigned int nCount = GetCount();
for (unsigned int n = 0; n < nCount; n++)
{
delete GetClientObject(n);
}
}
} // end of wxChoice::Free
#endif // wxUSE_CHOICE

View File

@@ -252,7 +252,7 @@ void wxListBox::DoSetFirstItem(int N)
::WinSendMsg(GetHwnd(), LM_SETTOPINDEX, MPFROMLONG(N), (MPARAM)0);
} // end of wxListBox::DoSetFirstItem
void wxListBox::Delete(unsigned int n)
void wxListBox::DoDeleteOneItem(unsigned int n)
{
wxCHECK_RET( IsValid(n),
wxT("invalid index in wxListBox::Delete") );
@@ -260,102 +260,67 @@ void wxListBox::Delete(unsigned int n)
#if wxUSE_OWNER_DRAWN
delete m_aItems[n];
m_aItems.RemoveAt(n);
#else // !wxUSE_OWNER_DRAWN
if (HasClientObjectData())
{
delete GetClientObject(n);
}
#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
::WinSendMsg(GetHwnd(), LM_DELETEITEM, (MPARAM)n, (MPARAM)0);
m_nNumItems--;
} // end of wxListBox::DoSetFirstItem
int wxListBox::DoAppend(const wxString& rsItem)
int wxListBox::DoInsertItems(const wxArrayStringsAdapter & items,
unsigned int pos,
void **clientData,
wxClientDataType type)
{
long lIndex = 0;
LONG lIndexType = 0;
bool incrementPos = false;
if (m_windowStyle & wxLB_SORT)
if (IsSorted())
lIndexType = LIT_SORTASCENDING;
else
else if (pos == GetCount())
lIndexType = LIT_END;
else
{
lIndexType = (LONG)pos;
incrementPos = true;
}
lIndex = (long)::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)rsItem.wx_str());
m_nNumItems++;
int n = wxNOT_FOUND;
unsigned int count = items.GetCount();
for (unsigned int i = 0; i < count; i++)
{
n = (int)::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)items[i].wx_str());
if (n < 0)
{
wxLogLastError(_T("WinSendMsg(LM_INSERTITEM)"));
n = wxNOT_FOUND;
break;
}
++m_nNumItems;
#if wxUSE_OWNER_DRAWN
if (m_windowStyle & wxLB_OWNERDRAW)
{
wxOwnerDrawn* pNewItem = CreateItem(lIndex); // dummy argument
wxScreenDC vDc;
pNewItem->SetName(rsItem);
m_aItems.Insert(pNewItem, lIndex);
::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, (MPARAM)lIndex, MPFROMP(pNewItem));
pNewItem->SetFont(GetFont());
}
if (HasFlag(wxLB_OWNERDRAW))
{
wxOwnerDrawn* pNewItem = CreateItem(n); // dummy argument
wxScreenDC vDc; // FIXME: is it really needed here?
pNewItem->SetName(items[i]);
m_aItems.Insert(pNewItem, n);
::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, (MPARAM)n, MPFROMP(pNewItem));
pNewItem->SetFont(GetFont());
}
#endif
return (int)lIndex;
} // end of wxListBox::DoAppend
AssignNewItemClientData(n, clientData, i, type);
void wxListBox::DoSetItems( const wxArrayString& raChoices,
void** ppClientData )
{
BOOL bHideAndShow = IsShown();
LONG lIndexType = 0;
if (bHideAndShow)
{
::WinShowWindow(GetHwnd(), FALSE);
}
::WinSendMsg(GetHwnd(), LM_DELETEALL, (MPARAM)0, (MPARAM)0);
m_nNumItems = raChoices.GetCount();
for (unsigned int i = 0; i < m_nNumItems; i++)
{
if (m_windowStyle & wxLB_SORT)
lIndexType = LIT_SORTASCENDING;
else
lIndexType = LIT_END;
::WinSendMsg(GetHwnd(), LM_INSERTITEM, (MPARAM)lIndexType, (MPARAM)raChoices[i].wx_str());
if (ppClientData)
{
#if wxUSE_OWNER_DRAWN
wxASSERT_MSG(ppClientData[i] == NULL,
wxT("Can't use client data with owner-drawn listboxes"));
#else // !wxUSE_OWNER_DRAWN
::WinSendMsg(WinUtil_GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(lCount), MPFROMP(ppClientData[i]));
#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
}
if (incrementPos)
++lIndexType;
}
#if wxUSE_OWNER_DRAWN
if ( m_windowStyle & wxLB_OWNERDRAW )
{
//
// First delete old items
//
WX_CLEAR_ARRAY(m_aItems);
return n;
} // end of wxListBox::DoInsertAppendItemsWithData
//
// Then create new ones
//
for (unsigned int ui = 0; ui < m_nNumItems; ui++)
{
wxOwnerDrawn* pNewItem = CreateItem(ui);
pNewItem->SetName(raChoices[ui]);
m_aItems.Add(pNewItem);
::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE, MPFROMLONG(ui), MPFROMP(pNewItem));
}
}
#endif // wxUSE_OWNER_DRAWN
::WinShowWindow(GetHwnd(), TRUE);
} // end of wxListBox::DoSetItems
void wxListBox::Clear()
void wxListBox::DoClear()
{
#if wxUSE_OWNER_DRAWN
unsigned int lUiCount = m_aItems.Count();
@@ -366,15 +331,7 @@ void wxListBox::Clear()
}
m_aItems.Clear();
#else // !wxUSE_OWNER_DRAWN
if (HasClientObjectData())
{
for (unsigned int n = 0; n < m_lNumItems; n++)
{
delete GetClientObject(n);
}
}
#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
#endif // wxUSE_OWNER_DRAWN
::WinSendMsg(GetHwnd(), LM_DELETEALL, (MPARAM)0, (MPARAM)0);
m_nNumItems = 0;
@@ -414,11 +371,6 @@ bool wxListBox::IsSelected( int N ) const
return (lItem == (LONG)N && lItem != LIT_NONE);
} // end of wxListBox::IsSelected
wxClientData* wxListBox::DoGetItemClientObject(unsigned int n) const
{
return (wxClientData *)DoGetItemClientData(n);
}
void* wxListBox::DoGetItemClientData(unsigned int n) const
{
wxCHECK_MSG( IsValid(n), NULL,
@@ -427,11 +379,6 @@ void* wxListBox::DoGetItemClientData(unsigned int n) const
return((void *)::WinSendMsg(GetHwnd(), LM_QUERYITEMHANDLE, MPFROMLONG(n), (MPARAM)0));
} // end of wxListBox::DoGetItemClientData
void wxListBox::DoSetItemClientObject(unsigned int n, wxClientData* pClientData)
{
DoSetItemClientData(n, pClientData);
} // end of wxListBox::DoSetItemClientObject
void wxListBox::DoSetItemClientData(unsigned int n, void* pClientData)
{
wxCHECK_RET( IsValid(n),
@@ -551,34 +498,6 @@ wxString wxListBox::GetString(unsigned int n) const
return sResult;
} // end of wxListBox::GetString
void wxListBox::DoInsertItems(const wxArrayString& asItems, unsigned int nPos)
{
wxCHECK_RET( IsValidInsert(nPos),
wxT("invalid index in wxListBox::InsertItems") );
unsigned int nItems = asItems.GetCount();
for (unsigned int i = 0; i < nItems; i++)
{
int nIndex = (int)::WinSendMsg( GetHwnd(),
LM_INSERTITEM,
MPFROMLONG((LONG)(i + nPos)),
(MPARAM)asItems[i].wx_str() );
wxOwnerDrawn* pNewItem = CreateItem(nIndex);
pNewItem->SetName(asItems[i]);
pNewItem->SetFont(GetFont());
m_aItems.Insert(pNewItem, nIndex);
::WinSendMsg( GetHwnd()
,LM_SETITEMHANDLE
,(MPARAM)((LONG)nIndex)
,MPFROMP(pNewItem)
);
m_nNumItems += nItems;
}
} // end of wxListBox::DoInsertItems
void wxListBox::SetString(unsigned int n, const wxString& rsString)
{
wxCHECK_RET( IsValid(n),