winpars.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: html/winpars.h
  3. // Purpose: interface of wxHtmlTagsModule
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxHtmlTagsModule
  9. This class provides easy way of filling wxHtmlWinParser's table of
  10. tag handlers. It is used almost exclusively together with the set of
  11. @ref overview_html_handlers "TAGS_MODULE_* macros"
  12. @library{wxhtml}
  13. @category{html}
  14. @see @ref overview_html_handlers, wxHtmlTagHandler, wxHtmlWinTagHandler
  15. */
  16. class wxHtmlTagsModule : public wxModule
  17. {
  18. public:
  19. /**
  20. You must override this method. In most common case its body consists
  21. only of lines of the following type:
  22. @code
  23. parser -> AddTagHandler(new MyHandler);
  24. @endcode
  25. It's recommended to use the @b TAGS_MODULE_* macros.
  26. @param parser
  27. Pointer to the parser that requested tables filling.
  28. */
  29. virtual void FillHandlersTable(wxHtmlWinParser* parser);
  30. };
  31. /**
  32. @class wxHtmlWinTagHandler
  33. This is basically wxHtmlTagHandler except that it is extended with protected
  34. member m_WParser pointing to the wxHtmlWinParser object (value of this member
  35. is identical to wxHtmlParser's m_Parser).
  36. @library{wxhtml}
  37. @category{html}
  38. */
  39. class wxHtmlWinTagHandler : public wxHtmlTagHandler
  40. {
  41. public:
  42. /**
  43. Constructor.
  44. */
  45. wxHtmlWinTagHandler();
  46. /**
  47. Assigns @a parser to this handler. Each @b instance of handler
  48. is guaranteed to be called only from the one parser.
  49. */
  50. virtual void SetParser(wxHtmlWinParser* parser);
  51. protected:
  52. /**
  53. Value of this attribute is identical to value of m_Parser.
  54. The only difference is that m_WParser points to wxHtmlWinParser object
  55. while m_Parser points to wxHtmlParser object. (The same object, but overcast.)
  56. */
  57. wxHtmlWinParser* m_WParser;
  58. };
  59. /**
  60. @class wxHtmlWinParser
  61. This class is derived from wxHtmlParser and its main goal is to parse HTML
  62. input so that it can be displayed in wxHtmlWindow.
  63. It uses a special wxHtmlWinTagHandler.
  64. @note The product of parsing is a wxHtmlCell (resp. wxHtmlContainer) object.
  65. @library{wxhtml}
  66. @category{html}
  67. @see @ref overview_html_handlers
  68. */
  69. class wxHtmlWinParser : public wxHtmlParser
  70. {
  71. public:
  72. /**
  73. Constructor.
  74. Don't use the default one, use the constructor with @a wndIface parameter
  75. (@a wndIface is a pointer to interface object for the associated wxHtmlWindow
  76. or other HTML rendering window such as wxHtmlListBox).
  77. */
  78. wxHtmlWinParser(wxHtmlWindowInterface* wndIface = NULL);
  79. /**
  80. Adds module() to the list of wxHtmlWinParser tag handler.
  81. */
  82. static void AddModule(wxHtmlTagsModule* module);
  83. /**
  84. Closes the container, sets actual container to the parent one
  85. and returns pointer to it (see @ref overview_html_cells).
  86. */
  87. wxHtmlContainerCell* CloseContainer();
  88. /**
  89. Creates font based on current setting (see SetFontSize(), SetFontBold(),
  90. SetFontItalic(), SetFontFixed(), wxHtmlWinParser::SetFontUnderlined)
  91. and returns pointer to it.
  92. If the font was already created only a pointer is returned.
  93. */
  94. virtual wxFont* CreateCurrentFont();
  95. /**
  96. Returns actual text colour.
  97. */
  98. const wxColour& GetActualColor() const;
  99. /**
  100. Returns default horizontal alignment.
  101. */
  102. int GetAlign() const;
  103. /**
  104. Returns (average) char height in standard font.
  105. It is used as DC-independent metrics.
  106. @note This function doesn't return the @e actual height. If you want to
  107. know the height of the current font, call @c GetDC->GetCharHeight().
  108. */
  109. int GetCharHeight() const;
  110. /**
  111. Returns average char width in standard font.
  112. It is used as DC-independent metrics.
  113. @note This function doesn't return the @e actual width. If you want to
  114. know the height of the current font, call @c GetDC->GetCharWidth().
  115. */
  116. int GetCharWidth() const;
  117. /**
  118. Returns pointer to the currently opened container (see @ref overview_html_cells).
  119. Common use:
  120. @code
  121. m_WParser -> GetContainer() -> InsertCell(new ...);
  122. @endcode
  123. */
  124. wxHtmlContainerCell* GetContainer() const;
  125. /**
  126. Returns pointer to the DC used during parsing.
  127. */
  128. wxDC* GetDC();
  129. /**
  130. Returns wxEncodingConverter class used to do conversion between the
  131. @ref GetInputEncoding() "input encoding" and the
  132. @ref GetOutputEncoding() "output encoding".
  133. */
  134. wxEncodingConverter* GetEncodingConverter() const;
  135. /**
  136. Returns @true if actual font is bold, @false otherwise.
  137. */
  138. int GetFontBold() const;
  139. /**
  140. Returns actual font face name.
  141. */
  142. wxString GetFontFace() const;
  143. /**
  144. Returns @true if actual font is fixed face, @false otherwise.
  145. */
  146. int GetFontFixed() const;
  147. /**
  148. Returns @true if actual font is italic, @false otherwise.
  149. */
  150. int GetFontItalic() const;
  151. /**
  152. Returns actual font size (HTML size varies from -2 to +4)
  153. */
  154. int GetFontSize() const;
  155. /**
  156. Returns @true if actual font is underlined, @false otherwise.
  157. */
  158. int GetFontUnderlined() const;
  159. /**
  160. Returns input encoding.
  161. */
  162. wxFontEncoding GetInputEncoding() const;
  163. /**
  164. Returns actual hypertext link.
  165. (This value has a non-empty @ref wxHtmlLinkInfo::GetHref Href string
  166. if the parser is between \<A\> and \</A\> tags, wxEmptyString otherwise.)
  167. */
  168. const wxHtmlLinkInfo& GetLink() const;
  169. /**
  170. Returns the colour of hypertext link text.
  171. */
  172. const wxColour& GetLinkColor() const;
  173. /**
  174. Returns output encoding, i.e. closest match to document's input encoding
  175. that is supported by operating system.
  176. */
  177. wxFontEncoding GetOutputEncoding() const;
  178. /**
  179. Returns associated window (wxHtmlWindow). This may be @NULL!
  180. (You should always test if it is non-@NULL.
  181. For example @c TITLE handler sets window title only if some window is
  182. associated, otherwise it does nothing.
  183. */
  184. wxHtmlWindowInterface* GetWindowInterface();
  185. /**
  186. Opens new container and returns pointer to it (see @ref overview_html_cells).
  187. */
  188. wxHtmlContainerCell* OpenContainer();
  189. /**
  190. Sets actual text colour. Note: this DOESN'T change the colour!
  191. You must create wxHtmlColourCell yourself.
  192. */
  193. void SetActualColor(const wxColour& clr);
  194. /**
  195. Sets default horizontal alignment (see wxHtmlContainerCell::SetAlignHor).
  196. Alignment of newly opened container is set to this value.
  197. */
  198. void SetAlign(int a);
  199. /**
  200. Allows you to directly set opened container.
  201. This is not recommended - you should use OpenContainer() wherever possible.
  202. */
  203. wxHtmlContainerCell* SetContainer(wxHtmlContainerCell* c);
  204. /**
  205. Sets the DC. This must be called before wxHtmlParser::Parse!
  206. @a pixel_scale can be used when rendering to high-resolution
  207. DCs (e.g. printer) to adjust size of pixel metrics. (Many dimensions in
  208. HTML are given in pixels -- e.g. image sizes. 300x300 image would be only one
  209. inch wide on typical printer. With pixel_scale = 3.0 it would be 3 inches.)
  210. */
  211. virtual void SetDC(wxDC* dc, double pixel_scale = 1.0e+0);
  212. /**
  213. Sets bold flag of actualfont. @a x is either @true of @false.
  214. */
  215. void SetFontBold(int x);
  216. /**
  217. Sets current font face to @a face. This affects either fixed size
  218. font or proportional, depending on context (whether the parser is
  219. inside @c \<TT\> tag or not).
  220. */
  221. void SetFontFace(const wxString& face);
  222. /**
  223. Sets fixed face flag of actualfont. @a x is either @true of @false.
  224. */
  225. void SetFontFixed(int x);
  226. /**
  227. Sets italic flag of actualfont. @a x is either @true of @false.
  228. */
  229. void SetFontItalic(int x);
  230. /**
  231. Sets actual font size (HTML size varies from 1 to 7).
  232. */
  233. void SetFontSize(int s);
  234. /**
  235. Sets underlined flag of actualfont. @a x is either @true of @false.
  236. */
  237. void SetFontUnderlined(int x);
  238. /**
  239. Sets fonts. See wxHtmlWindow::SetFonts for detailed description.
  240. */
  241. void SetFonts(const wxString& normal_face, const wxString& fixed_face,
  242. const int* sizes = 0);
  243. /**
  244. Sets input encoding. The parser uses this information to build conversion
  245. tables from document's encoding to some encoding supported by operating system.
  246. */
  247. void SetInputEncoding(wxFontEncoding enc);
  248. /**
  249. Sets actual hypertext link.
  250. Empty link is represented by wxHtmlLinkInfo with @e Href equal
  251. to wxEmptyString.
  252. */
  253. void SetLink(const wxHtmlLinkInfo& link);
  254. /**
  255. Sets colour of hypertext link.
  256. */
  257. void SetLinkColor(const wxColour& clr);
  258. };