+ wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
+ le.SetEventObject( GetParent() );
+ le.m_item.m_itemId =
+ le.m_itemIndex = itemEdit;
+
+ wxListLineData *data = GetLine(itemEdit);
+
+ wxCHECK_MSG( data, false, wxT("invalid index in OnRenameAccept()") );
+
+ data->GetItem( 0, le.m_item );
+ le.m_item.m_text = value;
+ return !GetParent()->GetEventHandler()->ProcessEvent( le ) ||
+ le.IsAllowed();
+}
+
+void wxListMainWindow::OnRenameCancelled(size_t itemEdit)
+{
+ // let owner know that the edit was cancelled
+ wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() );
+
+ le.SetEditCanceled(true);
+
+ le.SetEventObject( GetParent() );
+ le.m_item.m_itemId =
+ le.m_itemIndex = itemEdit;
+
+ wxListLineData *data = GetLine(itemEdit);
+ wxCHECK_RET( data, wxT("invalid index in OnRenameCancelled()") );
+
+ data->GetItem( 0, le.m_item );
+ GetEventHandler()->ProcessEvent( le );
+}
+
+void wxListMainWindow::OnMouse( wxMouseEvent &event )
+{
+#ifdef __WXMAC__
+ // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
+ // shutdown the edit control when the mouse is clicked elsewhere on the
+ // listctrl because the order of events is different (or something like
+ // that), so explicitly end the edit if it is active.
+ if ( event.LeftDown() && m_textctrlWrapper )
+ m_textctrlWrapper->EndEdit(wxListTextCtrlWrapper::End_Accept);
+#endif // __WXMAC__
+
+ if ( event.LeftDown() )
+ SetFocus();
+
+ event.SetEventObject( GetParent() );
+ if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
+ return;
+
+ if (event.GetEventType() == wxEVT_MOUSEWHEEL)
+ {
+ // let the base class handle mouse wheel events.
+ event.Skip();
+ return;
+ }
+
+ if ( !HasCurrent() || IsEmpty() )
+ {
+ if (event.RightDown())
+ {
+ SendNotify( (size_t)-1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
+
+ wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
+ GetParent()->GetId(),
+ ClientToScreen(event.GetPosition()));
+ evtCtx.SetEventObject(GetParent());
+ GetParent()->GetEventHandler()->ProcessEvent(evtCtx);
+ }
+ return;
+ }
+
+ if (m_dirty)
+ return;
+
+ if ( !(event.Dragging() || event.ButtonDown() || event.LeftUp() ||
+ event.ButtonDClick()) )
+ return;
+
+ int x = event.GetX();
+ int y = event.GetY();
+ GetListCtrl()->CalcUnscrolledPosition( x, y, &x, &y );
+
+ // where did we hit it (if we did)?
+ long hitResult = 0;
+
+ size_t count = GetItemCount(),
+ current;
+
+ if ( InReportView() )
+ {
+ current = y / GetLineHeight();
+ if ( current < count )
+ hitResult = HitTestLine(current, x, y);
+ }
+ 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!!
+ for ( current = 0; current < count; current++ )
+ {
+ hitResult = HitTestLine(current, x, y);
+ if ( hitResult )
+ break;
+ }
+ }
+
+ // Update drag events counter first as we must do it even if the mouse is
+ // not on any item right now as we must keep count in case we started
+ // dragging from the empty control area but continued to do it over a valid
+ // item -- in this situation we must not start dragging this item.
+ if (event.Dragging())
+ m_dragCount++;
+ else
+ m_dragCount = 0;
+
+ // The only mouse event that can be generated without any valid item is
+ // wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK as it can be useful to have a global
+ // popup menu for the list control itself which should be shown even when
+ // the user clicks outside of any item.
+ if ( !hitResult )
+ {
+ // outside of any item
+ if (event.RightDown())
+ {
+ SendNotify( (size_t) -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
+
+ wxContextMenuEvent evtCtx(
+ wxEVT_CONTEXT_MENU,
+ GetParent()->GetId(),
+ ClientToScreen(event.GetPosition()));
+ evtCtx.SetEventObject(GetParent());
+ GetParent()->GetEventHandler()->ProcessEvent(evtCtx);
+ }
+ else
+ {
+ // reset the selection and bail out
+ HighlightAll(false);
+ }
+
+ return;
+ }
+
+ if ( event.Dragging() )
+ {
+ if (m_dragCount == 1)
+ {
+ // 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();
+ }
+
+ if (m_dragCount != 3)
+ return;
+
+ int command = event.RightIsDown() ? wxEVT_COMMAND_LIST_BEGIN_RDRAG
+ : wxEVT_COMMAND_LIST_BEGIN_DRAG;
+
+ SendNotify( m_lineLastClicked, command, m_dragStart );
+
+ return;
+ }
+
+ bool forceClick = false;
+ if (event.ButtonDClick())
+ {
+ if ( m_renameTimer->IsRunning() )
+ m_renameTimer->Stop();
+
+ m_lastOnSame = false;
+
+ if ( current == m_lineLastClicked )
+ {
+ SendNotify( current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
+
+ return;
+ }
+ else
+ {
+ // The first click was on another item, so don't interpret this as
+ // a double click, but as a simple click instead
+ forceClick = true;
+ }
+ }
+
+ if (event.LeftUp())
+ {
+ if (m_lineSelectSingleOnUp != (size_t)-1)
+ {
+ // select single line
+ HighlightAll( false );
+ ReverseHighlight(m_lineSelectSingleOnUp);
+ }
+
+ if (m_lastOnSame)
+ {
+ if ((current == m_current) &&
+ (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
+ HasFlag(wxLC_EDIT_LABELS) )
+ {
+ if ( !InReportView() ||
+ GetLineLabelRect(current).Contains(x, y) )
+ {
+ int dclick = wxSystemSettings::GetMetric(wxSYS_DCLICK_MSEC);
+ m_renameTimer->Start(dclick > 0 ? dclick : 250, true);
+ }
+ }
+ }
+
+ m_lastOnSame = false;
+ m_lineSelectSingleOnUp = (size_t)-1;
+ }
+ else
+ {
+ // This is necessary, because after a DnD operation in
+ // from and to ourself, the up event is swallowed by the
+ // DnD code. So on next non-up event (which means here and
+ // now) m_lineSelectSingleOnUp should be reset.
+ m_lineSelectSingleOnUp = (size_t)-1;
+ }
+ if (event.RightDown())
+ {
+ m_lineBeforeLastClicked = m_lineLastClicked;
+ m_lineLastClicked = current;
+
+ // If the item is already selected, do not update the selection.
+ // Multi-selections should not be cleared if a selected item is clicked.
+ if (!IsHighlighted(current))
+ {
+ HighlightAll(false);
+ ChangeCurrent(current);
+ ReverseHighlight(m_current);
+ }
+
+ SendNotify( current, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition() );
+
+ // Allow generation of context menu event
+ event.Skip();
+ }
+ else if (event.MiddleDown())
+ {
+ SendNotify( current, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK );
+ }
+ else if ( event.LeftDown() || forceClick )
+ {
+ m_lineBeforeLastClicked = m_lineLastClicked;
+ m_lineLastClicked = current;
+
+ size_t oldCurrent = m_current;
+ bool oldWasSelected = IsHighlighted(m_current);
+
+ bool cmdModifierDown = event.CmdDown();
+ if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) )
+ {
+ if ( IsSingleSel() || !IsHighlighted(current) )
+ {
+ HighlightAll( false );
+
+ ChangeCurrent(current);
+
+ ReverseHighlight(m_current);
+ }
+ else // multi sel & current is highlighted & no mod keys
+ {
+ m_lineSelectSingleOnUp = current;
+ ChangeCurrent(current); // change focus
+ }
+ }
+ else // multi sel & either ctrl or shift is down
+ {
+ if (cmdModifierDown)
+ {
+ ChangeCurrent(current);
+
+ ReverseHighlight(m_current);
+ }
+ else if (event.ShiftDown())
+ {
+ ChangeCurrent(current);
+
+ size_t lineFrom = oldCurrent,
+ lineTo = current;
+
+ if ( lineTo < lineFrom )
+ {
+ lineTo = lineFrom;
+ lineFrom = m_current;
+ }
+
+ HighlightLines(lineFrom, lineTo);
+ }
+ else // !ctrl, !shift
+ {
+ // test in the enclosing if should make it impossible
+ wxFAIL_MSG( wxT("how did we get here?") );
+ }
+ }
+
+ if (m_current != oldCurrent)
+ RefreshLine( oldCurrent );
+
+ // forceClick is only set if the previous click was on another item
+ m_lastOnSame = !forceClick && (m_current == oldCurrent) && oldWasSelected;
+ }
+}
+
+void wxListMainWindow::MoveToItem(size_t item)
+{
+ if ( item == (size_t)-1 )
+ return;
+
+ wxRect rect = GetLineRect(item);
+
+ int client_w, client_h;
+ GetClientSize( &client_w, &client_h );
+
+ const int hLine = GetLineHeight();
+
+ int view_x = SCROLL_UNIT_X * GetListCtrl()->GetScrollPos( wxHORIZONTAL );
+ int view_y = hLine * GetListCtrl()->GetScrollPos( wxVERTICAL );
+
+ if ( InReportView() )
+ {
+ // the next we need the range of lines shown it might be different,
+ // so recalculate it
+ ResetVisibleLinesRange();
+
+ if (rect.y < view_y)
+ GetListCtrl()->Scroll( -1, rect.y / hLine );
+ if (rect.y + rect.height + 5 > view_y + client_h)
+ GetListCtrl()->Scroll( -1, (rect.y + rect.height - client_h + hLine) / hLine );
+
+#ifdef __WXMAC__
+ // At least on Mac the visible lines value will get reset inside of
+ // Scroll *before* it actually scrolls the window because of the
+ // Update() that happens there, so it will still have the wrong value.
+ // So let's reset it again and wait for it to be recalculated in the
+ // next paint event. I would expect this problem to show up in wxGTK
+ // too but couldn't duplicate it there. Perhaps the order of events
+ // is different... --Robin
+ ResetVisibleLinesRange();
+#endif
+ }
+ else // !report
+ {
+ int sx = -1,
+ sy = -1;
+
+ if (rect.x-view_x < 5)
+ sx = (rect.x - 5) / SCROLL_UNIT_X;
+ if (rect.x + rect.width - 5 > view_x + client_w)
+ sx = (rect.x + rect.width - client_w + SCROLL_UNIT_X) / SCROLL_UNIT_X;
+
+ if (rect.y-view_y < 5)
+ sy = (rect.y - 5) / hLine;
+ if (rect.y + rect.height - 5 > view_y + client_h)
+ sy = (rect.y + rect.height - client_h + hLine) / hLine;
+
+ GetListCtrl()->Scroll(sx, sy);
+ }
+}
+
+bool wxListMainWindow::ScrollList(int WXUNUSED(dx), int dy)
+{
+ if ( !InReportView() )
+ {
+ // TODO: this should work in all views but is not implemented now
+ return false;
+ }
+
+ size_t top, bottom;
+ GetVisibleLinesRange(&top, &bottom);
+
+ if ( bottom == (size_t)-1 )
+ return 0;
+
+ ResetVisibleLinesRange();
+
+ int hLine = GetLineHeight();
+
+ GetListCtrl()->Scroll(-1, top + dy / hLine);
+
+#ifdef __WXMAC__
+ // see comment in MoveToItem() for why we do this
+ ResetVisibleLinesRange();
+#endif
+
+ return true;
+}
+
+// ----------------------------------------------------------------------------
+// keyboard handling
+// ----------------------------------------------------------------------------
+
+void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
+{
+ wxCHECK_RET( newCurrent < (size_t)GetItemCount(),
+ wxT("invalid item index in OnArrowChar()") );
+
+ size_t oldCurrent = m_current;
+
+ // in single selection we just ignore Shift as we can't select several
+ // items anyhow
+ if ( event.ShiftDown() && !IsSingleSel() )
+ {
+ ChangeCurrent(newCurrent);
+
+ // refresh the old focus to remove it
+ RefreshLine( oldCurrent );
+
+ // select all the items between the old and the new one
+ if ( oldCurrent > newCurrent )
+ {
+ newCurrent = oldCurrent;
+ oldCurrent = m_current;
+ }
+
+ HighlightLines(oldCurrent, newCurrent);
+ }
+ else // !shift
+ {
+ // all previously selected items are unselected unless ctrl is held
+ // in a multiselection control
+ if ( !event.ControlDown() || IsSingleSel() )
+ HighlightAll(false);
+
+ ChangeCurrent(newCurrent);
+
+ // refresh the old focus to remove it
+ RefreshLine( oldCurrent );
+
+ // in single selection mode we must always have a selected item
+ if ( !event.ControlDown() || IsSingleSel() )
+ HighlightLine( m_current, true );
+ }
+
+ RefreshLine( m_current );
+
+ MoveToFocus();
+}
+
+void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
+{
+ wxWindow *parent = GetParent();
+
+ // propagate the key event upwards
+ wxKeyEvent ke(event);
+ ke.SetEventObject( parent );
+ if (parent->GetEventHandler()->ProcessEvent( ke ))
+ return;
+
+ // send a list event
+ wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, parent->GetId() );
+ le.m_item.m_itemId =
+ le.m_itemIndex = m_current;
+ if (HasCurrent())
+ GetLine(m_current)->GetItem( 0, le.m_item );
+ le.m_code = event.GetKeyCode();
+ le.SetEventObject( parent );
+ if (parent->GetEventHandler()->ProcessEvent( le ))
+ return;
+
+ event.Skip();
+}
+
+void wxListMainWindow::OnKeyUp( wxKeyEvent &event )
+{
+ wxWindow *parent = GetParent();
+
+ // propagate the key event upwards
+ wxKeyEvent ke(event);
+ if (parent->GetEventHandler()->ProcessEvent( ke ))
+ return;
+
+ event.Skip();
+}
+
+void wxListMainWindow::OnCharHook( wxKeyEvent &event )
+{
+ if ( m_textctrlWrapper )
+ {
+ // When an in-place editor is active we should ensure that it always
+ // gets the key events that are special to it.
+ if ( m_textctrlWrapper->CheckForEndEditKey(event) )
+ {
+ // Skip the call to wxEvent::Skip() below.
+ return;
+ }
+ }
+
+ event.Skip();
+}
+
+void wxListMainWindow::OnChar( wxKeyEvent &event )
+{
+ wxWindow *parent = GetParent();
+
+ // propagate the char event upwards
+ wxKeyEvent ke(event);
+ ke.SetEventObject( parent );
+ if (parent->GetEventHandler()->ProcessEvent( ke ))
+ return;
+
+ if ( HandleAsNavigationKey(event) )
+ return;
+
+ // no item -> nothing to do
+ if (!HasCurrent())
+ {
+ event.Skip();
+ return;
+ }
+
+ // don't use m_linesPerPage directly as it might not be computed yet
+ const int pageSize = GetCountPerPage();
+ wxCHECK_RET( pageSize, wxT("should have non zero page size") );
+
+ if (GetLayoutDirection() == wxLayout_RightToLeft)
+ {
+ if (event.GetKeyCode() == WXK_RIGHT)
+ event.m_keyCode = WXK_LEFT;
+ else if (event.GetKeyCode() == WXK_LEFT)
+ event.m_keyCode = WXK_RIGHT;
+ }
+
+ switch ( event.GetKeyCode() )
+ {
+ case WXK_UP:
+ if ( m_current > 0 )
+ OnArrowChar( m_current - 1, event );
+ break;
+
+ case WXK_DOWN:
+ if ( m_current < (size_t)GetItemCount() - 1 )
+ OnArrowChar( m_current + 1, event );
+ break;
+
+ case WXK_END:
+ if (!IsEmpty())
+ OnArrowChar( GetItemCount() - 1, event );
+ break;
+
+ case WXK_HOME:
+ if (!IsEmpty())
+ OnArrowChar( 0, event );
+ break;
+
+ case WXK_PAGEUP:
+ {
+ int steps = InReportView() ? pageSize - 1
+ : m_current % pageSize;
+
+ int index = m_current - steps;
+ if (index < 0)
+ index = 0;
+
+ OnArrowChar( index, event );
+ }
+ break;
+
+ case WXK_PAGEDOWN:
+ {
+ int steps = InReportView()
+ ? pageSize - 1
+ : pageSize - (m_current % pageSize) - 1;
+
+ size_t index = m_current + steps;
+ size_t count = GetItemCount();
+ if ( index >= count )
+ index = count - 1;
+
+ OnArrowChar( index, event );
+ }
+ break;
+
+ case WXK_LEFT:
+ if ( !InReportView() )
+ {
+ int index = m_current - pageSize;
+ if (index < 0)
+ index = 0;
+
+ OnArrowChar( index, event );
+ }
+ break;
+
+ case WXK_RIGHT:
+ if ( !InReportView() )
+ {
+ size_t index = m_current + pageSize;
+
+ size_t count = GetItemCount();
+ if ( index >= count )
+ index = count - 1;
+
+ OnArrowChar( index, event );
+ }
+ break;
+
+ case WXK_SPACE:
+ if ( IsSingleSel() )
+ {
+ if ( event.ControlDown() )
+ {
+ ReverseHighlight(m_current);
+ }
+ else // normal space press
+ {
+ SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
+ }
+ }
+ else // multiple selection
+ {
+ ReverseHighlight(m_current);
+ }
+ break;
+
+ case WXK_RETURN:
+ case WXK_EXECUTE:
+ SendNotify( m_current, wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
+ break;
+
+ default:
+ event.Skip();
+ }
+}
+
+// ----------------------------------------------------------------------------
+// focus handling
+// ----------------------------------------------------------------------------
+
+void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
+{
+ if ( GetParent() )
+ {
+ wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
+ event.SetEventObject( GetParent() );
+ if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
+ return;
+ }
+
+ // 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;
+
+ RefreshSelected();
+ }
+}
+
+void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
+{
+ if ( GetParent() )
+ {
+ wxFocusEvent event( wxEVT_KILL_FOCUS, GetParent()->GetId() );
+ event.SetEventObject( GetParent() );
+ if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
+ return;
+ }
+
+ m_hasFocus = false;
+ RefreshSelected();
+}
+
+void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
+{
+ if ( HasFlag(wxLC_ICON) && (m_normal_image_list))
+ {
+ m_normal_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
+ }
+ else if ( HasFlag(wxLC_SMALL_ICON) && (m_small_image_list))
+ {
+ m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
+ }
+ else if ( HasFlag(wxLC_LIST) && (m_small_image_list))
+ {
+ m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
+ }
+ else if ( InReportView() && (m_small_image_list))
+ {
+ m_small_image_list->Draw( index, *dc, x, y, wxIMAGELIST_DRAW_TRANSPARENT );
+ }
+}
+
+void wxListMainWindow::GetImageSize( int index, int &width, int &height ) const
+{
+ if ( HasFlag(wxLC_ICON) && m_normal_image_list )
+ {
+ m_normal_image_list->GetSize( index, width, height );
+ }
+ else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list )
+ {
+ m_small_image_list->GetSize( index, width, height );
+ }
+ else if ( HasFlag(wxLC_LIST) && m_small_image_list )
+ {
+ m_small_image_list->GetSize( index, width, height );
+ }
+ else if ( InReportView() && m_small_image_list )
+ {
+ m_small_image_list->GetSize( index, width, height );
+ }
+ else
+ {
+ width =
+ height = 0;
+ }
+}
+
+void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
+{
+ m_dirty = true;
+
+ // calc the spacing from the icon size
+ int width = 0, height = 0;
+
+ if ((imageList) && (imageList->GetImageCount()) )
+ imageList->GetSize(0, width, height);
+
+ if (which == wxIMAGE_LIST_NORMAL)
+ {
+ m_normal_image_list = imageList;
+ m_normal_spacing = width + 8;
+ }
+
+ if (which == wxIMAGE_LIST_SMALL)
+ {
+ m_small_image_list = imageList;
+ m_small_spacing = width + 14;
+ m_lineHeight = 0; // ensure that the line height will be recalc'd
+ }
+}
+
+void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall )
+{
+ m_dirty = true;
+ if (isSmall)
+ m_small_spacing = spacing;
+ else
+ m_normal_spacing = spacing;
+}
+
+int wxListMainWindow::GetItemSpacing( bool isSmall )
+{
+ return isSmall ? m_small_spacing : m_normal_spacing;
+}
+
+// ----------------------------------------------------------------------------
+// columns
+// ----------------------------------------------------------------------------
+
+int
+wxListMainWindow::ComputeMinHeaderWidth(const wxListHeaderData* column) const
+{
+ wxClientDC dc(const_cast<wxListMainWindow*>(this));
+
+ int width = dc.GetTextExtent(column->GetText()).x + AUTOSIZE_COL_MARGIN;
+
+ width += 2*EXTRA_WIDTH;
+
+ // check for column header's image availability
+ const int image = column->GetImage();
+ if ( image != -1 )
+ {
+ if ( m_small_image_list )
+ {
+ int ix = 0, iy = 0;
+ m_small_image_list->GetSize(image, ix, iy);
+ width += ix + HEADER_IMAGE_MARGIN_IN_REPORT_MODE;
+ }
+ }
+
+ return width;
+}
+
+void wxListMainWindow::SetColumn( int col, const wxListItem &item )
+{
+ wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
+
+ wxCHECK_RET( node, wxT("invalid column index in SetColumn") );
+
+ wxListHeaderData *column = node->GetData();
+ column->SetItem( item );
+
+ if ( item.m_width == wxLIST_AUTOSIZE_USEHEADER )
+ column->SetWidth(ComputeMinHeaderWidth(column));
+
+ wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
+ if ( headerWin )
+ headerWin->m_dirty = true;
+
+ m_dirty = true;
+
+ // invalidate it as it has to be recalculated
+ m_headerWidth = 0;
+}
+
+void wxListMainWindow::SetColumnWidth( int col, int width )
+{
+ wxCHECK_RET( col >= 0 && col < GetColumnCount(),
+ wxT("invalid column index") );
+
+ wxCHECK_RET( InReportView(),
+ wxT("SetColumnWidth() can only be called in report mode.") );
+
+ m_dirty = true;
+
+ wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
+ if ( headerWin )
+ headerWin->m_dirty = true;
+
+ wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
+ wxCHECK_RET( node, wxT("no column?") );
+
+ wxListHeaderData *column = node->GetData();
+
+ size_t count = GetItemCount();
+
+ if (width == wxLIST_AUTOSIZE_USEHEADER)
+ {
+ width = ComputeMinHeaderWidth(column);
+ }
+ else if ( width == wxLIST_AUTOSIZE )
+ {
+ width = ComputeMinHeaderWidth(column);
+
+ if ( !IsVirtual() )
+ {
+ wxClientDC dc(this);
+ dc.SetFont( GetFont() );
+
+ int max = AUTOSIZE_COL_MARGIN;
+
+ // if the cached column width isn't valid then recalculate it
+ if (m_aColWidths.Item(col)->bNeedsUpdate)
+ {
+ for (size_t i = 0; i < count; i++)
+ {
+ wxListLineData *line = GetLine( i );
+ wxListItemDataList::compatibility_iterator n = line->m_items.Item( col );
+
+ wxCHECK_RET( n, wxT("no subitem?") );
+
+ wxListItemData *itemData = n->GetData();
+ wxListItem item;
+
+ itemData->GetItem(item);
+ int itemWidth = GetItemWidthWithImage(&item);
+ if (itemWidth > max)
+ max = itemWidth;
+ }
+
+ m_aColWidths.Item(col)->bNeedsUpdate = false;
+ m_aColWidths.Item(col)->nMaxWidth = max;
+ }
+
+ max = m_aColWidths.Item(col)->nMaxWidth + AUTOSIZE_COL_MARGIN;
+ if ( width < max )
+ width = max;
+ }
+ }
+
+ column->SetWidth( width );
+
+ // invalidate it as it has to be recalculated
+ m_headerWidth = 0;
+}
+
+int wxListMainWindow::GetHeaderWidth() const
+{
+ if ( !m_headerWidth )
+ {
+ wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
+
+ size_t count = GetColumnCount();
+ for ( size_t col = 0; col < count; col++ )
+ {
+ self->m_headerWidth += GetColumnWidth(col);
+ }
+ }
+
+ return m_headerWidth;
+}
+
+void wxListMainWindow::GetColumn( int col, wxListItem &item ) const
+{
+ wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
+ wxCHECK_RET( node, wxT("invalid column index in GetColumn") );
+
+ wxListHeaderData *column = node->GetData();
+ column->GetItem( item );
+}
+
+int wxListMainWindow::GetColumnWidth( int col ) const
+{
+ wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col );
+ wxCHECK_MSG( node, 0, wxT("invalid column index") );
+
+ wxListHeaderData *column = node->GetData();
+ return column->GetWidth();
+}
+
+// ----------------------------------------------------------------------------
+// item state
+// ----------------------------------------------------------------------------
+
+void wxListMainWindow::SetItem( wxListItem &item )
+{
+ long id = item.m_itemId;
+ wxCHECK_RET( id >= 0 && (size_t)id < GetItemCount(),
+ wxT("invalid item index in SetItem") );
+
+ if ( !IsVirtual() )