htlbox.cpp 19 KB

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