示例#1
0
wxSize
wxGridCellAutoWrapStringRenderer::GetBestSize(wxGrid& grid,
                                              wxGridCellAttr& attr,
                                              wxDC& dc,
                                              int row, int col)
{
    wxCoord x,y, height , width = grid.GetColSize(col) -20;
    // for width, subtract 20 because ColSize includes a magin of 10 pixels
    // that we do not want here and because we always start with an increment
    // by 10 in the loop below.
    int count = 250; //Limit iterations..

    wxRect rect(0,0,width,10);

    // M is a nice large character 'y' gives descender!.
    dc.GetTextExtent(wxT("My"), &x, &y);

    do
    {
        width+=10;
        rect.SetWidth(width);
        height = y * (wx_truncate_cast(wxCoord, GetTextLines(grid,dc,attr,rect,row,col).GetCount()));
        count--;
    // Search for a shape no taller than the golden ratio.
    } while (count && (width  < (height*1.68)) );


    return wxSize(width,height);
}
示例#2
0
wxSize
wxGridCellAutoWrapStringRenderer::GetBestSize(wxGrid& grid,
                                              wxGridCellAttr& attr,
                                              wxDC& dc,
                                              int row, int col)
{
    wxCoord x,y, height , width = grid.GetColSize(col) -10;
    int count = 250; //Limit iterations..

    wxRect rect(0,0,width,10);

    // M is a nice large character 'y' gives descender!.
    dc.GetTextExtent(wxT("My"), &x, &y);

    do
    {
        width+=10;
        rect.SetWidth(width);
        height = y * (wx_truncate_cast(wxCoord, GetTextLines(grid,dc,attr,rect,row,col).GetCount()));
        count--;
    // Search for a shape no taller than the golden ratio.
    } while (count && (width  < (height*1.68)) );


    return wxSize(width,height);
}
示例#3
0
void CellRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool isSelected)
{
  dc.SetClippingRegion(rect);
  wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, false);

  if( m_Renderer != NULL && imageName != NULL && StrOp.len(imageName) > 0 ) {
    int cx = 0;
    int cy = 0;

    if( imageBitmap == NULL ) {
      wxMemoryDC tmpDC;
      m_Renderer->sizeSvgSym( imageName, wItem.west, &cx, &cy );
      if( imageBitmap != NULL )
        delete imageBitmap;
      imageBitmap = new wxBitmap();
      imageBitmap->Create(cx * 32 * m_Scale, cy * 32 * m_Scale , -1);
      tmpDC.SelectObject(*imageBitmap);
      tmpDC.SetBackground(*wxWHITE_BRUSH);
      tmpDC.Clear();
      tmpDC.SetUserScale( m_Scale, m_Scale );
      m_Renderer->drawSvgSym( (wxPaintDC&)tmpDC, 0, 0, imageName, wItem.west, &cx, &cy );
      tmpDC.SelectObject(wxNullBitmap);

      m_RowSize = cy * 32 * m_Scale + 4;

      if( grid.GetColSize(col) <  cx * 32 * m_Scale )
        grid.SetColSize(col, cx * 32 * m_Scale );
      if( grid.GetRowSize(row) <  m_RowSize )
        grid.SetRowSize(row, m_RowSize );
      TraceOp.trc( "cellrenderer", TRCLEVEL_DEBUG, __LINE__, 9999, "image: %s dc=%X row=%d col=%d cx=%d cy=%d rowsize=%d", imageName,
          &dc, row, col, cx, cy, m_RowSize );
    }

    dc.DrawBitmap(*imageBitmap, rect.x, rect.y + 2);

  }
  else if( imageName != NULL && StrOp.len(imageName) > 0 ) {
    if( imageBitmap == NULL )
      updateImage(rect);
    if( imageBitmap != NULL ) {
      dc.DrawBitmap(*imageBitmap, rect.x, rect.y);
      if( !m_bDidResize ) {
        grid.AutoSizeColumn(col);
        m_bDidResize = true;
      }
    }
  }

  dc.DestroyClippingRegion();
}
示例#4
0
//------------------------------------------------------------------------------
//          custom renderer
//------------------------------------------------------------------------------
void CustomRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool isSelected)
{
    dc.SetPen(wxPen(attr.GetBackgroundColour(), 1));
    dc.SetBrush(wxBrush( attr.GetBackgroundColour(), wxBRUSHSTYLE_SOLID ));
    dc.DrawRectangle( rect );
    if( m_IsDigit || m_dDir == GRIB_NOTDEF ) {        //digital format
        wxString text(wxEmptyString);
        if( m_dDir != GRIB_NOTDEF )
            text.Printf(_T("%03d\u00B0"), (int)m_dDir);
        dc.DrawLabel(text, rect, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
    } else {                                        //graphical format
        double si = sin( (m_dDir - 90) * M_PI / 180. );
        double co = cos( (m_dDir - 90) * M_PI / 180. );

        int i = rect.GetTopLeft().x + (rect.GetWidth() / 2);
        int j = rect.GetTopLeft().y + (rect.GetHeight() / 2);

        int arrowSize = rect.GetHeight() - 3;
        int dec = -arrowSize / 2;

#if wxUSE_GRAPHICS_CONTEXT
        wxGraphicsContext *gdc;
        wxClientDC *cdc = new wxClientDC(wxDynamicCast( &grid, wxWindow));
        cdc = wxDynamicCast(&dc, wxClientDC);
        if( cdc ) {
            gdc = wxGraphicsContext::Create(*cdc);
#ifdef __WXGTK__
            /*platforms don't manage the same way the gdc origin
            for linux, we have to re-compute the good one.
            To DO : verify it works on all other plateforms (done for MSW*/
            bool vis = false;
            int r = 0;
            for( int c = 0; c < grid.GetNumberCols(); c++){
                for(r = 0; r < grid.GetNumberRows(); r++) {
                    if(grid.IsVisible(r, c)){  //find the first row/col
                        vis = true;
                        i -= (c * grid.GetColSize(0));
                        j -= (r * grid.GetRowHeight(0));
                        break;
                    }
                }
                if(vis) break;
            }
#endif
            gdc->SetPen(wxPen(attr.GetTextColour(), 3));
            gdc->SetBrush(wxBrush( attr.GetBackgroundColour(), wxBRUSHSTYLE_SOLID ));

            double ii, jj, kk, ll;
            GetArrowsPoints( si, co, i, j, dec, 0, dec + arrowSize, 0, ii, jj, kk, ll );
            gdc->StrokeLine( ii, jj, kk, ll );
            GetArrowsPoints( si, co, i, j, dec - 3, 0, dec + 5, 3, ii, jj, kk, ll );
            gdc->StrokeLine( ii, jj, kk, ll );
            GetArrowsPoints( si, co, i, j, dec - 3, 0, dec + 5, -3, ii, jj, kk, ll );
            gdc->StrokeLine( ii, jj, kk, ll );
            delete gdc;
        } else
#endif
        {
            dc.SetPen(wxPen(attr.GetTextColour(), 3));
            double ii, jj, kk, ll;
            GetArrowsPoints( si, co, i, j, dec, 0, dec + arrowSize, 0, ii, jj, kk, ll );
            dc.DrawLine( (int)ii, (int)jj, (int)kk, (int)ll );
            GetArrowsPoints( si, co, i, j, dec - 3, 0, dec + 5, 3, ii, jj, kk, ll );
            dc.DrawLine( (int)ii, (int)jj, (int)kk, (int)ll );
            GetArrowsPoints( si, co, i, j, dec - 3, 0, dec + 5, -3, ii, jj, kk, ll );
            dc.DrawLine( (int)ii, (int)jj, (int)kk, (int)ll );
        }
    }
}
示例#5
0
void wxGridCellStringRenderer::Draw(wxGrid& grid,
                                    wxGridCellAttr& attr,
                                    wxDC& dc,
                                    const wxRect& rectCell,
                                    int row, int col,
                                    bool isSelected)
{
    wxRect rect = rectCell;
    rect.Inflate(-1);

    // erase only this cells background, overflow cells should have been erased
    wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);

    int hAlign, vAlign;
    attr.GetAlignment(&hAlign, &vAlign);

    int overflowCols = 0;

    if (attr.GetOverflow())
    {
        int cols = grid.GetNumberCols();
        int best_width = GetBestSize(grid,attr,dc,row,col).GetWidth();
        int cell_rows, cell_cols;
        attr.GetSize( &cell_rows, &cell_cols ); // shouldn't get here if <= 0
        if ((best_width > rectCell.width) && (col < cols) && grid.GetTable())
        {
            int i, c_cols, c_rows;
            for (i = col+cell_cols; i < cols; i++)
            {
                bool is_empty = true;
                for (int j=row; j < row + cell_rows; j++)
                {
                    // check w/ anchor cell for multicell block
                    grid.GetCellSize(j, i, &c_rows, &c_cols);
                    if (c_rows > 0)
                        c_rows = 0;
                    if (!grid.GetTable()->IsEmptyCell(j + c_rows, i))
                    {
                        is_empty = false;
                        break;
                    }
                }

                if (is_empty)
                {
                    rect.width += grid.GetColSize(i);
                }
                else
                {
                    i--;
                    break;
                }

                if (rect.width >= best_width)
                    break;
            }

            overflowCols = i - col - cell_cols + 1;
            if (overflowCols >= cols)
                overflowCols = cols - 1;
        }

        if (overflowCols > 0) // redraw overflow cells w/ proper hilight
        {
            hAlign = wxALIGN_LEFT; // if oveflowed then it's left aligned
            wxRect clip = rect;
            clip.x += rectCell.width;
            // draw each overflow cell individually
            int col_end = col + cell_cols + overflowCols;
            if (col_end >= grid.GetNumberCols())
                col_end = grid.GetNumberCols() - 1;
            for (int i = col + cell_cols; i <= col_end; i++)
            {
                clip.width = grid.GetColSize(i) - 1;
                dc.DestroyClippingRegion();
                dc.SetClippingRegion(clip);

                SetTextColoursAndFont(grid, attr, dc,
                        grid.IsInSelection(row,i));

                grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
                        rect, hAlign, vAlign);
                clip.x += grid.GetColSize(i) - 1;
            }

            rect = rectCell;
            rect.Inflate(-1);
            rect.width++;
            dc.DestroyClippingRegion();
        }
    }

    // now we only have to draw the text
    SetTextColoursAndFont(grid, attr, dc, isSelected);

    grid.DrawTextRectangle(dc, grid.GetCellValue(row, col),
                           rect, hAlign, vAlign);
}