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