]> git.saurik.com Git - wxWidgets.git/blame - src/generic/htmllbox.cpp
move everything inside wxUSE_RIBBON wrapper
[wxWidgets.git] / src / generic / htmllbox.cpp
CommitLineData
e0c6027b
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: generic/htmllbox.cpp
3// Purpose: implementation of wxHtmlListBox
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 31.05.03
7// RCS-ID: $Id$
8// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
0a53b9b8 9// License: wxWindows license
e0c6027b
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#ifndef WX_PRECOMP
bb178b29 28 #include "wx/dcclient.h"
e0c6027b
VZ
29#endif //WX_PRECOMP
30
461dae94
VZ
31#if wxUSE_HTML
32
e0c6027b
VZ
33#include "wx/htmllbox.h"
34
35#include "wx/html/htmlcell.h"
36#include "wx/html/winpars.h"
37
5ecdc7ab
VZ
38// this hack forces the linker to always link in m_* files
39#include "wx/html/forcelnk.h"
40FORCE_WXHTML_MODULES()
41
bc55e31b
VS
42// ----------------------------------------------------------------------------
43// constants
44// ----------------------------------------------------------------------------
45
46// small border always added to the cells:
47static const wxCoord CELL_BORDER = 2;
48
23318a53
FM
49const char wxHtmlListBoxNameStr[] = "htmlListBox";
50const char wxSimpleHtmlListBoxNameStr[] = "simpleHtmlListBox";
9ebb7cad 51
9a9b4940 52// ============================================================================
e0c6027b 53// private classes
9a9b4940
VZ
54// ============================================================================
55
56// ----------------------------------------------------------------------------
57// wxHtmlListBoxCache
e0c6027b
VZ
58// ----------------------------------------------------------------------------
59
60// this class is used by wxHtmlListBox to cache the parsed representation of
61// the items to avoid doing it anew each time an item must be drawn
e0c6027b
VZ
62class wxHtmlListBoxCache
63{
aead8a4e
VZ
64private:
65 // invalidate a single item, used by Clear() and InvalidateRange()
66 void InvalidateItem(size_t n)
67 {
68 m_items[n] = (size_t)-1;
69 delete m_cells[n];
70 m_cells[n] = NULL;
71 }
72
e0c6027b 73public:
5ecdc7ab
VZ
74 wxHtmlListBoxCache()
75 {
76 for ( size_t n = 0; n < SIZE; n++ )
77 {
78 m_items[n] = (size_t)-1;
79 m_cells[n] = NULL;
80 }
e0c6027b 81
5ecdc7ab
VZ
82 m_next = 0;
83 }
e0c6027b 84
5ecdc7ab 85 ~wxHtmlListBoxCache()
e0c6027b 86 {
5ecdc7ab
VZ
87 for ( size_t n = 0; n < SIZE; n++ )
88 {
89 delete m_cells[n];
90 }
91 }
e0c6027b 92
5ecdc7ab
VZ
93 // completely invalidate the cache
94 void Clear()
95 {
96 for ( size_t n = 0; n < SIZE; n++ )
97 {
aead8a4e 98 InvalidateItem(n);
5ecdc7ab 99 }
e0c6027b
VZ
100 }
101
102 // return the cached cell for this index or NULL if none
5ecdc7ab
VZ
103 wxHtmlCell *Get(size_t item) const
104 {
105 for ( size_t n = 0; n < SIZE; n++ )
106 {
107 if ( m_items[n] == item )
108 return m_cells[n];
109 }
110
111 return NULL;
112 }
113
114 // returns true if we already have this item cached
115 bool Has(size_t item) const { return Get(item) != NULL; }
116
117 // ensure that the item is cached
118 void Store(size_t item, wxHtmlCell *cell)
e0c6027b 119 {
5ecdc7ab
VZ
120 delete m_cells[m_next];
121 m_cells[m_next] = cell;
122 m_items[m_next] = item;
123
124 // advance to the next item wrapping around if there are no more
125 if ( ++m_next == SIZE )
126 m_next = 0;
e0c6027b
VZ
127 }
128
aead8a4e
VZ
129 // forget the cached value of the item(s) between the given ones (inclusive)
130 void InvalidateRange(size_t from, size_t to)
131 {
132 for ( size_t n = 0; n < SIZE; n++ )
133 {
134 if ( m_items[n] >= from && m_items[n] <= to )
135 {
136 InvalidateItem(n);
137 }
138 }
139 }
140
e0c6027b 141private:
5ecdc7ab
VZ
142 // the max number of the items we cache
143 enum { SIZE = 50 };
144
145 // the index of the LRU (oldest) cell
146 size_t m_next;
147
e0c6027b 148 // the parsed representation of the cached item or NULL
5ecdc7ab 149 wxHtmlCell *m_cells[SIZE];
e0c6027b 150
5ecdc7ab
VZ
151 // the index of the currently cached item (only valid if m_cells != NULL)
152 size_t m_items[SIZE];
e0c6027b
VZ
153};
154
9a9b4940
VZ
155// ----------------------------------------------------------------------------
156// wxHtmlListBoxStyle
157// ----------------------------------------------------------------------------
158
159// just forward wxDefaultHtmlRenderingStyle callbacks to the main class so that
160// they could be overridden by the user code
161class wxHtmlListBoxStyle : public wxDefaultHtmlRenderingStyle
162{
163public:
fbfb8bcc 164 wxHtmlListBoxStyle(const wxHtmlListBox& hlbox) : m_hlbox(hlbox) { }
9a9b4940
VZ
165
166 virtual wxColour GetSelectedTextColour(const wxColour& colFg)
167 {
c848185a
VZ
168 // by default wxHtmlListBox doesn't implement GetSelectedTextColour()
169 // and returns wxNullColour from it, so use the default HTML colour for
170 // selection
171 wxColour col = m_hlbox.GetSelectedTextColour(colFg);
172 if ( !col.IsOk() )
173 {
174 col = wxDefaultHtmlRenderingStyle::GetSelectedTextColour(colFg);
175 }
176
177 return col;
9a9b4940
VZ
178 }
179
180 virtual wxColour GetSelectedTextBgColour(const wxColour& colBg)
181 {
c848185a
VZ
182 wxColour col = m_hlbox.GetSelectedTextBgColour(colBg);
183 if ( !col.IsOk() )
184 {
185 col = wxDefaultHtmlRenderingStyle::GetSelectedTextBgColour(colBg);
186 }
187
188 return col;
9a9b4940
VZ
189 }
190
191private:
192 const wxHtmlListBox& m_hlbox;
27d0dcd0 193
c0c133e1 194 wxDECLARE_NO_COPY_CLASS(wxHtmlListBoxStyle);
9a9b4940
VZ
195};
196
5ecdc7ab
VZ
197// ----------------------------------------------------------------------------
198// event tables
199// ----------------------------------------------------------------------------
200
201BEGIN_EVENT_TABLE(wxHtmlListBox, wxVListBox)
202 EVT_SIZE(wxHtmlListBox::OnSize)
bc55e31b
VS
203 EVT_MOTION(wxHtmlListBox::OnMouseMove)
204 EVT_LEFT_DOWN(wxHtmlListBox::OnLeftDown)
5ecdc7ab
VZ
205END_EVENT_TABLE()
206
e0c6027b
VZ
207// ============================================================================
208// implementation
209// ============================================================================
210
0c8392ca
RD
211IMPLEMENT_ABSTRACT_CLASS(wxHtmlListBox, wxVListBox)
212
213
e0c6027b
VZ
214// ----------------------------------------------------------------------------
215// wxHtmlListBox creation
216// ----------------------------------------------------------------------------
217
bc55e31b
VS
218wxHtmlListBox::wxHtmlListBox()
219 : wxHtmlWindowMouseHelper(this)
220{
221 Init();
222}
223
224// normal constructor which calls Create() internally
225wxHtmlListBox::wxHtmlListBox(wxWindow *parent,
226 wxWindowID id,
227 const wxPoint& pos,
228 const wxSize& size,
229 long style,
230 const wxString& name)
231 : wxHtmlWindowMouseHelper(this)
232{
233 Init();
234
235 (void)Create(parent, id, pos, size, style, name);
236}
237
e0c6027b
VZ
238void wxHtmlListBox::Init()
239{
240 m_htmlParser = NULL;
9a9b4940 241 m_htmlRendStyle = new wxHtmlListBoxStyle(*this);
e0c6027b
VZ
242 m_cache = new wxHtmlListBoxCache;
243}
244
245bool wxHtmlListBox::Create(wxWindow *parent,
246 wxWindowID id,
247 const wxPoint& pos,
248 const wxSize& size,
e0c6027b
VZ
249 long style,
250 const wxString& name)
251{
43e319a3 252 return wxVListBox::Create(parent, id, pos, size, style, name);
e0c6027b
VZ
253}
254
255wxHtmlListBox::~wxHtmlListBox()
256{
257 delete m_cache;
9a9b4940 258
e0c6027b
VZ
259 if ( m_htmlParser )
260 {
261 delete m_htmlParser->GetDC();
262 delete m_htmlParser;
263 }
9a9b4940
VZ
264
265 delete m_htmlRendStyle;
266}
267
268// ----------------------------------------------------------------------------
269// wxHtmlListBox appearance
270// ----------------------------------------------------------------------------
271
c848185a
VZ
272wxColour
273wxHtmlListBox::GetSelectedTextColour(const wxColour& WXUNUSED(colFg)) const
9a9b4940 274{
c848185a 275 return wxNullColour;
9a9b4940
VZ
276}
277
278wxColour
279wxHtmlListBox::GetSelectedTextBgColour(const wxColour& WXUNUSED(colBg)) const
280{
5ae69f62 281 return GetSelectionBackground();
e0c6027b
VZ
282}
283
284// ----------------------------------------------------------------------------
285// wxHtmlListBox items markup
286// ----------------------------------------------------------------------------
287
288wxString wxHtmlListBox::OnGetItemMarkup(size_t n) const
289{
290 // we don't even need to wrap the value returned by OnGetItem() inside
291 // "<html><body>" and "</body></html>" because wxHTML can parse it even
292 // without these tags
293 return OnGetItem(n);
294}
295
5ecdc7ab
VZ
296// ----------------------------------------------------------------------------
297// wxHtmlListBox cache handling
298// ----------------------------------------------------------------------------
299
e0c6027b
VZ
300void wxHtmlListBox::CacheItem(size_t n) const
301{
302 if ( !m_cache->Has(n) )
303 {
304 if ( !m_htmlParser )
305 {
306 wxHtmlListBox *self = wxConstCast(this, wxHtmlListBox);
307
bc55e31b 308 self->m_htmlParser = new wxHtmlWinParser(self);
e0c6027b 309 m_htmlParser->SetDC(new wxClientDC(self));
2d814c19 310 m_htmlParser->SetFS(&self->m_filesystem);
67339f7d 311#if !wxUSE_UNICODE
85d3d198
JS
312 if (GetFont().Ok())
313 m_htmlParser->SetInputEncoding(GetFont().GetEncoding());
67339f7d 314#endif
f987cbb1
VS
315 // use system's default GUI font by default:
316 m_htmlParser->SetStandardFonts();
e0c6027b
VZ
317 }
318
319 wxHtmlContainerCell *cell = (wxHtmlContainerCell *)m_htmlParser->
320 Parse(OnGetItemMarkup(n));
9a83f860 321 wxCHECK_RET( cell, wxT("wxHtmlParser::Parse() returned NULL?") );
e0c6027b 322
bc55e31b
VS
323 // set the cell's ID to item's index so that CellCoordsToPhysical()
324 // can quickly find the item:
9a83f860 325 cell->SetId(wxString::Format(wxT("%lu"), (unsigned long)n));
bc55e31b 326
5ecdc7ab 327 cell->Layout(GetClientSize().x - 2*GetMargins().x);
e0c6027b
VZ
328
329 m_cache->Store(n, cell);
330 }
331}
332
5ecdc7ab
VZ
333void wxHtmlListBox::OnSize(wxSizeEvent& event)
334{
335 // we need to relayout all the cached cells
336 m_cache->Clear();
337
338 event.Skip();
339}
340
e02c72fa 341void wxHtmlListBox::RefreshRow(size_t line)
aead8a4e
VZ
342{
343 m_cache->InvalidateRange(line, line);
344
f18eaf26 345 wxVListBox::RefreshRow(line);
aead8a4e
VZ
346}
347
e02c72fa 348void wxHtmlListBox::RefreshRows(size_t from, size_t to)
aead8a4e
VZ
349{
350 m_cache->InvalidateRange(from, to);
351
f18eaf26 352 wxVListBox::RefreshRows(from, to);
aead8a4e
VZ
353}
354
5ecdc7ab
VZ
355void wxHtmlListBox::RefreshAll()
356{
357 m_cache->Clear();
358
359 wxVListBox::RefreshAll();
360}
361
03495767
VZ
362void wxHtmlListBox::SetItemCount(size_t count)
363{
364 // the items are going to change, forget the old ones
365 m_cache->Clear();
366
367 wxVListBox::SetItemCount(count);
368}
369
e0c6027b
VZ
370// ----------------------------------------------------------------------------
371// wxHtmlListBox implementation of wxVListBox pure virtuals
372// ----------------------------------------------------------------------------
373
c848185a
VZ
374void
375wxHtmlListBox::OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const
376{
377 if ( IsSelected(n) )
378 {
379 if ( DoDrawSolidBackground
380 (
381 GetSelectedTextBgColour(GetBackgroundColour()),
382 dc,
383 rect,
384 n
385 ) )
386 {
387 return;
388 }
389 //else: no custom selection background colour, use base class version
390 }
391
392 wxVListBox::OnDrawBackground(dc, rect, n);
393}
394
e0c6027b
VZ
395void wxHtmlListBox::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const
396{
397 CacheItem(n);
398
399 wxHtmlCell *cell = m_cache->Get(n);
9a83f860 400 wxCHECK_RET( cell, wxT("this cell should be cached!") );
e0c6027b 401
901b583c 402 wxHtmlRenderingInfo htmlRendInfo;
5ecdc7ab 403
c848185a
VZ
404 // draw the selected cell in selected state ourselves if we're using custom
405 // colours (to test for this, check the callbacks by passing them any dummy
406 // (but valid, to avoid asserts) colour):
407 if ( IsSelected(n) &&
408 (GetSelectedTextColour(*wxBLACK).IsOk() ||
409 GetSelectedTextBgColour(*wxWHITE).IsOk()) )
410 {
411 wxHtmlSelection htmlSel;
412 htmlSel.Set(wxPoint(0,0), cell, wxPoint(INT_MAX, INT_MAX), cell);
413 htmlRendInfo.SetSelection(&htmlSel);
414 htmlRendInfo.SetStyle(m_htmlRendStyle);
415 htmlRendInfo.GetState().SetSelectionState(wxHTML_SEL_IN);
416 }
417 //else: normal item or selected item with default colours, its background
418 // was already taken care of in the base class
419
5ecdc7ab
VZ
420 // note that we can't stop drawing exactly at the window boundary as then
421 // even the visible cells part could be not drawn, so always draw the
422 // entire cell
bc55e31b
VS
423 cell->Draw(dc,
424 rect.x + CELL_BORDER, rect.y + CELL_BORDER,
425 0, INT_MAX, htmlRendInfo);
e0c6027b
VZ
426}
427
428wxCoord wxHtmlListBox::OnMeasureItem(size_t n) const
429{
430 CacheItem(n);
431
432 wxHtmlCell *cell = m_cache->Get(n);
9a83f860 433 wxCHECK_MSG( cell, 0, wxT("this cell should be cached!") );
e0c6027b 434
d3017584 435 return cell->GetHeight() + cell->GetDescent() + 4;
e0c6027b
VZ
436}
437
bc55e31b
VS
438// ----------------------------------------------------------------------------
439// wxHtmlListBox implementation of wxHtmlListBoxWinInterface
440// ----------------------------------------------------------------------------
441
442void wxHtmlListBox::SetHTMLWindowTitle(const wxString& WXUNUSED(title))
443{
444 // nothing to do
445}
446
447void wxHtmlListBox::OnHTMLLinkClicked(const wxHtmlLinkInfo& link)
448{
449 OnLinkClicked(GetItemForCell(link.GetHtmlCell()), link);
450}
451
a3b5cead
VS
452void wxHtmlListBox::OnLinkClicked(size_t WXUNUSED(n),
453 const wxHtmlLinkInfo& link)
454{
455 wxHtmlLinkEvent event(GetId(), link);
456 GetEventHandler()->ProcessEvent(event);
457}
458
bc55e31b
VS
459wxHtmlOpeningStatus
460wxHtmlListBox::OnHTMLOpeningURL(wxHtmlURLType WXUNUSED(type),
461 const wxString& WXUNUSED(url),
462 wxString *WXUNUSED(redirect)) const
463{
464 return wxHTML_OPEN;
465}
466
467wxPoint wxHtmlListBox::HTMLCoordsToWindow(wxHtmlCell *cell,
468 const wxPoint& pos) const
469{
470 return CellCoordsToPhysical(pos, cell);
471}
472
473wxWindow* wxHtmlListBox::GetHTMLWindow() { return this; }
474
475wxColour wxHtmlListBox::GetHTMLBackgroundColour() const
476{
477 return GetBackgroundColour();
478}
479
480void wxHtmlListBox::SetHTMLBackgroundColour(const wxColour& WXUNUSED(clr))
481{
482 // nothing to do
483}
484
485void wxHtmlListBox::SetHTMLBackgroundImage(const wxBitmap& WXUNUSED(bmpBg))
486{
487 // nothing to do
488}
489
490void wxHtmlListBox::SetHTMLStatusText(const wxString& WXUNUSED(text))
491{
492 // nothing to do
493}
494
88a1b648
VS
495wxCursor wxHtmlListBox::GetHTMLCursor(HTMLCursor type) const
496{
497 // we don't want to show text selection cursor in listboxes
498 if (type == HTMLCursor_Text)
499 return wxHtmlWindow::GetDefaultHTMLCursor(HTMLCursor_Default);
500
501 // in all other cases, use the same cursor as wxHtmlWindow:
502 return wxHtmlWindow::GetDefaultHTMLCursor(type);
503}
504
bc55e31b
VS
505// ----------------------------------------------------------------------------
506// wxHtmlListBox handling of HTML links
507// ----------------------------------------------------------------------------
aead8a4e 508
bc55e31b
VS
509wxPoint wxHtmlListBox::GetRootCellCoords(size_t n) const
510{
511 wxPoint pos(CELL_BORDER, CELL_BORDER);
512 pos += GetMargins();
e02c72fa 513 pos.y += GetRowsHeight(GetVisibleBegin(), n);
bc55e31b
VS
514 return pos;
515}
516
517bool wxHtmlListBox::PhysicalCoordsToCell(wxPoint& pos, wxHtmlCell*& cell) const
518{
10368bff 519 int n = VirtualHitTest(pos.y);
bc55e31b
VS
520 if ( n == wxNOT_FOUND )
521 return false;
522
523 // convert mouse coordinates to coords relative to item's wxHtmlCell:
524 pos -= GetRootCellCoords(n);
525
526 CacheItem(n);
527 cell = m_cache->Get(n);
528
529 return true;
530}
531
532size_t wxHtmlListBox::GetItemForCell(const wxHtmlCell *cell) const
533{
9a83f860 534 wxCHECK_MSG( cell, 0, wxT("no cell") );
bc55e31b
VS
535
536 cell = cell->GetRootCell();
537
9a83f860 538 wxCHECK_MSG( cell, 0, wxT("no root cell") );
bc55e31b
VS
539
540 // the cell's ID contains item index, see CacheItem():
541 unsigned long n;
542 if ( !cell->GetId().ToULong(&n) )
543 {
9a83f860 544 wxFAIL_MSG( wxT("unexpected root cell's ID") );
bc55e31b
VS
545 return 0;
546 }
547
548 return n;
549}
550
551wxPoint
552wxHtmlListBox::CellCoordsToPhysical(const wxPoint& pos, wxHtmlCell *cell) const
553{
554 return pos + GetRootCellCoords(GetItemForCell(cell));
555}
556
557void wxHtmlListBox::OnInternalIdle()
558{
559 wxVListBox::OnInternalIdle();
560
561 if ( wxHtmlWindowMouseHelper::DidMouseMove() )
562 {
563 wxPoint pos = ScreenToClient(wxGetMousePosition());
564 wxHtmlCell *cell;
565
566 if ( !PhysicalCoordsToCell(pos, cell) )
567 return;
568
569 wxHtmlWindowMouseHelper::HandleIdle(cell, pos);
570 }
571}
572
573void wxHtmlListBox::OnMouseMove(wxMouseEvent& event)
574{
575 wxHtmlWindowMouseHelper::HandleMouseMoved();
576 event.Skip();
577}
578
579void wxHtmlListBox::OnLeftDown(wxMouseEvent& event)
580{
581 wxPoint pos = event.GetPosition();
582 wxHtmlCell *cell;
583
584 if ( !PhysicalCoordsToCell(pos, cell) )
585 {
586 event.Skip();
587 return;
588 }
589
590 if ( !wxHtmlWindowMouseHelper::HandleMouseClick(cell, pos, event) )
591 {
592 // no link was clicked, so let the listbox code handle the click (e.g.
593 // by selecting another item in the list):
594 event.Skip();
595 }
596}
597
9ebb7cad
VZ
598
599// ----------------------------------------------------------------------------
600// wxSimpleHtmlListBox
601// ----------------------------------------------------------------------------
602
603bool wxSimpleHtmlListBox::Create(wxWindow *parent, wxWindowID id,
604 const wxPoint& pos,
605 const wxSize& size,
606 int n, const wxString choices[],
607 long style,
608 const wxValidator& validator,
609 const wxString& name)
610{
611 if (!wxHtmlListBox::Create(parent, id, pos, size, style, name))
612 return false;
613
9a9b5822 614#if wxUSE_VALIDATORS
9ebb7cad 615 SetValidator(validator);
9a9b5822 616#endif
a236aa20
VZ
617
618 Append(n, choices);
9ebb7cad
VZ
619
620 return true;
621}
622
623bool wxSimpleHtmlListBox::Create(wxWindow *parent, wxWindowID id,
a236aa20
VZ
624 const wxPoint& pos,
625 const wxSize& size,
626 const wxArrayString& choices,
627 long style,
628 const wxValidator& validator,
629 const wxString& name)
9ebb7cad
VZ
630{
631 if (!wxHtmlListBox::Create(parent, id, pos, size, style, name))
632 return false;
633
9a9b5822 634#if wxUSE_VALIDATORS
9ebb7cad 635 SetValidator(validator);
9a9b5822 636#endif
a236aa20 637
9ebb7cad
VZ
638 Append(choices);
639
640 return true;
641}
642
643wxSimpleHtmlListBox::~wxSimpleHtmlListBox()
644{
a236aa20 645 wxItemContainer::Clear();
9ebb7cad
VZ
646}
647
a236aa20 648void wxSimpleHtmlListBox::DoClear()
9ebb7cad 649{
a236aa20
VZ
650 wxASSERT(m_items.GetCount() == m_HTMLclientData.GetCount());
651
9ebb7cad 652 m_items.Clear();
9d8f8138 653 m_HTMLclientData.Clear();
a236aa20 654
9ebb7cad
VZ
655 UpdateCount();
656}
657
e52cd41e
VZ
658void wxSimpleHtmlListBox::Clear()
659{
660 DoClear();
661}
662
a236aa20 663void wxSimpleHtmlListBox::DoDeleteOneItem(unsigned int n)
9ebb7cad
VZ
664{
665 m_items.RemoveAt(n);
a236aa20 666
9d8f8138 667 m_HTMLclientData.RemoveAt(n);
9ebb7cad 668
9ebb7cad
VZ
669 UpdateCount();
670}
671
a236aa20
VZ
672int wxSimpleHtmlListBox::DoInsertItems(const wxArrayStringsAdapter& items,
673 unsigned int pos,
674 void **clientData,
675 wxClientDataType type)
9ebb7cad 676{
a236aa20
VZ
677 const unsigned int count = items.GetCount();
678
679 m_items.Insert(wxEmptyString, pos, count);
680 m_HTMLclientData.Insert(NULL, pos, count);
681
682 for ( unsigned int i = 0; i < count; ++i, ++pos )
683 {
684 m_items[pos] = items[i];
685 AssignNewItemClientData(pos, clientData, i, type);
686 }
9ebb7cad 687
9ebb7cad 688 UpdateCount();
a236aa20 689
9ebb7cad
VZ
690 return pos;
691}
692
693void wxSimpleHtmlListBox::SetString(unsigned int n, const wxString& s)
694{
695 wxCHECK_RET( IsValid(n),
696 wxT("invalid index in wxSimpleHtmlListBox::SetString") );
697
a236aa20 698 m_items[n]=s;
e02c72fa 699 RefreshRow(n);
9ebb7cad
VZ
700}
701
702wxString wxSimpleHtmlListBox::GetString(unsigned int n) const
703{
704 wxCHECK_MSG( IsValid(n), wxEmptyString,
705 wxT("invalid index in wxSimpleHtmlListBox::GetString") );
706
707 return m_items[n];
708}
709
710void wxSimpleHtmlListBox::UpdateCount()
711{
9d8f8138 712 wxASSERT(m_items.GetCount() == m_HTMLclientData.GetCount());
9ebb7cad
VZ
713 wxHtmlListBox::SetItemCount(m_items.GetCount());
714
715 // very small optimization: if you need to add lot of items to
716 // a wxSimpleHtmlListBox be sure to use the
717 // wxSimpleHtmlListBox::Append(const wxArrayString&) method instead!
718 if (!this->IsFrozen())
719 RefreshAll();
720}
721
bc55e31b 722#endif // wxUSE_HTML