/ExtLibs/wxWidgets/src/generic/listctrl.cpp
C++ | 5477 lines | 3958 code | 974 blank | 545 comment | 729 complexity | f6cb5567847a4bd218f002128d7b0f1f MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.0, BSD-3-Clause, LGPL-3.0, LGPL-2.1, AGPL-3.0
Large files files are truncated, but you can click here to view the full file
- /////////////////////////////////////////////////////////////////////////////
- // Name: src/generic/listctrl.cpp
- // Purpose: generic implementation of wxListCtrl
- // Author: Robert Roebling
- // Vadim Zeitlin (virtual list control support)
- // Copyright: (c) 1998 Robert Roebling
- // Licence: wxWindows licence
- /////////////////////////////////////////////////////////////////////////////
- // TODO
- //
- // 1. we need to implement searching/sorting for virtual controls somehow
- // 2. when changing selection the lines are refreshed twice
- // For compilers that support precompilation, includes "wx.h".
- #include "wx/wxprec.h"
- #ifdef __BORLANDC__
- #pragma hdrstop
- #endif
- #if wxUSE_LISTCTRL
- #include "wx/listctrl.h"
- #ifndef WX_PRECOMP
- #include "wx/scrolwin.h"
- #include "wx/timer.h"
- #include "wx/settings.h"
- #include "wx/dynarray.h"
- #include "wx/dcclient.h"
- #include "wx/dcscreen.h"
- #include "wx/math.h"
- #include "wx/settings.h"
- #include "wx/sizer.h"
- #endif
- #include "wx/imaglist.h"
- #include "wx/renderer.h"
- #include "wx/generic/private/listctrl.h"
- #ifdef __WXMAC__
- #include "wx/osx/private.h"
- #endif
- #if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
- #define "wx/msw/wrapwin.h"
- #endif
- // NOTE: If using the wxListBox visual attributes works everywhere then this can
- // be removed, as well as the #else case below.
- #define _USE_VISATTR 0
- // ----------------------------------------------------------------------------
- // constants
- // ----------------------------------------------------------------------------
- // // the height of the header window (FIXME: should depend on its font!)
- // static const int HEADER_HEIGHT = 23;
- static const int SCROLL_UNIT_X = 15;
- // the spacing between the lines (in report mode)
- static const int LINE_SPACING = 0;
- // extra margins around the text label
- #ifdef __WXGTK__
- static const int EXTRA_WIDTH = 6;
- #else
- static const int EXTRA_WIDTH = 4;
- #endif
- #ifdef __WXGTK__
- static const int EXTRA_HEIGHT = 6;
- #else
- static const int EXTRA_HEIGHT = 4;
- #endif
- // margin between the window and the items
- static const int EXTRA_BORDER_X = 2;
- static const int EXTRA_BORDER_Y = 2;
- // offset for the header window
- static const int HEADER_OFFSET_X = 0;
- static const int HEADER_OFFSET_Y = 0;
- // margin between rows of icons in [small] icon view
- static const int MARGIN_BETWEEN_ROWS = 6;
- // when autosizing the columns, add some slack
- static const int AUTOSIZE_COL_MARGIN = 10;
- // default width for the header columns
- static const int WIDTH_COL_DEFAULT = 80;
- // the space between the image and the text in the report mode
- static const int IMAGE_MARGIN_IN_REPORT_MODE = 5;
- // the space between the image and the text in the report mode in header
- static const int HEADER_IMAGE_MARGIN_IN_REPORT_MODE = 2;
- // ----------------------------------------------------------------------------
- // arrays/list implementations
- // ----------------------------------------------------------------------------
- #include "wx/listimpl.cpp"
- WX_DEFINE_LIST(wxListItemDataList)
- #include "wx/arrimpl.cpp"
- WX_DEFINE_OBJARRAY(wxListLineDataArray)
- #include "wx/listimpl.cpp"
- WX_DEFINE_LIST(wxListHeaderDataList)
- // ----------------------------------------------------------------------------
- // wxListItemData
- // ----------------------------------------------------------------------------
- wxListItemData::~wxListItemData()
- {
- // in the virtual list control the attributes are managed by the main
- // program, so don't delete them
- if ( !m_owner->IsVirtual() )
- delete m_attr;
- delete m_rect;
- }
- void wxListItemData::Init()
- {
- m_image = -1;
- m_data = 0;
- m_attr = NULL;
- }
- wxListItemData::wxListItemData(wxListMainWindow *owner)
- {
- Init();
- m_owner = owner;
- if ( owner->InReportView() )
- m_rect = NULL;
- else
- m_rect = new wxRect;
- }
- void wxListItemData::SetItem( const wxListItem &info )
- {
- if ( info.m_mask & wxLIST_MASK_TEXT )
- SetText(info.m_text);
- if ( info.m_mask & wxLIST_MASK_IMAGE )
- m_image = info.m_image;
- if ( info.m_mask & wxLIST_MASK_DATA )
- m_data = info.m_data;
- if ( info.HasAttributes() )
- {
- if ( m_attr )
- m_attr->AssignFrom(*info.GetAttributes());
- else
- m_attr = new wxListItemAttr(*info.GetAttributes());
- }
- if ( m_rect )
- {
- m_rect->x =
- m_rect->y =
- m_rect->height = 0;
- m_rect->width = info.m_width;
- }
- }
- void wxListItemData::SetPosition( int x, int y )
- {
- wxCHECK_RET( m_rect, wxT("unexpected SetPosition() call") );
- m_rect->x = x;
- m_rect->y = y;
- }
- void wxListItemData::SetSize( int width, int height )
- {
- wxCHECK_RET( m_rect, wxT("unexpected SetSize() call") );
- if ( width != -1 )
- m_rect->width = width;
- if ( height != -1 )
- m_rect->height = height;
- }
- bool wxListItemData::IsHit( int x, int y ) const
- {
- wxCHECK_MSG( m_rect, false, wxT("can't be called in this mode") );
- return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Contains(x, y);
- }
- int wxListItemData::GetX() const
- {
- wxCHECK_MSG( m_rect, 0, wxT("can't be called in this mode") );
- return m_rect->x;
- }
- int wxListItemData::GetY() const
- {
- wxCHECK_MSG( m_rect, 0, wxT("can't be called in this mode") );
- return m_rect->y;
- }
- int wxListItemData::GetWidth() const
- {
- wxCHECK_MSG( m_rect, 0, wxT("can't be called in this mode") );
- return m_rect->width;
- }
- int wxListItemData::GetHeight() const
- {
- wxCHECK_MSG( m_rect, 0, wxT("can't be called in this mode") );
- return m_rect->height;
- }
- void wxListItemData::GetItem( wxListItem &info ) const
- {
- long mask = info.m_mask;
- if ( !mask )
- // by default, get everything for backwards compatibility
- mask = -1;
- if ( mask & wxLIST_MASK_TEXT )
- info.m_text = m_text;
- if ( mask & wxLIST_MASK_IMAGE )
- info.m_image = m_image;
- if ( mask & wxLIST_MASK_DATA )
- info.m_data = m_data;
- if ( m_attr )
- {
- if ( m_attr->HasTextColour() )
- info.SetTextColour(m_attr->GetTextColour());
- if ( m_attr->HasBackgroundColour() )
- info.SetBackgroundColour(m_attr->GetBackgroundColour());
- if ( m_attr->HasFont() )
- info.SetFont(m_attr->GetFont());
- }
- }
- //-----------------------------------------------------------------------------
- // wxListHeaderData
- //-----------------------------------------------------------------------------
- void wxListHeaderData::Init()
- {
- m_mask = 0;
- m_image = -1;
- m_format = 0;
- m_width = 0;
- m_xpos = 0;
- m_ypos = 0;
- m_height = 0;
- m_state = 0;
- }
- wxListHeaderData::wxListHeaderData()
- {
- Init();
- }
- wxListHeaderData::wxListHeaderData( const wxListItem &item )
- {
- Init();
- SetItem( item );
- }
- void wxListHeaderData::SetItem( const wxListItem &item )
- {
- m_mask = item.m_mask;
- if ( m_mask & wxLIST_MASK_TEXT )
- m_text = item.m_text;
- if ( m_mask & wxLIST_MASK_IMAGE )
- m_image = item.m_image;
- if ( m_mask & wxLIST_MASK_FORMAT )
- m_format = item.m_format;
- 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 )
- {
- m_xpos = x;
- m_ypos = y;
- }
- void wxListHeaderData::SetHeight( int h )
- {
- m_height = h;
- }
- 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;
- }
- bool wxListHeaderData::HasImage() const
- {
- return m_image != -1;
- }
- bool wxListHeaderData::IsHit( int x, int y ) const
- {
- return ((x >= m_xpos) && (x <= m_xpos+m_width) && (y >= m_ypos) && (y <= m_ypos+m_height));
- }
- void wxListHeaderData::GetItem( wxListItem& item )
- {
- long mask = item.m_mask;
- if ( !mask )
- {
- // by default, get everything for backwards compatibility
- mask = -1;
- }
- if ( mask & wxLIST_MASK_STATE )
- item.m_state = m_state;
- if ( mask & wxLIST_MASK_TEXT )
- item.m_text = m_text;
- if ( mask & wxLIST_MASK_IMAGE )
- item.m_image = m_image;
- if ( mask & wxLIST_MASK_WIDTH )
- item.m_width = m_width;
- if ( mask & wxLIST_MASK_FORMAT )
- item.m_format = m_format;
- }
- int wxListHeaderData::GetImage() const
- {
- return m_image;
- }
- int wxListHeaderData::GetWidth() const
- {
- return m_width;
- }
- int wxListHeaderData::GetFormat() const
- {
- return m_format;
- }
- int wxListHeaderData::GetState() const
- {
- return m_state;
- }
- //-----------------------------------------------------------------------------
- // wxListLineData
- //-----------------------------------------------------------------------------
- inline int wxListLineData::GetMode() const
- {
- return m_owner->GetListCtrl()->GetWindowStyleFlag() & wxLC_MASK_TYPE;
- }
- inline bool wxListLineData::InReportView() const
- {
- return m_owner->HasFlag(wxLC_REPORT);
- }
- inline bool wxListLineData::IsVirtual() const
- {
- return m_owner->IsVirtual();
- }
- wxListLineData::wxListLineData( wxListMainWindow *owner )
- {
- m_owner = owner;
- if ( InReportView() )
- m_gi = NULL;
- else // !report
- m_gi = new GeometryInfo;
- m_highlighted = false;
- InitItems( GetMode() == wxLC_REPORT ? m_owner->GetColumnCount() : 1 );
- }
- void wxListLineData::CalculateSize( wxDC *dc, int spacing )
- {
- wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
- wxCHECK_RET( node, wxT("no subitems at all??") );
- wxListItemData *item = node->GetData();
- wxString s;
- wxCoord lw, lh;
- switch ( GetMode() )
- {
- case wxLC_ICON:
- case wxLC_SMALL_ICON:
- m_gi->m_rectAll.width = spacing;
- s = item->GetText();
- if ( s.empty() )
- {
- lh =
- m_gi->m_rectLabel.width =
- m_gi->m_rectLabel.height = 0;
- }
- else // has label
- {
- dc->GetTextExtent( s, &lw, &lh );
- lw += EXTRA_WIDTH;
- lh += EXTRA_HEIGHT;
- m_gi->m_rectAll.height = spacing + lh;
- if (lw > spacing)
- m_gi->m_rectAll.width = lw;
- m_gi->m_rectLabel.width = lw;
- m_gi->m_rectLabel.height = lh;
- }
- if (item->HasImage())
- {
- int w, h;
- m_owner->GetImageSize( item->GetImage(), w, h );
- m_gi->m_rectIcon.width = w + 8;
- m_gi->m_rectIcon.height = h + 8;
- if ( m_gi->m_rectIcon.width > m_gi->m_rectAll.width )
- m_gi->m_rectAll.width = m_gi->m_rectIcon.width;
- if ( m_gi->m_rectIcon.height + lh > m_gi->m_rectAll.height - 4 )
- m_gi->m_rectAll.height = m_gi->m_rectIcon.height + lh + 4;
- }
- if ( item->HasText() )
- {
- m_gi->m_rectHighlight.width = m_gi->m_rectLabel.width;
- m_gi->m_rectHighlight.height = m_gi->m_rectLabel.height;
- }
- else // no text, highlight the icon
- {
- m_gi->m_rectHighlight.width = m_gi->m_rectIcon.width;
- m_gi->m_rectHighlight.height = m_gi->m_rectIcon.height;
- }
- break;
- case wxLC_LIST:
- s = item->GetTextForMeasuring();
- dc->GetTextExtent( s, &lw, &lh );
- lw += EXTRA_WIDTH;
- lh += EXTRA_HEIGHT;
- m_gi->m_rectLabel.width = lw;
- m_gi->m_rectLabel.height = lh;
- m_gi->m_rectAll.width = lw;
- m_gi->m_rectAll.height = lh;
- if (item->HasImage())
- {
- int w, h;
- m_owner->GetImageSize( item->GetImage(), w, h );
- m_gi->m_rectIcon.width = w;
- m_gi->m_rectIcon.height = h;
- m_gi->m_rectAll.width += 4 + w;
- if (h > m_gi->m_rectAll.height)
- m_gi->m_rectAll.height = h;
- }
- m_gi->m_rectHighlight.width = m_gi->m_rectAll.width;
- m_gi->m_rectHighlight.height = m_gi->m_rectAll.height;
- break;
- case wxLC_REPORT:
- wxFAIL_MSG( wxT("unexpected call to SetSize") );
- break;
- default:
- wxFAIL_MSG( wxT("unknown mode") );
- break;
- }
- }
- void wxListLineData::SetPosition( int x, int y, int spacing )
- {
- wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
- wxCHECK_RET( node, wxT("no subitems at all??") );
- wxListItemData *item = node->GetData();
- switch ( GetMode() )
- {
- case wxLC_ICON:
- case wxLC_SMALL_ICON:
- m_gi->m_rectAll.x = x;
- m_gi->m_rectAll.y = y;
- if ( item->HasImage() )
- {
- m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 4 +
- (m_gi->m_rectAll.width - m_gi->m_rectIcon.width) / 2;
- m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 4;
- }
- if ( item->HasText() )
- {
- if (m_gi->m_rectAll.width > spacing)
- m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2);
- else
- m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2) + (spacing / 2) - (m_gi->m_rectLabel.width / 2);
- m_gi->m_rectLabel.y = m_gi->m_rectAll.y + m_gi->m_rectAll.height + 2 - m_gi->m_rectLabel.height;
- m_gi->m_rectHighlight.x = m_gi->m_rectLabel.x - 2;
- m_gi->m_rectHighlight.y = m_gi->m_rectLabel.y - 2;
- }
- else // no text, highlight the icon
- {
- m_gi->m_rectHighlight.x = m_gi->m_rectIcon.x - 4;
- m_gi->m_rectHighlight.y = m_gi->m_rectIcon.y - 4;
- }
- break;
- case wxLC_LIST:
- m_gi->m_rectAll.x = x;
- m_gi->m_rectAll.y = y;
- m_gi->m_rectHighlight.x = m_gi->m_rectAll.x;
- m_gi->m_rectHighlight.y = m_gi->m_rectAll.y;
- m_gi->m_rectLabel.y = m_gi->m_rectAll.y + 2;
- if (item->HasImage())
- {
- m_gi->m_rectIcon.x = m_gi->m_rectAll.x + 2;
- m_gi->m_rectIcon.y = m_gi->m_rectAll.y + 2;
- m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 4 + (EXTRA_WIDTH/2) + m_gi->m_rectIcon.width;
- }
- else
- {
- m_gi->m_rectLabel.x = m_gi->m_rectAll.x + (EXTRA_WIDTH/2);
- }
- break;
- case wxLC_REPORT:
- wxFAIL_MSG( wxT("unexpected call to SetPosition") );
- break;
- default:
- wxFAIL_MSG( wxT("unknown mode") );
- break;
- }
- }
- void wxListLineData::InitItems( int num )
- {
- for (int i = 0; i < num; i++)
- m_items.Append( new wxListItemData(m_owner) );
- }
- void wxListLineData::SetItem( int index, const wxListItem &info )
- {
- wxListItemDataList::compatibility_iterator node = m_items.Item( index );
- wxCHECK_RET( node, wxT("invalid column index in SetItem") );
- wxListItemData *item = node->GetData();
- item->SetItem( info );
- }
- void wxListLineData::GetItem( int index, wxListItem &info )
- {
- wxListItemDataList::compatibility_iterator node = m_items.Item( index );
- if (node)
- {
- wxListItemData *item = node->GetData();
- item->GetItem( info );
- }
- }
- wxString wxListLineData::GetText(int index) const
- {
- wxString s;
- wxListItemDataList::compatibility_iterator node = m_items.Item( index );
- if (node)
- {
- wxListItemData *item = node->GetData();
- s = item->GetText();
- }
- return s;
- }
- void wxListLineData::SetText( int index, const wxString& s )
- {
- wxListItemDataList::compatibility_iterator node = m_items.Item( index );
- if (node)
- {
- wxListItemData *item = node->GetData();
- item->SetText( s );
- }
- }
- void wxListLineData::SetImage( int index, int image )
- {
- wxListItemDataList::compatibility_iterator node = m_items.Item( index );
- wxCHECK_RET( node, wxT("invalid column index in SetImage()") );
- wxListItemData *item = node->GetData();
- item->SetImage(image);
- }
- int wxListLineData::GetImage( int index ) const
- {
- wxListItemDataList::compatibility_iterator node = m_items.Item( index );
- wxCHECK_MSG( node, -1, wxT("invalid column index in GetImage()") );
- wxListItemData *item = node->GetData();
- return item->GetImage();
- }
- wxListItemAttr *wxListLineData::GetAttr() const
- {
- wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
- wxCHECK_MSG( node, NULL, wxT("invalid column index in GetAttr()") );
- wxListItemData *item = node->GetData();
- return item->GetAttr();
- }
- void wxListLineData::SetAttr(wxListItemAttr *attr)
- {
- wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
- wxCHECK_RET( node, wxT("invalid column index in SetAttr()") );
- wxListItemData *item = node->GetData();
- item->SetAttr(attr);
- }
- void wxListLineData::ApplyAttributes(wxDC *dc,
- const wxRect& rectHL,
- bool highlighted,
- bool current)
- {
- const wxListItemAttr * const attr = GetAttr();
- wxWindow * const listctrl = m_owner->GetParent();
- const bool hasFocus = listctrl->HasFocus()
- #if defined(__WXMAC__) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
- && IsControlActive( (ControlRef)listctrl->GetHandle() )
- #endif
- ;
- // fg colour
- // don't use foreground colour for drawing highlighted items - this might
- // make them completely invisible (and there is no way to do bit
- // arithmetics on wxColour, unfortunately)
- wxColour colText;
- if ( highlighted )
- {
- #ifdef __WXMAC__
- if ( hasFocus )
- colText = *wxWHITE;
- else
- colText = *wxBLACK;
- #else
- if ( hasFocus )
- colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
- else
- colText = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT);
- #endif
- }
- else if ( attr && attr->HasTextColour() )
- colText = attr->GetTextColour();
- else
- colText = listctrl->GetForegroundColour();
- dc->SetTextForeground(colText);
- // font
- wxFont font;
- if ( attr && attr->HasFont() )
- font = attr->GetFont();
- else
- font = listctrl->GetFont();
- dc->SetFont(font);
- // background
- if ( highlighted )
- {
- // Use the renderer method to ensure that the selected items use the
- // native look.
- int flags = wxCONTROL_SELECTED;
- if ( hasFocus )
- flags |= wxCONTROL_FOCUSED;
- if (current)
- flags |= wxCONTROL_CURRENT;
- wxRendererNative::Get().
- DrawItemSelectionRect( m_owner, *dc, rectHL, flags );
- }
- else if ( attr && attr->HasBackgroundColour() )
- {
- // Draw the background using the items custom background colour.
- dc->SetBrush(attr->GetBackgroundColour());
- dc->SetPen(*wxTRANSPARENT_PEN);
- dc->DrawRectangle(rectHL);
- }
- // just for debugging to better see where the items are
- #if 0
- dc->SetPen(*wxRED_PEN);
- dc->SetBrush(*wxTRANSPARENT_BRUSH);
- dc->DrawRectangle( m_gi->m_rectAll );
- dc->SetPen(*wxGREEN_PEN);
- dc->DrawRectangle( m_gi->m_rectIcon );
- #endif
- }
- void wxListLineData::Draw(wxDC *dc, bool current)
- {
- wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
- wxCHECK_RET( node, wxT("no subitems at all??") );
- ApplyAttributes(dc, m_gi->m_rectHighlight, IsHighlighted(), current);
- wxListItemData *item = node->GetData();
- if (item->HasImage())
- {
- // centre the image inside our rectangle, this looks nicer when items
- // ae aligned in a row
- const wxRect& rectIcon = m_gi->m_rectIcon;
- m_owner->DrawImage(item->GetImage(), dc, rectIcon.x, rectIcon.y);
- }
- if (item->HasText())
- {
- const wxRect& rectLabel = m_gi->m_rectLabel;
- wxDCClipper clipper(*dc, rectLabel);
- dc->DrawText(item->GetText(), rectLabel.x, rectLabel.y);
- }
- }
- void wxListLineData::DrawInReportMode( wxDC *dc,
- const wxRect& rect,
- const wxRect& rectHL,
- bool highlighted,
- bool current )
- {
- // TODO: later we should support setting different attributes for
- // different columns - to do it, just add "col" argument to
- // GetAttr() and move these lines into the loop below
- ApplyAttributes(dc, rectHL, highlighted, current);
- wxCoord x = rect.x + HEADER_OFFSET_X,
- yMid = rect.y + rect.height/2;
- #ifdef __WXGTK__
- // This probably needs to be done
- // on all platforms as the icons
- // otherwise nearly touch the border
- x += 2;
- #endif
- size_t col = 0;
- for ( wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
- node;
- node = node->GetNext(), col++ )
- {
- wxListItemData *item = node->GetData();
- int width = m_owner->GetColumnWidth(col);
- int xOld = x;
- x += width;
- width -= 8;
- const int wText = width;
- wxDCClipper clipper(*dc, xOld, rect.y, wText, rect.height);
- if ( item->HasImage() )
- {
- int ix, iy;
- m_owner->GetImageSize( item->GetImage(), ix, iy );
- m_owner->DrawImage( item->GetImage(), dc, xOld, yMid - iy/2 );
- ix += IMAGE_MARGIN_IN_REPORT_MODE;
- xOld += ix;
- width -= ix;
- }
- if ( item->HasText() )
- DrawTextFormatted(dc, item->GetText(), col, xOld, yMid, width);
- }
- }
- void wxListLineData::DrawTextFormatted(wxDC *dc,
- const wxString& textOrig,
- int col,
- int x,
- int yMid,
- int width)
- {
- // we don't support displaying multiple lines currently (and neither does
- // wxMSW FWIW) so just merge all the lines
- wxString text(textOrig);
- text.Replace(wxT("\n"), wxT(" "));
- wxCoord w, h;
- dc->GetTextExtent(text, &w, &h);
- const wxCoord y = yMid - (h + 1)/2;
- wxDCClipper clipper(*dc, x, y, width, h);
- // determine if the string can fit inside the current width
- if (w <= width)
- {
- // it can, draw it using the items alignment
- wxListItem item;
- m_owner->GetColumn(col, item);
- switch ( item.GetAlign() )
- {
- case wxLIST_FORMAT_LEFT:
- // nothing to do
- break;
- case wxLIST_FORMAT_RIGHT:
- x += width - w;
- break;
- case wxLIST_FORMAT_CENTER:
- x += (width - w) / 2;
- break;
- default:
- wxFAIL_MSG( wxT("unknown list item format") );
- break;
- }
- dc->DrawText(text, x, y);
- }
- else // otherwise, truncate and add an ellipsis if possible
- {
- // determine the base width
- wxString ellipsis(wxT("..."));
- wxCoord base_w;
- dc->GetTextExtent(ellipsis, &base_w, &h);
- // continue until we have enough space or only one character left
- wxCoord w_c, h_c;
- size_t len = text.length();
- wxString drawntext = text.Left(len);
- while (len > 1)
- {
- dc->GetTextExtent(drawntext.Last(), &w_c, &h_c);
- drawntext.RemoveLast();
- len--;
- w -= w_c;
- if (w + base_w <= width)
- break;
- }
- // if still not enough space, remove ellipsis characters
- while (ellipsis.length() > 0 && w + base_w > width)
- {
- ellipsis = ellipsis.Left(ellipsis.length() - 1);
- dc->GetTextExtent(ellipsis, &base_w, &h);
- }
- // now draw the text
- dc->DrawText(drawntext, x, y);
- dc->DrawText(ellipsis, x + w, y);
- }
- }
- bool wxListLineData::Highlight( bool on )
- {
- wxCHECK_MSG( !IsVirtual(), false, wxT("unexpected call to Highlight") );
- if ( on == m_highlighted )
- return false;
- m_highlighted = on;
- return true;
- }
- void wxListLineData::ReverseHighlight( void )
- {
- Highlight(!IsHighlighted());
- }
- //-----------------------------------------------------------------------------
- // wxListHeaderWindow
- //-----------------------------------------------------------------------------
- BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow)
- EVT_PAINT (wxListHeaderWindow::OnPaint)
- EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse)
- END_EVENT_TABLE()
- void wxListHeaderWindow::Init()
- {
- m_currentCursor = NULL;
- m_isDragging = false;
- m_dirty = false;
- m_sendSetColumnWidth = false;
- }
- wxListHeaderWindow::wxListHeaderWindow()
- {
- Init();
- m_owner = NULL;
- m_resizeCursor = NULL;
- }
- bool wxListHeaderWindow::Create( wxWindow *win,
- wxWindowID id,
- wxListMainWindow *owner,
- const wxPoint& pos,
- const wxSize& size,
- long style,
- const wxString &name )
- {
- if ( !wxWindow::Create(win, id, pos, size, style, name) )
- return false;
- Init();
- m_owner = owner;
- m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
- #if _USE_VISATTR
- wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes();
- SetOwnForegroundColour( attr.colFg );
- SetOwnBackgroundColour( attr.colBg );
- if (!m_hasFont)
- SetOwnFont( attr.font );
- #else
- SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
- SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
- if (!m_hasFont)
- SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT ));
- #endif
- return true;
- }
- wxListHeaderWindow::~wxListHeaderWindow()
- {
- delete m_resizeCursor;
- }
- #ifdef __WXUNIVERSAL__
- #include "wx/univ/renderer.h"
- #include "wx/univ/theme.h"
- #endif
- // shift the DC origin to match the position of the main window horz
- // scrollbar: this allows us to always use logical coords
- void wxListHeaderWindow::AdjustDC(wxDC& dc)
- {
- wxGenericListCtrl *parent = m_owner->GetListCtrl();
- int xpix;
- parent->GetScrollPixelsPerUnit( &xpix, NULL );
- int view_start;
- parent->GetViewStart( &view_start, NULL );
- int org_x = 0;
- int org_y = 0;
- dc.GetDeviceOrigin( &org_x, &org_y );
- // account for the horz scrollbar offset
- #ifdef __WXGTK__
- if (GetLayoutDirection() == wxLayout_RightToLeft)
- {
- // Maybe we just have to check for m_signX
- // in the DC, but I leave the #ifdef __WXGTK__
- // for now
- dc.SetDeviceOrigin( org_x + (view_start * xpix), org_y );
- }
- else
- #endif
- dc.SetDeviceOrigin( org_x - (view_start * xpix), org_y );
- }
- void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
- {
- wxGenericListCtrl *parent = m_owner->GetListCtrl();
- wxPaintDC dc( this );
- AdjustDC( dc );
- dc.SetFont( GetFont() );
- // width and height of the entire header window
- int w, h;
- GetClientSize( &w, &h );
- parent->CalcUnscrolledPosition(w, 0, &w, NULL);
- dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
- dc.SetTextForeground(GetForegroundColour());
- int x = HEADER_OFFSET_X;
- int numColumns = m_owner->GetColumnCount();
- wxListItem item;
- for ( int i = 0; i < numColumns && x < w; i++ )
- {
- m_owner->GetColumn( i, item );
- int wCol = item.m_width;
- int cw = wCol;
- int ch = h;
- 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 behaviour 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
- if (i == 0)
- flags |= wxCONTROL_SPECIAL; // mark as first column
- wxRendererNative::Get().DrawHeaderButton
- (
- this,
- dc,
- wxRect(x, HEADER_OFFSET_Y, cw, ch),
- flags
- );
- // see if we have enough space for the column label
- // for this we need the width of the text
- wxCoord wLabel;
- wxCoord hLabel;
- dc.GetTextExtent(item.GetText(), &wLabel, &hLabel);
- wLabel += 2 * EXTRA_WIDTH;
- // and the width of the icon, if any
- int ix = 0, iy = 0; // init them just to suppress the compiler warnings
- const int image = item.m_image;
- wxImageList *imageList;
- if ( image != -1 )
- {
- imageList = m_owner->GetSmallImageList();
- if ( imageList )
- {
- imageList->GetSize(image, ix, iy);
- wLabel += ix + HEADER_IMAGE_MARGIN_IN_REPORT_MODE;
- }
- }
- else
- {
- imageList = NULL;
- }
- // ignore alignment if there is not enough space anyhow
- int xAligned;
- switch ( wLabel < cw ? item.GetAlign() : wxLIST_FORMAT_LEFT )
- {
- default:
- wxFAIL_MSG( wxT("unknown list item format") );
- // fall through
- case wxLIST_FORMAT_LEFT:
- xAligned = x;
- break;
- case wxLIST_FORMAT_RIGHT:
- xAligned = x + cw - wLabel;
- break;
- case wxLIST_FORMAT_CENTER:
- xAligned = x + (cw - wLabel) / 2;
- break;
- }
- // draw the text and image clipping them so that they
- // don't overwrite the column boundary
- wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw, h);
- // if we have an image, draw it on the right of the label
- if ( imageList )
- {
- imageList->Draw
- (
- image,
- dc,
- xAligned + wLabel - ix - HEADER_IMAGE_MARGIN_IN_REPORT_MODE,
- HEADER_OFFSET_Y + (h - iy)/2,
- wxIMAGELIST_DRAW_TRANSPARENT
- );
- }
- dc.DrawText( item.GetText(),
- xAligned + EXTRA_WIDTH, (h - hLabel) / 2 );
- x += wCol;
- }
- // Fill in what's missing to the right of the columns, otherwise we will
- // leave an unpainted area when columns are removed (and it looks better)
- if ( x < w )
- {
- wxRendererNative::Get().DrawHeaderButton
- (
- this,
- dc,
- wxRect(x, HEADER_OFFSET_Y, w - x, h),
- wxCONTROL_DIRTY // mark as last column
- );
- }
- }
- void wxListHeaderWindow::OnInternalIdle()
- {
- wxWindow::OnInternalIdle();
- if (m_sendSetColumnWidth)
- {
- m_owner->SetColumnWidth( m_colToSend, m_widthToSend );
- m_sendSetColumnWidth = false;
- }
- }
- void wxListHeaderWindow::DrawCurrent()
- {
- #if 1
- // m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
- m_sendSetColumnWidth = true;
- m_colToSend = m_column;
- m_widthToSend = m_currentX - m_minX;
- #else
- int x1 = m_currentX;
- int y1 = 0;
- m_owner->ClientToScreen( &x1, &y1 );
- int x2 = m_currentX;
- int y2 = 0;
- m_owner->GetClientSize( NULL, &y2 );
- m_owner->ClientToScreen( &x2, &y2 );
- wxScreenDC dc;
- dc.SetLogicalFunction( wxINVERT );
- dc.SetPen( wxPen(*wxBLACK, 2) );
- dc.SetBrush( *wxTRANSPARENT_BRUSH );
- AdjustDC(dc);
- dc.DrawLine( x1, y1, x2, y2 );
- dc.SetLogicalFunction( wxCOPY );
- dc.SetPen( wxNullPen );
- dc.SetBrush( wxNullBrush );
- #endif
- }
- void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
- {
- wxGenericListCtrl *parent = m_owner->GetListCtrl();
- // we want to work with logical coords
- int x;
- parent->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL);
- int y = event.GetY();
- if (m_isDragging)
- {
- SendListEvent(wxEVT_LIST_COL_DRAGGING, event.GetPosition());
- // we don't draw the line beyond our window, but we allow dragging it
- // there
- int w = 0;
- GetClientSize( &w, NULL );
- parent->CalcUnscrolledPosition(w, 0, &w, NULL);
- w -= 6;
- // erase the line if it was drawn
- if ( m_currentX < w )
- DrawCurrent();
- if (event.ButtonUp())
- {
- ReleaseMouse();
- m_isDragging = false;
- m_dirty = true;
- m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
- SendListEvent(wxEVT_LIST_COL_END_DRAG, event.GetPosition());
- }
- else
- {
- if (x > m_minX + 7)
- m_currentX = x;
- else
- m_currentX = m_minX + 7;
- // draw in the new location
- if ( m_currentX < w )
- DrawCurrent();
- }
- }
- else // not dragging
- {
- m_minX = 0;
- bool hit_border = false;
- // end of the current column
- int xpos = 0;
- // find the column where this event occurred
- int col,
- countCol = m_owner->GetColumnCount();
- for (col = 0; col < countCol; col++)
- {
- xpos += m_owner->GetColumnWidth( col );
- m_column = col;
- if ( (abs(x-xpos) < 3) && (y < 22) )
- {
- // near the column border
- hit_border = true;
- break;
- }
- if ( x < xpos )
- {
- // inside the column
- break;
- }
- m_minX = xpos;
- }
- if ( col == countCol )
- m_column = -1;
- if (event.LeftDown() || event.RightUp())
- {
- if (hit_border && event.LeftDown())
- {
- if ( SendListEvent(wxEVT_LIST_COL_BEGIN_DRAG,
- event.GetPosition()) )
- {
- m_isDragging = true;
- m_currentX = x;
- CaptureMouse();
- DrawCurrent();
- }
- //else: column resizing was vetoed by the user code
- }
- 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_LIST_COL_CLICK
- : wxEVT_LIST_COL_RIGHT_CLICK,
- event.GetPosition());
- }
- }
- else if (event.Moving())
- {
- bool setCursor;
- if (hit_border)
- {
- setCursor = m_currentCursor == wxSTANDARD_CURSOR;
- m_currentCursor = m_resizeCursor;
- }
- else
- {
- setCursor = m_currentCursor != wxSTANDARD_CURSOR;
- m_currentCursor = wxSTANDARD_CURSOR;
- }
- if ( setCursor )
- SetCursor(*m_currentCursor);
- }
- }
- }
- bool wxListHeaderWindow::SendListEvent(wxEventType type, const 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();
- }
- //-----------------------------------------------------------------------------
- // wxListFindTimer (internal)
- //-----------------------------------------------------------------------------
- void wxListFindTimer::Notify()
- {
- m_owner->OnFindTimer();
- }
- //-----------------------------------------------------------------------------
- // wxListTextCtrlWrapper (internal)
- //-----------------------------------------------------------------------------
- BEGIN_EVENT_TABLE(wxListTextCtrlWrapper, wxEvtHandler)
- EVT_CHAR (wxListTextCtrlWrapper::OnChar)
- EVT_KEY_UP (wxListTextCtrlWrapper::OnKeyUp)
- EVT_KILL_FOCUS (wxListTextCtrlWrapper::OnKillFocus)
- END_EVENT_TABLE()
- wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow *owner,
- wxTextCtrl *text,
- size_t itemEdit)
- : m_startValue(owner->GetItemText(itemEdit)),
- m_itemEdited(itemEdit)
- {
- m_owner = owner;
- m_text = text;
- m_aboutToFinish = false;
- wxGenericListCtrl *parent = m_owner->GetListCtrl();
- wxRect rectLabel = owner->GetLineLabelRect(itemEdit);
- parent->CalcScrolledPosition(rectLabel.x, rectLabel.y,
- &rectLabel.x, &rectLabel.y);
- m_text->Create(owner, wxID_ANY, m_startValue,
- wxPoint(rectLabel.x-4,rectLabel.y-4),
- wxSize(rectLabel.width+11,rectLabel.height+8));
- m_text->SetFocus();
- m_text->PushEventHandler(this);
- }
- void wxListTextCtrlWrapper::EndEdit(EndReason reason)
- {
- m_aboutToFinish = true;
- switch ( reason )
- {
- case End_Accept:
- // Notify the owner about the changes
- AcceptChanges();
- // Even if vetoed, close the control (consistent with MSW)
- Finish( true );
- break;
- case End_Discard:
- m_owner->OnRenameCancelled(m_itemEdited);
- Finish( true );
- break;
- case End_Destroy:
- // Don't generate any notifications for the control being destroyed
- // and don't set focus to it neither.
- Finish(false);
- break;
- }
- }
- void wxListTextCtrlWrapper::Finish( bool setfocus )
- {
- m_text->RemoveEventHandler(this);
- m_owner->ResetTextControl( m_text );
- wxPendingDelete.Append( this );
- if (setfocus)
- m_owner->SetFocus();
- }
- bool wxListTextCtrlWrapper::AcceptChanges()
- {
- const wxString value = m_text->GetValue();
- // notice that we should always call OnRenameAccept() to generate the "end
- // label editing" event, even if the user hasn't really changed anything
- if ( !m_owner->OnRenameAccept(m_itemEdited, value) )
- {
- // vetoed by the user
- return false;
- }
- // accepted, do rename the item (unless nothing changed)
- if ( value != m_startValue )
- m_owner->SetItemText(m_itemEdited, value);
- return true;
- }
- void wxListTextCtrlWrapper::OnChar( wxKeyEvent &event )
- {
- if ( !CheckForEndEditKey(event) )
- event.Skip();
- }
- bool wxListTextCtrlWrapper::CheckForEndEditKey(const wxKeyEvent& event)
- {
- switch ( event.m_keyCode )
- {
- case WXK_RETURN:
- EndEdit( End_Accept );
- break;
- case WXK_ESCAPE:
- EndEdit( End_Discard );
- break;
- default:
- return false;
- }
- return true;
- }
- void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent &event )
- {
- if (m_aboutToFinish)
- {
- // auto-grow the textctrl:
- wxSize parentSize = m_owner->GetSize();
- wxPoint myPos = m_text->GetPosition();
- wxSize mySize = m_text->GetSize();
- int sx, sy;
- m_text->GetTextExtent(m_text->GetValue() + wxT("MM"), &sx, &sy);
- if (myPos.x + sx > parentSize.x)
- sx = parentSize.x - myPos.x;
- if (mySize.x > sx)
- sx = mySize.x;
- m_text->SetSize(sx, wxDefaultCoord);
- }
- event.Skip();
- }
- void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent &event )
- {
- if ( !m_aboutToFinish )
- {
- if ( !AcceptChanges() )
- m_owner->OnRenameCancelled( m_itemEdited );
- Finish( false );
- }
- // We must let the native text control handle focus
- event.Skip();
- }
- //-----------------------------------------------------------------------------
- // wxListMainWindow
- //-----------------------------------------------------------------------------
- BEGIN_EVENT_TABLE(wxListMainWindow, wxWindow)
- EVT_PAINT (wxListMainWindow::OnPaint)
- EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse)
- EVT_CHAR_HOOK (wxListMainWindow::OnCharHook)
- EVT_CHAR (wxListMainWindow::OnChar)
- EVT_KEY_DOWN (wxListMainWindow::OnKeyDown)
- EVT_KEY_UP (wxListMainWindow::OnKeyUp)
- EVT_SET_FOCUS (wxListMainWindow::OnSetFocus)
- EVT_KILL_FOCUS (wxListMainWindow::OnKillFocus)
- EVT_SCROLLWIN (wxListMainWindow::OnScroll)
- EVT_CHILD_FOCUS (wxListMainWindow::OnChildFocus)
- 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 = NULL;
- m_normal_image_list = 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_findTimer = NULL;
- m_findBell = 0; // default is to not ring bell at all
- m_textctrlWrapper = NULL;
- m_current =
- m_lineLastClicked =
- m_lineSelectSingleOnUp =
- m_lineBeforeLastClicked = (size_t)-1;
- }
- wxListMainWindow::wxListMainWindow()
- {
- Init();
- m_highlightBrush =
- m_highlightUnfocusedBrush = NULL;
- }
- wxListMainWindow::wxListMainWindow( wxWindow *parent,
- wxWindowID id,
- const wxPoint& pos,
- const wxSize& size )
- : wxWindow( parent, id, pos, size,
- wxWANTS_CHARS | wxBORDER_NONE )
- {
- Init();
- m_highlightBrush = new wxBrush
- (
- wxSystemSettings::GetColour
- (
- wxSYS_COLOUR_HIGHLIGHT
- ),
- wxBRUSHSTYLE_SOLID
- );
- m_highlightUnfocusedBrush = new wxBrush
- (
- wxSystemSettings::GetColour
- (
- wxSYS_COLOUR_BTNSHADOW
- ),
- wxBRUSHSTYLE_SOLID
- );
- wxVisualAttributes attr = wxGenericListCtrl::GetClassDefaultAttributes();
- SetOwnForegroundColour( attr.colFg );
- SetOwnBackgroundColour( attr.colBg );
- if (!m_hasFont)
- SetOwnFont( attr.font );
- }
- wxListMainWindow::~wxListMainWindow()
- {
- if ( m_textctrlWrapper )
- m_textctrlWrapper->EndEdit(wxListTextCtrlWrapper::End_Destroy);
- DoDeleteAllItems();
- WX_CLEAR_LIST(wxListHeaderDataList, m_columns);
- WX_CLEAR_ARRAY(m_aColWidths);
- delete m_highlightBrush;
- delete m_highlightUnfocusedBrush;
- delete m_renameTimer;
- delete m_findTimer;
- }
- void wxListMainWindow::SetReportView(bool inReportView)
- {
- const size_t count = m_lines.size();
- for ( size_t n = 0; n < count; n++ )
- {
- m_lines[n].SetReportView(inReportView);
- }
- }
- 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(col, listctrl->OnGetItemColumnImage(line, col));
- }
- ld->SetAttr(listctrl->OnGetItemAttr(line));
- }
- wxListLineData *wxListMainWindow::GetDummyLine() const
- {
- wxASSERT_MSG( !IsEmpty(), wxT("invalid line index") );
- wxASSERT_MSG( IsVirtual(), wxT("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(wxT("H"), NULL, &y);
- if ( m_small_image_list && m_small_image_list->GetImageCount() )
- {
- int iw = 0, 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
- {
- wxASSERT_MSG( InReportView(), wxT("only works in report mode") );
- return LINE_SPACING + line * GetLineHeight();
- }
- wxRect wxListMainWindow::GetLineRect(size_t line) const
- {
- if ( !InReportView() )
- return GetLine(line)->m_gi->m_rectAll;
- wxRect rect;
- rect.x = HEADER_OFFSET_X;
- rect.y = GetLineY(line);
- rect.width = GetHeaderWidth();
- rect.height = GetLineHeight();
- return rect;
- }
- wxRect wxListMainWindow::GetLineLabelRect(size_t line) const
- {
- if ( !InReportView() )
- return GetLine(line)->m_gi->m_rectLabel;
- int image_x = 0;
- wxListLineData *data = GetLine(line);
- wxListItemDataList::compatibility_iterator node = data->m_items.GetFirst();
- if (node)
- {
- wxListItemData *item = node->GetData();
- if ( item->HasImage() )
- {
- int ix, iy;
- GetImageSize( item->GetImage(), ix, iy );
- image_x = 3 + ix + IMAGE_MARGIN_IN_REPORT_MODE;
- }
- }
- wxRect rect;
- rect.x = image_x + HEADER_OFFSET_X;
- rect.y = GetLineY(line);
- rect.width = GetColumnWidth(0) - image_x;
- rect.height = GetLineHeight();
- return rect;
- }
- wxRect wxListMainWindow::GetLineIconRect(size_t line) const
- {
- if ( !InReportView() )
- return GetLine(line)->m_gi->m_rectIcon;
- wxListLineData *ld = GetLine(line);
- wxASSERT_MSG( ld->HasImage(), wxT("should have an image") );
- wxRect rect;
- rect.x = HEADER_OFFSET_X;
- rect.y = GetLineY(line);
- GetImageSize(ld->GetImage(), rect.width, rect.height);
- return rect;
- }
- wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const
- {
- return InReportView() ? GetLineRect(line)
- : GetLine(line)->m_gi->m_rectHighlight;
- }
- long wxListMainWindow::HitTestLine(size_t line, int x, int y) const
- {
- wxASSERT_MSG( line < GetItemCount(), wxT("invalid line in HitTestLine") );
- wxListLineData *ld = GetLine(line);
- if ( ld->HasImage() && GetLineIconRect(line).Contains(x, y) )
- return wxLIST_HITTEST_ONITEMICON;
- // VS: Testing for "ld->HasText() || InReportView()" instead of
- // "ld->HasText()" is needed to make empty lines in report view
- // possible
- if ( ld->HasText() || InReportView() )
- {
- wxRect rect = InReportView() ? GetLineRect(line)
- : GetLineLabelRect(line);
- if ( rect.Contains(x…
Large files files are truncated, but you can click here to view the full file