]>
Commit | Line | Data |
---|---|---|
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$ | |
8 | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org> | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_HTMLLBOX_H_ | |
13 | #define _WX_HTMLLBOX_H_ | |
14 | ||
15 | #include "wx/vlbox.h" // base class | |
16 | #include "wx/html/htmlwin.h" | |
17 | ||
18 | #if wxUSE_FILESYSTEM | |
19 | #include "wx/filesys.h" | |
20 | #endif // wxUSE_FILESYSTEM | |
21 | ||
22 | class WXDLLIMPEXP_HTML wxHtmlCell; | |
23 | class WXDLLIMPEXP_HTML wxHtmlWinParser; | |
24 | class WXDLLIMPEXP_HTML wxHtmlListBoxCache; | |
25 | class WXDLLIMPEXP_HTML wxHtmlListBoxStyle; | |
26 | ||
27 | // ---------------------------------------------------------------------------- | |
28 | // wxHtmlListBox | |
29 | // ---------------------------------------------------------------------------- | |
30 | ||
31 | class WXDLLIMPEXP_HTML wxHtmlListBox : public wxVListBox, | |
32 | public wxHtmlWindowInterface, | |
33 | private wxHtmlWindowMouseHelper | |
34 | { | |
35 | DECLARE_ABSTRACT_CLASS(wxHtmlListBox) | |
36 | public: | |
37 | // constructors and such | |
38 | // --------------------- | |
39 | ||
40 | // default constructor, you must call Create() later | |
41 | wxHtmlListBox(); | |
42 | ||
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, | |
48 | long style = 0, | |
49 | const wxString& name = wxVListBoxNameStr); | |
50 | ||
51 | // really creates the control and sets the initial number of items in it | |
52 | // (which may be changed later with SetItemCount()) | |
53 | // | |
54 | // the only special style which may be specified here is wxLB_MULTIPLE | |
55 | // | |
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, | |
61 | long style = 0, | |
62 | const wxString& name = wxVListBoxNameStr); | |
63 | ||
64 | // destructor cleans up whatever resources we use | |
65 | virtual ~wxHtmlListBox(); | |
66 | ||
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); | |
72 | ||
73 | ||
74 | #if wxUSE_FILESYSTEM | |
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 | |
80 | ||
81 | virtual void OnInternalIdle(); | |
82 | ||
83 | protected: | |
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; | |
87 | ||
88 | // this function may be overridden to decorate HTML returned by OnGetItem() | |
89 | virtual wxString OnGetItemMarkup(size_t n) const; | |
90 | ||
91 | ||
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 | |
95 | // | |
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; | |
99 | ||
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; | |
104 | ||
105 | ||
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; | |
110 | ||
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)) {} | |
115 | ||
116 | // event handlers | |
117 | void OnSize(wxSizeEvent& event); | |
118 | void OnMouseMove(wxMouseEvent& event); | |
119 | void OnLeftDown(wxMouseEvent& event); | |
120 | ||
121 | ||
122 | // common part of all ctors | |
123 | void Init(); | |
124 | ||
125 | // ensure that the given item is cached | |
126 | void CacheItem(size_t n) const; | |
127 | ||
128 | private: | |
129 | // wxHtmlWindowInterface methods: | |
130 | virtual void SetHTMLWindowTitle(const wxString& title); | |
131 | virtual void OnHTMLLinkClicked(const wxHtmlLinkInfo& link); | |
132 | virtual wxHtmlOpeningStatus OnHTMLOpeningURL(wxHtmlURLType type, | |
133 | const wxString& url, | |
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 | ||
143 | // returns index of item that contains given HTML cell | |
144 | size_t GetItemForCell(const wxHtmlCell *cell) const; | |
145 | ||
146 | // return physical coordinates of root wxHtmlCell of n-th item | |
147 | wxPoint GetRootCellCoords(size_t n) const; | |
148 | ||
149 | // Converts physical coordinates stored in @a pos into coordinates | |
150 | // relative to the root cell of the item under mouse cursor, if any. If no | |
151 | // cell is found under the cursor, returns false. Otherwise stores the new | |
152 | // coordinates back into @a pos and pointer to the cell under cursor into | |
153 | // @a cell and returns true. | |
154 | bool PhysicalCoordsToCell(wxPoint& pos, wxHtmlCell*& cell) const; | |
155 | ||
156 | // The opposite of PhysicalCoordsToCell: converts coordinates relative to | |
157 | // given cell to physical coordinates in the window | |
158 | wxPoint CellCoordsToPhysical(const wxPoint& pos, wxHtmlCell *cell) const; | |
159 | ||
160 | private: | |
161 | // this class caches the pre-parsed HTML to speed up display | |
162 | wxHtmlListBoxCache *m_cache; | |
163 | ||
164 | // HTML parser we use | |
165 | wxHtmlWinParser *m_htmlParser; | |
166 | ||
167 | #if wxUSE_FILESYSTEM | |
168 | // file system used by m_htmlParser | |
169 | wxFileSystem m_filesystem; | |
170 | #endif // wxUSE_FILESYSTEM | |
171 | ||
172 | // rendering style for the parser which allows us to customize our colours | |
173 | wxHtmlListBoxStyle *m_htmlRendStyle; | |
174 | ||
175 | ||
176 | // it calls our GetSelectedTextColour() and GetSelectedTextBgColour() | |
177 | friend class wxHtmlListBoxStyle; | |
178 | friend class wxHtmlListBoxWinInterface; | |
179 | ||
180 | ||
181 | DECLARE_EVENT_TABLE() | |
182 | DECLARE_NO_COPY_CLASS(wxHtmlListBox) | |
183 | }; | |
184 | ||
185 | #endif // _WX_HTMLLBOX_H_ | |
186 |