]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/listbox.h
Improve wxCheckListBox appearance under Vista/Win7.
[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();
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 Create(parent, id, pos, size, n, choices, style, validator, name);
51 }
52 wxListBox(wxWindow *parent, wxWindowID id,
53 const wxPoint& pos,
54 const wxSize& size,
55 const wxArrayString& choices,
56 long style = 0,
57 const wxValidator& validator = wxDefaultValidator,
58 const wxString& name = wxListBoxNameStr)
59 {
60 Create(parent, id, pos, size, choices, style, validator, name);
61 }
62
63 bool Create(wxWindow *parent, wxWindowID id,
64 const wxPoint& pos = wxDefaultPosition,
65 const wxSize& size = wxDefaultSize,
66 int n = 0, const wxString choices[] = NULL,
67 long style = 0,
68 const wxValidator& validator = wxDefaultValidator,
69 const wxString& name = wxListBoxNameStr);
70 bool Create(wxWindow *parent, wxWindowID id,
71 const wxPoint& pos,
72 const wxSize& size,
73 const wxArrayString& choices,
74 long style = 0,
75 const wxValidator& validator = wxDefaultValidator,
76 const wxString& name = wxListBoxNameStr);
77
78 virtual ~wxListBox();
79
80 virtual unsigned int GetCount() const;
81 virtual wxString GetString(unsigned int n) const;
82 virtual void SetString(unsigned int n, const wxString& s);
83 virtual int FindString(const wxString& s, bool bCase = false) const;
84
85 virtual bool IsSelected(int n) const;
86 virtual int GetSelection() const;
87 virtual int GetSelections(wxArrayInt& aSelections) const;
88
89 // return the index of the item at this position or wxNOT_FOUND
90 int HitTest(const wxPoint& pt) const { return DoHitTestList(pt); }
91 int HitTest(wxCoord x, wxCoord y) const { return DoHitTestList(wxPoint(x, y)); }
92
93 // ownerdrawn wxListBox and wxCheckListBox support
94 #if wxUSE_OWNER_DRAWN
95 // override base class virtuals
96 virtual void Delete(unsigned int n);
97 virtual bool SetFont(const wxFont &font);
98
99 bool MSWOnMeasure(WXMEASUREITEMSTRUCT *item);
100 bool MSWOnDraw(WXDRAWITEMSTRUCT *item);
101
102 // plug-in for derived classes
103 virtual wxOwnerDrawn *CreateLboxItem(size_t n);
104
105 // allows to get the item and use SetXXX functions to set it's appearance
106 wxOwnerDrawn *GetItem(size_t n) const { return m_aItems[n]; }
107
108 // get the index of the given item
109 int GetItemIndex(wxOwnerDrawn *item) const { return m_aItems.Index(item); }
110
111 // get rect of the given item index
112 bool GetItemRect(size_t n, wxRect& rect) const;
113
114 // redraw the given item
115 bool RefreshItem(size_t n);
116 #endif // wxUSE_OWNER_DRAWN
117
118 // Windows-specific code to update the horizontal extent of the listbox, if
119 // necessary. If s is non-empty, the horizontal extent is increased to the
120 // length of this string if it's currently too short, otherwise the maximum
121 // extent of all strings is used. In any case calls InvalidateBestSize()
122 virtual void SetHorizontalExtent(const wxString& s = wxEmptyString);
123
124 // Windows callbacks
125 bool MSWCommand(WXUINT param, WXWORD id);
126 WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
127
128 // under XP when using "transition effect for menus and tooltips" if we
129 // return true for WM_PRINTCLIENT here then it causes noticable slowdown
130 virtual bool MSWShouldPropagatePrintChild()
131 {
132 return false;
133 }
134
135 virtual wxVisualAttributes GetDefaultAttributes() const
136 {
137 return GetClassDefaultAttributes(GetWindowVariant());
138 }
139
140 static wxVisualAttributes
141 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL)
142 {
143 return GetCompositeControlsDefaultAttributes(variant);
144 }
145
146 // returns true if the platform should explicitly apply a theme border
147 virtual bool CanApplyThemeBorder() const { return false; }
148
149 protected:
150 virtual wxSize DoGetBestClientSize() const;
151
152 virtual void DoClear();
153 virtual void DoDeleteOneItem(unsigned int n);
154
155 virtual void DoSetSelection(int n, bool select);
156
157 virtual int DoInsertItems(const wxArrayStringsAdapter& items,
158 unsigned int pos,
159 void **clientData, wxClientDataType type);
160
161 virtual void DoSetFirstItem(int n);
162 virtual void DoSetItemClientData(unsigned int n, void* clientData);
163 virtual void* DoGetItemClientData(unsigned int n) const;
164
165 // this can't be called DoHitTest() because wxWindow already has this method
166 virtual int DoHitTestList(const wxPoint& point) const;
167
168 bool m_updateHorizontalExtent;
169 virtual void OnInternalIdle();
170
171 unsigned int m_noItems;
172
173 #if wxUSE_OWNER_DRAWN
174 // control items
175 wxListBoxItemsArray m_aItems;
176 #endif
177
178 private:
179 DECLARE_DYNAMIC_CLASS_NO_COPY(wxListBox)
180 };
181
182 #endif // wxUSE_LISTBOX
183
184 #endif
185 // _WX_LISTBOX_H_