⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listctrl.cpp

📁 电驴的MAC源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    wxListItemData *item = node->GetData();    return item->GetAttr();}void wxListLineData::SetAttr(wxListItemAttr *attr){    wxListItemDataList::compatibility_iterator node = m_items.GetFirst();    wxCHECK_RET( node, _T("invalid column index in SetAttr()") );    wxListItemData *item = node->GetData();    item->SetAttr(attr);}bool wxListLineData::SetAttributes(wxDC *dc,                                   const wxListItemAttr *attr,                                   bool highlighted){    wxWindow *listctrl = m_owner->GetParent();    // 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 (m_owner->HasFocus()#ifdef __WXMAC__                && IsControlActive( (ControlRef)m_owner->GetHandle() )#endif        )            colText = *wxWHITE;        else            colText = *wxBLACK;    }#else        colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);#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);    // bg colour    bool hasBgCol = attr && attr->HasBackgroundColour();    if ( highlighted || hasBgCol )    {        if ( highlighted )            dc->SetBrush( *m_owner->GetHighlightBrush() );        else            dc->SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID));        dc->SetPen( *wxTRANSPARENT_PEN );        return true;    }    return false;}void wxListLineData::Draw( wxDC *dc ){    wxListItemDataList::compatibility_iterator node = m_items.GetFirst();    wxCHECK_RET( node, _T("no subitems at all??") );    bool highlighted = IsHighlighted();    wxListItemAttr *attr = GetAttr();    if ( SetAttributes(dc, attr, highlighted) )#if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )    {        dc->DrawRectangle( m_gi->m_rectHighlight );    }#else    {        if (highlighted)        {            int flags = wxCONTROL_SELECTED;            if (m_owner->HasFocus()#ifdef __WXMAC__                && IsControlActive( (ControlRef)m_owner->GetHandle() )#endif            )                flags |= wxCONTROL_FOCUSED;            wxRendererNative::Get().DrawItemSelectionRect( m_owner, *dc, m_gi->m_rectHighlight, flags );        }        else        {            dc->DrawRectangle( m_gi->m_rectHighlight );        }    }#endif    // 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    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 ){    // 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    wxListItemAttr *attr = GetAttr();    if ( SetAttributes(dc, attr, highlighted) )#if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )    {        dc->DrawRectangle( rectHL );    }#else    {        if (highlighted)        {            int flags = wxCONTROL_SELECTED;            if (m_owner->HasFocus()#ifdef __WXMAC__                && IsControlActive( (ControlRef)m_owner->GetHandle() )#endif            )                flags |= wxCONTROL_FOCUSED;            wxRendererNative::Get().DrawItemSelectionRect( m_owner, *dc, rectHL, flags );        }        else        {            dc->DrawRectangle( rectHL );        }    }#endif    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;	// Fix for a bug in wxWidgets.	// This has been reported as patch 1898914:	// http://sourceforge.net/tracker/index.php?func=detail&aid=1898914&group_id=9863&atid=309863	//        // Prevents the drawing of images into the        // next collumn, in case of small widths.        wxDCClipper clipper(*dc, xOld, rect.y, width - 8, 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 - 8);    }}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(_T("\n"), _T(" "));    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( _T("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, _T("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)    EVT_SET_FOCUS     (wxListHeaderWindow::OnSetFocus)END_EVENT_TABLE()void wxListHeaderWindow::Init(){    m_currentCursor = (wxCursor *) NULL;    m_isDragging = false;    m_dirty = false;}wxListHeaderWindow::wxListHeaderWindow(){    Init();    m_owner = (wxListMainWindow *) NULL;    m_resizeCursor = (wxCursor *) NULL;}wxListHeaderWindow::wxListHeaderWindow( wxWindow *win,                                        wxWindowID id,                                        wxListMainWindow *owner,                                        const wxPoint& pos,                                        const wxSize& size,                                        long style,                                        const wxString &name )                  : wxWindow( win, id, pos, size, style, name ){    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}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 coordsvoid wxListHeaderWindow::AdjustDC(wxDC& dc){    int xpix;    m_owner->GetScrollPixelsPerUnit( &xpix, NULL );    int view_start;    m_owner->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) ){    wxPaintDC dc( this );    PrepareDC( dc );    AdjustDC( dc );    dc.SetFont( GetFont() );    // width and height of the entire header window    int w, h;    GetClientSize( &w, &h );    m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);    dc.SetBackgroundMode(wxTRANSPARENT);    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 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),                                    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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -