wxFLAGS_MEMBER(wxLB_HSCROLL)
wxFLAGS_MEMBER(wxLB_ALWAYS_SB)
wxFLAGS_MEMBER(wxLB_NEEDED_SB)
+ wxFLAGS_MEMBER(wxLB_NO_SB)
wxFLAGS_MEMBER(wxLB_SORT)
wxEND_FLAGS( wxListBoxStyle )
class wxListBoxItem : public wxOwnerDrawn
{
public:
- wxListBoxItem(const wxString& str = wxEmptyString);
-};
+ wxListBoxItem(wxListBox *parent)
+ { m_parent = parent; }
-wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, false)
-{
- // no bitmaps/checkmarks
- SetMarginWidth(0);
-}
+ wxListBox *GetParent() const
+ { return m_parent; }
+
+ int GetIndex() const
+ { return m_parent->GetItemIndex(const_cast<wxListBoxItem*>(this)); }
+
+ wxString GetName() const
+ { return m_parent->GetString(GetIndex()); }
+
+private:
+ wxListBox *m_parent;
+};
wxOwnerDrawn *wxListBox::CreateLboxItem(size_t WXUNUSED(n))
{
- return new wxListBoxItem();
+ return new wxListBoxItem(this);
}
#endif //USE_OWNER_DRAWN
return false;
// create the native control
- if ( !MSWCreateControl(_T("LISTBOX"), wxEmptyString, pos, size) )
+ if ( !MSWCreateControl(wxT("LISTBOX"), wxEmptyString, pos, size) )
{
// control creation failed
return false;
{
WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
- // always show the vertical scrollbar if necessary -- otherwise it is
- // impossible to use the control with the mouse
- msStyle |= WS_VSCROLL;
-
// we always want to get the notifications
msStyle |= LBS_NOTIFY;
msStyle |= LBS_NOINTEGRALHEIGHT;
wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED),
- _T("only one of listbox selection modes can be specified") );
+ wxT("only one of listbox selection modes can be specified") );
if ( style & wxLB_MULTIPLE )
msStyle |= LBS_MULTIPLESEL;
else if ( style & wxLB_EXTENDED )
msStyle |= LBS_EXTENDEDSEL;
- if ( m_windowStyle & wxLB_ALWAYS_SB )
- msStyle |= LBS_DISABLENOSCROLL;
+ wxASSERT_MSG( !(style & wxLB_ALWAYS_SB) || !(style & wxLB_NO_SB),
+ wxT( "Conflicting styles wxLB_ALWAYS_SB and wxLB_NO_SB." ) );
+
+ if ( !(style & wxLB_NO_SB) )
+ {
+ msStyle |= WS_VSCROLL;
+ if ( style & wxLB_ALWAYS_SB )
+ msStyle |= LBS_DISABLENOSCROLL;
+ }
+
if ( m_windowStyle & wxLB_HSCROLL )
msStyle |= WS_HSCROLL;
if ( m_windowStyle & wxLB_SORT )
void wxListBox::OnInternalIdle()
{
wxWindow::OnInternalIdle();
-
+
if (m_updateHorizontalExtent)
{
SetHorizontalExtent(wxEmptyString);
wxCHECK_RET( IsValid(n),
wxT("invalid index in wxListBox::Delete") );
+#if wxUSE_OWNER_DRAWN
+ if ( HasFlag(wxLB_OWNERDRAW) )
+ {
+ delete m_aItems[n];
+ m_aItems.RemoveAt(n);
+ }
+#endif // wxUSE_OWNER_DRAWN
+
SendMessage(GetHwnd(), LB_DELETESTRING, n, 0);
m_noItems--;
void wxListBox::DoClear()
{
- Free();
+#if wxUSE_OWNER_DRAWN
+ if ( HasFlag(wxLB_OWNERDRAW) )
+ {
+ WX_CLEAR_ARRAY(m_aItems);
+ }
+#endif // wxUSE_OWNER_DRAWN
ListBox_ResetContent(GetHwnd());
UpdateOldSelections();
}
-void wxListBox::Free()
-{
-#if wxUSE_OWNER_DRAWN
- if ( m_windowStyle & wxLB_OWNERDRAW )
- {
- WX_CLEAR_ARRAY(m_aItems);
- }
-#endif // wxUSE_OWNER_DRAWN
-}
-
void wxListBox::DoSetSelection(int N, bool select)
{
wxCHECK_RET( N == wxNOT_FOUND || IsValid(N),
wxT("invalid index in wxListBox::SetClientData") );
if ( ListBox_SetItemData(GetHwnd(), n, clientData) == LB_ERR )
+ {
wxLogDebug(wxT("LB_SETITEMDATA failed"));
+ }
}
// Return number of selections and an array of selected integers
int countSel = ListBox_GetSelCount(GetHwnd());
if ( countSel == LB_ERR )
{
- wxLogDebug(_T("ListBox_GetSelCount failed"));
+ wxLogDebug(wxT("ListBox_GetSelCount failed"));
}
else if ( countSel != 0 )
{
if ( HasFlag(wxLB_OWNERDRAW) )
{
wxOwnerDrawn *pNewItem = CreateLboxItem(n);
- pNewItem->SetName(items[i]);
pNewItem->SetFont(GetFont());
m_aItems.Insert(pNewItem, n);
}
return n;
}
-int wxListBox::DoListHitTest(const wxPoint& point) const
+int wxListBox::DoHitTestList(const wxPoint& point) const
{
LRESULT lRes = ::SendMessage(GetHwnd(), LB_ITEMFROMPOINT,
0, MAKELPARAM(point.x, point.y));
else if ( oldObjData )
SetClientObject(n, oldObjData);
-#if wxUSE_OWNER_DRAWN
- if ( m_windowStyle & wxLB_OWNERDRAW )
- {
- // update item's text
- m_aItems[n]->SetName(s);
- }
-#endif //USE_OWNER_DRAWN
-
// we may have lost the selection
if ( wasSelected )
Select(n);
//else: it shouldn't change
}
-wxSize wxListBox::DoGetBestSize() const
+wxSize wxListBox::DoGetBestClientSize() const
{
// find the widest string
int wLine;
wListbox = 100;
// the listbox should be slightly larger than the widest string
- int cx, cy;
- wxGetCharSize(GetHWND(), &cx, &cy, GetFont());
-
- wListbox += 3*cx;
+ wListbox += 3*GetCharWidth();
- // Add room for the scrollbar
+ // 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)*
+ int hListbox = SendMessage(GetHwnd(), LB_GETITEMHEIGHT, 0, 0)*
wxMin(wxMax(m_noItems, 3), 10);
- wxSize best(wListbox, hListbox);
- CacheBestSize(best);
- return best;
+ return wxSize(wListbox, hListbox);
}
// ----------------------------------------------------------------------------
}
// ----------------------------------------------------------------------------
-// wxCheckListBox support
+// owner-drawn list boxes support
// ----------------------------------------------------------------------------
#if wxUSE_OWNER_DRAWN
+// misc overloaded methods
+// -----------------------
+
+bool wxListBox::SetFont(const wxFont &font)
+{
+ if ( HasFlag(wxLB_OWNERDRAW) )
+ {
+ const unsigned count = m_aItems.GetCount();
+ for ( unsigned i = 0; i < count; i++ )
+ m_aItems[i]->SetFont(font);
+ }
+
+ wxListBoxBase::SetFont(font);
+
+ return true;
+}
+
+bool wxListBox::GetItemRect(size_t n, wxRect& rect) const
+{
+ wxCHECK_MSG( IsValid(n), false,
+ wxT("invalid index in wxListBox::GetItemRect") );
+
+ RECT rc;
+
+ if ( ListBox_GetItemRect(GetHwnd(), n, &rc) != LB_ERR )
+ {
+ rect = wxRectFromRECT(rc);
+ return true;
+ }
+ else
+ {
+ // couldn't retrieve rect: for example, item isn't visible
+ return false;
+ }
+}
+
+bool wxListBox::RefreshItem(size_t n)
+{
+ wxRect rect;
+ if ( !GetItemRect(n, rect) )
+ return false;
+
+ RECT rc;
+ wxCopyRectToRECT(rect, rc);
+
+ return ::InvalidateRect((HWND)GetHWND(), &rc, FALSE) == TRUE;
+}
+
+
// drawing
// -------
-// space beneath/above each row in pixels
-// "standard" checklistbox use 1 here, some might prefer 2. 0 is ugly.
-#define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
+namespace
+{
+ // space beneath/above each row in pixels
+ static const int LISTBOX_EXTRA_SPACE = 1;
+
+} // anonymous namespace
// the height is the same for all items
// TODO should be changed for LBS_OWNERDRAWVARIABLE style listboxes
bool wxListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item)
{
// only owner-drawn control should receive this message
- wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), false );
+ wxCHECK( HasFlag(wxLB_OWNERDRAW), false );
MEASUREITEMSTRUCT *pStruct = (MEASUREITEMSTRUCT *)item;
wxDCTemp dc((WXHDC)hdc);
dc.SetFont(GetFont());
- pStruct->itemHeight = dc.GetCharHeight() + 2*OWNER_DRAWN_LISTBOX_EXTRA_SPACE;
+ pStruct->itemHeight = dc.GetCharHeight() + 2 * LISTBOX_EXTRA_SPACE;
pStruct->itemWidth = dc.GetCharWidth();
}
bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT *item)
{
// only owner-drawn control should receive this message
- wxCHECK( ((m_windowStyle & wxLB_OWNERDRAW) == wxLB_OWNERDRAW), false );
+ wxCHECK( HasFlag(wxLB_OWNERDRAW), false );
DRAWITEMSTRUCT *pStruct = (DRAWITEMSTRUCT *)item;
wxListBoxItem *pItem = (wxListBoxItem *)m_aItems[pStruct->itemID];
wxDCTemp dc((WXHDC)pStruct->hDC);
- 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,
+ return pItem->OnDrawItem(dc, wxRectFromRECT(pStruct->rcItem),
(wxOwnerDrawn::wxODAction)pStruct->itemAction,
- (wxOwnerDrawn::wxODStatus)pStruct->itemState);
+ (wxOwnerDrawn::wxODStatus)(pStruct->itemState | wxOwnerDrawn::wxODHidePrefix));
}
#endif // wxUSE_OWNER_DRAWN