Source cleaning: whitespaces, -1/wxID_ANY/wxNOT_FOUND, TRUE/true, FALSE/false.
[wxWidgets.git] / include / wx / listbox.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/listbox.h
3 // Purpose: wxListBox class interface
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 22.10.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_LISTBOX_H_BASE_
13 #define _WX_LISTBOX_H_BASE_
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
20 #pragma interface "listboxbase.h"
21 #endif
22
23 #include "wx/defs.h"
24
25 #if wxUSE_LISTBOX
26
27 #include "wx/ctrlsub.h" // base class
28
29 // forward declarations are enough here
30 class WXDLLIMPEXP_BASE wxArrayInt;
31 class WXDLLIMPEXP_BASE wxArrayString;
32
33 // ----------------------------------------------------------------------------
34 // global data
35 // ----------------------------------------------------------------------------
36
37 WXDLLEXPORT_DATA(extern const wxChar*) wxListBoxNameStr;
38
39 // ----------------------------------------------------------------------------
40 // wxListBox interface is defined by the class wxListBoxBase
41 // ----------------------------------------------------------------------------
42
43 class WXDLLEXPORT wxListBoxBase : public wxControlWithItems
44 {
45 public:
46 wxListBoxBase() { }
47 virtual ~wxListBoxBase();
48
49 // all generic methods are in wxControlWithItems, except for the following
50 // ones which are not yet implemented by wxChoice/wxCombobox
51 void Insert(const wxString& item, int pos)
52 { DoInsert(item, pos); }
53 void Insert(const wxString& item, int pos, void *clientData)
54 { DoInsert(item, pos); SetClientData(pos, clientData); }
55 void Insert(const wxString& item, int pos, wxClientData *clientData)
56 { DoInsert(item, pos); SetClientObject(pos, clientData); }
57
58 void InsertItems(int nItems, const wxString *items, int pos);
59 void InsertItems(const wxArrayString& items, int pos)
60 { DoInsertItems(items, pos); }
61
62 void Set(int n, const wxString* items, void **clientData = NULL);
63 void Set(const wxArrayString& items, void **clientData = NULL)
64 { DoSetItems(items, clientData); }
65
66 // multiple selection logic
67 virtual bool IsSelected(int n) const = 0;
68 virtual void SetSelection(int n, bool select = true) = 0;
69 virtual void Select(int n) { SetSelection(n, true); }
70 void Deselect(int n) { SetSelection(n, false); }
71 void DeselectAll(int itemToLeaveSelected = -1);
72
73 virtual bool SetStringSelection(const wxString& s, bool select = true);
74
75 // works for single as well as multiple selection listboxes (unlike
76 // GetSelection which only works for listboxes with single selection)
77 virtual int GetSelections(wxArrayInt& aSelections) const = 0;
78
79 // set the specified item at the first visible item or scroll to max
80 // range.
81 void SetFirstItem(int n) { DoSetFirstItem(n); }
82 void SetFirstItem(const wxString& s);
83
84 // ensures that the given item is visible scrolling the listbox if
85 // necessary
86 virtual void EnsureVisible(int n);
87
88 // a combination of Append() and EnsureVisible(): appends the item to the
89 // listbox and ensures that it is visible i.e. not scrolled out of view
90 void AppendAndEnsureVisible(const wxString& s);
91
92 // return true if the listbox allows multiple selection
93 bool HasMultipleSelection() const
94 {
95 return (m_windowStyle & wxLB_MULTIPLE) ||
96 (m_windowStyle & wxLB_EXTENDED);
97 }
98
99 // return true if this listbox is sorted
100 bool IsSorted() const { return (m_windowStyle & wxLB_SORT) != 0; }
101
102 // emulate selecting or deselecting the item event.GetInt() (depending on
103 // event.GetExtraLong())
104 void Command(wxCommandEvent& event);
105
106 // compatibility - these functions are deprecated, use the new ones
107 // instead
108 bool Selected(int n) const { return IsSelected(n); }
109
110 protected:
111 // NB: due to wxGTK implementation details, DoInsert() is implemented
112 // using DoInsertItems() and not the other way round
113 virtual int DoInsert(const wxString& item, int pos)
114 { InsertItems(1, &item, pos); return pos; }
115
116 // to be implemented in derived classes
117 virtual void DoInsertItems(const wxArrayString& items, int pos) = 0;
118 virtual void DoSetItems(const wxArrayString& items, void **clientData) = 0;
119
120 virtual void DoSetFirstItem(int n) = 0;
121
122 DECLARE_NO_COPY_CLASS(wxListBoxBase)
123 };
124
125 // ----------------------------------------------------------------------------
126 // include the platform-specific class declaration
127 // ----------------------------------------------------------------------------
128
129 #if defined(__WXUNIVERSAL__)
130 #include "wx/univ/listbox.h"
131 #elif defined(__WXMSW__)
132 #include "wx/msw/listbox.h"
133 #elif defined(__WXMOTIF__)
134 #include "wx/motif/listbox.h"
135 #elif defined(__WXGTK__)
136 #include "wx/gtk/listbox.h"
137 #elif defined(__WXMAC__)
138 #include "wx/mac/listbox.h"
139 #elif defined(__WXPM__)
140 #include "wx/os2/listbox.h"
141 #elif defined(__WXCOCOA__)
142 #include "wx/cocoa/listbox.h"
143 #endif
144
145 #endif // wxUSE_LISTBOX
146
147 #endif
148 // _WX_LISTBOX_H_BASE_