1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlCell class is used by wxHtmlWindow/wxHtmlWinParser
4 // as a basic visual element of HTML page
5 // Author: Vaclav Slavik
7 // Copyright: (c) 1999 Vaclav Slavik
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_HTMLCELL_H_
13 #define _WX_HTMLCELL_H_
23 #include "wx/html/htmltag.h"
24 #include "wx/html/htmldefs.h"
25 #include "wx/window.h"
28 class WXDLLEXPORT wxHtmlLinkInfo
;
29 class WXDLLEXPORT wxHtmlCell
;
30 class WXDLLEXPORT wxHtmlContainerCell
;
32 //--------------------------------------------------------------------------------
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 //--------------------------------------------------------------------------------
40 class WXDLLEXPORT wxHtmlCell
: public wxObject
44 virtual ~wxHtmlCell();
46 void SetParent(wxHtmlContainerCell
*p
) {m_Parent
= p
;}
47 wxHtmlContainerCell
*GetParent() const {return m_Parent
;}
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
;}
54 virtual wxHtmlLinkInfo
* GetLink(int WXUNUSED(x
) = 0,
55 int WXUNUSED(y
) = 0) const
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
62 virtual void SetPos(int x
, int y
) {m_PosX
= x
, m_PosY
= y
;}
63 void SetLink(const wxHtmlLinkInfo
& link
);
64 void SetNext(wxHtmlCell
*cell
) {m_Next
= cell
;}
65 // members writin methods
67 virtual void Layout(int w
) {SetPos(0, 0); if (m_Next
) m_Next
-> Layout(w
);};
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
73 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
);}
76 virtual void DrawInvisible(wxDC
& dc
, int x
, int y
) {if (m_Next
) m_Next
-> DrawInvisible(dc
, x
, y
);};
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
80 virtual const wxHtmlCell
* Find(int condition
, const void* param
) const {if (m_Next
) return m_Next
-> Find(condition
, param
); else return NULL
;}
81 // This method returns pointer to the FIRST cell for that
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
89 // Example : m_Cell -> Find(wxHTML_COND_ISANCHOR, "news");
90 // returns pointer to anchor news
92 virtual void OnMouseClick(wxWindow
*parent
, int x
, int y
, bool left
, bool middle
, bool right
);
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
96 // Parent is pointer to wxHtmlWindow that generated the event
97 // HINT: if this handling is not enough for you you should use
100 virtual bool AdjustPagebreak(int *pagebreak
);
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
107 // Returned value : true if pagebreak was modified, false otherwise
108 // Usage : while (container->AdjustPagebreak(&p)) {}
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
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..
124 // position where the fragment is drawn
125 wxHtmlLinkInfo
*m_Link
;
126 // destination address if this fragment is hypertext link, "" otherwise
127 bool m_CanLiveOnPagebreak
;
128 // true if this cell can be placed on pagebreak, false otherwise
135 //--------------------------------------------------------------------------------
137 //--------------------------------------------------------------------------------
140 //--------------------------------------------------------------------------------
142 // Single word in input stream.
143 //--------------------------------------------------------------------------------
145 class WXDLLEXPORT wxHtmlWordCell
: public wxHtmlCell
151 wxHtmlWordCell(const wxString
& word
, wxDC
& dc
);
152 void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
);
159 //--------------------------------------------------------------------------------
160 // wxHtmlContainerCell
161 // Container - it contains other cells. Basic of layout algorithm.
162 //--------------------------------------------------------------------------------
164 class WXDLLEXPORT wxHtmlContainerCell
: public wxHtmlCell
167 int m_IndentLeft
, m_IndentRight
, m_IndentTop
, m_IndentBottom
;
168 // indentation of subcells. There is always m_Indent pixels
169 // big space between given border of the container and the subcells
170 // it m_Indent < 0 it is in PERCENTS, otherwise it is in pixels
171 int m_MinHeight
, m_MinHeightAlign
;
174 // maximal widht of line. Filled during Layout()
175 wxHtmlCell
*m_Cells
, *m_LastCell
;
176 // internal cells, m_Cells points to the first of them, m_LastCell to the last one.
177 // (LastCell is needed only to speed-up InsertCell)
178 int m_AlignHor
, m_AlignVer
;
179 // alignment horizontal and vertical (left, center, right)
180 int m_WidthFloat
, m_WidthFloatUnits
;
181 // width float is used in adjustWidth
184 // background color of this container
186 wxColour m_BorderColour1
, m_BorderColour2
;
187 // borders color of this container
190 wxHtmlContainerCell(wxHtmlContainerCell
*parent
);
191 ~wxHtmlContainerCell() {if (m_Cells
) delete m_Cells
;}
193 virtual void Layout(int w
);
194 virtual void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
);
195 virtual void DrawInvisible(wxDC
& dc
, int x
, int y
);
196 virtual bool AdjustPagebreak(int *pagebreak
);
198 void InsertCell(wxHtmlCell
*cell
);
199 // insert cell at the end of m_Cells list
200 void SetAlignHor(int al
) {m_AlignHor
= al
;}
201 int GetAlignHor() const {return m_AlignHor
;}
202 void SetAlignVer(int al
) {m_AlignVer
= al
;}
203 // sets horizontal/vertical alignment
204 int GetAlignVer() const {return m_AlignVer
;}
205 void SetIndent(int i
, int what
, int units
= wxHTML_UNITS_PIXELS
);
206 // sets left-border indentation. units is one of wxHTML_UNITS_* constants
207 // what is combination of wxHTML_INDENT_*
208 int GetIndent(int ind
) const;
209 // returns the indentation. ind is one of wxHTML_INDENT_* constants
210 int GetIndentUnits(int ind
) const;
211 // returns type of value returned by GetIndent(ind)
212 void SetAlign(const wxHtmlTag
& tag
);
213 // sets alignment info based on given tag's params
214 void SetWidthFloat(int w
, int units
) {m_WidthFloat
= w
; m_WidthFloatUnits
= units
;}
215 void SetWidthFloat(const wxHtmlTag
& tag
, double pixel_scale
= 1.0);
216 // sets floating width adjustment
217 // (examples : 32 percent of parent container,
218 // -15 pixels percent (this means 100 % - 15 pixels)
219 void SetMinHeight(int h
, int align
= wxHTML_ALIGN_TOP
) {m_MinHeight
= h
; m_MinHeightAlign
= align
;}
220 // sets minimal height of this container.
221 int GetMaxLineWidth() const {return m_MaxLineWidth
;}
222 // returns maximal line width in this container.
223 // Call to this method is valid only after calling
225 void SetBackgroundColour(const wxColour
& clr
) {m_UseBkColour
= TRUE
; m_BkColour
= clr
;}
226 void SetBorder(const wxColour
& clr1
, const wxColour
& clr2
) {m_UseBorder
= TRUE
; m_BorderColour1
= clr1
, m_BorderColour2
= clr2
;}
227 virtual wxHtmlLinkInfo
* GetLink(int x
= 0, int y
= 0) const;
228 virtual const wxHtmlCell
* Find(int condition
, const void* param
) const;
229 virtual void OnMouseClick(wxWindow
*parent
, int x
, int y
, bool left
, bool middle
, bool right
);
231 wxHtmlCell
* GetFirstCell() {return m_Cells
;}
232 // returns pointer to the first cell in container or NULL
239 //--------------------------------------------------------------------------------
242 //--------------------------------------------------------------------------------
244 class WXDLLEXPORT wxHtmlColourCell
: public wxHtmlCell
250 wxHtmlColourCell(const wxColour
& clr
, int flags
= wxHTML_CLR_FOREGROUND
) : wxHtmlCell() {m_Colour
= clr
; m_Flags
= flags
;}
251 virtual void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
);
252 virtual void DrawInvisible(wxDC
& dc
, int x
, int y
);
258 //--------------------------------------------------------------------------------
260 // Sets actual font used for text rendering
261 //--------------------------------------------------------------------------------
263 class WXDLLEXPORT wxHtmlFontCell
: public wxHtmlCell
268 wxHtmlFontCell(wxFont
*font
) : wxHtmlCell() { m_Font
= (*font
); }
269 virtual void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
);
270 virtual void DrawInvisible(wxDC
& dc
, int x
, int y
);
278 //--------------------------------------------------------------------------------
280 // This cell is connected with wxWindow object
281 // You can use it to insert windows into HTML page
282 // (buttons, input boxes etc.)
283 //--------------------------------------------------------------------------------
285 class WXDLLEXPORT wxHtmlWidgetCell
: public wxHtmlCell
290 // width float is used in adjustWidth (it is in percents)
293 wxHtmlWidgetCell(wxWindow
*wnd
, int w
= 0);
294 // !!! wnd must have correct parent!
295 // if w != 0 then the m_Wnd has 'floating' width - it adjust
296 // it's width according to parent container's width
297 // (w is percent of parent's width)
298 ~wxHtmlWidgetCell() {if (m_Wnd
) m_Wnd
-> Destroy(); }
299 virtual void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
);
300 virtual void DrawInvisible(wxDC
& dc
, int x
, int y
);
301 virtual void Layout(int w
);
306 //--------------------------------------------------------------------------------
308 // Internal data structure. It represents hypertext link
309 //--------------------------------------------------------------------------------
311 class WXDLLEXPORT wxHtmlLinkInfo
: public wxObject
314 wxHtmlLinkInfo() : wxObject()
315 { m_Href
= m_Target
= wxEmptyString
; }
316 wxHtmlLinkInfo(const wxString
& href
, const wxString
& target
= wxEmptyString
) : wxObject()
317 { m_Href
= href
; m_Target
= target
; }
318 wxHtmlLinkInfo(const wxHtmlLinkInfo
& l
)
319 { m_Href
= l
.m_Href
, m_Target
= l
.m_Target
; }
320 wxHtmlLinkInfo
& operator=(const wxHtmlLinkInfo
& l
)
321 { m_Href
= l
.m_Href
, m_Target
= l
.m_Target
; return *this; }
323 wxString
GetHref() const { return m_Href
; }
324 wxString
GetTarget() const { return m_Target
; }
327 wxString m_Href
, m_Target
;
335 #endif // _WX_HTMLCELL_H_