1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxListBox class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_LISTBOX_H_
13 #define _WX_LISTBOX_H_
15 #include "wx/control.h"
17 WXDLLEXPORT_DATA(extern const char*) wxListBoxNameStr
;
20 class WXDLLEXPORT wxOwnerDrawn
;
22 // define the array of list box items
23 #include <wx/dynarray.h>
25 WX_DEFINE_ARRAY(wxOwnerDrawn
*, wxListBoxItemsArray
);
28 // forward decl for GetSelections()
29 class WXDLLEXPORT wxArrayInt
;
31 WXDLLEXPORT_DATA(extern const char*) wxEmptyString
;
34 class WXDLLEXPORT wxListBox
: public wxControl
36 DECLARE_DYNAMIC_CLASS(wxListBox
)
40 inline wxListBox(wxWindow
*parent
, wxWindowID id
,
41 const wxPoint
& pos
= wxDefaultPosition
,
42 const wxSize
& size
= wxDefaultSize
,
43 int n
= 0, const wxString choices
[] = NULL
,
45 const wxValidator
& validator
= wxDefaultValidator
,
46 const wxString
& name
= wxListBoxNameStr
)
48 Create(parent
, id
, pos
, size
, n
, choices
, style
, validator
, name
);
51 bool Create(wxWindow
*parent
, wxWindowID id
,
52 const wxPoint
& pos
= wxDefaultPosition
,
53 const wxSize
& size
= wxDefaultSize
,
54 int n
= 0, const wxString choices
[] = NULL
,
56 const wxValidator
& validator
= wxDefaultValidator
,
57 const wxString
& name
= wxListBoxNameStr
);
61 bool OS2Command(WXUINT param
, WXWORD id
);
64 bool OS2OnMeasure(WXMEASUREITEMSTRUCT
*item
);
65 bool OS2OnDraw(WXDRAWITEMSTRUCT
*item
);
67 // plug-in for derived classes
68 virtual wxOwnerDrawn
*CreateItem(size_t n
);
70 // allows to get the item and use SetXXX functions to set it's appearance
71 wxOwnerDrawn
*GetItem(size_t n
) const { return m_aItems
[n
]; }
73 // get the index of the given item
74 int GetItemIndex(wxOwnerDrawn
*item
) const { return m_aItems
.Index(item
); }
75 #endif // wxUSE_OWNER_DRAWN
77 virtual void Append(const wxString
& item
);
78 virtual void Append(const wxString
& item
, void *clientData
);
79 virtual void Set(int n
, const wxString
* choices
, char **clientData
= NULL
);
80 virtual int FindString(const wxString
& s
) const ;
82 virtual void SetSelection(int n
, bool select
= TRUE
);
84 virtual void Deselect(int n
);
86 // For single choice list item only
87 virtual int GetSelection() const ;
88 virtual void Delete(int n
);
89 virtual void *GetClientData(int n
) const ;
90 virtual void SetClientData(int n
, void *clientData
);
91 virtual void SetString(int n
, const wxString
& s
);
93 // For single or multiple choice list item
94 virtual int GetSelections(wxArrayInt
& aSelections
) const;
95 virtual bool Selected(int n
) const ;
96 virtual wxString
GetString(int n
) const ;
98 // Set the specified item at the first visible item
99 // or scroll to max range.
100 virtual void SetFirstItem(int n
) ;
101 virtual void SetFirstItem(const wxString
& s
) ;
103 virtual void InsertItems(int nItems
, const wxString items
[], int pos
);
105 virtual wxString
GetStringSelection() const ;
106 virtual bool SetStringSelection(const wxString
& s
, bool flag
= TRUE
);
107 virtual int Number() const ;
109 void Command(wxCommandEvent
& event
);
111 // OS/2-PM-specific code to set the horizontal extent of
112 // the listbox, if necessary. If s is non-NULL, it's
113 // used to calculate the horizontal extent.
114 // Otherwise, all strings are used.
115 virtual void SetHorizontalExtent(const wxString
& s
= wxEmptyString
);
117 virtual WXHBRUSH
OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
118 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
120 virtual MRESULT
OS2WindowProc(HWND hwnd
, WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
121 virtual void SetupColours();
127 virtual wxSize
DoGetBestSize();
129 #if wxUSE_OWNER_DRAWN
131 wxListBoxItemsArray m_aItems
;
134 //Virtual function hiding suppression, do not use
135 virtual wxControl
*CreateItem(const wxItemResource
* childResource
,
136 const wxItemResource
* parentResource
,
137 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
)
138 { return(wxWindowBase::CreateItem(childResource
, parentResource
, table
));};