| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: listbox.h |
| 3 | // Purpose: wxListBox class |
| 4 | // Author: Stefan Csomor |
| 5 | // Modified by: |
| 6 | // Created: 1998-01-01 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) Stefan Csomor |
| 9 | // Licence: wxWindows licence |
| 10 | ///////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | |
| 13 | #ifndef _WX_LISTBOX_H_ |
| 14 | #define _WX_LISTBOX_H_ |
| 15 | |
| 16 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
| 17 | #pragma interface "listbox.h" |
| 18 | #endif |
| 19 | |
| 20 | // ---------------------------------------------------------------------------- |
| 21 | // simple types |
| 22 | // ---------------------------------------------------------------------------- |
| 23 | #include "wx/dynarray.h" |
| 24 | #include "wx/arrstr.h" |
| 25 | |
| 26 | #if wxUSE_OWNER_DRAWN |
| 27 | class WXDLLEXPORT wxOwnerDrawn; |
| 28 | |
| 29 | // define the array of list box items |
| 30 | #include "wx/dynarray.h" |
| 31 | |
| 32 | WX_DEFINE_EXPORTED_ARRAY(wxOwnerDrawn *, wxListBoxItemsArray); |
| 33 | #endif // wxUSE_OWNER_DRAWN |
| 34 | |
| 35 | // forward decl for GetSelections() |
| 36 | class wxArrayInt; |
| 37 | |
| 38 | // List box item |
| 39 | |
| 40 | WX_DEFINE_ARRAY( char * , wxListDataArray ) ; |
| 41 | |
| 42 | // ---------------------------------------------------------------------------- |
| 43 | // List box control |
| 44 | // ---------------------------------------------------------------------------- |
| 45 | |
| 46 | class WXDLLEXPORT wxListBox : public wxListBoxBase |
| 47 | { |
| 48 | public: |
| 49 | // ctors and such |
| 50 | wxListBox(); |
| 51 | wxListBox(wxWindow *parent, wxWindowID id, |
| 52 | const wxPoint& pos = wxDefaultPosition, |
| 53 | const wxSize& size = wxDefaultSize, |
| 54 | int n = 0, const wxString choices[] = NULL, |
| 55 | long style = 0, |
| 56 | const wxValidator& validator = wxDefaultValidator, |
| 57 | const wxString& name = wxListBoxNameStr) |
| 58 | { |
| 59 | Create(parent, id, pos, size, n, choices, style, validator, name); |
| 60 | } |
| 61 | wxListBox(wxWindow *parent, wxWindowID id, |
| 62 | const wxPoint& pos, |
| 63 | const wxSize& size, |
| 64 | const wxArrayString& choices, |
| 65 | long style = 0, |
| 66 | const wxValidator& validator = wxDefaultValidator, |
| 67 | const wxString& name = wxListBoxNameStr) |
| 68 | { |
| 69 | Create(parent, id, pos, size, choices, style, validator, name); |
| 70 | } |
| 71 | |
| 72 | bool Create(wxWindow *parent, wxWindowID id, |
| 73 | const wxPoint& pos = wxDefaultPosition, |
| 74 | const wxSize& size = wxDefaultSize, |
| 75 | int n = 0, const wxString choices[] = NULL, |
| 76 | long style = 0, |
| 77 | const wxValidator& validator = wxDefaultValidator, |
| 78 | const wxString& name = wxListBoxNameStr); |
| 79 | bool Create(wxWindow *parent, wxWindowID id, |
| 80 | const wxPoint& pos, |
| 81 | const wxSize& size, |
| 82 | const wxArrayString& choices, |
| 83 | long style = 0, |
| 84 | const wxValidator& validator = wxDefaultValidator, |
| 85 | const wxString& name = wxListBoxNameStr); |
| 86 | |
| 87 | virtual ~wxListBox(); |
| 88 | virtual void Refresh(bool eraseBack = TRUE, const wxRect *rect = NULL); |
| 89 | |
| 90 | // implement base class pure virtuals |
| 91 | virtual void Clear(); |
| 92 | virtual void Delete(int n); |
| 93 | |
| 94 | virtual int GetCount() const; |
| 95 | virtual wxString GetString(int n) const; |
| 96 | virtual void SetString(int n, const wxString& s); |
| 97 | virtual int FindString(const wxString& s) const; |
| 98 | |
| 99 | virtual bool IsSelected(int n) const; |
| 100 | virtual void DoSetSelection(int n, bool select); |
| 101 | virtual int GetSelection() const; |
| 102 | virtual int GetSelections(wxArrayInt& aSelections) const; |
| 103 | |
| 104 | virtual int DoAppend(const wxString& item); |
| 105 | virtual void DoInsertItems(const wxArrayString& items, int pos); |
| 106 | virtual void DoSetItems(const wxArrayString& items, void **clientData); |
| 107 | |
| 108 | virtual void DoSetFirstItem(int n); |
| 109 | |
| 110 | virtual void DoSetItemClientData(int n, void* clientData); |
| 111 | virtual void* DoGetItemClientData(int n) const; |
| 112 | virtual void DoSetItemClientObject(int n, wxClientData* clientData); |
| 113 | virtual wxClientData* DoGetItemClientObject(int n) const; |
| 114 | virtual void DoSetSize(int x, int y,int width, int height,int sizeFlags = wxSIZE_AUTO ) ; |
| 115 | |
| 116 | // wxCheckListBox support |
| 117 | #if wxUSE_OWNER_DRAWN |
| 118 | // plug-in for derived classes |
| 119 | virtual wxOwnerDrawn *CreateItem(size_t n); |
| 120 | |
| 121 | // allows to get the item and use SetXXX functions to set it's appearance |
| 122 | wxOwnerDrawn *GetItem(size_t n) const { return m_aItems[n]; } |
| 123 | |
| 124 | // get the index of the given item |
| 125 | int GetItemIndex(wxOwnerDrawn *item) const { return m_aItems.Index(item); } |
| 126 | #endif // wxUSE_OWNER_DRAWN |
| 127 | |
| 128 | |
| 129 | static wxVisualAttributes |
| 130 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); |
| 131 | |
| 132 | // Windows callbacks |
| 133 | #ifndef __WXMAC_OSX__ |
| 134 | void OnChar(wxKeyEvent& event); |
| 135 | #endif |
| 136 | |
| 137 | void* m_macList ; |
| 138 | wxArrayString m_stringArray ; |
| 139 | wxListDataArray m_dataArray ; |
| 140 | |
| 141 | // as we are getting the same events for human and API selection we have to suppress |
| 142 | // events in the latter case |
| 143 | bool MacIsSelectionSuppressed() const { return m_suppressSelection ; } |
| 144 | protected: |
| 145 | void MacDelete( int n ) ; |
| 146 | void MacInsert( int n , const wxString& item) ; |
| 147 | void MacAppend( const wxString& item) ; |
| 148 | void MacSet( int n , const wxString& item ) ; |
| 149 | void MacClear() ; |
| 150 | void MacDeselectAll() ; |
| 151 | void MacSetSelection( int n , bool select ) ; |
| 152 | int MacGetSelection() const ; |
| 153 | int MacGetSelections(wxArrayInt& aSelections) const ; |
| 154 | bool MacIsSelected( int n ) const ; |
| 155 | void MacScrollTo( int n ) ; |
| 156 | bool MacSuppressSelection( bool suppress ) ; |
| 157 | |
| 158 | // free memory (common part of Clear() and dtor) |
| 159 | // prevent collision with some BSD definitions of macro Free() |
| 160 | void FreeData(); |
| 161 | |
| 162 | int m_noItems; |
| 163 | int m_selected; |
| 164 | bool m_suppressSelection ; |
| 165 | wxString m_typeIn ; |
| 166 | long m_lastTypeIn ; |
| 167 | |
| 168 | virtual wxSize DoGetBestSize() const; |
| 169 | |
| 170 | #if wxUSE_OWNER_DRAWN |
| 171 | // control items |
| 172 | wxListBoxItemsArray m_aItems; |
| 173 | #endif |
| 174 | |
| 175 | private: |
| 176 | DECLARE_DYNAMIC_CLASS(wxListBox) |
| 177 | DECLARE_EVENT_TABLE() |
| 178 | }; |
| 179 | |
| 180 | #endif |
| 181 | // _WX_LISTBOX_H_ |