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