]> git.saurik.com Git - wxWidgets.git/blame - include/wx/listbox.h
correct closing comments in #endifs (patch 1756990)
[wxWidgets.git] / include / wx / listbox.h
CommitLineData
2ee3ee1b
VZ
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$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
2ee3ee1b
VZ
10///////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_LISTBOX_H_BASE_
13#define _WX_LISTBOX_H_BASE_
c801d85f 14
2ee3ee1b
VZ
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
2ee3ee1b
VZ
19#include "wx/defs.h"
20
21#if wxUSE_LISTBOX
22
6c8a980f 23#include "wx/ctrlsub.h" // base class
2ee3ee1b
VZ
24
25// forward declarations are enough here
b5dbe15d
VS
26class WXDLLIMPEXP_FWD_BASE wxArrayInt;
27class WXDLLIMPEXP_FWD_BASE wxArrayString;
2ee3ee1b
VZ
28
29// ----------------------------------------------------------------------------
30// global data
31// ----------------------------------------------------------------------------
32
63ec432b 33extern WXDLLEXPORT_DATA(const wxChar) wxListBoxNameStr[];
2ee3ee1b
VZ
34
35// ----------------------------------------------------------------------------
36// wxListBox interface is defined by the class wxListBoxBase
37// ----------------------------------------------------------------------------
38
6c8a980f 39class WXDLLEXPORT wxListBoxBase : public wxControlWithItems
2ee3ee1b
VZ
40{
41public:
6463b9f5 42 wxListBoxBase() { }
799ea011 43 virtual ~wxListBoxBase();
2ee3ee1b 44
aa61d352
VZ
45 void InsertItems(unsigned int nItems, const wxString *items, unsigned int pos);
46 void InsertItems(const wxArrayString& items, unsigned int pos)
2ee3ee1b
VZ
47 { DoInsertItems(items, pos); }
48
49 void Set(int n, const wxString* items, void **clientData = NULL);
50 void Set(const wxArrayString& items, void **clientData = NULL)
51 { DoSetItems(items, clientData); }
52
6c8a980f 53 // multiple selection logic
2ee3ee1b 54 virtual bool IsSelected(int n) const = 0;
c6179a84
VZ
55 virtual void SetSelection(int n) { DoSetSelection(n, true); }
56 void SetSelection(int n, bool select) { DoSetSelection(n, select); }
57 void Deselect(int n) { DoSetSelection(n, false); }
1e6feb95 58 void DeselectAll(int itemToLeaveSelected = -1);
2ee3ee1b 59
c6179a84
VZ
60 virtual bool SetStringSelection(const wxString& s, bool select);
61 virtual bool SetStringSelection(const wxString& s)
62 {
63 return SetStringSelection(s, true);
64 }
2ee3ee1b 65
6c8a980f
VZ
66 // works for single as well as multiple selection listboxes (unlike
67 // GetSelection which only works for listboxes with single selection)
68 virtual int GetSelections(wxArrayInt& aSelections) const = 0;
2ee3ee1b 69
1e6feb95 70 // set the specified item at the first visible item or scroll to max
2ee3ee1b
VZ
71 // range.
72 void SetFirstItem(int n) { DoSetFirstItem(n); }
73 void SetFirstItem(const wxString& s);
74
1e6feb95
VZ
75 // ensures that the given item is visible scrolling the listbox if
76 // necessary
77 virtual void EnsureVisible(int n);
78
79 // a combination of Append() and EnsureVisible(): appends the item to the
80 // listbox and ensures that it is visible i.e. not scrolled out of view
81 void AppendAndEnsureVisible(const wxString& s);
82
f644b28c 83 // return true if the listbox allows multiple selection
1e6feb95
VZ
84 bool HasMultipleSelection() const
85 {
86 return (m_windowStyle & wxLB_MULTIPLE) ||
87 (m_windowStyle & wxLB_EXTENDED);
88 }
89
f644b28c 90 // return true if this listbox is sorted
1e6feb95
VZ
91 bool IsSorted() const { return (m_windowStyle & wxLB_SORT) != 0; }
92
6c8a980f
VZ
93 // emulate selecting or deselecting the item event.GetInt() (depending on
94 // event.GetExtraLong())
95 void Command(wxCommandEvent& event);
2ee3ee1b 96
8243a339
WS
97 // returns the item number at a point or wxNOT_FOUND
98 int HitTest(const wxPoint& point) const { return DoListHitTest(point); }
99
40ff126a 100#if WXWIN_COMPATIBILITY_2_6
2ee3ee1b
VZ
101 // compatibility - these functions are deprecated, use the new ones
102 // instead
40ff126a 103 wxDEPRECATED( bool Selected(int n) const );
40ff126a 104#endif // WXWIN_COMPATIBILITY_2_6
c00fed0e 105
2ee3ee1b
VZ
106protected:
107 // NB: due to wxGTK implementation details, DoInsert() is implemented
108 // using DoInsertItems() and not the other way round
aa61d352 109 virtual int DoInsert(const wxString& item, unsigned int pos)
243dbf1a 110 { InsertItems(1, &item, pos); return pos; }
2ee3ee1b
VZ
111
112 // to be implemented in derived classes
aa61d352 113 virtual void DoInsertItems(const wxArrayString& items, unsigned int pos) = 0;
2ee3ee1b
VZ
114 virtual void DoSetItems(const wxArrayString& items, void **clientData) = 0;
115
116 virtual void DoSetFirstItem(int n) = 0;
fc7a2a60 117
c6179a84
VZ
118 virtual void DoSetSelection(int n, bool select) = 0;
119
c00fed0e
VZ
120 // there is already wxWindow::DoHitTest() so call this one differently
121 virtual int DoListHitTest(const wxPoint& WXUNUSED(point)) const
122 { return wxNOT_FOUND; }
123
c6179a84 124
fc7a2a60 125 DECLARE_NO_COPY_CLASS(wxListBoxBase)
2ee3ee1b
VZ
126};
127
40ff126a
WS
128#if WXWIN_COMPATIBILITY_2_6
129 inline bool wxListBoxBase::Selected(int n) const { return IsSelected(n); }
40ff126a
WS
130#endif // WXWIN_COMPATIBILITY_2_6
131
2ee3ee1b
VZ
132// ----------------------------------------------------------------------------
133// include the platform-specific class declaration
134// ----------------------------------------------------------------------------
135
1e6feb95
VZ
136#if defined(__WXUNIVERSAL__)
137 #include "wx/univ/listbox.h"
138#elif defined(__WXMSW__)
2ee3ee1b 139 #include "wx/msw/listbox.h"
2049ba38 140#elif defined(__WXMOTIF__)
2ee3ee1b 141 #include "wx/motif/listbox.h"
1be7a35c 142#elif defined(__WXGTK20__)
2ee3ee1b 143 #include "wx/gtk/listbox.h"
1be7a35c
MR
144#elif defined(__WXGTK__)
145 #include "wx/gtk1/listbox.h"
34138703 146#elif defined(__WXMAC__)
2ee3ee1b 147 #include "wx/mac/listbox.h"
1777b9bb 148#elif defined(__WXPM__)
2ee3ee1b 149 #include "wx/os2/listbox.h"
e64df9bc
DE
150#elif defined(__WXCOCOA__)
151 #include "wx/cocoa/listbox.h"
c801d85f
KB
152#endif
153
2ee3ee1b
VZ
154#endif // wxUSE_LISTBOX
155
c801d85f 156#endif
34138703 157 // _WX_LISTBOX_H_BASE_