📄 combobox.cpp
字号:
const wxPoint& pos, const wxSize& size, const wxArrayString& choices, long style, const wxValidator& validator, const wxString& name){ wxCArrayString chs( choices ); return Create( parent, id, value, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name );}bool wxComboBox::Create(wxWindow *parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, int n, const wxString choices[], long style, const wxValidator& validator, const wxString& name){ if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, style , validator, name) ) { return false; } m_choice = new wxComboBoxChoice(this, style ); wxSize csize = size; if ( style & wxCB_READONLY ) { m_text = NULL; } else { m_text = new wxComboBoxText(this); if ( size.y == -1 ) { csize.y = m_text->GetSize().y ; csize.y += 2 * TEXTFOCUSBORDER ; } } DoSetSize(pos.x, pos.y, csize.x, csize.y); for ( int i = 0 ; i < n ; i++ ) { m_choice->DoAppend( choices[ i ] ); } // Needed because it is a wxControlWithItems SetInitialSize(size); SetStringSelection(value); return true;}wxString wxComboBox::GetValue() const{ wxString result; if ( m_text == NULL ) result = m_choice->GetString( m_choice->GetSelection() ); else result = m_text->GetValue(); return result;}unsigned int wxComboBox::GetCount() const{ return m_choice->GetCount() ;}void wxComboBox::SetValue(const wxString& value){ if ( HasFlag(wxCB_READONLY) ) SetStringSelection( value ) ; else m_text->SetValue( value );}// Clipboard operationsvoid 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){ if ( m_text ) m_text->SetInsertionPoint(pos);}void wxComboBox::SetInsertionPointEnd(){ if ( m_text ) m_text->SetInsertionPointEnd();}long wxComboBox::GetInsertionPoint() const{ if ( m_text ) return m_text->GetInsertionPoint(); return 0;}wxTextPos wxComboBox::GetLastPosition() const{ if ( m_text ) return m_text->GetLastPosition(); return 0;}void wxComboBox::Replace(long from, long to, const wxString& value){ if ( m_text ) m_text->Replace(from,to,value);}void wxComboBox::Remove(long from, long to){ if ( m_text ) m_text->Remove(from,to);}void wxComboBox::SetSelection(long from, long to){ if ( m_text ) m_text->SetSelection(from,to);}int wxComboBox::DoAppend(const wxString& item){ return m_choice->DoAppend( item ) ;}int wxComboBox::DoInsert(const wxString& item, unsigned int pos){ return m_choice->DoInsert( item , pos ) ;}void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData){ return m_choice->DoSetItemClientData( n , clientData ) ;}void* wxComboBox::DoGetItemClientData(unsigned int n) const{ return m_choice->DoGetItemClientData( n ) ;}void wxComboBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData){ return m_choice->DoSetItemClientObject(n, clientData);}wxClientData* wxComboBox::DoGetItemClientObject(unsigned int n) const{ return m_choice->DoGetItemClientObject( n ) ;}void wxComboBox::FreeData(){ if ( HasClientObjectData() ) { unsigned int count = GetCount(); for ( unsigned int n = 0; n < count; n++ ) { SetClientObject( n, NULL ); } }}void wxComboBox::Delete(unsigned int n){ // force client object deletion if( HasClientObjectData() ) SetClientObject( n, NULL ); m_choice->Delete( n );}void wxComboBox::Clear(){ FreeData(); m_choice->Clear();}int wxComboBox::GetSelection() const{ return m_choice->GetSelection();}void wxComboBox::SetSelection(int n){ m_choice->SetSelection( n ); if ( m_text != NULL ) m_text->SetValue(GetString(n));}int wxComboBox::FindString(const wxString& s, bool bCase) const{ return m_choice->FindString( s, bCase );}wxString wxComboBox::GetString(unsigned int n) const{ return m_choice->GetString( n );}wxString wxComboBox::GetStringSelection() const{ int sel = GetSelection(); if (sel != wxNOT_FOUND) return wxString(this->GetString((unsigned int)sel)); else return wxEmptyString;}void wxComboBox::SetString(unsigned int n, const wxString& s){ m_choice->SetString( n , s );}bool wxComboBox::IsEditable() const{ return m_text != NULL && !HasFlag(wxCB_READONLY);}void wxComboBox::Undo(){ if (m_text != NULL) m_text->Undo();}void wxComboBox::Redo(){ if (m_text != NULL) m_text->Redo();}void wxComboBox::SelectAll(){ if (m_text != NULL) m_text->SelectAll();}bool wxComboBox::CanCopy() const{ if (m_text != NULL) return m_text->CanCopy(); else return false;}bool wxComboBox::CanCut() const{ if (m_text != NULL) return m_text->CanCut(); else return false;}bool wxComboBox::CanPaste() const{ if (m_text != NULL) return m_text->CanPaste(); else return false;}bool wxComboBox::CanUndo() const{ if (m_text != NULL) return m_text->CanUndo(); else return false;}bool wxComboBox::CanRedo() const{ if (m_text != NULL) return m_text->CanRedo(); else return false;}wxInt32 wxComboBox::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ){/* For consistency with other platforms, clicking in the text area does not constitute a selection wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId ); event.SetInt(GetSelection()); event.SetEventObject(this); event.SetString(GetStringSelection()); ProcessCommand(event);*/ return noErr ;}#endif // wxUSE_COMBOBOX
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -