1
//---------------------------------------------------------------------------------------
2
// LenMus Phonascus: The teacher of music
3
// Copyright (c) 2002-2012 LenMus project
5
// This program is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU General Public License as published by the Free Software Foundation,
7
// either version 3 of the License, or (at your option) any later version.
9
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
10
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
// You should have received a copy of the GNU General Public License along with this
14
// program. If not, see <http://www.gnu.org/licenses/>.
16
// For any comment, suggestion or feature request, please contact the manager of
17
// the project at cecilios@users.sourceforge.net
19
// This code is based on files wx/htmllbox.h and wx/vlbox.h from wxWidgets 2.8.0
20
// project. wxWidgets licence is compatible with GNU GPL.
21
// Author of these files is Vadim Zeitlin,
22
// Copyright (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
24
// Merged and modified by:
25
// Nov-2006 - Cecilio Salmeron. Implementation of a tree list box with images
27
//---------------------------------------------------------------------------------------
29
#ifndef __LENMUS_CONTENT_BOX_CTROL_H__
30
#define __LENMUS_CONTENT_BOX_CTROL_H__
33
#include "lenmus_standard_header.h"
34
#include "lenmus_injectors.h"
37
#include <wx/vscroll.h> // base class
38
#include <wx/bitmap.h>
40
class wxSelectionStore;
42
#define ContentBoxCtrolStr _T("ContentBoxCtrol")
44
// ----------------------------------------------------------------------------
46
// ----------------------------------------------------------------------------
48
#include <wx/html/htmlwin.h>
49
#include <wx/ctrlsub.h>
50
#include <wx/filesys.h>
53
class wxHtmlWinParser;
59
//forward declarations
60
class lmHtmlListBoxCache;
61
class ContentBoxStyle;
62
class lmHLB_TagHandler;
65
extern const wxString lmHtmlListBoxNameStr;
67
class ContentBoxCtrol : public wxVScrolledWindow,
68
public wxHtmlWindowInterface,
69
public wxHtmlWindowMouseHelper
72
ContentBoxCtrol(wxWindow *parent, ApplicationScope& appScope,
73
wxWindowID id = wxID_ANY,
74
const wxPoint& pos = wxDefaultPosition,
75
const wxSize& size = wxDefaultSize,
77
const wxString& name = ContentBoxCtrolStr);
79
bool Create(wxWindow *parent,
80
wxWindowID id = wxID_ANY,
81
const wxPoint& pos = wxDefaultPosition,
82
const wxSize& size = wxDefaultSize,
84
const wxString& name = ContentBoxCtrolStr);
86
virtual ~ContentBoxCtrol();
90
size_t GetItemCount() const { return GetLineCount(); }
91
int GetSelection() const { return m_current; }
93
bool IsCurrent(size_t item) const { return item == (size_t)m_current; }
94
#ifdef __WXUNIVERSAL__
95
bool IsCurrent() const { return wxVScrolledWindow::IsCurrent(); }
98
bool IsSelected(size_t item) const;
100
wxPoint GetMargins() const { return m_ptMargins; }
102
const wxColour& GetSelectionBackground() const { return m_colBgSel; }
103
wxColour GetSelectedTextColour(const wxColour& colFg) const;
104
wxColour GetSelectedTextBgColour(const wxColour& WXUNUSED(colBg)) const;
108
virtual void SetItemCount(size_t count);
109
void Clear() { SetItemCount(0); }
110
void SetSelection(int selection);
112
void SetMargins(const wxPoint& pt);
113
void SetMargins(wxCoord x, wxCoord y) { SetMargins(wxPoint(x, y)); }
114
void SetSelectionBackground(const wxColour& col);
118
wxString OnGetItemMarkup(size_t n) const;
119
void CacheItem(size_t n) const;
120
void OnSize(wxSizeEvent& event);
121
void RefreshLine(size_t line);
122
void RefreshLines(size_t from, size_t to);
124
void SetHTMLWindowTitle(const wxString& WXUNUSED(title));
125
void OnHTMLLinkClicked(const wxHtmlLinkInfo& link);
126
void OnLinkClicked(size_t WXUNUSED(n), const wxHtmlLinkInfo& link);
127
wxHtmlOpeningStatus OnHTMLOpeningURL(wxHtmlURLType WXUNUSED(type),
128
const wxString& WXUNUSED(url),
129
wxString *WXUNUSED(redirect)) const;
130
wxPoint HTMLCoordsToWindow(wxHtmlCell *cell, const wxPoint& pos) const;
131
wxWindow* GetHTMLWindow();
132
wxColour GetHTMLBackgroundColour() const;
133
void SetHTMLBackgroundColour(const wxColour& WXUNUSED(clr));
134
void SetHTMLBackgroundImage(const wxBitmap& WXUNUSED(bmpBg));
135
void SetHTMLStatusText(const wxString& WXUNUSED(text));
136
wxCursor GetHTMLCursor(HTMLCursor type) const;
137
wxPoint GetRootCellCoords(size_t n) const;
138
bool PhysicalCoordsToCell(wxPoint& pos, wxHtmlCell*& cell) const;
139
size_t GetItemForCell(const wxHtmlCell *cell) const;
140
wxPoint CellCoordsToPhysical(const wxPoint& pos, wxHtmlCell *cell) const;
141
virtual wxString OnGetItem(size_t n) const = 0;
142
virtual void OnInternalIdle();
144
// retrieve the file system used by the wxHtmlWinParser: if you use
145
// relative paths in your HTML, you should use its ChangePathTo() method
146
wxFileSystem& GetFileSystem() { return m_filesystem; }
147
const wxFileSystem& GetFileSystem() const { return m_filesystem; }
154
virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const;
155
virtual wxCoord OnMeasureItem(size_t n) const;
156
virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
157
virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
158
virtual wxCoord OnGetLineHeight(size_t line) const;
160
// flags for DoHandleItemClick
163
ItemClick_Shift = 1, // item shift-clicked
164
ItemClick_Ctrl = 2, // ctrl
165
ItemClick_Kbd = 4 // item selected from keyboard
168
// common part of keyboard and mouse handling processing code
169
virtual void DoHandleItemClick(int item, int flags);
172
void OnPaint(wxPaintEvent& event);
173
void OnKeyDown(wxKeyEvent& event);
174
void OnLeftDown(wxMouseEvent& event);
175
void OnLeftDClick(wxMouseEvent& event);
177
// common part of all ctors
180
// send the wxEVT_COMMAND_LISTBOX_SELECTED event
181
void SendSelectedEvent();
183
// change the current item (in single selection listbox it also implicitly
184
// changes the selection); current may be wxNOT_FOUND in which case there
185
// will be no current item any more
187
// return true if the current item changed, false otherwise
188
bool DoSetCurrent(int current);
192
ApplicationScope& m_appScope;
194
// the current item or wxNOT_FOUND
196
// if m_selStore == NULL this is also the selected item, otherwise the
197
// selections are managed by m_selStore
200
// the anchor of the selection for the multiselection listboxes:
201
// shift-clicking an item extends the selection from m_anchor to the item
202
// clicked, for example
204
// always wxNOT_FOUND for single selection listboxes
210
// the selection bg colour
213
// this class caches the pre-parsed HTML to speed up display
214
lmHtmlListBoxCache* m_cache;
216
// HTML parser we use
217
wxHtmlWinParser* m_htmlParser;
218
// file system used by m_htmlParser
219
wxFileSystem m_filesystem;
221
// rendering style for the parser which allows us to customize our colours
222
ContentBoxStyle* m_htmlRendStyle;
225
// it calls our GetSelectedTextColour() and GetSelectedTextBgColour()
226
friend class wxHtmlListBoxStyle;
227
friend class wxHtmlListBoxWinInterface;
229
DECLARE_EVENT_TABLE()
230
DECLARE_NO_COPY_CLASS(ContentBoxCtrol)
231
DECLARE_ABSTRACT_CLASS(ContentBoxCtrol)
237
#endif // __LENMUS_CONTENT_BOX_CTROL_H__