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;}; 
  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(HTML_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 
 101                 // pointer to the next cell 
 102         wxHtmlContainerCell 
*m_Parent
; 
 103             // pointer to parent cell 
 104         long m_Width
, m_Height
, m_Descent
; 
 105                 // dimensions of fragment 
 106                 // m_Descent is used to position text&images.. 
 108                 // position where the fragment is drawn 
 110                 // destination address if this fragment is hypertext link, "" otherwise 
 117 //-------------------------------------------------------------------------------- 
 119 //-------------------------------------------------------------------------------- 
 122 //-------------------------------------------------------------------------------- 
 124 //                  Single word in input stream. 
 125 //-------------------------------------------------------------------------------- 
 127 class WXDLLEXPORT wxHtmlWordCell 
: public wxHtmlCell
 
 133         wxHtmlWordCell(const wxString
& word
, wxDC
& dc
); 
 134         void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
); 
 141 //-------------------------------------------------------------------------------- 
 142 // wxHtmlContainerCell 
 143 //                  Container - it contains other cells. Basic of layout algorithm. 
 144 //-------------------------------------------------------------------------------- 
 146 class WXDLLEXPORT wxHtmlContainerCell 
: public wxHtmlCell
 
 149         int m_IndentLeft
, m_IndentRight
, m_IndentTop
, m_IndentBottom
; 
 150                 // indentation of subcells. There is always m_Indent pixels 
 151                 // big space between given border of the container and the subcells 
 152                 // it m_Indent < 0 it is in PERCENTS, otherwise it is in pixels 
 153         int m_MinHeight
, m_MinHeightAlign
; 
 156             // maximal widht of line. Filled during Layout() 
 157         wxHtmlCell 
*m_Cells
, *m_LastCell
; 
 158                 // internal cells, m_Cells points to the first of them, m_LastCell to the last one. 
 159                 // (LastCell is needed only to speed-up InsertCell) 
 160         int m_AlignHor
, m_AlignVer
; 
 161                 // alignment horizontal and vertical (left, center, right) 
 162         int m_WidthFloat
, m_WidthFloatUnits
; 
 163                 // width float is used in adjustWidth 
 166                 // background color of this container 
 168         wxColour m_BorderColour1
, m_BorderColour2
; 
 169                 // borders color of this container 
 172         wxHtmlContainerCell(wxHtmlContainerCell 
*parent
); 
 173         ~wxHtmlContainerCell() {if (m_Cells
) delete m_Cells
;} 
 175         virtual void Layout(int w
); 
 176         virtual void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
); 
 177         virtual void DrawInvisible(wxDC
& dc
, int x
, int y
); 
 179         void InsertCell(wxHtmlCell 
*cell
); 
 180                 // insert cell at the end of m_Cells list 
 181         void SetAlignHor(int al
) {m_AlignHor 
= al
;} 
 182         int GetAlignHor() const {return m_AlignHor
;} 
 183         void SetAlignVer(int al
) {m_AlignVer 
= al
;} 
 184                 // sets horizontal/vertical alignment 
 185         int GetAlignVer() const {return m_AlignVer
;} 
 186         void SetIndent(int i
, int what
, int units 
= HTML_UNITS_PIXELS
); 
 187                 // sets left-border indentation. units is one of HTML_UNITS_* constants 
 188                 // what is combination of HTML_INDENT_* 
 189         int GetIndent(int ind
) const; 
 190                 // returns the indentation. ind is one of HTML_INDENT_* constants 
 191         int GetIndentUnits(int ind
) const; 
 192                 // returns type of value returned by GetIndent(ind) 
 193         void SetAlign(const wxHtmlTag
& tag
); 
 194                 // sets alignment info based on given tag's params 
 195         void SetWidthFloat(int w
, int units
) {m_WidthFloat 
= w
; m_WidthFloatUnits 
= units
;} 
 196         void SetWidthFloat(const wxHtmlTag
& tag
); 
 197                 // sets floating width adjustment 
 198                 // (examples : 32 percent of parent container, 
 199                 // -15 pixels percent (this means 100 % - 15 pixels) 
 200         void SetMinHeight(int h
, int align 
= HTML_ALIGN_TOP
) {m_MinHeight 
= h
; m_MinHeightAlign 
= align
;} 
 201                 // sets minimal height of this container. 
 202         int GetMaxLineWidth() const {return m_MaxLineWidth
;} 
 203             // returns maximal line width in this container. 
 204             // Call to this method is valid only after calling 
 206         void SetBackgroundColour(const wxColour
& clr
) {m_UseBkColour 
= TRUE
; m_BkColour 
= clr
;} 
 207         void SetBorder(const wxColour
& clr1
, const wxColour
& clr2
) {m_UseBorder 
= TRUE
; m_BorderColour1 
= clr1
, m_BorderColour2 
= clr2
;} 
 208         virtual wxString 
GetLink(int x 
= 0, int y 
= 0) const; 
 209         virtual const wxHtmlCell
* Find(int condition
, const void* param
) const; 
 210         virtual void OnMouseClick(wxWindow 
*parent
, int x
, int y
, bool left
, bool middle
, bool right
); 
 212         wxHtmlCell
* GetFirstCell() {return m_Cells
;} 
 213                 // returns pointer to the first cell in container or NULL 
 220 //-------------------------------------------------------------------------------- 
 223 //-------------------------------------------------------------------------------- 
 225 class WXDLLEXPORT wxHtmlColourCell 
: public wxHtmlCell
 
 231         wxHtmlColourCell(wxColour clr
, int flags 
= HTML_CLR_FOREGROUND
) : wxHtmlCell() {m_Colour 
= clr
; m_Flags 
= flags
;} 
 232         virtual void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
); 
 233         virtual void DrawInvisible(wxDC
& dc
, int x
, int y
); 
 239 //-------------------------------------------------------------------------------- 
 241 //                  Sets actual font used for text rendering 
 242 //-------------------------------------------------------------------------------- 
 244 class WXDLLEXPORT wxHtmlFontCell 
: public wxHtmlCell
 
 249         wxHtmlFontCell(wxFont 
*font
) : wxHtmlCell() {m_Font 
= font
;}; 
 250         virtual void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
); 
 251         virtual void DrawInvisible(wxDC
& dc
, int x
, int y
); 
 259 //-------------------------------------------------------------------------------- 
 261 //                  This cell is connected with wxWindow object 
 262 //                  You can use it to insert windows into HTML page 
 263 //                  (buttons, input boxes etc.) 
 264 //-------------------------------------------------------------------------------- 
 266 class WXDLLEXPORT wxHtmlWidgetCell 
: public wxHtmlCell
 
 271                 // width float is used in adjustWidth (it is in percents) 
 274         wxHtmlWidgetCell(wxWindow 
*wnd
, int w 
= 0); 
 275                 // !!! wnd must have correct parent! 
 276                 // if w != 0 then the m_Wnd has 'floating' width - it adjust 
 277                 // it's width according to parent container's width 
 278                 // (w is percent of parent's width) 
 279         ~wxHtmlWidgetCell() {if (m_Wnd
) m_Wnd 
-> Destroy(); } 
 280         virtual void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
); 
 281         virtual void DrawInvisible(wxDC
& dc
, int x
, int y
); 
 282         virtual void Layout(int w
); 
 289 #endif // _WX_HTMLCELL_H_