]> git.saurik.com Git - wxWidgets.git/blame - include/wx/htmllbox.h
floating pane size now restores after perspective restore
[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
78#if wxUSE_FILESYSTEM
79 // retrieve the file system used by the wxHtmlWinParser: if you use
80 // relative paths in your HTML, you should use its ChangePathTo() method
81 wxFileSystem& GetFileSystem() { return m_filesystem; }
82 const wxFileSystem& GetFileSystem() const { return m_filesystem; }
83#endif // wxUSE_FILESYSTEM
84
bc55e31b
VS
85 virtual void OnInternalIdle();
86
e0c6027b
VZ
87protected:
88 // this method must be implemented in the derived class and should return
89 // the body (i.e. without <html>) of the HTML for the given item
90 virtual wxString OnGetItem(size_t n) const = 0;
91
92 // this function may be overridden to decorate HTML returned by OnGetItem()
93 virtual wxString OnGetItemMarkup(size_t n) const;
94
95
9a9b4940
VZ
96 // this method allows to customize the selection appearance: it may be used
97 // to specify the colour of the text which normally has the given colour
98 // colFg when it is inside the selection
99 //
100 // by default, the original colour is not used at all and all text has the
101 // same (default for this system) colour inside selection
102 virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
103
104 // this is the same as GetSelectedTextColour() but allows to customize the
105 // background colour -- this is even more rarely used as you can change it
106 // globally using SetSelectionBackground()
107 virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
108
109
e0c6027b
VZ
110 // we implement both of these functions in terms of OnGetItem(), they are
111 // not supposed to be overridden by our descendants
112 virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const;
113 virtual wxCoord OnMeasureItem(size_t n) const;
114
bc55e31b
VS
115 // This method may be overriden to handle clicking on a link in
116 // the listbox. By default, clicking links is ignored.
a1c3cdc4 117 virtual void OnLinkClicked(size_t n, const wxHtmlLinkInfo& link);
e0c6027b 118
5ecdc7ab
VZ
119 // event handlers
120 void OnSize(wxSizeEvent& event);
bc55e31b
VS
121 void OnMouseMove(wxMouseEvent& event);
122 void OnLeftDown(wxMouseEvent& event);
5ecdc7ab
VZ
123
124
e0c6027b
VZ
125 // common part of all ctors
126 void Init();
127
128 // ensure that the given item is cached
129 void CacheItem(size_t n) const;
130
bc55e31b
VS
131private:
132 // wxHtmlWindowInterface methods:
133 virtual void SetHTMLWindowTitle(const wxString& title);
134 virtual void OnHTMLLinkClicked(const wxHtmlLinkInfo& link);
135 virtual wxHtmlOpeningStatus OnHTMLOpeningURL(wxHtmlURLType type,
136 const wxString& url,
137 wxString *redirect) const;
138 virtual wxPoint HTMLCoordsToWindow(wxHtmlCell *cell,
139 const wxPoint& pos) const;
140 virtual wxWindow* GetHTMLWindow();
141 virtual wxColour GetHTMLBackgroundColour() const;
142 virtual void SetHTMLBackgroundColour(const wxColour& clr);
143 virtual void SetHTMLBackgroundImage(const wxBitmap& bmpBg);
144 virtual void SetHTMLStatusText(const wxString& text);
88a1b648 145 virtual wxCursor GetHTMLCursor(HTMLCursor type) const;
bc55e31b
VS
146
147 // returns index of item that contains given HTML cell
148 size_t GetItemForCell(const wxHtmlCell *cell) const;
149
150 // return physical coordinates of root wxHtmlCell of n-th item
151 wxPoint GetRootCellCoords(size_t n) const;
152
153 // Converts physical coordinates stored in @a pos into coordinates
154 // relative to the root cell of the item under mouse cursor, if any. If no
155 // cell is found under the cursor, returns false. Otherwise stores the new
156 // coordinates back into @a pos and pointer to the cell under cursor into
157 // @a cell and returns true.
158 bool PhysicalCoordsToCell(wxPoint& pos, wxHtmlCell*& cell) const;
159
160 // The opposite of PhysicalCoordsToCell: converts coordinates relative to
161 // given cell to physical coordinates in the window
162 wxPoint CellCoordsToPhysical(const wxPoint& pos, wxHtmlCell *cell) const;
163
e0c6027b 164private:
9a9b4940 165 // this class caches the pre-parsed HTML to speed up display
e0c6027b
VZ
166 wxHtmlListBoxCache *m_cache;
167
168 // HTML parser we use
169 wxHtmlWinParser *m_htmlParser;
5ecdc7ab 170
2d814c19
VZ
171#if wxUSE_FILESYSTEM
172 // file system used by m_htmlParser
173 wxFileSystem m_filesystem;
174#endif // wxUSE_FILESYSTEM
175
9a9b4940
VZ
176 // rendering style for the parser which allows us to customize our colours
177 wxHtmlListBoxStyle *m_htmlRendStyle;
178
179
180 // it calls our GetSelectedTextColour() and GetSelectedTextBgColour()
181 friend class wxHtmlListBoxStyle;
bc55e31b 182 friend class wxHtmlListBoxWinInterface;
9a9b4940 183
5ecdc7ab
VZ
184
185 DECLARE_EVENT_TABLE()
27d0dcd0 186 DECLARE_NO_COPY_CLASS(wxHtmlListBox)
e0c6027b
VZ
187};
188
9ebb7cad
VZ
189
190// ----------------------------------------------------------------------------
191// wxSimpleHtmlListBox
192// ----------------------------------------------------------------------------
193
194#define wxHLB_DEFAULT_STYLE wxBORDER_SUNKEN
195#define wxHLB_MULTIPLE wxLB_MULTIPLE
196
197class WXDLLIMPEXP_HTML wxSimpleHtmlListBox : public wxHtmlListBox,
198 public wxItemContainer
199{
200public:
201 // wxListbox-compatible constructors
202 // ---------------------------------
203
204 wxSimpleHtmlListBox() { }
205
206 wxSimpleHtmlListBox(wxWindow *parent,
207 wxWindowID id,
208 const wxPoint& pos = wxDefaultPosition,
209 const wxSize& size = wxDefaultSize,
210 int n = 0, const wxString choices[] = NULL,
211 long style = wxHLB_DEFAULT_STYLE,
212 const wxValidator& validator = wxDefaultValidator,
213 const wxString& name = wxSimpleHtmlListBoxNameStr)
214 {
215 Create(parent, id, pos, size, n, choices, style, validator, name);
216 }
217
218 wxSimpleHtmlListBox(wxWindow *parent,
219 wxWindowID id,
220 const wxPoint& pos,
221 const wxSize& size,
222 const wxArrayString& choices,
223 long style = wxHLB_DEFAULT_STYLE,
224 const wxValidator& validator = wxDefaultValidator,
225 const wxString& name = wxSimpleHtmlListBoxNameStr)
226 {
227 Create(parent, id, pos, size, choices, style, validator, name);
228 }
229
230 bool Create(wxWindow *parent, wxWindowID id,
231 const wxPoint& pos = wxDefaultPosition,
232 const wxSize& size = wxDefaultSize,
233 int n = 0, const wxString choices[] = NULL,
234 long style = wxHLB_DEFAULT_STYLE,
235 const wxValidator& validator = wxDefaultValidator,
236 const wxString& name = wxSimpleHtmlListBoxNameStr);
237 bool Create(wxWindow *parent, wxWindowID id,
238 const wxPoint& pos,
239 const wxSize& size,
240 const wxArrayString& choices,
241 long style = wxHLB_DEFAULT_STYLE,
242 const wxValidator& validator = wxDefaultValidator,
243 const wxString& name = wxSimpleHtmlListBoxNameStr);
d54b227f 244
9ebb7cad
VZ
245 virtual ~wxSimpleHtmlListBox();
246
247 // these must be overloaded otherwise the compiler will complain
248 // about wxItemContainerImmutable::[G|S]etSelection being pure virtuals...
249 void SetSelection(int n)
d54b227f 250 { wxVListBox::SetSelection(n); }
9ebb7cad
VZ
251 int GetSelection() const
252 { return wxVListBox::GetSelection(); }
253
254 // see ctrlsub.h for more info about this:
255 wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
256
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
272 virtual void Clear();
273 virtual void Delete(unsigned int n);
274
275 // override default unoptimized wxItemContainer::Append() function
276 void Append(const wxArrayString& strings);
277
278 // since we override one Append() overload, we need to overload all others too
279 int Append(const wxString& item)
280 { return wxItemContainer::Append(item); }
281 int Append(const wxString& item, void *clientData)
282 { return wxItemContainer::Append(item, clientData); }
283 int Append(const wxString& item, wxClientData *clientData)
284 { return wxItemContainer::Append(item, clientData); }
285
286
287protected:
288
289 virtual int DoAppend(const wxString& item);
290 virtual int DoInsert(const wxString& item, unsigned int pos);
291
292 virtual void DoSetItemClientData(unsigned int n, void *clientData)
9d8f8138 293 { m_HTMLclientData[n] = clientData; }
9ebb7cad
VZ
294
295 virtual void *DoGetItemClientData(unsigned int n) const
9d8f8138 296 { return m_HTMLclientData[n]; }
9ebb7cad 297 virtual void DoSetItemClientObject(unsigned int n, wxClientData *clientData)
9d8f8138 298 { m_HTMLclientData[n] = (void *)clientData; }
9ebb7cad 299 virtual wxClientData *DoGetItemClientObject(unsigned int n) const
9d8f8138 300 { return (wxClientData *)m_HTMLclientData[n]; }
9ebb7cad
VZ
301
302 // calls wxHtmlListBox::SetItemCount() and RefreshAll()
303 void UpdateCount();
304
305 // overload these functions just to change their visibility: users of
306 // wxSimpleHtmlListBox shouldn't be allowed to call them directly!
307 virtual void SetItemCount(size_t count)
d54b227f 308 { wxHtmlListBox::SetItemCount(count); }
9ebb7cad 309 virtual void SetLineCount(size_t count)
d54b227f 310 { wxHtmlListBox::SetLineCount(count); }
9ebb7cad
VZ
311
312 virtual wxString OnGetItem(size_t n) const
313 { return m_items[n]; }
314
315 wxArrayString m_items;
9d8f8138
SN
316 wxArrayPtrVoid m_HTMLclientData;
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