]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/listctrl.cpp
compile warnings, M_BITMAPDATA privatized
[wxWidgets.git] / src / generic / listctrl.cpp
index def1d4591a4c89bed1d9b70936fe79d10bf7ccfb..67279c9a1eaa1129da0e85166d3fb117a5ac6fc2 100644 (file)
@@ -769,7 +769,8 @@ public:
 
     // for double click logic
     size_t m_lineLastClicked,
-           m_lineBeforeLastClicked;
+           m_lineBeforeLastClicked,
+           m_lineSelectSingleOnUp;
 
 protected:
     // the total count of items in a virtual list control
@@ -2075,12 +2076,11 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event )
     switch ( event.m_keyCode )
     {
         case WXK_RETURN:
-            if ( AcceptChanges() )
-            {
-                // Close the text control, changes were accepted
-                Finish();
-            }
-            // else do nothing, do not accept and do not close
+            // Notify the owner about the changes
+            AcceptChanges();
+
+            // Even if vetoed, close the control (consistent with MSW)
+            Finish();
 
             break;
 
@@ -2176,6 +2176,7 @@ void wxListMainWindow::Init()
 
     m_current =
     m_lineLastClicked =
+    m_lineSelectSingleOnUp =
     m_lineBeforeLastClicked = (size_t)-1;
 
     m_freezeCount = 0;
@@ -2939,7 +2940,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
 
         wxListEvent le( command, GetParent()->GetId() );
         le.SetEventObject( GetParent() );
-        le.m_itemIndex = current;
+        le.m_itemIndex = m_lineLastClicked;
         le.m_pointDrag = m_dragStart;
         GetParent()->GetEventHandler()->ProcessEvent( le );
 
@@ -2970,26 +2971,56 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
         }
         else
         {
-            // the first click was on another item, so don't interpret this as
+            // The first click was on another item, so don't interpret this as
             // a double click, but as a simple click instead
             forceClick = true;
         }
     }
 
-    if (event.LeftUp() && m_lastOnSame)
+    if (event.LeftUp())
     {
-        if ((current == m_current) &&
-            (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
-            HasFlag(wxLC_EDIT_LABELS)  )
+        if(m_lineSelectSingleOnUp != (size_t) -1)
         {
-            m_renameTimer->Start( 100, true );
+            // select single line
+            HighlightAll( false );
+            ReverseHighlight(m_lineSelectSingleOnUp);
+        }
+        else if (m_lastOnSame)
+        {
+            if ((current == m_current) &&
+                (hitResult == wxLIST_HITTEST_ONITEMLABEL) &&
+                HasFlag(wxLC_EDIT_LABELS)  )
+            {
+                m_renameTimer->Start( 100, true );
+            }
         }
         m_lastOnSame = false;
+        m_lineSelectSingleOnUp = (size_t) -1;
+    }
+    else
+    {
+        // This is neccessary , because after a DnD operation in
+        // from and to ourself, the up event is swallowed by the
+        // DnD code. So on next non-up event (which means here and
+        // now) m_lineSelectSingleOnUp should be reset.
+        m_lineSelectSingleOnUp = (size_t) -1;
     }
-    else if (event.RightDown())
+    if (event.RightDown())
     {
+        m_lineBeforeLastClicked = m_lineLastClicked;
+        m_lineLastClicked = current;
+        // If the item is already selected, do not update the selection.
+        // Multi-selections should not be cleared if a selected item is clicked.
+        if (!IsHighlighted(current))
+        {
+            HighlightAll(false);
+            ChangeCurrent(current);
+            ReverseHighlight(m_current);
+        }
         SendNotify( current, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
                     event.GetPosition() );
+        // Allow generation of context menu event
+        event.Skip();
     }
     else if (event.MiddleDown())
     {
@@ -3002,13 +3033,21 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
 
         size_t oldCurrent = m_current;
         bool cmdModifierDown = event.CmdDown();
-        if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) )
+        if ( !(cmdModifierDown || event.ShiftDown()) )
         {
-            HighlightAll( false );
+            if( IsSingleSel() || !IsHighlighted(current) )
+            {
+                HighlightAll( false );
 
-            ChangeCurrent(current);
+                ChangeCurrent(current);
 
-            ReverseHighlight(m_current);
+                ReverseHighlight(m_current);
+            }
+            else // multi sel & current is highlighted & no mod keys
+            {
+                m_lineSelectSingleOnUp = current;
+                ChangeCurrent(current); // change focus
+            }
         }
         else // multi sel & either ctrl or shift is down
         {
@@ -4606,7 +4645,7 @@ void wxGenericListCtrl::CreateHeaderWindow()
     m_headerWin = new wxListHeaderWindow
                       (
                         this, wxID_ANY, m_mainWin,
-                        wxPoint(0, 0),
+                        wxPoint(),
                         wxSize(GetClientSize().x, m_headerHeight),
                         wxTAB_TRAVERSAL
                       );
@@ -4644,7 +4683,7 @@ bool wxGenericListCtrl::Create(wxWindow *parent,
     // don't create the inner window with the border
     style &= ~wxBORDER_MASK;
 
-    m_mainWin = new wxListMainWindow( this, wxID_ANY, wxPoint(0,0), size, style );
+    m_mainWin = new wxListMainWindow( this, wxID_ANY, wxPoint(), size, style );
 
 #ifdef  __WXMAC_CARBON__
     // Human Interface Guidelines ask us for a special font in this case