X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5c33522fca7cddc441a316f5b9fb50d7685435ba..cdbd62d6ff290fd58acd1bc5574dfc79db3a6f70:/src/osx/carbon/listctrl_mac.cpp diff --git a/src/osx/carbon/listctrl_mac.cpp b/src/osx/carbon/listctrl_mac.cpp index 655502d3a9..c9084e057e 100644 --- a/src/osx/carbon/listctrl_mac.cpp +++ b/src/osx/carbon/listctrl_mac.cpp @@ -4,7 +4,6 @@ // Author: Julian Smart // Modified by: Agron Selimaj // Created: 04/01/98 -// RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -41,79 +40,6 @@ #include "wx/hashmap.h" -#if wxUSE_EXTENDED_RTTI -WX_DEFINE_FLAGS( wxListCtrlStyle ) - -wxBEGIN_FLAGS( wxListCtrlStyle ) - // new style border flags, we put them first to - // use them for streaming out - wxFLAGS_MEMBER(wxBORDER_SIMPLE) - wxFLAGS_MEMBER(wxBORDER_SUNKEN) - wxFLAGS_MEMBER(wxBORDER_DOUBLE) - wxFLAGS_MEMBER(wxBORDER_RAISED) - wxFLAGS_MEMBER(wxBORDER_STATIC) - wxFLAGS_MEMBER(wxBORDER_NONE) - - // old style border flags - wxFLAGS_MEMBER(wxSIMPLE_BORDER) - wxFLAGS_MEMBER(wxSUNKEN_BORDER) - wxFLAGS_MEMBER(wxDOUBLE_BORDER) - wxFLAGS_MEMBER(wxRAISED_BORDER) - wxFLAGS_MEMBER(wxSTATIC_BORDER) - wxFLAGS_MEMBER(wxBORDER) - - // standard window styles - wxFLAGS_MEMBER(wxTAB_TRAVERSAL) - wxFLAGS_MEMBER(wxCLIP_CHILDREN) - wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) - wxFLAGS_MEMBER(wxWANTS_CHARS) - wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) - wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) - wxFLAGS_MEMBER(wxVSCROLL) - wxFLAGS_MEMBER(wxHSCROLL) - - wxFLAGS_MEMBER(wxLC_LIST) - wxFLAGS_MEMBER(wxLC_REPORT) - wxFLAGS_MEMBER(wxLC_ICON) - wxFLAGS_MEMBER(wxLC_SMALL_ICON) - wxFLAGS_MEMBER(wxLC_ALIGN_TOP) - wxFLAGS_MEMBER(wxLC_ALIGN_LEFT) - wxFLAGS_MEMBER(wxLC_AUTOARRANGE) - wxFLAGS_MEMBER(wxLC_USER_TEXT) - wxFLAGS_MEMBER(wxLC_EDIT_LABELS) - wxFLAGS_MEMBER(wxLC_NO_HEADER) - wxFLAGS_MEMBER(wxLC_SINGLE_SEL) - wxFLAGS_MEMBER(wxLC_SORT_ASCENDING) - wxFLAGS_MEMBER(wxLC_SORT_DESCENDING) - wxFLAGS_MEMBER(wxLC_VIRTUAL) - -wxEND_FLAGS( wxListCtrlStyle ) - -IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl, wxControl,"wx/listctrl.h") - -wxBEGIN_PROPERTIES_TABLE(wxListCtrl) - wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent ) - - wxPROPERTY_FLAGS( WindowStyle , wxListCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style -wxEND_PROPERTIES_TABLE() - -wxBEGIN_HANDLERS_TABLE(wxListCtrl) -wxEND_HANDLERS_TABLE() - -wxCONSTRUCTOR_5( wxListCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle ) - -/* - TODO : Expose more information of a list's layout etc. via appropriate objects (ï¿  la NotebookPageInfo) -*/ -#else -IMPLEMENT_DYNAMIC_CLASS(wxListCtrl, wxControl) -#endif - -IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl) -IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) - -IMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent) - WX_DECLARE_HASH_MAP( int, wxListItem*, wxIntegerHash, wxIntegerEqual, wxListItemList ); #include "wx/listimpl.cpp" @@ -136,7 +62,7 @@ static pascal OSStatus wxMacListCtrlEventHandler( EventHandlerCallRef handler , cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; wxListCtrl *window = (wxListCtrl*) data ; - wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, window->GetId() ); + wxListEvent le( wxEVT_LIST_COL_CLICK, window->GetId() ); le.SetEventObject( window ); switch ( GetEventKind( event ) ) @@ -148,7 +74,10 @@ static pascal OSStatus wxMacListCtrlEventHandler( EventHandlerCallRef handler , if (result == kControlButtonPart){ DataBrowserPropertyID col; GetDataBrowserSortProperty(controlRef, &col); - int column = col - kMinColumnId; + + DataBrowserTableViewColumnIndex column = 0; + verify_noerr( GetDataBrowserTableViewColumnPosition( controlRef, col, &column ) ); + le.m_col = column; // FIXME: we can't use the sort property for virtual listctrls // so we need to find a better way to determine which column was clicked... @@ -297,6 +226,9 @@ wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl* list, int id bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent& event ) { + int id = event.GetId(); + wxObject* obj = event.GetEventObject(); + // even though we use a generic list ctrl underneath, make sure // we present ourselves as wxListCtrl. event.SetEventObject( m_list ); @@ -304,10 +236,20 @@ bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent& event ) if ( !event.IsKindOf( CLASSINFO( wxCommandEvent ) ) ) { - if (m_list->HandleWindowEvent( event )) + if (m_list->GetEventHandler()->ProcessEvent( event )) + { + event.SetId(id); + event.SetEventObject(obj); return true; + } } - return wxEvtHandler::ProcessEvent(event); + // Also try with the original id + bool success = wxEvtHandler::ProcessEvent(event); + event.SetId(id); + event.SetEventObject(obj); + if (!success && id != m_id) + success = wxEvtHandler::ProcessEvent(event); + return success; } //----------------------------------------------------------------------------- @@ -479,7 +421,7 @@ void wxListCtrlTextCtrlWrapper::OnKeyUp( wxKeyEvent &event ) wxPoint myPos = m_text->GetPosition(); wxSize mySize = m_text->GetSize(); int sx, sy; - m_text->GetTextExtent(m_text->GetValue() + _T("MM"), &sx, &sy); + m_text->GetTextExtent(m_text->GetValue() + wxT("MM"), &sx, &sy); if (myPos.x + sx > parentSize.x) sx = parentSize.x - myPos.x; if (mySize.x > sx) @@ -503,14 +445,6 @@ void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent &event ) event.Skip(); } -BEGIN_EVENT_TABLE(wxListCtrl, wxControl) - EVT_LEFT_DOWN(wxListCtrl::OnLeftDown) - EVT_LEFT_DCLICK(wxListCtrl::OnDblClick) - EVT_MIDDLE_DOWN(wxListCtrl::OnMiddleDown) - EVT_RIGHT_DOWN(wxListCtrl::OnRightDown) - EVT_CHAR(wxListCtrl::OnChar) -END_EVENT_TABLE() - // ============================================================================ // implementation // ============================================================================ @@ -545,7 +479,7 @@ void wxListCtrl::Init() m_bgColor = wxNullColour; m_textctrlWrapper = NULL; m_current = -1; - m_renameTimer = new wxListCtrlRenameTimer( this ); + m_renameTimer = NULL; } class wxGenericListCtrlHook : public wxGenericListCtrl @@ -599,10 +533,11 @@ void wxListCtrl::OnLeftDown(wxMouseEvent& event) int hitResult; long current = HitTest(event.GetPosition(), hitResult); if ((current == m_current) && - (hitResult == wxLIST_HITTEST_ONITEM) && + (hitResult & wxLIST_HITTEST_ONITEMLABEL) && HasFlag(wxLC_EDIT_LABELS) ) { - m_renameTimer->Start( 100, true ); + if ( m_renameTimer ) + m_renameTimer->Start( 250, true ); } else { @@ -613,7 +548,8 @@ void wxListCtrl::OnLeftDown(wxMouseEvent& event) void wxListCtrl::OnDblClick(wxMouseEvent& event) { - m_current = -1; + if ( m_renameTimer && m_renameTimer->IsRunning() ) + m_renameTimer->Stop(); event.Skip(); } @@ -621,14 +557,14 @@ void wxListCtrl::OnDblClick(wxMouseEvent& event) void wxListCtrl::OnRightDown(wxMouseEvent& event) { if (m_dbImpl) - FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, event.GetPosition()); + FireMouseEvent(wxEVT_LIST_ITEM_RIGHT_CLICK, event.GetPosition()); event.Skip(); } void wxListCtrl::OnMiddleDown(wxMouseEvent& event) { if (m_dbImpl) - FireMouseEvent(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, event.GetPosition()); + FireMouseEvent(wxEVT_LIST_ITEM_MIDDLE_CLICK, event.GetPosition()); event.Skip(); } @@ -653,21 +589,21 @@ void wxListCtrl::FireMouseEvent(wxEventType eventType, wxPoint position) void wxListCtrl::OnChar(wxKeyEvent& event) { - + if (m_dbImpl) { - wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetId() ); + wxListEvent le( wxEVT_LIST_KEY_DOWN, GetId() ); le.SetEventObject(this); le.m_code = event.GetKeyCode(); le.m_itemIndex = -1; - + if (m_current == -1) { // if m_current isn't set, check if there's been a selection // made before continuing m_current = GetNextItem(-1, wxLIST_NEXT_BELOW, wxLIST_STATE_SELECTED); } - + // We need to determine m_current ourselves when navigation keys // are used. Note that PAGEUP and PAGEDOWN do not alter the current // item on native Mac ListCtrl, so we only handle up and down keys. @@ -678,7 +614,7 @@ void wxListCtrl::OnChar(wxKeyEvent& event) m_current -= 1; else m_current = 0; - + break; case WXK_DOWN: @@ -686,7 +622,7 @@ void wxListCtrl::OnChar(wxKeyEvent& event) m_current += 1; else m_current = GetItemCount() - 1; - + break; } @@ -718,8 +654,6 @@ bool wxListCtrl::Create(wxWindow *parent, && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL ) == 1)) || (style & wxLC_ICON) || (style & wxLC_SMALL_ICON) || (style & wxLC_LIST) ) { - m_macIsUserPane = true; - long paneStyle = style; paneStyle &= ~wxSIMPLE_BORDER; paneStyle &= ~wxDOUBLE_BORDER; @@ -737,17 +671,25 @@ bool wxListCtrl::Create(wxWindow *parent, else { - m_macIsUserPane = false; + DontCreatePeer(); if ( !wxWindow::Create(parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), name) ) return false; m_dbImpl = new wxMacDataBrowserListCtrlControl( this, pos, size, style ); - m_peer = m_dbImpl; + SetPeer(m_dbImpl); MacPostControlCreate( pos, size ); - InstallControlEventHandler( m_peer->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(), + InstallControlEventHandler( GetPeer()->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(), GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macListCtrlEventHandler); + + m_renameTimer = new wxListCtrlRenameTimer( this ); + + Connect( wxID_ANY, wxEVT_CHAR, wxCharEventHandler(wxListCtrl::OnChar), NULL, this ); + Connect( wxID_ANY, wxEVT_LEFT_DOWN, wxMouseEventHandler(wxListCtrl::OnLeftDown), NULL, this ); + Connect( wxID_ANY, wxEVT_LEFT_DCLICK, wxMouseEventHandler(wxListCtrl::OnDblClick), NULL, this ); + Connect( wxID_ANY, wxEVT_MIDDLE_DOWN, wxMouseEventHandler(wxListCtrl::OnMiddleDown), NULL, this ); + Connect( wxID_ANY, wxEVT_RIGHT_DOWN, wxMouseEventHandler(wxListCtrl::OnRightDown), NULL, this ); } return true; @@ -768,7 +710,7 @@ wxListCtrl::~wxListCtrl() delete m_imageListState; delete m_renameTimer; - + WX_CLEAR_LIST(wxColumnList, m_colsInfo); } @@ -780,7 +722,8 @@ wxListCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); - attr.font.MacCreateFromThemeFont(kThemeViewsFont); + static wxFont font = wxFont(wxOSX_SYSTEM_FONT_VIEWS); + attr.font = font; return attr; } @@ -831,7 +774,7 @@ void wxListCtrl::SetWindowStyleFlag(long flag) void wxListCtrl::DoSetSize( int x, int y, int width, int height, int sizeFlags ) { - wxControl::DoSetSize(x, y, width, height, sizeFlags); + wxListCtrlBase::DoSetSize(x, y, width, height, sizeFlags); if (m_genericImpl) m_genericImpl->SetSize(0, 0, width, height, sizeFlags); @@ -857,15 +800,9 @@ void wxListCtrl::DoSetSize( int x, int y, int width, int height, int sizeFlags ) } } -wxSize wxListCtrl::DoGetBestSize() const -{ - return wxWindow::DoGetBestSize(); -} - bool wxListCtrl::SetFont(const wxFont& font) { - bool rv = true; - rv = wxControl::SetFont(font); + bool rv = wxListCtrlBase::SetFont(font); if (m_genericImpl) rv = m_genericImpl->SetFont(font); return rv; @@ -901,6 +838,27 @@ wxColour wxListCtrl::GetBackgroundColour() const return wxNullColour; } +void wxListCtrl::Freeze () +{ + if (m_genericImpl) + m_genericImpl->Freeze(); + wxListCtrlBase::Freeze(); +} + +void wxListCtrl::Thaw () +{ + if (m_genericImpl) + m_genericImpl->Thaw(); + wxListCtrlBase::Thaw(); +} + +void wxListCtrl::Update () +{ + if (m_genericImpl) + m_genericImpl->Update(); + wxListCtrlBase::Update(); +} + // ---------------------------------------------------------------------------- // accessors // ---------------------------------------------------------------------------- @@ -916,7 +874,7 @@ bool wxListCtrl::GetColumn(int col, wxListItem& item) const if (m_dbImpl) { wxColumnList::compatibility_iterator node = m_colsInfo.Item( col ); - wxASSERT_MSG( node, _T("invalid column index in wxMacListCtrlItem") ); + wxASSERT_MSG( node, wxT("invalid column index in wxMacListCtrlItem") ); wxListItem* column = node->GetData(); long mask = column->GetMask(); @@ -938,20 +896,16 @@ bool wxListCtrl::GetColumn(int col, wxListItem& item) const } // Sets information about this column -bool wxListCtrl::SetColumn(int col, wxListItem& item) +bool wxListCtrl::SetColumn(int col, const wxListItem& item) { if (m_genericImpl) return m_genericImpl->SetColumn(col, item); if (m_dbImpl) { + wxASSERT_MSG( col < (int)m_colsInfo.GetCount(), wxT("invalid column index in wxMacListCtrlItem") ); + long mask = item.GetMask(); - if ( col >= (int)m_colsInfo.GetCount() ) - { - wxListItem* listItem = new wxListItem(item); - m_colsInfo.Append( listItem ); - } - else { wxListItem listItem; GetColumn( col, listItem ); @@ -973,13 +927,16 @@ bool wxListCtrl::SetColumn(int col, wxListItem& item) // change the appearance in the databrowser. DataBrowserListViewHeaderDesc columnDesc; columnDesc.version=kDataBrowserListViewLatestHeaderDesc; - verify_noerr( m_dbImpl->GetHeaderDesc( kMinColumnId + col, &columnDesc ) ); + + DataBrowserTableViewColumnID id = 0; + verify_noerr( m_dbImpl->GetColumnIDFromIndex( col, &id ) ); + verify_noerr( m_dbImpl->GetHeaderDesc( id, &columnDesc ) ); /* if (item.GetMask() & wxLIST_MASK_TEXT) { wxFontEncoding enc; - if ( m_font.Ok() ) + if ( m_font.IsOk() ) enc = GetFont().GetEncoding(); else enc = wxLocale::GetSystemEncoding(); @@ -1003,7 +960,7 @@ bool wxListCtrl::SetColumn(int col, wxListItem& item) } } - verify_noerr( m_dbImpl->SetHeaderDesc( kMinColumnId + col, &columnDesc ) ); + verify_noerr( m_dbImpl->SetHeaderDesc( id, &columnDesc ) ); } return true; @@ -1126,6 +1083,8 @@ bool wxListCtrl::GetItem(wxListItem& info) const if (info.m_itemId >= 0 && info.m_itemId < GetItemCount()) { m_dbImpl->MacGetColumnInfo(info.m_itemId, info.m_col, info); + // MacGetColumnInfo returns erroneous information in the state field, so zero it. + info.SetState(0); if (info.GetMask() & wxLIST_MASK_STATE) { DataBrowserItemID id = (DataBrowserItemID)m_dbImpl->GetItemFromLine(info.m_itemId); @@ -1310,15 +1269,16 @@ bool wxListCtrl::SetItemColumnImage(long item, long column, int image) } // Gets the item text -wxString wxListCtrl::GetItemText(long item) const +wxString wxListCtrl::GetItemText(long item, int column) const { if (m_genericImpl) - return m_genericImpl->GetItemText(item); + return m_genericImpl->GetItemText(item, column); wxListItem info; info.m_mask = wxLIST_MASK_TEXT; info.m_itemId = item; + info.m_col = column; if (!GetItem(info)) return wxEmptyString; @@ -1374,7 +1334,7 @@ bool wxListCtrl::SetItemPtrData(long item, wxUIntPtr data) wxRect wxListCtrl::GetViewRect() const { wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST), - _T("wxListCtrl::GetViewRect() only works in icon mode") ); + wxT("wxListCtrl::GetViewRect() only works in icon mode") ); if (m_genericImpl) return m_genericImpl->GetViewRect(); @@ -1383,6 +1343,15 @@ wxRect wxListCtrl::GetViewRect() const return rect; } +bool wxListCtrl::GetSubItemRect( long item, long subItem, wxRect& rect, int code ) const +{ + if (m_genericImpl) + return m_genericImpl->GetSubItemRect(item, subItem, rect, code); + + // TODO: implement for DataBrowser implementation + return false; +} + // Gets the item rectangle bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const { @@ -1393,7 +1362,10 @@ bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const if (m_dbImpl) { DataBrowserItemID id; - DataBrowserPropertyID col = kMinColumnId; + + DataBrowserTableViewColumnID col = 0; + verify_noerr( m_dbImpl->GetColumnIDFromIndex( 0, &col ) ); + Rect bounds; DataBrowserPropertyPart part = kDataBrowserPropertyEnclosingPart; if ( code == wxLIST_RECT_LABEL ) @@ -1640,6 +1612,9 @@ long wxListCtrl::GetNextItem(long item, int geom, int state) const if ( !IsVirtual() ) id = (DataBrowserItemID)m_dbImpl->GetItemFromLine(line); + if ( (state & wxLIST_STATE_FOCUSED) && (m_current == line)) + return line; + if ( (state == wxLIST_STATE_DONTCARE ) ) return line; @@ -1660,6 +1635,9 @@ long wxListCtrl::GetNextItem(long item, int geom, int state) const if ( !IsVirtual() ) id = (DataBrowserItemID)m_dbImpl->GetItemFromLine(line); + if ( (state & wxLIST_STATE_FOCUSED) && (m_current == line)) + return line; + if ( (state == wxLIST_STATE_DONTCARE ) ) return line; @@ -1759,7 +1737,7 @@ bool wxListCtrl::DeleteItem(long item) if (m_dbImpl) { m_dbImpl->MacDelete(item); - wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ITEM, GetId() ); + wxListEvent event( wxEVT_LIST_DELETE_ITEM, GetId() ); event.SetEventObject( this ); event.m_itemIndex = item; HandleWindowEvent( event ); @@ -1771,13 +1749,14 @@ bool wxListCtrl::DeleteItem(long item) // Deletes all items bool wxListCtrl::DeleteAllItems() { + m_current = -1; if (m_genericImpl) return m_genericImpl->DeleteAllItems(); if (m_dbImpl) { m_dbImpl->MacClear(); - wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetId() ); + wxListEvent event( wxEVT_LIST_DELETE_ALL_ITEMS, GetId() ); event.SetEventObject( this ); HandleWindowEvent( event ); } @@ -1847,7 +1826,7 @@ wxTextCtrl* wxListCtrl::EditLabel(long item, wxClassInfo* textControlClass) wxASSERT_MSG( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)), wxT("EditLabel() needs a text control") ); - wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() ); + wxListEvent le( wxEVT_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() ); le.SetEventObject( this ); le.m_itemIndex = item; le.m_col = 0; @@ -1874,7 +1853,11 @@ bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel)) return true; // m_genericImpl->EndEditLabel(cancel); if (m_dbImpl) - verify_noerr( SetDataBrowserEditItem(m_dbImpl->GetControlRef(), kDataBrowserNoItem, kMinColumnId) ); + { + DataBrowserTableViewColumnID id = 0; + verify_noerr( m_dbImpl->GetColumnIDFromIndex( 0, &id ) ); + verify_noerr( SetDataBrowserEditItem(m_dbImpl->GetControlRef(), kDataBrowserNoItem, id ) ); + } return true; } @@ -1958,11 +1941,16 @@ long wxListCtrl::FindItem(long start, const wxPoint& pt, int direction) return -1; } +static void calculateCGDrawingBounds(CGRect inItemRect, CGRect *outIconRect, CGRect *outTextRect, bool hasIcon); + // Determines which item (if any) is at the specified point, // giving details in 'flags' (see wxLIST_HITTEST_... flags above) long wxListCtrl::HitTest(const wxPoint& point, int& flags, long *ptrSubItem) const { + if (ptrSubItem) + *ptrSubItem = -1; + if (m_genericImpl) return m_genericImpl->HitTest(point, flags, ptrSubItem); @@ -1989,27 +1977,95 @@ wxListCtrl::HitTest(const wxPoint& point, int& flags, long *ptrSubItem) const DataBrowserItemID id; m_dbImpl->GetItemID( (DataBrowserTableViewRowIndex) row, &id ); - // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label - if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL ) ) - { - wxMacListCtrlItem* lcItem; - lcItem = (wxMacListCtrlItem*) id; - if (lcItem) - { - flags = wxLIST_HITTEST_ONITEM; - return row; - } - } - else + CGPoint click_point = CGPointMake( point.x, point.y ); + if (row < GetItemCount() ) { - if (row < GetItemCount() ) + short column; + for( column = 0; column < GetColumnCount(); column++ ) { - flags = wxLIST_HITTEST_ONITEM; - return row; - } - } - + Rect enclosingRect; + CGRect enclosingCGRect, iconCGRect, textCGRect; + int imgIndex = -1; + wxMacListCtrlItem* lcItem; + + WXUNUSED_UNLESS_DEBUG( OSStatus status = ) m_dbImpl->GetItemPartBounds( id, kMinColumnId + column, kDataBrowserPropertyEnclosingPart, &enclosingRect ); + wxASSERT( status == noErr ); + + enclosingCGRect = CGRectMake(enclosingRect.left, + enclosingRect.top, + enclosingRect.right - enclosingRect.left, + enclosingRect.bottom - enclosingRect.top); + + if (column >= 0) + { + if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL ) ) + { + lcItem = (wxMacListCtrlItem*) id; + if (lcItem->HasColumnInfo(column)) + { + wxListItem* item = lcItem->GetColumnInfo(column); + + if (item->GetMask() & wxLIST_MASK_IMAGE) + { + imgIndex = item->GetImage(); + } + } + } + else + { + long itemNum = (long)id-1; + if (itemNum >= 0 && itemNum < GetItemCount()) + { + imgIndex = OnGetItemColumnImage( itemNum, column ); + } + } + } + + calculateCGDrawingBounds(enclosingCGRect, &iconCGRect, &textCGRect, (imgIndex != -1) ); + + if ( CGRectContainsPoint( iconCGRect, click_point ) ) + { + flags = wxLIST_HITTEST_ONITEMICON; + if (ptrSubItem) + *ptrSubItem = column; + return row; + } + else if ( CGRectContainsPoint( textCGRect, click_point ) ) + { + flags = wxLIST_HITTEST_ONITEMLABEL; + if (ptrSubItem) + *ptrSubItem = column; + return row; + } + } + + if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL ) ) + { + wxMacListCtrlItem* lcItem; + lcItem = (wxMacListCtrlItem*) id; + if (lcItem) + { + flags = wxLIST_HITTEST_ONITEM; + if (ptrSubItem) + *ptrSubItem = column; + return row; + } + } + else + { + flags = wxLIST_HITTEST_ONITEM; + if (ptrSubItem) + *ptrSubItem = column; + return row; + } + } + else + { + if ( wxControl::HitTest( point ) ) + flags = wxLIST_HITTEST_NOWHERE; + } } + return -1; } @@ -2035,7 +2091,7 @@ int wxListCtrl::GetScrollPos(int orient) const // -1 otherwise. long wxListCtrl::InsertItem(wxListItem& info) { - wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") ); + wxASSERT_MSG( !IsVirtual(), wxT("can't be used with virtual controls") ); if (m_genericImpl) return m_genericImpl->InsertItem(info); @@ -2049,7 +2105,7 @@ long wxListCtrl::InsertItem(wxListItem& info) m_dbImpl->MacInsertItem(info.m_itemId, &info ); - wxListEvent event( wxEVT_COMMAND_LIST_INSERT_ITEM, GetId() ); + wxListEvent event( wxEVT_LIST_INSERT_ITEM, GetId() ); event.SetEventObject( this ); event.m_itemIndex = info.m_itemId; HandleWindowEvent( event ); @@ -2098,7 +2154,7 @@ long wxListCtrl::InsertItem(long index, const wxString& label, int imageIndex) } // For list view mode (only), inserts a column. -long wxListCtrl::InsertColumn(long col, wxListItem& item) +long wxListCtrl::DoInsertColumn(long col, const wxListItem& item) { if (m_genericImpl) return m_genericImpl->InsertColumn(col, item); @@ -2114,7 +2170,7 @@ long wxListCtrl::InsertColumn(long col, wxListItem& item) if (imageList && imageList->GetImageCount() > 0) { wxBitmap bmp = imageList->GetBitmap(0); - //if (bmp.Ok()) + //if (bmp.IsOk()) // type = kDataBrowserIconAndTextType; } @@ -2129,6 +2185,9 @@ long wxListCtrl::InsertColumn(long col, wxListItem& item) just = teFlushRight; } m_dbImpl->InsertColumn(col, type, item.GetText(), just, width); + + wxListItem* listItem = new wxListItem(item); + m_colsInfo.Insert( col, listItem ); SetColumn(col, item); // set/remove options based on the wxListCtrl type. @@ -2148,27 +2207,6 @@ long wxListCtrl::InsertColumn(long col, wxListItem& item) return col; } -long wxListCtrl::InsertColumn(long col, - const wxString& heading, - int format, - int width) -{ - if (m_genericImpl) - return m_genericImpl->InsertColumn(col, heading, format, width); - - wxListItem item; - item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT; - item.m_text = heading; - if ( width > -1 ) - { - item.m_mask |= wxLIST_MASK_WIDTH; - item.m_width = width; - } - item.m_format = format; - - return InsertColumn(col, item); -} - // scroll the control by the given number of pixels (exception: in list view, // dx is interpreted as number of columns) bool wxListCtrl::ScrollList(int dx, int dy) @@ -2178,13 +2216,15 @@ bool wxListCtrl::ScrollList(int dx, int dy) if (m_dbImpl) { - m_dbImpl->SetScrollPosition(dx, dy); + // Notice that the parameter order is correct here: first argument is + // the "top" displacement, second one is the "left" one. + m_dbImpl->SetScrollPosition(dy, dx); } return true; } -bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data) +bool wxListCtrl::SortItems(wxListCtrlCompare fn, wxIntPtr data) { if (m_genericImpl) return m_genericImpl->SortItems(fn, data); @@ -2213,7 +2253,7 @@ void wxListCtrl::OnRenameTimer() bool wxListCtrl::OnRenameAccept(long itemEdit, const wxString& value) { - wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetId() ); + wxListEvent le( wxEVT_LIST_END_LABEL_EDIT, GetId() ); le.SetEventObject( this ); le.m_itemIndex = itemEdit; @@ -2226,7 +2266,7 @@ bool wxListCtrl::OnRenameAccept(long itemEdit, const wxString& value) void wxListCtrl::OnRenameCancelled(long itemEdit) { // let owner know that the edit was cancelled - wxListEvent le( wxEVT_COMMAND_LIST_END_LABEL_EDIT, GetParent()->GetId() ); + wxListEvent le( wxEVT_LIST_END_LABEL_EDIT, GetParent()->GetId() ); le.SetEditCanceled(true); @@ -2245,7 +2285,7 @@ wxString wxListCtrl::OnGetItemText(long WXUNUSED(item), long WXUNUSED(col)) cons { // this is a pure virtual function, in fact - which is not really pure // because the controls which are not virtual don't need to implement it - wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") ); + wxFAIL_MSG( wxT("wxListCtrl::OnGetItemText not supposed to be called") ); return wxEmptyString; } @@ -2266,18 +2306,9 @@ int wxListCtrl::OnGetItemColumnImage(long item, long column) const return -1; } -wxListItemAttr *wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item)) const -{ - wxASSERT_MSG( item >= 0 && item < GetItemCount(), - _T("invalid item index in OnGetItemAttr()") ); - - // no attributes by default - return NULL; -} - void wxListCtrl::SetItemCount(long count) { - wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") ); + wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") ); if (m_genericImpl) { @@ -2445,7 +2476,7 @@ void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner , { bool trigger = false; - wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() ); + wxListEvent event( wxEVT_LIST_ITEM_SELECTED, list->GetId() ); bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0; event.SetEventObject( list ); @@ -2456,7 +2487,7 @@ void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner , switch (message) { case kDataBrowserItemDeselected: - event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED); + event.SetEventType(wxEVT_LIST_ITEM_DESELECTED); if ( !isSingle ) trigger = !lb->IsSelectionSuppressed(); break; @@ -2466,20 +2497,20 @@ void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner , break; case kDataBrowserItemDoubleClicked: - event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); + event.SetEventType( wxEVT_LIST_ITEM_ACTIVATED ); trigger = true; break; case kDataBrowserEditStarted : // TODO : how to veto ? - event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ; + event.SetEventType( wxEVT_LIST_BEGIN_LABEL_EDIT ) ; trigger = true ; break ; case kDataBrowserEditStopped : // TODO probably trigger only upon the value store callback, because // here IIRC we cannot veto - event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ; + event.SetEventType( wxEVT_LIST_END_LABEL_EDIT ) ; trigger = true ; break ; @@ -2628,11 +2659,10 @@ enum static void calculateCGDrawingBounds(CGRect inItemRect, CGRect *outIconRect, CGRect *outTextRect, bool hasIcon = false) { float textBottom; - float iconH, iconW = 0; + float iconW = 0; float padding = kItemPadding; if (hasIcon) { - iconH = kIconHeight; iconW = kIconWidth; padding = padding*2; } @@ -2659,7 +2689,9 @@ void wxMacDataBrowserListCtrlControl::DrawItem( wxString text; wxFont font = wxNullFont; int imgIndex = -1; - short listColumn = property - kMinColumnId; + + DataBrowserTableViewColumnIndex listColumn = 0; + GetColumnPosition( property, &listColumn ); wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl ); wxMacListCtrlItem* lcItem; @@ -2671,7 +2703,8 @@ void wxMacDataBrowserListCtrlControl::DrawItem( if (!m_isVirtual) { lcItem = (wxMacListCtrlItem*) itemID; - if (lcItem->HasColumnInfo(listColumn)){ + if (lcItem->HasColumnInfo(listColumn)) + { wxListItem* item = lcItem->GetColumnInfo(listColumn); // we always use the 0 column to get font and text/background colors. @@ -2715,7 +2748,7 @@ void wxMacDataBrowserListCtrlControl::DrawItem( if (bgColor == wxNullColour) bgColor = listBgColor; - if (!font.Ok()) + if (!font.IsOk()) font = list->GetFont(); wxCFStringRef cfString( text, wxLocale::GetSystemEncoding() ); @@ -2725,6 +2758,8 @@ void wxMacDataBrowserListCtrlControl::DrawItem( Boolean active; ThemeDrawingState savedState = NULL; CGContextRef context = (CGContextRef)list->MacGetDrawingContext(); + wxMacCGContextStateSaver top_saver_cg( context ); + RGBColor labelColor; labelColor.red = 0; labelColor.green = 0; @@ -2767,24 +2802,22 @@ void wxMacDataBrowserListCtrlControl::DrawItem( GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor, 32, true, &backgroundColor); GetThemeTextColor(kThemeTextColorBlack, gdDepth, colorDevice, &labelColor); } - CGContextSaveGState(context); + wxMacCGContextStateSaver cg( context ); CGContextSetRGBFillColor(context, (CGFloat)backgroundColor.red / (CGFloat)USHRT_MAX, (CGFloat)backgroundColor.green / (CGFloat)USHRT_MAX, (CGFloat)backgroundColor.blue / (CGFloat)USHRT_MAX, (CGFloat) 1.0); CGContextFillRect(context, enclosingCGRect); - - CGContextRestoreGState(context); } else { - if (color.Ok()) + if (color.IsOk()) color.GetRGBColor(&labelColor); - else if (list->GetTextColour().Ok()) + else if (list->GetTextColour().IsOk()) list->GetTextColour().GetRGBColor(&labelColor); - if (bgColor.Ok()) + if (bgColor.IsOk()) { bgColor.GetRGBColor(&backgroundColor); CGContextSaveGState(context); @@ -2803,18 +2836,18 @@ void wxMacDataBrowserListCtrlControl::DrawItem( if (imgIndex != -1) { wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL); - if (imageList && imageList->GetImageCount() > 0){ + if (imageList && imageList->GetImageCount() > 0) + { wxBitmap bmp = imageList->GetBitmap(imgIndex); IconRef icon = bmp.GetIconRef(); - CGContextSaveGState(context); + wxMacCGContextStateSaver cg( context ); + CGContextTranslateCTM(context, 0,iconCGRect.origin.y + CGRectGetMaxY(iconCGRect)); CGContextScaleCTM(context,1.0f,-1.0f); PlotIconRefInContext(context, &iconCGRect, kAlignNone, active ? kTransformNone : kTransformDisabled, NULL, kPlotIconRefNormalFlags, icon); - - CGContextRestoreGState(context); } } @@ -2826,10 +2859,10 @@ void wxMacDataBrowserListCtrlControl::DrawItem( { info.version = kHIThemeTextInfoVersionOne; info.fontID = kThemeViewsFont; - if (font.Ok()) + if (font.IsOk()) { info.fontID = kThemeSpecifiedFont; - info.font = (CTFontRef) font.MacGetCTFont(); + info.font = (CTFontRef) font.OSXGetCTFont(); setup = true; } } @@ -2840,11 +2873,11 @@ void wxMacDataBrowserListCtrlControl::DrawItem( info.version = kHIThemeTextInfoVersionZero; info.fontID = kThemeViewsFont; - if (font.Ok()) + if (font.IsOk()) { info.fontID = font.MacGetThemeFontID(); - ::TextSize( (short)(font.MacGetFontSize()) ) ; + ::TextSize( (short)(font.GetPointSize()) ) ; ::TextFace( font.MacGetFontStyle() ) ; } } @@ -2872,14 +2905,14 @@ void wxMacDataBrowserListCtrlControl::DrawItem( info.truncationPosition = kHIThemeTextTruncationEnd; info.truncationMaxLines = 1; - CGContextSaveGState(context); - CGContextSetRGBFillColor (context, (CGFloat)labelColor.red / (CGFloat)USHRT_MAX, + { + wxMacCGContextStateSaver cg( context ); + CGContextSetRGBFillColor (context, (CGFloat)labelColor.red / (CGFloat)USHRT_MAX, (CGFloat)labelColor.green / (CGFloat)USHRT_MAX, (CGFloat)labelColor.blue / (CGFloat)USHRT_MAX, (CGFloat) 1.0); - HIThemeDrawTextBox(cfString, &textCGRect, &info, context, kHIThemeOrientationNormal); - - CGContextRestoreGState(context); + HIThemeDrawTextBox(cfString, &textCGRect, &info, context, kHIThemeOrientationNormal); + } #ifndef __LP64__ if (savedState != NULL) @@ -2894,7 +2927,9 @@ OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemI { wxString text; int imgIndex = -1; - short listColumn = property - kMinColumnId; + + DataBrowserTableViewColumnIndex listColumn = 0; + verify_noerr( GetColumnPosition( property, &listColumn ) ); OSStatus err = errDataBrowserPropertyNotSupported; wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl ); @@ -2968,7 +3003,8 @@ OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemI default: if ( property >= kMinColumnId ) { - short listColumn = property - kMinColumnId; + DataBrowserTableViewColumnIndex listColumn = 0; + verify_noerr( GetColumnPosition( property, &listColumn ) ); // TODO probably send the 'end edit' from here, as we // can then deal with the veto @@ -2999,7 +3035,7 @@ void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID, { item = (wxMacListCtrlItem *) itemID; } - + // we want to depend on as little as possible to make sure tear-down of controls is safe if ( message == kDataBrowserItemRemoved ) { @@ -3021,7 +3057,7 @@ void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID, { bool trigger = false; - wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() ); + wxListEvent event( wxEVT_LIST_ITEM_SELECTED, list->GetId() ); event.SetEventObject( list ); if ( !list->IsVirtual() ) @@ -3040,7 +3076,7 @@ void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID, switch (message) { case kDataBrowserItemDeselected: - event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED); + event.SetEventType(wxEVT_LIST_ITEM_DESELECTED); // as the generic implementation is also triggering this // event for single selection, we do the same (different than listbox) trigger = !IsSelectionSuppressed(); @@ -3052,20 +3088,20 @@ void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID, break; case kDataBrowserItemDoubleClicked: - event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED ); + event.SetEventType( wxEVT_LIST_ITEM_ACTIVATED ); trigger = true; break; case kDataBrowserEditStarted : // TODO : how to veto ? - event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ; + event.SetEventType( wxEVT_LIST_BEGIN_LABEL_EDIT ) ; trigger = true ; break ; case kDataBrowserEditStopped : // TODO probably trigger only upon the value store callback, because // here IIRC we cannot veto - event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ; + event.SetEventType( wxEVT_LIST_END_LABEL_EDIT ) ; trigger = true ; break ; @@ -3092,7 +3128,8 @@ Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneI long itemOrder; long otherItemOrder; - int colId = sortProperty - kMinColumnId; + DataBrowserTableViewColumnIndex colId = 0; + verify_noerr( GetColumnPosition( sortProperty, &colId ) ); wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl ); @@ -3159,7 +3196,7 @@ wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl() void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item ) { wxMacDataItem* dataItem = GetItemFromLine(row); - wxASSERT_MSG( dataItem, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") ); + wxASSERT_MSG( dataItem, wxT("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") ); if (item) { wxMacListCtrlItem* listItem = static_cast(dataItem); @@ -3176,7 +3213,11 @@ void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row, unsign // would be shown. Making sure not to update items until the control is visible // seems to fix this issue. if (hasInfo && list->IsShown()) - UpdateItem( wxMacDataBrowserRootContainer, listItem , kMinColumnId + column ); + { + DataBrowserTableViewColumnID id = 0; + verify_noerr( GetColumnIDFromIndex( column, &id ) ); + UpdateItem( wxMacDataBrowserRootContainer, listItem , id ); + } } } @@ -3201,7 +3242,7 @@ void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem* dataItem, wxLis void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item ) { wxMacDataItem* dataItem = GetItemFromLine(row); - wxASSERT_MSG( dataItem, _T("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") ); + wxASSERT_MSG( dataItem, wxT("could not obtain wxMacDataItem in MacGetColumnInfo. Is row a valid wxListCtrl row?") ); // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate //if (item) { @@ -3238,10 +3279,10 @@ void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row, unsign } } } - + void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n, wxListItem* item ) { - + wxMacDataItemBrowserControl::MacInsert(n, new wxMacListCtrlItem() ); MacSetColumnInfo(n, 0, item); } @@ -3291,7 +3332,7 @@ void wxMacListCtrlItem::SetColumnTextValue( unsigned int column, const wxString& wxListItem* wxMacListCtrlItem::GetColumnInfo( unsigned int column ) { - wxASSERT_MSG( HasColumnInfo(column), _T("invalid column index in wxMacListCtrlItem") ); + wxASSERT_MSG( HasColumnInfo(column), wxT("invalid column index in wxMacListCtrlItem") ); return m_rowItems[column]; }