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