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 x
= 0, int y
= 0) const {return m_Link
;}
65 // returns the link associated with this cell. The position is position within
66 // the cell so it varies from 0 to m_Width, from 0 to m_Height
67 wxHtmlCell
*GetNext() const {return m_Next
;}
68 // members access methods
70 virtual void SetPos(int x
, int y
) {m_PosX
= x
, m_PosY
= y
;}
71 void SetLink(const wxString
& link
) {m_Link
= link
;}
72 void SetNext(wxHtmlCell
*cell
) {m_Next
= cell
;}
73 // members writin methods
75 virtual void Layout(int w
) {SetPos(0, 0); if (m_Next
) m_Next
-> Layout(w
);};
76 // 1. adjust cell's width according to the fact that maximal possible width is w.
77 // (this has sense when working with horizontal lines, tables etc.)
78 // 2. prepare layout (=fill-in m_PosX, m_PosY (and sometime m_Height) members)
79 // = place items to fit window, according to the width w
81 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 virtual void DrawInvisible(wxDC
& dc
, int x
, int y
) {if (m_Next
) m_Next
-> DrawInvisible(dc
, x
, y
);};
85 // proceed drawing actions in case the cell is not visible (scrolled out of screen).
86 // This is needed to change fonts, colors and so on
88 virtual const wxHtmlCell
* Find(int condition
, const void* param
) const {if (m_Next
) return m_Next
-> Find(condition
, param
); else return NULL
;}
89 // This method returns pointer to the FIRST cell for that
91 // is true. It first checks if the condition is true for this
92 // cell and then calls m_Next -> Find(). (Note: it checks
93 // all subcells if the cell is container)
94 // Condition is unique condition identifier (see htmldefs.h)
95 // (user-defined condition IDs should start from 10000)
96 // and param is optional parameter
97 // Example : m_Cell -> Find(HTML_COND_ISANCHOR, "news");
98 // returns pointer to anchor news
100 virtual void OnMouseClick(wxWindow
*parent
, int x
, int y
, bool left
, bool middle
, bool right
);
101 // This function is called when mouse button is clicked over the cell.
102 // left, middle, right are flags indicating whether the button was or wasn't
104 // Parent is pointer to wxHtmlWindow that generated the event
105 // HINT: if this handling is not enough for you you should use
112 //--------------------------------------------------------------------------------
114 //--------------------------------------------------------------------------------
117 //--------------------------------------------------------------------------------
119 // Single word in input stream.
120 //--------------------------------------------------------------------------------
122 class WXDLLEXPORT wxHtmlWordCell
: public wxHtmlCell
128 wxHtmlWordCell(const wxString
& word
, wxDC
& dc
);
129 void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
);
136 //--------------------------------------------------------------------------------
137 // wxHtmlContainerCell
138 // Container - it contains other cells. Basic of layout algorithm.
139 //--------------------------------------------------------------------------------
141 class WXDLLEXPORT wxHtmlContainerCell
: public wxHtmlCell
144 int m_IndentLeft
, m_IndentRight
, m_IndentTop
, m_IndentBottom
;
145 // indentation of subcells. There is always m_Indent pixels
146 // big space between given border of the container and the subcells
147 // it m_Indent < 0 it is in PERCENTS, otherwise it is in pixels
148 int m_MinHeight
, m_MinHeightAlign
;
151 // maximal widht of line. Filled during Layout()
152 wxHtmlCell
*m_Cells
, *m_LastCell
;
153 // internal cells, m_Cells points to the first of them, m_LastCell to the last one.
154 // (LastCell is needed only to speed-up InsertCell)
155 int m_AlignHor
, m_AlignVer
;
156 // alignment horizontal and vertical (left, center, right)
157 int m_WidthFloat
, m_WidthFloatUnits
;
158 // width float is used in adjustWidth
161 // background color of this container
163 wxColour m_BorderColour1
, m_BorderColour2
;
164 // borders color of this container
167 wxHtmlContainerCell(wxHtmlContainerCell
*parent
);
168 ~wxHtmlContainerCell() {if (m_Cells
) delete m_Cells
;}
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
);
174 void InsertCell(wxHtmlCell
*cell
);
175 // insert cell at the end of m_Cells list
176 void SetAlignHor(int al
) {m_AlignHor
= al
;}
177 int GetAlignHor() const {return m_AlignHor
;}
178 void SetAlignVer(int al
) {m_AlignVer
= al
;}
179 // sets horizontal/vertical alignment
180 int GetAlignVer() const {return m_AlignVer
;}
181 void SetIndent(int i
, int what
, int units
= HTML_UNITS_PIXELS
);
182 // sets left-border indentation. units is one of HTML_UNITS_* constants
183 // what is combination of HTML_INDENT_*
184 int GetIndent(int ind
) const;
185 // returns the indentation. ind is one of HTML_INDENT_* constants
186 int GetIndentUnits(int ind
) const;
187 // returns type of value returned by GetIndent(ind)
188 void SetAlign(const wxHtmlTag
& tag
);
189 // sets alignment info based on given tag's params
190 void SetWidthFloat(int w
, int units
) {m_WidthFloat
= w
; m_WidthFloatUnits
= units
;}
191 void SetWidthFloat(const wxHtmlTag
& tag
);
192 // sets floating width adjustment
193 // (examples : 32 percent of parent container,
194 // -15 pixels percent (this means 100 % - 15 pixels)
195 void SetMinHeight(int h
, int align
= HTML_ALIGN_TOP
) {m_MinHeight
= h
; m_MinHeightAlign
= align
;}
196 // sets minimal height of this container.
197 int GetMaxLineWidth() const {return m_MaxLineWidth
;}
198 // returns maximal line width in this container.
199 // Call to this method is valid only after calling
201 void SetBackgroundColour(const wxColour
& clr
) {m_UseBkColour
= TRUE
; m_BkColour
= clr
;}
202 void SetBorder(const wxColour
& clr1
, const wxColour
& clr2
) {m_UseBorder
= TRUE
; m_BorderColour1
= clr1
, m_BorderColour2
= clr2
;}
203 virtual wxString
GetLink(int x
= 0, int y
= 0) const;
204 virtual const wxHtmlCell
* Find(int condition
, const void* param
) const;
205 virtual void OnMouseClick(wxWindow
*parent
, int x
, int y
, bool left
, bool middle
, bool right
);
207 wxHtmlCell
* GetFirstCell() {return m_Cells
;}
208 // returns pointer to the first cell in container or NULL
215 //--------------------------------------------------------------------------------
218 //--------------------------------------------------------------------------------
220 class WXDLLEXPORT wxHtmlColourCell
: public wxHtmlCell
226 wxHtmlColourCell(wxColour clr
, int flags
= HTML_CLR_FOREGROUND
) : wxHtmlCell() {m_Colour
= clr
; m_Flags
= flags
;}
227 virtual void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
);
228 virtual void DrawInvisible(wxDC
& dc
, int x
, int y
);
234 //--------------------------------------------------------------------------------
236 // Sets actual font used for text rendering
237 //--------------------------------------------------------------------------------
239 class WXDLLEXPORT wxHtmlFontCell
: public wxHtmlCell
244 wxHtmlFontCell(wxFont
*font
) : wxHtmlCell() {m_Font
= font
;};
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
);
254 //--------------------------------------------------------------------------------
256 // This cell is connected with wxWindow object
257 // You can use it to insert windows into HTML page
258 // (buttons, input boxes etc.)
259 //--------------------------------------------------------------------------------
261 class WXDLLEXPORT wxHtmlWidgetCell
: public wxHtmlCell
266 // width float is used in adjustWidth (it is in percents)
269 wxHtmlWidgetCell(wxWindow
*wnd
, int w
= 0);
270 // !!! wnd must have correct parent!
271 // if w != 0 then the m_Wnd has 'floating' width - it adjust
272 // it's width according to parent container's width
273 // (w is percent of parent's width)
274 ~wxHtmlWidgetCell() {if (m_Wnd
) m_Wnd
-> Destroy(); }
275 virtual void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
);
276 virtual void DrawInvisible(wxDC
& dc
, int x
, int y
);
277 virtual void Layout(int w
);
283 #endif // __HTMLCELL_H__