]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/listbox.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[wxWidgets.git] / include / wx / msw / listbox.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/listbox.h
3 // Purpose: wxListBox class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_LISTBOX_H_
12 #define _WX_LISTBOX_H_
13
14 #if wxUSE_LISTBOX
15
16 // ----------------------------------------------------------------------------
17 // simple types
18 // ----------------------------------------------------------------------------
19
20 #if wxUSE_OWNER_DRAWN
21 class WXDLLIMPEXP_FWD_CORE wxOwnerDrawn;
22
23 // define the array of list box items
24 #include "wx/dynarray.h"
25
26 WX_DEFINE_EXPORTED_ARRAY_PTR(wxOwnerDrawn *, wxListBoxItemsArray);
27 #endif // wxUSE_OWNER_DRAWN
28
29 // forward decl for GetSelections()
30 class WXDLLIMPEXP_FWD_BASE wxArrayInt;
31
32 // ----------------------------------------------------------------------------
33 // List box control
34 // ----------------------------------------------------------------------------
35
36 class WXDLLIMPEXP_CORE wxListBox : public wxListBoxBase
37 {
38 public:
39 // ctors and such
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,
45 long style = 0,
46 const wxValidator& validator = wxDefaultValidator,
47 const wxString& name = wxListBoxNameStr)
48 {
49 Init();
50
51 Create(parent, id, pos, size, n, choices, style, validator, name);
52 }
53 wxListBox(wxWindow *parent, wxWindowID id,
54 const wxPoint& pos,
55 const wxSize& size,
56 const wxArrayString& choices,
57 long style = 0,
58 const wxValidator& validator = wxDefaultValidator,
59 const wxString& name = wxListBoxNameStr)
60 {
61 Init();
62
63 Create(parent, id, pos, size, choices, style, validator, name);
64 }
65
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,
70 long style = 0,
71 const wxValidator& validator = wxDefaultValidator,
72 const wxString& name = wxListBoxNameStr);
73 bool Create(wxWindow *parent, wxWindowID id,
74 const wxPoint& pos,
75 const wxSize& size,
76 const wxArrayString& choices,
77 long style = 0,
78 const wxValidator& validator = wxDefaultValidator,
79 const wxString& name = wxListBoxNameStr);
80
81 virtual ~wxListBox();
82
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;
87
88 virtual bool IsSelected(int n) const;
89 virtual int GetSelection() const;
90 virtual int GetSelections(wxArrayInt& aSelections) const;
91
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)); }
95
96 // ownerdrawn wxListBox and wxCheckListBox support
97 #if wxUSE_OWNER_DRAWN
98 // override base class virtuals
99 virtual bool SetFont(const wxFont &font);
100
101 bool MSWOnMeasure(WXMEASUREITEMSTRUCT *item);
102 bool MSWOnDraw(WXDRAWITEMSTRUCT *item);
103
104 // plug-in for derived classes
105 virtual wxOwnerDrawn *CreateLboxItem(size_t n);
106
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]; }
109
110 // get the index of the given item
111 int GetItemIndex(wxOwnerDrawn *item) const { return m_aItems.Index(item); }
112
113 // get rect of the given item index
114 bool GetItemRect(size_t n, wxRect& rect) const;
115
116 // redraw the given item
117 bool RefreshItem(size_t n);
118 #endif // wxUSE_OWNER_DRAWN
119
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);
125
126 // Windows callbacks
127 bool MSWCommand(WXUINT param, WXWORD id);
128 WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
129
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()
133 {
134 return false;
135 }
136
137 virtual wxVisualAttributes GetDefaultAttributes() const
138 {
139 return GetClassDefaultAttributes(GetWindowVariant());
140 }
141
142 static wxVisualAttributes
143 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL)
144 {
145 return GetCompositeControlsDefaultAttributes(variant);
146 }
147
148 // returns true if the platform should explicitly apply a theme border
149 virtual bool CanApplyThemeBorder() const { return false; }
150
151 virtual void OnInternalIdle();
152
153 protected:
154 virtual wxSize DoGetBestClientSize() const;
155
156 virtual void DoClear();
157 virtual void DoDeleteOneItem(unsigned int n);
158
159 virtual void DoSetSelection(int n, bool select);
160
161 virtual int DoInsertItems(const wxArrayStringsAdapter& items,
162 unsigned int pos,
163 void **clientData, wxClientDataType type);
164
165 virtual void DoSetFirstItem(int n);
166 virtual void DoSetItemClientData(unsigned int n, void* clientData);
167 virtual void* DoGetItemClientData(unsigned int n) const;
168
169 // this can't be called DoHitTest() because wxWindow already has this method
170 virtual int DoHitTestList(const wxPoint& point) const;
171
172 // free memory (common part of Clear() and dtor)
173 void Free();
174
175 unsigned int m_noItems;
176
177 #if wxUSE_OWNER_DRAWN
178 // control items
179 wxListBoxItemsArray m_aItems;
180 #endif
181
182 private:
183 // common part of all ctors
184 void Init();
185
186 // call this when items are added to or deleted from the listbox or an
187 // items text changes
188 void MSWOnItemsChanged();
189
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;
193
194
195 DECLARE_DYNAMIC_CLASS_NO_COPY(wxListBox)
196 };
197
198 #endif // wxUSE_LISTBOX
199
200 #endif
201 // _WX_LISTBOX_H_