X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3ca6a5f04692678cd2d9f3ea0843fc3f5a0b254f..f1d93f0beeec9d88f8a225aa35a9ccc163dcdb15:/src/generic/listctrl.cpp diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 607477e3eb..8e7857291f 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -25,6 +25,11 @@ #include "wx/generic/imaglist.h" #include "wx/dynarray.h" +#ifdef __WXGTK__ +#include +#include "wx/gtk/win_gtk.h" +#endif + #ifndef wxUSE_GENERIC_LIST_EXTENSIONS #define wxUSE_GENERIC_LIST_EXTENSIONS 1 #endif @@ -730,6 +735,23 @@ void wxListLineData::CalculateSize( wxDC *dc, int spacing ) m_bound_all.width = 0; m_bound_all.height = 0; wxNode *node = m_items.First(); + if (node) + { + wxListItemData *item = (wxListItemData*)node->Data(); + if (item->HasImage()) + { + int w = 0; + int h = 0; + m_owner->GetImageSize( item->GetImage(), w, h ); + m_bound_icon.width = w; + m_bound_icon.height = h; + } + else + { + m_bound_icon.width = 0; + m_bound_icon.height = 0; + } + } while (node) { wxListItemData *item = (wxListItemData*)node->Data(); @@ -746,6 +768,8 @@ void wxListLineData::CalculateSize( wxDC *dc, int spacing ) m_bound_all.height = lh; node = node->Next(); } + m_bound_label.width = m_bound_all.width; + m_bound_label.height = m_bound_all.height; break; } } @@ -1173,6 +1197,15 @@ wxListHeaderWindow::~wxListHeaderWindow( void ) void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h ) { +#ifdef __WXGTK__ + GtkStateType state = GTK_STATE_NORMAL; + if (!m_parent->IsEnabled()) state = GTK_STATE_INSENSITIVE; + + 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); +#else const int m_corner = 1; dc->SetBrush( *wxTRANSPARENT_BRUSH ); @@ -1192,6 +1225,7 @@ void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h ) dc->DrawRectangle( x, y, 1, h ); // left (outer) dc->DrawLine( x, y+h-1, x+1, y+h-1 ); dc->DrawLine( x+w-1, y, x+w-1, y+1 ); +#endif } // shift the DC origin to match the position of the main window horz @@ -1231,7 +1265,8 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) // do *not* use the listctrl colour for headers - one day we will have a // function to set it separately - dc.SetTextForeground( *wxBLACK ); + //dc.SetTextForeground( *wxBLACK ); + dc.SetTextForeground(wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT )); int x = 1; // left of the header rect const int y = 1; // top @@ -1625,6 +1660,12 @@ 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; wxListLineData *line = &m_lines[0]; int dummy = 0; @@ -1635,9 +1676,34 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) size_t i_to = y_s / lineSpacing + m_visibleLines+2; if (i_to >= m_lines.GetCount()) i_to = m_lines.GetCount(); - for (size_t i = y_s / lineSpacing; i < i_to; i++) + size_t i; + for (i = y_s / lineSpacing; i < i_to; i++) { m_lines[i].Draw( &dc ); + // Draw horizontal rule if required + if (GetWindowStyle() & wxLC_HRULES) + dc.DrawLine(0, i*lineSpacing, clientSize.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); + + // Draw vertical rules if required + if ((GetWindowStyle() & wxLC_VRULES) && (GetItemCount() > 0)) + { + int col = 0; + wxRect firstItemRect; + wxRect lastItemRect; + GetItemRect(0, firstItemRect); + GetItemRect(GetItemCount() - 1, lastItemRect); + int x = firstItemRect.GetX(); + for (col = 0; col < GetColumnCount(); col++) + { + int colWidth = GetColumnWidth(col); + x += colWidth ; + dc.DrawLine(x, firstItemRect.GetY() - 1, x, lastItemRect.GetBottom() + 1); + } } } else @@ -1703,7 +1769,7 @@ void wxListMainWindow::DeleteLine( wxListLineData *line ) void wxListMainWindow::EditLabel( long item ) { - wxCHECK_RET( ((size_t)item < m_lines.GetCount()), + wxCHECK_RET( ((size_t)item < m_lines.GetCount()), wxT("wrong index in wxListCtrl::Edit()") ); m_currentEdit = &m_lines[(size_t)item]; @@ -1768,6 +1834,7 @@ void wxListMainWindow::OnRenameAccept() void wxListMainWindow::OnMouse( wxMouseEvent &event ) { + event.SetEventObject( GetParent() ); if (GetParent()->GetEventHandler()->ProcessEvent( event)) return; if (!m_current) return; @@ -1887,7 +1954,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) else if (event.ShiftDown()) { size_t j; - + m_current = line; int numOfCurrent = -1; @@ -2095,7 +2162,7 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) if (index != wxNOT_FOUND) { index -= steps; - if (index < 0) index = 0; + if (index < 0) index = 0; OnArrowChar( &m_lines[index], event.ShiftDown() ); } break; @@ -2116,7 +2183,7 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) if (index != wxNOT_FOUND) { index += steps; - if ((size_t)index >= m_lines.GetCount()) + if ((size_t)index >= m_lines.GetCount()) index = m_lines.GetCount()-1; OnArrowChar( &m_lines[index], event.ShiftDown() ); } @@ -2144,7 +2211,7 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) if (index != wxNOT_FOUND) { index += m_visibleLines; - if ((size_t)index >= m_lines.GetCount()) + if ((size_t)index >= m_lines.GetCount()) index = m_lines.GetCount()-1; OnArrowChar( &m_lines[index], event.ShiftDown() ); } @@ -2381,7 +2448,7 @@ void wxListMainWindow::SetColumnWidth( int col, int width ) wxClientDC dc(this); dc.SetFont( GetFont() ); int max = 10; - + for (size_t i = 0; i < m_lines.GetCount(); i++) { wxListLineData *line = &m_lines[i]; @@ -2915,7 +2982,7 @@ long wxListMainWindow::HitTest( int x, int y, int &flags ) { wxListLineData *line = &m_lines[i]; long ret = line->IsHit( x, y ); - if (ret & flags) + if (ret) // & flags) // No: flags is output-only so may be garbage at this point { flags = (int)ret; return count; @@ -2954,6 +3021,7 @@ void wxListMainWindow::InsertItem( wxListItem &item ) else { m_lines.Add( line ); + item.m_itemId = m_lines.GetCount()-1; } } @@ -3126,12 +3194,16 @@ wxListCtrl::wxListCtrl() m_imageListNormal = (wxImageList *) NULL; m_imageListSmall = (wxImageList *) NULL; m_imageListState = (wxImageList *) NULL; + m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = FALSE; m_mainWin = (wxListMainWindow*) NULL; m_headerWin = (wxListHeaderWindow*) NULL; } wxListCtrl::~wxListCtrl() { + if (m_ownsImageListNormal) delete m_imageListNormal; + if (m_ownsImageListSmall) delete m_imageListSmall; + if (m_ownsImageListState) delete m_imageListState; } bool wxListCtrl::Create(wxWindow *parent, @@ -3145,6 +3217,7 @@ bool wxListCtrl::Create(wxWindow *parent, m_imageListNormal = (wxImageList *) NULL; m_imageListSmall = (wxImageList *) NULL; m_imageListState = (wxImageList *) NULL; + m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = FALSE; m_mainWin = (wxListMainWindow*) NULL; m_headerWin = (wxListHeaderWindow*) NULL; @@ -3442,9 +3515,39 @@ wxImageList *wxListCtrl::GetImageList(int which) const void wxListCtrl::SetImageList( wxImageList *imageList, int which ) { + if ( which == wxIMAGE_LIST_NORMAL ) + { + if (m_ownsImageListNormal) delete m_imageListNormal; + m_imageListNormal = imageList; + m_ownsImageListNormal = FALSE; + } + else if ( which == wxIMAGE_LIST_SMALL ) + { + if (m_ownsImageListSmall) delete m_imageListSmall; + m_imageListSmall = imageList; + m_ownsImageListSmall = FALSE; + } + else if ( which == wxIMAGE_LIST_STATE ) + { + if (m_ownsImageListState) delete m_imageListState; + m_imageListState = imageList; + m_ownsImageListState = FALSE; + } + m_mainWin->SetImageList( imageList, which ); } +void wxListCtrl::AssignImageList(wxImageList *imageList, int which) +{ + SetImageList(imageList, which); + if ( which == wxIMAGE_LIST_NORMAL ) + m_ownsImageListNormal = TRUE; + else if ( which == wxIMAGE_LIST_SMALL ) + m_ownsImageListSmall = TRUE; + else if ( which == wxIMAGE_LIST_STATE ) + m_ownsImageListState = TRUE; +} + bool wxListCtrl::Arrange( int WXUNUSED(flag) ) { return 0;