]>
Commit | Line | Data |
---|---|---|
5526e819 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: htmlcell.h | |
3 | // Purpose: wxHtmlCell class is used by wxHtmlWindow/wxHtmlWinParser | |
4 | // as a basic visual element of HTML page | |
5 | // Author: Vaclav Slavik | |
69941f05 | 6 | // RCS-ID: $Id$ |
5526e819 VS |
7 | // Copyright: (c) 1999 Vaclav Slavik |
8 | // Licence: wxWindows Licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | ||
69941f05 VS |
12 | #ifndef _WX_HTMLCELL_H_ |
13 | #define _WX_HTMLCELL_H_ | |
5526e819 VS |
14 | |
15 | #ifdef __GNUG__ | |
97494971 | 16 | #pragma interface "htmlcell.h" |
5526e819 VS |
17 | #endif |
18 | ||
19 | #include "wx/defs.h" | |
5526e819 | 20 | |
4dcaf11a | 21 | #if wxUSE_HTML |
5526e819 | 22 | |
4dcaf11a RR |
23 | #include "wx/html/htmltag.h" |
24 | #include "wx/html/htmldefs.h" | |
25 | #include "wx/window.h" | |
5526e819 | 26 | |
846914d1 | 27 | |
ffef2bde RD |
28 | class WXDLLEXPORT wxHtmlLinkInfo; |
29 | class WXDLLEXPORT wxHtmlCell; | |
30 | class WXDLLEXPORT wxHtmlContainerCell; | |
5526e819 VS |
31 | |
32 | //-------------------------------------------------------------------------------- | |
33 | // wxHtmlCell | |
34 | // Internal data structure. It represents fragments of parsed HTML | |
35 | // page - a word, picture, table, horizontal line and so on. | |
36 | // It is used by wxHtmlWindow to represent HTML page in memory. | |
37 | //-------------------------------------------------------------------------------- | |
38 | ||
39 | ||
40 | class WXDLLEXPORT wxHtmlCell : public wxObject | |
41 | { | |
97494971 VS |
42 | public: |
43 | wxHtmlCell(); | |
44 | virtual ~wxHtmlCell(); | |
45 | ||
46 | void SetParent(wxHtmlContainerCell *p) {m_Parent = p;} | |
47 | wxHtmlContainerCell *GetParent() const {return m_Parent;} | |
48 | ||
49 | int GetPosX() const {return m_PosX;} | |
50 | int GetPosY() const {return m_PosY;} | |
51 | int GetWidth() const {return m_Width;} | |
52 | int GetHeight() const {return m_Height;} | |
53 | int GetDescent() const {return m_Descent;} | |
54 | ||
55 | // returns the link associated with this cell. The position is position within | |
56 | // the cell so it varies from 0 to m_Width, from 0 to m_Height | |
57 | virtual wxHtmlLinkInfo* GetLink(int WXUNUSED(x) = 0, int WXUNUSED(y) = 0) const | |
58 | { return m_Link; } | |
59 | ||
60 | // members access methods | |
61 | wxHtmlCell *GetNext() const {return m_Next;} | |
62 | ||
f6010d8f | 63 | // members writing methods |
97494971 VS |
64 | virtual void SetPos(int x, int y) {m_PosX = x, m_PosY = y;} |
65 | void SetLink(const wxHtmlLinkInfo& link); | |
66 | void SetNext(wxHtmlCell *cell) {m_Next = cell;} | |
67 | ||
68 | // 1. adjust cell's width according to the fact that maximal possible width is w. | |
69 | // (this has sense when working with horizontal lines, tables etc.) | |
70 | // 2. prepare layout (=fill-in m_PosX, m_PosY (and sometime m_Height) members) | |
71 | // = place items to fit window, according to the width w | |
72 | virtual void Layout(int w); | |
73 | ||
74 | // renders the cell | |
d699f48b | 75 | virtual void Draw(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2)) {} |
97494971 VS |
76 | |
77 | // proceed drawing actions in case the cell is not visible (scrolled out of screen). | |
78 | // This is needed to change fonts, colors and so on | |
d699f48b | 79 | virtual void DrawInvisible(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y)) {} |
97494971 VS |
80 | |
81 | // This method returns pointer to the FIRST cell for that | |
82 | // the condition | |
83 | // is true. It first checks if the condition is true for this | |
84 | // cell and then calls m_Next->Find(). (Note: it checks | |
85 | // all subcells if the cell is container) | |
86 | // Condition is unique condition identifier (see htmldefs.h) | |
87 | // (user-defined condition IDs should start from 10000) | |
88 | // and param is optional parameter | |
89 | // Example : m_Cell->Find(wxHTML_COND_ISANCHOR, "news"); | |
90 | // returns pointer to anchor news | |
91 | virtual const wxHtmlCell* Find(int condition, const void* param) const; | |
92 | ||
93 | // This function is called when mouse button is clicked over the cell. | |
f6010d8f | 94 | // |
97494971 VS |
95 | // Parent is pointer to wxHtmlWindow that generated the event |
96 | // HINT: if this handling is not enough for you you should use | |
97 | // wxHtmlBinderCell | |
98 | virtual void OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event); | |
99 | ||
100 | // This method used to adjust pagebreak position. The parameter is | |
101 | // variable that contains y-coordinate of page break (= horizontal line that | |
102 | // should not be crossed by words, images etc.). If this cell cannot be divided | |
103 | // into two pieces (each one on another page) then it moves the pagebreak | |
104 | // few pixels up. | |
105 | // | |
106 | // Returned value : true if pagebreak was modified, false otherwise | |
107 | // Usage : while (container->AdjustPagebreak(&p)) {} | |
108 | virtual bool AdjustPagebreak(int *pagebreak) const; | |
109 | ||
110 | // Sets cell's behaviour on pagebreaks (see AdjustPagebreak). Default | |
111 | // is true - the cell can be split on two pages | |
79d6c018 | 112 | void SetCanLiveOnPagebreak(bool can) { m_CanLiveOnPagebreak = can; } |
97494971 | 113 | |
79d6c018 VS |
114 | // Returns y-coordinates that contraint the cell, i.e. left is highest |
115 | // and right lowest coordinate such that the cell lays between then. | |
116 | // Note: this method does not return meaningful values if you haven't | |
117 | // called Layout() before! | |
118 | virtual void GetHorizontalConstraints(int *left, int *right) const; | |
97494971 | 119 | |
f6010d8f VZ |
120 | // Returns true for simple == terminal cells, i.e. not composite ones. |
121 | // This if for internal usage only and may disappear in future versions! | |
122 | virtual bool IsTerminalCell() const { return true; } | |
123 | ||
124 | // Find the terminal cell inside this cell at the given position (relative | |
125 | // to this cell) | |
126 | // | |
127 | // Returns NULL if not found | |
128 | virtual wxHtmlCell *FindCellByPos(wxCoord x, wxCoord y) const; | |
129 | ||
97494971 VS |
130 | protected: |
131 | wxHtmlCell *m_Next; | |
132 | // pointer to the next cell | |
133 | wxHtmlContainerCell *m_Parent; | |
f6010d8f | 134 | // pointer to parent cell |
97494971 VS |
135 | long m_Width, m_Height, m_Descent; |
136 | // dimensions of fragment | |
137 | // m_Descent is used to position text&images.. | |
138 | long m_PosX, m_PosY; | |
139 | // position where the fragment is drawn | |
140 | wxHtmlLinkInfo *m_Link; | |
f6010d8f | 141 | // destination address if this fragment is hypertext link, NULL otherwise |
97494971 VS |
142 | bool m_CanLiveOnPagebreak; |
143 | // true if this cell can be placed on pagebreak, false otherwise | |
5526e819 VS |
144 | }; |
145 | ||
146 | ||
147 | ||
148 | ||
149 | //-------------------------------------------------------------------------------- | |
150 | // Inherited cells: | |
151 | //-------------------------------------------------------------------------------- | |
152 | ||
153 | ||
154 | //-------------------------------------------------------------------------------- | |
155 | // wxHtmlWordCell | |
156 | // Single word in input stream. | |
157 | //-------------------------------------------------------------------------------- | |
158 | ||
159 | class WXDLLEXPORT wxHtmlWordCell : public wxHtmlCell | |
160 | { | |
97494971 VS |
161 | public: |
162 | wxHtmlWordCell(const wxString& word, wxDC& dc); | |
163 | void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2); | |
60e87cb1 | 164 | |
97494971 VS |
165 | protected: |
166 | wxString m_Word; | |
5526e819 VS |
167 | }; |
168 | ||
169 | ||
170 | ||
171 | ||
172 | ||
173 | //-------------------------------------------------------------------------------- | |
174 | // wxHtmlContainerCell | |
175 | // Container - it contains other cells. Basic of layout algorithm. | |
176 | //-------------------------------------------------------------------------------- | |
177 | ||
178 | class WXDLLEXPORT wxHtmlContainerCell : public wxHtmlCell | |
179 | { | |
97494971 VS |
180 | public: |
181 | wxHtmlContainerCell(wxHtmlContainerCell *parent); | |
182 | ~wxHtmlContainerCell(); | |
183 | ||
184 | virtual void Layout(int w); | |
185 | virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2); | |
186 | virtual void DrawInvisible(wxDC& dc, int x, int y); | |
187 | virtual bool AdjustPagebreak(int *pagebreak) const; | |
188 | ||
189 | // insert cell at the end of m_Cells list | |
190 | void InsertCell(wxHtmlCell *cell); | |
191 | ||
192 | // sets horizontal/vertical alignment | |
193 | void SetAlignHor(int al) {m_AlignHor = al; m_LastLayout = -1;} | |
194 | int GetAlignHor() const {return m_AlignHor;} | |
195 | void SetAlignVer(int al) {m_AlignVer = al; m_LastLayout = -1;} | |
196 | int GetAlignVer() const {return m_AlignVer;} | |
197 | ||
198 | // sets left-border indentation. units is one of wxHTML_UNITS_* constants | |
199 | // what is combination of wxHTML_INDENT_* | |
200 | void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS); | |
201 | // returns the indentation. ind is one of wxHTML_INDENT_* constants | |
202 | int GetIndent(int ind) const; | |
203 | // returns type of value returned by GetIndent(ind) | |
204 | int GetIndentUnits(int ind) const; | |
205 | ||
206 | // sets alignment info based on given tag's params | |
207 | void SetAlign(const wxHtmlTag& tag); | |
208 | // sets floating width adjustment | |
209 | // (examples : 32 percent of parent container, | |
210 | // -15 pixels percent (this means 100 % - 15 pixels) | |
211 | void SetWidthFloat(int w, int units) {m_WidthFloat = w; m_WidthFloatUnits = units; m_LastLayout = -1;} | |
212 | void SetWidthFloat(const wxHtmlTag& tag, double pixel_scale = 1.0); | |
213 | // sets minimal height of this container. | |
214 | void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP) {m_MinHeight = h; m_MinHeightAlign = align; m_LastLayout = -1;} | |
215 | ||
216 | void SetBackgroundColour(const wxColour& clr) {m_UseBkColour = TRUE; m_BkColour = clr;} | |
217 | void SetBorder(const wxColour& clr1, const wxColour& clr2) {m_UseBorder = TRUE; m_BorderColour1 = clr1, m_BorderColour2 = clr2;} | |
218 | virtual wxHtmlLinkInfo* GetLink(int x = 0, int y = 0) const; | |
219 | virtual const wxHtmlCell* Find(int condition, const void* param) const; | |
220 | virtual void OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event); | |
79d6c018 | 221 | virtual void GetHorizontalConstraints(int *left, int *right) const; |
97494971 VS |
222 | |
223 | // returns pointer to the first cell in container or NULL | |
224 | wxHtmlCell* GetFirstCell() const {return m_Cells;} | |
225 | ||
f6010d8f VZ |
226 | // see comment in wxHtmlCell about this method |
227 | virtual bool IsTerminalCell() const { return false; } | |
228 | ||
229 | virtual wxHtmlCell *FindCellByPos(wxCoord x, wxCoord y) const; | |
230 | ||
97494971 VS |
231 | protected: |
232 | int m_IndentLeft, m_IndentRight, m_IndentTop, m_IndentBottom; | |
233 | // indentation of subcells. There is always m_Indent pixels | |
234 | // big space between given border of the container and the subcells | |
235 | // it m_Indent < 0 it is in PERCENTS, otherwise it is in pixels | |
236 | int m_MinHeight, m_MinHeightAlign; | |
237 | // minimal height. | |
238 | wxHtmlCell *m_Cells, *m_LastCell; | |
239 | // internal cells, m_Cells points to the first of them, m_LastCell to the last one. | |
240 | // (LastCell is needed only to speed-up InsertCell) | |
241 | int m_AlignHor, m_AlignVer; | |
242 | // alignment horizontal and vertical (left, center, right) | |
243 | int m_WidthFloat, m_WidthFloatUnits; | |
244 | // width float is used in adjustWidth | |
245 | bool m_UseBkColour; | |
246 | wxColour m_BkColour; | |
247 | // background color of this container | |
248 | bool m_UseBorder; | |
249 | wxColour m_BorderColour1, m_BorderColour2; | |
250 | // borders color of this container | |
251 | int m_LastLayout; | |
252 | // if != -1 then call to Layout may be no-op | |
253 | // if previous call to Layout has same argument | |
5526e819 VS |
254 | }; |
255 | ||
256 | ||
257 | ||
258 | ||
259 | ||
260 | //-------------------------------------------------------------------------------- | |
261 | // wxHtmlColourCell | |
262 | // Color changer. | |
263 | //-------------------------------------------------------------------------------- | |
264 | ||
265 | class WXDLLEXPORT wxHtmlColourCell : public wxHtmlCell | |
266 | { | |
97494971 VS |
267 | public: |
268 | wxHtmlColourCell(const wxColour& clr, int flags = wxHTML_CLR_FOREGROUND) : wxHtmlCell() {m_Colour = clr; m_Flags = flags;} | |
269 | virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2); | |
270 | virtual void DrawInvisible(wxDC& dc, int x, int y); | |
271 | ||
272 | protected: | |
273 | wxColour m_Colour; | |
274 | unsigned m_Flags; | |
5526e819 VS |
275 | }; |
276 | ||
277 | ||
278 | ||
279 | ||
280 | //-------------------------------------------------------------------------------- | |
281 | // wxHtmlFontCell | |
282 | // Sets actual font used for text rendering | |
283 | //-------------------------------------------------------------------------------- | |
284 | ||
285 | class WXDLLEXPORT wxHtmlFontCell : public wxHtmlCell | |
286 | { | |
97494971 VS |
287 | public: |
288 | wxHtmlFontCell(wxFont *font) : wxHtmlCell() { m_Font = (*font); } | |
289 | virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2); | |
290 | virtual void DrawInvisible(wxDC& dc, int x, int y); | |
60e87cb1 | 291 | |
97494971 VS |
292 | protected: |
293 | wxFont m_Font; | |
5526e819 VS |
294 | }; |
295 | ||
296 | ||
297 | ||
298 | ||
299 | ||
300 | ||
301 | //-------------------------------------------------------------------------------- | |
302 | // wxHtmlwidgetCell | |
303 | // This cell is connected with wxWindow object | |
304 | // You can use it to insert windows into HTML page | |
305 | // (buttons, input boxes etc.) | |
306 | //-------------------------------------------------------------------------------- | |
307 | ||
308 | class WXDLLEXPORT wxHtmlWidgetCell : public wxHtmlCell | |
309 | { | |
97494971 VS |
310 | public: |
311 | // !!! wnd must have correct parent! | |
312 | // if w != 0 then the m_Wnd has 'floating' width - it adjust | |
313 | // it's width according to parent container's width | |
314 | // (w is percent of parent's width) | |
315 | wxHtmlWidgetCell(wxWindow *wnd, int w = 0); | |
316 | ~wxHtmlWidgetCell() { m_Wnd->Destroy(); } | |
317 | virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2); | |
318 | virtual void DrawInvisible(wxDC& dc, int x, int y); | |
319 | virtual void Layout(int w); | |
320 | ||
321 | protected: | |
322 | wxWindow* m_Wnd; | |
323 | int m_WidthFloat; | |
324 | // width float is used in adjustWidth (it is in percents) | |
5526e819 VS |
325 | }; |
326 | ||
327 | ||
328 | ||
846914d1 VS |
329 | //-------------------------------------------------------------------------------- |
330 | // wxHtmlLinkInfo | |
331 | // Internal data structure. It represents hypertext link | |
332 | //-------------------------------------------------------------------------------- | |
333 | ||
ffef2bde | 334 | class WXDLLEXPORT wxHtmlLinkInfo : public wxObject |
846914d1 | 335 | { |
97494971 VS |
336 | public: |
337 | wxHtmlLinkInfo() : wxObject() | |
338 | { m_Href = m_Target = wxEmptyString; m_Event = NULL, m_Cell = NULL; } | |
339 | wxHtmlLinkInfo(const wxString& href, const wxString& target = wxEmptyString) : wxObject() | |
340 | { m_Href = href; m_Target = target; m_Event = NULL, m_Cell = NULL; } | |
341 | wxHtmlLinkInfo(const wxHtmlLinkInfo& l) : wxObject() | |
342 | { m_Href = l.m_Href, m_Target = l.m_Target, m_Event = l.m_Event; | |
343 | m_Cell = l.m_Cell; } | |
344 | wxHtmlLinkInfo& operator=(const wxHtmlLinkInfo& l) | |
345 | { m_Href = l.m_Href, m_Target = l.m_Target, m_Event = l.m_Event; | |
346 | m_Cell = l.m_Cell; return *this; } | |
347 | ||
348 | void SetEvent(const wxMouseEvent *e) { m_Event = e; } | |
349 | void SetHtmlCell(const wxHtmlCell *e) { m_Cell = e; } | |
350 | ||
351 | wxString GetHref() const { return m_Href; } | |
352 | wxString GetTarget() const { return m_Target; } | |
353 | const wxMouseEvent* GetEvent() const { return m_Event; } | |
354 | const wxHtmlCell* GetHtmlCell() const { return m_Cell; } | |
355 | ||
356 | private: | |
357 | wxString m_Href, m_Target; | |
358 | const wxMouseEvent *m_Event; | |
359 | const wxHtmlCell *m_Cell; | |
846914d1 VS |
360 | }; |
361 | ||
362 | ||
363 | ||
364 | ||
365 | #endif // wxUSE_HTML | |
5526e819 | 366 | |
69941f05 | 367 | #endif // _WX_HTMLCELL_H_ |
5526e819 | 368 |