]> git.saurik.com Git - wxWidgets.git/blame - samples/htlbox/htlbox.cpp
return correct item and position from wxTreeEvent::GetItem/Point() (patch 1622166)
[wxWidgets.git] / samples / htlbox / htlbox.cpp
CommitLineData
201ca879
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: htmllbox.cpp
be5a51fb 3// Purpose: HtmlLbox wxWidgets sample
201ca879
VZ
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 31.05.03
7// RCS-ID: $Id$
be5a51fb 8// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
201ca879
VZ
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx/wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
5f732810 27// for all others, include the necessary headers
201ca879
VZ
28#ifndef WX_PRECOMP
29 #include "wx/app.h"
30 #include "wx/frame.h"
31 #include "wx/log.h"
5f732810 32 #include "wx/textdlg.h"
6170c108
VZ
33 #include "wx/sizer.h"
34
35 #include "wx/menu.h"
36 #include "wx/msgdlg.h"
37 #include "wx/textctrl.h"
38
39 #include "wx/dc.h"
ed269e7b 40 #include "wx/icon.h"
201ca879
VZ
41#endif
42
9a9b4940 43#include "wx/colordlg.h"
e4f3eb42 44#include "wx/numdlg.h"
9a9b4940 45
201ca879
VZ
46#include "wx/htmllbox.h"
47
5f732810
VZ
48// you can also have a file containing HTML strings for testing, enable this if
49// you want to use it
c2a331e0 50//#define USE_HTML_FILE
5f732810
VZ
51#ifdef USE_HTML_FILE
52 #include "wx/textfile.h"
53#endif
54
b6cf9ad0 55#include "../sample.xpm"
201ca879
VZ
56
57// ----------------------------------------------------------------------------
58// private classes
59// ----------------------------------------------------------------------------
60
201ca879
VZ
61// to use wxHtmlListBox you must derive a new class from it as you must
62// implement pure virtual OnGetItem()
63class MyHtmlListBox : public wxHtmlListBox
64{
65public:
9ebb7cad 66 MyHtmlListBox() { }
9a9b4940 67 MyHtmlListBox(wxWindow *parent, bool multi = false);
5f732810 68
9a9b4940 69 void SetChangeSelFg(bool change) { m_change = change; }
1d41ed0a 70 void UpdateFirstItem();
201ca879
VZ
71
72protected:
1d41ed0a
VZ
73 // override this method to return data to be shown in the listbox (this is
74 // mandatory)
9a9b4940 75 virtual wxString OnGetItem(size_t n) const;
201ca879 76
1d41ed0a 77 // change the appearance by overriding these functions (this is optional)
5f732810 78 virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
9a9b4940 79 virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
201ca879 80
1d41ed0a
VZ
81 // flag telling us whether we should use fg colour even for the selected
82 // item
9a9b4940
VZ
83 bool m_change;
84
1d41ed0a
VZ
85 // flag which we toggle to update the first items text in OnGetItem()
86 bool m_firstItemUpdated;
87
a1c3cdc4
VS
88public:
89
bc55e31b
VS
90 // flag which we toggle when the user clicks on the link in 2nd item
91 // to change 2nd item's text
92 bool m_linkClicked;
1d41ed0a 93
9a9b4940 94#ifdef USE_HTML_FILE
5f732810 95 wxTextFile m_file;
9a9b4940 96#endif
27d0dcd0
VZ
97
98 DECLARE_NO_COPY_CLASS(MyHtmlListBox)
9ebb7cad 99 DECLARE_DYNAMIC_CLASS(MyHtmlListBox)
201ca879
VZ
100};
101
9ebb7cad 102
8613d47b
VZ
103class MyFrame : public wxFrame
104{
105public:
106 MyFrame();
107 virtual ~MyFrame();
108
109 // event handlers
9ebb7cad 110 void OnSimpleOrCustomBox(wxCommandEvent& event);
8613d47b
VZ
111 void OnQuit(wxCommandEvent& event);
112 void OnAbout(wxCommandEvent& event);
113
5f732810
VZ
114 void OnSetMargins(wxCommandEvent& event);
115 void OnDrawSeparator(wxCommandEvent&) { m_hlbox->RefreshAll(); }
116 void OnToggleMulti(wxCommandEvent& event);
117 void OnSelectAll(wxCommandEvent& event);
1d41ed0a 118 void OnUpdateItem(wxCommandEvent& event);
8613d47b 119
9a9b4940
VZ
120 void OnSetBgCol(wxCommandEvent& event);
121 void OnSetSelBgCol(wxCommandEvent& event);
122 void OnSetSelFgCol(wxCommandEvent& event);
123
124
5f732810 125 void OnUpdateUISelectAll(wxUpdateUIEvent& event);
8613d47b 126
5f732810 127 void OnLboxSelect(wxCommandEvent& event);
8613d47b
VZ
128 void OnLboxDClick(wxCommandEvent& event)
129 {
b143cf70 130 wxLogMessage(_T("Listbox item %d double clicked."), event.GetInt());
8613d47b 131 }
9ebb7cad 132
a1c3cdc4
VS
133 void OnHtmlLinkClicked(wxHtmlLinkEvent& event);
134 void OnHtmlCellHover(wxHtmlCellEvent &event);
135 void OnHtmlCellClicked(wxHtmlCellEvent &event);
136
9ebb7cad
VZ
137 wxSimpleHtmlListBox *GetSimpleBox()
138 { return wxDynamicCast(m_hlbox, wxSimpleHtmlListBox); }
139 MyHtmlListBox *GetMyBox()
140 { return wxDynamicCast(m_hlbox, MyHtmlListBox); }
141
142 void CreateBox();
8613d47b
VZ
143
144private:
9ebb7cad 145 wxHtmlListBox *m_hlbox;
8613d47b 146
be5a51fb 147 // any class wishing to process wxWidgets events must use this macro
8613d47b
VZ
148 DECLARE_EVENT_TABLE()
149};
150
5f732810
VZ
151class MyApp : public wxApp
152{
153public:
07850a49 154 virtual bool OnInit() { (new MyFrame())->Show(); return true; }
5f732810
VZ
155};
156
201ca879
VZ
157// ----------------------------------------------------------------------------
158// constants
159// ----------------------------------------------------------------------------
160
161// IDs for the controls and the menu commands
162enum
163{
164 // menu items
9ebb7cad
VZ
165 HtmlLbox_CustomBox = 1,
166 HtmlLbox_SimpleBox,
167 HtmlLbox_Quit,
201ca879 168
5f732810
VZ
169 HtmlLbox_SetMargins,
170 HtmlLbox_DrawSeparator,
171 HtmlLbox_ToggleMulti,
172 HtmlLbox_SelectAll,
1d41ed0a 173 HtmlLbox_UpdateItem,
5f732810 174
9a9b4940
VZ
175 HtmlLbox_SetBgCol,
176 HtmlLbox_SetSelBgCol,
177 HtmlLbox_SetSelFgCol,
178
201ca879
VZ
179 // it is important for the id corresponding to the "About" command to have
180 // this standard value as otherwise it won't be handled properly under Mac
181 // (where it is special and put into the "Apple" menu)
182 HtmlLbox_About = wxID_ABOUT
183};
184
185// ----------------------------------------------------------------------------
be5a51fb 186// event tables and other macros for wxWidgets
201ca879
VZ
187// ----------------------------------------------------------------------------
188
201ca879 189BEGIN_EVENT_TABLE(MyFrame, wxFrame)
9ebb7cad
VZ
190 EVT_MENU(HtmlLbox_CustomBox, MyFrame::OnSimpleOrCustomBox)
191 EVT_MENU(HtmlLbox_SimpleBox, MyFrame::OnSimpleOrCustomBox)
201ca879 192 EVT_MENU(HtmlLbox_Quit, MyFrame::OnQuit)
5f732810
VZ
193
194 EVT_MENU(HtmlLbox_SetMargins, MyFrame::OnSetMargins)
195 EVT_MENU(HtmlLbox_DrawSeparator, MyFrame::OnDrawSeparator)
196 EVT_MENU(HtmlLbox_ToggleMulti, MyFrame::OnToggleMulti)
197 EVT_MENU(HtmlLbox_SelectAll, MyFrame::OnSelectAll)
1d41ed0a 198 EVT_MENU(HtmlLbox_UpdateItem, MyFrame::OnUpdateItem)
5f732810 199
201ca879
VZ
200 EVT_MENU(HtmlLbox_About, MyFrame::OnAbout)
201
9a9b4940
VZ
202 EVT_MENU(HtmlLbox_SetBgCol, MyFrame::OnSetBgCol)
203 EVT_MENU(HtmlLbox_SetSelBgCol, MyFrame::OnSetSelBgCol)
204 EVT_MENU(HtmlLbox_SetSelFgCol, MyFrame::OnSetSelFgCol)
5f732810
VZ
205
206 EVT_UPDATE_UI(HtmlLbox_SelectAll, MyFrame::OnUpdateUISelectAll)
207
208
201ca879
VZ
209 EVT_LISTBOX(wxID_ANY, MyFrame::OnLboxSelect)
210 EVT_LISTBOX_DCLICK(wxID_ANY, MyFrame::OnLboxDClick)
a1c3cdc4
VS
211
212
213 // the HTML listbox's events
214 EVT_HTML_LINK_CLICKED(wxID_ANY, MyFrame::OnHtmlLinkClicked)
215 EVT_HTML_CELL_HOVER(wxID_ANY, MyFrame::OnHtmlCellHover)
216 EVT_HTML_CELL_CLICKED(wxID_ANY, MyFrame::OnHtmlCellClicked)
217
201ca879
VZ
218END_EVENT_TABLE()
219
201ca879
VZ
220IMPLEMENT_APP(MyApp)
221
222// ============================================================================
5f732810 223// MyFrame
201ca879
VZ
224// ============================================================================
225
226// ----------------------------------------------------------------------------
5f732810 227// MyFrame ctor/dtor
201ca879
VZ
228// ----------------------------------------------------------------------------
229
230// frame constructor
231MyFrame::MyFrame()
07850a49 232 : wxFrame(NULL, wxID_ANY, _T("HtmlLbox wxWidgets Sample"),
9ebb7cad 233 wxDefaultPosition, wxSize(500, 500))
201ca879
VZ
234{
235 // set the frame icon
b6cf9ad0 236 SetIcon(wxIcon(sample_xpm));
201ca879
VZ
237
238#if wxUSE_MENUS
239 // create a menu bar
240 wxMenu *menuFile = new wxMenu;
9ebb7cad
VZ
241 menuFile->AppendRadioItem(HtmlLbox_CustomBox, _T("Use custom box"),
242 _T("Use a wxHtmlListBox virtual class control"));
243 menuFile->AppendRadioItem(HtmlLbox_SimpleBox, _T("Use simple box"),
244 _T("Use a wxSimpleHtmlListBox control"));
245 menuFile->AppendSeparator();
5f732810
VZ
246 menuFile->Append(HtmlLbox_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
247
248 // create our specific menu
249 wxMenu *menuHLbox = new wxMenu;
250 menuHLbox->Append(HtmlLbox_SetMargins,
251 _T("Set &margins...\tCtrl-G"),
252 _T("Change the margins around the items"));
253 menuHLbox->AppendCheckItem(HtmlLbox_DrawSeparator,
9a9b4940 254 _T("&Draw separators\tCtrl-D"),
5f732810
VZ
255 _T("Toggle drawing separators between cells"));
256 menuHLbox->AppendSeparator();
257 menuHLbox->AppendCheckItem(HtmlLbox_ToggleMulti,
258 _T("&Multiple selection\tCtrl-M"),
259 _T("Toggle multiple selection on/off"));
260 menuHLbox->AppendSeparator();
261 menuHLbox->Append(HtmlLbox_SelectAll, _T("Select &all items\tCtrl-A"));
1d41ed0a 262 menuHLbox->Append(HtmlLbox_UpdateItem, _T("Update &first item\tCtrl-U"));
9a9b4940
VZ
263 menuHLbox->AppendSeparator();
264 menuHLbox->Append(HtmlLbox_SetBgCol, _T("Set &background...\tCtrl-B"));
265 menuHLbox->Append(HtmlLbox_SetSelBgCol,
266 _T("Set &selection background...\tCtrl-S"));
267 menuHLbox->AppendCheckItem(HtmlLbox_SetSelFgCol,
268 _T("Keep &foreground in selection\tCtrl-F"));
201ca879
VZ
269
270 // the "About" item should be in the help menu
271 wxMenu *helpMenu = new wxMenu;
272 helpMenu->Append(HtmlLbox_About, _T("&About...\tF1"), _T("Show about dialog"));
273
201ca879
VZ
274 // now append the freshly created menu to the menu bar...
275 wxMenuBar *menuBar = new wxMenuBar();
276 menuBar->Append(menuFile, _T("&File"));
5f732810 277 menuBar->Append(menuHLbox, _T("&Listbox"));
201ca879
VZ
278 menuBar->Append(helpMenu, _T("&Help"));
279
5f732810
VZ
280 menuBar->Check(HtmlLbox_DrawSeparator, true);
281
201ca879
VZ
282 // ... and attach this menu bar to the frame
283 SetMenuBar(menuBar);
284#endif // wxUSE_MENUS
285
286#if wxUSE_STATUSBAR
287 // create a status bar just for fun (by default with 1 pane only)
288 CreateStatusBar(2);
be5a51fb 289 SetStatusText(_T("Welcome to wxWidgets!"));
201ca879 290#endif // wxUSE_STATUSBAR
9ebb7cad 291
201ca879 292 // create the child controls
9ebb7cad 293 CreateBox();
07850a49 294 wxTextCtrl *text = new wxTextCtrl(this, wxID_ANY, _T(""),
201ca879
VZ
295 wxDefaultPosition, wxDefaultSize,
296 wxTE_MULTILINE);
297 delete wxLog::SetActiveTarget(new wxLogTextCtrl(text));
298
299 // and lay them out
300 wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
9ebb7cad
VZ
301 sizer->Add(m_hlbox, 2, wxGROW);
302 sizer->Add(text, 3, wxGROW);
201ca879
VZ
303
304 SetSizer(sizer);
305}
306
307MyFrame::~MyFrame()
308{
309 delete wxLog::SetActiveTarget(NULL);
310}
311
9ebb7cad
VZ
312void MyFrame::CreateBox()
313{
314 bool multi = GetMenuBar()->IsChecked(HtmlLbox_ToggleMulti);
315
316 if ( GetMenuBar()->IsChecked(HtmlLbox_CustomBox) )
317 {
318 m_hlbox = new MyHtmlListBox(this, multi);
319 }
320 else // simple listbox
321 {
322 m_hlbox = new wxSimpleHtmlListBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
323 0, NULL, multi ? wxLB_MULTIPLE : 0);
324
325 // unlike wxHtmlListBox which is abstract, wxSimpleHtmlListBox is a
326 // concrete control and doesn't support virtual mode, this we need
327 // to add all of its items from the beginning
328 wxArrayString arr;
329 for (size_t n = 0; n < 1000; n++ )
330 {
331 wxColour clr((unsigned char)(abs((int)n - 192) % 256),
332 (unsigned char)(abs((int)n - 256) % 256),
333 (unsigned char)(abs((int)n - 128) % 256));
334 int level = n % 6 + 1;
335
336 wxString label = wxString::Format(_T("<h%d><font color=%s>")
337 _T("Item</font> <b>%lu</b>")
338 _T("</h%d>"),
339 level,
340 clr.GetAsString(wxC2S_HTML_SYNTAX).c_str(),
341 (unsigned long)n, level);
342 arr.Add(label);
343 }
344
345 GetSimpleBox()->Append(arr);
346 }
347}
348
349
5f732810
VZ
350// ----------------------------------------------------------------------------
351// menu event handlers
352// ----------------------------------------------------------------------------
353
9ebb7cad
VZ
354void MyFrame::OnSimpleOrCustomBox(wxCommandEvent& WXUNUSED(event))
355{
356 wxWindow *old = m_hlbox;
357
358 // we need to recreate the listbox
359 CreateBox();
360 GetSizer()->Replace(old, m_hlbox);
361 delete old;
362
363 GetSizer()->Layout();
364 Refresh();
365}
366
201ca879
VZ
367void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
368{
07850a49
WS
369 // true is to force the frame to close
370 Close(true);
201ca879
VZ
371}
372
373void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
374{
375 wxMessageBox(_T("This sample shows wxHtmlListBox class.\n")
376 _T("\n")
62b45e06 377 _T("(c) 2003 Vadim Zeitlin"),
201ca879
VZ
378 _T("About HtmlLbox"),
379 wxOK | wxICON_INFORMATION,
380 this);
381}
382
9a9b4940 383void MyFrame::OnSetMargins(wxCommandEvent& WXUNUSED(event))
5f732810
VZ
384{
385 long margin = wxGetNumberFromUser
386 (
387 _T("Enter the margins to use for the listbox items."),
388 _T("Margin: "),
389 _T("HtmlLbox: Set the margins"),
390 0, 0, 20,
391 this
392 );
393
394 if ( margin != -1 )
395 {
396 m_hlbox->SetMargins(margin, margin);
397 m_hlbox->RefreshAll();
398 }
399}
400
9ebb7cad 401void MyFrame::OnToggleMulti(wxCommandEvent& WXUNUSED(event))
5f732810 402{
9ebb7cad
VZ
403 wxWindow *old = m_hlbox;
404
5f732810 405 // we need to recreate the listbox
9ebb7cad
VZ
406 CreateBox();
407 GetSizer()->Replace(old, m_hlbox);
408 delete old;
5f732810 409
9ebb7cad 410 GetSizer()->Layout();
5f732810
VZ
411}
412
9a9b4940 413void MyFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event))
5f732810 414{
4636a1e8 415 m_hlbox->SelectAll();
5f732810
VZ
416}
417
418void MyFrame::OnUpdateUISelectAll(wxUpdateUIEvent& event)
419{
420 event.Enable( m_hlbox && m_hlbox->HasMultipleSelection() );
421}
422
1d41ed0a
VZ
423void MyFrame::OnUpdateItem(wxCommandEvent& WXUNUSED(event))
424{
9ebb7cad
VZ
425 if (GetMyBox())
426 GetMyBox()->UpdateFirstItem();
1d41ed0a
VZ
427}
428
9a9b4940
VZ
429void MyFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event))
430{
431 wxColour col = wxGetColourFromUser(this, m_hlbox->GetBackgroundColour());
432 if ( col.Ok() )
433 {
434 m_hlbox->SetBackgroundColour(col);
435 m_hlbox->Refresh();
436
8520f137 437#if wxUSE_STATUSBAR
9a9b4940 438 SetStatusText(_T("Background colour changed."));
8520f137 439#endif // wxUSE_STATUSBAR
9a9b4940
VZ
440 }
441}
442
443void MyFrame::OnSetSelBgCol(wxCommandEvent& WXUNUSED(event))
444{
445 wxColour col = wxGetColourFromUser(this, m_hlbox->GetSelectionBackground());
446 if ( col.Ok() )
447 {
448 m_hlbox->SetSelectionBackground(col);
449 m_hlbox->Refresh();
450
8520f137 451#if wxUSE_STATUSBAR
9a9b4940 452 SetStatusText(_T("Selection background colour changed."));
8520f137 453#endif // wxUSE_STATUSBAR
9a9b4940
VZ
454 }
455}
456
457void MyFrame::OnSetSelFgCol(wxCommandEvent& event)
458{
9ebb7cad
VZ
459 if (GetMyBox())
460 {
461 GetMyBox()->SetChangeSelFg(!event.IsChecked());
462 GetMyBox()->Refresh();
463 }
9a9b4940
VZ
464}
465
a1c3cdc4
VS
466void MyFrame::OnHtmlLinkClicked(wxHtmlLinkEvent &event)
467{
468 wxLogMessage(wxT("The url '%s' has been clicked!"), event.GetLinkInfo().GetHref().c_str());
469
470 if (GetMyBox())
471 {
472 GetMyBox()->m_linkClicked = true;
473 GetMyBox()->RefreshLine(1);
474 }
475}
476
477void MyFrame::OnHtmlCellHover(wxHtmlCellEvent &event)
478{
479 wxLogMessage(wxT("Mouse moved over cell %p at %d;%d"),
480 event.GetCell(), event.GetPoint().x, event.GetPoint().y);
481}
482
483void MyFrame::OnHtmlCellClicked(wxHtmlCellEvent &event)
484{
485 wxLogMessage(wxT("Click over cell %p at %d;%d"),
486 event.GetCell(), event.GetPoint().x, event.GetPoint().y);
487
488 // if we don't skip the event, OnHtmlLinkClicked won't be called!
489 event.Skip();
490}
491
5f732810
VZ
492// ----------------------------------------------------------------------------
493// listbox event handlers
494// ----------------------------------------------------------------------------
495
496void MyFrame::OnLboxSelect(wxCommandEvent& event)
497{
b143cf70 498 wxLogMessage(_T("Listbox selection is now %d."), event.GetInt());
5f732810
VZ
499
500 if ( m_hlbox->HasMultipleSelection() )
501 {
502 wxString s;
503
504 bool first = true;
505 unsigned long cookie;
506 for ( int item = m_hlbox->GetFirstSelected(cookie);
507 item != wxNOT_FOUND;
508 item = m_hlbox->GetNextSelected(cookie) )
509 {
510 if ( first )
511 first = false;
512 else
513 s << _T(", ");
514
515 s << item;
516 }
517
518 if ( !s.empty() )
519 wxLogMessage(_T("Selected items: %s"), s.c_str());
520 }
521
8520f137 522#if wxUSE_STATUSBAR
5f732810
VZ
523 SetStatusText(wxString::Format(
524 _T("# items selected = %lu"),
525 (unsigned long)m_hlbox->GetSelectedCount()
526 ));
8520f137 527#endif // wxUSE_STATUSBAR
5f732810
VZ
528}
529
530// ============================================================================
531// MyHtmlListBox
532// ============================================================================
533
9ebb7cad
VZ
534IMPLEMENT_DYNAMIC_CLASS(MyHtmlListBox, wxHtmlListBox)
535
9a9b4940 536MyHtmlListBox::MyHtmlListBox(wxWindow *parent, bool multi)
07850a49 537 : wxHtmlListBox(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
9a9b4940
VZ
538 multi ? wxLB_MULTIPLE : 0)
539{
540 m_change = true;
1d41ed0a 541 m_firstItemUpdated = false;
bc55e31b 542 m_linkClicked = false;
1d41ed0a 543
9a9b4940
VZ
544
545 SetMargins(5, 5);
546
547#ifdef USE_HTML_FILE
c2a331e0 548 if ( !m_file.Open(_T("results")) )
9a9b4940 549 {
c2a331e0 550 wxLogError(_T("Failed to open results file"));
9a9b4940
VZ
551 }
552 else
553 {
554 SetItemCount(m_file.GetLineCount());
555 }
556#else
4636a1e8 557 SetItemCount(1000);
9a9b4940
VZ
558#endif
559
4636a1e8 560 SetSelection(3);
9a9b4940
VZ
561}
562
5f732810
VZ
563void MyHtmlListBox::OnDrawSeparator(wxDC& dc, wxRect& rect, size_t) const
564{
565 if ( ((MyFrame *)GetParent())->
566 GetMenuBar()->IsChecked(HtmlLbox_DrawSeparator) )
567 {
568 dc.SetPen(*wxBLACK_DASHED_PEN);
569 dc.DrawLine(rect.x, rect.y, rect.GetRight(), rect.y);
570 dc.DrawLine(rect.x, rect.GetBottom(), rect.GetRight(), rect.GetBottom());
571 }
572}
573
9a9b4940
VZ
574wxString MyHtmlListBox::OnGetItem(size_t n) const
575{
1d41ed0a
VZ
576 if ( !n && m_firstItemUpdated )
577 {
578 return wxString::Format(_T("<h1><b>Just updated</b></h1>"));
579 }
580
9a9b4940
VZ
581#ifdef USE_HTML_FILE
582 wxString s;
583 if ( m_file.IsOpened() )
584 s = m_file[n];
585
586 return s;
587#else
588 int level = n % 6 + 1;
6bdcf0b1 589
d924939b
WS
590 wxColour clr((unsigned char)(abs((int)n - 192) % 256),
591 (unsigned char)(abs((int)n - 256) % 256),
592 (unsigned char)(abs((int)n - 128) % 256));
6bdcf0b1
WS
593
594 wxString label = wxString::Format(_T("<h%d><font color=%s>")
bc55e31b
VS
595 _T("Item</font> <b>%lu</b>")
596 _T("</h%d>"),
597 level,
6bdcf0b1 598 clr.GetAsString(wxC2S_HTML_SYNTAX).c_str(),
bc55e31b
VS
599 (unsigned long)n, level);
600 if ( n == 1 )
601 {
602 if ( !m_linkClicked )
603 label += _T("<a href='1'>Click here...</a>");
604 else
605 label += _T("<font color='#9999ff'>Clicked here...</font>");
606 }
607
608 return label;
9a9b4940
VZ
609#endif
610}
611
612wxColour MyHtmlListBox::GetSelectedTextColour(const wxColour& colFg) const
613{
614 return m_change ? wxHtmlListBox::GetSelectedTextColour(colFg) : colFg;
615}
616
1d41ed0a
VZ
617void MyHtmlListBox::UpdateFirstItem()
618{
619 m_firstItemUpdated = !m_firstItemUpdated;
620
621 RefreshLine(0);
622}