]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/listctrl.cpp
Fix for [ 1351655 ] wxTextValidator::OnChar not working with numeric filter
[wxWidgets.git] / src / generic / listctrl.cpp
index cd1e3dd934acc86e44cde49aa0cc49ed9a538910..c6a51c95247c50b3e3259971879d6eedb405b930 100644 (file)
@@ -137,9 +137,8 @@ static const int MARGIN_BETWEEN_ROWS = 6;
 // when autosizing the columns, add some slack
 static const int AUTOSIZE_COL_MARGIN = 10;
 
-// default and minimal widths for the header columns
+// default width for the header columns
 static const int WIDTH_COL_DEFAULT = 80;
-static const int WIDTH_COL_MIN = 10;
 
 // the space between the image and the text in the report mode
 static const int IMAGE_MARGIN_IN_REPORT_MODE = 5;
@@ -285,7 +284,7 @@ private:
 
 WX_DECLARE_LIST(wxListItemData, wxListItemDataList);
 #include "wx/listimpl.cpp"
-WX_DEFINE_LIST(wxListItemDataList);
+WX_DEFINE_LIST(wxListItemDataList)
 
 class wxListLineData
 {
@@ -413,7 +412,7 @@ private:
 
 WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData, wxListLineDataArray);
 #include "wx/arrimpl.cpp"
-WX_DEFINE_OBJARRAY(wxListLineDataArray);
+WX_DEFINE_OBJARRAY(wxListLineDataArray)
 
 //-----------------------------------------------------------------------------
 //  wxListHeaderWindow (internal)
@@ -495,6 +494,8 @@ class WXDLLEXPORT wxListTextCtrl: public wxTextCtrl
 public:
     wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit);
 
+    void AcceptChangesAndFinish();
+
 protected:
     void OnChar( wxKeyEvent &event );
     void OnKeyUp( wxKeyEvent &event );
@@ -519,7 +520,7 @@ private:
 
 WX_DECLARE_LIST(wxListHeaderData, wxListHeaderDataList);
 #include "wx/listimpl.cpp"
-WX_DEFINE_LIST(wxListHeaderDataList);
+WX_DEFINE_LIST(wxListHeaderDataList)
 
 class wxListMainWindow : public wxScrolledWindow
 {
@@ -791,6 +792,8 @@ public:
            m_lineBeforeLastClicked,
            m_lineSelectSingleOnUp;
 
+    wxListTextCtrl*     m_textctrl;
+    
 protected:
     // the total count of items in a virtual list control
     size_t m_countVirt;
@@ -1075,11 +1078,7 @@ void wxListHeaderData::SetHeight( int h )
 
 void wxListHeaderData::SetWidth( int w )
 {
-    m_width = w;
-    if (m_width < 0)
-        m_width = WIDTH_COL_DEFAULT;
-    else if (m_width < WIDTH_COL_MIN)
-        m_width = WIDTH_COL_MIN;
+    m_width = w < 0 ? WIDTH_COL_DEFAULT : w;
 }
 
 void wxListHeaderData::SetFormat( int format )
@@ -2073,7 +2072,8 @@ void wxListTextCtrl::Finish()
     if ( !m_finished )
     {
         wxPendingDelete.Append(this);
-
+        m_owner->m_textctrl = NULL;
+        
         m_finished = true;
 
         m_owner->SetFocusIgnoringChildren();
@@ -2102,16 +2102,21 @@ bool wxListTextCtrl::AcceptChanges()
     return true;
 }
 
+void wxListTextCtrl::AcceptChangesAndFinish()
+{
+    m_aboutToFinish = true;
+    // Notify the owner about the changes
+    AcceptChanges();
+    // Even if vetoed, close the control (consistent with MSW)
+    Finish();
+}
+
 void wxListTextCtrl::OnChar( wxKeyEvent &event )
 {
     switch ( event.m_keyCode )
     {
         case WXK_RETURN:
-            m_aboutToFinish = true;
-            // Notify the owner about the changes
-            AcceptChanges();
-            // Even if vetoed, close the control (consistent with MSW)
-            Finish();
+            AcceptChangesAndFinish();
             break;
 
         case WXK_ESCAPE:
@@ -2203,7 +2208,8 @@ void wxListMainWindow::Init()
 
     m_lastOnSame = false;
     m_renameTimer = new wxListRenameTimer( this );
-
+    m_textctrl = NULL;
+    
     m_current =
     m_lineLastClicked =
     m_lineSelectSingleOnUp =
@@ -2852,9 +2858,8 @@ void wxListMainWindow::EditLabel( long item )
     if ( m_dirty )
         wxSafeYield();
 
-    wxListTextCtrl *text = new wxListTextCtrl(this, itemEdit);
-
-    text->SetFocus();
+    m_textctrl = new wxListTextCtrl(this, itemEdit);
+    m_textctrl->SetFocus();
 }
 
 void wxListMainWindow::OnRenameTimer()
@@ -2899,6 +2904,17 @@ void wxListMainWindow::OnRenameCancelled(size_t itemEdit)
 
 void wxListMainWindow::OnMouse( wxMouseEvent &event )
 {
+#ifdef __WXMAC__
+    // On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
+    // shutdown the edit control when the mouse is clicked elsewhere on the
+    // listctrl because the order of events is different (or something like
+    // that,) so explicitly end the edit if it is active.
+    if ( event.LeftDown() && m_textctrl)
+    {
+        m_textctrl->AcceptChangesAndFinish();
+    }
+#endif
+    
     event.SetEventObject( GetParent() );
     if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
         return;