htmllbox.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: htmllbox.h
  3. // Purpose: interface of wxHtmlListBox
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxHtmlListBox
  9. wxHtmlListBox is an implementation of wxVListBox which shows HTML content in
  10. the listbox rows. This is still an abstract base class and you will need to
  11. derive your own class from it (see htlbox sample for the example) but you will
  12. only need to override a single wxHtmlListBox::OnGetItem function.
  13. @beginEventEmissionTable{wxHtmlCellEvent,wxHtmlLinkEvent}
  14. @event{EVT_HTML_CELL_CLICKED(id, func)}
  15. A wxHtmlCell was clicked.
  16. @event{EVT_HTML_CELL_HOVER(id, func)}
  17. The mouse passed over a wxHtmlCell.
  18. @event{EVT_HTML_LINK_CLICKED(id, func)}
  19. A wxHtmlCell which contains an hyperlink was clicked.
  20. @endEventTable
  21. @library{wxhtml}
  22. @category{ctrl}
  23. @see wxSimpleHtmlListBox
  24. */
  25. class wxHtmlListBox : public wxVListBox
  26. {
  27. public:
  28. /**
  29. Normal constructor which calls Create() internally.
  30. */
  31. wxHtmlListBox(wxWindow* parent, wxWindowID id = wxID_ANY,
  32. const wxPoint& pos = wxDefaultPosition,
  33. const wxSize& size = wxDefaultSize,
  34. long style = 0,
  35. const wxString& name = wxHtmlListBoxNameStr);
  36. /**
  37. Default constructor, you must call Create() later.
  38. */
  39. wxHtmlListBox();
  40. /**
  41. Destructor cleans up whatever resources we use.
  42. */
  43. virtual ~wxHtmlListBox();
  44. /**
  45. Creates the control and optionally sets the initial number of items in it
  46. (it may also be set or changed later with wxVListBox::SetItemCount).
  47. There are no special styles defined for wxHtmlListBox, in particular the
  48. wxListBox styles (with the exception of @c wxLB_MULTIPLE) cannot be used here.
  49. Returns @true on success or @false if the control couldn't be created
  50. */
  51. bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
  52. const wxPoint& pos = wxDefaultPosition,
  53. const wxSize& size = wxDefaultSize,
  54. long style = 0,
  55. const wxString& name = wxHtmlListBoxNameStr);
  56. //@{
  57. /**
  58. Returns the wxFileSystem used by the HTML parser of this object.
  59. The file system object is used to resolve the paths in HTML fragments
  60. displayed in the control and you should use wxFileSystem::ChangePathTo
  61. if you use relative paths for the images or other resources embedded in
  62. your HTML.
  63. */
  64. wxFileSystem& GetFileSystem() const;
  65. const wxFileSystem& GetFileSystem() const;
  66. //@}
  67. protected:
  68. /**
  69. Called when the user clicks on hypertext link. Does nothing by default.
  70. Overloading this method is deprecated; intercept the event instead.
  71. @param n
  72. Index of the item containing the link.
  73. @param link
  74. Description of the link.
  75. @see wxHtmlLinkInfo.
  76. */
  77. virtual void OnLinkClicked(size_t n, const wxHtmlLinkInfo& link);
  78. /**
  79. This virtual function may be overridden to change the appearance of the
  80. background of the selected cells in the same way as GetSelectedTextColour().
  81. It should be rarely, if ever, used because wxVListBox::SetSelectionBackground
  82. allows to change the selection background for all cells at once and doing
  83. anything more fancy is probably going to look strangely.
  84. @see GetSelectedTextColour()
  85. */
  86. virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
  87. /**
  88. This virtual function may be overridden to customize the appearance of the
  89. selected cells. It is used to determine how the colour @a colFg is going to
  90. look inside selection. By default all original colours are completely ignored
  91. and the standard, system-dependent, selection colour is used but the program
  92. may wish to override this to achieve some custom appearance.
  93. @see GetSelectedTextBgColour(),
  94. wxVListBox::SetSelectionBackground, wxSystemSettings::GetColour
  95. */
  96. virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
  97. /**
  98. This function may be overridden to decorate HTML returned by OnGetItem().
  99. */
  100. virtual wxString OnGetItemMarkup(size_t n) const;
  101. /**
  102. This method must be implemented in the derived class and should return
  103. the body (i.e. without @c html nor @c body tags) of the HTML fragment
  104. for the given item.
  105. Note that this function should always return a text fragment for the @a n item
  106. which renders with the same height both when it is selected and when it's not:
  107. i.e. if you call, inside your OnGetItem() implementation, @c IsSelected(n) to
  108. make the items appear differently when they are selected, then you should make
  109. sure that the returned HTML fragment will render with the same height or else
  110. you'll see some artifacts when the user selects an item.
  111. */
  112. virtual wxString OnGetItem(size_t n) const = 0;
  113. };
  114. /**
  115. @class wxSimpleHtmlListBox
  116. wxSimpleHtmlListBox is an implementation of wxHtmlListBox which
  117. shows HTML content in the listbox rows.
  118. Unlike wxHtmlListBox, this is not an abstract class and thus it has the
  119. advantage that you can use it without deriving your own class from it.
  120. However, it also has the disadvantage that this is not a virtual control and
  121. thus it's not well-suited for those cases where you need to show a huge number
  122. of items: every time you add/insert a string, it will be stored internally
  123. and thus will take memory.
  124. The interface exposed by wxSimpleHtmlListBox fully implements the
  125. wxControlWithItems interface, thus you should refer to wxControlWithItems's
  126. documentation for the API reference for adding/removing/retrieving items in
  127. the listbox. Also note that the wxVListBox::SetItemCount function is
  128. @c protected in wxSimpleHtmlListBox's context so that you cannot call it
  129. directly, wxSimpleHtmlListBox will do it for you.
  130. Note: in case you need to append a lot of items to the control at once, make
  131. sure to use the
  132. @ref wxControlWithItems::Append "Append(const wxArrayString&)" function.
  133. Thus the only difference between a wxListBox and a wxSimpleHtmlListBox
  134. is that the latter stores strings which can contain HTML fragments (see the
  135. list of @ref overview_html_supptags "tags supported by wxHTML").
  136. Note that the HTML strings you fetch to wxSimpleHtmlListBox should not contain
  137. the @c \<html\> or @c \<body\> tags.
  138. @beginStyleTable
  139. @style{wxHLB_DEFAULT_STYLE}
  140. The default style: wxBORDER_SUNKEN
  141. @style{wxHLB_MULTIPLE}
  142. Multiple-selection list: the user can toggle multiple items on and off.
  143. @endStyleTable
  144. A wxSimpleHtmlListBox emits the same events used by wxListBox and by wxHtmlListBox.
  145. @beginEventEmissionTable
  146. @event{EVT_LISTBOX(id, func)}
  147. Process a @c wxEVT_LISTBOX event, when an item on the list
  148. is selected. See wxCommandEvent.
  149. @event{EVT_LISTBOX_DCLICK(id, func)}
  150. Process a @c wxEVT_LISTBOX_DCLICK event, when the listbox is
  151. double-clicked. See wxCommandEvent.
  152. @event{EVT_HTML_CELL_CLICKED(id, func)}
  153. A wxHtmlCell was clicked. See wxHtmlCellEvent.
  154. @event{EVT_HTML_CELL_HOVER(id, func)}
  155. The mouse passed over a wxHtmlCell. See wxHtmlCellEvent.
  156. @event{EVT_HTML_LINK_CLICKED(id, func)}
  157. A wxHtmlCell which contains an hyperlink was clicked. See wxHtmlLinkEvent
  158. @endEventTable
  159. @library{wxhtml}
  160. @category{ctrl}
  161. @genericAppearance{simplehtmllistbox}
  162. @see wxSimpleHtmlListBox::Create
  163. */
  164. class wxSimpleHtmlListBox : public wxHtmlListBox,
  165. public wxItemContainer
  166. {
  167. public:
  168. /**
  169. Constructor, creating and showing the HTML list box.
  170. @param parent
  171. Parent window. Must not be NULL.
  172. @param id
  173. Window identifier. A value of -1 indicates a default value.
  174. @param pos
  175. Window position.
  176. If ::wxDefaultPosition is specified then a default position is chosen.
  177. @param size
  178. Window size.
  179. If ::wxDefaultSize is specified then the window is sized appropriately.
  180. @param n
  181. Number of strings with which to initialise the control.
  182. @param choices
  183. An array of strings with which to initialise the control.
  184. @param style
  185. Window style. See wxHLB_* flags.
  186. @param validator
  187. Window validator.
  188. @param name
  189. Window name.
  190. */
  191. wxSimpleHtmlListBox(wxWindow* parent, wxWindowID id,
  192. const wxPoint& pos = wxDefaultPosition,
  193. const wxSize& size = wxDefaultSize,
  194. int n = 0,
  195. const wxString choices[] = NULL,
  196. long style = wxHLB_DEFAULT_STYLE,
  197. const wxValidator& validator = wxDefaultValidator,
  198. const wxString& name = wxSimpleHtmlListBoxNameStr);
  199. /**
  200. Constructor, creating and showing the HTML list box.
  201. @param parent
  202. Parent window. Must not be NULL.
  203. @param id
  204. Window identifier. A value of -1 indicates a default value.
  205. @param pos
  206. Window position.
  207. @param size
  208. Window size. If wxDefaultSize is specified then the window is sized appropriately.
  209. @param choices
  210. An array of strings with which to initialise the control.
  211. @param style
  212. Window style. See wxHLB_* flags.
  213. @param validator
  214. Window validator.
  215. @param name
  216. Window name.
  217. */
  218. wxSimpleHtmlListBox(wxWindow* parent, wxWindowID id,
  219. const wxPoint& pos,
  220. const wxSize& size,
  221. const wxArrayString& choices,
  222. long style = wxHLB_DEFAULT_STYLE,
  223. const wxValidator& validator = wxDefaultValidator,
  224. const wxString& name = wxSimpleHtmlListBoxNameStr);
  225. /**
  226. Default constructor, you must call Create() later.
  227. */
  228. wxSimpleHtmlListBox();
  229. /**
  230. Frees the array of stored items and relative client data.
  231. */
  232. virtual ~wxSimpleHtmlListBox();
  233. //@{
  234. /**
  235. Creates the HTML listbox for two-step construction.
  236. See wxSimpleHtmlListBox() for further details.
  237. */
  238. bool Create(wxWindow *parent, wxWindowID id,
  239. const wxPoint& pos = wxDefaultPosition,
  240. const wxSize& size = wxDefaultSize,
  241. int n = 0, const wxString choices[] = NULL,
  242. long style = wxHLB_DEFAULT_STYLE,
  243. const wxValidator& validator = wxDefaultValidator,
  244. const wxString& name = wxSimpleHtmlListBoxNameStr);
  245. bool Create(wxWindow *parent, wxWindowID id,
  246. const wxPoint& pos,
  247. const wxSize& size,
  248. const wxArrayString& choices,
  249. long style = wxHLB_DEFAULT_STYLE,
  250. const wxValidator& validator = wxDefaultValidator,
  251. const wxString& name = wxSimpleHtmlListBoxNameStr);
  252. //@}
  253. };