Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

preferences_widgets.cpp

00001 /*****************************************************************************
00002  * preferences_widgets.cpp : wxWindows plugin for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2000-2004 the VideoLAN team
00005  * $Id: preferences_widgets.cpp 12836 2005-10-15 13:23:08Z sigmunau $
00006  *
00007  * Authors: Gildas Bazin <[email protected]>
00008  *          Sigmund Augdal Helberg <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 /*****************************************************************************
00026  * Preamble
00027  *****************************************************************************/
00028 #include <stdlib.h>                                      /* malloc(), free() */
00029 #include <errno.h>                                                 /* ENOMEM */
00030 #include <string.h>                                            /* strerror() */
00031 #include <stdio.h>
00032 
00033 #include <vlc/vlc.h>
00034 #include <vlc/intf.h>
00035 
00036 #include <vlc_config_cat.h>
00037 
00038 #include "wxwidgets.h"
00039 #include "preferences_widgets.h"
00040 
00041 #include <wx/statline.h>
00042 
00043 /*****************************************************************************
00044  * CreateConfigControl wrapper
00045  *****************************************************************************/
00046 ConfigControl *CreateConfigControl( vlc_object_t *p_this,
00047                                     module_config_t *p_item, wxWindow *parent )
00048 {
00049     ConfigControl *p_control = NULL;
00050 
00051     /*Skip deprecated options */
00052     if( p_item->psz_current )
00053     {
00054         return NULL;
00055     }
00056 
00057     switch( p_item->i_type )
00058     {
00059     case CONFIG_ITEM_MODULE:
00060         p_control = new ModuleConfigControl( p_this, p_item, parent );
00061         break;
00062     case CONFIG_ITEM_MODULE_CAT:
00063         p_control = new ModuleCatConfigControl( p_this, p_item, parent );
00064         break;
00065     case CONFIG_ITEM_MODULE_LIST_CAT:
00066         p_control = new ModuleListCatConfigControl( p_this, p_item, parent );
00067         break;
00068 
00069     case CONFIG_ITEM_STRING:
00070         if( !p_item->i_list )
00071         {
00072             p_control = new StringConfigControl( p_this, p_item, parent );
00073         }
00074         else
00075         {
00076             p_control = new StringListConfigControl( p_this, p_item, parent );
00077         }
00078         break;
00079 
00080     case CONFIG_ITEM_FILE:
00081     case CONFIG_ITEM_DIRECTORY:
00082         p_control = new FileConfigControl( p_this, p_item, parent );
00083         break;
00084 
00085     case CONFIG_ITEM_INTEGER:
00086         if( p_item->i_list )
00087         {
00088             p_control = new IntegerListConfigControl( p_this, p_item, parent );
00089         }
00090         else if( p_item->i_min != 0 || p_item->i_max != 0 )
00091         {
00092             p_control = new RangedIntConfigControl( p_this, p_item, parent );
00093         }
00094         else
00095         {
00096             p_control = new IntegerConfigControl( p_this, p_item, parent );
00097         }
00098         break;
00099 
00100     case CONFIG_ITEM_KEY:
00101         p_control = new KeyConfigControl( p_this, p_item, parent );
00102         break;
00103 
00104     case CONFIG_ITEM_FLOAT:
00105         p_control = new FloatConfigControl( p_this, p_item, parent );
00106         break;
00107 
00108     case CONFIG_ITEM_BOOL:
00109         p_control = new BoolConfigControl( p_this, p_item, parent );
00110         break;
00111 
00112     case CONFIG_SECTION:
00113         p_control = new SectionConfigControl( p_this, p_item, parent );
00114         break;
00115 
00116     default:
00117         break;
00118     }
00119 
00120     return p_control;
00121 }
00122 
00123 /*****************************************************************************
00124  * ConfigControl implementation
00125  *****************************************************************************/
00126 ConfigControl::ConfigControl( vlc_object_t *_p_this,
00127                               module_config_t *p_item, wxWindow *parent )
00128   : wxPanel( parent ), p_this( _p_this ),
00129     pf_update_callback( NULL ), p_update_data( NULL ),
00130     name( wxU(p_item->psz_name) ), i_type( p_item->i_type ),
00131     b_advanced( p_item->b_advanced )
00132 
00133 {
00134     sizer = new wxBoxSizer( wxHORIZONTAL );
00135 }
00136 
00137 ConfigControl::~ConfigControl()
00138 {
00139 }
00140 
00141 wxSizer *ConfigControl::Sizer()
00142 {
00143     return sizer;
00144 }
00145 
00146 wxString ConfigControl::GetName()
00147 {
00148     return name;
00149 }
00150 
00151 int ConfigControl::GetType()
00152 {
00153     return i_type;
00154 }
00155 
00156 vlc_bool_t ConfigControl::IsAdvanced()
00157 {
00158     return b_advanced;
00159 }
00160 
00161 void ConfigControl::SetUpdateCallback( void (*p_callback)( void * ),
00162                                              void *p_data )
00163 {
00164     pf_update_callback = p_callback;
00165     p_update_data = p_data;
00166 }
00167 
00168 void ConfigControl::OnUpdate( wxCommandEvent& WXUNUSED(event) )
00169 {
00170     if( pf_update_callback )
00171     {
00172         pf_update_callback( p_update_data );
00173     }
00174 }
00175 
00176 void ConfigControl::OnUpdateScroll( wxScrollEvent& WXUNUSED(event) )
00177 {
00178     wxCommandEvent cevent;
00179     OnUpdate(cevent);
00180 }
00181 
00182 
00183 /*****************************************************************************
00184  * KeyConfigControl implementation
00185  *****************************************************************************/
00186 wxString *KeyConfigControl::m_keysList = NULL;
00187 
00188 KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
00189                                     module_config_t *p_item, wxWindow *parent )
00190   : ConfigControl( p_this, p_item, parent )
00191 {
00192     // Number of keys descriptions
00193     unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
00194 
00195     // Init the keys decriptions array
00196     if( m_keysList == NULL )
00197     {
00198         m_keysList = new wxString[i_keys];
00199         for( unsigned int i = 0; i < i_keys; i++ )
00200         {
00201             m_keysList[i] = wxU(vlc_keys[i].psz_key_string);
00202         }
00203     }
00204 
00205     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00206     alt = new wxCheckBox( this, -1, wxU(_("Alt")) );
00207     alt->SetValue( p_item->i_value & KEY_MODIFIER_ALT );
00208     ctrl = new wxCheckBox( this, -1, wxU(_("Ctrl")) );
00209     ctrl->SetValue( p_item->i_value & KEY_MODIFIER_CTRL );
00210     shift = new wxCheckBox( this, -1, wxU(_("Shift")) );
00211     shift->SetValue( p_item->i_value & KEY_MODIFIER_SHIFT );
00212     combo = new wxComboBox( this, -1, wxT(""), wxDefaultPosition,
00213                             wxDefaultSize, i_keys, m_keysList,
00214                             wxCB_READONLY );
00215     for( unsigned int i = 0; i < i_keys; i++ )
00216     {
00217         combo->SetClientData( i, (void*)vlc_keys[i].i_key_code );
00218         if( (unsigned int)vlc_keys[i].i_key_code ==
00219             ( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ) )
00220         {
00221             combo->SetSelection( i );
00222             combo->SetValue( wxU(_(vlc_keys[i].psz_key_string)) );
00223         }
00224     }
00225 
00226     sizer->Add( label, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
00227     sizer->Add( alt,   1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
00228     sizer->Add( ctrl,  1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
00229     sizer->Add( shift, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
00230     sizer->Add( combo, 2, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
00231     sizer->Layout();
00232     this->SetSizerAndFit( sizer );
00233 }
00234 
00235 KeyConfigControl::~KeyConfigControl()
00236 {
00237     if( m_keysList )
00238     {
00239         delete[] m_keysList;
00240         m_keysList = NULL;
00241     }
00242 }
00243 
00244 int KeyConfigControl::GetIntValue()
00245 {
00246     int result = 0;
00247     if( alt->IsChecked() )
00248     {
00249         result |= KEY_MODIFIER_ALT;
00250     }
00251     if( ctrl->IsChecked() )
00252     {
00253         result |= KEY_MODIFIER_CTRL;
00254     }
00255     if( shift->IsChecked() )
00256     {
00257         result |= KEY_MODIFIER_SHIFT;
00258     }
00259     int selected = combo->GetSelection();
00260     if( selected != -1 )
00261     {
00262         result |= (int)combo->GetClientData( selected );
00263     }
00264     return result;
00265 }
00266 
00267 /*****************************************************************************
00268  * ModuleConfigControl implementation
00269  *****************************************************************************/
00270 ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
00271                                           module_config_t *p_item,
00272                                           wxWindow *parent )
00273   : ConfigControl( p_this, p_item, parent )
00274 {
00275     vlc_list_t *p_list;
00276     module_t *p_parser;
00277 
00278     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00279     combo = new wxComboBox( this, -1, wxL2U(p_item->psz_value),
00280                             wxDefaultPosition, wxDefaultSize,
00281                             0, NULL, wxCB_READONLY | wxCB_SORT );
00282 
00283     /* build a list of available modules */
00284     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
00285     combo->Append( wxU(_("Default")), (void *)NULL );
00286     combo->SetSelection( 0 );
00287     for( int i_index = 0; i_index < p_list->i_count; i_index++ )
00288     {
00289         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
00290 
00291         if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
00292         {
00293             combo->Append( wxU(p_parser->psz_longname),
00294                            p_parser->psz_object_name );
00295             if( p_item->psz_value && !strcmp(p_item->psz_value,
00296                                              p_parser->psz_object_name) )
00297                 combo->SetValue( wxU(p_parser->psz_longname) );
00298         }
00299     }
00300     vlc_list_release( p_list );
00301 
00302     combo->SetToolTip( wxU(p_item->psz_longtext) );
00303     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00304     sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00305     sizer->Layout();
00306     this->SetSizerAndFit( sizer );
00307 }
00308 
00309 ModuleCatConfigControl::~ModuleCatConfigControl()
00310 {
00311     ;
00312 }
00313 
00314 wxString ModuleCatConfigControl::GetPszValue()
00315 {
00316     return wxU( (char *)combo->GetClientData( combo->GetSelection() ));
00317 }
00318 
00319 /*****************************************************************************
00320  * ModuleCatConfigControl implementation
00321  *****************************************************************************/
00322 ModuleCatConfigControl::ModuleCatConfigControl( vlc_object_t *p_this,
00323                                                 module_config_t *p_item,
00324                                                 wxWindow *parent )
00325   : ConfigControl( p_this, p_item, parent )
00326 {
00327     vlc_list_t *p_list;
00328     module_t *p_parser;
00329 
00330     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00331     combo = new wxComboBox( this, -1, wxL2U(p_item->psz_value),
00332                             wxDefaultPosition, wxDefaultSize,
00333                             0, NULL, wxCB_READONLY | wxCB_SORT );
00334 
00335     combo->Append( wxU(_("Default")), (void *)NULL );
00336     combo->SetSelection( 0 );
00337 
00338     /* build a list of available modules */
00339     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
00340     for(  int i_index = 0; i_index < p_list->i_count; i_index++ )
00341     {
00342         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
00343 
00344         if( !strcmp( p_parser->psz_object_name, "main" ) )
00345               continue;
00346 
00347         module_config_t *p_config = p_parser->p_config;
00348         if( p_config ) do
00349         {
00350             /* Hack: required subcategory is stored in i_min */
00351             if( p_config->i_type == CONFIG_SUBCATEGORY &&
00352                 p_config->i_value == p_item->i_min )
00353             {
00354                 combo->Append( wxU(p_parser->psz_longname),
00355                                    p_parser->psz_object_name );
00356                 if( p_item->psz_value && !strcmp(p_item->psz_value,
00357                                         p_parser->psz_object_name) )
00358                 combo->SetValue( wxU(p_parser->psz_longname) );
00359             }
00360         } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
00361     }
00362     vlc_list_release( p_list );
00363 
00364     combo->SetToolTip( wxU(p_item->psz_longtext) );
00365     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00366     sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00367     sizer->Layout();
00368     this->SetSizerAndFit( sizer );
00369 }
00370 
00371 ModuleConfigControl::~ModuleConfigControl()
00372 {
00373     ;
00374 }
00375 
00376 wxString ModuleConfigControl::GetPszValue()
00377 {
00378     return wxU( (char *)combo->GetClientData( combo->GetSelection() ));
00379 }
00380 
00381 
00382 /*****************************************************************************
00383  * ModuleListCatonfigControl implementation
00384  *****************************************************************************/
00385 BEGIN_EVENT_TABLE(ModuleListCatConfigControl, wxPanel)
00386     EVT_CHECKBOX( wxID_HIGHEST , ModuleListCatConfigControl::OnUpdate )
00387 END_EVENT_TABLE()
00388 
00389 
00390 ModuleListCatConfigControl::ModuleListCatConfigControl( vlc_object_t *p_this,
00391                                                      module_config_t *p_item,
00392                                                      wxWindow *parent )
00393   : ConfigControl( p_this, p_item, parent )
00394 {
00395     vlc_list_t *p_list;
00396     module_t *p_parser;
00397 
00398     delete sizer;
00399     sizer = new wxBoxSizer( wxVERTICAL );
00400     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00401     sizer->Add( label );
00402 
00403     text = new wxTextCtrl( this, -1, wxU(p_item->psz_value),
00404                            wxDefaultPosition,wxSize( 300, 20 ) );
00405 
00406 
00407     /* build a list of available modules */
00408     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
00409     for(  int i_index = 0; i_index < p_list->i_count; i_index++ )
00410     {
00411         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
00412 
00413         if( !strcmp( p_parser->psz_object_name, "main" ) )
00414               continue;
00415 
00416         module_config_t *p_config = p_parser->p_config;
00417         if( p_config ) do
00418         {
00419             /* Hack: required subcategory is stored in i_min */
00420             if( p_config->i_type == CONFIG_SUBCATEGORY &&
00421                 p_config->i_value == p_item->i_min )
00422             {
00423                 moduleCheckBox *mc = new moduleCheckBox;
00424                 mc->checkbox = new wxCheckBox( this, wxID_HIGHEST,
00425                                                wxU(p_parser->psz_longname));
00426                 mc->psz_module = strdup( p_parser->psz_object_name );
00427                 pp_checkboxes.push_back( mc );
00428 
00429                 if( p_item->psz_value &&
00430                     strstr( p_item->psz_value, p_parser->psz_object_name ) )
00431                 {
00432                     mc->checkbox->SetValue( true );
00433                 }
00434                 sizer->Add( mc->checkbox );
00435             }
00436         } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
00437     }
00438     vlc_list_release( p_list );
00439 
00440     text->SetToolTip( wxU(p_item->psz_longtext) );
00441     sizer->Add(text, 0, wxEXPAND|wxALL, 5 );
00442 
00443     sizer->Add (new wxStaticText( this, -1, wxU( vlc_wraptext( _("Select modules that you want. To get more advanced control, you can also modify the resulting chain by yourself") , 72, 1 ) ) ) );
00444 
00445     sizer->Layout();
00446     this->SetSizerAndFit( sizer );
00447 }
00448 
00449 ModuleListCatConfigControl::~ModuleListCatConfigControl()
00450 {
00451     ;
00452 }
00453 
00454 wxString ModuleListCatConfigControl::GetPszValue()
00455 {
00456     return text->GetValue() ;
00457 }
00458 
00459 void  ModuleListCatConfigControl::OnUpdate( wxCommandEvent &event )
00460 {
00461     bool b_waschecked = false;
00462     wxString newtext =  text->GetValue();
00463 
00464     for( unsigned int i = 0 ; i< pp_checkboxes.size() ; i++ )
00465     {
00466         b_waschecked = newtext.Find( wxU(pp_checkboxes[i]->psz_module)) != -1 ;
00467         /* For some reasons, ^^ doesn't compile :( */
00468         if( (pp_checkboxes[i]->checkbox->IsChecked() && ! b_waschecked )||
00469             (! pp_checkboxes[i]->checkbox->IsChecked() && b_waschecked) )
00470         {
00471             if( b_waschecked )
00472             {
00473                 /* Maybe not the clest solution */
00474                 if( ! newtext.Replace(wxString(wxT(":"))
00475                                       +wxU(pp_checkboxes[i]->psz_module),
00476                                       wxT("")))
00477                 {
00478                     if( ! newtext.Replace(wxString(wxU(pp_checkboxes[i]->psz_module))
00479                                            + wxT(":"),wxT("")))
00480             {
00481                         newtext.Replace(wxU(pp_checkboxes[i]->psz_module),wxU(""));
00482                     }
00483                 }
00484             }
00485             else
00486             {
00487                 if( newtext.Len() == 0 )
00488                 {
00489                     newtext = wxU(pp_checkboxes[i]->psz_module);
00490                 }
00491                 else
00492                 {
00493                     newtext += wxU( ":" );
00494                     newtext += wxU(pp_checkboxes[i]->psz_module);
00495                 }
00496             }
00497         }
00498     }
00499     text->SetValue( newtext );
00500 }
00501 
00502 /*****************************************************************************
00503  * StringConfigControl implementation
00504  *****************************************************************************/
00505 StringConfigControl::StringConfigControl( vlc_object_t *p_this,
00506                                           module_config_t *p_item,
00507                                           wxWindow *parent )
00508   : ConfigControl( p_this, p_item, parent )
00509 {
00510     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00511     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00512     textctrl = new wxTextCtrl( this, -1,
00513                                wxL2U(p_item->psz_value),
00514                                wxDefaultPosition,
00515                                wxDefaultSize,
00516                                wxTE_PROCESS_ENTER);
00517     textctrl->SetToolTip( wxU(p_item->psz_longtext) );
00518     sizer->Add( textctrl, 1, wxALL, 5 );
00519     sizer->Layout();
00520     this->SetSizerAndFit( sizer );
00521 }
00522 
00523 StringConfigControl::~StringConfigControl()
00524 {
00525     ;
00526 }
00527 
00528 wxString StringConfigControl::GetPszValue()
00529 {
00530     return textctrl->GetValue();
00531 }
00532 
00533 BEGIN_EVENT_TABLE(StringConfigControl, wxPanel)
00534     /* Text events */
00535     EVT_TEXT(-1, StringConfigControl::OnUpdate)
00536 END_EVENT_TABLE()
00537 
00538 /*****************************************************************************
00539  * StringListConfigControl implementation
00540  *****************************************************************************/
00541 StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
00542                                                   module_config_t *p_item,
00543                                                   wxWindow *parent )
00544   : ConfigControl( p_this, p_item, parent )
00545 {
00546     psz_default_value = p_item->psz_value;
00547     if( psz_default_value ) psz_default_value = strdup( psz_default_value );
00548 
00549     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00550     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00551     combo = new wxComboBox( this, -1, wxT(""),
00552                             wxDefaultPosition, wxDefaultSize,
00553                             0, NULL, wxCB_READONLY );
00554     UpdateCombo( p_item );
00555 
00556     combo->SetToolTip( wxU(p_item->psz_longtext) );
00557     sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00558 
00559     for( int i = 0; i < p_item->i_action; i++ )
00560     {
00561         wxButton *button =
00562             new wxButton( this, wxID_HIGHEST+i,
00563                           wxU(p_item->ppsz_action_text[i]) );
00564         sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
00565     }
00566 
00567     sizer->Layout();
00568     this->SetSizerAndFit( sizer );
00569 }
00570 
00571 StringListConfigControl::~StringListConfigControl()
00572 {
00573     if( psz_default_value ) free( psz_default_value );
00574 }
00575 
00576 void StringListConfigControl::UpdateCombo( module_config_t *p_item )
00577 {
00578     vlc_bool_t b_found = VLC_FALSE;
00579     int i_index;
00580 
00581     /* build a list of available options */
00582     for( i_index = 0; i_index < p_item->i_list; i_index++ )
00583     {
00584         combo->Append( ( p_item->ppsz_list_text &&
00585                          p_item->ppsz_list_text[i_index] ) ?
00586                        wxU(p_item->ppsz_list_text[i_index]) :
00587                        wxL2U(p_item->ppsz_list[i_index]) );
00588         combo->SetClientData( i_index, (void *)p_item->ppsz_list[i_index] );
00589         if( ( p_item->psz_value &&
00590               !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) ) ||
00591              ( !p_item->psz_value && !*p_item->ppsz_list[i_index] ) )
00592         {
00593             combo->SetSelection( i_index );
00594             combo->SetValue( ( p_item->ppsz_list_text &&
00595                                p_item->ppsz_list_text[i_index] ) ?
00596                              wxU(p_item->ppsz_list_text[i_index]) :
00597                              wxL2U(p_item->ppsz_list[i_index]) );
00598             b_found = VLC_TRUE;
00599         }
00600     }
00601 
00602     if( p_item->psz_value && !b_found )
00603     {
00604         /* Add custom entry to list */
00605         combo->Append( wxL2U(p_item->psz_value) );
00606         combo->SetClientData( i_index, (void *)psz_default_value );
00607         combo->SetSelection( i_index );
00608         combo->SetValue( wxL2U(p_item->psz_value) );
00609     }
00610 }
00611 
00612 BEGIN_EVENT_TABLE(StringListConfigControl, wxPanel)
00613     /* Button events */
00614     EVT_BUTTON(-1, StringListConfigControl::OnAction)
00615 
00616     /* Text events */
00617     EVT_TEXT(-1, StringListConfigControl::OnUpdate)
00618 END_EVENT_TABLE()
00619 
00620 void StringListConfigControl::OnAction( wxCommandEvent& event )
00621 {
00622     int i_action = event.GetId() - wxID_HIGHEST;
00623 
00624     module_config_t *p_item = config_FindConfig( p_this, GetName().mb_str() );
00625     if( !p_item ) return;
00626 
00627     if( i_action < 0 || i_action >= p_item->i_action ) return;
00628 
00629     vlc_value_t val;
00630     wxString value = GetPszValue();
00631     *((const char **)&val.psz_string) = value.mb_str();
00632     p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
00633 
00634     if( p_item->b_dirty )
00635     {
00636         combo->Clear();
00637         UpdateCombo( p_item );
00638         p_item->b_dirty = VLC_FALSE;
00639     }
00640 }
00641 
00642 wxString StringListConfigControl::GetPszValue()
00643 {
00644     int selected = combo->GetSelection();
00645     if( selected != -1 )
00646     {
00647         return wxL2U((char *)combo->GetClientData( selected ));
00648     }
00649     return wxString();
00650 }
00651 
00652 /*****************************************************************************
00653  * FileConfigControl implementation
00654  *****************************************************************************/
00655 FileConfigControl::FileConfigControl( vlc_object_t *p_this,
00656                                       module_config_t *p_item,
00657                                       wxWindow *parent )
00658   : ConfigControl( p_this, p_item, parent )
00659 {
00660     directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
00661     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00662     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00663     textctrl = new wxTextCtrl( this, -1,
00664                                wxL2U(p_item->psz_value),
00665                                wxDefaultPosition,
00666                                wxDefaultSize,
00667                                wxTE_PROCESS_ENTER);
00668     textctrl->SetToolTip( wxU(p_item->psz_longtext) );
00669     sizer->Add( textctrl, 1, wxALL, 5 );
00670     browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
00671     sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
00672     sizer->Layout();
00673     this->SetSizerAndFit( sizer );
00674 }
00675 
00676 BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
00677     /* Button events */
00678     EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
00679 END_EVENT_TABLE()
00680 
00681 void FileConfigControl::OnBrowse( wxCommandEvent& event )
00682 {
00683     if( directory )
00684     {
00685         wxDirDialog dialog( this, wxU(_("Choose directory")) );
00686 
00687         if( dialog.ShowModal() == wxID_OK )
00688         {
00689             textctrl->SetValue( dialog.GetPath() );
00690         }
00691     }
00692     else
00693     {
00694         wxFileDialog dialog( this, wxU(_("Choose file")),
00695                              wxT(""), wxT(""), wxT("*.*"),
00696 #if defined( __WXMSW__ )
00697                              wxOPEN
00698 #else
00699                              wxOPEN | wxSAVE
00700 #endif
00701                            );
00702         if( dialog.ShowModal() == wxID_OK )
00703         {
00704             textctrl->SetValue( dialog.GetPath() );
00705         }
00706     }
00707 }
00708 
00709 FileConfigControl::~FileConfigControl()
00710 {
00711     ;
00712 }
00713 
00714 wxString FileConfigControl::GetPszValue()
00715 {
00716     return textctrl->GetValue();
00717 }
00718 
00719 /*****************************************************************************
00720  * IntegerConfigControl implementation
00721  *****************************************************************************/
00722 BEGIN_EVENT_TABLE(IntegerConfigControl, wxPanel)
00723     EVT_TEXT(-1, IntegerConfigControl::OnUpdate)
00724     EVT_COMMAND_SCROLL(-1, IntegerConfigControl::OnUpdateScroll)
00725 END_EVENT_TABLE()
00726 
00727 IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this,
00728                                             module_config_t *p_item,
00729                                             wxWindow *parent )
00730   : ConfigControl( p_this, p_item, parent )
00731 {
00732     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00733     spin = new wxSpinCtrl( this, -1,
00734                            wxString::Format(wxT("%d"),
00735                                             p_item->i_value),
00736                            wxDefaultPosition, wxDefaultSize,
00737                            wxSP_ARROW_KEYS,
00738                            -100000000, 100000000, p_item->i_value);
00739     spin->SetToolTip( wxU(p_item->psz_longtext) );
00740     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00741     sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00742     sizer->Layout();
00743     this->SetSizerAndFit( sizer );
00744     i_value = p_item->i_value;
00745 }
00746 
00747 IntegerConfigControl::~IntegerConfigControl()
00748 {
00749     ;
00750 }
00751 
00752 int IntegerConfigControl::GetIntValue()
00753 {
00754     /* We avoid using GetValue because of a recursion bug with wxSpinCtrl with
00755      * wxGTK. */
00756     return i_value; //spin->GetValue();
00757 }
00758 
00759 void IntegerConfigControl::OnUpdate( wxCommandEvent &event )
00760 {
00761     i_value = event.GetInt();
00762     ConfigControl::OnUpdate( event );
00763 }
00764 void IntegerConfigControl::OnUpdateScroll( wxScrollEvent &event )
00765 {
00766     wxCommandEvent cevent;
00767     cevent.SetInt(event.GetPosition());
00768     OnUpdate(cevent);
00769 }
00770 
00771 /*****************************************************************************
00772  * IntegerListConfigControl implementation
00773  *****************************************************************************/
00774 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *p_this,
00775                                                     module_config_t *p_item,
00776                                                     wxWindow *parent )
00777   : ConfigControl( p_this, p_item, parent )
00778 {
00779     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00780     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00781     combo = new wxComboBox( this, -1, wxT(""),
00782                             wxDefaultPosition, wxDefaultSize,
00783                             0, NULL, wxCB_READONLY );
00784 
00785     UpdateCombo( p_item );
00786 
00787     combo->SetToolTip( wxU(p_item->psz_longtext) );
00788     sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00789 
00790     sizer->Layout();
00791     this->SetSizerAndFit( sizer );
00792 }
00793 
00794 IntegerListConfigControl::~IntegerListConfigControl()
00795 {
00796 }
00797 
00798 void IntegerListConfigControl::UpdateCombo( module_config_t *p_item )
00799 {
00800     /* build a list of available options */
00801     for( int i_index = 0; i_index < p_item->i_list; i_index++ )
00802     {
00803         if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
00804         {
00805             combo->Append( wxU(p_item->ppsz_list_text[i_index]) );
00806         }
00807         else
00808         {
00809             combo->Append( wxString::Format(wxT("%i"),
00810                                             p_item->pi_list[i_index]) );
00811         }
00812         combo->SetClientData( i_index, (void *)p_item->pi_list[i_index] );
00813         if( p_item->i_value == p_item->pi_list[i_index] )
00814         {
00815             combo->SetSelection( i_index );
00816             if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
00817             {
00818                 combo->SetValue( wxU(p_item->ppsz_list_text[i_index]) );
00819             }
00820             else
00821             {
00822                 combo->SetValue( wxString::Format(wxT("%i"),
00823                                                   p_item->pi_list[i_index]) );
00824             }
00825         }
00826     }
00827 }
00828 
00829 BEGIN_EVENT_TABLE(IntegerListConfigControl, wxPanel)
00830     /* Button events */
00831     EVT_BUTTON(-1, IntegerListConfigControl::OnAction)
00832 
00833     /* Update events */
00834     EVT_TEXT(-1, IntegerListConfigControl::OnUpdate)
00835 END_EVENT_TABLE()
00836 
00837 void IntegerListConfigControl::OnAction( wxCommandEvent& event )
00838 {
00839     int i_action = event.GetId() - wxID_HIGHEST;
00840 
00841     module_config_t *p_item;
00842     p_item = config_FindConfig( p_this, GetName().mb_str() );
00843     if( !p_item ) return;
00844 
00845     if( i_action < 0 || i_action >= p_item->i_action ) return;
00846 
00847     vlc_value_t val;
00848     val.i_int = GetIntValue();
00849     p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
00850 
00851     if( p_item->b_dirty )
00852     {
00853         combo->Clear();
00854         UpdateCombo( p_item );
00855         p_item->b_dirty = VLC_FALSE;
00856     }
00857 }
00858 
00859 int IntegerListConfigControl::GetIntValue()
00860 {
00861     int selected = combo->GetSelection();
00862     if( selected != -1 )
00863     {
00864         return (int)combo->GetClientData( selected );
00865     }
00866     return -1;
00867 }
00868 
00869 /*****************************************************************************
00870  * RangedIntConfigControl implementation
00871  *****************************************************************************/
00872 BEGIN_EVENT_TABLE(RangedIntConfigControl, wxPanel)
00873     EVT_COMMAND_SCROLL(-1, RangedIntConfigControl::OnUpdateScroll)
00874 END_EVENT_TABLE()
00875 
00876 RangedIntConfigControl::RangedIntConfigControl( vlc_object_t *p_this,
00877                                                 module_config_t *p_item,
00878                                                 wxWindow *parent )
00879   : ConfigControl( p_this, p_item, parent )
00880 {
00881     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00882     slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
00883                            p_item->i_max, wxDefaultPosition, wxDefaultSize,
00884                            wxSL_LABELS | wxSL_HORIZONTAL );
00885     slider->SetToolTip( wxU(p_item->psz_longtext) );
00886     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00887     sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00888     sizer->Layout();
00889     this->SetSizerAndFit( sizer );
00890 }
00891 
00892 RangedIntConfigControl::~RangedIntConfigControl()
00893 {
00894     ;
00895 }
00896 
00897 int RangedIntConfigControl::GetIntValue()
00898 {
00899     return slider->GetValue();
00900 }
00901 
00902 
00903 /*****************************************************************************
00904  * FloatConfigControl implementation
00905  *****************************************************************************/
00906 BEGIN_EVENT_TABLE(FloatConfigControl, wxPanel)
00907     EVT_TEXT(-1, FloatConfigControl::OnUpdate)
00908 END_EVENT_TABLE()
00909 
00910 FloatConfigControl::FloatConfigControl( vlc_object_t *p_this,
00911                                         module_config_t *p_item,
00912                                         wxWindow *parent )
00913   : ConfigControl( p_this, p_item, parent )
00914 {
00915     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00916     textctrl = new wxTextCtrl( this, -1,
00917                                wxString::Format(wxT("%f"),
00918                                                 p_item->f_value),
00919                                wxDefaultPosition, wxDefaultSize,
00920                                wxTE_PROCESS_ENTER );
00921     textctrl->SetToolTip( wxU(p_item->psz_longtext) );
00922     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00923     sizer->Add( textctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
00924     sizer->Layout();
00925     this->SetSizerAndFit( sizer );
00926 }
00927 
00928 FloatConfigControl::~FloatConfigControl()
00929 {
00930     ;
00931 }
00932 
00933 float FloatConfigControl::GetFloatValue()
00934 {
00935     float f_value;
00936     if( (wxSscanf(textctrl->GetValue(), wxT("%f"), &f_value) == 1) )
00937         return f_value;
00938     else return 0.0;
00939 }
00940 
00941 /*****************************************************************************
00942  * BoolConfigControl implementation
00943  *****************************************************************************/
00944 BEGIN_EVENT_TABLE(BoolConfigControl, wxPanel)
00945     EVT_CHECKBOX(-1, BoolConfigControl::OnUpdate)
00946 END_EVENT_TABLE()
00947 
00948 BoolConfigControl::BoolConfigControl( vlc_object_t *p_this,
00949                                       module_config_t *p_item,
00950                                       wxWindow *parent )
00951   : ConfigControl( p_this, p_item, parent )
00952 {
00953     checkbox = new wxCheckBox( this, -1, wxU(p_item->psz_text) );
00954     if( p_item->i_value ) checkbox->SetValue(TRUE);
00955     checkbox->SetToolTip( wxU(p_item->psz_longtext) );
00956     sizer->Add( checkbox, 0, wxALL, 5 );
00957     sizer->Layout();
00958     this->SetSizerAndFit( sizer );
00959 }
00960 
00961 BoolConfigControl::~BoolConfigControl()
00962 {
00963     ;
00964 }
00965 
00966 int BoolConfigControl::GetIntValue()
00967 {
00968     if( checkbox->IsChecked() ) return 1;
00969     else return 0;
00970 }
00971 
00972 /*****************************************************************************
00973  * SectionConfigControl implementation
00974  *****************************************************************************/
00975 SectionConfigControl::SectionConfigControl( vlc_object_t *p_this,
00976                                             module_config_t *p_item,
00977                                             wxWindow *parent )
00978   : ConfigControl( p_this, p_item, parent )
00979 {
00980     delete sizer;
00981     sizer = new wxBoxSizer( wxVERTICAL );
00982     sizer->Add( new wxStaticText( this, -1, wxU( p_item->psz_text ) ) );
00983     sizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND, 5 );
00984     sizer->Layout();
00985     this->SetSizerAndFit( sizer );
00986 }
00987 
00988 SectionConfigControl::~SectionConfigControl()
00989 {
00990     ;
00991 }

Generated on Tue Dec 20 10:14:46 2005 for vlc-0.8.4a by  doxygen 1.4.2