X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ccdbdc893684dee60877f35132c5ec5d8ec23446..9e1fc0e42822fdf1159582f1b73cde0c7d15bc92:/src/generic/listctrl.cpp diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 4f76d244cb..3bda4a220f 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -52,12 +52,6 @@ #include "wx/mac/private.h" #endif -#ifdef __WXGTK__ - #include "wx/gtk/private.h" - #include "wx/gtk/win_gtk.h" -#endif - - // NOTE: If using the wxListBox visual attributes works everywhere then this can // be removed, as well as the #else case below. @@ -209,6 +203,7 @@ public: void SetItem( const wxListItem &item ); void SetPosition( int x, int y ); void SetWidth( int w ); + void SetState( int state ); void SetFormat( int format ); void SetHeight( int h ); bool HasImage() const; @@ -223,6 +218,7 @@ public: int GetImage() const; int GetWidth() const; int GetFormat() const; + int GetState() const; protected: long m_mask; @@ -233,6 +229,7 @@ protected: int m_xpos, m_ypos; int m_height; + int m_state; private: void Init(); @@ -697,7 +694,7 @@ public: // send out a wxListEvent void SendNotify( size_t line, - wxEventType command, + wxEventType command, const wxPoint& point = wxDefaultPosition ); // override base class virtual to reset m_lineHeight when the font changes @@ -1008,6 +1005,7 @@ void wxListHeaderData::Init() m_xpos = 0; m_ypos = 0; m_height = 0; + m_state = 0; } wxListHeaderData::wxListHeaderData() @@ -1037,6 +1035,9 @@ void wxListHeaderData::SetItem( const wxListItem &item ) if ( m_mask & wxLIST_MASK_WIDTH ) SetWidth(item.m_width); + + if ( m_mask & wxLIST_MASK_STATE ) + SetState(item.m_state); } void wxListHeaderData::SetPosition( int x, int y ) @@ -1055,6 +1056,11 @@ void wxListHeaderData::SetWidth( int w ) m_width = w < 0 ? WIDTH_COL_DEFAULT : w; } +void wxListHeaderData::SetState( int flag ) +{ + m_state = flag; +} + void wxListHeaderData::SetFormat( int format ) { m_format = format; @@ -1077,6 +1083,7 @@ void wxListHeaderData::GetItem( wxListItem& item ) item.m_image = m_image; item.m_format = m_format; item.m_width = m_width; + item.m_state = m_state; } int wxListHeaderData::GetImage() const @@ -1094,6 +1101,11 @@ int wxListHeaderData::GetFormat() const return m_format; } +int wxListHeaderData::GetState() const +{ + return m_state; +} + //----------------------------------------------------------------------------- // wxListLineData //----------------------------------------------------------------------------- @@ -1448,7 +1460,7 @@ void wxListLineData::Draw( wxDC *dc ) wxListItemAttr *attr = GetAttr(); if ( SetAttributes(dc, attr, highlighted) ) -#ifndef __WXGTK__ +#if ( !defined(__WXGTK20__) && !defined(__WXMAC__) ) { dc->DrawRectangle( m_gi->m_rectHighlight ); } @@ -1456,17 +1468,11 @@ void wxListLineData::Draw( wxDC *dc ) { if (highlighted) { - wxRect rect2( m_gi->m_rectHighlight ); - m_owner->CalcScrolledPosition( rect2.x, rect2.y, &rect2.x, &rect2.y ); - - gtk_paint_flat_box( m_owner->m_widget->style, - GTK_PIZZA(m_owner->m_wxwindow)->bin_window, - GTK_STATE_SELECTED, - GTK_SHADOW_NONE, - NULL, - m_owner->m_wxwindow, - "cell_even", - rect2.x, rect2.y, rect2.width, rect2.height ); + int flags = wxCONTROL_SELECTED; + if (m_owner->HasFocus()) + flags |= wxCONTROL_FOCUSED; + wxRendererNative::Get().DrawItemSelectionRect( m_owner, *dc, m_gi->m_rectHighlight, flags ); + } else { @@ -1513,7 +1519,7 @@ void wxListLineData::DrawInReportMode( wxDC *dc, // GetAttr() and move these lines into the loop below wxListItemAttr *attr = GetAttr(); if ( SetAttributes(dc, attr, highlighted) ) -#ifndef __WXGTK__ +#if ( !defined(__WXGTK20__) && !defined(__WXMAC__) ) { dc->DrawRectangle( rectHL ); } @@ -1521,17 +1527,10 @@ void wxListLineData::DrawInReportMode( wxDC *dc, { if (highlighted) { - wxRect rect2( rectHL ); - m_owner->CalcScrolledPosition( rect2.x, rect2.y, &rect2.x, &rect2.y ); - - gtk_paint_flat_box( m_owner->m_widget->style, - GTK_PIZZA(m_owner->m_wxwindow)->bin_window, - GTK_STATE_SELECTED, - GTK_SHADOW_NONE, - NULL, - m_owner->m_wxwindow, - "cell_even", - rect2.x, rect2.y, rect2.width, rect2.height ); + int flags = wxCONTROL_SELECTED; + if (m_owner->HasFocus()) + flags |= wxCONTROL_FOCUSED; + wxRendererNative::Get().DrawItemSelectionRect( m_owner, *dc, rectHL, flags ); } else { @@ -1798,13 +1797,26 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) int ch = h - 2; #endif + int flags = 0; + if (!m_parent->IsEnabled()) + flags |= wxCONTROL_DISABLED; + +// NB: The code below is not really Mac-specific, but since we are close +// to 2.8 release and I don't have time to test on other platforms, I +// defined this only for wxMac. If this behavior is desired on +// other platforms, please go ahead and revise or remove the #ifdef. +#ifdef __WXMAC__ + if ( !m_owner->IsVirtual() && (item.m_mask & wxLIST_MASK_STATE) && + (item.m_state & wxLIST_STATE_SELECTED) ) + flags |= wxCONTROL_SELECTED; +#endif + wxRendererNative::Get().DrawHeaderButton ( this, dc, wxRect(x, HEADER_OFFSET_Y, cw, ch), - m_parent->IsEnabled() ? 0 - : (int)wxCONTROL_DISABLED + flags ); // see if we have enough space for the column label @@ -2000,6 +2012,22 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) } else // click on a column { + // record the selected state of the columns + if (event.LeftDown()) + { + for (int i=0; i < m_owner->GetColumnCount(); i++) + { + wxListItem colItem; + m_owner->GetColumn(i, colItem); + long state = colItem.GetState(); + if (i == m_column) + colItem.SetState(state | wxLIST_STATE_SELECTED); + else + colItem.SetState(state & ~wxLIST_STATE_SELECTED); + m_owner->SetColumn(i, colItem); + } + } + SendListEvent( event.LeftDown() ? wxEVT_COMMAND_LIST_COL_CLICK : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, @@ -2262,14 +2290,6 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, { Init(); - -#ifdef __WXMAC__ - // OS X sel item highlight color differs from text highlight color, which is - // what wxSYS_COLOUR_HIGHLIGHT returns. - RGBColor hilight; - GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor, 32, true, &hilight); - m_highlightBrush = new wxBrush( wxColour(hilight.red, hilight.green, hilight.blue ), wxSOLID ); -#else m_highlightBrush = new wxBrush ( wxSystemSettings::GetColour @@ -2278,14 +2298,7 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, ), wxSOLID ); -#endif - -#ifdef __WXMAC__ - // on Mac, this color also differs from the wxSYS_COLOUR_BTNSHADOW, enough to be noticable. - // I don't know if BTNSHADOW is appropriate in other contexts, so I'm just changing it here. - GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor, 32, true, &hilight); - m_highlightUnfocusedBrush = new wxBrush( wxColour(hilight.red, hilight.green, hilight.blue ), wxSOLID ); -#else + m_highlightUnfocusedBrush = new wxBrush ( wxSystemSettings::GetColour @@ -2294,7 +2307,6 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, ), wxSOLID ); -#endif SetScrollbars( 0, 0, 0, 0, 0, 0 ); @@ -2796,20 +2808,12 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) if ( m_hasFocus ) { wxRect rect( GetLineHighlightRect( m_current ) ); -#ifndef __WXGTK__ +#ifndef __WXGTK20__ dc.SetPen( *wxBLACK_PEN ); dc.SetBrush( *wxTRANSPARENT_BRUSH ); dc.DrawRectangle( rect ); #else - CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y ); - - gtk_paint_focus( m_widget->style, - GTK_PIZZA(m_wxwindow)->bin_window, - GTK_STATE_SELECTED, - NULL, - m_wxwindow, - "treeview", - rect.x, rect.y, rect.width, rect.height ); + wxRendererNative::Get().DrawItemSelectionRect( this, dc, rect, wxCONTROL_CURRENT|wxCONTROL_FOCUSED ); #endif } @@ -2842,6 +2846,7 @@ void wxListMainWindow::SendNotify( size_t line, { wxListEvent le( command, GetParent()->GetId() ); le.SetEventObject( GetParent() ); + le.m_itemIndex = line; // set only for events which have position @@ -2852,7 +2857,7 @@ void wxListMainWindow::SendNotify( size_t line, // program has it anyhow and if we did it would result in accessing all // the lines, even those which are not visible now and this is precisely // what we're trying to avoid - if ( !IsVirtual() && (command != wxEVT_COMMAND_LIST_DELETE_ITEM) ) + if ( !IsVirtual() ) { if ( line != (size_t)-1 ) { @@ -4332,11 +4337,11 @@ void wxListMainWindow::DeleteItem( long lindex ) if ( m_current != index || m_current == count - 1 ) m_current--; } - + if ( InReportView() ) { - // mark the Column Max Width cache as dirty if the items in the line - // we're deleting contain the Max Column Width + // mark the Column Max Width cache as dirty if the items in the line + // we're deleting contain the Max Column Width wxListLineData * const line = GetLine(index); wxListItemDataList::compatibility_iterator n; wxListItemData *itemData; @@ -4358,6 +4363,8 @@ void wxListMainWindow::DeleteItem( long lindex ) ResetVisibleLinesRange(); } + SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM, wxDefaultPosition ); + if ( IsVirtual() ) { m_countVirt--; @@ -4371,8 +4378,6 @@ void wxListMainWindow::DeleteItem( long lindex ) // we need to refresh the (vert) scrollbar as the number of items changed m_dirty = true; - SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM ); - RefreshAfter(index); }