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