📄 choicectrl.cpp
字号:
/* ChoiceCtrl.cpp *//******************************************************************************************* Copyright 2002-2003 ATMEL Corporation. This file is part of ATMEL Wireless LAN Drivers. ATMEL Wireless LAN Drivers is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ATMEL Wireless LAN Drivers is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ATMEL Wireless LAN Drivers; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*******************************************************************************************/#include "ChoiceCtrl.h"// CAutoChoice class implementation//==================================CAutoChoice::CAutoChoice( wxWindow *parent, int id, const wxPoint &pos, const wxSize &size, int n, wxString choices[ ], long style ) : wxChoice( parent, id, pos, size, n, choices, style ){ if( n != 0 ) { SetSelection( 0 ); }}CAutoChoice::CAutoChoice( wxWindow *parent, int id, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style ) : wxChoice( ){ int count = choices.GetCount( ); wxString *str_choices = new wxString[ count ]; for( int c = 0; c < count; c++ ) { str_choices[ c ] = choices[ c ]; } Create( parent, id, pos, size, count, str_choices, style ); if( count != 0 ) { SetSelection( 0 ); } delete str_choices;}CAutoChoice::~CAutoChoice( ){}bool CAutoChoice::SetStringSelection( const wxString &string ){ if( FindString( string ) != -1 ) { return wxChoice::SetStringSelection( string ); } else { SetSelection( 0 ); } return false;}void CAutoChoice::SetStrings( const wxString choices[], int n ){ wxArrayString array; for( int c = 0; c < n; c++ ) { array.Add( choices[ c ] ); } SetStrings( array ); return;}void CAutoChoice::SetStrings( wxArrayString &choices ){ wxString sel = GetStringSelection(); int sel_index = -1; while( GetCount() > 0 ) { Delete( 0 ); } for( unsigned int c = 0; c < choices.GetCount(); c++ ) { Append( choices[ c ] ); if( sel == choices[ c ] ) { sel_index = c; } } if( sel_index != -1 ) { SetSelection( sel_index ); } else { SetSelection( 0 ); } return;}// CStringHistory class implementation//=====================================CStringHistory::CStringHistory( int max_size ){ SetMaxSize( max_size );}CStringHistory::~CStringHistory( ){}int CStringHistory::GetMaxSize( ){ return mMaxSize;}void CStringHistory::SetMaxSize( int max_size ){ wxASSERT_MSG( max_size > 0, _( "CHistory::mMaxSize must be a positive integer." ) ); while( mStrings.GetCount( ) > max_size ) { mStrings.RemoveAt( 0 ); } mMaxSize = max_size; return;} bool CStringHistory::Add( const wxString &entry ){ if( mStrings.Index( entry ) != wxNOT_FOUND ) { return false; } mStrings.Add( entry ); if( mStrings.GetCount( ) > mMaxSize ) { mStrings.RemoveAt( 0 ); } return true;}int CStringHistory::GetCount( ){ return mStrings.GetCount( );}void CStringHistory::Clear( ){ mStrings.Clear( ); return;}wxString CStringHistory::GetEntry( int index ){ wxString ret = _( "" ); if( index < mStrings.GetCount( ) ) { ret = mStrings[ index ]; } return ret;}wxString CStringHistory::operator [ ]( int index ){ return GetEntry( index );}// CHistoryCombo class implementation//====================================CHistoryCombo::CHistoryCombo( wxWindow *parent, int id, const wxString &value, const wxPoint &pos, const wxSize &size, int n, const wxString choices[ ], long style ) : wxComboBox( parent, id, value, pos, size, n, choices, style ){ mHistoryAutoUpdateCounter = 0; mMaxLength = -1; wxEvtHandler::Connect( GetId( ), wxEVT_COMMAND_TEXT_UPDATED, ( wxObjectEventFunction ) ( wxEventFunction ) ( wxCommandEventFunction ) &CHistoryCombo::OnText, NULL );}CHistoryCombo::~CHistoryCombo( ){}void CHistoryCombo::BeginHistoryChanges( ){ mHistoryAutoUpdateCounter++; return;}void CHistoryCombo::AddHistory( const wxString &entry ){ BeginHistoryChanges( ); mHistory.Add( entry ); EndHistoryChanges( ); return;}void CHistoryCombo::ClearHistory( ){ BeginHistoryChanges( ); mHistory.Clear( ); EndHistoryChanges( ); return;}void CHistoryCombo::EndHistoryChanges( ){ wxASSERT_MSG( mHistoryAutoUpdateCounter > 0, _( "History update counter is zero or negative and it is about to decrease!" ) ); mHistoryAutoUpdateCounter--; if( mHistoryAutoUpdateCounter == 0 ) { refresh_history_list( ); } return;}void CHistoryCombo::SetHistoryMaxSize( int size ){ mHistory.SetMaxSize( size ); return;}int CHistoryCombo::GetHistorySize( ){ return mHistory.GetCount( );}wxString CHistoryCombo::GetHistoryEntry( int index ){ return mHistory[ index ];}void CHistoryCombo::SetValueEx( const wxString &value ){ if( value != _( "" ) ) { AddHistory( value ); } wxComboBox::SetValue( value ); return;}void CHistoryCombo::SetMaxLength( int max_length ){ wxString cur_val = GetValue( ); mMaxLength = max_length;// XXX: Implementation incombatibility between wxTextCtrl::SetMaxLength( ) and CHistoryCombo::SetMaxLength( ) if( mMaxLength != -1 ) { if( cur_val.Len( ) >= mMaxLength ) { wxComboBox::SetValue( cur_val.Mid( 0, mMaxLength ) ); } } return;}void CHistoryCombo::refresh_history_list( ){ int count = GetHistorySize( ); wxString old_value = GetValue( ); Clear( ); for( int c = count - 1; c >= 0; c-- ) { Append( GetHistoryEntry( c ) ); } SetValue( old_value ); return;}void CHistoryCombo::OnText( wxCommandEvent &event ){ static bool in_ontext = false; if( in_ontext == true ) { return; } in_ontext = true; event.Skip( ); SetMaxLength( mMaxLength ); in_ontext = false; return;}// CRadioListBox class implementation//====================================CRadioListBox::CRadioListBox( wxWindow *parent, int id, const wxPoint &pos, const wxSize &size, long style ) : wxCheckListBox( parent, id, pos, size, style ){ wxEvtHandler::Connect( GetId( ), wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, ( wxObjectEventFunction ) ( wxEventFunction ) ( wxCommandEventFunction ) &CRadioListBox::OnToggle, NULL );}CRadioListBox::~CRadioListBox( ){}int CRadioListBox::GetChecked( ){ int ret = -1; int c; for( c = 0; c < GetCount( ); c++ ) { if( IsChecked( c ) == true ) { ret = c; break; } } return ret;}void CRadioListBox::OnToggle( wxCommandEvent &event ){ int sel = event.GetInt( ); bool ischecked = IsChecked( sel ); int c; for( c = 0; c < GetCount( ); c++ ) { if( ischecked == true ) //Which means that the user has checked something { // Must uncheck everything else, except from the selection itself. if( IsChecked( c ) == true && sel != c ) { Check( c, false ); } } } event.Skip( ); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -