📄 preferences_widgets.cpp
字号:
label = new wxStaticText(this, -1, wxU(p_item->psz_text)); sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); combo = new wxComboBox( this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); UpdateCombo( p_item ); combo->SetToolTip( wxU(p_item->psz_longtext) ); sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); for( int i = 0; i < p_item->i_action; i++ ) { wxButton *button = new wxButton( this, wxID_HIGHEST+i, wxU(p_item->ppsz_action_text[i]) ); sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); } sizer->Layout(); this->SetSizerAndFit( sizer );}StringListConfigControl::~StringListConfigControl(){}void StringListConfigControl::UpdateCombo( module_config_t *p_item ){ /* build a list of available options */ for( int i_index = 0; i_index < p_item->i_list; i_index++ ) { combo->Append( ( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] ) ? wxU(p_item->ppsz_list_text[i_index]) : wxL2U(p_item->ppsz_list[i_index]) ); combo->SetClientData( i_index, (void *)p_item->ppsz_list[i_index] ); if( ( p_item->psz_value && !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) ) || ( !p_item->psz_value && !*p_item->ppsz_list[i_index] ) ) { combo->SetSelection( i_index ); combo->SetValue( ( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] ) ? wxU(p_item->ppsz_list_text[i_index]) : wxL2U(p_item->ppsz_list[i_index]) ); } }}BEGIN_EVENT_TABLE(StringListConfigControl, wxPanel) /* Button events */ EVT_BUTTON(-1, StringListConfigControl::OnAction) /* Text events */ EVT__T(-1, StringListConfigControl::OnUpdate)END_EVENT_TABLE()void StringListConfigControl::OnAction( wxCommandEvent& event ){ int i_action = event.GetId() - wxID_HIGHEST; module_config_t *p_item = config_FindConfig( p_this, GetName().mb_str() ); if( !p_item ) return; if( i_action < 0 || i_action >= p_item->i_action ) return; vlc_value_t val; wxString value = GetPszValue(); (const char *)val.psz_string = value.mb_str(); p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 ); if( p_item->b_dirty ) { combo->Clear(); UpdateCombo( p_item ); p_item->b_dirty = false; }}wxString StringListConfigControl::GetPszValue(){ int selected = combo->GetSelection(); if( selected != -1 ) { return wxL2U((char *)combo->GetClientData( selected )); } return wxString();}/***************************************************************************** * FileConfigControl implementation *****************************************************************************/FileConfigControl::FileConfigControl( vlc_object_t *p_this, module_config_t *p_item, HWND parent, HINSTANCE hInst, int * py_pos ) : ConfigControl( p_this, p_item, parent, hInst ){ directory = p_item->i_type == CONFIG_ITEM_DIRECTORY; label = new wxStaticText(this, -1, wxU(p_item->psz_text)); sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); textctrl = new wxTextCtrl( this, -1, wxL2U(p_item->psz_value), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); textctrl->SetToolTip( wxU(p_item->psz_longtext) ); sizer->Add( textctrl, 1, wxALL, 5 ); browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) ); sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); sizer->Layout(); this->SetSizerAndFit( sizer );}BEGIN_EVENT_TABLE(FileConfigControl, wxPanel) /* Button events */ EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)END_EVENT_TABLE()void FileConfigControl::OnBrowse( wxCommandEvent& event ){ if( directory ) { wxDirDialog dialog( this, wxU(_("Choose directory")) ); if( dialog.ShowModal() == wxID_OK ) { textctrl->SetValue( dialog.GetPath() ); } } else { wxFileDialog dialog( this, wxU(_("Choose file")), wxT(""), wxT(""), wxT("*.*"),#if defined( __WXMSW__ ) wxOPEN#else wxOPEN | wxSAVE#endif ); if( dialog.ShowModal() == wxID_OK ) { textctrl->SetValue( dialog.GetPath() ); } }}FileConfigControl::~FileConfigControl(){ ;}wxString FileConfigControl::GetPszValue(){ return textctrl->GetValue();}/***************************************************************************** * IntegerConfigControl implementation *****************************************************************************/IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this, module_config_t *p_item, HWND parent, HINSTANCE hInst, int * py_pos ) : ConfigControl( p_this, p_item, parent, hInst ){ label = new wxStaticText(this, -1, wxU(p_item->psz_text)); spin = new wxSpinCtrl( this, -1, wxString::Format(wxT("%d"), p_item->i_value), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, -10000000, 10000000, p_item->i_value); spin->SetToolTip( wxU(p_item->psz_longtext) ); sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); sizer->Layout(); this->SetSizerAndFit( sizer );}IntegerConfigControl::~IntegerConfigControl(){ ;}int IntegerConfigControl::GetIntValue(){ return spin->GetValue();}/***************************************************************************** * IntegerListConfigControl implementation *****************************************************************************/IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *p_this, module_config_t *p_item, HWND parent, HINSTANCE hInst, int * py_pos ) : ConfigControl( p_this, p_item, parent, hInst ){ label = new wxStaticText(this, -1, wxU(p_item->psz_text)); sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); combo = new wxComboBox( this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY ); UpdateCombo( p_item ); combo->SetToolTip( wxU(p_item->psz_longtext) ); sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); sizer->Layout(); this->SetSizerAndFit( sizer );}IntegerListConfigControl::~IntegerListConfigControl(){}void IntegerListConfigControl::UpdateCombo( module_config_t *p_item ){ /* build a list of available options */ for( int i_index = 0; i_index < p_item->i_list; i_index++ ) { if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] ) { combo->Append( wxU(p_item->ppsz_list_text[i_index]) ); } else { combo->Append( wxString::Format(wxT("%i"), p_item->pi_list[i_index]) ); } combo->SetClientData( i_index, (void *)p_item->pi_list[i_index] ); if( p_item->i_value == p_item->pi_list[i_index] ) { combo->SetSelection( i_index ); if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] ) { combo->SetValue( wxU(p_item->ppsz_list_text[i_index]) ); } else { combo->SetValue( wxString::Format(wxT("%i"), p_item->pi_list[i_index]) ); } } }}BEGIN_EVENT_TABLE(IntegerListConfigControl, wxPanel) /* Button events */ EVT_BUTTON(-1, IntegerListConfigControl::OnAction)END_EVENT_TABLE()void IntegerListConfigControl::OnAction( wxCommandEvent& event ){ int i_action = event.GetId() - wxID_HIGHEST; module_config_t *p_item; p_item = config_FindConfig( p_this, GetName().mb_str() ); if( !p_item ) return; if( i_action < 0 || i_action >= p_item->i_action ) return; vlc_value_t val; val.i_int = GetIntValue(); p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 ); if( p_item->b_dirty ) { combo->Clear(); UpdateCombo( p_item ); p_item->b_dirty = false; }}int IntegerListConfigControl::GetIntValue(){ int selected = combo->GetSelection(); if( selected != -1 ) { return (int)combo->GetClientData( selected ); } return -1;}/***************************************************************************** * RangedIntConfigControl implementation *****************************************************************************/RangedIntConfigControl::RangedIntConfigControl( vlc_object_t *p_this, module_config_t *p_item, HWND parent, HINSTANCE hInst, int * py_pos ) : ConfigControl( p_this, p_item, parent, hInst ){ label = new wxStaticText(this, -1, wxU(p_item->psz_text)); slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min, p_item->i_max, wxDefaultPosition, wxDefaultSize, wxSL_LABELS | wxSL_HORIZONTAL ); slider->SetToolTip( wxU(p_item->psz_longtext) ); sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); sizer->Layout(); this->SetSizerAndFit( sizer );}RangedIntConfigControl::~RangedIntConfigControl(){ ;}int RangedIntConfigControl::GetIntValue(){ return slider->GetValue();}#endif/***************************************************************************** * FloatConfigControl implementation *****************************************************************************/FloatConfigControl::FloatConfigControl( vlc_object_t *p_this, module_config_t *p_item, HWND parent, HINSTANCE hInst, int *py_pos ) : ConfigControl( p_this, p_item, parent, hInst ){ label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text), WS_CHILD | WS_VISIBLE | SS_LEFT, 5, *py_pos, 200, 15, parent, NULL, hInst, NULL ); *py_pos += 15 + 10; TCHAR psz_string[100]; _stprintf( psz_string, _T("%f"), p_item->f_value ); textctrl = CreateWindow( _T("EDIT"), psz_string, WS_CHILD | WS_VISIBLE | WS_BORDER | SS_RIGHT | ES_AUTOHSCROLL, 20, *py_pos - 3, 70, 15 + 3, parent, NULL, hInst, NULL ); *py_pos += 15 + 10;}FloatConfigControl::~FloatConfigControl(){ ;}float FloatConfigControl::GetFloatValue(){ float f_value; int i_size = Edit_GetTextLength( textctrl ); TCHAR *psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) ); Edit_GetText( textctrl, psz_string, i_size + 1 ); if( _tscanf( psz_string, _T("%f"), &f_value ) == 1 ) { free( psz_string ); return f_value; } free( psz_string ); return 0.0;}/***************************************************************************** * BoolConfigControl implementation *****************************************************************************/BoolConfigControl::BoolConfigControl( vlc_object_t *p_this, module_config_t *p_item, HWND parent, HINSTANCE hInst, int * py_pos ) : ConfigControl( p_this, p_item, parent, hInst ){ checkbox = CreateWindow( _T("BUTTON"), _T(""), WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, 5, *py_pos, 15, 15, parent, NULL, hInst, NULL ); Button_SetCheck( checkbox, p_item->i_value ? BST_CHECKED : BST_UNCHECKED ); checkbox_label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text), WS_CHILD | WS_VISIBLE | SS_LEFT, 5 + 15 + 5, *py_pos, 180, 15, parent, NULL, hInst, NULL ); *py_pos += 15 + 10;}BoolConfigControl::~BoolConfigControl(){ ;}int BoolConfigControl::GetIntValue(){ if( Button_GetCheck( checkbox ) ) return 1; else return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -