listctrl.cpp
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C++ 代码 · 共 2,239 行 · 第 1/5 页
CPP
2,239 行
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 = *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, _T("unexpected SetPosition() call") );
m_rect->x = x;
m_rect->y = y;
}
void wxListItemData::SetSize( int width, int height )
{
wxCHECK_RET( m_rect, _T("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, _T("can't be called in this mode") );
return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x, y);
}
int wxListItemData::GetX() const
{
wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
return m_rect->x;
}
int wxListItemData::GetY() const
{
wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
return m_rect->y;
}
int wxListItemData::GetWidth() const
{
wxCHECK_MSG( m_rect, 0, _T("can't be called in this mode") );
return m_rect->width;
}
int wxListItemData::GetHeight() const
{
wxCHECK_MSG( m_rect, 0, _T("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;
}
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);
}
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;
if (m_width < 0)
m_width = WIDTH_COL_DEFAULT;
else if (m_width < WIDTH_COL_MIN)
m_width = WIDTH_COL_MIN;
}
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 )
{
item.m_mask = m_mask;
item.m_text = m_text;
item.m_image = m_image;
item.m_format = m_format;
item.m_width = m_width;
}
int wxListHeaderData::GetImage() const
{
return m_image;
}
int wxListHeaderData::GetWidth() const
{
return m_width;
}
int wxListHeaderData::GetFormat() const
{
return m_format;
}
//-----------------------------------------------------------------------------
// 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, _T("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( _T("unexpected call to SetSize") );
break;
default:
wxFAIL_MSG( _T("unknown mode") );
}
}
void wxListLineData::SetPosition( int x, int y, int spacing )
{
wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
wxCHECK_RET( node, _T("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 + 2;
else
m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 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 + 6 + m_gi->m_rectIcon.width;
}
else
{
m_gi->m_rectLabel.x = m_gi->m_rectAll.x + 2;
}
break;
case wxLC_REPORT:
wxFAIL_MSG( _T("unexpected call to SetPosition") );
break;
default:
wxFAIL_MSG( _T("unknown mode") );
}
}
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 )
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?