コード例 #1
1
ファイル: Grid.cpp プロジェクト: RaphaelMarinier/audacity
wxSize NumericRenderer::GetBestSize(wxGrid &grid,
                                 wxGridCellAttr & WXUNUSED(attr),
                                 wxDC & WXUNUSED(dc),
                                 int row,
                                 int col)
{
   wxGridTableBase *table = grid.GetTable();
   NumericEditor *ne =
      static_cast<NumericEditor *>(grid.GetCellEditor(row, col));
   wxSize sz;

   if (ne) {
      double value;
      table->GetValue(row, col).ToDouble(&value);
      NumericTextCtrl tt(mType, &grid,
                      wxID_ANY,
                      ne->GetFormat(),
                      value,
                      ne->GetRate(),
                      wxPoint(10000, 10000),  // create offscreen
                      wxDefaultSize,
                      true);
      sz = tt.GetSize();

      ne->DecRef();
   }

   return sz;
}
コード例 #2
0
ファイル: gridctrl.cpp プロジェクト: 3v1n0/wxWidgets
wxString wxGridCellFloatRenderer::GetString(const wxGrid& grid, int row, int col)
{
    wxGridTableBase *table = grid.GetTable();

    bool hasDouble;
    double val;
    wxString text;
    if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) )
    {
        val = table->GetValueAsDouble(row, col);
        hasDouble = true;
    }
    else
    {
        text = table->GetValue(row, col);
        hasDouble = text.ToDouble(&val);
    }

    if ( hasDouble )
    {
        if ( !m_format )
        {
            if ( m_width == -1 )
            {
                if ( m_precision == -1 )
                {
                    // default width/precision
                    m_format = wxT("%");
                }
                else
                {
                    m_format.Printf(wxT("%%.%d"), m_precision);
                }
            }
            else if ( m_precision == -1 )
            {
                // default precision
                m_format.Printf(wxT("%%%d."), m_width);
            }
            else
            {
                m_format.Printf(wxT("%%%d.%d"), m_width, m_precision);
            }

            bool isUpper = ( ( m_style & wxGRID_FLOAT_FORMAT_UPPER ) == wxGRID_FLOAT_FORMAT_UPPER);
            if ( ( m_style & wxGRID_FLOAT_FORMAT_SCIENTIFIC ) == wxGRID_FLOAT_FORMAT_SCIENTIFIC)
                m_format += isUpper ? wxT('E') : wxT('e');
            else if ( ( m_style & wxGRID_FLOAT_FORMAT_COMPACT ) == wxGRID_FLOAT_FORMAT_COMPACT)
                m_format += isUpper ? wxT('G') : wxT('g');
            else
                m_format += wxT('f');
        }

        text.Printf(m_format, val);

    }
    //else: text already contains the string

    return text;
}
コード例 #3
0
ファイル: gridctrl.cpp プロジェクト: 3v1n0/wxWidgets
wxString wxGridCellDateTimeRenderer::GetString(const wxGrid& grid, int row, int col)
{
    wxGridTableBase *table = grid.GetTable();

    bool hasDatetime = false;
    wxDateTime val;
    wxString text;
    if ( table->CanGetValueAs(row, col, wxGRID_VALUE_DATETIME) )
    {
        void * tempval = table->GetValueAsCustom(row, col,wxGRID_VALUE_DATETIME);

        if (tempval)
        {
            val = *((wxDateTime *)tempval);
            hasDatetime = true;
            delete (wxDateTime *)tempval;
        }

    }

    if (!hasDatetime )
    {
        text = table->GetValue(row, col);
        const char * const end = val.ParseFormat(text, m_iformat, m_dateDef);
        hasDatetime = end && !*end;
    }

    if ( hasDatetime )
        text = val.Format(m_oformat, m_tz );

    // If we failed to parse string just show what we where given?
    return text;
}
コード例 #4
0
ファイル: Grid.cpp プロジェクト: ducknoir/audacity
wxSize TimeRenderer::GetBestSize(wxGrid &grid,
                                 wxGridCellAttr & WXUNUSED(attr),
                                 wxDC & WXUNUSED(dc),
                                 int row,
                                 int col)
{
    wxGridTableBase *table = grid.GetTable();
    TimeEditor *te = (TimeEditor *) grid.GetCellEditor(row, col);
    wxSize sz;

    if (te) {
        double value;
        table->GetValue(row, col).ToDouble(&value);
        NumericTextCtrl tt(NumericConverter::TIME, &grid,
                           wxID_ANY,
                           te->GetFormat(),
                           value,
                           te->GetRate(),
                           wxPoint(10000, 10000),  // create offscreen
                           wxDefaultSize,
                           true);
        sz = tt.GetSize();

        te->DecRef();
    }

    return sz;
}
コード例 #5
0
ファイル: Grid.cpp プロジェクト: tuanmasterit/audacity
wxSize TimeRenderer::GetBestSize(wxGrid &grid,
                                 wxGridCellAttr &attr,
                                 wxDC &dc,
                                 int row,
                                 int col)
{
   wxGridTableBase *table = grid.GetTable();
   TimeEditor *te = (TimeEditor *) grid.GetCellEditor(row, col);
   wxSize sz;

   if (te) {
      double value;
      table->GetValue(row, col).ToDouble(&value);
      TimeTextCtrl tt(&grid,
                      wxID_ANY,
                      wxT(""),
                      value,
                      te->GetRate(),
                      wxPoint(10000, 10000),  // create offscreen
                      wxDefaultSize,
                      true);
      tt.SetFormatString(tt.GetBuiltinFormat(te->GetFormat()));
      sz = tt.GetSize();

      te->DecRef();
   }

   return sz;
}
コード例 #6
0
ファイル: gridctrl.cpp プロジェクト: BloodRedd/gamekit
wxString wxGridCellFloatRenderer::GetString(const wxGrid& grid, int row, int col)
{
    wxGridTableBase *table = grid.GetTable();

    bool hasDouble;
    double val;
    wxString text;
    if ( table->CanGetValueAs(row, col, wxGRID_VALUE_FLOAT) )
    {
        val = table->GetValueAsDouble(row, col);
        hasDouble = true;
    }
    else
    {
        text = table->GetValue(row, col);
        hasDouble = text.ToDouble(&val);
    }

    if ( hasDouble )
    {
        if ( !m_format )
        {
            if ( m_width == -1 )
            {
                if ( m_precision == -1 )
                {
                    // default width/precision
                    m_format = wxT("%f");
                }
                else
                {
                    m_format.Printf(wxT("%%.%df"), m_precision);
                }
            }
            else if ( m_precision == -1 )
            {
                // default precision
                m_format.Printf(wxT("%%%d.f"), m_width);
            }
            else
            {
                m_format.Printf(wxT("%%%d.%df"), m_width, m_precision);
            }
        }

        text.Printf(m_format, val);

    }
    //else: text already contains the string

    return text;
}
コード例 #7
0
ファイル: gridctrl.cpp プロジェクト: 3v1n0/wxWidgets
wxString wxGridCellNumberRenderer::GetString(const wxGrid& grid, int row, int col)
{
    wxGridTableBase *table = grid.GetTable();
    wxString text;
    if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
    {
        text.Printf(wxT("%ld"), table->GetValueAsLong(row, col));
    }
    else
    {
        text = table->GetValue(row, col);
    }

    return text;
}
コード例 #8
0
ファイル: CellRenderer.cpp プロジェクト: Skier/vault_repo
/* -------------------------- implementation place -------------------------- */
void CellRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool isSelected) {

#if 0 

    DocTable* t = (DocTable*)grid.GetTable();
    if ( t->GetDocument().GetColumnDescriptor(t->Map(col)).IsRequired() && t->GetDocument().IsValidValue(row, t->Map(col))) {
		attr.SetBackgroundColour(REQUIRED_COL);
	} else if ( !t->GetDocument().IsValidValue(row, t->Map(col))) { 
		attr.SetBackgroundColour(NOT_VALID_COL);
	} else {
		attr.SetBackgroundColour(VALID_COL);
	}

#endif 

	wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
};
コード例 #9
0
ファイル: gridctrl.cpp プロジェクト: 3v1n0/wxWidgets
wxString wxGridCellEnumRenderer::GetString(const wxGrid& grid, int row, int col)
{
    wxGridTableBase *table = grid.GetTable();
    wxString text;
    if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
    {
        int choiceno = table->GetValueAsLong(row, col);
        text.Printf(wxT("%s"), m_choices[ choiceno ].c_str() );
    }
    else
    {
        text = table->GetValue(row, col);
    }


    //If we faild to parse string just show what we where given?
    return text;
}
コード例 #10
0
ファイル: gridctrl.cpp プロジェクト: 3v1n0/wxWidgets
void wxGridCellBoolRenderer::Draw(wxGrid& grid,
                                  wxGridCellAttr& attr,
                                  wxDC& dc,
                                  const wxRect& rect,
                                  int row, int col,
                                  bool isSelected)
{
    wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);

    // draw a check mark in the centre (ignoring alignment - TODO)
    wxSize size = GetBestSize(grid, attr, dc, row, col);

    // don't draw outside the cell
    wxCoord minSize = wxMin(rect.width, rect.height);
    if ( size.x >= minSize || size.y >= minSize )
    {
        // and even leave (at least) 1 pixel margin
        size.x = size.y = minSize;
    }

    // draw a border around checkmark
    int vAlign, hAlign;
    attr.GetAlignment(&hAlign, &vAlign);

    wxRect rectBorder;
    if (hAlign == wxALIGN_CENTRE)
    {
        rectBorder.x = rect.x + rect.width / 2 - size.x / 2;
        rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
        rectBorder.width = size.x;
        rectBorder.height = size.y;
    }
    else if (hAlign == wxALIGN_LEFT)
    {
        rectBorder.x = rect.x + 2;
        rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
        rectBorder.width = size.x;
        rectBorder.height = size.y;
    }
    else if (hAlign == wxALIGN_RIGHT)
    {
        rectBorder.x = rect.x + rect.width - size.x - 2;
        rectBorder.y = rect.y + rect.height / 2 - size.y / 2;
        rectBorder.width = size.x;
        rectBorder.height = size.y;
    }

    bool value;
    if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) )
    {
        value = grid.GetTable()->GetValueAsBool(row, col);
    }
    else
    {
        wxString cellval( grid.GetTable()->GetValue(row, col) );
        value = wxGridCellBoolEditor::IsTrueValue(cellval);
    }

    int flags = 0;
    if (value)
        flags |= wxCONTROL_CHECKED;

    wxRendererNative::Get().DrawCheckBox( &grid, dc, rectBorder, flags );
}
コード例 #11
0
ファイル: gridctrl.cpp プロジェクト: 3v1n0/wxWidgets
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);
}
コード例 #12
0
ファイル: Grid.cpp プロジェクト: ducknoir/audacity
void TimeRenderer::Draw(wxGrid &grid,
                        wxGridCellAttr &attr,
                        wxDC &dc,
                        const wxRect &rect,
                        int row,
                        int col,
                        bool isSelected)
{
    wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);

    wxGridTableBase *table = grid.GetTable();
    TimeEditor *te = (TimeEditor *) grid.GetCellEditor(row, col);
    wxString tstr;

    if (te) {
        double value;

        table->GetValue(row, col).ToDouble(&value);

        NumericTextCtrl tt(NumericConverter::TIME, &grid,
                           wxID_ANY,
                           te->GetFormat(),
                           value,
                           te->GetRate(),
                           wxPoint(10000, 10000),  // create offscreen
                           wxDefaultSize,
                           true);
        tstr = tt.GetString();

        te->DecRef();
    }

    dc.SetBackgroundMode(wxTRANSPARENT);

    if (grid.IsEnabled())
    {
        if (isSelected)
        {
            dc.SetTextBackground(grid.GetSelectionBackground());
            dc.SetTextForeground(grid.GetSelectionForeground());
        }
        else
        {
            dc.SetTextBackground(attr.GetBackgroundColour());
            dc.SetTextForeground(attr.GetTextColour());
        }
    }
    else
    {
        dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
        dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
    }

    dc.SetFont(attr.GetFont());

    int hAlign, vAlign;

    attr.GetAlignment(&hAlign, &vAlign);

    grid.DrawTextRectangle(dc, tstr, rect, hAlign, vAlign);
}
コード例 #13
0
ファイル: glyphcellrenderer.cpp プロジェクト: ampext/svgpath
void GlyphCellRenderer::Draw(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected)
{
	wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, false);

	wxString value = grid.GetTable()->GetValue(row, col);
	wxString label;

	auto it = glyphs.find(value);
	if (it == glyphs.end()) return;
	
	const SvgGlyph &glyph = it->second;

	if (!glyph.IsOk())
		return;

	if (showGlyphNames) label = glyph.glyphName;
	else label.Printf("%04x", glyph.unicode[0]);

	std::unique_ptr<wxGraphicsContext> gc(wxGraphicsContext::Create(static_cast<wxPaintDC&>(dc)));

	wxRect newRect = rect;

	// replace with gc->GetRenderer()->GetName() == L"cairo" after wx 3.1
	bool isCairo = false;

	#if wxUSE_CAIRO
		isCairo = true;
	#endif

	// Oh, crap
	if (isCairo)
	{
		newRect.x += dc.GetDeviceOrigin().x;
		newRect.y += dc.GetDeviceOrigin().y;
	}

	std::map<wxString, wxBitmap>::iterator findIt = glyphCache.find(glyph.unicode);

	if (findIt == glyphCache.end())
	{
		bool result;
		std::tie(findIt, result) = glyphCache.emplace(glyph.unicode, GetBitmapForGlyph(glyph, fontSize, glyphColor, attr.GetBackgroundColour(), false));

		if (!result) return;
	}

	if (hlCellCoords.GetCol() == col && hlCellCoords.GetRow() == row)
	{
		gc->SetPen(wxPen(hlColor, 1));
		gc->DrawRoundedRectangle(newRect.x + 1, newRect.y + 1, newRect.width - 2, newRect.height - 2, 5);
	}

	newRect.height -= labelFont.GetPixelSize().GetHeight() + 2 * padding;

	const wxBitmap &glyphBitmap = findIt->second;

	if (glyphBitmap.IsOk())
	{
		gc->DrawBitmap(glyphBitmap,
			newRect.x + (newRect.width - glyphBitmap.GetWidth()) / 2,
			newRect.y + (newRect.height - glyphBitmap.GetHeight()) / 2,
			glyphBitmap.GetWidth(), glyphBitmap.GetHeight());
	}

	double maxTextWidth = std::max(0, newRect.width - 2);
	double width, height, descent, externalLeading;

	gc->SetFont(labelFont, labelColor);
	gc->GetTextExtent(label, &width, &height, &descent, &externalLeading);

	wxString origLabel = label;
	size_t cutCntr = 1;

	while (width > maxTextWidth && !label.IsEmpty())
	{
		label = origLabel.Left(origLabel.Length() - cutCntr++) + L"\u2026";
		gc->GetTextExtent(label, &width, &height, &descent, &externalLeading);
	}

	gc->DrawText(label, newRect.x + (newRect.width - width) / 2, newRect.y + newRect.height + padding);
}
コード例 #14
0
ファイル: Grid.cpp プロジェクト: MindFy/audacity
void NumericRenderer::Draw(wxGrid &grid,
                        wxGridCellAttr &attr,
                        wxDC &dc,
                        const wxRect &rect,
                        int row,
                        int col,
                        bool isSelected)
{
   wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);

   wxGridTableBase *table = grid.GetTable();
   NumericEditor *ne =
      static_cast<NumericEditor *>(grid.GetCellEditor(row, col));
   wxString tstr;

   if (ne) {
      double value;

      table->GetValue(row, col).ToDouble(&value);

      NumericTextCtrl tt(&grid, wxID_ANY,
                      mType,
                      ne->GetFormat(),
                      value,
                      ne->GetRate(),
                      NumericTextCtrl::Options{}.AutoPos(true),
                      wxPoint(10000, 10000));  // create offscreen
      tstr = tt.GetString();

      ne->DecRef();
   }

   dc.SetBackgroundMode(wxTRANSPARENT);

   if (grid.IsEnabled())
   {
      if (isSelected)
      {
         dc.SetTextBackground(grid.GetSelectionBackground());
         dc.SetTextForeground(grid.GetSelectionForeground());
      }
      else
      {
         dc.SetTextBackground(attr.GetBackgroundColour());
         dc.SetTextForeground(attr.GetTextColour());
      }
   }
   else
   {
      dc.SetTextBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
      dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
   }

   dc.SetFont(attr.GetFont());

   int hAlign, vAlign;

   attr.GetAlignment(&hAlign, &vAlign);

   grid.DrawTextRectangle(dc, tstr, rect, hAlign, vAlign);
}