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