| 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 WXDLLEXPORT 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_BASE wxArrayInt; |
| 32 | |
| 33 | // ---------------------------------------------------------------------------- |
| 34 | // List box control |
| 35 | // ---------------------------------------------------------------------------- |
| 36 | |
| 37 | class WXDLLEXPORT 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 | // implement base class pure virtuals |
| 81 | virtual void Clear(); |
| 82 | virtual void Delete(int n); |
| 83 | |
| 84 | virtual int GetCount() const; |
| 85 | virtual wxString GetString(int n) const; |
| 86 | virtual void SetString(int n, const wxString& s); |
| 87 | virtual int FindString(const wxString& s, bool bCase = false) const; |
| 88 | |
| 89 | virtual bool IsSelected(int n) const; |
| 90 | virtual void DoSetSelection(int n, bool select); |
| 91 | virtual int GetSelection() const; |
| 92 | virtual int GetSelections(wxArrayInt& aSelections) const; |
| 93 | |
| 94 | virtual int DoAppend(const wxString& item); |
| 95 | virtual void DoInsertItems(const wxArrayString& items, int pos); |
| 96 | virtual void DoSetItems(const wxArrayString& items, void **clientData); |
| 97 | |
| 98 | virtual void DoSetFirstItem(int n); |
| 99 | |
| 100 | virtual void DoSetItemClientData(int n, void* clientData); |
| 101 | virtual void* DoGetItemClientData(int n) const; |
| 102 | virtual void DoSetItemClientObject(int n, wxClientData* clientData); |
| 103 | virtual wxClientData* DoGetItemClientObject(int n) const; |
| 104 | |
| 105 | // wxCheckListBox support |
| 106 | #if wxUSE_OWNER_DRAWN |
| 107 | bool MSWOnMeasure(WXMEASUREITEMSTRUCT *item); |
| 108 | bool MSWOnDraw(WXDRAWITEMSTRUCT *item); |
| 109 | |
| 110 | // plug-in for derived classes |
| 111 | virtual wxOwnerDrawn *CreateLboxItem(size_t n); |
| 112 | |
| 113 | // allows to get the item and use SetXXX functions to set it's appearance |
| 114 | wxOwnerDrawn *GetItem(size_t n) const { return m_aItems[n]; } |
| 115 | |
| 116 | // get the index of the given item |
| 117 | int GetItemIndex(wxOwnerDrawn *item) const { return m_aItems.Index(item); } |
| 118 | #endif // wxUSE_OWNER_DRAWN |
| 119 | |
| 120 | // Windows-specific code to set the horizontal extent of the listbox, if |
| 121 | // necessary. If s is non-NULL, it's used to calculate the horizontal |
| 122 | // extent. Otherwise, all strings are used. |
| 123 | virtual void SetHorizontalExtent(const wxString& s = wxEmptyString); |
| 124 | |
| 125 | // Windows callbacks |
| 126 | bool MSWCommand(WXUINT param, WXWORD id); |
| 127 | |
| 128 | virtual wxVisualAttributes GetDefaultAttributes() const |
| 129 | { |
| 130 | return GetClassDefaultAttributes(GetWindowVariant()); |
| 131 | } |
| 132 | |
| 133 | static wxVisualAttributes |
| 134 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL) |
| 135 | { |
| 136 | return GetCompositeControlsDefaultAttributes(variant); |
| 137 | } |
| 138 | |
| 139 | protected: |
| 140 | WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const; |
| 141 | |
| 142 | // free memory (common part of Clear() and dtor) |
| 143 | void Free(); |
| 144 | |
| 145 | int m_noItems; |
| 146 | int m_selected; |
| 147 | |
| 148 | virtual wxSize DoGetBestSize() const; |
| 149 | |
| 150 | // under XP when using "transition effect for menus and tooltips" if we |
| 151 | // return true for WM_PRINTCLIENT here then it causes noticable slowdown |
| 152 | virtual bool MSWShouldPropagatePrintChild() |
| 153 | { |
| 154 | return false; |
| 155 | } |
| 156 | |
| 157 | #if wxUSE_OWNER_DRAWN |
| 158 | // control items |
| 159 | wxListBoxItemsArray m_aItems; |
| 160 | #endif |
| 161 | |
| 162 | private: |
| 163 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxListBox) |
| 164 | }; |
| 165 | |
| 166 | #endif // wxUSE_LISTBOX |
| 167 | |
| 168 | #endif |
| 169 | // _WX_LISTBOX_H_ |