X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/655719367ac5e131d9642e5783f3ecf64d1a3385..fc32cd4a59dc7c6cedea430750b2ce2c2a342353:/src/mac/carbon/combobxc.cpp diff --git a/src/mac/carbon/combobxc.cpp b/src/mac/carbon/combobxc.cpp index 8f1e122bd0..b26e9741da 100644 --- a/src/mac/carbon/combobxc.cpp +++ b/src/mac/carbon/combobxc.cpp @@ -36,13 +36,55 @@ IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) #endif static int nextPopUpMenuId = 1000 ; -MenuHandle NewUniqueMenu() +MenuHandle NewUniqueMenu() { 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 ; + + 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 @@ -127,7 +169,7 @@ protected: return; } } - + event.Skip(); } private: @@ -166,7 +208,7 @@ protected: wxSize sz = wxChoice::DoGetBestSize() ; sz.x = POPUPWIDTH ; return sz ; - } + } private: wxComboBox *m_cb; @@ -207,11 +249,11 @@ wxSize wxComboBox::DoGetBestSize() const return wxControl::DoGetBestSize(); #else wxSize size = m_choice->GetBestSize(); - + if ( m_text != NULL ) { wxSize sizeText = m_text->GetBestSize(); - + size.x = POPUPWIDTH + sizeText.x + MARGIN; } @@ -224,7 +266,7 @@ void wxComboBox::DoMoveWindow(int x, int y, int width, int height) { wxControl::DoMoveWindow(x, y, width, height); #else height = POPUPHEIGHT; - + wxControl::DoMoveWindow(x, y, width, height); if ( m_text == NULL ) @@ -239,7 +281,7 @@ void wxComboBox::DoMoveWindow(int x, int y, int width, int height) { m_text->SetSize(0, 0, wText, height); m_choice->SetSize(0 + wText + MARGIN, 0, POPUPWIDTH, -1); } -#endif +#endif } @@ -326,12 +368,12 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, #if USE_HICOMBOBOX Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; HIRect hiRect; - + hiRect.origin.x = 20; //bounds.left; hiRect.origin.y = 25; //bounds.top; hiRect.size.width = 120;// bounds.right - bounds.left; - hiRect.size.height = 24; - + hiRect.size.height = 24; + //For some reason, this code causes the combo box not to be displayed at all. //hiRect.origin.x = bounds.left; //hiRect.origin.y = bounds.top; @@ -339,28 +381,34 @@ 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) ; - + for ( int i = 0 ; i < n ; i++ ) { 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 ); m_choice = new wxComboBoxChoice(this, style ); m_choice->SetSizeHints( wxSize( POPUPWIDTH , POPUPHEIGHT ) ) ; - + wxSize csize = size; if ( style & wxCB_READONLY ) { @@ -373,9 +421,9 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, 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 ] ); @@ -390,11 +438,11 @@ 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; - + if ( m_text == NULL ) { result = m_choice->GetString( m_choice->GetSelection() ); @@ -403,7 +451,7 @@ wxString wxComboBox::GetValue() const { result = m_text->GetValue(); } - + return result; #endif } @@ -411,7 +459,7 @@ wxString wxComboBox::GetValue() const void wxComboBox::SetValue(const wxString& value) { #if USE_HICOMBOBOX - + #else int s = FindString (value); if (s == wxNOT_FOUND && !HasFlag(wxCB_READONLY) ) @@ -461,7 +509,7 @@ void wxComboBox::SetEditable(bool editable) int currentX, currentY; GetPosition( ¤tX, ¤tY ); - + int currentW, currentH; GetSize( ¤tW, ¤tH ); @@ -505,32 +553,32 @@ void wxComboBox::SetSelection(long from, long to) // TODO } -int wxComboBox::DoAppend(const wxString& item) +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 ) ; #endif } -int wxComboBox::DoInsert(const wxString& item, int pos) +int wxComboBox::DoInsert(const wxString& item, int pos) { #if USE_HICOMBOBOX - HIComboBoxInsertTextItemAtIndex( (HIViewRef) m_macControl, (CFIndex)pos, wxMacCFStringHolder(item, m_font.GetEncoding()) ); - - //SetControl32BitMaximum( (HIViewRef) m_macControl, GetCount() ); - + HIComboBoxInsertTextItemAtIndex( *m_peer, (CFIndex)pos, wxMacCFStringHolder(item, m_font.GetEncoding()) ); + + //SetControl32BitMaximum( *m_peer, GetCount() ); + return pos; #else return m_choice->DoInsert( item , pos ) ; #endif } -void wxComboBox::DoSetItemClientData(int n, void* clientData) +void wxComboBox::DoSetItemClientData(int n, void* clientData) { #if USE_HICOMBOBOX return; //TODO @@ -557,7 +605,7 @@ void wxComboBox::DoSetItemClientObject(int n, wxClientData* clientData) #endif } -wxClientData* wxComboBox::DoGetItemClientObject(int n) const +wxClientData* wxComboBox::DoGetItemClientObject(int n) const { #if USE_HICOMBOBOX return NULL; @@ -580,16 +628,16 @@ 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() ; + 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() ) @@ -603,11 +651,8 @@ void wxComboBox::Clear() FreeData(); #if USE_HICOMBOBOX for ( CFIndex i = GetCount() - 1 ; i >= 0 ; ++ i ) - verify_noerr( HIComboBoxRemoveItemAtIndex( (HIViewRef) m_macControl, i ) ); - wxMacCFStringHolder cf(wxEmptyString,m_font.GetEncoding()) ; - CFStringRef cfr = cf ; - SetControlData((ControlRef) m_macControl,kHIComboBoxEditTextPart,kControlEditTextCFStringTag, - sizeof(CFStringRef),(Ptr) &cfr); + verify_noerr( HIComboBoxRemoveItemAtIndex( *m_peer, i ) ); + m_peer->SetData(kHIComboBoxEditTextPart,kControlEditTextCFStringTag,CFSTR("")); #else m_choice->Clear(); #endif @@ -625,10 +670,10 @@ 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 ); - + if ( m_text != NULL ) { m_text->SetValue( GetString( n ) ); @@ -654,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 ); @@ -664,12 +709,7 @@ wxString wxComboBox::GetString(int n) const wxString wxComboBox::GetStringSelection() const { #if USE_HICOMBOBOX - CFStringRef cfr ; - verify_noerr(GetControlData((ControlRef) m_macControl,kHIComboBoxEditTextPart,kControlEditTextCFStringTag, - sizeof(CFStringRef),(Ptr) &cfr,NULL)); - // takes of release responsibility - wxMacCFStringHolder cf( cfr ) ; - return cf.AsString() ; + return wxMacCFStringHolder(m_peer->GetData(kHIComboBoxEditTextPart,kControlEditTextCFStringTag)).AsString() ; #else int sel = GetSelection (); if (sel > -1) @@ -691,19 +731,123 @@ bool wxComboBox::SetStringSelection(const wxString& sel) return FALSE; } -void wxComboBox::SetString(int n, const wxString& s) +void wxComboBox::SetString(int n, const wxString& s) { #if USE_HICOMBOBOX - verify_noerr ( HIComboBoxInsertTextItemAtIndex( (HIViewRef) m_macControl, (CFIndex) n, + verify_noerr ( HIComboBoxInsertTextItemAtIndex( *m_peer, (CFIndex) n, wxMacCFStringHolder(s, m_font.GetEncoding()) ) ); - verify_noerr ( HIComboBoxRemoveItemAtIndex( (HIViewRef) m_macControl, (CFIndex) n + 1 ) ); + verify_noerr ( HIComboBoxRemoveItemAtIndex( *m_peer, (CFIndex) n + 1 ) ); #else m_choice->SetString( n , s ) ; #endif } +bool wxComboBox::IsEditable() const +{ +#if USE_HICOMBOBOX + // TODO + return !HasFlag(wxCB_READONLY); +#else + return m_text != NULL && !HasFlag(wxCB_READONLY); +#endif +} + +void wxComboBox::Undo() +{ +#if USE_HICOMBOBOX + // TODO +#else + if (m_text != NULL) + m_text->Undo(); +#endif +} + +void wxComboBox::Redo() +{ +#if USE_HICOMBOBOX + // TODO +#else + if (m_text != NULL) + m_text->Redo(); +#endif +} + +void wxComboBox::SelectAll() +{ +#if USE_HICOMBOBOX + // TODO +#else + if (m_text != NULL) + m_text->SelectAll(); +#endif +} + +bool wxComboBox::CanCopy() const +{ +#if USE_HICOMBOBOX + // TODO + return false; +#else + if (m_text != NULL) + return m_text->CanCopy(); + else + return false; +#endif +} + +bool wxComboBox::CanCut() const +{ +#if USE_HICOMBOBOX + // TODO + return false; +#else + if (m_text != NULL) + return m_text->CanCut(); + else + return false; +#endif +} + +bool wxComboBox::CanPaste() const +{ +#if USE_HICOMBOBOX + // TODO + return false; +#else + if (m_text != NULL) + return m_text->CanPaste(); + else + return false; +#endif +} + +bool wxComboBox::CanUndo() const +{ +#if USE_HICOMBOBOX + // TODO + return false; +#else + if (m_text != NULL) + return m_text->CanUndo(); + else + return false; +#endif +} + +bool wxComboBox::CanRedo() const +{ +#if USE_HICOMBOBOX + // TODO + return false; +#else + if (m_text != NULL) + return m_text->CanRedo(); + else + return false; +#endif +} -wxInt32 wxComboBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) +wxInt32 wxComboBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId ); event.SetInt(GetSelection());