]> git.saurik.com Git - wxWidgets.git/blame - include/wx/html/htmlcell.h
fixed DeleteContents inconsistency: didn't free memory if DeleteContents called befor...
[wxWidgets.git] / include / wx / html / htmlcell.h
CommitLineData
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
69941f05 6// RCS-ID: $Id$
5526e819
VS
7// Copyright: (c) 1999 Vaclav Slavik
8// Licence: wxWindows Licence
9/////////////////////////////////////////////////////////////////////////////
10
11
69941f05
VS
12#ifndef _WX_HTMLCELL_H_
13#define _WX_HTMLCELL_H_
5526e819
VS
14
15#ifdef __GNUG__
69941f05 16#pragma interface
5526e819
VS
17#endif
18
19#include "wx/defs.h"
5526e819 20
4dcaf11a 21#if wxUSE_HTML
5526e819 22
4dcaf11a
RR
23#include "wx/html/htmltag.h"
24#include "wx/html/htmldefs.h"
25#include "wx/window.h"
5526e819 26
846914d1 27
ffef2bde
RD
28class WXDLLEXPORT wxHtmlLinkInfo;
29class WXDLLEXPORT wxHtmlCell;
30class WXDLLEXPORT wxHtmlContainerCell;
5526e819
VS
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
40class WXDLLEXPORT wxHtmlCell : public wxObject
41{
5526e819 42 public:
846914d1
VS
43 wxHtmlCell();
44 virtual ~wxHtmlCell();
6e31e940 45
5526e819
VS
46 void SetParent(wxHtmlContainerCell *p) {m_Parent = p;}
47 wxHtmlContainerCell *GetParent() const {return m_Parent;}
6e31e940 48
5526e819
VS
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;}
846914d1 54 virtual wxHtmlLinkInfo* GetLink(int WXUNUSED(x) = 0,
6e31e940
VZ
55 int WXUNUSED(y) = 0) const
56 { return m_Link; }
5526e819
VS
57 // returns the link associated with this cell. The position is position within
58 // the cell so it varies from 0 to m_Width, from 0 to m_Height
59 wxHtmlCell *GetNext() const {return m_Next;}
60 // members access methods
61
62 virtual void SetPos(int x, int y) {m_PosX = x, m_PosY = y;}
846914d1 63 void SetLink(const wxHtmlLinkInfo& link);
5526e819
VS
64 void SetNext(wxHtmlCell *cell) {m_Next = cell;}
65 // members writin methods
66
721ab905 67 virtual void Layout(int w);
5526e819
VS
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
721ab905 73 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
5526e819
VS
74 // renders the cell
75
721ab905 76 virtual void DrawInvisible(wxDC& dc, int x, int y);
5526e819
VS
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
6e31e940 79
721ab905 80 virtual const wxHtmlCell* Find(int condition, const void* param) const;
5526e819
VS
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
efba2b89 89 // Example : m_Cell -> Find(wxHTML_COND_ISANCHOR, "news");
5526e819
VS
90 // returns pointer to anchor news
91
1be096c9 92 virtual void OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event);
5526e819
VS
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
ffef2bde 99
60e87cb1 100 virtual bool AdjustPagebreak(int *pagebreak) const;
db98870d
VS
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)) {}
ffef2bde 109
db98870d
VS
110 void SetCanLiveOnPagebreak(bool can) {m_CanLiveOnPagebreak = can;}
111 // Sets cell's behaviour on pagebreaks (see AdjustPagebreak). Default
112 // is true - the cell can be split on two pages
69941f05
VS
113
114
115 protected:
116 wxHtmlCell *m_Next;
117 // pointer to the next cell
118 wxHtmlContainerCell *m_Parent;
119 // pointer to parent cell
120 long m_Width, m_Height, m_Descent;
121 // dimensions of fragment
122 // m_Descent is used to position text&images..
123 long m_PosX, m_PosY;
124 // position where the fragment is drawn
846914d1 125 wxHtmlLinkInfo *m_Link;
69941f05 126 // destination address if this fragment is hypertext link, "" otherwise
db98870d
VS
127 bool m_CanLiveOnPagebreak;
128 // true if this cell can be placed on pagebreak, false otherwise
69941f05 129
5526e819
VS
130};
131
132
133
134
135//--------------------------------------------------------------------------------
136// Inherited cells:
137//--------------------------------------------------------------------------------
138
139
140//--------------------------------------------------------------------------------
141// wxHtmlWordCell
142// Single word in input stream.
143//--------------------------------------------------------------------------------
144
145class WXDLLEXPORT wxHtmlWordCell : public wxHtmlCell
146{
5526e819
VS
147 public:
148 wxHtmlWordCell(const wxString& word, wxDC& dc);
149 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
60e87cb1
VS
150
151 protected:
152 wxString m_Word;
5526e819
VS
153};
154
155
156
157
158
159//--------------------------------------------------------------------------------
160// wxHtmlContainerCell
161// Container - it contains other cells. Basic of layout algorithm.
162//--------------------------------------------------------------------------------
163
164class WXDLLEXPORT wxHtmlContainerCell : public wxHtmlCell
165{
5526e819
VS
166 public:
167 wxHtmlContainerCell(wxHtmlContainerCell *parent);
721ab905 168 ~wxHtmlContainerCell();
5526e819
VS
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);
60e87cb1 173 virtual bool AdjustPagebreak(int *pagebreak) const;
6e31e940 174
5526e819
VS
175 void InsertCell(wxHtmlCell *cell);
176 // insert cell at the end of m_Cells list
60e87cb1 177 void SetAlignHor(int al) {m_AlignHor = al; m_LastLayout = -1;}
5526e819 178 int GetAlignHor() const {return m_AlignHor;}
60e87cb1 179 void SetAlignVer(int al) {m_AlignVer = al; m_LastLayout = -1;}
5526e819
VS
180 // sets horizontal/vertical alignment
181 int GetAlignVer() const {return m_AlignVer;}
efba2b89
VS
182 void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
183 // sets left-border indentation. units is one of wxHTML_UNITS_* constants
184 // what is combination of wxHTML_INDENT_*
5526e819 185 int GetIndent(int ind) const;
efba2b89 186 // returns the indentation. ind is one of wxHTML_INDENT_* constants
5526e819
VS
187 int GetIndentUnits(int ind) const;
188 // returns type of value returned by GetIndent(ind)
189 void SetAlign(const wxHtmlTag& tag);
190 // sets alignment info based on given tag's params
60e87cb1 191 void SetWidthFloat(int w, int units) {m_WidthFloat = w; m_WidthFloatUnits = units; m_LastLayout = -1;}
edbd0635 192 void SetWidthFloat(const wxHtmlTag& tag, double pixel_scale = 1.0);
5526e819
VS
193 // sets floating width adjustment
194 // (examples : 32 percent of parent container,
195 // -15 pixels percent (this means 100 % - 15 pixels)
60e87cb1 196 void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP) {m_MinHeight = h; m_MinHeightAlign = align; m_LastLayout = -1;}
5526e819 197 // sets minimal height of this container.
5526e819
VS
198 void SetBackgroundColour(const wxColour& clr) {m_UseBkColour = TRUE; m_BkColour = clr;}
199 void SetBorder(const wxColour& clr1, const wxColour& clr2) {m_UseBorder = TRUE; m_BorderColour1 = clr1, m_BorderColour2 = clr2;}
846914d1 200 virtual wxHtmlLinkInfo* GetLink(int x = 0, int y = 0) const;
5526e819 201 virtual const wxHtmlCell* Find(int condition, const void* param) const;
1be096c9 202 virtual void OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event);
5526e819 203
60e87cb1 204 wxHtmlCell* GetFirstCell() const {return m_Cells;}
5526e819 205 // returns pointer to the first cell in container or NULL
60e87cb1
VS
206
207 protected:
208 int m_IndentLeft, m_IndentRight, m_IndentTop, m_IndentBottom;
209 // indentation of subcells. There is always m_Indent pixels
210 // big space between given border of the container and the subcells
211 // it m_Indent < 0 it is in PERCENTS, otherwise it is in pixels
212 int m_MinHeight, m_MinHeightAlign;
213 // minimal height.
60e87cb1
VS
214 wxHtmlCell *m_Cells, *m_LastCell;
215 // internal cells, m_Cells points to the first of them, m_LastCell to the last one.
216 // (LastCell is needed only to speed-up InsertCell)
217 int m_AlignHor, m_AlignVer;
218 // alignment horizontal and vertical (left, center, right)
219 int m_WidthFloat, m_WidthFloatUnits;
220 // width float is used in adjustWidth
221 bool m_UseBkColour;
222 wxColour m_BkColour;
223 // background color of this container
224 bool m_UseBorder;
225 wxColour m_BorderColour1, m_BorderColour2;
226 // borders color of this container
227 int m_LastLayout;
228 // if != -1 then call to Layout may be no-op
229 // if previous call to Layout has same argument
5526e819
VS
230};
231
232
233
234
235
236//--------------------------------------------------------------------------------
237// wxHtmlColourCell
238// Color changer.
239//--------------------------------------------------------------------------------
240
241class WXDLLEXPORT wxHtmlColourCell : public wxHtmlCell
242{
243 public:
ef8b2d91 244 wxHtmlColourCell(const wxColour& clr, int flags = wxHTML_CLR_FOREGROUND) : wxHtmlCell() {m_Colour = clr; m_Flags = flags;}
5526e819
VS
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);
60e87cb1
VS
247
248 protected:
249 wxColour m_Colour;
250 unsigned m_Flags;
5526e819
VS
251};
252
253
254
255
256//--------------------------------------------------------------------------------
257// wxHtmlFontCell
258// Sets actual font used for text rendering
259//--------------------------------------------------------------------------------
260
261class WXDLLEXPORT wxHtmlFontCell : public wxHtmlCell
262{
263 public:
921d0fb1 264 wxHtmlFontCell(wxFont *font) : wxHtmlCell() { m_Font = (*font); }
5526e819
VS
265 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
266 virtual void DrawInvisible(wxDC& dc, int x, int y);
60e87cb1
VS
267
268 protected:
269 wxFont m_Font;
5526e819
VS
270};
271
272
273
274
275
276
277//--------------------------------------------------------------------------------
278// wxHtmlwidgetCell
279// This cell is connected with wxWindow object
280// You can use it to insert windows into HTML page
281// (buttons, input boxes etc.)
282//--------------------------------------------------------------------------------
283
284class WXDLLEXPORT wxHtmlWidgetCell : public wxHtmlCell
285{
5526e819
VS
286 public:
287 wxHtmlWidgetCell(wxWindow *wnd, int w = 0);
288 // !!! wnd must have correct parent!
289 // if w != 0 then the m_Wnd has 'floating' width - it adjust
290 // it's width according to parent container's width
291 // (w is percent of parent's width)
721ab905 292 ~wxHtmlWidgetCell() { m_Wnd -> Destroy(); }
5526e819
VS
293 virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
294 virtual void DrawInvisible(wxDC& dc, int x, int y);
295 virtual void Layout(int w);
60e87cb1
VS
296
297 protected:
298 wxWindow* m_Wnd;
299 int m_WidthFloat;
300 // width float is used in adjustWidth (it is in percents)
5526e819
VS
301};
302
303
304
846914d1
VS
305//--------------------------------------------------------------------------------
306// wxHtmlLinkInfo
307// Internal data structure. It represents hypertext link
308//--------------------------------------------------------------------------------
309
ffef2bde 310class WXDLLEXPORT wxHtmlLinkInfo : public wxObject
846914d1
VS
311{
312 public:
313 wxHtmlLinkInfo() : wxObject()
9bc8fded 314 { m_Href = m_Target = wxEmptyString; m_Event = NULL, m_Cell = NULL; }
846914d1 315 wxHtmlLinkInfo(const wxString& href, const wxString& target = wxEmptyString) : wxObject()
9bc8fded 316 { m_Href = href; m_Target = target; m_Event = NULL, m_Cell = NULL; }
ffef2bde 317 wxHtmlLinkInfo(const wxHtmlLinkInfo& l)
9bc8fded 318 { m_Href = l.m_Href, m_Target = l.m_Target, m_Event = l.m_Event, m_Cell = l.m_Cell; }
ffef2bde 319 wxHtmlLinkInfo& operator=(const wxHtmlLinkInfo& l)
9bc8fded 320 { m_Href = l.m_Href, m_Target = l.m_Target, m_Event = l.m_Event, m_Cell = l.m_Cell; return *this; }
1be096c9
VS
321
322 void SetEvent(const wxMouseEvent *e) { m_Event = e; }
9bc8fded 323 void SetHtmlCell(const wxHtmlCell *e) { m_Cell = e; }
846914d1
VS
324
325 wxString GetHref() const { return m_Href; }
326 wxString GetTarget() const { return m_Target; }
1be096c9 327 const wxMouseEvent* GetEvent() const { return m_Event; }
9bc8fded 328 const wxHtmlCell* GetHtmlCell() const { return m_Cell; }
ffef2bde 329
846914d1
VS
330 private:
331 wxString m_Href, m_Target;
1be096c9 332 const wxMouseEvent *m_Event;
9bc8fded 333 const wxHtmlCell *m_Cell;
846914d1
VS
334};
335
336
337
338
339#endif // wxUSE_HTML
5526e819 340
69941f05 341#endif // _WX_HTMLCELL_H_
5526e819 342