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