X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ea5ac909f8bede0af4513c4732c65a1f4ff89daf..68cb30154e69c03d141aa649f024e916c5a96540:/src/generic/listctrl.cpp diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 0aa77ae8db..ac003ce0bc 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -1,12 +1,20 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: listctrl.cpp -// Purpose: +// Name: generic/listctrl.cpp +// Purpose: generic implementation of wxListCtrl // Author: Robert Roebling // Id: $Id$ // Copyright: (c) 1998 Robert Roebling // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + #ifdef __GNUG__ #pragma implementation "listctrl.h" #pragma implementation "listctrlbase.h" @@ -19,6 +27,8 @@ #pragma hdrstop #endif +#if wxUSE_LISTCTRL + #include "wx/dcscreen.h" #include "wx/app.h" #include "wx/listctrl.h" @@ -34,6 +44,27 @@ #define wxUSE_GENERIC_LIST_EXTENSIONS 1 #endif +// ---------------------------------------------------------------------------- +// events +// ---------------------------------------------------------------------------- + +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED) + // ============================================================================ // private classes // ============================================================================ @@ -44,31 +75,24 @@ class WXDLLEXPORT wxListItemData : public wxObject { -public: - wxString m_text; - int m_image; - long m_data; - int m_xpos,m_ypos; - int m_width,m_height; - - wxListItemAttr *m_attr; - public: wxListItemData(); ~wxListItemData() { delete m_attr; } wxListItemData( const wxListItem &info ); void SetItem( const wxListItem &info ); - void SetText( const wxString &s ); void SetImage( int image ); void SetData( long data ); void SetPosition( int x, int y ); void SetSize( int width, int height ); bool HasImage() const; - bool HasText() const; + + bool HasText() const { return !m_text.empty(); } + const wxString& GetText() const { return m_text; } + void SetText(const wxString& text) { m_text = text; } + bool IsHit( int x, int y ) const; - void GetText( wxString &s ); - const wxString& GetText() { return m_text; } + int GetX( void ) const; int GetY( void ) const; int GetWidth() const; @@ -78,6 +102,19 @@ public: wxListItemAttr *GetAttributes() const { return m_attr; } +public: + int m_image; + long m_data; + int m_xpos, + m_ypos; + int m_width, + m_height; + + wxListItemAttr *m_attr; + +protected: + wxString m_text; + private: DECLARE_DYNAMIC_CLASS(wxListItemData); }; @@ -94,7 +131,8 @@ protected: wxString m_text; int m_format; int m_width; - int m_xpos,m_ypos; + int m_xpos, + m_ypos; int m_height; public: @@ -106,10 +144,14 @@ public: void SetFormat( int format ); void SetHeight( int h ); bool HasImage() const; - bool HasText() const; - bool IsHit( int x, int y ) const; + + bool HasText() const { return !m_text.empty(); } + const wxString& GetText() const { return m_text; } + void SetText(const wxString& text) { m_text = text; } + void GetItem( wxListItem &item ); - void GetText( wxString &s ); + + bool IsHit( int x, int y ) const; int GetImage() const; int GetWidth() const; int GetFormat() const; @@ -122,10 +164,14 @@ private: // wxListLineData (internal) //----------------------------------------------------------------------------- +WX_DECLARE_LIST(wxListItemData, wxListItemDataList); +#include "wx/listimpl.cpp" +WX_DEFINE_LIST(wxListItemDataList); + class WXDLLEXPORT wxListLineData : public wxObject { public: - wxList m_items; + wxListItemDataList m_items; wxRect m_bound_all; wxRect m_bound_label; wxRect m_bound_icon; @@ -151,7 +197,7 @@ public: void InitItems( int num ); void SetItem( int index, const wxListItem &info ); void GetItem( int index, wxListItem &info ); - void GetText( int index, wxString &s ); + wxString GetText(int index) const; void SetText( int index, const wxString s ); int GetImage( int index ); void GetRect( wxRect &rect ); @@ -235,7 +281,7 @@ private: class WXDLLEXPORT wxListRenameTimer: public wxTimer { private: - wxListMainWindow *m_owner; + wxListMainWindow *m_owner; public: wxListRenameTimer( wxListMainWindow *owner ); @@ -276,18 +322,36 @@ private: // wxListMainWindow (internal) //----------------------------------------------------------------------------- +WX_DECLARE_LIST(wxListHeaderData, wxListHeaderDataList); +#include "wx/listimpl.cpp" +WX_DEFINE_LIST(wxListHeaderDataList); + class WXDLLEXPORT wxListMainWindow: public wxScrolledWindow { public: + // the style of the control (combination of wxLC_XXX) long m_mode; + + // the array of all line objects for a non virtual list control wxListLineDataArray m_lines; - wxList m_columns; + + // the total count of items in a virtual list control + long m_countVirt; + + // the list of column objects + wxListHeaderDataList m_columns; + + // currently focused item or NULL wxListLineData *m_current; - wxListLineData *m_currentEdit; + + // the item currently being edited or -1 + size_t m_currentEdit; + int m_visibleLines; wxBrush *m_hilightBrush; wxColour *m_hilightColour; - int m_xScroll,m_yScroll; + int m_xScroll, + m_yScroll; bool m_dirty; wxImageList *m_small_image_list; wxImageList *m_normal_image_list; @@ -304,19 +368,29 @@ public: wxPoint m_dragStart; // for double click logic - wxListLineData *m_lineLastClicked, - *m_lineBeforeLastClicked; + size_t m_lineLastClicked, + m_lineBeforeLastClicked; public: wxListMainWindow(); - wxListMainWindow( wxWindow *parent, wxWindowID id, - const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, - long style = 0, const wxString &name = "listctrlmainwindow" ); - ~wxListMainWindow(); + wxListMainWindow( wxWindow *parent, + wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString &name = _T("listctrlmainwindow") ); + + virtual ~wxListMainWindow(); + + // return true if this is a virtual list control + bool IsVirtual() const { return (m_mode & wxLC_VIRTUAL) != 0; } + void RefreshLine( wxListLineData *line ); void OnPaint( wxPaintEvent &event ); void HilightAll( bool on ); - void SendNotify( wxListLineData *line, wxEventType command ); + void SendNotify( wxListLineData *line, + wxEventType command, + wxPoint point = wxDefaultPosition ); void FocusLine( wxListLineData *line ); void UnfocusLine( wxListLineData *line ); void SelectLine( wxListLineData *line ); @@ -356,7 +430,6 @@ public: void GetItem( wxListItem &item ); void SetItemState( long item, long state, long stateMask ); int GetItemState( long item, long stateMask ); - int GetItemCount(); void GetItemRect( long index, wxRect &rect ); bool GetItemPosition( long item, wxPoint& pos ); int GetSelectedItemCount(); @@ -379,6 +452,22 @@ public: // void AddColumn( wxListItem &item ); void SortItems( wxListCtrlCompare fn, long data ); + int GetItemCount() const; + bool IsEmpty() const { return GetItemCount() == 0; } + void SetItemCount(long count); + +protected: + // common part of all ctors + void Init(); + + // get the line data for the given index + wxListLineData *GetLine(size_t n) const + { + wxASSERT_MSG( n != (size_t)-1, _T("invalid line index") ); + + return &m_lines[n]; + } + private: DECLARE_DYNAMIC_CLASS(wxListMainWindow); DECLARE_EVENT_TABLE() @@ -416,9 +505,12 @@ wxListItemData::wxListItemData( const wxListItem &info ) void wxListItemData::SetItem( const wxListItem &info ) { - if (info.m_mask & wxLIST_MASK_TEXT) m_text = 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.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() ) { @@ -434,11 +526,6 @@ void wxListItemData::SetItem( const wxListItem &info ) m_height = 0; } -void wxListItemData::SetText( const wxString &s ) -{ - m_text = s; -} - void wxListItemData::SetImage( int image ) { m_image = image; @@ -466,21 +553,11 @@ bool wxListItemData::HasImage() const return (m_image >= 0); } -bool wxListItemData::HasText() const -{ - return (!m_text.IsNull()); -} - bool wxListItemData::IsHit( int x, int y ) const { return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height)); } -void wxListItemData::GetText( wxString &s ) -{ - s = m_text; -} - int wxListItemData::GetX() const { return m_xpos; @@ -587,11 +664,6 @@ bool wxListHeaderData::HasImage() const return (m_image != 0); } -bool wxListHeaderData::HasText() const -{ - return (m_text.Length() > 0); -} - bool wxListHeaderData::IsHit( int x, int y ) const { return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height)); @@ -606,11 +678,6 @@ void wxListHeaderData::GetItem( wxListItem &item ) item.m_width = m_width; } -void wxListHeaderData::GetText( wxString &s ) -{ - s = m_text; -} - int wxListHeaderData::GetImage() const { return m_image; @@ -644,26 +711,31 @@ wxListLineData::wxListLineData( wxListMainWindow *owner, int mode, wxBrush *hili void wxListLineData::CalculateSize( wxDC *dc, int spacing ) { + wxListItemDataList::Node *node = m_items.GetFirst(); + m_spacing = spacing; switch (m_mode) { case wxLC_ICON: { m_bound_all.width = m_spacing; - wxNode *node = m_items.First(); if (node) { - wxListItemData *item = (wxListItemData*)node->Data(); + wxListItemData *item = node->GetData(); wxString s = item->GetText(); - if (s.IsEmpty()) s = wxT("H"); + if (s.IsEmpty()) + s = wxT("H"); + wxCoord lw,lh; dc->GetTextExtent( s, &lw, &lh ); - if (lh < 15) lh = 15; + if (lh < 15) + lh = 15; lw += 4; lh += 3; m_bound_all.height = m_spacing+lh; - if (lw > m_spacing) m_bound_all.width = lw; + if (lw > m_spacing) + m_bound_all.width = lw; m_bound_label.width = lw; m_bound_label.height = lh; @@ -696,18 +768,21 @@ void wxListLineData::CalculateSize( wxDC *dc, int spacing ) } case wxLC_LIST: { - wxNode *node = m_items.First(); if (node) { - wxListItemData *item = (wxListItemData*)node->Data(); + wxListItemData *item = node->GetData(); wxString s = item->GetText(); - if (s.IsEmpty()) s = wxT("H"); + if (s.IsEmpty()) + s = wxT("H"); + wxCoord lw,lh; dc->GetTextExtent( s, &lw, &lh ); - if (lh < 15) lh = 15; + if (lh < 15) + lh = 15; lw += 4; lh += 3; + m_bound_label.width = lw; m_bound_label.height = lh; @@ -735,10 +810,9 @@ void wxListLineData::CalculateSize( wxDC *dc, int spacing ) { m_bound_all.width = 0; m_bound_all.height = 0; - wxNode *node = m_items.First(); if (node) { - wxListItemData *item = (wxListItemData*)node->Data(); + wxListItemData *item = node->GetData(); if (item->HasImage()) { int w = 0; @@ -753,21 +827,25 @@ void wxListLineData::CalculateSize( wxDC *dc, int spacing ) m_bound_icon.height = 0; } } + while (node) { - wxListItemData *item = (wxListItemData*)node->Data(); + wxListItemData *item = node->GetData(); wxString s = item->GetText(); - if (s.IsEmpty()) s = wxT("H"); + if (s.IsEmpty()) + s = wxT("H"); + wxCoord lw,lh; dc->GetTextExtent( s, &lw, &lh ); - if (lh < 15) lh = 15; + if (lh < 15) + lh = 15; lw += 4; lh += 3; item->SetSize( item->GetWidth(), lh ); m_bound_all.width += lw; m_bound_all.height = lh; - node = node->Next(); + node = node->GetNext(); } m_bound_label.width = m_bound_all.width; m_bound_label.height = m_bound_all.height; @@ -779,16 +857,18 @@ void wxListLineData::CalculateSize( wxDC *dc, int spacing ) void wxListLineData::SetPosition( wxDC * WXUNUSED(dc), int x, int y, int window_width ) { + wxListItemDataList::Node *node = m_items.GetFirst(); + m_bound_all.x = x; m_bound_all.y = y; + switch (m_mode) { case wxLC_ICON: { - wxNode *node = m_items.First(); if (node) { - wxListItemData *item = (wxListItemData*)node->Data(); + wxListItemData *item = node->GetData(); if (item->HasImage()) { m_bound_icon.x = m_bound_all.x + 4 @@ -818,10 +898,9 @@ void wxListLineData::SetPosition( wxDC * WXUNUSED(dc), m_bound_hilight.x = m_bound_all.x; m_bound_hilight.y = m_bound_all.y; m_bound_label.y = m_bound_all.y + 2; - wxNode *node = m_items.First(); if (node) { - wxListItemData *item = (wxListItemData*)node->Data(); + wxListItemData *item = node->GetData(); if (item->HasImage()) { m_bound_icon.x = m_bound_all.x + 2; @@ -842,10 +921,9 @@ void wxListLineData::SetPosition( wxDC * WXUNUSED(dc), AssignRect( m_bound_hilight, m_bound_all ); m_bound_label.x = m_bound_all.x + 2; m_bound_label.y = m_bound_all.y + 2; - wxNode *node = m_items.First(); if (node) { - wxListItemData *item = (wxListItemData*)node->Data(); + wxListItemData *item = node->GetData(); if (item->HasImage()) { m_bound_icon.x = m_bound_all.x + 2; @@ -860,10 +938,10 @@ void wxListLineData::SetPosition( wxDC * WXUNUSED(dc), void wxListLineData::SetColumnPosition( int index, int x ) { - wxNode *node = m_items.Nth( (size_t)index ); + wxListItemDataList::Node *node = m_items.Item( (size_t)index ); if (node) { - wxListItemData *item = (wxListItemData*)node->Data(); + wxListItemData *item = node->GetData(); item->SetPosition( x, m_bound_all.y+1 ); } } @@ -897,75 +975,79 @@ void wxListLineData::GetRect( wxRect &rect ) long wxListLineData::IsHit( int x, int y ) { - wxNode *node = m_items.First(); + wxListItemDataList::Node *node = m_items.GetFirst(); if (node) { - wxListItemData *item = (wxListItemData*)node->Data(); - if (item->HasImage() && IsInRect( x, y, m_bound_icon )) return wxLIST_HITTEST_ONITEMICON; - if (item->HasText() && IsInRect( x, y, m_bound_label )) return wxLIST_HITTEST_ONITEMLABEL; -// if (!(item->HasImage() || item->HasText())) return 0; + wxListItemData *item = node->GetData(); + if (item->HasImage() && IsInRect( x, y, m_bound_icon )) + return wxLIST_HITTEST_ONITEMICON; + if (item->HasText() && IsInRect( x, y, m_bound_label )) + return wxLIST_HITTEST_ONITEMLABEL; + } + // if there is no icon or text = empty - if (IsInRect( x, y, m_bound_all )) return wxLIST_HITTEST_ONITEMICON; + if (IsInRect( x, y, m_bound_all )) + return wxLIST_HITTEST_ONITEMICON; + return 0; } void wxListLineData::InitItems( int num ) { - for (int i = 0; i < num; i++) m_items.Append( new wxListItemData() ); + for (int i = 0; i < num; i++) + m_items.Append( new wxListItemData() ); } void wxListLineData::SetItem( int index, const wxListItem &info ) { - wxNode *node = m_items.Nth( index ); - if (node) - { - wxListItemData *item = (wxListItemData*)node->Data(); - item->SetItem( info ); - } + wxListItemDataList::Node *node = m_items.Item( index ); + wxCHECK_RET( node, _T("invalid column index in SetItem") ); + + wxListItemData *item = node->GetData(); + item->SetItem( info ); } void wxListLineData::GetItem( int index, wxListItem &info ) { - int i = index; - wxNode *node = m_items.Nth( i ); + wxListItemDataList::Node *node = m_items.Item( index ); if (node) { - wxListItemData *item = (wxListItemData*)node->Data(); + wxListItemData *item = node->GetData(); item->GetItem( info ); } } -void wxListLineData::GetText( int index, wxString &s ) +wxString wxListLineData::GetText(int index) const { - int i = index; - wxNode *node = m_items.Nth( i ); - s = ""; + wxString s; + + wxListItemDataList::Node *node = m_items.Item( index ); if (node) { - wxListItemData *item = (wxListItemData*)node->Data(); - item->GetText( s ); + wxListItemData *item = node->GetData(); + s = item->GetText(); } + + return s; } void wxListLineData::SetText( int index, const wxString s ) { - int i = index; - wxNode *node = m_items.Nth( i ); + wxListItemDataList::Node *node = m_items.Item( index ); if (node) { - wxListItemData *item = (wxListItemData*)node->Data(); + wxListItemData *item = node->GetData(); item->SetText( s ); } } int wxListLineData::GetImage( int index ) { - int i = index; - wxNode *node = m_items.Nth( i ); + wxListItemDataList::Node *node = m_items.Item( index ); if (node) { - wxListItemData *item = (wxListItemData*)node->Data(); + wxListItemData *item = node->GetData(); return item->GetImage(); } return -1; @@ -1029,7 +1111,7 @@ void wxListLineData::DoDraw( wxDC *dc, bool hilight, bool paintBG ) // VZ: currently we set the colours/fonts only once, but like this (i.e. // using SetAttributes() inside the loop), it will be trivial to // customize the subitems (in report mode) too. - wxListItemData *item = (wxListItemData*)m_items.First()->Data(); + wxListItemData *item = m_items.GetFirst()->GetData(); wxListItemAttr *attr = item->GetAttributes(); SetAttributes(dc, attr, colText, font, hilight); @@ -1053,12 +1135,13 @@ void wxListLineData::DoDraw( wxDC *dc, bool hilight, bool paintBG ) m_bound_hilight.width, m_bound_hilight.height ); } + wxListItemDataList::Node *node = m_items.GetFirst(); + if (m_mode == wxLC_REPORT) { - wxNode *node = m_items.First(); while (node) { - wxListItemData *item = (wxListItemData*)node->Data(); + wxListItemData *item = node->GetData(); int x = item->GetX(); if (item->HasImage()) { @@ -1073,15 +1156,14 @@ void wxListLineData::DoDraw( wxDC *dc, bool hilight, bool paintBG ) dc->DrawText( item->GetText(), x, item->GetY()+1 ); } dc->DestroyClippingRegion(); - node = node->Next(); + node = node->GetNext(); } } - else + else // !report { - wxNode *node = m_items.First(); if (node) { - wxListItemData *item = (wxListItemData*)node->Data(); + wxListItemData *item = node->GetData(); if (item->HasImage()) { m_owner->DrawImage( item->GetImage(), dc, m_bound_icon.x, m_bound_icon.y ); @@ -1201,11 +1283,11 @@ void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h ) #ifdef __WXGTK__ GtkStateType state = GTK_STATE_NORMAL; if (!m_parent->IsEnabled()) state = GTK_STATE_INSENSITIVE; - + x = dc->XLOG2DEV( x ); - - gtk_paint_box (m_wxwindow->style, GTK_PIZZA(m_wxwindow)->bin_window, state, GTK_SHADOW_OUT, - (GdkRectangle*) NULL, m_wxwindow, "button", x-1, y-1, w+2, h+2); + + gtk_paint_box (m_wxwindow->style, GTK_PIZZA(m_wxwindow)->bin_window, state, GTK_SHADOW_OUT, + (GdkRectangle*) NULL, m_wxwindow, "button", x-1, y-1, w+2, h+2); #else const int m_corner = 1; @@ -1247,7 +1329,12 @@ void wxListHeaderWindow::AdjustDC(wxDC& dc) void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) { +#ifdef __WXGTK__ + wxClientDC dc( this ); +#else wxPaintDC dc( this ); +#endif + PrepareDC( dc ); AdjustDC( dc ); @@ -1293,7 +1380,7 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) DoDrawRect( &dc, x, y, cw, h-2 ); dc.SetClippingRegion( x, y, cw-5, h-4 ); - dc.DrawText( item.m_text, x+4, y+3 ); + dc.DrawText( item.GetText(), x+4, y+3 ); dc.DestroyClippingRegion(); x += wCol; @@ -1470,7 +1557,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl,wxTextCtrl); BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl) EVT_CHAR (wxListTextCtrl::OnChar) - EVT_KEY_UP (wxListTextCtrl::OnKeyUp) + EVT_KEY_UP (wxListTextCtrl::OnKeyUp) EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus) END_EVENT_TABLE() @@ -1535,7 +1622,7 @@ void wxListTextCtrl::OnKeyUp( wxKeyEvent &event ) if (myPos.x + sx > parentSize.x) sx = parentSize.x - myPos.x; if (mySize.x > sx) sx = mySize.x; SetSize(sx, -1); - + event.Skip(); } @@ -1565,49 +1652,59 @@ BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow) EVT_SCROLLWIN (wxListMainWindow::OnScroll) END_EVENT_TABLE() -wxListMainWindow::wxListMainWindow() +void wxListMainWindow::Init() { - m_mode = 0; m_columns.DeleteContents( TRUE ); m_current = (wxListLineData *) NULL; - m_visibleLines = 0; - m_hilightBrush = (wxBrush *) NULL; - m_xScroll = 0; - m_yScroll = 0; m_dirty = TRUE; + m_visibleLines = 0; + m_small_image_list = (wxImageList *) NULL; m_normal_image_list = (wxImageList *) NULL; + m_small_spacing = 30; m_normal_spacing = 40; + m_hasFocus = FALSE; + m_dragCount = 0; + m_isCreated = FALSE; + m_usedKeys = TRUE; m_lastOnSame = FALSE; m_renameTimer = new wxListRenameTimer( this ); - m_isCreated = FALSE; - m_dragCount = 0; + m_renameAccept = FALSE; + + m_currentEdit = (size_t)-1; m_lineLastClicked = - m_lineBeforeLastClicked = (wxListLineData *)NULL; + m_lineBeforeLastClicked = (size_t)-1; } -wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id, - const wxPoint &pos, const wxSize &size, - long style, const wxString &name ) : - wxScrolledWindow( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name ) +wxListMainWindow::wxListMainWindow() { + Init(); + + m_mode = 0; + + m_hilightBrush = (wxBrush *) NULL; + + m_xScroll = + m_yScroll = 0; +} + +wxListMainWindow::wxListMainWindow( wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString &name ) + : wxScrolledWindow( parent, id, pos, size, + style | wxHSCROLL | wxVSCROLL, name ) +{ + Init(); + m_mode = style; - m_columns.DeleteContents( TRUE ); - m_current = (wxListLineData *) NULL; - m_dirty = TRUE; - m_visibleLines = 0; m_hilightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID ); - m_small_image_list = (wxImageList *) NULL; - m_normal_image_list = (wxImageList *) NULL; - m_small_spacing = 30; - m_normal_spacing = 40; - m_hasFocus = FALSE; - m_dragCount = 0; - m_isCreated = FALSE; wxSize sz = size; sz.y = 25; @@ -1627,11 +1724,6 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id, } SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 ); - m_usedKeys = TRUE; - m_lastOnSame = FALSE; - m_renameTimer = new wxListRenameTimer( this ); - m_renameAccept = FALSE; - SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) ); } @@ -1665,11 +1757,23 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) // Note: a wxPaintDC must be constructed even if no drawing is // done (a Windows requirement). wxPaintDC dc( this ); + + if (m_dirty) + { + // postpone redrawing until the next OnIdle() call to minimize flicker + return; + } + PrepareDC( dc ); - if (m_dirty) return; + int dev_x, dev_y; + CalcScrolledPosition( 0, 0, &dev_x, &dev_y ); - if (m_lines.GetCount() == 0) return; + if ( GetItemCount() == 0 ) + { + // empty control. nothing to draw + return; + } dc.BeginDrawing(); @@ -1678,9 +1782,6 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) if (m_mode & wxLC_REPORT) { wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID); - dc.SetPen(pen); - dc.SetBrush(* wxTRANSPARENT_BRUSH); - wxSize clientSize = GetClientSize(); int lineSpacing = 0; @@ -1692,22 +1793,32 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) int y_s = m_yScroll*GetScrollPos( wxVERTICAL ); size_t i_to = y_s / lineSpacing + m_visibleLines+2; - if (i_to >= m_lines.GetCount()) i_to = m_lines.GetCount(); + if (i_to >= m_lines.GetCount()) + i_to = m_lines.GetCount(); + size_t i; for (i = y_s / lineSpacing; i < i_to; i++) { m_lines[i].Draw( &dc ); // Draw horizontal rule if required - if (GetWindowStyle() & wxLC_HRULES) - dc.DrawLine(0, i*lineSpacing, clientSize.x, i*lineSpacing); + if (m_mode & wxLC_HRULES) + { + dc.SetPen(pen); + dc.SetBrush(* wxTRANSPARENT_BRUSH); + dc.DrawLine(0 - dev_x , i*lineSpacing , clientSize.x - dev_x , i*lineSpacing ); + } } // Draw last horizontal rule - if ((i > (size_t) (y_s / lineSpacing)) && (GetWindowStyle() & wxLC_HRULES)) - dc.DrawLine(0, i*lineSpacing, clientSize.x, i*lineSpacing); + if ((i > (size_t) (y_s / lineSpacing)) && (m_mode & wxLC_HRULES)) + { + dc.SetPen(pen); + dc.SetBrush(* wxTRANSPARENT_BRUSH); + dc.DrawLine(0 - dev_x , i*lineSpacing , clientSize.x - dev_x , i*lineSpacing ); + } // Draw vertical rules if required - if ((GetWindowStyle() & wxLC_VRULES) && (GetItemCount() > 0)) + if ((m_mode & wxLC_VRULES) && (GetItemCount() > 0)) { int col = 0; wxRect firstItemRect; @@ -1715,28 +1826,33 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) GetItemRect(0, firstItemRect); GetItemRect(GetItemCount() - 1, lastItemRect); int x = firstItemRect.GetX(); + dc.SetPen(pen); + dc.SetBrush(* wxTRANSPARENT_BRUSH); for (col = 0; col < GetColumnCount(); col++) { int colWidth = GetColumnWidth(col); x += colWidth ; - dc.DrawLine(x, firstItemRect.GetY() - 1, x, lastItemRect.GetBottom() + 1); + dc.DrawLine(x - dev_x, firstItemRect.GetY() - 1 - dev_y, x - dev_x, lastItemRect.GetBottom() + 1 - dev_y); } } } - else + else // !report mode { - for (size_t i = 0; i < m_lines.GetCount(); i++) + size_t count = GetItemCount(); + for (size_t i = 0; i < count; i++) m_lines[i].Draw( &dc ); } - if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus ); + if (m_current) + m_current->DrawRubberBand( &dc, m_hasFocus ); dc.EndDrawing(); } void wxListMainWindow::HilightAll( bool on ) { - for (size_t i = 0; i < m_lines.GetCount(); i++) + size_t count = GetItemCount(); + for (size_t i = 0; i < count; i++) { wxListLineData *line = &m_lines[i]; if (line->IsHilighted() != on) @@ -1747,11 +1863,18 @@ void wxListMainWindow::HilightAll( bool on ) } } -void wxListMainWindow::SendNotify( wxListLineData *line, wxEventType command ) +void wxListMainWindow::SendNotify( wxListLineData *line, + wxEventType command, + wxPoint point ) { wxListEvent le( command, GetParent()->GetId() ); le.SetEventObject( GetParent() ); le.m_itemIndex = GetIndexOfLine( line ); + + // set only for events which have position + if ( point != wxDefaultPosition ) + le.m_pointDrag = point; + line->GetItem( 0, le.m_item ); GetParent()->GetEventHandler()->ProcessEvent( le ); // GetParent()->GetEventHandler()->AddPendingEvent( le ); @@ -1786,15 +1909,17 @@ void wxListMainWindow::DeleteLine( wxListLineData *line ) void wxListMainWindow::EditLabel( long item ) { - wxCHECK_RET( ((size_t)item < m_lines.GetCount()), + wxCHECK_RET( (item >= 0) && (item < GetItemCount()), wxT("wrong index in wxListCtrl::Edit()") ); - m_currentEdit = &m_lines[(size_t)item]; + m_currentEdit = (size_t)item; wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() ); le.SetEventObject( GetParent() ); - le.m_itemIndex = GetIndexOfLine( m_currentEdit ); - m_currentEdit->GetItem( 0, le.m_item ); + le.m_itemIndex = item; + wxListLineData *data = GetLine(m_currentEdit); + wxCHECK_RET( data, _T("invalid index in EditLabel()") ); + data->GetItem( 0, le.m_item ); GetParent()->GetEventHandler()->ProcessEvent( le ); if (!le.IsAllowed()) @@ -1805,13 +1930,12 @@ void wxListMainWindow::EditLabel( long item ) // update taken place. if (m_dirty) wxYield(); - wxString s; - m_currentEdit->GetText( 0, s ); + wxString s = data->GetText(0); int x = 0; int y = 0; int w = 0; int h = 0; - m_currentEdit->GetLabelExtent( x, y, w, h ); + data->GetLabelExtent( x, y, w, h ); wxClientDC dc(this); PrepareDC( dc ); @@ -1834,8 +1958,12 @@ void wxListMainWindow::OnRenameAccept() { wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); le.SetEventObject( GetParent() ); - le.m_itemIndex = GetIndexOfLine( m_currentEdit ); - m_currentEdit->GetItem( 0, le.m_item ); + le.m_itemIndex = m_currentEdit; + + wxListLineData *data = GetLine(m_currentEdit); + wxCHECK_RET( data, _T("invalid index in OnRenameAccept()") ); + + data->GetItem( 0, le.m_item ); le.m_item.m_text = m_renameRes; GetParent()->GetEventHandler()->ProcessEvent( le ); @@ -1865,11 +1993,14 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) /* Did we actually hit an item ? */ long hitResult = 0; wxListLineData *line = (wxListLineData *) NULL; - for (size_t i = 0; i < m_lines.GetCount(); i++) + + size_t idx; + for (idx = 0; idx < m_lines.GetCount(); idx++) { - line = &m_lines[i]; + line = &m_lines[idx]; hitResult = line->IsHit( x, y ); - if (hitResult) break; + if (hitResult) + break; line = (wxListLineData *) NULL; } @@ -1882,8 +2013,8 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) if (m_dragCount != 3) return; - int command = wxEVT_COMMAND_LIST_BEGIN_DRAG; - if (event.RightIsDown()) command = wxEVT_COMMAND_LIST_BEGIN_RDRAG; + int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG + : wxEVT_COMMAND_LIST_BEGIN_DRAG; wxListEvent le( command, GetParent()->GetId() ); le.SetEventObject( GetParent() ); @@ -1905,7 +2036,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) m_renameTimer->Stop(); m_lastOnSame = FALSE; - if ( line == m_lineBeforeLastClicked ) + if ( idx == m_lineBeforeLastClicked ) { m_usedKeys = FALSE; @@ -1936,7 +2067,8 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) if (event.RightDown()) { - SendNotify( line, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK ); + SendNotify( line, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, + event.GetPosition() ); return; } @@ -1949,7 +2081,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) if ( event.LeftDown() || forceClick ) { m_lineBeforeLastClicked = m_lineLastClicked; - m_lineLastClicked = line; + m_lineLastClicked = idx; m_usedKeys = FALSE; wxListLineData *oldCurrent = m_current; @@ -2046,8 +2178,8 @@ void wxListMainWindow::MoveToFocus() if (m_mode & wxLC_REPORT) { - if (item_y-5 < view_y ) - Scroll( -1, (item_y-5)/m_yScroll ); + if (item_y < view_y ) + Scroll( -1, (item_y)/m_yScroll ); if (item_y+item_h+5 > view_y+client_h) Scroll( -1, (item_y+item_h-client_h+15)/m_yScroll ); } @@ -2154,13 +2286,13 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) } case WXK_END: { - if (!m_lines.IsEmpty()) + if (!IsEmpty()) OnArrowChar( &m_lines.Last(), event.ShiftDown() ); break; } case WXK_HOME: { - if (!m_lines.IsEmpty()) + if (!IsEmpty()) OnArrowChar( &m_lines[0], event.ShiftDown() ); break; } @@ -2382,9 +2514,7 @@ int wxListMainWindow::GetTextLength( wxString &s ) int wxListMainWindow::GetIndexOfLine( const wxListLineData *line ) { - int i = m_lines.Index(*line); - if (i == wxNOT_FOUND) return -1; - else return i; + return m_lines.Index(*line); } void wxListMainWindow::SetImageList( wxImageList *imageList, int which ) @@ -2433,11 +2563,12 @@ int wxListMainWindow::GetItemSpacing( bool isSmall ) void wxListMainWindow::SetColumn( int col, wxListItem &item ) { m_dirty = TRUE; - wxNode *node = m_columns.Nth( col ); + wxListHeaderDataList::Node *node = m_columns.Item( col ); if (node) { - if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text )+7; - wxListHeaderData *column = (wxListHeaderData*)node->Data(); + if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) + item.m_width = GetTextLength( item.m_text )+7; + wxListHeaderData *column = node->GetData(); column->SetItem( item ); } @@ -2453,8 +2584,6 @@ void wxListMainWindow::SetColumnWidth( int col, int width ) m_dirty = TRUE; - wxNode *node = (wxNode*) NULL; - if (width == wxLIST_AUTOSIZE_USEHEADER) { // TODO do use the header @@ -2469,10 +2598,10 @@ void wxListMainWindow::SetColumnWidth( int col, int width ) for (size_t i = 0; i < m_lines.GetCount(); i++) { wxListLineData *line = &m_lines[i]; - wxNode *n = line->m_items.Nth( col ); + wxListItemDataList::Node *n = line->m_items.Item( col ); if (n) { - wxListItemData *item = (wxListItemData*)n->Data(); + wxListItemData *item = n->GetData(); int current = 0, ix = 0, iy = 0; wxCoord lx = 0, ly = 0; if (item->HasImage()) @@ -2482,31 +2611,32 @@ void wxListMainWindow::SetColumnWidth( int col, int width ) } if (item->HasText()) { - wxString str; - item->GetText( str ); + wxString str = item->GetText(); dc.GetTextExtent( str, &lx, &ly ); current += lx; } - if (current > max) max = current; + if (current > max) + max = current; } } width = max+10; } - node = m_columns.Nth( col ); + wxListHeaderDataList::Node *node = m_columns.Item( col ); if (node) { - wxListHeaderData *column = (wxListHeaderData*)node->Data(); + wxListHeaderData *column = node->GetData(); column->SetWidth( width ); } - for (size_t i = 0; i < m_lines.GetCount(); i++) + size_t count = m_lines.GetCount(); + for (size_t i = 0; i < count; i++) { wxListLineData *line = &m_lines[i]; - wxNode *n = line->m_items.Nth( col ); + wxListItemDataList::Node *n = line->m_items.Item( col ); if (n) { - wxListItemData *item = (wxListItemData*)n->Data(); + wxListItemData *item = n->GetData(); item->SetSize( width, -1 ); } } @@ -2518,17 +2648,17 @@ void wxListMainWindow::SetColumnWidth( int col, int width ) void wxListMainWindow::GetColumn( int col, wxListItem &item ) { - wxNode *node = m_columns.Nth( col ); + wxListHeaderDataList::Node *node = m_columns.Item( col ); if (node) { - wxListHeaderData *column = (wxListHeaderData*)node->Data(); + wxListHeaderData *column = node->GetData(); column->GetItem( item ); } else { item.m_format = 0; item.m_width = 0; - item.m_text = ""; + item.m_text = _T(""); item.m_image = 0; item.m_data = 0; } @@ -2536,21 +2666,16 @@ void wxListMainWindow::GetColumn( int col, wxListItem &item ) int wxListMainWindow::GetColumnWidth( int col ) { - wxNode *node = m_columns.Nth( col ); - if (node) - { - wxListHeaderData *column = (wxListHeaderData*)node->Data(); - return column->GetWidth(); - } - else - { - return 0; - } + wxListHeaderDataList::Node *node = m_columns.Item( col ); + wxCHECK_MSG( node, 0, _T("invalid column index") ); + + wxListHeaderData *column = node->GetData(); + return column->GetWidth(); } int wxListMainWindow::GetColumnCount() { - return m_columns.Number(); + return m_columns.GetCount(); } int wxListMainWindow::GetCountPerPage() @@ -2571,49 +2696,68 @@ void wxListMainWindow::SetItem( wxListItem &item ) void wxListMainWindow::SetItemState( long item, long state, long stateMask ) { + wxCHECK_RET( item >= 0 && (size_t)item < m_lines.GetCount(), + _T("invalid list ctrl item index in SetItem") ); + // m_dirty = TRUE; no recalcs needed wxListLineData *oldCurrent = m_current; - if (stateMask & wxLIST_STATE_FOCUSED) + if ( stateMask & wxLIST_STATE_FOCUSED ) { - if (item >= 0 && (size_t)item < m_lines.GetCount()) + wxListLineData *line = &m_lines[(size_t)item]; + if ( state & wxLIST_STATE_FOCUSED ) { - wxListLineData *line = &m_lines[(size_t)item]; - UnfocusLine( m_current ); - m_current = line; - FocusLine( m_current ); - if ((m_mode & wxLC_SINGLE_SEL) && oldCurrent) oldCurrent->Hilight( FALSE ); - RefreshLine( m_current ); - if (oldCurrent) RefreshLine( oldCurrent ); - } - } - - if (stateMask & wxLIST_STATE_SELECTED) - { - bool on = (state & wxLIST_STATE_SELECTED) != 0; - if (!on && (m_mode & wxLC_SINGLE_SEL)) return; - - if (item >= 0 && (size_t)item < m_lines.GetCount()) - { - wxListLineData *line = &m_lines[(size_t)item]; - if (m_mode & wxLC_SINGLE_SEL) + // don't do anything if this item is already focused + if ( line != m_current ) { UnfocusLine( m_current ); m_current = line; FocusLine( m_current ); - if (oldCurrent) oldCurrent->Hilight( FALSE ); + if ( (m_mode & wxLC_SINGLE_SEL) && oldCurrent ) + oldCurrent->Hilight( FALSE ); + RefreshLine( m_current ); - if (oldCurrent) RefreshLine( oldCurrent ); + if ( oldCurrent ) + RefreshLine( oldCurrent ); } - bool on = (state & wxLIST_STATE_SELECTED) != 0; - if (on != line->IsHilighted()) + } + else // unfocus + { + // don't do anything if this item is not focused + if ( line == m_current ) { - line->Hilight( on ); - RefreshLine( line ); + UnfocusLine( m_current ); + m_current = NULL; } } } + + if ( stateMask & wxLIST_STATE_SELECTED ) + { + bool on = (state & wxLIST_STATE_SELECTED) != 0; + if (!on && (m_mode & wxLC_SINGLE_SEL)) + return; + + wxListLineData *line = &m_lines[(size_t)item]; + if (m_mode & wxLC_SINGLE_SEL) + { + UnfocusLine( m_current ); + m_current = line; + FocusLine( m_current ); + if (oldCurrent) + oldCurrent->Hilight( FALSE ); + RefreshLine( m_current ); + if (oldCurrent) + RefreshLine( oldCurrent ); + } + + if (on != line->IsHilighted()) + { + line->Hilight( on ); + RefreshLine( line ); + } + } } int wxListMainWindow::GetItemState( long item, long stateMask ) @@ -2632,7 +2776,7 @@ int wxListMainWindow::GetItemState( long item, long stateMask ) if (item >= 0 && (size_t)item < m_lines.GetCount()) { wxListLineData *line = &m_lines[(size_t)item]; - if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED; + if (line->IsHilighted()) ret |= wxLIST_STATE_SELECTED; } } return ret; @@ -2648,15 +2792,22 @@ void wxListMainWindow::GetItem( wxListItem &item ) else { item.m_mask = 0; - item.m_text = ""; + item.m_text = _T(""); item.m_image = 0; item.m_data = 0; } } -int wxListMainWindow::GetItemCount() +int wxListMainWindow::GetItemCount() const { - return m_lines.GetCount(); + return IsVirtual() ? m_countVirt : m_lines.GetCount(); +} + +void wxListMainWindow::SetItemCount(long count) +{ + m_countVirt = count; + + Refresh(); } void wxListMainWindow::GetItemRect( long index, wxRect &rect ) @@ -2723,7 +2874,8 @@ long wxListMainWindow::GetMode() const void wxListMainWindow::CalculatePositions() { - if (m_lines.IsEmpty()) return; + if ( IsEmpty() ) + return; wxClientDC dc( this ); dc.SetFont( GetFont() ); @@ -2751,6 +2903,9 @@ void wxListMainWindow::CalculatePositions() if (m_mode & wxLC_REPORT) { + // scroll one line per step + m_yScroll = lineSpacing; + int x = 4; int y = 1; int entireHeight = m_lines.GetCount() * lineSpacing + 2; @@ -2758,7 +2913,7 @@ void wxListMainWindow::CalculatePositions() #if wxUSE_GENERIC_LIST_EXTENSIONS int x_scroll_pos = GetScrollPos( wxHORIZONTAL ); #else - SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+15) / m_yScroll, 0, scroll_pos, TRUE ); + SetScrollbars( m_xScroll, m_yScroll, 0, entireHeight/m_yScroll +1, 0, scroll_pos, TRUE ); #endif GetClientSize( &clientWidth, &clientHeight ); @@ -2780,9 +2935,9 @@ void wxListMainWindow::CalculatePositions() #endif y += lineSpacing; // one pixel blank line between items } - m_visibleLines = clientHeight / lineSpacing; + m_visibleLines = clientHeight / lineSpacing; #if wxUSE_GENERIC_LIST_EXTENSIONS - SetScrollbars( m_xScroll, m_yScroll, entireWidth / m_xScroll , (entireHeight+15) / m_yScroll, x_scroll_pos , scroll_pos, TRUE ); + SetScrollbars( m_xScroll, m_yScroll, entireWidth/m_xScroll +1, entireHeight/m_yScroll +1, x_scroll_pos , scroll_pos, TRUE ); #endif } else @@ -2844,7 +2999,7 @@ void wxListMainWindow::RealizeChanges() { if (!m_current) { - if (!m_lines.IsEmpty()) + if ( !IsEmpty() ) m_current = &m_lines[0]; } if (m_current) @@ -2905,12 +3060,12 @@ void wxListMainWindow::DeleteItem( long index ) void wxListMainWindow::DeleteColumn( int col ) { - wxCHECK_RET( col < (int)m_columns.GetCount(), - wxT("attempting to delete inexistent column in wxListView") ); + wxListHeaderDataList::Node *node = m_columns.Item( col ); + + wxCHECK_RET( node, wxT("invalid column index in DeleteColumn()") ); m_dirty = TRUE; - wxNode *node = m_columns.Nth( col ); - if (node) m_columns.DeleteNode( node ); + m_columns.DeleteNode( node ); } void wxListMainWindow::DeleteAllItems() @@ -2959,9 +3114,10 @@ long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(p for (size_t i = (size_t)pos; i < m_lines.GetCount(); i++) { wxListLineData *line = &m_lines[i]; - wxString s = ""; - line->GetText( 0, s ); - if (s == tmp) return pos; + wxString s = line->GetText(0); + if (s == tmp) + return pos; + pos++; } return -1; @@ -3005,10 +3161,18 @@ void wxListMainWindow::InsertItem( wxListItem &item ) { m_dirty = TRUE; int mode = 0; - if (m_mode & wxLC_REPORT) mode = wxLC_REPORT; - else if (m_mode & wxLC_LIST) mode = wxLC_LIST; - else if (m_mode & wxLC_ICON) mode = wxLC_ICON; - else if (m_mode & wxLC_SMALL_ICON) mode = wxLC_ICON; // no typo + if (m_mode & wxLC_REPORT) + mode = wxLC_REPORT; + else if (m_mode & wxLC_LIST) + mode = wxLC_LIST; + else if (m_mode & wxLC_ICON) + mode = wxLC_ICON; + else if (m_mode & wxLC_SMALL_ICON) + mode = wxLC_ICON; // no typo + else + { + wxFAIL_MSG( _T("unknown mode") ); + } wxListLineData *line = new wxListLineData( this, mode, m_hilightBrush ); @@ -3039,13 +3203,13 @@ void wxListMainWindow::InsertColumn( long col, wxListItem &item ) m_dirty = TRUE; if (m_mode & wxLC_REPORT) { - if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text ); + if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) + item.m_width = GetTextLength( item.m_text ); wxListHeaderData *column = new wxListHeaderData( item ); if ((col >= 0) && (col < (int)m_columns.GetCount())) { - wxNode *node = m_columns.Nth( (size_t)col ); - if (node) - m_columns.Insert( node, column ); + wxListHeaderDataList::Node *node = m_columns.Item( col ); + m_columns.Insert( node, column ); } else { @@ -3079,7 +3243,13 @@ void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data ) void wxListMainWindow::OnScroll(wxScrollWinEvent& event) { - wxScrolledWindow::OnScroll( event ) ; + // FIXME +#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) + wxScrolledWindow::OnScroll(event); +#else + HandleOnScroll( event ); +#endif + #if wxUSE_GENERIC_LIST_EXTENSIONS if (event.GetOrientation() == wxHORIZONTAL && ( m_mode & wxLC_REPORT )) @@ -3089,7 +3259,7 @@ void wxListMainWindow::OnScroll(wxScrollWinEvent& event) { lc->m_headerWin->Refresh() ; #ifdef __WXMAC__ - lc->m_headerWin->MacUpdateImmediately() ; + lc->m_headerWin->MacUpdateImmediately() ; #endif } } @@ -3128,7 +3298,7 @@ void wxListItem::Clear() m_data = 0; m_format = wxLIST_FORMAT_CENTRE; m_width = 0; - m_text = wxEmptyString; + m_text = _T(""); if (m_attr) delete m_attr; m_attr = NULL; @@ -3576,7 +3746,8 @@ bool wxListCtrl::DeleteAllItems() bool wxListCtrl::DeleteAllColumns() { - for ( size_t n = 0; n < m_mainWin->m_columns.GetCount(); n++ ) + size_t count = m_mainWin->m_columns.GetCount(); + for ( size_t n = 0; n < count; n++ ) DeleteColumn(n); return TRUE; @@ -3830,7 +4001,11 @@ wxColour wxListCtrl::GetForegroundColour() const bool wxListCtrl::DoPopupMenu( wxMenu *menu, int x, int y ) { +#if wxUSE_MENUS return m_mainWin->PopupMenu( menu, x, y ); +#else + return FALSE; +#endif // wxUSE_MENUS } void wxListCtrl::SetFocus() @@ -3840,3 +4015,33 @@ void wxListCtrl::SetFocus() if ( FindFocus() != this ) m_mainWin->SetFocus(); } + +// ---------------------------------------------------------------------------- +// virtual list control support +// ---------------------------------------------------------------------------- + +wxString wxListCtrl::OnGetItemText(long item, long col) const +{ + // this is a pure virtual function, in fact - which is not really pure + // because the controls which are not virtual don't need to implement it + wxFAIL_MSG( _T("not supposed to be called") ); + + return wxEmptyString; +} + +int wxListCtrl::OnGetItemImage(long item) const +{ + // same as above + wxFAIL_MSG( _T("not supposed to be called") ); + + return -1; +} + +void wxListCtrl::SetItemCount(long count) +{ + wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") ); + + m_mainWin->SetItemCount(count); +} + +#endif // wxUSE_LISTCTRL