X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ed269e7bb9ca2127125bbd248c6756588af37b45..e6113e3a52d1c1c486b3a31cb22b59e2d9555b2d:/samples/htlbox/htlbox.cpp diff --git a/samples/htlbox/htlbox.cpp b/samples/htlbox/htlbox.cpp index 419def086c..a1f9757624 100644 --- a/samples/htlbox/htlbox.cpp +++ b/samples/htlbox/htlbox.cpp @@ -77,6 +77,8 @@ protected: virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const; virtual wxColour GetSelectedTextColour(const wxColour& colFg) const; + // override this method to handle mouse clicks + virtual void OnLinkClicked(size_t n, const wxHtmlLinkInfo& link); // flag telling us whether we should use fg colour even for the selected // item @@ -85,6 +87,9 @@ protected: // flag which we toggle to update the first items text in OnGetItem() bool m_firstItemUpdated; + // flag which we toggle when the user clicks on the link in 2nd item + // to change 2nd item's text + bool m_linkClicked; #ifdef USE_HTML_FILE @@ -423,6 +428,7 @@ MyHtmlListBox::MyHtmlListBox(wxWindow *parent, bool multi) { m_change = true; m_firstItemUpdated = false; + m_linkClicked = false; SetMargins(5, 5); @@ -469,14 +475,26 @@ wxString MyHtmlListBox::OnGetItem(size_t n) const return s; #else int level = n % 6 + 1; - return wxString::Format(_T("") - _T("Item %lu") - _T(""), - level, - abs((int)n - 192) % 256, - abs((int)n - 256) % 256, - abs((int)n - 128) % 256, - (unsigned long)n, level); + + wxColour clr((unsigned char)(abs((int)n - 192) % 256), + (unsigned char)(abs((int)n - 256) % 256), + (unsigned char)(abs((int)n - 128) % 256)); + + wxString label = wxString::Format(_T("") + _T("Item %lu") + _T(""), + level, + clr.GetAsString(wxC2S_HTML_SYNTAX).c_str(), + (unsigned long)n, level); + if ( n == 1 ) + { + if ( !m_linkClicked ) + label += _T("Click here..."); + else + label += _T("Clicked here..."); + } + + return label; #endif } @@ -492,3 +510,10 @@ void MyHtmlListBox::UpdateFirstItem() RefreshLine(0); } +void MyHtmlListBox::OnLinkClicked(size_t WXUNUSED(n), + const wxHtmlLinkInfo& WXUNUSED(link)) +{ + m_linkClicked = true; + + RefreshLine(1); +}