X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c9c4274adc464db0c3de728c906fa1f27c6a3dd8..cdbd62d6ff290fd58acd1bc5574dfc79db3a6f70:/src/osx/carbon/listctrl_mac.cpp diff --git a/src/osx/carbon/listctrl_mac.cpp b/src/osx/carbon/listctrl_mac.cpp index 8e3ac789f6..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 (a 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 ) ) @@ -631,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(); } @@ -666,7 +592,7 @@ 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; @@ -728,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; @@ -747,20 +671,20 @@ 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 ); @@ -850,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); @@ -876,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; @@ -924,21 +842,21 @@ void wxListCtrl::Freeze () { if (m_genericImpl) m_genericImpl->Freeze(); - wxControl::Freeze(); + wxListCtrlBase::Freeze(); } void wxListCtrl::Thaw () { if (m_genericImpl) m_genericImpl->Thaw(); - wxControl::Thaw(); + wxListCtrlBase::Thaw(); } void wxListCtrl::Update () { if (m_genericImpl) m_genericImpl->Update(); - wxControl::Update(); + wxListCtrlBase::Update(); } // ---------------------------------------------------------------------------- @@ -978,7 +896,7 @@ 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); @@ -1018,7 +936,7 @@ bool wxListCtrl::SetColumn(int col, wxListItem& item) if (item.GetMask() & wxLIST_MASK_TEXT) { wxFontEncoding enc; - if ( m_font.Ok() ) + if ( m_font.IsOk() ) enc = GetFont().GetEncoding(); else enc = wxLocale::GetSystemEncoding(); @@ -1819,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 ); @@ -1838,7 +1756,7 @@ bool wxListCtrl::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 ); } @@ -1908,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; @@ -2187,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 ); @@ -2236,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); @@ -2252,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; } @@ -2289,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) @@ -2356,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; @@ -2369,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); @@ -2409,15 +2306,6 @@ 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(), - wxT("invalid item index in OnGetItemAttr()") ); - - // no attributes by default - return NULL; -} - void wxListCtrl::SetItemCount(long count) { wxASSERT_MSG( IsVirtual(), wxT("this is for virtual controls only") ); @@ -2588,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 ); @@ -2599,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; @@ -2609,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 ; @@ -2771,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; } @@ -2861,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() ); @@ -2925,12 +2812,12 @@ void wxMacDataBrowserListCtrlControl::DrawItem( 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); @@ -2972,7 +2859,7 @@ void wxMacDataBrowserListCtrlControl::DrawItem( { info.version = kHIThemeTextInfoVersionOne; info.fontID = kThemeViewsFont; - if (font.Ok()) + if (font.IsOk()) { info.fontID = kThemeSpecifiedFont; info.font = (CTFontRef) font.OSXGetCTFont(); @@ -2986,7 +2873,7 @@ void wxMacDataBrowserListCtrlControl::DrawItem( info.version = kHIThemeTextInfoVersionZero; info.fontID = kThemeViewsFont; - if (font.Ok()) + if (font.IsOk()) { info.fontID = font.MacGetThemeFontID(); @@ -3170,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() ) @@ -3189,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(); @@ -3201,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 ;