1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/listbox.h
3 // Purpose: wxListBox class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_LISTBOX_H_
13 #define _WX_LISTBOX_H_
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
22 class WXDLLIMPEXP_FWD_CORE wxOwnerDrawn
;
24 // define the array of list box items
25 #include "wx/dynarray.h"
27 WX_DEFINE_EXPORTED_ARRAY_PTR(wxOwnerDrawn
*, wxListBoxItemsArray
);
28 #endif // wxUSE_OWNER_DRAWN
30 // forward decl for GetSelections()
31 class WXDLLIMPEXP_FWD_BASE wxArrayInt
;
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 class WXDLLIMPEXP_CORE wxListBox
: public wxListBoxBase
41 wxListBox() { Init(); }
42 wxListBox(wxWindow
*parent
, wxWindowID id
,
43 const wxPoint
& pos
= wxDefaultPosition
,
44 const wxSize
& size
= wxDefaultSize
,
45 int n
= 0, const wxString choices
[] = NULL
,
47 const wxValidator
& validator
= wxDefaultValidator
,
48 const wxString
& name
= wxListBoxNameStr
)
52 Create(parent
, id
, pos
, size
, n
, choices
, style
, validator
, name
);
54 wxListBox(wxWindow
*parent
, wxWindowID id
,
57 const wxArrayString
& choices
,
59 const wxValidator
& validator
= wxDefaultValidator
,
60 const wxString
& name
= wxListBoxNameStr
)
64 Create(parent
, id
, pos
, size
, choices
, style
, validator
, name
);
67 bool Create(wxWindow
*parent
, wxWindowID id
,
68 const wxPoint
& pos
= wxDefaultPosition
,
69 const wxSize
& size
= wxDefaultSize
,
70 int n
= 0, const wxString choices
[] = NULL
,
72 const wxValidator
& validator
= wxDefaultValidator
,
73 const wxString
& name
= wxListBoxNameStr
);
74 bool Create(wxWindow
*parent
, wxWindowID id
,
77 const wxArrayString
& choices
,
79 const wxValidator
& validator
= wxDefaultValidator
,
80 const wxString
& name
= wxListBoxNameStr
);
84 virtual unsigned int GetCount() const;
85 virtual wxString
GetString(unsigned int n
) const;
86 virtual void SetString(unsigned int n
, const wxString
& s
);
87 virtual int FindString(const wxString
& s
, bool bCase
= false) const;
89 virtual bool IsSelected(int n
) const;
90 virtual int GetSelection() const;
91 virtual int GetSelections(wxArrayInt
& aSelections
) const;
93 // return the index of the item at this position or wxNOT_FOUND
94 int HitTest(const wxPoint
& pt
) const { return DoHitTestList(pt
); }
95 int HitTest(wxCoord x
, wxCoord y
) const { return DoHitTestList(wxPoint(x
, y
)); }
97 // ownerdrawn wxListBox and wxCheckListBox support
99 // override base class virtuals
100 virtual bool SetFont(const wxFont
&font
);
102 bool MSWOnMeasure(WXMEASUREITEMSTRUCT
*item
);
103 bool MSWOnDraw(WXDRAWITEMSTRUCT
*item
);
105 // plug-in for derived classes
106 virtual wxOwnerDrawn
*CreateLboxItem(size_t n
);
108 // allows to get the item and use SetXXX functions to set it's appearance
109 wxOwnerDrawn
*GetItem(size_t n
) const { return m_aItems
[n
]; }
111 // get the index of the given item
112 int GetItemIndex(wxOwnerDrawn
*item
) const { return m_aItems
.Index(item
); }
114 // get rect of the given item index
115 bool GetItemRect(size_t n
, wxRect
& rect
) const;
117 // redraw the given item
118 bool RefreshItem(size_t n
);
119 #endif // wxUSE_OWNER_DRAWN
121 // Windows-specific code to update the horizontal extent of the listbox, if
122 // necessary. If s is non-empty, the horizontal extent is increased to the
123 // length of this string if it's currently too short, otherwise the maximum
124 // extent of all strings is used. In any case calls InvalidateBestSize()
125 virtual void SetHorizontalExtent(const wxString
& s
= wxEmptyString
);
128 bool MSWCommand(WXUINT param
, WXWORD id
);
129 WXDWORD
MSWGetStyle(long style
, WXDWORD
*exstyle
) const;
131 // under XP when using "transition effect for menus and tooltips" if we
132 // return true for WM_PRINTCLIENT here then it causes noticable slowdown
133 virtual bool MSWShouldPropagatePrintChild()
138 virtual wxVisualAttributes
GetDefaultAttributes() const
140 return GetClassDefaultAttributes(GetWindowVariant());
143 static wxVisualAttributes
144 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
)
146 return GetCompositeControlsDefaultAttributes(variant
);
149 // returns true if the platform should explicitly apply a theme border
150 virtual bool CanApplyThemeBorder() const { return false; }
152 virtual void OnInternalIdle();
155 virtual wxSize
DoGetBestClientSize() const;
157 virtual void DoClear();
158 virtual void DoDeleteOneItem(unsigned int n
);
160 virtual void DoSetSelection(int n
, bool select
);
162 virtual int DoInsertItems(const wxArrayStringsAdapter
& items
,
164 void **clientData
, wxClientDataType type
);
166 virtual void DoSetFirstItem(int n
);
167 virtual void DoSetItemClientData(unsigned int n
, void* clientData
);
168 virtual void* DoGetItemClientData(unsigned int n
) const;
170 // this can't be called DoHitTest() because wxWindow already has this method
171 virtual int DoHitTestList(const wxPoint
& point
) const;
173 // free memory (common part of Clear() and dtor)
176 unsigned int m_noItems
;
178 #if wxUSE_OWNER_DRAWN
180 wxListBoxItemsArray m_aItems
;
184 // common part of all ctors
187 // call this when items are added to or deleted from the listbox or an
188 // items text changes
189 void MSWOnItemsChanged();
191 // flag indicating whether the max horizontal extent should be updated,
192 // i.e. if we need to call SetHorizontalExtent() from OnInternalIdle()
193 bool m_updateHorizontalExtent
;
196 DECLARE_DYNAMIC_CLASS_NO_COPY(wxListBox
)
199 #endif // wxUSE_LISTBOX