X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c13cace12594b37706e9520a6fbd602c949f8127..0c55409f3a315e45963bc48f52435245e6af6c9d:/src/generic/listctrl.cpp diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 6b0861d9b0..ba33085757 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -34,6 +34,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 // ============================================================================ @@ -316,7 +337,9 @@ public: 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 ); @@ -1204,8 +1227,8 @@ void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h ) 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 +1270,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 ); @@ -1667,6 +1695,10 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) wxPaintDC dc( this ); PrepareDC( dc ); + int dev_x = 0; + int dev_y = 0; + CalcScrolledPosition( 0, 0, &dev_x, &dev_y ); + if (m_dirty) return; if (m_lines.GetCount() == 0) return; @@ -1678,9 +1710,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; @@ -1699,12 +1728,20 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) m_lines[i].Draw( &dc ); // Draw horizontal rule if required if (GetWindowStyle() & wxLC_HRULES) - dc.DrawLine(0, i*lineSpacing, clientSize.x, i*lineSpacing); + { + 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); + { + 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)) @@ -1715,11 +1752,13 @@ 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); } } } @@ -1747,11 +1786,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 ); @@ -1882,8 +1928,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() ); @@ -1936,7 +1982,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; } @@ -2046,8 +2093,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 ); } @@ -2632,7 +2679,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; @@ -2664,6 +2711,7 @@ void wxListMainWindow::GetItemRect( long index, wxRect &rect ) if (index >= 0 && (size_t)index < m_lines.GetCount()) { m_lines[(size_t)index].GetRect( rect ); + this->CalcScrolledPosition(rect.x,rect.y,&rect.x,&rect.y); } else { @@ -2676,18 +2724,9 @@ void wxListMainWindow::GetItemRect( long index, wxRect &rect ) bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) { - if (item >= 0 && (size_t)item < m_lines.GetCount()) - { - wxRect rect; - m_lines[(size_t)item].GetRect( rect ); - pos.x = rect.x; - pos.y = rect.y; - } - else - { - pos.x = 0; - pos.y = 0; - } + wxRect rect; + this->GetItemRect(item,rect); + pos.x=rect.x; pos.y=rect.y; return TRUE; } @@ -2759,6 +2798,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; @@ -2766,7 +2808,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 ); @@ -2788,9 +2830,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 @@ -3087,7 +3129,8 @@ void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data ) void wxListMainWindow::OnScroll(wxScrollWinEvent& event) { - wxScrolledWindow::OnScroll( event ) ; + wxScrolledWindow::OnScroll( event ) ; + #if wxUSE_GENERIC_LIST_EXTENSIONS if (event.GetOrientation() == wxHORIZONTAL && ( m_mode & wxLC_REPORT ))