X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fa47d7a7ad7f37b0a3304e10a440ed791c387933..3549217b2467279abf72eff8fb5745cdf61f2482:/src/generic/listctrl.cpp diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index c561337dae..dece7fb5eb 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -76,6 +76,9 @@ #include "wx/mac/private.h" #endif +#include + + // 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 +94,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) @@ -161,7 +166,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 +205,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 @@ -514,6 +519,8 @@ public: const wxString &name = _T("listctrlmainwindow") ); virtual ~wxListMainWindow(); + + wxWindow *GetMainWindowOfCompositeControl() { return GetParent(); } bool HasFlag(int flag) const { return m_parent->HasFlag(flag); } @@ -676,7 +683,8 @@ public: 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, 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 ); @@ -1668,11 +1676,13 @@ wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes(); SetOwnForegroundColour( attr.colFg ); SetOwnBackgroundColour( attr.colBg ); - SetOwnFont( attr.font ); + if (!m_hasFont) + SetOwnFont( attr.font ); #else SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); - SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT )); + if (!m_hasFont) + SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT )); #endif } @@ -2068,12 +2078,14 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event ) switch ( event.m_keyCode ) { case WXK_RETURN: - if ( !AcceptChanges() ) + if ( AcceptChanges() ) { - // vetoed by the user code - break; + // Close the text control, changes were accepted + Finish(); } - //else: fall through + // else do nothing, do not accept and do not close + + break; case WXK_ESCAPE: Finish(); @@ -2103,7 +2115,7 @@ void wxListTextCtrl::OnKeyUp( wxKeyEvent &event ) sx = parentSize.x - myPos.x; if (mySize.x > sx) sx = mySize.x; - SetSize(sx, wxDefaultSize.y); + SetSize(sx, wxDefaultCoord); event.Skip(); } @@ -2112,13 +2124,16 @@ void wxListTextCtrl::OnKillFocus( wxFocusEvent &event ) { if ( !m_finished ) { - // 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(); } @@ -2214,7 +2229,8 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxVisualAttributes attr = wxGenericListCtrl::GetClassDefaultAttributes(); SetOwnForegroundColour( attr.colFg ); SetOwnBackgroundColour( attr.colBg ); - SetOwnFont( attr.font ); + if (!m_hasFont) + SetOwnFont( attr.font ); } wxListMainWindow::~wxListMainWindow() @@ -2981,12 +2997,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) m_lineLastClicked = current; size_t oldCurrent = m_current; - bool cmdModifierDown; -#ifdef __WXMAC__ - cmdModifierDown = event.MetaDown(); -#else - cmdModifierDown = event.ControlDown(); -#endif + bool cmdModifierDown = event.CmdDown(); if ( IsSingleSel() || !(cmdModifierDown || event.ShiftDown()) ) { HighlightAll( false ); @@ -3296,7 +3307,7 @@ void wxListMainWindow::SetFocus() // focus to the panel from wxListTextCtrl because the text control should // disappear when the user clicks outside it. - wxWindow *oldFocus = FindFocus(); + wxWindow *oldFocus = DoFindFocus(); if ( oldFocus && oldFocus->GetParent() == this ) { @@ -3857,7 +3868,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 @@ -4264,7 +4275,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) @@ -4283,6 +4294,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 ); @@ -4322,10 +4349,12 @@ 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; @@ -4370,7 +4399,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 ); @@ -4441,9 +4470,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 ); } @@ -4633,10 +4662,14 @@ bool wxGenericListCtrl::Create(wxWindow *parent, 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() ) { @@ -4791,7 +4824,8 @@ bool wxGenericListCtrl::SetItemState( long item, long state, long stateMask ) 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; @@ -4811,7 +4845,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; @@ -5051,15 +5085,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 ) @@ -5322,10 +5356,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 // ---------------------------------------------------------------------------- @@ -5341,9 +5383,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; }