X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/facd6764872eede45605ba7c9dfa0e1d0c708fa2..23176131010f41b2f9a54bef50c8afa25472e195:/src/mac/carbon/listbox.cpp diff --git a/src/mac/carbon/listbox.cpp b/src/mac/carbon/listbox.cpp index 3321963637..ff4dc28ea2 100644 --- a/src/mac/carbon/listbox.cpp +++ b/src/mac/carbon/listbox.cpp @@ -62,6 +62,58 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, style, validator, name); } +#if TARGET_API_MAC_OSX +static pascal void DataBrowserItemNotificationProc(ControlRef browser, DataBrowserItemID itemID, + DataBrowserItemNotification message, DataBrowserItemDataRef itemData) +#else +static pascal void DataBrowserItemNotificationProc(ControlRef browser, DataBrowserItemID itemID, + DataBrowserItemNotification message) +#endif +{ + long ref = GetControlReference( browser ) ; + if ( ref ) + { + wxListBox* list = wxDynamicCast( ref , wxListBox ) ; + for ( size_t i = 0 ; i < list->m_idArray.GetCount() ; ++i ) + if ( list->m_idArray[i] == (long) itemID ) + { + bool trigger = false ; + wxCommandEvent event( + wxEVT_COMMAND_LISTBOX_SELECTED, list->GetId() ); + switch( message ) + { + case kDataBrowserItemDeselected : + if ( list->HasMultipleSelection() ) + trigger = true ; + break ; + case kDataBrowserItemSelected : + trigger = true ; + break ; + case kDataBrowserItemDoubleClicked : + event.SetEventType(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED) ; + trigger = true ; + break ; + default : + break ; + } + if ( trigger ) + { + event.SetEventObject( list ); + if ( list->HasClientObjectData() ) + event.SetClientObject( list->GetClientObject(i) ); + else if ( list->HasClientUntypedData() ) + event.SetClientData( list->GetClientData(i) ); + event.SetString( list->GetString(i) ); + event.SetInt(i) ; + event.SetExtraLong( list->HasMultipleSelection() ? message == kDataBrowserItemSelected : TRUE ); + list->GetEventHandler()->ProcessEvent(event) ; + } + break ; + } + } +} + + static pascal OSStatus ListBoxGetSetItemData(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemDataRef itemData, Boolean changeValue) @@ -108,6 +160,9 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, const wxString& name) { m_macIsUserPane = FALSE ; + + wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED), + _T("only one of listbox selection modes can be specified") ); if ( !wxListBoxBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) ) return false; @@ -157,7 +212,11 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, columnDesc.propertyDesc.propertyID = 1024; columnDesc.propertyDesc.propertyType = kDataBrowserTextType; - columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewTypeSelectColumn | kDataBrowserTableViewSelectionColumn ; + columnDesc.propertyDesc.propertyFlags = +#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 + kDataBrowserListViewTypeSelectColumn | +#endif + kDataBrowserTableViewSelectionColumn ; verify_noerr(::AddDataBrowserListViewColumn(browser, &columnDesc, kDataBrowserListViewAppendColumn) ) ; @@ -174,6 +233,12 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, callbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP(ListBoxGetSetItemData); + callbacks.u.v1.itemNotificationCallback = +#if TARGET_API_MAC_OSX + (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc) ; +#else + NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc) ; +#endif SetDataBrowserCallbacks(browser, &callbacks); MacPostControlCreate(pos,size) ; @@ -306,11 +371,6 @@ void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData) #endif // wxUSE_OWNER_DRAWN } -bool wxListBox::HasMultipleSelection() const -{ - return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED); -} - int wxListBox::FindString(const wxString& s) const { @@ -583,12 +643,21 @@ void wxListBox::MacAppend( const wxString& text) void wxListBox::MacClear() { verify_noerr(::RemoveDataBrowserItems((ControlRef) m_macControl , kDataBrowserNoItem , 0 , NULL , kDataBrowserItemNoProperty ) ) ; - m_dataArray.Empty() ; + m_idArray.Empty() ; } void wxListBox::MacSetSelection( int n , bool select ) { UInt32 id = m_idArray[n] ; + if ( !(GetWindowStyle() & (wxLB_MULTIPLE|wxLB_EXTENDED) ) ) + { + int n = MacGetSelection() ; + if ( n >= 0 ) + { + UInt32 idOld = m_idArray[n] ; + SetDataBrowserSelectedItems((ControlRef) m_macControl , 1 , & idOld , kDataBrowserItemsRemove ) ; + } + } if ( ::IsDataBrowserItemSelected( (ControlRef) m_macControl , id ) != select ) { verify_noerr(::SetDataBrowserSelectedItems((ControlRef) m_macControl , 1 , & id , kDataBrowserItemsToggle ) ) ; @@ -647,6 +716,7 @@ void wxListBox::OnSize( wxSizeEvent &event) void wxListBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown)) { + /* Boolean wasDoubleClick = false ; long result ; @@ -659,6 +729,7 @@ void wxListBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart , { MacDoDoubleClick() ; } + */ } void wxListBox::MacSetRedraw( bool doDraw ) @@ -667,7 +738,7 @@ void wxListBox::MacSetRedraw( bool doDraw ) } void wxListBox::MacDoClick() -{ +{/* wxArrayInt aSelections; int n ; size_t count = GetSelections(aSelections); @@ -711,13 +782,16 @@ void wxListBox::MacDoClick() event.m_commandInt = n; GetEventHandler()->ProcessEvent(event); +*/ } void wxListBox::MacDoDoubleClick() { +/* wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId); event.SetEventObject( this ); GetEventHandler()->ProcessEvent(event) ; +*/ } void wxListBox::OnChar(wxKeyEvent& event)