]> git.saurik.com Git - wxWidgets.git/blame - include/wx/htmllbox.h
Children need to be updated in size_allocate even if widget is not realized.
[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
6acba9a7
VS
23class WXDLLIMPEXP_HTML wxHtmlCell;
24class WXDLLIMPEXP_HTML wxHtmlWinParser;
25class WXDLLIMPEXP_HTML wxHtmlListBoxCache;
26class WXDLLIMPEXP_HTML wxHtmlListBoxStyle;
e0c6027b 27
14d8546a
MW
28extern WXDLLIMPEXP_DATA_HTML(const wxChar) wxHtmlListBoxNameStr[];
29extern WXDLLIMPEXP_DATA_HTML(const wxChar) 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
5c2a509f
VZ
72 virtual void RefreshLine(size_t line);
73 virtual void RefreshLines(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
bc55e31b
VS
114 // This method may be overriden to handle clicking on a link in
115 // the listbox. By default, clicking links is ignored.
a1c3cdc4 116 virtual void OnLinkClicked(size_t n, const wxHtmlLinkInfo& link);
e0c6027b 117
5ecdc7ab
VZ
118 // event handlers
119 void OnSize(wxSizeEvent& event);
bc55e31b
VS
120 void OnMouseMove(wxMouseEvent& event);
121 void OnLeftDown(wxMouseEvent& event);
5ecdc7ab
VZ
122
123
e0c6027b
VZ
124 // common part of all ctors
125 void Init();
126
127 // ensure that the given item is cached
128 void CacheItem(size_t n) const;
129
bc55e31b
VS
130private:
131 // wxHtmlWindowInterface methods:
132 virtual void SetHTMLWindowTitle(const wxString& title);
133 virtual void OnHTMLLinkClicked(const wxHtmlLinkInfo& link);
134 virtual wxHtmlOpeningStatus OnHTMLOpeningURL(wxHtmlURLType type,
135 const wxString& url,
136 wxString *redirect) const;
137 virtual wxPoint HTMLCoordsToWindow(wxHtmlCell *cell,
138 const wxPoint& pos) const;
139 virtual wxWindow* GetHTMLWindow();
140 virtual wxColour GetHTMLBackgroundColour() const;
141 virtual void SetHTMLBackgroundColour(const wxColour& clr);
142 virtual void SetHTMLBackgroundImage(const wxBitmap& bmpBg);
143 virtual void SetHTMLStatusText(const wxString& text);
88a1b648 144 virtual wxCursor GetHTMLCursor(HTMLCursor type) const;
bc55e31b
VS
145
146 // returns index of item that contains given HTML cell
147 size_t GetItemForCell(const wxHtmlCell *cell) const;
148
149 // return physical coordinates of root wxHtmlCell of n-th item
150 wxPoint GetRootCellCoords(size_t n) const;
151
152 // Converts physical coordinates stored in @a pos into coordinates
153 // relative to the root cell of the item under mouse cursor, if any. If no
154 // cell is found under the cursor, returns false. Otherwise stores the new
155 // coordinates back into @a pos and pointer to the cell under cursor into
156 // @a cell and returns true.
157 bool PhysicalCoordsToCell(wxPoint& pos, wxHtmlCell*& cell) const;
158
159 // The opposite of PhysicalCoordsToCell: converts coordinates relative to
160 // given cell to physical coordinates in the window
161 wxPoint CellCoordsToPhysical(const wxPoint& pos, wxHtmlCell *cell) const;
162
e0c6027b 163private:
9a9b4940 164 // this class caches the pre-parsed HTML to speed up display
e0c6027b
VZ
165 wxHtmlListBoxCache *m_cache;
166
167 // HTML parser we use
168 wxHtmlWinParser *m_htmlParser;
5ecdc7ab 169
2d814c19
VZ
170#if wxUSE_FILESYSTEM
171 // file system used by m_htmlParser
172 wxFileSystem m_filesystem;
173#endif // wxUSE_FILESYSTEM
174
9a9b4940
VZ
175 // rendering style for the parser which allows us to customize our colours
176 wxHtmlListBoxStyle *m_htmlRendStyle;
177
178
179 // it calls our GetSelectedTextColour() and GetSelectedTextBgColour()
180 friend class wxHtmlListBoxStyle;
bc55e31b 181 friend class wxHtmlListBoxWinInterface;
9a9b4940 182
5ecdc7ab
VZ
183
184 DECLARE_EVENT_TABLE()
27d0dcd0 185 DECLARE_NO_COPY_CLASS(wxHtmlListBox)
e0c6027b
VZ
186};
187
9ebb7cad
VZ
188
189// ----------------------------------------------------------------------------
190// wxSimpleHtmlListBox
191// ----------------------------------------------------------------------------
192
193#define wxHLB_DEFAULT_STYLE wxBORDER_SUNKEN
194#define wxHLB_MULTIPLE wxLB_MULTIPLE
195
196class WXDLLIMPEXP_HTML wxSimpleHtmlListBox : public wxHtmlListBox,
197 public wxItemContainer
198{
199public:
200 // wxListbox-compatible constructors
201 // ---------------------------------
202
203 wxSimpleHtmlListBox() { }
204
205 wxSimpleHtmlListBox(wxWindow *parent,
206 wxWindowID id,
207 const wxPoint& pos = wxDefaultPosition,
208 const wxSize& size = wxDefaultSize,
209 int n = 0, const wxString choices[] = NULL,
210 long style = wxHLB_DEFAULT_STYLE,
211 const wxValidator& validator = wxDefaultValidator,
212 const wxString& name = wxSimpleHtmlListBoxNameStr)
213 {
214 Create(parent, id, pos, size, n, choices, style, validator, name);
215 }
216
217 wxSimpleHtmlListBox(wxWindow *parent,
218 wxWindowID id,
219 const wxPoint& pos,
220 const wxSize& size,
221 const wxArrayString& choices,
222 long style = wxHLB_DEFAULT_STYLE,
223 const wxValidator& validator = wxDefaultValidator,
224 const wxString& name = wxSimpleHtmlListBoxNameStr)
225 {
226 Create(parent, id, pos, size, choices, style, validator, name);
227 }
228
229 bool Create(wxWindow *parent, wxWindowID id,
230 const wxPoint& pos = wxDefaultPosition,
231 const wxSize& size = wxDefaultSize,
232 int n = 0, const wxString choices[] = NULL,
233 long style = wxHLB_DEFAULT_STYLE,
234 const wxValidator& validator = wxDefaultValidator,
235 const wxString& name = wxSimpleHtmlListBoxNameStr);
236 bool Create(wxWindow *parent, wxWindowID id,
237 const wxPoint& pos,
238 const wxSize& size,
239 const wxArrayString& choices,
240 long style = wxHLB_DEFAULT_STYLE,
241 const wxValidator& validator = wxDefaultValidator,
242 const wxString& name = wxSimpleHtmlListBoxNameStr);
d54b227f 243
9ebb7cad
VZ
244 virtual ~wxSimpleHtmlListBox();
245
246 // these must be overloaded otherwise the compiler will complain
247 // about wxItemContainerImmutable::[G|S]etSelection being pure virtuals...
248 void SetSelection(int n)
d54b227f 249 { wxVListBox::SetSelection(n); }
9ebb7cad
VZ
250 int GetSelection() const
251 { return wxVListBox::GetSelection(); }
252
253 // see ctrlsub.h for more info about this:
254 wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
255
256
257 // accessing strings
258 // -----------------
259
260 virtual unsigned int GetCount() const
261 { return m_items.GetCount(); }
262
263 virtual wxString GetString(unsigned int n) const;
264
265 // override default unoptimized wxItemContainer::GetStrings() function
266 wxArrayString GetStrings() const
267 { return m_items; }
268
269 virtual void SetString(unsigned int n, const wxString& s);
270
271 virtual void Clear();
272 virtual void Delete(unsigned int n);
273
274 // override default unoptimized wxItemContainer::Append() function
275 void Append(const wxArrayString& strings);
276
277 // since we override one Append() overload, we need to overload all others too
278 int Append(const wxString& item)
279 { return wxItemContainer::Append(item); }
280 int Append(const wxString& item, void *clientData)
281 { return wxItemContainer::Append(item, clientData); }
282 int Append(const wxString& item, wxClientData *clientData)
283 { return wxItemContainer::Append(item, clientData); }
284
285
286protected:
287
288 virtual int DoAppend(const wxString& item);
289 virtual int DoInsert(const wxString& item, unsigned int pos);
290
291 virtual void DoSetItemClientData(unsigned int n, void *clientData)
9d8f8138 292 { m_HTMLclientData[n] = clientData; }
9ebb7cad
VZ
293
294 virtual void *DoGetItemClientData(unsigned int n) const
9d8f8138 295 { return m_HTMLclientData[n]; }
9ebb7cad 296 virtual void DoSetItemClientObject(unsigned int n, wxClientData *clientData)
9d8f8138 297 { m_HTMLclientData[n] = (void *)clientData; }
9ebb7cad 298 virtual wxClientData *DoGetItemClientObject(unsigned int n) const
9d8f8138 299 { return (wxClientData *)m_HTMLclientData[n]; }
9ebb7cad
VZ
300
301 // calls wxHtmlListBox::SetItemCount() and RefreshAll()
302 void UpdateCount();
303
304 // overload these functions just to change their visibility: users of
305 // wxSimpleHtmlListBox shouldn't be allowed to call them directly!
306 virtual void SetItemCount(size_t count)
d54b227f 307 { wxHtmlListBox::SetItemCount(count); }
f18eaf26
VZ
308 virtual void SetRowCount(size_t count)
309 { wxHtmlListBox::SetRowCount(count); }
9ebb7cad
VZ
310
311 virtual wxString OnGetItem(size_t n) const
312 { return m_items[n]; }
313
67339f7d
JS
314 wxArrayString m_items;
315 wxArrayPtrVoid m_HTMLclientData;
316
9d8f8138
SN
317 // Note: For the benefit of old compilers (like gcc-2.8) this should
318 // not be named m_clientdata as that clashes with the name of an
319 // anonymous struct member in wxEvtHandler, which we derive from.
9ebb7cad
VZ
320
321 DECLARE_NO_COPY_CLASS(wxSimpleHtmlListBox)
322};
323
e0c6027b
VZ
324#endif // _WX_HTMLLBOX_H_
325