]> git.saurik.com Git - wxWidgets.git/blame - include/wx/listbox.h
Add wxDataViewRendererBase::GetEffectiveAlignment() and use it.
[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
77ffb593 7// Copyright: (c) wxWidgets team
65571936 8// Licence: wxWindows licence
2ee3ee1b
VZ
9///////////////////////////////////////////////////////////////////////////////
10
34138703
JS
11#ifndef _WX_LISTBOX_H_BASE_
12#define _WX_LISTBOX_H_BASE_
c801d85f 13
2ee3ee1b
VZ
14// ----------------------------------------------------------------------------
15// headers
16// ----------------------------------------------------------------------------
17
2ee3ee1b
VZ
18#include "wx/defs.h"
19
20#if wxUSE_LISTBOX
21
6c8a980f 22#include "wx/ctrlsub.h" // base class
2ee3ee1b
VZ
23
24// forward declarations are enough here
b5dbe15d
VS
25class WXDLLIMPEXP_FWD_BASE wxArrayInt;
26class WXDLLIMPEXP_FWD_BASE wxArrayString;
2ee3ee1b
VZ
27
28// ----------------------------------------------------------------------------
29// global data
30// ----------------------------------------------------------------------------
31
53a2db12 32extern WXDLLIMPEXP_DATA_CORE(const char) wxListBoxNameStr[];
2ee3ee1b
VZ
33
34// ----------------------------------------------------------------------------
35// wxListBox interface is defined by the class wxListBoxBase
36// ----------------------------------------------------------------------------
37
53a2db12 38class WXDLLIMPEXP_CORE wxListBoxBase : public wxControlWithItems
2ee3ee1b
VZ
39{
40public:
6463b9f5 41 wxListBoxBase() { }
799ea011 42 virtual ~wxListBoxBase();
2ee3ee1b 43
a236aa20
VZ
44 void InsertItems(unsigned int nItems, const wxString *items, unsigned int pos)
45 { Insert(nItems, items, pos); }
aa61d352 46 void InsertItems(const wxArrayString& items, unsigned int pos)
a236aa20 47 { Insert(items, pos); }
2ee3ee1b 48
6c8a980f 49 // multiple selection logic
2ee3ee1b 50 virtual bool IsSelected(int n) const = 0;
24ee1bef 51 virtual void SetSelection(int n);
c6179a84
VZ
52 void SetSelection(int n, bool select) { DoSetSelection(n, select); }
53 void Deselect(int n) { DoSetSelection(n, false); }
1e6feb95 54 void DeselectAll(int itemToLeaveSelected = -1);
2ee3ee1b 55
c6179a84
VZ
56 virtual bool SetStringSelection(const wxString& s, bool select);
57 virtual bool SetStringSelection(const wxString& s)
58 {
59 return SetStringSelection(s, true);
60 }
2ee3ee1b 61
6c8a980f
VZ
62 // works for single as well as multiple selection listboxes (unlike
63 // GetSelection which only works for listboxes with single selection)
64 virtual int GetSelections(wxArrayInt& aSelections) const = 0;
2ee3ee1b 65
1e6feb95 66 // set the specified item at the first visible item or scroll to max
2ee3ee1b
VZ
67 // range.
68 void SetFirstItem(int n) { DoSetFirstItem(n); }
69 void SetFirstItem(const wxString& s);
70
1e6feb95
VZ
71 // ensures that the given item is visible scrolling the listbox if
72 // necessary
73 virtual void EnsureVisible(int n);
74
75 // a combination of Append() and EnsureVisible(): appends the item to the
76 // listbox and ensures that it is visible i.e. not scrolled out of view
77 void AppendAndEnsureVisible(const wxString& s);
78
f644b28c 79 // return true if the listbox allows multiple selection
1e6feb95
VZ
80 bool HasMultipleSelection() const
81 {
82 return (m_windowStyle & wxLB_MULTIPLE) ||
83 (m_windowStyle & wxLB_EXTENDED);
84 }
85
a236aa20
VZ
86 // override wxItemContainer::IsSorted
87 virtual bool IsSorted() const { return HasFlag( wxLB_SORT ); }
1e6feb95 88
6c8a980f
VZ
89 // emulate selecting or deselecting the item event.GetInt() (depending on
90 // event.GetExtraLong())
91 void Command(wxCommandEvent& event);
2ee3ee1b 92
0a03dc7a 93 // return the index of the item at this position or wxNOT_FOUND
8243a339 94 int HitTest(const wxPoint& point) const { return DoListHitTest(point); }
0a03dc7a
VZ
95 int HitTest(int x, int y) const { return DoListHitTest(wxPoint(x, y)); }
96
8243a339 97
2ee3ee1b 98protected:
2ee3ee1b 99 virtual void DoSetFirstItem(int n) = 0;
fc7a2a60 100
c6179a84
VZ
101 virtual void DoSetSelection(int n, bool select) = 0;
102
c00fed0e
VZ
103 // there is already wxWindow::DoHitTest() so call this one differently
104 virtual int DoListHitTest(const wxPoint& WXUNUSED(point)) const
105 { return wxNOT_FOUND; }
106
24ee1bef
VZ
107 // Helper for the code generating events in single selection mode: updates
108 // m_oldSelections and return true if the selection really changed.
109 // Otherwise just returns false.
110 bool DoChangeSingleSelection(int item);
111
112 // Helper for generating events in multiple and extended mode: compare the
113 // current selections with the previously recorded ones (in
114 // m_oldSelections) and send the appropriate event if they differ,
115 // otherwise just return false.
116 bool CalcAndSendEvent();
117
53f60d4a
VZ
118 // Send a listbox (de)selection or double click event.
119 //
120 // Returns true if the event was processed.
121 bool SendEvent(wxEventType evtType, int item, bool selected);
122
c07b0669
VZ
123 // Array storing the indices of all selected items that we already notified
124 // the user code about for multi selection list boxes.
125 //
24ee1bef
VZ
126 // For single selection list boxes, we reuse this array to store the single
127 // currently selected item, this is used by DoChangeSingleSelection().
128 //
c07b0669
VZ
129 // TODO-OPT: wxSelectionStore would be more efficient for big list boxes.
130 wxArrayInt m_oldSelections;
131
132 // Update m_oldSelections with currently selected items (does nothing in
a614ffae 133 // single selection mode on platforms other than MSW).
c07b0669
VZ
134 void UpdateOldSelections();
135
a236aa20 136private:
c0c133e1 137 wxDECLARE_NO_COPY_CLASS(wxListBoxBase);
2ee3ee1b
VZ
138};
139
140// ----------------------------------------------------------------------------
141// include the platform-specific class declaration
142// ----------------------------------------------------------------------------
143
1e6feb95
VZ
144#if defined(__WXUNIVERSAL__)
145 #include "wx/univ/listbox.h"
146#elif defined(__WXMSW__)
2ee3ee1b 147 #include "wx/msw/listbox.h"
2049ba38 148#elif defined(__WXMOTIF__)
2ee3ee1b 149 #include "wx/motif/listbox.h"
1be7a35c 150#elif defined(__WXGTK20__)
2ee3ee1b 151 #include "wx/gtk/listbox.h"
1be7a35c
MR
152#elif defined(__WXGTK__)
153 #include "wx/gtk1/listbox.h"
34138703 154#elif defined(__WXMAC__)
ef0e9220 155 #include "wx/osx/listbox.h"
1777b9bb 156#elif defined(__WXPM__)
2ee3ee1b 157 #include "wx/os2/listbox.h"
e64df9bc
DE
158#elif defined(__WXCOCOA__)
159 #include "wx/cocoa/listbox.h"
c801d85f
KB
160#endif
161
2ee3ee1b
VZ
162#endif // wxUSE_LISTBOX
163
c801d85f 164#endif
34138703 165 // _WX_LISTBOX_H_BASE_