1 /////////////////////////////////////////////////////////////////////////////
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 /////////////////////////////////////////////////////////////////////////////
11 #ifndef __HTMLCELL_H__
12 #define __HTMLCELL_H__
15 #pragma interface "htmlcell.h"
22 #include "wx/html/htmltag.h"
23 #include "wx/html/htmldefs.h"
24 #include "wx/window.h"
27 class wxHtmlContainerCell
;
29 //--------------------------------------------------------------------------------
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 //--------------------------------------------------------------------------------
37 class WXDLLEXPORT wxHtmlCell
: public wxObject
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..
48 // position where the fragment is drawn
50 // destination address if this fragment is hypertext link, "" otherwise
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
;};
56 void SetParent(wxHtmlContainerCell
*p
) {m_Parent
= p
;}
57 wxHtmlContainerCell
*GetParent() const {return m_Parent
;}
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 WXUNUSED(x
) = 0,
65 int WXUNUSED(y
) = 0) const
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
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
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
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
);}
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
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
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
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
106 // Parent is pointer to wxHtmlWindow that generated the event
107 // HINT: if this handling is not enough for you you should use
114 //--------------------------------------------------------------------------------
116 //--------------------------------------------------------------------------------
119 //--------------------------------------------------------------------------------
121 // Single word in input stream.
122 //--------------------------------------------------------------------------------
124 class WXDLLEXPORT wxHtmlWordCell
: public wxHtmlCell
130 wxHtmlWordCell(const wxString
& word
, wxDC
& dc
);
131 void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
);
138 //--------------------------------------------------------------------------------
139 // wxHtmlContainerCell
140 // Container - it contains other cells. Basic of layout algorithm.
141 //--------------------------------------------------------------------------------
143 class WXDLLEXPORT wxHtmlContainerCell
: public wxHtmlCell
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
;
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
163 // background color of this container
165 wxColour m_BorderColour1
, m_BorderColour2
;
166 // borders color of this container
169 wxHtmlContainerCell(wxHtmlContainerCell
*parent
);
170 ~wxHtmlContainerCell() {if (m_Cells
) delete m_Cells
;}
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
);
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
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
);
209 wxHtmlCell
* GetFirstCell() {return m_Cells
;}
210 // returns pointer to the first cell in container or NULL
217 //--------------------------------------------------------------------------------
220 //--------------------------------------------------------------------------------
222 class WXDLLEXPORT wxHtmlColourCell
: public wxHtmlCell
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
);
236 //--------------------------------------------------------------------------------
238 // Sets actual font used for text rendering
239 //--------------------------------------------------------------------------------
241 class WXDLLEXPORT wxHtmlFontCell
: public wxHtmlCell
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
);
256 //--------------------------------------------------------------------------------
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 //--------------------------------------------------------------------------------
263 class WXDLLEXPORT wxHtmlWidgetCell
: public wxHtmlCell
268 // width float is used in adjustWidth (it is in percents)
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)
276 ~wxHtmlWidgetCell() {if (m_Wnd
) m_Wnd
-> Destroy(); }
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
);
285 #endif // __HTMLCELL_H__