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"
19 #include "wx/filesys.h"
20 #endif // wxUSE_FILESYSTEM
22 class WXDLLIMPEXP_HTML wxHtmlCell
;
23 class WXDLLIMPEXP_HTML wxHtmlWinParser
;
24 class WXDLLIMPEXP_HTML wxHtmlListBoxCache
;
25 class WXDLLIMPEXP_HTML wxHtmlListBoxStyle
;
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 class WXDLLIMPEXP_HTML wxHtmlListBox
: public wxVListBox
,
32 public wxHtmlWindowInterface
,
33 private wxHtmlWindowMouseHelper
35 DECLARE_ABSTRACT_CLASS(wxHtmlListBox
)
37 // constructors and such
38 // ---------------------
40 // default constructor, you must call Create() later
43 // normal constructor which calls Create() internally
44 wxHtmlListBox(wxWindow
*parent
,
45 wxWindowID id
= wxID_ANY
,
46 const wxPoint
& pos
= wxDefaultPosition
,
47 const wxSize
& size
= wxDefaultSize
,
49 const wxString
& name
= wxVListBoxNameStr
);
51 // really creates the control and sets the initial number of items in it
52 // (which may be changed later with SetItemCount())
54 // the only special style which may be specified here is wxLB_MULTIPLE
56 // returns true on success or false if the control couldn't be created
57 bool Create(wxWindow
*parent
,
58 wxWindowID id
= wxID_ANY
,
59 const wxPoint
& pos
= wxDefaultPosition
,
60 const wxSize
& size
= wxDefaultSize
,
62 const wxString
& name
= wxVListBoxNameStr
);
64 // destructor cleans up whatever resources we use
65 virtual ~wxHtmlListBox();
67 // override some base class virtuals
68 virtual void RefreshLine(size_t line
);
69 virtual void RefreshLines(size_t from
, size_t to
);
70 virtual void RefreshAll();
71 virtual void SetItemCount(size_t count
);
75 // retrieve the file system used by the wxHtmlWinParser: if you use
76 // relative paths in your HTML, you should use its ChangePathTo() method
77 wxFileSystem
& GetFileSystem() { return m_filesystem
; }
78 const wxFileSystem
& GetFileSystem() const { return m_filesystem
; }
79 #endif // wxUSE_FILESYSTEM
81 virtual void OnInternalIdle();
84 // this method must be implemented in the derived class and should return
85 // the body (i.e. without <html>) of the HTML for the given item
86 virtual wxString
OnGetItem(size_t n
) const = 0;
88 // this function may be overridden to decorate HTML returned by OnGetItem()
89 virtual wxString
OnGetItemMarkup(size_t n
) const;
92 // this method allows to customize the selection appearance: it may be used
93 // to specify the colour of the text which normally has the given colour
94 // colFg when it is inside the selection
96 // by default, the original colour is not used at all and all text has the
97 // same (default for this system) colour inside selection
98 virtual wxColour
GetSelectedTextColour(const wxColour
& colFg
) const;
100 // this is the same as GetSelectedTextColour() but allows to customize the
101 // background colour -- this is even more rarely used as you can change it
102 // globally using SetSelectionBackground()
103 virtual wxColour
GetSelectedTextBgColour(const wxColour
& colBg
) const;
106 // we implement both of these functions in terms of OnGetItem(), they are
107 // not supposed to be overridden by our descendants
108 virtual void OnDrawItem(wxDC
& dc
, const wxRect
& rect
, size_t n
) const;
109 virtual wxCoord
OnMeasureItem(size_t n
) const;
111 // This method may be overriden to handle clicking on a link in
112 // the listbox. By default, clicking links is ignored.
113 virtual void OnLinkClicked(size_t WXUNUSED(n
),
114 const wxHtmlLinkInfo
& WXUNUSED(link
)) {}
117 void OnSize(wxSizeEvent
& event
);
118 void OnMouseMove(wxMouseEvent
& event
);
119 void OnLeftDown(wxMouseEvent
& event
);
122 // common part of all ctors
125 // ensure that the given item is cached
126 void CacheItem(size_t n
) const;
129 // wxHtmlWindowInterface methods:
130 virtual void SetHTMLWindowTitle(const wxString
& title
);
131 virtual void OnHTMLLinkClicked(const wxHtmlLinkInfo
& link
);
132 virtual wxHtmlOpeningStatus
OnHTMLOpeningURL(wxHtmlURLType type
,
134 wxString
*redirect
) const;
135 virtual wxPoint
HTMLCoordsToWindow(wxHtmlCell
*cell
,
136 const wxPoint
& pos
) const;
137 virtual wxWindow
* GetHTMLWindow();
138 virtual wxColour
GetHTMLBackgroundColour() const;
139 virtual void SetHTMLBackgroundColour(const wxColour
& clr
);
140 virtual void SetHTMLBackgroundImage(const wxBitmap
& bmpBg
);
141 virtual void SetHTMLStatusText(const wxString
& text
);
142 virtual wxCursor
GetHTMLCursor(HTMLCursor type
) const;
144 // returns index of item that contains given HTML cell
145 size_t GetItemForCell(const wxHtmlCell
*cell
) const;
147 // return physical coordinates of root wxHtmlCell of n-th item
148 wxPoint
GetRootCellCoords(size_t n
) const;
150 // Converts physical coordinates stored in @a pos into coordinates
151 // relative to the root cell of the item under mouse cursor, if any. If no
152 // cell is found under the cursor, returns false. Otherwise stores the new
153 // coordinates back into @a pos and pointer to the cell under cursor into
154 // @a cell and returns true.
155 bool PhysicalCoordsToCell(wxPoint
& pos
, wxHtmlCell
*& cell
) const;
157 // The opposite of PhysicalCoordsToCell: converts coordinates relative to
158 // given cell to physical coordinates in the window
159 wxPoint
CellCoordsToPhysical(const wxPoint
& pos
, wxHtmlCell
*cell
) const;
162 // this class caches the pre-parsed HTML to speed up display
163 wxHtmlListBoxCache
*m_cache
;
165 // HTML parser we use
166 wxHtmlWinParser
*m_htmlParser
;
169 // file system used by m_htmlParser
170 wxFileSystem m_filesystem
;
171 #endif // wxUSE_FILESYSTEM
173 // rendering style for the parser which allows us to customize our colours
174 wxHtmlListBoxStyle
*m_htmlRendStyle
;
177 // it calls our GetSelectedTextColour() and GetSelectedTextBgColour()
178 friend class wxHtmlListBoxStyle
;
179 friend class wxHtmlListBoxWinInterface
;
182 DECLARE_EVENT_TABLE()
183 DECLARE_NO_COPY_CLASS(wxHtmlListBox
)
186 #endif // _WX_HTMLLBOX_H_