Пример #1
0
void wxSheetValueProviderSparseStringTest::SetValue( const wxSheetCoords& coords_,
                                                     const wxString& value )
{
    wxCHECK_RET(ContainsCell(coords_), wxT("Invalid coords"));
    wxSheetCoords coords(HasOption(wxSHEET_ValueProviderColPref) ? coords_ : coords_.GetSwapped());

    m_intArrayIntString.m_key = coords.m_row;
    const int rowPos = m_data.Index(&m_intArrayIntString);
    //const int rowPos = m_data.Index(wxSheetIntArrayIntString(coords.m_row));

    if (value.IsEmpty())
    {
        // remove the value if empty
        if (rowPos != wxNOT_FOUND)
        {
            m_data[rowPos].m_value->Remove(wxSheetIntString(coords.m_col));
            // remove this row if empty
            if (m_data[rowPos].m_value->GetCount() == 0)
                m_data.RemoveAt(rowPos);
        }
    }
    else
    {
        if (rowPos == wxNOT_FOUND)
        {
            //m_intArrayIntString.m_key = coords.m_row;
            //m_intArrayIntString.m_value = wxSheetIntStringSortedObjArray(wxSheetIntString(coords.m_col, value));
            //m_intArrayIntString.m_value.Add(new wxSheetIntString(coords.m_col, value));
            //m_data.Add(m_intArrayIntString);
            m_data.Add(new wxSheetIntArrayIntString(coords.m_row, new wxSheetIntStringSortedObjArray(new wxSheetIntString(coords.m_col, value))));
        }
        else
            m_data[rowPos].m_value->Add(new wxSheetIntString(coords.m_col, value));
    }
}
Пример #2
0
void wxSheetValueProviderSparseString::SetValue( const wxSheetCoords& coords_,
                                                 const wxString& value )
{
    wxCHECK_RET(ContainsCell(coords_), wxT("Invalid coords"));
    wxSheetCoords coords(HasOption(wxSHEET_ValueProviderColPref) ? coords_ : coords_.GetSwapped());
    const int rowPos = m_data.Index(coords.m_row);

    if (!HasOption(wxSHEET_ValueProviderAllowEmpty) && value.IsEmpty())
    {
        // remove the value if empty
        if (rowPos != wxNOT_FOUND)
        {
            m_data.ItemValue(rowPos).Remove(coords.m_col);
            // remove this row if empty
            if (m_data.ItemValue(rowPos).GetCount() == 0)
                m_data.RemoveAt(rowPos);
        }
    }
    else
    {
        if (rowPos == wxNOT_FOUND)
            m_data.GetOrCreateValue(coords.m_row).Add(coords.m_col, value);
        else
            m_data.ItemValue(rowPos).Add(coords.m_col, value);
    }
}
Пример #3
0
bool wxSheetValueProviderSparseStringTest::HasValue( const wxSheetCoords& coords_ ) const
{
    wxCHECK_MSG(ContainsCell(coords_), false, wxT("Invalid coords"));
    wxSheetCoords coords(HasOption(wxSHEET_ValueProviderColPref) ? coords_ : coords_.GetSwapped());
    const int rowPos = m_data.Index(wxSheetIntArrayIntString(coords.m_row));
    if (rowPos == wxNOT_FOUND)
        return false;

    return m_data[rowPos].m_value->Index(wxSheetIntString(coords.m_col)) != wxNOT_FOUND;
}
Пример #4
0
wxString wxSheetValueProviderSparseString::GetValue( const wxSheetCoords& coords_ ) const
{
    wxCHECK_MSG(ContainsCell(coords_), wxEmptyString, wxT("Invalid coords"));
    wxSheetCoords coords(HasOption(wxSHEET_ValueProviderColPref) ? coords_ : coords_.GetSwapped());

    const int rowPos = m_data.Index(coords.m_row);
    if (rowPos != wxNOT_FOUND)
        return m_data.ItemValue(rowPos).GetValue(coords.m_col);

    return wxEmptyString;
}
Пример #5
0
wxString wxSheetValueProviderString::GetValue( const wxSheetCoords& coords_ ) const
{
    wxCHECK_MSG(ContainsCell(coords_), wxEmptyString, wxT("Invalid coords"));
    wxSheetCoords coords(HasOption(wxSHEET_ValueProviderColPref) ? coords_ : coords_.GetSwapped());

    //wxPrintf(wxT("RC %d %d - NumRC %d %d DataRC %d %d '%s'\n"), coords_.m_row, coords_.m_col, m_numRows, m_numCols,
    //    m_data.GetCount(), int(m_data.GetCount()) > coords.m_col ? m_data[coords.m_col].GetCount() : 0,
    //    wxDateTime::Now().FormatISOTime().c_str());

    if ((int(m_data.GetCount()) > coords.m_row) &&
        (int(m_data[coords.m_row].GetCount()) > coords.m_col))
        return m_data[coords.m_row][coords.m_col];

    return wxEmptyString;
}
Пример #6
0
wxString wxSheetValueProviderSparseStringTest::GetValue( const wxSheetCoords& coords_ ) const
{
    wxCHECK_MSG(ContainsCell(coords_), wxEmptyString, wxT("Invalid coords"));
    wxSheetCoords coords(HasOption(wxSHEET_ValueProviderColPref) ? coords_ : coords_.GetSwapped());

    ((wxSheetValueProviderSparseStringTest*)this)->m_intArrayIntString.m_key = coords.m_row;
    const int rowPos = m_data.Index((wxSheetIntArrayIntString*)&m_intArrayIntString);
//    const int rowPos = m_data.Index(wxSheetIntArrayIntString(coords.m_row));

    if (rowPos != wxNOT_FOUND)
    {
        ((wxSheetValueProviderSparseStringTest*)this)->m_intString.m_key = coords.m_col;
        const int colPos = m_data[rowPos].m_value->Index((wxSheetIntString*)&m_intString);
        //const int colPos = m_data[rowPos].m_value.Index(wxSheetIntString(coords.m_col));
        if (colPos != wxNOT_FOUND)
            return m_data[rowPos].m_value->Item(colPos).m_value;
    }

    return wxEmptyString;
}
Пример #7
0
void wxSheetValueProviderString::SetValue( const wxSheetCoords& coords_, const wxString& value )
{
    wxCHECK_RET(ContainsCell(coords_), wxT("Invalid coords"));
    wxSheetCoords coords(HasOption(wxSHEET_ValueProviderColPref) ? coords_ : coords_.GetSwapped());

    // add "rows" as necessary to store value
    int count = m_data.GetCount();
    if (count <= coords.m_row)
    {
        wxArrayString sa;
        sa.Add( wxEmptyString, 1+coords.m_col );
        m_data.Insert( sa, count, 1+coords.m_row-count );
    }
    else // believe it or not - NOT having this else statement is 10% faster in gcc
    {
        // add "cols" as necessary to store value
        count = m_data[coords.m_row].GetCount();
        if (count <= coords.m_col)
        {
            m_data.Item(coords.m_row).Insert( wxEmptyString, count, 1+coords.m_col-count );
        }
    }
    m_data[coords.m_row][coords.m_col] = value;
}
Пример #8
0
wxSize wxSheetCellAutoWrapStringRendererRefData::GetBestSize(wxSheet& sheet,
        const wxSheetCellAttr& attr,
        wxDC& dc,
        const wxSheetCoords& coords)
{
    wxCoord x, y, height, width = sheet.GetColWidth(coords.GetCol()) -10;
    int count = 250; //Limit iterations..

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

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

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

    return wxSize(width, height);
}
Пример #9
0
// ----------------------------------------------------------------------------
// wxSheetCellAttrProvider
// ----------------------------------------------------------------------------
wxSheetCellAttr wxSheetCellAttrProvider::GetAttr(const wxSheetCoords& coords,
                                                 wxSheetAttr_Type type )
{   
    switch (wxSheet::GetCellCoordsType(coords))
    {
        case wxSHEET_CELL_GRID :
        {
            switch (type)
            {
                case wxSHEET_AttrAny:
                {
                    wxSheetCellAttr attrCell(m_cellAttrs.GetValue(coords));
                    wxSheetCellAttr attrRow(m_rowAttrs.GetValue(coords.GetRow()));
                    wxSheetCellAttr attrCol(m_colAttrs.GetValue(coords.GetCol()));

                    // points system, greater the level you get added last
                    // if two levels match use ordering col, row, cell on top.
                    wxPairArrayIntSheetCellAttr data;
                    if (attrCol.Ok())  data.SetValue(attrCol.GetLevel()+2, attrCol);
                    if (attrRow.Ok())  data.SetValue(attrRow.GetLevel()+1, attrRow);
                    if (attrCell.Ok()) data.SetValue(attrCell.GetLevel()+0, attrCell);

                    // the attr are sorted from low priority to high
                    const int count = data.GetCount();

                    switch (count)
                    {
                        case 0  : return wxNullSheetCellAttr;
                        case 1  : return data.GetItemValue(0);
                        default : break;
                    }

                    // This is the preferred way - link them together
                    // but you must make sure that it doesn't loop
                    // see check in wxSheetCellAttr::SetDefaultAttr
                    wxSheetCellAttr attr;
                    attr.Copy(data.GetItemValue(0));
                    attr.SetDefaultAttr(data.GetItemValue(1));
                    if (count > 2)
                        data.GetItemValue(1).SetDefaultAttr(data.GetItemValue(2));
/*
                    // This is the old way of copying the values to a single attr
                    wxSheetCellAttr attr;
                    attr.Copy(data.GetItemValue(0));
                    attr.MergeWith(data.GetItemValue(1));
                    if (count > 2)
                       attr.MergeWith(data.GetItemValue(2));
*/
                    // This is not a "real" attr but created
                    attr.SetKind(wxSHEET_AttrAny);
                    
                    return attr;
                }
                case wxSHEET_AttrCell : return m_cellAttrs.GetValue(coords);
                case wxSHEET_AttrRow  : return m_rowAttrs.GetValue(coords.GetRow());
                case wxSHEET_AttrCol  : return m_colAttrs.GetValue(coords.GetCol());
                default:
                    // unused as yet...
                    // (wxSheetCellAttr::Default):
                    // (wxSheetCellAttr::Merged):
                    break;
            }
            break;
        }
        case wxSHEET_CELL_ROWLABEL : return m_rowLabelAttrs.GetValue(coords.m_row);
        case wxSHEET_CELL_COLLABEL : return m_colLabelAttrs.GetValue(coords.m_col);
        default :
            wxFAIL_MSG(wxString::Format(wxT("Unhandled coords (%d, %d) in wxSheetCellAttrProvider::GetAttr"), coords.m_row, coords.m_col));
            break;
    }

    return wxNullSheetCellAttr;
}
Пример #10
0
void wxSheetCellStringRendererRefData::DoDraw(wxSheet& sheet,
        const wxSheetCellAttr& attr,
        wxDC& dc,
        const wxRect& rectCell,
        const wxSheetCoords& coords,
        bool isSelected)
{
    wxRect rect = rectCell;
    rect.Inflate(-1);

    int align = attr.GetAlignment();
    int orient = attr.GetOrientation();

    wxString value( sheet.GetCellValue(coords) );
    int best_width = DoGetBestSize(sheet, attr, dc, value).GetWidth();
    wxSheetCoords cellSpan(sheet.GetCellSpan(coords)); // shouldn't get here if <=0
    int cell_rows = cellSpan.m_row;
    int cell_cols = cellSpan.m_col;

    bool is_grid_cell = coords.IsGridCell();
    // no overflow for row/col/corner labels
    bool overflow = is_grid_cell && (orient == wxSHEET_AttrOrientHoriz) ? attr.GetOverflow() : false;
    int overflowCols = 0;
    int num_cols = sheet.GetNumberCols();
    // this is the right col which includes overflow
    int rightCol = coords.m_col + cell_cols - 1;

    // Check if this cell should overflow to right and for how many cells
    if (overflow)
    {
        bool is_editing = sheet.IsCellEditControlShown();
        wxSheetCoords editorCell = is_editing ? sheet.GetEditControlCoords() : wxNullSheetCoords;
        int row = coords.GetRow(), col = coords.GetCol();
        wxSheetCoords ownerCell;
        if ((best_width > rectCell.width) && (col < num_cols-1) && sheet.GetTable())
        {
            wxSheetCoords cell;
            for (cell.m_col = col+cell_cols; cell.m_col < num_cols; cell.m_col++)
            {
                bool is_empty = true;
                for (cell.m_row = row; cell.m_row < row+cell_rows; cell.m_row++)
                {
                    // check w/ anchor cell for spanned cell block
                    ownerCell = sheet.GetCellOwner(cell);
                    if ( sheet.GetTable()->HasValue(ownerCell) ||
                            (ownerCell == editorCell) )
                    {
                        is_empty = false;
                        break;
                    }
                }

                if (is_empty)
                    rect.width += sheet.GetColWidth(cell.m_col);
                else
                {
                    cell.m_col--;
                    break;
                }

                if (rect.width >= best_width)
                    break;
            }
            // this may extend out of sheet
            overflowCols = cell.m_col - col - cell_cols + 1;
            rightCol = wxMin(coords.m_col+cell_cols-1+overflowCols, num_cols - 1);
        }

        // redraw overflow cells individually for proper selection hilight
        if (overflowCols > 0)
        {
            // if overflowed then it's left aligned (yes I know ALIGN_LEFT=0)
            align &= ~wxSHEET_AttrAlignHoriz_Mask;
            align |= wxSHEET_AttrAlignLeft;

            wxRect clip(rect);
            clip.x += rectCell.width;

            int col_width;
            wxSheetCoords cell(coords);
            // draw each cell individually since it may be selected or not
            for (cell.m_col = col+cell_cols; cell.m_col <= rightCol; cell.m_col++)
            {
                col_width = sheet.GetColWidth(cell.m_col);
                clip.width = col_width - 1;
                dc.DestroyClippingRegion();
                dc.SetClippingRegion(clip);
                SetTextColoursAndFont(sheet, attr, dc, sheet.IsCellSelected(cell));
                sheet.DrawTextRectangle(dc, value, rect, align, orient);
                clip.x += col_width - 1;
            }

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

    // Draw the text
    SetTextColoursAndFont(sheet, attr, dc, isSelected);
    sheet.DrawTextRectangle(dc, value, rect, align, orient);

    if (attr.GetOverflowMarker())
    {
        // Draw a marker to show that the contents has been clipped off
        int cellRight = sheet.GetColRight(rightCol);
        if (cellRight - rect.x < best_width)
        {
            int bmpWidth   = s_overflowBitmap.GetWidth();
            int bmpHeight  = s_overflowBitmap.GetHeight();
            int cellWidth  = sheet.GetColWidth(rightCol);
            int cellHeight = sheet.GetRowHeight(coords.m_row);

            if ((bmpWidth < cellWidth-3) && (bmpHeight < cellHeight-3))
            {
                int cellTop = sheet.GetRowTop(coords.m_row);

                int x = cellRight - bmpWidth - 2;
                int y = cellTop + (cellHeight - bmpHeight)/2;
                wxRect r(x-2, cellTop, bmpWidth+4-1, cellHeight-1);
                wxSheetCellAttr rightAttr(attr);
                if (overflowCols > 0)
                {
                    wxSheetCoords clipCell(coords.m_row, rightCol);
                    isSelected = sheet.IsCellSelected(clipCell);
                    rightAttr = sheet.GetAttr(clipCell);
                }

                // clear background for bitmap
                wxSheetCellRendererRefData::Draw(sheet, rightAttr, dc, r, coords, isSelected);
                dc.DrawBitmap( s_overflowBitmap, x, y, true );
            }
        }
    }
}