gridsel.cpp

来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C++ 代码 · 共 1,132 行 · 第 1/3 页

CPP
1,132
字号
      }
      case wxGrid::wxGridSelectRows:
      {
          if ( !m_grid->GetBatchCount() )
          {
              r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, 0 ),
                                             wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ) );
              ((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
          }

          wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
                                          wxEVT_GRID_RANGE_SELECT,
                                          m_grid,
                                          wxGridCellCoords( row, 0 ),
                                          wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ),
                                          false,
                                          ControlDown, ShiftDown,
                                          AltDown, MetaDown );
          m_grid->GetEventHandler()->ProcessEvent(gridEvt);
          break;
      }
      case wxGrid::wxGridSelectColumns:
      {
          if ( !m_grid->GetBatchCount() )
          {
              r = m_grid->BlockToDeviceRect( wxGridCellCoords( 0, col ),
                                             wxGridCellCoords( m_grid->GetNumberRows() - 1, col ) );
              ((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
          }

          wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
                                          wxEVT_GRID_RANGE_SELECT,
                                          m_grid,
                                          wxGridCellCoords( 0, col ),
                                          wxGridCellCoords( m_grid->GetNumberRows() - 1, col ),
                                          false,
                                          ControlDown, ShiftDown,
                                          AltDown, MetaDown );
          m_grid->GetEventHandler()->ProcessEvent(gridEvt);
          break;
      }
    }
}

void wxGridSelection::ClearSelection()
{
    size_t n;
    wxRect r;
    wxGridCellCoords coords1, coords2;

    // deselect all invidiual cells and update the screen
    if ( m_selectionMode == wxGrid::wxGridSelectCells )
    {
        while( ( n = m_cellSelection.GetCount() ) > 0)
        {
            n--;
            coords1 = m_cellSelection[n];
            m_cellSelection.RemoveAt(n);
            if ( !m_grid->GetBatchCount() )
            {
                r = m_grid->BlockToDeviceRect( coords1, coords1 );
                ((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
#ifdef __WXMAC__
                ((wxWindow *)m_grid->m_gridWin)->Update();
#endif
            }
        }
    }

    // deselect all blocks and update the screen
    while( ( n = m_blockSelectionTopLeft.GetCount() ) > 0)
    {
        n--;
        coords1 = m_blockSelectionTopLeft[n];
        coords2 = m_blockSelectionBottomRight[n];
        m_blockSelectionTopLeft.RemoveAt(n);
        m_blockSelectionBottomRight.RemoveAt(n);
        if ( !m_grid->GetBatchCount() )
        {
            r = m_grid->BlockToDeviceRect( coords1, coords2 );
            ((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
#ifdef __WXMAC__
            ((wxWindow *)m_grid->m_gridWin)->Update();
#endif
        }
    }

    // deselect all rows and update the screen
    if ( m_selectionMode != wxGrid::wxGridSelectColumns )
    {
        while( ( n = m_rowSelection.GetCount() ) > 0)
        {
            n--;
            int row = m_rowSelection[n];
            m_rowSelection.RemoveAt(n);
            if ( !m_grid->GetBatchCount() )
            {
                r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, 0 ),
                                               wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ) );
                ((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
#ifdef __WXMAC__
                ((wxWindow *)m_grid->m_gridWin)->Update();
#endif
            }
        }
    }

    // deselect all columns and update the screen
    if ( m_selectionMode != wxGrid::wxGridSelectRows )
    {
        while( ( n = m_colSelection.GetCount() ) > 0)
        {
            n--;
            int col = m_colSelection[n];
            m_colSelection.RemoveAt(n);
            if ( !m_grid->GetBatchCount() )
            {
                r = m_grid->BlockToDeviceRect( wxGridCellCoords( 0, col ),
                                               wxGridCellCoords( m_grid->GetNumberRows() - 1, col ) );
                ((wxWindow *)m_grid->m_gridWin)->Refresh( false, &r );
#ifdef __WXMAC__
                ((wxWindow *)m_grid->m_gridWin)->Update();
#endif
            }
        }
    }

    // One deselection event, indicating deselection of _all_ cells.
    // (No finer grained events for each of the smaller regions
    //  deselected above!)
    wxGridRangeSelectEvent gridEvt( m_grid->GetId(),
                                    wxEVT_GRID_RANGE_SELECT,
                                    m_grid,
                                    wxGridCellCoords( 0, 0 ),
                                    wxGridCellCoords( m_grid->GetNumberRows() - 1,
                                                      m_grid->GetNumberCols() - 1 ),
                                    false );

    m_grid->GetEventHandler()->ProcessEvent(gridEvt);
}


void wxGridSelection::UpdateRows( size_t pos, int numRows )
{
    size_t count = m_cellSelection.GetCount();
    size_t n;
    for ( n = 0; n < count; n++ )
    {
        wxGridCellCoords& coords = m_cellSelection[n];
        wxCoord row = coords.GetRow();
        if ((size_t)row >= pos)
        {
            if (numRows > 0)
            {
                // If rows inserted, increase row counter where necessary
                coords.SetRow(row + numRows);
            }
            else if (numRows < 0)
            {
                // If rows deleted ...
                if ((size_t)row >= pos - numRows)
                {
                    // ...either decrement row counter (if row still exists)...
                    coords.SetRow(row + numRows);
                }
                else
                {
                    // ...or remove the attribute
                    m_cellSelection.RemoveAt(n);
                    n--; count--;
                }
            }
        }
    }

    count = m_blockSelectionTopLeft.GetCount();
    for ( n = 0; n < count; n++ )
    {
        wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
        wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
        wxCoord row1 = coords1.GetRow();
        wxCoord row2 = coords2.GetRow();
        if ((size_t)row2 >= pos)
        {
            if (numRows > 0)
            {
                // If rows inserted, increase row counter where necessary
                coords2.SetRow(row2 + numRows);
                if ( (size_t)row1 >= pos )
                    coords1.SetRow(row1 + numRows);
            }
            else if (numRows < 0)
            {
                // If rows deleted ...
                if ((size_t)row2 >= pos - numRows)
                {
                    // ...either decrement row counter (if row still exists)...
                    coords2.SetRow(row2 + numRows);
                    if ( (size_t) row1 >= pos)
                        coords1.SetRow( wxMax(row1 + numRows, (int) pos) );

                }
                else
                {
                    if ( (size_t) row1 >= pos)
                    {
                        // ...or remove the attribute
                        m_blockSelectionTopLeft.RemoveAt(n);
                        m_blockSelectionBottomRight.RemoveAt(n);
                        n--; count--;
                    }
                    else
                        coords2.SetRow(pos);
                }
            }
        }
    }

    count = m_rowSelection.GetCount();
    for ( n = 0; n < count; n++ )
    {
    int  rowOrCol_ = m_rowSelection [ n ];

      if ( ( size_t ) rowOrCol_ >= pos )
      {
          if ( numRows > 0 )
          {
              m_rowSelection [ n ] += numRows;
          }
          else if ( numRows < 0 )
          {
              if ( ( size_t ) rowOrCol_ >= ( pos - numRows ) )
                  m_rowSelection [ n ] += numRows;
              else
              {
                  m_rowSelection.RemoveAt ( n );
                  n--;
                  count--;
              }
          }
      }
    }
    // No need to touch selected columns, unless we removed _all_
    // rows, in this case, we remove all columns from the selection.

    if ( !m_grid->GetNumberRows() )
        m_colSelection.Clear();
}


void wxGridSelection::UpdateCols( size_t pos, int numCols )
{
    size_t count = m_cellSelection.GetCount();
    size_t n;
    for ( n = 0; n < count; n++ )
    {
        wxGridCellCoords& coords = m_cellSelection[n];
        wxCoord col = coords.GetCol();
        if ((size_t)col >= pos)
        {
            if (numCols > 0)
            {
                // If rows inserted, increase row counter where necessary
                coords.SetCol(col + numCols);
            }
            else if (numCols < 0)
            {
                // If rows deleted ...
                if ((size_t)col >= pos - numCols)
                {
                    // ...either decrement row counter (if row still exists)...
                    coords.SetCol(col + numCols);
                }
                else
                {
                    // ...or remove the attribute
                    m_cellSelection.RemoveAt(n);
                    n--; count--;
                }
            }
        }
    }

    count = m_blockSelectionTopLeft.GetCount();
    for ( n = 0; n < count; n++ )
    {
        wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
        wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
        wxCoord col1 = coords1.GetCol();
        wxCoord col2 = coords2.GetCol();
        if ((size_t)col2 >= pos)
        {
            if (numCols > 0)
            {
                // If rows inserted, increase row counter where necessary
                coords2.SetCol(col2 + numCols);
                if ( (size_t)col1 >= pos )
                    coords1.SetCol(col1 + numCols);
            }
            else if (numCols < 0)
            {
                // If cols deleted ...
                if ((size_t)col2 >= pos - numCols)
                {
                    // ...either decrement col counter (if col still exists)...
                    coords2.SetCol(col2 + numCols);
                    if ( (size_t) col1 >= pos)
                        coords1.SetCol( wxMax(col1 + numCols, (int) pos) );

                }
                else
                {
                    if ( (size_t) col1 >= pos)
                    {
                        // ...or remove the attribute
                        m_blockSelectionTopLeft.RemoveAt(n);
                        m_blockSelectionBottomRight.RemoveAt(n);
                        n--; count--;
                    }
                    else
                        coords2.SetCol(pos);
                }
            }
        }
    }

    count = m_colSelection.GetCount();
    for ( n = 0; n < count; n++ )
    {

      int   rowOrCol = m_colSelection [ n ];
        if ( ( size_t ) rowOrCol >= pos )
        {
            if ( numCols > 0 )
                m_colSelection [ n ] += numCols;
            else if ( numCols < 0 )
            {
                if ( ( size_t ) rowOrCol >= ( pos -numCols ) )
                    m_colSelection [ n ] += numCols;
                else
                {
                    m_colSelection.RemoveAt ( n );
                    n--;
                    count--;
                }
            }
        }

    }

    // No need to touch selected rows, unless we removed _all_
    // columns, in this case, we remove all rows from the selection.
    if ( !m_grid->GetNumberCols() )
        m_rowSelection.Clear();
}


int wxGridSelection::BlockContain( int topRow1, int leftCol1,
                                   int bottomRow1, int rightCol1,
                                   int topRow2, int leftCol2,
                                   int bottomRow2, int rightCol2 )
// returns 1, if Block1 contains Block2,
//        -1, if Block2 contains Block1,
//         0, otherwise
{
    if ( topRow1 <= topRow2 && bottomRow2 <= bottomRow1 &&
         leftCol1 <= leftCol2 && rightCol2 <= rightCol1 )
        return 1;
    else if ( topRow2 <= topRow1 && bottomRow1 <= bottomRow2 &&
              leftCol2 <= leftCol1 && rightCol1 <= rightCol2 )
        return -1;
    return 0;
}

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?