#include "wx/ownerdrw.h"
#endif
-#ifdef __GNUWIN32_OLD__
- #include "wx/msw/gnuwin32/extra.h"
-#endif
-
#if wxUSE_EXTENDED_RTTI
WX_DEFINE_FLAGS( wxListBoxStyle )
wxListBoxItem(const wxString& str = wxEmptyString);
};
-wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE)
+wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, false)
{
// no bitmaps/checkmarks
SetMarginWidth(0);
return false;
}
+ // Necessary to prevent scroll problems within a notebook with Windows
+ // effects enabled
+ SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
+
// initialize the contents
for ( int i = 0; i < n; i++ )
{
m_noItems--;
SetHorizontalExtent(wxEmptyString);
+
+ InvalidateBestSize();
}
int wxListBox::DoAppend(const wxString& item)
{
- InvalidateBestSize();
-
int index = ListBox_AddString(GetHwnd(), item);
m_noItems++;
SetHorizontalExtent(item);
+ InvalidateBestSize();
return index;
}
// show the listbox back if we hid it
ShowWindow(GetHwnd(), SW_SHOW);
}
+
+ InvalidateBestSize();
}
int wxListBox::FindString(const wxString& s) const
m_noItems = 0;
SetHorizontalExtent();
+
+ InvalidateBestSize();
}
void wxListBox::Free()
}
}
-void wxListBox::SetSelection(int N, bool select)
+void wxListBox::DoSetSelection(int N, bool select)
{
wxCHECK_RET( N == wxNOT_FOUND ||
(N >= 0 && N < m_noItems),
bool wxListBox::IsSelected(int N) const
{
- wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE,
+ wxCHECK_MSG( N >= 0 && N < m_noItems, false,
wxT("invalid index in wxListBox::Selected") );
- return SendMessage(GetHwnd(), LB_GETSEL, N, 0) == 0 ? FALSE : TRUE;
+ return SendMessage(GetHwnd(), LB_GETSEL, N, 0) == 0 ? false : true;
}
wxClientData* wxListBox::DoGetItemClientObject(int n) const
wxString wxListBox::GetString(int N) const
{
wxCHECK_MSG( N >= 0 && N < m_noItems, wxEmptyString,
- wxT("invalid index in wxListBox::GetClientData") );
+ wxT("invalid index in wxListBox::GetString") );
int len = ListBox_GetTextLen(GetHwnd(), N);
// +1 for terminating NUL
wxString result;
- ListBox_GetText(GetHwnd(), N, wxStringBuffer(result, len + 1));
+ ListBox_GetText(GetHwnd(), N, (wxChar*)wxStringBuffer(result, len + 1));
return result;
}
wxCHECK_RET( pos >= 0 && pos <= m_noItems,
wxT("invalid index in wxListBox::InsertItems") );
- InvalidateBestSize();
-
int nItems = items.GetCount();
for ( int i = 0; i < nItems; i++ )
{
m_noItems += nItems;
SetHorizontalExtent();
+
+ InvalidateBestSize();
}
void wxListBox::SetString(int N, const wxString& s)
// we may have lost the selection
if ( wasSelected )
Select(N);
+
+ InvalidateBestSize();
}
int wxListBox::GetCount() const
return;
TEXTMETRIC lpTextMetric;
- if ( !s.IsEmpty() )
+ if ( !s.empty() )
{
int existingExtent = (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT, 0, 0L);
HDC dc = GetWindowDC(GetHwnd());
HFONT oldFont = 0;
- if (GetFont().Ok() && GetFont().GetResourceHandle())
+ if (GetFont().Ok() && GetFont().GetResourceHandle() != 0)
oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle());
GetTextMetrics(dc, &lpTextMetric);
SIZE extentXY;
- ::GetTextExtentPoint(dc, (LPTSTR) (const wxChar *)s, s.Length(), &extentXY);
+ ::GetTextExtentPoint32(dc, (LPTSTR) (const wxChar *)s, s.Length(), &extentXY);
int extentX = (int)(extentXY.cx + lpTextMetric.tmAveCharWidth);
if (oldFont)
int largestExtent = 0;
HDC dc = GetWindowDC(GetHwnd());
HFONT oldFont = 0;
- if (GetFont().Ok() && GetFont().GetResourceHandle())
+ if (GetFont().Ok() && GetFont().GetResourceHandle() != 0)
oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle());
GetTextMetrics(dc, &lpTextMetric);
- // FIXME: buffer overflow!!
- wxChar buf[1024];
for (int i = 0; i < m_noItems; i++)
{
- int len = (int)SendMessage(GetHwnd(), LB_GETTEXT, i, (LPARAM)buf);
- buf[len] = 0;
+ wxString str = GetString(i);
SIZE extentXY;
- ::GetTextExtentPoint(dc, buf, len, &extentXY);
+ ::GetTextExtentPoint32(dc, str.c_str(), str.length(), &extentXY);
int extentX = (int)(extentXY.cx + lpTextMetric.tmAveCharWidth);
if (extentX > largestExtent)
largestExtent = extentX;
wListbox += 3*cx;
+ // Add room for the scrollbar
+ wListbox += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
+
// don't make the listbox too tall (limit height to 10 items) but don't
// make it too small neither
int hListbox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*
wxMin(wxMax(m_noItems, 3), 10);
- return wxSize(wListbox, hListbox);
+ wxSize best(wListbox, hListbox);
+ CacheBestSize(best);
+ return best;
}
// ----------------------------------------------------------------------------
else
{
// some event we're not interested in
- return FALSE;
+ return false;
}
wxCommandEvent event(evtType, m_windowId);
event.SetClientData( GetClientData(n) );
event.SetString( GetString(n) );
- event.SetExtraLong( HasMultipleSelection() ? IsSelected(n) : TRUE );
+ event.SetExtraLong( HasMultipleSelection() ? IsSelected(n) : true );
}
- event.m_commandInt = n;
+ event.SetInt(n);
return GetEventHandler()->ProcessEvent(event);
}
bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item)
{
// only owner-drawn control should receive this message
- wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE );
+ wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), false );
MEASUREITEMSTRUCT *pStruct = (MEASUREITEMSTRUCT *)item;
wxDC dc;
dc.SetHDC((WXHDC)hdc);
- dc.SetFont(wxSystemSettings::GetFont(wxSYS_ANSI_VAR_FONT));
+ dc.SetFont(GetFont());
pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE;
pStruct->itemWidth = dc.GetCharWidth();
DeleteDC(hdc);
- return TRUE;
+ return true;
}
// forward the message to the appropriate item
bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT *item)
{
// only owner-drawn control should receive this message
- wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), FALSE );
+ 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 )
- return FALSE;
+ return false;
long data = ListBox_GetItemData(GetHwnd(), pStruct->itemID);
- wxCHECK( data && (data != LB_ERR), FALSE );
+ wxCHECK( data && (data != LB_ERR), false );
wxListBoxItem *pItem = (wxListBoxItem *)data;
wxDCTemp dc((WXHDC)pStruct->hDC);
- wxRect rect(wxPoint(pStruct->rcItem.left, pStruct->rcItem.top),
- wxPoint(pStruct->rcItem.right, pStruct->rcItem.bottom));
+ wxPoint pt1(pStruct->rcItem.left, pStruct->rcItem.top);
+ wxPoint pt2(pStruct->rcItem.right, pStruct->rcItem.bottom);
+ wxRect rect(pt1, pt2);
return pItem->OnDrawItem(dc, rect,
(wxOwnerDrawn::wxODAction)pStruct->itemAction,