1 /////////////////////////////////////////////////////////////////////////////
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_
16 #pragma interface "listbox.h"
19 #include "wx/control.h"
21 WXDLLEXPORT_DATA(extern const wxChar
*) wxListBoxNameStr
;
24 class WXDLLEXPORT wxOwnerDrawn
;
26 // define the array of list box items
27 #include <wx/dynarray.h>
29 WX_DEFINE_ARRAY(wxOwnerDrawn
*, wxListBoxItemsArray
);
33 // forward decl for GetSelections()
36 WXDLLEXPORT_DATA(extern const wxChar
*) wxEmptyString
;
39 class WXDLLEXPORT wxListBox
: public wxControl
41 DECLARE_DYNAMIC_CLASS(wxListBox
)
45 wxListBox(wxWindow
*parent
, wxWindowID id
,
46 const wxPoint
& pos
= wxDefaultPosition
,
47 const wxSize
& size
= wxDefaultSize
,
48 int n
= 0, const wxString choices
[] = NULL
,
50 const wxValidator
& validator
= wxDefaultValidator
,
51 const wxString
& name
= wxListBoxNameStr
)
53 Create(parent
, id
, pos
, size
, n
, choices
, style
, validator
, name
);
56 bool Create(wxWindow
*parent
, wxWindowID id
,
57 const wxPoint
& pos
= wxDefaultPosition
,
58 const wxSize
& size
= wxDefaultSize
,
59 int n
= 0, const wxString choices
[] = NULL
,
61 const wxValidator
& validator
= wxDefaultValidator
,
62 const wxString
& name
= wxListBoxNameStr
);
66 bool MSWCommand(WXUINT param
, WXWORD id
);
69 bool MSWOnMeasure(WXMEASUREITEMSTRUCT
*item
);
70 bool MSWOnDraw(WXDRAWITEMSTRUCT
*item
);
72 // plug-in for derived classes
73 virtual wxOwnerDrawn
*CreateItem(size_t n
);
75 // allows to get the item and use SetXXX functions to set it's appearance
76 wxOwnerDrawn
*GetItem(size_t n
) const { return m_aItems
[n
]; }
78 // get the index of the given item
79 int GetItemIndex(wxOwnerDrawn
*item
) const { return m_aItems
.Index(item
); }
80 #endif // wxUSE_OWNER_DRAWN
82 virtual void Append(const wxString
& item
);
83 virtual void Append(const wxString
& item
, void *clientData
);
84 virtual void Set(int n
, const wxString
* choices
, void **clientData
= NULL
);
85 virtual int FindString(const wxString
& s
) const ;
87 virtual void SetSelection(int n
, bool select
= TRUE
);
89 virtual void Deselect(int n
);
91 // For single choice list item only
92 virtual int GetSelection() const ;
93 virtual void Delete(int n
);
94 virtual void *GetClientData(int n
) const ;
95 virtual void SetClientData(int n
, void *clientData
);
96 virtual void SetString(int n
, const wxString
& s
);
98 // For single or multiple choice list item
99 virtual int GetSelections(wxArrayInt
& aSelections
) const;
100 virtual bool Selected(int n
) const ;
101 virtual wxString
GetString(int n
) const ;
103 // Set the specified item at the first visible item
104 // or scroll to max range.
105 virtual void SetFirstItem(int n
) ;
106 virtual void SetFirstItem(const wxString
& s
) ;
108 virtual void InsertItems(int nItems
, const wxString items
[], int pos
);
110 virtual wxString
GetStringSelection() const ;
111 virtual bool SetStringSelection(const wxString
& s
, bool flag
= TRUE
);
112 virtual int Number() const ;
114 void Command(wxCommandEvent
& event
);
116 // Windows-specific code to set the horizontal extent of
117 // the listbox, if necessary. If s is non-NULL, it's
118 // used to calculate the horizontal extent.
119 // Otherwise, all strings are used.
120 virtual void SetHorizontalExtent(const wxString
& s
= wxEmptyString
);
122 virtual WXHBRUSH
OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
123 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
125 virtual long MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
126 virtual void SetupColours();
132 virtual wxSize
DoGetBestSize();
134 #if wxUSE_OWNER_DRAWN
136 wxListBoxItemsArray m_aItems
;