X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/655719367ac5e131d9642e5783f3ecf64d1a3385..9814d926198c75333d972f408fa527f84e9355d3:/src/generic/listctrl.cpp diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 99fec5e45f..72bd336298 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -69,13 +69,15 @@ #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 + + // NOTE: If using the wxListBox visual attributes works everywhere then this can // be removed, as well as the #else case below. #define _USE_VISATTR 0 @@ -91,8 +93,10 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS) +#if WXWIN_COMPATIBILITY_2_4 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO) +#endif DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN) @@ -149,6 +153,25 @@ static const int IMAGE_MARGIN_IN_REPORT_MODE = 5; // private classes // ============================================================================ +//----------------------------------------------------------------------------- +// wxColWidthInfo (internal) +//----------------------------------------------------------------------------- + +struct wxColWidthInfo +{ + int nMaxWidth; + bool bNeedsUpdate; // only set to true when an item whose + // width == nMaxWidth is removed + + wxColWidthInfo(int w = 0, bool needsUpdate = false) + { + nMaxWidth = w; + bNeedsUpdate = needsUpdate; + } +}; + +WX_DEFINE_ARRAY_PTR(wxColWidthInfo *, ColWidthArray); + //----------------------------------------------------------------------------- // wxListItemData (internal) //----------------------------------------------------------------------------- @@ -161,7 +184,7 @@ public: void SetItem( const wxListItem &info ); void SetImage( int image ) { m_image = image; } - void SetData( long data ) { m_data = data; } + void SetData( wxUIntPtr data ) { m_data = data; } void SetPosition( int x, int y ); void SetSize( int width, int height ); @@ -200,7 +223,7 @@ public: int m_image; // user data associated with the item - long m_data; + wxUIntPtr m_data; // the item coordinates are not used in report mode, instead this pointer // is NULL and the owner window is used to retrieve the item position and @@ -290,7 +313,7 @@ public: // the part to be highlighted wxRect m_rectHighlight; - // extend all our rects to be centered inside theo ne of given width + // extend all our rects to be centered inside the one of given width void ExtendWidth(wxCoord w) { wxASSERT_MSG( m_rectAll.width <= w, @@ -490,6 +513,7 @@ private: wxString m_startValue; size_t m_itemEdited; bool m_finished; + bool m_aboutToFinish; DECLARE_EVENT_TABLE() }; @@ -515,6 +539,8 @@ public: virtual ~wxListMainWindow(); + wxWindow *GetMainWindowOfCompositeControl() { return GetParent(); } + bool HasFlag(int flag) const { return m_parent->HasFlag(flag); } // return true if this is a virtual list control @@ -534,14 +560,14 @@ public: // all these functions only do something if the line is currently visible - // change the line "selected" state, return TRUE if it really changed - bool HighlightLine( size_t line, bool highlight = TRUE); + // change the line "selected" state, return true if it really changed + bool HighlightLine( size_t line, bool highlight = true); // as HighlightLine() but do it for the range of lines: this is incredibly // more efficient for virtual list controls! // // NB: unlike HighlightLine() this one does refresh the lines on screen - void HighlightLines( size_t lineFrom, size_t lineTo, bool on = TRUE ); + void HighlightLines( size_t lineFrom, size_t lineTo, bool on = true ); // toggle the line state and refresh it void ReverseHighlight( size_t line ) @@ -599,8 +625,6 @@ public: void Freeze(); void Thaw(); - void SetFocus(); - void OnRenameTimer(); bool OnRenameAccept(size_t itemEdit, const wxString& value); void OnRenameCancelled(size_t itemEdit); @@ -623,8 +647,8 @@ public: int GetTextLength( const wxString &s ) const; void SetImageList( wxImageListType *imageList, int which ); - void SetItemSpacing( int spacing, bool isSmall = FALSE ); - int GetItemSpacing( bool isSmall = FALSE ); + void SetItemSpacing( int spacing, bool isSmall = false ); + int GetItemSpacing( bool isSmall = false ); void SetColumn( int col, wxListItem &item ); void SetColumnWidth( int col, int width ); @@ -640,6 +664,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; @@ -664,7 +689,7 @@ public: } // set the scrollbars and update the positions of the items - void RecalculatePositions(bool noRefresh = FALSE); + void RecalculatePositions(bool noRefresh = false); // refresh the window and the header void RefreshAll(); @@ -675,11 +700,13 @@ public: void DeleteColumn( int col ); void DeleteEverything(); void EnsureVisible( long index ); - long FindItem( long start, const wxString& str, bool partial = FALSE ); - long FindItem( long start, long data); + long FindItem( long start, const wxString& str, bool partial = false ); + long FindItem( long start, wxUIntPtr data); + long FindItem( const wxPoint& pt ); long HitTest( int x, int y, int &flags ); void InsertItem( wxListItem &item ); void InsertColumn( long col, wxListItem &item ); + int GetItemWidthWithImage(wxListItem * item); void SortItems( wxListCtrlCompare fn, long data ); size_t GetItemCount() const; @@ -700,11 +727,11 @@ public: virtual bool SetFont(const wxFont& font) { if ( !wxScrolledWindow::SetFont(font) ) - return FALSE; + return false; m_lineHeight = 0; - return TRUE; + return true; } // these are for wxListLineData usage only @@ -761,10 +788,12 @@ public: bool m_isCreated; int m_dragCount; wxPoint m_dragStart; + ColWidthArray m_aColWidths; // 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 @@ -808,11 +837,7 @@ protected: // get the colour to be used for drawing the rules wxColour GetRuleColour() const { -#ifdef __WXMAC__ - return *wxWHITE; -#else return wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); -#endif } private: @@ -937,7 +962,7 @@ void wxListItemData::SetSize( int width, int height ) bool wxListItemData::IsHit( int x, int y ) const { - wxCHECK_MSG( m_rect, FALSE, _T("can't be called in this mode") ); + wxCHECK_MSG( m_rect, false, _T("can't be called in this mode") ); return wxRect(GetX(), GetY(), GetWidth(), GetHeight()).Inside(x, y); } @@ -1122,7 +1147,7 @@ wxListLineData::wxListLineData( wxListMainWindow *owner ) m_gi = new GeometryInfo; } - m_highlighted = FALSE; + m_highlighted = false; InitItems( GetMode() == wxLC_REPORT ? m_owner->GetColumnCount() : 1 ); } @@ -1438,10 +1463,10 @@ bool wxListLineData::SetAttributes(wxDC *dc, dc->SetPen( *wxTRANSPARENT_PEN ); - return TRUE; + return true; } - return FALSE; + return false; } void wxListLineData::Draw( wxDC *dc ) @@ -1608,14 +1633,14 @@ void wxListLineData::DrawTextFormatted(wxDC *dc, bool wxListLineData::Highlight( bool on ) { - wxCHECK_MSG( !IsVirtual(), FALSE, _T("unexpected call to Highlight") ); + wxCHECK_MSG( !IsVirtual(), false, _T("unexpected call to Highlight") ); if ( on == m_highlighted ) - return FALSE; + return false; m_highlighted = on; - return TRUE; + return true; } void wxListLineData::ReverseHighlight( void ) @@ -1638,8 +1663,8 @@ END_EVENT_TABLE() void wxListHeaderWindow::Init() { m_currentCursor = (wxCursor *) NULL; - m_isDragging = FALSE; - m_dirty = FALSE; + m_isDragging = false; + m_dirty = false; } wxListHeaderWindow::wxListHeaderWindow() @@ -1665,14 +1690,16 @@ wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE ); #if _USE_VISATTR - wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes(); - SetDefaultForegroundColour( attr.colFg ); - SetDefaultBackgroundColour( attr.colBg ); - SetDefaultFont( attr.font ); + wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes(); + SetOwnForegroundColour( attr.colFg ); + SetOwnBackgroundColour( attr.colBg ); + if (!m_hasFont) + SetOwnFont( attr.font ); #else - SetDefaultForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); - SetDefaultBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); - SetDefaultFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT )); + SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); + SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); + if (!m_hasFont) + SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT )); #endif } @@ -1719,7 +1746,7 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) dc.SetBackgroundMode(wxTRANSPARENT); dc.SetTextForeground(GetForegroundColour()); - + int x = HEADER_OFFSET_X; int numColumns = m_owner->GetColumnCount(); @@ -1731,22 +1758,27 @@ 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 // for this we need the width of the text wxCoord wLabel; - wxCoord hLabel; + wxCoord hLabel; dc.GetTextExtent(item.GetText(), &wLabel, &hLabel); wLabel += 2*EXTRA_WIDTH; @@ -1871,8 +1903,8 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) if (event.ButtonUp()) { ReleaseMouse(); - m_isDragging = FALSE; - m_dirty = TRUE; + m_isDragging = false; + m_dirty = true; m_owner->SetColumnWidth( m_column, m_currentX - m_minX ); SendListEvent(wxEVT_COMMAND_LIST_COL_END_DRAG, event.GetPosition()); } @@ -1891,12 +1923,12 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) else // not dragging { m_minX = 0; - bool hit_border = FALSE; + bool hit_border = false; // end of the current column int xpos = 0; - // find the column where this event occured + // find the column where this event occurred int col, countCol = m_owner->GetColumnCount(); for (col = 0; col < countCol; col++) @@ -1907,7 +1939,7 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) if ( (abs(x-xpos) < 3) && (y < 22) ) { // near the column border - hit_border = TRUE; + hit_border = true; break; } @@ -1930,7 +1962,7 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) if ( SendListEvent(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, event.GetPosition()) ) { - m_isDragging = TRUE; + m_isDragging = true; m_currentX = x; CaptureMouse(); DrawCurrent(); @@ -2017,7 +2049,8 @@ wxListTextCtrl::wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit) m_itemEdited(itemEdit) { m_owner = owner; - m_finished = FALSE; + m_finished = false; + m_aboutToFinish = false; wxRect rectLabel = owner->GetLineLabelRect(itemEdit); @@ -2035,9 +2068,9 @@ void wxListTextCtrl::Finish() { wxPendingDelete.Append(this); - m_finished = TRUE; + m_finished = true; - m_owner->SetFocus(); + m_owner->SetFocusIgnoringChildren(); } } @@ -2048,19 +2081,19 @@ bool wxListTextCtrl::AcceptChanges() if ( value == m_startValue ) { // nothing changed, always accept - return TRUE; + return true; } if ( !m_owner->OnRenameAccept(m_itemEdited, value) ) { // vetoed by the user - return FALSE; + return false; } // accepted, do rename the item m_owner->SetItemText(m_itemEdited, value); - return TRUE; + return true; } void wxListTextCtrl::OnChar( wxKeyEvent &event ) @@ -2068,12 +2101,12 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event ) switch ( event.m_keyCode ) { case WXK_RETURN: - if ( !AcceptChanges() ) - { - // vetoed by the user code - break; - } - //else: fall through + m_aboutToFinish = true; + // Notify the owner about the changes + AcceptChanges(); + // Even if vetoed, close the control (consistent with MSW) + Finish(); + break; case WXK_ESCAPE: Finish(); @@ -2103,22 +2136,25 @@ void wxListTextCtrl::OnKeyUp( wxKeyEvent &event ) sx = parentSize.x - myPos.x; if (mySize.x > sx) sx = mySize.x; - SetSize(sx, -1); + SetSize(sx, wxDefaultCoord); event.Skip(); } void wxListTextCtrl::OnKillFocus( wxFocusEvent &event ) { - if ( !m_finished ) + if ( !m_finished && !m_aboutToFinish ) { - // We must finish regardless of success, otherwise we'll get focus problems + // We must finish regardless of success, otherwise we'll get + // focus problems: Finish(); if ( !AcceptChanges() ) m_owner->OnRenameCancelled( m_itemEdited ); } + // We must let the native text control handle focus, too, otherwise + // it could have problems with the cursor (e.g., in wxGTK). event.Skip(); } @@ -2140,7 +2176,7 @@ END_EVENT_TABLE() void wxListMainWindow::Init() { - m_dirty = TRUE; + m_dirty = true; m_countVirt = 0; m_lineFrom = m_lineTo = (size_t)-1; @@ -2155,15 +2191,16 @@ void wxListMainWindow::Init() m_small_spacing = 30; m_normal_spacing = 40; - m_hasFocus = FALSE; + m_hasFocus = false; m_dragCount = 0; - m_isCreated = FALSE; + m_isCreated = false; - m_lastOnSame = FALSE; + m_lastOnSame = false; m_renameTimer = new wxListRenameTimer( this ); m_current = m_lineLastClicked = + m_lineSelectSingleOnUp = m_lineBeforeLastClicked = (size_t)-1; m_freezeCount = 0; @@ -2206,21 +2243,20 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxSOLID ); - wxSize sz = size; - sz.y = 25; - SetScrollbars( 0, 0, 0, 0, 0, 0 ); - wxVisualAttributes attr = wxGenericListCtrl::GetClassDefaultAttributes(); - SetDefaultForegroundColour( attr.colFg ); - SetDefaultBackgroundColour( attr.colBg ); - SetDefaultFont( attr.font ); + wxVisualAttributes attr = wxGenericListCtrl::GetClassDefaultAttributes(); + SetOwnForegroundColour( attr.colFg ); + SetOwnBackgroundColour( attr.colBg ); + if (!m_hasFont) + SetOwnFont( attr.font ); } wxListMainWindow::~wxListMainWindow() { DoDeleteAllItems(); WX_CLEAR_LIST(wxListHeaderDataList, m_columns); + WX_CLEAR_ARRAY(m_aColWidths); delete m_highlightBrush; delete m_highlightUnfocusedBrush; @@ -2400,7 +2436,7 @@ bool wxListMainWindow::IsHighlighted(size_t line) const else // !virtual { wxListLineData *ld = GetLine(line); - wxCHECK_MSG( ld, FALSE, _T("invalid index in IsHighlighted") ); + wxCHECK_MSG( ld, false, _T("invalid index in IsHighlighted") ); return ld->IsHighlighted(); } @@ -2451,7 +2487,7 @@ bool wxListMainWindow::HighlightLine( size_t line, bool highlight ) else // !virtual { wxListLineData *ld = GetLine(line); - wxCHECK_MSG( ld, FALSE, _T("invalid index in HighlightLine") ); + wxCHECK_MSG( ld, false, _T("invalid index in HighlightLine") ); changed = ld->Highlight(highlight); } @@ -2545,7 +2581,7 @@ void wxListMainWindow::RefreshAfter( size_t lineFrom ) else // !report { // TODO: how to do it more efficiently? - m_dirty = TRUE; + m_dirty = true; } } @@ -2740,7 +2776,7 @@ void wxListMainWindow::HighlightAll( bool on ) // we just have one item to turn off if ( HasCurrent() && IsHighlighted(m_current) ) { - HighlightLine(m_current, FALSE); + HighlightLine(m_current, false); RefreshLine(m_current); } } @@ -2829,7 +2865,7 @@ bool wxListMainWindow::OnRenameAccept(size_t itemEdit, const wxString& value) le.m_itemIndex = itemEdit; wxListLineData *data = GetLine(itemEdit); - wxCHECK_MSG( data, FALSE, _T("invalid index in OnRenameAccept()") ); + wxCHECK_MSG( data, false, _T("invalid index in OnRenameAccept()") ); data->GetItem( 0, le.m_item ); le.m_item.m_text = value; @@ -2842,7 +2878,7 @@ void wxListMainWindow::OnRenameCancelled(size_t itemEdit) // let owner know that the edit was cancelled wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); - le.SetEditCanceled(TRUE); + le.SetEditCanceled(true); le.SetEventObject( GetParent() ); le.m_itemIndex = itemEdit; @@ -2861,6 +2897,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; @@ -2919,7 +2962,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 ); @@ -2936,11 +2979,11 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) return; } - bool forceClick = FALSE; + bool forceClick = false; if (event.ButtonDClick()) { m_renameTimer->Stop(); - m_lastOnSame = FALSE; + m_lastOnSame = false; if ( current == m_lineLastClicked ) { @@ -2950,26 +2993,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; + 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) + { + // select single line + HighlightAll( false ); + ReverseHighlight(m_lineSelectSingleOnUp); + } + if (m_lastOnSame) { - m_renameTimer->Start( 100, TRUE ); + if ((current == m_current) && + (hitResult == wxLIST_HITTEST_ONITEMLABEL) && + HasFlag(wxLC_EDIT_LABELS) ) + { + m_renameTimer->Start( 100, true ); + } } - m_lastOnSame = FALSE; + m_lastOnSame = false; + m_lineSelectSingleOnUp = (size_t) -1; } - else if (event.RightDown()) + else { + // This is necessary, 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()) { @@ -2981,18 +3054,28 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) m_lineLastClicked = current; size_t oldCurrent = m_current; + bool oldWasSelected = IsHighlighted(m_current); - if ( IsSingleSel() || !(event.ControlDown() || event.ShiftDown()) ) + 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 { - if (event.ControlDown()) + if (cmdModifierDown) { ChangeCurrent(current); @@ -3026,7 +3109,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) } // forceClick is only set if the previous click was on another item - m_lastOnSame = !forceClick && (m_current == oldCurrent); + m_lastOnSame = !forceClick && (m_current == oldCurrent) && oldWasSelected; } } @@ -3098,19 +3181,19 @@ void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event) { // all previously selected items are unselected unless ctrl is held if ( !event.ControlDown() ) - HighlightAll(FALSE); + HighlightAll(false); ChangeCurrent(newCurrent); - + // refresh the old focus to remove it RefreshLine( oldCurrent ); if ( !event.ControlDown() ) { - HighlightLine( m_current, TRUE ); + HighlightLine( m_current, true ); } } - + RefreshLine( m_current ); MoveToFocus(); @@ -3283,26 +3366,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 = FindFocus(); - - if ( oldFocus && oldFocus->GetParent() == this ) - { - wxWindow::SetFocus(); - } - else - { - wxScrolledWindow::SetFocus(); - } -} - void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) { if ( GetParent() ) @@ -3319,7 +3382,7 @@ void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) ) // it if ( !m_hasFocus ) { - m_hasFocus = TRUE; + m_hasFocus = true; RefreshSelected(); } @@ -3334,7 +3397,7 @@ void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) return; } - m_hasFocus = FALSE; + m_hasFocus = false; RefreshSelected(); } @@ -3396,7 +3459,7 @@ int wxListMainWindow::GetTextLength( const wxString &s ) const void wxListMainWindow::SetImageList( wxImageListType *imageList, int which ) { - m_dirty = TRUE; + m_dirty = true; // calc the spacing from the icon size int width = 0, @@ -3422,7 +3485,7 @@ void wxListMainWindow::SetImageList( wxImageListType *imageList, int which ) void wxListMainWindow::SetItemSpacing( int spacing, bool isSmall ) { - m_dirty = TRUE; + m_dirty = true; if (isSmall) { m_small_spacing = spacing; @@ -3456,9 +3519,9 @@ void wxListMainWindow::SetColumn( int col, wxListItem &item ) wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; if ( headerWin ) - headerWin->m_dirty = TRUE; + headerWin->m_dirty = true; - m_dirty = TRUE; + m_dirty = true; // invalidate it as it has to be recalculated m_headerWidth = 0; @@ -3472,10 +3535,10 @@ void wxListMainWindow::SetColumnWidth( int col, int width ) wxCHECK_RET( InReportView(), _T("SetColumnWidth() can only be called in report mode.") ); - m_dirty = TRUE; + m_dirty = true; wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; if ( headerWin ) - headerWin->m_dirty = TRUE; + headerWin->m_dirty = true; wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); wxCHECK_RET( node, _T("no column?") ); @@ -3502,34 +3565,30 @@ void wxListMainWindow::SetColumnWidth( int col, int width ) int max = AUTOSIZE_COL_MARGIN; - for ( size_t i = 0; i < count; i++ ) + // if the cached column width isn't valid then recalculate it + if (m_aColWidths.Item(col)->bNeedsUpdate) { - wxListLineData *line = GetLine(i); - wxListItemDataList::compatibility_iterator n = line->m_items.Item( col ); - - wxCHECK_RET( n, _T("no subitem?") ); + for (size_t i = 0; i < count; i++) + { + wxListLineData *line = GetLine(i); + wxListItemDataList::compatibility_iterator n = line->m_items.Item( col ); - wxListItemData *item = n->GetData(); - int current = 0; + wxCHECK_RET( n, _T("no subitem?") ); - if (item->HasImage()) - { - int ix, iy; - GetImageSize( item->GetImage(), ix, iy ); - current += ix + 5; - } + wxListItemData *itemData = n->GetData(); + wxListItem item; - if (item->HasText()) - { - wxCoord w; - dc.GetTextExtent( item->GetText(), &w, NULL ); - current += w; + itemData->GetItem(item); + int itemWidth = GetItemWidthWithImage(&item); + if (itemWidth > max) + max = itemWidth; } - if (current > max) - max = current; + m_aColWidths.Item(col)->bNeedsUpdate = false; + m_aColWidths.Item(col)->nMaxWidth = max; } + max = m_aColWidths.Item(col)->nMaxWidth; width = max + AUTOSIZE_COL_MARGIN; } } @@ -3588,6 +3647,15 @@ void wxListMainWindow::SetItem( wxListItem &item ) { wxListLineData *line = GetLine((size_t)id); line->SetItem( item.m_col, item ); + + if (InReportView()) + { + // update the Max Width Cache if needed + int width = GetItemWidthWithImage(&item); + + if (width > m_aColWidths.Item(item.m_col)->nMaxWidth) + m_aColWidths.Item(item.m_col)->nMaxWidth = width; + } } // update the item on screen @@ -3596,8 +3664,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") ); @@ -3618,7 +3736,7 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask ) { if ( IsSingleSel() ) { - HighlightLine(oldCurrent, FALSE); + HighlightLine(oldCurrent, false); } RefreshLine(oldCurrent); @@ -3639,7 +3757,7 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask ) // we must unselect the old current item as well or we // might end up with more than one selected item in a // single selection control - HighlightLine(oldCurrent, FALSE); + HighlightLine(oldCurrent, false); } RefreshLine( oldCurrent ); @@ -3664,7 +3782,7 @@ void wxListMainWindow::SetItemState( long litem, long state, long stateMask ) if ( oldCurrent != (size_t)-1 ) { - HighlightLine( oldCurrent, FALSE ); + HighlightLine( oldCurrent, false ); RefreshLine( oldCurrent ); } } @@ -3732,7 +3850,7 @@ void wxListMainWindow::SetItemCount(long count) ResetVisibleLinesRange(); // scrollbars must be reset - m_dirty = TRUE; + m_dirty = true; } int wxListMainWindow::GetSelectedItemCount() const @@ -3740,7 +3858,7 @@ int wxListMainWindow::GetSelectedItemCount() const // deal with the quick case first if ( IsSingleSel() ) { - return HasCurrent() ? IsHighlighted(m_current) : FALSE; + return HasCurrent() ? IsHighlighted(m_current) : false; } // virtual controls remmebers all its selections itself @@ -3813,7 +3931,7 @@ void wxListMainWindow::GetItemRect( long index, wxRect &rect ) const if ( m_dirty ) { wxConstCast(this, wxListMainWindow)-> - RecalculatePositions(TRUE /* no refresh */); + RecalculatePositions(true /* no refresh */); } rect = GetLineRect((size_t)index); @@ -3829,7 +3947,7 @@ bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const pos.x = rect.x; pos.y = rect.y; - return TRUE; + return true; } // ---------------------------------------------------------------------------- @@ -3852,7 +3970,7 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh) iconSpacing = 0; // Note that we do not call GetClientSize() here but - // GetSize() and substract the border size for sunken + // GetSize() and subtract the border size for sunken // borders manually. This is technically incorrect, // but we need to know the client area's size WITHOUT // scrollbars here. Since we don't know if there are @@ -3887,7 +4005,7 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh) (entireHeight + lineHeight - 1) / lineHeight, GetScrollPos(wxHORIZONTAL), GetScrollPos(wxVERTICAL), - TRUE ); + true ); } else // !report { @@ -3944,7 +4062,7 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh) (y + lineHeight) / lineHeight, GetScrollPos( wxHORIZONTAL ), GetScrollPos( wxVERTICAL ), - TRUE + true ); } else // "flowed" arrangement, the most complicated case @@ -4025,7 +4143,7 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh) 0, GetScrollPos( wxHORIZONTAL ), 0, - TRUE + true ); } } @@ -4041,13 +4159,13 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh) void wxListMainWindow::RefreshAll() { - m_dirty = FALSE; + m_dirty = false; Refresh(); wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin; if ( headerWin && headerWin->m_dirty ) { - headerWin->m_dirty = FALSE; + headerWin->m_dirty = false; headerWin->Refresh(); } } @@ -4126,6 +4244,26 @@ void wxListMainWindow::DeleteItem( long lindex ) if ( InReportView() ) { + // mark the Column Max Width cache as dirty if the items in the line + // we're deleting contain the Max Column Width + wxListLineData * const line = GetLine(index); + wxListItemDataList::compatibility_iterator n; + wxListItemData *itemData; + wxListItem item; + int itemWidth; + + for (size_t i = 0; i < m_columns.GetCount(); i++) + { + n = line->m_items.Item( i ); + itemData = n->GetData(); + itemData->GetItem(item); + + itemWidth = GetItemWidthWithImage(&item); + + if (itemWidth >= m_aColWidths.Item(i)->nMaxWidth) + m_aColWidths.Item(i)->bNeedsUpdate = true; + } + ResetVisibleLinesRange(); } @@ -4141,7 +4279,7 @@ void wxListMainWindow::DeleteItem( long lindex ) } // we need to refresh the (vert) scrollbar as the number of items changed - m_dirty = TRUE; + m_dirty = true; SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM ); @@ -4154,7 +4292,7 @@ void wxListMainWindow::DeleteColumn( int col ) wxCHECK_RET( node, wxT("invalid column index in DeleteColumn()") ); - m_dirty = TRUE; + m_dirty = true; delete node->GetData(); m_columns.Erase( node ); @@ -4170,6 +4308,12 @@ void wxListMainWindow::DeleteColumn( int col ) } } + if ( InReportView() ) // we only cache max widths when in Report View + { + delete m_aColWidths.Item(col); + m_aColWidths.RemoveAt(col); + } + // invalidate it as it has to be recalculated m_headerWidth = 0; } @@ -4203,6 +4347,10 @@ void wxListMainWindow::DoDeleteAllItems() if ( InReportView() ) { ResetVisibleLinesRange(); + for (size_t i = 0; i < m_aColWidths.GetCount(); i++) + { + m_aColWidths.Item(i)->bNeedsUpdate = true; + } } m_lines.Clear(); @@ -4218,6 +4366,7 @@ void wxListMainWindow::DeleteAllItems() void wxListMainWindow::DeleteEverything() { WX_CLEAR_LIST(wxListHeaderDataList, m_columns); + WX_CLEAR_ARRAY(m_aColWidths); DeleteAllItems(); } @@ -4235,7 +4384,7 @@ void wxListMainWindow::EnsureVisible( long index ) // been added and its position is not known yet if ( m_dirty ) { - RecalculatePositions(TRUE /* no refresh */); + RecalculatePositions(true /* no refresh */); } MoveToItem((size_t)index); @@ -4259,7 +4408,7 @@ long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(p return wxNOT_FOUND; } -long wxListMainWindow::FindItem(long start, long data) +long wxListMainWindow::FindItem(long start, wxUIntPtr data) { long pos = start; if (pos < 0) @@ -4278,6 +4427,22 @@ long wxListMainWindow::FindItem(long start, long data) return wxNOT_FOUND; } +long wxListMainWindow::FindItem( const wxPoint& pt ) +{ + size_t topItem; + GetVisibleLinesRange(&topItem, NULL); + + wxPoint p; + GetItemPosition( GetItemCount()-1, p ); + if( p.y == 0 ) + return topItem; + long id = (long) floor( pt.y*double(GetItemCount()-topItem-1)/p.y+topItem ); + if( id >= 0 && id < (long)GetItemCount() ) + return id; + + return wxNOT_FOUND; +} + long wxListMainWindow::HitTest( int x, int y, int &flags ) { CalcUnscrolledPosition( x, y, &x, &y ); @@ -4317,59 +4482,35 @@ void wxListMainWindow::InsertItem( wxListItem &item ) { wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") ); - size_t count = GetItemCount(); - wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId <= count, - _T("invalid item index") ); + int count = GetItemCount(); + wxCHECK_RET( item.m_itemId >= 0, _T("invalid item index") ); + + if (item.m_itemId > count) + item.m_itemId = count; size_t id = item.m_itemId; - m_dirty = TRUE; + m_dirty = true; - #if 0 - // this is unused variable - int mode = 0; - #endif if ( InReportView() ) { - #if 0 - // this is unused variable - mode = wxLC_REPORT; - #endif ResetVisibleLinesRange(); - } - else if ( HasFlag(wxLC_LIST) ) - #if 0 - // this is unused variable - mode = wxLC_LIST; - #else - {} - #endif - else if ( HasFlag(wxLC_ICON) ) - #if 0 - // this is unused variable - mode = wxLC_ICON; - #else - {} - #endif - else if ( HasFlag(wxLC_SMALL_ICON) ) - #if 0 - // this is unused variable - mode = wxLC_ICON; // no typo - #else - {} - #endif - else - { - wxFAIL_MSG( _T("unknown mode") ); + + // calculate the width of the item and adjust the max column width + wxColWidthInfo *pWidthInfo = m_aColWidths.Item(item.GetColumn()); + int width = GetItemWidthWithImage(&item); + item.SetWidth(width); + if (width > pWidthInfo->nMaxWidth) + pWidthInfo->nMaxWidth = width; } wxListLineData *line = new wxListLineData(this); - line->SetItem( 0, item ); + line->SetItem( item.m_col, item ); m_lines.Insert( line, id ); - m_dirty = TRUE; + m_dirty = true; // If an item is selected at or below the point of insertion, we need to // increment the member variables because the current row's index has gone @@ -4386,22 +4527,27 @@ void wxListMainWindow::InsertItem( wxListItem &item ) void wxListMainWindow::InsertColumn( long col, wxListItem &item ) { - m_dirty = TRUE; + m_dirty = true; if ( InReportView() ) { if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text ); wxListHeaderData *column = new wxListHeaderData( item ); + wxColWidthInfo *colWidthInfo = new wxColWidthInfo(); + bool insert = (col >= 0) && ((size_t)col < m_columns.GetCount()); if ( insert ) { - wxListHeaderDataList::compatibility_iterator node = m_columns.Item( col ); + wxListHeaderDataList::compatibility_iterator + node = m_columns.Item( col ); m_columns.Insert( node, column ); + m_aColWidths.Insert( colWidthInfo, col ); } else { m_columns.Append( column ); + m_aColWidths.Add( colWidthInfo ); } if ( !IsVirtual() ) @@ -4423,6 +4569,30 @@ void wxListMainWindow::InsertColumn( long col, wxListItem &item ) } } +int wxListMainWindow::GetItemWidthWithImage(wxListItem * item) +{ + int width = 0; + wxClientDC dc(this); + + dc.SetFont( GetFont() ); + + if (item->GetImage() != -1) + { + int ix, iy; + GetImageSize( item->GetImage(), ix, iy ); + width += ix + 5; + } + + if (!item->GetText().empty()) + { + wxCoord w; + dc.GetTextExtent( item->GetText(), &w, NULL ); + width += w; + } + + return width; +} + // ---------------------------------------------------------------------------- // sorting // ---------------------------------------------------------------------------- @@ -4436,9 +4606,9 @@ int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData wxListLineData *line2 = *arg2; wxListItem item; line1->GetItem( 0, item ); - long data1 = item.m_data; + wxUIntPtr data1 = item.m_data; line2->GetItem( 0, item ); - long data2 = item.m_data; + wxUIntPtr data2 = item.m_data; return list_ctrl_compare_func_2( data1, data2, list_ctrl_compare_data ); } @@ -4447,7 +4617,7 @@ void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data ) list_ctrl_compare_func_2 = fn; list_ctrl_compare_data = data; m_lines.Sort( list_ctrl_compare_func_1 ); - m_dirty = TRUE; + m_dirty = true; } // ---------------------------------------------------------------------------- @@ -4461,7 +4631,7 @@ void wxListMainWindow::OnScroll(wxScrollWinEvent& event) ResetVisibleLinesRange(); // FIXME -#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) +#if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__) wxScrolledWindow::OnScroll(event); #else HandleOnScroll( event ); @@ -4544,7 +4714,7 @@ wxGenericListCtrl::wxGenericListCtrl() m_ownsImageListNormal = m_ownsImageListSmall = - m_ownsImageListState = FALSE; + m_ownsImageListState = false; m_mainWin = (wxListMainWindow*) NULL; m_headerWin = (wxListHeaderWindow*) NULL; @@ -4565,11 +4735,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 ) { @@ -4578,7 +4752,7 @@ void wxGenericListCtrl::CalculateAndSetHeaderHeight() m_headerWin->SetSize(m_headerWin->GetSize().x, m_headerHeight); if ( HasHeader() ) - ResizeReportView(TRUE); + ResizeReportView(true); } } } @@ -4587,8 +4761,8 @@ void wxGenericListCtrl::CreateHeaderWindow() { m_headerWin = new wxListHeaderWindow ( - this, -1, m_mainWin, - wxPoint(0, 0), + this, wxID_ANY, m_mainWin, + wxPoint(0,0), wxSize(GetClientSize().x, m_headerHeight), wxTAB_TRAVERSAL ); @@ -4608,7 +4782,7 @@ bool wxGenericListCtrl::Create(wxWindow *parent, m_imageListState = (wxImageListType *) NULL; m_ownsImageListNormal = m_ownsImageListSmall = - m_ownsImageListState = FALSE; + m_ownsImageListState = false; m_mainWin = (wxListMainWindow*) NULL; m_headerWin = (wxListHeaderWindow*) NULL; @@ -4621,32 +4795,44 @@ bool wxGenericListCtrl::Create(wxWindow *parent, } if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) ) - return FALSE; + return false; // don't create the inner window with the border style &= ~wxBORDER_MASK; - m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, style ); + m_mainWin = new wxListMainWindow( this, wxID_ANY, wxPoint(0,0), size, style ); -#if defined( __WXMAC__ ) && __WXMAC_CARBON__ - wxFont font ; - font.MacCreateThemeFont( kThemeViewsFont ) ; - SetFont( font ) ; +#ifdef __WXMAC_CARBON__ + // Human Interface Guidelines ask us for a special font in this case + if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ) + { + wxFont font ; + font.MacCreateThemeFont( kThemeViewsFont ) ; + SetFont( font ) ; + } #endif 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? - m_headerWin->Show( FALSE ); + m_headerWin->Show( false ); } } SetBestSize(size); - - return TRUE; + + return true; } void wxGenericListCtrl::SetSingleStyle( long style, bool add ) @@ -4696,7 +4882,7 @@ void wxGenericListCtrl::SetWindowStyleFlag( long flag ) if ( m_headerWin ) { // don't delete, just hide, as we can reuse it later - m_headerWin->Show(FALSE); + m_headerWin->Show(false); } //else: nothing to do } @@ -4708,7 +4894,7 @@ void wxGenericListCtrl::SetWindowStyleFlag( long flag ) } else // already have it, just show { - m_headerWin->Show( TRUE ); + m_headerWin->Show( true ); } } @@ -4722,13 +4908,13 @@ void wxGenericListCtrl::SetWindowStyleFlag( long flag ) bool wxGenericListCtrl::GetColumn(int col, wxListItem &item) const { m_mainWin->GetColumn( col, item ); - return TRUE; + return true; } bool wxGenericListCtrl::SetColumn( int col, wxListItem& item ) { m_mainWin->SetColumn( col, item ); - return TRUE; + return true; } int wxGenericListCtrl::GetColumnWidth( int col ) const @@ -4739,7 +4925,7 @@ int wxGenericListCtrl::GetColumnWidth( int col ) const bool wxGenericListCtrl::SetColumnWidth( int col, int width ) { m_mainWin->SetColumnWidth( col, width ); - return TRUE; + return true; } int wxGenericListCtrl::GetCountPerPage() const @@ -4750,13 +4936,13 @@ int wxGenericListCtrl::GetCountPerPage() const bool wxGenericListCtrl::GetItem( wxListItem &info ) const { m_mainWin->GetItem( info ); - return TRUE; + return true; } bool wxGenericListCtrl::SetItem( wxListItem &info ) { m_mainWin->SetItem( info ); - return TRUE; + return true; } long wxGenericListCtrl::SetItem( long index, int col, const wxString& label, int imageId ) @@ -4772,7 +4958,7 @@ long wxGenericListCtrl::SetItem( long index, int col, const wxString& label, int info.m_mask |= wxLIST_MASK_IMAGE; }; m_mainWin->SetItem(info); - return TRUE; + return true; } int wxGenericListCtrl::GetItemState( long item, long stateMask ) const @@ -4783,17 +4969,18 @@ int wxGenericListCtrl::GetItemState( long item, long stateMask ) const bool wxGenericListCtrl::SetItemState( long item, long state, long stateMask ) { m_mainWin->SetItemState( item, state, stateMask ); - return TRUE; + return true; } -bool wxGenericListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) ) +bool +wxGenericListCtrl::SetItemImage( long item, int image, int WXUNUSED(selImage) ) { wxListItem info; info.m_image = image; info.m_mask = wxLIST_MASK_IMAGE; info.m_itemId = item; m_mainWin->SetItem( info ); - return TRUE; + return true; } wxString wxGenericListCtrl::GetItemText( long item ) const @@ -4806,7 +4993,7 @@ void wxGenericListCtrl::SetItemText( long item, const wxString& str ) m_mainWin->SetItemText(item, str); } -long wxGenericListCtrl::GetItemData( long item ) const +wxUIntPtr wxGenericListCtrl::GetItemData( long item ) const { wxListItem info; info.m_itemId = item; @@ -4821,7 +5008,7 @@ bool wxGenericListCtrl::SetItemData( long item, long data ) info.m_itemId = item; info.m_data = data; m_mainWin->SetItem( info ); - return TRUE; + return true; } wxRect wxGenericListCtrl::GetViewRect() const @@ -4834,13 +5021,13 @@ bool wxGenericListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code m_mainWin->GetItemRect( item, rect ); if ( m_mainWin->HasHeader() ) rect.y += m_headerHeight + 1; - return TRUE; + return true; } bool wxGenericListCtrl::GetItemPosition( long item, wxPoint& pos ) const { m_mainWin->GetItemPosition( item, pos ); - return TRUE; + return true; } bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) ) @@ -4957,19 +5144,19 @@ void wxGenericListCtrl::SetImageList( wxImageListType *imageList, int which ) { if (m_ownsImageListNormal) delete m_imageListNormal; m_imageListNormal = imageList; - m_ownsImageListNormal = FALSE; + m_ownsImageListNormal = false; } else if ( which == wxIMAGE_LIST_SMALL ) { if (m_ownsImageListSmall) delete m_imageListSmall; m_imageListSmall = imageList; - m_ownsImageListSmall = FALSE; + m_ownsImageListSmall = false; } else if ( which == wxIMAGE_LIST_STATE ) { if (m_ownsImageListState) delete m_imageListState; m_imageListState = imageList; - m_ownsImageListState = FALSE; + m_ownsImageListState = false; } m_mainWin->SetImageList( imageList, which ); @@ -4979,11 +5166,11 @@ void wxGenericListCtrl::AssignImageList(wxImageListType *imageList, int which) { SetImageList(imageList, which); if ( which == wxIMAGE_LIST_NORMAL ) - m_ownsImageListNormal = TRUE; + m_ownsImageListNormal = true; else if ( which == wxIMAGE_LIST_SMALL ) - m_ownsImageListSmall = TRUE; + m_ownsImageListSmall = true; else if ( which == wxIMAGE_LIST_STATE ) - m_ownsImageListState = TRUE; + m_ownsImageListState = true; } bool wxGenericListCtrl::Arrange( int WXUNUSED(flag) ) @@ -4994,13 +5181,13 @@ bool wxGenericListCtrl::Arrange( int WXUNUSED(flag) ) bool wxGenericListCtrl::DeleteItem( long item ) { m_mainWin->DeleteItem( item ); - return TRUE; + return true; } bool wxGenericListCtrl::DeleteAllItems() { m_mainWin->DeleteAllItems(); - return TRUE; + return true; } bool wxGenericListCtrl::DeleteAllColumns() @@ -5009,7 +5196,7 @@ bool wxGenericListCtrl::DeleteAllColumns() for ( size_t n = 0; n < count; n++ ) DeleteColumn(0); - return TRUE; + return true; } void wxGenericListCtrl::ClearAll() @@ -5024,10 +5211,10 @@ bool wxGenericListCtrl::DeleteColumn( int col ) // if we don't have the header any longer, we need to relayout the window if ( !GetColumnCount() ) { - ResizeReportView(FALSE /* no header */); + ResizeReportView(false /* no header */); } - return TRUE; + return true; } void wxGenericListCtrl::Edit( long item ) @@ -5038,7 +5225,7 @@ void wxGenericListCtrl::Edit( long item ) bool wxGenericListCtrl::EnsureVisible( long item ) { m_mainWin->EnsureVisible( item ); - return TRUE; + return true; } long wxGenericListCtrl::FindItem( long start, const wxString& str, bool partial ) @@ -5046,15 +5233,15 @@ long wxGenericListCtrl::FindItem( long start, const wxString& str, bool partial return m_mainWin->FindItem( start, str, partial ); } -long wxGenericListCtrl::FindItem( long start, long data ) +long wxGenericListCtrl::FindItem( long start, wxUIntPtr data ) { return m_mainWin->FindItem( start, data ); } -long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt), +long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& pt, int WXUNUSED(direction)) { - return 0; + return m_mainWin->FindItem( pt ); } long wxGenericListCtrl::HitTest( const wxPoint &point, int &flags ) @@ -5106,7 +5293,7 @@ long wxGenericListCtrl::InsertColumn( long col, wxListItem &item ) // window if ( GetColumnCount() == 1 && m_mainWin->HasHeader() ) { - ResizeReportView(TRUE /* have header */); + ResizeReportView(true /* have header */); } m_headerWin->Refresh(); @@ -5148,7 +5335,7 @@ bool wxGenericListCtrl::ScrollList( int WXUNUSED(dx), int WXUNUSED(dy) ) bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn, long data ) { m_mainWin->SortItems( fn, data ); - return TRUE; + return true; } // ---------------------------------------------------------------------------- @@ -5201,21 +5388,21 @@ bool wxGenericListCtrl::SetBackgroundColour( const wxColour &colour ) if (m_mainWin) { m_mainWin->SetBackgroundColour( colour ); - m_mainWin->m_dirty = TRUE; + m_mainWin->m_dirty = true; } - return TRUE; + return true; } bool wxGenericListCtrl::SetForegroundColour( const wxColour &colour ) { if ( !wxWindow::SetForegroundColour( colour ) ) - return FALSE; + return false; if (m_mainWin) { m_mainWin->SetForegroundColour( colour ); - m_mainWin->m_dirty = TRUE; + m_mainWin->m_dirty = true; } if (m_headerWin) @@ -5223,18 +5410,18 @@ bool wxGenericListCtrl::SetForegroundColour( const wxColour &colour ) m_headerWin->SetForegroundColour( colour ); } - return TRUE; + return true; } bool wxGenericListCtrl::SetFont( const wxFont &font ) { if ( !wxWindow::SetFont( font ) ) - return FALSE; + return false; if (m_mainWin) { m_mainWin->SetFont( font ); - m_mainWin->m_dirty = TRUE; + m_mainWin->m_dirty = true; } if (m_headerWin) @@ -5245,7 +5432,7 @@ bool wxGenericListCtrl::SetFont( const wxFont &font ) Refresh(); - return TRUE; + return true; } @@ -5291,7 +5478,7 @@ wxDropTarget *wxGenericListCtrl::GetDropTarget() const bool wxGenericListCtrl::SetCursor( const wxCursor &cursor ) { - return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : FALSE; + return m_mainWin ? m_mainWin->wxWindow::SetCursor(cursor) : false; } wxColour wxGenericListCtrl::GetBackgroundColour() const @@ -5309,7 +5496,7 @@ bool wxGenericListCtrl::DoPopupMenu( wxMenu *menu, int x, int y ) #if wxUSE_MENUS return m_mainWin->PopupMenu( menu, x, y ); #else - return FALSE; + return false; #endif // wxUSE_MENUS } @@ -5317,10 +5504,18 @@ void wxGenericListCtrl::SetFocus() { /* The test in window.cpp fails as we are a composite window, so it checks against "this", but not m_mainWin. */ - if ( FindFocus() != this ) + if ( DoFindFocus() != this ) m_mainWin->SetFocus(); } +wxSize wxGenericListCtrl::DoGetBestSize() const +{ + // Something is better than nothing... + // 100x80 is what the MSW version will get from the default + // wxControl::DoGetBestSize + return wxSize(100,80); +} + // ---------------------------------------------------------------------------- // virtual list control support // ---------------------------------------------------------------------------- @@ -5336,9 +5531,9 @@ wxString wxGenericListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col int wxGenericListCtrl::OnGetItemImage(long WXUNUSED(item)) const { - // same as above - wxFAIL_MSG( _T("wxGenericListCtrl::OnGetItemImage not supposed to be called") ); - + wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL), + -1, + wxT("List control has an image list, OnGetItemImage should be overridden.")); return -1; }