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

preferences_widgets.cpp

00001 /*****************************************************************************
00002  * preferences_widgets.cpp : WinCE gui plugin for VLC
00003  *****************************************************************************
00004  * Copyright (C) 2000-2004 the VideoLAN team
00005  * $Id: preferences_widgets.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Marodon Cedric <[email protected]>
00008  *          Gildas Bazin <[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 <string.h>                                            /* strerror() */
00030 #include <stdio.h>
00031 #include <vlc/vlc.h>
00032 #include <vlc/intf.h>
00033 
00034 #include "wince.h"
00035 
00036 #include <windows.h>
00037 #include <windowsx.h>
00038 #include <winuser.h>
00039 #include <commctrl.h>
00040 
00041 #include "preferences_widgets.h"
00042 
00043 /*****************************************************************************
00044  * CreateConfigControl wrapper
00045  *****************************************************************************/
00046 ConfigControl *CreateConfigControl( vlc_object_t *p_this,
00047                                     module_config_t *p_item,
00048                                     HWND parent, HINSTANCE hInst,
00049                                     int *py_pos )
00050 {
00051     ConfigControl *p_control = NULL;
00052 
00053     if( p_item->psz_current )
00054     {
00055         return NULL;
00056     }
00057     switch( p_item->i_type )
00058     {
00059     case CONFIG_ITEM_MODULE:
00060         p_control = new ModuleConfigControl( p_this, p_item, parent, hInst, py_pos );
00061         break;
00062 
00063     case CONFIG_ITEM_STRING:
00064         if( !p_item->i_list )
00065         {
00066             p_control = new StringConfigControl( p_this, p_item, parent, hInst, py_pos );
00067         }
00068         /*else
00069         {
00070             p_control = new StringListConfigControl( p_this, p_item, parent, hInst, py_pos );
00071         }*/
00072         break;
00073 /*
00074     case CONFIG_ITEM_FILE:
00075     case CONFIG_ITEM_DIRECTORY:
00076         p_control = new FileConfigControl( p_this, p_item, parent, hInst, py_pos );
00077         break;
00078 
00079     case CONFIG_ITEM_INTEGER:
00080         if( p_item->i_list )
00081         {
00082             p_control = new IntegerListConfigControl( p_this, p_item, parent, hInst, py_pos );
00083         }
00084         else if( p_item->i_min != 0 || p_item->i_max != 0 )
00085         {
00086             p_control = new RangedIntConfigControl( p_this, p_item, parent, hInst, py_pos );
00087         }
00088         else
00089         {
00090             p_control = new IntegerConfigControl( p_this, p_item, parent, hInst, py_pos );
00091         }
00092         break;
00093 */
00094     case CONFIG_ITEM_KEY:
00095         p_control = new KeyConfigControl( p_this, p_item, parent, hInst, py_pos  );
00096         break;
00097 
00098     case CONFIG_ITEM_FLOAT:
00099         p_control = new FloatConfigControl( p_this, p_item, parent, hInst, py_pos );
00100         break;
00101 
00102     case CONFIG_ITEM_BOOL:
00103         p_control = new BoolConfigControl( p_this, p_item, parent, hInst, py_pos );
00104         break;
00105 
00106     default:
00107         break;
00108     }
00109 
00110     return p_control;
00111 }
00112 
00113 /*****************************************************************************
00114  * ConfigControl implementation
00115  *****************************************************************************/
00116 ConfigControl::ConfigControl( vlc_object_t *_p_this,
00117                               module_config_t *p_item,
00118                               HWND parent, HINSTANCE hInst )
00119   : p_this( _p_this ), pf_update_callback( NULL ), p_update_data( NULL ),
00120     parent( parent ), name( p_item->psz_name ), i_type( p_item->i_type ),
00121     b_advanced( p_item->b_advanced )
00122 
00123 {
00124     /*sizer = new wxBoxSizer( wxHORIZONTAL );*/
00125 }
00126 
00127 ConfigControl::~ConfigControl()
00128 {
00129 }
00130 
00131 /*wxSizer *ConfigControl::Sizer()
00132 {
00133     return sizer;
00134 }*/
00135 
00136 char *ConfigControl::GetName()
00137 {
00138     return name;
00139 }
00140 
00141 int ConfigControl::GetType()
00142 {
00143     return i_type;
00144 }
00145 
00146 vlc_bool_t ConfigControl::IsAdvanced()
00147 {
00148     return b_advanced;
00149 }
00150 
00151 void ConfigControl::SetUpdateCallback( void (*p_callback)( void * ),
00152                                              void *p_data )
00153 {
00154     pf_update_callback = p_callback;
00155     p_update_data = p_data;
00156 }
00157 
00158 void ConfigControl::OnUpdate( UINT event )
00159 {
00160     if( pf_update_callback )
00161     {
00162         pf_update_callback( p_update_data );
00163     }
00164 }
00165 
00166 /*****************************************************************************
00167  * KeyConfigControl implementation
00168  *****************************************************************************/
00169 string *KeyConfigControl::m_keysList = NULL;
00170 
00171 KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
00172                                     module_config_t *p_item,
00173                                     HWND parent, HINSTANCE hInst,
00174                                     int * py_pos )
00175   : ConfigControl( p_this, p_item, parent, hInst )
00176 {
00177     // Number of keys descriptions
00178     unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
00179 
00180     // Init the keys decriptions array
00181     if( m_keysList == NULL )
00182     {
00183         m_keysList = new string[i_keys];
00184         for( unsigned int i = 0; i < i_keys; i++ )
00185         {
00186             m_keysList[i] = vlc_keys[i].psz_key_string;
00187         }
00188     }
00189 
00190     label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
00191                 WS_CHILD | WS_VISIBLE | SS_LEFT, 5, *py_pos, 200, 15,
00192                 parent, NULL, hInst, NULL );
00193 
00194     *py_pos += 15 + 10;
00195 
00196     alt = CreateWindow( _T("BUTTON"), _T("Alt"),
00197                         WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
00198                         20, *py_pos, 15, 15, parent, NULL, hInst, NULL );
00199     Button_SetCheck( alt, p_item->i_value & KEY_MODIFIER_ALT ? BST_CHECKED :
00200                      BST_UNCHECKED );
00201 
00202     alt_label = CreateWindow( _T("STATIC"), _T("Alt"),
00203                 WS_CHILD | WS_VISIBLE | SS_LEFT, 20 + 15 + 5, *py_pos, 30, 15,
00204                 parent, NULL, hInst, NULL );
00205 
00206     ctrl = CreateWindow( _T("BUTTON"), _T("Ctrl"),
00207                 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
00208                 20 + 15 + 5 + 30 + 5, *py_pos, 15, 15,
00209                 parent, NULL, hInst, NULL );
00210     Button_SetCheck( ctrl, p_item->i_value & KEY_MODIFIER_CTRL ? BST_CHECKED :
00211                      BST_UNCHECKED );
00212 
00213     ctrl_label = CreateWindow( _T("STATIC"), _T("Ctrl"),
00214                 WS_CHILD | WS_VISIBLE | SS_LEFT,
00215                 20 + 15 + 5 + 30 + 5 + 15 + 5, *py_pos, 30, 15,
00216                 parent, NULL, hInst, NULL );
00217 
00218     shift = CreateWindow( _T("BUTTON"), _T("Shift"),
00219                 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
00220                 20 + 15 + 5 + 2*(30 + 5) + 15 + 5, *py_pos, 15, 15,
00221                 parent, NULL, hInst, NULL );
00222     Button_SetCheck( shift, p_item->i_value & KEY_MODIFIER_SHIFT ?
00223                      BST_CHECKED : BST_UNCHECKED );
00224 
00225     shift_label = CreateWindow( _T("STATIC"), _T("Shift"),
00226                 WS_CHILD | WS_VISIBLE | SS_LEFT,
00227                 20 + 15 + 5 + 2*(30 + 5) + 2*(15 + 5), *py_pos, 30, 15,
00228                 parent, NULL, hInst, NULL );
00229 
00230     *py_pos += 15 + 10;
00231 
00232     combo = CreateWindow( _T("COMBOBOX"), _T(""),
00233                 WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST |
00234                 CBS_SORT | WS_VSCROLL, 20, *py_pos, 130, 5*15 + 6,
00235                 parent, NULL, hInst, NULL );
00236 
00237     *py_pos += 15 + 10;
00238 
00239     for( unsigned int i = 0; i < i_keys ; i++ )
00240     {
00241         ComboBox_AddString( combo, _FROMMB(m_keysList[i].c_str()) );
00242         ComboBox_SetItemData( combo, i, (void*)vlc_keys[i].i_key_code );
00243         if( (unsigned int)vlc_keys[i].i_key_code ==
00244             ( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ) )
00245         {
00246             ComboBox_SetCurSel( combo, i );
00247             ComboBox_SetText( combo, _FROMMB(m_keysList[i].c_str()) );
00248         }
00249     }
00250 }
00251 
00252 KeyConfigControl::~KeyConfigControl()
00253 {
00254     if( m_keysList )
00255     {
00256         delete[] m_keysList;
00257         m_keysList = NULL;
00258     }
00259 }
00260 
00261 int KeyConfigControl::GetIntValue()
00262 {
00263     int result = 0;
00264     if( Button_GetCheck( alt ) )
00265     {
00266         result |= KEY_MODIFIER_ALT;
00267     }
00268     if( Button_GetCheck( ctrl ) )
00269     {
00270         result |= KEY_MODIFIER_CTRL;
00271     }
00272     if( Button_GetCheck( shift ) )
00273     {
00274         result |= KEY_MODIFIER_SHIFT;
00275     }
00276     int selected = ComboBox_GetCurSel( combo );
00277     if( selected != -1 )
00278     {
00279         result |= (int)ComboBox_GetItemData( combo, selected );
00280     }
00281     return result;
00282 }
00283 
00284 /*****************************************************************************
00285  * ModuleConfigControl implementation
00286  *****************************************************************************/
00287 ModuleConfigControl::ModuleConfigControl( vlc_object_t *p_this,
00288                                           module_config_t *p_item,
00289                                           HWND parent, HINSTANCE hInst,
00290                                           int * py_pos )
00291   : ConfigControl( p_this, p_item, parent, hInst )
00292 {
00293     vlc_list_t *p_list;
00294     module_t *p_parser;
00295 
00296     label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
00297                           WS_CHILD | WS_VISIBLE | SS_LEFT,
00298                           5, *py_pos, 200, 15,
00299                           parent, NULL, hInst, NULL );
00300 
00301     *py_pos += 15 + 10;
00302 
00303     combo = CreateWindow( _T("COMBOBOX"), _T(""),
00304                           WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL |
00305                           CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL,
00306                           20, *py_pos, 180, 5*15 + 6,
00307                           parent, NULL, hInst, NULL);
00308 
00309     *py_pos += 15 + 10;
00310 
00311     /* build a list of available modules */
00312     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
00313     ComboBox_AddString( combo, _T("Default") );
00314     ComboBox_SetItemData( combo, 0, (void *)NULL );
00315     ComboBox_SetCurSel( combo, 0 );
00316     //ComboBox_SetText( combo, _T("Default") );
00317     for( int i_index = 0; i_index < p_list->i_count; i_index++ )
00318     {
00319         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
00320 
00321         if( !strcmp( p_parser->psz_capability, p_item->psz_type ) )
00322         {
00323             ComboBox_AddString( combo, _FROMMB(p_parser->psz_longname) );
00324             ComboBox_SetItemData( combo, i_index,
00325                                   (void*)p_parser->psz_object_name );
00326             if( p_item->psz_value && !strcmp(p_item->psz_value,
00327                                              p_parser->psz_object_name) )
00328             {
00329                 ComboBox_SetCurSel( combo, i_index );
00330                 //ComboBox_SetText( combo, _FROMMB(p_parser->psz_longname) );
00331             }
00332         }
00333     }
00334     vlc_list_release( p_list );
00335 }
00336 
00337 ModuleConfigControl::~ModuleConfigControl()
00338 {
00339     ;
00340 }
00341 
00342 char *ModuleConfigControl::GetPszValue()
00343 {
00344     int selected = ComboBox_GetCurSel( combo );
00345     if( selected != -1 )
00346         return (char *)ComboBox_GetItemData( combo, selected );
00347     else return NULL;
00348 }
00349 
00350 /*****************************************************************************
00351  * StringConfigControl implementation
00352  *****************************************************************************/
00353 StringConfigControl::StringConfigControl( vlc_object_t *p_this,
00354                                           module_config_t *p_item,
00355                                           HWND parent, HINSTANCE hInst,
00356                                           int * py_pos )
00357   : ConfigControl( p_this, p_item, parent, hInst )
00358 {
00359     label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
00360                           WS_CHILD | WS_VISIBLE | SS_LEFT,
00361                           5, *py_pos, 200, 15,
00362                           parent, NULL, hInst, NULL );
00363 
00364     *py_pos += 15 + 10;
00365 
00366     textctrl = CreateWindow( _T("EDIT"), p_item->psz_value ?
00367                              _FROMMB(p_item->psz_value) : _T(""),
00368                              WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT |
00369                              ES_AUTOHSCROLL, 20, *py_pos - 3, 180, 15 + 3,
00370                              parent, NULL, hInst, NULL );
00371 
00372     *py_pos += 15 + 10;
00373 }
00374 
00375 StringConfigControl::~StringConfigControl()
00376 {
00377     ;
00378 }
00379 
00380 char *StringConfigControl::GetPszValue()
00381 {
00382     int i_size;
00383     char *psz_result;
00384     TCHAR *psz_string;
00385 
00386     i_size = Edit_GetTextLength( textctrl );
00387     psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) );
00388     Edit_GetText( textctrl, psz_string, i_size + 1 );
00389     psz_result = strdup( _TOMB(psz_string) );
00390     free( psz_string );
00391     return psz_result;
00392 }
00393 
00394 #if 0
00395 /*****************************************************************************
00396  * StringListConfigControl implementation
00397  *****************************************************************************/
00398 StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
00399                                                   module_config_t *p_item,
00400                                                   HWND parent, HINSTANCE hInst,
00401                                                   int * py_pos )
00402   : ConfigControl( p_this, p_item, parent, hInst )
00403 {
00404     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00405     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00406     combo = new wxComboBox( this, -1, wxT(""),
00407                             wxDefaultPosition, wxDefaultSize,
00408                             0, NULL, wxCB_READONLY );
00409     UpdateCombo( p_item );
00410 
00411     combo->SetToolTip( wxU(p_item->psz_longtext) );
00412     sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00413 
00414     for( int i = 0; i < p_item->i_action; i++ )
00415     {
00416         wxButton *button =
00417             new wxButton( this, wxID_HIGHEST+i,
00418                           wxU(p_item->ppsz_action_text[i]) );
00419         sizer->Add( button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
00420     }
00421 
00422     sizer->Layout();
00423     this->SetSizerAndFit( sizer );
00424 }
00425 
00426 StringListConfigControl::~StringListConfigControl()
00427 {
00428 }
00429 
00430 void StringListConfigControl::UpdateCombo( module_config_t *p_item )
00431 {
00432     /* build a list of available options */
00433     for( int i_index = 0; i_index < p_item->i_list; i_index++ )
00434     {
00435         combo->Append( ( p_item->ppsz_list_text &&
00436                          p_item->ppsz_list_text[i_index] ) ?
00437                        wxU(p_item->ppsz_list_text[i_index]) :
00438                        wxL2U(p_item->ppsz_list[i_index]) );
00439         combo->SetClientData( i_index, (void *)p_item->ppsz_list[i_index] );
00440         if( ( p_item->psz_value &&
00441               !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) ) ||
00442              ( !p_item->psz_value && !*p_item->ppsz_list[i_index] ) )
00443         {
00444             combo->SetSelection( i_index );
00445             combo->SetValue( ( p_item->ppsz_list_text &&
00446                                p_item->ppsz_list_text[i_index] ) ?
00447                              wxU(p_item->ppsz_list_text[i_index]) :
00448                              wxL2U(p_item->ppsz_list[i_index]) );
00449         }
00450     }
00451 }
00452 
00453 BEGIN_EVENT_TABLE(StringListConfigControl, wxPanel)
00454     /* Button events */
00455     EVT_BUTTON(-1, StringListConfigControl::OnAction)
00456 
00457     /* Text events */
00458     EVT__T(-1, StringListConfigControl::OnUpdate)
00459 END_EVENT_TABLE()
00460 
00461 void StringListConfigControl::OnAction( wxCommandEvent& event )
00462 {
00463     int i_action = event.GetId() - wxID_HIGHEST;
00464 
00465     module_config_t *p_item = config_FindConfig( p_this, GetName().mb_str() );
00466     if( !p_item ) return;
00467 
00468     if( i_action < 0 || i_action >= p_item->i_action ) return;
00469 
00470     vlc_value_t val;
00471     wxString value = GetPszValue();
00472     (const char *)val.psz_string = value.mb_str();
00473     p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
00474 
00475     if( p_item->b_dirty )
00476     {
00477         combo->Clear();
00478         UpdateCombo( p_item );
00479         p_item->b_dirty = VLC_FALSE;
00480     }
00481 }
00482 
00483 wxString StringListConfigControl::GetPszValue()
00484 {
00485     int selected = combo->GetSelection();
00486     if( selected != -1 )
00487     {
00488         return wxL2U((char *)combo->GetClientData( selected ));
00489     }
00490     return wxString();
00491 }
00492 
00493 /*****************************************************************************
00494  * FileConfigControl implementation
00495  *****************************************************************************/
00496 FileConfigControl::FileConfigControl( vlc_object_t *p_this,
00497                                       module_config_t *p_item,
00498                                       HWND parent, HINSTANCE hInst,
00499                                       int * py_pos )
00500   : ConfigControl( p_this, p_item, parent, hInst )
00501 {
00502     directory = p_item->i_type == CONFIG_ITEM_DIRECTORY;
00503     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00504     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00505     textctrl = new wxTextCtrl( this, -1,
00506                                wxL2U(p_item->psz_value),
00507                                wxDefaultPosition,
00508                                wxDefaultSize,
00509                                wxTE_PROCESS_ENTER);
00510     textctrl->SetToolTip( wxU(p_item->psz_longtext) );
00511     sizer->Add( textctrl, 1, wxALL, 5 );
00512     browse = new wxButton( this, wxID_HIGHEST, wxU(_("Browse...")) );
00513     sizer->Add( browse, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
00514     sizer->Layout();
00515     this->SetSizerAndFit( sizer );
00516 }
00517 
00518 BEGIN_EVENT_TABLE(FileConfigControl, wxPanel)
00519     /* Button events */
00520     EVT_BUTTON(wxID_HIGHEST, FileConfigControl::OnBrowse)
00521 END_EVENT_TABLE()
00522 
00523 void FileConfigControl::OnBrowse( wxCommandEvent& event )
00524 {
00525     if( directory )
00526     {
00527         wxDirDialog dialog( this, wxU(_("Choose directory")) );
00528 
00529         if( dialog.ShowModal() == wxID_OK )
00530         {
00531             textctrl->SetValue( dialog.GetPath() );
00532         }
00533     }
00534     else
00535     {
00536         wxFileDialog dialog( this, wxU(_("Choose file")),
00537                              wxT(""), wxT(""), wxT("*.*"),
00538 #if defined( __WXMSW__ )
00539                              wxOPEN
00540 #else
00541                              wxOPEN | wxSAVE
00542 #endif
00543                            );
00544         if( dialog.ShowModal() == wxID_OK )
00545         {
00546             textctrl->SetValue( dialog.GetPath() );
00547         }
00548     }
00549 }
00550 
00551 FileConfigControl::~FileConfigControl()
00552 {
00553     ;
00554 }
00555 
00556 wxString FileConfigControl::GetPszValue()
00557 {
00558     return textctrl->GetValue();
00559 }
00560 
00561 /*****************************************************************************
00562  * IntegerConfigControl implementation
00563  *****************************************************************************/
00564 IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this,
00565                                             module_config_t *p_item,
00566                                             HWND parent, HINSTANCE hInst,
00567                                             int * py_pos )
00568   : ConfigControl( p_this, p_item, parent, hInst )
00569 {
00570     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00571     spin = new wxSpinCtrl( this, -1,
00572                            wxString::Format(wxT("%d"),
00573                                             p_item->i_value),
00574                            wxDefaultPosition, wxDefaultSize,
00575                            wxSP_ARROW_KEYS,
00576                            -10000000, 10000000, p_item->i_value);
00577     spin->SetToolTip( wxU(p_item->psz_longtext) );
00578     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00579     sizer->Add( spin, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00580     sizer->Layout();
00581     this->SetSizerAndFit( sizer );
00582 }
00583 
00584 IntegerConfigControl::~IntegerConfigControl()
00585 {
00586     ;
00587 }
00588 
00589 int IntegerConfigControl::GetIntValue()
00590 {
00591     return spin->GetValue();
00592 }
00593 
00594 /*****************************************************************************
00595  * IntegerListConfigControl implementation
00596  *****************************************************************************/
00597 IntegerListConfigControl::IntegerListConfigControl( vlc_object_t *p_this,
00598                                                     module_config_t *p_item,
00599                                                     HWND parent,
00600                                                     HINSTANCE hInst,
00601                                                     int * py_pos )
00602   : ConfigControl( p_this, p_item, parent, hInst )
00603 {
00604     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00605     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00606     combo = new wxComboBox( this, -1, wxT(""),
00607                             wxDefaultPosition, wxDefaultSize,
00608                             0, NULL, wxCB_READONLY );
00609 
00610     UpdateCombo( p_item );
00611 
00612     combo->SetToolTip( wxU(p_item->psz_longtext) );
00613     sizer->Add( combo, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00614 
00615     sizer->Layout();
00616     this->SetSizerAndFit( sizer );
00617 }
00618 
00619 IntegerListConfigControl::~IntegerListConfigControl()
00620 {
00621 }
00622 
00623 void IntegerListConfigControl::UpdateCombo( module_config_t *p_item )
00624 {
00625     /* build a list of available options */
00626     for( int i_index = 0; i_index < p_item->i_list; i_index++ )
00627     {
00628         if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
00629         {
00630             combo->Append( wxU(p_item->ppsz_list_text[i_index]) );
00631         }
00632         else
00633         {
00634             combo->Append( wxString::Format(wxT("%i"),
00635                                             p_item->pi_list[i_index]) );
00636         }
00637         combo->SetClientData( i_index, (void *)p_item->pi_list[i_index] );
00638         if( p_item->i_value == p_item->pi_list[i_index] )
00639         {
00640             combo->SetSelection( i_index );
00641             if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
00642             {
00643                 combo->SetValue( wxU(p_item->ppsz_list_text[i_index]) );
00644             }
00645             else
00646             {
00647                 combo->SetValue( wxString::Format(wxT("%i"),
00648                                                   p_item->pi_list[i_index]) );
00649             }
00650         }
00651     }
00652 }
00653 
00654 BEGIN_EVENT_TABLE(IntegerListConfigControl, wxPanel)
00655     /* Button events */
00656     EVT_BUTTON(-1, IntegerListConfigControl::OnAction)
00657 END_EVENT_TABLE()
00658 
00659 void IntegerListConfigControl::OnAction( wxCommandEvent& event )
00660 {
00661     int i_action = event.GetId() - wxID_HIGHEST;
00662 
00663     module_config_t *p_item;
00664     p_item = config_FindConfig( p_this, GetName().mb_str() );
00665     if( !p_item ) return;
00666 
00667     if( i_action < 0 || i_action >= p_item->i_action ) return;
00668 
00669     vlc_value_t val;
00670     val.i_int = GetIntValue();
00671     p_item->ppf_action[i_action]( p_this, GetName().mb_str(), val, val, 0 );
00672 
00673     if( p_item->b_dirty )
00674     {
00675         combo->Clear();
00676         UpdateCombo( p_item );
00677         p_item->b_dirty = VLC_FALSE;
00678     }
00679 }
00680 
00681 int IntegerListConfigControl::GetIntValue()
00682 {
00683     int selected = combo->GetSelection();
00684     if( selected != -1 )
00685     {
00686         return (int)combo->GetClientData( selected );
00687     }
00688     return -1;
00689 }
00690 
00691 /*****************************************************************************
00692  * RangedIntConfigControl implementation
00693  *****************************************************************************/
00694 RangedIntConfigControl::RangedIntConfigControl( vlc_object_t *p_this,
00695                                                 module_config_t *p_item, 
00696                                                 HWND parent, HINSTANCE hInst,
00697                                                 int * py_pos )
00698   : ConfigControl( p_this, p_item, parent, hInst )
00699 {
00700     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
00701     slider = new wxSlider( this, -1, p_item->i_value, p_item->i_min,
00702                            p_item->i_max, wxDefaultPosition, wxDefaultSize,
00703                            wxSL_LABELS | wxSL_HORIZONTAL );
00704     slider->SetToolTip( wxU(p_item->psz_longtext) );
00705     sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00706     sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
00707     sizer->Layout();
00708     this->SetSizerAndFit( sizer );
00709 }
00710 
00711 RangedIntConfigControl::~RangedIntConfigControl()
00712 {
00713     ;
00714 }
00715 
00716 int RangedIntConfigControl::GetIntValue()
00717 {
00718     return slider->GetValue();
00719 }
00720 
00721 #endif
00722 /*****************************************************************************
00723  * FloatConfigControl implementation
00724  *****************************************************************************/
00725 FloatConfigControl::FloatConfigControl( vlc_object_t *p_this,
00726                                         module_config_t *p_item,
00727                                         HWND parent, HINSTANCE hInst,
00728                                         int *py_pos )
00729   : ConfigControl( p_this, p_item, parent, hInst )
00730 {
00731     label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
00732                           WS_CHILD | WS_VISIBLE | SS_LEFT,
00733                           5, *py_pos, 200, 15,
00734                           parent, NULL, hInst, NULL );
00735 
00736     *py_pos += 15 + 10;
00737 
00738     TCHAR psz_string[100];
00739     _stprintf( psz_string, _T("%f"), p_item->f_value );
00740     textctrl = CreateWindow( _T("EDIT"), psz_string,
00741         WS_CHILD | WS_VISIBLE | WS_BORDER | SS_RIGHT | ES_AUTOHSCROLL,
00742         20, *py_pos - 3, 70, 15 + 3, parent, NULL, hInst, NULL );
00743 
00744     *py_pos += 15 + 10;
00745 }
00746 
00747 FloatConfigControl::~FloatConfigControl()
00748 {
00749     ;
00750 }
00751 
00752 float FloatConfigControl::GetFloatValue()
00753 {
00754     float f_value;
00755 
00756     int i_size = Edit_GetTextLength( textctrl );  
00757     TCHAR *psz_string = (TCHAR *)malloc( (i_size + 1) * sizeof(TCHAR) );
00758     Edit_GetText( textctrl, psz_string, i_size + 1 );
00759 
00760     if( _tscanf( psz_string, _T("%f"), &f_value ) == 1 )
00761     {
00762         free( psz_string );
00763         return f_value;
00764     }
00765 
00766     free( psz_string );
00767     return 0.0;
00768 }
00769 
00770 /*****************************************************************************
00771  * BoolConfigControl implementation
00772  *****************************************************************************/
00773 BoolConfigControl::BoolConfigControl( vlc_object_t *p_this,
00774                                       module_config_t *p_item, HWND parent,
00775                                       HINSTANCE hInst, int * py_pos )
00776   : ConfigControl( p_this, p_item, parent, hInst )
00777 {
00778     checkbox = CreateWindow( _T("BUTTON"), _T(""),
00779                              WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
00780                              5, *py_pos, 15, 15,
00781                              parent, NULL, hInst, NULL );
00782     Button_SetCheck( checkbox, p_item->i_value ? BST_CHECKED : BST_UNCHECKED );
00783 
00784     checkbox_label = CreateWindow( _T("STATIC"), _FROMMB(p_item->psz_text),
00785                                    WS_CHILD | WS_VISIBLE | SS_LEFT,
00786                                    5 + 15 + 5, *py_pos, 180, 15,
00787                                    parent, NULL, hInst, NULL );
00788 
00789     *py_pos += 15 + 10;
00790 }
00791 
00792 BoolConfigControl::~BoolConfigControl()
00793 {
00794     ;
00795 }
00796 
00797 int BoolConfigControl::GetIntValue()
00798 {
00799     if( Button_GetCheck( checkbox ) ) return 1;
00800     else return 0;
00801 }

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