]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
wxDataObejct and related changes (won't compile right now)
[wxWidgets.git] / src / generic / grid.cpp
index c69d2694306574469d6c2e58893905fb3bcfeeb2..c8e79066cdea648267d3ec661c80add202ffaf19 100644 (file)
@@ -187,7 +187,7 @@ wxGridTableMessage::wxGridTableMessage( wxGridTableBase *table, int id,
 // this is a magic incantation which must be done!
 #include <wx/arrimpl.cpp>
 
-WX_DEFINE_OBJARRAY(wxGridStringArray);
+WX_DEFINE_OBJARRAY(wxGridStringArray)
 
 IMPLEMENT_DYNAMIC_CLASS( wxGridStringTable, wxGridTableBase )
 
@@ -602,6 +602,8 @@ void wxGridTextCtrl::OnKeyDown( wxKeyEvent& ev )
         case WXK_DOWN:
         case WXK_LEFT:
         case WXK_RIGHT:
+        case WXK_PRIOR:
+        case WXK_NEXT:
         case WXK_RETURN:
             if ( m_isCellControl )
             {
@@ -805,10 +807,9 @@ void wxGrid::Init()
                                          wxGRID_CELLCTRL,
                                          "",
                                          wxPoint(1,1),
-                                         wxSize(1,1),
-                                         wxNO_BORDER
+                                         wxSize(1,1)
 #ifdef __WXMSW__
-                                         | wxTE_MULTILINE | wxTE_NO_VSCROLL
+                                         , wxTE_MULTILINE | wxTE_NO_VSCROLL
 #endif
                                          );
                                          
@@ -1133,8 +1134,8 @@ bool wxGrid::SendEvent( const wxEventType type,
                        int row, int col,
                        wxMouseEvent& mouseEv )
 {
-    if ( type == EVT_WXGRID_ROW_SIZE ||
-        type == EVT_WXGRID_COL_SIZE )
+    if ( type == EVT_GRID_ROW_SIZE ||
+        type == EVT_GRID_COL_SIZE )
     {
        int rowOrCol = (row == -1 ? col : row);
 
@@ -1150,7 +1151,7 @@ bool wxGrid::SendEvent( const wxEventType type,
 
        return GetEventHandler()->ProcessEvent(gridEvt);
     }
-    else if ( type == EVT_WXGRID_RANGE_SELECT )
+    else if ( type == EVT_GRID_RANGE_SELECT )
     {
        wxGridRangeSelectEvent gridEvt( GetId(),
                                        type,
@@ -1187,8 +1188,8 @@ bool wxGrid::SendEvent( const wxEventType type,
 bool wxGrid::SendEvent( const wxEventType type,
                        int row, int col )
 {
-    if ( type == EVT_WXGRID_ROW_SIZE ||
-        type == EVT_WXGRID_COL_SIZE )
+    if ( type == EVT_GRID_ROW_SIZE ||
+        type == EVT_GRID_COL_SIZE )
     {
        int rowOrCol = (row == -1 ? col : row);
 
@@ -1380,7 +1381,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
                 if ( YToEdgeOfRow(y) < 0 )
                 {
                     row = YToRow(y);
-                    if ( !SendEvent( EVT_WXGRID_LABEL_LEFT_CLICK, row, col, ev ) )
+                    if ( !SendEvent( EVT_GRID_LABEL_LEFT_CLICK, row, col, ev ) )
                     {
                         SelectRow( row, ev.ShiftDown() );
                         m_cursorMode = WXGRID_CURSOR_SELECT_ROW;
@@ -1398,7 +1399,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
                 if ( XToEdgeOfCol(x) < 0 )
                 {
                     col = XToCol(x);
-                    if ( !SendEvent( EVT_WXGRID_LABEL_LEFT_CLICK, row, col, ev ) )
+                    if ( !SendEvent( EVT_GRID_LABEL_LEFT_CLICK, row, col, ev ) )
                     {
                         SelectCol( col, ev.ShiftDown() );
                         m_cursorMode = WXGRID_CURSOR_SELECT_COL;
@@ -1411,7 +1412,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
             {
                 // leave both row and col as -1
                 //
-                if ( !SendEvent( EVT_WXGRID_LABEL_LEFT_CLICK, row, col, ev ) )
+                if ( !SendEvent( EVT_GRID_LABEL_LEFT_CLICK, row, col, ev ) )
                 {
                     SelectAll();
                 }
@@ -1421,7 +1422,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
             case WXGRID_CELL:
             {
                 XYToCell( x, y, cellCoords );
-                if ( !SendEvent( EVT_WXGRID_CELL_LEFT_CLICK,
+                if ( !SendEvent( EVT_GRID_CELL_LEFT_CLICK,
                                  cellCoords.GetRow(),
                                  cellCoords.GetCol(),
                                  ev ) )
@@ -1460,7 +1461,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
                 if ( YToEdgeOfRow(y) < 0 )
                 {
                     row = YToRow(y);
-                    SendEvent(  EVT_WXGRID_LABEL_LEFT_DCLICK, row, col, ev );
+                    SendEvent(  EVT_GRID_LABEL_LEFT_DCLICK, row, col, ev );
                 }
             }
             break;
@@ -1474,7 +1475,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
                 if ( XToEdgeOfCol(x) < 0 )
                 {
                     col = XToCol(x);
-                    SendEvent(  EVT_WXGRID_LABEL_LEFT_DCLICK, row, col, ev );
+                    SendEvent(  EVT_GRID_LABEL_LEFT_DCLICK, row, col, ev );
                 }
             }
             break;
@@ -1483,14 +1484,14 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
             {
                 // leave both row and col as -1
                 //
-                SendEvent(  EVT_WXGRID_LABEL_LEFT_DCLICK, row, col, ev );                
+                SendEvent(  EVT_GRID_LABEL_LEFT_DCLICK, row, col, ev );                
             }
             break;
 
             case WXGRID_CELL:
             {
                 XYToCell( x, y, cellCoords );
-                SendEvent( EVT_WXGRID_CELL_LEFT_DCLICK,
+                SendEvent( EVT_GRID_CELL_LEFT_DCLICK,
                                  cellCoords.GetRow(),
                                  cellCoords.GetCol(),
                                  ev );
@@ -1535,7 +1536,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
                    // Note: we are ending the event *after* doing
                    // default processing in this case
                    //
-                   SendEvent( EVT_WXGRID_ROW_SIZE, m_dragRowOrCol, -1, ev );
+                   SendEvent( EVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, ev );
                }
            }
            break;
@@ -1563,7 +1564,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
                    // Note: we are ending the event *after* doing
                    // default processing in this case
                    //
-                   SendEvent( EVT_WXGRID_COL_SIZE, -1, m_dragRowOrCol, ev );
+                   SendEvent( EVT_GRID_COL_SIZE, -1, m_dragRowOrCol, ev );
                }
            }
            break;
@@ -1575,7 +1576,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
                    // Note: we are ending the event *after* doing
                    // default processing in this case
                    //
-                   SendEvent( EVT_WXGRID_RANGE_SELECT, -1, -1, ev );
+                   SendEvent( EVT_GRID_RANGE_SELECT, -1, -1, ev );
                }
            }
            break;
@@ -1599,7 +1600,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
            case WXGRID_ROWLABEL:
            {
                row = YToRow(y);
-               if ( !SendEvent( EVT_WXGRID_LABEL_RIGHT_CLICK, row, col, ev ) )
+               if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK, row, col, ev ) )
                {
                     // TODO: default processing ?
                 }
@@ -1609,7 +1610,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
             case WXGRID_COLLABEL:
             {
                 col = XToCol(x);
-               if ( !SendEvent( EVT_WXGRID_LABEL_RIGHT_CLICK, row, col, ev ) )
+               if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK, row, col, ev ) )
                 {
                     // TODO: default processing ?
                 }
@@ -1620,7 +1621,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
             {
                 // leave both row and col as -1
                 //
-                if ( !SendEvent( EVT_WXGRID_LABEL_RIGHT_CLICK, row, col, ev ) )
+                if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK, row, col, ev ) )
                 {
                     // TODO: default processing ?
                 }
@@ -1630,7 +1631,7 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
             case WXGRID_CELL:
             {
                 XYToCell( x, y, cellCoords );
-                if ( !SendEvent( EVT_WXGRID_CELL_RIGHT_CLICK,
+                if ( !SendEvent( EVT_GRID_CELL_RIGHT_CLICK,
                                 cellCoords.GetRow(),
                                 cellCoords.GetCol(),
                                 ev ) )
@@ -1663,14 +1664,14 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
            case WXGRID_ROWLABEL:
            {
                row = YToRow(y);
-               SendEvent( EVT_WXGRID_LABEL_RIGHT_DCLICK, row, col, ev );
+               SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK, row, col, ev );
             }
             break;
 
             case WXGRID_COLLABEL:
             {
                 col = XToCol(x);
-               SendEvent( EVT_WXGRID_LABEL_RIGHT_DCLICK, row, col, ev );
+               SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK, row, col, ev );
             }
             break;
 
@@ -1678,14 +1679,14 @@ void wxGrid::OnMouse( wxMouseEvent& ev )
             {
                 // leave both row and col as -1
                 //
-                SendEvent( EVT_WXGRID_LABEL_RIGHT_DCLICK, row, col, ev );
+                SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK, row, col, ev );
             }
             break;
 
             case WXGRID_CELL:
             {
                 XYToCell( x, y, cellCoords );
-                SendEvent( EVT_WXGRID_CELL_RIGHT_DCLICK,
+                SendEvent( EVT_GRID_CELL_RIGHT_DCLICK,
                            cellCoords.GetRow(),
                            cellCoords.GetCol(),
                            ev );
@@ -1964,6 +1965,12 @@ void wxGrid::OnGridScroll( wxScrollEvent& ev )
 
 void wxGrid::SelectCell( const wxGridCellCoords& coords )
 {
+    if ( SendEvent( EVT_GRID_SELECT_CELL, coords.GetRow(), coords.GetCol() ) )
+    {
+        // the event has been intercepted - do nothing
+        return;
+    }
+
     wxClientDC dc( this );
 
     if ( m_currentCellCoords != wxGridNoCellCoords )
@@ -2048,7 +2055,10 @@ void wxGrid::SetEditControlValue( const wxString& value )
     if ( m_table )
     {
         wxString s;
-        s = ( value == wxEmptyString ? GetCellValue(m_currentCellCoords) : value );
+        if ( !value )
+            s = GetCellValue(m_currentCellCoords);
+        else
+            s = value;
 
         if ( IsTopEditControlEnabled() )
         {
@@ -2150,7 +2160,7 @@ void wxGrid::SaveEditControlValue()
         
         if ( valueChanged )
         {
-            SendEvent( EVT_WXGRID_CELL_CHANGE,
+            SendEvent( EVT_GRID_CELL_CHANGE,
                        m_currentCellCoords.GetRow(),
                        m_currentCellCoords.GetCol() );
         }
@@ -3032,13 +3042,13 @@ void wxGrid::DrawCellHighlight( wxDC& dc, int row, int col )
         y = m_rowBottoms[row] - m_rowHeights[row];
         if ( y >= ch ) return;
 
-        dc.SetLogicalFunction( wxXOR );
+        dc.SetLogicalFunction( wxINVERT );
         dc.SetPen( wxPen(GetCellHighlightColour(), 2, wxSOLID) );
         dc.SetBrush( *wxTRANSPARENT_BRUSH );
 
-        dc.DrawRectangle( x, y,
-                          m_colWidths[col] + 2,
-                          m_rowHeights[row] + 2 );
+        dc.DrawRectangle( x-2, y-2,
+                          m_colWidths[col] + 6,
+                          m_rowHeights[row] + 6 );
 
         dc.SetLogicalFunction( wxCOPY );
     }
@@ -3073,7 +3083,8 @@ void wxGrid::DrawCell( int row, int col )
 //
 void wxGrid::HideCurrentCellHighlight( wxDC& dc )
 {
-    if ( m_currentCellHighlighted  &&
+    if ( !m_cellEditCtrlEnabled  &&
+         m_currentCellHighlighted  &&
          m_currentCellCoords != wxGridNoCellCoords )
     {
         DrawCellHighlight( dc, m_currentCellCoords );
@@ -3086,7 +3097,8 @@ void wxGrid::HideCurrentCellHighlight( wxDC& dc )
 //
 void wxGrid::ShowCurrentCellHighlight( wxDC& dc )
 {
-    if ( !m_currentCellHighlighted  &&
+    if ( !m_cellEditCtrlEnabled  &&
+         !m_currentCellHighlighted  &&
          m_currentCellCoords != wxGridNoCellCoords )
     {
         DrawCellHighlight( dc, m_currentCellCoords );
@@ -3351,8 +3363,26 @@ bool wxGrid::InsertRows( int pos, int numRows, bool WXUNUSED(updateLabels) )
         //
         if ( ok )
         {
+            if ( m_numCols == 0 ) 
+            {
+                m_table->AppendCols( WXGRID_DEFAULT_NUMBER_COLS );
+                //
+                // TODO: perhaps instead of appending the default number of cols
+                // we should remember what the last non-zero number of cols was ?
+                //
+            }
+            
+            if ( m_currentCellCoords == wxGridNoCellCoords )
+            {
+                // if we have just inserted cols into an empty grid the current
+                // cell will be undefined...
+                //
+                SelectCell( 0, 0 );  
+            }
+            
             if ( !GetBatchCount() ) Refresh();
         }
+
         SetEditControlValue();
         return ok;
     }
@@ -3374,6 +3404,14 @@ bool wxGrid::AppendRows( int numRows, bool WXUNUSED(updateLabels) )
     
     if ( m_table && m_table->AppendRows( numRows ) )
     {
+        if ( m_currentCellCoords == wxGridNoCellCoords )
+        {
+            // if we have just inserted cols into an empty grid the current
+            // cell will be undefined...
+            //
+            SelectCell( 0, 0 );  
+        }
+        
         // the table will have sent the results of the append row
         // operation to this view object as a grid table message
         //
@@ -3429,13 +3467,23 @@ bool wxGrid::InsertCols( int pos, int numCols, bool WXUNUSED(updateLabels) )
     {
         HideCellEditControl();
         bool ok = m_table->InsertCols( pos, numCols );
+            
+        // the table will have sent the results of the insert col
+        // operation to this view object as a grid table message
+        //
         if ( ok )
         {
-            // the table will have sent the results of the insert col
-            // operation to this view object as a grid table message
-            //
+            if ( m_currentCellCoords == wxGridNoCellCoords )
+            {
+                // if we have just inserted cols into an empty grid the current
+                // cell will be undefined...
+                //
+                SelectCell( 0, 0 );  
+            }
+
             if ( !GetBatchCount() ) Refresh();
         }
+        
         SetEditControlValue();
         return ok;
     }
@@ -3460,6 +3508,13 @@ bool wxGrid::AppendCols( int numCols, bool WXUNUSED(updateLabels) )
        // the table will have sent the results of the append col
        // operation to this view object as a grid table message
        //
+        if ( m_currentCellCoords == wxGridNoCellCoords )
+        {
+            // if we have just inserted cols into an empty grid the current
+            // cell will be undefined...
+            //
+            SelectCell( 0, 0 );  
+        }
        if ( !GetBatchCount() ) Refresh();
        return TRUE;
     }
@@ -3541,6 +3596,9 @@ void wxGrid::EnableCellEditControl( bool enable )
     if ( m_cellEditCtrl &&
          enable != m_cellEditCtrlEnabled )
     {
+        wxClientDC dc( this );
+        
+        HideCurrentCellHighlight( dc );
         HideCellEditControl();
         SaveEditControlValue();
         
@@ -3548,6 +3606,7 @@ void wxGrid::EnableCellEditControl( bool enable )
 
         SetEditControlValue();
         ShowCellEditControl();
+        ShowCurrentCellHighlight( dc );
     }
 }
 
@@ -3817,7 +3876,7 @@ void wxGrid::SetRowSize( int row, int height )
         // Note: we are ending the event *after* doing
         // default processing in this case
         //
-        SendEvent( EVT_WXGRID_ROW_SIZE,
+        SendEvent( EVT_GRID_ROW_SIZE,
                    row, -1 );
     }
     else
@@ -3856,7 +3915,7 @@ void wxGrid::SetColSize( int col, int width )
         // Note: we are ending the event *after* doing
         // default processing in this case
         //
-        SendEvent( EVT_WXGRID_COL_SIZE,
+        SendEvent( EVT_GRID_COL_SIZE,
                    -1, col );
     }
     else
@@ -4095,7 +4154,7 @@ void wxGrid::SelectRow( int row, bool addToSelected )
     }
     
     wxGridRangeSelectEvent gridEvt( GetId(),
-                                    EVT_WXGRID_RANGE_SELECT,
+                                    EVT_GRID_RANGE_SELECT,
                                     this,
                                     m_selectedTopLeft,
                                     m_selectedBottomRight );
@@ -4132,7 +4191,7 @@ void wxGrid::SelectCol( int col, bool addToSelected )
     }
 
     wxGridRangeSelectEvent gridEvt( GetId(),
-                                    EVT_WXGRID_RANGE_SELECT,
+                                    EVT_GRID_RANGE_SELECT,
                                     this,
                                     m_selectedTopLeft,
                                     m_selectedBottomRight );
@@ -4174,7 +4233,7 @@ void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol )
     if ( !m_isDragging )
     {
         wxGridRangeSelectEvent gridEvt( GetId(),
-                                        EVT_WXGRID_RANGE_SELECT,
+                                        EVT_GRID_RANGE_SELECT,
                                         this,
                                         m_selectedTopLeft,
                                         m_selectedBottomRight );