]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grid.cpp
check default library directories in WX_PATH_FIND_LIBRARIES; do *not* add default...
[wxWidgets.git] / src / generic / grid.cpp
index 395e94ac5dc1aa21aaafaa7f43fc31b34f891ec1..3e558a168aedaea70d501ada11438ee2dece933c 100644 (file)
@@ -240,27 +240,37 @@ private:
 class wxGridCellEditorEvtHandler : public wxEvtHandler
 {
 public:
-    wxGridCellEditorEvtHandler()
-        : m_grid(0), m_editor(0)
-        { }
     wxGridCellEditorEvtHandler(wxGrid* grid, wxGridCellEditor* editor)
-        : m_grid(grid), m_editor(editor)
-        { }
+        : m_grid(grid),
+          m_editor(editor),
+          m_inSetFocus(false)
+    {
+    }
 
+    void OnKillFocus(wxFocusEvent& event);
     void OnKeyDown(wxKeyEvent& event);
     void OnChar(wxKeyEvent& event);
 
+    void SetInSetFocus(bool inSetFocus) { m_inSetFocus = inSetFocus; }
+
 private:
     wxGrid*             m_grid;
     wxGridCellEditor*   m_editor;
-    DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler)
+
+    // Work around the fact that a focus kill event can be sent to
+    // a combobox within a set focus event.
+    bool                m_inSetFocus;
+
     DECLARE_EVENT_TABLE()
+    DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler)
     DECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler)
 };
 
 
-IMPLEMENT_DYNAMIC_CLASS( wxGridCellEditorEvtHandler, wxEvtHandler )
+IMPLEMENT_ABSTRACT_CLASS(wxGridCellEditorEvtHandler, wxEvtHandler)
+
 BEGIN_EVENT_TABLE( wxGridCellEditorEvtHandler, wxEvtHandler )
+    EVT_KILL_FOCUS( wxGridCellEditorEvtHandler::OnKillFocus )
     EVT_KEY_DOWN( wxGridCellEditorEvtHandler::OnKeyDown )
     EVT_CHAR( wxGridCellEditorEvtHandler::OnChar )
 END_EVENT_TABLE()
@@ -568,7 +578,7 @@ bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event)
     // through in that case.
     if ((ctrl || alt) && !(ctrl && alt))
         return false;
-    
+
 #if wxUSE_UNICODE
     int key = event.GetUnicodeKey();
     bool keyOk = true;
@@ -585,7 +595,7 @@ bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event)
     return keyOk;
 #else // !wxUSE_UNICODE
     int key = event.GetKeyCode();
-    if (key <= 255) 
+    if (key <= 255)
         return true;
     return false;
 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
@@ -749,7 +759,7 @@ void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
     wxTextCtrl* tc = Text();
     wxChar ch;
     long pos;
-    
+
 #if wxUSE_UNICODE
     ch = event.GetUnicodeKey();
     if (ch <= 127)
@@ -1103,7 +1113,7 @@ void wxGridCellFloatEditor::StartingKey(wxKeyEvent& event)
     tmpbuf[0] = (char) keycode;
     tmpbuf[1] = '\0';
     wxString strbuf(tmpbuf, *wxConvCurrent);
-#if wxUSE_INTL        
+#if wxUSE_INTL
     bool is_decimal_point = ( strbuf ==
        wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER) );
 #else
@@ -1181,14 +1191,14 @@ bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event)
         tmpbuf[0] = (char) keycode;
         tmpbuf[1] = '\0';
         wxString strbuf(tmpbuf, *wxConvCurrent);
-#if wxUSE_INTL        
+#if wxUSE_INTL
         bool is_decimal_point =
             ( strbuf == wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT,
                                           wxLOCALE_CAT_NUMBER) );
 #else
         bool is_decimal_point = ( strbuf == _T(".") );
 #endif
-        if ( (keycode < 128) && 
+        if ( (keycode < 128) &&
              (wxIsdigit(keycode) || tolower(keycode) == 'e' ||
               is_decimal_point || keycode == '+' || keycode == '-') )
             return true;
@@ -1372,11 +1382,11 @@ void wxGridCellBoolEditor::StartingKey(wxKeyEvent& event)
         case WXK_SPACE:
             CBox()->SetValue(!CBox()->GetValue());
             break;
-            
+
         case '+':
             CBox()->SetValue(true);
             break;
-                
+
         case '-':
             CBox()->SetValue(false);
             break;
@@ -1457,6 +1467,14 @@ void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
     wxASSERT_MSG(m_control,
                  wxT("The wxGridCellEditor must be Created first!"));
 
+    wxGridCellEditorEvtHandler* evtHandler = NULL;
+    if (m_control)
+        evtHandler = wxDynamicCast(m_control->GetEventHandler(), wxGridCellEditorEvtHandler);
+
+    // Don't immediately end if we get a kill focus event within BeginEdit
+    if (evtHandler)
+        evtHandler->SetInSetFocus(true);
+
     m_startValue = grid->GetTable()->GetValue(row, col);
 
     if (m_allowOthers)
@@ -1465,12 +1483,15 @@ void wxGridCellChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
     {
         // find the right position, or default to the first if not found
         int pos = Combo()->FindString(m_startValue);
-        if (pos == -1)
+        if (pos == wxNOT_FOUND)
             pos = 0;
         Combo()->SetSelection(pos);
     }
     Combo()->SetInsertionPointEnd();
     Combo()->SetFocus();
+
+    if (evtHandler)
+        evtHandler->SetInSetFocus(false);
 }
 
 bool wxGridCellChoiceEditor::EndEdit(int row, int col,
@@ -1520,6 +1541,18 @@ wxString wxGridCellChoiceEditor::GetValue() const
 // wxGridCellEditorEvtHandler
 // ----------------------------------------------------------------------------
 
+void wxGridCellEditorEvtHandler::OnKillFocus(wxFocusEvent& event)
+{
+    // Don't disable the cell if we're just starting to edit it
+    if (m_inSetFocus)
+        return;
+
+    // accept changes
+    m_grid->DisableCellEditControl();
+
+    event.Skip();
+}
+
 void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event)
 {
     switch ( event.GetKeyCode() )
@@ -1939,21 +1972,19 @@ void wxGridCellFloatRenderer::SetParameters(const wxString& params)
             {
                 wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params.c_str());
             }
-
         }
-                tmp = params.AfterFirst(_T(','));
-                if ( !tmp.empty() )
-                {
-                    long precision;
+        tmp = params.AfterFirst(_T(','));
+        if ( !tmp.empty() )
+        {
+            long precision;
             if ( tmp.ToLong(&precision) )
-                    {
+            {
                 SetPrecision((int)precision);
-                    }
-                    else
-                    {
+            }
+            else
+            {
                 wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params.c_str());
-        }
-
+            }
         }
     }
 }
@@ -3661,7 +3692,8 @@ void wxGridCornerLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )
     int client_width = 0;
     GetClientSize( &client_width, &client_height );
 
-#if __WXGTK__
+    // VZ: any reason for this ifdef? (FIXME)
+#ifdef __WXGTK__
     wxRect rect;
     rect.SetX( 1 );
     rect.SetY( 1 );
@@ -3669,7 +3701,7 @@ void wxGridCornerLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )
     rect.SetHeight( client_height - 2 );
 
     wxRendererNative::Get().DrawHeaderButton( this, dc, rect, 0 );
-#else
+#else // !__WXGTK__
     dc.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW),1, wxSOLID) );
     dc.DrawLine( client_width-1, client_height-1, client_width-1, 0 );
     dc.DrawLine( client_width-1, client_height-1, 0, client_height-1 );
@@ -3679,7 +3711,7 @@ void wxGridCornerLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) )
     dc.SetPen( *wxWHITE_PEN );
     dc.DrawLine( 1, 1, client_width-1, 1 );
     dc.DrawLine( 1, 1, 1, client_height-1 );
-#endif
+#endif // __WXGTK__/!__WXGTK__
 }
 
 
@@ -3772,7 +3804,7 @@ void wxGridWindow::OnMouseEvent( wxMouseEvent& event )
 {
     if (event.ButtonDown(wxMOUSE_BTN_LEFT) && FindFocus() != this)
         SetFocus();
-    
+
     m_owner->ProcessGridCellMouseEvent( event );
 }
 
@@ -4894,6 +4926,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
                 break;
 
                 case WXGRID_CURSOR_SELECT_ROW:
+                {
                     if ( (row = YToRow( y )) >= 0 )
                     {
                         if ( m_selection )
@@ -4905,6 +4938,8 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
                                                     event.MetaDown() );
                         }
                     }
+                }
+                break;
 
                 // default label to suppress warnings about "enumeration value
                 // 'xxx' not handled in switch
@@ -5116,6 +5151,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
                 break;
 
                 case WXGRID_CURSOR_SELECT_COL:
+                {
                     if ( (col = XToCol( x )) >= 0 )
                     {
                         if ( m_selection )
@@ -5127,6 +5163,8 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
                                                     event.MetaDown() );
                         }
                     }
+                }
+                break;
 
                 // default label to suppress warnings about "enumeration value
                 // 'xxx' not handled in switch
@@ -7824,7 +7862,9 @@ void wxGrid::HideCellEditControl()
         editor->Show( false );
         editor->DecRef();
         attr->DecRef();
+
         m_gridWin->SetFocus();
+
         // refresh whole row to the right
         wxRect rect( CellToRect(row, col) );
         CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y );