]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
fixed typo : _ instead of wxT
[wxWidgets.git] / src / generic / grid.cpp
index 1fd565857ee09cb032b1a49cca2a72b77160127f..4a3a28cce051a4c579aad4616e23776020fd99e2 100644 (file)
@@ -52,6 +52,9 @@
 #include "wx/grid.h"
 #include "wx/generic/gridsel.h"
 
+// Required for wxIs... functions
+#include <ctype.h>
+
 // ----------------------------------------------------------------------------
 // array classes
 // ----------------------------------------------------------------------------
@@ -2453,12 +2456,12 @@ wxGridStringTable::~wxGridStringTable()
 {
 }
 
-long wxGridStringTable::GetNumberRows()
+int wxGridStringTable::GetNumberRows()
 {
     return m_data.GetCount();
 }
 
-long wxGridStringTable::GetNumberCols()
+int wxGridStringTable::GetNumberCols()
 {
     if ( m_data.GetCount() > 0 )
         return m_data[0].GetCount();
@@ -3800,10 +3803,13 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
                 break;
 
                 case WXGRID_CURSOR_SELECT_ROW:
-                    if ( (row = YToRow( y )) >= 0  &&
-                         !IsInSelection( row, 0 ) )
-                    {
-                        SelectRow( row, TRUE );
+                    if ( (row = YToRow( y )) >= 0 )
+                   {
+                       m_selection->SelectRow( row,
+                                               event.ControlDown(),
+                                               event.ShiftDown(),
+                                               event.AltDown(),
+                                               event.MetaDown() );
                     }
 
                 // default label to suppress warnings about "enumeration value
@@ -3840,7 +3846,23 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
             if ( row >= 0  &&
                  !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) )
             {
-                SelectRow( row, event.ShiftDown() );
+               if ( !event.ShiftDown() && !event.ControlDown() )
+                   ClearSelection();
+               if ( event.ShiftDown() )
+                   m_selection->SelectBlock( m_currentCellCoords.GetRow(),
+                                             0,
+                                             row,
+                                             GetNumberCols() - 1,
+                                             event.ControlDown(),
+                                             event.ShiftDown(),
+                                             event.AltDown(),
+                                             event.MetaDown() );
+               else
+                   m_selection->SelectRow( row,
+                                           event.ControlDown(),
+                                           event.ShiftDown(),
+                                           event.AltDown(),
+                                           event.MetaDown() );
                 ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW, m_rowLabelWin);
             }
         }
@@ -3967,10 +3989,13 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
                 break;
 
                 case WXGRID_CURSOR_SELECT_COL:
-                    if ( (col = XToCol( x )) >= 0  &&
-                         !IsInSelection( 0, col ) )
-                    {
-                        SelectCol( col, TRUE );
+                    if ( (col = XToCol( x )) >= 0 )
+                   {
+                       m_selection->SelectCol( col,
+                                               event.ControlDown(),
+                                               event.ShiftDown(),
+                                               event.AltDown(),
+                                               event.MetaDown() );
                     }
 
                 // default label to suppress warnings about "enumeration value
@@ -4007,7 +4032,22 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
             if ( col >= 0  &&
                  !SendEvent( wxEVT_GRID_LABEL_LEFT_CLICK, -1, col, event ) )
             {
-                SelectCol( col, event.ShiftDown() );
+               if ( !event.ShiftDown() && !event.ControlDown() )
+                   ClearSelection();
+               if ( event.ShiftDown() )
+                   m_selection->SelectBlock( 0,
+                                             m_currentCellCoords.GetCol(),
+                                             GetNumberRows() - 1, col,
+                                             event.ControlDown(),
+                                             event.ShiftDown(),
+                                             event.AltDown(),
+                                             event.MetaDown() );
+               else
+                   m_selection->SelectCol( col,
+                                           event.ControlDown(),
+                                           event.ShiftDown(),
+                                           event.AltDown(),
+                                           event.MetaDown() );
                 ChangeCursorMode(WXGRID_CURSOR_SELECT_COL, m_colLabelWin);
             }
         }
@@ -4243,20 +4283,29 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
 
             if ( coords != wxGridNoCellCoords )
             {
-                if ( !IsSelection() )
-                {
-                    SelectBlock( coords, coords );
-                }
-                else
-                {
-                    SelectBlock( m_currentCellCoords, coords );
+               if ( event.ControlDown() )
+               {
+                   if ( m_selectingKeyboard == wxGridNoCellCoords)
+                       m_selectingKeyboard = coords;
+                   SelectBlock ( m_selectingKeyboard, coords );
+               }
+               else
+               {
+                   if ( !IsSelection() )
+                   {
+                       SelectBlock( coords, coords );
+                   }
+                   else
+                   {
+                       SelectBlock( m_currentCellCoords, coords );
+                   }
                 }
 
                 if (! IsVisible(coords))
                 {
                     MakeCellVisible(coords);
                     // TODO: need to introduce a delay or something here.  The
-                    // scrolling is way to fast, at least on MSW.
+                    // scrolling is way to fast, at least on MSW - also on GTK.
                 }
             }
         }
@@ -4363,15 +4412,20 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
                 }
                 else
                 {
-                    m_selection->ToggleCellSelection( coords.GetRow(),
-                                                      coords.GetCol(),
-                                                      event.ControlDown(),
-                                                      event.ShiftDown(),
-                                                      event.AltDown(),
-                                                      event.MetaDown() );
-                    m_selectingTopLeft = wxGridNoCellCoords;
-                    m_selectingBottomRight = wxGridNoCellCoords;
-                    SetCurrentCell( coords );
+                   if ( event.ControlDown() )
+                   {
+                       m_selection->ToggleCellSelection( coords.GetRow(),
+                                                         coords.GetCol(),
+                                                         event.ControlDown(),
+                                                         event.ShiftDown(),
+                                                         event.AltDown(),
+                                                         event.MetaDown() );
+                       m_selectingTopLeft = wxGridNoCellCoords;
+                       m_selectingBottomRight = wxGridNoCellCoords;
+                       m_selectingKeyboard = coords;
+                   }
+                   else
+                       SetCurrentCell( coords );
                     m_waitForSlowClick = TRUE;
                 }
             }
@@ -4932,8 +4986,8 @@ bool wxGrid::SendEvent( const wxEventType type,
                              type,
                              this,
                              row, col,
-                             FALSE,
                              mouseEv.GetX(), mouseEv.GetY(),
+                             FALSE,
                              mouseEv.ControlDown(),
                              mouseEv.ShiftDown(),
                              mouseEv.AltDown(),
@@ -5015,14 +5069,16 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
         if ( !event.ShiftDown() && 
              m_selectingKeyboard != wxGridNoCellCoords )
         {
-            m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
-                                      m_selectingTopLeft.GetCol(),
-                                      m_selectingBottomRight.GetRow(),
-                                      m_selectingBottomRight.GetCol(),
-                                      event.ControlDown(),
-                                      event.ShiftDown(),
-                                      event.AltDown(),
-                                      event.MetaDown() );
+           if ( m_selectingTopLeft != wxGridNoCellCoords &&
+                m_selectingBottomRight != wxGridNoCellCoords )
+               m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
+                                         m_selectingTopLeft.GetCol(),
+                                         m_selectingBottomRight.GetRow(),
+                                         m_selectingBottomRight.GetCol(),
+                                         event.ControlDown(),
+                                         event.ShiftDown(),
+                                         event.AltDown(),
+                                         event.MetaDown() );
             m_selectingTopLeft = wxGridNoCellCoords;
             m_selectingBottomRight = wxGridNoCellCoords;
             m_selectingKeyboard = wxGridNoCellCoords;
@@ -5086,7 +5142,7 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
                 break;
 
             case WXK_ESCAPE:
-                m_selection->ClearSelection();
+                ClearSelection();
                 break;
 
             case WXK_TAB:
@@ -5128,24 +5184,23 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
                 MovePageDown();
                 break;
 
-#if 1
             case WXK_SPACE:
+               if ( event.ControlDown() )
+               {
+                   m_selection->ToggleCellSelection( m_currentCellCoords.GetRow(),
+                                                     m_currentCellCoords.GetCol(),
+                                                     event.ControlDown(),
+                                                     event.ShiftDown(),
+                                                     event.AltDown(),
+                                                     event.MetaDown() );
+                   break;
+               }
                 if ( !IsEditable() )
                 {
                     MoveCursorRight( FALSE );
                     break;
                 }
                 // Otherwise fall through to default
-#else
-            case WXK_SPACE:
-                m_selection->ToggleCellSelection( m_currentCellCoords.GetRow(),
-                                                  m_currentCellCoords.GetCol(),
-                                                  event.ControlDown(),
-                                                  event.ShiftDown(),
-                                                  event.AltDown(),
-                                                  event.MetaDown() );
-                break;
-#endif
 
             default:
                 // alphanumeric keys or F2 (special key just for this) enable
@@ -6161,18 +6216,23 @@ bool wxGrid::MoveCursorUp( bool expandSelection )
     if ( m_currentCellCoords != wxGridNoCellCoords  &&
          m_currentCellCoords.GetRow() > 0 )
     {
-        MakeCellVisible( m_currentCellCoords.GetRow() - 1,
-                         m_currentCellCoords.GetCol() );
         if ( expandSelection )
         {
             if ( m_selectingKeyboard == wxGridNoCellCoords )
                 m_selectingKeyboard = m_currentCellCoords;
             m_selectingKeyboard.SetRow( m_selectingKeyboard.GetRow() - 1 );
+           MakeCellVisible( m_selectingKeyboard.GetRow(),
+                            m_selectingKeyboard.GetCol() );
             SelectBlock( m_currentCellCoords, m_selectingKeyboard );
         }
         else
+       {
+           ClearSelection();
+           MakeCellVisible( m_currentCellCoords.GetRow() - 1,
+                            m_currentCellCoords.GetCol() );
             SetCurrentCell( m_currentCellCoords.GetRow() - 1,
                             m_currentCellCoords.GetCol() );
+       }
         return TRUE;
     }
 
@@ -6185,18 +6245,23 @@ bool wxGrid::MoveCursorDown( bool expandSelection )
     if ( m_currentCellCoords != wxGridNoCellCoords  &&
          m_currentCellCoords.GetRow() < m_numRows-1 )
     {
-        MakeCellVisible( m_currentCellCoords.GetRow() + 1,
-                         m_currentCellCoords.GetCol() );
         if ( expandSelection )
         {
             if ( m_selectingKeyboard == wxGridNoCellCoords )
                 m_selectingKeyboard = m_currentCellCoords;
             m_selectingKeyboard.SetRow( m_selectingKeyboard.GetRow() + 1 );
+           MakeCellVisible( m_selectingKeyboard.GetRow(),
+                            m_selectingKeyboard.GetCol() );
             SelectBlock( m_currentCellCoords, m_selectingKeyboard );
         }
         else
+       {
+           ClearSelection();
+           MakeCellVisible( m_currentCellCoords.GetRow() + 1,
+                            m_currentCellCoords.GetCol() );
             SetCurrentCell( m_currentCellCoords.GetRow() + 1,
                             m_currentCellCoords.GetCol() );
+       }
         return TRUE;
     }
 
@@ -6209,18 +6274,23 @@ bool wxGrid::MoveCursorLeft( bool expandSelection )
     if ( m_currentCellCoords != wxGridNoCellCoords  &&
          m_currentCellCoords.GetCol() > 0 )
     {
-        MakeCellVisible( m_currentCellCoords.GetRow(),
-                         m_currentCellCoords.GetCol() - 1 );
         if ( expandSelection )
         {
             if ( m_selectingKeyboard == wxGridNoCellCoords )
                 m_selectingKeyboard = m_currentCellCoords;
             m_selectingKeyboard.SetCol( m_selectingKeyboard.GetCol() - 1 );
+           MakeCellVisible( m_selectingKeyboard.GetRow(),
+                            m_selectingKeyboard.GetCol() );
             SelectBlock( m_currentCellCoords, m_selectingKeyboard );
         }
         else
+       {
+           ClearSelection();
+           MakeCellVisible( m_currentCellCoords.GetRow(),
+                            m_currentCellCoords.GetCol() - 1 );
             SetCurrentCell( m_currentCellCoords.GetRow(),
                             m_currentCellCoords.GetCol() - 1 );
+       }
         return TRUE;
     }
 
@@ -6233,19 +6303,23 @@ bool wxGrid::MoveCursorRight( bool expandSelection )
     if ( m_currentCellCoords != wxGridNoCellCoords  &&
          m_currentCellCoords.GetCol() < m_numCols - 1 )
     {
-        MakeCellVisible( m_currentCellCoords.GetRow(),
-                        m_currentCellCoords.GetCol() + 1 );
-
         if ( expandSelection )
         {
             if ( m_selectingKeyboard == wxGridNoCellCoords )
                 m_selectingKeyboard = m_currentCellCoords;
             m_selectingKeyboard.SetCol( m_selectingKeyboard.GetCol() + 1 );
+           MakeCellVisible( m_selectingKeyboard.GetRow(),
+                            m_selectingKeyboard.GetCol() );
             SelectBlock( m_currentCellCoords, m_selectingKeyboard );
         }
         else
-            SetCurrentCell( m_currentCellCoords.GetRow(),
+       {
+           ClearSelection();
+           MakeCellVisible( m_currentCellCoords.GetRow(),
+                            m_currentCellCoords.GetCol() + 1 );
+           SetCurrentCell( m_currentCellCoords.GetRow(),
                             m_currentCellCoords.GetCol() + 1 );
+       }
         return TRUE;
     }
 
@@ -6366,8 +6440,10 @@ bool wxGrid::MoveCursorUpBlock( bool expandSelection )
             SelectBlock( m_currentCellCoords, m_selectingKeyboard );
         }
         else
-            SetCurrentCell( row, col );
-
+       {
+           ClearSelection();
+           SetCurrentCell( row, col );
+       }
         return TRUE;
     }
 
@@ -6427,7 +6503,10 @@ bool wxGrid::MoveCursorDownBlock( bool expandSelection )
             SelectBlock( m_currentCellCoords, m_selectingKeyboard );
         }
         else
-            SetCurrentCell( row, col );
+       {
+           ClearSelection();
+           SetCurrentCell( row, col );
+       }
 
         return TRUE;
     }
@@ -6488,7 +6567,10 @@ bool wxGrid::MoveCursorLeftBlock( bool expandSelection )
             SelectBlock( m_currentCellCoords, m_selectingKeyboard );
         }
         else
-            SetCurrentCell( row, col );
+       {
+           ClearSelection();
+           SetCurrentCell( row, col );
+       }
 
         return TRUE;
     }
@@ -6549,7 +6631,10 @@ bool wxGrid::MoveCursorRightBlock( bool expandSelection )
             SelectBlock( m_currentCellCoords, m_selectingKeyboard );
         }
         else
-            SetCurrentCell( row, col );
+       {
+           ClearSelection();
+           SetCurrentCell( row, col );
+       }
 
         return TRUE;
     }
@@ -7537,7 +7622,7 @@ void wxGrid::SetCellValue( int row, int col, const wxString& s )
 void wxGrid::SelectRow( int row, bool addToSelected )
 {
     if ( IsSelection() && !addToSelected )
-        m_selection->ClearSelection();
+        ClearSelection();
 
     m_selection->SelectRow( row );
 }
@@ -7546,7 +7631,7 @@ void wxGrid::SelectRow( int row, bool addToSelected )
 void wxGrid::SelectCol( int col, bool addToSelected )
 {
     if ( IsSelection() && !addToSelected )
-        m_selection->ClearSelection();
+        ClearSelection();
 
     m_selection->SelectCol( col );
 }