]> git.saurik.com Git - wxWidgets.git/blob - include/wx/html/htmlcell.h
TreeTest compiles again,
[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;};
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(HTML_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
99 protected:
100 wxHtmlCell *m_Next;
101 // pointer to the next cell
102 wxHtmlContainerCell *m_Parent;
103 // pointer to parent cell
104 long m_Width, m_Height, m_Descent;
105 // dimensions of fragment
106 // m_Descent is used to position text&images..
107 long m_PosX, m_PosY;
108 // position where the fragment is drawn
109 wxString m_Link;
110 // destination address if this fragment is hypertext link, "" otherwise
111
112 };
113
114
115
116
117 //--------------------------------------------------------------------------------
118 // Inherited cells:
119 //--------------------------------------------------------------------------------
120
121
122 //--------------------------------------------------------------------------------
123 // wxHtmlWordCell
124 // Single word in input stream.
125 //--------------------------------------------------------------------------------
126
127 class WXDLLEXPORT wxHtmlWordCell : public wxHtmlCell
128 {
129 protected:
130 wxString m_Word;
131
132 public:
133 wxHtmlWordCell(const wxString& word, wxDC& dc);
134 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
135 };
136
137
138
139
140
141 //--------------------------------------------------------------------------------
142 // wxHtmlContainerCell
143 // Container - it contains other cells. Basic of layout algorithm.
144 //--------------------------------------------------------------------------------
145
146 class WXDLLEXPORT wxHtmlContainerCell : public wxHtmlCell
147 {
148 protected:
149 int m_IndentLeft, m_IndentRight, m_IndentTop, m_IndentBottom;
150 // indentation of subcells. There is always m_Indent pixels
151 // big space between given border of the container and the subcells
152 // it m_Indent < 0 it is in PERCENTS, otherwise it is in pixels
153 int m_MinHeight, m_MinHeightAlign;
154 // minimal height.
155 int m_MaxLineWidth;
156 // maximal widht of line. Filled during Layout()
157 wxHtmlCell *m_Cells, *m_LastCell;
158 // internal cells, m_Cells points to the first of them, m_LastCell to the last one.
159 // (LastCell is needed only to speed-up InsertCell)
160 int m_AlignHor, m_AlignVer;
161 // alignment horizontal and vertical (left, center, right)
162 int m_WidthFloat, m_WidthFloatUnits;
163 // width float is used in adjustWidth
164 bool m_UseBkColour;
165 wxColour m_BkColour;
166 // background color of this container
167 bool m_UseBorder;
168 wxColour m_BorderColour1, m_BorderColour2;
169 // borders color of this container
170
171 public:
172 wxHtmlContainerCell(wxHtmlContainerCell *parent);
173 ~wxHtmlContainerCell() {if (m_Cells) delete m_Cells;}
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
179 void InsertCell(wxHtmlCell *cell);
180 // insert cell at the end of m_Cells list
181 void SetAlignHor(int al) {m_AlignHor = al;}
182 int GetAlignHor() const {return m_AlignHor;}
183 void SetAlignVer(int al) {m_AlignVer = al;}
184 // sets horizontal/vertical alignment
185 int GetAlignVer() const {return m_AlignVer;}
186 void SetIndent(int i, int what, int units = HTML_UNITS_PIXELS);
187 // sets left-border indentation. units is one of HTML_UNITS_* constants
188 // what is combination of HTML_INDENT_*
189 int GetIndent(int ind) const;
190 // returns the indentation. ind is one of HTML_INDENT_* constants
191 int GetIndentUnits(int ind) const;
192 // returns type of value returned by GetIndent(ind)
193 void SetAlign(const wxHtmlTag& tag);
194 // sets alignment info based on given tag's params
195 void SetWidthFloat(int w, int units) {m_WidthFloat = w; m_WidthFloatUnits = units;}
196 void SetWidthFloat(const wxHtmlTag& tag);
197 // sets floating width adjustment
198 // (examples : 32 percent of parent container,
199 // -15 pixels percent (this means 100 % - 15 pixels)
200 void SetMinHeight(int h, int align = HTML_ALIGN_TOP) {m_MinHeight = h; m_MinHeightAlign = align;}
201 // sets minimal height of this container.
202 int GetMaxLineWidth() const {return m_MaxLineWidth;}
203 // returns maximal line width in this container.
204 // Call to this method is valid only after calling
205 // Layout()
206 void SetBackgroundColour(const wxColour& clr) {m_UseBkColour = TRUE; m_BkColour = clr;}
207 void SetBorder(const wxColour& clr1, const wxColour& clr2) {m_UseBorder = TRUE; m_BorderColour1 = clr1, m_BorderColour2 = clr2;}
208 virtual wxString GetLink(int x = 0, int y = 0) const;
209 virtual const wxHtmlCell* Find(int condition, const void* param) const;
210 virtual void OnMouseClick(wxWindow *parent, int x, int y, bool left, bool middle, bool right);
211
212 wxHtmlCell* GetFirstCell() {return m_Cells;}
213 // returns pointer to the first cell in container or NULL
214 };
215
216
217
218
219
220 //--------------------------------------------------------------------------------
221 // wxHtmlColourCell
222 // Color changer.
223 //--------------------------------------------------------------------------------
224
225 class WXDLLEXPORT wxHtmlColourCell : public wxHtmlCell
226 {
227 public:
228 wxColour m_Colour;
229 unsigned m_Flags;
230
231 wxHtmlColourCell(wxColour clr, int flags = HTML_CLR_FOREGROUND) : wxHtmlCell() {m_Colour = clr; m_Flags = flags;}
232 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
233 virtual void DrawInvisible(wxDC& dc, int x, int y);
234 };
235
236
237
238
239 //--------------------------------------------------------------------------------
240 // wxHtmlFontCell
241 // Sets actual font used for text rendering
242 //--------------------------------------------------------------------------------
243
244 class WXDLLEXPORT wxHtmlFontCell : public wxHtmlCell
245 {
246 public:
247 wxFont *m_Font;
248
249 wxHtmlFontCell(wxFont *font) : wxHtmlCell() {m_Font = font;};
250 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
251 virtual void DrawInvisible(wxDC& dc, int x, int y);
252 };
253
254
255
256
257
258
259 //--------------------------------------------------------------------------------
260 // wxHtmlwidgetCell
261 // This cell is connected with wxWindow object
262 // You can use it to insert windows into HTML page
263 // (buttons, input boxes etc.)
264 //--------------------------------------------------------------------------------
265
266 class WXDLLEXPORT wxHtmlWidgetCell : public wxHtmlCell
267 {
268 protected:
269 wxWindow* m_Wnd;
270 int m_WidthFloat;
271 // width float is used in adjustWidth (it is in percents)
272
273 public:
274 wxHtmlWidgetCell(wxWindow *wnd, int w = 0);
275 // !!! wnd must have correct parent!
276 // if w != 0 then the m_Wnd has 'floating' width - it adjust
277 // it's width according to parent container's width
278 // (w is percent of parent's width)
279 ~wxHtmlWidgetCell() {if (m_Wnd) m_Wnd -> Destroy(); }
280 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
281 virtual void DrawInvisible(wxDC& dc, int x, int y);
282 virtual void Layout(int w);
283 };
284
285
286
287 #endif
288
289 #endif // _WX_HTMLCELL_H_
290