]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/listctrl.cpp
added debugging code for redrawing
[wxWidgets.git] / src / generic / listctrl.cpp
index 16ec1bbabc9686b042a191657bb9abd13750ae26..5e7ce897adeb7f15ee9e0929f6c8b48534ce777e 100644 (file)
 
 #if wxUSE_LISTCTRL
 
-#include "wx/dcscreen.h"
-#include "wx/app.h"
-#include "wx/listctrl.h"
+#ifndef WX_PRECOMP
+    #include "wx/app.h"
+
+    #include "wx/dynarray.h"
+
+    #include "wx/dcscreen.h"
+
+    #include "wx/textctrl.h"
+#endif
+
 #include "wx/imaglist.h"
-#include "wx/dynarray.h"
+#include "wx/listctrl.h"
 
 #ifdef __WXGTK__
-#include <gtk/gtk.h>
-#include "wx/gtk/win_gtk.h"
+    #include <gtk/gtk.h>
+    #include "wx/gtk/win_gtk.h"
 #endif
 
 // ----------------------------------------------------------------------------
@@ -72,6 +79,7 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT)
 
 // ----------------------------------------------------------------------------
@@ -494,6 +502,7 @@ private:
     wxString           *m_res;
     wxListMainWindow   *m_owner;
     wxString            m_startValue;
+    bool                m_finished;
 
 public:
     wxListTextCtrl() {}
@@ -684,7 +693,9 @@ public:
     bool IsEmpty() const { return GetItemCount() == 0; }
     void SetItemCount(long count);
 
-    void ResetCurrent() { m_current = (size_t)-1; }
+    // change the current (== focused) item, send a notification event
+    void ChangeCurrent(size_t current);
+    void ResetCurrent() { ChangeCurrent((size_t)-1); }
     bool HasCurrent() const { return m_current != (size_t)-1; }
 
     // send out a wxListEvent
@@ -827,12 +838,6 @@ private:
     // delete all items but don't refresh: called from dtor
     void DoDeleteAllItems();
 
-    // called when an item is [un]focuded, i.e. becomes [not] current
-    //
-    // currently unused
-    void OnFocusLine( size_t line );
-    void OnUnfocusLine( size_t line );
-
     // the height of one line using the current font
     wxCoord m_lineHeight;
 
@@ -974,8 +979,10 @@ bool wxSelectionStore::SelectRange(size_t itemFrom, size_t itemTo,
                             // stop counting (see comment below)
                             itemsChanged = NULL;
                         }
-
-                        itemsChanged->Add(m_itemsSel[i]);
+                        else
+                        {
+                            itemsChanged->Add(m_itemsSel[i]);
+                        }
                     }
 
                     m_itemsSel.RemoveAt(i);
@@ -2133,6 +2140,7 @@ wxListTextCtrl::wxListTextCtrl( wxWindow *parent,
     (*m_accept) = FALSE;
     (*m_res) = "";
     m_startValue = value;
+    m_finished = FALSE;
 }
 
 void wxListTextCtrl::OnChar( wxKeyEvent &event )
@@ -2145,9 +2153,12 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event )
         if (!wxPendingDelete.Member(this))
             wxPendingDelete.Append(this);
 
-        if ((*m_accept) && ((*m_res) != m_startValue))
+        if ((*m_res) != m_startValue)
             m_owner->OnRenameAccept();
 
+        m_finished = TRUE;
+        m_owner->SetFocus(); // This doesn't work. TODO.
+
         return;
     }
     if (event.m_keyCode == WXK_ESCAPE)
@@ -2158,6 +2169,9 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event )
         if (!wxPendingDelete.Member(this))
             wxPendingDelete.Append(this);
 
+        m_finished = TRUE;
+        m_owner->SetFocus(); // This doesn't work. TODO.
+
         return;
     }
 
@@ -2166,12 +2180,18 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event )
 
 void wxListTextCtrl::OnKeyUp( wxKeyEvent &event )
 {
+    if (m_finished)
+    {
+        event.Skip();
+        return;
+    }
+
     // auto-grow the textctrl:
     wxSize parentSize = m_owner->GetSize();
     wxPoint myPos = GetPosition();
     wxSize mySize = GetSize();
     int sx, sy;
-    GetTextExtent(GetValue() + _T("MM"), &sx, &sy); // FIXME: MM??
+    GetTextExtent(GetValue() + _T("M"), &sx, &sy); // FIXME: MM??
     if (myPos.x + sx > parentSize.x)
         sx = parentSize.x - myPos.x;
     if (mySize.x > sx)
@@ -2181,12 +2201,21 @@ void wxListTextCtrl::OnKeyUp( wxKeyEvent &event )
     event.Skip();
 }
 
-void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
+void wxListTextCtrl::OnKillFocus( wxFocusEvent &event )
 {
+    if (m_finished)
+    {
+        event.Skip();
+        return;
+    }
+
     if (!wxPendingDelete.Member(this))
         wxPendingDelete.Append(this);
 
-    if ((*m_accept) && ((*m_res) != m_startValue))
+    (*m_accept) = TRUE;
+    (*m_res) = GetValue();
+    
+    if ((*m_res) != m_startValue)
         m_owner->OnRenameAccept();
 }
 
@@ -2865,21 +2894,22 @@ void wxListMainWindow::SendNotify( size_t line,
     // what we're trying to avoid
     if ( !IsVirtual() && (command != wxEVT_COMMAND_LIST_DELETE_ITEM) )
     {
-        GetLine(line)->GetItem( 0, le.m_item );
+        if ( line != (size_t)-1 )
+        {
+            GetLine(line)->GetItem( 0, le.m_item );
+        }
+        //else: this happens for wxEVT_COMMAND_LIST_ITEM_FOCUSED event
     }
     //else: there may be no more such item
 
     GetParent()->GetEventHandler()->ProcessEvent( le );
 }
 
-void wxListMainWindow::OnFocusLine( size_t WXUNUSED(line) )
+void wxListMainWindow::ChangeCurrent(size_t current)
 {
-//  SendNotify( line, wxEVT_COMMAND_LIST_ITEM_FOCUSSED );
-}
+    m_current = current;
 
-void wxListMainWindow::OnUnfocusLine( size_t WXUNUSED(line) )
-{
-//  SendNotify( line, wxEVT_COMMAND_LIST_ITEM_UNFOCUSSED );
+    SendNotify(current, wxEVT_COMMAND_LIST_ITEM_FOCUSED);
 }
 
 void wxListMainWindow::EditLabel( long item )
@@ -3086,7 +3116,8 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
         if ( IsSingleSel() || !(event.ControlDown() || event.ShiftDown()) )
         {
             HighlightAll( FALSE );
-            m_current = current;
+
+            ChangeCurrent(current);
 
             ReverseHighlight(m_current);
         }
@@ -3094,13 +3125,13 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
         {
             if (event.ControlDown())
             {
-                m_current = current;
+                ChangeCurrent(current);
 
                 ReverseHighlight(m_current);
             }
             else if (event.ShiftDown())
             {
-                m_current = current;
+                ChangeCurrent(current);
 
                 size_t lineFrom = oldCurrent,
                        lineTo = current;
@@ -3123,8 +3154,6 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
         if (m_current != oldCurrent)
         {
             RefreshLine( oldCurrent );
-            OnUnfocusLine( oldCurrent );
-            OnFocusLine( m_current );
         }
 
         // forceClick is only set if the previous click was on another item
@@ -3180,7 +3209,7 @@ void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
     // items anyhow
     if ( event.ShiftDown() && !IsSingleSel() )
     {
-        m_current = newCurrent;
+        ChangeCurrent(newCurrent);
 
         // select all the items between the old and the new one
         if ( oldCurrent > newCurrent )
@@ -3197,7 +3226,7 @@ void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
         if ( !event.ControlDown() )
             HighlightAll(FALSE);
 
-        m_current = newCurrent;
+        ChangeCurrent(newCurrent);
 
         HighlightLine( oldCurrent, FALSE );
         RefreshLine( oldCurrent );
@@ -3208,8 +3237,6 @@ void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event)
         }
     }
 
-    OnUnfocusLine( oldCurrent );
-    OnFocusLine( m_current );
     RefreshLine( m_current );
 
     MoveToFocus();
@@ -3711,9 +3738,7 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
             // don't do anything if this item is already focused
             if ( item != m_current )
             {
-                OnUnfocusLine( m_current );
-                m_current = item;
-                OnFocusLine( m_current );
+                ChangeCurrent(item);
 
                 if ( oldCurrent != (size_t)-1 )
                 {
@@ -3733,8 +3758,7 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
             // don't do anything if this item is not focused
             if ( item == m_current )
             {
-                OnUnfocusLine( m_current );
-                m_current = (size_t)-1;
+                ResetCurrent();
 
                 RefreshLine( oldCurrent );
             }
@@ -3754,9 +3778,7 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
                 // single sel mode
                 if ( m_current != item )
                 {
-                    OnUnfocusLine( m_current );
-                    m_current = item;
-                    OnFocusLine( m_current );
+                    ChangeCurrent(item);
 
                     if ( oldCurrent != (size_t)-1 )
                     {
@@ -4013,12 +4035,7 @@ void wxListMainWindow::UpdateCurrent()
 {
     if ( !HasCurrent() && !IsEmpty() )
     {
-        m_current = 0;
-    }
-
-    if ( m_current != (size_t)-1 )
-    {
-        OnFocusLine( m_current );
+        ChangeCurrent(0);
     }
 }
 
@@ -4458,53 +4475,6 @@ void wxListItem::ClearAttributes()
     }
 }
 
-// -------------------------------------------------------------------------------------
-// wxListEvent
-// -------------------------------------------------------------------------------------
-
-IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
-
-wxListEvent::wxListEvent( wxEventType commandType, int id )
-           : wxNotifyEvent( commandType, id )
-{
-    m_code = 0;
-    m_itemIndex = 0;
-    m_oldItemIndex = 0;
-    m_col = 0;
-    m_cancelled = FALSE;
-    m_pointDrag.x = 0;
-    m_pointDrag.y = 0;
-}
-
-void wxListEvent::CopyObject(wxObject& object_dest) const
-{
-    wxListEvent *obj = (wxListEvent *)&object_dest;
-
-    wxNotifyEvent::CopyObject(object_dest);
-
-    obj->m_code = m_code;
-    obj->m_itemIndex = m_itemIndex;
-    obj->m_oldItemIndex = m_oldItemIndex;
-    obj->m_col = m_col;
-    obj->m_cancelled = m_cancelled;
-    obj->m_pointDrag = m_pointDrag;
-    obj->m_item.m_mask = m_item.m_mask;
-    obj->m_item.m_itemId = m_item.m_itemId;
-    obj->m_item.m_col = m_item.m_col;
-    obj->m_item.m_state = m_item.m_state;
-    obj->m_item.m_stateMask = m_item.m_stateMask;
-    obj->m_item.m_text = m_item.m_text;
-    obj->m_item.m_image = m_item.m_image;
-    obj->m_item.m_data = m_item.m_data;
-    obj->m_item.m_format = m_item.m_format;
-    obj->m_item.m_width = m_item.m_width;
-
-    if ( m_item.HasAttributes() )
-    {
-        obj->m_item.SetTextColour(m_item.GetTextColour());
-    }
-}
-
 // -------------------------------------------------------------------------------------
 // wxListCtrl
 // -------------------------------------------------------------------------------------
@@ -4512,6 +4482,8 @@ void wxListEvent::CopyObject(wxObject& object_dest) const
 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl)
 IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl)
 
+IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent)
+
 BEGIN_EVENT_TABLE(wxListCtrl,wxControl)
   EVT_SIZE(wxListCtrl::OnSize)
   EVT_IDLE(wxListCtrl::OnIdle)
@@ -4533,9 +4505,6 @@ wxListCtrl::wxListCtrl()
 
 wxListCtrl::~wxListCtrl()
 {
-    if ( m_mainWin )
-        m_mainWin->ResetCurrent();
-
     if (m_ownsImageListNormal)
         delete m_imageListNormal;
     if (m_ownsImageListSmall)