]> git.saurik.com Git - wxWidgets.git/blame - include/wx/htmllbox.h
Add some basic tests for wxDataViewCtrl selection handling.
[wxWidgets.git] / include / wx / htmllbox.h
CommitLineData
e0c6027b
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/htmllbox.h
3// Purpose: wxHtmlListBox is a listbox whose items are wxHtmlCells
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 31.05.03
7// RCS-ID: $Id$
77ffb593 8// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
65571936 9// Licence: wxWindows licence
e0c6027b
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_HTMLLBOX_H_
13#define _WX_HTMLLBOX_H_
14
15#include "wx/vlbox.h" // base class
bc55e31b 16#include "wx/html/htmlwin.h"
9ebb7cad 17#include "wx/ctrlsub.h"
e0c6027b 18
2d814c19
VZ
19#if wxUSE_FILESYSTEM
20 #include "wx/filesys.h"
21#endif // wxUSE_FILESYSTEM
22
b5dbe15d
VS
23class WXDLLIMPEXP_FWD_HTML wxHtmlCell;
24class WXDLLIMPEXP_FWD_HTML wxHtmlWinParser;
25class WXDLLIMPEXP_FWD_HTML wxHtmlListBoxCache;
26class WXDLLIMPEXP_FWD_HTML wxHtmlListBoxStyle;
e0c6027b 27
23318a53
FM
28extern WXDLLIMPEXP_DATA_HTML(const char) wxHtmlListBoxNameStr[];
29extern WXDLLIMPEXP_DATA_HTML(const char) wxSimpleHtmlListBoxNameStr[];
9ebb7cad 30
e0c6027b
VZ
31// ----------------------------------------------------------------------------
32// wxHtmlListBox
33// ----------------------------------------------------------------------------
34
bc55e31b
VS
35class WXDLLIMPEXP_HTML wxHtmlListBox : public wxVListBox,
36 public wxHtmlWindowInterface,
31297dbb 37 public wxHtmlWindowMouseHelper
e0c6027b 38{
0c8392ca 39 DECLARE_ABSTRACT_CLASS(wxHtmlListBox)
e0c6027b
VZ
40public:
41 // constructors and such
42 // ---------------------
43
44 // default constructor, you must call Create() later
bc55e31b 45 wxHtmlListBox();
e0c6027b
VZ
46
47 // normal constructor which calls Create() internally
48 wxHtmlListBox(wxWindow *parent,
49 wxWindowID id = wxID_ANY,
50 const wxPoint& pos = wxDefaultPosition,
51 const wxSize& size = wxDefaultSize,
e0c6027b 52 long style = 0,
9ebb7cad 53 const wxString& name = wxHtmlListBoxNameStr);
e0c6027b
VZ
54
55 // really creates the control and sets the initial number of items in it
56 // (which may be changed later with SetItemCount())
57 //
43e319a3 58 // the only special style which may be specified here is wxLB_MULTIPLE
e0c6027b
VZ
59 //
60 // returns true on success or false if the control couldn't be created
61 bool Create(wxWindow *parent,
62 wxWindowID id = wxID_ANY,
63 const wxPoint& pos = wxDefaultPosition,
64 const wxSize& size = wxDefaultSize,
e0c6027b 65 long style = 0,
9ebb7cad 66 const wxString& name = wxHtmlListBoxNameStr);
e0c6027b
VZ
67
68 // destructor cleans up whatever resources we use
69 virtual ~wxHtmlListBox();
70
03495767 71 // override some base class virtuals
e02c72fa
VZ
72 virtual void RefreshRow(size_t line);
73 virtual void RefreshRows(size_t from, size_t to);
5ecdc7ab 74 virtual void RefreshAll();
03495767 75 virtual void SetItemCount(size_t count);
5ecdc7ab 76
2d814c19
VZ
77#if wxUSE_FILESYSTEM
78 // retrieve the file system used by the wxHtmlWinParser: if you use
79 // relative paths in your HTML, you should use its ChangePathTo() method
80 wxFileSystem& GetFileSystem() { return m_filesystem; }
81 const wxFileSystem& GetFileSystem() const { return m_filesystem; }
82#endif // wxUSE_FILESYSTEM
83
bc55e31b
VS
84 virtual void OnInternalIdle();
85
e0c6027b
VZ
86protected:
87 // this method must be implemented in the derived class and should return
88 // the body (i.e. without <html>) of the HTML for the given item
89 virtual wxString OnGetItem(size_t n) const = 0;
90
91 // this function may be overridden to decorate HTML returned by OnGetItem()
92 virtual wxString OnGetItemMarkup(size_t n) const;
93
94
9a9b4940
VZ
95 // this method allows to customize the selection appearance: it may be used
96 // to specify the colour of the text which normally has the given colour
97 // colFg when it is inside the selection
98 //
99 // by default, the original colour is not used at all and all text has the
100 // same (default for this system) colour inside selection
101 virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
102
103 // this is the same as GetSelectedTextColour() but allows to customize the
104 // background colour -- this is even more rarely used as you can change it
105 // globally using SetSelectionBackground()
106 virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
107
108
e0c6027b
VZ
109 // we implement both of these functions in terms of OnGetItem(), they are
110 // not supposed to be overridden by our descendants
111 virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const;
112 virtual wxCoord OnMeasureItem(size_t n) const;
113
c848185a
VZ
114 // override this one to draw custom background for selected items correctly
115 virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
116
117 // this method may be overridden to handle clicking on a link in the
118 // listbox (by default, clicks on links are simply ignored)
a1c3cdc4 119 virtual void OnLinkClicked(size_t n, const wxHtmlLinkInfo& link);
e0c6027b 120
5ecdc7ab
VZ
121 // event handlers
122 void OnSize(wxSizeEvent& event);
bc55e31b
VS
123 void OnMouseMove(wxMouseEvent& event);
124 void OnLeftDown(wxMouseEvent& event);
5ecdc7ab
VZ
125
126
e0c6027b
VZ
127 // common part of all ctors
128 void Init();
129
130 // ensure that the given item is cached
131 void CacheItem(size_t n) const;
132
bc55e31b
VS
133private:
134 // wxHtmlWindowInterface methods:
135 virtual void SetHTMLWindowTitle(const wxString& title);
136 virtual void OnHTMLLinkClicked(const wxHtmlLinkInfo& link);
137 virtual wxHtmlOpeningStatus OnHTMLOpeningURL(wxHtmlURLType type,
138 const wxString& url,
139 wxString *redirect) const;
140 virtual wxPoint HTMLCoordsToWindow(wxHtmlCell *cell,
141 const wxPoint& pos) const;
142 virtual wxWindow* GetHTMLWindow();
143 virtual wxColour GetHTMLBackgroundColour() const;
144 virtual void SetHTMLBackgroundColour(const wxColour& clr);
145 virtual void SetHTMLBackgroundImage(const wxBitmap& bmpBg);
146 virtual void SetHTMLStatusText(const wxString& text);
88a1b648 147 virtual wxCursor GetHTMLCursor(HTMLCursor type) const;
bc55e31b
VS
148
149 // returns index of item that contains given HTML cell
150 size_t GetItemForCell(const wxHtmlCell *cell) const;
151
152 // return physical coordinates of root wxHtmlCell of n-th item
153 wxPoint GetRootCellCoords(size_t n) const;
154
155 // Converts physical coordinates stored in @a pos into coordinates
156 // relative to the root cell of the item under mouse cursor, if any. If no
157 // cell is found under the cursor, returns false. Otherwise stores the new
158 // coordinates back into @a pos and pointer to the cell under cursor into
159 // @a cell and returns true.
160 bool PhysicalCoordsToCell(wxPoint& pos, wxHtmlCell*& cell) const;
161
162 // The opposite of PhysicalCoordsToCell: converts coordinates relative to
163 // given cell to physical coordinates in the window
164 wxPoint CellCoordsToPhysical(const wxPoint& pos, wxHtmlCell *cell) const;
165
e0c6027b 166private:
9a9b4940 167 // this class caches the pre-parsed HTML to speed up display
e0c6027b
VZ
168 wxHtmlListBoxCache *m_cache;
169
170 // HTML parser we use
171 wxHtmlWinParser *m_htmlParser;
5ecdc7ab 172
2d814c19
VZ
173#if wxUSE_FILESYSTEM
174 // file system used by m_htmlParser
175 wxFileSystem m_filesystem;
176#endif // wxUSE_FILESYSTEM
177
9a9b4940
VZ
178 // rendering style for the parser which allows us to customize our colours
179 wxHtmlListBoxStyle *m_htmlRendStyle;
180
181
182 // it calls our GetSelectedTextColour() and GetSelectedTextBgColour()
183 friend class wxHtmlListBoxStyle;
bc55e31b 184 friend class wxHtmlListBoxWinInterface;
9a9b4940 185
5ecdc7ab
VZ
186
187 DECLARE_EVENT_TABLE()
c0c133e1 188 wxDECLARE_NO_COPY_CLASS(wxHtmlListBox);
e0c6027b
VZ
189};
190
9ebb7cad
VZ
191
192// ----------------------------------------------------------------------------
193// wxSimpleHtmlListBox
194// ----------------------------------------------------------------------------
195
196#define wxHLB_DEFAULT_STYLE wxBORDER_SUNKEN
197#define wxHLB_MULTIPLE wxLB_MULTIPLE
198
bf8f1022
VZ
199class WXDLLIMPEXP_HTML wxSimpleHtmlListBox :
200 public wxWindowWithItems<wxHtmlListBox, wxItemContainer>
9ebb7cad 201{
5cef2f65 202 DECLARE_ABSTRACT_CLASS(wxSimpleHtmlListBox)
9ebb7cad
VZ
203public:
204 // wxListbox-compatible constructors
205 // ---------------------------------
206
207 wxSimpleHtmlListBox() { }
208
209 wxSimpleHtmlListBox(wxWindow *parent,
210 wxWindowID id,
211 const wxPoint& pos = wxDefaultPosition,
212 const wxSize& size = wxDefaultSize,
213 int n = 0, const wxString choices[] = NULL,
214 long style = wxHLB_DEFAULT_STYLE,
215 const wxValidator& validator = wxDefaultValidator,
216 const wxString& name = wxSimpleHtmlListBoxNameStr)
217 {
218 Create(parent, id, pos, size, n, choices, style, validator, name);
219 }
220
221 wxSimpleHtmlListBox(wxWindow *parent,
222 wxWindowID id,
223 const wxPoint& pos,
224 const wxSize& size,
225 const wxArrayString& choices,
226 long style = wxHLB_DEFAULT_STYLE,
227 const wxValidator& validator = wxDefaultValidator,
228 const wxString& name = wxSimpleHtmlListBoxNameStr)
229 {
230 Create(parent, id, pos, size, choices, style, validator, name);
231 }
232
233 bool Create(wxWindow *parent, wxWindowID id,
234 const wxPoint& pos = wxDefaultPosition,
235 const wxSize& size = wxDefaultSize,
236 int n = 0, const wxString choices[] = NULL,
237 long style = wxHLB_DEFAULT_STYLE,
238 const wxValidator& validator = wxDefaultValidator,
239 const wxString& name = wxSimpleHtmlListBoxNameStr);
240 bool Create(wxWindow *parent, wxWindowID id,
241 const wxPoint& pos,
242 const wxSize& size,
243 const wxArrayString& choices,
244 long style = wxHLB_DEFAULT_STYLE,
245 const wxValidator& validator = wxDefaultValidator,
246 const wxString& name = wxSimpleHtmlListBoxNameStr);
d54b227f 247
9ebb7cad
VZ
248 virtual ~wxSimpleHtmlListBox();
249
250 // these must be overloaded otherwise the compiler will complain
251 // about wxItemContainerImmutable::[G|S]etSelection being pure virtuals...
252 void SetSelection(int n)
d54b227f 253 { wxVListBox::SetSelection(n); }
9ebb7cad
VZ
254 int GetSelection() const
255 { return wxVListBox::GetSelection(); }
256
9ebb7cad
VZ
257
258 // accessing strings
259 // -----------------
260
261 virtual unsigned int GetCount() const
262 { return m_items.GetCount(); }
263
264 virtual wxString GetString(unsigned int n) const;
265
266 // override default unoptimized wxItemContainer::GetStrings() function
267 wxArrayString GetStrings() const
268 { return m_items; }
269
270 virtual void SetString(unsigned int n, const wxString& s);
271
e52cd41e
VZ
272 // resolve ambiguity between wxItemContainer and wxVListBox versions
273 void Clear();
9ebb7cad
VZ
274
275protected:
a236aa20
VZ
276 virtual int DoInsertItems(const wxArrayStringsAdapter & items,
277 unsigned int pos,
278 void **clientData, wxClientDataType type);
9ebb7cad
VZ
279
280 virtual void DoSetItemClientData(unsigned int n, void *clientData)
9d8f8138 281 { m_HTMLclientData[n] = clientData; }
9ebb7cad
VZ
282
283 virtual void *DoGetItemClientData(unsigned int n) const
9d8f8138 284 { return m_HTMLclientData[n]; }
9ebb7cad 285
e52cd41e
VZ
286 // wxItemContainer methods
287 virtual void DoClear();
288 virtual void DoDeleteOneItem(unsigned int n);
289
9ebb7cad
VZ
290 // calls wxHtmlListBox::SetItemCount() and RefreshAll()
291 void UpdateCount();
292
e52cd41e 293 // override these functions just to change their visibility: users of
9ebb7cad
VZ
294 // wxSimpleHtmlListBox shouldn't be allowed to call them directly!
295 virtual void SetItemCount(size_t count)
d54b227f 296 { wxHtmlListBox::SetItemCount(count); }
f18eaf26
VZ
297 virtual void SetRowCount(size_t count)
298 { wxHtmlListBox::SetRowCount(count); }
9ebb7cad
VZ
299
300 virtual wxString OnGetItem(size_t n) const
301 { return m_items[n]; }
302
538483d8
FM
303 virtual void InitEvent(wxCommandEvent& event, int n)
304 {
305 // we're not a virtual control and we can include the string
306 // of the item which was clicked:
307 event.SetString(m_items[n]);
308 wxVListBox::InitEvent(event, n);
309 }
310
67339f7d
JS
311 wxArrayString m_items;
312 wxArrayPtrVoid m_HTMLclientData;
313
9d8f8138
SN
314 // Note: For the benefit of old compilers (like gcc-2.8) this should
315 // not be named m_clientdata as that clashes with the name of an
316 // anonymous struct member in wxEvtHandler, which we derive from.
9ebb7cad 317
c0c133e1 318 wxDECLARE_NO_COPY_CLASS(wxSimpleHtmlListBox);
9ebb7cad
VZ
319};
320
e0c6027b
VZ
321#endif // _WX_HTMLLBOX_H_
322