+ wxColour *m_highlightColour;
+ int m_xScroll,
+ m_yScroll;
+ wxImageList *m_small_image_list;
+ wxImageList *m_normal_image_list;
+ int m_small_spacing;
+ int m_normal_spacing;
+ bool m_hasFocus;
+
+ bool m_lastOnSame;
+ wxTimer *m_renameTimer;
+ bool m_renameAccept;
+ wxString m_renameRes;
+ bool m_isCreated;
+ int m_dragCount;
+ wxPoint m_dragStart;
+
+ // for double click logic
+ size_t m_lineLastClicked,
+ m_lineBeforeLastClicked;
+
+protected:
+ // the total count of items in a virtual list control
+ size_t m_countVirt;
+
+ // the object maintaining the items selection state, only used in virtual
+ // controls
+ wxSelectionStore m_selStore;
+
+ // common part of all ctors
+ void Init();
+
+ // intiialize m_[xy]Scroll
+ void InitScrolling();
+
+ // get the line data for the given index
+ wxListLineData *GetLine(size_t n) const
+ {
+ wxASSERT_MSG( n != (size_t)-1, _T("invalid line index") );
+
+ if ( IsVirtual() )
+ {
+ wxConstCast(this, wxListMainWindow)->CacheLineData(n);
+
+ n = 0;
+ }
+
+ return &m_lines[n];
+ }
+
+ // get a dummy line which can be used for geometry calculations and such:
+ // you must use GetLine() if you want to really draw the line
+ wxListLineData *GetDummyLine() const;
+
+ // cache the line data of the n-th line in m_lines[0]
+ void CacheLineData(size_t line);
+
+ // get the range of visible lines
+ void GetVisibleLinesRange(size_t *from, size_t *to);
+
+ // force us to recalculate the range of visible lines
+ void ResetVisibleLinesRange() { m_lineFrom = (size_t)-1; }
+
+ // get the colour to be used for drawing the rules
+ wxColour GetRuleColour() const
+ {
+#ifdef __WXMAC__
+ return *wxWHITE;
+#else
+ return wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT);
+#endif
+ }
+
+private:
+ // initialize the current item if needed
+ void UpdateCurrent();
+
+ // delete all items but don't refresh: called from dtor
+ void DoDeleteAllItems();
+
+ // called when an item is [un]focuded, i.e. becomes [not] current
+ //
+ // currently unused
+ void OnFocusLine( size_t line );
+ void OnUnfocusLine( size_t line );
+
+ // the height of one line using the current font
+ wxCoord m_lineHeight;
+
+ // the total header width or 0 if not calculated yet
+ wxCoord m_headerWidth;
+
+ // the first and last lines being shown on screen right now (inclusive),
+ // both may be -1 if they must be calculated so never access them directly:
+ // use GetVisibleLinesRange() above instead
+ size_t m_lineFrom,
+ m_lineTo;
+
+ // the brushes to use for item highlighting when we do/don't have focus
+ wxBrush *m_highlightBrush,
+ *m_highlightUnfocusedBrush;
+
+ DECLARE_DYNAMIC_CLASS(wxListMainWindow);
+ DECLARE_EVENT_TABLE()
+};
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxSelectionStore
+// ----------------------------------------------------------------------------
+
+bool wxSelectionStore::IsSelected(size_t item) const
+{
+ bool isSel = m_itemsSel.Index(item) != wxNOT_FOUND;
+
+ // if the default state is to be selected, being in m_itemsSel means that
+ // the item is not selected, so we have to inverse the logic
+ return m_defaultState ? !isSel : isSel;
+}
+
+bool wxSelectionStore::SelectItem(size_t item, bool select)
+{
+ // search for the item ourselves as like this we get the index where to
+ // insert it later if needed, so we do only one search in the array instead
+ // of two (adding item to a sorted array requires a search)
+ size_t index = m_itemsSel.IndexForInsert(item);
+ bool isSel = index < m_itemsSel.GetCount() && m_itemsSel[index] == item;
+
+ if ( select != m_defaultState )
+ {
+ if ( !isSel )
+ {
+ m_itemsSel.AddAt(item, index);
+
+ return TRUE;
+ }
+ }
+ else // reset to default state
+ {
+ if ( isSel )
+ {
+ m_itemsSel.RemoveAt(index);
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+bool wxSelectionStore::SelectRange(size_t itemFrom, size_t itemTo,
+ bool select,
+ wxArrayInt *itemsChanged)
+{
+ // 100 is hardcoded but it shouldn't matter much: the important thing is
+ // that we don't refresh everything when really few (e.g. 1 or 2) items
+ // change state
+ static const size_t MANY_ITEMS = 100;
+
+ wxASSERT_MSG( itemFrom <= itemTo, _T("should be in order") );
+
+ // are we going to have more [un]selected items than the other ones?
+ if ( itemTo - itemFrom > m_count/2 )
+ {
+ if ( select != m_defaultState )
+ {
+ // the default state now becomes the same as 'select'
+ m_defaultState = select;
+
+ // so all the old selections (which had state select) shouldn't be
+ // selected any more, but all the other ones should
+ wxIndexArray selOld = m_itemsSel;
+ m_itemsSel.Empty();
+
+ // TODO: it should be possible to optimize the searches a bit
+ // knowing the possible range
+
+ size_t item;
+ for ( item = 0; item < itemFrom; item++ )
+ {
+ if ( selOld.Index(item) == wxNOT_FOUND )
+ m_itemsSel.Add(item);
+ }
+
+ for ( item = itemTo + 1; item < m_count; item++ )
+ {
+ if ( selOld.Index(item) == wxNOT_FOUND )
+ m_itemsSel.Add(item);
+ }
+
+ // many items (> half) changed state
+ itemsChanged = NULL;
+ }
+ else // select == m_defaultState
+ {
+ // get the inclusive range of items between itemFrom and itemTo
+ size_t count = m_itemsSel.GetCount(),
+ start = m_itemsSel.IndexForInsert(itemFrom),
+ end = m_itemsSel.IndexForInsert(itemTo);
+
+ if ( start == count || m_itemsSel[start] < itemFrom )
+ {
+ start++;
+ }
+
+ if ( end == count || m_itemsSel[end] > itemTo )
+ {
+ end--;
+ }
+
+ if ( start <= end )
+ {
+ // delete all of them (from end to avoid changing indices)
+ for ( int i = end; i >= (int)start; i-- )
+ {
+ if ( itemsChanged )
+ {
+ if ( itemsChanged->GetCount() > MANY_ITEMS )
+ {
+ // stop counting (see comment below)
+ itemsChanged = NULL;
+ }
+
+ itemsChanged->Add(m_itemsSel[i]);
+ }
+
+ m_itemsSel.RemoveAt(i);
+ }
+ }
+ }
+ }
+ else // "few" items change state
+ {
+ if ( itemsChanged )
+ {
+ itemsChanged->Empty();
+ }
+
+ // just add the items to the selection
+ for ( size_t item = itemFrom; item <= itemTo; item++ )
+ {
+ if ( SelectItem(item, select) && itemsChanged )
+ {
+ itemsChanged->Add(item);
+
+ if ( itemsChanged->GetCount() > MANY_ITEMS )
+ {
+ // stop counting them, we'll just eat gobs of memory
+ // for nothing at all - faster to refresh everything in
+ // this case
+ itemsChanged = NULL;
+ }
+ }
+ }
+ }
+
+ // we set it to NULL if there are many items changing state
+ return itemsChanged != NULL;
+}
+
+void wxSelectionStore::OnItemDelete(size_t item)
+{
+ size_t count = m_itemsSel.GetCount(),
+ i = m_itemsSel.IndexForInsert(item);
+
+ if ( i < count && m_itemsSel[i] == item )
+ {
+ // this item itself was in m_itemsSel, remove it from there
+ m_itemsSel.RemoveAt(i);
+
+ count--;
+ }
+
+ // and adjust the index of all which follow it
+ while ( i < count )
+ {
+ // all following elements must be greater than the one we deleted
+ wxASSERT_MSG( m_itemsSel[i] > item, _T("logic error") );
+
+ m_itemsSel[i++]--;
+ }
+}
+
+//-----------------------------------------------------------------------------
+// wxListItemData
+//-----------------------------------------------------------------------------
+
+wxListItemData::~wxListItemData()
+{
+ // in the virtual list control the attributes are managed by the main
+ // program, so don't delete them
+ if ( !m_owner->IsVirtual() )
+ {
+ delete m_attr;
+ }
+
+ delete m_rect;
+}
+
+void wxListItemData::Init()
+{
+ m_image = -1;
+ m_data = 0;
+
+ m_attr = NULL;
+}
+
+wxListItemData::wxListItemData(wxListMainWindow *owner)
+{
+ Init();
+
+ m_owner = owner;
+
+ if ( owner->InReportView() )
+ {
+ m_rect = NULL;
+ }
+ else
+ {
+ m_rect = new wxRect;
+ }
+}
+
+void wxListItemData::SetItem( const wxListItem &info )
+{
+ if ( info.m_mask & wxLIST_MASK_TEXT )
+ SetText(info.m_text);
+ if ( info.m_mask & wxLIST_MASK_IMAGE )
+ m_image = info.m_image;
+ if ( info.m_mask & wxLIST_MASK_DATA )
+ m_data = info.m_data;
+
+ if ( info.HasAttributes() )
+ {
+ if ( m_attr )
+ *m_attr = *info.GetAttributes();
+ else
+ m_attr = new wxListItemAttr(*info.GetAttributes());
+ }
+
+ if ( m_rect )
+ {
+ m_rect->x =
+ m_rect->y =
+ m_rect->height = 0;
+ m_rect->width = info.m_width;
+ }
+}
+
+void wxListItemData::SetPosition( int x, int y )
+{
+ wxCHECK_RET( m_rect, _T("unexpected SetPosition() call") );
+
+ m_rect->x = x;
+ m_rect->y = y;
+}
+
+void wxListItemData::SetSize( int width, int height )
+{
+ wxCHECK_RET( m_rect, _T("unexpected SetSize() call") );
+
+ if ( width != -1 )
+ m_rect->width = width;
+ if ( height != -1 )
+ m_rect->height = height;
+}
+
+bool wxListItemData::IsHit( int x, int y ) const
+{
+ wxCHECK_MSG( m_rect, FALSE, _T("can't be called in this mode") );
+
+ return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x, y);
+}
+
+int wxListItemData::GetX() const
+{
+ wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
+
+ return m_rect->x;
+}
+
+int wxListItemData::GetY() const
+{
+ wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
+
+ return m_rect->y;
+}
+
+int wxListItemData::GetWidth() const
+{
+ wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
+
+ return m_rect->width;
+}
+
+int wxListItemData::GetHeight() const
+{
+ wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
+
+ return m_rect->height;
+}