]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwindows/preferences_widgets.cpp
* modules/gui/wxwindows/*: new --wxwin-keep-size option to remember the size of the...
[vlc] / modules / gui / wxwindows / preferences_widgets.cpp
index b6b0bd16b0dde064d8e75355f77da5ec9bbc09d2..af4206cfa269743690e6057ee113ba6fb43cb64e 100644 (file)
@@ -2,9 +2,9 @@
  * preferences_widgets.cpp : wxWindows plugin for vlc
  *****************************************************************************
  * Copyright (C) 2000-2004 VideoLAN
- * $Id: preferences_widgets.cpp,v 1.23 2004/01/29 17:04:01 gbazin Exp $
+ * $Id$
  *
- * Authors: Gildas Bazin <gbazin@netcourrier.com>
+ * Authors: Gildas Bazin <gbazin@videolan.org>
  *          Sigmund Augdal <sigmunau@idi.ntnu.no>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -158,82 +158,25 @@ void ConfigControl::OnUpdate( wxCommandEvent& WXUNUSED(event) )
 /*****************************************************************************
  * KeyConfigControl implementation
  *****************************************************************************/
-static wxString KeysList[] =
-{
-    wxT("Unset"),
-    wxT("Left"),
-    wxT("Right"),
-    wxT("Up"),
-    wxT("Down"),
-    wxT("Space"),
-    wxT("Enter"),
-    wxT("F1"),
-    wxT("F2"),
-    wxT("F3"),
-    wxT("F4"),
-    wxT("F5"),
-    wxT("F6"),
-    wxT("F7"),
-    wxT("F8"),
-    wxT("F9"),
-    wxT("F10"),
-    wxT("F11"),
-    wxT("F12"),
-    wxT("Home"),
-    wxT("End"),
-    wxT("Menu"),
-    wxT("Esc"),
-    wxT("Page Up"),
-    wxT("Page Down"),
-    wxT("Tab"),
-    wxT("Backspace"),
-    wxT("a"),
-    wxT("b"),
-    wxT("c"),
-    wxT("d"),
-    wxT("e"),
-    wxT("f"),
-    wxT("g"),
-    wxT("h"),
-    wxT("i"),
-    wxT("j"),
-    wxT("k"),
-    wxT("l"),
-    wxT("m"),
-    wxT("n"),
-    wxT("o"),
-    wxT("p"),
-    wxT("q"),
-    wxT("r"),
-    wxT("s"),
-    wxT("t"),
-    wxT("u"),
-    wxT("v"),
-    wxT("w"),
-    wxT("x"),
-    wxT("y"),
-    wxT("z"),
-    wxT("+"),
-    wxT("="),
-    wxT("-"),
-    wxT(","),
-    wxT("."),
-    wxT("<"),
-    wxT(">"),
-    wxT("`"),
-    wxT("/"),
-    wxT(";"),
-    wxT("'"),
-    wxT("\\"),
-    wxT("["),
-    wxT("]"),
-    wxT("*")
-};
+wxString *KeyConfigControl::m_keysList = NULL;
 
 KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
                                     module_config_t *p_item, wxWindow *parent )
   : ConfigControl( p_this, p_item, parent )
 {
+    // Number of keys descriptions
+    unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
+
+    // Init the keys decriptions array
+    if( m_keysList == NULL )
+    {
+        m_keysList = new wxString[i_keys];
+        for( unsigned int i = 0; i < i_keys; i++ )
+        {
+            m_keysList[i] = wxU(vlc_keys[i].psz_key_string);
+        }
+    }
+
     label = new wxStaticText(this, -1, wxU(p_item->psz_text));
     alt = new wxCheckBox( this, -1, wxU(_("Alt")) );
     alt->SetValue( p_item->i_value & KEY_MODIFIER_ALT );
@@ -242,9 +185,9 @@ KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
     shift = new wxCheckBox( this, -1, wxU(_("Shift")) );
     shift->SetValue( p_item->i_value & KEY_MODIFIER_SHIFT );
     combo = new wxComboBox( this, -1, wxT(""), wxDefaultPosition,
-                            wxDefaultSize, WXSIZEOF(KeysList), KeysList,
+                            wxDefaultSize, i_keys, m_keysList,
                             wxCB_READONLY );
-    for( unsigned int i = 0; i < WXSIZEOF(KeysList); i++ )
+    for( unsigned int i = 0; i < i_keys; i++ )
     {
         combo->SetClientData( i, (void*)vlc_keys[i].i_key_code );
         if( (unsigned int)vlc_keys[i].i_key_code ==
@@ -266,7 +209,11 @@ KeyConfigControl::KeyConfigControl( vlc_object_t *p_this,
 
 KeyConfigControl::~KeyConfigControl()
 {
-    ;
+    if( m_keysList )
+    {
+        delete[] m_keysList;
+        m_keysList = NULL;
+    }
 }
 
 int KeyConfigControl::GetIntValue()
@@ -388,6 +335,9 @@ StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
                                                   wxWindow *parent )
   : ConfigControl( p_this, p_item, parent )
 {
+    psz_default_value = p_item->psz_value;
+    if( psz_default_value ) psz_default_value = strdup( psz_default_value );
+
     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(""),
@@ -412,12 +362,16 @@ StringListConfigControl::StringListConfigControl( vlc_object_t *p_this,
 
 StringListConfigControl::~StringListConfigControl()
 {
+    if( psz_default_value ) free( psz_default_value );
 }
 
 void StringListConfigControl::UpdateCombo( module_config_t *p_item )
 {
+    vlc_bool_t b_found = VLC_FALSE;
+    int i_index;
+
     /* build a list of available options */
-    for( int i_index = 0; i_index < p_item->i_list; i_index++ )
+    for( 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] ) ?
@@ -433,8 +387,18 @@ void StringListConfigControl::UpdateCombo( module_config_t *p_item )
                                p_item->ppsz_list_text[i_index] ) ?
                              wxU(p_item->ppsz_list_text[i_index]) :
                              wxL2U(p_item->ppsz_list[i_index]) );
+            b_found = VLC_TRUE;
         }
     }
+
+    if( p_item->psz_value && !b_found )
+    {
+        /* Add custom entry to list */
+        combo->Append( wxL2U(p_item->psz_value) );
+        combo->SetClientData( i_index, (void *)psz_default_value );
+        combo->SetSelection( i_index );
+        combo->SetValue( wxL2U(p_item->psz_value) );
+    }
 }
 
 BEGIN_EVENT_TABLE(StringListConfigControl, wxPanel)
@@ -547,6 +511,11 @@ wxString FileConfigControl::GetPszValue()
 /*****************************************************************************
  * IntegerConfigControl implementation
  *****************************************************************************/
+BEGIN_EVENT_TABLE(IntegerConfigControl, wxPanel)
+    EVT_TEXT(-1, IntegerConfigControl::OnUpdate)
+    EVT_COMMAND_SCROLL(-1, IntegerConfigControl::OnUpdate)
+END_EVENT_TABLE()
+
 IntegerConfigControl::IntegerConfigControl( vlc_object_t *p_this,
                                             module_config_t *p_item,
                                             wxWindow *parent )
@@ -674,6 +643,10 @@ int IntegerListConfigControl::GetIntValue()
 /*****************************************************************************
  * RangedIntConfigControl implementation
  *****************************************************************************/
+BEGIN_EVENT_TABLE(RangedIntConfigControl, wxPanel)
+    EVT_COMMAND_SCROLL(-1, RangedIntConfigControl::OnUpdate)
+END_EVENT_TABLE()
+
 RangedIntConfigControl::RangedIntConfigControl( vlc_object_t *p_this,
                                                 module_config_t *p_item,
                                                 wxWindow *parent )
@@ -703,6 +676,10 @@ int RangedIntConfigControl::GetIntValue()
 /*****************************************************************************
  * FloatConfigControl implementation
  *****************************************************************************/
+BEGIN_EVENT_TABLE(FloatConfigControl, wxPanel)
+    EVT_TEXT(-1, FloatConfigControl::OnUpdate)
+END_EVENT_TABLE()
+
 FloatConfigControl::FloatConfigControl( vlc_object_t *p_this,
                                         module_config_t *p_item,
                                         wxWindow *parent )
@@ -737,6 +714,10 @@ float FloatConfigControl::GetFloatValue()
 /*****************************************************************************
  * BoolConfigControl implementation
  *****************************************************************************/
+BEGIN_EVENT_TABLE(BoolConfigControl, wxPanel)
+    EVT_CHECKBOX(-1, BoolConfigControl::OnUpdate)
+END_EVENT_TABLE()
+
 BoolConfigControl::BoolConfigControl( vlc_object_t *p_this,
                                       module_config_t *p_item,
                                       wxWindow *parent )
@@ -757,12 +738,6 @@ BoolConfigControl::~BoolConfigControl()
 
 int BoolConfigControl::GetIntValue()
 {
-    if( checkbox->IsChecked() )
-    {
-        return 1;
-    }
-    else
-    {
-        return 0;
-    }
+    if( checkbox->IsChecked() ) return 1;
+    else return 0;
 }