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