]> git.saurik.com Git - wxWidgets.git/blob - include/wx/htmllbox.h
Blind Tinderbox build fix.
[wxWidgets.git] / include / wx / htmllbox.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/htmllbox.h
3 // Purpose: wxHtmlListBox is a listbox whose items are wxHtmlCells
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 31.05.03
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_HTMLLBOX_H_
13 #define _WX_HTMLLBOX_H_
14
15 #include "wx/vlbox.h" // base class
16 #include "wx/html/htmlwin.h"
17
18 #if wxUSE_FILESYSTEM
19 #include "wx/filesys.h"
20 #endif // wxUSE_FILESYSTEM
21
22 class WXDLLIMPEXP_HTML wxHtmlCell;
23 class WXDLLIMPEXP_HTML wxHtmlWinParser;
24 class WXDLLIMPEXP_HTML wxHtmlListBoxCache;
25 class WXDLLIMPEXP_HTML wxHtmlListBoxStyle;
26
27 // ----------------------------------------------------------------------------
28 // wxHtmlListBox
29 // ----------------------------------------------------------------------------
30
31 class WXDLLIMPEXP_HTML wxHtmlListBox : public wxVListBox,
32 public wxHtmlWindowInterface,
33 public wxHtmlWindowMouseHelper
34 {
35 DECLARE_ABSTRACT_CLASS(wxHtmlListBox)
36 public:
37 // constructors and such
38 // ---------------------
39
40 // default constructor, you must call Create() later
41 wxHtmlListBox();
42
43 // normal constructor which calls Create() internally
44 wxHtmlListBox(wxWindow *parent,
45 wxWindowID id = wxID_ANY,
46 const wxPoint& pos = wxDefaultPosition,
47 const wxSize& size = wxDefaultSize,
48 long style = 0,
49 const wxString& name = wxVListBoxNameStr);
50
51 // really creates the control and sets the initial number of items in it
52 // (which may be changed later with SetItemCount())
53 //
54 // the only special style which may be specified here is wxLB_MULTIPLE
55 //
56 // returns true on success or false if the control couldn't be created
57 bool Create(wxWindow *parent,
58 wxWindowID id = wxID_ANY,
59 const wxPoint& pos = wxDefaultPosition,
60 const wxSize& size = wxDefaultSize,
61 long style = 0,
62 const wxString& name = wxVListBoxNameStr);
63
64 // destructor cleans up whatever resources we use
65 virtual ~wxHtmlListBox();
66
67 // override some base class virtuals
68 virtual void RefreshLine(size_t line);
69 virtual void RefreshLines(size_t from, size_t to);
70 virtual void RefreshAll();
71 virtual void SetItemCount(size_t count);
72
73
74 #if wxUSE_FILESYSTEM
75 // retrieve the file system used by the wxHtmlWinParser: if you use
76 // relative paths in your HTML, you should use its ChangePathTo() method
77 wxFileSystem& GetFileSystem() { return m_filesystem; }
78 const wxFileSystem& GetFileSystem() const { return m_filesystem; }
79 #endif // wxUSE_FILESYSTEM
80
81 virtual void OnInternalIdle();
82
83 protected:
84 // this method must be implemented in the derived class and should return
85 // the body (i.e. without <html>) of the HTML for the given item
86 virtual wxString OnGetItem(size_t n) const = 0;
87
88 // this function may be overridden to decorate HTML returned by OnGetItem()
89 virtual wxString OnGetItemMarkup(size_t n) const;
90
91
92 // this method allows to customize the selection appearance: it may be used
93 // to specify the colour of the text which normally has the given colour
94 // colFg when it is inside the selection
95 //
96 // by default, the original colour is not used at all and all text has the
97 // same (default for this system) colour inside selection
98 virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
99
100 // this is the same as GetSelectedTextColour() but allows to customize the
101 // background colour -- this is even more rarely used as you can change it
102 // globally using SetSelectionBackground()
103 virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
104
105
106 // we implement both of these functions in terms of OnGetItem(), they are
107 // not supposed to be overridden by our descendants
108 virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const;
109 virtual wxCoord OnMeasureItem(size_t n) const;
110
111 // This method may be overriden to handle clicking on a link in
112 // the listbox. By default, clicking links is ignored.
113 virtual void OnLinkClicked(size_t WXUNUSED(n),
114 const wxHtmlLinkInfo& WXUNUSED(link)) {}
115
116 // event handlers
117 void OnSize(wxSizeEvent& event);
118 void OnMouseMove(wxMouseEvent& event);
119 void OnLeftDown(wxMouseEvent& event);
120
121
122 // common part of all ctors
123 void Init();
124
125 // ensure that the given item is cached
126 void CacheItem(size_t n) const;
127
128 private:
129 // wxHtmlWindowInterface methods:
130 virtual void SetHTMLWindowTitle(const wxString& title);
131 virtual void OnHTMLLinkClicked(const wxHtmlLinkInfo& link);
132 virtual wxHtmlOpeningStatus OnHTMLOpeningURL(wxHtmlURLType type,
133 const wxString& url,
134 wxString *redirect) const;
135 virtual wxPoint HTMLCoordsToWindow(wxHtmlCell *cell,
136 const wxPoint& pos) const;
137 virtual wxWindow* GetHTMLWindow();
138 virtual wxColour GetHTMLBackgroundColour() const;
139 virtual void SetHTMLBackgroundColour(const wxColour& clr);
140 virtual void SetHTMLBackgroundImage(const wxBitmap& bmpBg);
141 virtual void SetHTMLStatusText(const wxString& text);
142 virtual wxCursor GetHTMLCursor(HTMLCursor type) const;
143
144 // returns index of item that contains given HTML cell
145 size_t GetItemForCell(const wxHtmlCell *cell) const;
146
147 // return physical coordinates of root wxHtmlCell of n-th item
148 wxPoint GetRootCellCoords(size_t n) const;
149
150 // Converts physical coordinates stored in @a pos into coordinates
151 // relative to the root cell of the item under mouse cursor, if any. If no
152 // cell is found under the cursor, returns false. Otherwise stores the new
153 // coordinates back into @a pos and pointer to the cell under cursor into
154 // @a cell and returns true.
155 bool PhysicalCoordsToCell(wxPoint& pos, wxHtmlCell*& cell) const;
156
157 // The opposite of PhysicalCoordsToCell: converts coordinates relative to
158 // given cell to physical coordinates in the window
159 wxPoint CellCoordsToPhysical(const wxPoint& pos, wxHtmlCell *cell) const;
160
161 private:
162 // this class caches the pre-parsed HTML to speed up display
163 wxHtmlListBoxCache *m_cache;
164
165 // HTML parser we use
166 wxHtmlWinParser *m_htmlParser;
167
168 #if wxUSE_FILESYSTEM
169 // file system used by m_htmlParser
170 wxFileSystem m_filesystem;
171 #endif // wxUSE_FILESYSTEM
172
173 // rendering style for the parser which allows us to customize our colours
174 wxHtmlListBoxStyle *m_htmlRendStyle;
175
176
177 // it calls our GetSelectedTextColour() and GetSelectedTextBgColour()
178 friend class wxHtmlListBoxStyle;
179 friend class wxHtmlListBoxWinInterface;
180
181
182 DECLARE_EVENT_TABLE()
183 DECLARE_NO_COPY_CLASS(wxHtmlListBox)
184 };
185
186 #endif // _WX_HTMLLBOX_H_
187