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 wxHtmlContainerCell
; 
  30 //-------------------------------------------------------------------------------- 
  32 //                  Internal data structure. It represents fragments of parsed HTML 
  33 //                  page - a word, picture, table, horizontal line and so on. 
  34 //                  It is used by wxHtmlWindow to represent HTML page in memory. 
  35 //-------------------------------------------------------------------------------- 
  38 class WXDLLEXPORT wxHtmlCell 
: public wxObject
 
  41         wxHtmlCell() : wxObject() {m_Next 
= NULL
; m_Parent 
= NULL
; m_Width 
= m_Height 
= m_Descent 
= 0; m_CanLiveOnPagebreak 
= TRUE
;} 
  42         virtual ~wxHtmlCell() {if (m_Next
) delete m_Next
;}; 
  44         void SetParent(wxHtmlContainerCell 
*p
) {m_Parent 
= p
;} 
  45         wxHtmlContainerCell 
*GetParent() const {return m_Parent
;} 
  47         int GetPosX() const {return m_PosX
;} 
  48         int GetPosY() const {return m_PosY
;} 
  49         int GetWidth() const {return m_Width
;} 
  50         int GetHeight() const {return m_Height
;} 
  51         int GetDescent() const {return m_Descent
;} 
  52         virtual wxString 
GetLink(int WXUNUSED(x
) = 0, 
  53                                  int WXUNUSED(y
) = 0) const 
  55                 // returns the link associated with this cell. The position is position within 
  56                 // the cell so it varies from 0 to m_Width, from 0 to m_Height 
  57         wxHtmlCell 
*GetNext() const {return m_Next
;} 
  58                 // members access methods 
  60         virtual void SetPos(int x
, int y
) {m_PosX 
= x
, m_PosY 
= y
;} 
  61         void SetLink(const wxString
& link
) {m_Link 
= link
;} 
  62         void SetNext(wxHtmlCell 
*cell
) {m_Next 
= cell
;} 
  63                 // members writin methods 
  65         virtual void Layout(int w
) {SetPos(0, 0); if (m_Next
) m_Next 
-> Layout(w
);}; 
  66                 // 1. adjust cell's width according to the fact that maximal possible width is w. 
  67                 //    (this has sense when working with horizontal lines, tables etc.) 
  68                 // 2. prepare layout (=fill-in m_PosX, m_PosY (and sometime m_Height) members) 
  69                 //    = place items to fit window, according to the width w 
  71         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
);} 
  74         virtual void DrawInvisible(wxDC
& dc
, int x
, int y
) {if (m_Next
) m_Next 
-> DrawInvisible(dc
, x
, y
);}; 
  75                 // proceed drawing actions in case the cell is not visible (scrolled out of screen). 
  76                 // This is needed to change fonts, colors and so on 
  78         virtual const wxHtmlCell
* Find(int condition
, const void* param
) const {if (m_Next
) return m_Next 
-> Find(condition
, param
); else return NULL
;} 
  79                 // This method returns pointer to the FIRST cell for that 
  81                 // is true. It first checks if the condition is true for this 
  82                 // cell and then calls m_Next -> Find(). (Note: it checks 
  83                 // all subcells if the cell is container) 
  84                 // Condition is unique condition identifier (see htmldefs.h) 
  85                 // (user-defined condition IDs should start from 10000) 
  86                 // and param is optional parameter 
  87                 // Example : m_Cell -> Find(wxHTML_COND_ISANCHOR, "news"); 
  88                 //   returns pointer to anchor news 
  90         virtual void OnMouseClick(wxWindow 
*parent
, int x
, int y
, bool left
, bool middle
, bool right
); 
  91                 // This function is called when mouse button is clicked over the cell. 
  92                 // left, middle, right are flags indicating whether the button was or wasn't 
  94                 // Parent is pointer to wxHtmlWindow that generated the event 
  95                 // HINT: if this handling is not enough for you you should use 
  98         virtual bool AdjustPagebreak(int *pagebreak
); 
  99                 // This method used to adjust pagebreak position. The parameter is 
 100                 // variable that contains y-coordinate of page break (= horizontal line that 
 101                 // should not be crossed by words, images etc.). If this cell cannot be divided 
 102                 // into two pieces (each one on another page) then it moves the pagebreak 
 105                 // Returned value : true if pagebreak was modified, false otherwise 
 106                 // Usage : while (container->AdjustPagebreak(&p)) {} 
 108         void SetCanLiveOnPagebreak(bool can
) {m_CanLiveOnPagebreak 
= can
;} 
 109                 // Sets cell's behaviour on pagebreaks (see AdjustPagebreak). Default 
 110                 // is true - the cell can be split on two pages 
 115                 // pointer to the next cell 
 116         wxHtmlContainerCell 
*m_Parent
; 
 117             // pointer to parent cell 
 118         long m_Width
, m_Height
, m_Descent
; 
 119                 // dimensions of fragment 
 120                 // m_Descent is used to position text&images.. 
 122                 // position where the fragment is drawn 
 124                 // destination address if this fragment is hypertext link, "" otherwise 
 125         bool m_CanLiveOnPagebreak
; 
 126                 // true if this cell can be placed on pagebreak, false otherwise 
 133 //-------------------------------------------------------------------------------- 
 135 //-------------------------------------------------------------------------------- 
 138 //-------------------------------------------------------------------------------- 
 140 //                  Single word in input stream. 
 141 //-------------------------------------------------------------------------------- 
 143 class WXDLLEXPORT wxHtmlWordCell 
: public wxHtmlCell
 
 149         wxHtmlWordCell(const wxString
& word
, wxDC
& dc
); 
 150         void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
); 
 157 //-------------------------------------------------------------------------------- 
 158 // wxHtmlContainerCell 
 159 //                  Container - it contains other cells. Basic of layout algorithm. 
 160 //-------------------------------------------------------------------------------- 
 162 class WXDLLEXPORT wxHtmlContainerCell 
: public wxHtmlCell
 
 165         int m_IndentLeft
, m_IndentRight
, m_IndentTop
, m_IndentBottom
; 
 166                 // indentation of subcells. There is always m_Indent pixels 
 167                 // big space between given border of the container and the subcells 
 168                 // it m_Indent < 0 it is in PERCENTS, otherwise it is in pixels 
 169         int m_MinHeight
, m_MinHeightAlign
; 
 172             // maximal widht of line. Filled during Layout() 
 173         wxHtmlCell 
*m_Cells
, *m_LastCell
; 
 174                 // internal cells, m_Cells points to the first of them, m_LastCell to the last one. 
 175                 // (LastCell is needed only to speed-up InsertCell) 
 176         int m_AlignHor
, m_AlignVer
; 
 177                 // alignment horizontal and vertical (left, center, right) 
 178         int m_WidthFloat
, m_WidthFloatUnits
; 
 179                 // width float is used in adjustWidth 
 182                 // background color of this container 
 184         wxColour m_BorderColour1
, m_BorderColour2
; 
 185                 // borders color of this container 
 188         wxHtmlContainerCell(wxHtmlContainerCell 
*parent
); 
 189         ~wxHtmlContainerCell() {if (m_Cells
) delete m_Cells
;} 
 191         virtual void Layout(int w
); 
 192         virtual void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
); 
 193         virtual void DrawInvisible(wxDC
& dc
, int x
, int y
); 
 194         virtual bool AdjustPagebreak(int *pagebreak
); 
 196         void InsertCell(wxHtmlCell 
*cell
); 
 197                 // insert cell at the end of m_Cells list 
 198         void SetAlignHor(int al
) {m_AlignHor 
= al
;} 
 199         int GetAlignHor() const {return m_AlignHor
;} 
 200         void SetAlignVer(int al
) {m_AlignVer 
= al
;} 
 201                 // sets horizontal/vertical alignment 
 202         int GetAlignVer() const {return m_AlignVer
;} 
 203         void SetIndent(int i
, int what
, int units 
= wxHTML_UNITS_PIXELS
); 
 204                 // sets left-border indentation. units is one of wxHTML_UNITS_* constants 
 205                 // what is combination of wxHTML_INDENT_* 
 206         int GetIndent(int ind
) const; 
 207                 // returns the indentation. ind is one of wxHTML_INDENT_* constants 
 208         int GetIndentUnits(int ind
) const; 
 209                 // returns type of value returned by GetIndent(ind) 
 210         void SetAlign(const wxHtmlTag
& tag
); 
 211                 // sets alignment info based on given tag's params 
 212         void SetWidthFloat(int w
, int units
) {m_WidthFloat 
= w
; m_WidthFloatUnits 
= units
;} 
 213         void SetWidthFloat(const wxHtmlTag
& tag
, double pixel_scale 
= 1.0); 
 214                 // sets floating width adjustment 
 215                 // (examples : 32 percent of parent container, 
 216                 // -15 pixels percent (this means 100 % - 15 pixels) 
 217         void SetMinHeight(int h
, int align 
= wxHTML_ALIGN_TOP
) {m_MinHeight 
= h
; m_MinHeightAlign 
= align
;} 
 218                 // sets minimal height of this container. 
 219         int GetMaxLineWidth() const {return m_MaxLineWidth
;} 
 220             // returns maximal line width in this container. 
 221             // Call to this method is valid only after calling 
 223         void SetBackgroundColour(const wxColour
& clr
) {m_UseBkColour 
= TRUE
; m_BkColour 
= clr
;} 
 224         void SetBorder(const wxColour
& clr1
, const wxColour
& clr2
) {m_UseBorder 
= TRUE
; m_BorderColour1 
= clr1
, m_BorderColour2 
= clr2
;} 
 225         virtual wxString 
GetLink(int x 
= 0, int y 
= 0) const; 
 226         virtual const wxHtmlCell
* Find(int condition
, const void* param
) const; 
 227         virtual void OnMouseClick(wxWindow 
*parent
, int x
, int y
, bool left
, bool middle
, bool right
); 
 229         wxHtmlCell
* GetFirstCell() {return m_Cells
;} 
 230                 // returns pointer to the first cell in container or NULL 
 237 //-------------------------------------------------------------------------------- 
 240 //-------------------------------------------------------------------------------- 
 242 class WXDLLEXPORT wxHtmlColourCell 
: public wxHtmlCell
 
 248         wxHtmlColourCell(wxColour clr
, int flags 
= wxHTML_CLR_FOREGROUND
) : wxHtmlCell() {m_Colour 
= clr
; m_Flags 
= flags
;} 
 249         virtual void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
); 
 250         virtual void DrawInvisible(wxDC
& dc
, int x
, int y
); 
 256 //-------------------------------------------------------------------------------- 
 258 //                  Sets actual font used for text rendering 
 259 //-------------------------------------------------------------------------------- 
 261 class WXDLLEXPORT wxHtmlFontCell 
: public wxHtmlCell
 
 266         wxHtmlFontCell(wxFont 
*font
) : wxHtmlCell() { m_Font 
= (*font
); } 
 267         virtual void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
); 
 268         virtual void DrawInvisible(wxDC
& dc
, int x
, int y
); 
 276 //-------------------------------------------------------------------------------- 
 278 //                  This cell is connected with wxWindow object 
 279 //                  You can use it to insert windows into HTML page 
 280 //                  (buttons, input boxes etc.) 
 281 //-------------------------------------------------------------------------------- 
 283 class WXDLLEXPORT wxHtmlWidgetCell 
: public wxHtmlCell
 
 288                 // width float is used in adjustWidth (it is in percents) 
 291         wxHtmlWidgetCell(wxWindow 
*wnd
, int w 
= 0); 
 292                 // !!! wnd must have correct parent! 
 293                 // if w != 0 then the m_Wnd has 'floating' width - it adjust 
 294                 // it's width according to parent container's width 
 295                 // (w is percent of parent's width) 
 296         ~wxHtmlWidgetCell() {if (m_Wnd
) m_Wnd 
-> Destroy(); } 
 297         virtual void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
); 
 298         virtual void DrawInvisible(wxDC
& dc
, int x
, int y
); 
 299         virtual void Layout(int w
); 
 306 #endif // _WX_HTMLCELL_H_