]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/listbox.h
No changes, just refactor wxListBox initialization in wxMSW.
[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 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_LISTBOX_H_
13 #define _WX_LISTBOX_H_
14
15 #if wxUSE_LISTBOX
16
17 // ----------------------------------------------------------------------------
18 // simple types
19 // ----------------------------------------------------------------------------
20
21 #if wxUSE_OWNER_DRAWN
22 class WXDLLIMPEXP_FWD_CORE wxOwnerDrawn;
23
24 // define the array of list box items
25 #include "wx/dynarray.h"
26
27 WX_DEFINE_EXPORTED_ARRAY_PTR(wxOwnerDrawn *, wxListBoxItemsArray);
28 #endif // wxUSE_OWNER_DRAWN
29
30 // forward decl for GetSelections()
31 class WXDLLIMPEXP_FWD_BASE wxArrayInt;
32
33 // ----------------------------------------------------------------------------
34 // List box control
35 // ----------------------------------------------------------------------------
36
37 class WXDLLIMPEXP_CORE wxListBox : public wxListBoxBase
38 {
39 public:
40 // ctors and such
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,
46 long style = 0,
47 const wxValidator& validator = wxDefaultValidator,
48 const wxString& name = wxListBoxNameStr)
49 {
50 Init();
51
52 Create(parent, id, pos, size, n, choices, style, validator, name);
53 }
54 wxListBox(wxWindow *parent, wxWindowID id,
55 const wxPoint& pos,
56 const wxSize& size,
57 const wxArrayString& choices,
58 long style = 0,
59 const wxValidator& validator = wxDefaultValidator,
60 const wxString& name = wxListBoxNameStr)
61 {
62 Create(parent, id, pos, size, choices, style, validator, name);
63 }
64
65 bool Create(wxWindow *parent, wxWindowID id,
66 const wxPoint& pos = wxDefaultPosition,
67 const wxSize& size = wxDefaultSize,
68 int n = 0, const wxString choices[] = NULL,
69 long style = 0,
70 const wxValidator& validator = wxDefaultValidator,
71 const wxString& name = wxListBoxNameStr);
72 bool Create(wxWindow *parent, wxWindowID id,
73 const wxPoint& pos,
74 const wxSize& size,
75 const wxArrayString& choices,
76 long style = 0,
77 const wxValidator& validator = wxDefaultValidator,
78 const wxString& name = wxListBoxNameStr);
79
80 virtual ~wxListBox();
81
82 virtual unsigned int GetCount() const;
83 virtual wxString GetString(unsigned int n) const;
84 virtual void SetString(unsigned int n, const wxString& s);
85 virtual int FindString(const wxString& s, bool bCase = false) const;
86
87 virtual bool IsSelected(int n) const;
88 virtual int GetSelection() const;
89 virtual int GetSelections(wxArrayInt& aSelections) const;
90
91 // return the index of the item at this position or wxNOT_FOUND
92 int HitTest(const wxPoint& pt) const { return DoHitTestList(pt); }
93 int HitTest(wxCoord x, wxCoord y) const { return DoHitTestList(wxPoint(x, y)); }
94
95 // ownerdrawn wxListBox and wxCheckListBox support
96 #if wxUSE_OWNER_DRAWN
97 // override base class virtuals
98 virtual bool SetFont(const wxFont &font);
99
100 bool MSWOnMeasure(WXMEASUREITEMSTRUCT *item);
101 bool MSWOnDraw(WXDRAWITEMSTRUCT *item);
102
103 // plug-in for derived classes
104 virtual wxOwnerDrawn *CreateLboxItem(size_t n);
105
106 // allows to get the item and use SetXXX functions to set it's appearance
107 wxOwnerDrawn *GetItem(size_t n) const { return m_aItems[n]; }
108
109 // get the index of the given item
110 int GetItemIndex(wxOwnerDrawn *item) const { return m_aItems.Index(item); }
111
112 // get rect of the given item index
113 bool GetItemRect(size_t n, wxRect& rect) const;
114
115 // redraw the given item
116 bool RefreshItem(size_t n);
117 #endif // wxUSE_OWNER_DRAWN
118
119 // Windows-specific code to update the horizontal extent of the listbox, if
120 // necessary. If s is non-empty, the horizontal extent is increased to the
121 // length of this string if it's currently too short, otherwise the maximum
122 // extent of all strings is used. In any case calls InvalidateBestSize()
123 virtual void SetHorizontalExtent(const wxString& s = wxEmptyString);
124
125 // Windows callbacks
126 bool MSWCommand(WXUINT param, WXWORD id);
127 WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
128
129 // under XP when using "transition effect for menus and tooltips" if we
130 // return true for WM_PRINTCLIENT here then it causes noticable slowdown
131 virtual bool MSWShouldPropagatePrintChild()
132 {
133 return false;
134 }
135
136 virtual wxVisualAttributes GetDefaultAttributes() const
137 {
138 return GetClassDefaultAttributes(GetWindowVariant());
139 }
140
141 static wxVisualAttributes
142 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL)
143 {
144 return GetCompositeControlsDefaultAttributes(variant);
145 }
146
147 // returns true if the platform should explicitly apply a theme border
148 virtual bool CanApplyThemeBorder() const { return false; }
149
150 virtual void OnInternalIdle();
151
152 protected:
153 virtual wxSize DoGetBestClientSize() const;
154
155 virtual void DoClear();
156 virtual void DoDeleteOneItem(unsigned int n);
157
158 virtual void DoSetSelection(int n, bool select);
159
160 virtual int DoInsertItems(const wxArrayStringsAdapter& items,
161 unsigned int pos,
162 void **clientData, wxClientDataType type);
163
164 virtual void DoSetFirstItem(int n);
165 virtual void DoSetItemClientData(unsigned int n, void* clientData);
166 virtual void* DoGetItemClientData(unsigned int n) const;
167
168 // this can't be called DoHitTest() because wxWindow already has this method
169 virtual int DoHitTestList(const wxPoint& point) const;
170
171 // free memory (common part of Clear() and dtor)
172 void Free();
173
174 unsigned int m_noItems;
175
176 #if wxUSE_OWNER_DRAWN
177 // control items
178 wxListBoxItemsArray m_aItems;
179 #endif
180
181 private:
182 // common part of all ctors
183 void Init();
184
185 // call this when items are added to or deleted from the listbox or an
186 // items text changes
187 void MSWOnItemsChanged();
188
189 // flag indicating whether the max horizontal extent should be updated,
190 // i.e. if we need to call SetHorizontalExtent() from OnInternalIdle()
191 bool m_updateHorizontalExtent;
192
193 DECLARE_DYNAMIC_CLASS_NO_COPY(wxListBox)
194 };
195
196 #endif // wxUSE_LISTBOX
197
198 #endif
199 // _WX_LISTBOX_H_