X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0698ed3ca89d0e7d8bf01df1d7e7973798b89768..e2c0faf71c4ec2ae9a604d7e9c2850f081bff266:/src/osx/carbon/listbox.cpp diff --git a/src/osx/carbon/listbox.cpp b/src/osx/carbon/listbox.cpp index e9d0776b22..8275ad0a81 100644 --- a/src/osx/carbon/listbox.cpp +++ b/src/osx/carbon/listbox.cpp @@ -4,7 +4,6 @@ // Author: Stefan Csomor // Modified by: // Created: 1998-01-01 -// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -30,12 +29,12 @@ // list box control implementation // ============================================================================ -wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer, - wxWindowMac* WXUNUSED(parent), - wxWindowID WXUNUSED(id), - const wxPoint& pos, +wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer, + wxWindowMac* WXUNUSED(parent), + wxWindowID WXUNUSED(id), + const wxPoint& pos, const wxSize& size, - long style, + long style, long WXUNUSED(extraStyle)) { wxMacDataBrowserListControl* control = new wxMacDataBrowserListControl( wxpeer, pos, size, style ); @@ -43,7 +42,7 @@ wxWidgetImplType* wxWidgetImpl::CreateListBox( wxWindowMac* wxpeer, return control; } -int wxListBox::DoListHitTest(const wxPoint& inpoint) const +int wxMacDataBrowserListControl::DoListHitTest(const wxPoint& inpoint) const { OSStatus err; @@ -59,7 +58,7 @@ int wxListBox::DoListHitTest(const wxPoint& inpoint) const // get column property ID (req. for call to itempartbounds) DataBrowserTableViewColumnID colId = 0; - err = GetDataBrowserTableViewColumnProperty(m_peer->GetControlRef(), 0, &colId); + err = GetDataBrowserTableViewColumnProperty(GetControlRef(), 0, &colId); wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewColumnProperty")); // OK, first we need to find the first visible item we have - @@ -68,17 +67,19 @@ int wxListBox::DoListHitTest(const wxPoint& inpoint) const // until we find a visible item, but we can do a cheap calculation // via the row height to speed things up a bit UInt32 scrollx, scrolly; - err = GetDataBrowserScrollPosition(m_peer->GetControlRef(), &scrollx, &scrolly); + err = GetDataBrowserScrollPosition(GetControlRef(), &scrollx, &scrolly); wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserScrollPosition")); UInt16 height; - err = GetDataBrowserTableViewRowHeight(m_peer->GetControlRef(), &height); + err = GetDataBrowserTableViewRowHeight(GetControlRef(), &height); wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewRowHeight")); + wxListBox *list = wxDynamicCast( GetWXPeer() , wxListBox ); + // these indices are 0-based, as usual, so we need to add 1 to them when // passing them to data browser functions which use 1-based indices int low = scrolly / height, - high = GetCount() - 1; + high = list->GetCount() - 1; // search for the first visible item (note that the scroll guess above // is the low bounds of where the item might lie so we only use that as a @@ -87,7 +88,7 @@ int wxListBox::DoListHitTest(const wxPoint& inpoint) const { Rect bounds; err = GetDataBrowserItemPartBounds( - m_peer->GetControlRef(), low + 1, colId, + GetControlRef(), low + 1, colId, kDataBrowserPropertyEnclosingPart, &bounds); // note +1 to translate to Mac ID if ( err == noErr ) @@ -109,7 +110,7 @@ int wxListBox::DoListHitTest(const wxPoint& inpoint) const Rect bounds; err = GetDataBrowserItemPartBounds( - m_peer->GetControlRef(), mid + 1, colId, + GetControlRef(), mid + 1, colId, kDataBrowserPropertyEnclosingPart, &bounds); //note +1 to trans to mac id wxCHECK_MSG( err == noErr || err == errDataBrowserItemNotFound, @@ -135,10 +136,10 @@ int wxListBox::DoListHitTest(const wxPoint& inpoint) const } if ( point.y < bounds.top ) - // index(bounds) greater then key(point) + // index(bounds) greater than key(point) high = mid - 1; else - // index(bounds) less then key(point) + // index(bounds) less than key(point) low = mid + 1; } } @@ -175,7 +176,7 @@ OSStatus wxMacListBoxItem::GetSetData(wxMacDataItemBrowserControl *owner , wxListBox *list = wxDynamicCast( owner->GetWXPeer() , wxListBox ); wxMacDataBrowserCellValue valueholder(itemData); list->GetValueCallback( n , col, valueholder ); - + err = noErr; } else @@ -191,7 +192,7 @@ OSStatus wxMacListBoxItem::GetSetData(wxMacDataItemBrowserControl *owner , } } - + } else { @@ -211,7 +212,7 @@ OSStatus wxMacListBoxItem::GetSetData(wxMacDataItemBrowserControl *owner , m_isChecked = newVal; err = noErr; - wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, checklist->GetId() ); + wxCommandEvent event( wxEVT_CHECKLISTBOX, checklist->GetId() ); event.SetInt( owner->GetLineFromItem( this ) ); event.SetEventObject( checklist ); checklist->HandleWindowEvent( event ); @@ -226,7 +227,7 @@ OSStatus wxMacListBoxItem::GetSetData(wxMacDataItemBrowserControl *owner , { err = wxMacDataItem::GetSetData(owner, property, itemData, changeValue); } - + return err; } @@ -261,7 +262,7 @@ wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const : wxMacDataItemBrowserControl( peer, pos, size, style ) { m_nextColumnId = 0 ; - + OSStatus err = noErr; m_clientDataItemsType = wxClientData_None; if ( style & wxLB_SORT ) @@ -335,8 +336,8 @@ wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const err = SetHasScrollBars( (style & wxHSCROLL) != 0 , true ); #if 0 // shouldn't be necessary anymore under 10.2 - m_peer->SetData( kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, (Boolean)false ); - m_peer->SetNeedsFocusRect( true ); + GetPeer()->SetData( kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, (Boolean)false ); + GetPeer()->SetNeedsFocusRect( true ); #endif } @@ -351,7 +352,7 @@ void wxMacDataBrowserListControl::ItemNotification( { wxListBox *list = wxDynamicCast( GetWXPeer() , wxListBox ); wxCHECK_RET( list != NULL , wxT("Listbox expected")); - + if (list->HasMultipleSelection() && (message == kDataBrowserSelectionSetChanged) && (!list->MacGetBlockEvents())) { list->CalcAndSendEvent(); @@ -360,15 +361,15 @@ void wxMacDataBrowserListControl::ItemNotification( if ((message == kDataBrowserSelectionSetChanged) && (!list->MacGetBlockEvents())) { - wxCommandEvent event( wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() ); - + wxCommandEvent event( wxEVT_LISTBOX, list->GetId() ); + int sel = list->GetSelection(); if ((sel < 0) || (sel > (int) list->GetCount())) // OS X can select an item below the last item (why?) return; list->HandleLineEvent( sel, false ); return; } - + // call super for item level(wxMacDataItem->Notification) callback processing wxMacDataItemBrowserControl::ItemNotification( itemID, message, itemData); } @@ -385,7 +386,7 @@ wxWindow * wxMacDataBrowserListControl::GetPeer() const // List Methods // -wxMacDataBrowserColumn* wxMacDataBrowserListControl::DoInsertColumn( unsigned int pos, DataBrowserPropertyID property, +wxMacDataBrowserColumn* wxMacDataBrowserListControl::DoInsertColumn( unsigned int pos, DataBrowserPropertyID property, const wxString& title, bool editable, DataBrowserPropertyType colType, SInt16 just, int width ) { @@ -404,7 +405,7 @@ wxMacDataBrowserColumn* wxMacDataBrowserListControl::DoInsertColumn( unsigned in // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is // defined for other modes? wxFontEncoding enc; - if ( m_font.Ok() ) + if ( m_font.IsOk() ) enc = m_font.GetEncoding(); else enc = wxLocale::GetSystemEncoding(); @@ -419,7 +420,7 @@ wxMacDataBrowserColumn* wxMacDataBrowserListControl::DoInsertColumn( unsigned in columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewSortableColumn; columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton; - + if ( editable ) columnDesc.propertyDesc.propertyFlags |= kDataBrowserPropertyIsMutable; @@ -431,38 +432,38 @@ wxMacDataBrowserColumn* wxMacDataBrowserListControl::DoInsertColumn( unsigned in } wxMacDataBrowserColumn *col = new wxMacDataBrowserColumn( property, colType, editable ); - + m_columns.Insert( col, pos ); - + return col; } -wxListWidgetColumn* wxMacDataBrowserListControl::InsertTextColumn( unsigned pos, const wxString& title, bool editable, - wxAlignment just, int defaultWidth) +wxListWidgetColumn* wxMacDataBrowserListControl::InsertTextColumn( unsigned pos, const wxString& title, bool editable, + wxAlignment just, int defaultWidth) { DataBrowserPropertyID property = kMinColumnId + m_nextColumnId++; - + SInt16 j = teFlushLeft; if ( just & wxALIGN_RIGHT ) j = teFlushRight; else if ( just & wxALIGN_CENTER_HORIZONTAL ) j = teCenter; - - return DoInsertColumn( pos, property, title, editable, kDataBrowserTextType, just, defaultWidth ); + + return DoInsertColumn( pos, property, title, editable, kDataBrowserTextType, just, defaultWidth ); } -wxListWidgetColumn* wxMacDataBrowserListControl::InsertCheckColumn( unsigned pos , const wxString& title, bool editable, - wxAlignment just, int defaultWidth ) +wxListWidgetColumn* wxMacDataBrowserListControl::InsertCheckColumn( unsigned pos , const wxString& title, bool editable, + wxAlignment just, int defaultWidth ) { DataBrowserPropertyID property = kMinColumnId + m_nextColumnId++; - + SInt16 j = teFlushLeft; if ( just & wxALIGN_RIGHT ) j = teFlushRight; else if ( just & wxALIGN_CENTER_HORIZONTAL ) j = teCenter; - - return DoInsertColumn( pos, property, title, editable, kDataBrowserCheckboxType, just, defaultWidth ); + + return DoInsertColumn( pos, property, title, editable, kDataBrowserCheckboxType, just, defaultWidth ); } wxMacDataBrowserColumn* wxMacDataBrowserListControl::GetColumnFromProperty( DataBrowserPropertyID property) @@ -470,7 +471,7 @@ wxMacDataBrowserColumn* wxMacDataBrowserListControl::GetColumnFromProperty( Data for ( unsigned int i = 0; i < m_columns.size() ; ++ i ) if ( m_columns[i]->GetProperty() == property ) return m_columns[i]; - + return NULL; } @@ -579,15 +580,15 @@ void wxMacDataBrowserListControl::ListScrollTo( unsigned int n ) RevealItem( item , kDataBrowserRevealWithoutSelecting ); } - -void wxMacDataBrowserListControl::UpdateLine( unsigned int n, wxListWidgetColumn* col ) + +void wxMacDataBrowserListControl::UpdateLine( unsigned int n, wxListWidgetColumn* col ) { wxMacDataBrowserColumn* dbcol = dynamic_cast (col); wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); UpdateItem(wxMacDataBrowserRootContainer, item, dbcol ? dbcol->GetProperty() : kDataBrowserNoItem ); } -void wxMacDataBrowserListControl::UpdateLineToEnd( unsigned int n) +void wxMacDataBrowserListControl::UpdateLineToEnd( unsigned int n) { // with databrowser inserting does not need updating the entire model, it's done by databrowser itself wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); @@ -607,20 +608,24 @@ void wxMacDataBrowserCellValue::Set( const wxString& value ) SetDataBrowserItemDataText( m_data, (CFStringRef) cf); } -void wxMacDataBrowserCellValue::Set( int value ) +void wxMacDataBrowserCellValue::Set( int value ) { SetDataBrowserItemDataValue( m_data, value ); - // SetDataBrowserItemDataButtonValue( m_data, value ? kThemeButtonOn : kThemeButtonOff); } - -int wxMacDataBrowserCellValue::GetIntValue() const + +void wxMacDataBrowserCellValue::Check( bool check ) +{ + SetDataBrowserItemDataButtonValue( m_data, check ? kThemeButtonOn : kThemeButtonOff); +} + +int wxMacDataBrowserCellValue::GetIntValue() const { SInt32 value; GetDataBrowserItemDataValue( m_data, &value ); return value; } -wxString wxMacDataBrowserCellValue::GetStringValue() const +wxString wxMacDataBrowserCellValue::GetStringValue() const { CFStringRef value; GetDataBrowserItemDataText ( m_data, &value );