#endif
#include "wx/msw/private.h"
+#include "wx/msw/dc.h"
#include <windowsx.h>
wxListBox::wxListBox()
{
m_noItems = 0;
- m_selected = 0;
+ m_updateHorizontalExtent = false;
}
bool wxListBox::Create(wxWindow *parent,
const wxString& name)
{
m_noItems = 0;
- m_selected = 0;
+ m_updateHorizontalExtent = false;
// initialize base class fields
if ( !CreateControl(parent, id, pos, size, style, validator, name) )
Append(choices[i]);
}
- // now we can compute our best size correctly, so do it if necessary
+ // now we can compute our best size correctly, so do it again
+ InvalidateBestSize();
SetInitialSize(size);
return true;
return msStyle;
}
+void wxListBox::OnInternalIdle()
+{
+ wxWindow::OnInternalIdle();
+
+ if (m_updateHorizontalExtent)
+ {
+ SetHorizontalExtent(wxEmptyString);
+ m_updateHorizontalExtent = false;
+ }
+}
+
// ----------------------------------------------------------------------------
// implementation of wxListBoxBase methods
// ----------------------------------------------------------------------------
SendMessage(GetHwnd(), LB_DELETESTRING, n, 0);
m_noItems--;
- SetHorizontalExtent(wxEmptyString);
+ // SetHorizontalExtent(wxEmptyString); can be slow
+ m_updateHorizontalExtent = true;
+
+ UpdateOldSelections();
}
int wxListBox::FindString(const wxString& s, bool bCase) const
ListBox_ResetContent(GetHwnd());
m_noItems = 0;
- SetHorizontalExtent();
+ m_updateHorizontalExtent = true;
+
+ UpdateOldSelections();
}
void wxListBox::Free()
{
SendMessage(GetHwnd(), LB_SETCURSEL, select ? N : -1, 0);
}
+
+ UpdateOldSelections();
}
bool wxListBox::IsSelected(int N) const
wxCHECK_RET( IsValid(n),
wxT("invalid index in wxListBox::SetClientData") );
-#if wxUSE_OWNER_DRAWN
- if ( m_windowStyle & wxLB_OWNERDRAW )
- {
- // client data must be pointer to wxOwnerDrawn, otherwise we would crash
- // in OnMeasure/OnDraw.
- wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
- }
-#endif // wxUSE_OWNER_DRAWN
-
if ( ListBox_SetItemData(GetHwnd(), n, clientData) == LB_ERR )
wxLogDebug(wxT("LB_SETITEMDATA failed"));
}
pNewItem->SetName(items[i]);
pNewItem->SetFont(GetFont());
m_aItems.Insert(pNewItem, n);
-
- ListBox_SetItemData(GetHwnd(), n, pNewItem);
}
#endif // wxUSE_OWNER_DRAWN
AssignNewItemClientData(n, clientData, i, type);
}
- SetHorizontalExtent();
+ m_updateHorizontalExtent = true;
+
+ UpdateOldSelections();
return n;
}
{
// update item's text
m_aItems[n]->SetName(s);
-
- // reassign the item's data
- ListBox_SetItemData(GetHwnd(), n, m_aItems[n]);
}
#endif //USE_OWNER_DRAWN
if ( wasSelected )
Select(n);
- SetHorizontalExtent();
+ m_updateHorizontalExtent = true;
}
unsigned int wxListBox::GetCount() const
bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
{
+ if ((param == LBN_SELCHANGE) && HasMultipleSelection())
+ {
+ CalcAndSendEvent();
+ return true;
+ }
+
wxEventType evtType;
if ( param == LBN_SELCHANGE )
{
event.SetClientData( GetClientData(n) );
event.SetString(GetString(n));
- event.SetExtraLong( HasMultipleSelection() ? IsSelected(n) : true );
+ }
+ else
+ {
+ return false;
}
event.SetInt(n);
wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), false );
DRAWITEMSTRUCT *pStruct = (DRAWITEMSTRUCT *)item;
- UINT itemID = pStruct->itemID;
// the item may be -1 for an empty listbox
- if ( itemID == (UINT)-1 )
+ if ( pStruct->itemID == (UINT)-1 )
return false;
- LRESULT data = ListBox_GetItemData(GetHwnd(), pStruct->itemID);
-
- wxCHECK( data && (data != LB_ERR), false );
-
- wxListBoxItem *pItem = (wxListBoxItem *)data;
+ wxListBoxItem *pItem = (wxListBoxItem *)m_aItems[pStruct->itemID];
wxDCTemp dc((WXHDC)pStruct->hDC);
wxPoint pt1(pStruct->rcItem.left, pStruct->rcItem.top);