X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/49ecb02984b85a19fab294ac0ff0271bdb1d9ad1..34dc8f910f88dc39a2f5fd9c3d894d797212a074:/src/generic/listctrl.cpp diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 6f51132d16..5e7ce897ad 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -12,7 +12,7 @@ TODO 1. we need to implement searching/sorting for virtual controls somehow - 2. when changing selection the lines are refreshed twice + ?2. when changing selection the lines are refreshed twice */ // ============================================================================ @@ -37,15 +37,22 @@ #if wxUSE_LISTCTRL -#include "wx/dcscreen.h" -#include "wx/app.h" -#include "wx/listctrl.h" +#ifndef WX_PRECOMP + #include "wx/app.h" + + #include "wx/dynarray.h" + + #include "wx/dcscreen.h" + + #include "wx/textctrl.h" +#endif + #include "wx/imaglist.h" -#include "wx/dynarray.h" +#include "wx/listctrl.h" #ifdef __WXGTK__ -#include -#include "wx/gtk/win_gtk.h" + #include + #include "wx/gtk/win_gtk.h" #endif // ---------------------------------------------------------------------------- @@ -65,9 +72,14 @@ 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_COL_RIGHT_CLICK) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG) 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) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT) // ---------------------------------------------------------------------------- @@ -260,16 +272,6 @@ protected: class WXDLLEXPORT wxListHeaderData : public wxObject { -protected: - long m_mask; - int m_image; - wxString m_text; - int m_format; - int m_width; - int m_xpos, - m_ypos; - int m_height; - public: wxListHeaderData(); wxListHeaderData( const wxListItem &info ); @@ -291,8 +293,18 @@ public: int GetWidth() const; int GetFormat() const; +protected: + long m_mask; + int m_image; + wxString m_text; + int m_format; + int m_width; + int m_xpos, + m_ypos; + int m_height; + private: - DECLARE_DYNAMIC_CLASS(wxListHeaderData); + void Init(); }; //----------------------------------------------------------------------------- @@ -435,7 +447,6 @@ protected: public: wxListHeaderWindow(); - virtual ~wxListHeaderWindow(); wxListHeaderWindow( wxWindow *win, wxWindowID id, @@ -445,6 +456,8 @@ public: long style = 0, const wxString &name = "wxlistctrlcolumntitles" ); + virtual ~wxListHeaderWindow(); + void DoDrawRect( wxDC *dc, int x, int y, int w, int h ); void DrawCurrent(); void AdjustDC(wxDC& dc); @@ -457,6 +470,9 @@ public: bool m_dirty; private: + // common part of all ctors + void Init(); + DECLARE_DYNAMIC_CLASS(wxListHeaderWindow) DECLARE_EVENT_TABLE() }; @@ -486,6 +502,7 @@ private: wxString *m_res; wxListMainWindow *m_owner; wxString m_startValue; + bool m_finished; public: wxListTextCtrl() {} @@ -603,7 +620,13 @@ public: // bring the current item into view void MoveToFocus() { MoveToItem(m_current); } + // start editing the label of the given item void EditLabel( long item ); + + // suspend/resume redrawing the control + void Freeze(); + void Thaw(); + void OnRenameTimer(); void OnRenameAccept(); @@ -670,7 +693,9 @@ public: bool IsEmpty() const { return GetItemCount() == 0; } void SetItemCount(long count); - void ResetCurrent() { m_current = (size_t)-1; } + // change the current (== focused) item, send a notification event + void ChangeCurrent(size_t current); + void ResetCurrent() { ChangeCurrent((size_t)-1); } bool HasCurrent() const { return m_current != (size_t)-1; } // send out a wxListEvent @@ -813,12 +838,6 @@ private: // 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; @@ -835,6 +854,9 @@ private: wxBrush *m_highlightBrush, *m_highlightUnfocusedBrush; + // if this is > 0, the control is frozen and doesn't redraw itself + size_t m_freezeCount; + DECLARE_DYNAMIC_CLASS(wxListMainWindow); DECLARE_EVENT_TABLE() }; @@ -957,8 +979,10 @@ bool wxSelectionStore::SelectRange(size_t itemFrom, size_t itemTo, // stop counting (see comment below) itemsChanged = NULL; } - - itemsChanged->Add(m_itemsSel[i]); + else + { + itemsChanged->Add(m_itemsSel[i]); + } } m_itemsSel.RemoveAt(i); @@ -1158,12 +1182,10 @@ void wxListItemData::GetItem( wxListItem &info ) const // wxListHeaderData //----------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxListHeaderData,wxObject); - -wxListHeaderData::wxListHeaderData() +void wxListHeaderData::Init() { m_mask = 0; - m_image = 0; + m_image = -1; m_format = 0; m_width = 0; m_xpos = 0; @@ -1171,22 +1193,33 @@ wxListHeaderData::wxListHeaderData() m_height = 0; } +wxListHeaderData::wxListHeaderData() +{ + Init(); +} + wxListHeaderData::wxListHeaderData( const wxListItem &item ) { + Init(); + SetItem( item ); - m_xpos = 0; - m_ypos = 0; - m_height = 0; } void wxListHeaderData::SetItem( const wxListItem &item ) { m_mask = item.m_mask; - m_text = item.m_text; - m_image = item.m_image; - m_format = item.m_format; - SetWidth(item.m_width); + if ( m_mask & wxLIST_MASK_TEXT ) + m_text = item.m_text; + + if ( m_mask & wxLIST_MASK_IMAGE ) + m_image = item.m_image; + + if ( m_mask & wxLIST_MASK_FORMAT ) + m_format = item.m_format; + + if ( m_mask & wxLIST_MASK_WIDTH ) + SetWidth(item.m_width); } void wxListHeaderData::SetPosition( int x, int y ) @@ -1205,7 +1238,7 @@ void wxListHeaderData::SetWidth( int w ) m_width = w; if (m_width < 0) m_width = WIDTH_COL_DEFAULT; - if (m_width < WIDTH_COL_MIN) + else if (m_width < WIDTH_COL_MIN) m_width = WIDTH_COL_MIN; } @@ -1216,7 +1249,7 @@ void wxListHeaderData::SetFormat( int format ) bool wxListHeaderData::HasImage() const { - return (m_image != 0); + return m_image != -1; } bool wxListHeaderData::IsHit( int x, int y ) const @@ -1224,7 +1257,7 @@ 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)); } -void wxListHeaderData::GetItem( wxListItem &item ) +void wxListHeaderData::GetItem( wxListItem& item ) { item.m_mask = m_mask; item.m_text = m_text; @@ -1724,30 +1757,39 @@ BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow) EVT_SET_FOCUS (wxListHeaderWindow::OnSetFocus) END_EVENT_TABLE() -wxListHeaderWindow::wxListHeaderWindow( void ) +void wxListHeaderWindow::Init() { - m_owner = (wxListMainWindow *) NULL; m_currentCursor = (wxCursor *) NULL; - m_resizeCursor = (wxCursor *) NULL; m_isDragging = FALSE; + m_dirty = FALSE; +} + +wxListHeaderWindow::wxListHeaderWindow() +{ + Init(); + + m_owner = (wxListMainWindow *) NULL; + m_resizeCursor = (wxCursor *) NULL; } -wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner, - const wxPoint &pos, const wxSize &size, - long style, const wxString &name ) : - wxWindow( win, id, pos, size, style, name ) +wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, + wxWindowID id, + wxListMainWindow *owner, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString &name ) + : wxWindow( win, id, pos, size, style, name ) { + Init(); + m_owner = owner; -// m_currentCursor = wxSTANDARD_CURSOR; - m_currentCursor = (wxCursor *) NULL; m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE ); - m_isDragging = FALSE; - m_dirty = FALSE; SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ) ); } -wxListHeaderWindow::~wxListHeaderWindow( void ) +wxListHeaderWindow::~wxListHeaderWindow() { delete m_resizeCursor; } @@ -1853,27 +1895,53 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) int numColumns = m_owner->GetColumnCount(); wxListItem item; - for (int i = 0; i < numColumns; i++) + for ( int i = 0; i < numColumns && x < w; i++ ) { m_owner->GetColumn( i, item ); int wCol = item.m_width; - int cw = wCol - 2; // the width of the rect to draw - int xEnd = x + wCol; + // the width of the rect to draw: make it smaller to fit entirely + // inside the column rect + int cw = wCol - 2; dc.SetPen( *wxWHITE_PEN ); DoDrawRect( &dc, x, HEADER_OFFSET_Y, cw, h-2 ); - wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw-5, h-4 ); + + // if we have an image, draw it on the right of the label + int image = item.m_image; + if ( image != -1 ) + { + wxImageList *imageList = m_owner->m_small_image_list; + if ( imageList ) + { + int ix, iy; + imageList->GetSize(image, ix, iy); + + imageList->Draw + ( + image, + dc, + x + cw - ix - 1, + HEADER_OFFSET_Y + (h - 4 - iy)/2, + wxIMAGELIST_DRAW_TRANSPARENT + ); + + cw -= ix + 2; + } + //else: ignore the column image + } + + // draw the text clipping it so that it doesn't overwrite the column + // boundary + wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h - 4 ); dc.DrawText( item.GetText(), x + EXTRA_WIDTH, HEADER_OFFSET_Y + EXTRA_HEIGHT ); x += wCol; - - if (xEnd > w+5) - break; } + dc.EndDrawing(); } @@ -1973,20 +2041,31 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) m_minX = xpos; } - if (event.LeftDown()) + if (event.LeftDown() || event.RightUp()) { - if (hit_border) + if (hit_border && event.LeftDown()) { m_isDragging = TRUE; m_currentX = x; DrawCurrent(); CaptureMouse(); } - else + else // click on a column { wxWindow *parent = GetParent(); - wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, parent->GetId() ); + wxListEvent le( event.LeftDown() + ? wxEVT_COMMAND_LIST_COL_CLICK + : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, + parent->GetId() ); le.SetEventObject( parent ); + le.m_pointDrag = event.GetPosition(); + + // the position should be relative to the parent window, not + // this one for compatibility with MSW and common sense: the + // user code doesn't know anything at all about this header + // window, so why should it get positions relative to it? + le.m_pointDrag.y -= GetSize().y; + le.m_col = m_column; parent->GetEventHandler()->ProcessEvent( le ); } @@ -2061,6 +2140,7 @@ wxListTextCtrl::wxListTextCtrl( wxWindow *parent, (*m_accept) = FALSE; (*m_res) = ""; m_startValue = value; + m_finished = FALSE; } void wxListTextCtrl::OnChar( wxKeyEvent &event ) @@ -2073,9 +2153,12 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event ) if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this); - if ((*m_accept) && ((*m_res) != m_startValue)) + if ((*m_res) != m_startValue) m_owner->OnRenameAccept(); + m_finished = TRUE; + m_owner->SetFocus(); // This doesn't work. TODO. + return; } if (event.m_keyCode == WXK_ESCAPE) @@ -2086,6 +2169,9 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event ) if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this); + m_finished = TRUE; + m_owner->SetFocus(); // This doesn't work. TODO. + return; } @@ -2094,12 +2180,18 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event ) void wxListTextCtrl::OnKeyUp( wxKeyEvent &event ) { + if (m_finished) + { + event.Skip(); + return; + } + // auto-grow the textctrl: wxSize parentSize = m_owner->GetSize(); wxPoint myPos = GetPosition(); wxSize mySize = GetSize(); int sx, sy; - GetTextExtent(GetValue() + _T("MM"), &sx, &sy); // FIXME: MM?? + GetTextExtent(GetValue() + _T("M"), &sx, &sy); // FIXME: MM?? if (myPos.x + sx > parentSize.x) sx = parentSize.x - myPos.x; if (mySize.x > sx) @@ -2109,12 +2201,21 @@ void wxListTextCtrl::OnKeyUp( wxKeyEvent &event ) event.Skip(); } -void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) +void wxListTextCtrl::OnKillFocus( wxFocusEvent &event ) { + if (m_finished) + { + event.Skip(); + return; + } + if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this); - if ((*m_accept) && ((*m_res) != m_startValue)) + (*m_accept) = TRUE; + (*m_res) = GetValue(); + + if ((*m_res) != m_startValue) m_owner->OnRenameAccept(); } @@ -2164,6 +2265,8 @@ void wxListMainWindow::Init() m_currentEdit = m_lineLastClicked = m_lineBeforeLastClicked = (size_t)-1; + + m_freezeCount = 0; } void wxListMainWindow::InitScrolling() @@ -2361,6 +2464,8 @@ wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const long wxListMainWindow::HitTestLine(size_t line, int x, int y) const { + wxASSERT_MSG( line < GetItemCount(), _T("invalid line in HitTestLine") ); + wxListLineData *ld = GetLine(line); if ( ld->HasImage() && GetLineIconRect(line).Inside(x, y) ) @@ -2554,7 +2659,15 @@ void wxListMainWindow::RefreshSelected() to = GetItemCount() - 1; } - if ( HasCurrent() && m_current > from && m_current <= to ) + // VZ: this code would work fine if wxGTK wxWindow::Refresh() were + // reasonable, i.e. if it only generated one expose event for + // several calls to it - as it is, each Refresh() results in a + // repaint which provokes flicker too horrible to be seen + // + // when/if wxGTK is fixed, this code should be restored as normally it + // should generate _less_ flicker than the version below +#ifndef __WXGTK__ + if ( HasCurrent() && m_current >= from && m_current <= to ) { RefreshLine(m_current); } @@ -2567,6 +2680,41 @@ void wxListMainWindow::RefreshSelected() RefreshLine(line); } } +#else // __WXGTK__ + size_t selMin = (size_t)-1, + selMax = 0; + + for ( size_t line = from; line <= to; line++ ) + { + if ( IsHighlighted(line) || (line == m_current) ) + { + if ( line < selMin ) + selMin = line; + if ( line > selMax ) + selMax = line; + } + } + + if ( selMin != (size_t)-1 ) + { + RefreshLines(selMin, selMax); + } +#endif // !__WXGTK__/__WXGTK__ +} + +void wxListMainWindow::Freeze() +{ + m_freezeCount++; +} + +void wxListMainWindow::Thaw() +{ + wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen list control?") ); + + if ( !--m_freezeCount ) + { + Refresh(); + } } void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) @@ -2575,9 +2723,9 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) // done (a Windows requirement). wxPaintDC dc( this ); - if ( IsEmpty() ) + if ( IsEmpty() || m_freezeCount ) { - // empty control. nothing to draw + // nothing to draw or not the moment to draw it return; } @@ -2746,21 +2894,22 @@ void wxListMainWindow::SendNotify( size_t line, // what we're trying to avoid if ( !IsVirtual() && (command != wxEVT_COMMAND_LIST_DELETE_ITEM) ) { - GetLine(line)->GetItem( 0, le.m_item ); + if ( line != (size_t)-1 ) + { + GetLine(line)->GetItem( 0, le.m_item ); + } + //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event } //else: there may be no more such item GetParent()->GetEventHandler()->ProcessEvent( le ); } -void wxListMainWindow::OnFocusLine( size_t WXUNUSED(line) ) +void wxListMainWindow::ChangeCurrent(size_t current) { -// SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED ); -} + m_current = current; -void wxListMainWindow::OnUnfocusLine( size_t WXUNUSED(line) ) -{ -// SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED ); + SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED); } void wxListMainWindow::EditLabel( long item ) @@ -2885,7 +3034,12 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) if (event.Dragging()) { if (m_dragCount == 0) - m_dragStart = wxPoint(x,y); + { + // we have to report the raw, physical coords as we want to be + // able to call HitTest(event.m_pointDrag) from the user code to + // get the item being dragged + m_dragStart = event.GetPosition(); + } m_dragCount++; @@ -2962,7 +3116,8 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) if ( IsSingleSel() || !(event.ControlDown() || event.ShiftDown()) ) { HighlightAll( FALSE ); - m_current = current; + + ChangeCurrent(current); ReverseHighlight(m_current); } @@ -2970,13 +3125,13 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) { if (event.ControlDown()) { - m_current = current; + ChangeCurrent(current); ReverseHighlight(m_current); } else if (event.ShiftDown()) { - m_current = current; + ChangeCurrent(current); size_t lineFrom = oldCurrent, lineTo = current; @@ -2999,8 +3154,6 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) if (m_current != oldCurrent) { RefreshLine( oldCurrent ); - OnUnfocusLine( oldCurrent ); - OnFocusLine( m_current ); } // forceClick is only set if the previous click was on another item @@ -3056,7 +3209,7 @@ void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event) // items anyhow if ( event.ShiftDown() && !IsSingleSel() ) { - m_current = newCurrent; + ChangeCurrent(newCurrent); // select all the items between the old and the new one if ( oldCurrent > newCurrent ) @@ -3073,7 +3226,7 @@ void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event) if ( !event.ControlDown() ) HighlightAll(FALSE); - m_current = newCurrent; + ChangeCurrent(newCurrent); HighlightLine( oldCurrent, FALSE ); RefreshLine( oldCurrent ); @@ -3084,8 +3237,6 @@ void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event) } } - OnUnfocusLine( oldCurrent ); - OnFocusLine( m_current ); RefreshLine( m_current ); MoveToFocus(); @@ -3144,7 +3295,8 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) nevent.SetDirection( !event.ShiftDown() ); nevent.SetEventObject( GetParent()->GetParent() ); nevent.SetCurrentFocus( m_parent ); - if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) return; + if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) + return; } /* no item -> nothing to do */ @@ -3244,12 +3396,7 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) case WXK_SPACE: if ( IsSingleSel() ) { - wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, - GetParent()->GetId() ); - le.SetEventObject( GetParent() ); - le.m_itemIndex = m_current; - GetLine(m_current)->GetItem( 0, le.m_item ); - GetParent()->GetEventHandler()->ProcessEvent( le ); + SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); if ( IsHighlighted(m_current) ) { @@ -3264,14 +3411,7 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) case WXK_RETURN: case WXK_EXECUTE: - { - wxListEvent le( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, - GetParent()->GetId() ); - le.SetEventObject( GetParent() ); - le.m_itemIndex = m_current; - GetLine(m_current)->GetItem( 0, le.m_item ); - GetParent()->GetEventHandler()->ProcessEvent( le ); - } + SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); break; default: @@ -3289,12 +3429,19 @@ extern wxWindow *g_focusWindow; void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) { - m_hasFocus = TRUE; + // wxGTK sends us EVT_SET_FOCUS events even if we had never got + // EVT_KILL_FOCUS before which means that we finish by redrawing the items + // which are already drawn correctly resulting in horrible flicker - avoid + // it + if ( !m_hasFocus ) + { + m_hasFocus = TRUE; - if (!GetParent()) - return; + RefreshSelected(); + } - RefreshSelected(); + if ( !GetParent() ) + return; #ifdef __WXGTK__ g_focusWindow = GetParent(); @@ -3446,6 +3593,9 @@ void wxListMainWindow::SetColumnWidth( int col, int width ) _T("SetColumnWidth() can only be called in report mode.") ); m_dirty = TRUE; + wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; + if ( headerWin ) + headerWin->m_dirty = TRUE; wxListHeaderDataList::Node *node = m_columns.Item( col ); wxCHECK_RET( node, _T("no column?") ); @@ -3588,9 +3738,7 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask ) // don't do anything if this item is already focused if ( item != m_current ) { - OnUnfocusLine( m_current ); - m_current = item; - OnFocusLine( m_current ); + ChangeCurrent(item); if ( oldCurrent != (size_t)-1 ) { @@ -3610,8 +3758,7 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask ) // don't do anything if this item is not focused if ( item == m_current ) { - OnUnfocusLine( m_current ); - m_current = (size_t)-1; + ResetCurrent(); RefreshLine( oldCurrent ); } @@ -3631,9 +3778,7 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask ) // single sel mode if ( m_current != item ) { - OnUnfocusLine( m_current ); - m_current = item; - OnFocusLine( m_current ); + ChangeCurrent(item); if ( oldCurrent != (size_t)-1 ) { @@ -3890,12 +4035,7 @@ void wxListMainWindow::UpdateCurrent() { if ( !HasCurrent() && !IsEmpty() ) { - m_current = 0; - } - - if ( m_current != (size_t)-1 ) - { - OnFocusLine( m_current ); + ChangeCurrent(0); } } @@ -4058,8 +4198,6 @@ void wxListMainWindow::EnsureVisible( long index ) // been added and its position is not known yet if ( m_dirty ) { - m_dirty = FALSE; - RecalculatePositions(TRUE /* no refresh */); } @@ -4107,18 +4245,22 @@ long wxListMainWindow::HitTest( int x, int y, int &flags ) { CalcUnscrolledPosition( x, y, &x, &y ); + size_t count = GetItemCount(); + if ( HasFlag(wxLC_REPORT) ) { size_t current = y / GetLineHeight(); - flags = HitTestLine(current, x, y); - if ( flags ) - return current; + if ( current < count ) + { + flags = HitTestLine(current, x, y); + if ( flags ) + return current; + } } else // !report { // TODO: optimize it too! this is less simple than for report view but // enumerating all items is still not a way to do it!! - size_t count = GetItemCount(); for ( size_t current = 0; current < count; current++ ) { flags = HitTestLine(current, x, y); @@ -4303,17 +4445,9 @@ IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) wxListItem::wxListItem() { - m_mask = 0; - m_itemId = 0; - m_col = 0; - m_state = 0; - m_stateMask = 0; - m_image = 0; - m_data = 0; - m_format = wxLIST_FORMAT_CENTRE; - m_width = 0; - m_attr = NULL; + + Clear(); } void wxListItem::Clear() @@ -4323,11 +4457,11 @@ void wxListItem::Clear() m_col = 0; m_state = 0; m_stateMask = 0; - m_image = 0; + m_image = -1; m_data = 0; m_format = wxLIST_FORMAT_CENTRE; m_width = 0; - m_text = _T(""); + m_text.clear(); ClearAttributes(); } @@ -4341,53 +4475,6 @@ void wxListItem::ClearAttributes() } } -// ------------------------------------------------------------------------------------- -// wxListEvent -// ------------------------------------------------------------------------------------- - -IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent) - -wxListEvent::wxListEvent( wxEventType commandType, int id ) - : wxNotifyEvent( commandType, id ) -{ - m_code = 0; - m_itemIndex = 0; - m_oldItemIndex = 0; - m_col = 0; - m_cancelled = FALSE; - m_pointDrag.x = 0; - m_pointDrag.y = 0; -} - -void wxListEvent::CopyObject(wxObject& object_dest) const -{ - wxListEvent *obj = (wxListEvent *)&object_dest; - - wxNotifyEvent::CopyObject(object_dest); - - obj->m_code = m_code; - obj->m_itemIndex = m_itemIndex; - obj->m_oldItemIndex = m_oldItemIndex; - obj->m_col = m_col; - obj->m_cancelled = m_cancelled; - obj->m_pointDrag = m_pointDrag; - obj->m_item.m_mask = m_item.m_mask; - obj->m_item.m_itemId = m_item.m_itemId; - obj->m_item.m_col = m_item.m_col; - obj->m_item.m_state = m_item.m_state; - obj->m_item.m_stateMask = m_item.m_stateMask; - obj->m_item.m_text = m_item.m_text; - obj->m_item.m_image = m_item.m_image; - obj->m_item.m_data = m_item.m_data; - obj->m_item.m_format = m_item.m_format; - obj->m_item.m_width = m_item.m_width; - - if ( m_item.HasAttributes() ) - { - obj->m_item.SetTextColour(m_item.GetTextColour()); - } -} - // ------------------------------------------------------------------------------------- // wxListCtrl // ------------------------------------------------------------------------------------- @@ -4395,6 +4482,8 @@ void wxListEvent::CopyObject(wxObject& object_dest) const IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl) +IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent) + BEGIN_EVENT_TABLE(wxListCtrl,wxControl) EVT_SIZE(wxListCtrl::OnSize) EVT_IDLE(wxListCtrl::OnIdle) @@ -4416,9 +4505,6 @@ wxListCtrl::wxListCtrl() wxListCtrl::~wxListCtrl() { - if ( m_mainWin ) - m_mainWin->ResetCurrent(); - if (m_ownsImageListNormal) delete m_imageListNormal; if (m_ownsImageListSmall) @@ -4800,7 +4886,7 @@ bool wxListCtrl::DeleteAllColumns() { size_t count = m_mainWin->m_columns.GetCount(); for ( size_t n = 0; n < count; n++ ) - DeleteColumn(n); + DeleteColumn(0); return TRUE; } @@ -5119,4 +5205,14 @@ void wxListCtrl::RefreshItems(long itemFrom, long itemTo) m_mainWin->RefreshLines(itemFrom, itemTo); } +void wxListCtrl::Freeze() +{ + m_mainWin->Freeze(); +} + +void wxListCtrl::Thaw() +{ + m_mainWin->Thaw(); +} + #endif // wxUSE_LISTCTRL