X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/94248d2ed19bb207a49cf1a5bd9bfea0fd04760b..931d6a47c32a5b4c283243cb553ce71ee2b535d5:/src/common/listctrlcmn.cpp diff --git a/src/common/listctrlcmn.cpp b/src/common/listctrlcmn.cpp index 861beef994..e6101be4c3 100644 --- a/src/common/listctrlcmn.cpp +++ b/src/common/listctrlcmn.cpp @@ -3,7 +3,6 @@ // Purpose: Common defines for wxListCtrl and wxListCtrl-based classes. // Author: Kevin Ollivier // Created: 09/15/06 -// RCS-ID: $Id$ // Copyright: (c) Kevin Ollivier // Licence: wxWindows licence //////////////////////////////////////////////////////////////////////////////// @@ -34,26 +33,26 @@ const char wxListCtrlNameStr[] = "listCtrl"; // ListCtrl events -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_BEGIN_DRAG, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_BEGIN_RDRAG, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_END_LABEL_EDIT, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_DELETE_ITEM, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_KEY_DOWN, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_INSERT_ITEM, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_COL_CLICK, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_COL_DRAGGING, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_COL_END_DRAG, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_ITEM_FOCUSED, wxListEvent ); -wxDEFINE_EVENT( wxEVT_COMMAND_LIST_CACHE_HINT, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_BEGIN_DRAG, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_BEGIN_RDRAG, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_BEGIN_LABEL_EDIT, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_END_LABEL_EDIT, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_DELETE_ITEM, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_DELETE_ALL_ITEMS, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_ITEM_SELECTED, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_ITEM_DESELECTED, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_KEY_DOWN, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_INSERT_ITEM, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_COL_CLICK, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_COL_RIGHT_CLICK, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_COL_BEGIN_DRAG, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_COL_DRAGGING, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_COL_END_DRAG, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_ITEM_RIGHT_CLICK, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_ITEM_MIDDLE_CLICK, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_ITEM_ACTIVATED, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_ITEM_FOCUSED, wxListEvent ); +wxDEFINE_EVENT( wxEVT_LIST_CACHE_HINT, wxListEvent ); // ----------------------------------------------------------------------------- // XTI @@ -111,7 +110,7 @@ wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl, "wx/listctrl.h") #endif wxBEGIN_PROPERTIES_TABLE(wxListCtrl) -wxEVENT_PROPERTY( TextUpdated, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEvent ) +wxEVENT_PROPERTY( TextUpdated, wxEVT_TEXT, wxCommandEvent ) wxPROPERTY_FLAGS( WindowStyle, wxListCtrlStyle, long, SetWindowStyleFlag, \ GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \ @@ -136,6 +135,14 @@ IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent) // wxListCtrlBase implementation // ---------------------------------------------------------------------------- +long +wxListCtrlBase::AppendColumn(const wxString& heading, + wxListColumnFormat format, + int width) +{ + return InsertColumn(GetColumnCount(), heading, format, width); +} + long wxListCtrlBase::InsertColumn(long col, const wxString& heading, @@ -145,7 +152,9 @@ wxListCtrlBase::InsertColumn(long col, wxListItem item; item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; item.m_text = heading; - if ( width > -1 ) + if ( width >= 0 + || width == wxLIST_AUTOSIZE + || width == wxLIST_AUTOSIZE_USEHEADER ) { item.m_mask |= wxLIST_MASK_WIDTH; item.m_width = width; @@ -175,6 +184,9 @@ wxSize wxListCtrlBase::DoGetBestClientSize() const if ( !InReportView() ) return wxControl::DoGetBestClientSize(); + int totalWidth; + wxClientDC dc(const_cast(this)); + // In report mode, we use only the column headers, not items, to determine // the best width. The reason for this is that it's easier (we can't just // iterate over all items, especially not in a virtual control, so we'd @@ -186,19 +198,55 @@ wxSize wxListCtrlBase::DoGetBestClientSize() const // headers are just truncated if there is not enough place for them. const int columns = GetColumnCount(); if ( HasFlag(wxLC_NO_HEADER) || !columns ) - return wxControl::DoGetBestClientSize(); - - wxClientDC dc(const_cast(this)); - - // Total width of all headers determines the best control width. - int totalWidth = 0; - for ( int col = 0; col < columns; col++ ) { - totalWidth += GetColumnWidth(col); + // Use some arbitrary width. + totalWidth = 50*dc.GetCharWidth(); + } + else // We do have columns, use them to determine the best width. + { + totalWidth = 0; + for ( int col = 0; col < columns; col++ ) + { + totalWidth += GetColumnWidth(col); + } } // Use some arbitrary height, there is no good way to determine it. return wxSize(totalWidth, 10*dc.GetCharHeight()); } +void wxListCtrlBase::SetAlternateRowColour(const wxColour& colour) +{ + wxASSERT(HasFlag(wxLC_VIRTUAL)); + m_alternateRowColour.SetBackgroundColour(colour); +} + +void wxListCtrlBase::EnableAlternateRowColours(bool enable) +{ + if ( enable ) + { + // This code is copied from wxDataViewMainWindow::OnPaint() + + // Determine the alternate rows colour automatically from the + // background colour. + const wxColour bgColour = GetBackgroundColour(); + + // Depending on the background, alternate row color + // will be 3% more dark or 50% brighter. + int alpha = bgColour.GetRGB() > 0x808080 ? 97 : 150; + SetAlternateRowColour(bgColour.ChangeLightness(alpha)); + } + else // Disable striping by setting invalid alternative colour. + { + SetAlternateRowColour(wxColour()); + } +} + +wxListItemAttr *wxListCtrlBase::OnGetItemAttr(long item) const +{ + return (m_alternateRowColour.GetBackgroundColour().IsOk() && (item % 2)) + ? wxConstCast(&m_alternateRowColour, wxListItemAttr) + : NULL; // no attributes by default +} + #endif // wxUSE_LISTCTRL