+void wxListHeaderWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
+{
+ m_owner->SetFocus();
+ m_owner->Update();
+}
+
+bool wxListHeaderWindow::SendListEvent(wxEventType type, wxPoint pos)
+{
+ wxWindow *parent = GetParent();
+ wxListEvent le( type, parent->GetId() );
+ le.SetEventObject( parent );
+ le.m_pointDrag = pos;
+
+ // 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;
+ return !parent->GetEventHandler()->ProcessEvent( le ) || le.IsAllowed();
+}
+
+//-----------------------------------------------------------------------------
+// wxListRenameTimer (internal)
+//-----------------------------------------------------------------------------
+
+wxListRenameTimer::wxListRenameTimer( wxListMainWindow *owner )
+{
+ m_owner = owner;
+}
+
+void wxListRenameTimer::Notify()
+{
+ m_owner->OnRenameTimer();
+}
+
+//-----------------------------------------------------------------------------
+// wxListTextCtrl (internal)
+//-----------------------------------------------------------------------------
+
+BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl)
+ EVT_CHAR (wxListTextCtrl::OnChar)
+ EVT_KEY_UP (wxListTextCtrl::OnKeyUp)
+ EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus)
+END_EVENT_TABLE()
+
+wxListTextCtrl::wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit)
+ : m_startValue(owner->GetItemText(itemEdit)),
+ m_itemEdited(itemEdit)
+{
+ m_owner = owner;
+ m_finished = false;
+ m_aboutToFinish = false;
+
+ wxRect rectLabel = owner->GetLineLabelRect(itemEdit);
+
+ m_owner->CalcScrolledPosition(rectLabel.x, rectLabel.y,
+ &rectLabel.x, &rectLabel.y);
+
+ (void)Create(owner, wxID_ANY, m_startValue,
+ wxPoint(rectLabel.x-4,rectLabel.y-4),
+ wxSize(rectLabel.width+11,rectLabel.height+8));
+}
+
+void wxListTextCtrl::Finish()
+{
+ if ( !m_finished )
+ {
+ wxPendingDelete.Append(this);
+
+ m_finished = true;
+
+ m_owner->SetFocusIgnoringChildren();
+ }
+}
+
+bool wxListTextCtrl::AcceptChanges()
+{
+ const wxString value = GetValue();
+
+ if ( value == m_startValue )
+ {
+ // nothing changed, always accept
+ return true;
+ }
+
+ if ( !m_owner->OnRenameAccept(m_itemEdited, value) )
+ {
+ // vetoed by the user
+ return false;
+ }
+
+ // accepted, do rename the item
+ m_owner->SetItemText(m_itemEdited, value);
+
+ return true;
+}
+
+void wxListTextCtrl::OnChar( wxKeyEvent &event )
+{
+ switch ( event.m_keyCode )
+ {
+ case WXK_RETURN:
+ m_aboutToFinish = true;
+ // Notify the owner about the changes
+ AcceptChanges();
+ // Even if vetoed, close the control (consistent with MSW)
+ Finish();
+ break;
+
+ case WXK_ESCAPE:
+ Finish();
+ m_owner->OnRenameCancelled( m_itemEdited );
+ break;
+
+ default:
+ event.Skip();
+ }
+}
+
+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);
+ if (myPos.x + sx > parentSize.x)
+ sx = parentSize.x - myPos.x;
+ if (mySize.x > sx)
+ sx = mySize.x;
+ SetSize(sx, wxDefaultCoord);
+
+ event.Skip();
+}
+
+void wxListTextCtrl::OnKillFocus( wxFocusEvent &event )
+{
+ if ( !m_finished && !m_aboutToFinish )
+ {
+ // We must finish regardless of success, otherwise we'll get
+ // focus problems:
+ Finish();
+
+ if ( !AcceptChanges() )
+ m_owner->OnRenameCancelled( m_itemEdited );
+ }
+
+ // We must let the native text control handle focus, too, otherwise
+ // it could have problems with the cursor (e.g., in wxGTK).
+ event.Skip();
+}
+
+//-----------------------------------------------------------------------------
+// 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_dirty = true;
+ m_countVirt = 0;
+ m_lineFrom =
+ m_lineTo = (size_t)-1;
+ m_linesPerPage = 0;
+
+ m_headerWidth =
+ m_lineHeight = 0;
+
+ m_small_image_list = (wxImageListType *) NULL;
+ m_normal_image_list = (wxImageListType *) 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_current =
+ m_lineLastClicked =
+ m_lineSelectSingleOnUp =
+ m_lineBeforeLastClicked = (size_t)-1;
+
+ m_freezeCount = 0;
+}
+
+wxListMainWindow::wxListMainWindow()
+{
+ Init();
+
+ m_highlightBrush =
+ m_highlightUnfocusedBrush = (wxBrush *) NULL;
+}
+
+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::GetColour
+ (
+ wxSYS_COLOUR_HIGHLIGHT
+ ),
+ wxSOLID
+ );
+
+ m_highlightUnfocusedBrush = new wxBrush
+ (
+ wxSystemSettings::GetColour
+ (
+ wxSYS_COLOUR_BTNSHADOW
+ ),
+ wxSOLID
+ );
+
+ SetScrollbars( 0, 0, 0, 0, 0, 0 );
+
+ wxVisualAttributes attr = wxGenericListCtrl::GetClassDefaultAttributes();
+ SetOwnForegroundColour( attr.colFg );
+ SetOwnBackgroundColour( attr.colBg );
+ if (!m_hasFont)
+ SetOwnFont( attr.font );
+}
+
+wxListMainWindow::~wxListMainWindow()
+{
+ DoDeleteAllItems();
+ WX_CLEAR_LIST(wxListHeaderDataList, m_columns);
+ WX_CLEAR_ARRAY(m_aColWidths);
+
+ delete m_highlightBrush;
+ delete m_highlightUnfocusedBrush;
+
+ delete m_renameTimer;
+}
+
+void wxListMainWindow::CacheLineData(size_t line)
+{
+ wxGenericListCtrl *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") );
+
+ wxASSERT_MSG( IsVirtual(), _T("GetDummyLine() shouldn't be called") );
+
+ wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
+
+ // we need to recreate the dummy line if the number of columns in the
+ // control changed as it would have the incorrect number of fields
+ // otherwise
+ if ( !m_lines.IsEmpty() &&
+ m_lines[0].m_items.GetCount() != (size_t)GetColumnCount() )
+ {
+ self->m_lines.Clear();
+ }
+
+ if ( m_lines.IsEmpty() )
+ {
+ wxListLineData *line = new wxListLineData(self);
+ self->m_lines.Add(line);
+
+ // don't waste extra memory -- there never going to be anything
+ // else/more in this array
+ self->m_lines.Shrink();
+ }
+
+ return &m_lines[0];
+}
+
+// ----------------------------------------------------------------------------
+// line geometry (report mode only)
+// ----------------------------------------------------------------------------
+
+wxCoord wxListMainWindow::GetLineHeight() const
+{
+ // 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 ( m_small_image_list && m_small_image_list->GetImageCount() )
+ {
+ int iw = 0;
+ int ih = 0;
+ m_small_image_list->GetSize(0, iw, ih);
+ y = wxMax(y, ih);
+ }
+
+ y += EXTRA_HEIGHT;
+ self->m_lineHeight = y + LINE_SPACING;
+ }
+
+ return m_lineHeight;
+}
+
+wxCoord wxListMainWindow::GetLineY(size_t line) const