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