#include "wx/button.h"
#include "wx/menu.h"
#include "wx/mac/uma.h"
+#if TARGET_API_MAC_OSX
#ifndef __HIVIEW__
#include <HIToolbox/HIView.h>
#endif
+#endif
#if !USE_SHARED_LIBRARY
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()
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
//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) ;
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 );
{
#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;
{
#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 ) ;
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
int wxComboBox::GetCount() const {
#if USE_HICOMBOBOX
- return (int) HIComboBoxGetItemCount( (HIViewRef) m_macControl );
+ return (int) HIComboBoxGetItemCount( *m_peer );
#else
return m_choice->GetCount() ;
#endif
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() )
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<CFStringRef>(kHIComboBoxEditTextPart,kControlEditTextCFStringTag,CFSTR(""));
#else
- FreeData();
m_choice->Clear();
#endif
}
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
void wxComboBox::SetSelection(int n)
{
#if USE_HICOMBOBOX
- SetControl32BitValue( (ControlRef) m_macControl , n + 1 ) ;
+ SetControl32BitValue( *m_peer , n + 1 ) ;
#else
m_choice->SetSelection( n );
{
#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 );
wxString wxComboBox::GetStringSelection() const
{
+#if USE_HICOMBOBOX
+ return wxMacCFStringHolder(m_peer->GetData<CFStringRef>(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)
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
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 ;
}