📄 combobxc.cpp
字号:
for ( int i = 0; i < n; i++ )
{
m_choice->DoAppend( choices[ i ] );
}
SetBestSize(csize); // Needed because it is a wxControlWithItems
#endif
return true;
}
wxString wxComboBox::GetValue() const
{
#if USE_HICOMBOBOX
CFStringRef myString;
HIComboBoxCopyTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)GetSelection(), &myString );
return wxMacCFStringHolder( myString, m_font.GetEncoding() ).AsString();
#else
wxString result;
if ( m_text == NULL )
{
result = m_choice->GetString( m_choice->GetSelection() );
}
else
{
result = m_text->GetValue();
}
return result;
#endif
}
void wxComboBox::SetValue(const wxString& value)
{
#if USE_HICOMBOBOX
#else
int s = FindString (value);
if (s == wxNOT_FOUND && !HasFlag(wxCB_READONLY) )
{
m_choice->Append(value);
}
SetStringSelection( value );
#endif
}
// Clipboard operations
void wxComboBox::Copy()
{
if ( m_text != NULL )
{
m_text->Copy();
}
}
void wxComboBox::Cut()
{
if ( m_text != NULL )
{
m_text->Cut();
}
}
void wxComboBox::Paste()
{
if ( m_text != NULL )
{
m_text->Paste();
}
}
void wxComboBox::SetEditable(bool editable)
{
if ( ( m_text == NULL ) && editable )
{
m_text = new wxComboBoxText( this );
}
else if ( ( m_text != NULL ) && !editable )
{
delete m_text;
m_text = NULL;
}
int currentX, currentY;
GetPosition( ¤tX, ¤tY );
int currentW, currentH;
GetSize( ¤tW, ¤tH );
DoMoveWindow( currentX, currentY, currentW, currentH );
}
void wxComboBox::SetInsertionPoint(long pos)
{
// TODO
}
void wxComboBox::SetInsertionPointEnd()
{
// TODO
}
long wxComboBox::GetInsertionPoint() const
{
// TODO
return 0;
}
wxTextPos wxComboBox::GetLastPosition() const
{
// TODO
return 0;
}
void wxComboBox::Replace(long from, long to, const wxString& value)
{
// TODO
}
void wxComboBox::Remove(long from, long to)
{
// TODO
}
void wxComboBox::SetSelection(long from, long to)
{
// TODO
}
int wxComboBox::DoAppend(const wxString& item)
{
#if USE_HICOMBOBOX
CFIndex outIndex;
HIComboBoxAppendTextItem( m_peer->GetControlRef(), wxMacCFStringHolder( item, m_font.GetEncoding() ), &outIndex );
//SetControl32BitMaximum( m_peer->GetControlRef(), GetCount() );
return (int) outIndex;
#else
return m_choice->DoAppend( item );
#endif
}
int wxComboBox::DoInsert(const wxString& item, unsigned int pos)
{
#if USE_HICOMBOBOX
HIComboBoxInsertTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)pos, wxMacCFStringHolder(item, m_font.GetEncoding()) );
//SetControl32BitMaximum( m_peer->GetControlRef(), GetCount() );
return pos;
#else
return m_choice->DoInsert( item , pos );
#endif
}
void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData)
{
#if USE_HICOMBOBOX
return; //TODO
#else
return m_choice->DoSetItemClientData( n , clientData );
#endif
}
void* wxComboBox::DoGetItemClientData(unsigned int n) const
{
#if USE_HICOMBOBOX
return NULL; //TODO
#else
return m_choice->DoGetItemClientData( n );
#endif
}
void wxComboBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData)
{
#if USE_HICOMBOBOX
return; //TODO
#else
return m_choice->DoSetItemClientObject( n , clientData );
#endif
}
wxClientData* wxComboBox::DoGetItemClientObject(unsigned int n) const
{
#if USE_HICOMBOBOX
return NULL;
#else
return m_choice->DoGetItemClientObject( n );
#endif
}
void wxComboBox::FreeData()
{
if (HasClientObjectData())
{
unsigned int count = GetCount();
for ( unsigned int n = 0; n < count; n++ )
{
SetClientObject( n, NULL );
}
}
}
unsigned int wxComboBox::GetCount() const {
#if USE_HICOMBOBOX
return (unsigned int) HIComboBoxGetItemCount( m_peer->GetControlRef() );
#else
return m_choice->GetCount();
#endif
}
void wxComboBox::Delete(unsigned int n)
{
#if USE_HICOMBOBOX
HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), (CFIndex)n );
#else
// force client object deletion
if( HasClientObjectData() )
SetClientObject( n, NULL );
m_choice->Delete( n );
#endif
}
void wxComboBox::Clear()
{
FreeData();
#if USE_HICOMBOBOX
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();
#endif
}
int wxComboBox::GetSelection() const
{
#if USE_HICOMBOBOX
return FindString( GetStringSelection() );
#else
return m_choice->GetSelection();
#endif
}
void wxComboBox::SetSelection(int n)
{
#if USE_HICOMBOBOX
SetControl32BitValue( m_peer->GetControlRef() , n + 1 );
#else
m_choice->SetSelection( n );
if ( m_text != NULL )
{
m_text->SetValue(GetString(n));
}
#endif
}
int wxComboBox::FindString(const wxString& s, bool bCase) const
{
#if USE_HICOMBOBOX
for( unsigned int i = 0 ; i < GetCount() ; i++ )
{
if (GetString(i).IsSameAs(s, bCase) )
return i ;
}
return wxNOT_FOUND;
#else
return m_choice->FindString( s, bCase );
#endif
}
wxString wxComboBox::GetString(unsigned int n) const
{
#if USE_HICOMBOBOX
CFStringRef itemText;
HIComboBoxCopyTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)n, &itemText );
return wxMacCFStringHolder(itemText).AsString();
#else
return m_choice->GetString( n );
#endif
}
wxString wxComboBox::GetStringSelection() const
{
#if USE_HICOMBOBOX
return wxMacCFStringHolder(m_peer->GetData<CFStringRef>(kHIComboBoxEditTextPart,kControlEditTextCFStringTag)).AsString();
#else
int sel = GetSelection ();
if (sel != wxNOT_FOUND)
return wxString(this->GetString((unsigned int)sel));
else
return wxEmptyString;
#endif
}
void wxComboBox::SetString(unsigned int n, const wxString& s)
{
#if USE_HICOMBOBOX
verify_noerr ( HIComboBoxInsertTextItemAtIndex( m_peer->GetControlRef(), (CFIndex) n,
wxMacCFStringHolder(s, m_font.GetEncoding()) ) );
verify_noerr ( HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), (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) )
{
wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
event.SetInt(GetSelection());
event.SetEventObject(this);
event.SetString(GetStringSelection());
ProcessCommand(event);
return noErr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -