]> git.saurik.com Git - wxWidgets.git/blame - include/wx/listbox.h
Add factory functions for use with future unit tests.
[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
62a9d04c
VS
26class WXDLLIMPEXP_BASE wxArrayInt;
27class WXDLLIMPEXP_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
fc7a2a60 45 // all generic methods are in wxControlWithItems, except for the following
43e8916f 46 // ones which are not yet implemented by wxChoice/wxComboBox
aa61d352 47 void Insert(const wxString& item, unsigned int pos)
be4bb86e 48 { /* return*/ wxControlWithItems::Insert(item,pos); }
aa61d352 49 void Insert(const wxString& item, unsigned int pos, void *clientData)
be4bb86e 50 { /* return*/ wxControlWithItems::Insert(item,pos,clientData); }
aa61d352 51 void Insert(const wxString& item, unsigned int pos, wxClientData *clientData)
be4bb86e 52 { /* return*/ wxControlWithItems::Insert(item,pos,clientData); }
2ee3ee1b 53
aa61d352
VZ
54 void InsertItems(unsigned int nItems, const wxString *items, unsigned int pos);
55 void InsertItems(const wxArrayString& items, unsigned int pos)
2ee3ee1b
VZ
56 { DoInsertItems(items, pos); }
57
58 void Set(int n, const wxString* items, void **clientData = NULL);
59 void Set(const wxArrayString& items, void **clientData = NULL)
60 { DoSetItems(items, clientData); }
61
6c8a980f 62 // multiple selection logic
2ee3ee1b 63 virtual bool IsSelected(int n) const = 0;
c6179a84
VZ
64 virtual void SetSelection(int n) { DoSetSelection(n, true); }
65 void SetSelection(int n, bool select) { DoSetSelection(n, select); }
66 void Deselect(int n) { DoSetSelection(n, false); }
1e6feb95 67 void DeselectAll(int itemToLeaveSelected = -1);
2ee3ee1b 68
c6179a84
VZ
69 virtual bool SetStringSelection(const wxString& s, bool select);
70 virtual bool SetStringSelection(const wxString& s)
71 {
72 return SetStringSelection(s, true);
73 }
2ee3ee1b 74
6c8a980f
VZ
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;
2ee3ee1b 78
1e6feb95 79 // set the specified item at the first visible item or scroll to max
2ee3ee1b
VZ
80 // range.
81 void SetFirstItem(int n) { DoSetFirstItem(n); }
82 void SetFirstItem(const wxString& s);
83
1e6feb95
VZ
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
f644b28c 92 // return true if the listbox allows multiple selection
1e6feb95
VZ
93 bool HasMultipleSelection() const
94 {
95 return (m_windowStyle & wxLB_MULTIPLE) ||
96 (m_windowStyle & wxLB_EXTENDED);
97 }
98
f644b28c 99 // return true if this listbox is sorted
1e6feb95
VZ
100 bool IsSorted() const { return (m_windowStyle & wxLB_SORT) != 0; }
101
6c8a980f
VZ
102 // emulate selecting or deselecting the item event.GetInt() (depending on
103 // event.GetExtraLong())
104 void Command(wxCommandEvent& event);
2ee3ee1b 105
8243a339
WS
106 // returns the item number at a point or wxNOT_FOUND
107 int HitTest(const wxPoint& point) const { return DoListHitTest(point); }
108
40ff126a 109#if WXWIN_COMPATIBILITY_2_6
2ee3ee1b
VZ
110 // compatibility - these functions are deprecated, use the new ones
111 // instead
40ff126a 112 wxDEPRECATED( bool Selected(int n) const );
40ff126a 113#endif // WXWIN_COMPATIBILITY_2_6
c00fed0e 114
2ee3ee1b
VZ
115protected:
116 // NB: due to wxGTK implementation details, DoInsert() is implemented
117 // using DoInsertItems() and not the other way round
aa61d352 118 virtual int DoInsert(const wxString& item, unsigned int pos)
243dbf1a 119 { InsertItems(1, &item, pos); return pos; }
2ee3ee1b
VZ
120
121 // to be implemented in derived classes
aa61d352 122 virtual void DoInsertItems(const wxArrayString& items, unsigned int pos) = 0;
2ee3ee1b
VZ
123 virtual void DoSetItems(const wxArrayString& items, void **clientData) = 0;
124
125 virtual void DoSetFirstItem(int n) = 0;
fc7a2a60 126
c6179a84
VZ
127 virtual void DoSetSelection(int n, bool select) = 0;
128
c00fed0e
VZ
129 // there is already wxWindow::DoHitTest() so call this one differently
130 virtual int DoListHitTest(const wxPoint& WXUNUSED(point)) const
131 { return wxNOT_FOUND; }
132
c6179a84 133
fc7a2a60 134 DECLARE_NO_COPY_CLASS(wxListBoxBase)
2ee3ee1b
VZ
135};
136
40ff126a
WS
137#if WXWIN_COMPATIBILITY_2_6
138 inline bool wxListBoxBase::Selected(int n) const { return IsSelected(n); }
40ff126a
WS
139#endif // WXWIN_COMPATIBILITY_2_6
140
2ee3ee1b
VZ
141// ----------------------------------------------------------------------------
142// include the platform-specific class declaration
143// ----------------------------------------------------------------------------
144
1e6feb95
VZ
145#if defined(__WXUNIVERSAL__)
146 #include "wx/univ/listbox.h"
147#elif defined(__WXMSW__)
2ee3ee1b 148 #include "wx/msw/listbox.h"
2049ba38 149#elif defined(__WXMOTIF__)
2ee3ee1b 150 #include "wx/motif/listbox.h"
1be7a35c 151#elif defined(__WXGTK20__)
2ee3ee1b 152 #include "wx/gtk/listbox.h"
1be7a35c
MR
153#elif defined(__WXGTK__)
154 #include "wx/gtk1/listbox.h"
34138703 155#elif defined(__WXMAC__)
2ee3ee1b 156 #include "wx/mac/listbox.h"
1777b9bb 157#elif defined(__WXPM__)
2ee3ee1b 158 #include "wx/os2/listbox.h"
e64df9bc
DE
159#elif defined(__WXCOCOA__)
160 #include "wx/cocoa/listbox.h"
c801d85f
KB
161#endif
162
2ee3ee1b
VZ
163#endif // wxUSE_LISTBOX
164
c801d85f 165#endif
34138703 166 // _WX_LISTBOX_H_BASE_