X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/46cc7c4e64bd885818aa6022e182fce4d2ca6992..b3231f0aaf369e384d41b2e5890b75a3e26f3fea:/src/mac/carbon/combobxc.cpp diff --git a/src/mac/carbon/combobxc.cpp b/src/mac/carbon/combobxc.cpp index e0549c540a..8cee1e946e 100644 --- a/src/mac/carbon/combobxc.cpp +++ b/src/mac/carbon/combobxc.cpp @@ -17,9 +17,11 @@ #include "wx/button.h" #include "wx/menu.h" #include "wx/mac/uma.h" +#if TARGET_API_MAC_OSX #ifndef __HIVIEW__ #include #endif +#endif #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) @@ -27,7 +29,11 @@ IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) // composite combobox implementation by Dan "Bud" Keith bud@otsys.com +#if TARGET_API_MAC_OSX #define USE_HICOMBOBOX 1 //use hi combobox define +#else +#define USE_HICOMBOBOX 0 +#endif static int nextPopUpMenuId = 1000 ; MenuHandle NewUniqueMenu() @@ -37,6 +43,48 @@ MenuHandle NewUniqueMenu() return handle ; } +#if USE_HICOMBOBOX +static const EventTypeSpec eventList[] = +{ + { kEventClassTextField , kEventTextAccepted } , +} ; + +static pascal OSStatus wxMacComboBoxEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +{ + OSStatus result = eventNotHandledErr ; + wxComboBox* cb = (wxComboBox*) data ; + + wxMacCarbonEvent cEvent( event ) ; + + switch( cEvent.GetClass() ) + { + case kEventClassTextField : + switch( cEvent.GetKind() ) + { + case kEventTextAccepted : + { + wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, cb->GetId() ); + event.SetInt( cb->GetSelection() ); + event.SetString( cb->GetStringSelection() ); + event.SetEventObject( cb ); + cb->GetEventHandler()->ProcessEvent( event ); + } + break ; + default : + break ; + } + break ; + default : + break ; + } + + + return result ; +} + +DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacComboBoxEventHandler ) + +#endif // ---------------------------------------------------------------------------- // constants @@ -333,12 +381,14 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, //hiRect.size.height = bounds.bottom - bounds.top; //printf("left = %d, right = %d, top = %d, bottom = %d\n", bounds.left, bounds.right, bounds.top, bounds.bottom); //printf("x = %d, y = %d, width = %d, height = %d\n", hibounds.origin.x, hibounds.origin.y, hibounds.size.width, hibounds.size.height); - verify_noerr( HIComboBoxCreate( &hiRect, CFSTR(""), NULL, NULL, kHIComboBoxStandardAttributes, (HIViewRef*) &m_macControl) ); + m_peer = new wxMacControl() ; + verify_noerr( HIComboBoxCreate( &hiRect, CFSTR(""), NULL, NULL, kHIComboBoxStandardAttributes, *m_peer ) ); + - SetControl32BitMinimum( (ControlRef) m_macControl , 0 ) ; - SetControl32BitMaximum( (ControlRef) m_macControl , 100) ; + SetControl32BitMinimum( *m_peer , 0 ) ; + SetControl32BitMaximum( *m_peer , 100) ; if ( n > 0 ) - SetControl32BitValue( (ControlRef) m_macControl , 1 ) ; + SetControl32BitValue( *m_peer , 1 ) ; MacPostControlCreate(pos,size) ; @@ -347,8 +397,12 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, DoAppend( choices[ i ] ); } - HIViewSetVisible( (HIViewRef) m_macControl, true ); + HIViewSetVisible( *m_peer, true ); SetSelection(0); + EventHandlerRef comboEventHandler ; + InstallControlEventHandler( *m_peer, GetwxMacComboBoxEventHandlerUPP(), + GetEventTypeCount(eventList), eventList, this, + (EventHandlerRef *)&comboEventHandler); #else m_choice = new wxComboBoxChoice(this, style ); @@ -384,7 +438,7 @@ wxString wxComboBox::GetValue() const { #if USE_HICOMBOBOX CFStringRef myString; - HIComboBoxCopyTextItemAtIndex( (HIViewRef) m_macControl, (CFIndex)GetSelection(), &myString ); + HIComboBoxCopyTextItemAtIndex( *m_peer, (CFIndex)GetSelection(), &myString ); return wxMacCFStringHolder( myString, m_font.GetEncoding() ).AsString(); #else wxString result; @@ -503,8 +557,8 @@ int wxComboBox::DoAppend(const wxString& item) { #if USE_HICOMBOBOX CFIndex outIndex; - HIComboBoxAppendTextItem( (HIViewRef) m_macControl, wxMacCFStringHolder( item, m_font.GetEncoding() ), &outIndex ); - //SetControl32BitMaximum( (HIViewRef) m_macControl, GetCount() ); + HIComboBoxAppendTextItem( *m_peer, wxMacCFStringHolder( item, m_font.GetEncoding() ), &outIndex ); + //SetControl32BitMaximum( *m_peer, GetCount() ); return (int) outIndex; #else return m_choice->DoAppend( item ) ; @@ -514,9 +568,9 @@ int wxComboBox::DoAppend(const wxString& item) int wxComboBox::DoInsert(const wxString& item, int pos) { #if USE_HICOMBOBOX - HIComboBoxInsertTextItemAtIndex( (HIViewRef) m_macControl, (CFIndex)pos, wxMacCFStringHolder(item, m_font.GetEncoding()) ); + HIComboBoxInsertTextItemAtIndex( *m_peer, (CFIndex)pos, wxMacCFStringHolder(item, m_font.GetEncoding()) ); - //SetControl32BitMaximum( (HIViewRef) m_macControl, GetCount() ); + //SetControl32BitMaximum( *m_peer, GetCount() ); return pos; #else @@ -574,7 +628,7 @@ void wxComboBox::FreeData() int wxComboBox::GetCount() const { #if USE_HICOMBOBOX - return (int) HIComboBoxGetItemCount( (HIViewRef) m_macControl ); + return (int) HIComboBoxGetItemCount( *m_peer ); #else return m_choice->GetCount() ; #endif @@ -583,7 +637,7 @@ int wxComboBox::GetCount() const { void wxComboBox::Delete(int n) { #if USE_HICOMBOBOX - HIComboBoxRemoveItemAtIndex( (HIViewRef) m_macControl, (CFIndex)n ); + HIComboBoxRemoveItemAtIndex( *m_peer, (CFIndex)n ); #else // force client object deletion if( HasClientObjectData() ) @@ -594,10 +648,12 @@ void wxComboBox::Delete(int n) void wxComboBox::Clear() { + FreeData(); #if USE_HICOMBOBOX - //TODO + for ( CFIndex i = GetCount() - 1 ; i >= 0 ; ++ i ) + verify_noerr( HIComboBoxRemoveItemAtIndex( *m_peer, i ) ); + m_peer->SetData(kHIComboBoxEditTextPart,kControlEditTextCFStringTag,CFSTR("")); #else - FreeData(); m_choice->Clear(); #endif } @@ -605,8 +661,7 @@ void wxComboBox::Clear() int wxComboBox::GetSelection() const { #if USE_HICOMBOBOX - int result = GetControl32BitValue( (HIViewRef) m_macControl ) -1; - return result; + return FindString( GetStringSelection() ) ; #else return m_choice->GetSelection(); #endif @@ -615,7 +670,7 @@ int wxComboBox::GetSelection() const void wxComboBox::SetSelection(int n) { #if USE_HICOMBOBOX - SetControl32BitValue( (ControlRef) m_macControl , n + 1 ) ; + SetControl32BitValue( *m_peer , n + 1 ) ; #else m_choice->SetSelection( n ); @@ -644,7 +699,7 @@ wxString wxComboBox::GetString(int n) const { #if USE_HICOMBOBOX CFStringRef itemText; - HIComboBoxCopyTextItemAtIndex( (HIViewRef) m_macControl, (CFIndex)n, &itemText ); + HIComboBoxCopyTextItemAtIndex( *m_peer, (CFIndex)n, &itemText ); return wxMacCFStringHolder(itemText).AsString(); #else return m_choice->GetString( n ); @@ -653,11 +708,15 @@ wxString wxComboBox::GetString(int n) const wxString wxComboBox::GetStringSelection() const { +#if USE_HICOMBOBOX + return wxMacCFStringHolder(m_peer->GetData(kHIComboBoxEditTextPart,kControlEditTextCFStringTag)).AsString() ; +#else int sel = GetSelection (); if (sel > -1) return wxString(this->GetString (sel)); else return wxEmptyString; +#endif } bool wxComboBox::SetStringSelection(const wxString& sel) @@ -675,7 +734,9 @@ bool wxComboBox::SetStringSelection(const wxString& sel) void wxComboBox::SetString(int n, const wxString& s) { #if USE_HICOMBOBOX - + verify_noerr ( HIComboBoxInsertTextItemAtIndex( *m_peer, (CFIndex) n, + wxMacCFStringHolder(s, m_font.GetEncoding()) ) ); + verify_noerr ( HIComboBoxRemoveItemAtIndex( *m_peer, (CFIndex) n + 1 ) ); #else m_choice->SetString( n , s ) ; #endif @@ -684,14 +745,11 @@ void wxComboBox::SetString(int n, const wxString& s) wxInt32 wxComboBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { -/* wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId ); event.SetInt(GetSelection()); event.SetEventObject(this); event.SetString(GetStringSelection()); ProcessCommand(event); return noErr ; -*/ - return eventNotHandledErr ; }