1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlListBox is a listbox whose items are wxHtmlCells
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_HTMLLBOX_H_
13 #define _WX_HTMLLBOX_H_
15 #include "wx/vlbox.h" // base class
16 #include "wx/html/htmlwin.h"
17 #include "wx/ctrlsub.h"
20 #include "wx/filesys.h"
21 #endif // wxUSE_FILESYSTEM
23 class WXDLLIMPEXP_HTML wxHtmlCell
;
24 class WXDLLIMPEXP_HTML wxHtmlWinParser
;
25 class WXDLLIMPEXP_HTML wxHtmlListBoxCache
;
26 class WXDLLIMPEXP_HTML wxHtmlListBoxStyle
;
28 extern WXDLLIMPEXP_DATA_HTML(const wxChar
) wxHtmlListBoxNameStr
[];
29 extern WXDLLIMPEXP_DATA_HTML(const wxChar
) wxSimpleHtmlListBoxNameStr
[];
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 class WXDLLIMPEXP_HTML wxHtmlListBox
: public wxVListBox
,
36 public wxHtmlWindowInterface
,
37 public wxHtmlWindowMouseHelper
39 DECLARE_ABSTRACT_CLASS(wxHtmlListBox
)
41 // constructors and such
42 // ---------------------
44 // default constructor, you must call Create() later
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
,
53 const wxString
& name
= wxHtmlListBoxNameStr
);
55 // really creates the control and sets the initial number of items in it
56 // (which may be changed later with SetItemCount())
58 // the only special style which may be specified here is wxLB_MULTIPLE
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
,
66 const wxString
& name
= wxHtmlListBoxNameStr
);
68 // destructor cleans up whatever resources we use
69 virtual ~wxHtmlListBox();
71 // override some base class virtuals
72 virtual void RefreshLine(size_t line
);
73 virtual void RefreshLines(size_t from
, size_t to
);
74 virtual void RefreshAll();
75 virtual void SetItemCount(size_t count
);
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
85 virtual void OnInternalIdle();
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;
92 // this function may be overridden to decorate HTML returned by OnGetItem()
93 virtual wxString
OnGetItemMarkup(size_t n
) const;
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
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;
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;
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;
115 // This method may be overriden to handle clicking on a link in
116 // the listbox. By default, clicking links is ignored.
117 virtual void OnLinkClicked(size_t WXUNUSED(n
),
118 const wxHtmlLinkInfo
& WXUNUSED(link
)) { }
121 void OnSize(wxSizeEvent
& event
);
122 void OnMouseMove(wxMouseEvent
& event
);
123 void OnLeftDown(wxMouseEvent
& event
);
126 // common part of all ctors
129 // ensure that the given item is cached
130 void CacheItem(size_t n
) const;
133 // wxHtmlWindowInterface methods:
134 virtual void SetHTMLWindowTitle(const wxString
& title
);
135 virtual void OnHTMLLinkClicked(const wxHtmlLinkInfo
& link
);
136 virtual wxHtmlOpeningStatus
OnHTMLOpeningURL(wxHtmlURLType type
,
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
);
146 virtual wxCursor
GetHTMLCursor(HTMLCursor type
) const;
148 // returns index of item that contains given HTML cell
149 size_t GetItemForCell(const wxHtmlCell
*cell
) const;
151 // return physical coordinates of root wxHtmlCell of n-th item
152 wxPoint
GetRootCellCoords(size_t n
) const;
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;
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;
166 // this class caches the pre-parsed HTML to speed up display
167 wxHtmlListBoxCache
*m_cache
;
169 // HTML parser we use
170 wxHtmlWinParser
*m_htmlParser
;
173 // file system used by m_htmlParser
174 wxFileSystem m_filesystem
;
175 #endif // wxUSE_FILESYSTEM
177 // rendering style for the parser which allows us to customize our colours
178 wxHtmlListBoxStyle
*m_htmlRendStyle
;
181 // it calls our GetSelectedTextColour() and GetSelectedTextBgColour()
182 friend class wxHtmlListBoxStyle
;
183 friend class wxHtmlListBoxWinInterface
;
186 DECLARE_EVENT_TABLE()
187 DECLARE_NO_COPY_CLASS(wxHtmlListBox
)
191 // ----------------------------------------------------------------------------
192 // wxSimpleHtmlListBox
193 // ----------------------------------------------------------------------------
195 #define wxHLB_DEFAULT_STYLE wxBORDER_SUNKEN
196 #define wxHLB_MULTIPLE wxLB_MULTIPLE
198 class WXDLLIMPEXP_HTML wxSimpleHtmlListBox
: public wxHtmlListBox
,
199 public wxItemContainer
202 // wxListbox-compatible constructors
203 // ---------------------------------
205 wxSimpleHtmlListBox() { }
207 wxSimpleHtmlListBox(wxWindow
*parent
,
209 const wxPoint
& pos
= wxDefaultPosition
,
210 const wxSize
& size
= wxDefaultSize
,
211 int n
= 0, const wxString choices
[] = NULL
,
212 long style
= wxHLB_DEFAULT_STYLE
,
213 const wxValidator
& validator
= wxDefaultValidator
,
214 const wxString
& name
= wxSimpleHtmlListBoxNameStr
)
216 Create(parent
, id
, pos
, size
, n
, choices
, style
, validator
, name
);
219 wxSimpleHtmlListBox(wxWindow
*parent
,
223 const wxArrayString
& choices
,
224 long style
= wxHLB_DEFAULT_STYLE
,
225 const wxValidator
& validator
= wxDefaultValidator
,
226 const wxString
& name
= wxSimpleHtmlListBoxNameStr
)
228 Create(parent
, id
, pos
, size
, choices
, style
, validator
, name
);
231 bool Create(wxWindow
*parent
, wxWindowID id
,
232 const wxPoint
& pos
= wxDefaultPosition
,
233 const wxSize
& size
= wxDefaultSize
,
234 int n
= 0, const wxString choices
[] = NULL
,
235 long style
= wxHLB_DEFAULT_STYLE
,
236 const wxValidator
& validator
= wxDefaultValidator
,
237 const wxString
& name
= wxSimpleHtmlListBoxNameStr
);
238 bool Create(wxWindow
*parent
, wxWindowID id
,
241 const wxArrayString
& choices
,
242 long style
= wxHLB_DEFAULT_STYLE
,
243 const wxValidator
& validator
= wxDefaultValidator
,
244 const wxString
& name
= wxSimpleHtmlListBoxNameStr
);
246 virtual ~wxSimpleHtmlListBox();
248 // these must be overloaded otherwise the compiler will complain
249 // about wxItemContainerImmutable::[G|S]etSelection being pure virtuals...
250 void SetSelection(int n
)
251 { wxVListBox::SetSelection(n
); }
252 int GetSelection() const
253 { return wxVListBox::GetSelection(); }
255 // see ctrlsub.h for more info about this:
256 wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
262 virtual unsigned int GetCount() const
263 { return m_items
.GetCount(); }
265 virtual wxString
GetString(unsigned int n
) const;
267 // override default unoptimized wxItemContainer::GetStrings() function
268 wxArrayString
GetStrings() const
271 virtual void SetString(unsigned int n
, const wxString
& s
);
273 virtual void Clear();
274 virtual void Delete(unsigned int n
);
276 // override default unoptimized wxItemContainer::Append() function
277 void Append(const wxArrayString
& strings
);
279 // since we override one Append() overload, we need to overload all others too
280 int Append(const wxString
& item
)
281 { return wxItemContainer::Append(item
); }
282 int Append(const wxString
& item
, void *clientData
)
283 { return wxItemContainer::Append(item
, clientData
); }
284 int Append(const wxString
& item
, wxClientData
*clientData
)
285 { return wxItemContainer::Append(item
, clientData
); }
290 virtual int DoAppend(const wxString
& item
);
291 virtual int DoInsert(const wxString
& item
, unsigned int pos
);
293 virtual void DoSetItemClientData(unsigned int n
, void *clientData
)
294 { m_clientData
[n
] = clientData
; }
296 virtual void *DoGetItemClientData(unsigned int n
) const
297 { return m_clientData
[n
]; }
298 virtual void DoSetItemClientObject(unsigned int n
, wxClientData
*clientData
)
299 { m_clientData
[n
] = (void *)clientData
; }
300 virtual wxClientData
*DoGetItemClientObject(unsigned int n
) const
301 { return (wxClientData
*)m_clientData
[n
]; }
303 // calls wxHtmlListBox::SetItemCount() and RefreshAll()
306 // overload these functions just to change their visibility: users of
307 // wxSimpleHtmlListBox shouldn't be allowed to call them directly!
308 virtual void SetItemCount(size_t count
)
309 { wxHtmlListBox::SetItemCount(count
); }
310 virtual void SetLineCount(size_t count
)
311 { wxHtmlListBox::SetLineCount(count
); }
313 virtual wxString
OnGetItem(size_t n
) const
314 { return m_items
[n
]; }
316 wxArrayString m_items
;
317 wxArrayPtrVoid m_clientData
;
319 DECLARE_NO_COPY_CLASS(wxSimpleHtmlListBox
)
322 #endif // _WX_HTMLLBOX_H_