home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2240.zip / wxWindows-2.4.0 / include / wx / html / htmlcell.h < prev    next >
C/C++ Source or Header  |  2002-10-16  |  15KB  |  377 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name:        htmlcell.h
  3. // Purpose:     wxHtmlCell class is used by wxHtmlWindow/wxHtmlWinParser
  4. //              as a basic visual element of HTML page
  5. // Author:      Vaclav Slavik
  6. // RCS-ID:      $Id: htmlcell.h,v 1.29.2.1 2002/10/11 22:21:56 VS Exp $
  7. // Copyright:   (c) 1999 Vaclav Slavik
  8. // Licence:     wxWindows Licence
  9. /////////////////////////////////////////////////////////////////////////////
  10.  
  11.  
  12. #ifndef _WX_HTMLCELL_H_
  13. #define _WX_HTMLCELL_H_
  14.  
  15. #if defined(__GNUG__) && !defined(__APPLE__)
  16. #pragma interface "htmlcell.h"
  17. #endif
  18.  
  19. #include "wx/defs.h"
  20.  
  21. #if wxUSE_HTML
  22.  
  23. #include "wx/html/htmltag.h"
  24. #include "wx/html/htmldefs.h"
  25. #include "wx/window.h"
  26.  
  27.  
  28. class WXDLLEXPORT wxHtmlLinkInfo;
  29. class WXDLLEXPORT wxHtmlCell;
  30. class WXDLLEXPORT wxHtmlContainerCell;
  31.  
  32. //--------------------------------------------------------------------------------
  33. // wxHtmlCell
  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. //--------------------------------------------------------------------------------
  38.  
  39.  
  40. class WXDLLEXPORT wxHtmlCell : public wxObject
  41. {
  42. public:
  43.     wxHtmlCell();
  44.     virtual ~wxHtmlCell();
  45.  
  46.     void SetParent(wxHtmlContainerCell *p) {m_Parent = p;}
  47.     wxHtmlContainerCell *GetParent() const {return m_Parent;}
  48.  
  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.  
  55.     const wxString& GetId() const { return m_id; }
  56.     void SetId(const wxString& id) { m_id = id; }
  57.  
  58.     // returns the link associated with this cell. The position is position within
  59.     // the cell so it varies from 0 to m_Width, from 0 to m_Height
  60.     virtual wxHtmlLinkInfo* GetLink(int WXUNUSED(x) = 0, int WXUNUSED(y) = 0) const
  61.         { return m_Link; }
  62.  
  63.     // members access methods
  64.     wxHtmlCell *GetNext() const {return m_Next;}
  65.  
  66.     // members writing methods
  67.     virtual void SetPos(int x, int y) {m_PosX = x, m_PosY = y;}
  68.     void SetLink(const wxHtmlLinkInfo& link);
  69.     void SetNext(wxHtmlCell *cell) {m_Next = cell;}
  70.  
  71.     // 1. adjust cell's width according to the fact that maximal possible width is w.
  72.     //    (this has sense when working with horizontal lines, tables etc.)
  73.     // 2. prepare layout (=fill-in m_PosX, m_PosY (and sometime m_Height) members)
  74.     //    = place items to fit window, according to the width w
  75.     virtual void Layout(int w);
  76.  
  77.     // renders the cell
  78.     virtual void Draw(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(view_y1), int WXUNUSED(view_y2)) {}
  79.  
  80.     // proceed drawing actions in case the cell is not visible (scrolled out of screen).
  81.     // This is needed to change fonts, colors and so on
  82.     virtual void DrawInvisible(wxDC& WXUNUSED(dc), int WXUNUSED(x), int WXUNUSED(y)) {}
  83.  
  84.     // This method returns pointer to the FIRST cell for that
  85.     // the condition
  86.     // is true. It first checks if the condition is true for this
  87.     // cell and then calls m_Next->Find(). (Note: it checks
  88.     // all subcells if the cell is container)
  89.     // Condition is unique condition identifier (see htmldefs.h)
  90.     // (user-defined condition IDs should start from 10000)
  91.     // and param is optional parameter
  92.     // Example : m_Cell->Find(wxHTML_COND_ISANCHOR, "news");
  93.     //   returns pointer to anchor news
  94.     virtual const wxHtmlCell* Find(int condition, const void* param) const;
  95.  
  96.     // This function is called when mouse button is clicked over the cell.
  97.     //
  98.     // Parent is pointer to wxHtmlWindow that generated the event
  99.     // HINT: if this handling is not enough for you you should use
  100.     //       wxHtmlWidgetCell
  101.     virtual void OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event);
  102.  
  103.     // This method used to adjust pagebreak position. The parameter is
  104.     // variable that contains y-coordinate of page break (= horizontal line that
  105.     // should not be crossed by words, images etc.). If this cell cannot be divided
  106.     // into two pieces (each one on another page) then it moves the pagebreak
  107.     // few pixels up.
  108.     //
  109.     // Returned value : true if pagebreak was modified, false otherwise
  110.     // Usage : while (container->AdjustPagebreak(&p)) {}
  111.     virtual bool AdjustPagebreak(int *pagebreak) const;
  112.  
  113.     // Sets cell's behaviour on pagebreaks (see AdjustPagebreak). Default
  114.     // is true - the cell can be split on two pages
  115.     void SetCanLiveOnPagebreak(bool can) { m_CanLiveOnPagebreak = can; }
  116.  
  117.     // Returns y-coordinates that contraint the cell, i.e. left is highest
  118.     // and right lowest coordinate such that the cell lays between then.
  119.     // Note: this method does not return meaningful values if you haven't
  120.     //       called Layout() before!
  121.     virtual void GetHorizontalConstraints(int *left, int *right) const;
  122.  
  123.     // Returns true for simple == terminal cells, i.e. not composite ones.
  124.     // This if for internal usage only and may disappear in future versions!
  125.     virtual bool IsTerminalCell() const { return TRUE; }
  126.  
  127.     // Find the terminal cell inside this cell at the given position (relative
  128.     // to this cell)
  129.     //
  130.     // Returns NULL if not found
  131.     virtual wxHtmlCell *FindCellByPos(wxCoord x, wxCoord y) const;
  132.  
  133. protected:
  134.     wxHtmlCell *m_Next;
  135.             // pointer to the next cell
  136.     wxHtmlContainerCell *m_Parent;
  137.             // pointer to parent cell
  138.     long m_Width, m_Height, m_Descent;
  139.             // dimensions of fragment
  140.             // m_Descent is used to position text&images..
  141.     long m_PosX, m_PosY;
  142.             // position where the fragment is drawn
  143.     wxHtmlLinkInfo *m_Link;
  144.             // destination address if this fragment is hypertext link, NULL otherwise
  145.     bool m_CanLiveOnPagebreak;
  146.             // true if this cell can be placed on pagebreak, false otherwise
  147.     wxString m_id;
  148.             // unique identifier of the cell, generated from "id" property of tags
  149. };
  150.  
  151.  
  152.  
  153.  
  154. //--------------------------------------------------------------------------------
  155. // Inherited cells:
  156. //--------------------------------------------------------------------------------
  157.  
  158.  
  159. //--------------------------------------------------------------------------------
  160. // wxHtmlWordCell
  161. //                  Single word in input stream.
  162. //--------------------------------------------------------------------------------
  163.  
  164. class WXDLLEXPORT wxHtmlWordCell : public wxHtmlCell
  165. {
  166. public:
  167.     wxHtmlWordCell(const wxString& word, wxDC& dc);
  168.     void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
  169.  
  170. protected:
  171.     wxString m_Word;
  172. };
  173.  
  174.  
  175.  
  176.  
  177.  
  178. //--------------------------------------------------------------------------------
  179. // wxHtmlContainerCell
  180. //                  Container - it contains other cells. Basic of layout algorithm.
  181. //--------------------------------------------------------------------------------
  182.  
  183. class WXDLLEXPORT wxHtmlContainerCell : public wxHtmlCell
  184. {
  185. public:
  186.     wxHtmlContainerCell(wxHtmlContainerCell *parent);
  187.     ~wxHtmlContainerCell();
  188.  
  189.     virtual void Layout(int w);
  190.     virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
  191.     virtual void DrawInvisible(wxDC& dc, int x, int y);
  192.     virtual bool AdjustPagebreak(int *pagebreak) const;
  193.  
  194.     // insert cell at the end of m_Cells list
  195.     void InsertCell(wxHtmlCell *cell);
  196.  
  197.     // sets horizontal/vertical alignment
  198.     void SetAlignHor(int al) {m_AlignHor = al; m_LastLayout = -1;}
  199.     int GetAlignHor() const {return m_AlignHor;}
  200.     void SetAlignVer(int al) {m_AlignVer = al; m_LastLayout = -1;}
  201.     int GetAlignVer() const {return m_AlignVer;}
  202.  
  203.     // sets left-border indentation. units is one of wxHTML_UNITS_* constants
  204.     // what is combination of wxHTML_INDENT_*
  205.     void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
  206.     // returns the indentation. ind is one of wxHTML_INDENT_* constants
  207.     int GetIndent(int ind) const;
  208.     // returns type of value returned by GetIndent(ind)
  209.     int GetIndentUnits(int ind) const;
  210.  
  211.     // sets alignment info based on given tag's params
  212.     void SetAlign(const wxHtmlTag& tag);
  213.     // sets floating width adjustment
  214.     // (examples : 32 percent of parent container,
  215.     // -15 pixels percent (this means 100 % - 15 pixels)
  216.     void SetWidthFloat(int w, int units) {m_WidthFloat = w; m_WidthFloatUnits = units; m_LastLayout = -1;}
  217.     void SetWidthFloat(const wxHtmlTag& tag, double pixel_scale = 1.0);
  218.     // sets minimal height of this container.
  219.     void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP) {m_MinHeight = h; m_MinHeightAlign = align; m_LastLayout = -1;}
  220.  
  221.     void SetBackgroundColour(const wxColour& clr) {m_UseBkColour = TRUE; m_BkColour = clr;}
  222.     // returns background colour (of wxNullColour if none set), so that widgets can
  223.     // adapt to it:
  224.     wxColour GetBackgroundColour();
  225.     void SetBorder(const wxColour& clr1, const wxColour& clr2) {m_UseBorder = TRUE; m_BorderColour1 = clr1, m_BorderColour2 = clr2;}
  226.     virtual wxHtmlLinkInfo* GetLink(int x = 0, int y = 0) const;
  227.     virtual const wxHtmlCell* Find(int condition, const void* param) const;
  228.     virtual void OnMouseClick(wxWindow *parent, int x, int y, const wxMouseEvent& event);
  229.     virtual void GetHorizontalConstraints(int *left, int *right) const;
  230.  
  231.     // returns pointer to the first cell in container or NULL
  232.     wxHtmlCell* GetFirstCell() const {return m_Cells;}
  233.  
  234.     // see comment in wxHtmlCell about this method
  235.     virtual bool IsTerminalCell() const { return FALSE; }
  236.  
  237.     virtual wxHtmlCell *FindCellByPos(wxCoord x, wxCoord y) const;
  238.  
  239. protected:
  240.     int m_IndentLeft, m_IndentRight, m_IndentTop, m_IndentBottom;
  241.             // indentation of subcells. There is always m_Indent pixels
  242.             // big space between given border of the container and the subcells
  243.             // it m_Indent < 0 it is in PERCENTS, otherwise it is in pixels
  244.     int m_MinHeight, m_MinHeightAlign;
  245.         // minimal height.
  246.     wxHtmlCell *m_Cells, *m_LastCell;
  247.             // internal cells, m_Cells points to the first of them, m_LastCell to the last one.
  248.             // (LastCell is needed only to speed-up InsertCell)
  249.     int m_AlignHor, m_AlignVer;
  250.             // alignment horizontal and vertical (left, center, right)
  251.     int m_WidthFloat, m_WidthFloatUnits;
  252.             // width float is used in adjustWidth
  253.     bool m_UseBkColour;
  254.     wxColour m_BkColour;
  255.             // background color of this container
  256.     bool m_UseBorder;
  257.     wxColour m_BorderColour1, m_BorderColour2;
  258.             // borders color of this container
  259.     int m_LastLayout;
  260.             // if != -1 then call to Layout may be no-op
  261.             // if previous call to Layout has same argument
  262. };
  263.  
  264.  
  265.  
  266.  
  267.  
  268. //--------------------------------------------------------------------------------
  269. // wxHtmlColourCell
  270. //                  Color changer.
  271. //--------------------------------------------------------------------------------
  272.  
  273. class WXDLLEXPORT wxHtmlColourCell : public wxHtmlCell
  274. {
  275. public:
  276.     wxHtmlColourCell(const wxColour& clr, int flags = wxHTML_CLR_FOREGROUND) : wxHtmlCell() {m_Colour = clr; m_Flags = flags;}
  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.  
  280. protected:
  281.     wxColour m_Colour;
  282.     unsigned m_Flags;
  283. };
  284.  
  285.  
  286.  
  287.  
  288. //--------------------------------------------------------------------------------
  289. // wxHtmlFontCell
  290. //                  Sets actual font used for text rendering
  291. //--------------------------------------------------------------------------------
  292.  
  293. class WXDLLEXPORT wxHtmlFontCell : public wxHtmlCell
  294. {
  295. public:
  296.     wxHtmlFontCell(wxFont *font) : wxHtmlCell() { m_Font = (*font); }
  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.  
  300. protected:
  301.     wxFont m_Font;
  302. };
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309. //--------------------------------------------------------------------------------
  310. // wxHtmlwidgetCell
  311. //                  This cell is connected with wxWindow object
  312. //                  You can use it to insert windows into HTML page
  313. //                  (buttons, input boxes etc.)
  314. //--------------------------------------------------------------------------------
  315.  
  316. class WXDLLEXPORT wxHtmlWidgetCell : public wxHtmlCell
  317. {
  318. public:
  319.     // !!! wnd must have correct parent!
  320.     // if w != 0 then the m_Wnd has 'floating' width - it adjust
  321.     // it's width according to parent container's width
  322.     // (w is percent of parent's width)
  323.     wxHtmlWidgetCell(wxWindow *wnd, int w = 0);
  324.     ~wxHtmlWidgetCell() { m_Wnd->Destroy(); }
  325.     virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
  326.     virtual void DrawInvisible(wxDC& dc, int x, int y);
  327.     virtual void Layout(int w);
  328.  
  329. protected:
  330.     wxWindow* m_Wnd;
  331.     int m_WidthFloat;
  332.             // width float is used in adjustWidth (it is in percents)
  333. };
  334.  
  335.  
  336.  
  337. //--------------------------------------------------------------------------------
  338. // wxHtmlLinkInfo
  339. //                  Internal data structure. It represents hypertext link
  340. //--------------------------------------------------------------------------------
  341.  
  342. class WXDLLEXPORT wxHtmlLinkInfo : public wxObject
  343. {
  344. public:
  345.     wxHtmlLinkInfo() : wxObject()
  346.           { m_Href = m_Target = wxEmptyString; m_Event = NULL, m_Cell = NULL; }
  347.     wxHtmlLinkInfo(const wxString& href, const wxString& target = wxEmptyString) : wxObject()
  348.           { m_Href = href; m_Target = target; m_Event = NULL, m_Cell = NULL; }
  349.     wxHtmlLinkInfo(const wxHtmlLinkInfo& l) : wxObject()
  350.           { m_Href = l.m_Href, m_Target = l.m_Target, m_Event = l.m_Event;
  351.             m_Cell = l.m_Cell; }
  352.     wxHtmlLinkInfo& operator=(const wxHtmlLinkInfo& l)
  353.           { m_Href = l.m_Href, m_Target = l.m_Target, m_Event = l.m_Event;
  354.             m_Cell = l.m_Cell; return *this; }
  355.  
  356.     void SetEvent(const wxMouseEvent *e) { m_Event = e; }
  357.     void SetHtmlCell(const wxHtmlCell *e) { m_Cell = e; }
  358.  
  359.     wxString GetHref() const { return m_Href; }
  360.     wxString GetTarget() const { return m_Target; }
  361.     const wxMouseEvent* GetEvent() const { return m_Event; }
  362.     const wxHtmlCell* GetHtmlCell() const { return m_Cell; }
  363.  
  364. private:
  365.     wxString m_Href, m_Target;
  366.     const wxMouseEvent *m_Event;
  367.     const wxHtmlCell *m_Cell;
  368. };
  369.  
  370.  
  371.  
  372.  
  373. #endif // wxUSE_HTML
  374.  
  375. #endif // _WX_HTMLCELL_H_
  376.  
  377.