beginnings of HTML4 tables layouter
[wxWidgets.git] / include / wx / html / htmlcell.h
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
6 // RCS-ID: $Id$
7 // Copyright: (c) 1999 Vaclav Slavik
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
10
11
12 #ifndef _WX_HTMLCELL_H_
13 #define _WX_HTMLCELL_H_
14
15 #ifdef __GNUG__
16 #pragma interface "htmlcell.h"
17 #endif
18
19 #include "wx/defs.h"
20
21 #if wxUSE_HTML
22
23 #include "wx/html/htmltag.h"
24 #include "wx/html/htmldefs.h"
25 #include "wx/window.h"
26
27
28 class WXDLLEXPORT wxHtmlLinkInfo;
29 class WXDLLEXPORT wxHtmlCell;
30 class WXDLLEXPORT wxHtmlContainerCell;
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 {
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
63 // members writin methods
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
75 virtual void Draw(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2)) {}
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
79 virtual void DrawInvisible(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y)) {}
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.
94 // left, middle, right are flags indicating whether the button was or wasn't
95 // pressed.
96 // Parent is pointer to wxHtmlWindow that generated the event
97 // HINT: if this handling is not enough for you you should use
98 // wxHtmlBinderCell
99 virtual void OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event);
100
101 // This method used to adjust pagebreak position. The parameter is
102 // variable that contains y-coordinate of page break (= horizontal line that
103 // should not be crossed by words, images etc.). If this cell cannot be divided
104 // into two pieces (each one on another page) then it moves the pagebreak
105 // few pixels up.
106 //
107 // Returned value : true if pagebreak was modified, false otherwise
108 // Usage : while (container->AdjustPagebreak(&p)) {}
109 virtual bool AdjustPagebreak(int *pagebreak) const;
110
111 // Sets cell's behaviour on pagebreaks (see AdjustPagebreak). Default
112 // is true - the cell can be split on two pages
113 void SetCanLiveOnPagebreak(bool can) { m_CanLiveOnPagebreak = can; }
114
115 // Returns y-coordinates that contraint the cell, i.e. left is highest
116 // and right lowest coordinate such that the cell lays between then.
117 // Note: this method does not return meaningful values if you haven't
118 // called Layout() before!
119 virtual void GetHorizontalConstraints(int *left, int *right) const;
120
121 protected:
122 wxHtmlCell *m_Next;
123 // pointer to the next cell
124 wxHtmlContainerCell *m_Parent;
125 // pointer to parent cell
126 long m_Width, m_Height, m_Descent;
127 // dimensions of fragment
128 // m_Descent is used to position text&images..
129 long m_PosX, m_PosY;
130 // position where the fragment is drawn
131 wxHtmlLinkInfo *m_Link;
132 // destination address if this fragment is hypertext link, "" otherwise
133 bool m_CanLiveOnPagebreak;
134 // true if this cell can be placed on pagebreak, false otherwise
135 };
136
137
138
139
140 //--------------------------------------------------------------------------------
141 // Inherited cells:
142 //--------------------------------------------------------------------------------
143
144
145 //--------------------------------------------------------------------------------
146 // wxHtmlWordCell
147 // Single word in input stream.
148 //--------------------------------------------------------------------------------
149
150 class WXDLLEXPORT wxHtmlWordCell : public wxHtmlCell
151 {
152 public:
153 wxHtmlWordCell(const wxString& word, wxDC& dc);
154 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
155
156 protected:
157 wxString m_Word;
158 };
159
160
161
162
163
164 //--------------------------------------------------------------------------------
165 // wxHtmlContainerCell
166 // Container - it contains other cells. Basic of layout algorithm.
167 //--------------------------------------------------------------------------------
168
169 class WXDLLEXPORT wxHtmlContainerCell : public wxHtmlCell
170 {
171 public:
172 wxHtmlContainerCell(wxHtmlContainerCell *parent);
173 ~wxHtmlContainerCell();
174
175 virtual void Layout(int w);
176 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
177 virtual void DrawInvisible(wxDC& dc, int x, int y);
178 virtual bool AdjustPagebreak(int *pagebreak) const;
179
180 // insert cell at the end of m_Cells list
181 void InsertCell(wxHtmlCell *cell);
182
183 // sets horizontal/vertical alignment
184 void SetAlignHor(int al) {m_AlignHor = al; m_LastLayout = -1;}
185 int GetAlignHor() const {return m_AlignHor;}
186 void SetAlignVer(int al) {m_AlignVer = al; m_LastLayout = -1;}
187 int GetAlignVer() const {return m_AlignVer;}
188
189 // sets left-border indentation. units is one of wxHTML_UNITS_* constants
190 // what is combination of wxHTML_INDENT_*
191 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
192 // returns the indentation. ind is one of wxHTML_INDENT_* constants
193 int GetIndent(int ind) const;
194 // returns type of value returned by GetIndent(ind)
195 int GetIndentUnits(int ind) const;
196
197 // sets alignment info based on given tag's params
198 void SetAlign(const wxHtmlTag& tag);
199 // sets floating width adjustment
200 // (examples : 32 percent of parent container,
201 // -15 pixels percent (this means 100 % - 15 pixels)
202 void SetWidthFloat(int w, int units) {m_WidthFloat = w; m_WidthFloatUnits = units; m_LastLayout = -1;}
203 void SetWidthFloat(const wxHtmlTag& tag, double pixel_scale = 1.0);
204 // sets minimal height of this container.
205 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP) {m_MinHeight = h; m_MinHeightAlign = align; m_LastLayout = -1;}
206
207 void SetBackgroundColour(const wxColour& clr) {m_UseBkColour = TRUE; m_BkColour = clr;}
208 void SetBorder(const wxColour& clr1, const wxColour& clr2) {m_UseBorder = TRUE; m_BorderColour1 = clr1, m_BorderColour2 = clr2;}
209 virtual wxHtmlLinkInfo* GetLink(int x = 0, int y = 0) const;
210 virtual const wxHtmlCell* Find(int condition, const void* param) const;
211 virtual void OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event);
212 virtual void GetHorizontalConstraints(int *left, int *right) const;
213
214 // returns pointer to the first cell in container or NULL
215 wxHtmlCell* GetFirstCell() const {return m_Cells;}
216
217 protected:
218 int m_IndentLeft, m_IndentRight, m_IndentTop, m_IndentBottom;
219 // indentation of subcells. There is always m_Indent pixels
220 // big space between given border of the container and the subcells
221 // it m_Indent < 0 it is in PERCENTS, otherwise it is in pixels
222 int m_MinHeight, m_MinHeightAlign;
223 // minimal height.
224 wxHtmlCell *m_Cells, *m_LastCell;
225 // internal cells, m_Cells points to the first of them, m_LastCell to the last one.
226 // (LastCell is needed only to speed-up InsertCell)
227 int m_AlignHor, m_AlignVer;
228 // alignment horizontal and vertical (left, center, right)
229 int m_WidthFloat, m_WidthFloatUnits;
230 // width float is used in adjustWidth
231 bool m_UseBkColour;
232 wxColour m_BkColour;
233 // background color of this container
234 bool m_UseBorder;
235 wxColour m_BorderColour1, m_BorderColour2;
236 // borders color of this container
237 int m_LastLayout;
238 // if != -1 then call to Layout may be no-op
239 // if previous call to Layout has same argument
240 };
241
242
243
244
245
246 //--------------------------------------------------------------------------------
247 // wxHtmlColourCell
248 // Color changer.
249 //--------------------------------------------------------------------------------
250
251 class WXDLLEXPORT wxHtmlColourCell : public wxHtmlCell
252 {
253 public:
254 wxHtmlColourCell(const wxColour& clr, int flags = wxHTML_CLR_FOREGROUND) : wxHtmlCell() {m_Colour = clr; m_Flags = flags;}
255 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
256 virtual void DrawInvisible(wxDC& dc, int x, int y);
257
258 protected:
259 wxColour m_Colour;
260 unsigned m_Flags;
261 };
262
263
264
265
266 //--------------------------------------------------------------------------------
267 // wxHtmlFontCell
268 // Sets actual font used for text rendering
269 //--------------------------------------------------------------------------------
270
271 class WXDLLEXPORT wxHtmlFontCell : public wxHtmlCell
272 {
273 public:
274 wxHtmlFontCell(wxFont *font) : wxHtmlCell() { m_Font = (*font); }
275 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
276 virtual void DrawInvisible(wxDC& dc, int x, int y);
277
278 protected:
279 wxFont m_Font;
280 };
281
282
283
284
285
286
287 //--------------------------------------------------------------------------------
288 // wxHtmlwidgetCell
289 // This cell is connected with wxWindow object
290 // You can use it to insert windows into HTML page
291 // (buttons, input boxes etc.)
292 //--------------------------------------------------------------------------------
293
294 class WXDLLEXPORT wxHtmlWidgetCell : public wxHtmlCell
295 {
296 public:
297 // !!! wnd must have correct parent!
298 // if w != 0 then the m_Wnd has 'floating' width - it adjust
299 // it's width according to parent container's width
300 // (w is percent of parent's width)
301 wxHtmlWidgetCell(wxWindow *wnd, int w = 0);
302 ~wxHtmlWidgetCell() { m_Wnd->Destroy(); }
303 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
304 virtual void DrawInvisible(wxDC& dc, int x, int y);
305 virtual void Layout(int w);
306
307 protected:
308 wxWindow* m_Wnd;
309 int m_WidthFloat;
310 // width float is used in adjustWidth (it is in percents)
311 };
312
313
314
315 //--------------------------------------------------------------------------------
316 // wxHtmlLinkInfo
317 // Internal data structure. It represents hypertext link
318 //--------------------------------------------------------------------------------
319
320 class WXDLLEXPORT wxHtmlLinkInfo : public wxObject
321 {
322 public:
323 wxHtmlLinkInfo() : wxObject()
324 { m_Href = m_Target = wxEmptyString; m_Event = NULL, m_Cell = NULL; }
325 wxHtmlLinkInfo(const wxString& href, const wxString& target = wxEmptyString) : wxObject()
326 { m_Href = href; m_Target = target; m_Event = NULL, m_Cell = NULL; }
327 wxHtmlLinkInfo(const wxHtmlLinkInfo& l) : wxObject()
328 { m_Href = l.m_Href, m_Target = l.m_Target, m_Event = l.m_Event;
329 m_Cell = l.m_Cell; }
330 wxHtmlLinkInfo& operator=(const wxHtmlLinkInfo& l)
331 { m_Href = l.m_Href, m_Target = l.m_Target, m_Event = l.m_Event;
332 m_Cell = l.m_Cell; return *this; }
333
334 void SetEvent(const wxMouseEvent *e) { m_Event = e; }
335 void SetHtmlCell(const wxHtmlCell *e) { m_Cell = e; }
336
337 wxString GetHref() const { return m_Href; }
338 wxString GetTarget() const { return m_Target; }
339 const wxMouseEvent* GetEvent() const { return m_Event; }
340 const wxHtmlCell* GetHtmlCell() const { return m_Cell; }
341
342 private:
343 wxString m_Href, m_Target;
344 const wxMouseEvent *m_Event;
345 const wxHtmlCell *m_Cell;
346 };
347
348
349
350
351 #endif // wxUSE_HTML
352
353 #endif // _WX_HTMLCELL_H_
354