📄 listctrl.cpp
字号:
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()).Contains(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; 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 ){ 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; item.m_state = m_state;}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, _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") ); break; }}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 + (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( _T("unexpected call to SetPosition") ); break; default: wxFAIL_MSG( _T("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, _T("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, _T("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, _T("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, _T("invalid column index in GetAttr()") );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -