]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/grideditors.cpp
Rename wxWebHistoryItem to wxWebViewHistoryItem.
[wxWidgets.git] / src / generic / grideditors.cpp
index c07eb137223ddc713d4f725c07fdf4c3ec0987b8..ac90aa3310bdb867d4a8c501a68a744f4fcfe730 100644 (file)
     #include "wx/textctrl.h"
     #include "wx/checkbox.h"
     #include "wx/combobox.h"
     #include "wx/textctrl.h"
     #include "wx/checkbox.h"
     #include "wx/combobox.h"
-    #include "wx/valtext.h"
     #include "wx/intl.h"
     #include "wx/math.h"
     #include "wx/listbox.h"
 #endif
 
     #include "wx/intl.h"
     #include "wx/math.h"
     #include "wx/listbox.h"
 #endif
 
+#include "wx/valnum.h"
 #include "wx/textfile.h"
 #include "wx/spinctrl.h"
 #include "wx/tokenzr.h"
 #include "wx/textfile.h"
 #include "wx/spinctrl.h"
 #include "wx/tokenzr.h"
@@ -300,13 +300,13 @@ void wxGridCellEditor::Show(bool show, wxGridCellAttr *attr)
     else
     {
         // restore the standard colours fonts
     else
     {
         // restore the standard colours fonts
-        if ( m_colFgOld.Ok() )
+        if ( m_colFgOld.IsOk() )
         {
             m_control->SetForegroundColour(m_colFgOld);
             m_colFgOld = wxNullColour;
         }
 
         {
             m_control->SetForegroundColour(m_colFgOld);
             m_colFgOld = wxNullColour;
         }
 
-        if ( m_colBgOld.Ok() )
+        if ( m_colBgOld.IsOk() )
         {
             m_control->SetBackgroundColour(m_colBgOld);
             m_colBgOld = wxNullColour;
         {
             m_control->SetBackgroundColour(m_colBgOld);
             m_colBgOld = wxNullColour;
@@ -314,7 +314,7 @@ void wxGridCellEditor::Show(bool show, wxGridCellAttr *attr)
 
 // Workaround for GTK+1 font setting problem on some platforms
 #if !defined(__WXGTK__) || defined(__WXGTK20__)
 
 // Workaround for GTK+1 font setting problem on some platforms
 #if !defined(__WXGTK__) || defined(__WXGTK20__)
-        if ( m_fontOld.Ok() )
+        if ( m_fontOld.IsOk() )
         {
             m_control->SetFont(m_fontOld);
             m_fontOld = wxNullFont;
         {
             m_control->SetFont(m_fontOld);
             m_fontOld = wxNullFont;
@@ -338,13 +338,15 @@ void wxGridCellEditor::HandleReturn(wxKeyEvent& event)
 bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event)
 {
     bool ctrl = event.ControlDown();
 bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event)
 {
     bool ctrl = event.ControlDown();
-    bool alt  = event.AltDown();
+    bool alt;
 
 #ifdef __WXMAC__
     // On the Mac the Alt key is more like shift and is used for entry of
     // valid characters, so check for Ctrl and Meta instead.
     alt = event.MetaDown();
 
 #ifdef __WXMAC__
     // On the Mac the Alt key is more like shift and is used for entry of
     // valid characters, so check for Ctrl and Meta instead.
     alt = event.MetaDown();
-#endif
+#else // !__WXMAC__
+    alt = event.AltDown();
+#endif // __WXMAC__/!__WXMAC__
 
     // Assume it's not a valid char if ctrl or alt is down, but if both are
     // down then it may be because of an AltGr key combination, so let them
 
     // Assume it's not a valid char if ctrl or alt is down, but if both are
     // down then it may be because of an AltGr key combination, so let them
@@ -353,14 +355,10 @@ bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event)
         return false;
 
 #if wxUSE_UNICODE
         return false;
 
 #if wxUSE_UNICODE
-    // if the unicode key code is not really a unicode character (it may
-    // be a function key or etc., the platforms appear to always give us a
-    // small value in this case) then fallback to the ASCII key code but
-    // don't do anything for function keys or etc.
-    if ( event.GetUnicodeKey() > 127 && event.GetKeyCode() > 127 )
+    if ( static_cast<int>(event.GetUnicodeKey()) == WXK_NONE )
         return false;
 #else
         return false;
 #else
-    if ( event.GetKeyCode() > 255 )
+    if ( event.GetKeyCode() > WXK_START )
         return false;
 #endif
 
         return false;
 #endif
 
@@ -399,7 +397,10 @@ void wxGridCellTextEditor::DoCreate(wxWindow* parent,
                                     wxEvtHandler* evtHandler,
                                     long style)
 {
                                     wxEvtHandler* evtHandler,
                                     long style)
 {
-    style |= wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxNO_BORDER;
+    // Use of wxTE_RICH2 is a strange hack to work around the bug #11681: a
+    // plain text control seems to lose its caret somehow when we hide it and
+    // show it again for a different cell.
+    style |= wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB | wxNO_BORDER | wxTE_RICH2;
 
     m_control = new wxTextCtrl(parent, id, wxEmptyString,
                                wxDefaultPosition, wxDefaultSize,
 
     m_control = new wxTextCtrl(parent, id, wxEmptyString,
                                wxDefaultPosition, wxDefaultSize,
@@ -527,7 +528,15 @@ void wxGridCellTextEditor::DoReset(const wxString& startValue)
 
 bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent& event)
 {
 
 bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent& event)
 {
-    return wxGridCellEditor::IsAcceptedKey(event);
+    switch ( event.GetKeyCode() )
+    {
+        case WXK_DELETE:
+        case WXK_BACK:
+            return true;
+
+        default:
+            return wxGridCellEditor::IsAcceptedKey(event);
+    }
 }
 
 void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
 }
 
 void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
@@ -538,35 +547,39 @@ void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
     // a valid character, so not a whole lot of testing needs to be done.
 
     wxTextCtrl* tc = Text();
     // a valid character, so not a whole lot of testing needs to be done.
 
     wxTextCtrl* tc = Text();
-    wxChar ch;
-    long pos;
+    int ch;
+
+    bool isPrintable;
 
 #if wxUSE_UNICODE
     ch = event.GetUnicodeKey();
 
 #if wxUSE_UNICODE
     ch = event.GetUnicodeKey();
-    if (ch <= 127)
-        ch = (wxChar)event.GetKeyCode();
-#else
-    ch = (wxChar)event.GetKeyCode();
-#endif
+    if ( ch != WXK_NONE )
+        isPrintable = true;
+    else
+#endif // wxUSE_UNICODE
+    {
+        ch = event.GetKeyCode();
+        isPrintable = ch >= WXK_SPACE && ch < WXK_START;
+    }
 
     switch (ch)
     {
         case WXK_DELETE:
 
     switch (ch)
     {
         case WXK_DELETE:
-            // delete the character at the cursor
-            pos = tc->GetInsertionPoint();
-            if (pos < tc->GetLastPosition())
-                tc->Remove(pos, pos + 1);
+            // Delete the initial character when starting to edit with DELETE.
+            tc->Remove(0, 1);
             break;
 
         case WXK_BACK:
             break;
 
         case WXK_BACK:
-            // delete the character before the cursor
-            pos = tc->GetInsertionPoint();
-            if (pos > 0)
+            // Delete the last character when starting to edit with BACKSPACE.
+            {
+                const long pos = tc->GetLastPosition();
                 tc->Remove(pos - 1, pos);
                 tc->Remove(pos - 1, pos);
+            }
             break;
 
         default:
             break;
 
         default:
-            tc->WriteText(ch);
+            if ( isPrintable )
+                tc->WriteText(static_cast<wxChar>(ch));
             break;
     }
 }
             break;
     }
 }
@@ -647,7 +660,7 @@ void wxGridCellNumberEditor::Create(wxWindow* parent,
         wxGridCellTextEditor::Create(parent, id, evtHandler);
 
 #if wxUSE_VALIDATORS
         wxGridCellTextEditor::Create(parent, id, evtHandler);
 
 #if wxUSE_VALIDATORS
-        Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
+        Text()->SetValidator(wxIntegerValidator<int>());
 #endif
     }
 }
 #endif
     }
 }
@@ -862,7 +875,7 @@ void wxGridCellFloatEditor::Create(wxWindow* parent,
     wxGridCellTextEditor::Create(parent, id, evtHandler);
 
 #if wxUSE_VALIDATORS
     wxGridCellTextEditor::Create(parent, id, evtHandler);
 
 #if wxUSE_VALIDATORS
-    Text()->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
+    Text()->SetValidator(wxFloatingPointValidator<double>(m_precision));
 #endif
 }
 
 #endif
 }
 
@@ -1027,13 +1040,8 @@ bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event)
     if ( wxGridCellEditor::IsAcceptedKey(event) )
     {
         const int keycode = event.GetKeyCode();
     if ( wxGridCellEditor::IsAcceptedKey(event) )
     {
         const int keycode = event.GetKeyCode();
-        if ( isascii(keycode) )
+        if ( wxIsascii(keycode) )
         {
         {
-            char tmpbuf[2];
-            tmpbuf[0] = (char) keycode;
-            tmpbuf[1] = '\0';
-            wxString strbuf(tmpbuf, *wxConvCurrent);
-
 #if wxUSE_INTL
             const wxString decimalPoint =
                 wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER);
 #if wxUSE_INTL
             const wxString decimalPoint =
                 wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER);
@@ -1498,7 +1506,6 @@ void wxGridCellEnumEditor::BeginEdit(int row, int col, wxGrid* grid)
     }
 
     Combo()->SetSelection(m_index);
     }
 
     Combo()->SetSelection(m_index);
-    Combo()->SetInsertionPointEnd();
     Combo()->SetFocus();
 
 }
     Combo()->SetFocus();
 
 }