void wxListBox::DoDraw(wxControlRenderer *renderer)
{
    // adjust the DC to account for scrolling
    wxDC& dc = renderer->GetDC();
    PrepareDC(dc);
    dc.SetFont(GetFont());

    // get the update rect
    wxRect rectUpdate = GetUpdateClientRect();

    int yTop, yBottom;
    CalcUnscrolledPosition(0, rectUpdate.GetTop(), NULL, &yTop);
    CalcUnscrolledPosition(0, rectUpdate.GetBottom(), NULL, &yBottom);

    // get the items which must be redrawn
    wxCoord lineHeight = GetLineHeight();
    size_t itemFirst = yTop / lineHeight,
           itemLast = (yBottom + lineHeight - 1) / lineHeight,
           itemMax = m_strings->GetCount();

    if ( itemFirst >= itemMax )
        return;

    if ( itemLast > itemMax )
        itemLast = itemMax;

    // do draw them
    wxLogTrace(_T("listbox"), _T("Repainting items %d..%d"),
               itemFirst, itemLast);

    DoDrawRange(renderer, itemFirst, itemLast);
}
Example #2
0
void wxVListBox::OnPaint(wxPaintEvent& WXUNUSED(event))
{
    wxSize clientSize = GetClientSize();

    wxAutoBufferedPaintDC dc(this);

    // the update rectangle
    wxRect rectUpdate = GetUpdateClientRect();

    // fill it with background colour
    dc.SetBackground(GetBackgroundColour());
    dc.Clear();

    // the bounding rectangle of the current line
    wxRect rectLine;
    rectLine.width = clientSize.x;

    // iterate over all visible lines
    const size_t lineMax = GetVisibleEnd();
    for ( size_t line = GetFirstVisibleLine(); line < lineMax; line++ )
    {
        const wxCoord hLine = OnGetLineHeight(line);

        rectLine.height = hLine;

        // and draw the ones which intersect the update rect
        if ( rectLine.Intersects(rectUpdate) )
        {
            // don't allow drawing outside of the lines rectangle
            wxDCClipper clip(dc, rectLine);

            wxRect rect = rectLine;
            OnDrawBackground(dc, rect, line);

            OnDrawSeparator(dc, rect, line);

            rect.Deflate(m_ptMargins.x, m_ptMargins.y);
            OnDrawItem(dc, rect, line);
        }
        else // no intersection
        {
            if ( rectLine.GetTop() > rectUpdate.GetBottom() )
            {
                // we are already below the update rect, no need to continue
                // further
                break;
            }
            //else: the next line may intersect the update rect
        }

        rectLine.y += hLine;
    }
}
void wxSymbolListCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
{
    // If size is larger, recalculate double buffer bitmap
    wxSize clientSize = GetClientSize();

    if ( !m_doubleBuffer ||
         clientSize.x > m_doubleBuffer->GetWidth() ||
         clientSize.y > m_doubleBuffer->GetHeight() )
    {
        delete m_doubleBuffer;
        m_doubleBuffer = new wxBitmap(clientSize.x+25,clientSize.y+25);
    }

    wxBufferedPaintDC dc(this,*m_doubleBuffer);

    // the update rectangle
    wxRect rectUpdate = GetUpdateClientRect();

    // fill it with background colour
    dc.SetBackground(GetBackgroundColour());
    dc.Clear();

    // set the font to be displayed
    dc.SetFont(GetFont());

    // the bounding rectangle of the current line
    wxRect rectRow;
    rectRow.width = clientSize.x;

    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)));
    dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
    dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);

    // iterate over all visible lines
    const size_t lineMax = GetVisibleEnd();
    for ( size_t line = GetVisibleBegin(); line < lineMax; line++ )
    {
        const wxCoord hRow = OnGetRowHeight(line);

        rectRow.height = hRow;

        // and draw the ones which intersect the update rect
        if ( rectRow.Intersects(rectUpdate) )
        {
            // don't allow drawing outside of the lines rectangle
            wxDCClipper clip(dc, rectRow);

            wxRect rect = rectRow;
            rect.Deflate(m_ptMargins.x, m_ptMargins.y);
            OnDrawItem(dc, rect, line);
        }
        else // no intersection
        {
            if ( rectRow.GetTop() > rectUpdate.GetBottom() )
            {
                // we are already below the update rect, no need to continue
                // further
                break;
            }
            //else: the next line may intersect the update rect
        }

        rectRow.y += hRow;
    }
}
Example #4
0
	void OnDraw(wxDC& dc)
	{
		dc.SetBackground(m_view->GetBackgroundColour());
		dc.Clear();

		dc.SetFont(m_view->GetFont());

		wxRect updateRect = GetUpdateClientRect();
		updateRect.SetPosition(CalcUnscrolledPosition(updateRect.GetPosition()));

		int startRow = updateRect.GetTop() / m_rowHeight;
		int endRow = std::ceil(updateRect.GetBottom() / (double)m_rowHeight);
		if (endRow > m_view->m_dataSize / m_view->m_rowsize)
			endRow = m_view->m_dataSize / m_view->m_rowsize;

		wxSize offsetSize = dc.GetTextExtent("00000000");
		offsetSize.x += 4;
		wxSize byteSize = dc.GetTextExtent("00");
		byteSize.x += 2;

		wxRect visRect = GetClientSize();
		wxPoint viewStart = GetViewStart();

		for (int row = startRow; row <= endRow; ++row)
		{
			int offset = row * m_view->m_rowsize;
			wxPoint rowPos = wxPoint(2, (row * m_rowHeight) + 2);

			int rowsize = m_view->m_rowsize;
			if (offset + rowsize > m_view->m_dataSize)
				rowsize = m_view->m_dataSize - offset;

			// Draw offset
			dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
			dc.DrawText(wxString::Format("%.8X", offset), rowPos);
			rowPos.x += offsetSize.GetWidth();

			// Draw row values
			dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
			for (int i = 0; i < m_view->m_rowsize; ++i)
			{
				if (i < rowsize)
					dc.DrawText(wxString::Format("%.2X", m_view->m_data[offset + i]), rowPos);

				rowPos.x += byteSize.GetWidth();
			}

			rowPos.x += m_charWidth;

			// Draw row characters
			wxString str((const char*)&m_view->m_data[offset], rowsize);
			for (auto it = str.begin(); it != str.end(); ++it)
			{
				if (*it < 32)
					*it = '.';
			}

			dc.DrawText(str, rowPos);

			rowPos.y += m_rowHeight;
		}
	}