]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
Module definitions files for build VisualAge C++ V3.0 dlls.
[wxWidgets.git] / src / generic / grid.cpp
index 7481b5c2a72c9046bcd1b2bebe4281cd82704dbc..792b92b12c5734497ec32fbce7abd78e0198efc5 100644 (file)
@@ -3090,7 +3090,6 @@ wxGrid::~wxGrid()
 void wxGrid::Create()
 {
     m_created = FALSE;    // set to TRUE by CreateGrid
-    m_displayed = TRUE; // FALSE;  // set to TRUE by OnPaint
 
     m_table        = (wxGridTableBase *) NULL;
     m_ownTable     = FALSE;
@@ -3191,7 +3190,7 @@ bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership,
         // View at runtime.  Is there anything in the implmentation that would
         // prevent this?
 
-        // At least, you now have to copy with m_selection
+        // At least, you now have to cope with m_selection
         wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
         return FALSE;
     }
@@ -4244,13 +4243,22 @@ 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))
@@ -4327,7 +4335,11 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
             m_selection->SelectBlock( m_currentCellCoords.GetRow(),
                                       m_currentCellCoords.GetCol(),
                                       coords.GetRow(),
-                                      coords.GetCol() );
+                                      coords.GetCol(),
+                                      event.ControlDown(),
+                                      event.ShiftDown(),
+                                      event.AltDown(),
+                                      event.MetaDown() );
         }
         else if ( XToEdgeOfCol(x) < 0  &&
                   YToEdgeOfRow(y) < 0 )
@@ -4360,11 +4372,20 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
                 }
                 else
                 {
-                    m_selection->ToggleCellSelection( coords.GetRow(),
-                                                      coords.GetCol() );
-                    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;
                 }
             }
@@ -4406,7 +4427,10 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
                                           m_selectingTopLeft.GetCol(),
                                           m_selectingBottomRight.GetRow(),
                                           m_selectingBottomRight.GetCol(),
-                                          & event );
+                                          event.ControlDown(),
+                                          event.ShiftDown(),
+                                          event.AltDown(),
+                                          event.MetaDown() );
                 m_selectingTopLeft = wxGridNoCellCoords;
                 m_selectingBottomRight = wxGridNoCellCoords;
             }
@@ -4922,7 +4946,7 @@ bool wxGrid::SendEvent( const wxEventType type,
                              type,
                              this,
                              row, col,
-                             false,
+                             FALSE,
                              mouseEv.GetX(), mouseEv.GetY(),
                              mouseEv.ControlDown(),
                              mouseEv.ShiftDown(),
@@ -4966,15 +4990,6 @@ bool wxGrid::SendEvent( const wxEventType type,
 void wxGrid::OnPaint( wxPaintEvent& WXUNUSED(event) )
 {
     wxPaintDC dc( this );
-
-    if ( m_currentCellCoords == wxGridNoCellCoords  &&
-         m_numRows && m_numCols )
-    {
-        m_currentCellCoords.Set(0, 0);
-        ShowCellEditControl();
-    }
-
-    m_displayed = TRUE;
 }
 
 
@@ -5011,6 +5026,24 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
 
         // try local handlers
         //
+        if ( !event.ShiftDown() && 
+             m_selectingKeyboard != wxGridNoCellCoords )
+        {
+           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;
+        }
+
         switch ( event.KeyCode() )
         {
             case WXK_UP:
@@ -5111,20 +5144,23 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
                 MovePageDown();
                 break;
 
-#if 0
             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() );
-                break;
-#endif
 
             default:
                 // alphanumeric keys or F2 (special key just for this) enable
@@ -5163,15 +5199,13 @@ void wxGrid::OnKeyDown( wxKeyEvent& event )
     m_inOnKeyDown = FALSE;
 }
 
-
 void wxGrid::OnEraseBackground(wxEraseEvent&)
 {
 }
 
 void wxGrid::SetCurrentCell( const wxGridCellCoords& coords )
 {
-    if ( m_displayed  &&
-         m_currentCellCoords != wxGridNoCellCoords )
+    if ( m_currentCellCoords != wxGridNoCellCoords )
     {
         HideCellEditControl();
         DisableCellEditControl();
@@ -5187,14 +5221,13 @@ void wxGrid::SetCurrentCell( const wxGridCellCoords& coords )
 
     m_currentCellCoords = coords;
 
-    if ( m_displayed )
-    {
-        wxClientDC dc(m_gridWin);
-        PrepareDC(dc);
+    wxClientDC dc(m_gridWin);
+    PrepareDC(dc);
+
+    wxGridCellAttr* attr = GetCellAttr(coords);
+    DrawCellHighlight(dc, attr);
+    attr->DecRef();
 
-        wxGridCellAttr* attr = GetCellAttr(coords);
-        DrawCellHighlight(dc, attr);
-        attr->DecRef();
 #if 0
         // SN: For my extended selection code, automatic
         //     deselection is definitely not a good idea.
@@ -5205,7 +5238,6 @@ void wxGrid::SetCurrentCell( const wxGridCellCoords& coords )
             if ( !GetBatchCount() ) m_gridWin->Refresh( FALSE, &r );
         }
 #endif
-    }
 }
 
 
@@ -5408,6 +5440,15 @@ void wxGrid::DrawCellBorder( wxDC& dc, const wxGridCellCoords& coords )
 
 void wxGrid::DrawHighlight(wxDC& dc)
 {
+    // This if block was previously in wxGrid::OnPaint but that doesn't
+    // seem to get called under wxGTK - MB
+    //
+    if ( m_currentCellCoords == wxGridNoCellCoords  &&
+         m_numRows && m_numCols )
+    {
+        m_currentCellCoords.Set(0, 0);
+    }
+
     if ( IsCellEditControlEnabled() )
     {
         // don't show highlight when the edit control is shown
@@ -6135,15 +6176,23 @@ bool wxGrid::MoveCursorUp( bool expandSelection )
     if ( m_currentCellCoords != wxGridNoCellCoords  &&
          m_currentCellCoords.GetRow() > 0 )
     {
-        MakeCellVisible( m_currentCellCoords.GetRow() - 1,
-                        m_currentCellCoords.GetCol() );
-
-        SetCurrentCell( m_currentCellCoords.GetRow() - 1,
-                        m_currentCellCoords.GetCol() );
-
         if ( expandSelection )
-            m_selection->SelectCell( m_currentCellCoords.GetRow(),
-                                     m_currentCellCoords.GetCol() );
+        {
+            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;
     }
 
@@ -6153,20 +6202,26 @@ bool wxGrid::MoveCursorUp( bool expandSelection )
 
 bool wxGrid::MoveCursorDown( bool expandSelection )
 {
-    // TODO: allow for scrolling
-    //
     if ( m_currentCellCoords != wxGridNoCellCoords  &&
          m_currentCellCoords.GetRow() < m_numRows-1 )
     {
-        MakeCellVisible( m_currentCellCoords.GetRow() + 1,
-                        m_currentCellCoords.GetCol() );
-
-        SetCurrentCell( m_currentCellCoords.GetRow() + 1,
-                        m_currentCellCoords.GetCol() );
-
         if ( expandSelection )
-            m_selection->SelectCell( m_currentCellCoords.GetRow(),
-                                     m_currentCellCoords.GetCol() );
+        {
+            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;
     }
 
@@ -6179,15 +6234,23 @@ bool wxGrid::MoveCursorLeft( bool expandSelection )
     if ( m_currentCellCoords != wxGridNoCellCoords  &&
          m_currentCellCoords.GetCol() > 0 )
     {
-        MakeCellVisible( m_currentCellCoords.GetRow(),
-                        m_currentCellCoords.GetCol() - 1 );
-
-        SetCurrentCell( m_currentCellCoords.GetRow(),
-                        m_currentCellCoords.GetCol() - 1 );
-
         if ( expandSelection )
-            m_selection->SelectCell( m_currentCellCoords.GetRow(),
-                                     m_currentCellCoords.GetCol() );
+        {
+            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;
     }
 
@@ -6200,15 +6263,23 @@ bool wxGrid::MoveCursorRight( bool expandSelection )
     if ( m_currentCellCoords != wxGridNoCellCoords  &&
          m_currentCellCoords.GetCol() < m_numCols - 1 )
     {
-        MakeCellVisible( m_currentCellCoords.GetRow(),
-                        m_currentCellCoords.GetCol() + 1 );
-
-        SetCurrentCell( m_currentCellCoords.GetRow(),
-                        m_currentCellCoords.GetCol() + 1 );
-
         if ( expandSelection )
-            m_selection->SelectCell( m_currentCellCoords.GetRow(),
-                                     m_currentCellCoords.GetCol() );
+        {
+            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;
     }
 
@@ -6324,11 +6395,15 @@ bool wxGrid::MoveCursorUpBlock( bool expandSelection )
 
         MakeCellVisible( row, col );
         if ( expandSelection )
-            m_selection->SelectBlock( m_currentCellCoords.GetRow(),
-                                      m_currentCellCoords.GetCol(),
-                                      row, col );
-        SetCurrentCell( row, col );
-
+        {
+            m_selectingKeyboard = wxGridCellCoords( row, col );
+            SelectBlock( m_currentCellCoords, m_selectingKeyboard );
+        }
+        else
+       {
+           ClearSelection();
+           SetCurrentCell( row, col );
+       }
         return TRUE;
     }
 
@@ -6383,10 +6458,15 @@ bool wxGrid::MoveCursorDownBlock( bool expandSelection )
 
         MakeCellVisible( row, col );
         if ( expandSelection )
-            m_selection->SelectBlock( m_currentCellCoords.GetRow(),
-                                      m_currentCellCoords.GetCol(),
-                                      row, col );
-        SetCurrentCell( row, col );
+        {
+            m_selectingKeyboard = wxGridCellCoords( row, col );
+            SelectBlock( m_currentCellCoords, m_selectingKeyboard );
+        }
+        else
+       {
+           ClearSelection();
+           SetCurrentCell( row, col );
+       }
 
         return TRUE;
     }
@@ -6442,10 +6522,15 @@ bool wxGrid::MoveCursorLeftBlock( bool expandSelection )
 
         MakeCellVisible( row, col );
         if ( expandSelection )
-            m_selection->SelectBlock( m_currentCellCoords.GetRow(),
-                                      m_currentCellCoords.GetCol(),
-                                      row, col );
-        SetCurrentCell( row, col );
+        {
+            m_selectingKeyboard = wxGridCellCoords( row, col );
+            SelectBlock( m_currentCellCoords, m_selectingKeyboard );
+        }
+        else
+       {
+           ClearSelection();
+           SetCurrentCell( row, col );
+       }
 
         return TRUE;
     }
@@ -6501,10 +6586,15 @@ bool wxGrid::MoveCursorRightBlock( bool expandSelection )
 
         MakeCellVisible( row, col );
         if ( expandSelection )
-            m_selection->SelectBlock( m_currentCellCoords.GetRow(),
-                                      m_currentCellCoords.GetCol(),
-                                      row, col );
-        SetCurrentCell( row, col );
+        {
+            m_selectingKeyboard = wxGridCellCoords( row, col );
+            SelectBlock( m_currentCellCoords, m_selectingKeyboard );
+        }
+        else
+       {
+           ClearSelection();
+           SetCurrentCell( row, col );
+       }
 
         return TRUE;
     }