htmlcell.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/html/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. // Copyright: (c) 1999-2003 Vaclav Slavik
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_HTMLCELL_H_
  10. #define _WX_HTMLCELL_H_
  11. #include "wx/defs.h"
  12. #if wxUSE_HTML
  13. #include "wx/html/htmltag.h"
  14. #include "wx/html/htmldefs.h"
  15. #include "wx/window.h"
  16. class WXDLLIMPEXP_FWD_HTML wxHtmlWindowInterface;
  17. class WXDLLIMPEXP_FWD_HTML wxHtmlLinkInfo;
  18. class WXDLLIMPEXP_FWD_HTML wxHtmlCell;
  19. class WXDLLIMPEXP_FWD_HTML wxHtmlContainerCell;
  20. // wxHtmlSelection is data holder with information about text selection.
  21. // Selection is defined by two positions (beginning and end of the selection)
  22. // and two leaf(!) cells at these positions.
  23. class WXDLLIMPEXP_HTML wxHtmlSelection
  24. {
  25. public:
  26. wxHtmlSelection()
  27. : m_fromPos(wxDefaultPosition), m_toPos(wxDefaultPosition),
  28. m_fromCharacterPos(-1), m_toCharacterPos(-1),
  29. m_fromCell(NULL), m_toCell(NULL) {}
  30. // this version is used for the user selection defined with the mouse
  31. void Set(const wxPoint& fromPos, const wxHtmlCell *fromCell,
  32. const wxPoint& toPos, const wxHtmlCell *toCell);
  33. void Set(const wxHtmlCell *fromCell, const wxHtmlCell *toCell);
  34. const wxHtmlCell *GetFromCell() const { return m_fromCell; }
  35. const wxHtmlCell *GetToCell() const { return m_toCell; }
  36. // these values are in absolute coordinates:
  37. const wxPoint& GetFromPos() const { return m_fromPos; }
  38. const wxPoint& GetToPos() const { return m_toPos; }
  39. // these are From/ToCell's private data
  40. void ClearFromToCharacterPos() { m_toCharacterPos = m_fromCharacterPos = -1; }
  41. bool AreFromToCharacterPosSet() const { return m_toCharacterPos != -1 && m_fromCharacterPos != -1; }
  42. void SetFromCharacterPos (wxCoord pos) { m_fromCharacterPos = pos; }
  43. void SetToCharacterPos (wxCoord pos) { m_toCharacterPos = pos; }
  44. wxCoord GetFromCharacterPos () const { return m_fromCharacterPos; }
  45. wxCoord GetToCharacterPos () const { return m_toCharacterPos; }
  46. bool IsEmpty() const
  47. { return m_fromPos == wxDefaultPosition &&
  48. m_toPos == wxDefaultPosition; }
  49. private:
  50. wxPoint m_fromPos, m_toPos;
  51. wxCoord m_fromCharacterPos, m_toCharacterPos;
  52. const wxHtmlCell *m_fromCell, *m_toCell;
  53. };
  54. enum wxHtmlSelectionState
  55. {
  56. wxHTML_SEL_OUT, // currently rendered cell is outside the selection
  57. wxHTML_SEL_IN, // ... is inside selection
  58. wxHTML_SEL_CHANGING // ... is the cell on which selection state changes
  59. };
  60. // Selection state is passed to wxHtmlCell::Draw so that it can render itself
  61. // differently e.g. when inside text selection or outside it.
  62. class WXDLLIMPEXP_HTML wxHtmlRenderingState
  63. {
  64. public:
  65. wxHtmlRenderingState() : m_selState(wxHTML_SEL_OUT) {}
  66. void SetSelectionState(wxHtmlSelectionState s) { m_selState = s; }
  67. wxHtmlSelectionState GetSelectionState() const { return m_selState; }
  68. void SetFgColour(const wxColour& c) { m_fgColour = c; }
  69. const wxColour& GetFgColour() const { return m_fgColour; }
  70. void SetBgColour(const wxColour& c) { m_bgColour = c; }
  71. const wxColour& GetBgColour() const { return m_bgColour; }
  72. void SetBgMode(int m) { m_bgMode = m; }
  73. int GetBgMode() const { return m_bgMode; }
  74. private:
  75. wxHtmlSelectionState m_selState;
  76. wxColour m_fgColour, m_bgColour;
  77. int m_bgMode;
  78. };
  79. // HTML rendering customization. This class is used when rendering wxHtmlCells
  80. // as a callback:
  81. class WXDLLIMPEXP_HTML wxHtmlRenderingStyle
  82. {
  83. public:
  84. virtual ~wxHtmlRenderingStyle() {}
  85. virtual wxColour GetSelectedTextColour(const wxColour& clr) = 0;
  86. virtual wxColour GetSelectedTextBgColour(const wxColour& clr) = 0;
  87. };
  88. // Standard style:
  89. class WXDLLIMPEXP_HTML wxDefaultHtmlRenderingStyle : public wxHtmlRenderingStyle
  90. {
  91. public:
  92. virtual wxColour GetSelectedTextColour(const wxColour& clr);
  93. virtual wxColour GetSelectedTextBgColour(const wxColour& clr);
  94. };
  95. // Information given to cells when drawing them. Contains rendering state,
  96. // selection information and rendering style object that can be used to
  97. // customize the output.
  98. class WXDLLIMPEXP_HTML wxHtmlRenderingInfo
  99. {
  100. public:
  101. wxHtmlRenderingInfo() : m_selection(NULL), m_style(NULL) {}
  102. void SetSelection(wxHtmlSelection *s) { m_selection = s; }
  103. wxHtmlSelection *GetSelection() const { return m_selection; }
  104. void SetStyle(wxHtmlRenderingStyle *style) { m_style = style; }
  105. wxHtmlRenderingStyle& GetStyle() { return *m_style; }
  106. wxHtmlRenderingState& GetState() { return m_state; }
  107. protected:
  108. wxHtmlSelection *m_selection;
  109. wxHtmlRenderingStyle *m_style;
  110. wxHtmlRenderingState m_state;
  111. };
  112. // Flags for wxHtmlCell::FindCellByPos
  113. enum
  114. {
  115. wxHTML_FIND_EXACT = 1,
  116. wxHTML_FIND_NEAREST_BEFORE = 2,
  117. wxHTML_FIND_NEAREST_AFTER = 4
  118. };
  119. // Superscript/subscript/normal script mode of a cell
  120. enum wxHtmlScriptMode
  121. {
  122. wxHTML_SCRIPT_NORMAL,
  123. wxHTML_SCRIPT_SUB,
  124. wxHTML_SCRIPT_SUP
  125. };
  126. // ---------------------------------------------------------------------------
  127. // wxHtmlCell
  128. // Internal data structure. It represents fragments of parsed
  129. // HTML page - a word, picture, table, horizontal line and so
  130. // on. It is used by wxHtmlWindow to represent HTML page in
  131. // memory.
  132. // ---------------------------------------------------------------------------
  133. class WXDLLIMPEXP_HTML wxHtmlCell : public wxObject
  134. {
  135. public:
  136. wxHtmlCell();
  137. virtual ~wxHtmlCell();
  138. void SetParent(wxHtmlContainerCell *p) {m_Parent = p;}
  139. wxHtmlContainerCell *GetParent() const {return m_Parent;}
  140. int GetPosX() const {return m_PosX;}
  141. int GetPosY() const {return m_PosY;}
  142. int GetWidth() const {return m_Width;}
  143. // Returns the maximum possible length of the cell.
  144. // Call Layout at least once before using GetMaxTotalWidth()
  145. virtual int GetMaxTotalWidth() const { return m_Width; }
  146. int GetHeight() const {return m_Height;}
  147. int GetDescent() const {return m_Descent;}
  148. void SetScriptMode(wxHtmlScriptMode mode, long previousBase);
  149. wxHtmlScriptMode GetScriptMode() const { return m_ScriptMode; }
  150. long GetScriptBaseline() { return m_ScriptBaseline; }
  151. // Formatting cells are not visible on the screen, they only alter
  152. // renderer's state.
  153. bool IsFormattingCell() const { return m_Width == 0 && m_Height == 0; }
  154. const wxString& GetId() const { return m_id; }
  155. void SetId(const wxString& id) { m_id = id; }
  156. // returns the link associated with this cell. The position is position
  157. // within the cell so it varies from 0 to m_Width, from 0 to m_Height
  158. virtual wxHtmlLinkInfo* GetLink(int WXUNUSED(x) = 0,
  159. int WXUNUSED(y) = 0) const
  160. { return m_Link; }
  161. // Returns cursor to be used when mouse is over the cell, can be
  162. // overridden by the derived classes to use a different cursor whenever the
  163. // mouse is over this cell.
  164. virtual wxCursor GetMouseCursor(wxHtmlWindowInterface *window) const;
  165. // Returns cursor to be used when mouse is over the given point, can be
  166. // overridden if the cursor should change depending on where exactly inside
  167. // the cell the mouse is.
  168. virtual wxCursor GetMouseCursorAt(wxHtmlWindowInterface *window,
  169. const wxPoint& relPos) const;
  170. #if WXWIN_COMPATIBILITY_2_6
  171. // this was replaced by GetMouseCursor, don't use in new code!
  172. virtual wxCursor GetCursor() const;
  173. #endif
  174. // return next cell among parent's cells
  175. wxHtmlCell *GetNext() const {return m_Next;}
  176. // returns first child cell (if there are any, i.e. if this is container):
  177. virtual wxHtmlCell* GetFirstChild() const { return NULL; }
  178. // members writing methods
  179. virtual void SetPos(int x, int y) {m_PosX = x, m_PosY = y;}
  180. void SetLink(const wxHtmlLinkInfo& link);
  181. void SetNext(wxHtmlCell *cell) {m_Next = cell;}
  182. // 1. adjust cell's width according to the fact that maximal possible width
  183. // is w. (this has sense when working with horizontal lines, tables
  184. // etc.)
  185. // 2. prepare layout (=fill-in m_PosX, m_PosY (and sometime m_Height)
  186. // members) = place items to fit window, according to the width w
  187. virtual void Layout(int w);
  188. // renders the cell
  189. virtual void Draw(wxDC& WXUNUSED(dc),
  190. int WXUNUSED(x), int WXUNUSED(y),
  191. int WXUNUSED(view_y1), int WXUNUSED(view_y2),
  192. wxHtmlRenderingInfo& WXUNUSED(info)) {}
  193. // proceed drawing actions in case the cell is not visible (scrolled out of
  194. // screen). This is needed to change fonts, colors and so on.
  195. virtual void DrawInvisible(wxDC& WXUNUSED(dc),
  196. int WXUNUSED(x), int WXUNUSED(y),
  197. wxHtmlRenderingInfo& WXUNUSED(info)) {}
  198. // This method returns pointer to the FIRST cell for that
  199. // the condition
  200. // is true. It first checks if the condition is true for this
  201. // cell and then calls m_Next->Find(). (Note: it checks
  202. // all subcells if the cell is container)
  203. // Condition is unique condition identifier (see htmldefs.h)
  204. // (user-defined condition IDs should start from 10000)
  205. // and param is optional parameter
  206. // Example : m_Cell->Find(wxHTML_COND_ISANCHOR, "news");
  207. // returns pointer to anchor news
  208. virtual const wxHtmlCell* Find(int condition, const void* param) const;
  209. // This function is called when mouse button is clicked over the cell.
  210. // Returns true if a link is clicked, false otherwise.
  211. //
  212. // 'window' is pointer to wxHtmlWindowInterface of the window which
  213. // generated the event.
  214. // HINT: if this handling is not enough for you you should use
  215. // wxHtmlWidgetCell
  216. virtual bool ProcessMouseClick(wxHtmlWindowInterface *window,
  217. const wxPoint& pos,
  218. const wxMouseEvent& event);
  219. #if WXWIN_COMPATIBILITY_2_6
  220. // this was replaced by ProcessMouseClick, don't use in new code!
  221. virtual void OnMouseClick(wxWindow *window,
  222. int x, int y, const wxMouseEvent& event);
  223. #endif
  224. // This method used to adjust pagebreak position. The parameter is variable
  225. // that contains y-coordinate of page break (= horizontal line that should
  226. // not be crossed by words, images etc.). If this cell cannot be divided
  227. // into two pieces (each one on another page) then it moves the pagebreak
  228. // few pixels up.
  229. //
  230. // Returned value : true if pagebreak was modified, false otherwise
  231. // Usage : while (container->AdjustPagebreak(&p)) {}
  232. virtual bool AdjustPagebreak(int *pagebreak,
  233. const wxArrayInt& known_pagebreaks,
  234. int pageHeight) const;
  235. // Sets cell's behaviour on pagebreaks (see AdjustPagebreak). Default
  236. // is true - the cell can be split on two pages
  237. // If there is no way to fit a cell in the current page size, the cell
  238. // is always split, ignoring this setting.
  239. void SetCanLiveOnPagebreak(bool can) { m_CanLiveOnPagebreak = can; }
  240. // Can the line be broken before this cell?
  241. virtual bool IsLinebreakAllowed() const
  242. { return !IsFormattingCell(); }
  243. // Returns true for simple == terminal cells, i.e. not composite ones.
  244. // This if for internal usage only and may disappear in future versions!
  245. virtual bool IsTerminalCell() const { return true; }
  246. // Find a cell inside this cell positioned at the given coordinates
  247. // (relative to this's positions). Returns NULL if no such cell exists.
  248. // The flag can be used to specify whether to look for terminal or
  249. // nonterminal cells or both. In either case, returned cell is deepest
  250. // cell in cells tree that contains [x,y].
  251. virtual wxHtmlCell *FindCellByPos(wxCoord x, wxCoord y,
  252. unsigned flags = wxHTML_FIND_EXACT) const;
  253. // Returns absolute position of the cell on HTML canvas.
  254. // If rootCell is provided, then it's considered to be the root of the
  255. // hierarchy and the returned value is relative to it.
  256. wxPoint GetAbsPos(wxHtmlCell *rootCell = NULL) const;
  257. // Returns root cell of the hierarchy (i.e. grand-grand-...-parent that
  258. // doesn't have a parent itself)
  259. wxHtmlCell *GetRootCell() const;
  260. // Returns first (last) terminal cell inside this cell. It may return NULL,
  261. // but it is rare -- only if there are no terminals in the tree.
  262. virtual wxHtmlCell *GetFirstTerminal() const
  263. { return wxConstCast(this, wxHtmlCell); }
  264. virtual wxHtmlCell *GetLastTerminal() const
  265. { return wxConstCast(this, wxHtmlCell); }
  266. // Returns cell's depth, i.e. how far under the root cell it is
  267. // (if it is the root, depth is 0)
  268. unsigned GetDepth() const;
  269. // Returns true if the cell appears before 'cell' in natural order of
  270. // cells (= as they are read). If cell A is (grand)parent of cell B,
  271. // then both A.IsBefore(B) and B.IsBefore(A) always return true.
  272. bool IsBefore(wxHtmlCell *cell) const;
  273. // Converts the cell into text representation. If sel != NULL then
  274. // only part of the cell inside the selection is converted.
  275. virtual wxString ConvertToText(wxHtmlSelection *WXUNUSED(sel)) const
  276. { return wxEmptyString; }
  277. protected:
  278. // pointer to the next cell
  279. wxHtmlCell *m_Next;
  280. // pointer to parent cell
  281. wxHtmlContainerCell *m_Parent;
  282. // dimensions of fragment (m_Descent is used to position text & images)
  283. int m_Width, m_Height, m_Descent;
  284. // position where the fragment is drawn:
  285. int m_PosX, m_PosY;
  286. // superscript/subscript/normal:
  287. wxHtmlScriptMode m_ScriptMode;
  288. long m_ScriptBaseline;
  289. // destination address if this fragment is hypertext link, NULL otherwise
  290. wxHtmlLinkInfo *m_Link;
  291. // true if this cell can be placed on pagebreak, false otherwise
  292. bool m_CanLiveOnPagebreak;
  293. // unique identifier of the cell, generated from "id" property of tags
  294. wxString m_id;
  295. DECLARE_ABSTRACT_CLASS(wxHtmlCell)
  296. wxDECLARE_NO_COPY_CLASS(wxHtmlCell);
  297. };
  298. // ----------------------------------------------------------------------------
  299. // Inherited cells:
  300. // ----------------------------------------------------------------------------
  301. // ----------------------------------------------------------------------------
  302. // wxHtmlWordCell
  303. // Single word in input stream.
  304. // ----------------------------------------------------------------------------
  305. class WXDLLIMPEXP_HTML wxHtmlWordCell : public wxHtmlCell
  306. {
  307. public:
  308. wxHtmlWordCell(const wxString& word, const wxDC& dc);
  309. void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
  310. wxHtmlRenderingInfo& info);
  311. virtual wxCursor GetMouseCursor(wxHtmlWindowInterface *window) const;
  312. virtual wxString ConvertToText(wxHtmlSelection *sel) const;
  313. bool IsLinebreakAllowed() const { return m_allowLinebreak; }
  314. void SetPreviousWord(wxHtmlWordCell *cell);
  315. protected:
  316. virtual wxString GetAllAsText() const
  317. { return m_Word; }
  318. virtual wxString GetPartAsText(int begin, int end) const
  319. { return m_Word.Mid(begin, end - begin); }
  320. void SetSelectionPrivPos(const wxDC& dc, wxHtmlSelection *s) const;
  321. void Split(const wxDC& dc,
  322. const wxPoint& selFrom, const wxPoint& selTo,
  323. unsigned& pos1, unsigned& pos2) const;
  324. wxString m_Word;
  325. bool m_allowLinebreak;
  326. DECLARE_ABSTRACT_CLASS(wxHtmlWordCell)
  327. wxDECLARE_NO_COPY_CLASS(wxHtmlWordCell);
  328. };
  329. // wxHtmlWordCell specialization for storing text fragments with embedded
  330. // '\t's; these differ from normal words in that the displayed text is
  331. // different from the text copied to clipboard
  332. class WXDLLIMPEXP_HTML wxHtmlWordWithTabsCell : public wxHtmlWordCell
  333. {
  334. public:
  335. wxHtmlWordWithTabsCell(const wxString& word,
  336. const wxString& wordOrig,
  337. size_t linepos,
  338. const wxDC& dc)
  339. : wxHtmlWordCell(word, dc),
  340. m_wordOrig(wordOrig),
  341. m_linepos(linepos)
  342. {}
  343. protected:
  344. virtual wxString GetAllAsText() const;
  345. virtual wxString GetPartAsText(int begin, int end) const;
  346. wxString m_wordOrig;
  347. size_t m_linepos;
  348. };
  349. // Container contains other cells, thus forming tree structure of rendering
  350. // elements. Basic code of layout algorithm is contained in this class.
  351. class WXDLLIMPEXP_HTML wxHtmlContainerCell : public wxHtmlCell
  352. {
  353. public:
  354. wxHtmlContainerCell(wxHtmlContainerCell *parent);
  355. virtual ~wxHtmlContainerCell();
  356. virtual void Layout(int w);
  357. virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
  358. wxHtmlRenderingInfo& info);
  359. virtual void DrawInvisible(wxDC& dc, int x, int y,
  360. wxHtmlRenderingInfo& info);
  361. virtual bool AdjustPagebreak(int *pagebreak,
  362. const wxArrayInt& known_pagebreaks,
  363. int pageHeight) const;
  364. // insert cell at the end of m_Cells list
  365. void InsertCell(wxHtmlCell *cell);
  366. // sets horizontal/vertical alignment
  367. void SetAlignHor(int al) {m_AlignHor = al; m_LastLayout = -1;}
  368. int GetAlignHor() const {return m_AlignHor;}
  369. void SetAlignVer(int al) {m_AlignVer = al; m_LastLayout = -1;}
  370. int GetAlignVer() const {return m_AlignVer;}
  371. // sets left-border indentation. units is one of wxHTML_UNITS_* constants
  372. // what is combination of wxHTML_INDENT_*
  373. void SetIndent(int i, int what, int units = wxHTML_UNITS_PIXELS);
  374. // returns the indentation. ind is one of wxHTML_INDENT_* constants
  375. int GetIndent(int ind) const;
  376. // returns type of value returned by GetIndent(ind)
  377. int GetIndentUnits(int ind) const;
  378. // sets alignment info based on given tag's params
  379. void SetAlign(const wxHtmlTag& tag);
  380. // sets floating width adjustment
  381. // (examples : 32 percent of parent container,
  382. // -15 pixels percent (this means 100 % - 15 pixels)
  383. void SetWidthFloat(int w, int units) {m_WidthFloat = w; m_WidthFloatUnits = units; m_LastLayout = -1;}
  384. void SetWidthFloat(const wxHtmlTag& tag, double pixel_scale = 1.0);
  385. // sets minimal height of this container.
  386. void SetMinHeight(int h, int align = wxHTML_ALIGN_TOP) {m_MinHeight = h; m_MinHeightAlign = align; m_LastLayout = -1;}
  387. void SetBackgroundColour(const wxColour& clr) {m_BkColour = clr;}
  388. // returns background colour (of wxNullColour if none set), so that widgets can
  389. // adapt to it:
  390. wxColour GetBackgroundColour();
  391. void SetBorder(const wxColour& clr1, const wxColour& clr2, int border = 1) {m_Border = border; m_BorderColour1 = clr1, m_BorderColour2 = clr2;}
  392. virtual wxHtmlLinkInfo* GetLink(int x = 0, int y = 0) const;
  393. virtual const wxHtmlCell* Find(int condition, const void* param) const;
  394. #if WXWIN_COMPATIBILITY_2_6
  395. // this was replaced by ProcessMouseClick, don't use in new code!
  396. virtual void OnMouseClick(wxWindow *window,
  397. int x, int y, const wxMouseEvent& event);
  398. #endif
  399. virtual bool ProcessMouseClick(wxHtmlWindowInterface *window,
  400. const wxPoint& pos,
  401. const wxMouseEvent& event);
  402. virtual wxHtmlCell* GetFirstChild() const { return m_Cells; }
  403. // returns last child cell:
  404. wxHtmlCell* GetLastChild() const { return m_LastCell; }
  405. // see comment in wxHtmlCell about this method
  406. virtual bool IsTerminalCell() const { return false; }
  407. virtual wxHtmlCell *FindCellByPos(wxCoord x, wxCoord y,
  408. unsigned flags = wxHTML_FIND_EXACT) const;
  409. virtual wxHtmlCell *GetFirstTerminal() const;
  410. virtual wxHtmlCell *GetLastTerminal() const;
  411. // Removes indentation on top or bottom of the container (i.e. above or
  412. // below first/last terminal cell). For internal use only.
  413. virtual void RemoveExtraSpacing(bool top, bool bottom);
  414. // Returns the maximum possible length of the container.
  415. // Call Layout at least once before using GetMaxTotalWidth()
  416. virtual int GetMaxTotalWidth() const { return m_MaxTotalWidth; }
  417. protected:
  418. void UpdateRenderingStatePre(wxHtmlRenderingInfo& info,
  419. wxHtmlCell *cell) const;
  420. void UpdateRenderingStatePost(wxHtmlRenderingInfo& info,
  421. wxHtmlCell *cell) const;
  422. protected:
  423. int m_IndentLeft, m_IndentRight, m_IndentTop, m_IndentBottom;
  424. // indentation of subcells. There is always m_Indent pixels
  425. // big space between given border of the container and the subcells
  426. // it m_Indent < 0 it is in PERCENTS, otherwise it is in pixels
  427. int m_MinHeight, m_MinHeightAlign;
  428. // minimal height.
  429. wxHtmlCell *m_Cells, *m_LastCell;
  430. // internal cells, m_Cells points to the first of them, m_LastCell to the last one.
  431. // (LastCell is needed only to speed-up InsertCell)
  432. int m_AlignHor, m_AlignVer;
  433. // alignment horizontal and vertical (left, center, right)
  434. int m_WidthFloat, m_WidthFloatUnits;
  435. // width float is used in adjustWidth
  436. wxColour m_BkColour;
  437. // background color of this container
  438. int m_Border;
  439. // border size. Draw only if m_Border > 0
  440. wxColour m_BorderColour1, m_BorderColour2;
  441. // borders color of this container
  442. int m_LastLayout;
  443. // if != -1 then call to Layout may be no-op
  444. // if previous call to Layout has same argument
  445. int m_MaxTotalWidth;
  446. // Maximum possible length if ignoring line wrap
  447. DECLARE_ABSTRACT_CLASS(wxHtmlContainerCell)
  448. wxDECLARE_NO_COPY_CLASS(wxHtmlContainerCell);
  449. };
  450. // ---------------------------------------------------------------------------
  451. // wxHtmlColourCell
  452. // Color changer.
  453. // ---------------------------------------------------------------------------
  454. class WXDLLIMPEXP_HTML wxHtmlColourCell : public wxHtmlCell
  455. {
  456. public:
  457. wxHtmlColourCell(const wxColour& clr, int flags = wxHTML_CLR_FOREGROUND) : wxHtmlCell() {m_Colour = clr; m_Flags = flags;}
  458. virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
  459. wxHtmlRenderingInfo& info);
  460. virtual void DrawInvisible(wxDC& dc, int x, int y,
  461. wxHtmlRenderingInfo& info);
  462. protected:
  463. wxColour m_Colour;
  464. unsigned m_Flags;
  465. DECLARE_ABSTRACT_CLASS(wxHtmlColourCell)
  466. wxDECLARE_NO_COPY_CLASS(wxHtmlColourCell);
  467. };
  468. //--------------------------------------------------------------------------------
  469. // wxHtmlFontCell
  470. // Sets actual font used for text rendering
  471. //--------------------------------------------------------------------------------
  472. class WXDLLIMPEXP_HTML wxHtmlFontCell : public wxHtmlCell
  473. {
  474. public:
  475. wxHtmlFontCell(wxFont *font) : wxHtmlCell() { m_Font = (*font); }
  476. virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
  477. wxHtmlRenderingInfo& info);
  478. virtual void DrawInvisible(wxDC& dc, int x, int y,
  479. wxHtmlRenderingInfo& info);
  480. protected:
  481. wxFont m_Font;
  482. DECLARE_ABSTRACT_CLASS(wxHtmlFontCell)
  483. wxDECLARE_NO_COPY_CLASS(wxHtmlFontCell);
  484. };
  485. //--------------------------------------------------------------------------------
  486. // wxHtmlwidgetCell
  487. // This cell is connected with wxWindow object
  488. // You can use it to insert windows into HTML page
  489. // (buttons, input boxes etc.)
  490. //--------------------------------------------------------------------------------
  491. class WXDLLIMPEXP_HTML wxHtmlWidgetCell : public wxHtmlCell
  492. {
  493. public:
  494. // !!! wnd must have correct parent!
  495. // if w != 0 then the m_Wnd has 'floating' width - it adjust
  496. // it's width according to parent container's width
  497. // (w is percent of parent's width)
  498. wxHtmlWidgetCell(wxWindow *wnd, int w = 0);
  499. virtual ~wxHtmlWidgetCell() { m_Wnd->Destroy(); }
  500. virtual void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
  501. wxHtmlRenderingInfo& info);
  502. virtual void DrawInvisible(wxDC& dc, int x, int y,
  503. wxHtmlRenderingInfo& info);
  504. virtual void Layout(int w);
  505. protected:
  506. wxWindow* m_Wnd;
  507. int m_WidthFloat;
  508. // width float is used in adjustWidth (it is in percents)
  509. DECLARE_ABSTRACT_CLASS(wxHtmlWidgetCell)
  510. wxDECLARE_NO_COPY_CLASS(wxHtmlWidgetCell);
  511. };
  512. //--------------------------------------------------------------------------------
  513. // wxHtmlLinkInfo
  514. // Internal data structure. It represents hypertext link
  515. //--------------------------------------------------------------------------------
  516. class WXDLLIMPEXP_HTML wxHtmlLinkInfo : public wxObject
  517. {
  518. public:
  519. wxHtmlLinkInfo() : wxObject()
  520. { m_Href = m_Target = wxEmptyString; m_Event = NULL, m_Cell = NULL; }
  521. wxHtmlLinkInfo(const wxString& href, const wxString& target = wxEmptyString) : wxObject()
  522. { m_Href = href; m_Target = target; m_Event = NULL, m_Cell = NULL; }
  523. wxHtmlLinkInfo(const wxHtmlLinkInfo& l) : wxObject()
  524. { m_Href = l.m_Href, m_Target = l.m_Target, m_Event = l.m_Event;
  525. m_Cell = l.m_Cell; }
  526. wxHtmlLinkInfo& operator=(const wxHtmlLinkInfo& l)
  527. { m_Href = l.m_Href, m_Target = l.m_Target, m_Event = l.m_Event;
  528. m_Cell = l.m_Cell; return *this; }
  529. void SetEvent(const wxMouseEvent *e) { m_Event = e; }
  530. void SetHtmlCell(const wxHtmlCell *e) { m_Cell = e; }
  531. wxString GetHref() const { return m_Href; }
  532. wxString GetTarget() const { return m_Target; }
  533. const wxMouseEvent* GetEvent() const { return m_Event; }
  534. const wxHtmlCell* GetHtmlCell() const { return m_Cell; }
  535. private:
  536. wxString m_Href, m_Target;
  537. const wxMouseEvent *m_Event;
  538. const wxHtmlCell *m_Cell;
  539. };
  540. // ----------------------------------------------------------------------------
  541. // wxHtmlTerminalCellsInterator
  542. // ----------------------------------------------------------------------------
  543. class WXDLLIMPEXP_HTML wxHtmlTerminalCellsInterator
  544. {
  545. public:
  546. wxHtmlTerminalCellsInterator(const wxHtmlCell *from, const wxHtmlCell *to)
  547. : m_to(to), m_pos(from) {}
  548. operator bool() const { return m_pos != NULL; }
  549. const wxHtmlCell* operator++();
  550. const wxHtmlCell* operator->() const { return m_pos; }
  551. const wxHtmlCell* operator*() const { return m_pos; }
  552. private:
  553. const wxHtmlCell *m_to, *m_pos;
  554. };
  555. #endif // wxUSE_HTML
  556. #endif // _WX_HTMLCELL_H_