// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "listbox.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#include "wx/ownerdrw.h"
#endif
-#ifdef __GNUWIN32_OLD__
- #include "wx/msw/gnuwin32/extra.h"
-#endif
-
#if wxUSE_EXTENDED_RTTI
WX_DEFINE_FLAGS( wxListBoxStyle )
wxFLAGS_MEMBER(wxBORDER_RAISED)
wxFLAGS_MEMBER(wxBORDER_STATIC)
wxFLAGS_MEMBER(wxBORDER_NONE)
-
+
// old style border flags
wxFLAGS_MEMBER(wxSIMPLE_BORDER)
wxFLAGS_MEMBER(wxSUNKEN_BORDER)
IMPLEMENT_DYNAMIC_CLASS_XTI(wxListBox, wxControl,"wx/listbox.h")
wxBEGIN_PROPERTIES_TABLE(wxListBox)
- wxEVENT_PROPERTY( Select , wxEVT_COMMAND_LISTBOX_SELECTED , wxCommandEvent )
- wxEVENT_PROPERTY( DoubleClick , wxEVT_COMMAND_LISTBOX_DOUBLECLICKED , wxCommandEvent )
+ wxEVENT_PROPERTY( Select , wxEVT_COMMAND_LISTBOX_SELECTED , wxCommandEvent )
+ wxEVENT_PROPERTY( DoubleClick , wxEVT_COMMAND_LISTBOX_DOUBLECLICKED , wxCommandEvent )
- wxPROPERTY( Font , wxFont , SetFont , GetFont , , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
+ wxPROPERTY( Font , wxFont , SetFont , GetFont , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
wxPROPERTY_COLLECTION( Choices , wxArrayString , wxString , AppendString , GetStrings, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
- wxPROPERTY( Selection ,int, SetSelection, GetSelection,, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
- wxPROPERTY_FLAGS( WindowStyle , wxListBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
+ wxPROPERTY( Selection ,int, SetSelection, GetSelection, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
+ wxPROPERTY_FLAGS( WindowStyle , wxListBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
wxEND_PROPERTIES_TABLE()
wxBEGIN_HANDLERS_TABLE(wxListBox)
wxEND_HANDLERS_TABLE()
-wxCONSTRUCTOR_4( wxListBox , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size )
+wxCONSTRUCTOR_4( wxListBox , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size )
#else
IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
#endif
/*
TODO PROPERTIES
- selection
- content
- item
+ selection
+ content
+ item
*/
// ============================================================================
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);
const wxSize& size,
int n, const wxString choices[],
long style,
- const wxValidator& wxVALIDATOR_PARAM(validator),
+ const wxValidator& validator,
const wxString& name)
{
m_noItems = 0;
Append(choices[i]);
}
+ // now we can compute our best size correctly, so do it if necessary
+ SetBestSize(size);
+
return true;
}
m_noItems--;
SetHorizontalExtent(wxEmptyString);
+
+ InvalidateBestSize();
}
int wxListBox::DoAppend(const wxString& item)
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
+int wxListBox::FindString(const wxString& s, bool bCase) const
{
- int pos = ListBox_FindStringExact(GetHwnd(), (WPARAM)-1, s);
+ // back to base class search for not native search type
+ if (bCase)
+ return wxItemContainerImmutable::FindString( s, bCase );
+
+ int pos = ListBox_FindStringExact(GetHwnd(), -1, s);
if (pos == LB_ERR)
return wxNOT_FOUND;
else
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 ||
+ wxCHECK_RET( N == wxNOT_FOUND ||
(N >= 0 && N < m_noItems),
wxT("invalid index in wxListBox::SetSelection") );
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;
}
ListBox_SetItemData(GetHwnd(), idx, pNewItem);
}
+#else
+ wxUnusedVar(idx);
#endif // wxUSE_OWNER_DRAWN
}
m_noItems += nItems;
SetHorizontalExtent();
+
+ InvalidateBestSize();
}
void wxListBox::SetString(int N, const wxString& s)
else if ( oldObjData )
SetClientObject(N, oldObjData);
- // we may have lost the selection
- if ( wasSelected )
- Select(N);
-
#if wxUSE_OWNER_DRAWN
if ( m_windowStyle & wxLB_OWNERDRAW )
{
ListBox_SetItemData(GetHwnd(), N, m_aItems[N]);
}
#endif //USE_OWNER_DRAWN
+
+ // 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;
// the listbox should be slightly larger than the widest string
int cx, cy;
- wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
+ wxGetCharSize(GetHWND(), &cx, &cy, GetFont());
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;
HDC hdc = CreateIC(wxT("DISPLAY"), NULL, NULL, 0);
#endif
- wxDC dc;
- dc.SetHDC((WXHDC)hdc);
- dc.SetFont(wxSystemSettings::GetFont(wxSYS_ANSI_VAR_FONT));
-
- pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE;
- pStruct->itemWidth = dc.GetCharWidth();
+ {
+ wxDCTemp dc((WXHDC)hdc);
+ dc.SetFont(GetFont());
- dc.SetHDC(0);
+ pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE;
+ pStruct->itemWidth = dc.GetCharWidth();
+ }
+#ifdef __WXWINCE__
+ ReleaseDC(NULL, hdc);
+#else
DeleteDC(hdc);
+#endif
- 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,