\membersection{wxHtmlListBox::Create}\label{wxhtmllistboxcreate}
-\func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID }{id = wxID\_ANY}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize}, \param{size\_t }{countItems = 0}, \param{long }{style = 0}, \param{const wxString\& }{name = wxVListBoxNameStr}}
+\func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID }{id = wxID\_ANY}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize}, \param{long }{style = 0}, \param{const wxString\& }{name = wxVListBoxNameStr}}
Creates the control and optionally sets the initial number of items in it
(it may also be set or changed later with
Returns {\tt true} on success or {\tt false} if the control couldn't be created
+\membersection{wxHtmlListBox::GetSelectedTextBgColour}\label{wxhtmllistboxgetselectedtextbgcolour}
+
+\constfunc{wxColour}{GetSelectedTextBgColour}{\param{const wxColour\& }{colBg}}
+
+This virtual function may be overridden to change the appearance of the
+background of the selected cells in the same way as
+\helpref{GetSelectedTextColour}{wxhtmllistboxgetselectedtextcolour}.
+
+It should be rarely, if ever, used because
+\helpref{SetSelectionBackground}{wxvlistboxsetselectionbackground} allows to
+change the selection background for all cells at once and doing anything more
+fancy is probably going to look strangely.
+
+\wxheading{See also}
+
+\helpref{GetSelectedTextColour}{wxhtmllistboxgetselectedtextcolour}
+
+
+\membersection{wxHtmlListBox::GetSelectedTextColour}\label{wxhtmllistboxgetselectedtextcolour}
+
+\constfunc{wxColour}{GetSelectedTextColour}{\param{const wxColour\& }{colFg}}
+
+This virtual function may be overridden to customize the appearance of the
+selected cells. It is used to determine how the colour {\it colFg} is going to
+look inside selection. By default all original colours are completely ignored
+and the standard, system-dependent, selection colour is used but the program
+may wish to override this to achieve some custom appearance.
+
+\wxheading{See also}
+
+\helpref{GetSelectedTextBgColour}{wxhtmllistboxgetselectedtextbgcolour},\\
+\helpref{SetSelectionBackground}{wxvlistboxsetselectionbackground},\\
+\helpref{wxSystemSettings::GetColour}{wxsystemsettingsgetcolour}
+
\membersection{wxHtmlListBox::OnGetItem}\label{wxhtmllistboxongetitem}
class WXDLLEXPORT wxHtmlCell;
class WXDLLEXPORT wxHtmlWinParser;
class WXDLLEXPORT wxHtmlListBoxCache;
+class WXDLLEXPORT wxHtmlListBoxStyle;
// ----------------------------------------------------------------------------
// wxHtmlListBox
virtual wxString OnGetItemMarkup(size_t n) const;
+ // this method allows to customize the selection appearance: it may be used
+ // to specify the colour of the text which normally has the given colour
+ // colFg when it is inside the selection
+ //
+ // by default, the original colour is not used at all and all text has the
+ // same (default for this system) colour inside selection
+ virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
+
+ // this is the same as GetSelectedTextColour() but allows to customize the
+ // background colour -- this is even more rarely used as you can change it
+ // globally using SetSelectionBackground()
+ virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
+
+
// we implement both of these functions in terms of OnGetItem(), they are
// not supposed to be overridden by our descendants
virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const;
void CacheItem(size_t n) const;
private:
+ // this class caches the pre-parsed HTML to speed up display
wxHtmlListBoxCache *m_cache;
// HTML parser we use
wxHtmlWinParser *m_htmlParser;
+ // rendering style for the parser which allows us to customize our colours
+ wxHtmlListBoxStyle *m_htmlRendStyle;
+
+
+ // it calls our GetSelectedTextColour() and GetSelectedTextBgColour()
+ friend class wxHtmlListBoxStyle;
+
DECLARE_EVENT_TABLE()
};
// get the margins around each item
wxPoint GetMargins() const { return m_ptMargins; }
+ // get the background colour of selected cells
+ const wxColour& GetSelectionBackground() const { return m_colBgSel; }
+
// operations
// ----------
void SetMargins(const wxPoint& pt);
void SetMargins(wxCoord x, wxCoord y) { SetMargins(wxPoint(x, y)); }
+ // change the background colour of the selected cells
+ void SetSelectionBackground(const wxColour& col);
+
protected:
// the derived class must implement this function to actually draw the item
// margins
wxPoint m_ptMargins;
+ // the selection bg colour
+ wxColour m_colBgSel;
+
+
DECLARE_EVENT_TABLE()
};
#include "wx/dc.h"
#endif
+#include "wx/colordlg.h"
+
#include "wx/htmllbox.h"
// you can also have a file containing HTML strings for testing, enable this if
class MyHtmlListBox : public wxHtmlListBox
{
public:
- MyHtmlListBox(wxWindow *parent, bool multi = false)
- : wxHtmlListBox(parent, -1, wxDefaultPosition, wxDefaultSize,
- multi ? wxLB_MULTIPLE : 0)
- {
- SetMargins(5, 5);
-
-#ifdef USE_HTML_FILE
- if ( !m_file.Open("results") )
- {
- wxLogError("Failed to open results file");
- }
- else
- {
- SetItemCount(m_file.GetLineCount());
- }
-#else
- SetItemCount(10);
-#endif
+ MyHtmlListBox(wxWindow *parent, bool multi = false);
- if ( HasMultipleSelection() )
- Select(3);
- else
- SetSelection(3);
- }
+ void SetChangeSelFg(bool change) { m_change = change; }
protected:
- virtual wxString OnGetItem(size_t n) const
- {
-#ifdef USE_HTML_FILE
- wxString s;
- if ( m_file.IsOpened() )
- s = m_file[n];
-
- return s;
-#else
- int level = n % 6 + 1;
- return wxString::Format(_T("<h%d><font color=#%2x%2x%2x>")
- _T("Item</font> <b>%lu</b>")
- _T("</h%d>"),
- level,
- abs(n - 192) % 256,
- abs(n - 256) % 256,
- abs(n - 128) % 256,
- (unsigned long)n, level);
-#endif
- }
+ virtual wxString OnGetItem(size_t n) const;
+ // change the appearance by overriding these functions
virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
+ virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
+ bool m_change;
+
+#ifdef USE_HTML_FILE
wxTextFile m_file;
+#endif
};
class MyFrame : public wxFrame
void OnToggleMulti(wxCommandEvent& event);
void OnSelectAll(wxCommandEvent& event);
+ void OnSetBgCol(wxCommandEvent& event);
+ void OnSetSelBgCol(wxCommandEvent& event);
+ void OnSetSelFgCol(wxCommandEvent& event);
+
+
void OnUpdateUISelectAll(wxUpdateUIEvent& event);
void OnLboxSelect(wxCommandEvent& event);
HtmlLbox_ToggleMulti,
HtmlLbox_SelectAll,
+ HtmlLbox_SetBgCol,
+ HtmlLbox_SetSelBgCol,
+ HtmlLbox_SetSelFgCol,
+
// it is important for the id corresponding to the "About" command to have
// this standard value as otherwise it won't be handled properly under Mac
// (where it is special and put into the "Apple" menu)
EVT_MENU(HtmlLbox_About, MyFrame::OnAbout)
+ EVT_MENU(HtmlLbox_SetBgCol, MyFrame::OnSetBgCol)
+ EVT_MENU(HtmlLbox_SetSelBgCol, MyFrame::OnSetSelBgCol)
+ EVT_MENU(HtmlLbox_SetSelFgCol, MyFrame::OnSetSelFgCol)
EVT_UPDATE_UI(HtmlLbox_SelectAll, MyFrame::OnUpdateUISelectAll)
_T("Set &margins...\tCtrl-G"),
_T("Change the margins around the items"));
menuHLbox->AppendCheckItem(HtmlLbox_DrawSeparator,
- _T("Draw &separators\tCtrl-S"),
+ _T("&Draw separators\tCtrl-D"),
_T("Toggle drawing separators between cells"));
menuHLbox->AppendSeparator();
menuHLbox->AppendCheckItem(HtmlLbox_ToggleMulti,
_T("Toggle multiple selection on/off"));
menuHLbox->AppendSeparator();
menuHLbox->Append(HtmlLbox_SelectAll, _T("Select &all items\tCtrl-A"));
+ menuHLbox->AppendSeparator();
+ menuHLbox->Append(HtmlLbox_SetBgCol, _T("Set &background...\tCtrl-B"));
+ menuHLbox->Append(HtmlLbox_SetSelBgCol,
+ _T("Set &selection background...\tCtrl-S"));
+ menuHLbox->AppendCheckItem(HtmlLbox_SetSelFgCol,
+ _T("Keep &foreground in selection\tCtrl-F"));
// the "About" item should be in the help menu
wxMenu *helpMenu = new wxMenu;
this);
}
-void MyFrame::OnSetMargins(wxCommandEvent&)
+void MyFrame::OnSetMargins(wxCommandEvent& WXUNUSED(event))
{
long margin = wxGetNumberFromUser
(
sizer->Layout();
}
-void MyFrame::OnSelectAll(wxCommandEvent& event)
+void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event))
{
m_hlbox->SelectRange(0, m_hlbox->GetItemCount() - 1);
}
event.Enable( m_hlbox && m_hlbox->HasMultipleSelection() );
}
+void MyFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event))
+{
+ wxColour col = wxGetColourFromUser(this, m_hlbox->GetBackgroundColour());
+ if ( col.Ok() )
+ {
+ m_hlbox->SetBackgroundColour(col);
+ m_hlbox->Refresh();
+
+ SetStatusText(_T("Background colour changed."));
+ }
+}
+
+void MyFrame::OnSetSelBgCol(wxCommandEvent& WXUNUSED(event))
+{
+ wxColour col = wxGetColourFromUser(this, m_hlbox->GetSelectionBackground());
+ if ( col.Ok() )
+ {
+ m_hlbox->SetSelectionBackground(col);
+ m_hlbox->Refresh();
+
+ SetStatusText(_T("Selection background colour changed."));
+ }
+}
+
+void MyFrame::OnSetSelFgCol(wxCommandEvent& event)
+{
+ m_hlbox->SetChangeSelFg(!event.IsChecked());
+ m_hlbox->Refresh();
+}
+
// ----------------------------------------------------------------------------
// listbox event handlers
// ----------------------------------------------------------------------------
// MyHtmlListBox
// ============================================================================
+MyHtmlListBox::MyHtmlListBox(wxWindow *parent, bool multi)
+ : wxHtmlListBox(parent, -1, wxDefaultPosition, wxDefaultSize,
+ multi ? wxLB_MULTIPLE : 0)
+{
+ m_change = true;
+
+ SetMargins(5, 5);
+
+#ifdef USE_HTML_FILE
+ if ( !m_file.Open("results") )
+ {
+ wxLogError("Failed to open results file");
+ }
+ else
+ {
+ SetItemCount(m_file.GetLineCount());
+ }
+#else
+ SetItemCount(10);
+#endif
+
+ // select something
+ if ( HasMultipleSelection() )
+ Select(3);
+ else
+ SetSelection(3);
+}
+
void MyHtmlListBox::OnDrawSeparator(wxDC& dc, wxRect& rect, size_t) const
{
if ( ((MyFrame *)GetParent())->
}
}
+wxString MyHtmlListBox::OnGetItem(size_t n) const
+{
+#ifdef USE_HTML_FILE
+ wxString s;
+ if ( m_file.IsOpened() )
+ s = m_file[n];
+
+ return s;
+#else
+ int level = n % 6 + 1;
+ return wxString::Format(_T("<h%d><font color=#%2x%2x%2x>")
+ _T("Item</font> <b>%lu</b>")
+ _T("</h%d>"),
+ level,
+ abs(n - 192) % 256,
+ abs(n - 256) % 256,
+ abs(n - 128) % 256,
+ (unsigned long)n, level);
+#endif
+}
+
+wxColour MyHtmlListBox::GetSelectedTextColour(const wxColour& colFg) const
+{
+ return m_change ? wxHtmlListBox::GetSelectedTextColour(colFg) : colFg;
+}
+
#include "wx/html/forcelnk.h"
FORCE_WXHTML_MODULES()
-// ----------------------------------------------------------------------------
+// ============================================================================
// private classes
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxHtmlListBoxCache
// ----------------------------------------------------------------------------
// this class is used by wxHtmlListBox to cache the parsed representation of
size_t m_items[SIZE];
};
+// ----------------------------------------------------------------------------
+// wxHtmlListBoxStyle
+// ----------------------------------------------------------------------------
+
+// just forward wxDefaultHtmlRenderingStyle callbacks to the main class so that
+// they could be overridden by the user code
+class wxHtmlListBoxStyle : public wxDefaultHtmlRenderingStyle
+{
+public:
+ wxHtmlListBoxStyle(wxHtmlListBox& hlbox) : m_hlbox(hlbox) { }
+
+ virtual wxColour GetSelectedTextColour(const wxColour& colFg)
+ {
+ return m_hlbox.GetSelectedTextColour(colFg);
+ }
+
+ virtual wxColour GetSelectedTextBgColour(const wxColour& colBg)
+ {
+ return m_hlbox.GetSelectedTextBgColour(colBg);
+ }
+
+private:
+ const wxHtmlListBox& m_hlbox;
+};
+
+
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
void wxHtmlListBox::Init()
{
m_htmlParser = NULL;
+ m_htmlRendStyle = new wxHtmlListBoxStyle(*this);
m_cache = new wxHtmlListBoxCache;
}
wxHtmlListBox::~wxHtmlListBox()
{
delete m_cache;
+
if ( m_htmlParser )
{
delete m_htmlParser->GetDC();
delete m_htmlParser;
}
+
+ delete m_htmlRendStyle;
+}
+
+// ----------------------------------------------------------------------------
+// wxHtmlListBox appearance
+// ----------------------------------------------------------------------------
+
+wxColour wxHtmlListBox::GetSelectedTextColour(const wxColour& colFg) const
+{
+ return m_htmlRendStyle->
+ wxDefaultHtmlRenderingStyle::GetSelectedTextColour(colFg);
+}
+
+wxColour
+wxHtmlListBox::GetSelectedTextBgColour(const wxColour& WXUNUSED(colBg)) const
+{
+ return GetSelectionBackground();
}
// ----------------------------------------------------------------------------
wxHtmlSelection htmlSel;
htmlSel.Set(wxPoint(0, 0), cell, wxPoint(INT_MAX, INT_MAX), cell);
htmlRendInfo.SetSelection(&htmlSel);
- //htmlRendInfo.SetSelectionState(wxHTML_SEL_IN);
+ if ( m_htmlRendStyle )
+ htmlRendInfo.SetStyle(m_htmlRendStyle);
+ htmlRendInfo.GetState().SetSelectionState(wxHTML_SEL_IN);
}
// note that we can't stop drawing exactly at the window boundary as then
if ( !wxVScrolledWindow::Create(parent, id, pos, size, style, name) )
return false;
- SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX));
-
if ( style & wxLB_MULTIPLE )
m_selStore = new wxSelectionStore;
+ SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX));
+ m_colBgSel = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
+
return true;
}
}
// ----------------------------------------------------------------------------
-// wxVListBox painting
+// wxVListBox appearance parameters
// ----------------------------------------------------------------------------
void wxVListBox::SetMargins(const wxPoint& pt)
}
}
+void wxVListBox::SetSelectionBackground(const wxColour& col)
+{
+ m_colBgSel = col;
+}
+
+// ----------------------------------------------------------------------------
+// wxVListBox painting
+// ----------------------------------------------------------------------------
+
wxCoord wxVListBox::OnGetLineHeight(size_t line) const
{
return OnMeasureItem(line) + 2*m_ptMargins.y;
{
if ( isSelected )
{
- wxBrush brush(wxSystemSettings::
- GetColour(wxSYS_COLOUR_HIGHLIGHT),
- wxSOLID);
- dc.SetBrush(brush);
+ dc.SetBrush(wxBrush(m_colBgSel, wxSOLID));
}
else // !selected
{