Example #1
0
wxSize wxGridCellStringRenderer::GetBestSize(wxGrid& grid,
                                             wxGridCellAttr& attr,
                                             wxDC& dc,
                                             int row, int col)
{
    return DoGetBestSize(attr, dc, grid.GetCellValue(row, col));
}
Example #2
0
wxArrayString
wxGridCellAutoWrapStringRenderer::GetTextLines(wxGrid& grid,
                                               wxDC& dc,
                                               const wxGridCellAttr& attr,
                                               const wxRect& rect,
                                               int row, int col)
{
    dc.SetFont(attr.GetFont());
    const wxCoord maxWidth = rect.GetWidth();

    // Transform logical lines into physical ones, wrapping the longer ones.
    const wxArrayString
        logicalLines = wxSplit(grid.GetCellValue(row, col), '\n', '\0');

    wxArrayString physicalLines;
    for ( wxArrayString::const_iterator it = logicalLines.begin();
          it != logicalLines.end();
          ++it )
    {
        const wxString& line = *it;

        if ( dc.GetTextExtent(line).x > maxWidth )
        {
            // Line does not fit, break it up.
            BreakLine(dc, line, maxWidth, physicalLines);
        }
        else // The entire line fits as is
        {
            physicalLines.push_back(line);
        }
    }

    return physicalLines;
}
Example #3
0
wxArrayString
wxGridCellAutoWrapStringRenderer::GetTextLines(wxGrid& grid,
                                               wxDC& dc,
                                               const wxGridCellAttr& attr,
                                               const wxRect& rect,
                                               int row, int col)
{
    wxString  data = grid.GetCellValue(row, col);

    wxArrayString lines;
    dc.SetFont(attr.GetFont());

    //Taken from wxGrid again!
    wxCoord x = 0, y = 0, curr_x = 0;
    wxCoord max_x = rect.GetWidth();

    dc.SetFont(attr.GetFont());
    wxStringTokenizer tk(data , wxT(" \n\t\r"));
    wxString thisline = wxEmptyString;

    while ( tk.HasMoreTokens() )
    {
        wxString tok = tk.GetNextToken();
        //FIXME: this causes us to print an extra unnecesary
        //       space at the end of the line. But it
        //       is invisible , simplifies the size calculation
        //       and ensures tokens are separated in the display
        tok += wxT(" ");

        dc.GetTextExtent(tok, &x, &y);
        if ( curr_x + x > max_x)
        {
            if ( curr_x == 0 )
            {
                // this means that a single token is wider than the maximal
                // width -- still use it as is as we need to show at least the
                // part of it which fits
                lines.Add(tok);
            }
            else
            {
                lines.Add(thisline);
                thisline = tok;
                curr_x = x;
            }
        }
        else
        {
            thisline+= tok;
            curr_x += x;
        }
    }
    //Add last line
    lines.Add( wxString(thisline) );

    return lines;
}
void CBOINCGridCellMessageRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool isSelected) {
	wxString szError(wxT("Error"));
	if(grid.GetCellValue(row,column).Trim(false).IsSameAs(szError)) {
		attr.SetTextColour(*wxRED);
	}
	else {
		attr.SetTextColour(*wxBLACK);
	}
	CBOINCGridCellRenderer::Draw(grid,attr,dc,rect,row,col,isSelected);
}
/* paints the progress bar */
void CBOINCGridCellProgressRenderer::DoProgressDrawing(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
	this->DrawBackground(grid, dc, rectCell, row, isSelected);
	// set text attributes
    int hAlign, vAlign;
	attr.GetAlignment(&hAlign, &vAlign);
    SetTextColoursAndFont(grid, attr, dc, isSelected);

	//calculate the two parts of the progress rect
    //
	double dv = 0.0;
	wxString strValue = grid.GetCellValue(row,col);
	if(m_bDoPercentAppending) {
		strValue = strValue + wxT(" %");
	}

    // Project view uses the format:  %0.0f (%0.2f%%)
    // Everyone else uses: %.3f%%
    if (strValue.Find(wxT("(")) != wxNOT_FOUND) {
        strValue.SubString(strValue.Find(wxT("(")) + 1, strValue.Find(wxT(")")) - 1).ToDouble( &dv );
    } else {
    	strValue.ToDouble ( &dv );	 // NOTE: we should do error-checking/reporting here!!
    }


	wxRect p1(rect);
	wxRect p2(rect);
	int r = (int)((rect.GetRight()-rect.GetLeft())*dv / 100.0);
	p1.SetRight(rect.GetLeft()+r);
	p2.SetLeft(rect.GetLeft()+r+1);
	p2.SetRight(rect.GetRight()-1);
	//start drawing
	dc.SetClippingRegion(rect);
	wxBrush old = dc.GetBrush();
	wxColour progressColour = wxTheColourDatabase->Find(wxT("LIGHT BLUE"));
	wxBrush* progressBrush = wxTheBrushList->FindOrCreateBrush(progressColour);
	wxPen* progressPen = wxThePenList->FindOrCreatePen(progressColour,1,wxSOLID);
	//draw the outline rectangle
	dc.SetBrush(*wxTRANSPARENT_BRUSH);
	dc.SetPen(*progressPen);
	dc.DrawRectangle(rect);
	// Draw the left part
	dc.SetBrush(*progressBrush);
	dc.DrawRectangle(p1);
	//draw the right part
	dc.SetBrush(old);
	dc.DrawRectangle(p2);
	//
	dc.DestroyClippingRegion();
	// draw the text
	grid.DrawTextRectangle(dc, strValue, rect, hAlign, vAlign);
}
Example #6
0
ptree getMappingJsonSerialized(const wxGrid &grid) {
  ptree root;
  ptree mappingArray;
  const int size = firstFreeRow(grid);
  for (int i = 0; i < size; ++i) {
    ptree child;
    std::vector<std::string> strings2d;
    std::vector<std::string> strings3d;
    string cellValue2d = string(grid.GetCellValue(i, 0));
    string cellValue3d = string(grid.GetCellValue(i, 1));
    boost::split(strings2d, cellValue2d, boost::is_any_of(";"));
    boost::split(strings3d, cellValue3d, boost::is_any_of(";"));
    child.put("2d-X", strings2d[0]);
    child.put("2d-Y", strings2d[1]);
    child.put("3d-X", strings3d[0]);
    child.put("3d-Y", strings3d[1]);
    child.put("3d-Z", strings3d[2]);
    mappingArray.push_back(make_pair("", child));
  }
  root.add_child("mapping", mappingArray);
  return root;
}
Example #7
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);
}
void wxGridCellChoiceRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
                                    const wxRect& rectCell, int row, int col, bool isSelected)
{
    wxGridCellRenderer::Draw(grid, attr, dc, rectCell, row, col, isSelected);
    // first calculate button size
    // don't draw outside the cell
    int nButtonWidth = 17;
    if (rectCell.height < 2) return;
    wxRect rectButton;
    rectButton.x = rectCell.x + rectCell.width - nButtonWidth;
    rectButton.y = rectCell.y + 1;
    int cell_rows, cell_cols;
    attr.GetSize(&cell_rows, &cell_cols);
    rectButton.width = nButtonWidth;
    if (cell_rows == 1)
        rectButton.height = rectCell.height-2;
    else
        rectButton.height = nButtonWidth;

    SetTextColoursAndFont(grid, attr, dc, isSelected);
    int hAlign, vAlign;
    attr.GetAlignment(&hAlign, &vAlign);
    // leave room for button
    wxRect rect = rectCell;
    rect.SetWidth(rectCell.GetWidth() - rectButton.GetWidth()-2);
    rect.Inflate(-1);
    grid.DrawTextRectangle(dc, grid.GetCellValue(row, col), rect, hAlign, vAlign);

    // don't bother drawing if the cell is too small
    if (rectButton.height < 4 || rectButton.width < 4) return;
    // draw 3-d button
    wxColour colourBackGround = wxColour(COLORBASE);
    dc.SetBrush(wxBrush(colourBackGround, wxSOLID));
    dc.SetPen(wxPen(colourBackGround, 1, wxSOLID));
    dc.DrawRectangle(rectButton);
    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), 1, wxSOLID));
    dc.DrawLine(rectButton.GetLeft(), rectButton.GetBottom(),
                rectButton.GetRight(), rectButton.GetBottom());
    dc.DrawLine(rectButton.GetRight(), rectButton.GetBottom(),
                rectButton.GetRight(), rectButton.GetTop()-1);
    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW),
                    1, wxSOLID));
    dc.DrawLine(rectButton.GetLeft()+1, rectButton.GetBottom()-1,
                rectButton.GetRight()-1, rectButton.GetBottom()-1);
    dc.DrawLine(rectButton.GetRight()-1, rectButton.GetBottom()-1,
                rectButton.GetRight()-1, rectButton.GetTop());
    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT),
                    1, wxSOLID));
    dc.DrawLine(rectButton.GetRight()-2, rectButton.GetTop()+1,
                rectButton.GetLeft()+1, rectButton.GetTop()+1);
    dc.DrawLine(rectButton.GetLeft()+1, rectButton.GetTop()+1,
                rectButton.GetLeft()+1, rectButton.GetBottom()-1);
    // Draw little triangle
    int nTriWidth = 7;
    int nTriHeight = 4;
    wxPoint point[3];
    point[0] = wxPoint(rectButton.GetLeft() + (rectButton.GetWidth()-nTriWidth)/2,
                       rectButton.GetTop()+(rectButton.GetHeight()-nTriHeight)/2);
    point[1] = wxPoint(point[0].x+nTriWidth-1, point[0].y);
    point[2] = wxPoint(point[0].x+3, point[0].y+nTriHeight-1);
    dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), wxSOLID));
    dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT), 1, wxSOLID));
    dc.DrawPolygon(3, point);
    if (m_border == wxLAYOUT_TOP)
    {
        dc.SetPen(wxPen(*wxBLACK, 1, wxDOT));
        dc.DrawLine(rectCell.GetRight(), rectCell.GetTop(),
                    rectCell.GetLeft(), rectCell.GetTop());
    }
}