]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/listctrl.cpp
revert togglable tools to previous state if the change was vetoed by OnLeftClick()
[wxWidgets.git] / src / generic / listctrl.cpp
index 0e408a6170dfd72e58bd4c8817cc89e44e6950b4..2e9852802b718ad4b663883436352aa55758df0b 100644 (file)
@@ -494,6 +494,7 @@ private:
     wxString            m_startValue;
     size_t              m_itemEdited;
     bool                m_finished;
+    bool                m_aboutToFinish;
 
     DECLARE_EVENT_TABLE()
 };
@@ -644,6 +645,7 @@ public:
     void SetItem( wxListItem &item );
     void GetItem( wxListItem &item ) const;
     void SetItemState( long item, long state, long stateMask );
+    void SetItemStateAll( long state, long stateMask );
     int GetItemState( long item, long stateMask ) const;
     void GetItemRect( long index, wxRect &rect ) const;
     wxRect GetViewRect() const;
@@ -1739,13 +1741,18 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
 
         // the width of the rect to draw: make it smaller to fit entirely
         // inside the column rect
+#ifdef __WXMAC__
+        int cw = wCol ;
+        int ch = h ;
+#else
         int cw = wCol - 2;
-
+        int ch = h-2 ;
+#endif
         wxRendererNative::Get().DrawHeaderButton
                                 (
                                     this,
                                     dc,
-                                    wxRect(x, HEADER_OFFSET_Y, cw, h - 2),
+                                    wxRect(x, HEADER_OFFSET_Y, cw, ch),
                                     m_parent->IsEnabled() ? 0
                                                           : (int)wxCONTROL_DISABLED
                                 );
@@ -2026,6 +2033,7 @@ wxListTextCtrl::wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit)
 {
     m_owner = owner;
     m_finished = false;
+    m_aboutToFinish = false;
 
     wxRect rectLabel = owner->GetLineLabelRect(itemEdit);
 
@@ -2076,12 +2084,11 @@ 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();
-
             break;
 
         case WXK_ESCAPE:
@@ -2130,7 +2137,7 @@ void wxListTextCtrl::OnKillFocus( wxFocusEvent &event )
     }
 
     // We must let the native text control handle focus, too, otherwise
-    // it could have problems with the cursor (e.g., in wxGTK):
+    // it could have problems with the cursor (e.g., in wxGTK).
     event.Skip();
 }
 
@@ -3000,10 +3007,10 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
     else
     {
         // This is neccessary , because after a DnD operation in
-        // from and to ourself, the up event is swallowed by the 
+        // 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;  
+        m_lineSelectSingleOnUp = (size_t) -1;
     }
     if (event.RightDown())
     {
@@ -3033,7 +3040,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
 
         size_t oldCurrent = m_current;
         bool cmdModifierDown = event.CmdDown();
-        if ( !(cmdModifierDown || event.ShiftDown()) )
+        if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) )
         {
             if( IsSingleSel() || !IsHighlighted(current) )
             {
@@ -3045,7 +3052,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
             }
             else // multi sel & current is highlighted & no mod keys
             {
-                m_lineSelectSingleOnUp = current;      
+                m_lineSelectSingleOnUp = current;
                 ChangeCurrent(current); // change focus
             }
         }
@@ -3635,8 +3642,58 @@ void wxListMainWindow::SetItem( wxListItem &item )
     RefreshRect(rectItem);
 }
 
+void wxListMainWindow::SetItemStateAll(long state, long stateMask)
+{
+    if ( IsEmpty() )
+        return;
+
+    // first deal with selection
+    if ( stateMask & wxLIST_STATE_SELECTED )
+    {
+        // set/clear select state
+        if ( IsVirtual() )
+        {
+            // optimized version for virtual listctrl.
+            m_selStore.SelectRange(0, GetItemCount() - 1, state == wxLIST_STATE_SELECTED);
+            Refresh();
+        }
+        else if ( state & wxLIST_STATE_SELECTED )
+        {
+            const long count = GetItemCount();
+            for( long i = 0; i <  count; i++ )
+            {
+                SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
+            }
+
+        }
+        else
+        {
+            // clear for non virtual (somewhat optimized by using GetNextItem())
+            long i = -1;
+            while ( (i = GetNextItem(i, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) != -1 )
+            {
+                SetItemState( i, 0, wxLIST_STATE_SELECTED );
+            }
+        }
+    }
+
+    if ( HasCurrent() && (state == 0) && (stateMask & wxLIST_STATE_FOCUSED) )
+    {
+        // unfocus all: only one item can be focussed, so clearing focus for
+        // all items is simply clearing focus of the focussed item.
+        SetItemState(m_current, state, stateMask);
+    }
+    //(setting focus to all items makes no sense, so it is not handled here.)
+}
+
 void wxListMainWindow::SetItemState( long litem, long state, long stateMask )
 {
+    if ( litem == -1 )
+    {
+        SetItemStateAll(state, stateMask);
+        return;
+    }
+
      wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(),
                   _T("invalid list ctrl item index in SetItem") );
 
@@ -4622,11 +4679,15 @@ void wxGenericListCtrl::CalculateAndSetHeaderHeight()
 {
     if ( m_headerWin )
     {
+#ifdef __WXMAC__
+        SInt32 h ;
+        GetThemeMetric( kThemeMetricListHeaderHeight, &h );
+#else
         // we use 'g' to get the descent, too
         int w, h, d;
         m_headerWin->GetTextExtent(wxT("Hg"), &w, &h, &d);
         h += d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT;
-
+#endif
         // only update if changed
         if ( h != m_headerHeight )
         {
@@ -4645,7 +4706,7 @@ void wxGenericListCtrl::CreateHeaderWindow()
     m_headerWin = new wxListHeaderWindow
                       (
                         this, wxID_ANY, m_mainWin,
-                        wxPoint(0, 0),
+                        wxPoint(0,0),
                         wxSize(GetClientSize().x, m_headerHeight),
                         wxTAB_TRAVERSAL
                       );
@@ -4697,7 +4758,15 @@ bool wxGenericListCtrl::Create(wxWindow *parent,
     if ( InReportView() )
     {
         CreateHeaderWindow();
-
+#ifdef  __WXMAC_CARBON__
+        if (m_headerWin)
+        {
+            wxFont font ;
+            font.MacCreateThemeFont( kThemeSmallSystemFont ) ;
+            m_headerWin->SetFont( font );
+            CalculateAndSetHeaderHeight();
+        }
+#endif
         if ( HasFlag(wxLC_NO_HEADER) )
         {
             // VZ: why do we create it at all then?