Small distrib updates,
[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 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifndef __HTMLCELL_H__
12 #define __HTMLCELL_H__
13
14 #ifdef __GNUG__
15 #pragma interface "htmlcell.h"
16 #endif
17
18 #include "wx/defs.h"
19
20 #if wxUSE_HTML
21
22 #include "wx/html/htmltag.h"
23 #include "wx/html/htmldefs.h"
24 #include "wx/window.h"
25
26 class wxHtmlCell;
27 class wxHtmlContainerCell;
28
29 //--------------------------------------------------------------------------------
30 // wxHtmlCell
31 // Internal data structure. It represents fragments of parsed HTML
32 // page - a word, picture, table, horizontal line and so on.
33 // It is used by wxHtmlWindow to represent HTML page in memory.
34 //--------------------------------------------------------------------------------
35
36
37 class WXDLLEXPORT wxHtmlCell : public wxObject
38 {
39 protected:
40 wxHtmlCell *m_Next;
41 // pointer to the next cell
42 wxHtmlContainerCell *m_Parent;
43 // pointer to parent cell
44 long m_Width, m_Height, m_Descent;
45 // dimensions of fragment
46 // m_Descent is used to position text&images..
47 long m_PosX, m_PosY;
48 // position where the fragment is drawn
49 wxString m_Link;
50 // destination address if this fragment is hypertext link, "" otherwise
51
52 public:
53 wxHtmlCell() : wxObject() {m_Next = NULL; m_Parent = NULL; m_Width = m_Height = m_Descent = 0;};
54 virtual ~wxHtmlCell() {if (m_Next) delete m_Next;};
55
56 void SetParent(wxHtmlContainerCell *p) {m_Parent = p;}
57 wxHtmlContainerCell *GetParent() const {return m_Parent;}
58
59 int GetPosX() const {return m_PosX;}
60 int GetPosY() const {return m_PosY;}
61 int GetWidth() const {return m_Width;}
62 int GetHeight() const {return m_Height;}
63 int GetDescent() const {return m_Descent;}
64 virtual wxString GetLink(int x = 0, int y = 0) const {return m_Link;}
65 // returns the link associated with this cell. The position is position within
66 // the cell so it varies from 0 to m_Width, from 0 to m_Height
67 wxHtmlCell *GetNext() const {return m_Next;}
68 // members access methods
69
70 virtual void SetPos(int x, int y) {m_PosX = x, m_PosY = y;}
71 void SetLink(const wxString& link) {m_Link = link;}
72 void SetNext(wxHtmlCell *cell) {m_Next = cell;}
73 // members writin methods
74
75 virtual void Layout(int w) {SetPos(0, 0); if (m_Next) m_Next -> Layout(w);};
76 // 1. adjust cell's width according to the fact that maximal possible width is w.
77 // (this has sense when working with horizontal lines, tables etc.)
78 // 2. prepare layout (=fill-in m_PosX, m_PosY (and sometime m_Height) members)
79 // = place items to fit window, according to the width w
80
81 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2) {if (m_Next) m_Next -> Draw(dc, x, y, view_y1, view_y2);}
82 // renders the cell
83
84 virtual void DrawInvisible(wxDC& dc, int x, int y) {if (m_Next) m_Next -> DrawInvisible(dc, x, y);};
85 // proceed drawing actions in case the cell is not visible (scrolled out of screen).
86 // This is needed to change fonts, colors and so on
87
88 virtual const wxHtmlCell* Find(int condition, const void* param) const {if (m_Next) return m_Next -> Find(condition, param); else return NULL;}
89 // This method returns pointer to the FIRST cell for that
90 // the condition
91 // is true. It first checks if the condition is true for this
92 // cell and then calls m_Next -> Find(). (Note: it checks
93 // all subcells if the cell is container)
94 // Condition is unique condition identifier (see htmldefs.h)
95 // (user-defined condition IDs should start from 10000)
96 // and param is optional parameter
97 // Example : m_Cell -> Find(HTML_COND_ISANCHOR, "news");
98 // returns pointer to anchor news
99
100 virtual void OnMouseClick(wxWindow *parent, int x, int y, bool left, bool middle, bool right);
101 // This function is called when mouse button is clicked over the cell.
102 // left, middle, right are flags indicating whether the button was or wasn't
103 // pressed.
104 // Parent is pointer to wxHtmlWindow that generated the event
105 // HINT: if this handling is not enough for you you should use
106 // wxHtmlBinderCell
107 };
108
109
110
111
112 //--------------------------------------------------------------------------------
113 // Inherited cells:
114 //--------------------------------------------------------------------------------
115
116
117 //--------------------------------------------------------------------------------
118 // wxHtmlWordCell
119 // Single word in input stream.
120 //--------------------------------------------------------------------------------
121
122 class WXDLLEXPORT wxHtmlWordCell : public wxHtmlCell
123 {
124 protected:
125 wxString m_Word;
126
127 public:
128 wxHtmlWordCell(const wxString& word, wxDC& dc);
129 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
130 };
131
132
133
134
135
136 //--------------------------------------------------------------------------------
137 // wxHtmlContainerCell
138 // Container - it contains other cells. Basic of layout algorithm.
139 //--------------------------------------------------------------------------------
140
141 class WXDLLEXPORT wxHtmlContainerCell : public wxHtmlCell
142 {
143 protected:
144 int m_IndentLeft, m_IndentRight, m_IndentTop, m_IndentBottom;
145 // indentation of subcells. There is always m_Indent pixels
146 // big space between given border of the container and the subcells
147 // it m_Indent < 0 it is in PERCENTS, otherwise it is in pixels
148 int m_MinHeight, m_MinHeightAlign;
149 // minimal height.
150 int m_MaxLineWidth;
151 // maximal widht of line. Filled during Layout()
152 wxHtmlCell *m_Cells, *m_LastCell;
153 // internal cells, m_Cells points to the first of them, m_LastCell to the last one.
154 // (LastCell is needed only to speed-up InsertCell)
155 int m_AlignHor, m_AlignVer;
156 // alignment horizontal and vertical (left, center, right)
157 int m_WidthFloat, m_WidthFloatUnits;
158 // width float is used in adjustWidth
159 bool m_UseBkColour;
160 wxColour m_BkColour;
161 // background color of this container
162 bool m_UseBorder;
163 wxColour m_BorderColour1, m_BorderColour2;
164 // borders color of this container
165
166 public:
167 wxHtmlContainerCell(wxHtmlContainerCell *parent);
168 ~wxHtmlContainerCell() {if (m_Cells) delete m_Cells;}
169
170 virtual void Layout(int w);
171 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
172 virtual void DrawInvisible(wxDC& dc, int x, int y);
173
174 void InsertCell(wxHtmlCell *cell);
175 // insert cell at the end of m_Cells list
176 void SetAlignHor(int al) {m_AlignHor = al;}
177 int GetAlignHor() const {return m_AlignHor;}
178 void SetAlignVer(int al) {m_AlignVer = al;}
179 // sets horizontal/vertical alignment
180 int GetAlignVer() const {return m_AlignVer;}
181 void SetIndent(int i, int what, int units = HTML_UNITS_PIXELS);
182 // sets left-border indentation. units is one of HTML_UNITS_* constants
183 // what is combination of HTML_INDENT_*
184 int GetIndent(int ind) const;
185 // returns the indentation. ind is one of HTML_INDENT_* constants
186 int GetIndentUnits(int ind) const;
187 // returns type of value returned by GetIndent(ind)
188 void SetAlign(const wxHtmlTag& tag);
189 // sets alignment info based on given tag's params
190 void SetWidthFloat(int w, int units) {m_WidthFloat = w; m_WidthFloatUnits = units;}
191 void SetWidthFloat(const wxHtmlTag& tag);
192 // sets floating width adjustment
193 // (examples : 32 percent of parent container,
194 // -15 pixels percent (this means 100 % - 15 pixels)
195 void SetMinHeight(int h, int align = HTML_ALIGN_TOP) {m_MinHeight = h; m_MinHeightAlign = align;}
196 // sets minimal height of this container.
197 int GetMaxLineWidth() const {return m_MaxLineWidth;}
198 // returns maximal line width in this container.
199 // Call to this method is valid only after calling
200 // Layout()
201 void SetBackgroundColour(const wxColour& clr) {m_UseBkColour = TRUE; m_BkColour = clr;}
202 void SetBorder(const wxColour& clr1, const wxColour& clr2) {m_UseBorder = TRUE; m_BorderColour1 = clr1, m_BorderColour2 = clr2;}
203 virtual wxString GetLink(int x = 0, int y = 0) const;
204 virtual const wxHtmlCell* Find(int condition, const void* param) const;
205 virtual void OnMouseClick(wxWindow *parent, int x, int y, bool left, bool middle, bool right);
206
207 wxHtmlCell* GetFirstCell() {return m_Cells;}
208 // returns pointer to the first cell in container or NULL
209 };
210
211
212
213
214
215 //--------------------------------------------------------------------------------
216 // wxHtmlColourCell
217 // Color changer.
218 //--------------------------------------------------------------------------------
219
220 class WXDLLEXPORT wxHtmlColourCell : public wxHtmlCell
221 {
222 public:
223 wxColour m_Colour;
224 unsigned m_Flags;
225
226 wxHtmlColourCell(wxColour clr, int flags = HTML_CLR_FOREGROUND) : wxHtmlCell() {m_Colour = clr; m_Flags = flags;}
227 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
228 virtual void DrawInvisible(wxDC& dc, int x, int y);
229 };
230
231
232
233
234 //--------------------------------------------------------------------------------
235 // wxHtmlFontCell
236 // Sets actual font used for text rendering
237 //--------------------------------------------------------------------------------
238
239 class WXDLLEXPORT wxHtmlFontCell : public wxHtmlCell
240 {
241 public:
242 wxFont *m_Font;
243
244 wxHtmlFontCell(wxFont *font) : wxHtmlCell() {m_Font = font;};
245 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
246 virtual void DrawInvisible(wxDC& dc, int x, int y);
247 };
248
249
250
251
252
253
254 //--------------------------------------------------------------------------------
255 // wxHtmlwidgetCell
256 // This cell is connected with wxWindow object
257 // You can use it to insert windows into HTML page
258 // (buttons, input boxes etc.)
259 //--------------------------------------------------------------------------------
260
261 class WXDLLEXPORT wxHtmlWidgetCell : public wxHtmlCell
262 {
263 protected:
264 wxWindow* m_Wnd;
265 int m_WidthFloat;
266 // width float is used in adjustWidth (it is in percents)
267
268 public:
269 wxHtmlWidgetCell(wxWindow *wnd, int w = 0);
270 // !!! wnd must have correct parent!
271 // if w != 0 then the m_Wnd has 'floating' width - it adjust
272 // it's width according to parent container's width
273 // (w is percent of parent's width)
274 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
275 virtual void DrawInvisible(wxDC& dc, int x, int y);
276 virtual void Layout(int w);
277 };
278
279
280
281
282 #endif // __HTMLCELL_H__
283
284 #endif
285
286
287
288
289
290
291
292