+void wxListTextCtrl::OnChar( wxKeyEvent &event )
+{
+ if (event.m_keyCode == WXK_RETURN)
+ {
+ (*m_accept) = TRUE;
+ (*m_res) = GetValue();
+
+ if (!wxPendingDelete.Member(this))
+ wxPendingDelete.Append(this);
+
+ if ((*m_accept) && ((*m_res) != m_startValue))
+ m_owner->OnRenameAccept();
+
+ return;
+ }
+ if (event.m_keyCode == WXK_ESCAPE)
+ {
+ (*m_accept) = FALSE;
+ (*m_res) = "";
+
+ if (!wxPendingDelete.Member(this))
+ wxPendingDelete.Append(this);
+
+ return;
+ }
+
+ event.Skip();
+}
+
+void wxListTextCtrl::OnKeyUp( wxKeyEvent &event )
+{
+ // 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??
+ if (myPos.x + sx > parentSize.x)
+ sx = parentSize.x - myPos.x;
+ if (mySize.x > sx)
+ sx = mySize.x;
+ SetSize(sx, -1);
+
+ event.Skip();
+}
+
+void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
+{
+ if (!wxPendingDelete.Member(this))
+ wxPendingDelete.Append(this);
+
+ if ((*m_accept) && ((*m_res) != m_startValue))
+ m_owner->OnRenameAccept();
+}
+
+//-----------------------------------------------------------------------------
+// wxListMainWindow
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow);
+
+BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow)
+ EVT_PAINT (wxListMainWindow::OnPaint)
+ EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse)
+ EVT_CHAR (wxListMainWindow::OnChar)
+ EVT_KEY_DOWN (wxListMainWindow::OnKeyDown)
+ EVT_SET_FOCUS (wxListMainWindow::OnSetFocus)
+ EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus)
+ EVT_SCROLLWIN (wxListMainWindow::OnScroll)
+END_EVENT_TABLE()
+
+void wxListMainWindow::Init()
+{
+ m_columns.DeleteContents( TRUE );
+ m_dirty = TRUE;
+ m_countVirt = 0;
+ m_lineFrom =
+ m_lineTo = (size_t)-1;
+ m_linesPerPage = 0;
+
+ m_headerWidth =
+ m_lineHeight = 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_lastOnSame = FALSE;
+ m_renameTimer = new wxListRenameTimer( this );
+ m_renameAccept = FALSE;
+
+ m_current =
+ m_currentEdit =
+ m_lineLastClicked =
+ m_lineBeforeLastClicked = (size_t)-1;
+}
+
+void wxListMainWindow::InitScrolling()
+{
+ if ( HasFlag(wxLC_REPORT) )
+ {
+ m_xScroll = SCROLL_UNIT_X;
+ m_yScroll = SCROLL_UNIT_Y;
+ }
+ else
+ {
+ m_xScroll = SCROLL_UNIT_Y;
+ m_yScroll = 0;
+ }
+}
+
+wxListMainWindow::wxListMainWindow()
+{
+ Init();
+
+ m_highlightBrush =
+ m_highlightUnfocusedBrush = (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_highlightBrush = new wxBrush
+ (
+ wxSystemSettings::GetSystemColour
+ (
+ wxSYS_COLOUR_HIGHLIGHT
+ ),
+ wxSOLID
+ );
+
+ m_highlightUnfocusedBrush = new wxBrush
+ (
+ wxSystemSettings::GetSystemColour
+ (
+ wxSYS_COLOUR_BTNSHADOW
+ ),
+ wxSOLID
+ );
+
+ wxSize sz = size;
+ sz.y = 25;
+
+ InitScrolling();
+ SetScrollbars( m_xScroll, m_yScroll, 0, 0, 0, 0 );
+
+ SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_LISTBOX ) );
+}
+
+wxListMainWindow::~wxListMainWindow()
+{
+ DoDeleteAllItems();
+
+ delete m_highlightBrush;
+ delete m_highlightUnfocusedBrush;
+
+ delete m_renameTimer;
+}
+
+void wxListMainWindow::CacheLineData(size_t line)
+{
+ wxListCtrl *listctrl = GetListCtrl();
+
+ wxListLineData *ld = GetDummyLine();
+
+ size_t countCol = GetColumnCount();
+ for ( size_t col = 0; col < countCol; col++ )
+ {
+ ld->SetText(col, listctrl->OnGetItemText(line, col));
+ }
+
+ ld->SetImage(listctrl->OnGetItemImage(line));
+ ld->SetAttr(listctrl->OnGetItemAttr(line));
+}
+
+wxListLineData *wxListMainWindow::GetDummyLine() const
+{
+ wxASSERT_MSG( !IsEmpty(), _T("invalid line index") );
+
+ if ( m_lines.IsEmpty() )
+ {
+ // normal controls are supposed to have something in m_lines
+ // already if it's not empty
+ wxASSERT_MSG( IsVirtual(), _T("logic error") );
+
+ wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
+ wxListLineData *line = new wxListLineData(self);
+ self->m_lines.Add(line);
+ }
+
+ return &m_lines[0];
+}
+
+// ----------------------------------------------------------------------------
+// line geometry (report mode only)
+// ----------------------------------------------------------------------------
+
+wxCoord wxListMainWindow::GetLineHeight() const
+{
+ wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("only works in report mode") );
+
+ // we cache the line height as calling GetTextExtent() is slow
+ if ( !m_lineHeight )
+ {
+ wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
+
+ wxClientDC dc( self );
+ dc.SetFont( GetFont() );
+
+ wxCoord y;
+ dc.GetTextExtent(_T("H"), NULL, &y);
+
+ if ( y < SCROLL_UNIT_Y )
+ y = SCROLL_UNIT_Y;
+ y += EXTRA_HEIGHT;
+
+ self->m_lineHeight = y + LINE_SPACING;
+ }
+
+ return m_lineHeight;
+}
+
+wxCoord wxListMainWindow::GetLineY(size_t line) const
+{
+ wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("only works in report mode") );
+
+ return LINE_SPACING + line*GetLineHeight();
+}
+
+wxRect wxListMainWindow::GetLineRect(size_t line) const
+{
+ if ( !InReportView() )
+ return GetLine(line)->m_gi->m_rectAll;
+
+ wxRect rect;
+ rect.x = HEADER_OFFSET_X;
+ rect.y = GetLineY(line);
+ rect.width = GetHeaderWidth();
+ rect.height = GetLineHeight();
+
+ return rect;
+}
+
+wxRect wxListMainWindow::GetLineLabelRect(size_t line) const
+{
+ if ( !InReportView() )
+ return GetLine(line)->m_gi->m_rectLabel;
+
+ wxRect rect;
+ rect.x = HEADER_OFFSET_X;
+ rect.y = GetLineY(line);
+ rect.width = GetColumnWidth(0);
+ rect.height = GetLineHeight();
+
+ return rect;
+}
+
+wxRect wxListMainWindow::GetLineIconRect(size_t line) const
+{
+ if ( !InReportView() )
+ return GetLine(line)->m_gi->m_rectIcon;
+
+ wxListLineData *ld = GetLine(line);
+ wxASSERT_MSG( ld->HasImage(), _T("should have an image") );
+
+ wxRect rect;
+ rect.x = HEADER_OFFSET_X;
+ rect.y = GetLineY(line);
+ GetImageSize(ld->GetImage(), rect.width, rect.height);
+
+ return rect;
+}
+
+wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const
+{
+ return InReportView() ? GetLineRect(line)
+ : GetLine(line)->m_gi->m_rectHighlight;
+}
+
+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) )
+ return wxLIST_HITTEST_ONITEMICON;
+
+ if ( ld->HasText() )
+ {
+ wxRect rect = InReportView() ? GetLineRect(line)
+ : GetLineLabelRect(line);
+
+ if ( rect.Inside(x, y) )
+ return wxLIST_HITTEST_ONITEMLABEL;
+ }
+
+ return 0;
+}
+
+// ----------------------------------------------------------------------------
+// highlight (selection) handling
+// ----------------------------------------------------------------------------
+
+bool wxListMainWindow::IsHighlighted(size_t line) const