1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/listbox.h
3 // Purpose: wxListBox class
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_LISTBOX_H_
12 #define _WX_LISTBOX_H_
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 class WXDLLIMPEXP_FWD_CORE wxOwnerDrawn
;
23 // define the array of list box items
24 #include "wx/dynarray.h"
26 WX_DEFINE_EXPORTED_ARRAY_PTR(wxOwnerDrawn
*, wxListBoxItemsArray
);
27 #endif // wxUSE_OWNER_DRAWN
29 // forward decl for GetSelections()
30 class WXDLLIMPEXP_FWD_BASE wxArrayInt
;
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 class WXDLLIMPEXP_CORE wxListBox
: public wxListBoxBase
40 wxListBox() { Init(); }
41 wxListBox(wxWindow
*parent
, wxWindowID id
,
42 const wxPoint
& pos
= wxDefaultPosition
,
43 const wxSize
& size
= wxDefaultSize
,
44 int n
= 0, const wxString choices
[] = NULL
,
46 const wxValidator
& validator
= wxDefaultValidator
,
47 const wxString
& name
= wxListBoxNameStr
)
51 Create(parent
, id
, pos
, size
, n
, choices
, style
, validator
, name
);
53 wxListBox(wxWindow
*parent
, wxWindowID id
,
56 const wxArrayString
& choices
,
58 const wxValidator
& validator
= wxDefaultValidator
,
59 const wxString
& name
= wxListBoxNameStr
)
63 Create(parent
, id
, pos
, size
, choices
, style
, validator
, name
);
66 bool Create(wxWindow
*parent
, wxWindowID id
,
67 const wxPoint
& pos
= wxDefaultPosition
,
68 const wxSize
& size
= wxDefaultSize
,
69 int n
= 0, const wxString choices
[] = NULL
,
71 const wxValidator
& validator
= wxDefaultValidator
,
72 const wxString
& name
= wxListBoxNameStr
);
73 bool Create(wxWindow
*parent
, wxWindowID id
,
76 const wxArrayString
& choices
,
78 const wxValidator
& validator
= wxDefaultValidator
,
79 const wxString
& name
= wxListBoxNameStr
);
83 virtual unsigned int GetCount() const;
84 virtual wxString
GetString(unsigned int n
) const;
85 virtual void SetString(unsigned int n
, const wxString
& s
);
86 virtual int FindString(const wxString
& s
, bool bCase
= false) const;
88 virtual bool IsSelected(int n
) const;
89 virtual int GetSelection() const;
90 virtual int GetSelections(wxArrayInt
& aSelections
) const;
92 // return the index of the item at this position or wxNOT_FOUND
93 int HitTest(const wxPoint
& pt
) const { return DoHitTestList(pt
); }
94 int HitTest(wxCoord x
, wxCoord y
) const { return DoHitTestList(wxPoint(x
, y
)); }
96 // ownerdrawn wxListBox and wxCheckListBox support
98 // override base class virtuals
99 virtual bool SetFont(const wxFont
&font
);
101 bool MSWOnMeasure(WXMEASUREITEMSTRUCT
*item
);
102 bool MSWOnDraw(WXDRAWITEMSTRUCT
*item
);
104 // plug-in for derived classes
105 virtual wxOwnerDrawn
*CreateLboxItem(size_t n
);
107 // allows to get the item and use SetXXX functions to set it's appearance
108 wxOwnerDrawn
*GetItem(size_t n
) const { return m_aItems
[n
]; }
110 // get the index of the given item
111 int GetItemIndex(wxOwnerDrawn
*item
) const { return m_aItems
.Index(item
); }
113 // get rect of the given item index
114 bool GetItemRect(size_t n
, wxRect
& rect
) const;
116 // redraw the given item
117 bool RefreshItem(size_t n
);
118 #endif // wxUSE_OWNER_DRAWN
120 // Windows-specific code to update the horizontal extent of the listbox, if
121 // necessary. If s is non-empty, the horizontal extent is increased to the
122 // length of this string if it's currently too short, otherwise the maximum
123 // extent of all strings is used. In any case calls InvalidateBestSize()
124 virtual void SetHorizontalExtent(const wxString
& s
= wxEmptyString
);
127 bool MSWCommand(WXUINT param
, WXWORD id
);
128 WXDWORD
MSWGetStyle(long style
, WXDWORD
*exstyle
) const;
130 // under XP when using "transition effect for menus and tooltips" if we
131 // return true for WM_PRINTCLIENT here then it causes noticable slowdown
132 virtual bool MSWShouldPropagatePrintChild()
137 virtual wxVisualAttributes
GetDefaultAttributes() const
139 return GetClassDefaultAttributes(GetWindowVariant());
142 static wxVisualAttributes
143 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
)
145 return GetCompositeControlsDefaultAttributes(variant
);
148 // returns true if the platform should explicitly apply a theme border
149 virtual bool CanApplyThemeBorder() const { return false; }
151 virtual void OnInternalIdle();
154 virtual wxSize
DoGetBestClientSize() const;
156 virtual void DoClear();
157 virtual void DoDeleteOneItem(unsigned int n
);
159 virtual void DoSetSelection(int n
, bool select
);
161 virtual int DoInsertItems(const wxArrayStringsAdapter
& items
,
163 void **clientData
, wxClientDataType type
);
165 virtual void DoSetFirstItem(int n
);
166 virtual void DoSetItemClientData(unsigned int n
, void* clientData
);
167 virtual void* DoGetItemClientData(unsigned int n
) const;
169 // this can't be called DoHitTest() because wxWindow already has this method
170 virtual int DoHitTestList(const wxPoint
& point
) const;
172 // free memory (common part of Clear() and dtor)
175 unsigned int m_noItems
;
177 #if wxUSE_OWNER_DRAWN
179 wxListBoxItemsArray m_aItems
;
183 // common part of all ctors
186 // call this when items are added to or deleted from the listbox or an
187 // items text changes
188 void MSWOnItemsChanged();
190 // flag indicating whether the max horizontal extent should be updated,
191 // i.e. if we need to call SetHorizontalExtent() from OnInternalIdle()
192 bool m_updateHorizontalExtent
;
195 DECLARE_DYNAMIC_CLASS_NO_COPY(wxListBox
)
198 #endif // wxUSE_LISTBOX