/////////////////////////////////////////////////////////////////////////////
-// Name: src/mac/carbon/combobox.cpp
-// Purpose: wxComboBox class
+// Name: src/mac/carbon/combobxc.cpp
+// Purpose: wxComboBox class using HIView ComboBox
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
#include "wx/wxprec.h"
#include "wx/combobox.h"
-#include "wx/button.h"
-#include "wx/menu.h"
+
+#ifndef WX_PRECOMP
+ #include "wx/button.h"
+ #include "wx/menu.h"
+#endif
+
#include "wx/mac/uma.h"
#if TARGET_API_MAC_OSX
#ifndef __HIVIEW__
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 ;
+static int nextPopUpMenuId = 1000;
MenuHandle NewUniqueMenu()
{
- MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" ) ;
- nextPopUpMenuId++ ;
- return handle ;
+ MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" );
+ nextPopUpMenuId++;
+ 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 ;
+ OSStatus result = eventNotHandledErr;
+ wxComboBox* cb = (wxComboBox*) data;
- wxMacCarbonEvent cEvent( event ) ;
+ wxMacCarbonEvent cEvent( event );
switch( cEvent.GetClass() )
{
event.SetInt( cb->GetSelection() );
event.SetString( cb->GetStringSelection() );
event.SetEventObject( cb );
- cb->GetEventHandler()->ProcessEvent( event );
+ cb->HandleWindowEvent( event );
}
- break ;
+ break;
default :
- break ;
+ break;
}
- break ;
+ break;
default :
- break ;
+ break;
}
- return result ;
+ return result;
}
DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacComboBoxEventHandler )
event.SetInt( 0 );
event.SetString( value );
event.SetEventObject( m_cb );
- m_cb->GetEventHandler()->ProcessEvent( event );
+ m_cb->HandleWindowEvent( event );
}
else
{
event.SetInt( m_cb->GetCount() - 1 );
event.SetString( value );
event.SetEventObject( m_cb );
- m_cb->GetEventHandler()->ProcessEvent( event );
+ m_cb->HandleWindowEvent( event );
}
// This will invoke the dialog default action, such
// as the clicking the default button.
- wxWindow *parent = GetParent();
- while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) {
- parent = parent->GetParent() ;
- }
- if ( parent && parent->GetDefaultItem() )
+ wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+ if ( tlw && tlw->GetDefaultItem() )
{
- wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
- wxButton);
+ wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
if ( def && def->IsEnabled() )
{
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
event.SetEventObject(def);
def->Command(event);
- return ;
+ return;
}
}
}
virtual wxSize DoGetBestSize() const
{
- wxSize sz = wxChoice::DoGetBestSize() ;
- sz.x = POPUPWIDTH ;
- return sz ;
+ wxSize sz = wxChoice::DoGetBestSize();
+ sz.x = POPUPWIDTH;
+ return sz;
}
private:
wxComboBox::~wxComboBox()
{
- // delete client objects
- FreeData();
-
// delete the controls now, don't leave them alive even though they would
// still be eventually deleted by our parent - but it will be too late, the
// user code expects them to be gone now
m_text = NULL;
m_choice = NULL;
#if USE_HICOMBOBOX
- m_macIsUserPane = false ;
+ m_macIsUserPane = false;
#endif
if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, style ,
wxDefaultValidator, name) )
return false;
}
#if USE_HICOMBOBOX
- Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
+ Rect bounds = wxMacGetBoundsForControl( this , pos , size );
HIRect hiRect;
hiRect.origin.x = 20; //bounds.left;
//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);
- m_peer = new wxMacControl(this) ;
- verify_noerr( HIComboBoxCreate( &hiRect, CFSTR(""), NULL, NULL, kHIComboBoxStandardAttributes, *m_peer ) );
+ m_peer = new wxMacControl(this);
+ verify_noerr( HIComboBoxCreate( &hiRect, CFSTR(""), NULL, NULL, kHIComboBoxStandardAttributes, m_peer->GetControlRefAddr() ) );
- SetControl32BitMinimum( *m_peer , 0 ) ;
- SetControl32BitMaximum( *m_peer , 100) ;
+ m_peer->SetMinimum( 0 );
+ m_peer->SetMaximum( 100);
if ( n > 0 )
- SetControl32BitValue( *m_peer , 1 ) ;
+ m_peer->SetValue( 1 );
- MacPostControlCreate(pos,size) ;
+ MacPostControlCreate(pos,size);
- for ( int i = 0 ; i < n ; i++ )
- {
- DoAppend( choices[ i ] );
- }
+ Append( choices[ i ] );
- HIViewSetVisible( *m_peer, true );
+ HIViewSetVisible( m_peer->GetControlRef(), true );
SetSelection(0);
- EventHandlerRef comboEventHandler ;
- InstallControlEventHandler( *m_peer, GetwxMacComboBoxEventHandlerUPP(),
+ EventHandlerRef comboEventHandler;
+ InstallControlEventHandler( m_peer->GetControlRef(), GetwxMacComboBoxEventHandlerUPP(),
GetEventTypeCount(eventList), eventList, this,
(EventHandlerRef *)&comboEventHandler);
#else
m_choice = new wxComboBoxChoice(this, style );
-
- m_choice = new wxComboBoxChoice(this, style );
- m_choice->SetSizeHints( wxSize( POPUPWIDTH , POPUPHEIGHT ) ) ;
+ m_choice->SetMinSize( wxSize( POPUPWIDTH , POPUPHEIGHT ) );
wxSize csize = size;
if ( style & wxCB_READONLY )
{
m_text = new wxComboBoxText(this);
if ( size.y == wxDefaultCoord ) {
- csize.y = m_text->GetSize().y ;
+ csize.y = m_text->GetSize().y;
}
}
DoSetSize(pos.x, pos.y, csize.x, csize.y);
- for ( int i = 0 ; i < n ; i++ )
- {
- m_choice->DoAppend( choices[ i ] );
- }
- SetBestSize(csize); // Needed because it is a wxControlWithItems
+ m_choice->Append( n, choices );
+ SetInitialSize(csize); // Needed because it is a wxControlWithItems
#endif
return true;
{
#if USE_HICOMBOBOX
CFStringRef myString;
- HIComboBoxCopyTextItemAtIndex( *m_peer, (CFIndex)GetSelection(), &myString );
- return wxMacCFStringHolder( myString, m_font.GetEncoding() ).AsString();
+ HIComboBoxCopyTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)GetSelection(), &myString );
+ return wxMacCFStringHolder( myString, GetFont().GetEncoding() ).AsString();
#else
wxString result;
int s = FindString (value);
if (s == wxNOT_FOUND && !HasFlag(wxCB_READONLY) )
{
- m_choice->Append(value) ;
+ m_choice->Append(value);
}
- SetStringSelection( value ) ;
+ SetStringSelection( value );
#endif
}
// TODO
}
-int wxComboBox::DoAppend(const wxString& item)
+int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items,
+ unsigned int pos,
+ void **clientData, wxClientDataType type)
{
#if USE_HICOMBOBOX
- CFIndex outIndex;
- HIComboBoxAppendTextItem( *m_peer, wxMacCFStringHolder( item, m_font.GetEncoding() ), &outIndex );
- //SetControl32BitMaximum( *m_peer, GetCount() );
- return (int) outIndex;
-#else
- return m_choice->DoAppend( item ) ;
-#endif
-}
-
-int wxComboBox::DoInsert(const wxString& item, int pos)
-{
-#if USE_HICOMBOBOX
- HIComboBoxInsertTextItemAtIndex( *m_peer, (CFIndex)pos, wxMacCFStringHolder(item, m_font.GetEncoding()) );
+ const unsigned int count = items.GetCount();
+ for ( unsigned int i = 0; i < count; ++i, ++pos )
+ {
+ HIComboBoxInsertTextItemAtIndex(m_peer->GetControlRef(),
+ (CFIndex)pos,
+ wxMacCFStringHolder(items[i],
+ GetFont().GetEncoding()));
+ AssignNewItemClientData(pos, clientData, i, type);
+ }
- //SetControl32BitMaximum( *m_peer, GetCount() );
+ //SetControl32BitMaximum( m_peer->GetControlRef(), GetCount() );
- return pos;
+ return pos - 1;
#else
- return m_choice->DoInsert( item , pos ) ;
+ return m_choice->DoInsertItems( items, pos, clientData, type );
#endif
}
-void wxComboBox::DoSetItemClientData(int n, void* clientData)
+void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData)
{
#if USE_HICOMBOBOX
return; //TODO
#else
- return m_choice->DoSetItemClientData( n , clientData ) ;
+ return m_choice->DoSetItemClientData( n , clientData );
#endif
}
-void* wxComboBox::DoGetItemClientData(int n) const
+void* wxComboBox::DoGetItemClientData(unsigned int n) const
{
#if USE_HICOMBOBOX
return NULL; //TODO
#else
- return m_choice->DoGetItemClientData( n ) ;
+ return m_choice->DoGetItemClientData( n );
#endif
}
-void wxComboBox::DoSetItemClientObject(int n, wxClientData* clientData)
-{
-#if USE_HICOMBOBOX
- return; //TODO
-#else
- return m_choice->DoSetItemClientObject( n , clientData ) ;
-#endif
-}
-
-wxClientData* wxComboBox::DoGetItemClientObject(int n) const
-{
-#if USE_HICOMBOBOX
- return NULL;
-#else
- return m_choice->DoGetItemClientObject( n ) ;
-#endif
-}
-
-void wxComboBox::FreeData()
-{
- if ( HasClientObjectData() )
- {
- size_t count = GetCount();
- for ( size_t n = 0; n < count; n++ )
- {
- SetClientObject( n, NULL );
- }
- }
-}
-
-int wxComboBox::GetCount() const {
+unsigned int wxComboBox::GetCount() const {
#if USE_HICOMBOBOX
- return (int) HIComboBoxGetItemCount( *m_peer );
+ return (unsigned int) HIComboBoxGetItemCount( m_peer->GetControlRef() );
#else
- return m_choice->GetCount() ;
+ return m_choice->GetCount();
#endif
}
-void wxComboBox::Delete(int n)
+void wxComboBox::DoDeleteOneItem(unsigned int n)
{
#if USE_HICOMBOBOX
- HIComboBoxRemoveItemAtIndex( *m_peer, (CFIndex)n );
+ HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), (CFIndex)n );
#else
- // force client object deletion
- if( HasClientObjectData() )
- SetClientObject( n, NULL );
m_choice->Delete( n );
#endif
}
-void wxComboBox::Clear()
+void wxComboBox::DoClear()
{
- FreeData();
#if USE_HICOMBOBOX
- for ( CFIndex i = GetCount() - 1 ; i >= 0 ; ++ i )
- verify_noerr( HIComboBoxRemoveItemAtIndex( *m_peer, i ) );
+ for ( CFIndex i = GetCount() - 1; i >= 0; ++ i )
+ verify_noerr( HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), i ) );
m_peer->SetData<CFStringRef>(kHIComboBoxEditTextPart,kControlEditTextCFStringTag,CFSTR(""));
#else
m_choice->Clear();
int wxComboBox::GetSelection() const
{
#if USE_HICOMBOBOX
- return FindString( GetStringSelection() ) ;
+ return FindString( GetStringSelection() );
#else
return m_choice->GetSelection();
#endif
void wxComboBox::SetSelection(int n)
{
#if USE_HICOMBOBOX
- SetControl32BitValue( *m_peer , n + 1 ) ;
+ SetControl32BitValue( m_peer->GetControlRef() , n + 1 );
#else
m_choice->SetSelection( n );
if ( m_text != NULL )
{
- m_text->SetValue( GetString( n ) );
+ m_text->SetValue(GetString(n));
}
#endif
}
int wxComboBox::FindString(const wxString& s, bool bCase) const
{
#if USE_HICOMBOBOX
- for( int i = 0 ; i < GetCount() ; i++ )
+ for( unsigned int i = 0 ; i < GetCount() ; i++ )
{
- if ( GetString( i ).IsSameAs(s, bCase) )
+ if (GetString(i).IsSameAs(s, bCase) )
return i ;
}
- return wxNOT_FOUND ;
+ return wxNOT_FOUND;
#else
return m_choice->FindString( s, bCase );
#endif
}
-wxString wxComboBox::GetString(int n) const
+wxString wxComboBox::GetString(unsigned int n) const
{
#if USE_HICOMBOBOX
CFStringRef itemText;
- HIComboBoxCopyTextItemAtIndex( *m_peer, (CFIndex)n, &itemText );
+ HIComboBoxCopyTextItemAtIndex( m_peer->GetControlRef(), (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() ;
+ return wxMacCFStringHolder(m_peer->GetData<CFStringRef>(kHIComboBoxEditTextPart,kControlEditTextCFStringTag)).AsString();
#else
int sel = GetSelection ();
- if (sel > -1)
- return wxString(this->GetString (sel));
+ if (sel != wxNOT_FOUND)
+ return wxString(this->GetString((unsigned int)sel));
else
return wxEmptyString;
#endif
}
-void wxComboBox::SetString(int n, const wxString& s)
+void wxComboBox::SetString(unsigned 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 ) );
+ verify_noerr ( HIComboBoxInsertTextItemAtIndex( m_peer->GetControlRef(), (CFIndex) n,
+ wxMacCFStringHolder(s, GetFont().GetEncoding()) ) );
+ verify_noerr ( HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), (CFIndex) n + 1 ) );
#else
- m_choice->SetString( n , s ) ;
+ m_choice->SetString( n , s );
#endif
}
event.SetEventObject(this);
event.SetString(GetStringSelection());
ProcessCommand(event);
- return noErr ;
+ return noErr;
}