X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/34621cc5d6eaf8933935fbda55625124429a0ff9..040e5f77e6f7f177bdc74b90327c22908d56fe59:/src/generic/listctrl.cpp diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index e965866237..2e9852802b 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -69,14 +69,13 @@ #endif // HAVE_NATIVE_LISTCTRL/!HAVE_NATIVE_LISTCTRL #include "wx/selstore.h" - #include "wx/renderer.h" +#include "wx/math.h" #ifdef __WXMAC__ #include "wx/mac/private.h" #endif -#include // NOTE: If using the wxListBox visual attributes works everywhere then this can @@ -495,6 +494,7 @@ private: wxString m_startValue; size_t m_itemEdited; bool m_finished; + bool m_aboutToFinish; DECLARE_EVENT_TABLE() }; @@ -519,7 +519,7 @@ public: const wxString &name = _T("listctrlmainwindow") ); virtual ~wxListMainWindow(); - + wxWindow *GetMainWindowOfCompositeControl() { return GetParent(); } bool HasFlag(int flag) const { return m_parent->HasFlag(flag); } @@ -606,8 +606,6 @@ public: void Freeze(); void Thaw(); - void SetFocus(); - void OnRenameTimer(); bool OnRenameAccept(size_t itemEdit, const wxString& value); void OnRenameCancelled(size_t itemEdit); @@ -647,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; @@ -772,7 +771,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 @@ -1741,15 +1741,20 @@ 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 - : wxCONTROL_DISABLED + : (int)wxCONTROL_DISABLED ); // see if we have enough space for the column label @@ -2028,6 +2033,7 @@ wxListTextCtrl::wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit) { m_owner = owner; m_finished = false; + m_aboutToFinish = false; wxRect rectLabel = owner->GetLineLabelRect(itemEdit); @@ -2047,7 +2053,7 @@ void wxListTextCtrl::Finish() m_finished = true; - m_owner->SetFocus(); + m_owner->SetFocusIgnoringChildren(); } } @@ -2078,13 +2084,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 - + m_aboutToFinish = true; + // Notify the owner about the changes + AcceptChanges(); + // Even if vetoed, close the control (consistent with MSW) + Finish(); break; case WXK_ESCAPE: @@ -2133,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(); } @@ -2179,6 +2183,7 @@ void wxListMainWindow::Init() m_current = m_lineLastClicked = + m_lineSelectSingleOnUp = m_lineBeforeLastClicked = (size_t)-1; m_freezeCount = 0; @@ -2877,6 +2882,13 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) return; + if (event.GetEventType() == wxEVT_MOUSEWHEEL) + { + // let the base handle mouse wheel events. + event.Skip(); + return; + } + if ( !HasCurrent() || IsEmpty() ) return; @@ -2935,7 +2947,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 ); @@ -2966,26 +2978,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 if (event.RightDown()) + 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; + } + 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()) { @@ -3000,11 +3042,19 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) bool cmdModifierDown = event.CmdDown(); if ( IsSingleSel() || !(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 { @@ -3299,26 +3349,6 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) // focus handling // ---------------------------------------------------------------------------- -void wxListMainWindow::SetFocus() -{ - // VS: wxListMainWindow derives from wxPanel (via wxScrolledWindow) and wxPanel - // overrides SetFocus in such way that it does never change focus from - // panel's child to the panel itself. Unfortunately, we must be able to change - // focus to the panel from wxListTextCtrl because the text control should - // disappear when the user clicks outside it. - - wxWindow *oldFocus = DoFindFocus(); - - if ( oldFocus && oldFocus->GetParent() == this ) - { - wxWindow::SetFocus(); - } - else - { - wxScrolledWindow::SetFocus(); - } -} - void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) { if ( GetParent() ) @@ -3612,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") ); @@ -4354,7 +4434,7 @@ void wxListMainWindow::InsertItem( wxListItem &item ) if (item.m_itemId > count) item.m_itemId = count; - + size_t id = item.m_itemId; m_dirty = true; @@ -4399,7 +4479,7 @@ void wxListMainWindow::InsertItem( wxListItem &item ) wxListLineData *line = new wxListLineData(this); - line->SetItem( 0, item ); + line->SetItem( item.m_col, item ); m_lines.Insert( line, id ); @@ -4599,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 ) { @@ -4622,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 ); @@ -4662,7 +4746,7 @@ bool wxGenericListCtrl::Create(wxWindow *parent, m_mainWin = new wxListMainWindow( this, wxID_ANY, wxPoint(0,0), size, style ); -#ifdef __WXMAC_CARBON__ +#ifdef __WXMAC_CARBON__ // Human Interface Guidelines ask us for a special font in this case if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ) { @@ -4674,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?